summaryrefslogtreecommitdiffstats
path: root/src/VBox/Devices/EFI/DevEFI.h
blob: 400f537a57b29731801b49e2b2eda31f32dd24fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* $Id: DevEFI.h $ */
/** @file
 * EFI for VirtualBox Common Definitions.
 *
 * WARNING: This header is used by both firmware and VBox device,
 * thus don't put anything here but numeric constants or helper
 * inline functions.
 */

/*
 * Copyright (C) 2009-2023 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * The contents of this file may alternatively be used under the terms
 * of the Common Development and Distribution License Version 1.0
 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
 * in the VirtualBox distribution, in which case the provisions of the
 * CDDL are applicable instead of those of the GPL.
 *
 * You may elect to license modified versions of this file under the
 * terms and conditions of either the GPL or the CDDL or both.
 *
 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
 */

#ifndef VBOX_INCLUDED_SRC_EFI_DevEFI_h
#define VBOX_INCLUDED_SRC_EFI_DevEFI_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

/** @defgroup grp_devefi    DevEFI <-> Firmware Interfaces
 * @{
 */

/** The base of the I/O ports used for interaction between the EFI firmware and DevEFI. */
#define EFI_PORT_BASE           0xEF10  /**< @todo r=klaus stupid choice which causes trouble with PCI resource allocation in complex bridge setups, change to 0x0400 with appropriate saved state and reset handling */
/** The number of ports. */
#define EFI_PORT_COUNT          0x0008


/** Information querying.
 * 32-bit write sets the info index and resets the reading, see EfiInfoIndex.
 * 32-bit read returns the size of the info (in bytes).
 * 8-bit reads returns the info as a byte sequence. */
#define EFI_INFO_PORT           (EFI_PORT_BASE+0x0)
/**
 * Information requests.
 */
typedef enum
{
    EFI_INFO_INDEX_INVALID = 0,
    EFI_INFO_INDEX_VOLUME_BASE,
    EFI_INFO_INDEX_VOLUME_SIZE,
    EFI_INFO_INDEX_TEMPMEM_BASE,
    EFI_INFO_INDEX_TEMPMEM_SIZE,
    EFI_INFO_INDEX_STACK_BASE,
    EFI_INFO_INDEX_STACK_SIZE,
    EFI_INFO_INDEX_BOOT_ARGS,
    EFI_INFO_INDEX_DEVICE_PROPS,
    EFI_INFO_INDEX_FSB_FREQUENCY,
    EFI_INFO_INDEX_CPU_FREQUENCY,
    EFI_INFO_INDEX_TSC_FREQUENCY,
    EFI_INFO_INDEX_GRAPHICS_MODE,
    EFI_INFO_INDEX_HORIZONTAL_RESOLUTION,
    EFI_INFO_INDEX_VERTICAL_RESOLUTION,
    EFI_INFO_INDEX_MCFG_BASE,
    EFI_INFO_INDEX_MCFG_SIZE,
    EFI_INFO_INDEX_APIC_MODE,
    EFI_INFO_INDEX_CPU_COUNT_CURRENT,
    EFI_INFO_INDEX_CPU_COUNT_MAX,
    EFI_INFO_INDEX_END
} EfiInfoIndex;

/** @name APIC mode defines as returned by EFI_INFO_INDEX_APIC_MODE
 * @{ */
#define EFI_APIC_MODE_DISABLED          0
#define EFI_APIC_MODE_APIC              1
#define EFI_APIC_MODE_X2APIC            2
/** @} */

/** Panic port.
 * Write causes action to be taken according to the value written,
 * see the EFI_PANIC_CMD_* defines below.
 * Reading from the port has no effect. */
#define EFI_PANIC_PORT          (EFI_PORT_BASE+0x1)

/** @defgroup grp_devefi_panic_cmd  Panic Commands for EFI_PANIC_PORT
 * @{ */
/** Used by the EfiThunk.asm to signal ORG inconsistency. */
#define EFI_PANIC_CMD_BAD_ORG           1
/** Used by the EfiThunk.asm to signal unexpected trap or interrupt. */
#define EFI_PANIC_CMD_THUNK_TRAP        2
/** Starts a panic message.
 * Makes sure the panic message buffer is empty. */
#define EFI_PANIC_CMD_START_MSG         3
/** Ends a panic message and enters guru meditation state. */
#define EFI_PANIC_CMD_END_MSG           4
/** The first panic message command.
 * The low byte of the command is the char to be added to the panic message. */
#define EFI_PANIC_CMD_MSG_FIRST         0x4201
/** The last panic message command. */
#define EFI_PANIC_CMD_MSG_LAST          0x427f
/** Makes a panic message command from a char. */
#define EFI_PANIC_CMD_MSG_FROM_CHAR(ch) (0x4200 | ((ch) & 0x7f) )
/** Extracts the char from a panic message command. */
#define EFI_PANIC_CMD_MSG_GET_CHAR(u32) ((u32) & 0x7f)
/** @} */

/** EFI event signalling.
 * A 16-bit event identifier is written first.
 * It might follow a number of writes to convey additional data,
 * the size depends on the event identifier.
 */
#define EFI_PORT_EVENT          (EFI_PORT_BASE+0x2)

/**
 * Events.
 */
typedef enum EFI_EVENT_TYPE
{
    /** Invalid event id. */
    EFI_EVENT_TYPE_INVALID = 0,
    /** Booting any guest OS failed. */
    EFI_EVENT_TYPE_BOOT_FAILED,
    /** 32bit blow up hack. */
    EFI_EVENT_TYPE_16_BIT_HACK = 0x7fff
} EFI_EVENT_TYPE;


/** Debug logging.
 * The chars written goes to the log.
 * Reading has no effect.
 * @remarks The port number is the same as on of those used by the PC BIOS. */
#define EFI_DEBUG_PORT          (EFI_PORT_BASE+0x3)

#define VBOX_EFI_DEBUG_BUFFER   512
/** The top of the EFI stack.
 * The firmware expects a 128KB stack.
 * @todo Move this to 1MB + 128KB and drop the stack relocation the firmware
 *       does. It expects the stack to be within the temporary memory that
 *       SEC hands to PEI and the VBoxAutoScan PEIM reports. */
#define VBOX_EFI_TOP_OF_STACK   0x300000

#define EFI_PORT_VARIABLE_OP    (EFI_PORT_BASE+0x4)
#define EFI_PORT_VARIABLE_PARAM (EFI_PORT_BASE+0x5)

#define EFI_VARIABLE_OP_QUERY        0xdead0001
#define EFI_VARIABLE_OP_QUERY_NEXT   0xdead0002
#define EFI_VARIABLE_OP_QUERY_REWIND 0xdead0003
#define EFI_VARIABLE_OP_ADD          0xdead0010

#define EFI_VARIABLE_OP_STATUS_OK         0xcafe0000
#define EFI_VARIABLE_OP_STATUS_ERROR      0xcafe0001
#define EFI_VARIABLE_OP_STATUS_NOT_FOUND  0xcafe0002
#define EFI_VARIABLE_OP_STATUS_WP         0xcafe0003
#define EFI_VARIABLE_OP_STATUS_BSY        0xcafe0010

/** The max number of variables allowed. */
#define EFI_VARIABLE_MAX            128
/** The max variable name length (in bytes, including the zero terminator). */
#define EFI_VARIABLE_NAME_MAX       1024
/** The max value length (in bytes). */
#define EFI_VARIABLE_VALUE_MAX      1024

typedef enum
{
    EFI_VM_VARIABLE_OP_START = 0,
    EFI_VM_VARIABLE_OP_RESERVED_USED_TO_BE_END,
    EFI_VM_VARIABLE_OP_RESERVED_USED_TO_BE_INDEX,
    EFI_VM_VARIABLE_OP_GUID,
    EFI_VM_VARIABLE_OP_ATTRIBUTE,
    EFI_VM_VARIABLE_OP_NAME,
    EFI_VM_VARIABLE_OP_NAME_LENGTH,
    EFI_VM_VARIABLE_OP_VALUE,
    EFI_VM_VARIABLE_OP_VALUE_LENGTH,
    EFI_VM_VARIABLE_OP_ERROR,
    EFI_VM_VARIABLE_OP_NAME_UTF16,
    EFI_VM_VARIABLE_OP_NAME_LENGTH_UTF16,
    EFI_VM_VARIABLE_OP_MAX,
    EFI_VM_VARIABLE_OP_32BIT_HACK = 0x7fffffff
} EFIVAROP;


/** Debug point. */
#define EFI_PORT_DEBUG_POINT    (EFI_PORT_BASE + 0x6)

/**
 * EFI debug points.
 */
typedef enum EFIDBGPOINT
{
    /** Invalid. */
    EFIDBGPOINT_INVALID = 0,
    /** DEBUG_AGENT_INIT_PREMEM_SEC. */
    EFIDBGPOINT_SEC_PREMEM = 1,
    /** DEBUG_AGENT_INIT_POST_SEC. */
    EFIDBGPOINT_SEC_POSTMEM,
    /** DEBUG_AGENT_INIT_DXE_CORE. */
    EFIDBGPOINT_DXE_CORE,
    /** DEBUG_AGENT_INIT_. */
    EFIDBGPOINT_SMM,
    /** DEBUG_AGENT_INIT_ENTER_SMI. */
    EFIDBGPOINT_SMI_ENTER,
    /** DEBUG_AGENT_INIT_EXIT_SMI. */
    EFIDBGPOINT_SMI_EXIT,
    /** DEBUG_AGENT_INIT_S3. */
    EFIDBGPOINT_GRAPHICS,
    /** DEBUG_AGENT_INIT_DXE_AP. */
    EFIDBGPOINT_DXE_AP,
    /** End of valid points. */
    EFIDBGPOINT_END,
    /** Blow up the type to 32-bits. */
    EFIDBGPOINT_32BIT_HACK = 0x7fffffff
} EFIDBGPOINT;


/** EFI image load or unload event. All writes are 32-bit writes. */
#define EFI_PORT_IMAGE_EVENT    (EFI_PORT_BASE + 0x7)

/** @defgroup grp_devefi_image_evt  EFI Image Events (EFI_PORT_IMAGE_EVENT).
 *
 * The lower 8-bit of the values written to EFI_PORT_IMAGE_EVENT can be seen as
 * the command.  The start and complete commands does not have any additional
 * payload.  The other commands uses bit 8 thru 23 or 8 thru 15 to pass a value.
 *
 * @{ */

/** The command mask. */
#define EFI_IMAGE_EVT_CMD_MASK                  UINT32_C(0x000000ff)
/** Get the payload value. */
#define EFI_IMAGE_EVT_GET_PAYLOAD(a_u32)        ((a_u32) >> 8)
/** Get the payload value as unsigned 16-bit. */
#define EFI_IMAGE_EVT_GET_PAYLOAD_U16(a_u32)    ( EFI_IMAGE_EVT_GET_PAYLOAD(a_u32) & UINT16_MAX )
/** Get the payload value as unsigned 8-bit. */
#define EFI_IMAGE_EVT_GET_PAYLOAD_U8(a_u32)     ( EFI_IMAGE_EVT_GET_PAYLOAD(a_u32) &  UINT8_MAX )
/** Combines a command and a payload value. */
#define EFI_IMAGE_EVT_MAKE(a_uCmd, a_uPayload)  ( ((a_uCmd) & UINT32_C(0xff)) | (uint32_t)((a_uPayload) << 8) )

/** Invalid. */
#define EFI_IMAGE_EVT_CMD_INVALID               UINT32_C(0x00000000)
/** The event is complete. */
#define EFI_IMAGE_EVT_CMD_COMPLETE              UINT32_C(0x00000001)
/** Starts a 32-bit load event.  Requires name and address, size is optional. */
#define EFI_IMAGE_EVT_CMD_START_LOAD32          UINT32_C(0x00000002)
/** Starts a 64-bit load event.  Requires name and address, size is optional. */
#define EFI_IMAGE_EVT_CMD_START_LOAD64          UINT32_C(0x00000003)
/** Starts a 32-bit unload event. Requires name and address. */
#define EFI_IMAGE_EVT_CMD_START_UNLOAD32        UINT32_C(0x00000004)
/** Starts a 64-bit unload event. Requires name and address. */
#define EFI_IMAGE_EVT_CMD_START_UNLOAD64        UINT32_C(0x00000005)
/** Starts a 32-bit relocation event. RRequires new and old base address. */
#define EFI_IMAGE_EVT_CMD_START_RELOC32         UINT32_C(0x0000000A)
/** Starts a 64-bit relocation event. Requires new and old base address. */
#define EFI_IMAGE_EVT_CMD_START_RELOC64         UINT32_C(0x0000000B)

/** The command for writing to the second address register (64-bit).
 * Takes a 16-bit payload value.  The register value is shifted 16-bits
 * to the left and then the payload is ORed in. */
#define EFI_IMAGE_EVT_CMD_ADDR0                 UINT32_C(0x00000006)
/** The command for writing to the second address register (64-bit).
 * Takes a 16-bit payload value.  The register value is shifted 16-bits
 * to the left and then the payload is ORed in. */
#define EFI_IMAGE_EVT_CMD_ADDR1                 UINT32_C(0x00000007)
/** The command for writing to the first size register (64-bit).
 * Takes a 16-bit payload value.  The register value is shifted 16-bits
 * to the left and then the payload is ORed in. */
#define EFI_IMAGE_EVT_CMD_SIZE0                 UINT32_C(0x00000008)
/** The command for appending a character to the module name.
 * Takes a 7-bit payload value that.  The value is appended to the field if
 * there is room. */
#define EFI_IMAGE_EVT_CMD_NAME                  UINT32_C(0x00000009)

/** @} */


/** @} */

#endif /* !VBOX_INCLUDED_SRC_EFI_DevEFI_h */