Path: blob/master/drivers/firmware/efi/libstub/efistub.h
26483 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#endif3536extern bool efi_no5lvl;37extern bool efi_nochunk;38extern bool efi_nokaslr;39extern int efi_loglevel;40extern int efi_mem_encrypt;41extern bool efi_novamap;42extern const efi_system_table_t *efi_system_table;4344typedef union efi_dxe_services_table efi_dxe_services_table_t;45extern const efi_dxe_services_table_t *efi_dxe_table;4647efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,48efi_system_table_t *sys_table_arg);4950#ifndef ARCH_HAS_EFISTUB_WRAPPERS5152#define efi_is_native() (true)53#define efi_table_attr(inst, attr) (inst)->attr54#define efi_fn_call(inst, func, ...) (inst)->func(__VA_ARGS__)5556#endif5758#define efi_call_proto(inst, func, ...) ({ \59__typeof__(inst) __inst = (inst); \60efi_fn_call(__inst, func, __inst, ##__VA_ARGS__); \61})62#define efi_bs_call(func, ...) \63efi_fn_call(efi_table_attr(efi_system_table, boottime), func, ##__VA_ARGS__)64#define efi_rt_call(func, ...) \65efi_fn_call(efi_table_attr(efi_system_table, runtime), func, ##__VA_ARGS__)66#define efi_dxe_call(func, ...) \67efi_fn_call(efi_dxe_table, func, ##__VA_ARGS__)6869#define efi_info(fmt, ...) \70efi_printk(KERN_INFO fmt, ##__VA_ARGS__)71#define efi_warn(fmt, ...) \72efi_printk(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)73#define efi_err(fmt, ...) \74efi_printk(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)75#define efi_debug(fmt, ...) \76efi_printk(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)7778#define efi_printk_once(fmt, ...) \79({ \80static bool __print_once; \81bool __ret_print_once = !__print_once; \82\83if (!__print_once) { \84__print_once = true; \85efi_printk(fmt, ##__VA_ARGS__); \86} \87__ret_print_once; \88})8990#define efi_info_once(fmt, ...) \91efi_printk_once(KERN_INFO fmt, ##__VA_ARGS__)92#define efi_warn_once(fmt, ...) \93efi_printk_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)94#define efi_err_once(fmt, ...) \95efi_printk_once(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)96#define efi_debug_once(fmt, ...) \97efi_printk_once(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)9899/* Helper macros for the usual case of using simple C variables: */100#ifndef fdt_setprop_inplace_var101#define fdt_setprop_inplace_var(fdt, node_offset, name, var) \102fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))103#endif104105#ifndef fdt_setprop_var106#define fdt_setprop_var(fdt, node_offset, name, var) \107fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))108#endif109110#define get_efi_var(name, vendor, ...) \111efi_rt_call(get_variable, (efi_char16_t *)(name), \112(efi_guid_t *)(vendor), __VA_ARGS__)113114#define set_efi_var(name, vendor, ...) \115efi_rt_call(set_variable, (efi_char16_t *)(name), \116(efi_guid_t *)(vendor), __VA_ARGS__)117118#define efi_get_handle_at(array, idx) \119(efi_is_native() ? (array)[idx] \120: (efi_handle_t)(unsigned long)((u32 *)(array))[idx])121122#define efi_get_handle_num(size) \123((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))124125#define for_each_efi_handle(handle, array, num) \126for (int __i = 0; __i < (num) && \127((handle = efi_get_handle_at((array), __i)) || true); \128__i++)129130static inline131void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)132{133*lo = lower_32_bits(data);134*hi = upper_32_bits(data);135}136137/*138* Allocation types for calls to boottime->allocate_pages.139*/140#define EFI_ALLOCATE_ANY_PAGES 0141#define EFI_ALLOCATE_MAX_ADDRESS 1142#define EFI_ALLOCATE_ADDRESS 2143#define EFI_MAX_ALLOCATE_TYPE 3144145/*146* The type of search to perform when calling boottime->locate_handle147*/148#define EFI_LOCATE_ALL_HANDLES 0149#define EFI_LOCATE_BY_REGISTER_NOTIFY 1150#define EFI_LOCATE_BY_PROTOCOL 2151152/*153* boottime->stall takes the time period in microseconds154*/155#define EFI_USEC_PER_SEC 1000000156157/*158* boottime->set_timer takes the time in 100ns units159*/160#define EFI_100NSEC_PER_USEC ((u64)10)161162/*163* An efi_boot_memmap is used by efi_get_memory_map() to return the164* EFI memory map in a dynamically allocated buffer.165*166* The buffer allocated for the EFI memory map includes extra room for167* a minimum of EFI_MMAP_NR_SLACK_SLOTS additional EFI memory descriptors.168* This facilitates the reuse of the EFI memory map buffer when a second169* call to ExitBootServices() is needed because of intervening changes to170* the EFI memory map. Other related structures, e.g. x86 e820ext, need171* to factor in this headroom requirement as well.172*/173#define EFI_MMAP_NR_SLACK_SLOTS 32174175typedef struct efi_generic_dev_path efi_device_path_protocol_t;176177union efi_device_path_to_text_protocol {178struct {179efi_char16_t *(__efiapi *convert_device_node_to_text)(180const efi_device_path_protocol_t *,181bool, bool);182efi_char16_t *(__efiapi *convert_device_path_to_text)(183const efi_device_path_protocol_t *,184bool, bool);185};186struct {187u32 convert_device_node_to_text;188u32 convert_device_path_to_text;189} mixed_mode;190};191192typedef union efi_device_path_to_text_protocol efi_device_path_to_text_protocol_t;193194union efi_device_path_from_text_protocol {195struct {196efi_device_path_protocol_t *197(__efiapi *convert_text_to_device_node)(const efi_char16_t *);198efi_device_path_protocol_t *199(__efiapi *convert_text_to_device_path)(const efi_char16_t *);200};201struct {202u32 convert_text_to_device_node;203u32 convert_text_to_device_path;204} mixed_mode;205};206207typedef union efi_device_path_from_text_protocol efi_device_path_from_text_protocol_t;208209typedef void *efi_event_t;210/* Note that notifications won't work in mixed mode */211typedef void (__efiapi *efi_event_notify_t)(efi_event_t, void *);212213#define EFI_EVT_TIMER 0x80000000U214#define EFI_EVT_RUNTIME 0x40000000U215#define EFI_EVT_NOTIFY_WAIT 0x00000100U216#define EFI_EVT_NOTIFY_SIGNAL 0x00000200U217218/**219* efi_set_event_at() - add event to events array220*221* @events: array of UEFI events222* @ids: index where to put the event in the array223* @event: event to add to the aray224*225* boottime->wait_for_event() takes an array of events as input.226* Provide a helper to set it up correctly for mixed mode.227*/228static inline229void efi_set_event_at(efi_event_t *events, size_t idx, efi_event_t event)230{231if (efi_is_native())232events[idx] = event;233else234((u32 *)events)[idx] = (u32)(unsigned long)event;235}236237#define EFI_TPL_APPLICATION 4238#define EFI_TPL_CALLBACK 8239#define EFI_TPL_NOTIFY 16240#define EFI_TPL_HIGH_LEVEL 31241242typedef enum {243EfiTimerCancel,244EfiTimerPeriodic,245EfiTimerRelative246} EFI_TIMER_DELAY;247248/*249* EFI Boot Services table250*/251union efi_boot_services {252struct {253efi_table_hdr_t hdr;254void *raise_tpl;255void *restore_tpl;256efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,257efi_physical_addr_t *);258efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,259unsigned long);260efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,261unsigned long *,262unsigned long *, u32 *);263efi_status_t (__efiapi *allocate_pool)(int, unsigned long,264void **);265efi_status_t (__efiapi *free_pool)(void *);266efi_status_t (__efiapi *create_event)(u32, unsigned long,267efi_event_notify_t, void *,268efi_event_t *);269efi_status_t (__efiapi *set_timer)(efi_event_t,270EFI_TIMER_DELAY, u64);271efi_status_t (__efiapi *wait_for_event)(unsigned long,272efi_event_t *,273unsigned long *);274void *signal_event;275efi_status_t (__efiapi *close_event)(efi_event_t);276void *check_event;277void *install_protocol_interface;278void *reinstall_protocol_interface;279void *uninstall_protocol_interface;280efi_status_t (__efiapi *handle_protocol)(efi_handle_t,281efi_guid_t *, void **);282void *__reserved;283void *register_protocol_notify;284efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,285void *, unsigned long *,286efi_handle_t *);287efi_status_t (__efiapi *locate_device_path)(efi_guid_t *,288efi_device_path_protocol_t **,289efi_handle_t *);290efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,291void *);292efi_status_t (__efiapi *load_image)(bool, efi_handle_t,293efi_device_path_protocol_t *,294void *, unsigned long,295efi_handle_t *);296efi_status_t (__efiapi *start_image)(efi_handle_t, unsigned long *,297efi_char16_t **);298efi_status_t __noreturn (__efiapi *exit)(efi_handle_t,299efi_status_t,300unsigned long,301efi_char16_t *);302efi_status_t (__efiapi *unload_image)(efi_handle_t);303efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,304unsigned long);305void *get_next_monotonic_count;306efi_status_t (__efiapi *stall)(unsigned long);307void *set_watchdog_timer;308void *connect_controller;309efi_status_t (__efiapi *disconnect_controller)(efi_handle_t,310efi_handle_t,311efi_handle_t);312void *open_protocol;313void *close_protocol;314void *open_protocol_information;315void *protocols_per_handle;316efi_status_t (__efiapi *locate_handle_buffer)(int, efi_guid_t *,317void *, unsigned long *,318efi_handle_t **);319efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,320void **);321efi_status_t (__efiapi *install_multiple_protocol_interfaces)(efi_handle_t *, ...);322efi_status_t (__efiapi *uninstall_multiple_protocol_interfaces)(efi_handle_t, ...);323void *calculate_crc32;324void (__efiapi *copy_mem)(void *, const void *, unsigned long);325void (__efiapi *set_mem)(void *, unsigned long, unsigned char);326void *create_event_ex;327};328struct {329efi_table_hdr_t hdr;330u32 raise_tpl;331u32 restore_tpl;332u32 allocate_pages;333u32 free_pages;334u32 get_memory_map;335u32 allocate_pool;336u32 free_pool;337u32 create_event;338u32 set_timer;339u32 wait_for_event;340u32 signal_event;341u32 close_event;342u32 check_event;343u32 install_protocol_interface;344u32 reinstall_protocol_interface;345u32 uninstall_protocol_interface;346u32 handle_protocol;347u32 __reserved;348u32 register_protocol_notify;349u32 locate_handle;350u32 locate_device_path;351u32 install_configuration_table;352u32 load_image;353u32 start_image;354u32 exit;355u32 unload_image;356u32 exit_boot_services;357u32 get_next_monotonic_count;358u32 stall;359u32 set_watchdog_timer;360u32 connect_controller;361u32 disconnect_controller;362u32 open_protocol;363u32 close_protocol;364u32 open_protocol_information;365u32 protocols_per_handle;366u32 locate_handle_buffer;367u32 locate_protocol;368u32 install_multiple_protocol_interfaces;369u32 uninstall_multiple_protocol_interfaces;370u32 calculate_crc32;371u32 copy_mem;372u32 set_mem;373u32 create_event_ex;374} mixed_mode;375};376377typedef enum {378EfiGcdMemoryTypeNonExistent,379EfiGcdMemoryTypeReserved,380EfiGcdMemoryTypeSystemMemory,381EfiGcdMemoryTypeMemoryMappedIo,382EfiGcdMemoryTypePersistent,383EfiGcdMemoryTypeMoreReliable,384EfiGcdMemoryTypeMaximum385} efi_gcd_memory_type_t;386387typedef struct {388efi_physical_addr_t base_address;389u64 length;390u64 capabilities;391u64 attributes;392efi_gcd_memory_type_t gcd_memory_type;393void *image_handle;394void *device_handle;395} efi_gcd_memory_space_desc_t;396397/*398* EFI DXE Services table399*/400union efi_dxe_services_table {401struct {402efi_table_hdr_t hdr;403void *add_memory_space;404void *allocate_memory_space;405void *free_memory_space;406void *remove_memory_space;407efi_status_t (__efiapi *get_memory_space_descriptor)(efi_physical_addr_t,408efi_gcd_memory_space_desc_t *);409efi_status_t (__efiapi *set_memory_space_attributes)(efi_physical_addr_t,410u64, u64);411void *get_memory_space_map;412void *add_io_space;413void *allocate_io_space;414void *free_io_space;415void *remove_io_space;416void *get_io_space_descriptor;417void *get_io_space_map;418void *dispatch;419void *schedule;420void *trust;421void *process_firmware_volume;422void *set_memory_space_capabilities;423};424struct {425efi_table_hdr_t hdr;426u32 add_memory_space;427u32 allocate_memory_space;428u32 free_memory_space;429u32 remove_memory_space;430u32 get_memory_space_descriptor;431u32 set_memory_space_attributes;432u32 get_memory_space_map;433u32 add_io_space;434u32 allocate_io_space;435u32 free_io_space;436u32 remove_io_space;437u32 get_io_space_descriptor;438u32 get_io_space_map;439u32 dispatch;440u32 schedule;441u32 trust;442u32 process_firmware_volume;443u32 set_memory_space_capabilities;444} mixed_mode;445};446447typedef union efi_memory_attribute_protocol efi_memory_attribute_protocol_t;448449union efi_memory_attribute_protocol {450struct {451efi_status_t (__efiapi *get_memory_attributes)(452efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64 *);453454efi_status_t (__efiapi *set_memory_attributes)(455efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64);456457efi_status_t (__efiapi *clear_memory_attributes)(458efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64);459};460struct {461u32 get_memory_attributes;462u32 set_memory_attributes;463u32 clear_memory_attributes;464} mixed_mode;465};466467typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;468469union efi_uga_draw_protocol {470struct {471efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,472u32*, u32*, u32*, u32*);473void *set_mode;474void *blt;475};476struct {477u32 get_mode;478u32 set_mode;479u32 blt;480} mixed_mode;481};482483typedef struct {484u16 scan_code;485efi_char16_t unicode_char;486} efi_input_key_t;487488union efi_simple_text_input_protocol {489struct {490void *reset;491efi_status_t (__efiapi *read_keystroke)(efi_simple_text_input_protocol_t *,492efi_input_key_t *);493efi_event_t wait_for_key;494};495struct {496u32 reset;497u32 read_keystroke;498u32 wait_for_key;499} mixed_mode;500};501502efi_status_t efi_wait_for_key(unsigned long usec, efi_input_key_t *key);503504union efi_simple_text_output_protocol {505struct {506void *reset;507efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,508efi_char16_t *);509void *test_string;510};511struct {512u32 reset;513u32 output_string;514u32 test_string;515} mixed_mode;516};517518#define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0519#define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1520#define PIXEL_BIT_MASK 2521#define PIXEL_BLT_ONLY 3522#define PIXEL_FORMAT_MAX 4523524typedef struct {525u32 red_mask;526u32 green_mask;527u32 blue_mask;528u32 reserved_mask;529} efi_pixel_bitmask_t;530531typedef struct {532u32 version;533u32 horizontal_resolution;534u32 vertical_resolution;535int pixel_format;536efi_pixel_bitmask_t pixel_information;537u32 pixels_per_scan_line;538} efi_graphics_output_mode_info_t;539540typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;541542union efi_graphics_output_protocol_mode {543struct {544u32 max_mode;545u32 mode;546efi_graphics_output_mode_info_t *info;547unsigned long size_of_info;548efi_physical_addr_t frame_buffer_base;549unsigned long frame_buffer_size;550};551struct {552u32 max_mode;553u32 mode;554u32 info;555u32 size_of_info;556u64 frame_buffer_base;557u32 frame_buffer_size;558} mixed_mode;559};560561typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;562563union efi_graphics_output_protocol {564struct {565efi_status_t (__efiapi *query_mode)(efi_graphics_output_protocol_t *,566u32, unsigned long *,567efi_graphics_output_mode_info_t **);568efi_status_t (__efiapi *set_mode) (efi_graphics_output_protocol_t *, u32);569void *blt;570efi_graphics_output_protocol_mode_t *mode;571};572struct {573u32 query_mode;574u32 set_mode;575u32 blt;576u32 mode;577} mixed_mode;578};579580typedef union {581struct {582u32 revision;583efi_handle_t parent_handle;584efi_system_table_t *system_table;585efi_handle_t device_handle;586void *file_path;587void *reserved;588u32 load_options_size;589void *load_options;590void *image_base;591__aligned_u64 image_size;592unsigned int image_code_type;593unsigned int image_data_type;594efi_status_t (__efiapi *unload)(efi_handle_t image_handle);595};596struct {597u32 revision;598u32 parent_handle;599u32 system_table;600u32 device_handle;601u32 file_path;602u32 reserved;603u32 load_options_size;604u32 load_options;605u32 image_base;606__aligned_u64 image_size;607u32 image_code_type;608u32 image_data_type;609u32 unload;610} mixed_mode;611} efi_loaded_image_t;612613typedef struct {614u64 size;615u64 file_size;616u64 phys_size;617efi_time_t create_time;618efi_time_t last_access_time;619efi_time_t modification_time;620__aligned_u64 attribute;621efi_char16_t filename[];622} efi_file_info_t;623624typedef union efi_file_protocol efi_file_protocol_t;625626union efi_file_protocol {627struct {628u64 revision;629efi_status_t (__efiapi *open) (efi_file_protocol_t *,630efi_file_protocol_t **,631efi_char16_t *, u64,632u64);633efi_status_t (__efiapi *close) (efi_file_protocol_t *);634efi_status_t (__efiapi *delete) (efi_file_protocol_t *);635efi_status_t (__efiapi *read) (efi_file_protocol_t *,636unsigned long *,637void *);638efi_status_t (__efiapi *write) (efi_file_protocol_t *,639unsigned long, void *);640efi_status_t (__efiapi *get_position)(efi_file_protocol_t *,641u64 *);642efi_status_t (__efiapi *set_position)(efi_file_protocol_t *,643u64);644efi_status_t (__efiapi *get_info) (efi_file_protocol_t *,645efi_guid_t *,646unsigned long *,647void *);648efi_status_t (__efiapi *set_info) (efi_file_protocol_t *,649efi_guid_t *,650unsigned long,651void *);652efi_status_t (__efiapi *flush) (efi_file_protocol_t *);653};654struct {655u64 revision;656u32 open;657u32 close;658u32 delete;659u32 read;660u32 write;661u32 get_position;662u32 set_position;663u32 get_info;664u32 set_info;665u32 flush;666} mixed_mode;667};668669typedef union efi_simple_file_system_protocol efi_simple_file_system_protocol_t;670671union efi_simple_file_system_protocol {672struct {673u64 revision;674efi_status_t (__efiapi *open_volume)(efi_simple_file_system_protocol_t *,675efi_file_protocol_t **);676};677struct {678u64 revision;679u32 open_volume;680} mixed_mode;681};682683#define EFI_FILE_MODE_READ 0x0000000000000001684#define EFI_FILE_MODE_WRITE 0x0000000000000002685#define EFI_FILE_MODE_CREATE 0x8000000000000000686687typedef enum {688EfiPciIoWidthUint8,689EfiPciIoWidthUint16,690EfiPciIoWidthUint32,691EfiPciIoWidthUint64,692EfiPciIoWidthFifoUint8,693EfiPciIoWidthFifoUint16,694EfiPciIoWidthFifoUint32,695EfiPciIoWidthFifoUint64,696EfiPciIoWidthFillUint8,697EfiPciIoWidthFillUint16,698EfiPciIoWidthFillUint32,699EfiPciIoWidthFillUint64,700EfiPciIoWidthMaximum701} EFI_PCI_IO_PROTOCOL_WIDTH;702703typedef enum {704EfiPciIoAttributeOperationGet,705EfiPciIoAttributeOperationSet,706EfiPciIoAttributeOperationEnable,707EfiPciIoAttributeOperationDisable,708EfiPciIoAttributeOperationSupported,709EfiPciIoAttributeOperationMaximum710} EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;711712typedef struct {713u32 read;714u32 write;715} efi_pci_io_protocol_access_32_t;716717typedef union efi_pci_io_protocol efi_pci_io_protocol_t;718719typedef720efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,721EFI_PCI_IO_PROTOCOL_WIDTH,722u32 offset,723unsigned long count,724void *buffer);725726typedef struct {727void *read;728void *write;729} efi_pci_io_protocol_access_t;730731typedef struct {732efi_pci_io_protocol_cfg_t read;733efi_pci_io_protocol_cfg_t write;734} efi_pci_io_protocol_config_access_t;735736union efi_pci_io_protocol {737struct {738void *poll_mem;739void *poll_io;740efi_pci_io_protocol_access_t mem;741efi_pci_io_protocol_access_t io;742efi_pci_io_protocol_config_access_t pci;743void *copy_mem;744void *map;745void *unmap;746void *allocate_buffer;747void *free_buffer;748void *flush;749efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,750unsigned long *segment_nr,751unsigned long *bus_nr,752unsigned long *device_nr,753unsigned long *func_nr);754void *attributes;755void *get_bar_attributes;756void *set_bar_attributes;757uint64_t romsize;758void *romimage;759};760struct {761u32 poll_mem;762u32 poll_io;763efi_pci_io_protocol_access_32_t mem;764efi_pci_io_protocol_access_32_t io;765efi_pci_io_protocol_access_32_t pci;766u32 copy_mem;767u32 map;768u32 unmap;769u32 allocate_buffer;770u32 free_buffer;771u32 flush;772u32 get_location;773u32 attributes;774u32 get_bar_attributes;775u32 set_bar_attributes;776u64 romsize;777u32 romimage;778} mixed_mode;779};780781#define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001782#define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002783#define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004784#define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008785#define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010786#define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020787#define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040788#define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080789#define EFI_PCI_IO_ATTRIBUTE_IO 0x0100790#define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200791#define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400792#define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800793#define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000794#define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000795#define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000796#define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000797#define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000798#define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000799#define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000800801struct efi_dev_path;802803typedef union apple_properties_protocol apple_properties_protocol_t;804805union apple_properties_protocol {806struct {807unsigned long version;808efi_status_t (__efiapi *get)(apple_properties_protocol_t *,809struct efi_dev_path *,810efi_char16_t *, void *, u32 *);811efi_status_t (__efiapi *set)(apple_properties_protocol_t *,812struct efi_dev_path *,813efi_char16_t *, void *, u32);814efi_status_t (__efiapi *del)(apple_properties_protocol_t *,815struct efi_dev_path *,816efi_char16_t *);817efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,818void *buffer, u32 *);819};820struct {821u32 version;822u32 get;823u32 set;824u32 del;825u32 get_all;826} mixed_mode;827};828829typedef u32 efi_tcg2_event_log_format;830831#define INITRD_EVENT_TAG_ID 0x8F3B22ECU832#define LOAD_OPTIONS_EVENT_TAG_ID 0x8F3B22EDU833#define EV_EVENT_TAG 0x00000006U834#define EFI_TCG2_EVENT_HEADER_VERSION 0x1835836struct efi_tcg2_event {837u32 event_size;838struct {839u32 header_size;840u16 header_version;841u32 pcr_index;842u32 event_type;843} __packed event_header;844/* u8[] event follows here */845} __packed;846847/* from TCG PC Client Platform Firmware Profile Specification */848typedef struct tdTCG_PCClientTaggedEvent {849u32 tagged_event_id;850u32 tagged_event_data_size;851u8 tagged_event_data[];852} TCG_PCClientTaggedEvent;853854typedef struct efi_tcg2_event efi_tcg2_event_t;855typedef union efi_tcg2_protocol efi_tcg2_protocol_t;856857union efi_tcg2_protocol {858struct {859void *get_capability;860efi_status_t (__efiapi *get_event_log)(efi_tcg2_protocol_t *,861efi_tcg2_event_log_format,862efi_physical_addr_t *,863efi_physical_addr_t *,864efi_bool_t *);865efi_status_t (__efiapi *hash_log_extend_event)(efi_tcg2_protocol_t *,866u64,867efi_physical_addr_t,868u64,869const efi_tcg2_event_t *);870void *submit_command;871void *get_active_pcr_banks;872void *set_active_pcr_banks;873void *get_result_of_set_active_pcr_banks;874};875struct {876u32 get_capability;877u32 get_event_log;878u32 hash_log_extend_event;879u32 submit_command;880u32 get_active_pcr_banks;881u32 set_active_pcr_banks;882u32 get_result_of_set_active_pcr_banks;883} mixed_mode;884};885886typedef struct {887u8 major;888u8 minor;889} efi_cc_version_t;890891typedef struct {892u8 type;893u8 sub_type;894} efi_cc_type_t;895896/* EFI CC type/subtype defines */897#define EFI_CC_TYPE_NONE 0898#define EFI_CC_TYPE_AMD_SEV 1899#define EFI_CC_TYPE_INTEL_TDX 2900901typedef u32 efi_cc_mr_index_t;902903struct efi_cc_event {904u32 event_size;905struct {906u32 header_size;907u16 header_version;908u32 mr_index;909u32 event_type;910} __packed event_header;911/* u8[] event follows here */912} __packed;913914typedef struct efi_cc_event efi_cc_event_t;915916typedef u32 efi_cc_event_log_bitmap_t;917typedef u32 efi_cc_event_log_format_t;918typedef u32 efi_cc_event_algorithm_bitmap_t;919920typedef struct {921u8 size;922efi_cc_version_t structure_version;923efi_cc_version_t protocol_version;924efi_cc_event_algorithm_bitmap_t hash_algorithm_bitmap;925efi_cc_event_log_bitmap_t supported_event_logs;926efi_cc_type_t cc_type;927} efi_cc_boot_service_cap_t;928929#define EFI_CC_EVENT_HEADER_VERSION 1930931#define EFI_CC_BOOT_HASH_ALG_SHA384 0x00000004932933#define EFI_CC_EVENT_LOG_FORMAT_TCG_2 0x00000002934935typedef union efi_cc_protocol efi_cc_protocol_t;936937union efi_cc_protocol {938struct {939efi_status_t940(__efiapi *get_capability)(efi_cc_protocol_t *,941efi_cc_boot_service_cap_t *);942943efi_status_t944(__efiapi *get_event_log)(efi_cc_protocol_t *,945efi_cc_event_log_format_t,946efi_physical_addr_t *,947efi_physical_addr_t *,948efi_bool_t *);949950efi_status_t951(__efiapi *hash_log_extend_event)(efi_cc_protocol_t *, u64,952efi_physical_addr_t, u64,953const efi_cc_event_t *);954955efi_status_t956(__efiapi *map_pcr_to_mr_index)(efi_cc_protocol_t *, u32,957efi_cc_mr_index_t *);958};959struct {960u32 get_capability;961u32 get_event_log;962u32 hash_log_extend_event;963u32 map_pcr_to_mr_index;964} mixed_mode;965};966967struct riscv_efi_boot_protocol {968u64 revision;969970efi_status_t (__efiapi *get_boot_hartid)(struct riscv_efi_boot_protocol *,971unsigned long *boot_hartid);972};973974typedef union efi_load_file_protocol efi_load_file_protocol_t;975typedef union efi_load_file_protocol efi_load_file2_protocol_t;976977union efi_load_file_protocol {978struct {979efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *,980efi_device_path_protocol_t *,981bool, unsigned long *, void *);982};983struct {984u32 load_file;985} mixed_mode;986};987988typedef struct {989u32 attributes;990u16 file_path_list_length;991u8 variable_data[];992// efi_char16_t description[];993// efi_device_path_protocol_t file_path_list[];994// u8 optional_data[];995} __packed efi_load_option_t;996997#define EFI_LOAD_OPTION_ACTIVE 0x0001U998#define EFI_LOAD_OPTION_FORCE_RECONNECT 0x0002U999#define EFI_LOAD_OPTION_HIDDEN 0x0008U1000#define EFI_LOAD_OPTION_CATEGORY 0x1f00U1001#define EFI_LOAD_OPTION_CATEGORY_BOOT 0x0000U1002#define EFI_LOAD_OPTION_CATEGORY_APP 0x0100U10031004#define EFI_LOAD_OPTION_BOOT_MASK \1005(EFI_LOAD_OPTION_ACTIVE|EFI_LOAD_OPTION_HIDDEN|EFI_LOAD_OPTION_CATEGORY)1006#define EFI_LOAD_OPTION_MASK (EFI_LOAD_OPTION_FORCE_RECONNECT|EFI_LOAD_OPTION_BOOT_MASK)10071008typedef struct {1009u32 attributes;1010u16 file_path_list_length;1011const efi_char16_t *description;1012const efi_device_path_protocol_t *file_path_list;1013u32 optional_data_size;1014const void *optional_data;1015} efi_load_option_unpacked_t;10161017void efi_pci_disable_bridge_busmaster(void);10181019typedef efi_status_t (*efi_exit_boot_map_processing)(1020struct efi_boot_memmap *map,1021void *priv);10221023efi_status_t efi_exit_boot_services(void *handle, void *priv,1024efi_exit_boot_map_processing priv_func);10251026efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,1027unsigned long kernel_addr, char *cmdline_ptr);10281029void *get_fdt(unsigned long *fdt_size);10301031efi_status_t efi_alloc_virtmap(efi_memory_desc_t **virtmap,1032unsigned long *desc_size, u32 *desc_ver);1033void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,1034unsigned long desc_size, efi_memory_desc_t *runtime_map,1035int *count);10361037efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);10381039efi_status_t efi_random_alloc(unsigned long size, unsigned long align,1040unsigned long *addr, unsigned long random_seed,1041int memory_type, unsigned long alloc_min,1042unsigned long alloc_max);10431044efi_status_t efi_random_get_seed(void);10451046efi_status_t check_platform_features(void);10471048void *get_efi_config_table(efi_guid_t guid);10491050/* NOTE: These functions do not print a trailing newline after the string */1051void efi_char16_puts(efi_char16_t *);1052void efi_puts(const char *str);10531054__printf(1, 2) int efi_printk(char const *fmt, ...);10551056void efi_free(unsigned long size, unsigned long addr);1057DEFINE_FREE(efi_pool, void *, if (_T) efi_bs_call(free_pool, _T));10581059void efi_apply_loadoptions_quirk(const void **load_options, u32 *load_options_size);10601061char *efi_convert_cmdline(efi_loaded_image_t *image);10621063efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,1064bool install_cfg_tbl);10651066efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,1067unsigned long max);10681069efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,1070unsigned long max, unsigned long align,1071int memory_type);10721073efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,1074unsigned long *addr, unsigned long min);10751076efi_status_t efi_relocate_kernel(unsigned long *image_addr,1077unsigned long image_size,1078unsigned long alloc_size,1079unsigned long preferred_addr,1080unsigned long alignment,1081unsigned long min_addr);10821083efi_status_t efi_parse_options(char const *cmdline);10841085void efi_parse_option_graphics(char *option);10861087efi_status_t efi_setup_gop(struct screen_info *si);10881089efi_status_t handle_cmdline_files(efi_loaded_image_t *image,1090const efi_char16_t *optstr,1091int optstr_size,1092unsigned long soft_limit,1093unsigned long hard_limit,1094unsigned long *load_addr,1095unsigned long *load_size);109610971098static inline efi_status_t efi_load_dtb(efi_loaded_image_t *image,1099unsigned long *load_addr,1100unsigned long *load_size)1101{1102return handle_cmdline_files(image, L"dtb=", sizeof(L"dtb=") - 2,1103ULONG_MAX, ULONG_MAX, load_addr, load_size);1104}11051106efi_status_t efi_load_initrd(efi_loaded_image_t *image,1107unsigned long soft_limit,1108unsigned long hard_limit,1109const struct linux_efi_initrd **out);1110/*1111* This function handles the architcture specific differences between arm and1112* arm64 regarding where the kernel image must be loaded and any memory that1113* must be reserved. On failure it is required to free all1114* all allocations it has made.1115*/1116efi_status_t handle_kernel_image(unsigned long *image_addr,1117unsigned long *image_size,1118unsigned long *reserve_addr,1119unsigned long *reserve_size,1120efi_loaded_image_t *image,1121efi_handle_t image_handle);11221123/* shared entrypoint between the normal stub and the zboot stub */1124efi_status_t efi_stub_common(efi_handle_t handle,1125efi_loaded_image_t *image,1126unsigned long image_addr,1127char *cmdline_ptr);11281129efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr);11301131asmlinkage void __noreturn efi_enter_kernel(unsigned long entrypoint,1132unsigned long fdt_addr,1133unsigned long fdt_size);11341135void efi_handle_post_ebs_state(void);11361137enum efi_secureboot_mode efi_get_secureboot(void);11381139#ifdef CONFIG_RESET_ATTACK_MITIGATION1140void efi_enable_reset_attack_mitigation(void);1141#else1142static inline void1143efi_enable_reset_attack_mitigation(void) { }1144#endif11451146void efi_retrieve_eventlog(void);11471148struct screen_info *alloc_screen_info(void);1149struct screen_info *__alloc_screen_info(void);1150void free_screen_info(struct screen_info *si);11511152void efi_cache_sync_image(unsigned long image_base,1153unsigned long alloc_size);11541155struct efi_smbios_record {1156u8 type;1157u8 length;1158u16 handle;1159};11601161const struct efi_smbios_record *efi_get_smbios_record(u8 type);11621163struct efi_smbios_type1_record {1164struct efi_smbios_record header;11651166u8 manufacturer;1167u8 product_name;1168u8 version;1169u8 serial_number;1170efi_guid_t uuid;1171u8 wakeup_type;1172u8 sku_number;1173u8 family;1174};11751176struct efi_smbios_type4_record {1177struct efi_smbios_record header;11781179u8 socket;1180u8 processor_type;1181u8 processor_family;1182u8 processor_manufacturer;1183u8 processor_id[8];1184u8 processor_version;1185u8 voltage;1186u16 external_clock;1187u16 max_speed;1188u16 current_speed;1189u8 status;1190u8 processor_upgrade;1191u16 l1_cache_handle;1192u16 l2_cache_handle;1193u16 l3_cache_handle;1194u8 serial_number;1195u8 asset_tag;1196u8 part_number;1197u8 core_count;1198u8 enabled_core_count;1199u8 thread_count;1200u16 processor_characteristics;1201u16 processor_family2;1202u16 core_count2;1203u16 enabled_core_count2;1204u16 thread_count2;1205u16 thread_enabled;1206};12071208#define efi_get_smbios_string(__record, __field) ({ \1209__typeof__(__record) __rec = __record; \1210__efi_get_smbios_string(&__rec->header, &__rec->__field); \1211})12121213const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record,1214const u8 *offset);12151216void efi_remap_image(unsigned long image_base, unsigned alloc_size,1217unsigned long code_size);1218efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,1219unsigned long *reserve_addr,1220unsigned long *reserve_size,1221unsigned long kernel_size,1222unsigned long kernel_codesize,1223unsigned long kernel_memsize,1224u32 phys_seed);1225u32 efi_kaslr_get_phys_seed(efi_handle_t image_handle);12261227asmlinkage efi_status_t __efiapi1228efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab);12291230efi_status_t allocate_unaccepted_bitmap(__u32 nr_desc,1231struct efi_boot_memmap *map);1232void process_unaccepted_memory(u64 start, u64 end);1233void accept_memory(phys_addr_t start, unsigned long size);1234void arch_accept_memory(phys_addr_t start, phys_addr_t end);12351236efi_status_t efi_zboot_decompress_init(unsigned long *alloc_size);1237efi_status_t efi_zboot_decompress(u8 *out, unsigned long outlen);12381239#endif124012411242