1 /*
2 * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3 * Licensed under the Mulan PSL v2.
4 * You can use this software according to the terms and conditions of the Mulan PSL v2.
5 * You may obtain a copy of Mulan PSL v2 at:
6 * http://license.coscl.org.cn/MulanPSL2
7 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9 * PURPOSE.
10 * See the Mulan PSL v2 for more details.
11 */
12
13 #ifndef LIB_EFI_H
14 #define LIB_EFI_H
15
16 #include "image.h"
17 #include "boot.h"
18
19 /*
20 * Extensible Firmware Interface
21 * Based on 'Extensible Firmware Interface Specification' version 0.9, April 30, 1999
22 *
23 * Copyright (C) 1999 VA Linux Systems
24 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
25 * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
26 * David Mosberger-Tang <davidm@hpl.hp.com>
27 * Stephane Eranian <eranian@hpl.hp.com>
28 */
29 /* Directly pass the memory map to the kernel */
30 #define EFI_MEMMAP_SIZE 128
31
32 #define BITS_PER_LONG 64
33 #define EFI_SUCCESS 0
34 #define EFI_LOAD_ERROR (1 | (1UL << (BITS_PER_LONG - 1)))
35 #define EFI_INVALID_PARAMETER (2 | (1UL << (BITS_PER_LONG - 1)))
36 #define EFI_UNSUPPORTED (3 | (1UL << (BITS_PER_LONG - 1)))
37 #define EFI_BAD_BUFFER_SIZE (4 | (1UL << (BITS_PER_LONG - 1)))
38 #define EFI_BUFFER_TOO_SMALL (5 | (1UL << (BITS_PER_LONG - 1)))
39 #define EFI_NOT_READY (6 | (1UL << (BITS_PER_LONG - 1)))
40 #define EFI_DEVICE_ERROR (7 | (1UL << (BITS_PER_LONG - 1)))
41 #define EFI_WRITE_PROTECTED (8 | (1UL << (BITS_PER_LONG - 1)))
42 #define EFI_OUT_OF_RESOURCES (9 | (1UL << (BITS_PER_LONG - 1)))
43 #define EFI_NOT_FOUND (14 | (1UL << (BITS_PER_LONG - 1)))
44 #define EFI_ABORTED (21 | (1UL << (BITS_PER_LONG - 1)))
45 #define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG - 1)))
46
47 #define EFI_RT_VIRTUAL_BASE SZ_512M
48 #define EFI_ALLOC_ALIGN SZ_64K
49
50 #define efi_call_early(f, ...) efi_sys_table->boottime->f(__VA_ARGS__)
51 #define EFI_MMAP_NR_SLACK_SLOTS 8
52 #define MIN_KIMG_ALIGN SZ_2M
53
54 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
55 #define round_up(x, y) ((((x)-1) | __round_mask(x, y)) + 1)
56 #define round_down(x, y) ((x) & ~__round_mask(x, y))
57
58 typedef unsigned long u64;
59 typedef char bool;
60 #define true 1
61 #define false 0
62 typedef unsigned int u32;
63 typedef unsigned char u8;
64 typedef unsigned short u16;
65 typedef short s16;
66 #define __aligned_u64 u64 __attribute__((aligned(8)))
67 #define __packed __attribute__((packed))
68
69 typedef unsigned long efi_status_t;
70 typedef unsigned char efi_bool_t;
71 typedef unsigned short efi_char16_t; /* UNICODE character */
72 typedef unsigned long efi_physical_addr_t;
73 typedef void *efi_handle_t;
74
75 typedef struct {
76 unsigned char b[16];
77 } guid_t;
78 typedef guid_t uuid_le;
79 typedef uuid_le efi_guid_t;
80
81 #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
82 UUID_LE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
83
84 /*
85 * Generic EFI table header
86 */
87 typedef struct {
88 u64 signature;
89 u32 revision;
90 u32 headersize;
91 u32 crc32;
92 u32 reserved;
93 } efi_table_hdr_t;
94
95 /*
96 * Memory map descriptor:
97 */
98
99 /* Memory types: */
100 #define EFI_RESERVED_TYPE 0
101 #define EFI_LOADER_CODE 1
102 #define EFI_LOADER_DATA 2
103 #define EFI_BOOT_SERVICES_CODE 3
104 #define EFI_BOOT_SERVICES_DATA 4
105 #define EFI_RUNTIME_SERVICES_CODE 5
106 #define EFI_RUNTIME_SERVICES_DATA 6
107 #define EFI_CONVENTIONAL_MEMORY 7
108 #define EFI_UNUSABLE_MEMORY 8
109 #define EFI_ACPI_RECLAIM_MEMORY 9
110 #define EFI_ACPI_MEMORY_NVS 10
111 #define EFI_MEMORY_MAPPED_IO 11
112 #define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12
113 #define EFI_PAL_CODE 13
114 #define EFI_PERSISTENT_MEMORY 14
115 #define EFI_MAX_MEMORY_TYPE 15
116
117 /* Attribute values: */
118 #define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */
119 #define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */
120 #define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */
121 #define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */
122 #define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */
123 #define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */
124 #define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */
125 #define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */
126 #define EFI_MEMORY_NV ((u64)0x0000000000008000ULL) /* non-volatile */
127 #define EFI_MEMORY_MORE_RELIABLE \
128 ((u64)0x0000000000010000ULL) /* higher reliability */
129 #define EFI_MEMORY_RO ((u64)0x0000000000020000ULL) /* read-only */
130 #define EFI_MEMORY_RUNTIME \
131 ((u64)0x8000000000000000ULL) /* range requires runtime mapping */
132 #define EFI_MEMORY_DESCRIPTOR_VERSION 1
133
134 #define EFI_PAGE_SHIFT 12
135 #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
136 #define EFI_PAGES_MAX (U64_MAX >> EFI_PAGE_SHIFT)
137
138 typedef struct {
139 u32 type;
140 u32 pad;
141 u64 phys_addr;
142 u64 virt_addr;
143 u64 num_pages;
144 u64 attribute;
145 } efi_memory_desc_t;
146
147 typedef struct {
148 efi_guid_t guid;
149 u32 headersize;
150 u32 flags;
151 u32 imagesize;
152 } efi_capsule_header_t;
153
154 struct efi_boot_memmap {
155 efi_memory_desc_t **map;
156 unsigned long *map_size;
157 unsigned long *desc_size;
158 u32 *desc_ver;
159 unsigned long *key_ptr;
160 unsigned long *buff_size;
161 };
162
163 /*
164 * EFI capsule flags
165 */
166 #define EFI_CAPSULE_PERSIST_ACROSS_RESET 0x00010000
167 #define EFI_CAPSULE_POPULATE_SYSTEM_TABLE 0x00020000
168 #define EFI_CAPSULE_INITIATE_RESET 0x00040000
169
170 /*
171 * Allocation types for calls to boottime->allocate_pages.
172 */
173 #define EFI_ALLOCATE_ANY_PAGES 0
174 #define EFI_ALLOCATE_MAX_ADDRESS 1
175 #define EFI_ALLOCATE_ADDRESS 2
176 #define EFI_MAX_ALLOCATE_TYPE 3
177
178 typedef int (*efi_freemem_callback_t)(u64 start, u64 end, void *arg);
179
180 /*
181 * Types and defines for Time Services
182 */
183 #define EFI_TIME_ADJUST_DAYLIGHT 0x1
184 #define EFI_TIME_IN_DAYLIGHT 0x2
185 #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
186
187 typedef struct {
188 u16 year;
189 u8 month;
190 u8 day;
191 u8 hour;
192 u8 minute;
193 u8 second;
194 u8 pad1;
195 u32 nanosecond;
196 s16 timezone;
197 u8 daylight;
198 u8 pad2;
199 } efi_time_t;
200
201 typedef struct {
202 u32 resolution;
203 u32 accuracy;
204 u8 sets_to_zero;
205 } efi_time_cap_t;
206
207 typedef struct {
208 efi_table_hdr_t hdr;
209 u32 raise_tpl;
210 u32 restore_tpl;
211 u32 allocate_pages;
212 u32 free_pages;
213 u32 get_memory_map;
214 u32 allocate_pool;
215 u32 free_pool;
216 u32 create_event;
217 u32 set_timer;
218 u32 wait_for_event;
219 u32 signal_event;
220 u32 close_event;
221 u32 check_event;
222 u32 install_protocol_interface;
223 u32 reinstall_protocol_interface;
224 u32 uninstall_protocol_interface;
225 u32 handle_protocol;
226 u32 __reserved;
227 u32 register_protocol_notify;
228 u32 locate_handle;
229 u32 locate_device_path;
230 u32 install_configuration_table;
231 u32 load_image;
232 u32 start_image;
233 u32 exit;
234 u32 unload_image;
235 u32 exit_boot_services;
236 u32 get_next_monotonic_count;
237 u32 stall;
238 u32 set_watchdog_timer;
239 u32 connect_controller;
240 u32 disconnect_controller;
241 u32 open_protocol;
242 u32 close_protocol;
243 u32 open_protocol_information;
244 u32 protocols_per_handle;
245 u32 locate_handle_buffer;
246 u32 locate_protocol;
247 u32 install_multiple_protocol_interfaces;
248 u32 uninstall_multiple_protocol_interfaces;
249 u32 calculate_crc32;
250 u32 copy_mem;
251 u32 set_mem;
252 u32 create_event_ex;
253 } __packed efi_boot_services_32_t;
254
255 typedef struct {
256 efi_table_hdr_t hdr;
257 u64 raise_tpl;
258 u64 restore_tpl;
259 u64 allocate_pages;
260 u64 free_pages;
261 u64 get_memory_map;
262 u64 allocate_pool;
263 u64 free_pool;
264 u64 create_event;
265 u64 set_timer;
266 u64 wait_for_event;
267 u64 signal_event;
268 u64 close_event;
269 u64 check_event;
270 u64 install_protocol_interface;
271 u64 reinstall_protocol_interface;
272 u64 uninstall_protocol_interface;
273 u64 handle_protocol;
274 u64 __reserved;
275 u64 register_protocol_notify;
276 u64 locate_handle;
277 u64 locate_device_path;
278 u64 install_configuration_table;
279 u64 load_image;
280 u64 start_image;
281 u64 exit;
282 u64 unload_image;
283 u64 exit_boot_services;
284 u64 get_next_monotonic_count;
285 u64 stall;
286 u64 set_watchdog_timer;
287 u64 connect_controller;
288 u64 disconnect_controller;
289 u64 open_protocol;
290 u64 close_protocol;
291 u64 open_protocol_information;
292 u64 protocols_per_handle;
293 u64 locate_handle_buffer;
294 u64 locate_protocol;
295 u64 install_multiple_protocol_interfaces;
296 u64 uninstall_multiple_protocol_interfaces;
297 u64 calculate_crc32;
298 u64 copy_mem;
299 u64 set_mem;
300 u64 create_event_ex;
301 } __packed efi_boot_services_64_t;
302
303 /*
304 * EFI Boot Services table
305 */
306 typedef struct {
307 efi_table_hdr_t hdr;
308 void *raise_tpl;
309 void *restore_tpl;
310 efi_status_t (*allocate_pages)(int, int, unsigned long,
311 efi_physical_addr_t *);
312 efi_status_t (*free_pages)(efi_physical_addr_t, unsigned long);
313 efi_status_t (*get_memory_map)(unsigned long *, void *, unsigned long *,
314 unsigned long *, u32 *);
315 efi_status_t (*allocate_pool)(int, unsigned long, void **);
316 efi_status_t (*free_pool)(void *);
317 void *create_event;
318 void *set_timer;
319 void *wait_for_event;
320 void *signal_event;
321 void *close_event;
322 void *check_event;
323 void *install_protocol_interface;
324 void *reinstall_protocol_interface;
325 void *uninstall_protocol_interface;
326 efi_status_t (*handle_protocol)(efi_handle_t, efi_guid_t *, void **);
327 void *__reserved;
328 void *register_protocol_notify;
329 efi_status_t (*locate_handle)(int, efi_guid_t *, void *, unsigned long *,
330 efi_handle_t *);
331 void *locate_device_path;
332 efi_status_t (*install_configuration_table)(efi_guid_t *, void *);
333 void *load_image;
334 void *start_image;
335 void *exit;
336 void *unload_image;
337 efi_status_t (*exit_boot_services)(efi_handle_t, unsigned long);
338 void *get_next_monotonic_count;
339 void *stall;
340 void *set_watchdog_timer;
341 void *connect_controller;
342 void *disconnect_controller;
343 void *open_protocol;
344 void *close_protocol;
345 void *open_protocol_information;
346 void *protocols_per_handle;
347 void *locate_handle_buffer;
348 efi_status_t (*locate_protocol)(efi_guid_t *, void *, void **);
349 void *install_multiple_protocol_interfaces;
350 void *uninstall_multiple_protocol_interfaces;
351 void *calculate_crc32;
352 void *copy_mem;
353 void *set_mem;
354 void *create_event_ex;
355 } efi_boot_services_t;
356
357 typedef enum {
358 EfiPciIoWidthUint8,
359 EfiPciIoWidthUint16,
360 EfiPciIoWidthUint32,
361 EfiPciIoWidthUint64,
362 EfiPciIoWidthFifoUint8,
363 EfiPciIoWidthFifoUint16,
364 EfiPciIoWidthFifoUint32,
365 EfiPciIoWidthFifoUint64,
366 EfiPciIoWidthFillUint8,
367 EfiPciIoWidthFillUint16,
368 EfiPciIoWidthFillUint32,
369 EfiPciIoWidthFillUint64,
370 EfiPciIoWidthMaximum
371 } EFI_PCI_IO_PROTOCOL_WIDTH;
372
373 typedef enum {
374 EfiPciIoAttributeOperationGet,
375 EfiPciIoAttributeOperationSet,
376 EfiPciIoAttributeOperationEnable,
377 EfiPciIoAttributeOperationDisable,
378 EfiPciIoAttributeOperationSupported,
379 EfiPciIoAttributeOperationMaximum
380 } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
381
382 typedef struct {
383 u32 read;
384 u32 write;
385 } efi_pci_io_protocol_access_32_t;
386
387 typedef struct {
388 u64 read;
389 u64 write;
390 } efi_pci_io_protocol_access_64_t;
391
392 typedef struct {
393 void *read;
394 void *write;
395 } efi_pci_io_protocol_access_t;
396
397 typedef struct {
398 u32 poll_mem;
399 u32 poll_io;
400 efi_pci_io_protocol_access_32_t mem;
401 efi_pci_io_protocol_access_32_t io;
402 efi_pci_io_protocol_access_32_t pci;
403 u32 copy_mem;
404 u32 map;
405 u32 unmap;
406 u32 allocate_buffer;
407 u32 free_buffer;
408 u32 flush;
409 u32 get_location;
410 u32 attributes;
411 u32 get_bar_attributes;
412 u32 set_bar_attributes;
413 u64 romsize;
414 void *romimage;
415 } efi_pci_io_protocol_32;
416
417 typedef struct {
418 u64 poll_mem;
419 u64 poll_io;
420 efi_pci_io_protocol_access_64_t mem;
421 efi_pci_io_protocol_access_64_t io;
422 efi_pci_io_protocol_access_64_t pci;
423 u64 copy_mem;
424 u64 map;
425 u64 unmap;
426 u64 allocate_buffer;
427 u64 free_buffer;
428 u64 flush;
429 u64 get_location;
430 u64 attributes;
431 u64 get_bar_attributes;
432 u64 set_bar_attributes;
433 u64 romsize;
434 void *romimage;
435 } efi_pci_io_protocol_64;
436
437 typedef struct {
438 void *poll_mem;
439 void *poll_io;
440 efi_pci_io_protocol_access_t mem;
441 efi_pci_io_protocol_access_t io;
442 efi_pci_io_protocol_access_t pci;
443 void *copy_mem;
444 void *map;
445 void *unmap;
446 void *allocate_buffer;
447 void *free_buffer;
448 void *flush;
449 void *get_location;
450 void *attributes;
451 void *get_bar_attributes;
452 void *set_bar_attributes;
453 u64 romsize;
454 void *romimage;
455 } efi_pci_io_protocol;
456
457 #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
458 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
459 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
460 #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
461 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
462 #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
463 #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
464 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
465 #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
466 #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
467 #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
468 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
469 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
470 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
471 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
472 #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
473 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
474 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
475 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
476
477 /*
478 * Types and defines for EFI ResetSystem
479 */
480 #define EFI_RESET_COLD 0
481 #define EFI_RESET_WARM 1
482 #define EFI_RESET_SHUTDOWN 2
483
484 /*
485 * EFI Runtime Services table
486 */
487 #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
488 #define EFI_RUNTIME_SERVICES_REVISION 0x00010000
489
490 typedef struct {
491 efi_table_hdr_t hdr;
492 u32 get_time;
493 u32 set_time;
494 u32 get_wakeup_time;
495 u32 set_wakeup_time;
496 u32 set_virtual_address_map;
497 u32 convert_pointer;
498 u32 get_variable;
499 u32 get_next_variable;
500 u32 set_variable;
501 u32 get_next_high_mono_count;
502 u32 reset_system;
503 u32 update_capsule;
504 u32 query_capsule_caps;
505 u32 query_variable_info;
506 } efi_runtime_services_32_t;
507
508 typedef struct {
509 efi_table_hdr_t hdr;
510 u64 get_time;
511 u64 set_time;
512 u64 get_wakeup_time;
513 u64 set_wakeup_time;
514 u64 set_virtual_address_map;
515 u64 convert_pointer;
516 u64 get_variable;
517 u64 get_next_variable;
518 u64 set_variable;
519 u64 get_next_high_mono_count;
520 u64 reset_system;
521 u64 update_capsule;
522 u64 query_capsule_caps;
523 u64 query_variable_info;
524 } efi_runtime_services_64_t;
525
526 typedef struct {
527 efi_table_hdr_t hdr;
528 void *get_time;
529 void *set_time;
530 void *get_wakeup_time;
531 void *set_wakeup_time;
532 void *set_virtual_address_map;
533 void *convert_pointer;
534 void *get_variable;
535 void *get_next_variable;
536 void *set_variable;
537 void *get_next_high_mono_count;
538 void *reset_system;
539 void *update_capsule;
540 void *query_capsule_caps;
541 void *query_variable_info;
542 } efi_runtime_services_t;
543
544 typedef efi_status_t efi_get_time_t(efi_time_t *tm, efi_time_cap_t *tc);
545 typedef efi_status_t efi_set_time_t(efi_time_t *tm);
546 typedef efi_status_t efi_get_wakeup_time_t(efi_bool_t *enabled,
547 efi_bool_t *pending, efi_time_t *tm);
548 typedef efi_status_t efi_set_wakeup_time_t(efi_bool_t enabled, efi_time_t *tm);
549 typedef efi_status_t efi_get_variable_t(efi_char16_t *name, efi_guid_t *vendor,
550 u32 *attr, unsigned long *data_size,
551 void *data);
552 typedef efi_status_t efi_get_next_variable_t(unsigned long *name_size,
553 efi_char16_t *name,
554 efi_guid_t *vendor);
555 typedef efi_status_t efi_set_variable_t(efi_char16_t *name, efi_guid_t *vendor,
556 u32 attr, unsigned long data_size,
557 void *data);
558 typedef efi_status_t efi_get_next_high_mono_count_t(u32 *count);
559 typedef void efi_reset_system_t(int reset_type, efi_status_t status,
560 unsigned long data_size, efi_char16_t *data);
561 typedef efi_status_t efi_set_virtual_address_map_t(
562 unsigned long memory_map_size, unsigned long descriptor_size,
563 u32 descriptor_version, efi_memory_desc_t *virtual_map);
564 typedef efi_status_t efi_query_variable_info_t(u32 attr, u64 *storage_space,
565 u64 *remaining_space,
566 u64 *max_variable_size);
567 typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
568 unsigned long count,
569 unsigned long sg_list);
570 typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
571 unsigned long count,
572 u64 *max_size, int *reset_type);
573 typedef efi_status_t efi_query_variable_store_t(u32 attributes,
574 unsigned long size,
575 bool nonblocking);
576
577 void efi_native_runtime_setup(void);
578
579 /*
580 * EFI Configuration Table and GUID definitions
581 *
582 * These are all defined in a single line to make them easier to
583 * grep for and to see them at a glance - while still having a
584 * similar structure to the definitions in the spec.
585 *
586 * Here's how they are structured:
587 *
588 * GUID: 12345678-1234-1234-1234-123456789012
589 * Spec:
590 * #define EFI_SOME_PROTOCOL_GUID \
591 * {0x12345678,0x1234,0x1234,\
592 * {0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x12}}
593 * Here:
594 * #define SOME_PROTOCOL_GUID EFI_GUID(0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12)
595 * ^ tabs ^extra space
596 *
597 * Note that the 'extra space' separates the values at the same place
598 * where the UEFI SPEC breaks the line.
599 */
600 #define NULL_GUID \
601 EFI_GUID(0x00000000, \
602 0x0000, \
603 0x0000, \
604 0x00, \
605 0x00, \
606 0x00, \
607 0x00, \
608 0x00, \
609 0x00, \
610 0x00, \
611 0x00)
612 #define MPS_TABLE_GUID \
613 EFI_GUID(0xeb9d2d2f, \
614 0x2d88, \
615 0x11d3, \
616 0x9a, \
617 0x16, \
618 0x00, \
619 0x90, \
620 0x27, \
621 0x3f, \
622 0xc1, \
623 0x4d)
624 #define ACPI_TABLE_GUID \
625 EFI_GUID(0xeb9d2d30, \
626 0x2d88, \
627 0x11d3, \
628 0x9a, \
629 0x16, \
630 0x00, \
631 0x90, \
632 0x27, \
633 0x3f, \
634 0xc1, \
635 0x4d)
636 #define ACPI_20_TABLE_GUID \
637 EFI_GUID(0x8868e871, \
638 0xe4f1, \
639 0x11d3, \
640 0xbc, \
641 0x22, \
642 0x00, \
643 0x80, \
644 0xc7, \
645 0x3c, \
646 0x88, \
647 0x81)
648 #define SMBIOS_TABLE_GUID \
649 EFI_GUID(0xeb9d2d31, \
650 0x2d88, \
651 0x11d3, \
652 0x9a, \
653 0x16, \
654 0x00, \
655 0x90, \
656 0x27, \
657 0x3f, \
658 0xc1, \
659 0x4d)
660 #define SMBIOS3_TABLE_GUID \
661 EFI_GUID(0xf2fd1544, \
662 0x9794, \
663 0x4a2c, \
664 0x99, \
665 0x2e, \
666 0xe5, \
667 0xbb, \
668 0xcf, \
669 0x20, \
670 0xe3, \
671 0x94)
672 #define SAL_SYSTEM_TABLE_GUID \
673 EFI_GUID(0xeb9d2d32, \
674 0x2d88, \
675 0x11d3, \
676 0x9a, \
677 0x16, \
678 0x00, \
679 0x90, \
680 0x27, \
681 0x3f, \
682 0xc1, \
683 0x4d)
684 #define HCDP_TABLE_GUID \
685 EFI_GUID(0xf951938d, \
686 0x620b, \
687 0x42ef, \
688 0x82, \
689 0x79, \
690 0xa8, \
691 0x4b, \
692 0x79, \
693 0x61, \
694 0x78, \
695 0x98)
696 #define UGA_IO_PROTOCOL_GUID \
697 EFI_GUID(0x61a4d49e, \
698 0x6f68, \
699 0x4f1b, \
700 0xb9, \
701 0x22, \
702 0xa8, \
703 0x6e, \
704 0xed, \
705 0x0b, \
706 0x07, \
707 0xa2)
708 #define EFI_GLOBAL_VARIABLE_GUID \
709 EFI_GUID(0x8be4df61, \
710 0x93ca, \
711 0x11d2, \
712 0xaa, \
713 0x0d, \
714 0x00, \
715 0xe0, \
716 0x98, \
717 0x03, \
718 0x2b, \
719 0x8c)
720 #define UV_SYSTEM_TABLE_GUID \
721 EFI_GUID(0x3b13a7d4, \
722 0x633e, \
723 0x11dd, \
724 0x93, \
725 0xec, \
726 0xda, \
727 0x25, \
728 0x56, \
729 0xd8, \
730 0x95, \
731 0x93)
732 #define LINUX_EFI_CRASH_GUID \
733 EFI_GUID(0xcfc8fc79, \
734 0xbe2e, \
735 0x4ddc, \
736 0x97, \
737 0xf0, \
738 0x9f, \
739 0x98, \
740 0xbf, \
741 0xe2, \
742 0x98, \
743 0xa0)
744 #define LOADED_IMAGE_PROTOCOL_GUID \
745 EFI_GUID(0x5b1b31a1, \
746 0x9562, \
747 0x11d2, \
748 0x8e, \
749 0x3f, \
750 0x00, \
751 0xa0, \
752 0xc9, \
753 0x69, \
754 0x72, \
755 0x3b)
756 #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
757 EFI_GUID(0x9042a9de, \
758 0x23dc, \
759 0x4a38, \
760 0x96, \
761 0xfb, \
762 0x7a, \
763 0xde, \
764 0xd0, \
765 0x80, \
766 0x51, \
767 0x6a)
768 #define EFI_UGA_PROTOCOL_GUID \
769 EFI_GUID(0x982c298b, \
770 0xf4fa, \
771 0x41cb, \
772 0xb8, \
773 0x38, \
774 0x77, \
775 0xaa, \
776 0x68, \
777 0x8f, \
778 0xb8, \
779 0x39)
780 #define EFI_PCI_IO_PROTOCOL_GUID \
781 EFI_GUID(0x4cf5b200, \
782 0x68b8, \
783 0x4ca5, \
784 0x9e, \
785 0xec, \
786 0xb2, \
787 0x3e, \
788 0x3f, \
789 0x50, \
790 0x02, \
791 0x9a)
792 #define EFI_FILE_INFO_ID \
793 EFI_GUID(0x09576e92, \
794 0x6d3f, \
795 0x11d2, \
796 0x8e, \
797 0x39, \
798 0x00, \
799 0xa0, \
800 0xc9, \
801 0x69, \
802 0x72, \
803 0x3b)
804 #define EFI_SYSTEM_RESOURCE_TABLE_GUID \
805 EFI_GUID(0xb122a263, \
806 0x3661, \
807 0x4f68, \
808 0x99, \
809 0x29, \
810 0x78, \
811 0xf8, \
812 0xb0, \
813 0xd6, \
814 0x21, \
815 0x80)
816 #define EFI_FILE_SYSTEM_GUID \
817 EFI_GUID(0x964e5b22, \
818 0x6459, \
819 0x11d2, \
820 0x8e, \
821 0x39, \
822 0x00, \
823 0xa0, \
824 0xc9, \
825 0x69, \
826 0x72, \
827 0x3b)
828 #define DEVICE_TREE_GUID \
829 EFI_GUID(0xb1b621d5, \
830 0xf19c, \
831 0x41a5, \
832 0x83, \
833 0x0b, \
834 0xd9, \
835 0x15, \
836 0x2c, \
837 0x69, \
838 0xaa, \
839 0xe0)
840 #define EFI_PROPERTIES_TABLE_GUID \
841 EFI_GUID(0x880aaca3, \
842 0x4adc, \
843 0x4a04, \
844 0x90, \
845 0x79, \
846 0xb7, \
847 0x47, \
848 0x34, \
849 0x08, \
850 0x25, \
851 0xe5)
852 #define EFI_RNG_PROTOCOL_GUID \
853 EFI_GUID(0x3152bca5, \
854 0xeade, \
855 0x433d, \
856 0x86, \
857 0x2e, \
858 0xc0, \
859 0x1c, \
860 0xdc, \
861 0x29, \
862 0x1f, \
863 0x44)
864 #define EFI_MEMORY_ATTRIBUTES_TABLE_GUID \
865 EFI_GUID(0xdcfa911d, \
866 0x26eb, \
867 0x469f, \
868 0xa2, \
869 0x20, \
870 0x38, \
871 0xb7, \
872 0xdc, \
873 0x46, \
874 0x12, \
875 0x20)
876 #define EFI_CONSOLE_OUT_DEVICE_GUID \
877 EFI_GUID(0xd3b36f2c, \
878 0xd551, \
879 0x11d4, \
880 0x9a, \
881 0x46, \
882 0x00, \
883 0x90, \
884 0x27, \
885 0x3f, \
886 0xc1, \
887 0x4d)
888
889 /*
890 * This GUID is used to pass to the kernel proper the struct screen_info
891 * structure that was populated by the stub based on the GOP protocol instance
892 * associated with ConOut
893 */
894 #define LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID \
895 EFI_GUID(0xe03fc20a, \
896 0x85dc, \
897 0x406e, \
898 0xb9, \
899 0x0e, \
900 0x4a, \
901 0xb5, \
902 0x02, \
903 0x37, \
904 0x1d, \
905 0x95)
906 #define LINUX_EFI_LOADER_ENTRY_GUID \
907 EFI_GUID(0x4a67b082, \
908 0x0a4c, \
909 0x41cf, \
910 0xb6, \
911 0xc7, \
912 0x44, \
913 0x0b, \
914 0x29, \
915 0xbb, \
916 0x8c, \
917 0x4f)
918
919 typedef struct {
920 efi_guid_t guid;
921 u64 table;
922 } efi_config_table_64_t;
923
924 typedef struct {
925 efi_guid_t guid;
926 u32 table;
927 } efi_config_table_32_t;
928
929 typedef struct {
930 efi_guid_t guid;
931 unsigned long table;
932 } efi_config_table_t;
933
934 typedef struct {
935 efi_guid_t guid;
936 const char *name;
937 unsigned long *ptr;
938 } efi_config_table_type_t;
939
940 #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
941
942 #define EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30))
943 #define EFI_2_20_SYSTEM_TABLE_REVISION ((2 << 16) | (20))
944 #define EFI_2_10_SYSTEM_TABLE_REVISION ((2 << 16) | (10))
945 #define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | (00))
946 #define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10))
947 #define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02))
948
949 typedef struct {
950 efi_table_hdr_t hdr;
951 u64 fw_vendor; /* physical addr of CHAR16 vendor string */
952 u32 fw_revision;
953 u32 __pad1;
954 u64 con_in_handle;
955 u64 con_in;
956 u64 con_out_handle;
957 u64 con_out;
958 u64 stderr_handle;
959 u64 stderr;
960 u64 runtime;
961 u64 boottime;
962 u32 nr_tables;
963 u32 __pad2;
964 u64 tables;
965 } efi_system_table_64_t;
966
967 typedef struct {
968 efi_table_hdr_t hdr;
969 u32 fw_vendor; /* physical addr of CHAR16 vendor string */
970 u32 fw_revision;
971 u32 con_in_handle;
972 u32 con_in;
973 u32 con_out_handle;
974 u32 con_out;
975 u32 stderr_handle;
976 u32 stderr;
977 u32 runtime;
978 u32 boottime;
979 u32 nr_tables;
980 u32 tables;
981 } efi_system_table_32_t;
982
983 typedef struct {
984 efi_table_hdr_t hdr;
985 unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */
986 u32 fw_revision;
987 unsigned long con_in_handle;
988 unsigned long con_in;
989 unsigned long con_out_handle;
990 unsigned long con_out;
991 unsigned long stderr_handle;
992 unsigned long stderr;
993 efi_runtime_services_t *runtime;
994 efi_boot_services_t *boottime;
995 unsigned long nr_tables;
996 unsigned long tables;
997 } efi_system_table_t;
998
999 extern efi_system_table_t *efi_sys_table;
1000 typedef u64 phys_addr_t;
1001 /*
1002 * Architecture independent structure for describing a memory map for the
1003 * benefit of efi_memmap_init_early(), saving us the need to pass four
1004 * parameters.
1005 */
1006 struct efi_memory_map_data {
1007 phys_addr_t phys_map;
1008 unsigned long size;
1009 unsigned long desc_version;
1010 unsigned long desc_size;
1011 };
1012
1013 struct efi_memory_map {
1014 phys_addr_t phys_map;
1015 void *map;
1016 void *map_end;
1017 int nr_map;
1018 unsigned long desc_version;
1019 unsigned long desc_size;
1020 bool late;
1021 };
1022
1023 struct range {
1024 u64 start;
1025 u64 end;
1026 };
1027
1028 struct efi_mem_range {
1029 struct range range;
1030 u64 attribute;
1031 };
1032
1033 typedef struct {
1034 u32 revision;
1035 void *parent_handle;
1036 efi_system_table_t *system_table;
1037 void *device_handle;
1038 void *file_path;
1039 void *reserved;
1040 u32 load_options_size;
1041 void *load_options;
1042 void *image_base;
1043 __aligned_u64 image_size;
1044 unsigned int image_code_type;
1045 unsigned int image_data_type;
1046 unsigned long unload;
1047 } efi_loaded_image_t;
1048
1049 struct efi_fdt_params {
1050 u64 system_table;
1051 u64 mmap;
1052 u32 mmap_size;
1053 u32 desc_size;
1054 u32 desc_ver;
1055 };
1056
1057 typedef struct {
1058 u32 revision;
1059 u32 parent_handle;
1060 u32 system_table;
1061 u32 device_handle;
1062 u32 file_path;
1063 u32 reserved;
1064 u32 load_options_size;
1065 u32 load_options;
1066 u32 image_base;
1067 __aligned_u64 image_size;
1068 unsigned int image_code_type;
1069 unsigned int image_data_type;
1070 unsigned long unload;
1071 } efi_loaded_image_32_t;
1072
1073 typedef struct {
1074 u32 revision;
1075 u64 parent_handle;
1076 u64 system_table;
1077 u64 device_handle;
1078 u64 file_path;
1079 u64 reserved;
1080 u32 load_options_size;
1081 u64 load_options;
1082 u64 image_base;
1083 __aligned_u64 image_size;
1084 unsigned int image_code_type;
1085 unsigned int image_data_type;
1086 unsigned long unload;
1087 } efi_loaded_image_64_t;
1088
1089 typedef struct {
1090 u64 size;
1091 u64 file_size;
1092 u64 phys_size;
1093 efi_time_t create_time;
1094 efi_time_t last_access_time;
1095 efi_time_t modification_time;
1096 __aligned_u64 attribute;
1097 efi_char16_t filename[1];
1098 } efi_file_info_t;
1099
1100 typedef struct {
1101 u64 revision;
1102 u32 open;
1103 u32 close;
1104 u32 delete;
1105 u32 read;
1106 u32 write;
1107 u32 get_position;
1108 u32 set_position;
1109 u32 get_info;
1110 u32 set_info;
1111 u32 flush;
1112 } efi_file_handle_32_t;
1113
1114 typedef struct {
1115 u64 revision;
1116 u64 open;
1117 u64 close;
1118 u64 delete;
1119 u64 read;
1120 u64 write;
1121 u64 get_position;
1122 u64 set_position;
1123 u64 get_info;
1124 u64 set_info;
1125 u64 flush;
1126 } efi_file_handle_64_t;
1127
1128 typedef struct _efi_file_handle {
1129 u64 revision;
1130 efi_status_t (*open)(struct _efi_file_handle *, struct _efi_file_handle **,
1131 efi_char16_t *, u64, u64);
1132 efi_status_t (*close)(struct _efi_file_handle *);
1133 void *delete;
1134 efi_status_t (*read)(struct _efi_file_handle *, unsigned long *, void *);
1135 void *write;
1136 void *get_position;
1137 void *set_position;
1138 efi_status_t (*get_info)(struct _efi_file_handle *, efi_guid_t *,
1139 unsigned long *, void *);
1140 void *set_info;
1141 void *flush;
1142 } efi_file_handle_t;
1143
1144 typedef struct _efi_file_io_interface {
1145 u64 revision;
1146 int (*open_volume)(struct _efi_file_io_interface *, efi_file_handle_t **);
1147 } efi_file_io_interface_t;
1148
1149 #define EFI_FILE_MODE_READ 0x0000000000000001
1150 #define EFI_FILE_MODE_WRITE 0x0000000000000002
1151 #define EFI_FILE_MODE_CREATE 0x8000000000000000
1152
1153 typedef struct {
1154 u32 version;
1155 u32 length;
1156 u64 memory_protection_attribute;
1157 } efi_properties_table_t;
1158
1159 #define EFI_PROPERTIES_TABLE_VERSION 0x00010000
1160 #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA 0x1
1161
1162 #define EFI_INVALID_TABLE_ADDR (~0UL)
1163
1164 typedef struct {
1165 u32 version;
1166 u32 num_entries;
1167 u32 desc_size;
1168 u32 reserved;
1169 efi_memory_desc_t entry[0];
1170 } efi_memory_attributes_table_t;
1171
1172 /*
1173 * All runtime access to EFI goes through this structure:
1174 */
1175 extern struct efi {
1176 efi_system_table_t *systab; /* EFI system table */
1177 unsigned int runtime_version; /* Runtime services version */
1178 unsigned long mps; /* MPS table */
1179 unsigned long acpi; /* ACPI table (IA64 ext 0.71) */
1180 unsigned long acpi20; /* ACPI table (ACPI 2.0) */
1181 unsigned long smbios; /* SMBIOS table (32 bit entry point) */
1182 unsigned long smbios3; /* SMBIOS table (64 bit entry point) */
1183 unsigned long sal_systab; /* SAL system table */
1184 unsigned long boot_info; /* boot info table */
1185 unsigned long hcdp; /* HCDP table */
1186 unsigned long uga; /* UGA table */
1187 unsigned long uv_systab; /* UV system table */
1188 unsigned long fw_vendor; /* fw_vendor */
1189 unsigned long runtime; /* runtime table */
1190 unsigned long config_table; /* config tables */
1191 unsigned long esrt; /* ESRT table */
1192 unsigned long properties_table; /* properties table */
1193 unsigned long mem_attr_table; /* memory attributes table */
1194 efi_get_time_t *get_time;
1195 efi_set_time_t *set_time;
1196 efi_get_wakeup_time_t *get_wakeup_time;
1197 efi_set_wakeup_time_t *set_wakeup_time;
1198 efi_get_variable_t *get_variable;
1199 efi_get_next_variable_t *get_next_variable;
1200 efi_set_variable_t *set_variable;
1201 efi_set_variable_t *set_variable_nonblocking;
1202 efi_query_variable_info_t *query_variable_info;
1203 efi_query_variable_info_t *query_variable_info_nonblocking;
1204 efi_update_capsule_t *update_capsule;
1205 efi_query_capsule_caps_t *query_capsule_caps;
1206 efi_get_next_high_mono_count_t *get_next_high_mono_count;
1207 efi_reset_system_t *reset_system;
1208 efi_set_virtual_address_map_t *set_virtual_address_map;
1209 struct efi_memory_map memmap;
1210 unsigned long flags;
1211 } efi;
1212
1213 extern void efi_init(void);
1214 extern void *efi_get_pal_addr(void);
1215 extern void efi_map_pal_code(void);
1216 extern void efi_memmap_walk(efi_freemem_callback_t callback, void *arg);
1217 extern void
1218 efi_enter_virtual_mode(void); /* switch EFI to virtual mode, if possible */
1219 #ifdef CONFIG_X86
1220 extern void efi_late_init(void);
1221 extern void efi_free_boot_services(void);
1222 extern efi_status_t efi_query_variable_store(u32 attributes, unsigned long size,
1223 bool nonblocking);
1224 extern void efi_find_mirror(void);
1225 #else
efi_late_init(void)1226 static inline void efi_late_init(void)
1227 {
1228 }
1229
efi_free_boot_services(void)1230 static inline void efi_free_boot_services(void)
1231 {
1232 }
1233
1234 static inline efi_status_t
efi_query_variable_store(u32 attributes,unsigned long size,bool nonblocking)1235 efi_query_variable_store(u32 attributes, unsigned long size, bool nonblocking)
1236 {
1237 return EFI_SUCCESS;
1238 }
1239 #endif
1240
1241 /* Iterate through an efi_memory_map */
1242 #define for_each_efi_memory_desc_in_map(m, md) \
1243 for ((md) = (m)->map; \
1244 (md) && ((void *)(md) + (m)->desc_size) <= (m)->map_end; \
1245 (md) = (void *)(md) + (m)->desc_size)
1246
1247 /**
1248 * for_each_efi_memory_desc - iterate over descriptors in efi.memmap
1249 * @md: the efi_memory_desc_t * iterator
1250 *
1251 * Once the loop finishes @md must not be accessed.
1252 */
1253 #define for_each_efi_memory_desc(md) \
1254 for_each_efi_memory_desc_in_map (&efi.memmap, md)
1255
1256 /*
1257 * Format an EFI memory descriptor's type and attributes to a user-provided
1258 * character buffer, as per snprintf(), and return the buffer.
1259 */
1260 char *efi_md_typeattr_format(char *buf, size_t size,
1261 const efi_memory_desc_t *md);
1262
1263 #ifdef CONFIG_EFI_PCDP
1264 extern int efi_setup_pcdp_console(char *);
1265 #endif
1266
1267 /*
1268 * We play games with efi_enabled so that the compiler will, if
1269 * possible, remove EFI-related code altogether.
1270 */
1271 #define EFI_BOOT 0 /* Were we booted from EFI? */
1272 #define EFI_CONFIG_TABLES 2 /* Can we use EFI config tables? */
1273 #define EFI_RUNTIME_SERVICES 3 /* Can we use runtime services? */
1274 #define EFI_MEMMAP 4 /* Can we use EFI memory map? */
1275 #define EFI_64BIT 5 /* Is the firmware 64-bit? */
1276 #define EFI_PARAVIRT 6 /* Access is via a paravirt interface */
1277 #define EFI_ARCH_1 7 /* First arch-specific bit */
1278 #define EFI_DBG 8 /* Print additional debug info at runtime */
1279 #define EFI_NX_PE_DATA \
1280 9 /* Can runtime data regions be mapped non-executable? */
1281
1282 #ifdef CONFIG_EFI
1283 /*
1284 * Test whether the above EFI_* bits are enabled.
1285 */
efi_enabled(int feature)1286 static inline bool efi_enabled(int feature)
1287 {
1288 return test_bit(feature, &efi.flags) != 0;
1289 }
1290
1291 extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
1292 #else
efi_enabled(int feature)1293 static inline bool efi_enabled(int feature)
1294 {
1295 return false;
1296 }
1297
efi_capsule_pending(int * reset_type)1298 static inline bool efi_capsule_pending(int *reset_type)
1299 {
1300 return false;
1301 }
1302 #endif
1303
1304 extern int efi_status_to_err(efi_status_t status);
1305
1306 /*
1307 * Variable Attributes
1308 */
1309 #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
1310 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
1311 #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
1312 #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
1313 #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
1314 #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
1315 #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
1316
1317 #define EFI_VARIABLE_MASK \
1318 (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS \
1319 | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_HARDWARE_ERROR_RECORD \
1320 | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS \
1321 | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS \
1322 | EFI_VARIABLE_APPEND_WRITE)
1323 /*
1324 * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
1325 * not including trailing NUL
1326 */
1327 #define EFI_VARIABLE_GUID_LEN UUID_STRING_LEN
1328
1329 /*
1330 * The type of search to perform when calling boottime->locate_handle
1331 */
1332 #define EFI_LOCATE_ALL_HANDLES 0
1333 #define EFI_LOCATE_BY_REGISTER_NOTIFY 1
1334 #define EFI_LOCATE_BY_PROTOCOL 2
1335
1336 /*
1337 * EFI Device Path information
1338 */
1339 #define EFI_DEV_HW 0x01
1340 #define EFI_DEV_PCI 1
1341 #define EFI_DEV_PCCARD 2
1342 #define EFI_DEV_MEM_MAPPED 3
1343 #define EFI_DEV_VENDOR 4
1344 #define EFI_DEV_CONTROLLER 5
1345 #define EFI_DEV_ACPI 0x02
1346 #define EFI_DEV_BASIC_ACPI 1
1347 #define EFI_DEV_EXPANDED_ACPI 2
1348 #define EFI_DEV_MSG 0x03
1349 #define EFI_DEV_MSG_ATAPI 1
1350 #define EFI_DEV_MSG_SCSI 2
1351 #define EFI_DEV_MSG_FC 3
1352 #define EFI_DEV_MSG_1394 4
1353 #define EFI_DEV_MSG_USB 5
1354 #define EFI_DEV_MSG_USB_CLASS 15
1355 #define EFI_DEV_MSG_I20 6
1356 #define EFI_DEV_MSG_MAC 11
1357 #define EFI_DEV_MSG_IPV4 12
1358 #define EFI_DEV_MSG_IPV6 13
1359 #define EFI_DEV_MSG_INFINIBAND 9
1360 #define EFI_DEV_MSG_UART 14
1361 #define EFI_DEV_MSG_VENDOR 10
1362 #define EFI_DEV_MEDIA 0x04
1363 #define EFI_DEV_MEDIA_HARD_DRIVE 1
1364 #define EFI_DEV_MEDIA_CDROM 2
1365 #define EFI_DEV_MEDIA_VENDOR 3
1366 #define EFI_DEV_MEDIA_FILE 4
1367 #define EFI_DEV_MEDIA_PROTOCOL 5
1368 #define EFI_DEV_BIOS_BOOT 0x05
1369 #define EFI_DEV_END_PATH 0x7F
1370 #define EFI_DEV_END_PATH2 0xFF
1371 #define EFI_DEV_END_INSTANCE 0x01
1372 #define EFI_DEV_END_ENTIRE 0xFF
1373
1374 struct efi_generic_dev_path {
1375 u8 type;
1376 u8 sub_type;
1377 u16 length;
1378 } __attribute((packed));
1379
1380 /*
1381 * EFI Variable support.
1382 *
1383 * Different firmware drivers can expose their EFI-like variables using
1384 * the following.
1385 */
1386
1387 struct efivar_operations {
1388 efi_get_variable_t *get_variable;
1389 efi_get_next_variable_t *get_next_variable;
1390 efi_set_variable_t *set_variable;
1391 efi_set_variable_t *set_variable_nonblocking;
1392 efi_query_variable_store_t *query_variable_store;
1393 };
1394
1395 struct efivars {
1396 struct kset *kset;
1397 struct kobject *kobject;
1398 const struct efivar_operations *ops;
1399 };
1400
1401 /*
1402 * The maximum size of VariableName + Data = 1024
1403 * Therefore, it's reasonable to save that much
1404 * space in each part of the structure,
1405 * and we use a page for reading/writing.
1406 */
1407
1408 #define EFI_VAR_NAME_LEN 1024
1409
1410 struct efi_variable {
1411 efi_char16_t VariableName[EFI_VAR_NAME_LEN / sizeof(efi_char16_t)];
1412 efi_guid_t VendorGuid;
1413 unsigned long DataSize;
1414 u8 Data[1024];
1415 efi_status_t Status;
1416 u32 Attributes;
1417 } __attribute__((packed));
1418
1419 struct list_head {
1420 struct list_head *next, *prev;
1421 };
1422
1423 struct efivar_entry {
1424 struct efi_variable var;
1425 struct list_head list;
1426 void *kobj;
1427 bool scanning;
1428 bool deleting;
1429 };
1430
1431 struct efi_simple_text_output_protocol_32 {
1432 u32 reset;
1433 u32 output_string;
1434 u32 test_string;
1435 };
1436
1437 struct efi_simple_text_output_protocol_64 {
1438 u64 reset;
1439 u64 output_string;
1440 u64 test_string;
1441 };
1442
1443 struct efi_simple_text_output_protocol {
1444 void *reset;
1445 efi_status_t (*output_string)(void *, void *);
1446 void *test_string;
1447 };
1448
1449 #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0
1450 #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1
1451 #define PIXEL_BIT_MASK 2
1452 #define PIXEL_BLT_ONLY 3
1453 #define PIXEL_FORMAT_MAX 4
1454
1455 struct efi_pixel_bitmask {
1456 u32 red_mask;
1457 u32 green_mask;
1458 u32 blue_mask;
1459 u32 reserved_mask;
1460 };
1461
1462 struct efi_graphics_output_mode_info {
1463 u32 version;
1464 u32 horizontal_resolution;
1465 u32 vertical_resolution;
1466 int pixel_format;
1467 struct efi_pixel_bitmask pixel_information;
1468 u32 pixels_per_scan_line;
1469 } __packed;
1470
1471 struct efi_graphics_output_protocol_mode_32 {
1472 u32 max_mode;
1473 u32 mode;
1474 u32 info;
1475 u32 size_of_info;
1476 u64 frame_buffer_base;
1477 u32 frame_buffer_size;
1478 } __packed;
1479
1480 struct efi_graphics_output_protocol_mode_64 {
1481 u32 max_mode;
1482 u32 mode;
1483 u64 info;
1484 u64 size_of_info;
1485 u64 frame_buffer_base;
1486 u64 frame_buffer_size;
1487 } __packed;
1488
1489 struct efi_graphics_output_protocol_mode {
1490 u32 max_mode;
1491 u32 mode;
1492 unsigned long info;
1493 unsigned long size_of_info;
1494 u64 frame_buffer_base;
1495 unsigned long frame_buffer_size;
1496 } __packed;
1497
1498 struct efi_graphics_output_protocol_32 {
1499 u32 query_mode;
1500 u32 set_mode;
1501 u32 blt;
1502 u32 mode;
1503 };
1504
1505 struct efi_graphics_output_protocol_64 {
1506 u64 query_mode;
1507 u64 set_mode;
1508 u64 blt;
1509 u64 mode;
1510 };
1511
1512 struct efi_graphics_output_protocol {
1513 unsigned long query_mode;
1514 unsigned long set_mode;
1515 unsigned long blt;
1516 struct efi_graphics_output_protocol_mode *mode;
1517 };
1518
1519 typedef efi_status_t (*efi_graphics_output_protocol_query_mode)(
1520 struct efi_graphics_output_protocol *, u32, unsigned long *,
1521 struct efi_graphics_output_mode_info **);
1522
1523 extern struct list_head efivar_sysfs_list;
1524
efivar_unregister(struct efivar_entry * var)1525 static inline void efivar_unregister(struct efivar_entry *var)
1526 {
1527 }
1528
1529 int efivars_register(struct efivars *efivars,
1530 const struct efivar_operations *ops,
1531 struct kobject *kobject);
1532 int efivars_unregister(struct efivars *efivars);
1533 struct kobject *efivars_kobject(void);
1534
1535 int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
1536 void *data, bool duplicates, struct list_head *head);
1537
1538 int efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
1539 int efivar_entry_remove(struct efivar_entry *entry);
1540
1541 int __efivar_entry_delete(struct efivar_entry *entry);
1542 int efivar_entry_delete(struct efivar_entry *entry);
1543
1544 int efivar_entry_size(struct efivar_entry *entry, unsigned long *size);
1545 int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
1546 unsigned long *size, void *data);
1547 int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
1548 unsigned long *size, void *data);
1549 int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
1550 unsigned long size, void *data, struct list_head *head);
1551 int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
1552 unsigned long *size, void *data, bool *set);
1553 int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
1554 bool block, unsigned long size, void *data);
1555
1556 int efivar_entry_iter_begin(void);
1557 void efivar_entry_iter_end(void);
1558
1559 int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1560 struct list_head *head, void *data,
1561 struct efivar_entry **prev);
1562 int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1563 struct list_head *head, void *data);
1564
1565 struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
1566 struct list_head *head, bool remove);
1567
1568 bool efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
1569 unsigned long data_size);
1570 bool efivar_variable_is_removable(efi_guid_t vendor, const char *name,
1571 size_t len);
1572
1573 extern struct work_struct efivar_work;
1574 void efivar_run_worker(void);
1575 /* prototypes shared between arch specific and generic stub code */
1576
1577 void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
1578 unsigned long addr);
1579
1580 char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
1581 efi_loaded_image_t *image, int *cmd_line_len);
1582
1583 efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
1584 struct efi_boot_memmap *map);
1585
1586 efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
1587 unsigned long size, unsigned long align,
1588 unsigned long *addr);
1589
1590 efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
1591 unsigned long size, unsigned long align,
1592 unsigned long *addr, unsigned long max);
1593
1594 efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
1595 unsigned long *image_addr,
1596 unsigned long image_size,
1597 unsigned long alloc_size,
1598 unsigned long preferred_addr,
1599 unsigned long alignment);
1600
1601 efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
1602 efi_loaded_image_t *image, char *cmd_line,
1603 char *option_string, unsigned long max_addr,
1604 unsigned long *load_addr,
1605 unsigned long *load_size);
1606
1607 efi_status_t efi_parse_options(char const *cmdline);
1608
1609 bool efi_runtime_disabled(void);
1610 extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
1611
1612 typedef efi_status_t (*efi_exit_boot_map_processing)(
1613 efi_system_table_t *sys_table_arg, struct efi_boot_memmap *map, void *priv);
1614
1615 efi_status_t efi_exit_boot_services(efi_system_table_t *sys_table, void *handle,
1616 struct efi_boot_memmap *map, void *priv,
1617 efi_exit_boot_map_processing priv_func);
1618
1619 struct exit_boot_struct {
1620 efi_memory_desc_t *runtime_map;
1621 int *runtime_entry_count;
1622 };
1623 efi_status_t
1624 handle_kernel_image(efi_system_table_t *sys_table_arg,
1625 unsigned long *image_addr, unsigned long *image_size,
1626 unsigned long *reserve_addr, unsigned long *reserve_size,
1627 unsigned long dram_base, efi_loaded_image_t *image);
1628 efi_status_t exit_boot(efi_system_table_t *sys_table, void *handle);
1629 efi_status_t get_dram_base(efi_system_table_t *sys_table,
1630 unsigned long *dram_base);
1631 efi_status_t efi_get_phy_memory_map(efi_system_table_t *sys_table_arg);
1632 void *memcpy(void *dst, const void *src, size_t len);
1633 void efi_error(char *str, efi_status_t status);
1634 void move_memmap(unsigned long dram_base);
1635
1636 /* ChCore mem desc */
1637 #define MAX_DESC 128
1638 #define MEMORY_DESC_ADDR 0x100000000
1639
1640 struct chcore_memory_desc {
1641 u64 start_addr;
1642 u64 end_addr;
1643 u64 attribute;
1644 u32 type;
1645 u32 pad;
1646 };
1647
1648 struct chcore_memory_map {
1649 struct chcore_memory_desc descs[MAX_DESC];
1650 };
1651
1652 extern struct chcore_memory_map *global_map;
1653
1654 #endif /* LIB_EFI_H */