Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 
0003 #ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H
0004 #define _DRIVERS_FIRMWARE_EFI_EFISTUB_H
0005 
0006 #include <linux/compiler.h>
0007 #include <linux/efi.h>
0008 #include <linux/kernel.h>
0009 #include <linux/kern_levels.h>
0010 #include <linux/types.h>
0011 #include <asm/efi.h>
0012 
0013 /*
0014  * __init annotations should not be used in the EFI stub, since the code is
0015  * either included in the decompressor (x86, ARM) where they have no effect,
0016  * or the whole stub is __init annotated at the section level (arm64), by
0017  * renaming the sections, in which case the __init annotation will be
0018  * redundant, and will result in section names like .init.init.text, and our
0019  * linker script does not expect that.
0020  */
0021 #undef __init
0022 
0023 /*
0024  * Allow the platform to override the allocation granularity: this allows
0025  * systems that have the capability to run with a larger page size to deal
0026  * with the allocations for initrd and fdt more efficiently.
0027  */
0028 #ifndef EFI_ALLOC_ALIGN
0029 #define EFI_ALLOC_ALIGN     EFI_PAGE_SIZE
0030 #endif
0031 
0032 extern bool efi_nochunk;
0033 extern bool efi_nokaslr;
0034 extern int efi_loglevel;
0035 extern bool efi_novamap;
0036 
0037 extern const efi_system_table_t *efi_system_table;
0038 
0039 typedef union efi_dxe_services_table efi_dxe_services_table_t;
0040 extern const efi_dxe_services_table_t *efi_dxe_table;
0041 
0042 efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
0043                    efi_system_table_t *sys_table_arg);
0044 
0045 #ifndef ARCH_HAS_EFISTUB_WRAPPERS
0046 
0047 #define efi_is_native()     (true)
0048 #define efi_bs_call(func, ...)  efi_system_table->boottime->func(__VA_ARGS__)
0049 #define efi_rt_call(func, ...)  efi_system_table->runtime->func(__VA_ARGS__)
0050 #define efi_dxe_call(func, ...) efi_dxe_table->func(__VA_ARGS__)
0051 #define efi_table_attr(inst, attr)  (inst->attr)
0052 #define efi_call_proto(inst, func, ...) inst->func(inst, ##__VA_ARGS__)
0053 
0054 #endif
0055 
0056 #define efi_info(fmt, ...) \
0057     efi_printk(KERN_INFO fmt, ##__VA_ARGS__)
0058 #define efi_warn(fmt, ...) \
0059     efi_printk(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
0060 #define efi_err(fmt, ...) \
0061     efi_printk(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)
0062 #define efi_debug(fmt, ...) \
0063     efi_printk(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)
0064 
0065 #define efi_printk_once(fmt, ...)       \
0066 ({                      \
0067     static bool __print_once;       \
0068     bool __ret_print_once = !__print_once;  \
0069                         \
0070     if (!__print_once) {            \
0071         __print_once = true;        \
0072         efi_printk(fmt, ##__VA_ARGS__); \
0073     }                   \
0074     __ret_print_once;           \
0075 })
0076 
0077 #define efi_info_once(fmt, ...) \
0078     efi_printk_once(KERN_INFO fmt, ##__VA_ARGS__)
0079 #define efi_warn_once(fmt, ...) \
0080     efi_printk_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
0081 #define efi_err_once(fmt, ...) \
0082     efi_printk_once(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)
0083 #define efi_debug_once(fmt, ...) \
0084     efi_printk_once(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)
0085 
0086 /* Helper macros for the usual case of using simple C variables: */
0087 #ifndef fdt_setprop_inplace_var
0088 #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \
0089     fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))
0090 #endif
0091 
0092 #ifndef fdt_setprop_var
0093 #define fdt_setprop_var(fdt, node_offset, name, var) \
0094     fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))
0095 #endif
0096 
0097 #define get_efi_var(name, vendor, ...)              \
0098     efi_rt_call(get_variable, (efi_char16_t *)(name),   \
0099             (efi_guid_t *)(vendor), __VA_ARGS__)
0100 
0101 #define set_efi_var(name, vendor, ...)              \
0102     efi_rt_call(set_variable, (efi_char16_t *)(name),   \
0103             (efi_guid_t *)(vendor), __VA_ARGS__)
0104 
0105 #define efi_get_handle_at(array, idx)                   \
0106     (efi_is_native() ? (array)[idx]                 \
0107         : (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
0108 
0109 #define efi_get_handle_num(size)                    \
0110     ((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))
0111 
0112 #define for_each_efi_handle(handle, array, size, i)         \
0113     for (i = 0;                         \
0114          i < efi_get_handle_num(size) &&                \
0115         ((handle = efi_get_handle_at((array), i)) || true); \
0116          i++)
0117 
0118 static inline
0119 void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)
0120 {
0121     *lo = lower_32_bits(data);
0122     *hi = upper_32_bits(data);
0123 }
0124 
0125 /*
0126  * Allocation types for calls to boottime->allocate_pages.
0127  */
0128 #define EFI_ALLOCATE_ANY_PAGES      0
0129 #define EFI_ALLOCATE_MAX_ADDRESS    1
0130 #define EFI_ALLOCATE_ADDRESS        2
0131 #define EFI_MAX_ALLOCATE_TYPE       3
0132 
0133 /*
0134  * The type of search to perform when calling boottime->locate_handle
0135  */
0136 #define EFI_LOCATE_ALL_HANDLES          0
0137 #define EFI_LOCATE_BY_REGISTER_NOTIFY       1
0138 #define EFI_LOCATE_BY_PROTOCOL          2
0139 
0140 /*
0141  * boottime->stall takes the time period in microseconds
0142  */
0143 #define EFI_USEC_PER_SEC        1000000
0144 
0145 /*
0146  * boottime->set_timer takes the time in 100ns units
0147  */
0148 #define EFI_100NSEC_PER_USEC    ((u64)10)
0149 
0150 /*
0151  * An efi_boot_memmap is used by efi_get_memory_map() to return the
0152  * EFI memory map in a dynamically allocated buffer.
0153  *
0154  * The buffer allocated for the EFI memory map includes extra room for
0155  * a minimum of EFI_MMAP_NR_SLACK_SLOTS additional EFI memory descriptors.
0156  * This facilitates the reuse of the EFI memory map buffer when a second
0157  * call to ExitBootServices() is needed because of intervening changes to
0158  * the EFI memory map. Other related structures, e.g. x86 e820ext, need
0159  * to factor in this headroom requirement as well.
0160  */
0161 #define EFI_MMAP_NR_SLACK_SLOTS 8
0162 
0163 struct efi_boot_memmap {
0164     efi_memory_desc_t   **map;
0165     unsigned long       *map_size;
0166     unsigned long       *desc_size;
0167     u32         *desc_ver;
0168     unsigned long       *key_ptr;
0169     unsigned long       *buff_size;
0170 };
0171 
0172 typedef struct efi_generic_dev_path efi_device_path_protocol_t;
0173 
0174 typedef void *efi_event_t;
0175 /* Note that notifications won't work in mixed mode */
0176 typedef void (__efiapi *efi_event_notify_t)(efi_event_t, void *);
0177 
0178 #define EFI_EVT_TIMER       0x80000000U
0179 #define EFI_EVT_RUNTIME     0x40000000U
0180 #define EFI_EVT_NOTIFY_WAIT 0x00000100U
0181 #define EFI_EVT_NOTIFY_SIGNAL   0x00000200U
0182 
0183 /**
0184  * efi_set_event_at() - add event to events array
0185  *
0186  * @events: array of UEFI events
0187  * @ids:    index where to put the event in the array
0188  * @event:  event to add to the aray
0189  *
0190  * boottime->wait_for_event() takes an array of events as input.
0191  * Provide a helper to set it up correctly for mixed mode.
0192  */
0193 static inline
0194 void efi_set_event_at(efi_event_t *events, size_t idx, efi_event_t event)
0195 {
0196     if (efi_is_native())
0197         events[idx] = event;
0198     else
0199         ((u32 *)events)[idx] = (u32)(unsigned long)event;
0200 }
0201 
0202 #define EFI_TPL_APPLICATION 4
0203 #define EFI_TPL_CALLBACK    8
0204 #define EFI_TPL_NOTIFY      16
0205 #define EFI_TPL_HIGH_LEVEL  31
0206 
0207 typedef enum {
0208     EfiTimerCancel,
0209     EfiTimerPeriodic,
0210     EfiTimerRelative
0211 } EFI_TIMER_DELAY;
0212 
0213 /*
0214  * EFI Boot Services table
0215  */
0216 union efi_boot_services {
0217     struct {
0218         efi_table_hdr_t hdr;
0219         void *raise_tpl;
0220         void *restore_tpl;
0221         efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,
0222                             efi_physical_addr_t *);
0223         efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,
0224                             unsigned long);
0225         efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,
0226                             unsigned long *,
0227                             unsigned long *, u32 *);
0228         efi_status_t (__efiapi *allocate_pool)(int, unsigned long,
0229                                void **);
0230         efi_status_t (__efiapi *free_pool)(void *);
0231         efi_status_t (__efiapi *create_event)(u32, unsigned long,
0232                               efi_event_notify_t, void *,
0233                               efi_event_t *);
0234         efi_status_t (__efiapi *set_timer)(efi_event_t,
0235                           EFI_TIMER_DELAY, u64);
0236         efi_status_t (__efiapi *wait_for_event)(unsigned long,
0237                             efi_event_t *,
0238                             unsigned long *);
0239         void *signal_event;
0240         efi_status_t (__efiapi *close_event)(efi_event_t);
0241         void *check_event;
0242         void *install_protocol_interface;
0243         void *reinstall_protocol_interface;
0244         void *uninstall_protocol_interface;
0245         efi_status_t (__efiapi *handle_protocol)(efi_handle_t,
0246                              efi_guid_t *, void **);
0247         void *__reserved;
0248         void *register_protocol_notify;
0249         efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,
0250                                void *, unsigned long *,
0251                                efi_handle_t *);
0252         efi_status_t (__efiapi *locate_device_path)(efi_guid_t *,
0253                                 efi_device_path_protocol_t **,
0254                                 efi_handle_t *);
0255         efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,
0256                                      void *);
0257         void *load_image;
0258         void *start_image;
0259         efi_status_t __noreturn (__efiapi *exit)(efi_handle_t,
0260                              efi_status_t,
0261                              unsigned long,
0262                              efi_char16_t *);
0263         void *unload_image;
0264         efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,
0265                                 unsigned long);
0266         void *get_next_monotonic_count;
0267         efi_status_t (__efiapi *stall)(unsigned long);
0268         void *set_watchdog_timer;
0269         void *connect_controller;
0270         efi_status_t (__efiapi *disconnect_controller)(efi_handle_t,
0271                                    efi_handle_t,
0272                                    efi_handle_t);
0273         void *open_protocol;
0274         void *close_protocol;
0275         void *open_protocol_information;
0276         void *protocols_per_handle;
0277         void *locate_handle_buffer;
0278         efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,
0279                              void **);
0280         void *install_multiple_protocol_interfaces;
0281         void *uninstall_multiple_protocol_interfaces;
0282         void *calculate_crc32;
0283         void *copy_mem;
0284         void *set_mem;
0285         void *create_event_ex;
0286     };
0287     struct {
0288         efi_table_hdr_t hdr;
0289         u32 raise_tpl;
0290         u32 restore_tpl;
0291         u32 allocate_pages;
0292         u32 free_pages;
0293         u32 get_memory_map;
0294         u32 allocate_pool;
0295         u32 free_pool;
0296         u32 create_event;
0297         u32 set_timer;
0298         u32 wait_for_event;
0299         u32 signal_event;
0300         u32 close_event;
0301         u32 check_event;
0302         u32 install_protocol_interface;
0303         u32 reinstall_protocol_interface;
0304         u32 uninstall_protocol_interface;
0305         u32 handle_protocol;
0306         u32 __reserved;
0307         u32 register_protocol_notify;
0308         u32 locate_handle;
0309         u32 locate_device_path;
0310         u32 install_configuration_table;
0311         u32 load_image;
0312         u32 start_image;
0313         u32 exit;
0314         u32 unload_image;
0315         u32 exit_boot_services;
0316         u32 get_next_monotonic_count;
0317         u32 stall;
0318         u32 set_watchdog_timer;
0319         u32 connect_controller;
0320         u32 disconnect_controller;
0321         u32 open_protocol;
0322         u32 close_protocol;
0323         u32 open_protocol_information;
0324         u32 protocols_per_handle;
0325         u32 locate_handle_buffer;
0326         u32 locate_protocol;
0327         u32 install_multiple_protocol_interfaces;
0328         u32 uninstall_multiple_protocol_interfaces;
0329         u32 calculate_crc32;
0330         u32 copy_mem;
0331         u32 set_mem;
0332         u32 create_event_ex;
0333     } mixed_mode;
0334 };
0335 
0336 typedef enum {
0337     EfiGcdMemoryTypeNonExistent,
0338     EfiGcdMemoryTypeReserved,
0339     EfiGcdMemoryTypeSystemMemory,
0340     EfiGcdMemoryTypeMemoryMappedIo,
0341     EfiGcdMemoryTypePersistent,
0342     EfiGcdMemoryTypeMoreReliable,
0343     EfiGcdMemoryTypeMaximum
0344 } efi_gcd_memory_type_t;
0345 
0346 typedef struct {
0347     efi_physical_addr_t base_address;
0348     u64 length;
0349     u64 capabilities;
0350     u64 attributes;
0351     efi_gcd_memory_type_t gcd_memory_type;
0352     void *image_handle;
0353     void *device_handle;
0354 } efi_gcd_memory_space_desc_t;
0355 
0356 /*
0357  * EFI DXE Services table
0358  */
0359 union efi_dxe_services_table {
0360     struct {
0361         efi_table_hdr_t hdr;
0362         void *add_memory_space;
0363         void *allocate_memory_space;
0364         void *free_memory_space;
0365         void *remove_memory_space;
0366         efi_status_t (__efiapi *get_memory_space_descriptor)(efi_physical_addr_t,
0367                                      efi_gcd_memory_space_desc_t *);
0368         efi_status_t (__efiapi *set_memory_space_attributes)(efi_physical_addr_t,
0369                                      u64, u64);
0370         void *get_memory_space_map;
0371         void *add_io_space;
0372         void *allocate_io_space;
0373         void *free_io_space;
0374         void *remove_io_space;
0375         void *get_io_space_descriptor;
0376         void *get_io_space_map;
0377         void *dispatch;
0378         void *schedule;
0379         void *trust;
0380         void *process_firmware_volume;
0381         void *set_memory_space_capabilities;
0382     };
0383     struct {
0384         efi_table_hdr_t hdr;
0385         u32 add_memory_space;
0386         u32 allocate_memory_space;
0387         u32 free_memory_space;
0388         u32 remove_memory_space;
0389         u32 get_memory_space_descriptor;
0390         u32 set_memory_space_attributes;
0391         u32 get_memory_space_map;
0392         u32 add_io_space;
0393         u32 allocate_io_space;
0394         u32 free_io_space;
0395         u32 remove_io_space;
0396         u32 get_io_space_descriptor;
0397         u32 get_io_space_map;
0398         u32 dispatch;
0399         u32 schedule;
0400         u32 trust;
0401         u32 process_firmware_volume;
0402         u32 set_memory_space_capabilities;
0403     } mixed_mode;
0404 };
0405 
0406 typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
0407 
0408 union efi_uga_draw_protocol {
0409     struct {
0410         efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,
0411                           u32*, u32*, u32*, u32*);
0412         void *set_mode;
0413         void *blt;
0414     };
0415     struct {
0416         u32 get_mode;
0417         u32 set_mode;
0418         u32 blt;
0419     } mixed_mode;
0420 };
0421 
0422 typedef struct {
0423     u16 scan_code;
0424     efi_char16_t unicode_char;
0425 } efi_input_key_t;
0426 
0427 union efi_simple_text_input_protocol {
0428     struct {
0429         void *reset;
0430         efi_status_t (__efiapi *read_keystroke)(efi_simple_text_input_protocol_t *,
0431                             efi_input_key_t *);
0432         efi_event_t wait_for_key;
0433     };
0434     struct {
0435         u32 reset;
0436         u32 read_keystroke;
0437         u32 wait_for_key;
0438     } mixed_mode;
0439 };
0440 
0441 efi_status_t efi_wait_for_key(unsigned long usec, efi_input_key_t *key);
0442 
0443 union efi_simple_text_output_protocol {
0444     struct {
0445         void *reset;
0446         efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
0447                                efi_char16_t *);
0448         void *test_string;
0449     };
0450     struct {
0451         u32 reset;
0452         u32 output_string;
0453         u32 test_string;
0454     } mixed_mode;
0455 };
0456 
0457 #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR       0
0458 #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR       1
0459 #define PIXEL_BIT_MASK                  2
0460 #define PIXEL_BLT_ONLY                  3
0461 #define PIXEL_FORMAT_MAX                4
0462 
0463 typedef struct {
0464     u32 red_mask;
0465     u32 green_mask;
0466     u32 blue_mask;
0467     u32 reserved_mask;
0468 } efi_pixel_bitmask_t;
0469 
0470 typedef struct {
0471     u32 version;
0472     u32 horizontal_resolution;
0473     u32 vertical_resolution;
0474     int pixel_format;
0475     efi_pixel_bitmask_t pixel_information;
0476     u32 pixels_per_scan_line;
0477 } efi_graphics_output_mode_info_t;
0478 
0479 typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;
0480 
0481 union efi_graphics_output_protocol_mode {
0482     struct {
0483         u32 max_mode;
0484         u32 mode;
0485         efi_graphics_output_mode_info_t *info;
0486         unsigned long size_of_info;
0487         efi_physical_addr_t frame_buffer_base;
0488         unsigned long frame_buffer_size;
0489     };
0490     struct {
0491         u32 max_mode;
0492         u32 mode;
0493         u32 info;
0494         u32 size_of_info;
0495         u64 frame_buffer_base;
0496         u32 frame_buffer_size;
0497     } mixed_mode;
0498 };
0499 
0500 typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;
0501 
0502 union efi_graphics_output_protocol {
0503     struct {
0504         efi_status_t (__efiapi *query_mode)(efi_graphics_output_protocol_t *,
0505                             u32, unsigned long *,
0506                             efi_graphics_output_mode_info_t **);
0507         efi_status_t (__efiapi *set_mode)  (efi_graphics_output_protocol_t *, u32);
0508         void *blt;
0509         efi_graphics_output_protocol_mode_t *mode;
0510     };
0511     struct {
0512         u32 query_mode;
0513         u32 set_mode;
0514         u32 blt;
0515         u32 mode;
0516     } mixed_mode;
0517 };
0518 
0519 typedef union {
0520     struct {
0521         u32         revision;
0522         efi_handle_t        parent_handle;
0523         efi_system_table_t  *system_table;
0524         efi_handle_t        device_handle;
0525         void            *file_path;
0526         void            *reserved;
0527         u32         load_options_size;
0528         void            *load_options;
0529         void            *image_base;
0530         __aligned_u64       image_size;
0531         unsigned int        image_code_type;
0532         unsigned int        image_data_type;
0533         efi_status_t        (__efiapi *unload)(efi_handle_t image_handle);
0534     };
0535     struct {
0536         u32     revision;
0537         u32     parent_handle;
0538         u32     system_table;
0539         u32     device_handle;
0540         u32     file_path;
0541         u32     reserved;
0542         u32     load_options_size;
0543         u32     load_options;
0544         u32     image_base;
0545         __aligned_u64   image_size;
0546         u32     image_code_type;
0547         u32     image_data_type;
0548         u32     unload;
0549     } mixed_mode;
0550 } efi_loaded_image_t;
0551 
0552 typedef struct {
0553     u64         size;
0554     u64         file_size;
0555     u64         phys_size;
0556     efi_time_t      create_time;
0557     efi_time_t      last_access_time;
0558     efi_time_t      modification_time;
0559     __aligned_u64       attribute;
0560     efi_char16_t        filename[];
0561 } efi_file_info_t;
0562 
0563 typedef struct efi_file_protocol efi_file_protocol_t;
0564 
0565 struct efi_file_protocol {
0566     u64     revision;
0567     efi_status_t    (__efiapi *open)    (efi_file_protocol_t *,
0568                          efi_file_protocol_t **,
0569                          efi_char16_t *, u64, u64);
0570     efi_status_t    (__efiapi *close)   (efi_file_protocol_t *);
0571     efi_status_t    (__efiapi *delete)  (efi_file_protocol_t *);
0572     efi_status_t    (__efiapi *read)    (efi_file_protocol_t *,
0573                          unsigned long *, void *);
0574     efi_status_t    (__efiapi *write)   (efi_file_protocol_t *,
0575                          unsigned long, void *);
0576     efi_status_t    (__efiapi *get_position)(efi_file_protocol_t *, u64 *);
0577     efi_status_t    (__efiapi *set_position)(efi_file_protocol_t *, u64);
0578     efi_status_t    (__efiapi *get_info)    (efi_file_protocol_t *,
0579                          efi_guid_t *, unsigned long *,
0580                          void *);
0581     efi_status_t    (__efiapi *set_info)    (efi_file_protocol_t *,
0582                          efi_guid_t *, unsigned long,
0583                          void *);
0584     efi_status_t    (__efiapi *flush)   (efi_file_protocol_t *);
0585 };
0586 
0587 typedef struct efi_simple_file_system_protocol efi_simple_file_system_protocol_t;
0588 
0589 struct efi_simple_file_system_protocol {
0590     u64 revision;
0591     int (__efiapi *open_volume)(efi_simple_file_system_protocol_t *,
0592                     efi_file_protocol_t **);
0593 };
0594 
0595 #define EFI_FILE_MODE_READ  0x0000000000000001
0596 #define EFI_FILE_MODE_WRITE 0x0000000000000002
0597 #define EFI_FILE_MODE_CREATE    0x8000000000000000
0598 
0599 typedef enum {
0600     EfiPciIoWidthUint8,
0601     EfiPciIoWidthUint16,
0602     EfiPciIoWidthUint32,
0603     EfiPciIoWidthUint64,
0604     EfiPciIoWidthFifoUint8,
0605     EfiPciIoWidthFifoUint16,
0606     EfiPciIoWidthFifoUint32,
0607     EfiPciIoWidthFifoUint64,
0608     EfiPciIoWidthFillUint8,
0609     EfiPciIoWidthFillUint16,
0610     EfiPciIoWidthFillUint32,
0611     EfiPciIoWidthFillUint64,
0612     EfiPciIoWidthMaximum
0613 } EFI_PCI_IO_PROTOCOL_WIDTH;
0614 
0615 typedef enum {
0616     EfiPciIoAttributeOperationGet,
0617     EfiPciIoAttributeOperationSet,
0618     EfiPciIoAttributeOperationEnable,
0619     EfiPciIoAttributeOperationDisable,
0620     EfiPciIoAttributeOperationSupported,
0621     EfiPciIoAttributeOperationMaximum
0622 } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
0623 
0624 typedef struct {
0625     u32 read;
0626     u32 write;
0627 } efi_pci_io_protocol_access_32_t;
0628 
0629 typedef union efi_pci_io_protocol efi_pci_io_protocol_t;
0630 
0631 typedef
0632 efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
0633                            EFI_PCI_IO_PROTOCOL_WIDTH,
0634                            u32 offset,
0635                            unsigned long count,
0636                            void *buffer);
0637 
0638 typedef struct {
0639     void *read;
0640     void *write;
0641 } efi_pci_io_protocol_access_t;
0642 
0643 typedef struct {
0644     efi_pci_io_protocol_cfg_t read;
0645     efi_pci_io_protocol_cfg_t write;
0646 } efi_pci_io_protocol_config_access_t;
0647 
0648 union efi_pci_io_protocol {
0649     struct {
0650         void *poll_mem;
0651         void *poll_io;
0652         efi_pci_io_protocol_access_t mem;
0653         efi_pci_io_protocol_access_t io;
0654         efi_pci_io_protocol_config_access_t pci;
0655         void *copy_mem;
0656         void *map;
0657         void *unmap;
0658         void *allocate_buffer;
0659         void *free_buffer;
0660         void *flush;
0661         efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,
0662                               unsigned long *segment_nr,
0663                               unsigned long *bus_nr,
0664                               unsigned long *device_nr,
0665                               unsigned long *func_nr);
0666         void *attributes;
0667         void *get_bar_attributes;
0668         void *set_bar_attributes;
0669         uint64_t romsize;
0670         void *romimage;
0671     };
0672     struct {
0673         u32 poll_mem;
0674         u32 poll_io;
0675         efi_pci_io_protocol_access_32_t mem;
0676         efi_pci_io_protocol_access_32_t io;
0677         efi_pci_io_protocol_access_32_t pci;
0678         u32 copy_mem;
0679         u32 map;
0680         u32 unmap;
0681         u32 allocate_buffer;
0682         u32 free_buffer;
0683         u32 flush;
0684         u32 get_location;
0685         u32 attributes;
0686         u32 get_bar_attributes;
0687         u32 set_bar_attributes;
0688         u64 romsize;
0689         u32 romimage;
0690     } mixed_mode;
0691 };
0692 
0693 #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
0694 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
0695 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
0696 #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
0697 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
0698 #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
0699 #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
0700 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
0701 #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
0702 #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
0703 #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
0704 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
0705 #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
0706 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
0707 #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
0708 #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
0709 #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
0710 #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
0711 #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
0712 
0713 struct efi_dev_path;
0714 
0715 typedef union apple_properties_protocol apple_properties_protocol_t;
0716 
0717 union apple_properties_protocol {
0718     struct {
0719         unsigned long version;
0720         efi_status_t (__efiapi *get)(apple_properties_protocol_t *,
0721                          struct efi_dev_path *,
0722                          efi_char16_t *, void *, u32 *);
0723         efi_status_t (__efiapi *set)(apple_properties_protocol_t *,
0724                          struct efi_dev_path *,
0725                          efi_char16_t *, void *, u32);
0726         efi_status_t (__efiapi *del)(apple_properties_protocol_t *,
0727                          struct efi_dev_path *,
0728                          efi_char16_t *);
0729         efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,
0730                          void *buffer, u32 *);
0731     };
0732     struct {
0733         u32 version;
0734         u32 get;
0735         u32 set;
0736         u32 del;
0737         u32 get_all;
0738     } mixed_mode;
0739 };
0740 
0741 typedef u32 efi_tcg2_event_log_format;
0742 
0743 #define INITRD_EVENT_TAG_ID 0x8F3B22ECU
0744 #define EV_EVENT_TAG 0x00000006U
0745 #define EFI_TCG2_EVENT_HEADER_VERSION   0x1
0746 
0747 struct efi_tcg2_event {
0748     u32     event_size;
0749     struct {
0750         u32 header_size;
0751         u16 header_version;
0752         u32 pcr_index;
0753         u32 event_type;
0754     } __packed event_header;
0755     /* u8[] event follows here */
0756 } __packed;
0757 
0758 struct efi_tcg2_tagged_event {
0759     u32 tagged_event_id;
0760     u32 tagged_event_data_size;
0761     /* u8  tagged event data follows here */
0762 } __packed;
0763 
0764 typedef struct efi_tcg2_event efi_tcg2_event_t;
0765 typedef struct efi_tcg2_tagged_event efi_tcg2_tagged_event_t;
0766 typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
0767 
0768 union efi_tcg2_protocol {
0769     struct {
0770         void *get_capability;
0771         efi_status_t (__efiapi *get_event_log)(efi_tcg2_protocol_t *,
0772                                efi_tcg2_event_log_format,
0773                                efi_physical_addr_t *,
0774                                efi_physical_addr_t *,
0775                                efi_bool_t *);
0776         efi_status_t (__efiapi *hash_log_extend_event)(efi_tcg2_protocol_t *,
0777                                    u64,
0778                                    efi_physical_addr_t,
0779                                    u64,
0780                                    const efi_tcg2_event_t *);
0781         void *submit_command;
0782         void *get_active_pcr_banks;
0783         void *set_active_pcr_banks;
0784         void *get_result_of_set_active_pcr_banks;
0785     };
0786     struct {
0787         u32 get_capability;
0788         u32 get_event_log;
0789         u32 hash_log_extend_event;
0790         u32 submit_command;
0791         u32 get_active_pcr_banks;
0792         u32 set_active_pcr_banks;
0793         u32 get_result_of_set_active_pcr_banks;
0794     } mixed_mode;
0795 };
0796 
0797 struct riscv_efi_boot_protocol {
0798     u64 revision;
0799 
0800     efi_status_t (__efiapi *get_boot_hartid)(struct riscv_efi_boot_protocol *,
0801                          unsigned long *boot_hartid);
0802 };
0803 
0804 typedef union efi_load_file_protocol efi_load_file_protocol_t;
0805 typedef union efi_load_file_protocol efi_load_file2_protocol_t;
0806 
0807 union efi_load_file_protocol {
0808     struct {
0809         efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *,
0810                            efi_device_path_protocol_t *,
0811                            bool, unsigned long *, void *);
0812     };
0813     struct {
0814         u32 load_file;
0815     } mixed_mode;
0816 };
0817 
0818 typedef struct {
0819     u32 attributes;
0820     u16 file_path_list_length;
0821     u8 variable_data[];
0822     // efi_char16_t description[];
0823     // efi_device_path_protocol_t file_path_list[];
0824     // u8 optional_data[];
0825 } __packed efi_load_option_t;
0826 
0827 #define EFI_LOAD_OPTION_ACTIVE      0x0001U
0828 #define EFI_LOAD_OPTION_FORCE_RECONNECT 0x0002U
0829 #define EFI_LOAD_OPTION_HIDDEN      0x0008U
0830 #define EFI_LOAD_OPTION_CATEGORY    0x1f00U
0831 #define   EFI_LOAD_OPTION_CATEGORY_BOOT 0x0000U
0832 #define   EFI_LOAD_OPTION_CATEGORY_APP  0x0100U
0833 
0834 #define EFI_LOAD_OPTION_BOOT_MASK \
0835     (EFI_LOAD_OPTION_ACTIVE|EFI_LOAD_OPTION_HIDDEN|EFI_LOAD_OPTION_CATEGORY)
0836 #define EFI_LOAD_OPTION_MASK (EFI_LOAD_OPTION_FORCE_RECONNECT|EFI_LOAD_OPTION_BOOT_MASK)
0837 
0838 typedef struct {
0839     u32 attributes;
0840     u16 file_path_list_length;
0841     const efi_char16_t *description;
0842     const efi_device_path_protocol_t *file_path_list;
0843     size_t optional_data_size;
0844     const void *optional_data;
0845 } efi_load_option_unpacked_t;
0846 
0847 void efi_pci_disable_bridge_busmaster(void);
0848 
0849 typedef efi_status_t (*efi_exit_boot_map_processing)(
0850     struct efi_boot_memmap *map,
0851     void *priv);
0852 
0853 efi_status_t efi_exit_boot_services(void *handle,
0854                     struct efi_boot_memmap *map,
0855                     void *priv,
0856                     efi_exit_boot_map_processing priv_func);
0857 
0858 efi_status_t allocate_new_fdt_and_exit_boot(void *handle,
0859                         unsigned long *new_fdt_addr,
0860                         u64 initrd_addr, u64 initrd_size,
0861                         char *cmdline_ptr,
0862                         unsigned long fdt_addr,
0863                         unsigned long fdt_size);
0864 
0865 void *get_fdt(unsigned long *fdt_size);
0866 
0867 void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
0868              unsigned long desc_size, efi_memory_desc_t *runtime_map,
0869              int *count);
0870 
0871 efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
0872 
0873 efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
0874                   unsigned long *addr, unsigned long random_seed);
0875 
0876 efi_status_t check_platform_features(void);
0877 
0878 void *get_efi_config_table(efi_guid_t guid);
0879 
0880 /* NOTE: These functions do not print a trailing newline after the string */
0881 void efi_char16_puts(efi_char16_t *);
0882 void efi_puts(const char *str);
0883 
0884 __printf(1, 2) int efi_printk(char const *fmt, ...);
0885 
0886 void efi_free(unsigned long size, unsigned long addr);
0887 
0888 void efi_apply_loadoptions_quirk(const void **load_options, int *load_options_size);
0889 
0890 char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len);
0891 
0892 efi_status_t efi_get_memory_map(struct efi_boot_memmap *map);
0893 
0894 efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,
0895                 unsigned long max);
0896 
0897 efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,
0898                     unsigned long max, unsigned long align);
0899 
0900 efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,
0901                  unsigned long *addr, unsigned long min);
0902 
0903 efi_status_t efi_relocate_kernel(unsigned long *image_addr,
0904                  unsigned long image_size,
0905                  unsigned long alloc_size,
0906                  unsigned long preferred_addr,
0907                  unsigned long alignment,
0908                  unsigned long min_addr);
0909 
0910 efi_status_t efi_parse_options(char const *cmdline);
0911 
0912 void efi_parse_option_graphics(char *option);
0913 
0914 efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto,
0915                unsigned long size);
0916 
0917 efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
0918                   const efi_char16_t *optstr,
0919                   int optstr_size,
0920                   unsigned long soft_limit,
0921                   unsigned long hard_limit,
0922                   unsigned long *load_addr,
0923                   unsigned long *load_size);
0924 
0925 
0926 static inline efi_status_t efi_load_dtb(efi_loaded_image_t *image,
0927                     unsigned long *load_addr,
0928                     unsigned long *load_size)
0929 {
0930     return handle_cmdline_files(image, L"dtb=", sizeof(L"dtb=") - 2,
0931                     ULONG_MAX, ULONG_MAX, load_addr, load_size);
0932 }
0933 
0934 efi_status_t efi_load_initrd(efi_loaded_image_t *image,
0935                  unsigned long *load_addr,
0936                  unsigned long *load_size,
0937                  unsigned long soft_limit,
0938                  unsigned long hard_limit);
0939 /*
0940  * This function handles the architcture specific differences between arm and
0941  * arm64 regarding where the kernel image must be loaded and any memory that
0942  * must be reserved. On failure it is required to free all
0943  * all allocations it has made.
0944  */
0945 efi_status_t handle_kernel_image(unsigned long *image_addr,
0946                  unsigned long *image_size,
0947                  unsigned long *reserve_addr,
0948                  unsigned long *reserve_size,
0949                  efi_loaded_image_t *image,
0950                  efi_handle_t image_handle);
0951 
0952 asmlinkage void __noreturn efi_enter_kernel(unsigned long entrypoint,
0953                         unsigned long fdt_addr,
0954                         unsigned long fdt_size);
0955 
0956 void efi_handle_post_ebs_state(void);
0957 
0958 enum efi_secureboot_mode efi_get_secureboot(void);
0959 
0960 #ifdef CONFIG_RESET_ATTACK_MITIGATION
0961 void efi_enable_reset_attack_mitigation(void);
0962 #else
0963 static inline void
0964 efi_enable_reset_attack_mitigation(void) { }
0965 #endif
0966 
0967 void efi_retrieve_tpm2_eventlog(void);
0968 
0969 #endif