xref: /openbmc/linux/include/linux/efi.h (revision 8f24f8c2fc82f701866419dcb594e2cc1d3f46ba)
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 
51*8f24f8c2SArd Biesheuvel #ifdef CONFIG_X86_64
52*8f24f8c2SArd Biesheuvel #define __efiapi __attribute__((ms_abi))
53*8f24f8c2SArd Biesheuvel #else
54*8f24f8c2SArd Biesheuvel #define __efiapi
55*8f24f8c2SArd Biesheuvel #endif
56*8f24f8c2SArd 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;
281*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *allocate_pages)(int, int, unsigned long,
282ed37ddffSRoy Franz 							efi_physical_addr_t *);
283*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *free_pages)(efi_physical_addr_t,
284*8f24f8c2SArd Biesheuvel 						    unsigned long);
285*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *get_memory_map)(unsigned long *, void *,
286*8f24f8c2SArd Biesheuvel 							unsigned long *,
287ed37ddffSRoy Franz 							unsigned long *, u32 *);
288*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *allocate_pool)(int, unsigned long,
289*8f24f8c2SArd Biesheuvel 						       void **);
290*8f24f8c2SArd 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;
300*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *handle_protocol)(efi_handle_t,
301*8f24f8c2SArd Biesheuvel 							 efi_guid_t *, void **);
302f30ca6baSMatt Fleming 		void *__reserved;
303f30ca6baSMatt Fleming 		void *register_protocol_notify;
304*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *locate_handle)(int, efi_guid_t *,
305*8f24f8c2SArd Biesheuvel 						       void *, unsigned long *,
306*8f24f8c2SArd Biesheuvel 						       efi_handle_t *);
307f30ca6baSMatt Fleming 		void *locate_device_path;
308*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *install_configuration_table)(efi_guid_t *,
309*8f24f8c2SArd Biesheuvel 								     void *);
310f30ca6baSMatt Fleming 		void *load_image;
311f30ca6baSMatt Fleming 		void *start_image;
312f30ca6baSMatt Fleming 		void *exit;
313f30ca6baSMatt Fleming 		void *unload_image;
314*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *exit_boot_services)(efi_handle_t,
315*8f24f8c2SArd 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;
326*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *,
327*8f24f8c2SArd 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
371*8f24f8c2SArd Biesheuvel efi_status_t (__efiapi *efi_pci_io_protocol_cfg_t)(efi_pci_io_protocol_t *,
3721786e830SArd Biesheuvel 						   EFI_PCI_IO_PROTOCOL_WIDTH,
373*8f24f8c2SArd Biesheuvel 						   u32 offset,
374*8f24f8c2SArd 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;
400*8f24f8c2SArd 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,
404*8f24f8c2SArd 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;
459*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *get)(apple_properties_protocol_t *,
460*8f24f8c2SArd Biesheuvel 					     struct efi_dev_path *,
461*8f24f8c2SArd Biesheuvel 					     efi_char16_t *, void *, u32 *);
462*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *set)(apple_properties_protocol_t *,
463*8f24f8c2SArd Biesheuvel 					     struct efi_dev_path *,
464*8f24f8c2SArd Biesheuvel 					     efi_char16_t *, void *, u32);
465*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *del)(apple_properties_protocol_t *,
466*8f24f8c2SArd Biesheuvel 					     struct efi_dev_path *,
467*8f24f8c2SArd Biesheuvel 					     efi_char16_t *);
468*8f24f8c2SArd 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;
487*8f24f8c2SArd 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;
595*8f24f8c2SArd Biesheuvel 		efi_get_time_t __efiapi			*get_time;
596*8f24f8c2SArd Biesheuvel 		efi_set_time_t __efiapi			*set_time;
597*8f24f8c2SArd Biesheuvel 		efi_get_wakeup_time_t __efiapi		*get_wakeup_time;
598*8f24f8c2SArd Biesheuvel 		efi_set_wakeup_time_t __efiapi		*set_wakeup_time;
599*8f24f8c2SArd Biesheuvel 		efi_set_virtual_address_map_t __efiapi	*set_virtual_address_map;
600c4c39c70SArd Biesheuvel 		void					*convert_pointer;
601*8f24f8c2SArd Biesheuvel 		efi_get_variable_t __efiapi		*get_variable;
602*8f24f8c2SArd Biesheuvel 		efi_get_next_variable_t __efiapi	*get_next_variable;
603*8f24f8c2SArd Biesheuvel 		efi_set_variable_t __efiapi		*set_variable;
604*8f24f8c2SArd Biesheuvel 		efi_get_next_high_mono_count_t __efiapi	*get_next_high_mono_count;
605*8f24f8c2SArd Biesheuvel 		efi_reset_system_t __efiapi		*reset_system;
606*8f24f8c2SArd Biesheuvel 		efi_update_capsule_t __efiapi		*update_capsule;
607*8f24f8c2SArd Biesheuvel 		efi_query_capsule_caps_t __efiapi	*query_capsule_caps;
608*8f24f8c2SArd 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 
8091786e830SArd Biesheuvel typedef union efi_loaded_image efi_loaded_image_t;
8101786e830SArd Biesheuvel 
8111786e830SArd Biesheuvel union efi_loaded_image {
8121786e830SArd Biesheuvel 	struct {
813677703ceSMatt Fleming 		u32 revision;
8149fa76ca7SArvind Sankar 		efi_handle_t parent_handle;
8158e84f345SMatt Fleming 		efi_system_table_t *system_table;
8169fa76ca7SArvind Sankar 		efi_handle_t device_handle;
8178e84f345SMatt Fleming 		void *file_path;
8188e84f345SMatt Fleming 		void *reserved;
8198e84f345SMatt Fleming 		u32 load_options_size;
8208e84f345SMatt Fleming 		void *load_options;
8218e84f345SMatt Fleming 		void *image_base;
8228e84f345SMatt Fleming 		__aligned_u64 image_size;
8238e84f345SMatt Fleming 		unsigned int image_code_type;
8248e84f345SMatt Fleming 		unsigned int image_data_type;
825*8f24f8c2SArd Biesheuvel 		efi_status_t ( __efiapi *unload)(efi_handle_t image_handle);
8261786e830SArd Biesheuvel 	};
8271786e830SArd Biesheuvel 	struct {
8281786e830SArd Biesheuvel 		u32 revision;
8291786e830SArd Biesheuvel 		u32 parent_handle;
8301786e830SArd Biesheuvel 		u32 system_table;
8311786e830SArd Biesheuvel 		u32 device_handle;
8321786e830SArd Biesheuvel 		u32 file_path;
8331786e830SArd Biesheuvel 		u32 reserved;
8341786e830SArd Biesheuvel 		u32 load_options_size;
8351786e830SArd Biesheuvel 		u32 load_options;
8361786e830SArd Biesheuvel 		u32 image_base;
8371786e830SArd Biesheuvel 		__aligned_u64 image_size;
8381786e830SArd Biesheuvel 		unsigned int image_code_type;
8391786e830SArd Biesheuvel 		unsigned int image_data_type;
8401786e830SArd Biesheuvel 		u32 unload;
8411786e830SArd Biesheuvel 	} mixed_mode;
8421786e830SArd Biesheuvel };
84355839d51SMatt Fleming 
84455839d51SMatt Fleming typedef struct {
84555839d51SMatt Fleming 	u64 size;
84655839d51SMatt Fleming 	u64 file_size;
84755839d51SMatt Fleming 	u64 phys_size;
84855839d51SMatt Fleming 	efi_time_t create_time;
84955839d51SMatt Fleming 	efi_time_t last_access_time;
85055839d51SMatt Fleming 	efi_time_t modification_time;
85155839d51SMatt Fleming 	__aligned_u64 attribute;
85255839d51SMatt Fleming 	efi_char16_t filename[1];
85355839d51SMatt Fleming } efi_file_info_t;
85455839d51SMatt Fleming 
8551786e830SArd Biesheuvel typedef union efi_file_handle efi_file_handle_t;
8561786e830SArd Biesheuvel 
8571786e830SArd Biesheuvel union efi_file_handle {
8581786e830SArd Biesheuvel 	struct {
85955839d51SMatt Fleming 		u64 revision;
860*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *open)(efi_file_handle_t *,
8611786e830SArd Biesheuvel 					      efi_file_handle_t **,
862ed37ddffSRoy Franz 					      efi_char16_t *, u64, u64);
863*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *close)(efi_file_handle_t *);
86455839d51SMatt Fleming 		void *delete;
865*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *read)(efi_file_handle_t *,
866*8f24f8c2SArd Biesheuvel 					      unsigned long *, void *);
86755839d51SMatt Fleming 		void *write;
86855839d51SMatt Fleming 		void *get_position;
86955839d51SMatt Fleming 		void *set_position;
870*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *get_info)(efi_file_handle_t *,
871*8f24f8c2SArd Biesheuvel 						  efi_guid_t *, unsigned long *,
872*8f24f8c2SArd Biesheuvel 						  void *);
87355839d51SMatt Fleming 		void *set_info;
87455839d51SMatt Fleming 		void *flush;
8751786e830SArd Biesheuvel 	};
8761786e830SArd Biesheuvel 	struct {
8771786e830SArd Biesheuvel 		u64 revision;
8781786e830SArd Biesheuvel 		u32 open;
8791786e830SArd Biesheuvel 		u32 close;
8801786e830SArd Biesheuvel 		u32 delete;
8811786e830SArd Biesheuvel 		u32 read;
8821786e830SArd Biesheuvel 		u32 write;
8831786e830SArd Biesheuvel 		u32 get_position;
8841786e830SArd Biesheuvel 		u32 set_position;
8851786e830SArd Biesheuvel 		u32 get_info;
8861786e830SArd Biesheuvel 		u32 set_info;
8871786e830SArd Biesheuvel 		u32 flush;
8881786e830SArd Biesheuvel 	} mixed_mode;
8891786e830SArd Biesheuvel };
89055839d51SMatt Fleming 
8911786e830SArd Biesheuvel typedef union efi_file_io_interface efi_file_io_interface_t;
8921786e830SArd Biesheuvel 
8931786e830SArd Biesheuvel union efi_file_io_interface {
8941786e830SArd Biesheuvel 	struct {
895ed37ddffSRoy Franz 		u64 revision;
896*8f24f8c2SArd Biesheuvel 		int (__efiapi *open_volume)(efi_file_io_interface_t *,
897ed37ddffSRoy Franz 					    efi_file_handle_t **);
8981786e830SArd Biesheuvel 	};
8991786e830SArd Biesheuvel 	struct {
9001786e830SArd Biesheuvel 		u64 revision;
9011786e830SArd Biesheuvel 		u32 open_volume;
9021786e830SArd Biesheuvel 	} mixed_mode;
9031786e830SArd Biesheuvel };
904ed37ddffSRoy Franz 
90555839d51SMatt Fleming #define EFI_FILE_MODE_READ	0x0000000000000001
90655839d51SMatt Fleming #define EFI_FILE_MODE_WRITE	0x0000000000000002
90755839d51SMatt Fleming #define EFI_FILE_MODE_CREATE	0x8000000000000000
90855839d51SMatt Fleming 
909bf924863SArd Biesheuvel typedef struct {
910bf924863SArd Biesheuvel 	u32 version;
911bf924863SArd Biesheuvel 	u32 length;
912bf924863SArd Biesheuvel 	u64 memory_protection_attribute;
913bf924863SArd Biesheuvel } efi_properties_table_t;
914bf924863SArd Biesheuvel 
915bf924863SArd Biesheuvel #define EFI_PROPERTIES_TABLE_VERSION	0x00010000
916bf924863SArd Biesheuvel #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA	0x1
917bf924863SArd Biesheuvel 
918b2c99e3cSBjorn Helgaas #define EFI_INVALID_TABLE_ADDR		(~0UL)
919b2c99e3cSBjorn Helgaas 
920a604af07SArd Biesheuvel typedef struct {
921a604af07SArd Biesheuvel 	u32 version;
922a604af07SArd Biesheuvel 	u32 num_entries;
923a604af07SArd Biesheuvel 	u32 desc_size;
924a604af07SArd Biesheuvel 	u32 reserved;
925a604af07SArd Biesheuvel 	efi_memory_desc_t entry[0];
926a604af07SArd Biesheuvel } efi_memory_attributes_table_t;
927a604af07SArd Biesheuvel 
9285c126ba2SDave Howells typedef struct {
9295c126ba2SDave Howells 	efi_guid_t signature_owner;
9305c126ba2SDave Howells 	u8 signature_data[];
9315c126ba2SDave Howells } efi_signature_data_t;
9325c126ba2SDave Howells 
9335c126ba2SDave Howells typedef struct {
9345c126ba2SDave Howells 	efi_guid_t signature_type;
9355c126ba2SDave Howells 	u32 signature_list_size;
9365c126ba2SDave Howells 	u32 signature_header_size;
9375c126ba2SDave Howells 	u32 signature_size;
9385c126ba2SDave Howells 	u8 signature_header[];
9395c126ba2SDave Howells 	/* efi_signature_data_t signatures[][] */
9405c126ba2SDave Howells } efi_signature_list_t;
9415c126ba2SDave Howells 
9425c126ba2SDave Howells typedef u8 efi_sha256_hash_t[32];
9435c126ba2SDave Howells 
9445c126ba2SDave Howells typedef struct {
9455c126ba2SDave Howells 	efi_sha256_hash_t to_be_signed_hash;
9465c126ba2SDave Howells 	efi_time_t time_of_revocation;
9475c126ba2SDave Howells } efi_cert_x509_sha256_t;
9485c126ba2SDave Howells 
9491da177e4SLinus Torvalds /*
9501da177e4SLinus Torvalds  * All runtime access to EFI goes through this structure:
9511da177e4SLinus Torvalds  */
9521da177e4SLinus Torvalds extern struct efi {
9531da177e4SLinus Torvalds 	efi_system_table_t *systab;	/* EFI system table */
9543b370237SMatthew Garrett 	unsigned int runtime_version;	/* Runtime services version */
955b2c99e3cSBjorn Helgaas 	unsigned long mps;		/* MPS table */
956b2c99e3cSBjorn Helgaas 	unsigned long acpi;		/* ACPI table  (IA64 ext 0.71) */
957b2c99e3cSBjorn Helgaas 	unsigned long acpi20;		/* ACPI table  (ACPI 2.0) */
958e1ccbbc9SArd Biesheuvel 	unsigned long smbios;		/* SMBIOS table (32 bit entry point) */
959e1ccbbc9SArd Biesheuvel 	unsigned long smbios3;		/* SMBIOS table (64 bit entry point) */
960b2c99e3cSBjorn Helgaas 	unsigned long boot_info;	/* boot info table */
961b2c99e3cSBjorn Helgaas 	unsigned long hcdp;		/* HCDP table */
962b2c99e3cSBjorn Helgaas 	unsigned long uga;		/* UGA table */
963a0998eb1SDave Young 	unsigned long fw_vendor;	/* fw_vendor */
964a0998eb1SDave Young 	unsigned long runtime;		/* runtime table */
965a0998eb1SDave Young 	unsigned long config_table;	/* config tables */
9660bb54905SPeter Jones 	unsigned long esrt;		/* ESRT table */
967bf924863SArd Biesheuvel 	unsigned long properties_table;	/* properties table */
968a604af07SArd Biesheuvel 	unsigned long mem_attr_table;	/* memory attributes table */
96963625988SArd Biesheuvel 	unsigned long rng_seed;		/* UEFI firmware random seed */
97033b6d034SThiebaud Weksteen 	unsigned long tpm_log;		/* TPM2 Event Log table */
971c46f3405SMatthew Garrett 	unsigned long tpm_final_log;	/* TPM2 Final Events Log table */
97271e0940dSArd Biesheuvel 	unsigned long mem_reserve;	/* Linux EFI memreserve table */
9731da177e4SLinus Torvalds 	efi_get_time_t *get_time;
9741da177e4SLinus Torvalds 	efi_set_time_t *set_time;
9751da177e4SLinus Torvalds 	efi_get_wakeup_time_t *get_wakeup_time;
9761da177e4SLinus Torvalds 	efi_set_wakeup_time_t *set_wakeup_time;
9771da177e4SLinus Torvalds 	efi_get_variable_t *get_variable;
9781da177e4SLinus Torvalds 	efi_get_next_variable_t *get_next_variable;
9791da177e4SLinus Torvalds 	efi_set_variable_t *set_variable;
98070d2a3cfSArd Biesheuvel 	efi_set_variable_t *set_variable_nonblocking;
9813b370237SMatthew Garrett 	efi_query_variable_info_t *query_variable_info;
982d3cac1f8SArd Biesheuvel 	efi_query_variable_info_t *query_variable_info_nonblocking;
9833b370237SMatthew Garrett 	efi_update_capsule_t *update_capsule;
9843b370237SMatthew Garrett 	efi_query_capsule_caps_t *query_capsule_caps;
9851da177e4SLinus Torvalds 	efi_get_next_high_mono_count_t *get_next_high_mono_count;
9861da177e4SLinus Torvalds 	efi_reset_system_t *reset_system;
9871da177e4SLinus Torvalds 	efi_set_virtual_address_map_t *set_virtual_address_map;
988884f4f66SMatt Fleming 	struct efi_memory_map memmap;
9893e909599SMatt Fleming 	unsigned long flags;
9901da177e4SLinus Torvalds } efi;
9911da177e4SLinus Torvalds 
9927e904a91SSai Praneeth extern struct mm_struct efi_mm;
9937e904a91SSai Praneeth 
9941da177e4SLinus Torvalds static inline int
9951da177e4SLinus Torvalds efi_guidcmp (efi_guid_t left, efi_guid_t right)
9961da177e4SLinus Torvalds {
9971da177e4SLinus Torvalds 	return memcmp(&left, &right, sizeof (efi_guid_t));
9981da177e4SLinus Torvalds }
9991da177e4SLinus Torvalds 
10001da177e4SLinus Torvalds static inline char *
100126e02272SBorislav Petkov efi_guid_to_str(efi_guid_t *guid, char *out)
10021da177e4SLinus Torvalds {
1003925ede0bSJoe Perches 	sprintf(out, "%pUl", guid->b);
10041da177e4SLinus Torvalds         return out;
10051da177e4SLinus Torvalds }
10061da177e4SLinus Torvalds 
10071da177e4SLinus Torvalds extern void efi_init (void);
10081da177e4SLinus Torvalds extern void *efi_get_pal_addr (void);
10091da177e4SLinus Torvalds extern void efi_map_pal_code (void);
10101da177e4SLinus Torvalds extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
101170f4f935SArnd Bergmann extern void efi_gettimeofday (struct timespec64 *ts);
10121da177e4SLinus Torvalds extern void efi_enter_virtual_mode (void);	/* switch EFI to virtual mode, if possible */
101378510792SJosh Triplett #ifdef CONFIG_X86
1014ca0e30dcSArd Biesheuvel extern efi_status_t efi_query_variable_store(u32 attributes,
1015ca0e30dcSArd Biesheuvel 					     unsigned long size,
1016ca0e30dcSArd Biesheuvel 					     bool nonblocking);
101778510792SJosh Triplett #else
1018a6e4d5a0SMatt Fleming 
1019ca0e30dcSArd Biesheuvel static inline efi_status_t efi_query_variable_store(u32 attributes,
1020ca0e30dcSArd Biesheuvel 						    unsigned long size,
1021ca0e30dcSArd Biesheuvel 						    bool nonblocking)
1022a6e4d5a0SMatt Fleming {
1023a6e4d5a0SMatt Fleming 	return EFI_SUCCESS;
1024a6e4d5a0SMatt Fleming }
102578510792SJosh Triplett #endif
10267bc90e01SJosh Triplett extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
10279479c7ceSMatt Fleming 
102820b1e22dSNicolai Stange extern phys_addr_t __init efi_memmap_alloc(unsigned int num_entries);
10299479c7ceSMatt Fleming extern int __init efi_memmap_init_early(struct efi_memory_map_data *data);
1030dca0f971SMatt Fleming extern int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size);
10319479c7ceSMatt Fleming extern void __init efi_memmap_unmap(void);
1032c45f4da3SMatt Fleming extern int __init efi_memmap_install(phys_addr_t addr, unsigned int nr_map);
103360863c0dSMatt Fleming extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
103460863c0dSMatt Fleming 					 struct range *range);
103560863c0dSMatt Fleming extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap,
103660863c0dSMatt Fleming 				     void *buf, struct efi_mem_range *mem);
10379479c7ceSMatt Fleming 
1038272686bfSLeif Lindholm extern int efi_config_init(efi_config_table_type_t *arch_tables);
10393846c158SPeter Jones #ifdef CONFIG_EFI_ESRT
10400bb54905SPeter Jones extern void __init efi_esrt_init(void);
10413846c158SPeter Jones #else
10423846c158SPeter Jones static inline void efi_esrt_init(void) { }
10433846c158SPeter Jones #endif
10447bb68410SArd Biesheuvel extern int efi_config_parse_tables(void *config_tables, int count, int sz,
10457bb68410SArd Biesheuvel 				   efi_config_table_type_t *arch_tables);
10461da177e4SLinus Torvalds extern u64 efi_get_iobase (void);
1047f99afd08STom Lendacky extern int efi_mem_type(unsigned long phys_addr);
10481da177e4SLinus Torvalds extern u64 efi_mem_attributes (unsigned long phys_addr);
104932e62c63SBjorn Helgaas extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
10501da177e4SLinus Torvalds extern int __init efi_uart_console_only (void);
10510bb54905SPeter Jones extern u64 efi_mem_desc_end(efi_memory_desc_t *md);
10520bb54905SPeter Jones extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
1053816e7612SMatt Fleming extern void efi_mem_reserve(phys_addr_t addr, u64 size);
1054a23d3bb0SArd Biesheuvel extern int efi_mem_reserve_persistent(phys_addr_t addr, u64 size);
10551da177e4SLinus Torvalds extern void efi_initialize_iomem_resources(struct resource *code_resource,
105600bf4098SBernhard Walle 		struct resource *data_resource, struct resource *bss_resource);
10577968c0e3SLeif Lindholm extern int efi_get_fdt_params(struct efi_fdt_params *params);
10580bb54905SPeter Jones extern struct kobject *efi_kobj;
10591da177e4SLinus Torvalds 
106044be28e9SMatt Fleming extern int efi_reboot_quirk_mode;
10610c5ed61aSMatt Fleming extern bool efi_poweroff_required(void);
10620c5ed61aSMatt Fleming 
10630f96a99dSTaku Izumi #ifdef CONFIG_EFI_FAKE_MEMMAP
10640f96a99dSTaku Izumi extern void __init efi_fake_memmap(void);
10650f96a99dSTaku Izumi #else
10660f96a99dSTaku Izumi static inline void efi_fake_memmap(void) { }
10670f96a99dSTaku Izumi #endif
10680f96a99dSTaku Izumi 
106910f0d2f5SArd Biesheuvel /*
107010f0d2f5SArd Biesheuvel  * efi_memattr_perm_setter - arch specific callback function passed into
107110f0d2f5SArd Biesheuvel  *                           efi_memattr_apply_permissions() that updates the
107210f0d2f5SArd Biesheuvel  *                           mapping permissions described by the second
107310f0d2f5SArd Biesheuvel  *                           argument in the page tables referred to by the
107410f0d2f5SArd Biesheuvel  *                           first argument.
107510f0d2f5SArd Biesheuvel  */
107610f0d2f5SArd Biesheuvel typedef int (*efi_memattr_perm_setter)(struct mm_struct *, efi_memory_desc_t *);
107710f0d2f5SArd Biesheuvel 
107810f0d2f5SArd Biesheuvel extern int efi_memattr_init(void);
107910f0d2f5SArd Biesheuvel extern int efi_memattr_apply_permissions(struct mm_struct *mm,
108010f0d2f5SArd Biesheuvel 					 efi_memattr_perm_setter fn);
108110f0d2f5SArd Biesheuvel 
108202e43c2dSBaoquan He /*
108302e43c2dSBaoquan He  * efi_early_memdesc_ptr - get the n-th EFI memmap descriptor
108402e43c2dSBaoquan He  * @map: the start of efi memmap
108502e43c2dSBaoquan He  * @desc_size: the size of space for each EFI memmap descriptor
108602e43c2dSBaoquan He  * @n: the index of efi memmap descriptor
108702e43c2dSBaoquan He  *
108802e43c2dSBaoquan He  * EFI boot service provides the GetMemoryMap() function to get a copy of the
108902e43c2dSBaoquan He  * current memory map which is an array of memory descriptors, each of
109002e43c2dSBaoquan He  * which describes a contiguous block of memory. It also gets the size of the
109102e43c2dSBaoquan He  * map, and the size of each descriptor, etc.
109202e43c2dSBaoquan He  *
109302e43c2dSBaoquan He  * Note that per section 6.2 of UEFI Spec 2.6 Errata A, the returned size of
109402e43c2dSBaoquan He  * each descriptor might not be equal to sizeof(efi_memory_memdesc_t),
109502e43c2dSBaoquan He  * since efi_memory_memdesc_t may be extended in the future. Thus the OS
109602e43c2dSBaoquan He  * MUST use the returned size of the descriptor to find the start of each
109702e43c2dSBaoquan He  * efi_memory_memdesc_t in the memory map array. This should only be used
109802e43c2dSBaoquan He  * during bootup since for_each_efi_memory_desc_xxx() is available after the
109902e43c2dSBaoquan He  * kernel initializes the EFI subsystem to set up struct efi_memory_map.
110002e43c2dSBaoquan He  */
110102e43c2dSBaoquan He #define efi_early_memdesc_ptr(map, desc_size, n)			\
110202e43c2dSBaoquan He 	(efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
110302e43c2dSBaoquan He 
1104e885cd80SMark Salter /* Iterate through an efi_memory_map */
110578ce248fSMatt Fleming #define for_each_efi_memory_desc_in_map(m, md)				   \
1106e885cd80SMark Salter 	for ((md) = (m)->map;						   \
1107d4c4fed0SJan Beulich 	     (md) && ((void *)(md) + (m)->desc_size) <= (m)->map_end;	   \
1108e885cd80SMark Salter 	     (md) = (void *)(md) + (m)->desc_size)
1109e885cd80SMark Salter 
111078ce248fSMatt Fleming /**
111178ce248fSMatt Fleming  * for_each_efi_memory_desc - iterate over descriptors in efi.memmap
111278ce248fSMatt Fleming  * @md: the efi_memory_desc_t * iterator
111378ce248fSMatt Fleming  *
111478ce248fSMatt Fleming  * Once the loop finishes @md must not be accessed.
111578ce248fSMatt Fleming  */
111678ce248fSMatt Fleming #define for_each_efi_memory_desc(md) \
1117884f4f66SMatt Fleming 	for_each_efi_memory_desc_in_map(&efi.memmap, md)
111878ce248fSMatt Fleming 
111998d2a6caSLaszlo Ersek /*
112098d2a6caSLaszlo Ersek  * Format an EFI memory descriptor's type and attributes to a user-provided
112198d2a6caSLaszlo Ersek  * character buffer, as per snprintf(), and return the buffer.
112298d2a6caSLaszlo Ersek  */
112398d2a6caSLaszlo Ersek char * __init efi_md_typeattr_format(char *buf, size_t size,
112498d2a6caSLaszlo Ersek 				     const efi_memory_desc_t *md);
112598d2a6caSLaszlo Ersek 
11260bc9ae39SDave Howells 
11270bc9ae39SDave Howells typedef void (*efi_element_handler_t)(const char *source,
11280bc9ae39SDave Howells 				      const void *element_data,
11290bc9ae39SDave Howells 				      size_t element_size);
11300bc9ae39SDave Howells extern int __init parse_efi_signature_list(
11310bc9ae39SDave Howells 	const char *source,
11320bc9ae39SDave Howells 	const void *data, size_t size,
11330bc9ae39SDave Howells 	efi_element_handler_t (*get_handler_for_guid)(const efi_guid_t *));
11340bc9ae39SDave Howells 
11351da177e4SLinus Torvalds /**
11361da177e4SLinus Torvalds  * efi_range_is_wc - check the WC bit on an address range
11371da177e4SLinus Torvalds  * @start: starting kvirt address
11381da177e4SLinus Torvalds  * @len: length of range
11391da177e4SLinus Torvalds  *
11401da177e4SLinus Torvalds  * Consult the EFI memory map and make sure it's ok to set this range WC.
11411da177e4SLinus Torvalds  * Returns true or false.
11421da177e4SLinus Torvalds  */
11431da177e4SLinus Torvalds static inline int efi_range_is_wc(unsigned long start, unsigned long len)
11441da177e4SLinus Torvalds {
1145986a80d5SJesper Juhl 	unsigned long i;
11461da177e4SLinus Torvalds 
11471da177e4SLinus Torvalds 	for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
11481da177e4SLinus Torvalds 		unsigned long paddr = __pa(start + i);
11491da177e4SLinus Torvalds 		if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
11501da177e4SLinus Torvalds 			return 0;
11511da177e4SLinus Torvalds 	}
11521da177e4SLinus Torvalds 	/* The range checked out */
11531da177e4SLinus Torvalds 	return 1;
11541da177e4SLinus Torvalds }
11551da177e4SLinus Torvalds 
11561da177e4SLinus Torvalds #ifdef CONFIG_EFI_PCDP
11571da177e4SLinus Torvalds extern int __init efi_setup_pcdp_console(char *);
11581da177e4SLinus Torvalds #endif
11591da177e4SLinus Torvalds 
11601da177e4SLinus Torvalds /*
116183e68189SMatt Fleming  * We play games with efi_enabled so that the compiler will, if
116283e68189SMatt Fleming  * possible, remove EFI-related code altogether.
11631da177e4SLinus Torvalds  */
116483e68189SMatt Fleming #define EFI_BOOT		0	/* Were we booted from EFI? */
116583e68189SMatt Fleming #define EFI_CONFIG_TABLES	2	/* Can we use EFI config tables? */
116683e68189SMatt Fleming #define EFI_RUNTIME_SERVICES	3	/* Can we use runtime services? */
116783e68189SMatt Fleming #define EFI_MEMMAP		4	/* Can we use EFI memory map? */
116883e68189SMatt Fleming #define EFI_64BIT		5	/* Is the firmware 64-bit? */
11699f27bc54SDaniel Kiper #define EFI_PARAVIRT		6	/* Access is via a paravirt interface */
11709f27bc54SDaniel Kiper #define EFI_ARCH_1		7	/* First arch-specific bit */
1171fed6cefeSBorislav Petkov #define EFI_DBG			8	/* Print additional debug info at runtime */
1172a1041713SArd Biesheuvel #define EFI_NX_PE_DATA		9	/* Can runtime data regions be mapped non-executable? */
1173a19ebf59SSai Praneeth #define EFI_MEM_ATTR		10	/* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */
1174b617c526SDan Williams #define EFI_MEM_NO_SOFT_RESERVE	11	/* Is the kernel configured to ignore soft reservations? */
117583e68189SMatt Fleming 
11761da177e4SLinus Torvalds #ifdef CONFIG_EFI
11773e909599SMatt Fleming /*
11783e909599SMatt Fleming  * Test whether the above EFI_* bits are enabled.
11793e909599SMatt Fleming  */
11803e909599SMatt Fleming static inline bool efi_enabled(int feature)
118183e68189SMatt Fleming {
11823e909599SMatt Fleming 	return test_bit(feature, &efi.flags) != 0;
11833e909599SMatt Fleming }
11848562c99cSMatt Fleming extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
1185b617c526SDan Williams 
1186b617c526SDan Williams bool __pure __efi_soft_reserve_enabled(void);
1187b617c526SDan Williams 
1188b617c526SDan Williams static inline bool __pure efi_soft_reserve_enabled(void)
1189b617c526SDan Williams {
1190b617c526SDan Williams 	return IS_ENABLED(CONFIG_EFI_SOFT_RESERVE)
1191b617c526SDan Williams 		&& __efi_soft_reserve_enabled();
1192b617c526SDan Williams }
11933e909599SMatt Fleming #else
11943e909599SMatt Fleming static inline bool efi_enabled(int feature)
11953e909599SMatt Fleming {
11963e909599SMatt Fleming 	return false;
119783e68189SMatt Fleming }
11988562c99cSMatt Fleming static inline void
11998562c99cSMatt Fleming efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
120087615a34SMatt Fleming 
120187615a34SMatt Fleming static inline bool
120287615a34SMatt Fleming efi_capsule_pending(int *reset_type)
120387615a34SMatt Fleming {
120487615a34SMatt Fleming 	return false;
120587615a34SMatt Fleming }
1206b617c526SDan Williams 
1207b617c526SDan Williams static inline bool efi_soft_reserve_enabled(void)
1208b617c526SDan Williams {
1209b617c526SDan Williams 	return false;
1210b617c526SDan Williams }
12111da177e4SLinus Torvalds #endif
12121da177e4SLinus Torvalds 
1213806b0351SMatt Fleming extern int efi_status_to_err(efi_status_t status);
1214806b0351SMatt Fleming 
12151da177e4SLinus Torvalds /*
12161da177e4SLinus Torvalds  * Variable Attributes
12171da177e4SLinus Torvalds  */
12181da177e4SLinus Torvalds #define EFI_VARIABLE_NON_VOLATILE       0x0000000000000001
12191da177e4SLinus Torvalds #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
12201da177e4SLinus Torvalds #define EFI_VARIABLE_RUNTIME_ACCESS     0x0000000000000004
122141b3254cSMatthew Garrett #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
122241b3254cSMatthew Garrett #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
122341b3254cSMatthew Garrett #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
122441b3254cSMatthew Garrett #define EFI_VARIABLE_APPEND_WRITE	0x0000000000000040
12251da177e4SLinus Torvalds 
122641b3254cSMatthew Garrett #define EFI_VARIABLE_MASK 	(EFI_VARIABLE_NON_VOLATILE | \
122741b3254cSMatthew Garrett 				EFI_VARIABLE_BOOTSERVICE_ACCESS | \
122841b3254cSMatthew Garrett 				EFI_VARIABLE_RUNTIME_ACCESS | \
122941b3254cSMatthew Garrett 				EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
123041b3254cSMatthew Garrett 				EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
123141b3254cSMatthew Garrett 				EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
123241b3254cSMatthew Garrett 				EFI_VARIABLE_APPEND_WRITE)
12331da177e4SLinus Torvalds /*
1234e14ab23dSMatt Fleming  * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
1235e14ab23dSMatt Fleming  * not including trailing NUL
1236e14ab23dSMatt Fleming  */
1237ba7e34b1SAndy Shevchenko #define EFI_VARIABLE_GUID_LEN	UUID_STRING_LEN
1238e14ab23dSMatt Fleming 
1239e14ab23dSMatt Fleming /*
1240e2527a7cSMatt Fleming  * The type of search to perform when calling boottime->locate_handle
1241e2527a7cSMatt Fleming  */
1242e2527a7cSMatt Fleming #define EFI_LOCATE_ALL_HANDLES			0
1243e2527a7cSMatt Fleming #define EFI_LOCATE_BY_REGISTER_NOTIFY		1
1244e2527a7cSMatt Fleming #define EFI_LOCATE_BY_PROTOCOL			2
1245e2527a7cSMatt Fleming 
1246e2527a7cSMatt Fleming /*
12471da177e4SLinus Torvalds  * EFI Device Path information
12481da177e4SLinus Torvalds  */
12491da177e4SLinus Torvalds #define EFI_DEV_HW			0x01
12501da177e4SLinus Torvalds #define  EFI_DEV_PCI				 1
12511da177e4SLinus Torvalds #define  EFI_DEV_PCCARD				 2
12521da177e4SLinus Torvalds #define  EFI_DEV_MEM_MAPPED			 3
12531da177e4SLinus Torvalds #define  EFI_DEV_VENDOR				 4
12541da177e4SLinus Torvalds #define  EFI_DEV_CONTROLLER			 5
12551da177e4SLinus Torvalds #define EFI_DEV_ACPI			0x02
12561da177e4SLinus Torvalds #define   EFI_DEV_BASIC_ACPI			 1
12571da177e4SLinus Torvalds #define   EFI_DEV_EXPANDED_ACPI			 2
12581da177e4SLinus Torvalds #define EFI_DEV_MSG			0x03
12591da177e4SLinus Torvalds #define   EFI_DEV_MSG_ATAPI			 1
12601da177e4SLinus Torvalds #define   EFI_DEV_MSG_SCSI			 2
12611da177e4SLinus Torvalds #define   EFI_DEV_MSG_FC			 3
12621da177e4SLinus Torvalds #define   EFI_DEV_MSG_1394			 4
12631da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB			 5
12641da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB_CLASS			15
12651da177e4SLinus Torvalds #define   EFI_DEV_MSG_I20			 6
12661da177e4SLinus Torvalds #define   EFI_DEV_MSG_MAC			11
12671da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV4			12
12681da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV6			13
12691da177e4SLinus Torvalds #define   EFI_DEV_MSG_INFINIBAND		 9
12701da177e4SLinus Torvalds #define   EFI_DEV_MSG_UART			14
12711da177e4SLinus Torvalds #define   EFI_DEV_MSG_VENDOR			10
12721da177e4SLinus Torvalds #define EFI_DEV_MEDIA			0x04
12731da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_HARD_DRIVE		 1
12741da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_CDROM			 2
12751da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_VENDOR			 3
12761da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_FILE			 4
12771da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_PROTOCOL		 5
12781da177e4SLinus Torvalds #define EFI_DEV_BIOS_BOOT		0x05
12791da177e4SLinus Torvalds #define EFI_DEV_END_PATH		0x7F
12801da177e4SLinus Torvalds #define EFI_DEV_END_PATH2		0xFF
12811da177e4SLinus Torvalds #define   EFI_DEV_END_INSTANCE			0x01
12821da177e4SLinus Torvalds #define   EFI_DEV_END_ENTIRE			0xFF
12831da177e4SLinus Torvalds 
12841da177e4SLinus Torvalds struct efi_generic_dev_path {
12851da177e4SLinus Torvalds 	u8 type;
12861da177e4SLinus Torvalds 	u8 sub_type;
12871da177e4SLinus Torvalds 	u16 length;
12881da177e4SLinus Torvalds } __attribute ((packed));
12891da177e4SLinus Torvalds 
129046cd4b75SLukas Wunner struct efi_dev_path {
129146cd4b75SLukas Wunner 	u8 type;	/* can be replaced with unnamed */
129246cd4b75SLukas Wunner 	u8 sub_type;	/* struct efi_generic_dev_path; */
129346cd4b75SLukas Wunner 	u16 length;	/* once we've moved to -std=c11 */
129446cd4b75SLukas Wunner 	union {
129546cd4b75SLukas Wunner 		struct {
129646cd4b75SLukas Wunner 			u32 hid;
129746cd4b75SLukas Wunner 			u32 uid;
129846cd4b75SLukas Wunner 		} acpi;
129946cd4b75SLukas Wunner 		struct {
130046cd4b75SLukas Wunner 			u8 fn;
130146cd4b75SLukas Wunner 			u8 dev;
130246cd4b75SLukas Wunner 		} pci;
130346cd4b75SLukas Wunner 	};
130446cd4b75SLukas Wunner } __attribute ((packed));
130546cd4b75SLukas Wunner 
130646cd4b75SLukas Wunner #if IS_ENABLED(CONFIG_EFI_DEV_PATH_PARSER)
130746cd4b75SLukas Wunner struct device *efi_get_device_by_path(struct efi_dev_path **node, size_t *len);
130846cd4b75SLukas Wunner #endif
130946cd4b75SLukas Wunner 
13104a3575fdSHuang, Ying static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
13114a3575fdSHuang, Ying {
13124a3575fdSHuang, Ying 	*npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
13134a3575fdSHuang, Ying 	*addr &= PAGE_MASK;
13144a3575fdSHuang, Ying }
13154a3575fdSHuang, Ying 
131604851772SMatt Fleming /*
13174fc756bdSMike Waychison  * EFI Variable support.
13184fc756bdSMike Waychison  *
13194fc756bdSMike Waychison  * Different firmware drivers can expose their EFI-like variables using
13204fc756bdSMike Waychison  * the following.
13214fc756bdSMike Waychison  */
13224fc756bdSMike Waychison 
13234fc756bdSMike Waychison struct efivar_operations {
13244fc756bdSMike Waychison 	efi_get_variable_t *get_variable;
13254fc756bdSMike Waychison 	efi_get_next_variable_t *get_next_variable;
13264fc756bdSMike Waychison 	efi_set_variable_t *set_variable;
132770d2a3cfSArd Biesheuvel 	efi_set_variable_t *set_variable_nonblocking;
1328a6e4d5a0SMatt Fleming 	efi_query_variable_store_t *query_variable_store;
13294fc756bdSMike Waychison };
13304fc756bdSMike Waychison 
13314fc756bdSMike Waychison struct efivars {
13324fc756bdSMike Waychison 	struct kset *kset;
1333605e70c7SLee, Chun-Yi 	struct kobject *kobject;
13344fc756bdSMike Waychison 	const struct efivar_operations *ops;
13354fc756bdSMike Waychison };
13364fc756bdSMike Waychison 
1337e14ab23dSMatt Fleming /*
1338e14ab23dSMatt Fleming  * The maximum size of VariableName + Data = 1024
1339e14ab23dSMatt Fleming  * Therefore, it's reasonable to save that much
1340e14ab23dSMatt Fleming  * space in each part of the structure,
1341e14ab23dSMatt Fleming  * and we use a page for reading/writing.
1342e14ab23dSMatt Fleming  */
1343e14ab23dSMatt Fleming 
1344a5d92ad3SMatt Fleming #define EFI_VAR_NAME_LEN	1024
1345a5d92ad3SMatt Fleming 
1346e14ab23dSMatt Fleming struct efi_variable {
1347a5d92ad3SMatt Fleming 	efi_char16_t  VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
1348e14ab23dSMatt Fleming 	efi_guid_t    VendorGuid;
1349e14ab23dSMatt Fleming 	unsigned long DataSize;
1350e14ab23dSMatt Fleming 	__u8          Data[1024];
1351e14ab23dSMatt Fleming 	efi_status_t  Status;
1352e14ab23dSMatt Fleming 	__u32         Attributes;
1353e14ab23dSMatt Fleming } __attribute__((packed));
1354e14ab23dSMatt Fleming 
1355e14ab23dSMatt Fleming struct efivar_entry {
1356e14ab23dSMatt Fleming 	struct efi_variable var;
1357e14ab23dSMatt Fleming 	struct list_head list;
1358e14ab23dSMatt Fleming 	struct kobject kobj;
1359e0d59733SSeiji Aguchi 	bool scanning;
1360e0d59733SSeiji Aguchi 	bool deleting;
1361e14ab23dSMatt Fleming };
1362e14ab23dSMatt Fleming 
13631786e830SArd Biesheuvel union efi_simple_text_output_protocol {
13641786e830SArd Biesheuvel 	struct {
1365ed37ddffSRoy Franz 		void *reset;
1366*8f24f8c2SArd Biesheuvel 		efi_status_t (__efiapi *output_string)(efi_simple_text_output_protocol_t *,
13671786e830SArd Biesheuvel 						       efi_char16_t *);
1368ed37ddffSRoy Franz 		void *test_string;
1369ed37ddffSRoy Franz 	};
13701786e830SArd Biesheuvel 	struct {
13711786e830SArd Biesheuvel 		u32 reset;
13721786e830SArd Biesheuvel 		u32 output_string;
13731786e830SArd Biesheuvel 		u32 test_string;
13741786e830SArd Biesheuvel 	} mixed_mode;
13751786e830SArd Biesheuvel };
1376ed37ddffSRoy Franz 
1377fc372064SArd Biesheuvel #define PIXEL_RGB_RESERVED_8BIT_PER_COLOR		0
1378fc372064SArd Biesheuvel #define PIXEL_BGR_RESERVED_8BIT_PER_COLOR		1
1379fc372064SArd Biesheuvel #define PIXEL_BIT_MASK					2
1380fc372064SArd Biesheuvel #define PIXEL_BLT_ONLY					3
1381fc372064SArd Biesheuvel #define PIXEL_FORMAT_MAX				4
1382fc372064SArd Biesheuvel 
138344c84b4aSArvind Sankar typedef struct {
1384fc372064SArd Biesheuvel 	u32 red_mask;
1385fc372064SArd Biesheuvel 	u32 green_mask;
1386fc372064SArd Biesheuvel 	u32 blue_mask;
1387fc372064SArd Biesheuvel 	u32 reserved_mask;
138844c84b4aSArvind Sankar } efi_pixel_bitmask_t;
1389fc372064SArd Biesheuvel 
139044c84b4aSArvind Sankar typedef struct {
1391fc372064SArd Biesheuvel 	u32 version;
1392fc372064SArd Biesheuvel 	u32 horizontal_resolution;
1393fc372064SArd Biesheuvel 	u32 vertical_resolution;
1394fc372064SArd Biesheuvel 	int pixel_format;
139544c84b4aSArvind Sankar 	efi_pixel_bitmask_t pixel_information;
1396fc372064SArd Biesheuvel 	u32 pixels_per_scan_line;
139744c84b4aSArvind Sankar } efi_graphics_output_mode_info_t;
1398fc372064SArd Biesheuvel 
13991786e830SArd Biesheuvel typedef union efi_graphics_output_protocol_mode efi_graphics_output_protocol_mode_t;
14001786e830SArd Biesheuvel 
14011786e830SArd Biesheuvel union efi_graphics_output_protocol_mode {
14021786e830SArd Biesheuvel 	struct {
1403fc372064SArd Biesheuvel 		u32 max_mode;
1404fc372064SArd Biesheuvel 		u32 mode;
140544c84b4aSArvind Sankar 		efi_graphics_output_mode_info_t *info;
1406fc372064SArd Biesheuvel 		unsigned long size_of_info;
140744c84b4aSArvind Sankar 		efi_physical_addr_t frame_buffer_base;
1408fc372064SArd Biesheuvel 		unsigned long frame_buffer_size;
14091786e830SArd Biesheuvel 	};
14101786e830SArd Biesheuvel 	struct {
14111786e830SArd Biesheuvel 		u32 max_mode;
14121786e830SArd Biesheuvel 		u32 mode;
14131786e830SArd Biesheuvel 		u32 info;
14141786e830SArd Biesheuvel 		u32 size_of_info;
14151786e830SArd Biesheuvel 		u64 frame_buffer_base;
14161786e830SArd Biesheuvel 		u32 frame_buffer_size;
14171786e830SArd Biesheuvel 	} mixed_mode;
14181786e830SArd Biesheuvel };
1419fc372064SArd Biesheuvel 
14201786e830SArd Biesheuvel typedef union efi_graphics_output_protocol efi_graphics_output_protocol_t;
14211786e830SArd Biesheuvel 
14221786e830SArd Biesheuvel union efi_graphics_output_protocol {
14231786e830SArd Biesheuvel 	struct {
142444c84b4aSArvind Sankar 		void *query_mode;
142544c84b4aSArvind Sankar 		void *set_mode;
142644c84b4aSArvind Sankar 		void *blt;
142744c84b4aSArvind Sankar 		efi_graphics_output_protocol_mode_t *mode;
14281786e830SArd Biesheuvel 	};
14291786e830SArd Biesheuvel 	struct {
14301786e830SArd Biesheuvel 		u32 query_mode;
14311786e830SArd Biesheuvel 		u32 set_mode;
14321786e830SArd Biesheuvel 		u32 blt;
14331786e830SArd Biesheuvel 		u32 mode;
14341786e830SArd Biesheuvel 	} mixed_mode;
14351786e830SArd Biesheuvel };
1436fc372064SArd Biesheuvel 
143704851772SMatt Fleming extern struct list_head efivar_sysfs_list;
143804851772SMatt Fleming 
143904851772SMatt Fleming static inline void
144004851772SMatt Fleming efivar_unregister(struct efivar_entry *var)
144104851772SMatt Fleming {
144204851772SMatt Fleming 	kobject_put(&var->kobj);
144304851772SMatt Fleming }
144404851772SMatt Fleming 
1445e14ab23dSMatt Fleming int efivars_register(struct efivars *efivars,
14464fc756bdSMike Waychison 		     const struct efivar_operations *ops,
1447e14ab23dSMatt Fleming 		     struct kobject *kobject);
1448e14ab23dSMatt Fleming int efivars_unregister(struct efivars *efivars);
1449e14ab23dSMatt Fleming struct kobject *efivars_kobject(void);
1450e14ab23dSMatt Fleming 
1451e14ab23dSMatt Fleming int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
14521cfd6316SJulia Lawall 		void *data, bool duplicates, struct list_head *head);
1453e14ab23dSMatt Fleming 
145421b3ddd3SSylvain Chouleur int efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
145521b3ddd3SSylvain Chouleur int efivar_entry_remove(struct efivar_entry *entry);
1456e14ab23dSMatt Fleming 
1457e14ab23dSMatt Fleming int __efivar_entry_delete(struct efivar_entry *entry);
1458e14ab23dSMatt Fleming int efivar_entry_delete(struct efivar_entry *entry);
1459e14ab23dSMatt Fleming 
1460e14ab23dSMatt Fleming int efivar_entry_size(struct efivar_entry *entry, unsigned long *size);
14618a415b8cSMatt Fleming int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
14628a415b8cSMatt Fleming 		       unsigned long *size, void *data);
1463e14ab23dSMatt Fleming int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
1464e14ab23dSMatt Fleming 		     unsigned long *size, void *data);
1465e14ab23dSMatt Fleming int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
1466e14ab23dSMatt Fleming 		     unsigned long size, void *data, struct list_head *head);
1467e14ab23dSMatt Fleming int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
1468e14ab23dSMatt Fleming 			      unsigned long *size, void *data, bool *set);
1469e14ab23dSMatt Fleming int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
1470e14ab23dSMatt Fleming 			  bool block, unsigned long size, void *data);
1471e14ab23dSMatt Fleming 
147221b3ddd3SSylvain Chouleur int efivar_entry_iter_begin(void);
1473e14ab23dSMatt Fleming void efivar_entry_iter_end(void);
1474e14ab23dSMatt Fleming 
1475e14ab23dSMatt Fleming int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1476e14ab23dSMatt Fleming 			struct list_head *head, void *data,
1477e14ab23dSMatt Fleming 			struct efivar_entry **prev);
1478e14ab23dSMatt Fleming int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
1479e14ab23dSMatt Fleming 		      struct list_head *head, void *data);
1480e14ab23dSMatt Fleming 
1481e14ab23dSMatt Fleming struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
1482e14ab23dSMatt Fleming 				       struct list_head *head, bool remove);
1483e14ab23dSMatt Fleming 
14848282f5d9SPeter Jones bool efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
14858282f5d9SPeter Jones 		     unsigned long data_size);
1486ed8b0de5SPeter Jones bool efivar_variable_is_removable(efi_guid_t vendor, const char *name,
1487ed8b0de5SPeter Jones 				  size_t len);
1488e14ab23dSMatt Fleming 
1489a9499fa7STom Gundersen extern struct work_struct efivar_work;
149004851772SMatt Fleming void efivar_run_worker(void);
149104851772SMatt Fleming 
1492a9499fa7STom Gundersen #if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
1493e14ab23dSMatt Fleming int efivars_sysfs_init(void);
14944fc756bdSMike Waychison 
1495e0d59733SSeiji Aguchi #define EFIVARS_DATA_SIZE_MAX 1024
1496e0d59733SSeiji Aguchi 
14974fc756bdSMike Waychison #endif /* CONFIG_EFI_VARS */
1498f0133f3cSMatt Fleming extern bool efi_capsule_pending(int *reset_type);
1499f0133f3cSMatt Fleming 
1500f0133f3cSMatt Fleming extern int efi_capsule_supported(efi_guid_t guid, u32 flags,
1501f0133f3cSMatt Fleming 				 size_t size, int *reset);
1502f0133f3cSMatt Fleming 
1503f0133f3cSMatt Fleming extern int efi_capsule_update(efi_capsule_header_t *capsule,
15042a457fb3SArd Biesheuvel 			      phys_addr_t *pages);
15054fc756bdSMike Waychison 
1506926172d4SDave Young #ifdef CONFIG_EFI_RUNTIME_MAP
1507926172d4SDave Young int efi_runtime_map_init(struct kobject *);
15086a2c20e7SVivek Goyal int efi_get_runtime_map_size(void);
15096a2c20e7SVivek Goyal int efi_get_runtime_map_desc_size(void);
15106a2c20e7SVivek Goyal int efi_runtime_map_copy(void *buf, size_t bufsz);
1511926172d4SDave Young #else
1512926172d4SDave Young static inline int efi_runtime_map_init(struct kobject *kobj)
1513926172d4SDave Young {
1514926172d4SDave Young 	return 0;
1515926172d4SDave Young }
1516926172d4SDave Young 
15176a2c20e7SVivek Goyal static inline int efi_get_runtime_map_size(void)
15186a2c20e7SVivek Goyal {
15196a2c20e7SVivek Goyal 	return 0;
15206a2c20e7SVivek Goyal }
15216a2c20e7SVivek Goyal 
15226a2c20e7SVivek Goyal static inline int efi_get_runtime_map_desc_size(void)
15236a2c20e7SVivek Goyal {
15246a2c20e7SVivek Goyal 	return 0;
15256a2c20e7SVivek Goyal }
15266a2c20e7SVivek Goyal 
15276a2c20e7SVivek Goyal static inline int efi_runtime_map_copy(void *buf, size_t bufsz)
15286a2c20e7SVivek Goyal {
15296a2c20e7SVivek Goyal 	return 0;
15306a2c20e7SVivek Goyal }
15316a2c20e7SVivek Goyal 
1532926172d4SDave Young #endif
1533926172d4SDave Young 
1534bd669475SArd Biesheuvel /* prototypes shared between arch specific and generic stub code */
1535bd669475SArd Biesheuvel 
1536bd669475SArd Biesheuvel void efi_printk(efi_system_table_t *sys_table_arg, char *str);
1537bd669475SArd Biesheuvel 
1538bd669475SArd Biesheuvel void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
1539bd669475SArd Biesheuvel 	      unsigned long addr);
1540bd669475SArd Biesheuvel 
1541bd669475SArd Biesheuvel char *efi_convert_cmdline(efi_system_table_t *sys_table_arg,
1542bd669475SArd Biesheuvel 			  efi_loaded_image_t *image, int *cmd_line_len);
1543bd669475SArd Biesheuvel 
1544bd669475SArd Biesheuvel efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg,
1545dadb57abSJeffrey Hugo 				struct efi_boot_memmap *map);
1546bd669475SArd Biesheuvel 
1547220dd769SKairui Song efi_status_t efi_low_alloc_above(efi_system_table_t *sys_table_arg,
1548220dd769SKairui Song 				 unsigned long size, unsigned long align,
1549220dd769SKairui Song 				 unsigned long *addr, unsigned long min);
1550220dd769SKairui Song 
1551220dd769SKairui Song static inline
1552bd669475SArd Biesheuvel efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
1553bd669475SArd Biesheuvel 			   unsigned long size, unsigned long align,
1554220dd769SKairui Song 			   unsigned long *addr)
1555220dd769SKairui Song {
1556220dd769SKairui Song 	/*
1557220dd769SKairui Song 	 * Don't allocate at 0x0. It will confuse code that
1558220dd769SKairui Song 	 * checks pointers against NULL. Skip the first 8
1559220dd769SKairui Song 	 * bytes so we start at a nice even number.
1560220dd769SKairui Song 	 */
1561220dd769SKairui Song 	return efi_low_alloc_above(sys_table_arg, size, align, addr, 0x8);
1562220dd769SKairui Song }
1563bd669475SArd Biesheuvel 
1564bd669475SArd Biesheuvel efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg,
1565bd669475SArd Biesheuvel 			    unsigned long size, unsigned long align,
1566bd669475SArd Biesheuvel 			    unsigned long *addr, unsigned long max);
1567bd669475SArd Biesheuvel 
1568bd669475SArd Biesheuvel efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
1569bd669475SArd Biesheuvel 				 unsigned long *image_addr,
1570bd669475SArd Biesheuvel 				 unsigned long image_size,
1571bd669475SArd Biesheuvel 				 unsigned long alloc_size,
1572bd669475SArd Biesheuvel 				 unsigned long preferred_addr,
1573220dd769SKairui Song 				 unsigned long alignment,
1574220dd769SKairui Song 				 unsigned long min_addr);
1575bd669475SArd Biesheuvel 
1576bd669475SArd Biesheuvel efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
1577bd669475SArd Biesheuvel 				  efi_loaded_image_t *image,
1578bd669475SArd Biesheuvel 				  char *cmd_line, char *option_string,
1579bd669475SArd Biesheuvel 				  unsigned long max_addr,
1580bd669475SArd Biesheuvel 				  unsigned long *load_addr,
1581bd669475SArd Biesheuvel 				  unsigned long *load_size);
1582bd669475SArd Biesheuvel 
158360f38de7SArd Biesheuvel efi_status_t efi_parse_options(char const *cmdline);
15845a17dae4SMatt Fleming 
15852c23b73cSArd Biesheuvel efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg,
15862c23b73cSArd Biesheuvel 			   struct screen_info *si, efi_guid_t *proto,
15872c23b73cSArd Biesheuvel 			   unsigned long size);
15882c23b73cSArd Biesheuvel 
15890082517fSJian-Hong Pan #ifdef CONFIG_EFI
15900082517fSJian-Hong Pan extern bool efi_runtime_disabled(void);
15910082517fSJian-Hong Pan #else
15920082517fSJian-Hong Pan static inline bool efi_runtime_disabled(void) { return true; }
15930082517fSJian-Hong Pan #endif
15940082517fSJian-Hong Pan 
159580e75596SAlex Thorlton extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
159613b210ddSJulien Thierry extern unsigned long efi_call_virt_save_flags(void);
159780e75596SAlex Thorlton 
1598de8cb458SDavid Howells enum efi_secureboot_mode {
1599de8cb458SDavid Howells 	efi_secureboot_mode_unset,
1600de8cb458SDavid Howells 	efi_secureboot_mode_unknown,
1601de8cb458SDavid Howells 	efi_secureboot_mode_disabled,
1602de8cb458SDavid Howells 	efi_secureboot_mode_enabled,
1603de8cb458SDavid Howells };
1604de8cb458SDavid Howells enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table);
1605de8cb458SDavid Howells 
1606ccc829baSMatthew Garrett #ifdef CONFIG_RESET_ATTACK_MITIGATION
1607ccc829baSMatthew Garrett void efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg);
1608ccc829baSMatthew Garrett #else
1609ccc829baSMatthew Garrett static inline void
1610ccc829baSMatthew Garrett efi_enable_reset_attack_mitigation(efi_system_table_t *sys_table_arg) { }
1611ccc829baSMatthew Garrett #endif
1612ccc829baSMatthew Garrett 
16130d959814SDominik Brodowski efi_status_t efi_random_get_seed(efi_system_table_t *sys_table_arg);
16140d959814SDominik Brodowski 
161533b6d034SThiebaud Weksteen void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table);
161633b6d034SThiebaud Weksteen 
161780e75596SAlex Thorlton /*
161880e75596SAlex Thorlton  * Arch code can implement the following three template macros, avoiding
161980e75596SAlex Thorlton  * reptition for the void/non-void return cases of {__,}efi_call_virt():
162080e75596SAlex Thorlton  *
162180e75596SAlex Thorlton  *  * arch_efi_call_virt_setup()
162280e75596SAlex Thorlton  *
162380e75596SAlex Thorlton  *    Sets up the environment for the call (e.g. switching page tables,
162480e75596SAlex Thorlton  *    allowing kernel-mode use of floating point, if required).
162580e75596SAlex Thorlton  *
162680e75596SAlex Thorlton  *  * arch_efi_call_virt()
162780e75596SAlex Thorlton  *
162880e75596SAlex Thorlton  *    Performs the call. The last expression in the macro must be the call
162980e75596SAlex Thorlton  *    itself, allowing the logic to be shared by the void and non-void
163080e75596SAlex Thorlton  *    cases.
163180e75596SAlex Thorlton  *
163280e75596SAlex Thorlton  *  * arch_efi_call_virt_teardown()
163380e75596SAlex Thorlton  *
163480e75596SAlex Thorlton  *    Restores the usual kernel environment once the call has returned.
163580e75596SAlex Thorlton  */
163680e75596SAlex Thorlton 
163780e75596SAlex Thorlton #define efi_call_virt_pointer(p, f, args...)				\
163880e75596SAlex Thorlton ({									\
163980e75596SAlex Thorlton 	efi_status_t __s;						\
164080e75596SAlex Thorlton 	unsigned long __flags;						\
164180e75596SAlex Thorlton 									\
164280e75596SAlex Thorlton 	arch_efi_call_virt_setup();					\
164380e75596SAlex Thorlton 									\
164413b210ddSJulien Thierry 	__flags = efi_call_virt_save_flags();				\
164580e75596SAlex Thorlton 	__s = arch_efi_call_virt(p, f, args);				\
164680e75596SAlex Thorlton 	efi_call_virt_check_flags(__flags, __stringify(f));		\
164780e75596SAlex Thorlton 									\
164880e75596SAlex Thorlton 	arch_efi_call_virt_teardown();					\
164980e75596SAlex Thorlton 									\
165080e75596SAlex Thorlton 	__s;								\
165180e75596SAlex Thorlton })
165280e75596SAlex Thorlton 
165380e75596SAlex Thorlton #define __efi_call_virt_pointer(p, f, args...)				\
165480e75596SAlex Thorlton ({									\
165580e75596SAlex Thorlton 	unsigned long __flags;						\
165680e75596SAlex Thorlton 									\
165780e75596SAlex Thorlton 	arch_efi_call_virt_setup();					\
165880e75596SAlex Thorlton 									\
165913b210ddSJulien Thierry 	__flags = efi_call_virt_save_flags();				\
166080e75596SAlex Thorlton 	arch_efi_call_virt(p, f, args);					\
166180e75596SAlex Thorlton 	efi_call_virt_check_flags(__flags, __stringify(f));		\
166280e75596SAlex Thorlton 									\
166380e75596SAlex Thorlton 	arch_efi_call_virt_teardown();					\
166480e75596SAlex Thorlton })
166580e75596SAlex Thorlton 
1666fc07716bSJeffrey Hugo typedef efi_status_t (*efi_exit_boot_map_processing)(
1667fc07716bSJeffrey Hugo 	efi_system_table_t *sys_table_arg,
1668fc07716bSJeffrey Hugo 	struct efi_boot_memmap *map,
1669fc07716bSJeffrey Hugo 	void *priv);
1670fc07716bSJeffrey Hugo 
1671fc07716bSJeffrey Hugo efi_status_t efi_exit_boot_services(efi_system_table_t *sys_table,
1672fc07716bSJeffrey Hugo 				    void *handle,
1673fc07716bSJeffrey Hugo 				    struct efi_boot_memmap *map,
1674fc07716bSJeffrey Hugo 				    void *priv,
1675fc07716bSJeffrey Hugo 				    efi_exit_boot_map_processing priv_func);
167663625988SArd Biesheuvel 
1677c2ceb5fdSArd Biesheuvel #define EFI_RANDOM_SEED_SIZE		64U
1678c2ceb5fdSArd Biesheuvel 
167963625988SArd Biesheuvel struct linux_efi_random_seed {
168063625988SArd Biesheuvel 	u32	size;
168163625988SArd Biesheuvel 	u8	bits[];
168263625988SArd Biesheuvel };
168363625988SArd Biesheuvel 
168433b6d034SThiebaud Weksteen struct linux_efi_tpm_eventlog {
168533b6d034SThiebaud Weksteen 	u32	size;
1686166a2809SMatthew Garrett 	u32	final_events_preboot_size;
168733b6d034SThiebaud Weksteen 	u8	version;
168833b6d034SThiebaud Weksteen 	u8	log[];
168933b6d034SThiebaud Weksteen };
169033b6d034SThiebaud Weksteen 
169133b6d034SThiebaud Weksteen extern int efi_tpm_eventlog_init(void);
169233b6d034SThiebaud Weksteen 
1693c46f3405SMatthew Garrett struct efi_tcg2_final_events_table {
1694c46f3405SMatthew Garrett 	u64 version;
1695c46f3405SMatthew Garrett 	u64 nr_events;
1696c46f3405SMatthew Garrett 	u8 events[];
1697c46f3405SMatthew Garrett };
1698c46f3405SMatthew Garrett extern int efi_tpm_final_log_size;
1699c46f3405SMatthew Garrett 
17001c5fecb6SNarendra K extern unsigned long rci2_table_phys;
17011c5fecb6SNarendra K 
17023425d934SSai Praneeth /*
17033425d934SSai Praneeth  * efi_runtime_service() function identifiers.
17043425d934SSai Praneeth  * "NONE" is used by efi_recover_from_page_fault() to check if the page
17053425d934SSai Praneeth  * fault happened while executing an efi runtime service.
17063425d934SSai Praneeth  */
17079dbbedaaSSai Praneeth enum efi_rts_ids {
17085c418dc7SAnders Roxell 	EFI_NONE,
17095c418dc7SAnders Roxell 	EFI_GET_TIME,
17105c418dc7SAnders Roxell 	EFI_SET_TIME,
17115c418dc7SAnders Roxell 	EFI_GET_WAKEUP_TIME,
17125c418dc7SAnders Roxell 	EFI_SET_WAKEUP_TIME,
17135c418dc7SAnders Roxell 	EFI_GET_VARIABLE,
17145c418dc7SAnders Roxell 	EFI_GET_NEXT_VARIABLE,
17155c418dc7SAnders Roxell 	EFI_SET_VARIABLE,
17165c418dc7SAnders Roxell 	EFI_QUERY_VARIABLE_INFO,
17175c418dc7SAnders Roxell 	EFI_GET_NEXT_HIGH_MONO_COUNT,
17185c418dc7SAnders Roxell 	EFI_RESET_SYSTEM,
17195c418dc7SAnders Roxell 	EFI_UPDATE_CAPSULE,
17205c418dc7SAnders Roxell 	EFI_QUERY_CAPSULE_CAPS,
17219dbbedaaSSai Praneeth };
17229dbbedaaSSai Praneeth 
17239dbbedaaSSai Praneeth /*
17249dbbedaaSSai Praneeth  * efi_runtime_work:	Details of EFI Runtime Service work
17259dbbedaaSSai Praneeth  * @arg<1-5>:		EFI Runtime Service function arguments
17269dbbedaaSSai Praneeth  * @status:		Status of executing EFI Runtime Service
17279dbbedaaSSai Praneeth  * @efi_rts_id:		EFI Runtime Service function identifier
17289dbbedaaSSai Praneeth  * @efi_rts_comp:	Struct used for handling completions
17299dbbedaaSSai Praneeth  */
17309dbbedaaSSai Praneeth struct efi_runtime_work {
17319dbbedaaSSai Praneeth 	void *arg1;
17329dbbedaaSSai Praneeth 	void *arg2;
17339dbbedaaSSai Praneeth 	void *arg3;
17349dbbedaaSSai Praneeth 	void *arg4;
17359dbbedaaSSai Praneeth 	void *arg5;
17369dbbedaaSSai Praneeth 	efi_status_t status;
17379dbbedaaSSai Praneeth 	struct work_struct work;
17389dbbedaaSSai Praneeth 	enum efi_rts_ids efi_rts_id;
17399dbbedaaSSai Praneeth 	struct completion efi_rts_comp;
17409dbbedaaSSai Praneeth };
17419dbbedaaSSai Praneeth 
17429dbbedaaSSai Praneeth extern struct efi_runtime_work efi_rts_work;
17439dbbedaaSSai Praneeth 
17443eb420e7SSai Praneeth /* Workqueue to queue EFI Runtime Services */
17453eb420e7SSai Praneeth extern struct workqueue_struct *efi_rts_wq;
17463eb420e7SSai Praneeth 
174771e0940dSArd Biesheuvel struct linux_efi_memreserve {
17485f0b0ecfSArd Biesheuvel 	int		size;			// allocated size of the array
17495f0b0ecfSArd Biesheuvel 	atomic_t	count;			// number of entries used
17505f0b0ecfSArd Biesheuvel 	phys_addr_t	next;			// pa of next struct instance
17515f0b0ecfSArd Biesheuvel 	struct {
175271e0940dSArd Biesheuvel 		phys_addr_t	base;
175371e0940dSArd Biesheuvel 		phys_addr_t	size;
17545f0b0ecfSArd Biesheuvel 	} entry[0];
175571e0940dSArd Biesheuvel };
175671e0940dSArd Biesheuvel 
17575f0b0ecfSArd Biesheuvel #define EFI_MEMRESERVE_SIZE(count) (sizeof(struct linux_efi_memreserve) + \
17585f0b0ecfSArd Biesheuvel 	(count) * sizeof(((struct linux_efi_memreserve *)0)->entry[0]))
17595f0b0ecfSArd Biesheuvel 
176080424b02SArd Biesheuvel #define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \
176180424b02SArd Biesheuvel 	/ sizeof(((struct linux_efi_memreserve *)0)->entry[0]))
176280424b02SArd Biesheuvel 
17631da177e4SLinus Torvalds #endif /* _LINUX_EFI_H */
1764