xref: /openbmc/linux/include/linux/efi.h (revision 59f2a619a2db86111e8bb30f349aebff6eb75baa)
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 
5189ed4865SArd Biesheuvel #if defined(CONFIG_X86_64)
528f24f8c2SArd Biesheuvel #define __efiapi __attribute__((ms_abi))
5389ed4865SArd Biesheuvel #elif defined(CONFIG_X86_32)
5489ed4865SArd Biesheuvel #define __efiapi __attribute__((regparm(0)))
558f24f8c2SArd Biesheuvel #else
568f24f8c2SArd Biesheuvel #define __efiapi
578f24f8c2SArd Biesheuvel #endif
588f24f8c2SArd Biesheuvel 
59494c704fSArd Biesheuvel /*
60494c704fSArd Biesheuvel  * The UEFI spec and EDK2 reference implementation both define EFI_GUID as
61494c704fSArd Biesheuvel  * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment
62494c704fSArd Biesheuvel  * is 32 bits not 8 bits like our guid_t. In some cases (i.e., on 32-bit ARM),
63494c704fSArd Biesheuvel  * this means that firmware services invoked by the kernel may assume that
64494c704fSArd Biesheuvel  * efi_guid_t* arguments are 32-bit aligned, and use memory accessors that
65494c704fSArd Biesheuvel  * do not tolerate misalignment. So let's set the minimum alignment to 32 bits.
66494c704fSArd Biesheuvel  *
67494c704fSArd Biesheuvel  * Note that the UEFI spec as well as some comments in the EDK2 code base
68494c704fSArd Biesheuvel  * suggest that EFI_GUID should be 64-bit aligned, but this appears to be
69494c704fSArd Biesheuvel  * a mistake, given that no code seems to exist that actually enforces that
70494c704fSArd Biesheuvel  * or relies on it.
71494c704fSArd Biesheuvel  */
72494c704fSArd Biesheuvel typedef guid_t efi_guid_t __aligned(__alignof__(u32));
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \
75c0020756SAndy Shevchenko 	GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
761da177e4SLinus Torvalds 
771da177e4SLinus Torvalds /*
781da177e4SLinus Torvalds  * Generic EFI table header
791da177e4SLinus Torvalds  */
801da177e4SLinus Torvalds typedef	struct {
811da177e4SLinus Torvalds 	u64 signature;
821da177e4SLinus Torvalds 	u32 revision;
831da177e4SLinus Torvalds 	u32 headersize;
841da177e4SLinus Torvalds 	u32 crc32;
851da177e4SLinus Torvalds 	u32 reserved;
861da177e4SLinus Torvalds } efi_table_hdr_t;
871da177e4SLinus Torvalds 
881da177e4SLinus Torvalds /*
891da177e4SLinus Torvalds  * Memory map descriptor:
901da177e4SLinus Torvalds  */
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds /* Memory types: */
931da177e4SLinus Torvalds #define EFI_RESERVED_TYPE		 0
941da177e4SLinus Torvalds #define EFI_LOADER_CODE			 1
951da177e4SLinus Torvalds #define EFI_LOADER_DATA			 2
961da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_CODE		 3
971da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_DATA		 4
981da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_CODE	 5
991da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_DATA	 6
1001da177e4SLinus Torvalds #define EFI_CONVENTIONAL_MEMORY		 7
1011da177e4SLinus Torvalds #define EFI_UNUSABLE_MEMORY		 8
1021da177e4SLinus Torvalds #define EFI_ACPI_RECLAIM_MEMORY		 9
1031da177e4SLinus Torvalds #define EFI_ACPI_MEMORY_NVS		10
1041da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO		11
1051da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO_PORT_SPACE	12
1061da177e4SLinus Torvalds #define EFI_PAL_CODE			13
107ad5fb870SDan Williams #define EFI_PERSISTENT_MEMORY		14
108ad5fb870SDan Williams #define EFI_MAX_MEMORY_TYPE		15
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds /* Attribute values: */
1111da177e4SLinus Torvalds #define EFI_MEMORY_UC		((u64)0x0000000000000001ULL)	/* uncached */
1121da177e4SLinus Torvalds #define EFI_MEMORY_WC		((u64)0x0000000000000002ULL)	/* write-coalescing */
1131da177e4SLinus Torvalds #define EFI_MEMORY_WT		((u64)0x0000000000000004ULL)	/* write-through */
1141da177e4SLinus Torvalds #define EFI_MEMORY_WB		((u64)0x0000000000000008ULL)	/* write-back */
1159c97e0bdSLaszlo Ersek #define EFI_MEMORY_UCE		((u64)0x0000000000000010ULL)	/* uncached, exported */
1161da177e4SLinus Torvalds #define EFI_MEMORY_WP		((u64)0x0000000000001000ULL)	/* write-protect */
1171da177e4SLinus Torvalds #define EFI_MEMORY_RP		((u64)0x0000000000002000ULL)	/* read-protect */
1181da177e4SLinus Torvalds #define EFI_MEMORY_XP		((u64)0x0000000000004000ULL)	/* execute-protect */
119c016ca08SRobert Elliott #define EFI_MEMORY_NV		((u64)0x0000000000008000ULL)	/* non-volatile */
120b05b9f5fSTony Luck #define EFI_MEMORY_MORE_RELIABLE \
121b05b9f5fSTony Luck 				((u64)0x0000000000010000ULL)	/* higher reliability */
12287db73aeSArd Biesheuvel #define EFI_MEMORY_RO		((u64)0x0000000000020000ULL)	/* read-only */
123fe3e5e65SDan Williams #define EFI_MEMORY_SP		((u64)0x0000000000040000ULL)	/* soft reserved */
1241da177e4SLinus Torvalds #define EFI_MEMORY_RUNTIME	((u64)0x8000000000000000ULL)	/* range requires runtime mapping */
1251da177e4SLinus Torvalds #define EFI_MEMORY_DESCRIPTOR_VERSION	1
1261da177e4SLinus Torvalds 
1271da177e4SLinus Torvalds #define EFI_PAGE_SHIFT		12
128ed37ddffSRoy Franz #define EFI_PAGE_SIZE		(1UL << EFI_PAGE_SHIFT)
1290100a3e6SPeter Jones #define EFI_PAGES_MAX		(U64_MAX >> EFI_PAGE_SHIFT)
1301da177e4SLinus Torvalds 
1311da177e4SLinus Torvalds typedef struct {
1321da177e4SLinus Torvalds 	u32 type;
1331da177e4SLinus Torvalds 	u32 pad;
1341da177e4SLinus Torvalds 	u64 phys_addr;
1351da177e4SLinus Torvalds 	u64 virt_addr;
1361da177e4SLinus Torvalds 	u64 num_pages;
1371da177e4SLinus Torvalds 	u64 attribute;
1381da177e4SLinus Torvalds } efi_memory_desc_t;
1391da177e4SLinus Torvalds 
1403b370237SMatthew Garrett typedef struct {
1413b370237SMatthew Garrett 	efi_guid_t guid;
1423b370237SMatthew Garrett 	u32 headersize;
1433b370237SMatthew Garrett 	u32 flags;
1443b370237SMatthew Garrett 	u32 imagesize;
1453b370237SMatthew Garrett } efi_capsule_header_t;
1463b370237SMatthew Garrett 
147bb05e4baSMatt Fleming /*
148f0133f3cSMatt Fleming  * EFI capsule flags
149f0133f3cSMatt Fleming  */
150f0133f3cSMatt Fleming #define EFI_CAPSULE_PERSIST_ACROSS_RESET	0x00010000
151f0133f3cSMatt Fleming #define EFI_CAPSULE_POPULATE_SYSTEM_TABLE	0x00020000
152f0133f3cSMatt Fleming #define EFI_CAPSULE_INITIATE_RESET		0x00040000
153f0133f3cSMatt Fleming 
1543fabd628SArd Biesheuvel struct capsule_info {
1553fabd628SArd Biesheuvel 	efi_capsule_header_t	header;
156f24c4d47SArd Biesheuvel 	efi_capsule_header_t	*capsule;
1573fabd628SArd Biesheuvel 	int			reset_type;
1583fabd628SArd Biesheuvel 	long			index;
1593fabd628SArd Biesheuvel 	size_t			count;
1603fabd628SArd Biesheuvel 	size_t			total_size;
161f24c4d47SArd Biesheuvel 	struct page		**pages;
162f24c4d47SArd Biesheuvel 	phys_addr_t		*phys;
1633fabd628SArd Biesheuvel 	size_t			page_bytes_remain;
1643fabd628SArd Biesheuvel };
1653fabd628SArd Biesheuvel 
1663fabd628SArd Biesheuvel int __efi_capsule_setup_info(struct capsule_info *cap_info);
1673fabd628SArd Biesheuvel 
168e088a4adSMatthew Wilcox typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg);
1691da177e4SLinus Torvalds 
1701da177e4SLinus Torvalds /*
1711da177e4SLinus Torvalds  * Types and defines for Time Services
1721da177e4SLinus Torvalds  */
1731da177e4SLinus Torvalds #define EFI_TIME_ADJUST_DAYLIGHT 0x1
1741da177e4SLinus Torvalds #define EFI_TIME_IN_DAYLIGHT     0x2
1751da177e4SLinus Torvalds #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
1761da177e4SLinus Torvalds 
1771da177e4SLinus Torvalds typedef struct {
1781da177e4SLinus Torvalds 	u16 year;
1791da177e4SLinus Torvalds 	u8 month;
1801da177e4SLinus Torvalds 	u8 day;
1811da177e4SLinus Torvalds 	u8 hour;
1821da177e4SLinus Torvalds 	u8 minute;
1831da177e4SLinus Torvalds 	u8 second;
1841da177e4SLinus Torvalds 	u8 pad1;
1851da177e4SLinus Torvalds 	u32 nanosecond;
1861da177e4SLinus Torvalds 	s16 timezone;
1871da177e4SLinus Torvalds 	u8 daylight;
1881da177e4SLinus Torvalds 	u8 pad2;
1891da177e4SLinus Torvalds } efi_time_t;
1901da177e4SLinus Torvalds 
1911da177e4SLinus Torvalds typedef struct {
1921da177e4SLinus Torvalds 	u32 resolution;
1931da177e4SLinus Torvalds 	u32 accuracy;
1941da177e4SLinus Torvalds 	u8 sets_to_zero;
1951da177e4SLinus Torvalds } efi_time_cap_t;
1961da177e4SLinus Torvalds 
1978166ec09SArd Biesheuvel typedef union efi_boot_services efi_boot_services_t;
19833b6d034SThiebaud Weksteen 
199f30ca6baSMatt Fleming /*
2001da177e4SLinus Torvalds  * Types and defines for EFI ResetSystem
2011da177e4SLinus Torvalds  */
2021da177e4SLinus Torvalds #define EFI_RESET_COLD 0
2031da177e4SLinus Torvalds #define EFI_RESET_WARM 1
2041da177e4SLinus Torvalds #define EFI_RESET_SHUTDOWN 2
2051da177e4SLinus Torvalds 
2061da177e4SLinus Torvalds /*
2071da177e4SLinus Torvalds  * EFI Runtime Services table
2081da177e4SLinus Torvalds  */
2091da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
2101da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_REVISION  0x00010000
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds typedef struct {
2131da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
214677703ceSMatt Fleming 	u32 get_time;
215677703ceSMatt Fleming 	u32 set_time;
216677703ceSMatt Fleming 	u32 get_wakeup_time;
217677703ceSMatt Fleming 	u32 set_wakeup_time;
218677703ceSMatt Fleming 	u32 set_virtual_address_map;
219677703ceSMatt Fleming 	u32 convert_pointer;
220677703ceSMatt Fleming 	u32 get_variable;
221677703ceSMatt Fleming 	u32 get_next_variable;
222677703ceSMatt Fleming 	u32 set_variable;
223677703ceSMatt Fleming 	u32 get_next_high_mono_count;
224677703ceSMatt Fleming 	u32 reset_system;
225677703ceSMatt Fleming 	u32 update_capsule;
226677703ceSMatt Fleming 	u32 query_capsule_caps;
227677703ceSMatt Fleming 	u32 query_variable_info;
228677703ceSMatt Fleming } efi_runtime_services_32_t;
229677703ceSMatt Fleming 
2301da177e4SLinus Torvalds typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
2311da177e4SLinus Torvalds typedef efi_status_t efi_set_time_t (efi_time_t *tm);
2321da177e4SLinus Torvalds typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
2331da177e4SLinus Torvalds 					    efi_time_t *tm);
2341da177e4SLinus Torvalds typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm);
2351da177e4SLinus Torvalds typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
2361da177e4SLinus Torvalds 					 unsigned long *data_size, void *data);
2371da177e4SLinus Torvalds typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
2381da177e4SLinus Torvalds 					      efi_guid_t *vendor);
2391da177e4SLinus Torvalds typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
240f7a2d73fSMatthew Garrett 					 u32 attr, unsigned long data_size,
2411da177e4SLinus Torvalds 					 void *data);
2421da177e4SLinus Torvalds typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
2431da177e4SLinus Torvalds typedef void efi_reset_system_t (int reset_type, efi_status_t status,
2441da177e4SLinus Torvalds 				 unsigned long data_size, efi_char16_t *data);
2451da177e4SLinus Torvalds typedef efi_status_t efi_set_virtual_address_map_t (unsigned long memory_map_size,
2461da177e4SLinus Torvalds 						unsigned long descriptor_size,
2471da177e4SLinus Torvalds 						u32 descriptor_version,
2481da177e4SLinus Torvalds 						efi_memory_desc_t *virtual_map);
2493b370237SMatthew Garrett typedef efi_status_t efi_query_variable_info_t(u32 attr,
2503b370237SMatthew Garrett 					       u64 *storage_space,
2513b370237SMatthew Garrett 					       u64 *remaining_space,
2523b370237SMatthew Garrett 					       u64 *max_variable_size);
2533b370237SMatthew Garrett typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
2543b370237SMatthew Garrett 					  unsigned long count,
2553b370237SMatthew Garrett 					  unsigned long sg_list);
2563b370237SMatthew Garrett typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
2573b370237SMatthew Garrett 					      unsigned long count,
2583b370237SMatthew Garrett 					      u64 *max_size,
2593b370237SMatthew Garrett 					      int *reset_type);
260ca0e30dcSArd Biesheuvel typedef efi_status_t efi_query_variable_store_t(u32 attributes,
261ca0e30dcSArd Biesheuvel 						unsigned long size,
262ca0e30dcSArd Biesheuvel 						bool nonblocking);
2631da177e4SLinus Torvalds 
2641786e830SArd Biesheuvel typedef union {
2651786e830SArd Biesheuvel 	struct {
266c4c39c70SArd Biesheuvel 		efi_table_hdr_t				hdr;
2678f24f8c2SArd Biesheuvel 		efi_get_time_t __efiapi			*get_time;
2688f24f8c2SArd Biesheuvel 		efi_set_time_t __efiapi			*set_time;
2698f24f8c2SArd Biesheuvel 		efi_get_wakeup_time_t __efiapi		*get_wakeup_time;
2708f24f8c2SArd Biesheuvel 		efi_set_wakeup_time_t __efiapi		*set_wakeup_time;
2718f24f8c2SArd Biesheuvel 		efi_set_virtual_address_map_t __efiapi	*set_virtual_address_map;
272c4c39c70SArd Biesheuvel 		void					*convert_pointer;
2738f24f8c2SArd Biesheuvel 		efi_get_variable_t __efiapi		*get_variable;
2748f24f8c2SArd Biesheuvel 		efi_get_next_variable_t __efiapi	*get_next_variable;
2758f24f8c2SArd Biesheuvel 		efi_set_variable_t __efiapi		*set_variable;
2768f24f8c2SArd Biesheuvel 		efi_get_next_high_mono_count_t __efiapi	*get_next_high_mono_count;
2778f24f8c2SArd Biesheuvel 		efi_reset_system_t __efiapi		*reset_system;
2788f24f8c2SArd Biesheuvel 		efi_update_capsule_t __efiapi		*update_capsule;
2798f24f8c2SArd Biesheuvel 		efi_query_capsule_caps_t __efiapi	*query_capsule_caps;
2808f24f8c2SArd Biesheuvel 		efi_query_variable_info_t __efiapi	*query_variable_info;
2811786e830SArd Biesheuvel 	};
2821786e830SArd Biesheuvel 	efi_runtime_services_32_t mixed_mode;
283c4c39c70SArd Biesheuvel } efi_runtime_services_t;
284c4c39c70SArd Biesheuvel 
285022ee6c5SArd Biesheuvel void efi_native_runtime_setup(void);
286022ee6c5SArd Biesheuvel 
2871da177e4SLinus Torvalds /*
2881da177e4SLinus Torvalds  * EFI Configuration Table and GUID definitions
28954fd11feSPeter Jones  *
2907fb2b43cSIngo Molnar  * These are all defined in a single line to make them easier to
2917fb2b43cSIngo Molnar  * grep for and to see them at a glance - while still having a
2927fb2b43cSIngo Molnar  * similar structure to the definitions in the spec.
2937fb2b43cSIngo Molnar  *
2947fb2b43cSIngo Molnar  * Here's how they are structured:
29554fd11feSPeter Jones  *
29654fd11feSPeter Jones  * GUID: 12345678-1234-1234-1234-123456789012
29754fd11feSPeter Jones  * Spec:
29854fd11feSPeter Jones  *      #define EFI_SOME_PROTOCOL_GUID \
29954fd11feSPeter Jones  *        {0x12345678,0x1234,0x1234,\
30054fd11feSPeter Jones  *          {0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x12}}
30154fd11feSPeter Jones  * Here:
3027fb2b43cSIngo Molnar  *	#define SOME_PROTOCOL_GUID		EFI_GUID(0x12345678, 0x1234, 0x1234,  0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12)
3037fb2b43cSIngo Molnar  *					^ tabs					    ^extra space
3047fb2b43cSIngo Molnar  *
3057fb2b43cSIngo Molnar  * Note that the 'extra space' separates the values at the same place
3067fb2b43cSIngo Molnar  * where the UEFI SPEC breaks the line.
3071da177e4SLinus Torvalds  */
3087fb2b43cSIngo Molnar #define NULL_GUID				EFI_GUID(0x00000000, 0x0000, 0x0000,  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
3097fb2b43cSIngo Molnar #define MPS_TABLE_GUID				EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
3107fb2b43cSIngo Molnar #define ACPI_TABLE_GUID				EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
3117fb2b43cSIngo Molnar #define ACPI_20_TABLE_GUID			EFI_GUID(0x8868e871, 0xe4f1, 0x11d3,  0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
3127fb2b43cSIngo Molnar #define SMBIOS_TABLE_GUID			EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
3137fb2b43cSIngo Molnar #define SMBIOS3_TABLE_GUID			EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c,  0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
3147fb2b43cSIngo Molnar #define SAL_SYSTEM_TABLE_GUID			EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
3157fb2b43cSIngo Molnar #define HCDP_TABLE_GUID				EFI_GUID(0xf951938d, 0x620b, 0x42ef,  0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98)
3167fb2b43cSIngo Molnar #define UGA_IO_PROTOCOL_GUID			EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b,  0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2)
3177fb2b43cSIngo Molnar #define EFI_GLOBAL_VARIABLE_GUID		EFI_GUID(0x8be4df61, 0x93ca, 0x11d2,  0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
3187fb2b43cSIngo Molnar #define UV_SYSTEM_TABLE_GUID			EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd,  0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93)
3197fb2b43cSIngo Molnar #define LINUX_EFI_CRASH_GUID			EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc,  0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0)
3207fb2b43cSIngo Molnar #define LOADED_IMAGE_PROTOCOL_GUID		EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2,  0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
3217fb2b43cSIngo Molnar #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID	EFI_GUID(0x9042a9de, 0x23dc, 0x4a38,  0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
3227fb2b43cSIngo Molnar #define EFI_UGA_PROTOCOL_GUID			EFI_GUID(0x982c298b, 0xf4fa, 0x41cb,  0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39)
3237fb2b43cSIngo Molnar #define EFI_PCI_IO_PROTOCOL_GUID		EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5,  0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a)
3247fb2b43cSIngo Molnar #define EFI_FILE_INFO_ID			EFI_GUID(0x09576e92, 0x6d3f, 0x11d2,  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
3257fb2b43cSIngo Molnar #define EFI_SYSTEM_RESOURCE_TABLE_GUID		EFI_GUID(0xb122a263, 0x3661, 0x4f68,  0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
3267fb2b43cSIngo Molnar #define EFI_FILE_SYSTEM_GUID			EFI_GUID(0x964e5b22, 0x6459, 0x11d2,  0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
3277fb2b43cSIngo Molnar #define DEVICE_TREE_GUID			EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5,  0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
3287fb2b43cSIngo Molnar #define EFI_PROPERTIES_TABLE_GUID		EFI_GUID(0x880aaca3, 0x4adc, 0x4a04,  0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5)
3297fb2b43cSIngo Molnar #define EFI_RNG_PROTOCOL_GUID			EFI_GUID(0x3152bca5, 0xeade, 0x433d,  0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
330568bc4e8SArd Biesheuvel #define EFI_RNG_ALGORITHM_RAW			EFI_GUID(0xe43176d7, 0xb6e8, 0x4827,  0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)
3317fb2b43cSIngo Molnar #define EFI_MEMORY_ATTRIBUTES_TABLE_GUID	EFI_GUID(0xdcfa911d, 0x26eb, 0x469f,  0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
3327fb2b43cSIngo Molnar #define EFI_CONSOLE_OUT_DEVICE_GUID		EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4,  0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
33358c5475aSLukas Wunner #define APPLE_PROPERTIES_PROTOCOL_GUID		EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb,  0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0)
33433b6d034SThiebaud Weksteen #define EFI_TCG2_PROTOCOL_GUID			EFI_GUID(0x607f766c, 0x7455, 0x42be,  0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
3352931d526SArd Biesheuvel #define EFI_LOAD_FILE_PROTOCOL_GUID		EFI_GUID(0x56ec3091, 0x954c, 0x11d2,  0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
3362931d526SArd Biesheuvel #define EFI_LOAD_FILE2_PROTOCOL_GUID		EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e,  0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d)
337fc372064SArd Biesheuvel 
338e58910cdSJosh Boyer #define EFI_IMAGE_SECURITY_DATABASE_GUID	EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596,  0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)
339e58910cdSJosh Boyer #define EFI_SHIM_LOCK_GUID			EFI_GUID(0x605dab50, 0xe046, 0x4300,  0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
340e58910cdSJosh Boyer 
3415c126ba2SDave Howells #define EFI_CERT_SHA256_GUID			EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28)
3425c126ba2SDave Howells #define EFI_CERT_X509_GUID			EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72)
3435c126ba2SDave Howells #define EFI_CERT_X509_SHA256_GUID		EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed)
3445c126ba2SDave Howells 
345801820beSArd Biesheuvel /*
346801820beSArd Biesheuvel  * This GUID is used to pass to the kernel proper the struct screen_info
347801820beSArd Biesheuvel  * structure that was populated by the stub based on the GOP protocol instance
348801820beSArd Biesheuvel  * associated with ConOut
349801820beSArd Biesheuvel  */
3507fb2b43cSIngo Molnar #define LINUX_EFI_ARM_SCREEN_INFO_TABLE_GUID	EFI_GUID(0xe03fc20a, 0x85dc, 0x406e,  0xb9, 0x0e, 0x4a, 0xb5, 0x02, 0x37, 0x1d, 0x95)
3517fb2b43cSIngo Molnar #define LINUX_EFI_LOADER_ENTRY_GUID		EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf,  0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
35263625988SArd Biesheuvel #define LINUX_EFI_RANDOM_SEED_TABLE_GUID	EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2,  0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b)
35333b6d034SThiebaud Weksteen #define LINUX_EFI_TPM_EVENT_LOG_GUID		EFI_GUID(0xb7799cb0, 0xeca2, 0x4943,  0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa)
354c46f3405SMatthew Garrett #define LINUX_EFI_TPM_FINAL_LOG_GUID		EFI_GUID(0x1e2ed096, 0x30e2, 0x4254,  0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25)
35571e0940dSArd Biesheuvel #define LINUX_EFI_MEMRESERVE_TABLE_GUID		EFI_GUID(0x888eb0c6, 0x8ede, 0x4ff5,  0xa8, 0xf0, 0x9a, 0xee, 0x5c, 0xb9, 0x77, 0xc2)
356ec93fc37SArd Biesheuvel #define LINUX_EFI_INITRD_MEDIA_GUID		EFI_GUID(0x5568e427, 0x68fc, 0x4f3d,  0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
35706f7d4a1SCompostella, Jeremy 
3581c5fecb6SNarendra K /* OEM GUIDs */
3591c5fecb6SNarendra K #define DELLEMC_EFI_RCI2_TABLE_GUID		EFI_GUID(0x2d9f28a2, 0xa886, 0x456a,  0x97, 0xa8, 0xf1, 0x1e, 0xf2, 0x4f, 0xf4, 0x55)
3601c5fecb6SNarendra K 
3611da177e4SLinus Torvalds typedef struct {
3621da177e4SLinus Torvalds 	efi_guid_t guid;
3631adbfa35SOlof Johansson 	u64 table;
3641adbfa35SOlof Johansson } efi_config_table_64_t;
3651adbfa35SOlof Johansson 
3661adbfa35SOlof Johansson typedef struct {
3671adbfa35SOlof Johansson 	efi_guid_t guid;
3681adbfa35SOlof Johansson 	u32 table;
3691adbfa35SOlof Johansson } efi_config_table_32_t;
3701adbfa35SOlof Johansson 
3711786e830SArd Biesheuvel typedef union {
3721786e830SArd Biesheuvel 	struct {
3731adbfa35SOlof Johansson 		efi_guid_t guid;
374f958efe9SArd Biesheuvel 		void *table;
3751786e830SArd Biesheuvel 	};
3761786e830SArd Biesheuvel 	efi_config_table_32_t mixed_mode;
3771da177e4SLinus Torvalds } efi_config_table_t;
3781da177e4SLinus Torvalds 
379272686bfSLeif Lindholm typedef struct {
380272686bfSLeif Lindholm 	efi_guid_t guid;
381272686bfSLeif Lindholm 	const char *name;
382272686bfSLeif Lindholm 	unsigned long *ptr;
383272686bfSLeif Lindholm } efi_config_table_type_t;
384272686bfSLeif Lindholm 
3851da177e4SLinus Torvalds #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
3861da177e4SLinus Torvalds 
3873b370237SMatthew Garrett #define EFI_2_30_SYSTEM_TABLE_REVISION  ((2 << 16) | (30))
3883b370237SMatthew Garrett #define EFI_2_20_SYSTEM_TABLE_REVISION  ((2 << 16) | (20))
3893b370237SMatthew Garrett #define EFI_2_10_SYSTEM_TABLE_REVISION  ((2 << 16) | (10))
3903b370237SMatthew Garrett #define EFI_2_00_SYSTEM_TABLE_REVISION  ((2 << 16) | (00))
3913b370237SMatthew Garrett #define EFI_1_10_SYSTEM_TABLE_REVISION  ((1 << 16) | (10))
3923b370237SMatthew Garrett #define EFI_1_02_SYSTEM_TABLE_REVISION  ((1 << 16) | (02))
3933b370237SMatthew Garrett 
3941da177e4SLinus Torvalds typedef struct {
3951da177e4SLinus Torvalds 	efi_table_hdr_t hdr;
3961adbfa35SOlof Johansson 	u64 fw_vendor;	/* physical addr of CHAR16 vendor string */
3971adbfa35SOlof Johansson 	u32 fw_revision;
3981adbfa35SOlof Johansson 	u32 __pad1;
3991adbfa35SOlof Johansson 	u64 con_in_handle;
4001adbfa35SOlof Johansson 	u64 con_in;
4011adbfa35SOlof Johansson 	u64 con_out_handle;
4021adbfa35SOlof Johansson 	u64 con_out;
4031adbfa35SOlof Johansson 	u64 stderr_handle;
4041adbfa35SOlof Johansson 	u64 stderr;
4051adbfa35SOlof Johansson 	u64 runtime;
4061adbfa35SOlof Johansson 	u64 boottime;
4071adbfa35SOlof Johansson 	u32 nr_tables;
4081adbfa35SOlof Johansson 	u32 __pad2;
4091adbfa35SOlof Johansson 	u64 tables;
4101adbfa35SOlof Johansson } efi_system_table_64_t;
4111adbfa35SOlof Johansson 
4121adbfa35SOlof Johansson typedef struct {
4131adbfa35SOlof Johansson 	efi_table_hdr_t hdr;
4141adbfa35SOlof Johansson 	u32 fw_vendor;	/* physical addr of CHAR16 vendor string */
4151adbfa35SOlof Johansson 	u32 fw_revision;
4161adbfa35SOlof Johansson 	u32 con_in_handle;
4171adbfa35SOlof Johansson 	u32 con_in;
4181adbfa35SOlof Johansson 	u32 con_out_handle;
4191adbfa35SOlof Johansson 	u32 con_out;
4201adbfa35SOlof Johansson 	u32 stderr_handle;
4211adbfa35SOlof Johansson 	u32 stderr;
4221adbfa35SOlof Johansson 	u32 runtime;
4231adbfa35SOlof Johansson 	u32 boottime;
4241adbfa35SOlof Johansson 	u32 nr_tables;
4251adbfa35SOlof Johansson 	u32 tables;
4261adbfa35SOlof Johansson } efi_system_table_32_t;
4271adbfa35SOlof Johansson 
428960a8d01SArd Biesheuvel typedef union efi_simple_text_output_protocol efi_simple_text_output_protocol_t;
429960a8d01SArd Biesheuvel 
4301786e830SArd Biesheuvel typedef union {
4311786e830SArd Biesheuvel 	struct {
4321adbfa35SOlof Johansson 		efi_table_hdr_t hdr;
4331da177e4SLinus Torvalds 		unsigned long fw_vendor;	/* physical addr of CHAR16 vendor string */
4341da177e4SLinus Torvalds 		u32 fw_revision;
4351da177e4SLinus Torvalds 		unsigned long con_in_handle;
4361da177e4SLinus Torvalds 		unsigned long con_in;
4371da177e4SLinus Torvalds 		unsigned long con_out_handle;
438960a8d01SArd Biesheuvel 		efi_simple_text_output_protocol_t *con_out;
4391da177e4SLinus Torvalds 		unsigned long stderr_handle;
4401da177e4SLinus Torvalds 		unsigned long stderr;
4411da177e4SLinus Torvalds 		efi_runtime_services_t *runtime;
442f30ca6baSMatt Fleming 		efi_boot_services_t *boottime;
4431da177e4SLinus Torvalds 		unsigned long nr_tables;
4441da177e4SLinus Torvalds 		unsigned long tables;
4451786e830SArd Biesheuvel 	};
4461786e830SArd Biesheuvel 	efi_system_table_32_t mixed_mode;
4471da177e4SLinus Torvalds } efi_system_table_t;
4481da177e4SLinus Torvalds 
4499479c7ceSMatt Fleming /*
4509479c7ceSMatt Fleming  * Architecture independent structure for describing a memory map for the
4511db91035SDan Williams  * benefit of efi_memmap_init_early(), and for passing context between
4521db91035SDan Williams  * efi_memmap_alloc() and efi_memmap_install().
4539479c7ceSMatt Fleming  */
4549479c7ceSMatt Fleming struct efi_memory_map_data {
4559479c7ceSMatt Fleming 	phys_addr_t phys_map;
4569479c7ceSMatt Fleming 	unsigned long size;
4579479c7ceSMatt Fleming 	unsigned long desc_version;
4589479c7ceSMatt Fleming 	unsigned long desc_size;
45926c0e44aSDan Williams 	unsigned long flags;
4609479c7ceSMatt Fleming };
4619479c7ceSMatt Fleming 
4621da177e4SLinus Torvalds struct efi_memory_map {
46344511fb9SArd Biesheuvel 	phys_addr_t phys_map;
4647ae65fd3SMatt Tolentino 	void *map;
4657ae65fd3SMatt Tolentino 	void *map_end;
4661da177e4SLinus Torvalds 	int nr_map;
4671da177e4SLinus Torvalds 	unsigned long desc_version;
4687ae65fd3SMatt Tolentino 	unsigned long desc_size;
46926c0e44aSDan Williams #define EFI_MEMMAP_LATE (1UL << 0)
4701db91035SDan Williams #define EFI_MEMMAP_MEMBLOCK (1UL << 1)
4711db91035SDan Williams #define EFI_MEMMAP_SLAB (1UL << 2)
47226c0e44aSDan Williams 	unsigned long flags;
4731da177e4SLinus Torvalds };
4741da177e4SLinus Torvalds 
47560863c0dSMatt Fleming struct efi_mem_range {
47660863c0dSMatt Fleming 	struct range range;
47760863c0dSMatt Fleming 	u64 attribute;
4781da177e4SLinus Torvalds };
4791da177e4SLinus Torvalds 
4800302f71cSMark Salter struct efi_fdt_params {
4810302f71cSMark Salter 	u64 system_table;
4820302f71cSMark Salter 	u64 mmap;
4830302f71cSMark Salter 	u32 mmap_size;
4840302f71cSMark Salter 	u32 desc_size;
4850302f71cSMark Salter 	u32 desc_ver;
4860302f71cSMark Salter };
4870302f71cSMark Salter 
488bf924863SArd Biesheuvel typedef struct {
489bf924863SArd Biesheuvel 	u32 version;
490bf924863SArd Biesheuvel 	u32 length;
491bf924863SArd Biesheuvel 	u64 memory_protection_attribute;
492bf924863SArd Biesheuvel } efi_properties_table_t;
493bf924863SArd Biesheuvel 
494bf924863SArd Biesheuvel #define EFI_PROPERTIES_TABLE_VERSION	0x00010000
495bf924863SArd Biesheuvel #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA	0x1
496bf924863SArd Biesheuvel 
497b2c99e3cSBjorn Helgaas #define EFI_INVALID_TABLE_ADDR		(~0UL)
498b2c99e3cSBjorn Helgaas 
499a604af07SArd Biesheuvel typedef struct {
500a604af07SArd Biesheuvel 	u32 version;
501a604af07SArd Biesheuvel 	u32 num_entries;
502a604af07SArd Biesheuvel 	u32 desc_size;
503a604af07SArd Biesheuvel 	u32 reserved;
504a604af07SArd Biesheuvel 	efi_memory_desc_t entry[0];
505a604af07SArd Biesheuvel } efi_memory_attributes_table_t;
506a604af07SArd Biesheuvel 
5075c126ba2SDave Howells typedef struct {
5085c126ba2SDave Howells 	efi_guid_t signature_owner;
5095c126ba2SDave Howells 	u8 signature_data[];
5105c126ba2SDave Howells } efi_signature_data_t;
5115c126ba2SDave Howells 
5125c126ba2SDave Howells typedef struct {
5135c126ba2SDave Howells 	efi_guid_t signature_type;
5145c126ba2SDave Howells 	u32 signature_list_size;
5155c126ba2SDave Howells 	u32 signature_header_size;
5165c126ba2SDave Howells 	u32 signature_size;
5175c126ba2SDave Howells 	u8 signature_header[];
5185c126ba2SDave Howells 	/* efi_signature_data_t signatures[][] */
5195c126ba2SDave Howells } efi_signature_list_t;
5205c126ba2SDave Howells 
5215c126ba2SDave Howells typedef u8 efi_sha256_hash_t[32];
5225c126ba2SDave Howells 
5235c126ba2SDave Howells typedef struct {
5245c126ba2SDave Howells 	efi_sha256_hash_t to_be_signed_hash;
5255c126ba2SDave Howells 	efi_time_t time_of_revocation;
5265c126ba2SDave Howells } efi_cert_x509_sha256_t;
5275c126ba2SDave Howells 
5281da177e4SLinus Torvalds /*
5291da177e4SLinus Torvalds  * All runtime access to EFI goes through this structure:
5301da177e4SLinus Torvalds  */
5311da177e4SLinus Torvalds extern struct efi {
532*59f2a619SArd Biesheuvel 	const efi_runtime_services_t	*runtime;		/* EFI runtime services table */
5331da177e4SLinus Torvalds 	efi_system_table_t *systab;	/* EFI system table */
5343b370237SMatthew Garrett 	unsigned int runtime_version;	/* Runtime services version */
535b2c99e3cSBjorn Helgaas 	unsigned long acpi;		/* ACPI table  (IA64 ext 0.71) */
536b2c99e3cSBjorn Helgaas 	unsigned long acpi20;		/* ACPI table  (ACPI 2.0) */
537e1ccbbc9SArd Biesheuvel 	unsigned long smbios;		/* SMBIOS table (32 bit entry point) */
538e1ccbbc9SArd Biesheuvel 	unsigned long smbios3;		/* SMBIOS table (64 bit entry point) */
5390bb54905SPeter Jones 	unsigned long esrt;		/* ESRT table */
54033b6d034SThiebaud Weksteen 	unsigned long tpm_log;		/* TPM2 Event Log table */
541c46f3405SMatthew Garrett 	unsigned long tpm_final_log;	/* TPM2 Final Events Log table */
5421da177e4SLinus Torvalds 	efi_get_time_t *get_time;
5431da177e4SLinus Torvalds 	efi_set_time_t *set_time;
5441da177e4SLinus Torvalds 	efi_get_wakeup_time_t *get_wakeup_time;
5451da177e4SLinus Torvalds 	efi_set_wakeup_time_t *set_wakeup_time;
5461da177e4SLinus Torvalds 	efi_get_variable_t *get_variable;
5471da177e4SLinus Torvalds 	efi_get_next_variable_t *get_next_variable;
5481da177e4SLinus Torvalds 	efi_set_variable_t *set_variable;
54970d2a3cfSArd Biesheuvel 	efi_set_variable_t *set_variable_nonblocking;
5503b370237SMatthew Garrett 	efi_query_variable_info_t *query_variable_info;
551d3cac1f8SArd Biesheuvel 	efi_query_variable_info_t *query_variable_info_nonblocking;
5523b370237SMatthew Garrett 	efi_update_capsule_t *update_capsule;
5533b370237SMatthew Garrett 	efi_query_capsule_caps_t *query_capsule_caps;
5541da177e4SLinus Torvalds 	efi_get_next_high_mono_count_t *get_next_high_mono_count;
5551da177e4SLinus Torvalds 	efi_reset_system_t *reset_system;
556884f4f66SMatt Fleming 	struct efi_memory_map memmap;
5573e909599SMatt Fleming 	unsigned long flags;
5581da177e4SLinus Torvalds } efi;
5591da177e4SLinus Torvalds 
5607e904a91SSai Praneeth extern struct mm_struct efi_mm;
5617e904a91SSai Praneeth 
5621da177e4SLinus Torvalds static inline int
5631da177e4SLinus Torvalds efi_guidcmp (efi_guid_t left, efi_guid_t right)
5641da177e4SLinus Torvalds {
5651da177e4SLinus Torvalds 	return memcmp(&left, &right, sizeof (efi_guid_t));
5661da177e4SLinus Torvalds }
5671da177e4SLinus Torvalds 
5681da177e4SLinus Torvalds static inline char *
56926e02272SBorislav Petkov efi_guid_to_str(efi_guid_t *guid, char *out)
5701da177e4SLinus Torvalds {
571925ede0bSJoe Perches 	sprintf(out, "%pUl", guid->b);
5721da177e4SLinus Torvalds         return out;
5731da177e4SLinus Torvalds }
5741da177e4SLinus Torvalds 
5751da177e4SLinus Torvalds extern void efi_init (void);
5761da177e4SLinus Torvalds extern void *efi_get_pal_addr (void);
5771da177e4SLinus Torvalds extern void efi_map_pal_code (void);
5781da177e4SLinus Torvalds extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg);
57970f4f935SArnd Bergmann extern void efi_gettimeofday (struct timespec64 *ts);
5801da177e4SLinus Torvalds extern void efi_enter_virtual_mode (void);	/* switch EFI to virtual mode, if possible */
58178510792SJosh Triplett #ifdef CONFIG_X86
582ca0e30dcSArd Biesheuvel extern efi_status_t efi_query_variable_store(u32 attributes,
583ca0e30dcSArd Biesheuvel 					     unsigned long size,
584ca0e30dcSArd Biesheuvel 					     bool nonblocking);
58578510792SJosh Triplett #else
586a6e4d5a0SMatt Fleming 
587ca0e30dcSArd Biesheuvel static inline efi_status_t efi_query_variable_store(u32 attributes,
588ca0e30dcSArd Biesheuvel 						    unsigned long size,
589ca0e30dcSArd Biesheuvel 						    bool nonblocking)
590a6e4d5a0SMatt Fleming {
591a6e4d5a0SMatt Fleming 	return EFI_SUCCESS;
592a6e4d5a0SMatt Fleming }
59378510792SJosh Triplett #endif
5947bc90e01SJosh Triplett extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr);
5959479c7ceSMatt Fleming 
5961db91035SDan Williams extern int __init efi_memmap_alloc(unsigned int num_entries,
5971db91035SDan Williams 				   struct efi_memory_map_data *data);
598484a418dSDan Williams extern void __efi_memmap_free(u64 phys, unsigned long size,
599484a418dSDan Williams 			      unsigned long flags);
6009479c7ceSMatt Fleming extern int __init efi_memmap_init_early(struct efi_memory_map_data *data);
601dca0f971SMatt Fleming extern int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size);
6029479c7ceSMatt Fleming extern void __init efi_memmap_unmap(void);
6031db91035SDan Williams extern int __init efi_memmap_install(struct efi_memory_map_data *data);
60460863c0dSMatt Fleming extern int __init efi_memmap_split_count(efi_memory_desc_t *md,
60560863c0dSMatt Fleming 					 struct range *range);
60660863c0dSMatt Fleming extern void __init efi_memmap_insert(struct efi_memory_map *old_memmap,
60760863c0dSMatt Fleming 				     void *buf, struct efi_mem_range *mem);
6089479c7ceSMatt Fleming 
6093846c158SPeter Jones #ifdef CONFIG_EFI_ESRT
6100bb54905SPeter Jones extern void __init efi_esrt_init(void);
6113846c158SPeter Jones #else
6123846c158SPeter Jones static inline void efi_esrt_init(void) { }
6133846c158SPeter Jones #endif
61406c0bd93SArd Biesheuvel extern int efi_config_parse_tables(const efi_config_table_t *config_tables,
61506c0bd93SArd Biesheuvel 				   int count,
61606c0bd93SArd Biesheuvel 				   const efi_config_table_type_t *arch_tables);
61714fb4209SArd Biesheuvel extern int efi_systab_check_header(const efi_table_hdr_t *systab_hdr,
61814fb4209SArd Biesheuvel 				   int min_major_version);
61914fb4209SArd Biesheuvel extern void efi_systab_report_header(const efi_table_hdr_t *systab_hdr,
62014fb4209SArd Biesheuvel 				     unsigned long fw_vendor);
6211da177e4SLinus Torvalds extern u64 efi_get_iobase (void);
622f99afd08STom Lendacky extern int efi_mem_type(unsigned long phys_addr);
6231da177e4SLinus Torvalds extern u64 efi_mem_attributes (unsigned long phys_addr);
62432e62c63SBjorn Helgaas extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
6251da177e4SLinus Torvalds extern int __init efi_uart_console_only (void);
6260bb54905SPeter Jones extern u64 efi_mem_desc_end(efi_memory_desc_t *md);
6270bb54905SPeter Jones extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
628816e7612SMatt Fleming extern void efi_mem_reserve(phys_addr_t addr, u64 size);
629a23d3bb0SArd Biesheuvel extern int efi_mem_reserve_persistent(phys_addr_t addr, u64 size);
6301da177e4SLinus Torvalds extern void efi_initialize_iomem_resources(struct resource *code_resource,
63100bf4098SBernhard Walle 		struct resource *data_resource, struct resource *bss_resource);
6327968c0e3SLeif Lindholm extern int efi_get_fdt_params(struct efi_fdt_params *params);
6330bb54905SPeter Jones extern struct kobject *efi_kobj;
6341da177e4SLinus Torvalds 
63544be28e9SMatt Fleming extern int efi_reboot_quirk_mode;
6360c5ed61aSMatt Fleming extern bool efi_poweroff_required(void);
6370c5ed61aSMatt Fleming 
6380f96a99dSTaku Izumi #ifdef CONFIG_EFI_FAKE_MEMMAP
6390f96a99dSTaku Izumi extern void __init efi_fake_memmap(void);
6400f96a99dSTaku Izumi #else
6410f96a99dSTaku Izumi static inline void efi_fake_memmap(void) { }
6420f96a99dSTaku Izumi #endif
6430f96a99dSTaku Izumi 
644a17e809eSArd Biesheuvel extern unsigned long efi_mem_attr_table;
645a17e809eSArd Biesheuvel 
64610f0d2f5SArd Biesheuvel /*
64710f0d2f5SArd Biesheuvel  * efi_memattr_perm_setter - arch specific callback function passed into
64810f0d2f5SArd Biesheuvel  *                           efi_memattr_apply_permissions() that updates the
64910f0d2f5SArd Biesheuvel  *                           mapping permissions described by the second
65010f0d2f5SArd Biesheuvel  *                           argument in the page tables referred to by the
65110f0d2f5SArd Biesheuvel  *                           first argument.
65210f0d2f5SArd Biesheuvel  */
65310f0d2f5SArd Biesheuvel typedef int (*efi_memattr_perm_setter)(struct mm_struct *, efi_memory_desc_t *);
65410f0d2f5SArd Biesheuvel 
65510f0d2f5SArd Biesheuvel extern int efi_memattr_init(void);
65610f0d2f5SArd Biesheuvel extern int efi_memattr_apply_permissions(struct mm_struct *mm,
65710f0d2f5SArd Biesheuvel 					 efi_memattr_perm_setter fn);
65810f0d2f5SArd Biesheuvel 
65902e43c2dSBaoquan He /*
66002e43c2dSBaoquan He  * efi_early_memdesc_ptr - get the n-th EFI memmap descriptor
66102e43c2dSBaoquan He  * @map: the start of efi memmap
66202e43c2dSBaoquan He  * @desc_size: the size of space for each EFI memmap descriptor
66302e43c2dSBaoquan He  * @n: the index of efi memmap descriptor
66402e43c2dSBaoquan He  *
66502e43c2dSBaoquan He  * EFI boot service provides the GetMemoryMap() function to get a copy of the
66602e43c2dSBaoquan He  * current memory map which is an array of memory descriptors, each of
66702e43c2dSBaoquan He  * which describes a contiguous block of memory. It also gets the size of the
66802e43c2dSBaoquan He  * map, and the size of each descriptor, etc.
66902e43c2dSBaoquan He  *
67002e43c2dSBaoquan He  * Note that per section 6.2 of UEFI Spec 2.6 Errata A, the returned size of
67102e43c2dSBaoquan He  * each descriptor might not be equal to sizeof(efi_memory_memdesc_t),
67202e43c2dSBaoquan He  * since efi_memory_memdesc_t may be extended in the future. Thus the OS
67302e43c2dSBaoquan He  * MUST use the returned size of the descriptor to find the start of each
67402e43c2dSBaoquan He  * efi_memory_memdesc_t in the memory map array. This should only be used
67502e43c2dSBaoquan He  * during bootup since for_each_efi_memory_desc_xxx() is available after the
67602e43c2dSBaoquan He  * kernel initializes the EFI subsystem to set up struct efi_memory_map.
67702e43c2dSBaoquan He  */
67802e43c2dSBaoquan He #define efi_early_memdesc_ptr(map, desc_size, n)			\
67902e43c2dSBaoquan He 	(efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
68002e43c2dSBaoquan He 
681e885cd80SMark Salter /* Iterate through an efi_memory_map */
68278ce248fSMatt Fleming #define for_each_efi_memory_desc_in_map(m, md)				   \
683e885cd80SMark Salter 	for ((md) = (m)->map;						   \
684d4c4fed0SJan Beulich 	     (md) && ((void *)(md) + (m)->desc_size) <= (m)->map_end;	   \
685e885cd80SMark Salter 	     (md) = (void *)(md) + (m)->desc_size)
686e885cd80SMark Salter 
68778ce248fSMatt Fleming /**
68878ce248fSMatt Fleming  * for_each_efi_memory_desc - iterate over descriptors in efi.memmap
68978ce248fSMatt Fleming  * @md: the efi_memory_desc_t * iterator
69078ce248fSMatt Fleming  *
69178ce248fSMatt Fleming  * Once the loop finishes @md must not be accessed.
69278ce248fSMatt Fleming  */
69378ce248fSMatt Fleming #define for_each_efi_memory_desc(md) \
694884f4f66SMatt Fleming 	for_each_efi_memory_desc_in_map(&efi.memmap, md)
69578ce248fSMatt Fleming 
69698d2a6caSLaszlo Ersek /*
69798d2a6caSLaszlo Ersek  * Format an EFI memory descriptor's type and attributes to a user-provided
69898d2a6caSLaszlo Ersek  * character buffer, as per snprintf(), and return the buffer.
69998d2a6caSLaszlo Ersek  */
70098d2a6caSLaszlo Ersek char * __init efi_md_typeattr_format(char *buf, size_t size,
70198d2a6caSLaszlo Ersek 				     const efi_memory_desc_t *md);
70298d2a6caSLaszlo Ersek 
7030bc9ae39SDave Howells 
7040bc9ae39SDave Howells typedef void (*efi_element_handler_t)(const char *source,
7050bc9ae39SDave Howells 				      const void *element_data,
7060bc9ae39SDave Howells 				      size_t element_size);
7070bc9ae39SDave Howells extern int __init parse_efi_signature_list(
7080bc9ae39SDave Howells 	const char *source,
7090bc9ae39SDave Howells 	const void *data, size_t size,
7100bc9ae39SDave Howells 	efi_element_handler_t (*get_handler_for_guid)(const efi_guid_t *));
7110bc9ae39SDave Howells 
7121da177e4SLinus Torvalds /**
7131da177e4SLinus Torvalds  * efi_range_is_wc - check the WC bit on an address range
7141da177e4SLinus Torvalds  * @start: starting kvirt address
7151da177e4SLinus Torvalds  * @len: length of range
7161da177e4SLinus Torvalds  *
7171da177e4SLinus Torvalds  * Consult the EFI memory map and make sure it's ok to set this range WC.
7181da177e4SLinus Torvalds  * Returns true or false.
7191da177e4SLinus Torvalds  */
7201da177e4SLinus Torvalds static inline int efi_range_is_wc(unsigned long start, unsigned long len)
7211da177e4SLinus Torvalds {
722986a80d5SJesper Juhl 	unsigned long i;
7231da177e4SLinus Torvalds 
7241da177e4SLinus Torvalds 	for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
7251da177e4SLinus Torvalds 		unsigned long paddr = __pa(start + i);
7261da177e4SLinus Torvalds 		if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
7271da177e4SLinus Torvalds 			return 0;
7281da177e4SLinus Torvalds 	}
7291da177e4SLinus Torvalds 	/* The range checked out */
7301da177e4SLinus Torvalds 	return 1;
7311da177e4SLinus Torvalds }
7321da177e4SLinus Torvalds 
7331da177e4SLinus Torvalds #ifdef CONFIG_EFI_PCDP
7341da177e4SLinus Torvalds extern int __init efi_setup_pcdp_console(char *);
7351da177e4SLinus Torvalds #endif
7361da177e4SLinus Torvalds 
7371da177e4SLinus Torvalds /*
73883e68189SMatt Fleming  * We play games with efi_enabled so that the compiler will, if
73983e68189SMatt Fleming  * possible, remove EFI-related code altogether.
7401da177e4SLinus Torvalds  */
74183e68189SMatt Fleming #define EFI_BOOT		0	/* Were we booted from EFI? */
74283e68189SMatt Fleming #define EFI_CONFIG_TABLES	2	/* Can we use EFI config tables? */
74383e68189SMatt Fleming #define EFI_RUNTIME_SERVICES	3	/* Can we use runtime services? */
74483e68189SMatt Fleming #define EFI_MEMMAP		4	/* Can we use EFI memory map? */
74583e68189SMatt Fleming #define EFI_64BIT		5	/* Is the firmware 64-bit? */
7469f27bc54SDaniel Kiper #define EFI_PARAVIRT		6	/* Access is via a paravirt interface */
7479f27bc54SDaniel Kiper #define EFI_ARCH_1		7	/* First arch-specific bit */
748fed6cefeSBorislav Petkov #define EFI_DBG			8	/* Print additional debug info at runtime */
749a1041713SArd Biesheuvel #define EFI_NX_PE_DATA		9	/* Can runtime data regions be mapped non-executable? */
750a19ebf59SSai Praneeth #define EFI_MEM_ATTR		10	/* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */
751b617c526SDan Williams #define EFI_MEM_NO_SOFT_RESERVE	11	/* Is the kernel configured to ignore soft reservations? */
75283e68189SMatt Fleming 
7531da177e4SLinus Torvalds #ifdef CONFIG_EFI
7543e909599SMatt Fleming /*
7553e909599SMatt Fleming  * Test whether the above EFI_* bits are enabled.
7563e909599SMatt Fleming  */
7573e909599SMatt Fleming static inline bool efi_enabled(int feature)
75883e68189SMatt Fleming {
7593e909599SMatt Fleming 	return test_bit(feature, &efi.flags) != 0;
7603e909599SMatt Fleming }
7618562c99cSMatt Fleming extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
762b617c526SDan Williams 
763b617c526SDan Williams bool __pure __efi_soft_reserve_enabled(void);
764b617c526SDan Williams 
765b617c526SDan Williams static inline bool __pure efi_soft_reserve_enabled(void)
766b617c526SDan Williams {
767b617c526SDan Williams 	return IS_ENABLED(CONFIG_EFI_SOFT_RESERVE)
768b617c526SDan Williams 		&& __efi_soft_reserve_enabled();
769b617c526SDan Williams }
7703e909599SMatt Fleming #else
7713e909599SMatt Fleming static inline bool efi_enabled(int feature)
7723e909599SMatt Fleming {
7733e909599SMatt Fleming 	return false;
77483e68189SMatt Fleming }
7758562c99cSMatt Fleming static inline void
7768562c99cSMatt Fleming efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
77787615a34SMatt Fleming 
77887615a34SMatt Fleming static inline bool
77987615a34SMatt Fleming efi_capsule_pending(int *reset_type)
78087615a34SMatt Fleming {
78187615a34SMatt Fleming 	return false;
78287615a34SMatt Fleming }
783b617c526SDan Williams 
784b617c526SDan Williams static inline bool efi_soft_reserve_enabled(void)
785b617c526SDan Williams {
786b617c526SDan Williams 	return false;
787b617c526SDan Williams }
7881da177e4SLinus Torvalds #endif
7891da177e4SLinus Torvalds 
790806b0351SMatt Fleming extern int efi_status_to_err(efi_status_t status);
791806b0351SMatt Fleming 
7921da177e4SLinus Torvalds /*
7931da177e4SLinus Torvalds  * Variable Attributes
7941da177e4SLinus Torvalds  */
7951da177e4SLinus Torvalds #define EFI_VARIABLE_NON_VOLATILE       0x0000000000000001
7961da177e4SLinus Torvalds #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
7971da177e4SLinus Torvalds #define EFI_VARIABLE_RUNTIME_ACCESS     0x0000000000000004
79841b3254cSMatthew Garrett #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
79941b3254cSMatthew Garrett #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
80041b3254cSMatthew Garrett #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
80141b3254cSMatthew Garrett #define EFI_VARIABLE_APPEND_WRITE	0x0000000000000040
8021da177e4SLinus Torvalds 
80341b3254cSMatthew Garrett #define EFI_VARIABLE_MASK 	(EFI_VARIABLE_NON_VOLATILE | \
80441b3254cSMatthew Garrett 				EFI_VARIABLE_BOOTSERVICE_ACCESS | \
80541b3254cSMatthew Garrett 				EFI_VARIABLE_RUNTIME_ACCESS | \
80641b3254cSMatthew Garrett 				EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
80741b3254cSMatthew Garrett 				EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
80841b3254cSMatthew Garrett 				EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
80941b3254cSMatthew Garrett 				EFI_VARIABLE_APPEND_WRITE)
8101da177e4SLinus Torvalds /*
811e14ab23dSMatt Fleming  * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
812e14ab23dSMatt Fleming  * not including trailing NUL
813e14ab23dSMatt Fleming  */
814ba7e34b1SAndy Shevchenko #define EFI_VARIABLE_GUID_LEN	UUID_STRING_LEN
815e14ab23dSMatt Fleming 
816e14ab23dSMatt Fleming /*
8171da177e4SLinus Torvalds  * EFI Device Path information
8181da177e4SLinus Torvalds  */
8191da177e4SLinus Torvalds #define EFI_DEV_HW			0x01
8201da177e4SLinus Torvalds #define  EFI_DEV_PCI				 1
8211da177e4SLinus Torvalds #define  EFI_DEV_PCCARD				 2
8221da177e4SLinus Torvalds #define  EFI_DEV_MEM_MAPPED			 3
8231da177e4SLinus Torvalds #define  EFI_DEV_VENDOR				 4
8241da177e4SLinus Torvalds #define  EFI_DEV_CONTROLLER			 5
8251da177e4SLinus Torvalds #define EFI_DEV_ACPI			0x02
8261da177e4SLinus Torvalds #define   EFI_DEV_BASIC_ACPI			 1
8271da177e4SLinus Torvalds #define   EFI_DEV_EXPANDED_ACPI			 2
8281da177e4SLinus Torvalds #define EFI_DEV_MSG			0x03
8291da177e4SLinus Torvalds #define   EFI_DEV_MSG_ATAPI			 1
8301da177e4SLinus Torvalds #define   EFI_DEV_MSG_SCSI			 2
8311da177e4SLinus Torvalds #define   EFI_DEV_MSG_FC			 3
8321da177e4SLinus Torvalds #define   EFI_DEV_MSG_1394			 4
8331da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB			 5
8341da177e4SLinus Torvalds #define   EFI_DEV_MSG_USB_CLASS			15
8351da177e4SLinus Torvalds #define   EFI_DEV_MSG_I20			 6
8361da177e4SLinus Torvalds #define   EFI_DEV_MSG_MAC			11
8371da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV4			12
8381da177e4SLinus Torvalds #define   EFI_DEV_MSG_IPV6			13
8391da177e4SLinus Torvalds #define   EFI_DEV_MSG_INFINIBAND		 9
8401da177e4SLinus Torvalds #define   EFI_DEV_MSG_UART			14
8411da177e4SLinus Torvalds #define   EFI_DEV_MSG_VENDOR			10
8421da177e4SLinus Torvalds #define EFI_DEV_MEDIA			0x04
8431da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_HARD_DRIVE		 1
8441da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_CDROM			 2
8451da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_VENDOR			 3
8461da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_FILE			 4
8471da177e4SLinus Torvalds #define   EFI_DEV_MEDIA_PROTOCOL		 5
8481da177e4SLinus Torvalds #define EFI_DEV_BIOS_BOOT		0x05
8491da177e4SLinus Torvalds #define EFI_DEV_END_PATH		0x7F
8501da177e4SLinus Torvalds #define EFI_DEV_END_PATH2		0xFF
8511da177e4SLinus Torvalds #define   EFI_DEV_END_INSTANCE			0x01
8521da177e4SLinus Torvalds #define   EFI_DEV_END_ENTIRE			0xFF
8531da177e4SLinus Torvalds 
8541da177e4SLinus Torvalds struct efi_generic_dev_path {
8551da177e4SLinus Torvalds 	u8				type;
8561da177e4SLinus Torvalds 	u8				sub_type;
8571da177e4SLinus Torvalds 	u16				length;
858db8952e7SArd Biesheuvel } __packed;
8591da177e4SLinus Torvalds 
860db8952e7SArd Biesheuvel struct efi_acpi_dev_path {
861db8952e7SArd Biesheuvel 	struct efi_generic_dev_path	header;
86246cd4b75SLukas Wunner 	u32				hid;
86346cd4b75SLukas Wunner 	u32				uid;
864db8952e7SArd Biesheuvel } __packed;
865db8952e7SArd Biesheuvel 
866db8952e7SArd Biesheuvel struct efi_pci_dev_path {
867db8952e7SArd Biesheuvel 	struct efi_generic_dev_path	header;
86846cd4b75SLukas Wunner 	u8				fn;
86946cd4b75SLukas Wunner 	u8				dev;
870db8952e7SArd Biesheuvel } __packed;
87146cd4b75SLukas Wunner 
872db8952e7SArd Biesheuvel struct efi_vendor_dev_path {
873db8952e7SArd Biesheuvel 	struct efi_generic_dev_path	header;
874db8952e7SArd Biesheuvel 	efi_guid_t			vendorguid;
875db8952e7SArd Biesheuvel 	u8				vendordata[];
876db8952e7SArd Biesheuvel } __packed;
877db8952e7SArd Biesheuvel 
878db8952e7SArd Biesheuvel struct efi_dev_path {
879db8952e7SArd Biesheuvel 	union {
880db8952e7SArd Biesheuvel 		struct efi_generic_dev_path	header;
881db8952e7SArd Biesheuvel 		struct efi_acpi_dev_path	acpi;
882db8952e7SArd Biesheuvel 		struct efi_pci_dev_path		pci;
883db8952e7SArd Biesheuvel 		struct efi_vendor_dev_path	vendor;
884db8952e7SArd Biesheuvel 	};
885db8952e7SArd Biesheuvel } __packed;
886db8952e7SArd Biesheuvel 
887db8952e7SArd Biesheuvel struct device *efi_get_device_by_path(const struct efi_dev_path **node,
888db8952e7SArd Biesheuvel 				      size_t *len);
88946cd4b75SLukas Wunner 
8904a3575fdSHuang, Ying static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
8914a3575fdSHuang, Ying {
8924a3575fdSHuang, Ying 	*npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
8934a3575fdSHuang, Ying 	*addr &= PAGE_MASK;
8944a3575fdSHuang, Ying }
8954a3575fdSHuang, Ying 
89604851772SMatt Fleming /*
8974fc756bdSMike Waychison  * EFI Variable support.
8984fc756bdSMike Waychison  *
8994fc756bdSMike Waychison  * Different firmware drivers can expose their EFI-like variables using
9004fc756bdSMike Waychison  * the following.
9014fc756bdSMike Waychison  */
9024fc756bdSMike Waychison 
9034fc756bdSMike Waychison struct efivar_operations {
9044fc756bdSMike Waychison 	efi_get_variable_t *get_variable;
9054fc756bdSMike Waychison 	efi_get_next_variable_t *get_next_variable;
9064fc756bdSMike Waychison 	efi_set_variable_t *set_variable;
90770d2a3cfSArd Biesheuvel 	efi_set_variable_t *set_variable_nonblocking;
908a6e4d5a0SMatt Fleming 	efi_query_variable_store_t *query_variable_store;
9094fc756bdSMike Waychison };
9104fc756bdSMike Waychison 
9114fc756bdSMike Waychison struct efivars {
9124fc756bdSMike Waychison 	struct kset *kset;
913605e70c7SLee, Chun-Yi 	struct kobject *kobject;
9144fc756bdSMike Waychison 	const struct efivar_operations *ops;
9154fc756bdSMike Waychison };
9164fc756bdSMike Waychison 
917e14ab23dSMatt Fleming /*
918e14ab23dSMatt Fleming  * The maximum size of VariableName + Data = 1024
919e14ab23dSMatt Fleming  * Therefore, it's reasonable to save that much
920e14ab23dSMatt Fleming  * space in each part of the structure,
921e14ab23dSMatt Fleming  * and we use a page for reading/writing.
922e14ab23dSMatt Fleming  */
923e14ab23dSMatt Fleming 
924a5d92ad3SMatt Fleming #define EFI_VAR_NAME_LEN	1024
925a5d92ad3SMatt Fleming 
926e14ab23dSMatt Fleming struct efi_variable {
927a5d92ad3SMatt Fleming 	efi_char16_t  VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
928e14ab23dSMatt Fleming 	efi_guid_t    VendorGuid;
929e14ab23dSMatt Fleming 	unsigned long DataSize;
930e14ab23dSMatt Fleming 	__u8          Data[1024];
931e14ab23dSMatt Fleming 	efi_status_t  Status;
932e14ab23dSMatt Fleming 	__u32         Attributes;
933e14ab23dSMatt Fleming } __attribute__((packed));
934e14ab23dSMatt Fleming 
935e14ab23dSMatt Fleming struct efivar_entry {
936e14ab23dSMatt Fleming 	struct efi_variable var;
937e14ab23dSMatt Fleming 	struct list_head list;
938e14ab23dSMatt Fleming 	struct kobject kobj;
939e0d59733SSeiji Aguchi 	bool scanning;
940e0d59733SSeiji Aguchi 	bool deleting;
941e14ab23dSMatt Fleming };
942e14ab23dSMatt Fleming 
94304851772SMatt Fleming extern struct list_head efivar_sysfs_list;
94404851772SMatt Fleming 
94504851772SMatt Fleming static inline void
94604851772SMatt Fleming efivar_unregister(struct efivar_entry *var)
94704851772SMatt Fleming {
94804851772SMatt Fleming 	kobject_put(&var->kobj);
94904851772SMatt Fleming }
95004851772SMatt Fleming 
951e14ab23dSMatt Fleming int efivars_register(struct efivars *efivars,
9524fc756bdSMike Waychison 		     const struct efivar_operations *ops,
953e14ab23dSMatt Fleming 		     struct kobject *kobject);
954e14ab23dSMatt Fleming int efivars_unregister(struct efivars *efivars);
955e14ab23dSMatt Fleming struct kobject *efivars_kobject(void);
956e14ab23dSMatt Fleming 
957e14ab23dSMatt Fleming int efivar_init(int (*func)(efi_char16_t *, efi_guid_t, unsigned long, void *),
9581cfd6316SJulia Lawall 		void *data, bool duplicates, struct list_head *head);
959e14ab23dSMatt Fleming 
96021b3ddd3SSylvain Chouleur int efivar_entry_add(struct efivar_entry *entry, struct list_head *head);
96121b3ddd3SSylvain Chouleur int efivar_entry_remove(struct efivar_entry *entry);
962e14ab23dSMatt Fleming 
963e14ab23dSMatt Fleming int __efivar_entry_delete(struct efivar_entry *entry);
964e14ab23dSMatt Fleming int efivar_entry_delete(struct efivar_entry *entry);
965e14ab23dSMatt Fleming 
966e14ab23dSMatt Fleming int efivar_entry_size(struct efivar_entry *entry, unsigned long *size);
9678a415b8cSMatt Fleming int __efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
9688a415b8cSMatt Fleming 		       unsigned long *size, void *data);
969e14ab23dSMatt Fleming int efivar_entry_get(struct efivar_entry *entry, u32 *attributes,
970e14ab23dSMatt Fleming 		     unsigned long *size, void *data);
971e14ab23dSMatt Fleming int efivar_entry_set(struct efivar_entry *entry, u32 attributes,
972e14ab23dSMatt Fleming 		     unsigned long size, void *data, struct list_head *head);
973e14ab23dSMatt Fleming int efivar_entry_set_get_size(struct efivar_entry *entry, u32 attributes,
974e14ab23dSMatt Fleming 			      unsigned long *size, void *data, bool *set);
975e14ab23dSMatt Fleming int efivar_entry_set_safe(efi_char16_t *name, efi_guid_t vendor, u32 attributes,
976e14ab23dSMatt Fleming 			  bool block, unsigned long size, void *data);
977e14ab23dSMatt Fleming 
97821b3ddd3SSylvain Chouleur int efivar_entry_iter_begin(void);
979e14ab23dSMatt Fleming void efivar_entry_iter_end(void);
980e14ab23dSMatt Fleming 
981e14ab23dSMatt Fleming int __efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
982e14ab23dSMatt Fleming 			struct list_head *head, void *data,
983e14ab23dSMatt Fleming 			struct efivar_entry **prev);
984e14ab23dSMatt Fleming int efivar_entry_iter(int (*func)(struct efivar_entry *, void *),
985e14ab23dSMatt Fleming 		      struct list_head *head, void *data);
986e14ab23dSMatt Fleming 
987e14ab23dSMatt Fleming struct efivar_entry *efivar_entry_find(efi_char16_t *name, efi_guid_t guid,
988e14ab23dSMatt Fleming 				       struct list_head *head, bool remove);
989e14ab23dSMatt Fleming 
9908282f5d9SPeter Jones bool efivar_validate(efi_guid_t vendor, efi_char16_t *var_name, u8 *data,
9918282f5d9SPeter Jones 		     unsigned long data_size);
992ed8b0de5SPeter Jones bool efivar_variable_is_removable(efi_guid_t vendor, const char *name,
993ed8b0de5SPeter Jones 				  size_t len);
994e14ab23dSMatt Fleming 
995a9499fa7STom Gundersen extern struct work_struct efivar_work;
99604851772SMatt Fleming void efivar_run_worker(void);
99704851772SMatt Fleming 
998a9499fa7STom Gundersen #if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
999e14ab23dSMatt Fleming int efivars_sysfs_init(void);
10004fc756bdSMike Waychison 
1001e0d59733SSeiji Aguchi #define EFIVARS_DATA_SIZE_MAX 1024
1002e0d59733SSeiji Aguchi 
10034fc756bdSMike Waychison #endif /* CONFIG_EFI_VARS */
1004f0133f3cSMatt Fleming extern bool efi_capsule_pending(int *reset_type);
1005f0133f3cSMatt Fleming 
1006f0133f3cSMatt Fleming extern int efi_capsule_supported(efi_guid_t guid, u32 flags,
1007f0133f3cSMatt Fleming 				 size_t size, int *reset);
1008f0133f3cSMatt Fleming 
1009f0133f3cSMatt Fleming extern int efi_capsule_update(efi_capsule_header_t *capsule,
10102a457fb3SArd Biesheuvel 			      phys_addr_t *pages);
10114fc756bdSMike Waychison 
1012926172d4SDave Young #ifdef CONFIG_EFI_RUNTIME_MAP
1013926172d4SDave Young int efi_runtime_map_init(struct kobject *);
10146a2c20e7SVivek Goyal int efi_get_runtime_map_size(void);
10156a2c20e7SVivek Goyal int efi_get_runtime_map_desc_size(void);
10166a2c20e7SVivek Goyal int efi_runtime_map_copy(void *buf, size_t bufsz);
1017926172d4SDave Young #else
1018926172d4SDave Young static inline int efi_runtime_map_init(struct kobject *kobj)
1019926172d4SDave Young {
1020926172d4SDave Young 	return 0;
1021926172d4SDave Young }
1022926172d4SDave Young 
10236a2c20e7SVivek Goyal static inline int efi_get_runtime_map_size(void)
10246a2c20e7SVivek Goyal {
10256a2c20e7SVivek Goyal 	return 0;
10266a2c20e7SVivek Goyal }
10276a2c20e7SVivek Goyal 
10286a2c20e7SVivek Goyal static inline int efi_get_runtime_map_desc_size(void)
10296a2c20e7SVivek Goyal {
10306a2c20e7SVivek Goyal 	return 0;
10316a2c20e7SVivek Goyal }
10326a2c20e7SVivek Goyal 
10336a2c20e7SVivek Goyal static inline int efi_runtime_map_copy(void *buf, size_t bufsz)
10346a2c20e7SVivek Goyal {
10356a2c20e7SVivek Goyal 	return 0;
10366a2c20e7SVivek Goyal }
10376a2c20e7SVivek Goyal 
1038926172d4SDave Young #endif
1039926172d4SDave Young 
10400082517fSJian-Hong Pan #ifdef CONFIG_EFI
10410082517fSJian-Hong Pan extern bool efi_runtime_disabled(void);
10420082517fSJian-Hong Pan #else
10430082517fSJian-Hong Pan static inline bool efi_runtime_disabled(void) { return true; }
10440082517fSJian-Hong Pan #endif
10450082517fSJian-Hong Pan 
104680e75596SAlex Thorlton extern void efi_call_virt_check_flags(unsigned long flags, const char *call);
104713b210ddSJulien Thierry extern unsigned long efi_call_virt_save_flags(void);
104880e75596SAlex Thorlton 
1049de8cb458SDavid Howells enum efi_secureboot_mode {
1050de8cb458SDavid Howells 	efi_secureboot_mode_unset,
1051de8cb458SDavid Howells 	efi_secureboot_mode_unknown,
1052de8cb458SDavid Howells 	efi_secureboot_mode_disabled,
1053de8cb458SDavid Howells 	efi_secureboot_mode_enabled,
1054de8cb458SDavid Howells };
1055cd33a5c1SArd Biesheuvel enum efi_secureboot_mode efi_get_secureboot(void);
1056de8cb458SDavid Howells 
1057ccc829baSMatthew Garrett #ifdef CONFIG_RESET_ATTACK_MITIGATION
1058cd33a5c1SArd Biesheuvel void efi_enable_reset_attack_mitigation(void);
1059ccc829baSMatthew Garrett #else
1060ccc829baSMatthew Garrett static inline void
1061cd33a5c1SArd Biesheuvel efi_enable_reset_attack_mitigation(void) { }
1062ccc829baSMatthew Garrett #endif
1063ccc829baSMatthew Garrett 
1064cd33a5c1SArd Biesheuvel efi_status_t efi_random_get_seed(void);
10650d959814SDominik Brodowski 
1066cd33a5c1SArd Biesheuvel void efi_retrieve_tpm2_eventlog(void);
106733b6d034SThiebaud Weksteen 
106880e75596SAlex Thorlton /*
106980e75596SAlex Thorlton  * Arch code can implement the following three template macros, avoiding
107080e75596SAlex Thorlton  * reptition for the void/non-void return cases of {__,}efi_call_virt():
107180e75596SAlex Thorlton  *
107280e75596SAlex Thorlton  *  * arch_efi_call_virt_setup()
107380e75596SAlex Thorlton  *
107480e75596SAlex Thorlton  *    Sets up the environment for the call (e.g. switching page tables,
107580e75596SAlex Thorlton  *    allowing kernel-mode use of floating point, if required).
107680e75596SAlex Thorlton  *
107780e75596SAlex Thorlton  *  * arch_efi_call_virt()
107880e75596SAlex Thorlton  *
107980e75596SAlex Thorlton  *    Performs the call. The last expression in the macro must be the call
108080e75596SAlex Thorlton  *    itself, allowing the logic to be shared by the void and non-void
108180e75596SAlex Thorlton  *    cases.
108280e75596SAlex Thorlton  *
108380e75596SAlex Thorlton  *  * arch_efi_call_virt_teardown()
108480e75596SAlex Thorlton  *
108580e75596SAlex Thorlton  *    Restores the usual kernel environment once the call has returned.
108680e75596SAlex Thorlton  */
108780e75596SAlex Thorlton 
108880e75596SAlex Thorlton #define efi_call_virt_pointer(p, f, args...)				\
108980e75596SAlex Thorlton ({									\
109080e75596SAlex Thorlton 	efi_status_t __s;						\
109180e75596SAlex Thorlton 	unsigned long __flags;						\
109280e75596SAlex Thorlton 									\
109380e75596SAlex Thorlton 	arch_efi_call_virt_setup();					\
109480e75596SAlex Thorlton 									\
109513b210ddSJulien Thierry 	__flags = efi_call_virt_save_flags();				\
109680e75596SAlex Thorlton 	__s = arch_efi_call_virt(p, f, args);				\
109780e75596SAlex Thorlton 	efi_call_virt_check_flags(__flags, __stringify(f));		\
109880e75596SAlex Thorlton 									\
109980e75596SAlex Thorlton 	arch_efi_call_virt_teardown();					\
110080e75596SAlex Thorlton 									\
110180e75596SAlex Thorlton 	__s;								\
110280e75596SAlex Thorlton })
110380e75596SAlex Thorlton 
110480e75596SAlex Thorlton #define __efi_call_virt_pointer(p, f, args...)				\
110580e75596SAlex Thorlton ({									\
110680e75596SAlex Thorlton 	unsigned long __flags;						\
110780e75596SAlex Thorlton 									\
110880e75596SAlex Thorlton 	arch_efi_call_virt_setup();					\
110980e75596SAlex Thorlton 									\
111013b210ddSJulien Thierry 	__flags = efi_call_virt_save_flags();				\
111180e75596SAlex Thorlton 	arch_efi_call_virt(p, f, args);					\
111280e75596SAlex Thorlton 	efi_call_virt_check_flags(__flags, __stringify(f));		\
111380e75596SAlex Thorlton 									\
111480e75596SAlex Thorlton 	arch_efi_call_virt_teardown();					\
111580e75596SAlex Thorlton })
111680e75596SAlex Thorlton 
1117c2ceb5fdSArd Biesheuvel #define EFI_RANDOM_SEED_SIZE		64U
1118c2ceb5fdSArd Biesheuvel 
111963625988SArd Biesheuvel struct linux_efi_random_seed {
112063625988SArd Biesheuvel 	u32	size;
112163625988SArd Biesheuvel 	u8	bits[];
112263625988SArd Biesheuvel };
112363625988SArd Biesheuvel 
112433b6d034SThiebaud Weksteen struct linux_efi_tpm_eventlog {
112533b6d034SThiebaud Weksteen 	u32	size;
1126166a2809SMatthew Garrett 	u32	final_events_preboot_size;
112733b6d034SThiebaud Weksteen 	u8	version;
112833b6d034SThiebaud Weksteen 	u8	log[];
112933b6d034SThiebaud Weksteen };
113033b6d034SThiebaud Weksteen 
113133b6d034SThiebaud Weksteen extern int efi_tpm_eventlog_init(void);
113233b6d034SThiebaud Weksteen 
1133c46f3405SMatthew Garrett struct efi_tcg2_final_events_table {
1134c46f3405SMatthew Garrett 	u64 version;
1135c46f3405SMatthew Garrett 	u64 nr_events;
1136c46f3405SMatthew Garrett 	u8 events[];
1137c46f3405SMatthew Garrett };
1138c46f3405SMatthew Garrett extern int efi_tpm_final_log_size;
1139c46f3405SMatthew Garrett 
11401c5fecb6SNarendra K extern unsigned long rci2_table_phys;
11411c5fecb6SNarendra K 
11423425d934SSai Praneeth /*
11433425d934SSai Praneeth  * efi_runtime_service() function identifiers.
11443425d934SSai Praneeth  * "NONE" is used by efi_recover_from_page_fault() to check if the page
11453425d934SSai Praneeth  * fault happened while executing an efi runtime service.
11463425d934SSai Praneeth  */
11479dbbedaaSSai Praneeth enum efi_rts_ids {
11485c418dc7SAnders Roxell 	EFI_NONE,
11495c418dc7SAnders Roxell 	EFI_GET_TIME,
11505c418dc7SAnders Roxell 	EFI_SET_TIME,
11515c418dc7SAnders Roxell 	EFI_GET_WAKEUP_TIME,
11525c418dc7SAnders Roxell 	EFI_SET_WAKEUP_TIME,
11535c418dc7SAnders Roxell 	EFI_GET_VARIABLE,
11545c418dc7SAnders Roxell 	EFI_GET_NEXT_VARIABLE,
11555c418dc7SAnders Roxell 	EFI_SET_VARIABLE,
11565c418dc7SAnders Roxell 	EFI_QUERY_VARIABLE_INFO,
11575c418dc7SAnders Roxell 	EFI_GET_NEXT_HIGH_MONO_COUNT,
11585c418dc7SAnders Roxell 	EFI_RESET_SYSTEM,
11595c418dc7SAnders Roxell 	EFI_UPDATE_CAPSULE,
11605c418dc7SAnders Roxell 	EFI_QUERY_CAPSULE_CAPS,
11619dbbedaaSSai Praneeth };
11629dbbedaaSSai Praneeth 
11639dbbedaaSSai Praneeth /*
11649dbbedaaSSai Praneeth  * efi_runtime_work:	Details of EFI Runtime Service work
11659dbbedaaSSai Praneeth  * @arg<1-5>:		EFI Runtime Service function arguments
11669dbbedaaSSai Praneeth  * @status:		Status of executing EFI Runtime Service
11679dbbedaaSSai Praneeth  * @efi_rts_id:		EFI Runtime Service function identifier
11689dbbedaaSSai Praneeth  * @efi_rts_comp:	Struct used for handling completions
11699dbbedaaSSai Praneeth  */
11709dbbedaaSSai Praneeth struct efi_runtime_work {
11719dbbedaaSSai Praneeth 	void *arg1;
11729dbbedaaSSai Praneeth 	void *arg2;
11739dbbedaaSSai Praneeth 	void *arg3;
11749dbbedaaSSai Praneeth 	void *arg4;
11759dbbedaaSSai Praneeth 	void *arg5;
11769dbbedaaSSai Praneeth 	efi_status_t status;
11779dbbedaaSSai Praneeth 	struct work_struct work;
11789dbbedaaSSai Praneeth 	enum efi_rts_ids efi_rts_id;
11799dbbedaaSSai Praneeth 	struct completion efi_rts_comp;
11809dbbedaaSSai Praneeth };
11819dbbedaaSSai Praneeth 
11829dbbedaaSSai Praneeth extern struct efi_runtime_work efi_rts_work;
11839dbbedaaSSai Praneeth 
11843eb420e7SSai Praneeth /* Workqueue to queue EFI Runtime Services */
11853eb420e7SSai Praneeth extern struct workqueue_struct *efi_rts_wq;
11863eb420e7SSai Praneeth 
118771e0940dSArd Biesheuvel struct linux_efi_memreserve {
11885f0b0ecfSArd Biesheuvel 	int		size;			// allocated size of the array
11895f0b0ecfSArd Biesheuvel 	atomic_t	count;			// number of entries used
11905f0b0ecfSArd Biesheuvel 	phys_addr_t	next;			// pa of next struct instance
11915f0b0ecfSArd Biesheuvel 	struct {
119271e0940dSArd Biesheuvel 		phys_addr_t	base;
119371e0940dSArd Biesheuvel 		phys_addr_t	size;
11945f0b0ecfSArd Biesheuvel 	} entry[0];
119571e0940dSArd Biesheuvel };
119671e0940dSArd Biesheuvel 
11975f0b0ecfSArd Biesheuvel #define EFI_MEMRESERVE_SIZE(count) (sizeof(struct linux_efi_memreserve) + \
11985f0b0ecfSArd Biesheuvel 	(count) * sizeof(((struct linux_efi_memreserve *)0)->entry[0]))
11995f0b0ecfSArd Biesheuvel 
120080424b02SArd Biesheuvel #define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \
120180424b02SArd Biesheuvel 	/ sizeof(((struct linux_efi_memreserve *)0)->entry[0]))
120280424b02SArd Biesheuvel 
12031da177e4SLinus Torvalds #endif /* _LINUX_EFI_H */
1204