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 noinitrd(void);
37 extern bool __pure is_quiet(void);
38 extern bool __pure novamap(void);
40 extern __pure efi_system_table_t *efi_system_table(void);
42 #define pr_efi(msg) do { \
43 if (!is_quiet()) efi_printk("EFI stub: "msg); \
46 #define pr_efi_err(msg) efi_printk("EFI stub: ERROR: "msg)
48 /* Helper macros for the usual case of using simple C variables: */
49 #ifndef fdt_setprop_inplace_var
50 #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \
51 fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))
54 #ifndef fdt_setprop_var
55 #define fdt_setprop_var(fdt, node_offset, name, var) \
56 fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))
59 #define get_efi_var(name, vendor, ...) \
60 efi_rt_call(get_variable, (efi_char16_t *)(name), \
61 (efi_guid_t *)(vendor), __VA_ARGS__)
63 #define set_efi_var(name, vendor, ...) \
64 efi_rt_call(set_variable, (efi_char16_t *)(name), \
65 (efi_guid_t *)(vendor), __VA_ARGS__)
67 #define efi_get_handle_at(array, idx) \
68 (efi_is_native() ? (array)[idx] \
69 : (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
71 #define efi_get_handle_num(size) \
72 ((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))
74 #define for_each_efi_handle(handle, array, size, i) \
76 i < efi_get_handle_num(size) && \
77 ((handle = efi_get_handle_at((array), i)) || true); \
81 * Allocation types for calls to boottime->allocate_pages.
83 #define EFI_ALLOCATE_ANY_PAGES 0
84 #define EFI_ALLOCATE_MAX_ADDRESS 1
85 #define EFI_ALLOCATE_ADDRESS 2
86 #define EFI_MAX_ALLOCATE_TYPE 3
89 * The type of search to perform when calling boottime->locate_handle
91 #define EFI_LOCATE_ALL_HANDLES 0
92 #define EFI_LOCATE_BY_REGISTER_NOTIFY 1
93 #define EFI_LOCATE_BY_PROTOCOL 2
95 struct efi_boot_memmap {
96 efi_memory_desc_t **map;
97 unsigned long *map_size;
98 unsigned long *desc_size;
100 unsigned long *key_ptr;
101 unsigned long *buff_size;
104 typedef struct efi_generic_dev_path efi_device_path_protocol_t;
107 * EFI Boot Services table
109 union efi_boot_services {
114 efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,
115 efi_physical_addr_t *);
116 efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,
118 efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,
120 unsigned long *, u32 *);
121 efi_status_t (__efiapi *allocate_pool)(int, unsigned long,
123 efi_status_t (__efiapi *free_pool)(void *);
126 void *wait_for_event;
130 void *install_protocol_interface;
131 void *reinstall_protocol_interface;
132 void *uninstall_protocol_interface;
133 efi_status_t (__efiapi *handle_protocol)(efi_handle_t,
134 efi_guid_t *, void **);
136 void *register_protocol_notify;
137 efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,
138 void *, unsigned long *,
140 efi_status_t (__efiapi *locate_device_path)(efi_guid_t *,
141 efi_device_path_protocol_t **,
143 efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,
147 efi_status_t __noreturn (__efiapi *exit)(efi_handle_t,
152 efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,
154 void *get_next_monotonic_count;
156 void *set_watchdog_timer;
157 void *connect_controller;
158 efi_status_t (__efiapi *disconnect_controller)(efi_handle_t,
162 void *close_protocol;
163 void *open_protocol_information;
164 void *protocols_per_handle;
165 void *locate_handle_buffer;
166 efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,
168 void *install_multiple_protocol_interfaces;
169 void *uninstall_multiple_protocol_interfaces;
170 void *calculate_crc32;
173 void *create_event_ex;
190 u32 install_protocol_interface;
191 u32 reinstall_protocol_interface;
192 u32 uninstall_protocol_interface;
195 u32 register_protocol_notify;
197 u32 locate_device_path;
198 u32 install_configuration_table;
203 u32 exit_boot_services;
204 u32 get_next_monotonic_count;
206 u32 set_watchdog_timer;
207 u32 connect_controller;
208 u32 disconnect_controller;
211 u32 open_protocol_information;
212 u32 protocols_per_handle;
213 u32 locate_handle_buffer;
215 u32 install_multiple_protocol_interfaces;
216 u32 uninstall_multiple_protocol_interfaces;
224 typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
226 union efi_uga_draw_protocol {
228 efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,
229 u32*, u32*, u32*, u32*);
240 union efi_simple_text_output_protocol {
243 efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
254 #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0
255 #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1
256 #define PIXEL_BIT_MASK 2
257 #define PIXEL_BLT_ONLY 3
258 #define PIXEL_FORMAT_MAX 4
265 } efi_pixel_bitmask_t;
269 u32 horizontal_resolution;
270 u32 vertical_resolution;
272 efi_pixel_bitmask_t pixel_information;
273 u32 pixels_per_scan_line;
274 } efi_graphics_output_mode_info_t;
276 typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;
278 union efi_graphics_output_protocol_mode {
282 efi_graphics_output_mode_info_t *info;
283 unsigned long size_of_info;
284 efi_physical_addr_t frame_buffer_base;
285 unsigned long frame_buffer_size;
292 u64 frame_buffer_base;
293 u32 frame_buffer_size;
297 typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;
299 union efi_graphics_output_protocol {
304 efi_graphics_output_protocol_mode_t *mode;
317 efi_handle_t parent_handle;
318 efi_system_table_t *system_table;
319 efi_handle_t device_handle;
322 u32 load_options_size;
325 __aligned_u64 image_size;
326 unsigned int image_code_type;
327 unsigned int image_data_type;
328 efi_status_t (__efiapi *unload)(efi_handle_t image_handle);
337 u32 load_options_size;
340 __aligned_u64 image_size;
345 } efi_loaded_image_t;
351 efi_time_t create_time;
352 efi_time_t last_access_time;
353 efi_time_t modification_time;
354 __aligned_u64 attribute;
355 efi_char16_t filename[];
358 typedef struct efi_file_protocol efi_file_protocol_t;
360 struct efi_file_protocol {
362 efi_status_t (__efiapi *open) (efi_file_protocol_t *,
363 efi_file_protocol_t **,
364 efi_char16_t *, u64, u64);
365 efi_status_t (__efiapi *close) (efi_file_protocol_t *);
366 efi_status_t (__efiapi *delete) (efi_file_protocol_t *);
367 efi_status_t (__efiapi *read) (efi_file_protocol_t *,
368 unsigned long *, void *);
369 efi_status_t (__efiapi *write) (efi_file_protocol_t *,
370 unsigned long, void *);
371 efi_status_t (__efiapi *get_position)(efi_file_protocol_t *, u64 *);
372 efi_status_t (__efiapi *set_position)(efi_file_protocol_t *, u64);
373 efi_status_t (__efiapi *get_info) (efi_file_protocol_t *,
374 efi_guid_t *, unsigned long *,
376 efi_status_t (__efiapi *set_info) (efi_file_protocol_t *,
377 efi_guid_t *, unsigned long,
379 efi_status_t (__efiapi *flush) (efi_file_protocol_t *);
382 typedef struct efi_simple_file_system_protocol efi_simple_file_system_protocol_t;
384 struct efi_simple_file_system_protocol {
386 int (__efiapi *open_volume)(efi_simple_file_system_protocol_t *,
387 efi_file_protocol_t **);
390 #define EFI_FILE_MODE_READ 0x0000000000000001
391 #define EFI_FILE_MODE_WRITE 0x0000000000000002
392 #define EFI_FILE_MODE_CREATE 0x8000000000000000
399 EfiPciIoWidthFifoUint8,
400 EfiPciIoWidthFifoUint16,
401 EfiPciIoWidthFifoUint32,
402 EfiPciIoWidthFifoUint64,
403 EfiPciIoWidthFillUint8,
404 EfiPciIoWidthFillUint16,
405 EfiPciIoWidthFillUint32,
406 EfiPciIoWidthFillUint64,
408 } EFI_PCI_IO_PROTOCOL_WIDTH;
411 EfiPciIoAttributeOperationGet,
412 EfiPciIoAttributeOperationSet,
413 EfiPciIoAttributeOperationEnable,
414 EfiPciIoAttributeOperationDisable,
415 EfiPciIoAttributeOperationSupported,
416 EfiPciIoAttributeOperationMaximum
417 } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
422 } efi_pci_io_protocol_access_32_t;
424 typedef union efi_pci_io_protocol efi_pci_io_protocol_t;
427 efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
428 EFI_PCI_IO_PROTOCOL_WIDTH,
436 } efi_pci_io_protocol_access_t;
439 efi_pci_io_protocol_cfg_t read;
440 efi_pci_io_protocol_cfg_t write;
441 } efi_pci_io_protocol_config_access_t;
443 union efi_pci_io_protocol {
447 efi_pci_io_protocol_access_t mem;
448 efi_pci_io_protocol_access_t io;
449 efi_pci_io_protocol_config_access_t pci;
453 void *allocate_buffer;
456 efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,
457 unsigned long *segment_nr,
458 unsigned long *bus_nr,
459 unsigned long *device_nr,
460 unsigned long *func_nr);
462 void *get_bar_attributes;
463 void *set_bar_attributes;
470 efi_pci_io_protocol_access_32_t mem;
471 efi_pci_io_protocol_access_32_t io;
472 efi_pci_io_protocol_access_32_t pci;
481 u32 get_bar_attributes;
482 u32 set_bar_attributes;
488 #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
489 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
490 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
491 #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
492 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
493 #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
494 #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
495 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
496 #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
497 #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
498 #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
499 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
500 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
501 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
502 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
503 #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
504 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
505 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
506 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
510 typedef union apple_properties_protocol apple_properties_protocol_t;
512 union apple_properties_protocol {
514 unsigned long version;
515 efi_status_t (__efiapi *get)(apple_properties_protocol_t *,
516 struct efi_dev_path *,
517 efi_char16_t *, void *, u32 *);
518 efi_status_t (__efiapi *set)(apple_properties_protocol_t *,
519 struct efi_dev_path *,
520 efi_char16_t *, void *, u32);
521 efi_status_t (__efiapi *del)(apple_properties_protocol_t *,
522 struct efi_dev_path *,
524 efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,
525 void *buffer, u32 *);
536 typedef u32 efi_tcg2_event_log_format;
538 typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
540 union efi_tcg2_protocol {
542 void *get_capability;
543 efi_status_t (__efiapi *get_event_log)(efi_handle_t,
544 efi_tcg2_event_log_format,
545 efi_physical_addr_t *,
546 efi_physical_addr_t *,
548 void *hash_log_extend_event;
549 void *submit_command;
550 void *get_active_pcr_banks;
551 void *set_active_pcr_banks;
552 void *get_result_of_set_active_pcr_banks;
557 u32 hash_log_extend_event;
559 u32 get_active_pcr_banks;
560 u32 set_active_pcr_banks;
561 u32 get_result_of_set_active_pcr_banks;
565 typedef union efi_load_file_protocol efi_load_file_protocol_t;
566 typedef union efi_load_file_protocol efi_load_file2_protocol_t;
568 union efi_load_file_protocol {
570 efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *,
571 efi_device_path_protocol_t *,
572 bool, unsigned long *, void *);
579 void efi_pci_disable_bridge_busmaster(void);
581 typedef efi_status_t (*efi_exit_boot_map_processing)(
582 struct efi_boot_memmap *map,
585 efi_status_t efi_exit_boot_services(void *handle,
586 struct efi_boot_memmap *map,
588 efi_exit_boot_map_processing priv_func);
590 void efi_char16_printk(efi_char16_t *);
592 efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
593 unsigned long *new_fdt_addr,
594 unsigned long max_addr,
595 u64 initrd_addr, u64 initrd_size,
597 unsigned long fdt_addr,
598 unsigned long fdt_size);
600 void *get_fdt(unsigned long *fdt_size);
602 void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
603 unsigned long desc_size, efi_memory_desc_t *runtime_map,
606 efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
608 efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
609 unsigned long *addr, unsigned long random_seed);
611 efi_status_t check_platform_features(void);
613 void *get_efi_config_table(efi_guid_t guid);
615 void efi_printk(char *str);
617 void efi_free(unsigned long size, unsigned long addr);
619 char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len,
620 unsigned long max_addr);
622 efi_status_t efi_get_memory_map(struct efi_boot_memmap *map);
624 efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,
625 unsigned long *addr, unsigned long min);
628 efi_status_t efi_low_alloc(unsigned long size, unsigned long align,
632 * Don't allocate at 0x0. It will confuse code that
633 * checks pointers against NULL. Skip the first 8
634 * bytes so we start at a nice even number.
636 return efi_low_alloc_above(size, align, addr, 0x8);
639 efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,
642 efi_status_t efi_relocate_kernel(unsigned long *image_addr,
643 unsigned long image_size,
644 unsigned long alloc_size,
645 unsigned long preferred_addr,
646 unsigned long alignment,
647 unsigned long min_addr);
649 efi_status_t efi_parse_options(char const *cmdline);
651 efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto,
654 efi_status_t efi_load_dtb(efi_loaded_image_t *image,
655 unsigned long *load_addr,
656 unsigned long *load_size);
658 efi_status_t efi_load_initrd(efi_loaded_image_t *image,
659 unsigned long *load_addr,
660 unsigned long *load_size,
661 unsigned long soft_limit,
662 unsigned long hard_limit);
664 efi_status_t efi_load_initrd_dev_path(unsigned long *load_addr,
665 unsigned long *load_size,