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
28 #if defined(CONFIG_ARM) || defined(CONFIG_X86)
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
96 * An efi_boot_memmap is used by efi_get_memory_map() to return the
97 * EFI memory map in a dynamically allocated buffer.
99 * The buffer allocated for the EFI memory map includes extra room for
100 * a minimum of EFI_MMAP_NR_SLACK_SLOTS additional EFI memory descriptors.
101 * This facilitates the reuse of the EFI memory map buffer when a second
102 * call to ExitBootServices() is needed because of intervening changes to
103 * the EFI memory map. Other related structures, e.g. x86 e820ext, need
104 * to factor in this headroom requirement as well.
106 #define EFI_MMAP_NR_SLACK_SLOTS 8
108 struct efi_boot_memmap
{
109 efi_memory_desc_t
**map
;
110 unsigned long *map_size
;
111 unsigned long *desc_size
;
113 unsigned long *key_ptr
;
114 unsigned long *buff_size
;
117 typedef struct efi_generic_dev_path efi_device_path_protocol_t
;
120 * EFI Boot Services table
122 union efi_boot_services
{
127 efi_status_t (__efiapi
*allocate_pages
)(int, int, unsigned long,
128 efi_physical_addr_t
*);
129 efi_status_t (__efiapi
*free_pages
)(efi_physical_addr_t
,
131 efi_status_t (__efiapi
*get_memory_map
)(unsigned long *, void *,
133 unsigned long *, u32
*);
134 efi_status_t (__efiapi
*allocate_pool
)(int, unsigned long,
136 efi_status_t (__efiapi
*free_pool
)(void *);
139 void *wait_for_event
;
143 void *install_protocol_interface
;
144 void *reinstall_protocol_interface
;
145 void *uninstall_protocol_interface
;
146 efi_status_t (__efiapi
*handle_protocol
)(efi_handle_t
,
147 efi_guid_t
*, void **);
149 void *register_protocol_notify
;
150 efi_status_t (__efiapi
*locate_handle
)(int, efi_guid_t
*,
151 void *, unsigned long *,
153 efi_status_t (__efiapi
*locate_device_path
)(efi_guid_t
*,
154 efi_device_path_protocol_t
**,
156 efi_status_t (__efiapi
*install_configuration_table
)(efi_guid_t
*,
160 efi_status_t
__noreturn (__efiapi
*exit
)(efi_handle_t
,
165 efi_status_t (__efiapi
*exit_boot_services
)(efi_handle_t
,
167 void *get_next_monotonic_count
;
169 void *set_watchdog_timer
;
170 void *connect_controller
;
171 efi_status_t (__efiapi
*disconnect_controller
)(efi_handle_t
,
175 void *close_protocol
;
176 void *open_protocol_information
;
177 void *protocols_per_handle
;
178 void *locate_handle_buffer
;
179 efi_status_t (__efiapi
*locate_protocol
)(efi_guid_t
*, void *,
181 void *install_multiple_protocol_interfaces
;
182 void *uninstall_multiple_protocol_interfaces
;
183 void *calculate_crc32
;
186 void *create_event_ex
;
203 u32 install_protocol_interface
;
204 u32 reinstall_protocol_interface
;
205 u32 uninstall_protocol_interface
;
208 u32 register_protocol_notify
;
210 u32 locate_device_path
;
211 u32 install_configuration_table
;
216 u32 exit_boot_services
;
217 u32 get_next_monotonic_count
;
219 u32 set_watchdog_timer
;
220 u32 connect_controller
;
221 u32 disconnect_controller
;
224 u32 open_protocol_information
;
225 u32 protocols_per_handle
;
226 u32 locate_handle_buffer
;
228 u32 install_multiple_protocol_interfaces
;
229 u32 uninstall_multiple_protocol_interfaces
;
237 typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t
;
239 union efi_uga_draw_protocol
{
241 efi_status_t (__efiapi
*get_mode
)(efi_uga_draw_protocol_t
*,
242 u32
*, u32
*, u32
*, u32
*);
253 union efi_simple_text_output_protocol
{
256 efi_status_t (__efiapi
*output_string
)(efi_simple_text_output_protocol_t
*,
267 #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0
268 #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1
269 #define PIXEL_BIT_MASK 2
270 #define PIXEL_BLT_ONLY 3
271 #define PIXEL_FORMAT_MAX 4
278 } efi_pixel_bitmask_t
;
282 u32 horizontal_resolution
;
283 u32 vertical_resolution
;
285 efi_pixel_bitmask_t pixel_information
;
286 u32 pixels_per_scan_line
;
287 } efi_graphics_output_mode_info_t
;
289 typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t
;
291 union efi_graphics_output_protocol_mode
{
295 efi_graphics_output_mode_info_t
*info
;
296 unsigned long size_of_info
;
297 efi_physical_addr_t frame_buffer_base
;
298 unsigned long frame_buffer_size
;
305 u64 frame_buffer_base
;
306 u32 frame_buffer_size
;
310 typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t
;
312 union efi_graphics_output_protocol
{
317 efi_graphics_output_protocol_mode_t
*mode
;
330 efi_handle_t parent_handle
;
331 efi_system_table_t
*system_table
;
332 efi_handle_t device_handle
;
335 u32 load_options_size
;
338 __aligned_u64 image_size
;
339 unsigned int image_code_type
;
340 unsigned int image_data_type
;
341 efi_status_t (__efiapi
*unload
)(efi_handle_t image_handle
);
350 u32 load_options_size
;
353 __aligned_u64 image_size
;
358 } efi_loaded_image_t
;
364 efi_time_t create_time
;
365 efi_time_t last_access_time
;
366 efi_time_t modification_time
;
367 __aligned_u64 attribute
;
368 efi_char16_t filename
[];
371 typedef struct efi_file_protocol efi_file_protocol_t
;
373 struct efi_file_protocol
{
375 efi_status_t (__efiapi
*open
) (efi_file_protocol_t
*,
376 efi_file_protocol_t
**,
377 efi_char16_t
*, u64
, u64
);
378 efi_status_t (__efiapi
*close
) (efi_file_protocol_t
*);
379 efi_status_t (__efiapi
*delete) (efi_file_protocol_t
*);
380 efi_status_t (__efiapi
*read
) (efi_file_protocol_t
*,
381 unsigned long *, void *);
382 efi_status_t (__efiapi
*write
) (efi_file_protocol_t
*,
383 unsigned long, void *);
384 efi_status_t (__efiapi
*get_position
)(efi_file_protocol_t
*, u64
*);
385 efi_status_t (__efiapi
*set_position
)(efi_file_protocol_t
*, u64
);
386 efi_status_t (__efiapi
*get_info
) (efi_file_protocol_t
*,
387 efi_guid_t
*, unsigned long *,
389 efi_status_t (__efiapi
*set_info
) (efi_file_protocol_t
*,
390 efi_guid_t
*, unsigned long,
392 efi_status_t (__efiapi
*flush
) (efi_file_protocol_t
*);
395 typedef struct efi_simple_file_system_protocol efi_simple_file_system_protocol_t
;
397 struct efi_simple_file_system_protocol
{
399 int (__efiapi
*open_volume
)(efi_simple_file_system_protocol_t
*,
400 efi_file_protocol_t
**);
403 #define EFI_FILE_MODE_READ 0x0000000000000001
404 #define EFI_FILE_MODE_WRITE 0x0000000000000002
405 #define EFI_FILE_MODE_CREATE 0x8000000000000000
412 EfiPciIoWidthFifoUint8
,
413 EfiPciIoWidthFifoUint16
,
414 EfiPciIoWidthFifoUint32
,
415 EfiPciIoWidthFifoUint64
,
416 EfiPciIoWidthFillUint8
,
417 EfiPciIoWidthFillUint16
,
418 EfiPciIoWidthFillUint32
,
419 EfiPciIoWidthFillUint64
,
421 } EFI_PCI_IO_PROTOCOL_WIDTH
;
424 EfiPciIoAttributeOperationGet
,
425 EfiPciIoAttributeOperationSet
,
426 EfiPciIoAttributeOperationEnable
,
427 EfiPciIoAttributeOperationDisable
,
428 EfiPciIoAttributeOperationSupported
,
429 EfiPciIoAttributeOperationMaximum
430 } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION
;
435 } efi_pci_io_protocol_access_32_t
;
437 typedef union efi_pci_io_protocol efi_pci_io_protocol_t
;
440 efi_status_t (__efiapi
*efi_pci_io_protocol_cfg_t
)(efi_pci_io_protocol_t
*,
441 EFI_PCI_IO_PROTOCOL_WIDTH
,
449 } efi_pci_io_protocol_access_t
;
452 efi_pci_io_protocol_cfg_t read
;
453 efi_pci_io_protocol_cfg_t write
;
454 } efi_pci_io_protocol_config_access_t
;
456 union efi_pci_io_protocol
{
460 efi_pci_io_protocol_access_t mem
;
461 efi_pci_io_protocol_access_t io
;
462 efi_pci_io_protocol_config_access_t pci
;
466 void *allocate_buffer
;
469 efi_status_t (__efiapi
*get_location
)(efi_pci_io_protocol_t
*,
470 unsigned long *segment_nr
,
471 unsigned long *bus_nr
,
472 unsigned long *device_nr
,
473 unsigned long *func_nr
);
475 void *get_bar_attributes
;
476 void *set_bar_attributes
;
483 efi_pci_io_protocol_access_32_t mem
;
484 efi_pci_io_protocol_access_32_t io
;
485 efi_pci_io_protocol_access_32_t pci
;
494 u32 get_bar_attributes
;
495 u32 set_bar_attributes
;
501 #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
502 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
503 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
504 #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
505 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
506 #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
507 #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
508 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
509 #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
510 #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
511 #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
512 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
513 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
514 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
515 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
516 #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
517 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
518 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
519 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
523 typedef union apple_properties_protocol apple_properties_protocol_t
;
525 union apple_properties_protocol
{
527 unsigned long version
;
528 efi_status_t (__efiapi
*get
)(apple_properties_protocol_t
*,
529 struct efi_dev_path
*,
530 efi_char16_t
*, void *, u32
*);
531 efi_status_t (__efiapi
*set
)(apple_properties_protocol_t
*,
532 struct efi_dev_path
*,
533 efi_char16_t
*, void *, u32
);
534 efi_status_t (__efiapi
*del
)(apple_properties_protocol_t
*,
535 struct efi_dev_path
*,
537 efi_status_t (__efiapi
*get_all
)(apple_properties_protocol_t
*,
538 void *buffer
, u32
*);
549 typedef u32 efi_tcg2_event_log_format
;
551 typedef union efi_tcg2_protocol efi_tcg2_protocol_t
;
553 union efi_tcg2_protocol
{
555 void *get_capability
;
556 efi_status_t (__efiapi
*get_event_log
)(efi_handle_t
,
557 efi_tcg2_event_log_format
,
558 efi_physical_addr_t
*,
559 efi_physical_addr_t
*,
561 void *hash_log_extend_event
;
562 void *submit_command
;
563 void *get_active_pcr_banks
;
564 void *set_active_pcr_banks
;
565 void *get_result_of_set_active_pcr_banks
;
570 u32 hash_log_extend_event
;
572 u32 get_active_pcr_banks
;
573 u32 set_active_pcr_banks
;
574 u32 get_result_of_set_active_pcr_banks
;
578 typedef union efi_load_file_protocol efi_load_file_protocol_t
;
579 typedef union efi_load_file_protocol efi_load_file2_protocol_t
;
581 union efi_load_file_protocol
{
583 efi_status_t (__efiapi
*load_file
)(efi_load_file_protocol_t
*,
584 efi_device_path_protocol_t
*,
585 bool, unsigned long *, void *);
592 void efi_pci_disable_bridge_busmaster(void);
594 typedef efi_status_t (*efi_exit_boot_map_processing
)(
595 struct efi_boot_memmap
*map
,
598 efi_status_t
efi_exit_boot_services(void *handle
,
599 struct efi_boot_memmap
*map
,
601 efi_exit_boot_map_processing priv_func
);
603 void efi_char16_printk(efi_char16_t
*);
605 efi_status_t
allocate_new_fdt_and_exit_boot(void *handle
,
606 unsigned long *new_fdt_addr
,
607 unsigned long max_addr
,
608 u64 initrd_addr
, u64 initrd_size
,
610 unsigned long fdt_addr
,
611 unsigned long fdt_size
);
613 void *get_fdt(unsigned long *fdt_size
);
615 void efi_get_virtmap(efi_memory_desc_t
*memory_map
, unsigned long map_size
,
616 unsigned long desc_size
, efi_memory_desc_t
*runtime_map
,
619 efi_status_t
efi_get_random_bytes(unsigned long size
, u8
*out
);
621 efi_status_t
efi_random_alloc(unsigned long size
, unsigned long align
,
622 unsigned long *addr
, unsigned long random_seed
);
624 efi_status_t
check_platform_features(void);
626 void *get_efi_config_table(efi_guid_t guid
);
628 void efi_printk(char *str
);
630 void efi_free(unsigned long size
, unsigned long addr
);
632 char *efi_convert_cmdline(efi_loaded_image_t
*image
, int *cmd_line_len
,
633 unsigned long max_addr
);
635 efi_status_t
efi_get_memory_map(struct efi_boot_memmap
*map
);
637 efi_status_t
efi_low_alloc_above(unsigned long size
, unsigned long align
,
638 unsigned long *addr
, unsigned long min
);
641 efi_status_t
efi_low_alloc(unsigned long size
, unsigned long align
,
645 * Don't allocate at 0x0. It will confuse code that
646 * checks pointers against NULL. Skip the first 8
647 * bytes so we start at a nice even number.
649 return efi_low_alloc_above(size
, align
, addr
, 0x8);
652 efi_status_t
efi_allocate_pages(unsigned long size
, unsigned long *addr
,
655 efi_status_t
efi_relocate_kernel(unsigned long *image_addr
,
656 unsigned long image_size
,
657 unsigned long alloc_size
,
658 unsigned long preferred_addr
,
659 unsigned long alignment
,
660 unsigned long min_addr
);
662 efi_status_t
efi_parse_options(char const *cmdline
);
664 efi_status_t
efi_setup_gop(struct screen_info
*si
, efi_guid_t
*proto
,
667 efi_status_t
efi_load_dtb(efi_loaded_image_t
*image
,
668 unsigned long *load_addr
,
669 unsigned long *load_size
);
671 efi_status_t
efi_load_initrd(efi_loaded_image_t
*image
,
672 unsigned long *load_addr
,
673 unsigned long *load_size
,
674 unsigned long soft_limit
,
675 unsigned long hard_limit
);
677 efi_status_t
efi_load_initrd_dev_path(unsigned long *load_addr
,
678 unsigned long *load_size
,