Path: blob/master/drivers/firmware/efi/libstub/efistub.h
51675 views
/* SPDX-License-Identifier: GPL-2.0 */12#ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H3#define _DRIVERS_FIRMWARE_EFI_EFISTUB_H45#include <linux/compiler.h>6#include <linux/cleanup.h>7#include <linux/efi.h>8#include <linux/kernel.h>9#include <linux/kern_levels.h>10#include <linux/types.h>11#include <asm/efi.h>1213/*14* __init annotations should not be used in the EFI stub, since the code is15* either included in the decompressor (x86, ARM) where they have no effect,16* or the whole stub is __init annotated at the section level (arm64), by17* renaming the sections, in which case the __init annotation will be18* redundant, and will result in section names like .init.init.text, and our19* linker script does not expect that.20*/21#undef __init2223/*24* Allow the platform to override the allocation granularity: this allows25* systems that have the capability to run with a larger page size to deal26* with the allocations for initrd and fdt more efficiently.27*/28#ifndef EFI_ALLOC_ALIGN29#define EFI_ALLOC_ALIGN EFI_PAGE_SIZE30#endif3132#ifndef EFI_ALLOC_LIMIT33#define EFI_ALLOC_LIMIT ULONG_MAX34#endif3536struct edid_info;37struct screen_info;38struct sysfb_display_info;3940extern bool efi_no5lvl;41extern bool efi_nochunk;42extern bool efi_nokaslr;43extern int efi_loglevel;44extern int efi_mem_encrypt;45extern bool efi_novamap;46extern const efi_system_table_t *efi_system_table;4748typedef union efi_dxe_services_table efi_dxe_services_table_t;49extern const efi_dxe_services_table_t *efi_dxe_table;5051efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,52efi_system_table_t *sys_table_arg);5354#ifndef ARCH_HAS_EFISTUB_WRAPPERS5556#define efi_is_native() (true)57#define efi_table_attr(inst, attr) (inst)->attr58#define efi_fn_call(inst, func, ...) (inst)->func(__VA_ARGS__)5960#endif6162#define efi_call_proto(inst, func, ...) ({ \63__typeof__(inst) __inst = (inst); \64efi_fn_call(__inst, func, __inst, ##__VA_ARGS__); \65})66#define efi_bs_call(func, ...) \67efi_fn_call(efi_table_attr(efi_system_table, boottime), func, ##__VA_ARGS__)68#define efi_rt_call(func, ...) \69efi_fn_call(efi_table_attr(efi_system_table, runtime), func, ##__VA_ARGS__)70#define efi_dxe_call(func, ...) \71efi_fn_call(efi_dxe_table, func, ##__VA_ARGS__)7273#define efi_info(fmt, ...) \74efi_printk(KERN_INFO fmt, ##__VA_ARGS__)75#define efi_warn(fmt, ...) \76efi_printk(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)77#define efi_err(fmt, ...) \78efi_printk(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)79#define efi_debug(fmt, ...) \80efi_printk(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)8182#define efi_printk_once(fmt, ...) \83({ \84static bool __print_once; \85bool __ret_print_once = !__print_once; \86\87if (!__print_once) { \88__print_once = true; \89efi_printk(fmt, ##__VA_ARGS__); \90} \91__ret_print_once; \92})9394#define efi_info_once(fmt, ...) \95efi_printk_once(KERN_INFO fmt, ##__VA_ARGS__)96#define efi_warn_once(fmt, ...) \97efi_printk_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)98#define efi_err_once(fmt, ...) \99efi_printk_once(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)100#define efi_debug_once(fmt, ...) \101efi_printk_once(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)102103/* Helper macros for the usual case of using simple C variables: */104#ifndef fdt_setprop_inplace_var105#define fdt_setprop_inplace_var(fdt, node_offset, name, var) \106fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))107#endif108109#ifndef fdt_setprop_var110#define fdt_setprop_var(fdt, node_offset, name, var) \111fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))112#endif113114#define get_efi_var(name, vendor, ...) \115efi_rt_call(get_variable, (efi_char16_t *)(name), \116(efi_guid_t *)(vendor), __VA_ARGS__)117118#define set_efi_var(name, vendor, ...) \119efi_rt_call(set_variable, (efi_char16_t *)(name), \120(efi_guid_t *)(vendor), __VA_ARGS__)121122#define efi_get_handle_at(array, idx) \123(efi_is_native() ? (array)[idx] \124: (efi_handle_t)(unsigned long)((u32 *)(array))[idx])125126#define efi_get_handle_num(size) \127((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))128129#define for_each_efi_handle(handle, array, num) \130for (int __i = 0; __i < (num) && \131((handle = efi_get_handle_at((array), __i)) || true); \132__i++)133134static inline135void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)136{137*lo = lower_32_bits(data);138*hi = upper_32_bits(data);139}140141/*142* Allocation types for calls to boottime->allocate_pages.143*/144#define EFI_ALLOCATE_ANY_PAGES 0145#define EFI_ALLOCATE_MAX_ADDRESS 1146#define EFI_ALLOCATE_ADDRESS 2147#define EFI_MAX_ALLOCATE_TYPE 3148149/*150* The type of search to perform when calling boottime->locate_handle151*/152#define EFI_LOCATE_ALL_HANDLES 0153#define EFI_LOCATE_BY_REGISTER_NOTIFY 1154#define EFI_LOCATE_BY_PROTOCOL 2155156/*157* boottime->stall takes the time period in microseconds158*/159#define EFI_USEC_PER_SEC 1000000160161/*162* boottime->set_timer takes the time in 100ns units163*/164#define EFI_100NSEC_PER_USEC ((u64)10)165166/*167* An efi_boot_memmap is used by efi_get_memory_map() to return the168* EFI memory map in a dynamically allocated buffer.169*170* The buffer allocated for the EFI memory map includes extra room for171* a minimum of EFI_MMAP_NR_SLACK_SLOTS additional EFI memory descriptors.172* This facilitates the reuse of the EFI memory map buffer when a second173* call to ExitBootServices() is needed because of intervening changes to174* the EFI memory map. Other related structures, e.g. x86 e820ext, need175* to factor in this headroom requirement as well.176*/177#define EFI_MMAP_NR_SLACK_SLOTS 32178179typedef struct efi_generic_dev_path efi_device_path_protocol_t;180181union efi_device_path_to_text_protocol {182struct {183efi_char16_t *(__efiapi *convert_device_node_to_text)(184const efi_device_path_protocol_t *,185bool, bool);186efi_char16_t *(__efiapi *convert_device_path_to_text)(187const efi_device_path_protocol_t *,188bool, bool);189};190struct {191u32 convert_device_node_to_text;192u32 convert_device_path_to_text;193} mixed_mode;194};195196typedef union efi_device_path_to_text_protocol efi_device_path_to_text_protocol_t;197198union efi_device_path_from_text_protocol {199struct {200efi_device_path_protocol_t *201(__efiapi *convert_text_to_device_node)(const efi_char16_t *);202efi_device_path_protocol_t *203(__efiapi *convert_text_to_device_path)(const efi_char16_t *);204};205struct {206u32 convert_text_to_device_node;207u32 convert_text_to_device_path;208} mixed_mode;209};210211typedef union efi_device_path_from_text_protocol efi_device_path_from_text_protocol_t;212213typedef void *efi_event_t;214/* Note that notifications won't work in mixed mode */215typedef void (__efiapi *efi_event_notify_t)(efi_event_t, void *);216217#define EFI_EVT_TIMER 0x80000000U218#define EFI_EVT_RUNTIME 0x40000000U219#define EFI_EVT_NOTIFY_WAIT 0x00000100U220#define EFI_EVT_NOTIFY_SIGNAL 0x00000200U221222/**223* efi_set_event_at() - add event to events array224*225* @events: array of UEFI events226* @ids: index where to put the event in the array227* @event: event to add to the aray228*229* boottime->wait_for_event() takes an array of events as input.230* Provide a helper to set it up correctly for mixed mode.231*/232static inline233void efi_set_event_at(efi_event_t *events, size_t idx, efi_event_t event)234{235if (efi_is_native())236events[idx] = event;237else238((u32 *)events)[idx] = (u32)(unsigned long)event;239}240241#define EFI_TPL_APPLICATION 4242#define EFI_TPL_CALLBACK 8243#define EFI_TPL_NOTIFY 16244#define EFI_TPL_HIGH_LEVEL 31245246typedef enum {247EfiTimerCancel,248EfiTimerPeriodic,249EfiTimerRelative250} EFI_TIMER_DELAY;251252/*253* EFI Boot Services table254*/255union efi_boot_services {256struct {257efi_table_hdr_t hdr;258void *raise_tpl;259void *restore_tpl;260efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,261efi_physical_addr_t *);262efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,263unsigned long);264efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,265unsigned long *,266unsigned long *, u32 *);267efi_status_t (__efiapi *allocate_pool)(int, unsigned long,268void **);269efi_status_t (__efiapi *free_pool)(void *);270efi_status_t (__efiapi *create_event)(u32, unsigned long,271efi_event_notify_t, void *,272efi_event_t *);273efi_status_t (__efiapi *set_timer)(efi_event_t,274EFI_TIMER_DELAY, u64);275efi_status_t (__efiapi *wait_for_event)(unsigned long,276efi_event_t *,277unsigned long *);278void *signal_event;279efi_status_t (__efiapi *close_event)(efi_event_t);280void *check_event;281void *install_protocol_interface;282void *reinstall_protocol_interface;283void *uninstall_protocol_interface;284efi_status_t (__efiapi *handle_protocol)(efi_handle_t,285efi_guid_t *, void **);286void *__reserved;287void *register_protocol_notify;288efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,289void *, unsigned long *,290efi_handle_t *);291efi_status_t (__efiapi *locate_device_path)(efi_guid_t *,292efi_device_path_protocol_t **,293efi_handle_t *);294efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,295void *);296efi_status_t (__efiapi *load_image)(bool, efi_handle_t,297efi_device_path_protocol_t *,298void *, unsigned long,299efi_handle_t *);300efi_status_t (__efiapi *start_image)(efi_handle_t, unsigned long *,301efi_char16_t **);302efi_status_t __noreturn (__efiapi *exit)(efi_handle_t,303efi_status_t,304unsigned long,305efi_char16_t *);306efi_status_t (__efiapi *unload_image)(efi_handle_t);307efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,308unsigned long);309void *get_next_monotonic_count;310efi_status_t (__efiapi *stall)(unsigned long);311void *set_watchdog_timer;312void *connect_controller;313efi_status_t (__efiapi *disconnect_controller)(efi_handle_t,314efi_handle_t,315efi_handle_t);316void *open_protocol;317void *close_protocol;318void *open_protocol_information;319void *protocols_per_handle;320efi_status_t (__efiapi *locate_handle_buffer)(int, efi_guid_t *,321void *, unsigned long *,322efi_handle_t **);323efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,324void **);325efi_status_t (__efiapi *install_multiple_protocol_interfaces)(efi_handle_t *, ...);326efi_status_t (__efiapi *uninstall_multiple_protocol_interfaces)(efi_handle_t, ...);327void *calculate_crc32;328void (__efiapi *copy_mem)(void *, const void *, unsigned long);329void (__efiapi *set_mem)(void *, unsigned long, unsigned char);330void *create_event_ex;331};332struct {333efi_table_hdr_t hdr;334u32 raise_tpl;335u32 restore_tpl;336u32 allocate_pages;337u32 free_pages;338u32 get_memory_map;339u32 allocate_pool;340u32 free_pool;341u32 create_event;342u32 set_timer;343u32 wait_for_event;344u32 signal_event;345u32 close_event;346u32 check_event;347u32 install_protocol_interface;348u32 reinstall_protocol_interface;349u32 uninstall_protocol_interface;350u32 handle_protocol;351u32 __reserved;352u32 register_protocol_notify;353u32 locate_handle;354u32 locate_device_path;355u32 install_configuration_table;356u32 load_image;357u32 start_image;358u32 exit;359u32 unload_image;360u32 exit_boot_services;361u32 get_next_monotonic_count;362u32 stall;363u32 set_watchdog_timer;364u32 connect_controller;365u32 disconnect_controller;366u32 open_protocol;367u32 close_protocol;368u32 open_protocol_information;369u32 protocols_per_handle;370u32 locate_handle_buffer;371u32 locate_protocol;372u32 install_multiple_protocol_interfaces;373u32 uninstall_multiple_protocol_interfaces;374u32 calculate_crc32;375u32 copy_mem;376u32 set_mem;377u32 create_event_ex;378} mixed_mode;379};380381typedef enum {382EfiGcdMemoryTypeNonExistent,383EfiGcdMemoryTypeReserved,384EfiGcdMemoryTypeSystemMemory,385EfiGcdMemoryTypeMemoryMappedIo,386EfiGcdMemoryTypePersistent,387EfiGcdMemoryTypeMoreReliable,388EfiGcdMemoryTypeMaximum389} efi_gcd_memory_type_t;390391typedef struct {392efi_physical_addr_t base_address;393u64 length;394u64 capabilities;395u64 attributes;396efi_gcd_memory_type_t gcd_memory_type;397void *image_handle;398void *device_handle;399} efi_gcd_memory_space_desc_t;400401/*402* EFI DXE Services table403*/404union efi_dxe_services_table {405struct {406efi_table_hdr_t hdr;407void *add_memory_space;408void *allocate_memory_space;409void *free_memory_space;410void *remove_memory_space;411efi_status_t (__efiapi *get_memory_space_descriptor)(efi_physical_addr_t,412efi_gcd_memory_space_desc_t *);413efi_status_t (__efiapi *set_memory_space_attributes)(efi_physical_addr_t,414u64, u64);415void *get_memory_space_map;416void *add_io_space;417void *allocate_io_space;418void *free_io_space;419void *remove_io_space;420void *get_io_space_descriptor;421void *get_io_space_map;422void *dispatch;423void *schedule;424void *trust;425void *process_firmware_volume;426void *set_memory_space_capabilities;427};428struct {429efi_table_hdr_t hdr;430u32 add_memory_space;431u32 allocate_memory_space;432u32 free_memory_space;433u32 remove_memory_space;434u32 get_memory_space_descriptor;435u32 set_memory_space_attributes;436u32 get_memory_space_map;437u32 add_io_space;438u32 allocate_io_space;439u32 free_io_space;440u32 remove_io_space;441u32 get_io_space_descriptor;442u32 get_io_space_map;443u32 dispatch;444u32 schedule;445u32 trust;446u32 process_firmware_volume;447u32 set_memory_space_capabilities;448} mixed_mode;449};450451typedef union efi_memory_attribute_protocol efi_memory_attribute_protocol_t;452453union efi_memory_attribute_protocol {454struct {455efi_status_t (__efiapi *get_memory_attributes)(456efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64 *);457458efi_status_t (__efiapi *set_memory_attributes)(459efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64);460461efi_status_t (__efiapi *clear_memory_attributes)(462efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64);463};464struct {465u32 get_memory_attributes;466u32 set_memory_attributes;467u32 clear_memory_attributes;468} mixed_mode;469};470471typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;472473union efi_uga_draw_protocol {474struct {475efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,476u32*, u32*, u32*, u32*);477void *set_mode;478void *blt;479};480struct {481u32 get_mode;482u32 set_mode;483u32 blt;484} mixed_mode;485};486487typedef struct {488u16 scan_code;489efi_char16_t unicode_char;490} efi_input_key_t;491492union efi_simple_text_input_protocol {493struct {494void *reset;495efi_status_t (__efiapi *read_keystroke)(efi_simple_text_input_protocol_t *,496efi_input_key_t *);497efi_event_t wait_for_key;498};499struct {500u32 reset;501u32 read_keystroke;502u32 wait_for_key;503} mixed_mode;504};505506efi_status_t efi_wait_for_key(unsigned long usec, efi_input_key_t *key);507508union efi_simple_text_output_protocol {509struct {510void *reset;511efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,512efi_char16_t *);513void *test_string;514};515struct {516u32 reset;517u32 output_string;518u32 test_string;519} mixed_mode;520};521522#define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0523#define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1524#define PIXEL_BIT_MASK 2525#define PIXEL_BLT_ONLY 3526#define PIXEL_FORMAT_MAX 4527528typedef struct {529u32 red_mask;530u32 green_mask;531u32 blue_mask;532u32 reserved_mask;533} efi_pixel_bitmask_t;534535typedef struct {536u32 version;537u32 horizontal_resolution;538u32 vertical_resolution;539int pixel_format;540efi_pixel_bitmask_t pixel_information;541u32 pixels_per_scan_line;542} efi_graphics_output_mode_info_t;543544typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;545546union efi_graphics_output_protocol_mode {547struct {548u32 max_mode;549u32 mode;550efi_graphics_output_mode_info_t *info;551unsigned long size_of_info;552efi_physical_addr_t frame_buffer_base;553unsigned long frame_buffer_size;554};555struct {556u32 max_mode;557u32 mode;558u32 info;559u32 size_of_info;560u64 frame_buffer_base;561u32 frame_buffer_size;562} mixed_mode;563};564565typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;566567union efi_graphics_output_protocol {568struct {569efi_status_t (__efiapi *query_mode)(efi_graphics_output_protocol_t *,570u32, unsigned long *,571efi_graphics_output_mode_info_t **);572efi_status_t (__efiapi *set_mode) (efi_graphics_output_protocol_t *, u32);573void *blt;574efi_graphics_output_protocol_mode_t *mode;575};576struct {577u32 query_mode;578u32 set_mode;579u32 blt;580u32 mode;581} mixed_mode;582};583584typedef union efi_edid_discovered_protocol efi_edid_discovered_protocol_t;585586union efi_edid_discovered_protocol {587struct {588u32 size_of_edid;589u8 *edid;590};591struct {592u32 size_of_edid;593u32 edid;594} mixed_mode;595};596597typedef union efi_edid_active_protocol efi_edid_active_protocol_t;598599union efi_edid_active_protocol {600struct {601u32 size_of_edid;602u8 *edid;603};604struct {605u32 size_of_edid;606u32 edid;607} mixed_mode;608};609610typedef union {611struct {612u32 revision;613efi_handle_t parent_handle;614efi_system_table_t *system_table;615efi_handle_t device_handle;616void *file_path;617void *reserved;618u32 load_options_size;619void *load_options;620void *image_base;621__aligned_u64 image_size;622unsigned int image_code_type;623unsigned int image_data_type;624efi_status_t (__efiapi *unload)(efi_handle_t image_handle);625};626struct {627u32 revision;628u32 parent_handle;629u32 system_table;630u32 device_handle;631u32 file_path;632u32 reserved;633u32 load_options_size;634u32 load_options;635u32 image_base;636__aligned_u64 image_size;637u32 image_code_type;638u32 image_data_type;639u32 unload;640} mixed_mode;641} efi_loaded_image_t;642643typedef struct {644u64 size;645u64 file_size;646u64 phys_size;647efi_time_t create_time;648efi_time_t last_access_time;649efi_time_t modification_time;650__aligned_u64 attribute;651efi_char16_t filename[];652} efi_file_info_t;653654typedef union efi_file_protocol efi_file_protocol_t;655656union efi_file_protocol {657struct {658u64 revision;659efi_status_t (__efiapi *open) (efi_file_protocol_t *,660efi_file_protocol_t **,661efi_char16_t *, u64,662u64);663efi_status_t (__efiapi *close) (efi_file_protocol_t *);664efi_status_t (__efiapi *delete) (efi_file_protocol_t *);665efi_status_t (__efiapi *read) (efi_file_protocol_t *,666unsigned long *,667void *);668efi_status_t (__efiapi *write) (efi_file_protocol_t *,669unsigned long, void *);670efi_status_t (__efiapi *get_position)(efi_file_protocol_t *,671u64 *);672efi_status_t (__efiapi *set_position)(efi_file_protocol_t *,673u64);674efi_status_t (__efiapi *get_info) (efi_file_protocol_t *,675efi_guid_t *,676unsigned long *,677void *);678efi_status_t (__efiapi *set_info) (efi_file_protocol_t *,679efi_guid_t *,680unsigned long,681void *);682efi_status_t (__efiapi *flush) (efi_file_protocol_t *);683};684struct {685u64 revision;686u32 open;687u32 close;688u32 delete;689u32 read;690u32 write;691u32 get_position;692u32 set_position;693u32 get_info;694u32 set_info;695u32 flush;696} mixed_mode;697};698699typedef union efi_simple_file_system_protocol efi_simple_file_system_protocol_t;700701union efi_simple_file_system_protocol {702struct {703u64 revision;704efi_status_t (__efiapi *open_volume)(efi_simple_file_system_protocol_t *,705efi_file_protocol_t **);706};707struct {708u64 revision;709u32 open_volume;710} mixed_mode;711};712713#define EFI_FILE_MODE_READ 0x0000000000000001714#define EFI_FILE_MODE_WRITE 0x0000000000000002715#define EFI_FILE_MODE_CREATE 0x8000000000000000716717typedef enum {718EfiPciIoWidthUint8,719EfiPciIoWidthUint16,720EfiPciIoWidthUint32,721EfiPciIoWidthUint64,722EfiPciIoWidthFifoUint8,723EfiPciIoWidthFifoUint16,724EfiPciIoWidthFifoUint32,725EfiPciIoWidthFifoUint64,726EfiPciIoWidthFillUint8,727EfiPciIoWidthFillUint16,728EfiPciIoWidthFillUint32,729EfiPciIoWidthFillUint64,730EfiPciIoWidthMaximum731} EFI_PCI_IO_PROTOCOL_WIDTH;732733typedef enum {734EfiPciIoAttributeOperationGet,735EfiPciIoAttributeOperationSet,736EfiPciIoAttributeOperationEnable,737EfiPciIoAttributeOperationDisable,738EfiPciIoAttributeOperationSupported,739EfiPciIoAttributeOperationMaximum740} EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;741742typedef struct {743u32 read;744u32 write;745} efi_pci_io_protocol_access_32_t;746747typedef union efi_pci_io_protocol efi_pci_io_protocol_t;748749typedef750efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,751EFI_PCI_IO_PROTOCOL_WIDTH,752u32 offset,753unsigned long count,754void *buffer);755756typedef struct {757void *read;758void *write;759} efi_pci_io_protocol_access_t;760761typedef struct {762efi_pci_io_protocol_cfg_t read;763efi_pci_io_protocol_cfg_t write;764} efi_pci_io_protocol_config_access_t;765766union efi_pci_io_protocol {767struct {768void *poll_mem;769void *poll_io;770efi_pci_io_protocol_access_t mem;771efi_pci_io_protocol_access_t io;772efi_pci_io_protocol_config_access_t pci;773void *copy_mem;774void *map;775void *unmap;776void *allocate_buffer;777void *free_buffer;778void *flush;779efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,780unsigned long *segment_nr,781unsigned long *bus_nr,782unsigned long *device_nr,783unsigned long *func_nr);784void *attributes;785void *get_bar_attributes;786void *set_bar_attributes;787uint64_t romsize;788void *romimage;789};790struct {791u32 poll_mem;792u32 poll_io;793efi_pci_io_protocol_access_32_t mem;794efi_pci_io_protocol_access_32_t io;795efi_pci_io_protocol_access_32_t pci;796u32 copy_mem;797u32 map;798u32 unmap;799u32 allocate_buffer;800u32 free_buffer;801u32 flush;802u32 get_location;803u32 attributes;804u32 get_bar_attributes;805u32 set_bar_attributes;806u64 romsize;807u32 romimage;808} mixed_mode;809};810811#define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001812#define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002813#define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004814#define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008815#define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010816#define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020817#define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040818#define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080819#define EFI_PCI_IO_ATTRIBUTE_IO 0x0100820#define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200821#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400822#define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800823#define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000824#define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000825#define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000826#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000827#define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000828#define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000829#define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000830831struct efi_dev_path;832833typedef union apple_properties_protocol apple_properties_protocol_t;834835union apple_properties_protocol {836struct {837unsigned long version;838efi_status_t (__efiapi *get)(apple_properties_protocol_t *,839struct efi_dev_path *,840efi_char16_t *, void *, u32 *);841efi_status_t (__efiapi *set)(apple_properties_protocol_t *,842struct efi_dev_path *,843efi_char16_t *, void *, u32);844efi_status_t (__efiapi *del)(apple_properties_protocol_t *,845struct efi_dev_path *,846efi_char16_t *);847efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,848void *buffer, u32 *);849};850struct {851u32 version;852u32 get;853u32 set;854u32 del;855u32 get_all;856} mixed_mode;857};858859typedef u32 efi_tcg2_event_log_format;860861#define INITRD_EVENT_TAG_ID 0x8F3B22ECU862#define LOAD_OPTIONS_EVENT_TAG_ID 0x8F3B22EDU863#define EV_EVENT_TAG 0x00000006U864#define EFI_TCG2_EVENT_HEADER_VERSION 0x1865866struct efi_tcg2_event {867u32 event_size;868struct {869u32 header_size;870u16 header_version;871u32 pcr_index;872u32 event_type;873} __packed event_header;874/* u8[] event follows here */875} __packed;876877/* from TCG PC Client Platform Firmware Profile Specification */878typedef struct tdTCG_PCClientTaggedEvent {879u32 tagged_event_id;880u32 tagged_event_data_size;881u8 tagged_event_data[];882} TCG_PCClientTaggedEvent;883884typedef struct efi_tcg2_event efi_tcg2_event_t;885typedef union efi_tcg2_protocol efi_tcg2_protocol_t;886887union efi_tcg2_protocol {888struct {889void *get_capability;890efi_status_t (__efiapi *get_event_log)(efi_tcg2_protocol_t *,891efi_tcg2_event_log_format,892efi_physical_addr_t *,893efi_physical_addr_t *,894efi_bool_t *);895efi_status_t (__efiapi *hash_log_extend_event)(efi_tcg2_protocol_t *,896u64,897efi_physical_addr_t,898u64,899const efi_tcg2_event_t *);900void *submit_command;901void *get_active_pcr_banks;902void *set_active_pcr_banks;903void *get_result_of_set_active_pcr_banks;904};905struct {906u32 get_capability;907u32 get_event_log;908u32 hash_log_extend_event;909u32 submit_command;910u32 get_active_pcr_banks;911u32 set_active_pcr_banks;912u32 get_result_of_set_active_pcr_banks;913} mixed_mode;914};915916typedef struct {917u8 major;918u8 minor;919} efi_cc_version_t;920921typedef struct {922u8 type;923u8 sub_type;924} efi_cc_type_t;925926/* EFI CC type/subtype defines */927#define EFI_CC_TYPE_NONE 0928#define EFI_CC_TYPE_AMD_SEV 1929#define EFI_CC_TYPE_INTEL_TDX 2930931typedef u32 efi_cc_mr_index_t;932933struct efi_cc_event {934u32 event_size;935struct {936u32 header_size;937u16 header_version;938u32 mr_index;939u32 event_type;940} __packed event_header;941/* u8[] event follows here */942} __packed;943944typedef struct efi_cc_event efi_cc_event_t;945946typedef u32 efi_cc_event_log_bitmap_t;947typedef u32 efi_cc_event_log_format_t;948typedef u32 efi_cc_event_algorithm_bitmap_t;949950typedef struct {951u8 size;952efi_cc_version_t structure_version;953efi_cc_version_t protocol_version;954efi_cc_event_algorithm_bitmap_t hash_algorithm_bitmap;955efi_cc_event_log_bitmap_t supported_event_logs;956efi_cc_type_t cc_type;957} efi_cc_boot_service_cap_t;958959#define EFI_CC_EVENT_HEADER_VERSION 1960961#define EFI_CC_BOOT_HASH_ALG_SHA384 0x00000004962963#define EFI_CC_EVENT_LOG_FORMAT_TCG_2 0x00000002964965typedef union efi_cc_protocol efi_cc_protocol_t;966967union efi_cc_protocol {968struct {969efi_status_t970(__efiapi *get_capability)(efi_cc_protocol_t *,971efi_cc_boot_service_cap_t *);972973efi_status_t974(__efiapi *get_event_log)(efi_cc_protocol_t *,975efi_cc_event_log_format_t,976efi_physical_addr_t *,977efi_physical_addr_t *,978efi_bool_t *);979980efi_status_t981(__efiapi *hash_log_extend_event)(efi_cc_protocol_t *, u64,982efi_physical_addr_t, u64,983const efi_cc_event_t *);984985efi_status_t986(__efiapi *map_pcr_to_mr_index)(efi_cc_protocol_t *, u32,987efi_cc_mr_index_t *);988};989struct {990u32 get_capability;991u32 get_event_log;992u32 hash_log_extend_event;993u32 map_pcr_to_mr_index;994} mixed_mode;995};996997struct riscv_efi_boot_protocol {998u64 revision;9991000efi_status_t (__efiapi *get_boot_hartid)(struct riscv_efi_boot_protocol *,1001unsigned long *boot_hartid);1002};10031004typedef union efi_load_file_protocol efi_load_file_protocol_t;1005typedef union efi_load_file_protocol efi_load_file2_protocol_t;10061007union efi_load_file_protocol {1008struct {1009efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *,1010efi_device_path_protocol_t *,1011bool, unsigned long *, void *);1012};1013struct {1014u32 load_file;1015} mixed_mode;1016};10171018typedef struct {1019u32 attributes;1020u16 file_path_list_length;1021u8 variable_data[];1022// efi_char16_t description[];1023// efi_device_path_protocol_t file_path_list[];1024// u8 optional_data[];1025} __packed efi_load_option_t;10261027#define EFI_LOAD_OPTION_ACTIVE 0x0001U1028#define EFI_LOAD_OPTION_FORCE_RECONNECT 0x0002U1029#define EFI_LOAD_OPTION_HIDDEN 0x0008U1030#define EFI_LOAD_OPTION_CATEGORY 0x1f00U1031#define EFI_LOAD_OPTION_CATEGORY_BOOT 0x0000U1032#define EFI_LOAD_OPTION_CATEGORY_APP 0x0100U10331034#define EFI_LOAD_OPTION_BOOT_MASK \1035(EFI_LOAD_OPTION_ACTIVE|EFI_LOAD_OPTION_HIDDEN|EFI_LOAD_OPTION_CATEGORY)1036#define EFI_LOAD_OPTION_MASK (EFI_LOAD_OPTION_FORCE_RECONNECT|EFI_LOAD_OPTION_BOOT_MASK)10371038typedef struct {1039u32 attributes;1040u16 file_path_list_length;1041const efi_char16_t *description;1042const efi_device_path_protocol_t *file_path_list;1043u32 optional_data_size;1044const void *optional_data;1045} efi_load_option_unpacked_t;10461047void efi_pci_disable_bridge_busmaster(void);10481049typedef efi_status_t (*efi_exit_boot_map_processing)(1050struct efi_boot_memmap *map,1051void *priv);10521053efi_status_t efi_exit_boot_services(void *handle, void *priv,1054efi_exit_boot_map_processing priv_func);10551056efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,1057unsigned long kernel_addr, char *cmdline_ptr);10581059void *get_fdt(unsigned long *fdt_size);10601061efi_status_t efi_alloc_virtmap(efi_memory_desc_t **virtmap,1062unsigned long *desc_size, u32 *desc_ver);1063void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,1064unsigned long desc_size, efi_memory_desc_t *runtime_map,1065int *count);10661067efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);10681069efi_status_t efi_random_alloc(unsigned long size, unsigned long align,1070unsigned long *addr, unsigned long random_seed,1071int memory_type, unsigned long alloc_min,1072unsigned long alloc_max);10731074efi_status_t efi_random_get_seed(void);10751076efi_status_t check_platform_features(void);10771078void *get_efi_config_table(efi_guid_t guid);10791080/* NOTE: These functions do not print a trailing newline after the string */1081void efi_char16_puts(efi_char16_t *);1082void efi_puts(const char *str);10831084__printf(1, 2) int efi_printk(char const *fmt, ...);10851086void efi_free(unsigned long size, unsigned long addr);1087DEFINE_FREE(efi_pool, void *, if (_T) efi_bs_call(free_pool, _T));10881089void efi_apply_loadoptions_quirk(const void **load_options, u32 *load_options_size);10901091char *efi_convert_cmdline(efi_loaded_image_t *image);10921093efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,1094bool install_cfg_tbl);10951096efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,1097unsigned long max);10981099efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,1100unsigned long max, unsigned long align,1101int memory_type);11021103efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,1104unsigned long *addr, unsigned long min);11051106efi_status_t efi_relocate_kernel(unsigned long *image_addr,1107unsigned long image_size,1108unsigned long alloc_size,1109unsigned long preferred_addr,1110unsigned long alignment,1111unsigned long min_addr);11121113efi_status_t efi_parse_options(char const *cmdline);11141115void efi_parse_option_graphics(char *option);11161117efi_status_t efi_setup_graphics(struct screen_info *si, struct edid_info *edid);11181119efi_status_t handle_cmdline_files(efi_loaded_image_t *image,1120const efi_char16_t *optstr,1121int optstr_size,1122unsigned long soft_limit,1123unsigned long hard_limit,1124unsigned long *load_addr,1125unsigned long *load_size);112611271128static inline efi_status_t efi_load_dtb(efi_loaded_image_t *image,1129unsigned long *load_addr,1130unsigned long *load_size)1131{1132return handle_cmdline_files(image, L"dtb=", sizeof(L"dtb=") - 2,1133ULONG_MAX, ULONG_MAX, load_addr, load_size);1134}11351136efi_status_t efi_load_initrd(efi_loaded_image_t *image,1137unsigned long soft_limit,1138unsigned long hard_limit,1139const struct linux_efi_initrd **out);1140/*1141* This function handles the architcture specific differences between arm and1142* arm64 regarding where the kernel image must be loaded and any memory that1143* must be reserved. On failure it is required to free all1144* all allocations it has made.1145*/1146efi_status_t handle_kernel_image(unsigned long *image_addr,1147unsigned long *image_size,1148unsigned long *reserve_addr,1149unsigned long *reserve_size,1150efi_loaded_image_t *image,1151efi_handle_t image_handle);11521153/* shared entrypoint between the normal stub and the zboot stub */1154efi_status_t efi_stub_common(efi_handle_t handle,1155efi_loaded_image_t *image,1156unsigned long image_addr,1157char *cmdline_ptr);11581159efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr);11601161asmlinkage void __noreturn efi_enter_kernel(unsigned long entrypoint,1162unsigned long fdt_addr,1163unsigned long fdt_size);11641165void efi_handle_post_ebs_state(void);11661167enum efi_secureboot_mode efi_get_secureboot(void);11681169#ifdef CONFIG_RESET_ATTACK_MITIGATION1170void efi_enable_reset_attack_mitigation(void);1171#else1172static inline void1173efi_enable_reset_attack_mitigation(void) { }1174#endif11751176void efi_retrieve_eventlog(void);11771178struct sysfb_display_info *alloc_primary_display(void);1179struct sysfb_display_info *__alloc_primary_display(void);1180void free_primary_display(struct sysfb_display_info *dpy);11811182void efi_cache_sync_image(unsigned long image_base,1183unsigned long alloc_size);11841185struct efi_smbios_record {1186u8 type;1187u8 length;1188u16 handle;1189};11901191const struct efi_smbios_record *efi_get_smbios_record(u8 type);11921193struct efi_smbios_type1_record {1194struct efi_smbios_record header;11951196u8 manufacturer;1197u8 product_name;1198u8 version;1199u8 serial_number;1200efi_guid_t uuid;1201u8 wakeup_type;1202u8 sku_number;1203u8 family;1204};12051206struct efi_smbios_type4_record {1207struct efi_smbios_record header;12081209u8 socket;1210u8 processor_type;1211u8 processor_family;1212u8 processor_manufacturer;1213u8 processor_id[8];1214u8 processor_version;1215u8 voltage;1216u16 external_clock;1217u16 max_speed;1218u16 current_speed;1219u8 status;1220u8 processor_upgrade;1221u16 l1_cache_handle;1222u16 l2_cache_handle;1223u16 l3_cache_handle;1224u8 serial_number;1225u8 asset_tag;1226u8 part_number;1227u8 core_count;1228u8 enabled_core_count;1229u8 thread_count;1230u16 processor_characteristics;1231u16 processor_family2;1232u16 core_count2;1233u16 enabled_core_count2;1234u16 thread_count2;1235u16 thread_enabled;1236};12371238#define efi_get_smbios_string(__record, __field) ({ \1239__typeof__(__record) __rec = __record; \1240__efi_get_smbios_string(&__rec->header, &__rec->__field); \1241})12421243const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record,1244const u8 *offset);12451246void efi_remap_image(unsigned long image_base, unsigned alloc_size,1247unsigned long code_size);1248efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,1249unsigned long *reserve_addr,1250unsigned long *reserve_size,1251unsigned long kernel_size,1252unsigned long kernel_codesize,1253unsigned long kernel_memsize,1254u32 phys_seed);1255u32 efi_kaslr_get_phys_seed(efi_handle_t image_handle);12561257asmlinkage efi_status_t __efiapi1258efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab);12591260efi_status_t allocate_unaccepted_bitmap(__u32 nr_desc,1261struct efi_boot_memmap *map);1262void process_unaccepted_memory(u64 start, u64 end);1263void accept_memory(phys_addr_t start, unsigned long size);1264void arch_accept_memory(phys_addr_t start, phys_addr_t end);12651266efi_status_t efi_zboot_decompress_init(unsigned long *alloc_size);1267efi_status_t efi_zboot_decompress(u8 *out, unsigned long outlen);12681269#endif127012711272