1 #pragma once
2 #include <efidef.h>
3 #include "compiler_attributes.h"
4 #include "types.h"
5 #include <efiapi.h>
6 #include <efierr.h>
7 #include "linux/pfn.h"
8 #if defined(CONFIG_riscv64)
9 #include "riscv64.h"
10 #endif
11
12 #define efi_table_hdr_t EFI_TABLE_HEADER
13 #define efi_guid_t EFI_GUID
14 #define efi_runtime_services_t EFI_RUNTIME_SERVICES
15 #define efi_boot_services_t EFI_BOOT_SERVICES
16 #define efi_memory_desc_t EFI_MEMORY_DESCRIPTOR
17 #define efi_capsule_header_t EFI_CAPSULE_HEADER
18 #define efi_time_t EFI_TIME
19 #define efi_time_cap_t EFI_TIME_CAPABILITIES
20
21 #define MAKE_EFI_GUID(a, b, c, d...) \
22 (efi_guid_t) \
23 { \
24 a, b & 0xffff, c & 0xffff, \
25 { \
26 d \
27 } \
28 }
29
30 /*
31 * EFI Configuration Table and GUID definitions
32 *
33 * These are all defined in a single line to make them easier to
34 * grep for and to see them at a glance - while still having a
35 * similar structure to the definitions in the spec.
36 *
37 * Here's how they are structured:
38 *
39 * GUID: 12345678-1234-1234-1234-123456789012
40 * Spec:
41 * #define EFI_SOME_PROTOCOL_GUID \
42 * {0x12345678,0x1234,0x1234,\
43 * {0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x12}}
44 * Here:
45 * #define SOME_PROTOCOL_GUID EFI_GUID(0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12)
46 * ^ tabs ^extra space
47 *
48 * Note that the 'extra space' separates the values at the same place
49 * where the UEFI SPEC breaks the line.
50 */
51 #define NULL_GUID \
52 MAKE_EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, \
53 0x00, 0x00, 0x00, 0x00)
54 #ifndef MPS_TABLE_GUID
55 #define MPS_TABLE_GUID \
56 MAKE_EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, \
57 0x27, 0x3f, 0xc1, 0x4d)
58 #endif
59 #ifndef ACPI_TABLE_GUID
60 #define ACPI_TABLE_GUID \
61 MAKE_EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, \
62 0x27, 0x3f, 0xc1, 0x4d)
63 #endif
64 #ifndef ACPI_20_TABLE_GUID
65 #define ACPI_20_TABLE_GUID \
66 MAKE_EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x00, 0x80, \
67 0xc7, 0x3c, 0x88, 0x81)
68 #endif
69 #ifndef SMBIOS_TABLE_GUID
70 #define SMBIOS_TABLE_GUID \
71 MAKE_EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, \
72 0x27, 0x3f, 0xc1, 0x4d)
73 #endif
74 #ifndef SMBIOS3_TABLE_GUID
75 #define SMBIOS3_TABLE_GUID \
76 MAKE_EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, \
77 0xcf, 0x20, 0xe3, 0x94)
78 #endif
79 #ifndef SAL_SYSTEM_TABLE_GUID
80 #define SAL_SYSTEM_TABLE_GUID \
81 MAKE_EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, \
82 0x27, 0x3f, 0xc1, 0x4d)
83 #endif
84 #define HCDP_TABLE_GUID \
85 MAKE_EFI_GUID(0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, \
86 0x79, 0x61, 0x78, 0x98)
87 #define UGA_IO_PROTOCOL_GUID \
88 MAKE_EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, \
89 0xed, 0x0b, 0x07, 0xa2)
90 #define EFI_GLOBAL_VARIABLE_GUID \
91 MAKE_EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, \
92 0x98, 0x03, 0x2b, 0x8c)
93 #define UV_SYSTEM_TABLE_GUID \
94 MAKE_EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, \
95 0x56, 0xd8, 0x95, 0x93)
96 #define LINUX_EFI_CRASH_GUID \
97 MAKE_EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, \
98 0xbf, 0xe2, 0x98, 0xa0)
99 #define LOADED_IMAGE_PROTOCOL_GUID \
100 MAKE_EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, \
101 0xc9, 0x69, 0x72, 0x3b)
102 #define LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID \
103 MAKE_EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, 0x99, 0x20, 0x2d, 0x3b, \
104 0x36, 0xd7, 0x50, 0xdf)
105 #ifndef EFI_DEVICE_PATH_PROTOCOL_GUID
106 #define EFI_DEVICE_PATH_PROTOCOL_GUID \
107 MAKE_EFI_GUID(0x09576e91, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, \
108 0xc9, 0x69, 0x72, 0x3b)
109 #endif
110 #ifndef EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID
111 #define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
112 MAKE_EFI_GUID(0x8b843e20, 0x8132, 0x4852, 0x90, 0xcc, 0x55, 0x1a, \
113 0x4e, 0x4a, 0x7f, 0x1c)
114 #endif
115 #ifndef EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID
116 #define EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID \
117 MAKE_EFI_GUID(0x05c99a21, 0xc70f, 0x4ad2, 0x8a, 0x5f, 0x35, 0xdf, \
118 0x33, 0x43, 0xf5, 0x1e)
119 #endif
120 #ifndef EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
121 #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
122 MAKE_EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, \
123 0xd0, 0x80, 0x51, 0x6a)
124 #endif
125 #define EFI_UGA_PROTOCOL_GUID \
126 MAKE_EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, \
127 0x68, 0x8f, 0xb8, 0x39)
128 #ifndef EFI_PCI_IO_PROTOCOL_GUID
129 #define EFI_PCI_IO_PROTOCOL_GUID \
130 MAKE_EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, \
131 0x3f, 0x50, 0x02, 0x9a)
132 #endif
133 #ifndef EFI_FILE_INFO_ID
134 #define EFI_FILE_INFO_ID \
135 MAKE_EFI_GUID(0x09576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, \
136 0xc9, 0x69, 0x72, 0x3b)
137 #endif
138 #define EFI_SYSTEM_RESOURCE_TABLE_GUID \
139 MAKE_EFI_GUID(0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, \
140 0xb0, 0xd6, 0x21, 0x80)
141 #define EFI_FILE_SYSTEM_GUID \
142 MAKE_EFI_GUID(0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, \
143 0xc9, 0x69, 0x72, 0x3b)
144 #define DEVICE_TREE_GUID \
145 MAKE_EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, \
146 0x2c, 0x69, 0xaa, 0xe0)
147 #define EFI_PROPERTIES_TABLE_GUID \
148 MAKE_EFI_GUID(0x880aaca3, 0x4adc, 0x4a04, 0x90, 0x79, 0xb7, 0x47, \
149 0x34, 0x08, 0x25, 0xe5)
150 #ifndef EFI_RNG_PROTOCOL_GUID
151 #define EFI_RNG_PROTOCOL_GUID \
152 MAKE_EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, 0xc0, 0x1c, \
153 0xdc, 0x29, 0x1f, 0x44)
154 #endif
155 #ifndef EFI_RNG_ALGORITHM_RAW
156 #define EFI_RNG_ALGORITHM_RAW \
157 MAKE_EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, 0x7f, 0xfd, \
158 0xc4, 0xb6, 0x85, 0x61)
159 #endif
160 #define EFI_MEMORY_ATTRIBUTES_TABLE_GUID \
161 MAKE_EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, \
162 0xdc, 0x46, 0x12, 0x20)
163 #define EFI_CONSOLE_OUT_DEVICE_GUID \
164 MAKE_EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, \
165 0x27, 0x3f, 0xc1, 0x4d)
166 #define APPLE_PROPERTIES_PROTOCOL_GUID \
167 MAKE_EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, \
168 0xab, 0x30, 0x3a, 0xe0)
169 #define EFI_TCG2_PROTOCOL_GUID \
170 MAKE_EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, \
171 0x6d, 0xb2, 0x72, 0x0f)
172 #ifndef EFI_LOAD_FILE_PROTOCOL_GUID
173 #define EFI_LOAD_FILE_PROTOCOL_GUID \
174 MAKE_EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, \
175 0xc9, 0x69, 0x72, 0x3b)
176 #endif
177 #define EFI_LOAD_FILE2_PROTOCOL_GUID \
178 MAKE_EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, \
179 0x87, 0x24, 0xe0, 0x6d)
180 #define EFI_RT_PROPERTIES_TABLE_GUID \
181 MAKE_EFI_GUID(0xeb66918a, 0x7eef, 0x402a, 0x84, 0x2e, 0x93, 0x1d, \
182 0x21, 0xc3, 0x8a, 0xe9)
183 #define EFI_DXE_SERVICES_TABLE_GUID \
184 MAKE_EFI_GUID(0x05ad34ba, 0x6f02, 0x4214, 0x95, 0x2e, 0x4d, 0xa0, \
185 0x39, 0x8e, 0x2b, 0xb9)
186 #define EFI_SMBIOS_PROTOCOL_GUID \
187 MAKE_EFI_GUID(0x03583ff6, 0xcb36, 0x4940, 0x94, 0x7e, 0xb9, 0xb3, \
188 0x9f, 0x4a, 0xfa, 0xf7)
189 #define EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID \
190 MAKE_EFI_GUID(0xf4560cf6, 0x40ec, 0x4b4a, 0xa1, 0x92, 0xbf, 0x1d, \
191 0x57, 0xd0, 0xb1, 0x89)
192
193 #define EFI_IMAGE_SECURITY_DATABASE_GUID \
194 MAKE_EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, \
195 0x0e, 0x67, 0x65, 0x6f)
196 #define EFI_SHIM_LOCK_GUID \
197 MAKE_EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, \
198 0x10, 0xdd, 0x8b, 0x23)
199
200 #define EFI_CERT_SHA256_GUID \
201 MAKE_EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, 0x41, 0xf9, \
202 0x36, 0x93, 0x43, 0x28)
203 #define EFI_CERT_X509_GUID \
204 MAKE_EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, 0xab, 0x15, \
205 0x5c, 0x2b, 0xf0, 0x72)
206 #define EFI_CERT_X509_SHA256_GUID \
207 MAKE_EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, 0xfc, 0xf9, \
208 0x8e, 0xf1, 0x03, 0xed)
209 #define EFI_CC_BLOB_GUID \
210 MAKE_EFI_GUID(0x067b1f5f, 0xcf26, 0x44c5, 0x85, 0x54, 0x93, 0xd7, \
211 0x77, 0x91, 0x2d, 0x42)
212
213 /*
214 * This GUID is used to pass to the kernel proper the struct screen_info
215 * structure that was populated by the stub based on the GOP protocol instance
216 * associated with ConOut
217 */
218 #define LINUX_EFI_SCREEN_INFO_TABLE_GUID \
219 MAKE_EFI_GUID(0xe03fc20a, 0x85dc, 0x406e, 0xb9, 0x0e, 0x4a, 0xb5, \
220 0x02, 0x37, 0x1d, 0x95)
221 #define LINUX_EFI_ARM_CPU_STATE_TABLE_GUID \
222 MAKE_EFI_GUID(0xef79e4aa, 0x3c3d, 0x4989, 0xb9, 0x02, 0x07, 0xa9, \
223 0x43, 0xe5, 0x50, 0xd2)
224 #define LINUX_EFI_LOADER_ENTRY_GUID \
225 MAKE_EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, \
226 0x29, 0xbb, 0x8c, 0x4f)
227 #define LINUX_EFI_RANDOM_SEED_TABLE_GUID \
228 MAKE_EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, \
229 0xf1, 0x80, 0xf5, 0x7b)
230 #define LINUX_EFI_TPM_EVENT_LOG_GUID \
231 MAKE_EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, \
232 0x07, 0xb7, 0x47, 0xfa)
233 #define LINUX_EFI_TPM_FINAL_LOG_GUID \
234 MAKE_EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, \
235 0xbe, 0xf8, 0x23, 0x25)
236 #define LINUX_EFI_MEMRESERVE_TABLE_GUID \
237 MAKE_EFI_GUID(0x888eb0c6, 0x8ede, 0x4ff5, 0xa8, 0xf0, 0x9a, 0xee, \
238 0x5c, 0xb9, 0x77, 0xc2)
239 #define LINUX_EFI_INITRD_MEDIA_GUID \
240 MAKE_EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, 0xca, 0x55, \
241 0x52, 0x31, 0xcc, 0x68)
242 #define LINUX_EFI_MOK_VARIABLE_TABLE_GUID \
243 MAKE_EFI_GUID(0xc451ed2b, 0x9694, 0x45d3, 0xba, 0xba, 0xed, 0x9f, \
244 0x89, 0x88, 0xa3, 0x89)
245 #define LINUX_EFI_COCO_SECRET_AREA_GUID \
246 MAKE_EFI_GUID(0xadf956ad, 0xe98c, 0x484c, 0xae, 0x11, 0xb5, 0x1c, \
247 0x7d, 0x33, 0x64, 0x47)
248 #define LINUX_EFI_BOOT_MEMMAP_GUID \
249 MAKE_EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, 0x96, 0x5c, \
250 0x3c, 0x6f, 0xe2, 0xb4)
251 #define LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID \
252 MAKE_EFI_GUID(0xd5d1de3c, 0x105c, 0x44f9, 0x9e, 0xa9, 0xbc, 0xef, \
253 0x98, 0x12, 0x00, 0x31)
254 #define RISCV_EFI_BOOT_PROTOCOL_GUID \
255 MAKE_EFI_GUID(0xccd15fec, 0x6f73, 0x4eec, 0x83, 0x95, 0x3e, 0x69, \
256 0xe4, 0xb9, 0x40, 0xbf)
257
258 #if defined(CONFIG_X86_64)
259 #define __efiapi __attribute__((ms_abi))
260 #elif defined(CONFIG_X86_32)
261 #define __efiapi __attribute__((regparm(0)))
262 #elif defined(CONFIG_riscv64)
263 #define __efiapi
264 #elif defined(CONFIG_aarch64)
265 #define __efiapi
266 #else
267 #error "Unsupported architecture"
268 #endif
269
270 /*
271 * EFI Device Path information
272 */
273 #define EFI_DEV_HW 0x01
274 #define EFI_DEV_PCI 1
275 #define EFI_DEV_PCCARD 2
276 #define EFI_DEV_MEM_MAPPED 3
277 #define EFI_DEV_VENDOR 4
278 #define EFI_DEV_CONTROLLER 5
279 #define EFI_DEV_ACPI 0x02
280 #define EFI_DEV_BASIC_ACPI 1
281 #define EFI_DEV_EXPANDED_ACPI 2
282 #define EFI_DEV_MSG 0x03
283 #define EFI_DEV_MSG_ATAPI 1
284 #define EFI_DEV_MSG_SCSI 2
285 #define EFI_DEV_MSG_FC 3
286 #define EFI_DEV_MSG_1394 4
287 #define EFI_DEV_MSG_USB 5
288 #define EFI_DEV_MSG_USB_CLASS 15
289 #define EFI_DEV_MSG_I20 6
290 #define EFI_DEV_MSG_MAC 11
291 #define EFI_DEV_MSG_IPV4 12
292 #define EFI_DEV_MSG_IPV6 13
293 #define EFI_DEV_MSG_INFINIBAND 9
294 #define EFI_DEV_MSG_UART 14
295 #define EFI_DEV_MSG_VENDOR 10
296 #define EFI_DEV_MEDIA 0x04
297 #define EFI_DEV_MEDIA_HARD_DRIVE 1
298 #define EFI_DEV_MEDIA_CDROM 2
299 #define EFI_DEV_MEDIA_VENDOR 3
300 #define EFI_DEV_MEDIA_FILE 4
301 #define EFI_DEV_MEDIA_PROTOCOL 5
302 #define EFI_DEV_MEDIA_REL_OFFSET 8
303 #define EFI_DEV_BIOS_BOOT 0x05
304 #define EFI_DEV_END_PATH 0x7F
305 #define EFI_DEV_END_PATH2 0xFF
306 #define EFI_DEV_END_INSTANCE 0x01
307 #define EFI_DEV_END_ENTIRE 0xFF
308
309 struct efi_generic_dev_path {
310 u8 type;
311 u8 sub_type;
312 u16 length;
313 } __packed;
314
315 struct efi_acpi_dev_path {
316 struct efi_generic_dev_path header;
317 u32 hid;
318 u32 uid;
319 } __packed;
320
321 struct efi_pci_dev_path {
322 struct efi_generic_dev_path header;
323 u8 fn;
324 u8 dev;
325 } __packed;
326
327 struct efi_vendor_dev_path {
328 struct efi_generic_dev_path header;
329 efi_guid_t vendorguid;
330 u8 vendordata[];
331 } __packed;
332
333 struct efi_rel_offset_dev_path {
334 struct efi_generic_dev_path header;
335 u32 reserved;
336 u64 starting_offset;
337 u64 ending_offset;
338 } __packed;
339
340 struct efi_mem_mapped_dev_path {
341 struct efi_generic_dev_path header;
342 u32 memory_type;
343 u64 starting_addr;
344 u64 ending_addr;
345 } __packed;
346
347 struct efi_file_path_dev_path {
348 struct efi_generic_dev_path header;
349 efi_char16_t filename[];
350 } __packed;
351
352 struct efi_dev_path {
353 union {
354 struct efi_generic_dev_path header;
355 struct efi_acpi_dev_path acpi;
356 struct efi_pci_dev_path pci;
357 struct efi_vendor_dev_path vendor;
358 struct efi_rel_offset_dev_path rel_offset;
359 };
360 } __packed;
361
362 // struct device *efi_get_device_by_path(const struct efi_dev_path **node,
363 // size_t *len);
364
memrange_efi_to_native(u64 * addr,u64 * npages)365 static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
366 {
367 *npages = PFN_UP(*addr + (*npages << EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
368 *addr &= PAGE_MASK;
369 }
370
371 struct linux_efi_memreserve {
372 int size; // allocated size of the array
373 int count; // number of entries used
374 phys_addr_t next; // pa of next struct instance
375 struct {
376 phys_addr_t base;
377 phys_addr_t size;
378 } entry[];
379 };
380
381 #define EFI_MEMRESERVE_COUNT(size) \
382 (((size) - sizeof(struct linux_efi_memreserve)) / \
383 sizeof_field(struct linux_efi_memreserve, entry[0]))
384
385 enum efi_secureboot_mode {
386 efi_secureboot_mode_unset,
387 efi_secureboot_mode_unknown,
388 efi_secureboot_mode_disabled,
389 efi_secureboot_mode_enabled,
390 };
391
392 /// @brief 打印efi_secureboot_mode
393 void print_efi_secureboot_mode(enum efi_secureboot_mode mode);
394
395 typedef efi_status_t efi_get_time_t(efi_time_t *tm, efi_time_cap_t *tc);
396 typedef efi_status_t efi_set_time_t(efi_time_t *tm);
397 typedef efi_status_t efi_get_wakeup_time_t(efi_bool_t *enabled,
398 efi_bool_t *pending, efi_time_t *tm);
399 typedef efi_status_t efi_set_wakeup_time_t(efi_bool_t enabled, efi_time_t *tm);
400 typedef efi_status_t efi_get_variable_t(efi_char16_t *name, efi_guid_t *vendor,
401 u32 *attr, unsigned long *data_size,
402 void *data);
403 typedef efi_status_t efi_get_next_variable_t(unsigned long *name_size,
404 efi_char16_t *name,
405 efi_guid_t *vendor);
406 typedef efi_status_t efi_set_variable_t(efi_char16_t *name, efi_guid_t *vendor,
407 u32 attr, unsigned long data_size,
408 void *data);
409 typedef efi_status_t efi_get_next_high_mono_count_t(u32 *count);
410 typedef void efi_reset_system_t(int reset_type, efi_status_t status,
411 unsigned long data_size, efi_char16_t *data);
412 typedef efi_status_t efi_set_virtual_address_map_t(
413 unsigned long memory_map_size, unsigned long descriptor_size,
414 u32 descriptor_version, efi_memory_desc_t *virtual_map);
415 typedef efi_status_t efi_query_variable_info_t(u32 attr, u64 *storage_space,
416 u64 *remaining_space,
417 u64 *max_variable_size);
418 typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
419 unsigned long count,
420 unsigned long sg_list);
421 typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
422 unsigned long count,
423 u64 *max_size, int *reset_type);
424 typedef efi_status_t efi_query_variable_store_t(u32 attributes,
425 unsigned long size,
426 bool nonblocking);
427
428 static inline enum efi_secureboot_mode
efi_get_secureboot_mode(efi_get_variable_t * get_var)429 efi_get_secureboot_mode(efi_get_variable_t *get_var)
430 {
431 u8 secboot, setupmode = 0;
432 efi_status_t status;
433 unsigned long size;
434
435 size = sizeof(secboot);
436 status = get_var(L"SecureBoot", &EFI_GLOBAL_VARIABLE_GUID, NULL, &size,
437 &secboot);
438 if (status == EFI_NOT_FOUND)
439 return efi_secureboot_mode_disabled;
440 if (status != EFI_SUCCESS)
441 return efi_secureboot_mode_unknown;
442
443 size = sizeof(setupmode);
444 get_var(L"SetupMode", &EFI_GLOBAL_VARIABLE_GUID, NULL, &size,
445 &setupmode);
446 if (secboot == 0 || setupmode == 1)
447 return efi_secureboot_mode_disabled;
448 return efi_secureboot_mode_enabled;
449 }
450
451 struct efi_boot_memmap {
452 unsigned long map_size;
453 unsigned long desc_size;
454 u32 desc_ver;
455 unsigned long map_key;
456 unsigned long buff_size;
457 efi_memory_desc_t map[];
458 };
459
460 #define EFI_RT_SUPPORTED_GET_TIME 0x0001
461 #define EFI_RT_SUPPORTED_SET_TIME 0x0002
462 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004
463 #define EFI_RT_SUPPORTED_SET_WAKEUP_TIME 0x0008
464 #define EFI_RT_SUPPORTED_GET_VARIABLE 0x0010
465 #define EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME 0x0020
466 #define EFI_RT_SUPPORTED_SET_VARIABLE 0x0040
467 #define EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP 0x0080
468 #define EFI_RT_SUPPORTED_CONVERT_POINTER 0x0100
469 #define EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT 0x0200
470 #define EFI_RT_SUPPORTED_RESET_SYSTEM 0x0400
471 #define EFI_RT_SUPPORTED_UPDATE_CAPSULE 0x0800
472 #define EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES 0x1000
473 #define EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO 0x2000
474
475 #define EFI_RT_SUPPORTED_ALL 0x3fff
476
477 #define EFI_RT_SUPPORTED_TIME_SERVICES 0x0003
478 #define EFI_RT_SUPPORTED_WAKEUP_SERVICES 0x000c
479 #define EFI_RT_SUPPORTED_VARIABLE_SERVICES 0x0070
480
481 typedef struct {
482 u32 version;
483 u32 length;
484 u64 memory_protection_attribute;
485 } efi_properties_table_t;
486
487 #define EFI_PROPERTIES_TABLE_VERSION 0x00010000
488 #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA 0x1
489
490 typedef struct {
491 u16 version;
492 u16 length;
493 u32 runtime_services_supported;
494 } efi_rt_properties_table_t;
495
496 #define EFI_RT_PROPERTIES_TABLE_VERSION 0x1
497
498 #define EFI_INVALID_TABLE_ADDR (~0UL)
499
500 // BIT0 implies that Runtime code includes the forward control flow guard
501 // instruction, such as X86 CET-IBT or ARM BTI.
502 #define EFI_MEMORY_ATTRIBUTES_FLAGS_RT_FORWARD_CONTROL_FLOW_GUARD 0x1
503