xref: /linux/drivers/firmware/efi/libstub/efistub.h (revision ade7ccba2d647fced0c1f5f290705dcab14b674e)
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>
70b767353SArvind Sankar #include <linux/efi.h>
80b767353SArvind Sankar #include <linux/kernel.h>
923d5b73fSArvind Sankar #include <linux/kern_levels.h>
100b767353SArvind Sankar #include <linux/types.h>
110b767353SArvind Sankar #include <asm/efi.h>
120b767353SArvind Sankar 
1307e83dbbSArd Biesheuvel /*
1407e83dbbSArd Biesheuvel  * __init annotations should not be used in the EFI stub, since the code is
1507e83dbbSArd Biesheuvel  * either included in the decompressor (x86, ARM) where they have no effect,
1607e83dbbSArd Biesheuvel  * or the whole stub is __init annotated at the section level (arm64), by
1707e83dbbSArd Biesheuvel  * renaming the sections, in which case the __init annotation will be
1807e83dbbSArd Biesheuvel  * redundant, and will result in section names like .init.init.text, and our
1907e83dbbSArd Biesheuvel  * linker script does not expect that.
2007e83dbbSArd Biesheuvel  */
2107e83dbbSArd Biesheuvel #undef __init
2207e83dbbSArd Biesheuvel 
23a6a14469SArd Biesheuvel /*
24a6a14469SArd Biesheuvel  * Allow the platform to override the allocation granularity: this allows
25a6a14469SArd Biesheuvel  * systems that have the capability to run with a larger page size to deal
26a6a14469SArd Biesheuvel  * with the allocations for initrd and fdt more efficiently.
27a6a14469SArd Biesheuvel  */
28a6a14469SArd Biesheuvel #ifndef EFI_ALLOC_ALIGN
29a6a14469SArd Biesheuvel #define EFI_ALLOC_ALIGN		EFI_PAGE_SIZE
30a6a14469SArd Biesheuvel #endif
31a6a14469SArd Biesheuvel 
32a37dac5cSArd Biesheuvel #ifndef EFI_ALLOC_LIMIT
33a37dac5cSArd Biesheuvel #define EFI_ALLOC_LIMIT		ULONG_MAX
34a37dac5cSArd Biesheuvel #endif
35a37dac5cSArd Biesheuvel 
36cb1c9e02SArd Biesheuvel extern bool efi_no5lvl;
37980771f6SArd Biesheuvel extern bool efi_nochunk;
38980771f6SArd Biesheuvel extern bool efi_nokaslr;
3923d5b73fSArvind Sankar extern int efi_loglevel;
407205f06eSArd Biesheuvel extern int efi_mem_encrypt;
41980771f6SArd Biesheuvel extern bool efi_novamap;
42ccc27ae7SArd Biesheuvel extern const efi_system_table_t *efi_system_table;
432fcdad2aSArd Biesheuvel 
443ba75c13SBaskov Evgeniy typedef union efi_dxe_services_table efi_dxe_services_table_t;
453ba75c13SBaskov Evgeniy extern const efi_dxe_services_table_t *efi_dxe_table;
463ba75c13SBaskov Evgeniy 
476e99d321SArd Biesheuvel efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
486e99d321SArd Biesheuvel 				   efi_system_table_t *sys_table_arg);
496e99d321SArd Biesheuvel 
50de8c5520SArvind Sankar #ifndef ARCH_HAS_EFISTUB_WRAPPERS
51de8c5520SArvind Sankar 
5222090f84SArd Biesheuvel #define efi_is_native()			(true)
53a61962d8SArd Biesheuvel #define efi_table_attr(inst, attr)	(inst)->attr
54a61962d8SArd Biesheuvel #define efi_fn_call(inst, func, ...)	(inst)->func(__VA_ARGS__)
55de8c5520SArvind Sankar 
5622090f84SArd Biesheuvel #endif
5722090f84SArd Biesheuvel 
58a61962d8SArd Biesheuvel #define efi_call_proto(inst, func, ...) ({			\
59a61962d8SArd Biesheuvel 	__typeof__(inst) __inst = (inst);			\
60a61962d8SArd Biesheuvel 	efi_fn_call(__inst, func, __inst, ##__VA_ARGS__);	\
61a61962d8SArd Biesheuvel })
62a61962d8SArd Biesheuvel #define efi_bs_call(func, ...) \
63a61962d8SArd Biesheuvel 	efi_fn_call(efi_table_attr(efi_system_table, boottime), func, ##__VA_ARGS__)
64a61962d8SArd Biesheuvel #define efi_rt_call(func, ...) \
65a61962d8SArd Biesheuvel 	efi_fn_call(efi_table_attr(efi_system_table, runtime), func, ##__VA_ARGS__)
66a61962d8SArd Biesheuvel #define efi_dxe_call(func, ...) \
67a61962d8SArd Biesheuvel 	efi_fn_call(efi_dxe_table, func, ##__VA_ARGS__)
68a61962d8SArd Biesheuvel 
6923d5b73fSArvind Sankar #define efi_info(fmt, ...) \
7023d5b73fSArvind Sankar 	efi_printk(KERN_INFO fmt, ##__VA_ARGS__)
71c1df5e0cSArvind Sankar #define efi_warn(fmt, ...) \
72c1df5e0cSArvind Sankar 	efi_printk(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
7323d5b73fSArvind Sankar #define efi_err(fmt, ...) \
7423d5b73fSArvind Sankar 	efi_printk(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)
7523d5b73fSArvind Sankar #define efi_debug(fmt, ...) \
7623d5b73fSArvind Sankar 	efi_printk(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)
7760f38de7SArd Biesheuvel 
78c1df5e0cSArvind Sankar #define efi_printk_once(fmt, ...) 		\
79c1df5e0cSArvind Sankar ({						\
80c1df5e0cSArvind Sankar 	static bool __print_once;		\
81c1df5e0cSArvind Sankar 	bool __ret_print_once = !__print_once;	\
82c1df5e0cSArvind Sankar 						\
83c1df5e0cSArvind Sankar 	if (!__print_once) {			\
84c1df5e0cSArvind Sankar 		__print_once = true;		\
85c1df5e0cSArvind Sankar 		efi_printk(fmt, ##__VA_ARGS__);	\
86c1df5e0cSArvind Sankar 	}					\
87c1df5e0cSArvind Sankar 	__ret_print_once;			\
88c1df5e0cSArvind Sankar })
89c1df5e0cSArvind Sankar 
90c1df5e0cSArvind Sankar #define efi_info_once(fmt, ...) \
91c1df5e0cSArvind Sankar 	efi_printk_once(KERN_INFO fmt, ##__VA_ARGS__)
92c1df5e0cSArvind Sankar #define efi_warn_once(fmt, ...) \
93c1df5e0cSArvind Sankar 	efi_printk_once(KERN_WARNING "WARNING: " fmt, ##__VA_ARGS__)
94c1df5e0cSArvind Sankar #define efi_err_once(fmt, ...) \
95c1df5e0cSArvind Sankar 	efi_printk_once(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)
96c1df5e0cSArvind Sankar #define efi_debug_once(fmt, ...) \
97c1df5e0cSArvind Sankar 	efi_printk_once(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)
98c1df5e0cSArvind Sankar 
99ac9aff8eSIngo Molnar /* Helper macros for the usual case of using simple C variables: */
100ac9aff8eSIngo Molnar #ifndef fdt_setprop_inplace_var
101ac9aff8eSIngo Molnar #define fdt_setprop_inplace_var(fdt, node_offset, name, var) \
102ac9aff8eSIngo Molnar 	fdt_setprop_inplace((fdt), (node_offset), (name), &(var), sizeof(var))
103ac9aff8eSIngo Molnar #endif
104ac9aff8eSIngo Molnar 
105ac9aff8eSIngo Molnar #ifndef fdt_setprop_var
106ac9aff8eSIngo Molnar #define fdt_setprop_var(fdt, node_offset, name, var) \
107ac9aff8eSIngo Molnar 	fdt_setprop((fdt), (node_offset), (name), &(var), sizeof(var))
108ac9aff8eSIngo Molnar #endif
109ac9aff8eSIngo Molnar 
110966291f6SArd Biesheuvel #define get_efi_var(name, vendor, ...)				\
111966291f6SArd Biesheuvel 	efi_rt_call(get_variable, (efi_char16_t *)(name),	\
112966291f6SArd Biesheuvel 		    (efi_guid_t *)(vendor), __VA_ARGS__)
113966291f6SArd Biesheuvel 
114966291f6SArd Biesheuvel #define set_efi_var(name, vendor, ...)				\
115966291f6SArd Biesheuvel 	efi_rt_call(set_variable, (efi_char16_t *)(name),	\
116966291f6SArd Biesheuvel 		    (efi_guid_t *)(vendor), __VA_ARGS__)
117966291f6SArd Biesheuvel 
1188166ec09SArd Biesheuvel #define efi_get_handle_at(array, idx)					\
1198166ec09SArd Biesheuvel 	(efi_is_native() ? (array)[idx] 				\
1208166ec09SArd Biesheuvel 		: (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
1218166ec09SArd Biesheuvel 
1228166ec09SArd Biesheuvel #define efi_get_handle_num(size)					\
1238166ec09SArd Biesheuvel 	((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))
1248166ec09SArd Biesheuvel 
1258166ec09SArd Biesheuvel #define for_each_efi_handle(handle, array, size, i)			\
1268166ec09SArd Biesheuvel 	for (i = 0;							\
1278166ec09SArd Biesheuvel 	     i < efi_get_handle_num(size) &&				\
1288166ec09SArd Biesheuvel 		((handle = efi_get_handle_at((array), i)) || true);	\
1298166ec09SArd Biesheuvel 	     i++)
1308166ec09SArd Biesheuvel 
131eed4e019SArvind Sankar static inline
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  */
174fd626195SLenny Szubowicz #define EFI_MMAP_NR_SLACK_SLOTS	8
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
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;
3178166ec09SArd Biesheuvel 		void *locate_handle_buffer;
3188166ec09SArd Biesheuvel 		efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,
3198166ec09SArd Biesheuvel 							 void **);
320c7007d9fSArd Biesheuvel 		efi_status_t (__efiapi *install_multiple_protocol_interfaces)(efi_handle_t *, ...);
321c7007d9fSArd Biesheuvel 		efi_status_t (__efiapi *uninstall_multiple_protocol_interfaces)(efi_handle_t, ...);
3228166ec09SArd Biesheuvel 		void *calculate_crc32;
323c82ceb44SArd Biesheuvel 		void (__efiapi *copy_mem)(void *, const void *, unsigned long);
324c82ceb44SArd Biesheuvel 		void (__efiapi *set_mem)(void *, unsigned long, unsigned char);
3258166ec09SArd Biesheuvel 		void *create_event_ex;
3268166ec09SArd Biesheuvel 	};
3278166ec09SArd Biesheuvel 	struct {
3288166ec09SArd Biesheuvel 		efi_table_hdr_t hdr;
3298166ec09SArd Biesheuvel 		u32 raise_tpl;
3308166ec09SArd Biesheuvel 		u32 restore_tpl;
3318166ec09SArd Biesheuvel 		u32 allocate_pages;
3328166ec09SArd Biesheuvel 		u32 free_pages;
3338166ec09SArd Biesheuvel 		u32 get_memory_map;
3348166ec09SArd Biesheuvel 		u32 allocate_pool;
3358166ec09SArd Biesheuvel 		u32 free_pool;
3368166ec09SArd Biesheuvel 		u32 create_event;
3378166ec09SArd Biesheuvel 		u32 set_timer;
3388166ec09SArd Biesheuvel 		u32 wait_for_event;
3398166ec09SArd Biesheuvel 		u32 signal_event;
3408166ec09SArd Biesheuvel 		u32 close_event;
3418166ec09SArd Biesheuvel 		u32 check_event;
3428166ec09SArd Biesheuvel 		u32 install_protocol_interface;
3438166ec09SArd Biesheuvel 		u32 reinstall_protocol_interface;
3448166ec09SArd Biesheuvel 		u32 uninstall_protocol_interface;
3458166ec09SArd Biesheuvel 		u32 handle_protocol;
3468166ec09SArd Biesheuvel 		u32 __reserved;
3478166ec09SArd Biesheuvel 		u32 register_protocol_notify;
3488166ec09SArd Biesheuvel 		u32 locate_handle;
3498166ec09SArd Biesheuvel 		u32 locate_device_path;
3508166ec09SArd Biesheuvel 		u32 install_configuration_table;
3518166ec09SArd Biesheuvel 		u32 load_image;
3528166ec09SArd Biesheuvel 		u32 start_image;
3538166ec09SArd Biesheuvel 		u32 exit;
3548166ec09SArd Biesheuvel 		u32 unload_image;
3558166ec09SArd Biesheuvel 		u32 exit_boot_services;
3568166ec09SArd Biesheuvel 		u32 get_next_monotonic_count;
3578166ec09SArd Biesheuvel 		u32 stall;
3588166ec09SArd Biesheuvel 		u32 set_watchdog_timer;
3598166ec09SArd Biesheuvel 		u32 connect_controller;
3608166ec09SArd Biesheuvel 		u32 disconnect_controller;
3618166ec09SArd Biesheuvel 		u32 open_protocol;
3628166ec09SArd Biesheuvel 		u32 close_protocol;
3638166ec09SArd Biesheuvel 		u32 open_protocol_information;
3648166ec09SArd Biesheuvel 		u32 protocols_per_handle;
3658166ec09SArd Biesheuvel 		u32 locate_handle_buffer;
3668166ec09SArd Biesheuvel 		u32 locate_protocol;
3678166ec09SArd Biesheuvel 		u32 install_multiple_protocol_interfaces;
3688166ec09SArd Biesheuvel 		u32 uninstall_multiple_protocol_interfaces;
3698166ec09SArd Biesheuvel 		u32 calculate_crc32;
3708166ec09SArd Biesheuvel 		u32 copy_mem;
3718166ec09SArd Biesheuvel 		u32 set_mem;
3728166ec09SArd Biesheuvel 		u32 create_event_ex;
3738166ec09SArd Biesheuvel 	} mixed_mode;
3748166ec09SArd Biesheuvel };
3758166ec09SArd Biesheuvel 
3763ba75c13SBaskov Evgeniy typedef enum {
3773ba75c13SBaskov Evgeniy 	EfiGcdMemoryTypeNonExistent,
3783ba75c13SBaskov Evgeniy 	EfiGcdMemoryTypeReserved,
3793ba75c13SBaskov Evgeniy 	EfiGcdMemoryTypeSystemMemory,
3803ba75c13SBaskov Evgeniy 	EfiGcdMemoryTypeMemoryMappedIo,
3813ba75c13SBaskov Evgeniy 	EfiGcdMemoryTypePersistent,
3823ba75c13SBaskov Evgeniy 	EfiGcdMemoryTypeMoreReliable,
3833ba75c13SBaskov Evgeniy 	EfiGcdMemoryTypeMaximum
3843ba75c13SBaskov Evgeniy } efi_gcd_memory_type_t;
3853ba75c13SBaskov Evgeniy 
3863ba75c13SBaskov Evgeniy typedef struct {
3873ba75c13SBaskov Evgeniy 	efi_physical_addr_t base_address;
3883ba75c13SBaskov Evgeniy 	u64 length;
3893ba75c13SBaskov Evgeniy 	u64 capabilities;
3903ba75c13SBaskov Evgeniy 	u64 attributes;
3913ba75c13SBaskov Evgeniy 	efi_gcd_memory_type_t gcd_memory_type;
3923ba75c13SBaskov Evgeniy 	void *image_handle;
3933ba75c13SBaskov Evgeniy 	void *device_handle;
3943ba75c13SBaskov Evgeniy } efi_gcd_memory_space_desc_t;
3953ba75c13SBaskov Evgeniy 
3963ba75c13SBaskov Evgeniy /*
3973ba75c13SBaskov Evgeniy  * EFI DXE Services table
3983ba75c13SBaskov Evgeniy  */
3993ba75c13SBaskov Evgeniy union efi_dxe_services_table {
4003ba75c13SBaskov Evgeniy 	struct {
4013ba75c13SBaskov Evgeniy 		efi_table_hdr_t hdr;
4023ba75c13SBaskov Evgeniy 		void *add_memory_space;
4033ba75c13SBaskov Evgeniy 		void *allocate_memory_space;
4043ba75c13SBaskov Evgeniy 		void *free_memory_space;
4053ba75c13SBaskov Evgeniy 		void *remove_memory_space;
4063ba75c13SBaskov Evgeniy 		efi_status_t (__efiapi *get_memory_space_descriptor)(efi_physical_addr_t,
4073ba75c13SBaskov Evgeniy 								     efi_gcd_memory_space_desc_t *);
4083ba75c13SBaskov Evgeniy 		efi_status_t (__efiapi *set_memory_space_attributes)(efi_physical_addr_t,
4093ba75c13SBaskov Evgeniy 								     u64, u64);
4103ba75c13SBaskov Evgeniy 		void *get_memory_space_map;
4113ba75c13SBaskov Evgeniy 		void *add_io_space;
4123ba75c13SBaskov Evgeniy 		void *allocate_io_space;
4133ba75c13SBaskov Evgeniy 		void *free_io_space;
4143ba75c13SBaskov Evgeniy 		void *remove_io_space;
4153ba75c13SBaskov Evgeniy 		void *get_io_space_descriptor;
4163ba75c13SBaskov Evgeniy 		void *get_io_space_map;
4173ba75c13SBaskov Evgeniy 		void *dispatch;
4183ba75c13SBaskov Evgeniy 		void *schedule;
4193ba75c13SBaskov Evgeniy 		void *trust;
4203ba75c13SBaskov Evgeniy 		void *process_firmware_volume;
4213ba75c13SBaskov Evgeniy 		void *set_memory_space_capabilities;
4223ba75c13SBaskov Evgeniy 	};
4233ba75c13SBaskov Evgeniy 	struct {
4243ba75c13SBaskov Evgeniy 		efi_table_hdr_t hdr;
4253ba75c13SBaskov Evgeniy 		u32 add_memory_space;
4263ba75c13SBaskov Evgeniy 		u32 allocate_memory_space;
4273ba75c13SBaskov Evgeniy 		u32 free_memory_space;
4283ba75c13SBaskov Evgeniy 		u32 remove_memory_space;
4293ba75c13SBaskov Evgeniy 		u32 get_memory_space_descriptor;
4303ba75c13SBaskov Evgeniy 		u32 set_memory_space_attributes;
4313ba75c13SBaskov Evgeniy 		u32 get_memory_space_map;
4323ba75c13SBaskov Evgeniy 		u32 add_io_space;
4333ba75c13SBaskov Evgeniy 		u32 allocate_io_space;
4343ba75c13SBaskov Evgeniy 		u32 free_io_space;
4353ba75c13SBaskov Evgeniy 		u32 remove_io_space;
4363ba75c13SBaskov Evgeniy 		u32 get_io_space_descriptor;
4373ba75c13SBaskov Evgeniy 		u32 get_io_space_map;
4383ba75c13SBaskov Evgeniy 		u32 dispatch;
4393ba75c13SBaskov Evgeniy 		u32 schedule;
4403ba75c13SBaskov Evgeniy 		u32 trust;
4413ba75c13SBaskov Evgeniy 		u32 process_firmware_volume;
4423ba75c13SBaskov Evgeniy 		u32 set_memory_space_capabilities;
4433ba75c13SBaskov Evgeniy 	} mixed_mode;
4443ba75c13SBaskov Evgeniy };
4453ba75c13SBaskov Evgeniy 
44679729f26SEvgeniy Baskov typedef union efi_memory_attribute_protocol efi_memory_attribute_protocol_t;
44779729f26SEvgeniy Baskov 
44879729f26SEvgeniy Baskov union efi_memory_attribute_protocol {
44979729f26SEvgeniy Baskov 	struct {
45079729f26SEvgeniy Baskov 		efi_status_t (__efiapi *get_memory_attributes)(
45179729f26SEvgeniy Baskov 			efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64 *);
45279729f26SEvgeniy Baskov 
45379729f26SEvgeniy Baskov 		efi_status_t (__efiapi *set_memory_attributes)(
45479729f26SEvgeniy Baskov 			efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64);
45579729f26SEvgeniy Baskov 
45679729f26SEvgeniy Baskov 		efi_status_t (__efiapi *clear_memory_attributes)(
45779729f26SEvgeniy Baskov 			efi_memory_attribute_protocol_t *, efi_physical_addr_t, u64, u64);
45879729f26SEvgeniy Baskov 	};
45979729f26SEvgeniy Baskov 	struct {
46079729f26SEvgeniy Baskov 		u32 get_memory_attributes;
46179729f26SEvgeniy Baskov 		u32 set_memory_attributes;
46279729f26SEvgeniy Baskov 		u32 clear_memory_attributes;
46379729f26SEvgeniy Baskov 	} mixed_mode;
46479729f26SEvgeniy Baskov };
46579729f26SEvgeniy Baskov 
466c2d0b470SArd Biesheuvel typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
467c2d0b470SArd Biesheuvel 
468c2d0b470SArd Biesheuvel union efi_uga_draw_protocol {
469c2d0b470SArd Biesheuvel 	struct {
470c2d0b470SArd Biesheuvel 		efi_status_t (__efiapi *get_mode)(efi_uga_draw_protocol_t *,
471c2d0b470SArd Biesheuvel 						  u32*, u32*, u32*, u32*);
472c2d0b470SArd Biesheuvel 		void *set_mode;
473c2d0b470SArd Biesheuvel 		void *blt;
474c2d0b470SArd Biesheuvel 	};
475c2d0b470SArd Biesheuvel 	struct {
476c2d0b470SArd Biesheuvel 		u32 get_mode;
477c2d0b470SArd Biesheuvel 		u32 set_mode;
478c2d0b470SArd Biesheuvel 		u32 blt;
479c2d0b470SArd Biesheuvel 	} mixed_mode;
480c2d0b470SArd Biesheuvel };
481c2d0b470SArd Biesheuvel 
4829b47c527SArvind Sankar typedef struct {
4839b47c527SArvind Sankar 	u16 scan_code;
4849b47c527SArvind Sankar 	efi_char16_t unicode_char;
4859b47c527SArvind Sankar } efi_input_key_t;
4869b47c527SArvind Sankar 
4879b47c527SArvind Sankar union efi_simple_text_input_protocol {
4889b47c527SArvind Sankar 	struct {
4899b47c527SArvind Sankar 		void *reset;
4909b47c527SArvind Sankar 		efi_status_t (__efiapi *read_keystroke)(efi_simple_text_input_protocol_t *,
4919b47c527SArvind Sankar 							efi_input_key_t *);
4929b47c527SArvind Sankar 		efi_event_t wait_for_key;
4939b47c527SArvind Sankar 	};
4949b47c527SArvind Sankar 	struct {
4959b47c527SArvind Sankar 		u32 reset;
4969b47c527SArvind Sankar 		u32 read_keystroke;
4979b47c527SArvind Sankar 		u32 wait_for_key;
4989b47c527SArvind Sankar 	} mixed_mode;
4999b47c527SArvind Sankar };
5009b47c527SArvind Sankar 
50114c574f3SArvind Sankar efi_status_t efi_wait_for_key(unsigned long usec, efi_input_key_t *key);
50214c574f3SArvind Sankar 
5038166ec09SArd Biesheuvel union efi_simple_text_output_protocol {
5048166ec09SArd Biesheuvel 	struct {
5058166ec09SArd Biesheuvel 		void *reset;
5068166ec09SArd Biesheuvel 		efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
5078166ec09SArd Biesheuvel 						       efi_char16_t *);
5088166ec09SArd Biesheuvel 		void *test_string;
5098166ec09SArd Biesheuvel 	};
5108166ec09SArd Biesheuvel 	struct {
5118166ec09SArd Biesheuvel 		u32 reset;
5128166ec09SArd Biesheuvel 		u32 output_string;
5138166ec09SArd Biesheuvel 		u32 test_string;
5148166ec09SArd Biesheuvel 	} mixed_mode;
5158166ec09SArd Biesheuvel };
5168166ec09SArd Biesheuvel 
5178166ec09SArd Biesheuvel #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR		0
5188166ec09SArd Biesheuvel #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR		1
5198166ec09SArd Biesheuvel #define PIXEL_BIT_MASK					2
5208166ec09SArd Biesheuvel #define PIXEL_BLT_ONLY					3
5218166ec09SArd Biesheuvel #define PIXEL_FORMAT_MAX				4
5228166ec09SArd Biesheuvel 
5238166ec09SArd Biesheuvel typedef struct {
5248166ec09SArd Biesheuvel 	u32 red_mask;
5258166ec09SArd Biesheuvel 	u32 green_mask;
5268166ec09SArd Biesheuvel 	u32 blue_mask;
5278166ec09SArd Biesheuvel 	u32 reserved_mask;
5288166ec09SArd Biesheuvel } efi_pixel_bitmask_t;
5298166ec09SArd Biesheuvel 
5308166ec09SArd Biesheuvel typedef struct {
5318166ec09SArd Biesheuvel 	u32 version;
5328166ec09SArd Biesheuvel 	u32 horizontal_resolution;
5338166ec09SArd Biesheuvel 	u32 vertical_resolution;
5348166ec09SArd Biesheuvel 	int pixel_format;
5358166ec09SArd Biesheuvel 	efi_pixel_bitmask_t pixel_information;
5368166ec09SArd Biesheuvel 	u32 pixels_per_scan_line;
5378166ec09SArd Biesheuvel } efi_graphics_output_mode_info_t;
5388166ec09SArd Biesheuvel 
5398166ec09SArd Biesheuvel typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;
5408166ec09SArd Biesheuvel 
5418166ec09SArd Biesheuvel union efi_graphics_output_protocol_mode {
5428166ec09SArd Biesheuvel 	struct {
5438166ec09SArd Biesheuvel 		u32 max_mode;
5448166ec09SArd Biesheuvel 		u32 mode;
5458166ec09SArd Biesheuvel 		efi_graphics_output_mode_info_t *info;
5468166ec09SArd Biesheuvel 		unsigned long size_of_info;
5478166ec09SArd Biesheuvel 		efi_physical_addr_t frame_buffer_base;
5488166ec09SArd Biesheuvel 		unsigned long frame_buffer_size;
5498166ec09SArd Biesheuvel 	};
5508166ec09SArd Biesheuvel 	struct {
5518166ec09SArd Biesheuvel 		u32 max_mode;
5528166ec09SArd Biesheuvel 		u32 mode;
5538166ec09SArd Biesheuvel 		u32 info;
5548166ec09SArd Biesheuvel 		u32 size_of_info;
5558166ec09SArd Biesheuvel 		u64 frame_buffer_base;
5568166ec09SArd Biesheuvel 		u32 frame_buffer_size;
5578166ec09SArd Biesheuvel 	} mixed_mode;
5588166ec09SArd Biesheuvel };
5598166ec09SArd Biesheuvel 
5608166ec09SArd Biesheuvel typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;
5618166ec09SArd Biesheuvel 
5628166ec09SArd Biesheuvel union efi_graphics_output_protocol {
5638166ec09SArd Biesheuvel 	struct {
564b4b89a02SArvind Sankar 		efi_status_t (__efiapi *query_mode)(efi_graphics_output_protocol_t *,
565b4b89a02SArvind Sankar 						    u32, unsigned long *,
566b4b89a02SArvind Sankar 						    efi_graphics_output_mode_info_t **);
567b4b89a02SArvind Sankar 		efi_status_t (__efiapi *set_mode)  (efi_graphics_output_protocol_t *, u32);
5688166ec09SArd Biesheuvel 		void *blt;
5698166ec09SArd Biesheuvel 		efi_graphics_output_protocol_mode_t *mode;
5708166ec09SArd Biesheuvel 	};
5718166ec09SArd Biesheuvel 	struct {
5728166ec09SArd Biesheuvel 		u32 query_mode;
5738166ec09SArd Biesheuvel 		u32 set_mode;
5748166ec09SArd Biesheuvel 		u32 blt;
5758166ec09SArd Biesheuvel 		u32 mode;
5768166ec09SArd Biesheuvel 	} mixed_mode;
5778166ec09SArd Biesheuvel };
5788166ec09SArd Biesheuvel 
579f7b85b33SArd Biesheuvel typedef union {
580f7b85b33SArd Biesheuvel 	struct {
581a46a290aSArd Biesheuvel 		u32			revision;
582a46a290aSArd Biesheuvel 		efi_handle_t		parent_handle;
583a46a290aSArd Biesheuvel 		efi_system_table_t	*system_table;
584a46a290aSArd Biesheuvel 		efi_handle_t		device_handle;
585a46a290aSArd Biesheuvel 		void			*file_path;
586a46a290aSArd Biesheuvel 		void			*reserved;
587a46a290aSArd Biesheuvel 		u32			load_options_size;
588a46a290aSArd Biesheuvel 		void			*load_options;
589a46a290aSArd Biesheuvel 		void			*image_base;
590a46a290aSArd Biesheuvel 		__aligned_u64		image_size;
591a46a290aSArd Biesheuvel 		unsigned int		image_code_type;
592a46a290aSArd Biesheuvel 		unsigned int		image_data_type;
593a46a290aSArd Biesheuvel 		efi_status_t		(__efiapi *unload)(efi_handle_t image_handle);
594f7b85b33SArd Biesheuvel 	};
595f7b85b33SArd Biesheuvel 	struct {
596f7b85b33SArd Biesheuvel 		u32		revision;
597f7b85b33SArd Biesheuvel 		u32		parent_handle;
598f7b85b33SArd Biesheuvel 		u32		system_table;
599f7b85b33SArd Biesheuvel 		u32		device_handle;
600f7b85b33SArd Biesheuvel 		u32		file_path;
601f7b85b33SArd Biesheuvel 		u32		reserved;
602f7b85b33SArd Biesheuvel 		u32		load_options_size;
603f7b85b33SArd Biesheuvel 		u32		load_options;
604f7b85b33SArd Biesheuvel 		u32		image_base;
605f7b85b33SArd Biesheuvel 		__aligned_u64	image_size;
606f7b85b33SArd Biesheuvel 		u32		image_code_type;
607f7b85b33SArd Biesheuvel 		u32		image_data_type;
608f7b85b33SArd Biesheuvel 		u32		unload;
609f7b85b33SArd Biesheuvel 	} mixed_mode;
610a46a290aSArd Biesheuvel } efi_loaded_image_t;
611a46a290aSArd Biesheuvel 
612a46a290aSArd Biesheuvel typedef struct {
613a46a290aSArd Biesheuvel 	u64			size;
614a46a290aSArd Biesheuvel 	u64			file_size;
615a46a290aSArd Biesheuvel 	u64			phys_size;
616a46a290aSArd Biesheuvel 	efi_time_t		create_time;
617a46a290aSArd Biesheuvel 	efi_time_t		last_access_time;
618a46a290aSArd Biesheuvel 	efi_time_t		modification_time;
619a46a290aSArd Biesheuvel 	__aligned_u64		attribute;
6209302c1bbSArd Biesheuvel 	efi_char16_t		filename[];
621a46a290aSArd Biesheuvel } efi_file_info_t;
622a46a290aSArd Biesheuvel 
623f8a31244SArd Biesheuvel typedef union efi_file_protocol efi_file_protocol_t;
624a46a290aSArd Biesheuvel 
625f8a31244SArd Biesheuvel union efi_file_protocol {
626f8a31244SArd Biesheuvel 	struct {
627a46a290aSArd Biesheuvel 		u64		revision;
628a46a290aSArd Biesheuvel 		efi_status_t	(__efiapi *open)	(efi_file_protocol_t *,
629a46a290aSArd Biesheuvel 							 efi_file_protocol_t **,
630f8a31244SArd Biesheuvel 							 efi_char16_t *, u64,
631f8a31244SArd Biesheuvel 							 u64);
632a46a290aSArd Biesheuvel 		efi_status_t	(__efiapi *close)	(efi_file_protocol_t *);
633a46a290aSArd Biesheuvel 		efi_status_t	(__efiapi *delete)	(efi_file_protocol_t *);
634a46a290aSArd Biesheuvel 		efi_status_t	(__efiapi *read)	(efi_file_protocol_t *,
635f8a31244SArd Biesheuvel 							 unsigned long *,
636f8a31244SArd Biesheuvel 							 void *);
637a46a290aSArd Biesheuvel 		efi_status_t	(__efiapi *write)	(efi_file_protocol_t *,
638a46a290aSArd Biesheuvel 							 unsigned long, void *);
639f8a31244SArd Biesheuvel 		efi_status_t	(__efiapi *get_position)(efi_file_protocol_t *,
640f8a31244SArd Biesheuvel 							 u64 *);
641f8a31244SArd Biesheuvel 		efi_status_t	(__efiapi *set_position)(efi_file_protocol_t *,
642f8a31244SArd Biesheuvel 							 u64);
643a46a290aSArd Biesheuvel 		efi_status_t	(__efiapi *get_info)	(efi_file_protocol_t *,
644f8a31244SArd Biesheuvel 							 efi_guid_t *,
645f8a31244SArd Biesheuvel 							 unsigned long *,
646a46a290aSArd Biesheuvel 							 void *);
647a46a290aSArd Biesheuvel 		efi_status_t	(__efiapi *set_info)	(efi_file_protocol_t *,
648f8a31244SArd Biesheuvel 							 efi_guid_t *,
649f8a31244SArd Biesheuvel 							 unsigned long,
650a46a290aSArd Biesheuvel 							 void *);
651a46a290aSArd Biesheuvel 		efi_status_t	(__efiapi *flush)	(efi_file_protocol_t *);
652a46a290aSArd Biesheuvel 	};
653f8a31244SArd Biesheuvel 	struct {
654a46a290aSArd Biesheuvel 		u64 revision;
655f8a31244SArd Biesheuvel 		u32 open;
656f8a31244SArd Biesheuvel 		u32 close;
657f8a31244SArd Biesheuvel 		u32 delete;
658f8a31244SArd Biesheuvel 		u32 read;
659f8a31244SArd Biesheuvel 		u32 write;
660f8a31244SArd Biesheuvel 		u32 get_position;
661f8a31244SArd Biesheuvel 		u32 set_position;
662f8a31244SArd Biesheuvel 		u32 get_info;
663f8a31244SArd Biesheuvel 		u32 set_info;
664f8a31244SArd Biesheuvel 		u32 flush;
665f8a31244SArd Biesheuvel 	} mixed_mode;
666f8a31244SArd Biesheuvel };
667f8a31244SArd Biesheuvel 
668f8a31244SArd Biesheuvel typedef union efi_simple_file_system_protocol efi_simple_file_system_protocol_t;
669f8a31244SArd Biesheuvel 
670f8a31244SArd Biesheuvel union efi_simple_file_system_protocol {
671f8a31244SArd Biesheuvel 	struct {
672f8a31244SArd Biesheuvel 		u64		revision;
673f8a31244SArd Biesheuvel 		efi_status_t	(__efiapi *open_volume)(efi_simple_file_system_protocol_t *,
674a46a290aSArd Biesheuvel 							efi_file_protocol_t **);
675a46a290aSArd Biesheuvel 	};
676f8a31244SArd Biesheuvel 	struct {
677f8a31244SArd Biesheuvel 		u64 revision;
678f8a31244SArd Biesheuvel 		u32 open_volume;
679f8a31244SArd Biesheuvel 	} mixed_mode;
680f8a31244SArd Biesheuvel };
681a46a290aSArd Biesheuvel 
682a46a290aSArd Biesheuvel #define EFI_FILE_MODE_READ	0x0000000000000001
683a46a290aSArd Biesheuvel #define EFI_FILE_MODE_WRITE	0x0000000000000002
684a46a290aSArd Biesheuvel #define EFI_FILE_MODE_CREATE	0x8000000000000000
685a46a290aSArd Biesheuvel 
6868166ec09SArd Biesheuvel typedef enum {
6878166ec09SArd Biesheuvel 	EfiPciIoWidthUint8,
6888166ec09SArd Biesheuvel 	EfiPciIoWidthUint16,
6898166ec09SArd Biesheuvel 	EfiPciIoWidthUint32,
6908166ec09SArd Biesheuvel 	EfiPciIoWidthUint64,
6918166ec09SArd Biesheuvel 	EfiPciIoWidthFifoUint8,
6928166ec09SArd Biesheuvel 	EfiPciIoWidthFifoUint16,
6938166ec09SArd Biesheuvel 	EfiPciIoWidthFifoUint32,
6948166ec09SArd Biesheuvel 	EfiPciIoWidthFifoUint64,
6958166ec09SArd Biesheuvel 	EfiPciIoWidthFillUint8,
6968166ec09SArd Biesheuvel 	EfiPciIoWidthFillUint16,
6978166ec09SArd Biesheuvel 	EfiPciIoWidthFillUint32,
6988166ec09SArd Biesheuvel 	EfiPciIoWidthFillUint64,
6998166ec09SArd Biesheuvel 	EfiPciIoWidthMaximum
7008166ec09SArd Biesheuvel } EFI_PCI_IO_PROTOCOL_WIDTH;
7018166ec09SArd Biesheuvel 
7028166ec09SArd Biesheuvel typedef enum {
7038166ec09SArd Biesheuvel 	EfiPciIoAttributeOperationGet,
7048166ec09SArd Biesheuvel 	EfiPciIoAttributeOperationSet,
7058166ec09SArd Biesheuvel 	EfiPciIoAttributeOperationEnable,
7068166ec09SArd Biesheuvel 	EfiPciIoAttributeOperationDisable,
7078166ec09SArd Biesheuvel 	EfiPciIoAttributeOperationSupported,
7088166ec09SArd Biesheuvel     EfiPciIoAttributeOperationMaximum
7098166ec09SArd Biesheuvel } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
7108166ec09SArd Biesheuvel 
7118166ec09SArd Biesheuvel typedef struct {
7128166ec09SArd Biesheuvel 	u32 read;
7138166ec09SArd Biesheuvel 	u32 write;
7148166ec09SArd Biesheuvel } efi_pci_io_protocol_access_32_t;
7158166ec09SArd Biesheuvel 
7168166ec09SArd Biesheuvel typedef union efi_pci_io_protocol efi_pci_io_protocol_t;
7178166ec09SArd Biesheuvel 
7188166ec09SArd Biesheuvel typedef
7198166ec09SArd Biesheuvel efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
7208166ec09SArd Biesheuvel 						   EFI_PCI_IO_PROTOCOL_WIDTH,
7218166ec09SArd Biesheuvel 						   u32 offset,
7228166ec09SArd Biesheuvel 						   unsigned long count,
7238166ec09SArd Biesheuvel 						   void *buffer);
7248166ec09SArd Biesheuvel 
7258166ec09SArd Biesheuvel typedef struct {
7268166ec09SArd Biesheuvel 	void *read;
7278166ec09SArd Biesheuvel 	void *write;
7288166ec09SArd Biesheuvel } efi_pci_io_protocol_access_t;
7298166ec09SArd Biesheuvel 
7308166ec09SArd Biesheuvel typedef struct {
7318166ec09SArd Biesheuvel 	efi_pci_io_protocol_cfg_t read;
7328166ec09SArd Biesheuvel 	efi_pci_io_protocol_cfg_t write;
7338166ec09SArd Biesheuvel } efi_pci_io_protocol_config_access_t;
7348166ec09SArd Biesheuvel 
7358166ec09SArd Biesheuvel union efi_pci_io_protocol {
7368166ec09SArd Biesheuvel 	struct {
7378166ec09SArd Biesheuvel 		void *poll_mem;
7388166ec09SArd Biesheuvel 		void *poll_io;
7398166ec09SArd Biesheuvel 		efi_pci_io_protocol_access_t mem;
7408166ec09SArd Biesheuvel 		efi_pci_io_protocol_access_t io;
7418166ec09SArd Biesheuvel 		efi_pci_io_protocol_config_access_t pci;
7428166ec09SArd Biesheuvel 		void *copy_mem;
7438166ec09SArd Biesheuvel 		void *map;
7448166ec09SArd Biesheuvel 		void *unmap;
7458166ec09SArd Biesheuvel 		void *allocate_buffer;
7468166ec09SArd Biesheuvel 		void *free_buffer;
7478166ec09SArd Biesheuvel 		void *flush;
7488166ec09SArd Biesheuvel 		efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,
7498166ec09SArd Biesheuvel 						      unsigned long *segment_nr,
7508166ec09SArd Biesheuvel 						      unsigned long *bus_nr,
7518166ec09SArd Biesheuvel 						      unsigned long *device_nr,
7528166ec09SArd Biesheuvel 						      unsigned long *func_nr);
7538166ec09SArd Biesheuvel 		void *attributes;
7548166ec09SArd Biesheuvel 		void *get_bar_attributes;
7558166ec09SArd Biesheuvel 		void *set_bar_attributes;
7568166ec09SArd Biesheuvel 		uint64_t romsize;
7578166ec09SArd Biesheuvel 		void *romimage;
7588166ec09SArd Biesheuvel 	};
7598166ec09SArd Biesheuvel 	struct {
7608166ec09SArd Biesheuvel 		u32 poll_mem;
7618166ec09SArd Biesheuvel 		u32 poll_io;
7628166ec09SArd Biesheuvel 		efi_pci_io_protocol_access_32_t mem;
7638166ec09SArd Biesheuvel 		efi_pci_io_protocol_access_32_t io;
7648166ec09SArd Biesheuvel 		efi_pci_io_protocol_access_32_t pci;
7658166ec09SArd Biesheuvel 		u32 copy_mem;
7668166ec09SArd Biesheuvel 		u32 map;
7678166ec09SArd Biesheuvel 		u32 unmap;
7688166ec09SArd Biesheuvel 		u32 allocate_buffer;
7698166ec09SArd Biesheuvel 		u32 free_buffer;
7708166ec09SArd Biesheuvel 		u32 flush;
7718166ec09SArd Biesheuvel 		u32 get_location;
7728166ec09SArd Biesheuvel 		u32 attributes;
7738166ec09SArd Biesheuvel 		u32 get_bar_attributes;
7748166ec09SArd Biesheuvel 		u32 set_bar_attributes;
7758166ec09SArd Biesheuvel 		u64 romsize;
7768166ec09SArd Biesheuvel 		u32 romimage;
7778166ec09SArd Biesheuvel 	} mixed_mode;
7788166ec09SArd Biesheuvel };
7798166ec09SArd Biesheuvel 
7808166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
7818166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
7828166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
7838166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
7848166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
7858166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
7868166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
7878166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
7888166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
7898166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
7908166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
7918166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
7928166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
7938166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
7948166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
7958166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
7968166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
7978166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
7988166ec09SArd Biesheuvel #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
7998166ec09SArd Biesheuvel 
8008166ec09SArd Biesheuvel struct efi_dev_path;
8018166ec09SArd Biesheuvel 
8028166ec09SArd Biesheuvel typedef union apple_properties_protocol apple_properties_protocol_t;
8038166ec09SArd Biesheuvel 
8048166ec09SArd Biesheuvel union apple_properties_protocol {
8058166ec09SArd Biesheuvel 	struct {
8068166ec09SArd Biesheuvel 		unsigned long version;
8078166ec09SArd Biesheuvel 		efi_status_t (__efiapi *get)(apple_properties_protocol_t *,
8088166ec09SArd Biesheuvel 					     struct efi_dev_path *,
8098166ec09SArd Biesheuvel 					     efi_char16_t *, void *, u32 *);
8108166ec09SArd Biesheuvel 		efi_status_t (__efiapi *set)(apple_properties_protocol_t *,
8118166ec09SArd Biesheuvel 					     struct efi_dev_path *,
8128166ec09SArd Biesheuvel 					     efi_char16_t *, void *, u32);
8138166ec09SArd Biesheuvel 		efi_status_t (__efiapi *del)(apple_properties_protocol_t *,
8148166ec09SArd Biesheuvel 					     struct efi_dev_path *,
8158166ec09SArd Biesheuvel 					     efi_char16_t *);
8168166ec09SArd Biesheuvel 		efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,
8178166ec09SArd Biesheuvel 						 void *buffer, u32 *);
8188166ec09SArd Biesheuvel 	};
8198166ec09SArd Biesheuvel 	struct {
8208166ec09SArd Biesheuvel 		u32 version;
8218166ec09SArd Biesheuvel 		u32 get;
8228166ec09SArd Biesheuvel 		u32 set;
8238166ec09SArd Biesheuvel 		u32 del;
8248166ec09SArd Biesheuvel 		u32 get_all;
8258166ec09SArd Biesheuvel 	} mixed_mode;
8268166ec09SArd Biesheuvel };
8278166ec09SArd Biesheuvel 
8288166ec09SArd Biesheuvel typedef u32 efi_tcg2_event_log_format;
8298166ec09SArd Biesheuvel 
8304da87c51SArd Biesheuvel #define INITRD_EVENT_TAG_ID 0x8F3B22ECU
83171c7adc9SIlias Apalodimas #define LOAD_OPTIONS_EVENT_TAG_ID 0x8F3B22EDU
8324da87c51SArd Biesheuvel #define EV_EVENT_TAG 0x00000006U
8334da87c51SArd Biesheuvel #define EFI_TCG2_EVENT_HEADER_VERSION	0x1
8344da87c51SArd Biesheuvel 
8354da87c51SArd Biesheuvel struct efi_tcg2_event {
8364da87c51SArd Biesheuvel 	u32		event_size;
8374da87c51SArd Biesheuvel 	struct {
8384da87c51SArd Biesheuvel 		u32	header_size;
8394da87c51SArd Biesheuvel 		u16	header_version;
8404da87c51SArd Biesheuvel 		u32	pcr_index;
8414da87c51SArd Biesheuvel 		u32	event_type;
8424da87c51SArd Biesheuvel 	} __packed event_header;
8434da87c51SArd Biesheuvel 	/* u8[] event follows here */
8444da87c51SArd Biesheuvel } __packed;
8454da87c51SArd Biesheuvel 
8463e0b0f88SArd Biesheuvel /* from TCG PC Client Platform Firmware Profile Specification */
8473e0b0f88SArd Biesheuvel typedef struct tdTCG_PCClientTaggedEvent {
8484da87c51SArd Biesheuvel 	u32	tagged_event_id;
8494da87c51SArd Biesheuvel 	u32	tagged_event_data_size;
8503e0b0f88SArd Biesheuvel 	u8	tagged_event_data[];
8513e0b0f88SArd Biesheuvel } TCG_PCClientTaggedEvent;
8524da87c51SArd Biesheuvel 
8534da87c51SArd Biesheuvel typedef struct efi_tcg2_event efi_tcg2_event_t;
8548166ec09SArd Biesheuvel typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
8558166ec09SArd Biesheuvel 
8568166ec09SArd Biesheuvel union efi_tcg2_protocol {
8578166ec09SArd Biesheuvel 	struct {
8588166ec09SArd Biesheuvel 		void *get_capability;
859cdec91c0SArd Biesheuvel 		efi_status_t (__efiapi *get_event_log)(efi_tcg2_protocol_t *,
8608166ec09SArd Biesheuvel 						       efi_tcg2_event_log_format,
8618166ec09SArd Biesheuvel 						       efi_physical_addr_t *,
8628166ec09SArd Biesheuvel 						       efi_physical_addr_t *,
8638166ec09SArd Biesheuvel 						       efi_bool_t *);
8644da87c51SArd Biesheuvel 		efi_status_t (__efiapi *hash_log_extend_event)(efi_tcg2_protocol_t *,
8654da87c51SArd Biesheuvel 							       u64,
8664da87c51SArd Biesheuvel 							       efi_physical_addr_t,
8674da87c51SArd Biesheuvel 							       u64,
8684da87c51SArd Biesheuvel 							       const efi_tcg2_event_t *);
8698166ec09SArd Biesheuvel 		void *submit_command;
8708166ec09SArd Biesheuvel 		void *get_active_pcr_banks;
8718166ec09SArd Biesheuvel 		void *set_active_pcr_banks;
8728166ec09SArd Biesheuvel 		void *get_result_of_set_active_pcr_banks;
8738166ec09SArd Biesheuvel 	};
8748166ec09SArd Biesheuvel 	struct {
8758166ec09SArd Biesheuvel 		u32 get_capability;
8768166ec09SArd Biesheuvel 		u32 get_event_log;
8778166ec09SArd Biesheuvel 		u32 hash_log_extend_event;
8788166ec09SArd Biesheuvel 		u32 submit_command;
8798166ec09SArd Biesheuvel 		u32 get_active_pcr_banks;
8808166ec09SArd Biesheuvel 		u32 set_active_pcr_banks;
8818166ec09SArd Biesheuvel 		u32 get_result_of_set_active_pcr_banks;
8828166ec09SArd Biesheuvel 	} mixed_mode;
8838166ec09SArd Biesheuvel };
8848166ec09SArd Biesheuvel 
8850bbe5b0eSKuppuswamy Sathyanarayanan typedef struct {
8860bbe5b0eSKuppuswamy Sathyanarayanan 	u8 major;
8870bbe5b0eSKuppuswamy Sathyanarayanan 	u8 minor;
8880bbe5b0eSKuppuswamy Sathyanarayanan } efi_cc_version_t;
8890bbe5b0eSKuppuswamy Sathyanarayanan 
8900bbe5b0eSKuppuswamy Sathyanarayanan typedef struct {
8910bbe5b0eSKuppuswamy Sathyanarayanan 	u8 type;
8920bbe5b0eSKuppuswamy Sathyanarayanan 	u8 sub_type;
8930bbe5b0eSKuppuswamy Sathyanarayanan } efi_cc_type_t;
8940bbe5b0eSKuppuswamy Sathyanarayanan 
8950bbe5b0eSKuppuswamy Sathyanarayanan /* EFI CC type/subtype defines */
8960bbe5b0eSKuppuswamy Sathyanarayanan #define EFI_CC_TYPE_NONE		0
8970bbe5b0eSKuppuswamy Sathyanarayanan #define EFI_CC_TYPE_AMD_SEV		1
8980bbe5b0eSKuppuswamy Sathyanarayanan #define EFI_CC_TYPE_INTEL_TDX		2
8990bbe5b0eSKuppuswamy Sathyanarayanan 
9000bbe5b0eSKuppuswamy Sathyanarayanan typedef u32 efi_cc_mr_index_t;
9010bbe5b0eSKuppuswamy Sathyanarayanan 
9020bbe5b0eSKuppuswamy Sathyanarayanan struct efi_cc_event {
9030bbe5b0eSKuppuswamy Sathyanarayanan 	u32 event_size;
9040bbe5b0eSKuppuswamy Sathyanarayanan 	struct {
9050bbe5b0eSKuppuswamy Sathyanarayanan 		u32 header_size;
9060bbe5b0eSKuppuswamy Sathyanarayanan 		u16 header_version;
9070bbe5b0eSKuppuswamy Sathyanarayanan 		u32 mr_index;
9080bbe5b0eSKuppuswamy Sathyanarayanan 		u32 event_type;
9090bbe5b0eSKuppuswamy Sathyanarayanan 	} __packed event_header;
9100bbe5b0eSKuppuswamy Sathyanarayanan 	/* u8[] event follows here */
9110bbe5b0eSKuppuswamy Sathyanarayanan } __packed;
9120bbe5b0eSKuppuswamy Sathyanarayanan 
9130bbe5b0eSKuppuswamy Sathyanarayanan typedef struct efi_cc_event efi_cc_event_t;
9140bbe5b0eSKuppuswamy Sathyanarayanan 
9150bbe5b0eSKuppuswamy Sathyanarayanan typedef u32 efi_cc_event_log_bitmap_t;
9160bbe5b0eSKuppuswamy Sathyanarayanan typedef u32 efi_cc_event_log_format_t;
9170bbe5b0eSKuppuswamy Sathyanarayanan typedef u32 efi_cc_event_algorithm_bitmap_t;
9180bbe5b0eSKuppuswamy Sathyanarayanan 
9190bbe5b0eSKuppuswamy Sathyanarayanan typedef struct {
9200bbe5b0eSKuppuswamy Sathyanarayanan 	u8				size;
9210bbe5b0eSKuppuswamy Sathyanarayanan 	efi_cc_version_t		structure_version;
9220bbe5b0eSKuppuswamy Sathyanarayanan 	efi_cc_version_t		protocol_version;
9230bbe5b0eSKuppuswamy Sathyanarayanan 	efi_cc_event_algorithm_bitmap_t	hash_algorithm_bitmap;
9240bbe5b0eSKuppuswamy Sathyanarayanan 	efi_cc_event_log_bitmap_t	supported_event_logs;
9250bbe5b0eSKuppuswamy Sathyanarayanan 	efi_cc_type_t			cc_type;
9260bbe5b0eSKuppuswamy Sathyanarayanan } efi_cc_boot_service_cap_t;
9270bbe5b0eSKuppuswamy Sathyanarayanan 
9280bbe5b0eSKuppuswamy Sathyanarayanan #define EFI_CC_EVENT_HEADER_VERSION	1
9290bbe5b0eSKuppuswamy Sathyanarayanan 
9300bbe5b0eSKuppuswamy Sathyanarayanan #define EFI_CC_BOOT_HASH_ALG_SHA384	0x00000004
9310bbe5b0eSKuppuswamy Sathyanarayanan 
932d228814bSKuppuswamy Sathyanarayanan #define EFI_CC_EVENT_LOG_FORMAT_TCG_2	0x00000002
933d228814bSKuppuswamy Sathyanarayanan 
9340bbe5b0eSKuppuswamy Sathyanarayanan typedef union efi_cc_protocol efi_cc_protocol_t;
9350bbe5b0eSKuppuswamy Sathyanarayanan 
9360bbe5b0eSKuppuswamy Sathyanarayanan union efi_cc_protocol {
9370bbe5b0eSKuppuswamy Sathyanarayanan 	struct {
9380bbe5b0eSKuppuswamy Sathyanarayanan 		efi_status_t
9390bbe5b0eSKuppuswamy Sathyanarayanan 		(__efiapi *get_capability)(efi_cc_protocol_t *,
9400bbe5b0eSKuppuswamy Sathyanarayanan 					   efi_cc_boot_service_cap_t *);
9410bbe5b0eSKuppuswamy Sathyanarayanan 
9420bbe5b0eSKuppuswamy Sathyanarayanan 		efi_status_t
9430bbe5b0eSKuppuswamy Sathyanarayanan 		(__efiapi *get_event_log)(efi_cc_protocol_t *,
9440bbe5b0eSKuppuswamy Sathyanarayanan 					  efi_cc_event_log_format_t,
9450bbe5b0eSKuppuswamy Sathyanarayanan 					  efi_physical_addr_t *,
9460bbe5b0eSKuppuswamy Sathyanarayanan 					  efi_physical_addr_t *,
9470bbe5b0eSKuppuswamy Sathyanarayanan 					  efi_bool_t *);
9480bbe5b0eSKuppuswamy Sathyanarayanan 
9490bbe5b0eSKuppuswamy Sathyanarayanan 		efi_status_t
9500bbe5b0eSKuppuswamy Sathyanarayanan 		(__efiapi *hash_log_extend_event)(efi_cc_protocol_t *, u64,
9510bbe5b0eSKuppuswamy Sathyanarayanan 						  efi_physical_addr_t, u64,
9520bbe5b0eSKuppuswamy Sathyanarayanan 						  const efi_cc_event_t *);
9530bbe5b0eSKuppuswamy Sathyanarayanan 
9540bbe5b0eSKuppuswamy Sathyanarayanan 		efi_status_t
9550bbe5b0eSKuppuswamy Sathyanarayanan 		(__efiapi *map_pcr_to_mr_index)(efi_cc_protocol_t *, u32,
9560bbe5b0eSKuppuswamy Sathyanarayanan 						efi_cc_mr_index_t *);
9570bbe5b0eSKuppuswamy Sathyanarayanan 	};
9580bbe5b0eSKuppuswamy Sathyanarayanan 	struct {
9590bbe5b0eSKuppuswamy Sathyanarayanan 		u32 get_capability;
9600bbe5b0eSKuppuswamy Sathyanarayanan 		u32 get_event_log;
9610bbe5b0eSKuppuswamy Sathyanarayanan 		u32 hash_log_extend_event;
9620bbe5b0eSKuppuswamy Sathyanarayanan 		u32 map_pcr_to_mr_index;
9630bbe5b0eSKuppuswamy Sathyanarayanan 	} mixed_mode;
9640bbe5b0eSKuppuswamy Sathyanarayanan };
9650bbe5b0eSKuppuswamy Sathyanarayanan 
9663f68e695SSunil V L struct riscv_efi_boot_protocol {
9673f68e695SSunil V L 	u64 revision;
9683f68e695SSunil V L 
9693f68e695SSunil V L 	efi_status_t (__efiapi *get_boot_hartid)(struct riscv_efi_boot_protocol *,
9703f68e695SSunil V L 						 unsigned long *boot_hartid);
9713f68e695SSunil V L };
9723f68e695SSunil V L 
9732931d526SArd Biesheuvel typedef union efi_load_file_protocol efi_load_file_protocol_t;
9742931d526SArd Biesheuvel typedef union efi_load_file_protocol efi_load_file2_protocol_t;
9752931d526SArd Biesheuvel 
9762931d526SArd Biesheuvel union efi_load_file_protocol {
9772931d526SArd Biesheuvel 	struct {
9782931d526SArd Biesheuvel 		efi_status_t (__efiapi *load_file)(efi_load_file_protocol_t *,
9792931d526SArd Biesheuvel 						   efi_device_path_protocol_t *,
9802931d526SArd Biesheuvel 						   bool, unsigned long *, void *);
9812931d526SArd Biesheuvel 	};
9822931d526SArd Biesheuvel 	struct {
9832931d526SArd Biesheuvel 		u32 load_file;
9842931d526SArd Biesheuvel 	} mixed_mode;
9852931d526SArd Biesheuvel };
9862931d526SArd Biesheuvel 
9874a568ce2SArvind Sankar typedef struct {
9884a568ce2SArvind Sankar 	u32 attributes;
9894a568ce2SArvind Sankar 	u16 file_path_list_length;
9904a568ce2SArvind Sankar 	u8 variable_data[];
9914a568ce2SArvind Sankar 	// efi_char16_t description[];
9924a568ce2SArvind Sankar 	// efi_device_path_protocol_t file_path_list[];
9934a568ce2SArvind Sankar 	// u8 optional_data[];
9944a568ce2SArvind Sankar } __packed efi_load_option_t;
9954a568ce2SArvind Sankar 
9964a568ce2SArvind Sankar #define EFI_LOAD_OPTION_ACTIVE		0x0001U
9974a568ce2SArvind Sankar #define EFI_LOAD_OPTION_FORCE_RECONNECT	0x0002U
9984a568ce2SArvind Sankar #define EFI_LOAD_OPTION_HIDDEN		0x0008U
9994a568ce2SArvind Sankar #define EFI_LOAD_OPTION_CATEGORY	0x1f00U
10004a568ce2SArvind Sankar #define   EFI_LOAD_OPTION_CATEGORY_BOOT	0x0000U
10014a568ce2SArvind Sankar #define   EFI_LOAD_OPTION_CATEGORY_APP	0x0100U
10024a568ce2SArvind Sankar 
10034a568ce2SArvind Sankar #define EFI_LOAD_OPTION_BOOT_MASK \
10044a568ce2SArvind Sankar 	(EFI_LOAD_OPTION_ACTIVE|EFI_LOAD_OPTION_HIDDEN|EFI_LOAD_OPTION_CATEGORY)
10054a568ce2SArvind Sankar #define EFI_LOAD_OPTION_MASK (EFI_LOAD_OPTION_FORCE_RECONNECT|EFI_LOAD_OPTION_BOOT_MASK)
10064a568ce2SArvind Sankar 
10074a568ce2SArvind Sankar typedef struct {
10084a568ce2SArvind Sankar 	u32 attributes;
10094a568ce2SArvind Sankar 	u16 file_path_list_length;
10104a568ce2SArvind Sankar 	const efi_char16_t *description;
10114a568ce2SArvind Sankar 	const efi_device_path_protocol_t *file_path_list;
1012a241d94bSArd Biesheuvel 	u32 optional_data_size;
10134a568ce2SArvind Sankar 	const void *optional_data;
10144a568ce2SArvind Sankar } efi_load_option_unpacked_t;
10154a568ce2SArvind Sankar 
10168166ec09SArd Biesheuvel void efi_pci_disable_bridge_busmaster(void);
10178166ec09SArd Biesheuvel 
10188166ec09SArd Biesheuvel typedef efi_status_t (*efi_exit_boot_map_processing)(
10198166ec09SArd Biesheuvel 	struct efi_boot_memmap *map,
10208166ec09SArd Biesheuvel 	void *priv);
10218166ec09SArd Biesheuvel 
1022eab31265SArd Biesheuvel efi_status_t efi_exit_boot_services(void *handle, void *priv,
10238166ec09SArd Biesheuvel 				    efi_exit_boot_map_processing priv_func);
10248166ec09SArd Biesheuvel 
10254fc8e738SArd Biesheuvel efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
10264fc8e738SArd Biesheuvel 			     unsigned long kernel_addr, char *cmdline_ptr);
10278166ec09SArd Biesheuvel 
10288166ec09SArd Biesheuvel void *get_fdt(unsigned long *fdt_size);
10298166ec09SArd Biesheuvel 
1030f80d2604SArd Biesheuvel efi_status_t efi_alloc_virtmap(efi_memory_desc_t **virtmap,
1031f80d2604SArd Biesheuvel 			       unsigned long *desc_size, u32 *desc_ver);
10328166ec09SArd Biesheuvel void efi_get_virtmap(efi_memory_desc_t *memory_map, unsigned long map_size,
10338166ec09SArd Biesheuvel 		     unsigned long desc_size, efi_memory_desc_t *runtime_map,
10348166ec09SArd Biesheuvel 		     int *count);
10358166ec09SArd Biesheuvel 
10368166ec09SArd Biesheuvel efi_status_t efi_get_random_bytes(unsigned long size, u8 *out);
10378166ec09SArd Biesheuvel 
10388166ec09SArd Biesheuvel efi_status_t efi_random_alloc(unsigned long size, unsigned long align,
10399cf42bcaSArd Biesheuvel 			      unsigned long *addr, unsigned long random_seed,
10402f77465bSArd Biesheuvel 			      int memory_type, unsigned long alloc_min,
10412f77465bSArd Biesheuvel 			      unsigned long alloc_max);
10428166ec09SArd Biesheuvel 
1043196dff27SArd Biesheuvel efi_status_t efi_random_get_seed(void);
1044196dff27SArd Biesheuvel 
10458166ec09SArd Biesheuvel efi_status_t check_platform_features(void);
10468166ec09SArd Biesheuvel 
10478166ec09SArd Biesheuvel void *get_efi_config_table(efi_guid_t guid);
10488166ec09SArd Biesheuvel 
1049cb8c90a0SArvind Sankar /* NOTE: These functions do not print a trailing newline after the string */
1050cb8c90a0SArvind Sankar void efi_char16_puts(efi_char16_t *);
1051cb8c90a0SArvind Sankar void efi_puts(const char *str);
10528166ec09SArd Biesheuvel 
10532c7d1e30SArvind Sankar __printf(1, 2) int efi_printk(char const *fmt, ...);
10548166ec09SArd Biesheuvel 
10558166ec09SArd Biesheuvel void efi_free(unsigned long size, unsigned long addr);
10568166ec09SArd Biesheuvel 
1057a241d94bSArd Biesheuvel void efi_apply_loadoptions_quirk(const void **load_options, u32 *load_options_size);
10584a568ce2SArvind Sankar 
1059*ade7ccbaSJonathan Marek char *efi_convert_cmdline(efi_loaded_image_t *image);
10608166ec09SArd Biesheuvel 
1061171539f5SArd Biesheuvel efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,
1062171539f5SArd Biesheuvel 				bool install_cfg_tbl);
10638166ec09SArd Biesheuvel 
10648166ec09SArd Biesheuvel efi_status_t efi_allocate_pages(unsigned long size, unsigned long *addr,
10658166ec09SArd Biesheuvel 				unsigned long max);
10668166ec09SArd Biesheuvel 
106743b1df0eSArd Biesheuvel efi_status_t efi_allocate_pages_aligned(unsigned long size, unsigned long *addr,
10689cf42bcaSArd Biesheuvel 					unsigned long max, unsigned long align,
10699cf42bcaSArd Biesheuvel 					int memory_type);
107043b1df0eSArd Biesheuvel 
10711a895dbfSArd Biesheuvel efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,
10721a895dbfSArd Biesheuvel 				 unsigned long *addr, unsigned long min);
10731a895dbfSArd Biesheuvel 
10748166ec09SArd Biesheuvel efi_status_t efi_relocate_kernel(unsigned long *image_addr,
10758166ec09SArd Biesheuvel 				 unsigned long image_size,
10768166ec09SArd Biesheuvel 				 unsigned long alloc_size,
10778166ec09SArd Biesheuvel 				 unsigned long preferred_addr,
10788166ec09SArd Biesheuvel 				 unsigned long alignment,
10798166ec09SArd Biesheuvel 				 unsigned long min_addr);
10808166ec09SArd Biesheuvel 
10818166ec09SArd Biesheuvel efi_status_t efi_parse_options(char const *cmdline);
10828166ec09SArd Biesheuvel 
1083fffb6804SArvind Sankar void efi_parse_option_graphics(char *option);
1084fffb6804SArvind Sankar 
10858166ec09SArd Biesheuvel efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto,
10868166ec09SArd Biesheuvel 			   unsigned long size);
10878166ec09SArd Biesheuvel 
1088cf6b8366SArd Biesheuvel efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
1089cf6b8366SArd Biesheuvel 				  const efi_char16_t *optstr,
1090cf6b8366SArd Biesheuvel 				  int optstr_size,
1091cf6b8366SArd Biesheuvel 				  unsigned long soft_limit,
1092cf6b8366SArd Biesheuvel 				  unsigned long hard_limit,
10939302c1bbSArd Biesheuvel 				  unsigned long *load_addr,
10949302c1bbSArd Biesheuvel 				  unsigned long *load_size);
10959302c1bbSArd Biesheuvel 
1096cf6b8366SArd Biesheuvel 
1097cf6b8366SArd Biesheuvel static inline efi_status_t efi_load_dtb(efi_loaded_image_t *image,
1098cf6b8366SArd Biesheuvel 					unsigned long *load_addr,
1099cf6b8366SArd Biesheuvel 					unsigned long *load_size)
1100cf6b8366SArd Biesheuvel {
1101cf6b8366SArd Biesheuvel 	return handle_cmdline_files(image, L"dtb=", sizeof(L"dtb=") - 2,
1102cf6b8366SArd Biesheuvel 				    ULONG_MAX, ULONG_MAX, load_addr, load_size);
1103cf6b8366SArd Biesheuvel }
1104cf6b8366SArd Biesheuvel 
1105f61900fdSArvind Sankar efi_status_t efi_load_initrd(efi_loaded_image_t *image,
110631f5e546SArd Biesheuvel 			     unsigned long soft_limit,
1107f4dc7fffSArd Biesheuvel 			     unsigned long hard_limit,
1108f4dc7fffSArd Biesheuvel 			     const struct linux_efi_initrd **out);
11093230d95cSAtish Patra /*
11103230d95cSAtish Patra  * This function handles the architcture specific differences between arm and
11113230d95cSAtish Patra  * arm64 regarding where the kernel image must be loaded and any memory that
11123230d95cSAtish Patra  * must be reserved. On failure it is required to free all
11133230d95cSAtish Patra  * all allocations it has made.
11143230d95cSAtish Patra  */
11153230d95cSAtish Patra efi_status_t handle_kernel_image(unsigned long *image_addr,
11163230d95cSAtish Patra 				 unsigned long *image_size,
11173230d95cSAtish Patra 				 unsigned long *reserve_addr,
11183230d95cSAtish Patra 				 unsigned long *reserve_size,
1119416a9f84SArd Biesheuvel 				 efi_loaded_image_t *image,
1120416a9f84SArd Biesheuvel 				 efi_handle_t image_handle);
11213230d95cSAtish Patra 
112242c8ea3dSArd Biesheuvel /* shared entrypoint between the normal stub and the zboot stub */
112342c8ea3dSArd Biesheuvel efi_status_t efi_stub_common(efi_handle_t handle,
112442c8ea3dSArd Biesheuvel 			     efi_loaded_image_t *image,
112542c8ea3dSArd Biesheuvel 			     unsigned long image_addr,
112642c8ea3dSArd Biesheuvel 			     char *cmdline_ptr);
112742c8ea3dSArd Biesheuvel 
112842c8ea3dSArd Biesheuvel efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr);
112942c8ea3dSArd Biesheuvel 
11303230d95cSAtish Patra asmlinkage void __noreturn efi_enter_kernel(unsigned long entrypoint,
11313230d95cSAtish Patra 					    unsigned long fdt_addr,
11323230d95cSAtish Patra 					    unsigned long fdt_size);
1133ec93fc37SArd Biesheuvel 
11342a55280aSArd Biesheuvel void efi_handle_post_ebs_state(void);
11352a55280aSArd Biesheuvel 
1136e1ac4b24SChester Lin enum efi_secureboot_mode efi_get_secureboot(void);
1137e1ac4b24SChester Lin 
11383820749dSArd Biesheuvel #ifdef CONFIG_RESET_ATTACK_MITIGATION
11393820749dSArd Biesheuvel void efi_enable_reset_attack_mitigation(void);
11403820749dSArd Biesheuvel #else
11413820749dSArd Biesheuvel static inline void
11423820749dSArd Biesheuvel efi_enable_reset_attack_mitigation(void) { }
11433820749dSArd Biesheuvel #endif
11443820749dSArd Biesheuvel 
1145d228814bSKuppuswamy Sathyanarayanan void efi_retrieve_eventlog(void);
11463820749dSArd Biesheuvel 
1147732ea9dbSArd Biesheuvel struct screen_info *alloc_screen_info(void);
1148fc3608aaSArd Biesheuvel struct screen_info *__alloc_screen_info(void);
1149732ea9dbSArd Biesheuvel void free_screen_info(struct screen_info *si);
1150732ea9dbSArd Biesheuvel 
1151d9ffe524SArd Biesheuvel void efi_cache_sync_image(unsigned long image_base,
1152026b8579SArd Biesheuvel 			  unsigned long alloc_size);
1153d9ffe524SArd Biesheuvel 
1154550b33cfSArd Biesheuvel struct efi_smbios_record {
1155550b33cfSArd Biesheuvel 	u8	type;
1156550b33cfSArd Biesheuvel 	u8	length;
1157550b33cfSArd Biesheuvel 	u16	handle;
1158550b33cfSArd Biesheuvel };
1159550b33cfSArd Biesheuvel 
1160eb684408SArd Biesheuvel const struct efi_smbios_record *efi_get_smbios_record(u8 type);
1161eb684408SArd Biesheuvel 
1162550b33cfSArd Biesheuvel struct efi_smbios_type1_record {
1163550b33cfSArd Biesheuvel 	struct efi_smbios_record	header;
1164550b33cfSArd Biesheuvel 
1165550b33cfSArd Biesheuvel 	u8				manufacturer;
1166550b33cfSArd Biesheuvel 	u8				product_name;
1167550b33cfSArd Biesheuvel 	u8				version;
1168550b33cfSArd Biesheuvel 	u8				serial_number;
1169550b33cfSArd Biesheuvel 	efi_guid_t			uuid;
1170550b33cfSArd Biesheuvel 	u8				wakeup_type;
1171550b33cfSArd Biesheuvel 	u8				sku_number;
1172550b33cfSArd Biesheuvel 	u8				family;
1173550b33cfSArd Biesheuvel };
1174550b33cfSArd Biesheuvel 
1175eb684408SArd Biesheuvel struct efi_smbios_type4_record {
1176eb684408SArd Biesheuvel 	struct efi_smbios_record	header;
1177eb684408SArd Biesheuvel 
1178eb684408SArd Biesheuvel 	u8				socket;
1179eb684408SArd Biesheuvel 	u8				processor_type;
1180eb684408SArd Biesheuvel 	u8				processor_family;
1181eb684408SArd Biesheuvel 	u8				processor_manufacturer;
1182eb684408SArd Biesheuvel 	u8				processor_id[8];
1183eb684408SArd Biesheuvel 	u8				processor_version;
1184eb684408SArd Biesheuvel 	u8				voltage;
1185eb684408SArd Biesheuvel 	u16				external_clock;
1186eb684408SArd Biesheuvel 	u16				max_speed;
1187eb684408SArd Biesheuvel 	u16				current_speed;
1188eb684408SArd Biesheuvel 	u8				status;
1189eb684408SArd Biesheuvel 	u8				processor_upgrade;
1190eb684408SArd Biesheuvel 	u16				l1_cache_handle;
1191eb684408SArd Biesheuvel 	u16				l2_cache_handle;
1192eb684408SArd Biesheuvel 	u16				l3_cache_handle;
1193eb684408SArd Biesheuvel 	u8				serial_number;
1194eb684408SArd Biesheuvel 	u8				asset_tag;
1195eb684408SArd Biesheuvel 	u8				part_number;
1196eb684408SArd Biesheuvel 	u8				core_count;
1197eb684408SArd Biesheuvel 	u8				enabled_core_count;
1198eb684408SArd Biesheuvel 	u8				thread_count;
1199eb684408SArd Biesheuvel 	u16				processor_characteristics;
1200eb684408SArd Biesheuvel 	u16				processor_family2;
1201eb684408SArd Biesheuvel 	u16				core_count2;
1202eb684408SArd Biesheuvel 	u16				enabled_core_count2;
1203eb684408SArd Biesheuvel 	u16				thread_count2;
1204eb684408SArd Biesheuvel 	u16				thread_enabled;
1205eb684408SArd Biesheuvel };
1206eb684408SArd Biesheuvel 
12070dad9ee3SArd Biesheuvel #define efi_get_smbios_string(__record, __field) ({			\
12080dad9ee3SArd Biesheuvel 	__typeof__(__record) __rec = __record;				\
12090dad9ee3SArd Biesheuvel 	__efi_get_smbios_string(&__rec->header, &__rec->__field);	\
1210550b33cfSArd Biesheuvel })
1211550b33cfSArd Biesheuvel 
1212eb684408SArd Biesheuvel const u8 *__efi_get_smbios_string(const struct efi_smbios_record *record,
12130dad9ee3SArd Biesheuvel 				  const u8 *offset);
1214550b33cfSArd Biesheuvel 
1215ace013a5SArd Biesheuvel void efi_remap_image(unsigned long image_base, unsigned alloc_size,
1216ace013a5SArd Biesheuvel 		     unsigned long code_size);
12176b56beb5SAlexandre Ghiti efi_status_t efi_kaslr_relocate_kernel(unsigned long *image_addr,
12186b56beb5SAlexandre Ghiti 				       unsigned long *reserve_addr,
12196b56beb5SAlexandre Ghiti 				       unsigned long *reserve_size,
12206b56beb5SAlexandre Ghiti 				       unsigned long kernel_size,
12216b56beb5SAlexandre Ghiti 				       unsigned long kernel_codesize,
12226b56beb5SAlexandre Ghiti 				       unsigned long kernel_memsize,
12236b56beb5SAlexandre Ghiti 				       u32 phys_seed);
12246b56beb5SAlexandre Ghiti u32 efi_kaslr_get_phys_seed(efi_handle_t image_handle);
1225ace013a5SArd Biesheuvel 
1226fd936fd8SArnd Bergmann asmlinkage efi_status_t __efiapi
1227fd936fd8SArnd Bergmann efi_zboot_entry(efi_handle_t handle, efi_system_table_t *systab);
1228fd936fd8SArnd Bergmann 
1229745e3ed8SKirill A. Shutemov efi_status_t allocate_unaccepted_bitmap(__u32 nr_desc,
1230745e3ed8SKirill A. Shutemov 					struct efi_boot_memmap *map);
1231745e3ed8SKirill A. Shutemov void process_unaccepted_memory(u64 start, u64 end);
12325adfeaecSKirill A. Shutemov void accept_memory(phys_addr_t start, unsigned long size);
1233745e3ed8SKirill A. Shutemov void arch_accept_memory(phys_addr_t start, phys_addr_t end);
1234745e3ed8SKirill A. Shutemov 
1235bd669475SArd Biesheuvel #endif
1236