1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H
4 #define _DRIVERS_FIRMWARE_EFI_EFISTUB_H
6 /* error code which can't be mistaken for valid address */
7 #define EFI_ERROR (~0UL)
10 * __init annotations should not be used in the EFI stub, since the code is
11 * either included in the decompressor (x86, ARM) where they have no effect,
12 * or the whole stub is __init annotated at the section level (arm64), by
13 * renaming the sections, in which case the __init annotation will be
14 * redundant, and will result in section names like .init.init.text, and our
15 * linker script does not expect that.
20 * Allow the platform to override the allocation granularity: this allows
21 * systems that have the capability to run with a larger page size to deal
22 * with the allocations for initrd and fdt more efficiently.
24 #ifndef EFI_ALLOC_ALIGN
25 #define EFI_ALLOC_ALIGN EFI_PAGE_SIZE
29 #define __efistub_global __section(.data)
31 #define __efistub_global
34 extern bool __pure nochunk(void);
35 extern bool __pure nokaslr(void);
36 extern bool __pure is_quiet(void);
37 extern bool __pure novamap(void);
39 extern __pure efi_system_table_t *efi_system_table(void);
41 #define pr_efi(msg) do { \
42 if (!is_quiet()) efi_printk("EFI stub: "msg); \
45 #define pr_efi_err(msg) efi_printk("EFI stub: ERROR: "msg)
47 /* Helper macros for the usual case of using simple C variables: */
48 #ifndef fdt_setprop_inplace_var
49 #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \
50 fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))
53 #ifndef fdt_setprop_var
54 #define fdt_setprop_var(fdt, node_offset, name, var) \
55 fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))
58 #define get_efi_var(name, vendor, ...) \
59 efi_rt_call(get_variable, (efi_char16_t *)(name), \
60 (efi_guid_t *)(vendor), __VA_ARGS__)
62 #define set_efi_var(name, vendor, ...) \
63 efi_rt_call(set_variable, (efi_char16_t *)(name), \
64 (efi_guid_t *)(vendor), __VA_ARGS__)
66 #define efi_get_handle_at(array, idx) \
67 (efi_is_native() ? (array)[idx] \
68 : (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
70 #define efi_get_handle_num(size) \
71 ((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))
73 #define for_each_efi_handle(handle, array, size, i) \
75 i < efi_get_handle_num(size) && \
76 ((handle = efi_get_handle_at((array), i)) || true); \
80 * Allocation types for calls to boottime->allocate_pages.
82 #define EFI_ALLOCATE_ANY_PAGES 0
83 #define EFI_ALLOCATE_MAX_ADDRESS 1
84 #define EFI_ALLOCATE_ADDRESS 2
85 #define EFI_MAX_ALLOCATE_TYPE 3
88 * The type of search to perform when calling boottime->locate_handle
90 #define EFI_LOCATE_ALL_HANDLES 0
91 #define EFI_LOCATE_BY_REGISTER_NOTIFY 1
92 #define EFI_LOCATE_BY_PROTOCOL 2
94 struct efi_boot_memmap {
95 efi_memory_desc_t **map;
96 unsigned long *map_size;
97 unsigned long *desc_size;
99 unsigned long *key_ptr;
100 unsigned long *buff_size;
104 * EFI Boot Services table
106 union efi_boot_services {
111 efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,
112 efi_physical_addr_t *);
113 efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,
115 efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,
117 unsigned long *, u32 *);
118 efi_status_t (__efiapi *allocate_pool)(int, unsigned long,
120 efi_status_t (__efiapi *free_pool)(void *);
123 void *wait_for_event;
127 void *install_protocol_interface;
128 void *reinstall_protocol_interface;
129 void *uninstall_protocol_interface;
130 efi_status_t (__efiapi *handle_protocol)(efi_handle_t,
131 efi_guid_t *, void **);
133 void *register_protocol_notify;
134 efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,
135 void *, unsigned long *,
137 void *locate_device_path;
138 efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,
144 efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,
146 void *get_next_monotonic_count;
148 void *set_watchdog_timer;
149 void *connect_controller;
150 efi_status_t (__efiapi *disconnect_controller)(efi_handle_t,
154 void *close_protocol;
155 void *open_protocol_information;
156 void *protocols_per_handle;
157 void *locate_handle_buffer;
158 efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,
160 void *install_multiple_protocol_interfaces;
161 void *uninstall_multiple_protocol_interfaces;
162 void *calculate_crc32;
165 void *create_event_ex;
182 u32 install_protocol_interface;
183 u32 reinstall_protocol_interface;
184 u32 uninstall_protocol_interface;
187 u32 register_protocol_notify;
189 u32 locate_device_path;
190 u32 install_configuration_table;
195 u32 exit_boot_services;
196 u32 get_next_monotonic_count;
198 u32 set_watchdog_timer;
199 u32 connect_controller;
200 u32 disconnect_controller;
203 u32 open_protocol_information;
204 u32 protocols_per_handle;
205 u32 locate_handle_buffer;
207 u32 install_multiple_protocol_interfaces;
208 u32 uninstall_multiple_protocol_interfaces;
216 typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
218 union efi_uga_draw_protocol {
220 efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,
221 u32*, u32*, u32*, u32*);
232 union efi_simple_text_output_protocol {
235 efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
246 #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0
247 #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1
248 #define PIXEL_BIT_MASK 2
249 #define PIXEL_BLT_ONLY 3
250 #define PIXEL_FORMAT_MAX 4
257 } efi_pixel_bitmask_t;
261 u32 horizontal_resolution;
262 u32 vertical_resolution;
264 efi_pixel_bitmask_t pixel_information;
265 u32 pixels_per_scan_line;
266 } efi_graphics_output_mode_info_t;
268 typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;
270 union efi_graphics_output_protocol_mode {
274 efi_graphics_output_mode_info_t *info;
275 unsigned long size_of_info;
276 efi_physical_addr_t frame_buffer_base;
277 unsigned long frame_buffer_size;
284 u64 frame_buffer_base;
285 u32 frame_buffer_size;
289 typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;
291 union efi_graphics_output_protocol {
296 efi_graphics_output_protocol_mode_t *mode;
308 efi_handle_t parent_handle;
309 efi_system_table_t *system_table;
310 efi_handle_t device_handle;
313 u32 load_options_size;
316 __aligned_u64 image_size;
317 unsigned int image_code_type;
318 unsigned int image_data_type;
319 efi_status_t (__efiapi *unload)(efi_handle_t image_handle);
320 } efi_loaded_image_t;
326 efi_time_t create_time;
327 efi_time_t last_access_time;
328 efi_time_t modification_time;
329 __aligned_u64 attribute;
330 efi_char16_t filename[];
333 typedef struct efi_file_protocol efi_file_protocol_t;
335 struct efi_file_protocol {
337 efi_status_t (__efiapi *open) (efi_file_protocol_t *,
338 efi_file_protocol_t **,
339 efi_char16_t *, u64, u64);
340 efi_status_t (__efiapi *close) (efi_file_protocol_t *);
341 efi_status_t (__efiapi *delete) (efi_file_protocol_t *);
342 efi_status_t (__efiapi *read) (efi_file_protocol_t *,
343 unsigned long *, void *);
344 efi_status_t (__efiapi *write) (efi_file_protocol_t *,
345 unsigned long, void *);
346 efi_status_t (__efiapi *get_position)(efi_file_protocol_t *, u64 *);
347 efi_status_t (__efiapi *set_position)(efi_file_protocol_t *, u64);
348 efi_status_t (__efiapi *get_info) (efi_file_protocol_t *,
349 efi_guid_t *, unsigned long *,
351 efi_status_t (__efiapi *set_info) (efi_file_protocol_t *,
352 efi_guid_t *, unsigned long,
354 efi_status_t (__efiapi *flush) (efi_file_protocol_t *);
357 typedef struct efi_simple_file_system_protocol efi_simple_file_system_protocol_t;
359 struct efi_simple_file_system_protocol {
361 int (__efiapi *open_volume)(efi_simple_file_system_protocol_t *,
362 efi_file_protocol_t **);
365 #define EFI_FILE_MODE_READ 0x0000000000000001
366 #define EFI_FILE_MODE_WRITE 0x0000000000000002
367 #define EFI_FILE_MODE_CREATE 0x8000000000000000
374 EfiPciIoWidthFifoUint8,
375 EfiPciIoWidthFifoUint16,
376 EfiPciIoWidthFifoUint32,
377 EfiPciIoWidthFifoUint64,
378 EfiPciIoWidthFillUint8,
379 EfiPciIoWidthFillUint16,
380 EfiPciIoWidthFillUint32,
381 EfiPciIoWidthFillUint64,
383 } EFI_PCI_IO_PROTOCOL_WIDTH;
386 EfiPciIoAttributeOperationGet,
387 EfiPciIoAttributeOperationSet,
388 EfiPciIoAttributeOperationEnable,
389 EfiPciIoAttributeOperationDisable,
390 EfiPciIoAttributeOperationSupported,
391 EfiPciIoAttributeOperationMaximum
392 } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
397 } efi_pci_io_protocol_access_32_t;
399 typedef union efi_pci_io_protocol efi_pci_io_protocol_t;
402 efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
403 EFI_PCI_IO_PROTOCOL_WIDTH,
411 } efi_pci_io_protocol_access_t;
414 efi_pci_io_protocol_cfg_t read;
415 efi_pci_io_protocol_cfg_t write;
416 } efi_pci_io_protocol_config_access_t;
418 union efi_pci_io_protocol {
422 efi_pci_io_protocol_access_t mem;
423 efi_pci_io_protocol_access_t io;
424 efi_pci_io_protocol_config_access_t pci;
428 void *allocate_buffer;
431 efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,
432 unsigned long *segment_nr,
433 unsigned long *bus_nr,
434 unsigned long *device_nr,
435 unsigned long *func_nr);
437 void *get_bar_attributes;
438 void *set_bar_attributes;
445 efi_pci_io_protocol_access_32_t mem;
446 efi_pci_io_protocol_access_32_t io;
447 efi_pci_io_protocol_access_32_t pci;
456 u32 get_bar_attributes;
457 u32 set_bar_attributes;
463 #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
464 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
465 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
466 #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
467 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
468 #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
469 #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
470 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
471 #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
472 #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
473 #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
474 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
475 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
476 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
477 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
478 #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
479 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
480 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
481 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
485 typedef union apple_properties_protocol apple_properties_protocol_t;
487 union apple_properties_protocol {
489 unsigned long version;
490 efi_status_t (__efiapi *get)(apple_properties_protocol_t *,
491 struct efi_dev_path *,
492 efi_char16_t *, void *, u32 *);
493 efi_status_t (__efiapi *set)(apple_properties_protocol_t *,
494 struct efi_dev_path *,
495 efi_char16_t *, void *, u32);
496 efi_status_t (__efiapi *del)(apple_properties_protocol_t *,
497 struct efi_dev_path *,
499 efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,
500 void *buffer, u32 *);
511 typedef u32 efi_tcg2_event_log_format;
513 typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
515 union efi_tcg2_protocol {
517 void *get_capability;
518 efi_status_t (__efiapi *get_event_log)(efi_handle_t,
519 efi_tcg2_event_log_format,
520 efi_physical_addr_t *,
521 efi_physical_addr_t *,
523 void *hash_log_extend_event;
524 void *submit_command;
525 void *get_active_pcr_banks;
526 void *set_active_pcr_banks;
527 void *get_result_of_set_active_pcr_banks;
532 u32 hash_log_extend_event;
534 u32 get_active_pcr_banks;
535 u32 set_active_pcr_banks;
536 u32 get_result_of_set_active_pcr_banks;
540 void efi_pci_disable_bridge_busmaster(void);
542 typedef efi_status_t (*efi_exit_boot_map_processing)(
543 struct efi_boot_memmap *map,
546 efi_status_t efi_exit_boot_services(void *handle,
547 struct efi_boot_memmap *map,
549 efi_exit_boot_map_processing priv_func);
551 void efi_char16_printk(efi_char16_t *);
553 efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
554 unsigned long *new_fdt_addr,
555 unsigned long max_addr,
556 u64 initrd_addr, u64 initrd_size,
558 unsigned long fdt_addr,
559 unsigned long fdt_size);
561 void *get_fdt(unsigned long *fdt_size);
563 void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
564 unsigned long desc_size, efi_memory_desc_t *runtime_map,
567 efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
569 efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
570 unsigned long *addr, unsigned long random_seed);
572 efi_status_t check_platform_features(void);
574 void *get_efi_config_table(efi_guid_t guid);
576 void efi_printk(char *str);
578 void efi_free(unsigned long size, unsigned long addr);
580 char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len,
581 unsigned long max_addr);
583 efi_status_t efi_get_memory_map(struct efi_boot_memmap *map);
585 efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,
586 unsigned long *addr, unsigned long min);
589 efi_status_t efi_low_alloc(unsigned long size, unsigned long align,
593 * Don't allocate at 0x0. It will confuse code that
594 * checks pointers against NULL. Skip the first 8
595 * bytes so we start at a nice even number.
597 return efi_low_alloc_above(size, align, addr, 0x8);
600 efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,
603 efi_status_t efi_relocate_kernel(unsigned long *image_addr,
604 unsigned long image_size,
605 unsigned long alloc_size,
606 unsigned long preferred_addr,
607 unsigned long alignment,
608 unsigned long min_addr);
610 efi_status_t efi_parse_options(char const *cmdline);
612 efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto,
615 efi_status_t efi_load_dtb(efi_loaded_image_t *image,
616 unsigned long *load_addr,
617 unsigned long *load_size);
619 efi_status_t efi_load_initrd(efi_loaded_image_t *image,
620 unsigned long *load_addr,
621 unsigned long *load_size,
622 unsigned long soft_limit,
623 unsigned long hard_limit);