xref: /openbmc/linux/include/linux/efi.h (revision cd33a5c1d53e43bef1683c70dc3b68b6d9e8eca6)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef _LINUX_EFI_H
31da177e4SLinus Torvalds #define _LINUX_EFI_H
41da177e4SLinus Torvalds 
51da177e4SLinus Torvalds /*
61da177e4SLinus Torvalds  * Extensible Firmware Interface
71da177e4SLinus Torvalds  * Based on 'Extensible Firmware Interface Specification' version 0.9, April 30, 1999
81da177e4SLinus Torvalds  *
91da177e4SLinus Torvalds  * Copyright (C) 1999 VA Linux Systems
101da177e4SLinus Torvalds  * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
111da177e4SLinus Torvalds  * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
121da177e4SLinus Torvalds  *	David Mosberger-Tang <davidm@hpl.hp.com>
131da177e4SLinus Torvalds  *	Stephane Eranian <eranian@hpl.hp.com>
141da177e4SLinus Torvalds  */
151da177e4SLinus Torvalds #include <linux/init.h>
161da177e4SLinus Torvalds #include <linux/string.h>
171da177e4SLinus Torvalds #include <linux/time.h>
181da177e4SLinus Torvalds #include <linux/types.h>
191da177e4SLinus Torvalds #include <linux/proc_fs.h>
201da177e4SLinus Torvalds #include <linux/rtc.h>
211da177e4SLinus Torvalds #include <linux/ioport.h>
224a3575fdSHuang, Ying #include <linux/pfn.h>
235ee9c198SMatthew Garrett #include <linux/pstore.h>
2460863c0dSMatt Fleming #include <linux/range.h>
258562c99cSMatt Fleming #include <linux/reboot.h>
26ba7e34b1SAndy Shevchenko #include <linux/uuid.h>
272c23b73cSArd Biesheuvel #include <linux/screen_info.h>
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #include <asm/page.h>
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds #define EFI_SUCCESS		0
321da177e4SLinus Torvalds #define EFI_LOAD_ERROR          ( 1 | (1UL << (BITS_PER_LONG-1)))
331da177e4SLinus Torvalds #define EFI_INVALID_PARAMETER	( 2 | (1UL << (BITS_PER_LONG-1)))
341da177e4SLinus Torvalds #define EFI_UNSUPPORTED		( 3 | (1UL << (BITS_PER_LONG-1)))
351da177e4SLinus Torvalds #define EFI_BAD_BUFFER_SIZE     ( 4 | (1UL << (BITS_PER_LONG-1)))
361da177e4SLinus Torvalds #define EFI_BUFFER_TOO_SMALL	( 5 | (1UL << (BITS_PER_LONG-1)))
375d9db883SMatthew Garrett #define EFI_NOT_READY		( 6 | (1UL << (BITS_PER_LONG-1)))
385d9db883SMatthew Garrett #define EFI_DEVICE_ERROR	( 7 | (1UL << (BITS_PER_LONG-1)))
395d9db883SMatthew Garrett #define EFI_WRITE_PROTECTED	( 8 | (1UL << (BITS_PER_LONG-1)))
405d9db883SMatthew Garrett #define EFI_OUT_OF_RESOURCES	( 9 | (1UL << (BITS_PER_LONG-1)))
411da177e4SLinus Torvalds #define EFI_NOT_FOUND		(14 | (1UL << (BITS_PER_LONG-1)))
42dce48e35SArd Biesheuvel #define EFI_ABORTED		(21 | (1UL << (BITS_PER_LONG-1)))
435d9db883SMatthew Garrett #define EFI_SECURITY_VIOLATION	(26 | (1UL << (BITS_PER_LONG-1)))
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds typedef unsigned long efi_status_t;
461da177e4SLinus Torvalds typedef u8 efi_bool_t;
471da177e4SLinus Torvalds typedef u16 efi_char16_t;		/* UNICODE character */
48ed37ddffSRoy Franz typedef u64 efi_physical_addr_t;
49ed37ddffSRoy Franz typedef void *efi_handle_t;
501da177e4SLinus Torvalds 
518f24f8c2SArd Biesheuvel #ifdef CONFIG_X86_64
528f24f8c2SArd Biesheuvel #define __efiapi __attribute__((ms_abi))
538f24f8c2SArd Biesheuvel #else
548f24f8c2SArd Biesheuvel #define __efiapi
558f24f8c2SArd Biesheuvel #endif
568f24f8c2SArd Biesheuvel 
572732ea0dSArd Biesheuvel #define efi_get_handle_at(array, idx)					\
58f958efe9SArd Biesheuvel 	(efi_is_native() ? (array)[idx] 				\
592732ea0dSArd Biesheuvel 		: (efi_handle_t)(unsigned long)((u32 *)(array))[idx])
602732ea0dSArd Biesheuvel 
612732ea0dSArd Biesheuvel #define efi_get_handle_num(size)					\
62f958efe9SArd Biesheuvel 	((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32)))
632732ea0dSArd Biesheuvel 
642732ea0dSArd Biesheuvel #define for_each_efi_handle(handle, array, size, i)			\
652732ea0dSArd Biesheuvel 	for (i = 0;							\
662732ea0dSArd Biesheuvel 	     i < efi_get_handle_num(size) &&				\
672732ea0dSArd Biesheuvel 		((handle = efi_get_handle_at((array), i)) || true);	\
682732ea0dSArd Biesheuvel 	     i++)
692732ea0dSArd Biesheuvel 
70494c704fSArd Biesheuvel /*
71494c704fSArd Biesheuvel  * The UEFI spec and EDK2 reference implementation both define EFI_GUID as
72494c704fSArd Biesheuvel  * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment
73494c704fSArd Biesheuvel  * is 32 bits not 8 bits like our guid_t. In some cases (i.e., on 32-bit ARM),
74494c704fSArd Biesheuvel  * this means that firmware services invoked by the kernel may assume that
75494c704fSArd Biesheuvel  * efi_guid_t* arguments are 32-bit aligned, and use memory accessors that
76494c704fSArd Biesheuvel  * do not tolerate misalignment. So let's set the minimum alignment to 32 bits.
77494c704fSArd Biesheuvel  *
78494c704fSArd Biesheuvel  * Note that the UEFI spec as well as some comments in the EDK2 code base
79494c704fSArd Biesheuvel  * suggest that EFI_GUID should be 64-bit aligned, but this appears to be
80494c704fSArd Biesheuvel  * a mistake, given that no code seems to exist that actually enforces that
81494c704fSArd Biesheuvel  * or relies on it.
82494c704fSArd Biesheuvel  */
83494c704fSArd Biesheuvel typedef guid_t efi_guid_t __aligned(__alignof__(u32));
841da177e4SLinus Torvalds 
851da177e4SLinus Torvalds #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
86c0020756SAndy Shevchenko 	GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
871da177e4SLinus Torvalds 
881da177e4SLinus Torvalds /*
891da177e4SLinus Torvalds  * Generic EFI table header
901da177e4SLinus Torvalds  */
911da177e4SLinus Torvalds typedef	struct {
921da177e4SLinus Torvalds 	u64 signature;
931da177e4SLinus Torvalds 	u32 revision;
941da177e4SLinus Torvalds 	u32 headersize;
951da177e4SLinus Torvalds 	u32 crc32;
961da177e4SLinus Torvalds 	u32 reserved;
971da177e4SLinus Torvalds } efi_table_hdr_t;
981da177e4SLinus Torvalds 
991da177e4SLinus Torvalds /*
1001da177e4SLinus Torvalds  * Memory map descriptor:
1011da177e4SLinus Torvalds  */
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds /* Memory types: */
1041da177e4SLinus Torvalds #define EFI_RESERVED_TYPE		 0
1051da177e4SLinus Torvalds #define EFI_LOADER_CODE			 1
1061da177e4SLinus Torvalds #define EFI_LOADER_DATA			 2
1071da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_CODE		 3
1081da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_DATA		 4
1091da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_CODE	 5
1101da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_DATA	 6
1111da177e4SLinus Torvalds #define EFI_CONVENTIONAL_MEMORY		 7
1121da177e4SLinus Torvalds #define EFI_UNUSABLE_MEMORY		 8
1131da177e4SLinus Torvalds #define EFI_ACPI_RECLAIM_MEMORY		 9
1141da177e4SLinus Torvalds #define EFI_ACPI_MEMORY_NVS		10
1151da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO		11
1161da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO_PORT_SPACE	12
1171da177e4SLinus Torvalds #define EFI_PAL_CODE			13
118ad5fb870SDan Williams #define EFI_PERSISTENT_MEMORY		14
119ad5fb870SDan Williams #define EFI_MAX_MEMORY_TYPE		15
1201da177e4SLinus Torvalds 
1211da177e4SLinus Torvalds /* Attribute values: */
1221da177e4SLinus Torvalds #define EFI_MEMORY_UC		((u64)0x0000000000000001ULL)	/* uncached */
1231da177e4SLinus Torvalds #define EFI_MEMORY_WC		((u64)0x0000000000000002ULL)	/* write-coalescing */
1241da177e4SLinus Torvalds #define EFI_MEMORY_WT		((u64)0x0000000000000004ULL)	/* write-through */
1251da177e4SLinus Torvalds #define EFI_MEMORY_WB		((u64)0x0000000000000008ULL)	/* write-back */
1269c97e0bdSLaszlo Ersek #define EFI_MEMORY_UCE		((u64)0x0000000000000010ULL)	/* uncached, exported */
1271da177e4SLinus Torvalds #define EFI_MEMORY_WP		((u64)0x0000000000001000ULL)	/* write-protect */
1281da177e4SLinus Torvalds #define EFI_MEMORY_RP		((u64)0x0000000000002000ULL)	/* read-protect */
1291da177e4SLinus Torvalds #define EFI_MEMORY_XP		((u64)0x0000000000004000ULL)	/* execute-protect */
130c016ca08SRobert Elliott #define EFI_MEMORY_NV		((u64)0x0000000000008000ULL)	/* non-volatile */
131b05b9f5fSTony Luck #define EFI_MEMORY_MORE_RELIABLE \
132b05b9f5fSTony Luck 				((u64)0x0000000000010000ULL)	/* higher reliability */
13387db73aeSArd Biesheuvel #define EFI_MEMORY_RO		((u64)0x0000000000020000ULL)	/* read-only */
134fe3e5e65SDan Williams #define EFI_MEMORY_SP		((u64)0x0000000000040000ULL)	/* soft reserved */
1351da177e4SLinus Torvalds #define EFI_MEMORY_RUNTIME	((u64)0x8000000000000000ULL)	/* range requires runtime mapping */
1361da177e4SLinus Torvalds #define EFI_MEMORY_DESCRIPTOR_VERSION	1
1371da177e4SLinus Torvalds 
1381da177e4SLinus Torvalds #define EFI_PAGE_SHIFT		12
139ed37ddffSRoy Franz #define EFI_PAGE_SIZE		(1UL << EFI_PAGE_SHIFT)
1400100a3e6SPeter Jones #define EFI_PAGES_MAX		(U64_MAX >> EFI_PAGE_SHIFT)
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds typedef struct {
1431da177e4SLinus Torvalds 	u32 type;
1441da177e4SLinus Torvalds 	u32 pad;
1451da177e4SLinus Torvalds 	u64 phys_addr;
1461da177e4SLinus Torvalds 	u64 virt_addr;
1471da177e4SLinus Torvalds 	u64 num_pages;
1481da177e4SLinus Torvalds 	u64 attribute;
1491da177e4SLinus Torvalds } efi_memory_desc_t;
1501da177e4SLinus Torvalds 
1513b370237SMatthew Garrett typedef struct {
1523b370237SMatthew Garrett 	efi_guid_t guid;
1533b370237SMatthew Garrett 	u32 headersize;
1543b370237SMatthew Garrett 	u32 flags;
1553b370237SMatthew Garrett 	u32 imagesize;
1563b370237SMatthew Garrett } efi_capsule_header_t;
1573b370237SMatthew Garrett 
158dadb57abSJeffrey Hugo struct efi_boot_memmap {
159dadb57abSJeffrey Hugo 	efi_memory_desc_t	**map;
160dadb57abSJeffrey Hugo 	unsigned long		*map_size;
161dadb57abSJeffrey Hugo 	unsigned long		*desc_size;
162dadb57abSJeffrey Hugo 	u32			*desc_ver;
163dadb57abSJeffrey Hugo 	unsigned long		*key_ptr;
164dadb57abSJeffrey Hugo 	unsigned long		*buff_size;
165dadb57abSJeffrey Hugo };
166dadb57abSJeffrey Hugo 
167bb05e4baSMatt Fleming /*
168f0133f3cSMatt Fleming  * EFI capsule flags
169f0133f3cSMatt Fleming  */
170f0133f3cSMatt Fleming #define EFI_CAPSULE_PERSIST_ACROSS_RESET	0x00010000
171f0133f3cSMatt Fleming #define EFI_CAPSULE_POPULATE_SYSTEM_TABLE	0x00020000
172f0133f3cSMatt Fleming #define EFI_CAPSULE_INITIATE_RESET		0x00040000
173f0133f3cSMatt Fleming 
1743fabd628SArd Biesheuvel struct capsule_info {
1753fabd628SArd Biesheuvel 	efi_capsule_header_t	header;
176f24c4d47SArd Biesheuvel 	efi_capsule_header_t	*capsule;
1773fabd628SArd Biesheuvel 	int			reset_type;
1783fabd628SArd Biesheuvel 	long			index;
1793fabd628SArd Biesheuvel 	size_t			count;
1803fabd628SArd Biesheuvel 	size_t			total_size;
181f24c4d47SArd Biesheuvel 	struct page		**pages;
182f24c4d47SArd Biesheuvel 	phys_addr_t		*phys;
1833fabd628SArd Biesheuvel 	size_t			page_bytes_remain;
1843fabd628SArd Biesheuvel };
1853fabd628SArd Biesheuvel 
1863fabd628SArd Biesheuvel int __efi_capsule_setup_info(struct capsule_info *cap_info);
1873fabd628SArd Biesheuvel 
188f0133f3cSMatt Fleming /*
189bb05e4baSMatt Fleming  * Allocation types for calls to boottime->allocate_pages.
190bb05e4baSMatt Fleming  */
191bb05e4baSMatt Fleming #define EFI_ALLOCATE_ANY_PAGES		0
192bb05e4baSMatt Fleming #define EFI_ALLOCATE_MAX_ADDRESS	1
193bb05e4baSMatt Fleming #define EFI_ALLOCATE_ADDRESS		2
194bb05e4baSMatt Fleming #define EFI_MAX_ALLOCATE_TYPE		3
195bb05e4baSMatt Fleming 
196e088a4adSMatthew Wilcox typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds /*
1991da177e4SLinus Torvalds  * Types and defines for Time Services
2001da177e4SLinus Torvalds  */
2011da177e4SLinus Torvalds #define EFI_TIME_ADJUST_DAYLIGHT 0x1
2021da177e4SLinus Torvalds #define EFI_TIME_IN_DAYLIGHT     0x2
2031da177e4SLinus Torvalds #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
2041da177e4SLinus Torvalds 
2051da177e4SLinus Torvalds typedef struct {
2061da177e4SLinus Torvalds 	u16 year;
2071da177e4SLinus Torvalds 	u8 month;
2081da177e4SLinus Torvalds 	u8 day;
2091da177e4SLinus Torvalds 	u8 hour;
2101da177e4SLinus Torvalds 	u8 minute;
2111da177e4SLinus Torvalds 	u8 second;
2121da177e4SLinus Torvalds 	u8 pad1;
2131da177e4SLinus Torvalds 	u32 nanosecond;
2141da177e4SLinus Torvalds 	s16 timezone;
2151da177e4SLinus Torvalds 	u8 daylight;
2161da177e4SLinus Torvalds 	u8 pad2;
2171da177e4SLinus Torvalds } efi_time_t;
2181da177e4SLinus Torvalds 
2191da177e4SLinus Torvalds typedef struct {
2201da177e4SLinus Torvalds 	u32 resolution;
2211da177e4SLinus Torvalds 	u32 accuracy;
2221da177e4SLinus Torvalds 	u8 sets_to_zero;
2231da177e4SLinus Torvalds } efi_time_cap_t;
2241da177e4SLinus Torvalds 
225677703ceSMatt Fleming typedef struct {
226677703ceSMatt Fleming 	efi_table_hdr_t hdr;
227677703ceSMatt Fleming 	u32 raise_tpl;
228677703ceSMatt Fleming 	u32 restore_tpl;
229677703ceSMatt Fleming 	u32 allocate_pages;
230677703ceSMatt Fleming 	u32 free_pages;
231677703ceSMatt Fleming 	u32 get_memory_map;
232677703ceSMatt Fleming 	u32 allocate_pool;
233677703ceSMatt Fleming 	u32 free_pool;
234677703ceSMatt Fleming 	u32 create_event;
235677703ceSMatt Fleming 	u32 set_timer;
236677703ceSMatt Fleming 	u32 wait_for_event;
237677703ceSMatt Fleming 	u32 signal_event;
238677703ceSMatt Fleming 	u32 close_event;
239677703ceSMatt Fleming 	u32 check_event;
240677703ceSMatt Fleming 	u32 install_protocol_interface;
241677703ceSMatt Fleming 	u32 reinstall_protocol_interface;
242677703ceSMatt Fleming 	u32 uninstall_protocol_interface;
243677703ceSMatt Fleming 	u32 handle_protocol;
244677703ceSMatt Fleming 	u32 __reserved;
245677703ceSMatt Fleming 	u32 register_protocol_notify;
246677703ceSMatt Fleming 	u32 locate_handle;
247677703ceSMatt Fleming 	u32 locate_device_path;
248677703ceSMatt Fleming 	u32 install_configuration_table;
249677703ceSMatt Fleming 	u32 load_image;
250677703ceSMatt Fleming 	u32 start_image;
251677703ceSMatt Fleming 	u32 exit;
252677703ceSMatt Fleming 	u32 unload_image;
253677703ceSMatt Fleming 	u32 exit_boot_services;
254677703ceSMatt Fleming 	u32 get_next_monotonic_count;
255677703ceSMatt Fleming 	u32 stall;
256677703ceSMatt Fleming 	u32 set_watchdog_timer;
257677703ceSMatt Fleming 	u32 connect_controller;
258677703ceSMatt Fleming 	u32 disconnect_controller;
259677703ceSMatt Fleming 	u32 open_protocol;
260677703ceSMatt Fleming 	u32 close_protocol;
261677703ceSMatt Fleming 	u32 open_protocol_information;
262677703ceSMatt Fleming 	u32 protocols_per_handle;
263677703ceSMatt Fleming 	u32 locate_handle_buffer;
264677703ceSMatt Fleming 	u32 locate_protocol;
265677703ceSMatt Fleming 	u32 install_multiple_protocol_interfaces;
266677703ceSMatt Fleming 	u32 uninstall_multiple_protocol_interfaces;
267677703ceSMatt Fleming 	u32 calculate_crc32;
268677703ceSMatt Fleming 	u32 copy_mem;
269677703ceSMatt Fleming 	u32 set_mem;
270677703ceSMatt Fleming 	u32 create_event_ex;
271677703ceSMatt Fleming } __packed efi_boot_services_32_t;
272677703ceSMatt Fleming 
2731da177e4SLinus Torvalds /*
274f30ca6baSMatt Fleming  * EFI Boot Services table
275f30ca6baSMatt Fleming  */
2761786e830SArd Biesheuvel typedef union {
2771786e830SArd Biesheuvel 	struct {
278f30ca6baSMatt Fleming 		efi_table_hdr_t hdr;
279f30ca6baSMatt Fleming 		void *raise_tpl;
280f30ca6baSMatt Fleming 		void *restore_tpl;
2818f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,
282ed37ddffSRoy Franz 							efi_physical_addr_t *);
2838f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,
2848f24f8c2SArd Biesheuvel 						    unsigned long);
2858f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,
2868f24f8c2SArd Biesheuvel 							unsigned long *,
287ed37ddffSRoy Franz 							unsigned long *, u32 *);
2888f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *allocate_pool)(int, unsigned long,
2898f24f8c2SArd Biesheuvel 						       void **);
2908f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *free_pool)(void *);
291f30ca6baSMatt Fleming 		void *create_event;
292f30ca6baSMatt Fleming 		void *set_timer;
293f30ca6baSMatt Fleming 		void *wait_for_event;
294f30ca6baSMatt Fleming 		void *signal_event;
295f30ca6baSMatt Fleming 		void *close_event;
296f30ca6baSMatt Fleming 		void *check_event;
297f30ca6baSMatt Fleming 		void *install_protocol_interface;
298f30ca6baSMatt Fleming 		void *reinstall_protocol_interface;
299f30ca6baSMatt Fleming 		void *uninstall_protocol_interface;
3008f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *handle_protocol)(efi_handle_t,
3018f24f8c2SArd Biesheuvel 							 efi_guid_t *, void **);
302f30ca6baSMatt Fleming 		void *__reserved;
303f30ca6baSMatt Fleming 		void *register_protocol_notify;
3048f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,
3058f24f8c2SArd Biesheuvel 						       void *, unsigned long *,
3068f24f8c2SArd Biesheuvel 						       efi_handle_t *);
307f30ca6baSMatt Fleming 		void *locate_device_path;
3088f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,
3098f24f8c2SArd Biesheuvel 								     void *);
310f30ca6baSMatt Fleming 		void *load_image;
311f30ca6baSMatt Fleming 		void *start_image;
312f30ca6baSMatt Fleming 		void *exit;
313f30ca6baSMatt Fleming 		void *unload_image;
3148f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,
3158f24f8c2SArd Biesheuvel 							    unsigned long);
316f30ca6baSMatt Fleming 		void *get_next_monotonic_count;
317f30ca6baSMatt Fleming 		void *stall;
318f30ca6baSMatt Fleming 		void *set_watchdog_timer;
319f30ca6baSMatt Fleming 		void *connect_controller;
320f30ca6baSMatt Fleming 		void *disconnect_controller;
321f30ca6baSMatt Fleming 		void *open_protocol;
322f30ca6baSMatt Fleming 		void *close_protocol;
323f30ca6baSMatt Fleming 		void *open_protocol_information;
324f30ca6baSMatt Fleming 		void *protocols_per_handle;
325f30ca6baSMatt Fleming 		void *locate_handle_buffer;
3268f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,
3278f24f8c2SArd Biesheuvel 							 void **);
328f30ca6baSMatt Fleming 		void *install_multiple_protocol_interfaces;
329f30ca6baSMatt Fleming 		void *uninstall_multiple_protocol_interfaces;
330f30ca6baSMatt Fleming 		void *calculate_crc32;
331f30ca6baSMatt Fleming 		void *copy_mem;
332f30ca6baSMatt Fleming 		void *set_mem;
333f30ca6baSMatt Fleming 		void *create_event_ex;
3341786e830SArd Biesheuvel 	};
3351786e830SArd Biesheuvel 	efi_boot_services_32_t mixed_mode;
336f30ca6baSMatt Fleming } efi_boot_services_t;
337f30ca6baSMatt Fleming 
338dd5fc854SMatthew Garrett typedef enum {
339dd5fc854SMatthew Garrett 	EfiPciIoWidthUint8,
340dd5fc854SMatthew Garrett 	EfiPciIoWidthUint16,
341dd5fc854SMatthew Garrett 	EfiPciIoWidthUint32,
342dd5fc854SMatthew Garrett 	EfiPciIoWidthUint64,
343dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint8,
344dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint16,
345dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint32,
346dd5fc854SMatthew Garrett 	EfiPciIoWidthFifoUint64,
347dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint8,
348dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint16,
349dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint32,
350dd5fc854SMatthew Garrett 	EfiPciIoWidthFillUint64,
351dd5fc854SMatthew Garrett 	EfiPciIoWidthMaximum
352dd5fc854SMatthew Garrett } EFI_PCI_IO_PROTOCOL_WIDTH;
353dd5fc854SMatthew Garrett 
354dd5fc854SMatthew Garrett typedef enum {
355dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationGet,
356dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationSet,
357dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationEnable,
358dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationDisable,
359dd5fc854SMatthew Garrett 	EfiPciIoAttributeOperationSupported,
360dd5fc854SMatthew Garrett     EfiPciIoAttributeOperationMaximum
361dd5fc854SMatthew Garrett } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION;
362dd5fc854SMatthew Garrett 
363677703ceSMatt Fleming typedef struct {
364677703ceSMatt Fleming 	u32 read;
365677703ceSMatt Fleming 	u32 write;
366677703ceSMatt Fleming } efi_pci_io_protocol_access_32_t;
367677703ceSMatt Fleming 
3681786e830SArd Biesheuvel typedef union efi_pci_io_protocol efi_pci_io_protocol_t;
3691786e830SArd Biesheuvel 
3701786e830SArd Biesheuvel typedef
3718f24f8c2SArd Biesheuvel efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
3721786e830SArd Biesheuvel 						   EFI_PCI_IO_PROTOCOL_WIDTH,
3738f24f8c2SArd Biesheuvel 						   u32 offset,
3748f24f8c2SArd Biesheuvel 						   unsigned long count,
3751786e830SArd Biesheuvel 						   void *buffer);
3761786e830SArd Biesheuvel 
377dd5fc854SMatthew Garrett typedef struct {
378dd5fc854SMatthew Garrett 	void *read;
379dd5fc854SMatthew Garrett 	void *write;
380dd5fc854SMatthew Garrett } efi_pci_io_protocol_access_t;
381dd5fc854SMatthew Garrett 
382dd5fc854SMatthew Garrett typedef struct {
3831786e830SArd Biesheuvel 	efi_pci_io_protocol_cfg_t read;
3841786e830SArd Biesheuvel 	efi_pci_io_protocol_cfg_t write;
3851786e830SArd Biesheuvel } efi_pci_io_protocol_config_access_t;
3861786e830SArd Biesheuvel 
3871786e830SArd Biesheuvel union efi_pci_io_protocol {
3881786e830SArd Biesheuvel 	struct {
389dd5fc854SMatthew Garrett 		void *poll_mem;
390dd5fc854SMatthew Garrett 		void *poll_io;
391dd5fc854SMatthew Garrett 		efi_pci_io_protocol_access_t mem;
392dd5fc854SMatthew Garrett 		efi_pci_io_protocol_access_t io;
3931786e830SArd Biesheuvel 		efi_pci_io_protocol_config_access_t pci;
394dd5fc854SMatthew Garrett 		void *copy_mem;
395dd5fc854SMatthew Garrett 		void *map;
396dd5fc854SMatthew Garrett 		void *unmap;
397dd5fc854SMatthew Garrett 		void *allocate_buffer;
398dd5fc854SMatthew Garrett 		void *free_buffer;
399dd5fc854SMatthew Garrett 		void *flush;
4008f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *get_location)(efi_pci_io_protocol_t *,
401960a8d01SArd Biesheuvel 						      unsigned long *segment_nr,
402960a8d01SArd Biesheuvel 						      unsigned long *bus_nr,
403960a8d01SArd Biesheuvel 						      unsigned long *device_nr,
4048f24f8c2SArd Biesheuvel 						      unsigned long *func_nr);
405dd5fc854SMatthew Garrett 		void *attributes;
406dd5fc854SMatthew Garrett 		void *get_bar_attributes;
407dd5fc854SMatthew Garrett 		void *set_bar_attributes;
408dd5fc854SMatthew Garrett 		uint64_t romsize;
409dd5fc854SMatthew Garrett 		void *romimage;
4101786e830SArd Biesheuvel 	};
4111786e830SArd Biesheuvel 	struct {
4121786e830SArd Biesheuvel 		u32 poll_mem;
4131786e830SArd Biesheuvel 		u32 poll_io;
4141786e830SArd Biesheuvel 		efi_pci_io_protocol_access_32_t mem;
4151786e830SArd Biesheuvel 		efi_pci_io_protocol_access_32_t io;
4161786e830SArd Biesheuvel 		efi_pci_io_protocol_access_32_t pci;
4171786e830SArd Biesheuvel 		u32 copy_mem;
4181786e830SArd Biesheuvel 		u32 map;
4191786e830SArd Biesheuvel 		u32 unmap;
4201786e830SArd Biesheuvel 		u32 allocate_buffer;
4211786e830SArd Biesheuvel 		u32 free_buffer;
4221786e830SArd Biesheuvel 		u32 flush;
4231786e830SArd Biesheuvel 		u32 get_location;
4241786e830SArd Biesheuvel 		u32 attributes;
4251786e830SArd Biesheuvel 		u32 get_bar_attributes;
4261786e830SArd Biesheuvel 		u32 set_bar_attributes;
4271786e830SArd Biesheuvel 		u64 romsize;
4281786e830SArd Biesheuvel 		u32 romimage;
4291786e830SArd Biesheuvel 	} mixed_mode;
4301786e830SArd Biesheuvel };
431dd5fc854SMatthew Garrett 
432dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO 0x0001
433dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_IO 0x0002
434dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO 0x0004
435dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY 0x0008
436dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_IO 0x0010
437dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO 0x0020
438dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO 0x0040
439dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_WRITE_COMBINE 0x0080
440dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_IO 0x0100
441dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY 0x0200
442dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_BUS_MASTER 0x0400
443dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_CACHED 0x0800
444dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_MEMORY_DISABLE 0x1000
445dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE 0x2000
446dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM 0x4000
447dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE 0x8000
448dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_ISA_IO_16 0x10000
449dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_PALETTE_IO_16 0x20000
450dd5fc854SMatthew Garrett #define EFI_PCI_IO_ATTRIBUTE_VGA_IO_16 0x40000
451dd5fc854SMatthew Garrett 
4521786e830SArd Biesheuvel struct efi_dev_path;
4531786e830SArd Biesheuvel 
4541786e830SArd Biesheuvel typedef union apple_properties_protocol apple_properties_protocol_t;
4551786e830SArd Biesheuvel 
4561786e830SArd Biesheuvel union apple_properties_protocol {
4571786e830SArd Biesheuvel 	struct {
4581786e830SArd Biesheuvel 		unsigned long version;
4598f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *get)(apple_properties_protocol_t *,
4608f24f8c2SArd Biesheuvel 					     struct efi_dev_path *,
4618f24f8c2SArd Biesheuvel 					     efi_char16_t *, void *, u32 *);
4628f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *set)(apple_properties_protocol_t *,
4638f24f8c2SArd Biesheuvel 					     struct efi_dev_path *,
4648f24f8c2SArd Biesheuvel 					     efi_char16_t *, void *, u32);
4658f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *del)(apple_properties_protocol_t *,
4668f24f8c2SArd Biesheuvel 					     struct efi_dev_path *,
4678f24f8c2SArd Biesheuvel 					     efi_char16_t *);
4688f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *get_all)(apple_properties_protocol_t *,
4691786e830SArd Biesheuvel 						 void *buffer, u32 *);
4701786e830SArd Biesheuvel 	};
4711786e830SArd Biesheuvel 	struct {
4721786e830SArd Biesheuvel 		u32 version;
4731786e830SArd Biesheuvel 		u32 get;
4741786e830SArd Biesheuvel 		u32 set;
4751786e830SArd Biesheuvel 		u32 del;
4761786e830SArd Biesheuvel 		u32 get_all;
4771786e830SArd Biesheuvel 	} mixed_mode;
4781786e830SArd Biesheuvel };
4791786e830SArd Biesheuvel 
48033b6d034SThiebaud Weksteen typedef u32 efi_tcg2_event_log_format;
48133b6d034SThiebaud Weksteen 
4821786e830SArd Biesheuvel typedef union efi_tcg2_protocol efi_tcg2_protocol_t;
4831786e830SArd Biesheuvel 
4841786e830SArd Biesheuvel union efi_tcg2_protocol {
4851786e830SArd Biesheuvel 	struct {
48633b6d034SThiebaud Weksteen 		void *get_capability;
4878f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *get_event_log)(efi_handle_t,
4881786e830SArd Biesheuvel 						       efi_tcg2_event_log_format,
4891786e830SArd Biesheuvel 						       efi_physical_addr_t *,
4901786e830SArd Biesheuvel 						       efi_physical_addr_t *,
4911786e830SArd Biesheuvel 						       efi_bool_t *);
49233b6d034SThiebaud Weksteen 		void *hash_log_extend_event;
49333b6d034SThiebaud Weksteen 		void *submit_command;
49433b6d034SThiebaud Weksteen 		void *get_active_pcr_banks;
49533b6d034SThiebaud Weksteen 		void *set_active_pcr_banks;
49633b6d034SThiebaud Weksteen 		void *get_result_of_set_active_pcr_banks;
4971786e830SArd Biesheuvel 	};
4981786e830SArd Biesheuvel 	struct {
4991786e830SArd Biesheuvel 		u32 get_capability;
5001786e830SArd Biesheuvel 		u32 get_event_log;
5011786e830SArd Biesheuvel 		u32 hash_log_extend_event;
5021786e830SArd Biesheuvel 		u32 submit_command;
5031786e830SArd Biesheuvel 		u32 get_active_pcr_banks;
5041786e830SArd Biesheuvel 		u32 set_active_pcr_banks;
5051786e830SArd Biesheuvel 		u32 get_result_of_set_active_pcr_banks;
5061786e830SArd Biesheuvel 	} mixed_mode;
5071786e830SArd Biesheuvel };
50833b6d034SThiebaud Weksteen 
509f30ca6baSMatt Fleming /*
5101da177e4SLinus Torvalds  * Types and defines for EFI ResetSystem
5111da177e4SLinus Torvalds  */
5121da177e4SLinus Torvalds #define EFI_RESET_COLD 0
5131da177e4SLinus Torvalds #define EFI_RESET_WARM 1
5141da177e4SLinus Torvalds #define EFI_RESET_SHUTDOWN 2
5151da177e4SLinus Torvalds 
5161da177e4SLinus Torvalds /*
5171da177e4SLinus Torvalds  * EFI Runtime Services table
5181da177e4SLinus Torvalds  */
5191da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
5201da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_REVISION  0x00010000
5211da177e4SLinus Torvalds 
5221da177e4SLinus Torvalds typedef struct {
5231da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
524677703ceSMatt Fleming 	u32 get_time;
525677703ceSMatt Fleming 	u32 set_time;
526677703ceSMatt Fleming 	u32 get_wakeup_time;
527677703ceSMatt Fleming 	u32 set_wakeup_time;
528677703ceSMatt Fleming 	u32 set_virtual_address_map;
529677703ceSMatt Fleming 	u32 convert_pointer;
530677703ceSMatt Fleming 	u32 get_variable;
531677703ceSMatt Fleming 	u32 get_next_variable;
532677703ceSMatt Fleming 	u32 set_variable;
533677703ceSMatt Fleming 	u32 get_next_high_mono_count;
534677703ceSMatt Fleming 	u32 reset_system;
535677703ceSMatt Fleming 	u32 update_capsule;
536677703ceSMatt Fleming 	u32 query_capsule_caps;
537677703ceSMatt Fleming 	u32 query_variable_info;
538677703ceSMatt Fleming } efi_runtime_services_32_t;
539677703ceSMatt Fleming 
540677703ceSMatt Fleming typedef struct {
541677703ceSMatt Fleming 	efi_table_hdr_t hdr;
542677703ceSMatt Fleming 	u64 get_time;
543677703ceSMatt Fleming 	u64 set_time;
544677703ceSMatt Fleming 	u64 get_wakeup_time;
545677703ceSMatt Fleming 	u64 set_wakeup_time;
546677703ceSMatt Fleming 	u64 set_virtual_address_map;
547677703ceSMatt Fleming 	u64 convert_pointer;
548677703ceSMatt Fleming 	u64 get_variable;
549677703ceSMatt Fleming 	u64 get_next_variable;
550677703ceSMatt Fleming 	u64 set_variable;
551677703ceSMatt Fleming 	u64 get_next_high_mono_count;
552677703ceSMatt Fleming 	u64 reset_system;
553677703ceSMatt Fleming 	u64 update_capsule;
554677703ceSMatt Fleming 	u64 query_capsule_caps;
555677703ceSMatt Fleming 	u64 query_variable_info;
556677703ceSMatt Fleming } efi_runtime_services_64_t;
557677703ceSMatt Fleming 
5581da177e4SLinus Torvalds typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
5591da177e4SLinus Torvalds typedef efi_status_t efi_set_time_t (efi_time_t *tm);
5601da177e4SLinus Torvalds typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
5611da177e4SLinus Torvalds 					    efi_time_t *tm);
5621da177e4SLinus Torvalds typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm);
5631da177e4SLinus Torvalds typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
5641da177e4SLinus Torvalds 					 unsigned long *data_size, void *data);
5651da177e4SLinus Torvalds typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
5661da177e4SLinus Torvalds 					      efi_guid_t *vendor);
5671da177e4SLinus Torvalds typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
568f7a2d73fSMatthew Garrett 					 u32 attr, unsigned long data_size,
5691da177e4SLinus Torvalds 					 void *data);
5701da177e4SLinus Torvalds typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
5711da177e4SLinus Torvalds typedef void efi_reset_system_t (int reset_type, efi_status_t status,
5721da177e4SLinus Torvalds 				 unsigned long data_size, efi_char16_t *data);
5731da177e4SLinus Torvalds typedef efi_status_t efi_set_virtual_address_map_t (unsigned long memory_map_size,
5741da177e4SLinus Torvalds 						unsigned long descriptor_size,
5751da177e4SLinus Torvalds 						u32 descriptor_version,
5761da177e4SLinus Torvalds 						efi_memory_desc_t *virtual_map);
5773b370237SMatthew Garrett typedef efi_status_t efi_query_variable_info_t(u32 attr,
5783b370237SMatthew Garrett 					       u64 *storage_space,
5793b370237SMatthew Garrett 					       u64 *remaining_space,
5803b370237SMatthew Garrett 					       u64 *max_variable_size);
5813b370237SMatthew Garrett typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
5823b370237SMatthew Garrett 					  unsigned long count,
5833b370237SMatthew Garrett 					  unsigned long sg_list);
5843b370237SMatthew Garrett typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
5853b370237SMatthew Garrett 					      unsigned long count,
5863b370237SMatthew Garrett 					      u64 *max_size,
5873b370237SMatthew Garrett 					      int *reset_type);
588ca0e30dcSArd Biesheuvel typedef efi_status_t efi_query_variable_store_t(u32 attributes,
589ca0e30dcSArd Biesheuvel 						unsigned long size,
590ca0e30dcSArd Biesheuvel 						bool nonblocking);
5911da177e4SLinus Torvalds 
5921786e830SArd Biesheuvel typedef union {
5931786e830SArd Biesheuvel 	struct {
594c4c39c70SArd Biesheuvel 		efi_table_hdr_t				hdr;
5958f24f8c2SArd Biesheuvel 		efi_get_time_t __efiapi			*get_time;
5968f24f8c2SArd Biesheuvel 		efi_set_time_t __efiapi			*set_time;
5978f24f8c2SArd Biesheuvel 		efi_get_wakeup_time_t __efiapi		*get_wakeup_time;
5988f24f8c2SArd Biesheuvel 		efi_set_wakeup_time_t __efiapi		*set_wakeup_time;
5998f24f8c2SArd Biesheuvel 		efi_set_virtual_address_map_t __efiapi	*set_virtual_address_map;
600c4c39c70SArd Biesheuvel 		void					*convert_pointer;
6018f24f8c2SArd Biesheuvel 		efi_get_variable_t __efiapi		*get_variable;
6028f24f8c2SArd Biesheuvel 		efi_get_next_variable_t __efiapi	*get_next_variable;
6038f24f8c2SArd Biesheuvel 		efi_set_variable_t __efiapi		*set_variable;
6048f24f8c2SArd Biesheuvel 		efi_get_next_high_mono_count_t __efiapi	*get_next_high_mono_count;
6058f24f8c2SArd Biesheuvel 		efi_reset_system_t __efiapi		*reset_system;
6068f24f8c2SArd Biesheuvel 		efi_update_capsule_t __efiapi		*update_capsule;
6078f24f8c2SArd Biesheuvel 		efi_query_capsule_caps_t __efiapi	*query_capsule_caps;
6088f24f8c2SArd Biesheuvel 		efi_query_variable_info_t __efiapi	*query_variable_info;
6091786e830SArd Biesheuvel 	};
6101786e830SArd Biesheuvel 	efi_runtime_services_32_t mixed_mode;
611c4c39c70SArd Biesheuvel } efi_runtime_services_t;
612c4c39c70SArd Biesheuvel 
613022ee6c5SArd Biesheuvel void efi_native_runtime_setup(void);
614022ee6c5SArd Biesheuvel 
6151da177e4SLinus Torvalds /*
6161da177e4SLinus Torvalds  * EFI Configuration Table and GUID definitions
61754fd11feSPeter Jones  *
6187fb2b43cSIngo Molnar  * These are all defined in a single line to make them easier to
6197fb2b43cSIngo Molnar  * grep for and to see them at a glance - while still having a
6207fb2b43cSIngo Molnar  * similar structure to the definitions in the spec.
6217fb2b43cSIngo Molnar  *
6227fb2b43cSIngo Molnar  * Here's how they are structured:
62354fd11feSPeter Jones  *
62454fd11feSPeter Jones  * GUID: 12345678-1234-1234-1234-123456789012
62554fd11feSPeter Jones  * Spec:
62654fd11feSPeter Jones  *      #define EFI_SOME_PROTOCOL_GUID \
62754fd11feSPeter Jones  *        {0x12345678,0x1234,0x1234,\
62854fd11feSPeter Jones  *          {0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x12}}
62954fd11feSPeter Jones  * Here:
6307fb2b43cSIngo Molnar  *	#define SOME_PROTOCOL_GUID		EFI_GUID(0x12345678, 0x1234, 0x1234,  0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12)
6317fb2b43cSIngo Molnar  *					^ tabs					    ^extra space
6327fb2b43cSIngo Molnar  *
6337fb2b43cSIngo Molnar  * Note that the 'extra space' separates the values at the same place
6347fb2b43cSIngo Molnar  * where the UEFI SPEC breaks the line.
6351da177e4SLinus Torvalds  */
6367fb2b43cSIngo Molnar #define NULL_GUID				EFI_GUID(0x00000000, 0x0000, 0x0000,  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
6377fb2b43cSIngo Molnar #define MPS_TABLE_GUID				EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
6387fb2b43cSIngo Molnar #define ACPI_TABLE_GUID				EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
6397fb2b43cSIngo Molnar #define ACPI_20_TABLE_GUID			EFI_GUID(0x8868e871, 0xe4f1, 0x11d3,  0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
6407fb2b43cSIngo Molnar #define SMBIOS_TABLE_GUID			EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
6417fb2b43cSIngo Molnar #define SMBIOS3_TABLE_GUID			EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c,  0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
6427fb2b43cSIngo Molnar #define SAL_SYSTEM_TABLE_GUID			EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
6437fb2b43cSIngo Molnar #define HCDP_TABLE_GUID				EFI_GUID(0xf951938d, 0x620b, 0x42ef,  0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98)
6447fb2b43cSIngo Molnar #define UGA_IO_PROTOCOL_GUID			EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b,  0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2)
6457fb2b43cSIngo Molnar #define EFI_GLOBAL_VARIABLE_GUID		EFI_GUID(0x8be4df61, 0x93ca, 0x11d2,  0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
6467fb2b43cSIngo Molnar #define UV_SYSTEM_TABLE_GUID			EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd,  0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93)
6477fb2b43cSIngo Molnar #define LINUX_EFI_CRASH_GUID			EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc,  0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0)
6487fb2b43cSIngo Molnar #define LOADED_IMAGE_PROTOCOL_GUID		EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2,  0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
6497fb2b43cSIngo Molnar #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID	EFI_GUID(0x9042a9de, 0x23dc, 0x4a38,  0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
6507fb2b43cSIngo Molnar #define EFI_UGA_PROTOCOL_GUID			EFI_GUID(0x982c298b, 0xf4fa, 0x41cb,  0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39)
6517fb2b43cSIngo Molnar #define EFI_PCI_IO_PROTOCOL_GUID		EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5,  0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a)
6527fb2b43cSIngo Molnar #define EFI_FILE_INFO_ID			EFI_GUID(0x09576e92, 0x6d3f, 0x11d2,  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
6537fb2b43cSIngo Molnar #define EFI_SYSTEM_RESOURCE_TABLE_GUID		EFI_GUID(0xb122a263, 0x3661, 0x4f68,  0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
6547fb2b43cSIngo Molnar #define EFI_FILE_SYSTEM_GUID			EFI_GUID(0x964e5b22, 0x6459, 0x11d2,  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
6557fb2b43cSIngo Molnar #define DEVICE_TREE_GUID			EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5,  0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
6567fb2b43cSIngo Molnar #define EFI_PROPERTIES_TABLE_GUID		EFI_GUID(0x880aaca3, 0x4adc, 0x4a04,  0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5)
6577fb2b43cSIngo Molnar #define EFI_RNG_PROTOCOL_GUID			EFI_GUID(0x3152bca5, 0xeade, 0x433d,  0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
658568bc4e8SArd Biesheuvel #define EFI_RNG_ALGORITHM_RAW			EFI_GUID(0xe43176d7, 0xb6e8, 0x4827,  0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)
6597fb2b43cSIngo Molnar #define EFI_MEMORY_ATTRIBUTES_TABLE_GUID	EFI_GUID(0xdcfa911d, 0x26eb, 0x469f,  0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
6607fb2b43cSIngo Molnar #define EFI_CONSOLE_OUT_DEVICE_GUID		EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4,  0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
66158c5475aSLukas Wunner #define APPLE_PROPERTIES_PROTOCOL_GUID		EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb,  0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0)
66233b6d034SThiebaud Weksteen #define EFI_TCG2_PROTOCOL_GUID			EFI_GUID(0x607f766c, 0x7455, 0x42be,  0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
663fc372064SArd Biesheuvel 
664e58910cdSJosh Boyer #define EFI_IMAGE_SECURITY_DATABASE_GUID	EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596,  0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)
665e58910cdSJosh Boyer #define EFI_SHIM_LOCK_GUID			EFI_GUID(0x605dab50, 0xe046, 0x4300,  0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
666e58910cdSJosh Boyer 
6675c126ba2SDave Howells #define EFI_CERT_SHA256_GUID			EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28)
6685c126ba2SDave Howells #define EFI_CERT_X509_GUID			EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72)
6695c126ba2SDave Howells #define EFI_CERT_X509_SHA256_GUID		EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed)
6705c126ba2SDave Howells 
671801820beSArd Biesheuvel /*
672801820beSArd Biesheuvel  * This GUID is used to pass to the kernel proper the struct screen_info
673801820beSArd Biesheuvel  * structure that was populated by the stub based on the GOP protocol instance
674801820beSArd Biesheuvel  * associated with ConOut
675801820beSArd Biesheuvel  */
6767fb2b43cSIngo Molnar #define LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID	EFI_GUID(0xe03fc20a, 0x85dc, 0x406e,  0xb9, 0x0e, 0x4a, 0xb5, 0x02, 0x37, 0x1d, 0x95)
6777fb2b43cSIngo Molnar #define LINUX_EFI_LOADER_ENTRY_GUID		EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf,  0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
67863625988SArd Biesheuvel #define LINUX_EFI_RANDOM_SEED_TABLE_GUID	EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2,  0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b)
67933b6d034SThiebaud Weksteen #define LINUX_EFI_TPM_EVENT_LOG_GUID		EFI_GUID(0xb7799cb0, 0xeca2, 0x4943,  0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa)
680c46f3405SMatthew Garrett #define LINUX_EFI_TPM_FINAL_LOG_GUID		EFI_GUID(0x1e2ed096, 0x30e2, 0x4254,  0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25)
68171e0940dSArd Biesheuvel #define LINUX_EFI_MEMRESERVE_TABLE_GUID		EFI_GUID(0x888eb0c6, 0x8ede, 0x4ff5,  0xa8, 0xf0, 0x9a, 0xee, 0x5c, 0xb9, 0x77, 0xc2)
68206f7d4a1SCompostella, Jeremy 
6831c5fecb6SNarendra K /* OEM GUIDs */
6841c5fecb6SNarendra K #define DELLEMC_EFI_RCI2_TABLE_GUID		EFI_GUID(0x2d9f28a2, 0xa886, 0x456a,  0x97, 0xa8, 0xf1, 0x1e, 0xf2, 0x4f, 0xf4, 0x55)
6851c5fecb6SNarendra K 
6861da177e4SLinus Torvalds typedef struct {
6871da177e4SLinus Torvalds 	efi_guid_t guid;
6881adbfa35SOlof Johansson 	u64 table;
6891adbfa35SOlof Johansson } efi_config_table_64_t;
6901adbfa35SOlof Johansson 
6911adbfa35SOlof Johansson typedef struct {
6921adbfa35SOlof Johansson 	efi_guid_t guid;
6931adbfa35SOlof Johansson 	u32 table;
6941adbfa35SOlof Johansson } efi_config_table_32_t;
6951adbfa35SOlof Johansson 
6961786e830SArd Biesheuvel typedef union {
6971786e830SArd Biesheuvel 	struct {
6981adbfa35SOlof Johansson 		efi_guid_t guid;
699f958efe9SArd Biesheuvel 		void *table;
7001786e830SArd Biesheuvel 	};
7011786e830SArd Biesheuvel 	efi_config_table_32_t mixed_mode;
7021da177e4SLinus Torvalds } efi_config_table_t;
7031da177e4SLinus Torvalds 
704272686bfSLeif Lindholm typedef struct {
705272686bfSLeif Lindholm 	efi_guid_t guid;
706272686bfSLeif Lindholm 	const char *name;
707272686bfSLeif Lindholm 	unsigned long *ptr;
708272686bfSLeif Lindholm } efi_config_table_type_t;
709272686bfSLeif Lindholm 
7101da177e4SLinus Torvalds #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
7111da177e4SLinus Torvalds 
7123b370237SMatthew Garrett #define EFI_2_30_SYSTEM_TABLE_REVISION  ((2 << 16) | (30))
7133b370237SMatthew Garrett #define EFI_2_20_SYSTEM_TABLE_REVISION  ((2 << 16) | (20))
7143b370237SMatthew Garrett #define EFI_2_10_SYSTEM_TABLE_REVISION  ((2 << 16) | (10))
7153b370237SMatthew Garrett #define EFI_2_00_SYSTEM_TABLE_REVISION  ((2 << 16) | (00))
7163b370237SMatthew Garrett #define EFI_1_10_SYSTEM_TABLE_REVISION  ((1 << 16) | (10))
7173b370237SMatthew Garrett #define EFI_1_02_SYSTEM_TABLE_REVISION  ((1 << 16) | (02))
7183b370237SMatthew Garrett 
7191da177e4SLinus Torvalds typedef struct {
7201da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
7211adbfa35SOlof Johansson 	u64 fw_vendor;	/* physical addr of CHAR16 vendor string */
7221adbfa35SOlof Johansson 	u32 fw_revision;
7231adbfa35SOlof Johansson 	u32 __pad1;
7241adbfa35SOlof Johansson 	u64 con_in_handle;
7251adbfa35SOlof Johansson 	u64 con_in;
7261adbfa35SOlof Johansson 	u64 con_out_handle;
7271adbfa35SOlof Johansson 	u64 con_out;
7281adbfa35SOlof Johansson 	u64 stderr_handle;
7291adbfa35SOlof Johansson 	u64 stderr;
7301adbfa35SOlof Johansson 	u64 runtime;
7311adbfa35SOlof Johansson 	u64 boottime;
7321adbfa35SOlof Johansson 	u32 nr_tables;
7331adbfa35SOlof Johansson 	u32 __pad2;
7341adbfa35SOlof Johansson 	u64 tables;
7351adbfa35SOlof Johansson } efi_system_table_64_t;
7361adbfa35SOlof Johansson 
7371adbfa35SOlof Johansson typedef struct {
7381adbfa35SOlof Johansson 	efi_table_hdr_t hdr;
7391adbfa35SOlof Johansson 	u32 fw_vendor;	/* physical addr of CHAR16 vendor string */
7401adbfa35SOlof Johansson 	u32 fw_revision;
7411adbfa35SOlof Johansson 	u32 con_in_handle;
7421adbfa35SOlof Johansson 	u32 con_in;
7431adbfa35SOlof Johansson 	u32 con_out_handle;
7441adbfa35SOlof Johansson 	u32 con_out;
7451adbfa35SOlof Johansson 	u32 stderr_handle;
7461adbfa35SOlof Johansson 	u32 stderr;
7471adbfa35SOlof Johansson 	u32 runtime;
7481adbfa35SOlof Johansson 	u32 boottime;
7491adbfa35SOlof Johansson 	u32 nr_tables;
7501adbfa35SOlof Johansson 	u32 tables;
7511adbfa35SOlof Johansson } efi_system_table_32_t;
7521adbfa35SOlof Johansson 
753960a8d01SArd Biesheuvel typedef union efi_simple_text_output_protocol efi_simple_text_output_protocol_t;
754960a8d01SArd Biesheuvel 
7551786e830SArd Biesheuvel typedef union {
7561786e830SArd Biesheuvel 	struct {
7571adbfa35SOlof Johansson 		efi_table_hdr_t hdr;
7581da177e4SLinus Torvalds 		unsigned long fw_vendor;	/* physical addr of CHAR16 vendor string */
7591da177e4SLinus Torvalds 		u32 fw_revision;
7601da177e4SLinus Torvalds 		unsigned long con_in_handle;
7611da177e4SLinus Torvalds 		unsigned long con_in;
7621da177e4SLinus Torvalds 		unsigned long con_out_handle;
763960a8d01SArd Biesheuvel 		efi_simple_text_output_protocol_t *con_out;
7641da177e4SLinus Torvalds 		unsigned long stderr_handle;
7651da177e4SLinus Torvalds 		unsigned long stderr;
7661da177e4SLinus Torvalds 		efi_runtime_services_t *runtime;
767f30ca6baSMatt Fleming 		efi_boot_services_t *boottime;
7681da177e4SLinus Torvalds 		unsigned long nr_tables;
7691da177e4SLinus Torvalds 		unsigned long tables;
7701786e830SArd Biesheuvel 	};
7711786e830SArd Biesheuvel 	efi_system_table_32_t mixed_mode;
7721da177e4SLinus Torvalds } efi_system_table_t;
7731da177e4SLinus Torvalds 
7749479c7ceSMatt Fleming /*
7759479c7ceSMatt Fleming  * Architecture independent structure for describing a memory map for the
7769479c7ceSMatt Fleming  * benefit of efi_memmap_init_early(), saving us the need to pass four
7779479c7ceSMatt Fleming  * parameters.
7789479c7ceSMatt Fleming  */
7799479c7ceSMatt Fleming struct efi_memory_map_data {
7809479c7ceSMatt Fleming 	phys_addr_t phys_map;
7819479c7ceSMatt Fleming 	unsigned long size;
7829479c7ceSMatt Fleming 	unsigned long desc_version;
7839479c7ceSMatt Fleming 	unsigned long desc_size;
7849479c7ceSMatt Fleming };
7859479c7ceSMatt Fleming 
7861da177e4SLinus Torvalds struct efi_memory_map {
78744511fb9SArd Biesheuvel 	phys_addr_t phys_map;
7887ae65fd3SMatt Tolentino 	void *map;
7897ae65fd3SMatt Tolentino 	void *map_end;
7901da177e4SLinus Torvalds 	int nr_map;
7911da177e4SLinus Torvalds 	unsigned long desc_version;
7927ae65fd3SMatt Tolentino 	unsigned long desc_size;
793dca0f971SMatt Fleming 	bool late;
7941da177e4SLinus Torvalds };
7951da177e4SLinus Torvalds 
79660863c0dSMatt Fleming struct efi_mem_range {
79760863c0dSMatt Fleming 	struct range range;
79860863c0dSMatt Fleming 	u64 attribute;
7991da177e4SLinus Torvalds };
8001da177e4SLinus Torvalds 
8010302f71cSMark Salter struct efi_fdt_params {
8020302f71cSMark Salter 	u64 system_table;
8030302f71cSMark Salter 	u64 mmap;
8040302f71cSMark Salter 	u32 mmap_size;
8050302f71cSMark Salter 	u32 desc_size;
8060302f71cSMark Salter 	u32 desc_ver;
8070302f71cSMark Salter };
8080302f71cSMark Salter 
80914e900c7SArd Biesheuvel typedef struct {
810677703ceSMatt Fleming 	u32 revision;
8119fa76ca7SArvind Sankar 	efi_handle_t parent_handle;
8128e84f345SMatt Fleming 	efi_system_table_t *system_table;
8139fa76ca7SArvind Sankar 	efi_handle_t device_handle;
8148e84f345SMatt Fleming 	void *file_path;
8158e84f345SMatt Fleming 	void *reserved;
8168e84f345SMatt Fleming 	u32 load_options_size;
8178e84f345SMatt Fleming 	void *load_options;
8188e84f345SMatt Fleming 	void *image_base;
8198e84f345SMatt Fleming 	__aligned_u64 image_size;
8208e84f345SMatt Fleming 	unsigned int image_code_type;
8218e84f345SMatt Fleming 	unsigned int image_data_type;
8228f24f8c2SArd Biesheuvel 	efi_status_t ( __efiapi *unload)(efi_handle_t image_handle);
82314e900c7SArd Biesheuvel } efi_loaded_image_t;
82455839d51SMatt Fleming 
82555839d51SMatt Fleming typedef struct {
82655839d51SMatt Fleming 	u64 size;
82755839d51SMatt Fleming 	u64 file_size;
82855839d51SMatt Fleming 	u64 phys_size;
82955839d51SMatt Fleming 	efi_time_t create_time;
83055839d51SMatt Fleming 	efi_time_t last_access_time;
83155839d51SMatt Fleming 	efi_time_t modification_time;
83255839d51SMatt Fleming 	__aligned_u64 attribute;
83355839d51SMatt Fleming 	efi_char16_t filename[1];
83455839d51SMatt Fleming } efi_file_info_t;
83555839d51SMatt Fleming 
83614e900c7SArd Biesheuvel typedef struct efi_file_handle efi_file_handle_t;
8371786e830SArd Biesheuvel 
83814e900c7SArd Biesheuvel struct efi_file_handle {
83955839d51SMatt Fleming 	u64 revision;
8408f24f8c2SArd Biesheuvel 	efi_status_t (__efiapi *open)(efi_file_handle_t *,
8411786e830SArd Biesheuvel 				      efi_file_handle_t **,
842ed37ddffSRoy Franz 				      efi_char16_t *, u64, u64);
8438f24f8c2SArd Biesheuvel 	efi_status_t (__efiapi *close)(efi_file_handle_t *);
84455839d51SMatt Fleming 	void *delete;
8458f24f8c2SArd Biesheuvel 	efi_status_t (__efiapi *read)(efi_file_handle_t *,
8468f24f8c2SArd Biesheuvel 				      unsigned long *, void *);
84755839d51SMatt Fleming 	void *write;
84855839d51SMatt Fleming 	void *get_position;
84955839d51SMatt Fleming 	void *set_position;
8508f24f8c2SArd Biesheuvel 	efi_status_t (__efiapi *get_info)(efi_file_handle_t *,
8518f24f8c2SArd Biesheuvel 					  efi_guid_t *, unsigned long *,
8528f24f8c2SArd Biesheuvel 					  void *);
85355839d51SMatt Fleming 	void *set_info;
85455839d51SMatt Fleming 	void *flush;
8551786e830SArd Biesheuvel };
85655839d51SMatt Fleming 
85714e900c7SArd Biesheuvel typedef struct efi_file_io_interface efi_file_io_interface_t;
8581786e830SArd Biesheuvel 
85914e900c7SArd Biesheuvel struct efi_file_io_interface {
860ed37ddffSRoy Franz 	u64 revision;
8618f24f8c2SArd Biesheuvel 	int (__efiapi *open_volume)(efi_file_io_interface_t *,
862ed37ddffSRoy Franz 				    efi_file_handle_t **);
8631786e830SArd Biesheuvel };
864ed37ddffSRoy Franz 
86555839d51SMatt Fleming #define EFI_FILE_MODE_READ	0x0000000000000001
86655839d51SMatt Fleming #define EFI_FILE_MODE_WRITE	0x0000000000000002
86755839d51SMatt Fleming #define EFI_FILE_MODE_CREATE	0x8000000000000000
86855839d51SMatt Fleming 
869bf924863SArd Biesheuvel typedef struct {
870bf924863SArd Biesheuvel 	u32 version;
871bf924863SArd Biesheuvel 	u32 length;
872bf924863SArd Biesheuvel 	u64 memory_protection_attribute;
873bf924863SArd Biesheuvel } efi_properties_table_t;
874bf924863SArd Biesheuvel 
875bf924863SArd Biesheuvel #define EFI_PROPERTIES_TABLE_VERSION	0x00010000
876bf924863SArd Biesheuvel #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA	0x1
877bf924863SArd Biesheuvel 
878b2c99e3cSBjorn Helgaas #define EFI_INVALID_TABLE_ADDR		(~0UL)
879b2c99e3cSBjorn Helgaas 
880a604af07SArd Biesheuvel typedef struct {
881a604af07SArd Biesheuvel 	u32 version;
882a604af07SArd Biesheuvel 	u32 num_entries;
883a604af07SArd Biesheuvel 	u32 desc_size;
884a604af07SArd Biesheuvel 	u32 reserved;
885a604af07SArd Biesheuvel 	efi_memory_desc_t entry[0];
886a604af07SArd Biesheuvel } efi_memory_attributes_table_t;
887a604af07SArd Biesheuvel 
8885c126ba2SDave Howells typedef struct {
8895c126ba2SDave Howells 	efi_guid_t signature_owner;
8905c126ba2SDave Howells 	u8 signature_data[];
8915c126ba2SDave Howells } efi_signature_data_t;
8925c126ba2SDave Howells 
8935c126ba2SDave Howells typedef struct {
8945c126ba2SDave Howells 	efi_guid_t signature_type;
8955c126ba2SDave Howells 	u32 signature_list_size;
8965c126ba2SDave Howells 	u32 signature_header_size;
8975c126ba2SDave Howells 	u32 signature_size;
8985c126ba2SDave Howells 	u8 signature_header[];
8995c126ba2SDave Howells 	/* efi_signature_data_t signatures[][] */
9005c126ba2SDave Howells } efi_signature_list_t;
9015c126ba2SDave Howells 
9025c126ba2SDave Howells typedef u8 efi_sha256_hash_t[32];
9035c126ba2SDave Howells 
9045c126ba2SDave Howells typedef struct {
9055c126ba2SDave Howells 	efi_sha256_hash_t to_be_signed_hash;
9065c126ba2SDave Howells 	efi_time_t time_of_revocation;
9075c126ba2SDave Howells } efi_cert_x509_sha256_t;
9085c126ba2SDave Howells 
9091da177e4SLinus Torvalds /*
9101da177e4SLinus Torvalds  * All runtime access to EFI goes through this structure:
9111da177e4SLinus Torvalds  */
9121da177e4SLinus Torvalds extern struct efi {
9131da177e4SLinus Torvalds 	efi_system_table_t *systab;	/* EFI system table */
9143b370237SMatthew Garrett 	unsigned int runtime_version;	/* Runtime services version */
915b2c99e3cSBjorn Helgaas 	unsigned long mps;		/* MPS table */
916b2c99e3cSBjorn Helgaas 	unsigned long acpi;		/* ACPI table  (IA64 ext 0.71) */
917b2c99e3cSBjorn Helgaas 	unsigned long acpi20;		/* ACPI table  (ACPI 2.0) */
918e1ccbbc9SArd Biesheuvel 	unsigned long smbios;		/* SMBIOS table (32 bit entry point) */
919e1ccbbc9SArd Biesheuvel 	unsigned long smbios3;		/* SMBIOS table (64 bit entry point) */
920b2c99e3cSBjorn Helgaas 	unsigned long boot_info;	/* boot info table */
921b2c99e3cSBjorn Helgaas 	unsigned long hcdp;		/* HCDP table */
922b2c99e3cSBjorn Helgaas 	unsigned long uga;		/* UGA table */
923a0998eb1SDave Young 	unsigned long fw_vendor;	/* fw_vendor */
924a0998eb1SDave Young 	unsigned long runtime;		/* runtime table */
925a0998eb1SDave Young 	unsigned long config_table;	/* config tables */
9260bb54905SPeter Jones 	unsigned long esrt;		/* ESRT table */
927bf924863SArd Biesheuvel 	unsigned long properties_table;	/* properties table */
928a604af07SArd Biesheuvel 	unsigned long mem_attr_table;	/* memory attributes table */
92963625988SArd Biesheuvel 	unsigned long rng_seed;		/* UEFI firmware random seed */
93033b6d034SThiebaud Weksteen 	unsigned long tpm_log;		/* TPM2 Event Log table */
931c46f3405SMatthew Garrett 	unsigned long tpm_final_log;	/* TPM2 Final Events Log table */
93271e0940dSArd Biesheuvel 	unsigned long mem_reserve;	/* Linux EFI memreserve table */
9331da177e4SLinus Torvalds 	efi_get_time_t *get_time;
9341da177e4SLinus Torvalds 	efi_set_time_t *set_time;
9351da177e4SLinus Torvalds 	efi_get_wakeup_time_t *get_wakeup_time;
9361da177e4SLinus Torvalds 	efi_set_wakeup_time_t *set_wakeup_time;
9371da177e4SLinus Torvalds 	efi_get_variable_t *get_variable;
9381da177e4SLinus Torvalds 	efi_get_next_variable_t *get_next_variable;
9391da177e4SLinus Torvalds 	efi_set_variable_t *set_variable;
94070d2a3cfSArd Biesheuvel 	efi_set_variable_t *set_variable_nonblocking;
9413b370237SMatthew Garrett 	efi_query_variable_info_t *query_variable_info;
942d3cac1f8SArd Biesheuvel 	efi_query_variable_info_t *query_variable_info_nonblocking;
9433b370237SMatthew Garrett 	efi_update_capsule_t *update_capsule;
9443b370237SMatthew Garrett 	efi_query_capsule_caps_t *query_capsule_caps;
9451da177e4SLinus Torvalds 	efi_get_next_high_mono_count_t *get_next_high_mono_count;
9461da177e4SLinus Torvalds 	efi_reset_system_t *reset_system;
9471da177e4SLinus Torvalds 	efi_set_virtual_address_map_t *set_virtual_address_map;
948884f4f66SMatt Fleming 	struct efi_memory_map memmap;
9493e909599SMatt Fleming 	unsigned long flags;
9501da177e4SLinus Torvalds } efi;
9511da177e4SLinus Torvalds 
9527e904a91SSai Praneeth extern struct mm_struct efi_mm;
9537e904a91SSai Praneeth 
9541da177e4SLinus Torvalds static inline int
9551da177e4SLinus Torvalds efi_guidcmp (efi_guid_t left, efi_guid_t right)
9561da177e4SLinus Torvalds {
9571da177e4SLinus Torvalds 	return memcmp(&left, &right, sizeof (efi_guid_t));
9581da177e4SLinus Torvalds }
9591da177e4SLinus Torvalds 
9601da177e4SLinus Torvalds static inline char *
96126e02272SBorislav Petkov efi_guid_to_str(efi_guid_t *guid, char *out)
9621da177e4SLinus Torvalds {
963925ede0bSJoe Perches 	sprintf(out, "%pUl", guid->b);
9641da177e4SLinus Torvalds         return out;
9651da177e4SLinus Torvalds }
9661da177e4SLinus Torvalds 
9671da177e4SLinus Torvalds extern void efi_init (void);
9681da177e4SLinus Torvalds extern void *efi_get_pal_addr (void);
9691da177e4SLinus Torvalds extern void efi_map_pal_code (void);
9701da177e4SLinus Torvalds extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
97170f4f935SArnd Bergmann extern void efi_gettimeofday (struct timespec64 *ts);
9721da177e4SLinus Torvalds extern void efi_enter_virtual_mode (void);	/* switch EFI to virtual mode, if possible */
97378510792SJosh Triplett #ifdef CONFIG_X86
974ca0e30dcSArd Biesheuvel extern efi_status_t efi_query_variable_store(u32 attributes,
975ca0e30dcSArd Biesheuvel 					     unsigned long size,
976ca0e30dcSArd Biesheuvel 					     bool nonblocking);
97778510792SJosh Triplett #else
978a6e4d5a0SMatt Fleming 
979ca0e30dcSArd Biesheuvel static inline efi_status_t efi_query_variable_store(u32 attributes,
980ca0e30dcSArd Biesheuvel 						    unsigned long size,
981ca0e30dcSArd Biesheuvel 						    bool nonblocking)
982a6e4d5a0SMatt Fleming {
983a6e4d5a0SMatt Fleming 	return EFI_SUCCESS;
984a6e4d5a0SMatt Fleming }
98578510792SJosh Triplett #endif
9867bc90e01SJosh Triplett extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
9879479c7ceSMatt Fleming 
98820b1e22dSNicolai Stange extern phys_addr_t __init efi_memmap_alloc(unsigned int num_entries);
9899479c7ceSMatt Fleming extern int __init efi_memmap_init_early(struct efi_memory_map_data *data);
990dca0f971SMatt Fleming extern int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size);
9919479c7ceSMatt Fleming extern void __init efi_memmap_unmap(void);
992c45f4da3SMatt Fleming extern int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map);
99360863c0dSMatt Fleming extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
99460863c0dSMatt Fleming 					 struct range *range);
99560863c0dSMatt Fleming extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap,
99660863c0dSMatt Fleming 				     void *buf, struct efi_mem_range *mem);
9979479c7ceSMatt Fleming 
998272686bfSLeif Lindholm extern int efi_config_init(efi_config_table_type_t *arch_tables);
9993846c158SPeter Jones #ifdef CONFIG_EFI_ESRT
10000bb54905SPeter Jones extern void __init efi_esrt_init(void);
10013846c158SPeter Jones #else
10023846c158SPeter Jones static inline void efi_esrt_init(void) { }
10033846c158SPeter Jones #endif
10047bb68410SArd Biesheuvel extern int efi_config_parse_tables(void *config_tables, int count, int sz,
10057bb68410SArd Biesheuvel 				   efi_config_table_type_t *arch_tables);
10061da177e4SLinus Torvalds extern u64 efi_get_iobase (void);
1007f99afd08STom Lendacky extern int efi_mem_type(unsigned long phys_addr);
10081da177e4SLinus Torvalds extern u64 efi_mem_attributes (unsigned long phys_addr);
100932e62c63SBjorn Helgaas extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
10101da177e4SLinus Torvalds extern int __init efi_uart_console_only (void);
10110bb54905SPeter Jones extern u64 efi_mem_desc_end(efi_memory_desc_t *md);
10120bb54905SPeter Jones extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
1013816e7612SMatt Fleming extern void efi_mem_reserve(phys_addr_t addr, u64 size);
1014a23d3bb0SArd Biesheuvel extern int efi_mem_reserve_persistent(phys_addr_t addr, u64 size);
10151da177e4SLinus Torvalds extern void efi_initialize_iomem_resources(struct resource *code_resource,
101600bf4098SBernhard Walle 		struct resource *data_resource, struct resource *bss_resource);
10177968c0e3SLeif Lindholm extern int efi_get_fdt_params(struct efi_fdt_params *params);
10180bb54905SPeter Jones extern struct kobject *efi_kobj;
10191da177e4SLinus Torvalds 
102044be28e9SMatt Fleming extern int efi_reboot_quirk_mode;
10210c5ed61aSMatt Fleming extern bool efi_poweroff_required(void);
10220c5ed61aSMatt Fleming 
10230f96a99dSTaku Izumi #ifdef CONFIG_EFI_FAKE_MEMMAP
10240f96a99dSTaku Izumi extern void __init efi_fake_memmap(void);
10250f96a99dSTaku Izumi #else
10260f96a99dSTaku Izumi static inline void efi_fake_memmap(void) { }
10270f96a99dSTaku Izumi #endif
10280f96a99dSTaku Izumi 
102910f0d2f5SArd Biesheuvel /*
103010f0d2f5SArd Biesheuvel  * efi_memattr_perm_setter - arch specific callback function passed into
103110f0d2f5SArd Biesheuvel  *                           efi_memattr_apply_permissions() that updates the
103210f0d2f5SArd Biesheuvel  *                           mapping permissions described by the second
103310f0d2f5SArd Biesheuvel  *                           argument in the page tables referred to by the
103410f0d2f5SArd Biesheuvel  *                           first argument.
103510f0d2f5SArd Biesheuvel  */
103610f0d2f5SArd Biesheuvel typedef int (*efi_memattr_perm_setter)(struct mm_struct *, efi_memory_desc_t *);
103710f0d2f5SArd Biesheuvel 
103810f0d2f5SArd Biesheuvel extern int efi_memattr_init(void);
103910f0d2f5SArd Biesheuvel extern int efi_memattr_apply_permissions(struct mm_struct *mm,
104010f0d2f5SArd Biesheuvel 					 efi_memattr_perm_setter fn);
104110f0d2f5SArd Biesheuvel 
104202e43c2dSBaoquan He /*
104302e43c2dSBaoquan He  * efi_early_memdesc_ptr - get the n-th EFI memmap descriptor
104402e43c2dSBaoquan He  * @map: the start of efi memmap
104502e43c2dSBaoquan He  * @desc_size: the size of space for each EFI memmap descriptor
104602e43c2dSBaoquan He  * @n: the index of efi memmap descriptor
104702e43c2dSBaoquan He  *
104802e43c2dSBaoquan He  * EFI boot service provides the GetMemoryMap() function to get a copy of the
104902e43c2dSBaoquan He  * current memory map which is an array of memory descriptors, each of
105002e43c2dSBaoquan He  * which describes a contiguous block of memory. It also gets the size of the
105102e43c2dSBaoquan He  * map, and the size of each descriptor, etc.
105202e43c2dSBaoquan He  *
105302e43c2dSBaoquan He  * Note that per section 6.2 of UEFI Spec 2.6 Errata A, the returned size of
105402e43c2dSBaoquan He  * each descriptor might not be equal to sizeof(efi_memory_memdesc_t),
105502e43c2dSBaoquan He  * since efi_memory_memdesc_t may be extended in the future. Thus the OS
105602e43c2dSBaoquan He  * MUST use the returned size of the descriptor to find the start of each
105702e43c2dSBaoquan He  * efi_memory_memdesc_t in the memory map array. This should only be used
105802e43c2dSBaoquan He  * during bootup since for_each_efi_memory_desc_xxx() is available after the
105902e43c2dSBaoquan He  * kernel initializes the EFI subsystem to set up struct efi_memory_map.
106002e43c2dSBaoquan He  */
106102e43c2dSBaoquan He #define efi_early_memdesc_ptr(map, desc_size, n)			\
106202e43c2dSBaoquan He 	(efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
106302e43c2dSBaoquan He 
1064e885cd80SMark Salter /* Iterate through an efi_memory_map */
106578ce248fSMatt Fleming #define for_each_efi_memory_desc_in_map(m, md)				   \
1066e885cd80SMark Salter 	for ((md) = (m)->map;						   \
1067d4c4fed0SJan Beulich 	     (md) && ((void *)(md) + (m)->desc_size) <= (m)->map_end;	   \
1068e885cd80SMark Salter 	     (md) = (void *)(md) + (m)->desc_size)
1069e885cd80SMark Salter 
107078ce248fSMatt Fleming /**
107178ce248fSMatt Fleming  * for_each_efi_memory_desc - iterate over descriptors in efi.memmap
107278ce248fSMatt Fleming  * @md: the efi_memory_desc_t * iterator
107378ce248fSMatt Fleming  *
107478ce248fSMatt Fleming  * Once the loop finishes @md must not be accessed.
107578ce248fSMatt Fleming  */
107678ce248fSMatt Fleming #define for_each_efi_memory_desc(md) \
1077884f4f66SMatt Fleming 	for_each_efi_memory_desc_in_map(&efi.memmap, md)
107878ce248fSMatt Fleming 
107998d2a6caSLaszlo Ersek /*
108098d2a6caSLaszlo Ersek  * Format an EFI memory descriptor's type and attributes to a user-provided
108198d2a6caSLaszlo Ersek  * character buffer, as per snprintf(), and return the buffer.
108298d2a6caSLaszlo Ersek  */
108398d2a6caSLaszlo Ersek char * __init efi_md_typeattr_format(char *buf, size_t size,
108498d2a6caSLaszlo Ersek 				     const efi_memory_desc_t *md);
108598d2a6caSLaszlo Ersek 
10860bc9ae39SDave Howells 
10870bc9ae39SDave Howells typedef void (*efi_element_handler_t)(const char *source,
10880bc9ae39SDave Howells 				      const void *element_data,
10890bc9ae39SDave Howells 				      size_t element_size);
10900bc9ae39SDave Howells extern int __init parse_efi_signature_list(
10910bc9ae39SDave Howells 	const char *source,
10920bc9ae39SDave Howells 	const void *data, size_t size,
10930bc9ae39SDave Howells 	efi_element_handler_t (*get_handler_for_guid)(const efi_guid_t *));
10940bc9ae39SDave Howells 
10951da177e4SLinus Torvalds /**
10961da177e4SLinus Torvalds  * efi_range_is_wc - check the WC bit on an address range
10971da177e4SLinus Torvalds  * @start: starting kvirt address
10981da177e4SLinus Torvalds  * @len: length of range
10991da177e4SLinus Torvalds  *
11001da177e4SLinus Torvalds  * Consult the EFI memory map and make sure it's ok to set this range WC.
11011da177e4SLinus Torvalds  * Returns true or false.
11021da177e4SLinus Torvalds  */
11031da177e4SLinus Torvalds static inline int efi_range_is_wc(unsigned long start, unsigned long len)
11041da177e4SLinus Torvalds {
1105986a80d5SJesper Juhl 	unsigned long i;
11061da177e4SLinus Torvalds 
11071da177e4SLinus Torvalds 	for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
11081da177e4SLinus Torvalds 		unsigned long paddr = __pa(start + i);
11091da177e4SLinus Torvalds 		if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
11101da177e4SLinus Torvalds 			return 0;
11111da177e4SLinus Torvalds 	}
11121da177e4SLinus Torvalds 	/* The range checked out */
11131da177e4SLinus Torvalds 	return 1;
11141da177e4SLinus Torvalds }
11151da177e4SLinus Torvalds 
11161da177e4SLinus Torvalds #ifdef CONFIG_EFI_PCDP
11171da177e4SLinus Torvalds extern int __init efi_setup_pcdp_console(char *);
11181da177e4SLinus Torvalds #endif
11191da177e4SLinus Torvalds 
11201da177e4SLinus Torvalds /*
112183e68189SMatt Fleming  * We play games with efi_enabled so that the compiler will, if
112283e68189SMatt Fleming  * possible, remove EFI-related code altogether.
11231da177e4SLinus Torvalds  */
112483e68189SMatt Fleming #define EFI_BOOT		0	/* Were we booted from EFI? */
112583e68189SMatt Fleming #define EFI_CONFIG_TABLES	2	/* Can we use EFI config tables? */
112683e68189SMatt Fleming #define EFI_RUNTIME_SERVICES	3	/* Can we use runtime services? */
112783e68189SMatt Fleming #define EFI_MEMMAP		4	/* Can we use EFI memory map? */
112883e68189SMatt Fleming #define EFI_64BIT		5	/* Is the firmware 64-bit? */
11299f27bc54SDaniel Kiper #define EFI_PARAVIRT		6	/* Access is via a paravirt interface */
11309f27bc54SDaniel Kiper #define EFI_ARCH_1		7	/* First arch-specific bit */
1131fed6cefeSBorislav Petkov #define EFI_DBG			8	/* Print additional debug info at runtime */
1132a1041713SArd Biesheuvel #define EFI_NX_PE_DATA		9	/* Can runtime data regions be mapped non-executable? */
1133a19ebf59SSai Praneeth #define EFI_MEM_ATTR		10	/* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */
1134b617c526SDan Williams #define EFI_MEM_NO_SOFT_RESERVE	11	/* Is the kernel configured to ignore soft reservations? */
113583e68189SMatt Fleming 
11361da177e4SLinus Torvalds #ifdef CONFIG_EFI
11373e909599SMatt Fleming /*
11383e909599SMatt Fleming  * Test whether the above EFI_* bits are enabled.
11393e909599SMatt Fleming  */
11403e909599SMatt Fleming static inline bool efi_enabled(int feature)
114183e68189SMatt Fleming {
11423e909599SMatt Fleming 	return test_bit(feature, &efi.flags) != 0;
11433e909599SMatt Fleming }
11448562c99cSMatt Fleming extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
1145b617c526SDan Williams 
1146b617c526SDan Williams bool __pure __efi_soft_reserve_enabled(void);
1147b617c526SDan Williams 
1148b617c526SDan Williams static inline bool __pure efi_soft_reserve_enabled(void)
1149b617c526SDan Williams {
1150b617c526SDan Williams 	return IS_ENABLED(CONFIG_EFI_SOFT_RESERVE)
1151b617c526SDan Williams 		&& __efi_soft_reserve_enabled();
1152b617c526SDan Williams }
11533e909599SMatt Fleming #else
11543e909599SMatt Fleming static inline bool efi_enabled(int feature)
11553e909599SMatt Fleming {
11563e909599SMatt Fleming 	return false;
115783e68189SMatt Fleming }
11588562c99cSMatt Fleming static inline void
11598562c99cSMatt Fleming efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
116087615a34SMatt Fleming 
116187615a34SMatt Fleming static inline bool
116287615a34SMatt Fleming efi_capsule_pending(int *reset_type)
116387615a34SMatt Fleming {
116487615a34SMatt Fleming 	return false;
116587615a34SMatt Fleming }
1166b617c526SDan Williams 
1167b617c526SDan Williams static inline bool efi_soft_reserve_enabled(void)
1168b617c526SDan Williams {
1169b617c526SDan Williams 	return false;
1170b617c526SDan Williams }
11711da177e4SLinus Torvalds #endif
11721da177e4SLinus Torvalds 
1173806b0351SMatt Fleming extern int efi_status_to_err(efi_status_t status);
1174806b0351SMatt Fleming 
11751da177e4SLinus Torvalds /*
11761da177e4SLinus Torvalds  * Variable Attributes
11771da177e4SLinus Torvalds  */
11781da177e4SLinus Torvalds #define EFI_VARIABLE_NON_VOLATILE       0x0000000000000001
11791da177e4SLinus Torvalds #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
11801da177e4SLinus Torvalds #define EFI_VARIABLE_RUNTIME_ACCESS     0x0000000000000004
118141b3254cSMatthew Garrett #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
118241b3254cSMatthew Garrett #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
118341b3254cSMatthew Garrett #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
118441b3254cSMatthew Garrett #define EFI_VARIABLE_APPEND_WRITE	0x0000000000000040
11851da177e4SLinus Torvalds 
118641b3254cSMatthew Garrett #define EFI_VARIABLE_MASK 	(EFI_VARIABLE_NON_VOLATILE | \
118741b3254cSMatthew Garrett 				EFI_VARIABLE_BOOTSERVICE_ACCESS | \
118841b3254cSMatthew Garrett 				EFI_VARIABLE_RUNTIME_ACCESS | \
118941b3254cSMatthew Garrett 				EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
119041b3254cSMatthew Garrett 				EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
119141b3254cSMatthew Garrett 				EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
119241b3254cSMatthew Garrett 				EFI_VARIABLE_APPEND_WRITE)
11931da177e4SLinus Torvalds /*
1194e14ab23dSMatt Fleming  * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
1195e14ab23dSMatt Fleming  * not including trailing NUL
1196e14ab23dSMatt Fleming  */
1197ba7e34b1SAndy Shevchenko #define EFI_VARIABLE_GUID_LEN	UUID_STRING_LEN
1198e14ab23dSMatt Fleming 
1199e14ab23dSMatt Fleming /*
1200e2527a7cSMatt Fleming  * The type of search to perform when calling boottime->locate_handle
1201e2527a7cSMatt Fleming  */
1202e2527a7cSMatt Fleming #define EFI_LOCATE_ALL_HANDLES			0
1203e2527a7cSMatt Fleming #define EFI_LOCATE_BY_REGISTER_NOTIFY		1
1204e2527a7cSMatt Fleming #define EFI_LOCATE_BY_PROTOCOL			2
1205e2527a7cSMatt Fleming 
1206e2527a7cSMatt Fleming /*
12071da177e4SLinus Torvalds  * EFI Device Path information
12081da177e4SLinus Torvalds  */
12091da177e4SLinus Torvalds #define EFI_DEV_HW			0x01
12101da177e4SLinus Torvalds #define  EFI_DEV_PCI				 1
12111da177e4SLinus Torvalds #define  EFI_DEV_PCCARD				 2
12121da177e4SLinus Torvalds #define  EFI_DEV_MEM_MAPPED			 3
12131da177e4SLinus Torvalds #define  EFI_DEV_VENDOR				 4
12141da177e4SLinus Torvalds #define  EFI_DEV_CONTROLLER			 5
12151da177e4SLinus Torvalds #define EFI_DEV_ACPI			0x02
12161da177e4SLinus Torvalds #define   EFI_DEV_BASIC_ACPI			 1
12171da177e4SLinus Torvalds #define   EFI_DEV_EXPANDED_ACPI			 2
12181da177e4SLinus Torvalds #define EFI_DEV_MSG			0x03
12191da177e4SLinus Torvalds #define   EFI_DEV_MSG_ATAPI			 1
12201da177e4SLinus Torvalds #define   EFI_DEV_MSG_SCSI			 2
12211da177e4SLinus Torvalds #define   EFI_DEV_MSG_FC			 3
12221da177e4SLinus Torvalds #define   EFI_DEV_MSG_1394			 4
12231da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB			 5
12241da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB_CLASS			15
12251da177e4SLinus Torvalds #define   EFI_DEV_MSG_I20			 6
12261da177e4SLinus Torvalds #define   EFI_DEV_MSG_MAC			11
12271da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV4			12
12281da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV6			13
12291da177e4SLinus Torvalds #define   EFI_DEV_MSG_INFINIBAND		 9
12301da177e4SLinus Torvalds #define   EFI_DEV_MSG_UART			14
12311da177e4SLinus Torvalds #define   EFI_DEV_MSG_VENDOR			10
12321da177e4SLinus Torvalds #define EFI_DEV_MEDIA			0x04
12331da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_HARD_DRIVE		 1
12341da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_CDROM			 2
12351da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_VENDOR			 3
12361da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_FILE			 4
12371da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_PROTOCOL		 5
12381da177e4SLinus Torvalds #define EFI_DEV_BIOS_BOOT		0x05
12391da177e4SLinus Torvalds #define EFI_DEV_END_PATH		0x7F
12401da177e4SLinus Torvalds #define EFI_DEV_END_PATH2		0xFF
12411da177e4SLinus Torvalds #define   EFI_DEV_END_INSTANCE			0x01
12421da177e4SLinus Torvalds #define   EFI_DEV_END_ENTIRE			0xFF
12431da177e4SLinus Torvalds 
12441da177e4SLinus Torvalds struct efi_generic_dev_path {
12451da177e4SLinus Torvalds 	u8 type;
12461da177e4SLinus Torvalds 	u8 sub_type;
12471da177e4SLinus Torvalds 	u16 length;
12481da177e4SLinus Torvalds } __attribute ((packed));
12491da177e4SLinus Torvalds 
125046cd4b75SLukas Wunner struct efi_dev_path {
125146cd4b75SLukas Wunner 	u8 type;	/* can be replaced with unnamed */
125246cd4b75SLukas Wunner 	u8 sub_type;	/* struct efi_generic_dev_path; */
125346cd4b75SLukas Wunner 	u16 length;	/* once we've moved to -std=c11 */
125446cd4b75SLukas Wunner 	union {
125546cd4b75SLukas Wunner 		struct {
125646cd4b75SLukas Wunner 			u32 hid;
125746cd4b75SLukas Wunner 			u32 uid;
125846cd4b75SLukas Wunner 		} acpi;
125946cd4b75SLukas Wunner 		struct {
126046cd4b75SLukas Wunner 			u8 fn;
126146cd4b75SLukas Wunner 			u8 dev;
126246cd4b75SLukas Wunner 		} pci;
126346cd4b75SLukas Wunner 	};
126446cd4b75SLukas Wunner } __attribute ((packed));
126546cd4b75SLukas Wunner 
126646cd4b75SLukas Wunner #if IS_ENABLED(CONFIG_EFI_DEV_PATH_PARSER)
126746cd4b75SLukas Wunner struct device *efi_get_device_by_path(struct efi_dev_path **node, size_t *len);
126846cd4b75SLukas Wunner #endif
126946cd4b75SLukas Wunner 
12704a3575fdSHuang, Ying static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
12714a3575fdSHuang, Ying {
12724a3575fdSHuang, Ying 	*npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
12734a3575fdSHuang, Ying 	*addr &= PAGE_MASK;
12744a3575fdSHuang, Ying }
12754a3575fdSHuang, Ying 
127604851772SMatt Fleming /*
12774fc756bdSMike Waychison  * EFI Variable support.
12784fc756bdSMike Waychison  *
12794fc756bdSMike Waychison  * Different firmware drivers can expose their EFI-like variables using
12804fc756bdSMike Waychison  * the following.
12814fc756bdSMike Waychison  */
12824fc756bdSMike Waychison 
12834fc756bdSMike Waychison struct efivar_operations {
12844fc756bdSMike Waychison 	efi_get_variable_t *get_variable;
12854fc756bdSMike Waychison 	efi_get_next_variable_t *get_next_variable;
12864fc756bdSMike Waychison 	efi_set_variable_t *set_variable;
128770d2a3cfSArd Biesheuvel 	efi_set_variable_t *set_variable_nonblocking;
1288a6e4d5a0SMatt Fleming 	efi_query_variable_store_t *query_variable_store;
12894fc756bdSMike Waychison };
12904fc756bdSMike Waychison 
12914fc756bdSMike Waychison struct efivars {
12924fc756bdSMike Waychison 	struct kset *kset;
1293605e70c7SLee, Chun-Yi 	struct kobject *kobject;
12944fc756bdSMike Waychison 	const struct efivar_operations *ops;
12954fc756bdSMike Waychison };
12964fc756bdSMike Waychison 
1297e14ab23dSMatt Fleming /*
1298e14ab23dSMatt Fleming  * The maximum size of VariableName + Data = 1024
1299e14ab23dSMatt Fleming  * Therefore, it's reasonable to save that much
1300e14ab23dSMatt Fleming  * space in each part of the structure,
1301e14ab23dSMatt Fleming  * and we use a page for reading/writing.
1302e14ab23dSMatt Fleming  */
1303e14ab23dSMatt Fleming 
1304a5d92ad3SMatt Fleming #define EFI_VAR_NAME_LEN	1024
1305a5d92ad3SMatt Fleming 
1306e14ab23dSMatt Fleming struct efi_variable {
1307a5d92ad3SMatt Fleming 	efi_char16_t  VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
1308e14ab23dSMatt Fleming 	efi_guid_t    VendorGuid;
1309e14ab23dSMatt Fleming 	unsigned long DataSize;
1310e14ab23dSMatt Fleming 	__u8          Data[1024];
1311e14ab23dSMatt Fleming 	efi_status_t  Status;
1312e14ab23dSMatt Fleming 	__u32         Attributes;
1313e14ab23dSMatt Fleming } __attribute__((packed));
1314e14ab23dSMatt Fleming 
1315e14ab23dSMatt Fleming struct efivar_entry {
1316e14ab23dSMatt Fleming 	struct efi_variable var;
1317e14ab23dSMatt Fleming 	struct list_head list;
1318e14ab23dSMatt Fleming 	struct kobject kobj;
1319e0d59733SSeiji Aguchi 	bool scanning;
1320e0d59733SSeiji Aguchi 	bool deleting;
1321e14ab23dSMatt Fleming };
1322e14ab23dSMatt Fleming 
13231786e830SArd Biesheuvel union efi_simple_text_output_protocol {
13241786e830SArd Biesheuvel 	struct {
1325ed37ddffSRoy Franz 		void *reset;
13268f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
13271786e830SArd Biesheuvel 						       efi_char16_t *);
1328ed37ddffSRoy Franz 		void *test_string;
1329ed37ddffSRoy Franz 	};
13301786e830SArd Biesheuvel 	struct {
13311786e830SArd Biesheuvel 		u32 reset;
13321786e830SArd Biesheuvel 		u32 output_string;
13331786e830SArd Biesheuvel 		u32 test_string;
13341786e830SArd Biesheuvel 	} mixed_mode;
13351786e830SArd Biesheuvel };
1336ed37ddffSRoy Franz 
1337fc372064SArd Biesheuvel #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR		0
1338fc372064SArd Biesheuvel #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR		1
1339fc372064SArd Biesheuvel #define PIXEL_BIT_MASK					2
1340fc372064SArd Biesheuvel #define PIXEL_BLT_ONLY					3
1341fc372064SArd Biesheuvel #define PIXEL_FORMAT_MAX				4
1342fc372064SArd Biesheuvel 
134344c84b4aSArvind Sankar typedef struct {
1344fc372064SArd Biesheuvel 	u32 red_mask;
1345fc372064SArd Biesheuvel 	u32 green_mask;
1346fc372064SArd Biesheuvel 	u32 blue_mask;
1347fc372064SArd Biesheuvel 	u32 reserved_mask;
134844c84b4aSArvind Sankar } efi_pixel_bitmask_t;
1349fc372064SArd Biesheuvel 
135044c84b4aSArvind Sankar typedef struct {
1351fc372064SArd Biesheuvel 	u32 version;
1352fc372064SArd Biesheuvel 	u32 horizontal_resolution;
1353fc372064SArd Biesheuvel 	u32 vertical_resolution;
1354fc372064SArd Biesheuvel 	int pixel_format;
135544c84b4aSArvind Sankar 	efi_pixel_bitmask_t pixel_information;
1356fc372064SArd Biesheuvel 	u32 pixels_per_scan_line;
135744c84b4aSArvind Sankar } efi_graphics_output_mode_info_t;
1358fc372064SArd Biesheuvel 
13591786e830SArd Biesheuvel typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;
13601786e830SArd Biesheuvel 
13611786e830SArd Biesheuvel union efi_graphics_output_protocol_mode {
13621786e830SArd Biesheuvel 	struct {
1363fc372064SArd Biesheuvel 		u32 max_mode;
1364fc372064SArd Biesheuvel 		u32 mode;
136544c84b4aSArvind Sankar 		efi_graphics_output_mode_info_t *info;
1366fc372064SArd Biesheuvel 		unsigned long size_of_info;
136744c84b4aSArvind Sankar 		efi_physical_addr_t frame_buffer_base;
1368fc372064SArd Biesheuvel 		unsigned long frame_buffer_size;
13691786e830SArd Biesheuvel 	};
13701786e830SArd Biesheuvel 	struct {
13711786e830SArd Biesheuvel 		u32 max_mode;
13721786e830SArd Biesheuvel 		u32 mode;
13731786e830SArd Biesheuvel 		u32 info;
13741786e830SArd Biesheuvel 		u32 size_of_info;
13751786e830SArd Biesheuvel 		u64 frame_buffer_base;
13761786e830SArd Biesheuvel 		u32 frame_buffer_size;
13771786e830SArd Biesheuvel 	} mixed_mode;
13781786e830SArd Biesheuvel };
1379fc372064SArd Biesheuvel 
13801786e830SArd Biesheuvel typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;
13811786e830SArd Biesheuvel 
13821786e830SArd Biesheuvel union efi_graphics_output_protocol {
13831786e830SArd Biesheuvel 	struct {
138444c84b4aSArvind Sankar 		void *query_mode;
138544c84b4aSArvind Sankar 		void *set_mode;
138644c84b4aSArvind Sankar 		void *blt;
138744c84b4aSArvind Sankar 		efi_graphics_output_protocol_mode_t *mode;
13881786e830SArd Biesheuvel 	};
13891786e830SArd Biesheuvel 	struct {
13901786e830SArd Biesheuvel 		u32 query_mode;
13911786e830SArd Biesheuvel 		u32 set_mode;
13921786e830SArd Biesheuvel 		u32 blt;
13931786e830SArd Biesheuvel 		u32 mode;
13941786e830SArd Biesheuvel 	} mixed_mode;
13951786e830SArd Biesheuvel };
1396fc372064SArd Biesheuvel 
139704851772SMatt Fleming extern struct list_head efivar_sysfs_list;
139804851772SMatt Fleming 
139904851772SMatt Fleming static inline void
140004851772SMatt Fleming efivar_unregister(struct efivar_entry *var)
140104851772SMatt Fleming {
140204851772SMatt Fleming 	kobject_put(&var->kobj);
140304851772SMatt Fleming }
140404851772SMatt Fleming 
1405e14ab23dSMatt Fleming int efivars_register(struct efivars *efivars,
14064fc756bdSMike Waychison 		     const struct efivar_operations *ops,
1407e14ab23dSMatt Fleming 		     struct kobject *kobject);
1408e14ab23dSMatt Fleming int efivars_unregister(struct efivars *efivars);
1409e14ab23dSMatt Fleming struct kobject *efivars_kobject(void);
1410e14ab23dSMatt Fleming 
1411e14ab23dSMatt Fleming int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
14121cfd6316SJulia Lawall 		void *data, bool duplicates, struct list_head *head);
1413e14ab23dSMatt Fleming 
141421b3ddd3SSylvain Chouleur int efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
141521b3ddd3SSylvain Chouleur int efivar_entry_remove(struct efivar_entry *entry);
1416e14ab23dSMatt Fleming 
1417e14ab23dSMatt Fleming int __efivar_entry_delete(struct efivar_entry *entry);
1418e14ab23dSMatt Fleming int efivar_entry_delete(struct efivar_entry *entry);
1419e14ab23dSMatt Fleming 
1420e14ab23dSMatt Fleming int efivar_entry_size(struct efivar_entry *entry, unsigned long *size);
14218a415b8cSMatt Fleming int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
14228a415b8cSMatt Fleming 		       unsigned long *size, void *data);
1423e14ab23dSMatt Fleming int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
1424e14ab23dSMatt Fleming 		     unsigned long *size, void *data);
1425e14ab23dSMatt Fleming int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
1426e14ab23dSMatt Fleming 		     unsigned long size, void *data, struct list_head *head);
1427e14ab23dSMatt Fleming int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
1428e14ab23dSMatt Fleming 			      unsigned long *size, void *data, bool *set);
1429e14ab23dSMatt Fleming int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
1430e14ab23dSMatt Fleming 			  bool block, unsigned long size, void *data);
1431e14ab23dSMatt Fleming 
143221b3ddd3SSylvain Chouleur int efivar_entry_iter_begin(void);
1433e14ab23dSMatt Fleming void efivar_entry_iter_end(void);
1434e14ab23dSMatt Fleming 
1435e14ab23dSMatt Fleming int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1436e14ab23dSMatt Fleming 			struct list_head *head, void *data,
1437e14ab23dSMatt Fleming 			struct efivar_entry **prev);
1438e14ab23dSMatt Fleming int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1439e14ab23dSMatt Fleming 		      struct list_head *head, void *data);
1440e14ab23dSMatt Fleming 
1441e14ab23dSMatt Fleming struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
1442e14ab23dSMatt Fleming 				       struct list_head *head, bool remove);
1443e14ab23dSMatt Fleming 
14448282f5d9SPeter Jones bool efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
14458282f5d9SPeter Jones 		     unsigned long data_size);
1446ed8b0de5SPeter Jones bool efivar_variable_is_removable(efi_guid_t vendor, const char *name,
1447ed8b0de5SPeter Jones 				  size_t len);
1448e14ab23dSMatt Fleming 
1449a9499fa7STom Gundersen extern struct work_struct efivar_work;
145004851772SMatt Fleming void efivar_run_worker(void);
145104851772SMatt Fleming 
1452a9499fa7STom Gundersen #if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
1453e14ab23dSMatt Fleming int efivars_sysfs_init(void);
14544fc756bdSMike Waychison 
1455e0d59733SSeiji Aguchi #define EFIVARS_DATA_SIZE_MAX 1024
1456e0d59733SSeiji Aguchi 
14574fc756bdSMike Waychison #endif /* CONFIG_EFI_VARS */
1458f0133f3cSMatt Fleming extern bool efi_capsule_pending(int *reset_type);
1459f0133f3cSMatt Fleming 
1460f0133f3cSMatt Fleming extern int efi_capsule_supported(efi_guid_t guid, u32 flags,
1461f0133f3cSMatt Fleming 				 size_t size, int *reset);
1462f0133f3cSMatt Fleming 
1463f0133f3cSMatt Fleming extern int efi_capsule_update(efi_capsule_header_t *capsule,
14642a457fb3SArd Biesheuvel 			      phys_addr_t *pages);
14654fc756bdSMike Waychison 
1466926172d4SDave Young #ifdef CONFIG_EFI_RUNTIME_MAP
1467926172d4SDave Young int efi_runtime_map_init(struct kobject *);
14686a2c20e7SVivek Goyal int efi_get_runtime_map_size(void);
14696a2c20e7SVivek Goyal int efi_get_runtime_map_desc_size(void);
14706a2c20e7SVivek Goyal int efi_runtime_map_copy(void *buf, size_t bufsz);
1471926172d4SDave Young #else
1472926172d4SDave Young static inline int efi_runtime_map_init(struct kobject *kobj)
1473926172d4SDave Young {
1474926172d4SDave Young 	return 0;
1475926172d4SDave Young }
1476926172d4SDave Young 
14776a2c20e7SVivek Goyal static inline int efi_get_runtime_map_size(void)
14786a2c20e7SVivek Goyal {
14796a2c20e7SVivek Goyal 	return 0;
14806a2c20e7SVivek Goyal }
14816a2c20e7SVivek Goyal 
14826a2c20e7SVivek Goyal static inline int efi_get_runtime_map_desc_size(void)
14836a2c20e7SVivek Goyal {
14846a2c20e7SVivek Goyal 	return 0;
14856a2c20e7SVivek Goyal }
14866a2c20e7SVivek Goyal 
14876a2c20e7SVivek Goyal static inline int efi_runtime_map_copy(void *buf, size_t bufsz)
14886a2c20e7SVivek Goyal {
14896a2c20e7SVivek Goyal 	return 0;
14906a2c20e7SVivek Goyal }
14916a2c20e7SVivek Goyal 
1492926172d4SDave Young #endif
1493926172d4SDave Young 
1494bd669475SArd Biesheuvel /* prototypes shared between arch specific and generic stub code */
1495bd669475SArd Biesheuvel 
14968173ec79SArd Biesheuvel void efi_printk(char *str);
1497bd669475SArd Biesheuvel 
1498*cd33a5c1SArd Biesheuvel void efi_free(unsigned long size, unsigned long addr);
1499bd669475SArd Biesheuvel 
1500*cd33a5c1SArd Biesheuvel char *efi_convert_cmdline(efi_loaded_image_t *image, int *cmd_line_len);
1501bd669475SArd Biesheuvel 
1502*cd33a5c1SArd Biesheuvel efi_status_t efi_get_memory_map(struct efi_boot_memmap *map);
1503bd669475SArd Biesheuvel 
1504*cd33a5c1SArd Biesheuvel efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align,
1505220dd769SKairui Song 				 unsigned long *addr, unsigned long min);
1506220dd769SKairui Song 
1507220dd769SKairui Song static inline
1508*cd33a5c1SArd Biesheuvel efi_status_t efi_low_alloc(unsigned long size, unsigned long align,
1509220dd769SKairui Song 			   unsigned long *addr)
1510220dd769SKairui Song {
1511220dd769SKairui Song 	/*
1512220dd769SKairui Song 	 * Don't allocate at 0x0. It will confuse code that
1513220dd769SKairui Song 	 * checks pointers against NULL. Skip the first 8
1514220dd769SKairui Song 	 * bytes so we start at a nice even number.
1515220dd769SKairui Song 	 */
1516*cd33a5c1SArd Biesheuvel 	return efi_low_alloc_above(size, align, addr, 0x8);
1517220dd769SKairui Song }
1518bd669475SArd Biesheuvel 
1519*cd33a5c1SArd Biesheuvel efi_status_t efi_high_alloc(unsigned long size, unsigned long align,
1520bd669475SArd Biesheuvel 			    unsigned long *addr, unsigned long max);
1521bd669475SArd Biesheuvel 
1522*cd33a5c1SArd Biesheuvel efi_status_t efi_relocate_kernel(unsigned long *image_addr,
1523bd669475SArd Biesheuvel 				 unsigned long image_size,
1524bd669475SArd Biesheuvel 				 unsigned long alloc_size,
1525bd669475SArd Biesheuvel 				 unsigned long preferred_addr,
1526220dd769SKairui Song 				 unsigned long alignment,
1527220dd769SKairui Song 				 unsigned long min_addr);
1528bd669475SArd Biesheuvel 
1529*cd33a5c1SArd Biesheuvel efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
1530bd669475SArd Biesheuvel 				  char *cmd_line, char *option_string,
1531bd669475SArd Biesheuvel 				  unsigned long max_addr,
1532bd669475SArd Biesheuvel 				  unsigned long *load_addr,
1533bd669475SArd Biesheuvel 				  unsigned long *load_size);
1534bd669475SArd Biesheuvel 
153560f38de7SArd Biesheuvel efi_status_t efi_parse_options(char const *cmdline);
15365a17dae4SMatt Fleming 
1537*cd33a5c1SArd Biesheuvel efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto,
15382c23b73cSArd Biesheuvel 			   unsigned long size);
15392c23b73cSArd Biesheuvel 
15400082517fSJian-Hong Pan #ifdef CONFIG_EFI
15410082517fSJian-Hong Pan extern bool efi_runtime_disabled(void);
15420082517fSJian-Hong Pan #else
15430082517fSJian-Hong Pan static inline bool efi_runtime_disabled(void) { return true; }
15440082517fSJian-Hong Pan #endif
15450082517fSJian-Hong Pan 
154680e75596SAlex Thorlton extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
154713b210ddSJulien Thierry extern unsigned long efi_call_virt_save_flags(void);
154880e75596SAlex Thorlton 
1549de8cb458SDavid Howells enum efi_secureboot_mode {
1550de8cb458SDavid Howells 	efi_secureboot_mode_unset,
1551de8cb458SDavid Howells 	efi_secureboot_mode_unknown,
1552de8cb458SDavid Howells 	efi_secureboot_mode_disabled,
1553de8cb458SDavid Howells 	efi_secureboot_mode_enabled,
1554de8cb458SDavid Howells };
1555*cd33a5c1SArd Biesheuvel enum efi_secureboot_mode efi_get_secureboot(void);
1556de8cb458SDavid Howells 
1557ccc829baSMatthew Garrett #ifdef CONFIG_RESET_ATTACK_MITIGATION
1558*cd33a5c1SArd Biesheuvel void efi_enable_reset_attack_mitigation(void);
1559ccc829baSMatthew Garrett #else
1560ccc829baSMatthew Garrett static inline void
1561*cd33a5c1SArd Biesheuvel efi_enable_reset_attack_mitigation(void) { }
1562ccc829baSMatthew Garrett #endif
1563ccc829baSMatthew Garrett 
1564*cd33a5c1SArd Biesheuvel efi_status_t efi_random_get_seed(void);
15650d959814SDominik Brodowski 
1566*cd33a5c1SArd Biesheuvel void efi_retrieve_tpm2_eventlog(void);
156733b6d034SThiebaud Weksteen 
156880e75596SAlex Thorlton /*
156980e75596SAlex Thorlton  * Arch code can implement the following three template macros, avoiding
157080e75596SAlex Thorlton  * reptition for the void/non-void return cases of {__,}efi_call_virt():
157180e75596SAlex Thorlton  *
157280e75596SAlex Thorlton  *  * arch_efi_call_virt_setup()
157380e75596SAlex Thorlton  *
157480e75596SAlex Thorlton  *    Sets up the environment for the call (e.g. switching page tables,
157580e75596SAlex Thorlton  *    allowing kernel-mode use of floating point, if required).
157680e75596SAlex Thorlton  *
157780e75596SAlex Thorlton  *  * arch_efi_call_virt()
157880e75596SAlex Thorlton  *
157980e75596SAlex Thorlton  *    Performs the call. The last expression in the macro must be the call
158080e75596SAlex Thorlton  *    itself, allowing the logic to be shared by the void and non-void
158180e75596SAlex Thorlton  *    cases.
158280e75596SAlex Thorlton  *
158380e75596SAlex Thorlton  *  * arch_efi_call_virt_teardown()
158480e75596SAlex Thorlton  *
158580e75596SAlex Thorlton  *    Restores the usual kernel environment once the call has returned.
158680e75596SAlex Thorlton  */
158780e75596SAlex Thorlton 
158880e75596SAlex Thorlton #define efi_call_virt_pointer(p, f, args...)				\
158980e75596SAlex Thorlton ({									\
159080e75596SAlex Thorlton 	efi_status_t __s;						\
159180e75596SAlex Thorlton 	unsigned long __flags;						\
159280e75596SAlex Thorlton 									\
159380e75596SAlex Thorlton 	arch_efi_call_virt_setup();					\
159480e75596SAlex Thorlton 									\
159513b210ddSJulien Thierry 	__flags = efi_call_virt_save_flags();				\
159680e75596SAlex Thorlton 	__s = arch_efi_call_virt(p, f, args);				\
159780e75596SAlex Thorlton 	efi_call_virt_check_flags(__flags, __stringify(f));		\
159880e75596SAlex Thorlton 									\
159980e75596SAlex Thorlton 	arch_efi_call_virt_teardown();					\
160080e75596SAlex Thorlton 									\
160180e75596SAlex Thorlton 	__s;								\
160280e75596SAlex Thorlton })
160380e75596SAlex Thorlton 
160480e75596SAlex Thorlton #define __efi_call_virt_pointer(p, f, args...)				\
160580e75596SAlex Thorlton ({									\
160680e75596SAlex Thorlton 	unsigned long __flags;						\
160780e75596SAlex Thorlton 									\
160880e75596SAlex Thorlton 	arch_efi_call_virt_setup();					\
160980e75596SAlex Thorlton 									\
161013b210ddSJulien Thierry 	__flags = efi_call_virt_save_flags();				\
161180e75596SAlex Thorlton 	arch_efi_call_virt(p, f, args);					\
161280e75596SAlex Thorlton 	efi_call_virt_check_flags(__flags, __stringify(f));		\
161380e75596SAlex Thorlton 									\
161480e75596SAlex Thorlton 	arch_efi_call_virt_teardown();					\
161580e75596SAlex Thorlton })
161680e75596SAlex Thorlton 
1617fc07716bSJeffrey Hugo typedef efi_status_t (*efi_exit_boot_map_processing)(
1618fc07716bSJeffrey Hugo 	struct efi_boot_memmap *map,
1619fc07716bSJeffrey Hugo 	void *priv);
1620fc07716bSJeffrey Hugo 
1621*cd33a5c1SArd Biesheuvel efi_status_t efi_exit_boot_services(void *handle,
1622fc07716bSJeffrey Hugo 				    struct efi_boot_memmap *map,
1623fc07716bSJeffrey Hugo 				    void *priv,
1624fc07716bSJeffrey Hugo 				    efi_exit_boot_map_processing priv_func);
162563625988SArd Biesheuvel 
1626c2ceb5fdSArd Biesheuvel #define EFI_RANDOM_SEED_SIZE		64U
1627c2ceb5fdSArd Biesheuvel 
162863625988SArd Biesheuvel struct linux_efi_random_seed {
162963625988SArd Biesheuvel 	u32	size;
163063625988SArd Biesheuvel 	u8	bits[];
163163625988SArd Biesheuvel };
163263625988SArd Biesheuvel 
163333b6d034SThiebaud Weksteen struct linux_efi_tpm_eventlog {
163433b6d034SThiebaud Weksteen 	u32	size;
1635166a2809SMatthew Garrett 	u32	final_events_preboot_size;
163633b6d034SThiebaud Weksteen 	u8	version;
163733b6d034SThiebaud Weksteen 	u8	log[];
163833b6d034SThiebaud Weksteen };
163933b6d034SThiebaud Weksteen 
164033b6d034SThiebaud Weksteen extern int efi_tpm_eventlog_init(void);
164133b6d034SThiebaud Weksteen 
1642c46f3405SMatthew Garrett struct efi_tcg2_final_events_table {
1643c46f3405SMatthew Garrett 	u64 version;
1644c46f3405SMatthew Garrett 	u64 nr_events;
1645c46f3405SMatthew Garrett 	u8 events[];
1646c46f3405SMatthew Garrett };
1647c46f3405SMatthew Garrett extern int efi_tpm_final_log_size;
1648c46f3405SMatthew Garrett 
16491c5fecb6SNarendra K extern unsigned long rci2_table_phys;
16501c5fecb6SNarendra K 
16513425d934SSai Praneeth /*
16523425d934SSai Praneeth  * efi_runtime_service() function identifiers.
16533425d934SSai Praneeth  * "NONE" is used by efi_recover_from_page_fault() to check if the page
16543425d934SSai Praneeth  * fault happened while executing an efi runtime service.
16553425d934SSai Praneeth  */
16569dbbedaaSSai Praneeth enum efi_rts_ids {
16575c418dc7SAnders Roxell 	EFI_NONE,
16585c418dc7SAnders Roxell 	EFI_GET_TIME,
16595c418dc7SAnders Roxell 	EFI_SET_TIME,
16605c418dc7SAnders Roxell 	EFI_GET_WAKEUP_TIME,
16615c418dc7SAnders Roxell 	EFI_SET_WAKEUP_TIME,
16625c418dc7SAnders Roxell 	EFI_GET_VARIABLE,
16635c418dc7SAnders Roxell 	EFI_GET_NEXT_VARIABLE,
16645c418dc7SAnders Roxell 	EFI_SET_VARIABLE,
16655c418dc7SAnders Roxell 	EFI_QUERY_VARIABLE_INFO,
16665c418dc7SAnders Roxell 	EFI_GET_NEXT_HIGH_MONO_COUNT,
16675c418dc7SAnders Roxell 	EFI_RESET_SYSTEM,
16685c418dc7SAnders Roxell 	EFI_UPDATE_CAPSULE,
16695c418dc7SAnders Roxell 	EFI_QUERY_CAPSULE_CAPS,
16709dbbedaaSSai Praneeth };
16719dbbedaaSSai Praneeth 
16729dbbedaaSSai Praneeth /*
16739dbbedaaSSai Praneeth  * efi_runtime_work:	Details of EFI Runtime Service work
16749dbbedaaSSai Praneeth  * @arg<1-5>:		EFI Runtime Service function arguments
16759dbbedaaSSai Praneeth  * @status:		Status of executing EFI Runtime Service
16769dbbedaaSSai Praneeth  * @efi_rts_id:		EFI Runtime Service function identifier
16779dbbedaaSSai Praneeth  * @efi_rts_comp:	Struct used for handling completions
16789dbbedaaSSai Praneeth  */
16799dbbedaaSSai Praneeth struct efi_runtime_work {
16809dbbedaaSSai Praneeth 	void *arg1;
16819dbbedaaSSai Praneeth 	void *arg2;
16829dbbedaaSSai Praneeth 	void *arg3;
16839dbbedaaSSai Praneeth 	void *arg4;
16849dbbedaaSSai Praneeth 	void *arg5;
16859dbbedaaSSai Praneeth 	efi_status_t status;
16869dbbedaaSSai Praneeth 	struct work_struct work;
16879dbbedaaSSai Praneeth 	enum efi_rts_ids efi_rts_id;
16889dbbedaaSSai Praneeth 	struct completion efi_rts_comp;
16899dbbedaaSSai Praneeth };
16909dbbedaaSSai Praneeth 
16919dbbedaaSSai Praneeth extern struct efi_runtime_work efi_rts_work;
16929dbbedaaSSai Praneeth 
16933eb420e7SSai Praneeth /* Workqueue to queue EFI Runtime Services */
16943eb420e7SSai Praneeth extern struct workqueue_struct *efi_rts_wq;
16953eb420e7SSai Praneeth 
169671e0940dSArd Biesheuvel struct linux_efi_memreserve {
16975f0b0ecfSArd Biesheuvel 	int		size;			// allocated size of the array
16985f0b0ecfSArd Biesheuvel 	atomic_t	count;			// number of entries used
16995f0b0ecfSArd Biesheuvel 	phys_addr_t	next;			// pa of next struct instance
17005f0b0ecfSArd Biesheuvel 	struct {
170171e0940dSArd Biesheuvel 		phys_addr_t	base;
170271e0940dSArd Biesheuvel 		phys_addr_t	size;
17035f0b0ecfSArd Biesheuvel 	} entry[0];
170471e0940dSArd Biesheuvel };
170571e0940dSArd Biesheuvel 
17065f0b0ecfSArd Biesheuvel #define EFI_MEMRESERVE_SIZE(count) (sizeof(struct linux_efi_memreserve) + \
17075f0b0ecfSArd Biesheuvel 	(count) * sizeof(((struct linux_efi_memreserve *)0)->entry[0]))
17085f0b0ecfSArd Biesheuvel 
170980424b02SArd Biesheuvel #define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \
171080424b02SArd Biesheuvel 	/ sizeof(((struct linux_efi_memreserve *)0)->entry[0]))
171180424b02SArd Biesheuvel 
17121da177e4SLinus Torvalds #endif /* _LINUX_EFI_H */
1713