1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2bd669475SArd Biesheuvel
3bd669475SArd Biesheuvel #ifndef _DRIVERS_FIRMWARE_EFI_EFISTUB_H
4bd669475SArd Biesheuvel #define _DRIVERS_FIRMWARE_EFI_EFISTUB_H
5bd669475SArd Biesheuvel
62c7d1e30SArvind Sankar #include <linux/compiler.h>
760a34085SArd Biesheuvel #include <linux/cleanup.h>
80b767353SArvind Sankar #include <linux/efi.h>
90b767353SArvind Sankar #include <linux/kernel.h>
1023d5b73fSArvind Sankar #include <linux/kern_levels.h>
110b767353SArvind Sankar #include <linux/types.h>
120b767353SArvind Sankar #include <asm/efi.h>
130b767353SArvind Sankar
1407e83dbbSArd Biesheuvel /*
1507e83dbbSArd Biesheuvel * __init annotations should not be used in the EFI stub, since the code is
1607e83dbbSArd Biesheuvel * either included in the decompressor (x86, ARM) where they have no effect,
1707e83dbbSArd Biesheuvel * or the whole stub is __init annotated at the section level (arm64), by
1807e83dbbSArd Biesheuvel * renaming the sections, in which case the __init annotation will be
1907e83dbbSArd Biesheuvel * redundant, and will result in section names like .init.init.text, and our
2007e83dbbSArd Biesheuvel * linker script does not expect that.
2107e83dbbSArd Biesheuvel */
2207e83dbbSArd Biesheuvel #undef __init
2307e83dbbSArd Biesheuvel
24a6a14469SArd Biesheuvel /*
25a6a14469SArd Biesheuvel * Allow the platform to override the allocation granularity: this allows
26a6a14469SArd Biesheuvel * systems that have the capability to run with a larger page size to deal
27a6a14469SArd Biesheuvel * with the allocations for initrd and fdt more efficiently.
28a6a14469SArd Biesheuvel */
29a6a14469SArd Biesheuvel #ifndef EFI_ALLOC_ALIGN
30a6a14469SArd Biesheuvel #define EFI_ALLOC_ALIGN EFI_PAGE_SIZE
31a6a14469SArd Biesheuvel #endif
32a6a14469SArd Biesheuvel
33a37dac5cSArd Biesheuvel #ifndef EFI_ALLOC_LIMIT
34a37dac5cSArd Biesheuvel #define EFI_ALLOC_LIMIT ULONG_MAX
35a37dac5cSArd Biesheuvel #endif
36a37dac5cSArd Biesheuvel
37cb1c9e02SArd Biesheuvel extern bool efi_no5lvl;
38980771f6SArd Biesheuvel extern bool efi_nochunk;
39980771f6SArd Biesheuvel extern bool efi_nokaslr;
4023d5b73fSArvind Sankar extern int efi_loglevel;
417205f06eSArd Biesheuvel extern int efi_mem_encrypt;
42980771f6SArd Biesheuvel extern bool efi_novamap;
43ccc27ae7SArd Biesheuvel extern const efi_system_table_t *efi_system_table;
442fcdad2aSArd Biesheuvel
453ba75c13SBaskov Evgeniy typedef union efi_dxe_services_table efi_dxe_services_table_t;
463ba75c13SBaskov Evgeniy extern const efi_dxe_services_table_t *efi_dxe_table;
473ba75c13SBaskov Evgeniy
486e99d321SArd Biesheuvel efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
496e99d321SArd Biesheuvel efi_system_table_t *sys_table_arg);
506e99d321SArd Biesheuvel
51de8c5520SArvind Sankar #ifndef ARCH_HAS_EFISTUB_WRAPPERS
52de8c5520SArvind Sankar
5322090f84SArd Biesheuvel #define efi_is_native() (true)
54a61962d8SArd Biesheuvel #define efi_table_attr(inst, attr) (inst)->attr
55a61962d8SArd Biesheuvel #define efi_fn_call(inst, func, ...) (inst)->func(__VA_ARGS__)
56de8c5520SArvind Sankar
5722090f84SArd Biesheuvel #endif
5822090f84SArd Biesheuvel
59a61962d8SArd Biesheuvel #define efi_call_proto(inst, func, ...) ({ \
60a61962d8SArd Biesheuvel __typeof__(inst) __inst = (inst); \
61a61962d8SArd Biesheuvel efi_fn_call(__inst, func, __inst, ##__VA_ARGS__); \
62a61962d8SArd Biesheuvel })
63a61962d8SArd Biesheuvel #define efi_bs_call(func, ...) \
64a61962d8SArd Biesheuvel efi_fn_call(efi_table_attr(efi_system_table, boottime), func, ##__VA_ARGS__)
65a61962d8SArd Biesheuvel #define efi_rt_call(func, ...) \
66a61962d8SArd Biesheuvel efi_fn_call(efi_table_attr(efi_system_table, runtime), func, ##__VA_ARGS__)
67a61962d8SArd Biesheuvel #define efi_dxe_call(func, ...) \
68a61962d8SArd Biesheuvel efi_fn_call(efi_dxe_table, func, ##__VA_ARGS__)
69a61962d8SArd Biesheuvel
7023d5b73fSArvind Sankar #define efi_info(fmt, ...) \
7123d5b73fSArvind Sankar efi_printk(KERN_INFO fmt, ##__VA_ARGS__)
72c1df5e0cSArvind Sankar #define efi_warn(fmt, ...) \
73c1df5e0cSArvind Sankar efi_printk(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
7423d5b73fSArvind Sankar #define efi_err(fmt, ...) \
7523d5b73fSArvind Sankar efi_printk(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)
7623d5b73fSArvind Sankar #define efi_debug(fmt, ...) \
7723d5b73fSArvind Sankar efi_printk(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)
7860f38de7SArd Biesheuvel
79c1df5e0cSArvind Sankar #define efi_printk_once(fmt, ...) \
80c1df5e0cSArvind Sankar ({ \
81c1df5e0cSArvind Sankar static bool __print_once; \
82c1df5e0cSArvind Sankar bool __ret_print_once = !__print_once; \
83c1df5e0cSArvind Sankar \
84c1df5e0cSArvind Sankar if (!__print_once) { \
85c1df5e0cSArvind Sankar __print_once = true; \
86c1df5e0cSArvind Sankar efi_printk(fmt, ##__VA_ARGS__); \
87c1df5e0cSArvind Sankar } \
88c1df5e0cSArvind Sankar __ret_print_once; \
89c1df5e0cSArvind Sankar })
90c1df5e0cSArvind Sankar
91c1df5e0cSArvind Sankar #define efi_info_once(fmt, ...) \
92c1df5e0cSArvind Sankar efi_printk_once(KERN_INFO fmt, ##__VA_ARGS__)
93c1df5e0cSArvind Sankar #define efi_warn_once(fmt, ...) \
94c1df5e0cSArvind Sankar efi_printk_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
95c1df5e0cSArvind Sankar #define efi_err_once(fmt, ...) \
96c1df5e0cSArvind Sankar efi_printk_once(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)
97c1df5e0cSArvind Sankar #define efi_debug_once(fmt, ...) \
98c1df5e0cSArvind Sankar efi_printk_once(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)
99c1df5e0cSArvind Sankar
100ac9aff8eSIngo Molnar /* Helper macros for the usual case of using simple C variables: */
101ac9aff8eSIngo Molnar #ifndef fdt_setprop_inplace_var
102ac9aff8eSIngo Molnar #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \
103ac9aff8eSIngo Molnar fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))
104ac9aff8eSIngo Molnar #endif
105ac9aff8eSIngo Molnar
106ac9aff8eSIngo Molnar #ifndef fdt_setprop_var
107ac9aff8eSIngo Molnar #define fdt_setprop_var(fdt, node_offset, name, var) \
108ac9aff8eSIngo Molnar fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))
109ac9aff8eSIngo Molnar #endif
110ac9aff8eSIngo Molnar
111966291f6SArd Biesheuvel #define get_efi_var(name, vendor, ...) \
112966291f6SArd Biesheuvel efi_rt_call(get_variable, (efi_char16_t *)(name), \
113966291f6SArd Biesheuvel (efi_guid_t *)(vendor), __VA_ARGS__)
114966291f6SArd Biesheuvel
115966291f6SArd Biesheuvel #define set_efi_var(name, vendor, ...) \
116966291f6SArd Biesheuvel efi_rt_call(set_variable, (efi_char16_t *)(name), \
117966291f6SArd Biesheuvel (efi_guid_t *)(vendor), __VA_ARGS__)
118966291f6SArd Biesheuvel
1198166ec09SArd Biesheuvel #define efi_get_handle_at(array, idx) \
1208166ec09SArd Biesheuvel (efi_is_native() ? (array)[idx] \
1218166ec09SArd Biesheuvel : (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
1228166ec09SArd Biesheuvel
1238166ec09SArd Biesheuvel #define efi_get_handle_num(size) \
1248166ec09SArd Biesheuvel ((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))
1258166ec09SArd Biesheuvel
126c14bca3fSArd Biesheuvel #define for_each_efi_handle(handle, array, num) \
127c14bca3fSArd Biesheuvel for (int __i = 0; __i < (num) && \
128c14bca3fSArd Biesheuvel ((handle = efi_get_handle_at((array), __i)) || true); \
129c14bca3fSArd Biesheuvel __i++)
1308166ec09SArd Biesheuvel
131eed4e019SArvind Sankar static inline
efi_set_u64_split(u64 data,u32 * lo,u32 * hi)132eed4e019SArvind Sankar void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)
133eed4e019SArvind Sankar {
134eed4e019SArvind Sankar *lo = lower_32_bits(data);
135eed4e019SArvind Sankar *hi = upper_32_bits(data);
136eed4e019SArvind Sankar }
137eed4e019SArvind Sankar
1388166ec09SArd Biesheuvel /*
1398166ec09SArd Biesheuvel * Allocation types for calls to boottime->allocate_pages.
1408166ec09SArd Biesheuvel */
1418166ec09SArd Biesheuvel #define EFI_ALLOCATE_ANY_PAGES 0
1428166ec09SArd Biesheuvel #define EFI_ALLOCATE_MAX_ADDRESS 1
1438166ec09SArd Biesheuvel #define EFI_ALLOCATE_ADDRESS 2
1448166ec09SArd Biesheuvel #define EFI_MAX_ALLOCATE_TYPE 3
1458166ec09SArd Biesheuvel
1468166ec09SArd Biesheuvel /*
1478166ec09SArd Biesheuvel * The type of search to perform when calling boottime->locate_handle
1488166ec09SArd Biesheuvel */
1498166ec09SArd Biesheuvel #define EFI_LOCATE_ALL_HANDLES 0
1508166ec09SArd Biesheuvel #define EFI_LOCATE_BY_REGISTER_NOTIFY 1
1518166ec09SArd Biesheuvel #define EFI_LOCATE_BY_PROTOCOL 2
1528166ec09SArd Biesheuvel
153fd626195SLenny Szubowicz /*
1549b47c527SArvind Sankar * boottime->stall takes the time period in microseconds
1559b47c527SArvind Sankar */
1569b47c527SArvind Sankar #define EFI_USEC_PER_SEC 1000000
1579b47c527SArvind Sankar
1589b47c527SArvind Sankar /*
1599b47c527SArvind Sankar * boottime->set_timer takes the time in 100ns units
1609b47c527SArvind Sankar */
1619b47c527SArvind Sankar #define EFI_100NSEC_PER_USEC ((u64)10)
1629b47c527SArvind Sankar
163d1343da3SIngo Molnar /*
164fd626195SLenny Szubowicz * An efi_boot_memmap is used by efi_get_memory_map() to return the
165fd626195SLenny Szubowicz * EFI memory map in a dynamically allocated buffer.
166fd626195SLenny Szubowicz *
167fd626195SLenny Szubowicz * The buffer allocated for the EFI memory map includes extra room for
168fd626195SLenny Szubowicz * a minimum of EFI_MMAP_NR_SLACK_SLOTS additional EFI memory descriptors.
169fd626195SLenny Szubowicz * This facilitates the reuse of the EFI memory map buffer when a second
170fd626195SLenny Szubowicz * call to ExitBootServices() is needed because of intervening changes to
171fd626195SLenny Szubowicz * the EFI memory map. Other related structures, e.g. x86 e820ext, need
172fd626195SLenny Szubowicz * to factor in this headroom requirement as well.
173fd626195SLenny Szubowicz */
174ec469692SHamza Mahfooz #define EFI_MMAP_NR_SLACK_SLOTS 32
175fd626195SLenny Szubowicz
176abd26868SArd Biesheuvel typedef struct efi_generic_dev_path efi_device_path_protocol_t;
177abd26868SArd Biesheuvel
178c7007d9fSArd Biesheuvel union efi_device_path_to_text_protocol {
179c7007d9fSArd Biesheuvel struct {
180c7007d9fSArd Biesheuvel efi_char16_t *(__efiapi *convert_device_node_to_text)(
181c7007d9fSArd Biesheuvel const efi_device_path_protocol_t *,
182c7007d9fSArd Biesheuvel bool, bool);
183c7007d9fSArd Biesheuvel efi_char16_t *(__efiapi *convert_device_path_to_text)(
184c7007d9fSArd Biesheuvel const efi_device_path_protocol_t *,
185c7007d9fSArd Biesheuvel bool, bool);
186c7007d9fSArd Biesheuvel };
187c7007d9fSArd Biesheuvel struct {
188c7007d9fSArd Biesheuvel u32 convert_device_node_to_text;
189c7007d9fSArd Biesheuvel u32 convert_device_path_to_text;
190c7007d9fSArd Biesheuvel } mixed_mode;
191c7007d9fSArd Biesheuvel };
192c7007d9fSArd Biesheuvel
193c7007d9fSArd Biesheuvel typedef union efi_device_path_to_text_protocol efi_device_path_to_text_protocol_t;
194c7007d9fSArd Biesheuvel
19570912985SArd Biesheuvel union efi_device_path_from_text_protocol {
19670912985SArd Biesheuvel struct {
19770912985SArd Biesheuvel efi_device_path_protocol_t *
19870912985SArd Biesheuvel (__efiapi *convert_text_to_device_node)(const efi_char16_t *);
19970912985SArd Biesheuvel efi_device_path_protocol_t *
20070912985SArd Biesheuvel (__efiapi *convert_text_to_device_path)(const efi_char16_t *);
20170912985SArd Biesheuvel };
20270912985SArd Biesheuvel struct {
20370912985SArd Biesheuvel u32 convert_text_to_device_node;
20470912985SArd Biesheuvel u32 convert_text_to_device_path;
20570912985SArd Biesheuvel } mixed_mode;
20670912985SArd Biesheuvel };
20770912985SArd Biesheuvel
20870912985SArd Biesheuvel typedef union efi_device_path_from_text_protocol efi_device_path_from_text_protocol_t;
20970912985SArd Biesheuvel
2109b47c527SArvind Sankar typedef void *efi_event_t;
2119b47c527SArvind Sankar /* Note that notifications won't work in mixed mode */
2129b47c527SArvind Sankar typedef void (__efiapi *efi_event_notify_t)(efi_event_t, void *);
2139b47c527SArvind Sankar
2149b47c527SArvind Sankar #define EFI_EVT_TIMER 0x80000000U
2159b47c527SArvind Sankar #define EFI_EVT_RUNTIME 0x40000000U
2169b47c527SArvind Sankar #define EFI_EVT_NOTIFY_WAIT 0x00000100U
2179b47c527SArvind Sankar #define EFI_EVT_NOTIFY_SIGNAL 0x00000200U
2189b47c527SArvind Sankar
2198c0a839cSHeinrich Schuchardt /**
2208c0a839cSHeinrich Schuchardt * efi_set_event_at() - add event to events array
2218c0a839cSHeinrich Schuchardt *
2228c0a839cSHeinrich Schuchardt * @events: array of UEFI events
2238c0a839cSHeinrich Schuchardt * @ids: index where to put the event in the array
2248c0a839cSHeinrich Schuchardt * @event: event to add to the aray
2258c0a839cSHeinrich Schuchardt *
2268c0a839cSHeinrich Schuchardt * boottime->wait_for_event() takes an array of events as input.
2279b47c527SArvind Sankar * Provide a helper to set it up correctly for mixed mode.
2289b47c527SArvind Sankar */
2299b47c527SArvind Sankar static inline
efi_set_event_at(efi_event_t * events,size_t idx,efi_event_t event)2309b47c527SArvind Sankar void efi_set_event_at(efi_event_t *events, size_t idx, efi_event_t event)
2319b47c527SArvind Sankar {
2329b47c527SArvind Sankar if (efi_is_native())
2339b47c527SArvind Sankar events[idx] = event;
2349b47c527SArvind Sankar else
2359b47c527SArvind Sankar ((u32 *)events)[idx] = (u32)(unsigned long)event;
2369b47c527SArvind Sankar }
2379b47c527SArvind Sankar
2389b47c527SArvind Sankar #define EFI_TPL_APPLICATION 4
2399b47c527SArvind Sankar #define EFI_TPL_CALLBACK 8
2409b47c527SArvind Sankar #define EFI_TPL_NOTIFY 16
2419b47c527SArvind Sankar #define EFI_TPL_HIGH_LEVEL 31
2429b47c527SArvind Sankar
2439b47c527SArvind Sankar typedef enum {
2449b47c527SArvind Sankar EfiTimerCancel,
2459b47c527SArvind Sankar EfiTimerPeriodic,
2469b47c527SArvind Sankar EfiTimerRelative
2479b47c527SArvind Sankar } EFI_TIMER_DELAY;
2489b47c527SArvind Sankar
2498166ec09SArd Biesheuvel /*
2508166ec09SArd Biesheuvel * EFI Boot Services table
2518166ec09SArd Biesheuvel */
2528166ec09SArd Biesheuvel union efi_boot_services {
2538166ec09SArd Biesheuvel struct {
2548166ec09SArd Biesheuvel efi_table_hdr_t hdr;
2558166ec09SArd Biesheuvel void *raise_tpl;
2568166ec09SArd Biesheuvel void *restore_tpl;
2578166ec09SArd Biesheuvel efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,
2588166ec09SArd Biesheuvel efi_physical_addr_t *);
2598166ec09SArd Biesheuvel efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,
2608166ec09SArd Biesheuvel unsigned long);
2618166ec09SArd Biesheuvel efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,
2628166ec09SArd Biesheuvel unsigned long *,
2638166ec09SArd Biesheuvel unsigned long *, u32 *);
2648166ec09SArd Biesheuvel efi_status_t (__efiapi *allocate_pool)(int, unsigned long,
2658166ec09SArd Biesheuvel void **);
2668166ec09SArd Biesheuvel efi_status_t (__efiapi *free_pool)(void *);
2679b47c527SArvind Sankar efi_status_t (__efiapi *create_event)(u32, unsigned long,
2689b47c527SArvind Sankar efi_event_notify_t, void *,
2699b47c527SArvind Sankar efi_event_t *);
2709b47c527SArvind Sankar efi_status_t (__efiapi *set_timer)(efi_event_t,
2719b47c527SArvind Sankar EFI_TIMER_DELAY, u64);
2729b47c527SArvind Sankar efi_status_t (__efiapi *wait_for_event)(unsigned long,
2739b47c527SArvind Sankar efi_event_t *,
2749b47c527SArvind Sankar unsigned long *);
2758166ec09SArd Biesheuvel void *signal_event;
2769b47c527SArvind Sankar efi_status_t (__efiapi *close_event)(efi_event_t);
2778166ec09SArd Biesheuvel void *check_event;
2788166ec09SArd Biesheuvel void *install_protocol_interface;
2798166ec09SArd Biesheuvel void *reinstall_protocol_interface;
2808166ec09SArd Biesheuvel void *uninstall_protocol_interface;
2818166ec09SArd Biesheuvel efi_status_t (__efiapi *handle_protocol)(efi_handle_t,
2828166ec09SArd Biesheuvel efi_guid_t *, void **);
2838166ec09SArd Biesheuvel void *__reserved;
2848166ec09SArd Biesheuvel void *register_protocol_notify;
2858166ec09SArd Biesheuvel efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,
2868166ec09SArd Biesheuvel void *, unsigned long *,
2878166ec09SArd Biesheuvel efi_handle_t *);
288abd26868SArd Biesheuvel efi_status_t (__efiapi *locate_device_path)(efi_guid_t *,
289abd26868SArd Biesheuvel efi_device_path_protocol_t **,
290abd26868SArd Biesheuvel efi_handle_t *);
2918166ec09SArd Biesheuvel efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,
2928166ec09SArd Biesheuvel void *);
293c7007d9fSArd Biesheuvel efi_status_t (__efiapi *load_image)(bool, efi_handle_t,
294c7007d9fSArd Biesheuvel efi_device_path_protocol_t *,
295c7007d9fSArd Biesheuvel void *, unsigned long,
296c7007d9fSArd Biesheuvel efi_handle_t *);
297c7007d9fSArd Biesheuvel efi_status_t (__efiapi *start_image)(efi_handle_t, unsigned long *,
298c7007d9fSArd Biesheuvel efi_char16_t **);
2993b8f44fcSArd Biesheuvel efi_status_t __noreturn (__efiapi *exit)(efi_handle_t,
3003b8f44fcSArd Biesheuvel efi_status_t,
3013b8f44fcSArd Biesheuvel unsigned long,
3023b8f44fcSArd Biesheuvel efi_char16_t *);
303c7007d9fSArd Biesheuvel efi_status_t (__efiapi *unload_image)(efi_handle_t);
3048166ec09SArd Biesheuvel efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,
3058166ec09SArd Biesheuvel unsigned long);
3068166ec09SArd Biesheuvel void *get_next_monotonic_count;
3079b47c527SArvind Sankar efi_status_t (__efiapi *stall)(unsigned long);
3088166ec09SArd Biesheuvel void *set_watchdog_timer;
3098166ec09SArd Biesheuvel void *connect_controller;
3108166ec09SArd Biesheuvel efi_status_t (__efiapi *disconnect_controller)(efi_handle_t,
3118166ec09SArd Biesheuvel efi_handle_t,
3128166ec09SArd Biesheuvel efi_handle_t);
3138166ec09SArd Biesheuvel void *open_protocol;
3148166ec09SArd Biesheuvel void *close_protocol;
3158166ec09SArd Biesheuvel void *open_protocol_information;
3168166ec09SArd Biesheuvel void *protocols_per_handle;
31760a34085SArd Biesheuvel efi_status_t (__efiapi *locate_handle_buffer)(int, efi_guid_t *,
31860a34085SArd Biesheuvel void *, unsigned long *,
31960a34085SArd Biesheuvel efi_handle_t **);
3208166ec09SArd Biesheuvel efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,
3218166ec09SArd Biesheuvel void **);
322c7007d9fSArd Biesheuvel efi_status_t (__efiapi *install_multiple_protocol_interfaces)(efi_handle_t *, ...);
323c7007d9fSArd Biesheuvel efi_status_t (__efiapi *uninstall_multiple_protocol_interfaces)(efi_handle_t, ...);
3248166ec09SArd Biesheuvel void *calculate_crc32;
325c82ceb44SArd Biesheuvel void (__efiapi *copy_mem)(void *, const void *, unsigned long);
326c82ceb44SArd Biesheuvel void (__efiapi *set_mem)(void *, unsigned long, unsigned char);
3278166ec09SArd Biesheuvel void *create_event_ex;
3288166ec09SArd Biesheuvel };
3298166ec09SArd Biesheuvel struct {
3308166ec09SArd Biesheuvel efi_table_hdr_t hdr;
3318166ec09SArd Biesheuvel u32 raise_tpl;
3328166ec09SArd Biesheuvel u32 restore_tpl;
3338166ec09SArd Biesheuvel u32 allocate_pages;
3348166ec09SArd Biesheuvel u32 free_pages;
3358166ec09SArd Biesheuvel u32 get_memory_map;
3368166ec09SArd Biesheuvel u32 allocate_pool;
3378166ec09SArd Biesheuvel u32 free_pool;
3388166ec09SArd Biesheuvel u32 create_event;
3398166ec09SArd Biesheuvel u32 set_timer;
3408166ec09SArd Biesheuvel u32 wait_for_event;
3418166ec09SArd Biesheuvel u32 signal_event;
3428166ec09SArd Biesheuvel u32 close_event;
3438166ec09SArd Biesheuvel u32 check_event;
3448166ec09SArd Biesheuvel u32 install_protocol_interface;
3458166ec09SArd Biesheuvel u32 reinstall_protocol_interface;
3468166ec09SArd Biesheuvel u32 uninstall_protocol_interface;
3478166ec09SArd Biesheuvel u32 handle_protocol;
3488166ec09SArd Biesheuvel u32 __reserved;
3498166ec09SArd Biesheuvel u32 register_protocol_notify;
3508166ec09SArd Biesheuvel u32 locate_handle;
3518166ec09SArd Biesheuvel u32 locate_device_path;
3528166ec09SArd Biesheuvel u32 install_configuration_table;
3538166ec09SArd Biesheuvel u32 load_image;
3548166ec09SArd Biesheuvel u32 start_image;
3558166ec09SArd Biesheuvel u32 exit;
3568166ec09SArd Biesheuvel u32 unload_image;
3578166ec09SArd Biesheuvel u32 exit_boot_services;
3588166ec09SArd Biesheuvel u32 get_next_monotonic_count;
3598166ec09SArd Biesheuvel u32 stall;
3608166ec09SArd Biesheuvel u32 set_watchdog_timer;
3618166ec09SArd Biesheuvel u32 connect_controller;
3628166ec09SArd Biesheuvel u32 disconnect_controller;
3638166ec09SArd Biesheuvel u32 open_protocol;
3648166ec09SArd Biesheuvel u32 close_protocol;
3658166ec09SArd Biesheuvel u32 open_protocol_information;
3668166ec09SArd Biesheuvel u32 protocols_per_handle;
3678166ec09SArd Biesheuvel u32 locate_handle_buffer;
3688166ec09SArd Biesheuvel u32 locate_protocol;
3698166ec09SArd Biesheuvel u32 install_multiple_protocol_interfaces;
3708166ec09SArd Biesheuvel u32 uninstall_multiple_protocol_interfaces;
3718166ec09SArd Biesheuvel u32 calculate_crc32;
3728166ec09SArd Biesheuvel u32 copy_mem;
3738166ec09SArd Biesheuvel u32 set_mem;
3748166ec09SArd Biesheuvel u32 create_event_ex;
3758166ec09SArd Biesheuvel } mixed_mode;
3768166ec09SArd Biesheuvel };
3778166ec09SArd Biesheuvel
3783ba75c13SBaskov Evgeniy typedef enum {
3793ba75c13SBaskov Evgeniy EfiGcdMemoryTypeNonExistent,
3803ba75c13SBaskov Evgeniy EfiGcdMemoryTypeReserved,
3813ba75c13SBaskov Evgeniy EfiGcdMemoryTypeSystemMemory,
3823ba75c13SBaskov Evgeniy EfiGcdMemoryTypeMemoryMappedIo,
3833ba75c13SBaskov Evgeniy EfiGcdMemoryTypePersistent,
3843ba75c13SBaskov Evgeniy EfiGcdMemoryTypeMoreReliable,
3853ba75c13SBaskov Evgeniy EfiGcdMemoryTypeMaximum
3863ba75c13SBaskov Evgeniy } efi_gcd_memory_type_t;
3873ba75c13SBaskov Evgeniy
3883ba75c13SBaskov Evgeniy typedef struct {
3893ba75c13SBaskov Evgeniy efi_physical_addr_t base_address;
3903ba75c13SBaskov Evgeniy u64 length;
3913ba75c13SBaskov Evgeniy u64 capabilities;
3923ba75c13SBaskov Evgeniy u64 attributes;
3933ba75c13SBaskov Evgeniy efi_gcd_memory_type_t gcd_memory_type;
3943ba75c13SBaskov Evgeniy void *image_handle;
3953ba75c13SBaskov Evgeniy void *device_handle;
3963ba75c13SBaskov Evgeniy } efi_gcd_memory_space_desc_t;
3973ba75c13SBaskov Evgeniy
3983ba75c13SBaskov Evgeniy /*
3993ba75c13SBaskov Evgeniy * EFI DXE Services table
4003ba75c13SBaskov Evgeniy */
4013ba75c13SBaskov Evgeniy union efi_dxe_services_table {
4023ba75c13SBaskov Evgeniy struct {
4033ba75c13SBaskov Evgeniy efi_table_hdr_t hdr;
4043ba75c13SBaskov Evgeniy void *add_memory_space;
4053ba75c13SBaskov Evgeniy void *allocate_memory_space;
4063ba75c13SBaskov Evgeniy void *free_memory_space;
4073ba75c13SBaskov Evgeniy void *remove_memory_space;
4083ba75c13SBaskov Evgeniy efi_status_t (__efiapi *get_memory_space_descriptor)(efi_physical_addr_t,
4093ba75c13SBaskov Evgeniy efi_gcd_memory_space_desc_t *);
4103ba75c13SBaskov Evgeniy efi_status_t (__efiapi *set_memory_space_attributes)(efi_physical_addr_t,
4113ba75c13SBaskov Evgeniy u64, u64);
4123ba75c13SBaskov Evgeniy void *get_memory_space_map;
4133ba75c13SBaskov Evgeniy void *add_io_space;
4143ba75c13SBaskov Evgeniy void *allocate_io_space;
4153ba75c13SBaskov Evgeniy void *free_io_space;
4163ba75c13SBaskov Evgeniy void *remove_io_space;
4173ba75c13SBaskov Evgeniy void *get_io_space_descriptor;
4183ba75c13SBaskov Evgeniy void *get_io_space_map;
4193ba75c13SBaskov Evgeniy void *dispatch;
4203ba75c13SBaskov Evgeniy void *schedule;
4213ba75c13SBaskov Evgeniy void *trust;
4223ba75c13SBaskov Evgeniy void *process_firmware_volume;
4233ba75c13SBaskov Evgeniy void *set_memory_space_capabilities;
4243ba75c13SBaskov Evgeniy };
4253ba75c13SBaskov Evgeniy struct {
4263ba75c13SBaskov Evgeniy efi_table_hdr_t hdr;
4273ba75c13SBaskov Evgeniy u32 add_memory_space;
4283ba75c13SBaskov Evgeniy u32 allocate_memory_space;
4293ba75c13SBaskov Evgeniy u32 free_memory_space;
4303ba75c13SBaskov Evgeniy u32 remove_memory_space;
4313ba75c13SBaskov Evgeniy u32 get_memory_space_descriptor;
4323ba75c13SBaskov Evgeniy u32 set_memory_space_attributes;
4333ba75c13SBaskov Evgeniy u32 get_memory_space_map;
4343ba75c13SBaskov Evgeniy u32 add_io_space;
4353ba75c13SBaskov Evgeniy u32 allocate_io_space;
4363ba75c13SBaskov Evgeniy u32 free_io_space;
4373ba75c13SBaskov Evgeniy u32 remove_io_space;
4383ba75c13SBaskov Evgeniy u32 get_io_space_descriptor;
4393ba75c13SBaskov Evgeniy u32 get_io_space_map;
4403ba75c13SBaskov Evgeniy u32 dispatch;
4413ba75c13SBaskov Evgeniy u32 schedule;
4423ba75c13SBaskov Evgeniy u32 trust;
4433ba75c13SBaskov Evgeniy u32 process_firmware_volume;
4443ba75c13SBaskov Evgeniy u32 set_memory_space_capabilities;
4453ba75c13SBaskov Evgeniy } mixed_mode;
4463ba75c13SBaskov Evgeniy };
4473ba75c13SBaskov Evgeniy
44879729f26SEvgeniy Baskov typedef union efi_memory_attribute_protocol efi_memory_attribute_protocol_t;
44979729f26SEvgeniy Baskov
45079729f26SEvgeniy Baskov union efi_memory_attribute_protocol {
45179729f26SEvgeniy Baskov struct {
45279729f26SEvgeniy Baskov efi_status_t (__efiapi *get_memory_attributes)(
45379729f26SEvgeniy Baskov efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64 *);
45479729f26SEvgeniy Baskov
45579729f26SEvgeniy Baskov efi_status_t (__efiapi *set_memory_attributes)(
45679729f26SEvgeniy Baskov efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64);
45779729f26SEvgeniy Baskov
45879729f26SEvgeniy Baskov efi_status_t (__efiapi *clear_memory_attributes)(
45979729f26SEvgeniy Baskov efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64);
46079729f26SEvgeniy Baskov };
46179729f26SEvgeniy Baskov struct {
46279729f26SEvgeniy Baskov u32 get_memory_attributes;
46379729f26SEvgeniy Baskov u32 set_memory_attributes;
46479729f26SEvgeniy Baskov u32 clear_memory_attributes;
46579729f26SEvgeniy Baskov } mixed_mode;
46679729f26SEvgeniy Baskov };
46779729f26SEvgeniy Baskov
468c2d0b470SArd Biesheuvel typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
469c2d0b470SArd Biesheuvel
470c2d0b470SArd Biesheuvel union efi_uga_draw_protocol {
471c2d0b470SArd Biesheuvel struct {
472c2d0b470SArd Biesheuvel efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,
473c2d0b470SArd Biesheuvel u32*, u32*, u32*, u32*);
474c2d0b470SArd Biesheuvel void *set_mode;
475c2d0b470SArd Biesheuvel void *blt;
476c2d0b470SArd Biesheuvel };
477c2d0b470SArd Biesheuvel struct {
478c2d0b470SArd Biesheuvel u32 get_mode;
479c2d0b470SArd Biesheuvel u32 set_mode;
480c2d0b470SArd Biesheuvel u32 blt;
481c2d0b470SArd Biesheuvel } mixed_mode;
482c2d0b470SArd Biesheuvel };
483c2d0b470SArd Biesheuvel
4849b47c527SArvind Sankar typedef struct {
4859b47c527SArvind Sankar u16 scan_code;
4869b47c527SArvind Sankar efi_char16_t unicode_char;
4879b47c527SArvind Sankar } efi_input_key_t;
4889b47c527SArvind Sankar
4899b47c527SArvind Sankar union efi_simple_text_input_protocol {
4909b47c527SArvind Sankar struct {
4919b47c527SArvind Sankar void *reset;
4929b47c527SArvind Sankar efi_status_t (__efiapi *read_keystroke)(efi_simple_text_input_protocol_t *,
4939b47c527SArvind Sankar efi_input_key_t *);
4949b47c527SArvind Sankar efi_event_t wait_for_key;
4959b47c527SArvind Sankar };
4969b47c527SArvind Sankar struct {
4979b47c527SArvind Sankar u32 reset;
4989b47c527SArvind Sankar u32 read_keystroke;
4999b47c527SArvind Sankar u32 wait_for_key;
5009b47c527SArvind Sankar } mixed_mode;
5019b47c527SArvind Sankar };
5029b47c527SArvind Sankar
50314c574f3SArvind Sankar efi_status_t efi_wait_for_key(unsigned long usec, efi_input_key_t *key);
50414c574f3SArvind Sankar
5058166ec09SArd Biesheuvel union efi_simple_text_output_protocol {
5068166ec09SArd Biesheuvel struct {
5078166ec09SArd Biesheuvel void *reset;
5088166ec09SArd Biesheuvel efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
5098166ec09SArd Biesheuvel efi_char16_t *);
5108166ec09SArd Biesheuvel void *test_string;
5118166ec09SArd Biesheuvel };
5128166ec09SArd Biesheuvel struct {
5138166ec09SArd Biesheuvel u32 reset;
5148166ec09SArd Biesheuvel u32 output_string;
5158166ec09SArd Biesheuvel u32 test_string;
5168166ec09SArd Biesheuvel } mixed_mode;
5178166ec09SArd Biesheuvel };
5188166ec09SArd Biesheuvel
5198166ec09SArd Biesheuvel #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR 0
5208166ec09SArd Biesheuvel #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR 1
5218166ec09SArd Biesheuvel #define PIXEL_BIT_MASK 2
5228166ec09SArd Biesheuvel #define PIXEL_BLT_ONLY 3
5238166ec09SArd Biesheuvel #define PIXEL_FORMAT_MAX 4
5248166ec09SArd Biesheuvel
5258166ec09SArd Biesheuvel typedef struct {
5268166ec09SArd Biesheuvel u32 red_mask;
5278166ec09SArd Biesheuvel u32 green_mask;
5288166ec09SArd Biesheuvel u32 blue_mask;
5298166ec09SArd Biesheuvel u32 reserved_mask;
5308166ec09SArd Biesheuvel } efi_pixel_bitmask_t;
5318166ec09SArd Biesheuvel
5328166ec09SArd Biesheuvel typedef struct {
5338166ec09SArd Biesheuvel u32 version;
5348166ec09SArd Biesheuvel u32 horizontal_resolution;
5358166ec09SArd Biesheuvel u32 vertical_resolution;
5368166ec09SArd Biesheuvel int pixel_format;
5378166ec09SArd Biesheuvel efi_pixel_bitmask_t pixel_information;
5388166ec09SArd Biesheuvel u32 pixels_per_scan_line;
5398166ec09SArd Biesheuvel } efi_graphics_output_mode_info_t;
5408166ec09SArd Biesheuvel
5418166ec09SArd Biesheuvel typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;
5428166ec09SArd Biesheuvel
5438166ec09SArd Biesheuvel union efi_graphics_output_protocol_mode {
5448166ec09SArd Biesheuvel struct {
5458166ec09SArd Biesheuvel u32 max_mode;
5468166ec09SArd Biesheuvel u32 mode;
5478166ec09SArd Biesheuvel efi_graphics_output_mode_info_t *info;
5488166ec09SArd Biesheuvel unsigned long size_of_info;
5498166ec09SArd Biesheuvel efi_physical_addr_t frame_buffer_base;
5508166ec09SArd Biesheuvel unsigned long frame_buffer_size;
5518166ec09SArd Biesheuvel };
5528166ec09SArd Biesheuvel struct {
5538166ec09SArd Biesheuvel u32 max_mode;
5548166ec09SArd Biesheuvel u32 mode;
5558166ec09SArd Biesheuvel u32 info;
5568166ec09SArd Biesheuvel u32 size_of_info;
5578166ec09SArd Biesheuvel u64 frame_buffer_base;
5588166ec09SArd Biesheuvel u32 frame_buffer_size;
5598166ec09SArd Biesheuvel } mixed_mode;
5608166ec09SArd Biesheuvel };
5618166ec09SArd Biesheuvel
5628166ec09SArd Biesheuvel typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;
5638166ec09SArd Biesheuvel
5648166ec09SArd Biesheuvel union efi_graphics_output_protocol {
5658166ec09SArd Biesheuvel struct {
566b4b89a02SArvind Sankar efi_status_t (__efiapi *query_mode)(efi_graphics_output_protocol_t *,
567b4b89a02SArvind Sankar u32, unsigned long *,
568b4b89a02SArvind Sankar efi_graphics_output_mode_info_t **);
569b4b89a02SArvind Sankar efi_status_t (__efiapi *set_mode) (efi_graphics_output_protocol_t *, u32);
5708166ec09SArd Biesheuvel void *blt;
5718166ec09SArd Biesheuvel efi_graphics_output_protocol_mode_t *mode;
5728166ec09SArd Biesheuvel };
5738166ec09SArd Biesheuvel struct {
5748166ec09SArd Biesheuvel u32 query_mode;
5758166ec09SArd Biesheuvel u32 set_mode;
5768166ec09SArd Biesheuvel u32 blt;
5778166ec09SArd Biesheuvel u32 mode;
5788166ec09SArd Biesheuvel } mixed_mode;
5798166ec09SArd Biesheuvel };
5808166ec09SArd Biesheuvel
581f7b85b33SArd Biesheuvel typedef union {
582f7b85b33SArd Biesheuvel struct {
583a46a290aSArd Biesheuvel u32 revision;
584a46a290aSArd Biesheuvel efi_handle_t parent_handle;
585a46a290aSArd Biesheuvel efi_system_table_t *system_table;
586a46a290aSArd Biesheuvel efi_handle_t device_handle;
587a46a290aSArd Biesheuvel void *file_path;
588a46a290aSArd Biesheuvel void *reserved;
589a46a290aSArd Biesheuvel u32 load_options_size;
590a46a290aSArd Biesheuvel void *load_options;
591a46a290aSArd Biesheuvel void *image_base;
592a46a290aSArd Biesheuvel __aligned_u64 image_size;
593a46a290aSArd Biesheuvel unsigned int image_code_type;
594a46a290aSArd Biesheuvel unsigned int image_data_type;
595a46a290aSArd Biesheuvel efi_status_t (__efiapi *unload)(efi_handle_t image_handle);
596f7b85b33SArd Biesheuvel };
597f7b85b33SArd Biesheuvel struct {
598f7b85b33SArd Biesheuvel u32 revision;
599f7b85b33SArd Biesheuvel u32 parent_handle;
600f7b85b33SArd Biesheuvel u32 system_table;
601f7b85b33SArd Biesheuvel u32 device_handle;
602f7b85b33SArd Biesheuvel u32 file_path;
603f7b85b33SArd Biesheuvel u32 reserved;
604f7b85b33SArd Biesheuvel u32 load_options_size;
605f7b85b33SArd Biesheuvel u32 load_options;
606f7b85b33SArd Biesheuvel u32 image_base;
607f7b85b33SArd Biesheuvel __aligned_u64 image_size;
608f7b85b33SArd Biesheuvel u32 image_code_type;
609f7b85b33SArd Biesheuvel u32 image_data_type;
610f7b85b33SArd Biesheuvel u32 unload;
611f7b85b33SArd Biesheuvel } mixed_mode;
612a46a290aSArd Biesheuvel } efi_loaded_image_t;
613a46a290aSArd Biesheuvel
614a46a290aSArd Biesheuvel typedef struct {
615a46a290aSArd Biesheuvel u64 size;
616a46a290aSArd Biesheuvel u64 file_size;
617a46a290aSArd Biesheuvel u64 phys_size;
618a46a290aSArd Biesheuvel efi_time_t create_time;
619a46a290aSArd Biesheuvel efi_time_t last_access_time;
620a46a290aSArd Biesheuvel efi_time_t modification_time;
621a46a290aSArd Biesheuvel __aligned_u64 attribute;
6229302c1bbSArd Biesheuvel efi_char16_t filename[];
623a46a290aSArd Biesheuvel } efi_file_info_t;
624a46a290aSArd Biesheuvel
625f8a31244SArd Biesheuvel typedef union efi_file_protocol efi_file_protocol_t;
626a46a290aSArd Biesheuvel
627f8a31244SArd Biesheuvel union efi_file_protocol {
628f8a31244SArd Biesheuvel struct {
629a46a290aSArd Biesheuvel u64 revision;
630a46a290aSArd Biesheuvel efi_status_t (__efiapi *open) (efi_file_protocol_t *,
631a46a290aSArd Biesheuvel efi_file_protocol_t **,
632f8a31244SArd Biesheuvel efi_char16_t *, u64,
633f8a31244SArd Biesheuvel u64);
634a46a290aSArd Biesheuvel efi_status_t (__efiapi *close) (efi_file_protocol_t *);
635a46a290aSArd Biesheuvel efi_status_t (__efiapi *delete) (efi_file_protocol_t *);
636a46a290aSArd Biesheuvel efi_status_t (__efiapi *read) (efi_file_protocol_t *,
637f8a31244SArd Biesheuvel unsigned long *,
638f8a31244SArd Biesheuvel void *);
639a46a290aSArd Biesheuvel efi_status_t (__efiapi *write) (efi_file_protocol_t *,
640a46a290aSArd Biesheuvel unsigned long, void *);
641f8a31244SArd Biesheuvel efi_status_t (__efiapi *get_position)(efi_file_protocol_t *,
642f8a31244SArd Biesheuvel u64 *);
643f8a31244SArd Biesheuvel efi_status_t (__efiapi *set_position)(efi_file_protocol_t *,
644f8a31244SArd Biesheuvel u64);
645a46a290aSArd Biesheuvel efi_status_t (__efiapi *get_info) (efi_file_protocol_t *,
646f8a31244SArd Biesheuvel efi_guid_t *,
647f8a31244SArd Biesheuvel unsigned long *,
648a46a290aSArd Biesheuvel void *);
649a46a290aSArd Biesheuvel efi_status_t (__efiapi *set_info) (efi_file_protocol_t *,
650f8a31244SArd Biesheuvel efi_guid_t *,
651f8a31244SArd Biesheuvel unsigned long,
652a46a290aSArd Biesheuvel void *);
653a46a290aSArd Biesheuvel efi_status_t (__efiapi *flush) (efi_file_protocol_t *);
654a46a290aSArd Biesheuvel };
655f8a31244SArd Biesheuvel struct {
656a46a290aSArd Biesheuvel u64 revision;
657f8a31244SArd Biesheuvel u32 open;
658f8a31244SArd Biesheuvel u32 close;
659f8a31244SArd Biesheuvel u32 delete;
660f8a31244SArd Biesheuvel u32 read;
661f8a31244SArd Biesheuvel u32 write;
662f8a31244SArd Biesheuvel u32 get_position;
663f8a31244SArd Biesheuvel u32 set_position;
664f8a31244SArd Biesheuvel u32 get_info;
665f8a31244SArd Biesheuvel u32 set_info;
666f8a31244SArd Biesheuvel u32 flush;
667f8a31244SArd Biesheuvel } mixed_mode;
668f8a31244SArd Biesheuvel };
669f8a31244SArd Biesheuvel
670f8a31244SArd Biesheuvel typedef union efi_simple_file_system_protocol efi_simple_file_system_protocol_t;
671f8a31244SArd Biesheuvel
672f8a31244SArd Biesheuvel union efi_simple_file_system_protocol {
673f8a31244SArd Biesheuvel struct {
674f8a31244SArd Biesheuvel u64 revision;
675f8a31244SArd Biesheuvel efi_status_t (__efiapi *open_volume)(efi_simple_file_system_protocol_t *,
676a46a290aSArd Biesheuvel efi_file_protocol_t **);
677a46a290aSArd Biesheuvel };
678f8a31244SArd Biesheuvel struct {
679f8a31244SArd Biesheuvel u64 revision;
680f8a31244SArd Biesheuvel u32 open_volume;
681f8a31244SArd Biesheuvel } mixed_mode;
682f8a31244SArd Biesheuvel };
683a46a290aSArd Biesheuvel
684a46a290aSArd Biesheuvel #define EFI_FILE_MODE_READ 0x0000000000000001
685a46a290aSArd Biesheuvel #define EFI_FILE_MODE_WRITE 0x0000000000000002
686a46a290aSArd Biesheuvel #define EFI_FILE_MODE_CREATE 0x8000000000000000
687a46a290aSArd Biesheuvel
6888166ec09SArd Biesheuvel typedef enum {
6898166ec09SArd Biesheuvel EfiPciIoWidthUint8,
6908166ec09SArd Biesheuvel EfiPciIoWidthUint16,
6918166ec09SArd Biesheuvel EfiPciIoWidthUint32,
6928166ec09SArd Biesheuvel EfiPciIoWidthUint64,
6938166ec09SArd Biesheuvel EfiPciIoWidthFifoUint8,
6948166ec09SArd Biesheuvel EfiPciIoWidthFifoUint16,
6958166ec09SArd Biesheuvel EfiPciIoWidthFifoUint32,
6968166ec09SArd Biesheuvel EfiPciIoWidthFifoUint64,
6978166ec09SArd Biesheuvel EfiPciIoWidthFillUint8,
6988166ec09SArd Biesheuvel EfiPciIoWidthFillUint16,
6998166ec09SArd Biesheuvel EfiPciIoWidthFillUint32,
7008166ec09SArd Biesheuvel EfiPciIoWidthFillUint64,
7018166ec09SArd Biesheuvel EfiPciIoWidthMaximum
7028166ec09SArd Biesheuvel } EFI_PCI_IO_PROTOCOL_WIDTH;
7038166ec09SArd Biesheuvel
7048166ec09SArd Biesheuvel typedef enum {
7058166ec09SArd Biesheuvel EfiPciIoAttributeOperationGet,
7068166ec09SArd Biesheuvel EfiPciIoAttributeOperationSet,
7078166ec09SArd Biesheuvel EfiPciIoAttributeOperationEnable,
7088166ec09SArd Biesheuvel EfiPciIoAttributeOperationDisable,
7098166ec09SArd Biesheuvel EfiPciIoAttributeOperationSupported,
7108166ec09SArd Biesheuvel EfiPciIoAttributeOperationMaximum
7118166ec09SArd Biesheuvel } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
7128166ec09SArd Biesheuvel
7138166ec09SArd Biesheuvel typedef struct {
7148166ec09SArd Biesheuvel u32 read;
7158166ec09SArd Biesheuvel u32 write;
7168166ec09SArd Biesheuvel } efi_pci_io_protocol_access_32_t;
7178166ec09SArd Biesheuvel
7188166ec09SArd Biesheuvel typedef union efi_pci_io_protocol efi_pci_io_protocol_t;
7198166ec09SArd Biesheuvel
7208166ec09SArd Biesheuvel typedef
7218166ec09SArd Biesheuvel efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
7228166ec09SArd Biesheuvel EFI_PCI_IO_PROTOCOL_WIDTH,
7238166ec09SArd Biesheuvel u32 offset,
7248166ec09SArd Biesheuvel unsigned long count,
7258166ec09SArd Biesheuvel void *buffer);
7268166ec09SArd Biesheuvel
7278166ec09SArd Biesheuvel typedef struct {
7288166ec09SArd Biesheuvel void *read;
7298166ec09SArd Biesheuvel void *write;
7308166ec09SArd Biesheuvel } efi_pci_io_protocol_access_t;
7318166ec09SArd Biesheuvel
7328166ec09SArd Biesheuvel typedef struct {
7338166ec09SArd Biesheuvel efi_pci_io_protocol_cfg_t read;
7348166ec09SArd Biesheuvel efi_pci_io_protocol_cfg_t write;
7358166ec09SArd Biesheuvel } efi_pci_io_protocol_config_access_t;
7368166ec09SArd Biesheuvel
7378166ec09SArd Biesheuvel union efi_pci_io_protocol {
7388166ec09SArd Biesheuvel struct {
7398166ec09SArd Biesheuvel void *poll_mem;
7408166ec09SArd Biesheuvel void *poll_io;
7418166ec09SArd Biesheuvel efi_pci_io_protocol_access_t mem;
7428166ec09SArd Biesheuvel efi_pci_io_protocol_access_t io;
7438166ec09SArd Biesheuvel efi_pci_io_protocol_config_access_t pci;
7448166ec09SArd Biesheuvel void *copy_mem;
7458166ec09SArd Biesheuvel void *map;
7468166ec09SArd Biesheuvel void *unmap;
7478166ec09SArd Biesheuvel void *allocate_buffer;
7488166ec09SArd Biesheuvel void *free_buffer;
7498166ec09SArd Biesheuvel void *flush;
7508166ec09SArd Biesheuvel efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,
7518166ec09SArd Biesheuvel unsigned long *segment_nr,
7528166ec09SArd Biesheuvel unsigned long *bus_nr,
7538166ec09SArd Biesheuvel unsigned long *device_nr,
7548166ec09SArd Biesheuvel unsigned long *func_nr);
7558166ec09SArd Biesheuvel void *attributes;
7568166ec09SArd Biesheuvel void *get_bar_attributes;
7578166ec09SArd Biesheuvel void *set_bar_attributes;
7588166ec09SArd Biesheuvel uint64_t romsize;
7598166ec09SArd Biesheuvel void *romimage;
7608166ec09SArd Biesheuvel };
7618166ec09SArd Biesheuvel struct {
7628166ec09SArd Biesheuvel u32 poll_mem;
7638166ec09SArd Biesheuvel u32 poll_io;
7648166ec09SArd Biesheuvel efi_pci_io_protocol_access_32_t mem;
7658166ec09SArd Biesheuvel efi_pci_io_protocol_access_32_t io;
7668166ec09SArd Biesheuvel efi_pci_io_protocol_access_32_t pci;
7678166ec09SArd Biesheuvel u32 copy_mem;
7688166ec09SArd Biesheuvel u32 map;
7698166ec09SArd Biesheuvel u32 unmap;
7708166ec09SArd Biesheuvel u32 allocate_buffer;
7718166ec09SArd Biesheuvel u32 free_buffer;
7728166ec09SArd Biesheuvel u32 flush;
7738166ec09SArd Biesheuvel u32 get_location;
7748166ec09SArd Biesheuvel u32 attributes;
7758166ec09SArd Biesheuvel u32 get_bar_attributes;
7768166ec09SArd Biesheuvel u32 set_bar_attributes;
7778166ec09SArd Biesheuvel u64 romsize;
7788166ec09SArd Biesheuvel u32 romimage;
7798166ec09SArd Biesheuvel } mixed_mode;
7808166ec09SArd Biesheuvel };
7818166ec09SArd Biesheuvel
7828166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
7838166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
7848166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
7858166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
7868166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
7878166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
7888166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
7898166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
7908166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
7918166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
7928166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
7938166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
7948166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
7958166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
7968166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
7978166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
7988166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
7998166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
8008166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
8018166ec09SArd Biesheuvel
8028166ec09SArd Biesheuvel struct efi_dev_path;
8038166ec09SArd Biesheuvel
8048166ec09SArd Biesheuvel typedef union apple_properties_protocol apple_properties_protocol_t;
8058166ec09SArd Biesheuvel
8068166ec09SArd Biesheuvel union apple_properties_protocol {
8078166ec09SArd Biesheuvel struct {
8088166ec09SArd Biesheuvel unsigned long version;
8098166ec09SArd Biesheuvel efi_status_t (__efiapi *get)(apple_properties_protocol_t *,
8108166ec09SArd Biesheuvel struct efi_dev_path *,
8118166ec09SArd Biesheuvel efi_char16_t *, void *, u32 *);
8128166ec09SArd Biesheuvel efi_status_t (__efiapi *set)(apple_properties_protocol_t *,
8138166ec09SArd Biesheuvel struct efi_dev_path *,
8148166ec09SArd Biesheuvel efi_char16_t *, void *, u32);
8158166ec09SArd Biesheuvel efi_status_t (__efiapi *del)(apple_properties_protocol_t *,
8168166ec09SArd Biesheuvel struct efi_dev_path *,
8178166ec09SArd Biesheuvel efi_char16_t *);
8188166ec09SArd Biesheuvel efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,
8198166ec09SArd Biesheuvel void *buffer, u32 *);
8208166ec09SArd Biesheuvel };
8218166ec09SArd Biesheuvel struct {
8228166ec09SArd Biesheuvel u32 version;
8238166ec09SArd Biesheuvel u32 get;
8248166ec09SArd Biesheuvel u32 set;
8258166ec09SArd Biesheuvel u32 del;
8268166ec09SArd Biesheuvel u32 get_all;
8278166ec09SArd Biesheuvel } mixed_mode;
8288166ec09SArd Biesheuvel };
8298166ec09SArd Biesheuvel
8308166ec09SArd Biesheuvel typedef u32 efi_tcg2_event_log_format;
8318166ec09SArd Biesheuvel
8324da87c51SArd Biesheuvel #define INITRD_EVENT_TAG_ID 0x8F3B22ECU
83371c7adc9SIlias Apalodimas #define LOAD_OPTIONS_EVENT_TAG_ID 0x8F3B22EDU
8344da87c51SArd Biesheuvel #define EV_EVENT_TAG 0x00000006U
8354da87c51SArd Biesheuvel #define EFI_TCG2_EVENT_HEADER_VERSION 0x1
8364da87c51SArd Biesheuvel
8374da87c51SArd Biesheuvel struct efi_tcg2_event {
8384da87c51SArd Biesheuvel u32 event_size;
8394da87c51SArd Biesheuvel struct {
8404da87c51SArd Biesheuvel u32 header_size;
8414da87c51SArd Biesheuvel u16 header_version;
8424da87c51SArd Biesheuvel u32 pcr_index;
8434da87c51SArd Biesheuvel u32 event_type;
8444da87c51SArd Biesheuvel } __packed event_header;
8454da87c51SArd Biesheuvel /* u8[] event follows here */
8464da87c51SArd Biesheuvel } __packed;
8474da87c51SArd Biesheuvel
8483e0b0f88SArd Biesheuvel /* from TCG PC Client Platform Firmware Profile Specification */
8493e0b0f88SArd Biesheuvel typedef struct tdTCG_PCClientTaggedEvent {
8504da87c51SArd Biesheuvel u32 tagged_event_id;
8514da87c51SArd Biesheuvel u32 tagged_event_data_size;
8523e0b0f88SArd Biesheuvel u8 tagged_event_data[];
8533e0b0f88SArd Biesheuvel } TCG_PCClientTaggedEvent;
8544da87c51SArd Biesheuvel
8554da87c51SArd Biesheuvel typedef struct efi_tcg2_event efi_tcg2_event_t;
8568166ec09SArd Biesheuvel typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
8578166ec09SArd Biesheuvel
8588166ec09SArd Biesheuvel union efi_tcg2_protocol {
8598166ec09SArd Biesheuvel struct {
8608166ec09SArd Biesheuvel void *get_capability;
861cdec91c0SArd Biesheuvel efi_status_t (__efiapi *get_event_log)(efi_tcg2_protocol_t *,
8628166ec09SArd Biesheuvel efi_tcg2_event_log_format,
8638166ec09SArd Biesheuvel efi_physical_addr_t *,
8648166ec09SArd Biesheuvel efi_physical_addr_t *,
8658166ec09SArd Biesheuvel efi_bool_t *);
8664da87c51SArd Biesheuvel efi_status_t (__efiapi *hash_log_extend_event)(efi_tcg2_protocol_t *,
8674da87c51SArd Biesheuvel u64,
8684da87c51SArd Biesheuvel efi_physical_addr_t,
8694da87c51SArd Biesheuvel u64,
8704da87c51SArd Biesheuvel const efi_tcg2_event_t *);
8718166ec09SArd Biesheuvel void *submit_command;
8728166ec09SArd Biesheuvel void *get_active_pcr_banks;
8738166ec09SArd Biesheuvel void *set_active_pcr_banks;
8748166ec09SArd Biesheuvel void *get_result_of_set_active_pcr_banks;
8758166ec09SArd Biesheuvel };
8768166ec09SArd Biesheuvel struct {
8778166ec09SArd Biesheuvel u32 get_capability;
8788166ec09SArd Biesheuvel u32 get_event_log;
8798166ec09SArd Biesheuvel u32 hash_log_extend_event;
8808166ec09SArd Biesheuvel u32 submit_command;
8818166ec09SArd Biesheuvel u32 get_active_pcr_banks;
8828166ec09SArd Biesheuvel u32 set_active_pcr_banks;
8838166ec09SArd Biesheuvel u32 get_result_of_set_active_pcr_banks;
8848166ec09SArd Biesheuvel } mixed_mode;
8858166ec09SArd Biesheuvel };
8868166ec09SArd Biesheuvel
8870bbe5b0eSKuppuswamy Sathyanarayanan typedef struct {
8880bbe5b0eSKuppuswamy Sathyanarayanan u8 major;
8890bbe5b0eSKuppuswamy Sathyanarayanan u8 minor;
8900bbe5b0eSKuppuswamy Sathyanarayanan } efi_cc_version_t;
8910bbe5b0eSKuppuswamy Sathyanarayanan
8920bbe5b0eSKuppuswamy Sathyanarayanan typedef struct {
8930bbe5b0eSKuppuswamy Sathyanarayanan u8 type;
8940bbe5b0eSKuppuswamy Sathyanarayanan u8 sub_type;
8950bbe5b0eSKuppuswamy Sathyanarayanan } efi_cc_type_t;
8960bbe5b0eSKuppuswamy Sathyanarayanan
8970bbe5b0eSKuppuswamy Sathyanarayanan /* EFI CC type/subtype defines */
8980bbe5b0eSKuppuswamy Sathyanarayanan #define EFI_CC_TYPE_NONE 0
8990bbe5b0eSKuppuswamy Sathyanarayanan #define EFI_CC_TYPE_AMD_SEV 1
9000bbe5b0eSKuppuswamy Sathyanarayanan #define EFI_CC_TYPE_INTEL_TDX 2
9010bbe5b0eSKuppuswamy Sathyanarayanan
9020bbe5b0eSKuppuswamy Sathyanarayanan typedef u32 efi_cc_mr_index_t;
9030bbe5b0eSKuppuswamy Sathyanarayanan
9040bbe5b0eSKuppuswamy Sathyanarayanan struct efi_cc_event {
9050bbe5b0eSKuppuswamy Sathyanarayanan u32 event_size;
9060bbe5b0eSKuppuswamy Sathyanarayanan struct {
9070bbe5b0eSKuppuswamy Sathyanarayanan u32 header_size;
9080bbe5b0eSKuppuswamy Sathyanarayanan u16 header_version;
9090bbe5b0eSKuppuswamy Sathyanarayanan u32 mr_index;
9100bbe5b0eSKuppuswamy Sathyanarayanan u32 event_type;
9110bbe5b0eSKuppuswamy Sathyanarayanan } __packed event_header;
9120bbe5b0eSKuppuswamy Sathyanarayanan /* u8[] event follows here */
9130bbe5b0eSKuppuswamy Sathyanarayanan } __packed;
9140bbe5b0eSKuppuswamy Sathyanarayanan
9150bbe5b0eSKuppuswamy Sathyanarayanan typedef struct efi_cc_event efi_cc_event_t;
9160bbe5b0eSKuppuswamy Sathyanarayanan
9170bbe5b0eSKuppuswamy Sathyanarayanan typedef u32 efi_cc_event_log_bitmap_t;
9180bbe5b0eSKuppuswamy Sathyanarayanan typedef u32 efi_cc_event_log_format_t;
9190bbe5b0eSKuppuswamy Sathyanarayanan typedef u32 efi_cc_event_algorithm_bitmap_t;
9200bbe5b0eSKuppuswamy Sathyanarayanan
9210bbe5b0eSKuppuswamy Sathyanarayanan typedef struct {
9220bbe5b0eSKuppuswamy Sathyanarayanan u8 size;
9230bbe5b0eSKuppuswamy Sathyanarayanan efi_cc_version_t structure_version;
9240bbe5b0eSKuppuswamy Sathyanarayanan efi_cc_version_t protocol_version;
9250bbe5b0eSKuppuswamy Sathyanarayanan efi_cc_event_algorithm_bitmap_t hash_algorithm_bitmap;
9260bbe5b0eSKuppuswamy Sathyanarayanan efi_cc_event_log_bitmap_t supported_event_logs;
9270bbe5b0eSKuppuswamy Sathyanarayanan efi_cc_type_t cc_type;
9280bbe5b0eSKuppuswamy Sathyanarayanan } efi_cc_boot_service_cap_t;
9290bbe5b0eSKuppuswamy Sathyanarayanan
9300bbe5b0eSKuppuswamy Sathyanarayanan #define EFI_CC_EVENT_HEADER_VERSION 1
9310bbe5b0eSKuppuswamy Sathyanarayanan
9320bbe5b0eSKuppuswamy Sathyanarayanan #define EFI_CC_BOOT_HASH_ALG_SHA384 0x00000004
9330bbe5b0eSKuppuswamy Sathyanarayanan
934d228814bSKuppuswamy Sathyanarayanan #define EFI_CC_EVENT_LOG_FORMAT_TCG_2 0x00000002
935d228814bSKuppuswamy Sathyanarayanan
9360bbe5b0eSKuppuswamy Sathyanarayanan typedef union efi_cc_protocol efi_cc_protocol_t;
9370bbe5b0eSKuppuswamy Sathyanarayanan
9380bbe5b0eSKuppuswamy Sathyanarayanan union efi_cc_protocol {
9390bbe5b0eSKuppuswamy Sathyanarayanan struct {
9400bbe5b0eSKuppuswamy Sathyanarayanan efi_status_t
9410bbe5b0eSKuppuswamy Sathyanarayanan (__efiapi *get_capability)(efi_cc_protocol_t *,
9420bbe5b0eSKuppuswamy Sathyanarayanan efi_cc_boot_service_cap_t *);
9430bbe5b0eSKuppuswamy Sathyanarayanan
9440bbe5b0eSKuppuswamy Sathyanarayanan efi_status_t
9450bbe5b0eSKuppuswamy Sathyanarayanan (__efiapi *get_event_log)(efi_cc_protocol_t *,
9460bbe5b0eSKuppuswamy Sathyanarayanan efi_cc_event_log_format_t,
9470bbe5b0eSKuppuswamy Sathyanarayanan efi_physical_addr_t *,
9480bbe5b0eSKuppuswamy Sathyanarayanan efi_physical_addr_t *,
9490bbe5b0eSKuppuswamy Sathyanarayanan efi_bool_t *);
9500bbe5b0eSKuppuswamy Sathyanarayanan
9510bbe5b0eSKuppuswamy Sathyanarayanan efi_status_t
9520bbe5b0eSKuppuswamy Sathyanarayanan (__efiapi *hash_log_extend_event)(efi_cc_protocol_t *, u64,
9530bbe5b0eSKuppuswamy Sathyanarayanan efi_physical_addr_t, u64,
9540bbe5b0eSKuppuswamy Sathyanarayanan const efi_cc_event_t *);
9550bbe5b0eSKuppuswamy Sathyanarayanan
9560bbe5b0eSKuppuswamy Sathyanarayanan efi_status_t
9570bbe5b0eSKuppuswamy Sathyanarayanan (__efiapi *map_pcr_to_mr_index)(efi_cc_protocol_t *, u32,
9580bbe5b0eSKuppuswamy Sathyanarayanan efi_cc_mr_index_t *);
9590bbe5b0eSKuppuswamy Sathyanarayanan };
9600bbe5b0eSKuppuswamy Sathyanarayanan struct {
9610bbe5b0eSKuppuswamy Sathyanarayanan u32 get_capability;
9620bbe5b0eSKuppuswamy Sathyanarayanan u32 get_event_log;
9630bbe5b0eSKuppuswamy Sathyanarayanan u32 hash_log_extend_event;
9640bbe5b0eSKuppuswamy Sathyanarayanan u32 map_pcr_to_mr_index;
9650bbe5b0eSKuppuswamy Sathyanarayanan } mixed_mode;
9660bbe5b0eSKuppuswamy Sathyanarayanan };
9670bbe5b0eSKuppuswamy Sathyanarayanan
9683f68e695SSunil V L struct riscv_efi_boot_protocol {
9693f68e695SSunil V L u64 revision;
9703f68e695SSunil V L
9713f68e695SSunil V L efi_status_t (__efiapi *get_boot_hartid)(struct riscv_efi_boot_protocol *,
9723f68e695SSunil V L unsigned long *boot_hartid);
9733f68e695SSunil V L };
9743f68e695SSunil V L
9752931d526SArd Biesheuvel typedef union efi_load_file_protocol efi_load_file_protocol_t;
9762931d526SArd Biesheuvel typedef union efi_load_file_protocol efi_load_file2_protocol_t;
9772931d526SArd Biesheuvel
9782931d526SArd Biesheuvel union efi_load_file_protocol {
9792931d526SArd Biesheuvel struct {
9802931d526SArd Biesheuvel efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *,
9812931d526SArd Biesheuvel efi_device_path_protocol_t *,
9822931d526SArd Biesheuvel bool, unsigned long *, void *);
9832931d526SArd Biesheuvel };
9842931d526SArd Biesheuvel struct {
9852931d526SArd Biesheuvel u32 load_file;
9862931d526SArd Biesheuvel } mixed_mode;
9872931d526SArd Biesheuvel };
9882931d526SArd Biesheuvel
9894a568ce2SArvind Sankar typedef struct {
9904a568ce2SArvind Sankar u32 attributes;
9914a568ce2SArvind Sankar u16 file_path_list_length;
9924a568ce2SArvind Sankar u8 variable_data[];
9934a568ce2SArvind Sankar // efi_char16_t description[];
9944a568ce2SArvind Sankar // efi_device_path_protocol_t file_path_list[];
9954a568ce2SArvind Sankar // u8 optional_data[];
9964a568ce2SArvind Sankar } __packed efi_load_option_t;
9974a568ce2SArvind Sankar
9984a568ce2SArvind Sankar #define EFI_LOAD_OPTION_ACTIVE 0x0001U
9994a568ce2SArvind Sankar #define EFI_LOAD_OPTION_FORCE_RECONNECT 0x0002U
10004a568ce2SArvind Sankar #define EFI_LOAD_OPTION_HIDDEN 0x0008U
10014a568ce2SArvind Sankar #define EFI_LOAD_OPTION_CATEGORY 0x1f00U
10024a568ce2SArvind Sankar #define EFI_LOAD_OPTION_CATEGORY_BOOT 0x0000U
10034a568ce2SArvind Sankar #define EFI_LOAD_OPTION_CATEGORY_APP 0x0100U
10044a568ce2SArvind Sankar
10054a568ce2SArvind Sankar #define EFI_LOAD_OPTION_BOOT_MASK \
10064a568ce2SArvind Sankar (EFI_LOAD_OPTION_ACTIVE|EFI_LOAD_OPTION_HIDDEN|EFI_LOAD_OPTION_CATEGORY)
10074a568ce2SArvind Sankar #define EFI_LOAD_OPTION_MASK (EFI_LOAD_OPTION_FORCE_RECONNECT|EFI_LOAD_OPTION_BOOT_MASK)
10084a568ce2SArvind Sankar
10094a568ce2SArvind Sankar typedef struct {
10104a568ce2SArvind Sankar u32 attributes;
10114a568ce2SArvind Sankar u16 file_path_list_length;
10124a568ce2SArvind Sankar const efi_char16_t *description;
10134a568ce2SArvind Sankar const efi_device_path_protocol_t *file_path_list;
1014a241d94bSArd Biesheuvel u32 optional_data_size;
10154a568ce2SArvind Sankar const void *optional_data;
10164a568ce2SArvind Sankar } efi_load_option_unpacked_t;
10174a568ce2SArvind Sankar
10188166ec09SArd Biesheuvel void efi_pci_disable_bridge_busmaster(void);
10198166ec09SArd Biesheuvel
10208166ec09SArd Biesheuvel typedef efi_status_t (*efi_exit_boot_map_processing)(
10218166ec09SArd Biesheuvel struct efi_boot_memmap *map,
10228166ec09SArd Biesheuvel void *priv);
10238166ec09SArd Biesheuvel
1024eab31265SArd Biesheuvel efi_status_t efi_exit_boot_services(void *handle, void *priv,
10258166ec09SArd Biesheuvel efi_exit_boot_map_processing priv_func);
10268166ec09SArd Biesheuvel
10274fc8e738SArd Biesheuvel efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
10284fc8e738SArd Biesheuvel unsigned long kernel_addr, char *cmdline_ptr);
10298166ec09SArd Biesheuvel
10308166ec09SArd Biesheuvel void *get_fdt(unsigned long *fdt_size);
10318166ec09SArd Biesheuvel
1032f80d2604SArd Biesheuvel efi_status_t efi_alloc_virtmap(efi_memory_desc_t **virtmap,
1033f80d2604SArd Biesheuvel unsigned long *desc_size, u32 *desc_ver);
10348166ec09SArd Biesheuvel void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
10358166ec09SArd Biesheuvel unsigned long desc_size, efi_memory_desc_t *runtime_map,
10368166ec09SArd Biesheuvel int *count);
10378166ec09SArd Biesheuvel
10388166ec09SArd Biesheuvel efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
10398166ec09SArd Biesheuvel
10408166ec09SArd Biesheuvel efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
10419cf42bcaSArd Biesheuvel unsigned long *addr, unsigned long random_seed,
10422f77465bSArd Biesheuvel int memory_type, unsigned long alloc_min,
10432f77465bSArd Biesheuvel unsigned long alloc_max);
10448166ec09SArd Biesheuvel
1045196dff27SArd Biesheuvel efi_status_t efi_random_get_seed(void);
1046196dff27SArd Biesheuvel
10478166ec09SArd Biesheuvel efi_status_t check_platform_features(void);
10488166ec09SArd Biesheuvel
10498166ec09SArd Biesheuvel void *get_efi_config_table(efi_guid_t guid);
10508166ec09SArd Biesheuvel
1051cb8c90a0SArvind Sankar /* NOTE: These functions do not print a trailing newline after the string */
1052cb8c90a0SArvind Sankar void efi_char16_puts(efi_char16_t *);
1053cb8c90a0SArvind Sankar void efi_puts(const char *str);
10548166ec09SArd Biesheuvel
10552c7d1e30SArvind Sankar __printf(1, 2) int efi_printk(char const *fmt, ...);
10568166ec09SArd Biesheuvel
10578166ec09SArd Biesheuvel void efi_free(unsigned long size, unsigned long addr);
105860a34085SArd Biesheuvel DEFINE_FREE(efi_pool, void *, if (_T) efi_bs_call(free_pool, _T));
10598166ec09SArd Biesheuvel
1060a241d94bSArd Biesheuvel void efi_apply_loadoptions_quirk(const void **load_options, u32 *load_options_size);
10614a568ce2SArvind Sankar
1062ade7ccbaSJonathan Marek char *efi_convert_cmdline(efi_loaded_image_t *image);
10638166ec09SArd Biesheuvel
1064171539f5SArd Biesheuvel efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,
1065171539f5SArd Biesheuvel bool install_cfg_tbl);
10668166ec09SArd Biesheuvel
10678166ec09SArd Biesheuvel efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,
10688166ec09SArd Biesheuvel unsigned long max);
10698166ec09SArd Biesheuvel
107043b1df0eSArd Biesheuvel efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,
10719cf42bcaSArd Biesheuvel unsigned long max, unsigned long align,
10729cf42bcaSArd Biesheuvel int memory_type);
107343b1df0eSArd Biesheuvel
10741a895dbfSArd Biesheuvel efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,
10751a895dbfSArd Biesheuvel unsigned long *addr, unsigned long min);
10761a895dbfSArd Biesheuvel
10778166ec09SArd Biesheuvel efi_status_t efi_relocate_kernel(unsigned long *image_addr,
10788166ec09SArd Biesheuvel unsigned long image_size,
10798166ec09SArd Biesheuvel unsigned long alloc_size,
10808166ec09SArd Biesheuvel unsigned long preferred_addr,
10818166ec09SArd Biesheuvel unsigned long alignment,
10828166ec09SArd Biesheuvel unsigned long min_addr);
10838166ec09SArd Biesheuvel
10848166ec09SArd Biesheuvel efi_status_t efi_parse_options(char const *cmdline);
10858166ec09SArd Biesheuvel
1086fffb6804SArvind Sankar void efi_parse_option_graphics(char *option);
1087fffb6804SArvind Sankar
108860a34085SArd Biesheuvel efi_status_t efi_setup_gop(struct screen_info *si);
10898166ec09SArd Biesheuvel
1090cf6b8366SArd Biesheuvel efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
1091cf6b8366SArd Biesheuvel const efi_char16_t *optstr,
1092cf6b8366SArd Biesheuvel int optstr_size,
1093cf6b8366SArd Biesheuvel unsigned long soft_limit,
1094cf6b8366SArd Biesheuvel unsigned long hard_limit,
10959302c1bbSArd Biesheuvel unsigned long *load_addr,
10969302c1bbSArd Biesheuvel unsigned long *load_size);
10979302c1bbSArd Biesheuvel
1098cf6b8366SArd Biesheuvel
efi_load_dtb(efi_loaded_image_t * image,unsigned long * load_addr,unsigned long * load_size)1099cf6b8366SArd Biesheuvel static inline efi_status_t efi_load_dtb(efi_loaded_image_t *image,
1100cf6b8366SArd Biesheuvel unsigned long *load_addr,
1101cf6b8366SArd Biesheuvel unsigned long *load_size)
1102cf6b8366SArd Biesheuvel {
1103cf6b8366SArd Biesheuvel return handle_cmdline_files(image, L"dtb=", sizeof(L"dtb=") - 2,
1104cf6b8366SArd Biesheuvel ULONG_MAX, ULONG_MAX, load_addr, load_size);
1105cf6b8366SArd Biesheuvel }
1106cf6b8366SArd Biesheuvel
1107f61900fdSArvind Sankar efi_status_t efi_load_initrd(efi_loaded_image_t *image,
110831f5e546SArd Biesheuvel unsigned long soft_limit,
1109f4dc7fffSArd Biesheuvel unsigned long hard_limit,
1110f4dc7fffSArd Biesheuvel const struct linux_efi_initrd **out);
11113230d95cSAtish Patra /*
11123230d95cSAtish Patra * This function handles the architcture specific differences between arm and
11133230d95cSAtish Patra * arm64 regarding where the kernel image must be loaded and any memory that
11143230d95cSAtish Patra * must be reserved. On failure it is required to free all
11153230d95cSAtish Patra * all allocations it has made.
11163230d95cSAtish Patra */
11173230d95cSAtish Patra efi_status_t handle_kernel_image(unsigned long *image_addr,
11183230d95cSAtish Patra unsigned long *image_size,
11193230d95cSAtish Patra unsigned long *reserve_addr,
11203230d95cSAtish Patra unsigned long *reserve_size,
1121416a9f84SArd Biesheuvel efi_loaded_image_t *image,
1122416a9f84SArd Biesheuvel efi_handle_t image_handle);
11233230d95cSAtish Patra
112442c8ea3dSArd Biesheuvel /* shared entrypoint between the normal stub and the zboot stub */
112542c8ea3dSArd Biesheuvel efi_status_t efi_stub_common(efi_handle_t handle,
112642c8ea3dSArd Biesheuvel efi_loaded_image_t *image,
112742c8ea3dSArd Biesheuvel unsigned long image_addr,
112842c8ea3dSArd Biesheuvel char *cmdline_ptr);
112942c8ea3dSArd Biesheuvel
113042c8ea3dSArd Biesheuvel efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr);
113142c8ea3dSArd Biesheuvel
11323230d95cSAtish Patra asmlinkage void __noreturn efi_enter_kernel(unsigned long entrypoint,
11333230d95cSAtish Patra unsigned long fdt_addr,
11343230d95cSAtish Patra unsigned long fdt_size);
1135ec93fc37SArd Biesheuvel
11362a55280aSArd Biesheuvel void efi_handle_post_ebs_state(void);
11372a55280aSArd Biesheuvel
1138e1ac4b24SChester Lin enum efi_secureboot_mode efi_get_secureboot(void);
1139e1ac4b24SChester Lin
11403820749dSArd Biesheuvel #ifdef CONFIG_RESET_ATTACK_MITIGATION
11413820749dSArd Biesheuvel void efi_enable_reset_attack_mitigation(void);
11423820749dSArd Biesheuvel #else
11433820749dSArd Biesheuvel static inline void
efi_enable_reset_attack_mitigation(void)11443820749dSArd Biesheuvel efi_enable_reset_attack_mitigation(void) { }
11453820749dSArd Biesheuvel #endif
11463820749dSArd Biesheuvel
1147d228814bSKuppuswamy Sathyanarayanan void efi_retrieve_eventlog(void);
11483820749dSArd Biesheuvel
1149732ea9dbSArd Biesheuvel struct screen_info *alloc_screen_info(void);
1150fc3608aaSArd Biesheuvel struct screen_info *__alloc_screen_info(void);
1151732ea9dbSArd Biesheuvel void free_screen_info(struct screen_info *si);
1152732ea9dbSArd Biesheuvel
1153d9ffe524SArd Biesheuvel void efi_cache_sync_image(unsigned long image_base,
1154026b8579SArd Biesheuvel unsigned long alloc_size);
1155d9ffe524SArd Biesheuvel
1156550b33cfSArd Biesheuvel struct efi_smbios_record {
1157550b33cfSArd Biesheuvel u8 type;
1158550b33cfSArd Biesheuvel u8 length;
1159550b33cfSArd Biesheuvel u16 handle;
1160550b33cfSArd Biesheuvel };
1161550b33cfSArd Biesheuvel
1162eb684408SArd Biesheuvel const struct efi_smbios_record *efi_get_smbios_record(u8 type);
1163eb684408SArd Biesheuvel
1164550b33cfSArd Biesheuvel struct efi_smbios_type1_record {
1165550b33cfSArd Biesheuvel struct efi_smbios_record header;
1166550b33cfSArd Biesheuvel
1167550b33cfSArd Biesheuvel u8 manufacturer;
1168550b33cfSArd Biesheuvel u8 product_name;
1169550b33cfSArd Biesheuvel u8 version;
1170550b33cfSArd Biesheuvel u8 serial_number;
1171550b33cfSArd Biesheuvel efi_guid_t uuid;
1172550b33cfSArd Biesheuvel u8 wakeup_type;
1173550b33cfSArd Biesheuvel u8 sku_number;
1174550b33cfSArd Biesheuvel u8 family;
1175550b33cfSArd Biesheuvel };
1176550b33cfSArd Biesheuvel
1177eb684408SArd Biesheuvel struct efi_smbios_type4_record {
1178eb684408SArd Biesheuvel struct efi_smbios_record header;
1179eb684408SArd Biesheuvel
1180eb684408SArd Biesheuvel u8 socket;
1181eb684408SArd Biesheuvel u8 processor_type;
1182eb684408SArd Biesheuvel u8 processor_family;
1183eb684408SArd Biesheuvel u8 processor_manufacturer;
1184eb684408SArd Biesheuvel u8 processor_id[8];
1185eb684408SArd Biesheuvel u8 processor_version;
1186eb684408SArd Biesheuvel u8 voltage;
1187eb684408SArd Biesheuvel u16 external_clock;
1188eb684408SArd Biesheuvel u16 max_speed;
1189eb684408SArd Biesheuvel u16 current_speed;
1190eb684408SArd Biesheuvel u8 status;
1191eb684408SArd Biesheuvel u8 processor_upgrade;
1192eb684408SArd Biesheuvel u16 l1_cache_handle;
1193eb684408SArd Biesheuvel u16 l2_cache_handle;
1194eb684408SArd Biesheuvel u16 l3_cache_handle;
1195eb684408SArd Biesheuvel u8 serial_number;
1196eb684408SArd Biesheuvel u8 asset_tag;
1197eb684408SArd Biesheuvel u8 part_number;
1198eb684408SArd Biesheuvel u8 core_count;
1199eb684408SArd Biesheuvel u8 enabled_core_count;
1200eb684408SArd Biesheuvel u8 thread_count;
1201eb684408SArd Biesheuvel u16 processor_characteristics;
1202eb684408SArd Biesheuvel u16 processor_family2;
1203eb684408SArd Biesheuvel u16 core_count2;
1204eb684408SArd Biesheuvel u16 enabled_core_count2;
1205eb684408SArd Biesheuvel u16 thread_count2;
1206eb684408SArd Biesheuvel u16 thread_enabled;
1207eb684408SArd Biesheuvel };
1208eb684408SArd Biesheuvel
12090dad9ee3SArd Biesheuvel #define efi_get_smbios_string(__record, __field) ({ \
12100dad9ee3SArd Biesheuvel __typeof__(__record) __rec = __record; \
12110dad9ee3SArd Biesheuvel __efi_get_smbios_string(&__rec->header, &__rec->__field); \
1212550b33cfSArd Biesheuvel })
1213550b33cfSArd Biesheuvel
1214eb684408SArd Biesheuvel const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record,
12150dad9ee3SArd Biesheuvel const u8 *offset);
1216550b33cfSArd Biesheuvel
1217ace013a5SArd Biesheuvel void efi_remap_image(unsigned long image_base, unsigned alloc_size,
1218ace013a5SArd Biesheuvel unsigned long code_size);
12196b56beb5SAlexandre Ghiti efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,
12206b56beb5SAlexandre Ghiti unsigned long *reserve_addr,
12216b56beb5SAlexandre Ghiti unsigned long *reserve_size,
12226b56beb5SAlexandre Ghiti unsigned long kernel_size,
12236b56beb5SAlexandre Ghiti unsigned long kernel_codesize,
12246b56beb5SAlexandre Ghiti unsigned long kernel_memsize,
12256b56beb5SAlexandre Ghiti u32 phys_seed);
12266b56beb5SAlexandre Ghiti u32 efi_kaslr_get_phys_seed(efi_handle_t image_handle);
1227ace013a5SArd Biesheuvel
1228fd936fd8SArnd Bergmann asmlinkage efi_status_t __efiapi
1229fd936fd8SArnd Bergmann efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab);
1230fd936fd8SArnd Bergmann
1231745e3ed8SKirill A. Shutemov efi_status_t allocate_unaccepted_bitmap(__u32 nr_desc,
1232745e3ed8SKirill A. Shutemov struct efi_boot_memmap *map);
1233745e3ed8SKirill A. Shutemov void process_unaccepted_memory(u64 start, u64 end);
12345adfeaecSKirill A. Shutemov void accept_memory(phys_addr_t start, unsigned long size);
1235745e3ed8SKirill A. Shutemov void arch_accept_memory(phys_addr_t start, phys_addr_t end);
1236745e3ed8SKirill A. Shutemov
1237*0dc1754eSArd Biesheuvel efi_status_t efi_zboot_decompress_init(unsigned long *alloc_size);
1238*0dc1754eSArd Biesheuvel efi_status_t efi_zboot_decompress(u8 *out, unsigned long outlen);
1239*0dc1754eSArd Biesheuvel
1240bd669475SArd Biesheuvel #endif
1241