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>
271da177e4SLinus Torvalds
281da177e4SLinus Torvalds #include <asm/page.h>
291da177e4SLinus Torvalds
308b0d1354SThomas Zimmermann struct screen_info;
318b0d1354SThomas Zimmermann
321da177e4SLinus Torvalds #define EFI_SUCCESS 0
331da177e4SLinus Torvalds #define EFI_LOAD_ERROR ( 1 | (1UL << (BITS_PER_LONG-1)))
341da177e4SLinus Torvalds #define EFI_INVALID_PARAMETER ( 2 | (1UL << (BITS_PER_LONG-1)))
351da177e4SLinus Torvalds #define EFI_UNSUPPORTED ( 3 | (1UL << (BITS_PER_LONG-1)))
361da177e4SLinus Torvalds #define EFI_BAD_BUFFER_SIZE ( 4 | (1UL << (BITS_PER_LONG-1)))
371da177e4SLinus Torvalds #define EFI_BUFFER_TOO_SMALL ( 5 | (1UL << (BITS_PER_LONG-1)))
385d9db883SMatthew Garrett #define EFI_NOT_READY ( 6 | (1UL << (BITS_PER_LONG-1)))
395d9db883SMatthew Garrett #define EFI_DEVICE_ERROR ( 7 | (1UL << (BITS_PER_LONG-1)))
405d9db883SMatthew Garrett #define EFI_WRITE_PROTECTED ( 8 | (1UL << (BITS_PER_LONG-1)))
415d9db883SMatthew Garrett #define EFI_OUT_OF_RESOURCES ( 9 | (1UL << (BITS_PER_LONG-1)))
421da177e4SLinus Torvalds #define EFI_NOT_FOUND (14 | (1UL << (BITS_PER_LONG-1)))
4314c574f3SArvind Sankar #define EFI_TIMEOUT (18 | (1UL << (BITS_PER_LONG-1)))
44dce48e35SArd Biesheuvel #define EFI_ABORTED (21 | (1UL << (BITS_PER_LONG-1)))
455d9db883SMatthew Garrett #define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG-1)))
461da177e4SLinus Torvalds
471da177e4SLinus Torvalds typedef unsigned long efi_status_t;
481da177e4SLinus Torvalds typedef u8 efi_bool_t;
491da177e4SLinus Torvalds typedef u16 efi_char16_t; /* UNICODE character */
50ed37ddffSRoy Franz typedef u64 efi_physical_addr_t;
51ed37ddffSRoy Franz typedef void *efi_handle_t;
521da177e4SLinus Torvalds
5389ed4865SArd Biesheuvel #if defined(CONFIG_X86_64)
548f24f8c2SArd Biesheuvel #define __efiapi __attribute__((ms_abi))
5589ed4865SArd Biesheuvel #elif defined(CONFIG_X86_32)
5689ed4865SArd Biesheuvel #define __efiapi __attribute__((regparm(0)))
578f24f8c2SArd Biesheuvel #else
588f24f8c2SArd Biesheuvel #define __efiapi
598f24f8c2SArd Biesheuvel #endif
608f24f8c2SArd Biesheuvel
61494c704fSArd Biesheuvel /*
62494c704fSArd Biesheuvel * The UEFI spec and EDK2 reference implementation both define EFI_GUID as
63494c704fSArd Biesheuvel * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment
64494c704fSArd Biesheuvel * is 32 bits not 8 bits like our guid_t. In some cases (i.e., on 32-bit ARM),
65494c704fSArd Biesheuvel * this means that firmware services invoked by the kernel may assume that
66494c704fSArd Biesheuvel * efi_guid_t* arguments are 32-bit aligned, and use memory accessors that
67494c704fSArd Biesheuvel * do not tolerate misalignment. So let's set the minimum alignment to 32 bits.
68494c704fSArd Biesheuvel *
69494c704fSArd Biesheuvel * Note that the UEFI spec as well as some comments in the EDK2 code base
70494c704fSArd Biesheuvel * suggest that EFI_GUID should be 64-bit aligned, but this appears to be
71494c704fSArd Biesheuvel * a mistake, given that no code seems to exist that actually enforces that
72494c704fSArd Biesheuvel * or relies on it.
73494c704fSArd Biesheuvel */
74494c704fSArd Biesheuvel typedef guid_t efi_guid_t __aligned(__alignof__(u32));
751da177e4SLinus Torvalds
76fb98cc0bSArd Biesheuvel #define EFI_GUID(a, b, c, d...) (efi_guid_t){ { \
77fb98cc0bSArd Biesheuvel (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \
78fb98cc0bSArd Biesheuvel (b) & 0xff, ((b) >> 8) & 0xff, \
79fb98cc0bSArd Biesheuvel (c) & 0xff, ((c) >> 8) & 0xff, d } }
801da177e4SLinus Torvalds
811da177e4SLinus Torvalds /*
821da177e4SLinus Torvalds * Generic EFI table header
831da177e4SLinus Torvalds */
841da177e4SLinus Torvalds typedef struct {
851da177e4SLinus Torvalds u64 signature;
861da177e4SLinus Torvalds u32 revision;
871da177e4SLinus Torvalds u32 headersize;
881da177e4SLinus Torvalds u32 crc32;
891da177e4SLinus Torvalds u32 reserved;
901da177e4SLinus Torvalds } efi_table_hdr_t;
911da177e4SLinus Torvalds
921da177e4SLinus Torvalds /*
931da177e4SLinus Torvalds * Memory map descriptor:
941da177e4SLinus Torvalds */
951da177e4SLinus Torvalds
961da177e4SLinus Torvalds /* Memory types: */
971da177e4SLinus Torvalds #define EFI_RESERVED_TYPE 0
981da177e4SLinus Torvalds #define EFI_LOADER_CODE 1
991da177e4SLinus Torvalds #define EFI_LOADER_DATA 2
1001da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_CODE 3
1011da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_DATA 4
1021da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_CODE 5
1031da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_DATA 6
1041da177e4SLinus Torvalds #define EFI_CONVENTIONAL_MEMORY 7
1051da177e4SLinus Torvalds #define EFI_UNUSABLE_MEMORY 8
1061da177e4SLinus Torvalds #define EFI_ACPI_RECLAIM_MEMORY 9
1071da177e4SLinus Torvalds #define EFI_ACPI_MEMORY_NVS 10
1081da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO 11
1091da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12
1101da177e4SLinus Torvalds #define EFI_PAL_CODE 13
111ad5fb870SDan Williams #define EFI_PERSISTENT_MEMORY 14
112745e3ed8SKirill A. Shutemov #define EFI_UNACCEPTED_MEMORY 15
113745e3ed8SKirill A. Shutemov #define EFI_MAX_MEMORY_TYPE 16
1141da177e4SLinus Torvalds
1151da177e4SLinus Torvalds /* Attribute values: */
1161da177e4SLinus Torvalds #define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */
1171da177e4SLinus Torvalds #define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */
1181da177e4SLinus Torvalds #define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */
1191da177e4SLinus Torvalds #define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */
1209c97e0bdSLaszlo Ersek #define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */
1211da177e4SLinus Torvalds #define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */
1221da177e4SLinus Torvalds #define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */
1231da177e4SLinus Torvalds #define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */
124c016ca08SRobert Elliott #define EFI_MEMORY_NV ((u64)0x0000000000008000ULL) /* non-volatile */
125b05b9f5fSTony Luck #define EFI_MEMORY_MORE_RELIABLE \
126b05b9f5fSTony Luck ((u64)0x0000000000010000ULL) /* higher reliability */
12787db73aeSArd Biesheuvel #define EFI_MEMORY_RO ((u64)0x0000000000020000ULL) /* read-only */
128fe3e5e65SDan Williams #define EFI_MEMORY_SP ((u64)0x0000000000040000ULL) /* soft reserved */
1296277e374SArd Biesheuvel #define EFI_MEMORY_CPU_CRYPTO ((u64)0x0000000000080000ULL) /* supports encryption */
1301da177e4SLinus Torvalds #define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */
1311da177e4SLinus Torvalds #define EFI_MEMORY_DESCRIPTOR_VERSION 1
1321da177e4SLinus Torvalds
1331da177e4SLinus Torvalds #define EFI_PAGE_SHIFT 12
134ed37ddffSRoy Franz #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
1350100a3e6SPeter Jones #define EFI_PAGES_MAX (U64_MAX >> EFI_PAGE_SHIFT)
1361da177e4SLinus Torvalds
1371da177e4SLinus Torvalds typedef struct {
1381da177e4SLinus Torvalds u32 type;
1391da177e4SLinus Torvalds u32 pad;
1401da177e4SLinus Torvalds u64 phys_addr;
1411da177e4SLinus Torvalds u64 virt_addr;
1421da177e4SLinus Torvalds u64 num_pages;
1431da177e4SLinus Torvalds u64 attribute;
1441da177e4SLinus Torvalds } efi_memory_desc_t;
1451da177e4SLinus Torvalds
1463b370237SMatthew Garrett typedef struct {
1473b370237SMatthew Garrett efi_guid_t guid;
1483b370237SMatthew Garrett u32 headersize;
1493b370237SMatthew Garrett u32 flags;
1503b370237SMatthew Garrett u32 imagesize;
1513b370237SMatthew Garrett } efi_capsule_header_t;
1523b370237SMatthew Garrett
1531882de7fSChen Yu /* EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER */
1541882de7fSChen Yu struct efi_manage_capsule_header {
1551882de7fSChen Yu u32 ver;
1561882de7fSChen Yu u16 emb_drv_cnt;
1571882de7fSChen Yu u16 payload_cnt;
1581882de7fSChen Yu /*
1591882de7fSChen Yu * Variable-size array of the size given by the sum of
1601882de7fSChen Yu * emb_drv_cnt and payload_cnt.
1611882de7fSChen Yu */
1621882de7fSChen Yu u64 offset_list[];
1631882de7fSChen Yu } __packed;
1641882de7fSChen Yu
1651882de7fSChen Yu /* EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER */
1661882de7fSChen Yu struct efi_manage_capsule_image_header {
1671882de7fSChen Yu u32 ver;
1681882de7fSChen Yu efi_guid_t image_type_id;
1691882de7fSChen Yu u8 image_index;
1701882de7fSChen Yu u8 reserved_bytes[3];
1711882de7fSChen Yu u32 image_size;
1721882de7fSChen Yu u32 vendor_code_size;
1731882de7fSChen Yu /* hw_ins was introduced in version 2 */
1741882de7fSChen Yu u64 hw_ins;
1751882de7fSChen Yu /* capsule_support was introduced in version 3 */
1761882de7fSChen Yu u64 capsule_support;
1771882de7fSChen Yu } __packed;
1781882de7fSChen Yu
1791882de7fSChen Yu /* WIN_CERTIFICATE */
1801882de7fSChen Yu struct win_cert {
1811882de7fSChen Yu u32 len;
1821882de7fSChen Yu u16 rev;
1831882de7fSChen Yu u16 cert_type;
1841882de7fSChen Yu };
1851882de7fSChen Yu
1861882de7fSChen Yu /* WIN_CERTIFICATE_UEFI_GUID */
1871882de7fSChen Yu struct win_cert_uefi_guid {
1881882de7fSChen Yu struct win_cert hdr;
1891882de7fSChen Yu efi_guid_t cert_type;
1901882de7fSChen Yu u8 cert_data[];
1911882de7fSChen Yu };
1921882de7fSChen Yu
1931882de7fSChen Yu /* EFI_FIRMWARE_IMAGE_AUTHENTICATION */
1941882de7fSChen Yu struct efi_image_auth {
1951882de7fSChen Yu u64 mon_count;
1961882de7fSChen Yu struct win_cert_uefi_guid auth_info;
1971882de7fSChen Yu };
1981882de7fSChen Yu
199bb05e4baSMatt Fleming /*
200f0133f3cSMatt Fleming * EFI capsule flags
201f0133f3cSMatt Fleming */
202f0133f3cSMatt Fleming #define EFI_CAPSULE_PERSIST_ACROSS_RESET 0x00010000
203f0133f3cSMatt Fleming #define EFI_CAPSULE_POPULATE_SYSTEM_TABLE 0x00020000
204f0133f3cSMatt Fleming #define EFI_CAPSULE_INITIATE_RESET 0x00040000
205f0133f3cSMatt Fleming
2063fabd628SArd Biesheuvel struct capsule_info {
2073fabd628SArd Biesheuvel efi_capsule_header_t header;
208f24c4d47SArd Biesheuvel efi_capsule_header_t *capsule;
2093fabd628SArd Biesheuvel int reset_type;
2103fabd628SArd Biesheuvel long index;
2113fabd628SArd Biesheuvel size_t count;
2123fabd628SArd Biesheuvel size_t total_size;
213f24c4d47SArd Biesheuvel struct page **pages;
214f24c4d47SArd Biesheuvel phys_addr_t *phys;
2153fabd628SArd Biesheuvel size_t page_bytes_remain;
2163fabd628SArd Biesheuvel };
2173fabd628SArd Biesheuvel
218aa480379SJan Kiszka int efi_capsule_setup_info(struct capsule_info *cap_info, void *kbuff,
219aa480379SJan Kiszka size_t hdr_bytes);
2203fabd628SArd Biesheuvel int __efi_capsule_setup_info(struct capsule_info *cap_info);
2213fabd628SArd Biesheuvel
2221da177e4SLinus Torvalds /*
2231da177e4SLinus Torvalds * Types and defines for Time Services
2241da177e4SLinus Torvalds */
2251da177e4SLinus Torvalds #define EFI_TIME_ADJUST_DAYLIGHT 0x1
2261da177e4SLinus Torvalds #define EFI_TIME_IN_DAYLIGHT 0x2
2271da177e4SLinus Torvalds #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
2281da177e4SLinus Torvalds
2291da177e4SLinus Torvalds typedef struct {
2301da177e4SLinus Torvalds u16 year;
2311da177e4SLinus Torvalds u8 month;
2321da177e4SLinus Torvalds u8 day;
2331da177e4SLinus Torvalds u8 hour;
2341da177e4SLinus Torvalds u8 minute;
2351da177e4SLinus Torvalds u8 second;
2361da177e4SLinus Torvalds u8 pad1;
2371da177e4SLinus Torvalds u32 nanosecond;
2381da177e4SLinus Torvalds s16 timezone;
2391da177e4SLinus Torvalds u8 daylight;
2401da177e4SLinus Torvalds u8 pad2;
2411da177e4SLinus Torvalds } efi_time_t;
2421da177e4SLinus Torvalds
2431da177e4SLinus Torvalds typedef struct {
2441da177e4SLinus Torvalds u32 resolution;
2451da177e4SLinus Torvalds u32 accuracy;
2461da177e4SLinus Torvalds u8 sets_to_zero;
2471da177e4SLinus Torvalds } efi_time_cap_t;
2481da177e4SLinus Torvalds
2498166ec09SArd Biesheuvel typedef union efi_boot_services efi_boot_services_t;
25033b6d034SThiebaud Weksteen
251f30ca6baSMatt Fleming /*
2521da177e4SLinus Torvalds * Types and defines for EFI ResetSystem
2531da177e4SLinus Torvalds */
2541da177e4SLinus Torvalds #define EFI_RESET_COLD 0
2551da177e4SLinus Torvalds #define EFI_RESET_WARM 1
2561da177e4SLinus Torvalds #define EFI_RESET_SHUTDOWN 2
2571da177e4SLinus Torvalds
2581da177e4SLinus Torvalds /*
2591da177e4SLinus Torvalds * EFI Runtime Services table
2601da177e4SLinus Torvalds */
2611da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL)
2621da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_REVISION 0x00010000
2631da177e4SLinus Torvalds
2641da177e4SLinus Torvalds typedef struct {
2651da177e4SLinus Torvalds efi_table_hdr_t hdr;
266677703ceSMatt Fleming u32 get_time;
267677703ceSMatt Fleming u32 set_time;
268677703ceSMatt Fleming u32 get_wakeup_time;
269677703ceSMatt Fleming u32 set_wakeup_time;
270677703ceSMatt Fleming u32 set_virtual_address_map;
271677703ceSMatt Fleming u32 convert_pointer;
272677703ceSMatt Fleming u32 get_variable;
273677703ceSMatt Fleming u32 get_next_variable;
274677703ceSMatt Fleming u32 set_variable;
275677703ceSMatt Fleming u32 get_next_high_mono_count;
276677703ceSMatt Fleming u32 reset_system;
277677703ceSMatt Fleming u32 update_capsule;
278677703ceSMatt Fleming u32 query_capsule_caps;
279677703ceSMatt Fleming u32 query_variable_info;
280677703ceSMatt Fleming } efi_runtime_services_32_t;
281677703ceSMatt Fleming
2821da177e4SLinus Torvalds typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc);
2831da177e4SLinus Torvalds typedef efi_status_t efi_set_time_t (efi_time_t *tm);
2841da177e4SLinus Torvalds typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending,
2851da177e4SLinus Torvalds efi_time_t *tm);
2861da177e4SLinus Torvalds typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm);
2871da177e4SLinus Torvalds typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr,
2881da177e4SLinus Torvalds unsigned long *data_size, void *data);
2891da177e4SLinus Torvalds typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
2901da177e4SLinus Torvalds efi_guid_t *vendor);
2911da177e4SLinus Torvalds typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
292f7a2d73fSMatthew Garrett u32 attr, unsigned long data_size,
2931da177e4SLinus Torvalds void *data);
2941da177e4SLinus Torvalds typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
2951da177e4SLinus Torvalds typedef void efi_reset_system_t (int reset_type, efi_status_t status,
2961da177e4SLinus Torvalds unsigned long data_size, efi_char16_t *data);
2971da177e4SLinus Torvalds typedef efi_status_t efi_set_virtual_address_map_t (unsigned long memory_map_size,
2981da177e4SLinus Torvalds unsigned long descriptor_size,
2991da177e4SLinus Torvalds u32 descriptor_version,
3001da177e4SLinus Torvalds efi_memory_desc_t *virtual_map);
3013b370237SMatthew Garrett typedef efi_status_t efi_query_variable_info_t(u32 attr,
3023b370237SMatthew Garrett u64 *storage_space,
3033b370237SMatthew Garrett u64 *remaining_space,
3043b370237SMatthew Garrett u64 *max_variable_size);
3053b370237SMatthew Garrett typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules,
3063b370237SMatthew Garrett unsigned long count,
3073b370237SMatthew Garrett unsigned long sg_list);
3083b370237SMatthew Garrett typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules,
3093b370237SMatthew Garrett unsigned long count,
3103b370237SMatthew Garrett u64 *max_size,
3113b370237SMatthew Garrett int *reset_type);
312ca0e30dcSArd Biesheuvel typedef efi_status_t efi_query_variable_store_t(u32 attributes,
313ca0e30dcSArd Biesheuvel unsigned long size,
314ca0e30dcSArd Biesheuvel bool nonblocking);
3151da177e4SLinus Torvalds
3161786e830SArd Biesheuvel typedef union {
3171786e830SArd Biesheuvel struct {
318c4c39c70SArd Biesheuvel efi_table_hdr_t hdr;
3198f24f8c2SArd Biesheuvel efi_get_time_t __efiapi *get_time;
3208f24f8c2SArd Biesheuvel efi_set_time_t __efiapi *set_time;
3218f24f8c2SArd Biesheuvel efi_get_wakeup_time_t __efiapi *get_wakeup_time;
3228f24f8c2SArd Biesheuvel efi_set_wakeup_time_t __efiapi *set_wakeup_time;
3238f24f8c2SArd Biesheuvel efi_set_virtual_address_map_t __efiapi *set_virtual_address_map;
324c4c39c70SArd Biesheuvel void *convert_pointer;
3258f24f8c2SArd Biesheuvel efi_get_variable_t __efiapi *get_variable;
3268f24f8c2SArd Biesheuvel efi_get_next_variable_t __efiapi *get_next_variable;
3278f24f8c2SArd Biesheuvel efi_set_variable_t __efiapi *set_variable;
3288f24f8c2SArd Biesheuvel efi_get_next_high_mono_count_t __efiapi *get_next_high_mono_count;
3298f24f8c2SArd Biesheuvel efi_reset_system_t __efiapi *reset_system;
3308f24f8c2SArd Biesheuvel efi_update_capsule_t __efiapi *update_capsule;
3318f24f8c2SArd Biesheuvel efi_query_capsule_caps_t __efiapi *query_capsule_caps;
3328f24f8c2SArd Biesheuvel efi_query_variable_info_t __efiapi *query_variable_info;
3331786e830SArd Biesheuvel };
3341786e830SArd Biesheuvel efi_runtime_services_32_t mixed_mode;
335c4c39c70SArd Biesheuvel } efi_runtime_services_t;
336c4c39c70SArd Biesheuvel
337022ee6c5SArd Biesheuvel void efi_native_runtime_setup(void);
338022ee6c5SArd Biesheuvel
3391da177e4SLinus Torvalds /*
3401da177e4SLinus Torvalds * EFI Configuration Table and GUID definitions
34154fd11feSPeter Jones *
3427fb2b43cSIngo Molnar * These are all defined in a single line to make them easier to
3437fb2b43cSIngo Molnar * grep for and to see them at a glance - while still having a
3447fb2b43cSIngo Molnar * similar structure to the definitions in the spec.
3457fb2b43cSIngo Molnar *
3467fb2b43cSIngo Molnar * Here's how they are structured:
34754fd11feSPeter Jones *
34854fd11feSPeter Jones * GUID: 12345678-1234-1234-1234-123456789012
34954fd11feSPeter Jones * Spec:
35054fd11feSPeter Jones * #define EFI_SOME_PROTOCOL_GUID \
35154fd11feSPeter Jones * {0x12345678,0x1234,0x1234,\
35254fd11feSPeter Jones * {0x12,0x34,0x12,0x34,0x56,0x78,0x90,0x12}}
35354fd11feSPeter Jones * Here:
3547fb2b43cSIngo Molnar * #define SOME_PROTOCOL_GUID EFI_GUID(0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12)
3557fb2b43cSIngo Molnar * ^ tabs ^extra space
3567fb2b43cSIngo Molnar *
3577fb2b43cSIngo Molnar * Note that the 'extra space' separates the values at the same place
3587fb2b43cSIngo Molnar * where the UEFI SPEC breaks the line.
3591da177e4SLinus Torvalds */
3607fb2b43cSIngo Molnar #define NULL_GUID EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
3617fb2b43cSIngo Molnar #define MPS_TABLE_GUID EFI_GUID(0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
3627fb2b43cSIngo Molnar #define ACPI_TABLE_GUID EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
3637fb2b43cSIngo Molnar #define ACPI_20_TABLE_GUID EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
3647fb2b43cSIngo Molnar #define SMBIOS_TABLE_GUID EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
3657fb2b43cSIngo Molnar #define SMBIOS3_TABLE_GUID EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94)
3667fb2b43cSIngo Molnar #define SAL_SYSTEM_TABLE_GUID EFI_GUID(0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
3677fb2b43cSIngo Molnar #define HCDP_TABLE_GUID EFI_GUID(0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98)
3687fb2b43cSIngo Molnar #define UGA_IO_PROTOCOL_GUID EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2)
3697fb2b43cSIngo Molnar #define EFI_GLOBAL_VARIABLE_GUID EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
3707fb2b43cSIngo Molnar #define UV_SYSTEM_TABLE_GUID EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93)
3717fb2b43cSIngo Molnar #define LINUX_EFI_CRASH_GUID EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0)
3727fb2b43cSIngo Molnar #define LOADED_IMAGE_PROTOCOL_GUID EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
373c7007d9fSArd Biesheuvel #define LOADED_IMAGE_DEVICE_PATH_PROTOCOL_GUID EFI_GUID(0xbc62157e, 0x3e33, 0x4fec, 0x99, 0x20, 0x2d, 0x3b, 0x36, 0xd7, 0x50, 0xdf)
374c7007d9fSArd Biesheuvel #define EFI_DEVICE_PATH_PROTOCOL_GUID EFI_GUID(0x09576e91, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
375c7007d9fSArd Biesheuvel #define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID EFI_GUID(0x8b843e20, 0x8132, 0x4852, 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c)
37670912985SArd Biesheuvel #define EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID EFI_GUID(0x05c99a21, 0xc70f, 0x4ad2, 0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e)
3777fb2b43cSIngo Molnar #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
3787fb2b43cSIngo Molnar #define EFI_UGA_PROTOCOL_GUID EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39)
3797fb2b43cSIngo Molnar #define EFI_PCI_IO_PROTOCOL_GUID EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a)
3807fb2b43cSIngo Molnar #define EFI_FILE_INFO_ID EFI_GUID(0x09576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
3817fb2b43cSIngo Molnar #define EFI_SYSTEM_RESOURCE_TABLE_GUID EFI_GUID(0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
3827fb2b43cSIngo Molnar #define EFI_FILE_SYSTEM_GUID EFI_GUID(0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
3837fb2b43cSIngo Molnar #define DEVICE_TREE_GUID EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
3847fb2b43cSIngo Molnar #define EFI_PROPERTIES_TABLE_GUID EFI_GUID(0x880aaca3, 0x4adc, 0x4a04, 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5)
3857fb2b43cSIngo Molnar #define EFI_RNG_PROTOCOL_GUID EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)
386568bc4e8SArd Biesheuvel #define EFI_RNG_ALGORITHM_RAW EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)
3877fb2b43cSIngo Molnar #define EFI_MEMORY_ATTRIBUTES_TABLE_GUID EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
3887fb2b43cSIngo Molnar #define EFI_CONSOLE_OUT_DEVICE_GUID EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
38958c5475aSLukas Wunner #define APPLE_PROPERTIES_PROTOCOL_GUID EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0)
39033b6d034SThiebaud Weksteen #define EFI_TCG2_PROTOCOL_GUID EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
3912931d526SArd Biesheuvel #define EFI_LOAD_FILE_PROTOCOL_GUID EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
3922931d526SArd Biesheuvel #define EFI_LOAD_FILE2_PROTOCOL_GUID EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d)
393fe4db90aSArd Biesheuvel #define EFI_RT_PROPERTIES_TABLE_GUID EFI_GUID(0xeb66918a, 0x7eef, 0x402a, 0x84, 0x2e, 0x93, 0x1d, 0x21, 0xc3, 0x8a, 0xe9)
3943ba75c13SBaskov Evgeniy #define EFI_DXE_SERVICES_TABLE_GUID EFI_GUID(0x05ad34ba, 0x6f02, 0x4214, 0x95, 0x2e, 0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9)
395550b33cfSArd Biesheuvel #define EFI_SMBIOS_PROTOCOL_GUID EFI_GUID(0x03583ff6, 0xcb36, 0x4940, 0x94, 0x7e, 0xb9, 0xb3, 0x9f, 0x4a, 0xfa, 0xf7)
39679729f26SEvgeniy Baskov #define EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID EFI_GUID(0xf4560cf6, 0x40ec, 0x4b4a, 0xa1, 0x92, 0xbf, 0x1d, 0x57, 0xd0, 0xb1, 0x89)
397fc372064SArd Biesheuvel
398e58910cdSJosh Boyer #define EFI_IMAGE_SECURITY_DATABASE_GUID EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)
399e58910cdSJosh Boyer #define EFI_SHIM_LOCK_GUID EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23)
400e58910cdSJosh Boyer
4015c126ba2SDave Howells #define EFI_CERT_SHA256_GUID EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28)
4025c126ba2SDave Howells #define EFI_CERT_X509_GUID EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72)
4035c126ba2SDave Howells #define EFI_CERT_X509_SHA256_GUID EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed)
4045ea98e01SBrijesh Singh #define EFI_CC_BLOB_GUID EFI_GUID(0x067b1f5f, 0xcf26, 0x44c5, 0x85, 0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42)
4055c126ba2SDave Howells
406801820beSArd Biesheuvel /*
407801820beSArd Biesheuvel * This GUID is used to pass to the kernel proper the struct screen_info
408801820beSArd Biesheuvel * structure that was populated by the stub based on the GOP protocol instance
409801820beSArd Biesheuvel * associated with ConOut
410801820beSArd Biesheuvel */
411732ea9dbSArd Biesheuvel #define LINUX_EFI_SCREEN_INFO_TABLE_GUID EFI_GUID(0xe03fc20a, 0x85dc, 0x406e, 0xb9, 0x0e, 0x4a, 0xb5, 0x02, 0x37, 0x1d, 0x95)
4122a55280aSArd Biesheuvel #define LINUX_EFI_ARM_CPU_STATE_TABLE_GUID EFI_GUID(0xef79e4aa, 0x3c3d, 0x4989, 0xb9, 0x02, 0x07, 0xa9, 0x43, 0xe5, 0x50, 0xd2)
4137fb2b43cSIngo Molnar #define LINUX_EFI_LOADER_ENTRY_GUID EFI_GUID(0x4a67b082, 0x0a4c, 0x41cf, 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f)
41463625988SArd Biesheuvel #define LINUX_EFI_RANDOM_SEED_TABLE_GUID EFI_GUID(0x1ce1e5bc, 0x7ceb, 0x42f2, 0x81, 0xe5, 0x8a, 0xad, 0xf1, 0x80, 0xf5, 0x7b)
41533b6d034SThiebaud Weksteen #define LINUX_EFI_TPM_EVENT_LOG_GUID EFI_GUID(0xb7799cb0, 0xeca2, 0x4943, 0x96, 0x67, 0x1f, 0xae, 0x07, 0xb7, 0x47, 0xfa)
416c46f3405SMatthew Garrett #define LINUX_EFI_TPM_FINAL_LOG_GUID EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25)
41771e0940dSArd Biesheuvel #define LINUX_EFI_MEMRESERVE_TABLE_GUID EFI_GUID(0x888eb0c6, 0x8ede, 0x4ff5, 0xa8, 0xf0, 0x9a, 0xee, 0x5c, 0xb9, 0x77, 0xc2)
418ec93fc37SArd Biesheuvel #define LINUX_EFI_INITRD_MEDIA_GUID EFI_GUID(0x5568e427, 0x68fc, 0x4f3d, 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68)
41958c90902SLenny Szubowicz #define LINUX_EFI_MOK_VARIABLE_TABLE_GUID EFI_GUID(0xc451ed2b, 0x9694, 0x45d3, 0xba, 0xba, 0xed, 0x9f, 0x89, 0x88, 0xa3, 0x89)
42012274189SDov Murik #define LINUX_EFI_COCO_SECRET_AREA_GUID EFI_GUID(0xadf956ad, 0xe98c, 0x484c, 0xae, 0x11, 0xb5, 0x1c, 0x7d, 0x33, 0x64, 0x47)
421171539f5SArd Biesheuvel #define LINUX_EFI_BOOT_MEMMAP_GUID EFI_GUID(0x800f683f, 0xd08b, 0x423a, 0xa2, 0x93, 0x96, 0x5c, 0x3c, 0x6f, 0xe2, 0xb4)
422745e3ed8SKirill A. Shutemov #define LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID EFI_GUID(0xd5d1de3c, 0x105c, 0x44f9, 0x9e, 0xa9, 0xbc, 0xef, 0x98, 0x12, 0x00, 0x31)
42306f7d4a1SCompostella, Jeremy
4243f68e695SSunil V L #define RISCV_EFI_BOOT_PROTOCOL_GUID EFI_GUID(0xccd15fec, 0x6f73, 0x4eec, 0x83, 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf)
4253f68e695SSunil V L
42607768c55SArd Biesheuvel /*
42707768c55SArd Biesheuvel * This GUID may be installed onto the kernel image's handle as a NULL protocol
42807768c55SArd Biesheuvel * to signal to the stub that the placement of the image should be respected,
42907768c55SArd Biesheuvel * and moving the image in physical memory is undesirable. To ensure
43007768c55SArd Biesheuvel * compatibility with 64k pages kernels with virtually mapped stacks, and to
43107768c55SArd Biesheuvel * avoid defeating physical randomization, this protocol should only be
43207768c55SArd Biesheuvel * installed if the image was placed at a randomized 128k aligned address in
43307768c55SArd Biesheuvel * memory.
43407768c55SArd Biesheuvel */
43507768c55SArd Biesheuvel #define LINUX_EFI_LOADED_IMAGE_FIXED_GUID EFI_GUID(0xf5a37b6d, 0x3344, 0x42a5, 0xb6, 0xbb, 0x97, 0x86, 0x48, 0xc1, 0x89, 0x0a)
43607768c55SArd Biesheuvel
4371c5fecb6SNarendra K /* OEM GUIDs */
4381c5fecb6SNarendra K #define DELLEMC_EFI_RCI2_TABLE_GUID EFI_GUID(0x2d9f28a2, 0xa886, 0x456a, 0x97, 0xa8, 0xf1, 0x1e, 0xf2, 0x4f, 0xf4, 0x55)
4392f70ddb1SAshish Kalra #define AMD_SEV_MEM_ENCRYPT_GUID EFI_GUID(0x0cf29b71, 0x9e51, 0x433a, 0xa3, 0xb7, 0x81, 0xf3, 0xab, 0x16, 0xb8, 0x75)
4401c5fecb6SNarendra K
441c0461bd1SDionna Glaze /* OVMF protocol GUIDs */
442c0461bd1SDionna Glaze #define OVMF_SEV_MEMORY_ACCEPTANCE_PROTOCOL_GUID EFI_GUID(0xc5a010fe, 0x38a7, 0x4531, 0x8a, 0x4a, 0x05, 0x00, 0xd2, 0xfd, 0x16, 0x49)
443c0461bd1SDionna Glaze
4441da177e4SLinus Torvalds typedef struct {
4451da177e4SLinus Torvalds efi_guid_t guid;
4461adbfa35SOlof Johansson u64 table;
4471adbfa35SOlof Johansson } efi_config_table_64_t;
4481adbfa35SOlof Johansson
4491adbfa35SOlof Johansson typedef struct {
4501adbfa35SOlof Johansson efi_guid_t guid;
4511adbfa35SOlof Johansson u32 table;
4521adbfa35SOlof Johansson } efi_config_table_32_t;
4531adbfa35SOlof Johansson
4541786e830SArd Biesheuvel typedef union {
4551786e830SArd Biesheuvel struct {
4561adbfa35SOlof Johansson efi_guid_t guid;
457f958efe9SArd Biesheuvel void *table;
4581786e830SArd Biesheuvel };
4591786e830SArd Biesheuvel efi_config_table_32_t mixed_mode;
4601da177e4SLinus Torvalds } efi_config_table_t;
4611da177e4SLinus Torvalds
462272686bfSLeif Lindholm typedef struct {
463272686bfSLeif Lindholm efi_guid_t guid;
464272686bfSLeif Lindholm unsigned long *ptr;
4654e9a0f73SArd Biesheuvel const char name[16];
466272686bfSLeif Lindholm } efi_config_table_type_t;
467272686bfSLeif Lindholm
4681da177e4SLinus Torvalds #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
4693ba75c13SBaskov Evgeniy #define EFI_DXE_SERVICES_TABLE_SIGNATURE ((u64)0x565245535f455844ULL)
4701da177e4SLinus Torvalds
4713b370237SMatthew Garrett #define EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30))
4723b370237SMatthew Garrett #define EFI_2_20_SYSTEM_TABLE_REVISION ((2 << 16) | (20))
4733b370237SMatthew Garrett #define EFI_2_10_SYSTEM_TABLE_REVISION ((2 << 16) | (10))
4743b370237SMatthew Garrett #define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | (00))
4753b370237SMatthew Garrett #define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10))
4763b370237SMatthew Garrett #define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02))
4773b370237SMatthew Garrett
4781da177e4SLinus Torvalds typedef struct {
4791da177e4SLinus Torvalds efi_table_hdr_t hdr;
4801adbfa35SOlof Johansson u64 fw_vendor; /* physical addr of CHAR16 vendor string */
4811adbfa35SOlof Johansson u32 fw_revision;
4821adbfa35SOlof Johansson u32 __pad1;
4831adbfa35SOlof Johansson u64 con_in_handle;
4841adbfa35SOlof Johansson u64 con_in;
4851adbfa35SOlof Johansson u64 con_out_handle;
4861adbfa35SOlof Johansson u64 con_out;
4871adbfa35SOlof Johansson u64 stderr_handle;
4881adbfa35SOlof Johansson u64 stderr;
4891adbfa35SOlof Johansson u64 runtime;
4901adbfa35SOlof Johansson u64 boottime;
4911adbfa35SOlof Johansson u32 nr_tables;
4921adbfa35SOlof Johansson u32 __pad2;
4931adbfa35SOlof Johansson u64 tables;
4941adbfa35SOlof Johansson } efi_system_table_64_t;
4951adbfa35SOlof Johansson
4961adbfa35SOlof Johansson typedef struct {
4971adbfa35SOlof Johansson efi_table_hdr_t hdr;
4981adbfa35SOlof Johansson u32 fw_vendor; /* physical addr of CHAR16 vendor string */
4991adbfa35SOlof Johansson u32 fw_revision;
5001adbfa35SOlof Johansson u32 con_in_handle;
5011adbfa35SOlof Johansson u32 con_in;
5021adbfa35SOlof Johansson u32 con_out_handle;
5031adbfa35SOlof Johansson u32 con_out;
5041adbfa35SOlof Johansson u32 stderr_handle;
5051adbfa35SOlof Johansson u32 stderr;
5061adbfa35SOlof Johansson u32 runtime;
5071adbfa35SOlof Johansson u32 boottime;
5081adbfa35SOlof Johansson u32 nr_tables;
5091adbfa35SOlof Johansson u32 tables;
5101adbfa35SOlof Johansson } efi_system_table_32_t;
5111adbfa35SOlof Johansson
5129b47c527SArvind Sankar typedef union efi_simple_text_input_protocol efi_simple_text_input_protocol_t;
513960a8d01SArd Biesheuvel typedef union efi_simple_text_output_protocol efi_simple_text_output_protocol_t;
514960a8d01SArd Biesheuvel
5151786e830SArd Biesheuvel typedef union {
5161786e830SArd Biesheuvel struct {
5171adbfa35SOlof Johansson efi_table_hdr_t hdr;
5181da177e4SLinus Torvalds unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */
5191da177e4SLinus Torvalds u32 fw_revision;
5201da177e4SLinus Torvalds unsigned long con_in_handle;
5219b47c527SArvind Sankar efi_simple_text_input_protocol_t *con_in;
5221da177e4SLinus Torvalds unsigned long con_out_handle;
523960a8d01SArd Biesheuvel efi_simple_text_output_protocol_t *con_out;
5241da177e4SLinus Torvalds unsigned long stderr_handle;
5251da177e4SLinus Torvalds unsigned long stderr;
5261da177e4SLinus Torvalds efi_runtime_services_t *runtime;
527f30ca6baSMatt Fleming efi_boot_services_t *boottime;
5281da177e4SLinus Torvalds unsigned long nr_tables;
5291da177e4SLinus Torvalds unsigned long tables;
5301786e830SArd Biesheuvel };
5311786e830SArd Biesheuvel efi_system_table_32_t mixed_mode;
5321da177e4SLinus Torvalds } efi_system_table_t;
5331da177e4SLinus Torvalds
534eab31265SArd Biesheuvel struct efi_boot_memmap {
535eab31265SArd Biesheuvel unsigned long map_size;
536eab31265SArd Biesheuvel unsigned long desc_size;
537eab31265SArd Biesheuvel u32 desc_ver;
538eab31265SArd Biesheuvel unsigned long map_key;
539eab31265SArd Biesheuvel unsigned long buff_size;
540eab31265SArd Biesheuvel efi_memory_desc_t map[];
541eab31265SArd Biesheuvel };
542eab31265SArd Biesheuvel
543745e3ed8SKirill A. Shutemov struct efi_unaccepted_memory {
544745e3ed8SKirill A. Shutemov u32 version;
545745e3ed8SKirill A. Shutemov u32 unit_size;
546745e3ed8SKirill A. Shutemov u64 phys_base;
547745e3ed8SKirill A. Shutemov u64 size;
548745e3ed8SKirill A. Shutemov unsigned long bitmap[];
549745e3ed8SKirill A. Shutemov };
550745e3ed8SKirill A. Shutemov
5519479c7ceSMatt Fleming /*
5529479c7ceSMatt Fleming * Architecture independent structure for describing a memory map for the
5531db91035SDan Williams * benefit of efi_memmap_init_early(), and for passing context between
5541db91035SDan Williams * efi_memmap_alloc() and efi_memmap_install().
5559479c7ceSMatt Fleming */
5569479c7ceSMatt Fleming struct efi_memory_map_data {
5579479c7ceSMatt Fleming phys_addr_t phys_map;
5589479c7ceSMatt Fleming unsigned long size;
5599479c7ceSMatt Fleming unsigned long desc_version;
5609479c7ceSMatt Fleming unsigned long desc_size;
56126c0e44aSDan Williams unsigned long flags;
5629479c7ceSMatt Fleming };
5639479c7ceSMatt Fleming
5641da177e4SLinus Torvalds struct efi_memory_map {
56544511fb9SArd Biesheuvel phys_addr_t phys_map;
5667ae65fd3SMatt Tolentino void *map;
5677ae65fd3SMatt Tolentino void *map_end;
5681da177e4SLinus Torvalds int nr_map;
5691da177e4SLinus Torvalds unsigned long desc_version;
5707ae65fd3SMatt Tolentino unsigned long desc_size;
57126c0e44aSDan Williams #define EFI_MEMMAP_LATE (1UL << 0)
5721db91035SDan Williams #define EFI_MEMMAP_MEMBLOCK (1UL << 1)
5731db91035SDan Williams #define EFI_MEMMAP_SLAB (1UL << 2)
57426c0e44aSDan Williams unsigned long flags;
5751da177e4SLinus Torvalds };
5761da177e4SLinus Torvalds
57760863c0dSMatt Fleming struct efi_mem_range {
57860863c0dSMatt Fleming struct range range;
57960863c0dSMatt Fleming u64 attribute;
5801da177e4SLinus Torvalds };
5811da177e4SLinus Torvalds
582bf924863SArd Biesheuvel typedef struct {
583bf924863SArd Biesheuvel u32 version;
584bf924863SArd Biesheuvel u32 length;
585bf924863SArd Biesheuvel u64 memory_protection_attribute;
586bf924863SArd Biesheuvel } efi_properties_table_t;
587bf924863SArd Biesheuvel
588bf924863SArd Biesheuvel #define EFI_PROPERTIES_TABLE_VERSION 0x00010000
589bf924863SArd Biesheuvel #define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA 0x1
590bf924863SArd Biesheuvel
591fe4db90aSArd Biesheuvel typedef struct {
592fe4db90aSArd Biesheuvel u16 version;
593fe4db90aSArd Biesheuvel u16 length;
594fe4db90aSArd Biesheuvel u32 runtime_services_supported;
595fe4db90aSArd Biesheuvel } efi_rt_properties_table_t;
596fe4db90aSArd Biesheuvel
597fe4db90aSArd Biesheuvel #define EFI_RT_PROPERTIES_TABLE_VERSION 0x1
598fe4db90aSArd Biesheuvel
599b2c99e3cSBjorn Helgaas #define EFI_INVALID_TABLE_ADDR (~0UL)
600b2c99e3cSBjorn Helgaas
601cf1d2ffcSArd Biesheuvel // BIT0 implies that Runtime code includes the forward control flow guard
602cf1d2ffcSArd Biesheuvel // instruction, such as X86 CET-IBT or ARM BTI.
603cf1d2ffcSArd Biesheuvel #define EFI_MEMORY_ATTRIBUTES_FLAGS_RT_FORWARD_CONTROL_FLOW_GUARD 0x1
604cf1d2ffcSArd Biesheuvel
605a604af07SArd Biesheuvel typedef struct {
606a604af07SArd Biesheuvel u32 version;
607a604af07SArd Biesheuvel u32 num_entries;
608a604af07SArd Biesheuvel u32 desc_size;
609cf1d2ffcSArd Biesheuvel u32 flags;
610a604af07SArd Biesheuvel efi_memory_desc_t entry[0];
611a604af07SArd Biesheuvel } efi_memory_attributes_table_t;
612a604af07SArd Biesheuvel
6135c126ba2SDave Howells typedef struct {
6145c126ba2SDave Howells efi_guid_t signature_owner;
6155c126ba2SDave Howells u8 signature_data[];
6165c126ba2SDave Howells } efi_signature_data_t;
6175c126ba2SDave Howells
6185c126ba2SDave Howells typedef struct {
6195c126ba2SDave Howells efi_guid_t signature_type;
6205c126ba2SDave Howells u32 signature_list_size;
6215c126ba2SDave Howells u32 signature_header_size;
6225c126ba2SDave Howells u32 signature_size;
6235c126ba2SDave Howells u8 signature_header[];
6245c126ba2SDave Howells /* efi_signature_data_t signatures[][] */
6255c126ba2SDave Howells } efi_signature_list_t;
6265c126ba2SDave Howells
6275c126ba2SDave Howells typedef u8 efi_sha256_hash_t[32];
6285c126ba2SDave Howells
6295c126ba2SDave Howells typedef struct {
6305c126ba2SDave Howells efi_sha256_hash_t to_be_signed_hash;
6315c126ba2SDave Howells efi_time_t time_of_revocation;
6325c126ba2SDave Howells } efi_cert_x509_sha256_t;
6335c126ba2SDave Howells
634badc6198STom Lendacky extern unsigned long __ro_after_init efi_rng_seed; /* RNG Seed table */
635badc6198STom Lendacky
6361da177e4SLinus Torvalds /*
6371da177e4SLinus Torvalds * All runtime access to EFI goes through this structure:
6381da177e4SLinus Torvalds */
6391da177e4SLinus Torvalds extern struct efi {
64059f2a619SArd Biesheuvel const efi_runtime_services_t *runtime; /* EFI runtime services table */
6413b370237SMatthew Garrett unsigned int runtime_version; /* Runtime services version */
64296a3dd3dSArd Biesheuvel unsigned int runtime_supported_mask;
643fd268304SArd Biesheuvel
644b2c99e3cSBjorn Helgaas unsigned long acpi; /* ACPI table (IA64 ext 0.71) */
645b2c99e3cSBjorn Helgaas unsigned long acpi20; /* ACPI table (ACPI 2.0) */
646e1ccbbc9SArd Biesheuvel unsigned long smbios; /* SMBIOS table (32 bit entry point) */
647e1ccbbc9SArd Biesheuvel unsigned long smbios3; /* SMBIOS table (64 bit entry point) */
6480bb54905SPeter Jones unsigned long esrt; /* ESRT table */
64933b6d034SThiebaud Weksteen unsigned long tpm_log; /* TPM2 Event Log table */
650c46f3405SMatthew Garrett unsigned long tpm_final_log; /* TPM2 Final Events Log table */
65158c90902SLenny Szubowicz unsigned long mokvar_table; /* MOK variable config table */
65212274189SDov Murik unsigned long coco_secret; /* Confidential computing secret table */
6532053bc57SKirill A. Shutemov unsigned long unaccepted; /* Unaccepted memory table */
654fd268304SArd Biesheuvel
6551da177e4SLinus Torvalds efi_get_time_t *get_time;
6561da177e4SLinus Torvalds efi_set_time_t *set_time;
6571da177e4SLinus Torvalds efi_get_wakeup_time_t *get_wakeup_time;
6581da177e4SLinus Torvalds efi_set_wakeup_time_t *set_wakeup_time;
6591da177e4SLinus Torvalds efi_get_variable_t *get_variable;
6601da177e4SLinus Torvalds efi_get_next_variable_t *get_next_variable;
6611da177e4SLinus Torvalds efi_set_variable_t *set_variable;
66270d2a3cfSArd Biesheuvel efi_set_variable_t *set_variable_nonblocking;
6633b370237SMatthew Garrett efi_query_variable_info_t *query_variable_info;
664d3cac1f8SArd Biesheuvel efi_query_variable_info_t *query_variable_info_nonblocking;
6653b370237SMatthew Garrett efi_update_capsule_t *update_capsule;
6663b370237SMatthew Garrett efi_query_capsule_caps_t *query_capsule_caps;
6671da177e4SLinus Torvalds efi_get_next_high_mono_count_t *get_next_high_mono_count;
6681da177e4SLinus Torvalds efi_reset_system_t *reset_system;
669fd268304SArd Biesheuvel
670884f4f66SMatt Fleming struct efi_memory_map memmap;
6713e909599SMatt Fleming unsigned long flags;
6721da177e4SLinus Torvalds } efi;
6731da177e4SLinus Torvalds
67496a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_GET_TIME 0x0001
67596a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_SET_TIME 0x0002
67696a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004
67796a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_SET_WAKEUP_TIME 0x0008
67896a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_GET_VARIABLE 0x0010
67996a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME 0x0020
68096a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_SET_VARIABLE 0x0040
68196a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP 0x0080
68296a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_CONVERT_POINTER 0x0100
68396a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT 0x0200
68496a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_RESET_SYSTEM 0x0400
68596a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_UPDATE_CAPSULE 0x0800
68696a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES 0x1000
68796a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO 0x2000
68896a3dd3dSArd Biesheuvel
68996a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_ALL 0x3fff
69096a3dd3dSArd Biesheuvel
691101ca8d0SShanker Donthineni #define EFI_RT_SUPPORTED_TIME_SERVICES 0x0003
692101ca8d0SShanker Donthineni #define EFI_RT_SUPPORTED_WAKEUP_SERVICES 0x000c
69396a3dd3dSArd Biesheuvel #define EFI_RT_SUPPORTED_VARIABLE_SERVICES 0x0070
69496a3dd3dSArd Biesheuvel
6957e904a91SSai Praneeth extern struct mm_struct efi_mm;
6967e904a91SSai Praneeth
6971da177e4SLinus Torvalds static inline int
efi_guidcmp(efi_guid_t left,efi_guid_t right)6981da177e4SLinus Torvalds efi_guidcmp (efi_guid_t left, efi_guid_t right)
6991da177e4SLinus Torvalds {
7001da177e4SLinus Torvalds return memcmp(&left, &right, sizeof (efi_guid_t));
7011da177e4SLinus Torvalds }
7021da177e4SLinus Torvalds
7031da177e4SLinus Torvalds static inline char *
efi_guid_to_str(efi_guid_t * guid,char * out)70426e02272SBorislav Petkov efi_guid_to_str(efi_guid_t *guid, char *out)
7051da177e4SLinus Torvalds {
706925ede0bSJoe Perches sprintf(out, "%pUl", guid->b);
7071da177e4SLinus Torvalds return out;
7081da177e4SLinus Torvalds }
7091da177e4SLinus Torvalds
7101da177e4SLinus Torvalds extern void efi_init (void);
7118b3a149dSArd Biesheuvel extern void efi_earlycon_reprobe(void);
7122c547f9dSAndrey Konovalov #ifdef CONFIG_EFI
7131da177e4SLinus Torvalds extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */
7142c547f9dSAndrey Konovalov #else
efi_enter_virtual_mode(void)7152c547f9dSAndrey Konovalov static inline void efi_enter_virtual_mode (void) {}
7162c547f9dSAndrey Konovalov #endif
71778510792SJosh Triplett #ifdef CONFIG_X86
718ca0e30dcSArd Biesheuvel extern efi_status_t efi_query_variable_store(u32 attributes,
719ca0e30dcSArd Biesheuvel unsigned long size,
720ca0e30dcSArd Biesheuvel bool nonblocking);
72178510792SJosh Triplett #else
722a6e4d5a0SMatt Fleming
efi_query_variable_store(u32 attributes,unsigned long size,bool nonblocking)723ca0e30dcSArd Biesheuvel static inline efi_status_t efi_query_variable_store(u32 attributes,
724ca0e30dcSArd Biesheuvel unsigned long size,
725ca0e30dcSArd Biesheuvel bool nonblocking)
726a6e4d5a0SMatt Fleming {
727a6e4d5a0SMatt Fleming return EFI_SUCCESS;
728a6e4d5a0SMatt Fleming }
72978510792SJosh Triplett #endif
7309479c7ceSMatt Fleming
731fdc6d38dSArd Biesheuvel extern int __init __efi_memmap_init(struct efi_memory_map_data *data);
7329479c7ceSMatt Fleming extern int __init efi_memmap_init_early(struct efi_memory_map_data *data);
733dca0f971SMatt Fleming extern int __init efi_memmap_init_late(phys_addr_t addr, unsigned long size);
7349479c7ceSMatt Fleming extern void __init efi_memmap_unmap(void);
7359479c7ceSMatt Fleming
7363846c158SPeter Jones #ifdef CONFIG_EFI_ESRT
7370bb54905SPeter Jones extern void __init efi_esrt_init(void);
7383846c158SPeter Jones #else
efi_esrt_init(void)7393846c158SPeter Jones static inline void efi_esrt_init(void) { }
7403846c158SPeter Jones #endif
74106c0bd93SArd Biesheuvel extern int efi_config_parse_tables(const efi_config_table_t *config_tables,
74206c0bd93SArd Biesheuvel int count,
74306c0bd93SArd Biesheuvel const efi_config_table_type_t *arch_tables);
744234fa51dSArd Biesheuvel extern int efi_systab_check_header(const efi_table_hdr_t *systab_hdr);
74514fb4209SArd Biesheuvel extern void efi_systab_report_header(const efi_table_hdr_t *systab_hdr,
74614fb4209SArd Biesheuvel unsigned long fw_vendor);
7471da177e4SLinus Torvalds extern u64 efi_get_iobase (void);
748f99afd08STom Lendacky extern int efi_mem_type(unsigned long phys_addr);
7491da177e4SLinus Torvalds extern u64 efi_mem_attributes (unsigned long phys_addr);
75032e62c63SBjorn Helgaas extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size);
7511da177e4SLinus Torvalds extern int __init efi_uart_console_only (void);
7520bb54905SPeter Jones extern u64 efi_mem_desc_end(efi_memory_desc_t *md);
7530bb54905SPeter Jones extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
754aca1d27aSDemi Marie Obenour extern int __efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md);
755816e7612SMatt Fleming extern void efi_mem_reserve(phys_addr_t addr, u64 size);
756a23d3bb0SArd Biesheuvel extern int efi_mem_reserve_persistent(phys_addr_t addr, u64 size);
7571da177e4SLinus Torvalds extern void efi_initialize_iomem_resources(struct resource *code_resource,
75800bf4098SBernhard Walle struct resource *data_resource, struct resource *bss_resource);
7593b2e4b4cSArd Biesheuvel extern u64 efi_get_fdt_params(struct efi_memory_map_data *data);
7600bb54905SPeter Jones extern struct kobject *efi_kobj;
7611da177e4SLinus Torvalds
76244be28e9SMatt Fleming extern int efi_reboot_quirk_mode;
7630c5ed61aSMatt Fleming extern bool efi_poweroff_required(void);
7640c5ed61aSMatt Fleming
765a17e809eSArd Biesheuvel extern unsigned long efi_mem_attr_table;
766a17e809eSArd Biesheuvel
76710f0d2f5SArd Biesheuvel /*
76810f0d2f5SArd Biesheuvel * efi_memattr_perm_setter - arch specific callback function passed into
76910f0d2f5SArd Biesheuvel * efi_memattr_apply_permissions() that updates the
77010f0d2f5SArd Biesheuvel * mapping permissions described by the second
77110f0d2f5SArd Biesheuvel * argument in the page tables referred to by the
77210f0d2f5SArd Biesheuvel * first argument.
77310f0d2f5SArd Biesheuvel */
774cf1d2ffcSArd Biesheuvel typedef int (*efi_memattr_perm_setter)(struct mm_struct *, efi_memory_desc_t *, bool);
77510f0d2f5SArd Biesheuvel
77610f0d2f5SArd Biesheuvel extern int efi_memattr_init(void);
77710f0d2f5SArd Biesheuvel extern int efi_memattr_apply_permissions(struct mm_struct *mm,
77810f0d2f5SArd Biesheuvel efi_memattr_perm_setter fn);
77910f0d2f5SArd Biesheuvel
78002e43c2dSBaoquan He /*
78102e43c2dSBaoquan He * efi_early_memdesc_ptr - get the n-th EFI memmap descriptor
78202e43c2dSBaoquan He * @map: the start of efi memmap
78302e43c2dSBaoquan He * @desc_size: the size of space for each EFI memmap descriptor
78402e43c2dSBaoquan He * @n: the index of efi memmap descriptor
78502e43c2dSBaoquan He *
78602e43c2dSBaoquan He * EFI boot service provides the GetMemoryMap() function to get a copy of the
78702e43c2dSBaoquan He * current memory map which is an array of memory descriptors, each of
78802e43c2dSBaoquan He * which describes a contiguous block of memory. It also gets the size of the
78902e43c2dSBaoquan He * map, and the size of each descriptor, etc.
79002e43c2dSBaoquan He *
79102e43c2dSBaoquan He * Note that per section 6.2 of UEFI Spec 2.6 Errata A, the returned size of
79202e43c2dSBaoquan He * each descriptor might not be equal to sizeof(efi_memory_memdesc_t),
79302e43c2dSBaoquan He * since efi_memory_memdesc_t may be extended in the future. Thus the OS
79402e43c2dSBaoquan He * MUST use the returned size of the descriptor to find the start of each
79502e43c2dSBaoquan He * efi_memory_memdesc_t in the memory map array. This should only be used
79602e43c2dSBaoquan He * during bootup since for_each_efi_memory_desc_xxx() is available after the
79702e43c2dSBaoquan He * kernel initializes the EFI subsystem to set up struct efi_memory_map.
79802e43c2dSBaoquan He */
79902e43c2dSBaoquan He #define efi_early_memdesc_ptr(map, desc_size, n) \
80002e43c2dSBaoquan He (efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
80102e43c2dSBaoquan He
802e885cd80SMark Salter /* Iterate through an efi_memory_map */
80378ce248fSMatt Fleming #define for_each_efi_memory_desc_in_map(m, md) \
804e885cd80SMark Salter for ((md) = (m)->map; \
805d4c4fed0SJan Beulich (md) && ((void *)(md) + (m)->desc_size) <= (m)->map_end; \
806e885cd80SMark Salter (md) = (void *)(md) + (m)->desc_size)
807e885cd80SMark Salter
80878ce248fSMatt Fleming /**
80978ce248fSMatt Fleming * for_each_efi_memory_desc - iterate over descriptors in efi.memmap
81078ce248fSMatt Fleming * @md: the efi_memory_desc_t * iterator
81178ce248fSMatt Fleming *
81278ce248fSMatt Fleming * Once the loop finishes @md must not be accessed.
81378ce248fSMatt Fleming */
81478ce248fSMatt Fleming #define for_each_efi_memory_desc(md) \
815884f4f66SMatt Fleming for_each_efi_memory_desc_in_map(&efi.memmap, md)
81678ce248fSMatt Fleming
81798d2a6caSLaszlo Ersek /*
81898d2a6caSLaszlo Ersek * Format an EFI memory descriptor's type and attributes to a user-provided
81998d2a6caSLaszlo Ersek * character buffer, as per snprintf(), and return the buffer.
82098d2a6caSLaszlo Ersek */
82198d2a6caSLaszlo Ersek char * __init efi_md_typeattr_format(char *buf, size_t size,
82298d2a6caSLaszlo Ersek const efi_memory_desc_t *md);
82398d2a6caSLaszlo Ersek
8240bc9ae39SDave Howells
8250bc9ae39SDave Howells typedef void (*efi_element_handler_t)(const char *source,
8260bc9ae39SDave Howells const void *element_data,
8270bc9ae39SDave Howells size_t element_size);
8280bc9ae39SDave Howells extern int __init parse_efi_signature_list(
8290bc9ae39SDave Howells const char *source,
8300bc9ae39SDave Howells const void *data, size_t size,
8310bc9ae39SDave Howells efi_element_handler_t (*get_handler_for_guid)(const efi_guid_t *));
8320bc9ae39SDave Howells
8331da177e4SLinus Torvalds /**
8341da177e4SLinus Torvalds * efi_range_is_wc - check the WC bit on an address range
8351da177e4SLinus Torvalds * @start: starting kvirt address
8361da177e4SLinus Torvalds * @len: length of range
8371da177e4SLinus Torvalds *
8381da177e4SLinus Torvalds * Consult the EFI memory map and make sure it's ok to set this range WC.
8391da177e4SLinus Torvalds * Returns true or false.
8401da177e4SLinus Torvalds */
efi_range_is_wc(unsigned long start,unsigned long len)8411da177e4SLinus Torvalds static inline int efi_range_is_wc(unsigned long start, unsigned long len)
8421da177e4SLinus Torvalds {
843986a80d5SJesper Juhl unsigned long i;
8441da177e4SLinus Torvalds
8451da177e4SLinus Torvalds for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) {
8461da177e4SLinus Torvalds unsigned long paddr = __pa(start + i);
8471da177e4SLinus Torvalds if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC))
8481da177e4SLinus Torvalds return 0;
8491da177e4SLinus Torvalds }
8501da177e4SLinus Torvalds /* The range checked out */
8511da177e4SLinus Torvalds return 1;
8521da177e4SLinus Torvalds }
8531da177e4SLinus Torvalds
8541da177e4SLinus Torvalds #ifdef CONFIG_EFI_PCDP
8551da177e4SLinus Torvalds extern int __init efi_setup_pcdp_console(char *);
8561da177e4SLinus Torvalds #endif
8571da177e4SLinus Torvalds
8581da177e4SLinus Torvalds /*
85983e68189SMatt Fleming * We play games with efi_enabled so that the compiler will, if
86083e68189SMatt Fleming * possible, remove EFI-related code altogether.
8611da177e4SLinus Torvalds */
86283e68189SMatt Fleming #define EFI_BOOT 0 /* Were we booted from EFI? */
86383e68189SMatt Fleming #define EFI_CONFIG_TABLES 2 /* Can we use EFI config tables? */
86483e68189SMatt Fleming #define EFI_RUNTIME_SERVICES 3 /* Can we use runtime services? */
86583e68189SMatt Fleming #define EFI_MEMMAP 4 /* Can we use EFI memory map? */
86683e68189SMatt Fleming #define EFI_64BIT 5 /* Is the firmware 64-bit? */
8679f27bc54SDaniel Kiper #define EFI_PARAVIRT 6 /* Access is via a paravirt interface */
8689f27bc54SDaniel Kiper #define EFI_ARCH_1 7 /* First arch-specific bit */
869fed6cefeSBorislav Petkov #define EFI_DBG 8 /* Print additional debug info at runtime */
870a1041713SArd Biesheuvel #define EFI_NX_PE_DATA 9 /* Can runtime data regions be mapped non-executable? */
871a19ebf59SSai Praneeth #define EFI_MEM_ATTR 10 /* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */
872b617c526SDan Williams #define EFI_MEM_NO_SOFT_RESERVE 11 /* Is the kernel configured to ignore soft reservations? */
8730e72a6a3SHans de Goede #define EFI_PRESERVE_BS_REGIONS 12 /* Are EFI boot-services memory segments available? */
87483e68189SMatt Fleming
8751da177e4SLinus Torvalds #ifdef CONFIG_EFI
8763e909599SMatt Fleming /*
8773e909599SMatt Fleming * Test whether the above EFI_* bits are enabled.
8783e909599SMatt Fleming */
efi_enabled(int feature)8793e909599SMatt Fleming static inline bool efi_enabled(int feature)
88083e68189SMatt Fleming {
8813e909599SMatt Fleming return test_bit(feature, &efi.flags) != 0;
8823e909599SMatt Fleming }
8838562c99cSMatt Fleming extern void efi_reboot(enum reboot_mode reboot_mode, const char *__unused);
884b617c526SDan Williams
885b617c526SDan Williams bool __pure __efi_soft_reserve_enabled(void);
886b617c526SDan Williams
efi_soft_reserve_enabled(void)887b617c526SDan Williams static inline bool __pure efi_soft_reserve_enabled(void)
888b617c526SDan Williams {
889b617c526SDan Williams return IS_ENABLED(CONFIG_EFI_SOFT_RESERVE)
890b617c526SDan Williams && __efi_soft_reserve_enabled();
891b617c526SDan Williams }
89296a3dd3dSArd Biesheuvel
efi_rt_services_supported(unsigned int mask)89396a3dd3dSArd Biesheuvel static inline bool efi_rt_services_supported(unsigned int mask)
89496a3dd3dSArd Biesheuvel {
89596a3dd3dSArd Biesheuvel return (efi.runtime_supported_mask & mask) == mask;
89696a3dd3dSArd Biesheuvel }
8976365a193SMa Wupeng extern void efi_find_mirror(void);
8983e909599SMatt Fleming #else
efi_enabled(int feature)8993e909599SMatt Fleming static inline bool efi_enabled(int feature)
9003e909599SMatt Fleming {
9013e909599SMatt Fleming return false;
90283e68189SMatt Fleming }
9038562c99cSMatt Fleming static inline void
efi_reboot(enum reboot_mode reboot_mode,const char * __unused)9048562c99cSMatt Fleming efi_reboot(enum reboot_mode reboot_mode, const char *__unused) {}
90587615a34SMatt Fleming
efi_soft_reserve_enabled(void)906b617c526SDan Williams static inline bool efi_soft_reserve_enabled(void)
907b617c526SDan Williams {
908b617c526SDan Williams return false;
909b617c526SDan Williams }
91096a3dd3dSArd Biesheuvel
efi_rt_services_supported(unsigned int mask)91196a3dd3dSArd Biesheuvel static inline bool efi_rt_services_supported(unsigned int mask)
91296a3dd3dSArd Biesheuvel {
91396a3dd3dSArd Biesheuvel return false;
91496a3dd3dSArd Biesheuvel }
9156365a193SMa Wupeng
efi_find_mirror(void)9166365a193SMa Wupeng static inline void efi_find_mirror(void) {}
9171da177e4SLinus Torvalds #endif
9181da177e4SLinus Torvalds
919806b0351SMatt Fleming extern int efi_status_to_err(efi_status_t status);
920806b0351SMatt Fleming
9211da177e4SLinus Torvalds /*
9221da177e4SLinus Torvalds * Variable Attributes
9231da177e4SLinus Torvalds */
9241da177e4SLinus Torvalds #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
9251da177e4SLinus Torvalds #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
9261da177e4SLinus Torvalds #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
92741b3254cSMatthew Garrett #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
92841b3254cSMatthew Garrett #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
92941b3254cSMatthew Garrett #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
93041b3254cSMatthew Garrett #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
9311da177e4SLinus Torvalds
93241b3254cSMatthew Garrett #define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
93341b3254cSMatthew Garrett EFI_VARIABLE_BOOTSERVICE_ACCESS | \
93441b3254cSMatthew Garrett EFI_VARIABLE_RUNTIME_ACCESS | \
93541b3254cSMatthew Garrett EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
93641b3254cSMatthew Garrett EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
93741b3254cSMatthew Garrett EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
93841b3254cSMatthew Garrett EFI_VARIABLE_APPEND_WRITE)
9391da177e4SLinus Torvalds /*
940e14ab23dSMatt Fleming * Length of a GUID string (strlen("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
941e14ab23dSMatt Fleming * not including trailing NUL
942e14ab23dSMatt Fleming */
943ba7e34b1SAndy Shevchenko #define EFI_VARIABLE_GUID_LEN UUID_STRING_LEN
944e14ab23dSMatt Fleming
945e14ab23dSMatt Fleming /*
9461da177e4SLinus Torvalds * EFI Device Path information
9471da177e4SLinus Torvalds */
9481da177e4SLinus Torvalds #define EFI_DEV_HW 0x01
9491da177e4SLinus Torvalds #define EFI_DEV_PCI 1
9501da177e4SLinus Torvalds #define EFI_DEV_PCCARD 2
9511da177e4SLinus Torvalds #define EFI_DEV_MEM_MAPPED 3
9521da177e4SLinus Torvalds #define EFI_DEV_VENDOR 4
9531da177e4SLinus Torvalds #define EFI_DEV_CONTROLLER 5
9541da177e4SLinus Torvalds #define EFI_DEV_ACPI 0x02
9551da177e4SLinus Torvalds #define EFI_DEV_BASIC_ACPI 1
9561da177e4SLinus Torvalds #define EFI_DEV_EXPANDED_ACPI 2
9571da177e4SLinus Torvalds #define EFI_DEV_MSG 0x03
9581da177e4SLinus Torvalds #define EFI_DEV_MSG_ATAPI 1
9591da177e4SLinus Torvalds #define EFI_DEV_MSG_SCSI 2
9601da177e4SLinus Torvalds #define EFI_DEV_MSG_FC 3
9611da177e4SLinus Torvalds #define EFI_DEV_MSG_1394 4
9621da177e4SLinus Torvalds #define EFI_DEV_MSG_USB 5
9631da177e4SLinus Torvalds #define EFI_DEV_MSG_USB_CLASS 15
9641da177e4SLinus Torvalds #define EFI_DEV_MSG_I20 6
9651da177e4SLinus Torvalds #define EFI_DEV_MSG_MAC 11
9661da177e4SLinus Torvalds #define EFI_DEV_MSG_IPV4 12
9671da177e4SLinus Torvalds #define EFI_DEV_MSG_IPV6 13
9681da177e4SLinus Torvalds #define EFI_DEV_MSG_INFINIBAND 9
9691da177e4SLinus Torvalds #define EFI_DEV_MSG_UART 14
9701da177e4SLinus Torvalds #define EFI_DEV_MSG_VENDOR 10
9711da177e4SLinus Torvalds #define EFI_DEV_MEDIA 0x04
9721da177e4SLinus Torvalds #define EFI_DEV_MEDIA_HARD_DRIVE 1
9731da177e4SLinus Torvalds #define EFI_DEV_MEDIA_CDROM 2
9741da177e4SLinus Torvalds #define EFI_DEV_MEDIA_VENDOR 3
9751da177e4SLinus Torvalds #define EFI_DEV_MEDIA_FILE 4
9761da177e4SLinus Torvalds #define EFI_DEV_MEDIA_PROTOCOL 5
977c7007d9fSArd Biesheuvel #define EFI_DEV_MEDIA_REL_OFFSET 8
9781da177e4SLinus Torvalds #define EFI_DEV_BIOS_BOOT 0x05
9791da177e4SLinus Torvalds #define EFI_DEV_END_PATH 0x7F
9801da177e4SLinus Torvalds #define EFI_DEV_END_PATH2 0xFF
9811da177e4SLinus Torvalds #define EFI_DEV_END_INSTANCE 0x01
9821da177e4SLinus Torvalds #define EFI_DEV_END_ENTIRE 0xFF
9831da177e4SLinus Torvalds
9841da177e4SLinus Torvalds struct efi_generic_dev_path {
9851da177e4SLinus Torvalds u8 type;
9861da177e4SLinus Torvalds u8 sub_type;
9871da177e4SLinus Torvalds u16 length;
988db8952e7SArd Biesheuvel } __packed;
9891da177e4SLinus Torvalds
990db8952e7SArd Biesheuvel struct efi_acpi_dev_path {
991db8952e7SArd Biesheuvel struct efi_generic_dev_path header;
99246cd4b75SLukas Wunner u32 hid;
99346cd4b75SLukas Wunner u32 uid;
994db8952e7SArd Biesheuvel } __packed;
995db8952e7SArd Biesheuvel
996db8952e7SArd Biesheuvel struct efi_pci_dev_path {
997db8952e7SArd Biesheuvel struct efi_generic_dev_path header;
99846cd4b75SLukas Wunner u8 fn;
99946cd4b75SLukas Wunner u8 dev;
1000db8952e7SArd Biesheuvel } __packed;
100146cd4b75SLukas Wunner
1002db8952e7SArd Biesheuvel struct efi_vendor_dev_path {
1003db8952e7SArd Biesheuvel struct efi_generic_dev_path header;
1004db8952e7SArd Biesheuvel efi_guid_t vendorguid;
1005db8952e7SArd Biesheuvel u8 vendordata[];
1006db8952e7SArd Biesheuvel } __packed;
1007db8952e7SArd Biesheuvel
1008c7007d9fSArd Biesheuvel struct efi_rel_offset_dev_path {
1009c7007d9fSArd Biesheuvel struct efi_generic_dev_path header;
1010c7007d9fSArd Biesheuvel u32 reserved;
1011c7007d9fSArd Biesheuvel u64 starting_offset;
1012c7007d9fSArd Biesheuvel u64 ending_offset;
1013c7007d9fSArd Biesheuvel } __packed;
1014c7007d9fSArd Biesheuvel
10153c6edd90SArd Biesheuvel struct efi_mem_mapped_dev_path {
10163c6edd90SArd Biesheuvel struct efi_generic_dev_path header;
10173c6edd90SArd Biesheuvel u32 memory_type;
10183c6edd90SArd Biesheuvel u64 starting_addr;
10193c6edd90SArd Biesheuvel u64 ending_addr;
10203c6edd90SArd Biesheuvel } __packed;
10213c6edd90SArd Biesheuvel
102270912985SArd Biesheuvel struct efi_file_path_dev_path {
102370912985SArd Biesheuvel struct efi_generic_dev_path header;
102470912985SArd Biesheuvel efi_char16_t filename[];
102570912985SArd Biesheuvel } __packed;
102670912985SArd Biesheuvel
1027db8952e7SArd Biesheuvel struct efi_dev_path {
1028db8952e7SArd Biesheuvel union {
1029db8952e7SArd Biesheuvel struct efi_generic_dev_path header;
1030db8952e7SArd Biesheuvel struct efi_acpi_dev_path acpi;
1031db8952e7SArd Biesheuvel struct efi_pci_dev_path pci;
1032db8952e7SArd Biesheuvel struct efi_vendor_dev_path vendor;
1033c7007d9fSArd Biesheuvel struct efi_rel_offset_dev_path rel_offset;
1034db8952e7SArd Biesheuvel };
1035db8952e7SArd Biesheuvel } __packed;
1036db8952e7SArd Biesheuvel
1037db8952e7SArd Biesheuvel struct device *efi_get_device_by_path(const struct efi_dev_path **node,
1038db8952e7SArd Biesheuvel size_t *len);
103946cd4b75SLukas Wunner
memrange_efi_to_native(u64 * addr,u64 * npages)10404a3575fdSHuang, Ying static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
10414a3575fdSHuang, Ying {
10424a3575fdSHuang, Ying *npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr);
10434a3575fdSHuang, Ying *addr &= PAGE_MASK;
10444a3575fdSHuang, Ying }
10454a3575fdSHuang, Ying
104604851772SMatt Fleming /*
10474fc756bdSMike Waychison * EFI Variable support.
10484fc756bdSMike Waychison *
10494fc756bdSMike Waychison * Different firmware drivers can expose their EFI-like variables using
10504fc756bdSMike Waychison * the following.
10514fc756bdSMike Waychison */
10524fc756bdSMike Waychison
10534fc756bdSMike Waychison struct efivar_operations {
10544fc756bdSMike Waychison efi_get_variable_t *get_variable;
10554fc756bdSMike Waychison efi_get_next_variable_t *get_next_variable;
10564fc756bdSMike Waychison efi_set_variable_t *set_variable;
105770d2a3cfSArd Biesheuvel efi_set_variable_t *set_variable_nonblocking;
1058a6e4d5a0SMatt Fleming efi_query_variable_store_t *query_variable_store;
1059d86ff333SAnisse Astier efi_query_variable_info_t *query_variable_info;
10604fc756bdSMike Waychison };
10614fc756bdSMike Waychison
10624fc756bdSMike Waychison struct efivars {
10634fc756bdSMike Waychison struct kset *kset;
10644fc756bdSMike Waychison const struct efivar_operations *ops;
10654fc756bdSMike Waychison };
10664fc756bdSMike Waychison
1067d86ff333SAnisse Astier #ifdef CONFIG_X86
1068d86ff333SAnisse Astier u64 __attribute_const__ efivar_reserved_space(void);
1069d86ff333SAnisse Astier #else
efivar_reserved_space(void)1070d86ff333SAnisse Astier static inline u64 efivar_reserved_space(void) { return 0; }
1071d86ff333SAnisse Astier #endif
1072d86ff333SAnisse Astier
1073e14ab23dSMatt Fleming /*
1074e14ab23dSMatt Fleming * The maximum size of VariableName + Data = 1024
1075e14ab23dSMatt Fleming * Therefore, it's reasonable to save that much
1076e14ab23dSMatt Fleming * space in each part of the structure,
1077e14ab23dSMatt Fleming * and we use a page for reading/writing.
1078e14ab23dSMatt Fleming */
1079e14ab23dSMatt Fleming
1080a5d92ad3SMatt Fleming #define EFI_VAR_NAME_LEN 1024
1081a5d92ad3SMatt Fleming
1082e14ab23dSMatt Fleming int efivars_register(struct efivars *efivars,
1083ade7fd90SJohan Hovold const struct efivar_operations *ops);
1084e14ab23dSMatt Fleming int efivars_unregister(struct efivars *efivars);
1085e14ab23dSMatt Fleming
1086ade7fd90SJohan Hovold #ifdef CONFIG_EFI
1087ade7fd90SJohan Hovold bool efivar_is_available(void);
1088ade7fd90SJohan Hovold #else
efivar_is_available(void)1089ade7fd90SJohan Hovold static inline bool efivar_is_available(void) { return false; }
1090ade7fd90SJohan Hovold #endif
1091e14ab23dSMatt Fleming
10922cf9e278SJohan Hovold bool efivar_supports_writes(void);
1093e14ab23dSMatt Fleming
1094472831d4SArd Biesheuvel int efivar_lock(void);
1095472831d4SArd Biesheuvel int efivar_trylock(void);
1096472831d4SArd Biesheuvel void efivar_unlock(void);
1097472831d4SArd Biesheuvel
1098472831d4SArd Biesheuvel efi_status_t efivar_get_variable(efi_char16_t *name, efi_guid_t *vendor,
1099472831d4SArd Biesheuvel u32 *attr, unsigned long *size, void *data);
1100472831d4SArd Biesheuvel
1101472831d4SArd Biesheuvel efi_status_t efivar_get_next_variable(unsigned long *name_size,
1102472831d4SArd Biesheuvel efi_char16_t *name, efi_guid_t *vendor);
1103472831d4SArd Biesheuvel
1104472831d4SArd Biesheuvel efi_status_t efivar_set_variable_locked(efi_char16_t *name, efi_guid_t *vendor,
1105472831d4SArd Biesheuvel u32 attr, unsigned long data_size,
1106472831d4SArd Biesheuvel void *data, bool nonblocking);
1107472831d4SArd Biesheuvel
1108472831d4SArd Biesheuvel efi_status_t efivar_set_variable(efi_char16_t *name, efi_guid_t *vendor,
1109472831d4SArd Biesheuvel u32 attr, unsigned long data_size, void *data);
1110472831d4SArd Biesheuvel
1111d86ff333SAnisse Astier efi_status_t efivar_query_variable_info(u32 attr, u64 *storage_space,
1112d86ff333SAnisse Astier u64 *remaining_space,
1113d86ff333SAnisse Astier u64 *max_variable_size);
1114d86ff333SAnisse Astier
1115e0a6aa30SArd Biesheuvel #if IS_ENABLED(CONFIG_EFI_CAPSULE_LOADER)
1116f0133f3cSMatt Fleming extern bool efi_capsule_pending(int *reset_type);
1117f0133f3cSMatt Fleming
1118f0133f3cSMatt Fleming extern int efi_capsule_supported(efi_guid_t guid, u32 flags,
1119f0133f3cSMatt Fleming size_t size, int *reset);
1120f0133f3cSMatt Fleming
1121f0133f3cSMatt Fleming extern int efi_capsule_update(efi_capsule_header_t *capsule,
11222a457fb3SArd Biesheuvel phys_addr_t *pages);
1123e0a6aa30SArd Biesheuvel #else
efi_capsule_pending(int * reset_type)1124e0a6aa30SArd Biesheuvel static inline bool efi_capsule_pending(int *reset_type) { return false; }
1125e0a6aa30SArd Biesheuvel #endif
11264fc756bdSMike Waychison
11270082517fSJian-Hong Pan #ifdef CONFIG_EFI
11280082517fSJian-Hong Pan extern bool efi_runtime_disabled(void);
11290082517fSJian-Hong Pan #else
efi_runtime_disabled(void)11300082517fSJian-Hong Pan static inline bool efi_runtime_disabled(void) { return true; }
11310082517fSJian-Hong Pan #endif
11320082517fSJian-Hong Pan
11333c17ae41SArd Biesheuvel extern void efi_call_virt_check_flags(unsigned long flags, const void *caller);
113413b210ddSJulien Thierry extern unsigned long efi_call_virt_save_flags(void);
113580e75596SAlex Thorlton
1136de8cb458SDavid Howells enum efi_secureboot_mode {
1137de8cb458SDavid Howells efi_secureboot_mode_unset,
1138de8cb458SDavid Howells efi_secureboot_mode_unknown,
1139de8cb458SDavid Howells efi_secureboot_mode_disabled,
1140de8cb458SDavid Howells efi_secureboot_mode_enabled,
1141de8cb458SDavid Howells };
1142e1ac4b24SChester Lin
1143e1ac4b24SChester Lin static inline
efi_get_secureboot_mode(efi_get_variable_t * get_var)1144e1ac4b24SChester Lin enum efi_secureboot_mode efi_get_secureboot_mode(efi_get_variable_t *get_var)
1145e1ac4b24SChester Lin {
1146e1ac4b24SChester Lin u8 secboot, setupmode = 0;
1147e1ac4b24SChester Lin efi_status_t status;
1148e1ac4b24SChester Lin unsigned long size;
1149e1ac4b24SChester Lin
1150e1ac4b24SChester Lin size = sizeof(secboot);
1151e1ac4b24SChester Lin status = get_var(L"SecureBoot", &EFI_GLOBAL_VARIABLE_GUID, NULL, &size,
1152e1ac4b24SChester Lin &secboot);
1153e1ac4b24SChester Lin if (status == EFI_NOT_FOUND)
1154e1ac4b24SChester Lin return efi_secureboot_mode_disabled;
1155e1ac4b24SChester Lin if (status != EFI_SUCCESS)
1156e1ac4b24SChester Lin return efi_secureboot_mode_unknown;
1157e1ac4b24SChester Lin
1158e1ac4b24SChester Lin size = sizeof(setupmode);
1159e1ac4b24SChester Lin get_var(L"SetupMode", &EFI_GLOBAL_VARIABLE_GUID, NULL, &size, &setupmode);
1160e1ac4b24SChester Lin if (secboot == 0 || setupmode == 1)
1161e1ac4b24SChester Lin return efi_secureboot_mode_disabled;
1162e1ac4b24SChester Lin return efi_secureboot_mode_enabled;
1163e1ac4b24SChester Lin }
1164de8cb458SDavid Howells
1165f0df68d5SHans de Goede #ifdef CONFIG_EFI_EMBEDDED_FIRMWARE
1166f0df68d5SHans de Goede void efi_check_for_embedded_firmwares(void);
1167f0df68d5SHans de Goede #else
efi_check_for_embedded_firmwares(void)1168f0df68d5SHans de Goede static inline void efi_check_for_embedded_firmwares(void) { }
1169f0df68d5SHans de Goede #endif
1170f0df68d5SHans de Goede
11718add9a3aSSudeep Holla #define arch_efi_call_virt(p, f, args...) ((p)->f(args))
11728add9a3aSSudeep Holla
117380e75596SAlex Thorlton /*
1174e38abdabSArd Biesheuvel * Arch code must implement the following three routines:
117580e75596SAlex Thorlton *
117680e75596SAlex Thorlton * * arch_efi_call_virt_setup()
117780e75596SAlex Thorlton *
117880e75596SAlex Thorlton * Sets up the environment for the call (e.g. switching page tables,
117980e75596SAlex Thorlton * allowing kernel-mode use of floating point, if required).
118080e75596SAlex Thorlton *
118180e75596SAlex Thorlton * * arch_efi_call_virt()
118280e75596SAlex Thorlton *
1183e38abdabSArd Biesheuvel * Performs the call. This routine takes a variable number of arguments so
1184e38abdabSArd Biesheuvel * it must be implemented as a variadic preprocessor macro.
118580e75596SAlex Thorlton *
118680e75596SAlex Thorlton * * arch_efi_call_virt_teardown()
118780e75596SAlex Thorlton *
118880e75596SAlex Thorlton * Restores the usual kernel environment once the call has returned.
118980e75596SAlex Thorlton */
119080e75596SAlex Thorlton
119180e75596SAlex Thorlton #define efi_call_virt_pointer(p, f, args...) \
119280e75596SAlex Thorlton ({ \
1193e38abdabSArd Biesheuvel typeof((p)->f(args)) __s; \
119480e75596SAlex Thorlton unsigned long __flags; \
119580e75596SAlex Thorlton \
119680e75596SAlex Thorlton arch_efi_call_virt_setup(); \
119780e75596SAlex Thorlton \
119813b210ddSJulien Thierry __flags = efi_call_virt_save_flags(); \
119980e75596SAlex Thorlton __s = arch_efi_call_virt(p, f, args); \
12003c17ae41SArd Biesheuvel efi_call_virt_check_flags(__flags, NULL); \
120180e75596SAlex Thorlton \
120280e75596SAlex Thorlton arch_efi_call_virt_teardown(); \
120380e75596SAlex Thorlton \
120480e75596SAlex Thorlton __s; \
120580e75596SAlex Thorlton })
120680e75596SAlex Thorlton
1207161a438dSArd Biesheuvel #define EFI_RANDOM_SEED_SIZE 32U // BLAKE2S_HASH_SIZE
1208c2ceb5fdSArd Biesheuvel
120963625988SArd Biesheuvel struct linux_efi_random_seed {
121063625988SArd Biesheuvel u32 size;
121163625988SArd Biesheuvel u8 bits[];
121263625988SArd Biesheuvel };
121363625988SArd Biesheuvel
121433b6d034SThiebaud Weksteen struct linux_efi_tpm_eventlog {
121533b6d034SThiebaud Weksteen u32 size;
1216166a2809SMatthew Garrett u32 final_events_preboot_size;
121733b6d034SThiebaud Weksteen u8 version;
121833b6d034SThiebaud Weksteen u8 log[];
121933b6d034SThiebaud Weksteen };
122033b6d034SThiebaud Weksteen
122133b6d034SThiebaud Weksteen extern int efi_tpm_eventlog_init(void);
122233b6d034SThiebaud Weksteen
1223c46f3405SMatthew Garrett struct efi_tcg2_final_events_table {
1224c46f3405SMatthew Garrett u64 version;
1225c46f3405SMatthew Garrett u64 nr_events;
1226c46f3405SMatthew Garrett u8 events[];
1227c46f3405SMatthew Garrett };
1228c46f3405SMatthew Garrett extern int efi_tpm_final_log_size;
1229c46f3405SMatthew Garrett
12301c5fecb6SNarendra K extern unsigned long rci2_table_phys;
12311c5fecb6SNarendra K
1232*5894cf57SArd Biesheuvel efi_status_t
1233*5894cf57SArd Biesheuvel efi_call_acpi_prm_handler(efi_status_t (__efiapi *handler_addr)(u64, void *),
1234*5894cf57SArd Biesheuvel u64 param_buffer_addr, void *context);
1235*5894cf57SArd Biesheuvel
12363425d934SSai Praneeth /*
12373425d934SSai Praneeth * efi_runtime_service() function identifiers.
12383425d934SSai Praneeth * "NONE" is used by efi_recover_from_page_fault() to check if the page
12393425d934SSai Praneeth * fault happened while executing an efi runtime service.
12403425d934SSai Praneeth */
12419dbbedaaSSai Praneeth enum efi_rts_ids {
12425c418dc7SAnders Roxell EFI_NONE,
12435c418dc7SAnders Roxell EFI_GET_TIME,
12445c418dc7SAnders Roxell EFI_SET_TIME,
12455c418dc7SAnders Roxell EFI_GET_WAKEUP_TIME,
12465c418dc7SAnders Roxell EFI_SET_WAKEUP_TIME,
12475c418dc7SAnders Roxell EFI_GET_VARIABLE,
12485c418dc7SAnders Roxell EFI_GET_NEXT_VARIABLE,
12495c418dc7SAnders Roxell EFI_SET_VARIABLE,
12505c418dc7SAnders Roxell EFI_QUERY_VARIABLE_INFO,
12515c418dc7SAnders Roxell EFI_GET_NEXT_HIGH_MONO_COUNT,
12525c418dc7SAnders Roxell EFI_RESET_SYSTEM,
12535c418dc7SAnders Roxell EFI_UPDATE_CAPSULE,
12545c418dc7SAnders Roxell EFI_QUERY_CAPSULE_CAPS,
1255*5894cf57SArd Biesheuvel EFI_ACPI_PRM_HANDLER,
12569dbbedaaSSai Praneeth };
12579dbbedaaSSai Praneeth
1258c7c7bce0SArd Biesheuvel union efi_rts_args;
1259c7c7bce0SArd Biesheuvel
12609dbbedaaSSai Praneeth /*
12619dbbedaaSSai Praneeth * efi_runtime_work: Details of EFI Runtime Service work
1262c7c7bce0SArd Biesheuvel * @args: Pointer to union describing the arguments
12639dbbedaaSSai Praneeth * @status: Status of executing EFI Runtime Service
12649dbbedaaSSai Praneeth * @efi_rts_id: EFI Runtime Service function identifier
12659dbbedaaSSai Praneeth * @efi_rts_comp: Struct used for handling completions
12663c17ae41SArd Biesheuvel * @caller: The caller of the runtime service
12679dbbedaaSSai Praneeth */
12689dbbedaaSSai Praneeth struct efi_runtime_work {
1269c7c7bce0SArd Biesheuvel union efi_rts_args *args;
12709dbbedaaSSai Praneeth efi_status_t status;
12719dbbedaaSSai Praneeth struct work_struct work;
12729dbbedaaSSai Praneeth enum efi_rts_ids efi_rts_id;
12739dbbedaaSSai Praneeth struct completion efi_rts_comp;
12743c17ae41SArd Biesheuvel const void *caller;
12759dbbedaaSSai Praneeth };
12769dbbedaaSSai Praneeth
12779dbbedaaSSai Praneeth extern struct efi_runtime_work efi_rts_work;
12789dbbedaaSSai Praneeth
12793eb420e7SSai Praneeth /* Workqueue to queue EFI Runtime Services */
12803eb420e7SSai Praneeth extern struct workqueue_struct *efi_rts_wq;
12813eb420e7SSai Praneeth
128271e0940dSArd Biesheuvel struct linux_efi_memreserve {
12835f0b0ecfSArd Biesheuvel int size; // allocated size of the array
12845f0b0ecfSArd Biesheuvel atomic_t count; // number of entries used
12855f0b0ecfSArd Biesheuvel phys_addr_t next; // pa of next struct instance
12865f0b0ecfSArd Biesheuvel struct {
128771e0940dSArd Biesheuvel phys_addr_t base;
128871e0940dSArd Biesheuvel phys_addr_t size;
128929637951SGustavo A. R. Silva } entry[];
129071e0940dSArd Biesheuvel };
129171e0940dSArd Biesheuvel
129280424b02SArd Biesheuvel #define EFI_MEMRESERVE_COUNT(size) (((size) - sizeof(struct linux_efi_memreserve)) \
129329637951SGustavo A. R. Silva / sizeof_field(struct linux_efi_memreserve, entry[0]))
129480424b02SArd Biesheuvel
1295860f89e6SBenjamin Thiel void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size);
1296860f89e6SBenjamin Thiel
1297e8da08a0SBenjamin Thiel char *efi_systab_show_arch(char *str);
1298e8da08a0SBenjamin Thiel
129958c90902SLenny Szubowicz /*
130058c90902SLenny Szubowicz * The LINUX_EFI_MOK_VARIABLE_TABLE_GUID config table can be provided
130158c90902SLenny Szubowicz * to the kernel by an EFI boot loader. The table contains a packed
130258c90902SLenny Szubowicz * sequence of these entries, one for each named MOK variable.
130358c90902SLenny Szubowicz * The sequence is terminated by an entry with a completely NULL
130458c90902SLenny Szubowicz * name and 0 data size.
130558c90902SLenny Szubowicz */
130658c90902SLenny Szubowicz struct efi_mokvar_table_entry {
130758c90902SLenny Szubowicz char name[256];
130858c90902SLenny Szubowicz u64 data_size;
130958c90902SLenny Szubowicz u8 data[];
131058c90902SLenny Szubowicz } __attribute((packed));
131158c90902SLenny Szubowicz
131258c90902SLenny Szubowicz #ifdef CONFIG_LOAD_UEFI_KEYS
131358c90902SLenny Szubowicz extern void __init efi_mokvar_table_init(void);
131458c90902SLenny Szubowicz extern struct efi_mokvar_table_entry *efi_mokvar_entry_next(
131558c90902SLenny Szubowicz struct efi_mokvar_table_entry **mokvar_entry);
131658c90902SLenny Szubowicz extern struct efi_mokvar_table_entry *efi_mokvar_entry_find(const char *name);
131758c90902SLenny Szubowicz #else
efi_mokvar_table_init(void)131858c90902SLenny Szubowicz static inline void efi_mokvar_table_init(void) { }
efi_mokvar_entry_next(struct efi_mokvar_table_entry ** mokvar_entry)131958c90902SLenny Szubowicz static inline struct efi_mokvar_table_entry *efi_mokvar_entry_next(
132058c90902SLenny Szubowicz struct efi_mokvar_table_entry **mokvar_entry)
132158c90902SLenny Szubowicz {
132258c90902SLenny Szubowicz return NULL;
132358c90902SLenny Szubowicz }
efi_mokvar_entry_find(const char * name)132458c90902SLenny Szubowicz static inline struct efi_mokvar_table_entry *efi_mokvar_entry_find(
132558c90902SLenny Szubowicz const char *name)
132658c90902SLenny Szubowicz {
132758c90902SLenny Szubowicz return NULL;
132858c90902SLenny Szubowicz }
132958c90902SLenny Szubowicz #endif
133058c90902SLenny Szubowicz
13314bc5e64eSJavier Martinez Canillas extern void efifb_setup_from_dmi(struct screen_info *si, const char *opt);
13324bc5e64eSJavier Martinez Canillas
133312274189SDov Murik struct linux_efi_coco_secret_area {
133412274189SDov Murik u64 base_pa;
133512274189SDov Murik u64 size;
133612274189SDov Murik };
133712274189SDov Murik
1338f4dc7fffSArd Biesheuvel struct linux_efi_initrd {
1339f4dc7fffSArd Biesheuvel unsigned long base;
1340f4dc7fffSArd Biesheuvel unsigned long size;
1341f4dc7fffSArd Biesheuvel };
1342f4dc7fffSArd Biesheuvel
134312274189SDov Murik /* Header of a populated EFI secret area */
134412274189SDov Murik #define EFI_SECRET_TABLE_HEADER_GUID EFI_GUID(0x1e74f542, 0x71dd, 0x4d66, 0x96, 0x3e, 0xef, 0x42, 0x87, 0xff, 0x17, 0x3b)
134512274189SDov Murik
1346c0fecaa4SDemi Marie Obenour bool xen_efi_config_table_is_usable(const efi_guid_t *guid, unsigned long table);
1347c0fecaa4SDemi Marie Obenour
1348c0fecaa4SDemi Marie Obenour static inline
efi_config_table_is_usable(const efi_guid_t * guid,unsigned long table)1349c0fecaa4SDemi Marie Obenour bool efi_config_table_is_usable(const efi_guid_t *guid, unsigned long table)
1350c0fecaa4SDemi Marie Obenour {
1351c0fecaa4SDemi Marie Obenour if (!IS_ENABLED(CONFIG_XEN_EFI))
1352c0fecaa4SDemi Marie Obenour return true;
1353c0fecaa4SDemi Marie Obenour return xen_efi_config_table_is_usable(guid, table);
1354c0fecaa4SDemi Marie Obenour }
1355c0fecaa4SDemi Marie Obenour
1356fd936fd8SArnd Bergmann umode_t efi_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n);
1357fd936fd8SArnd Bergmann
13581da177e4SLinus Torvalds #endif /* _LINUX_EFI_H */
1359