xref: /linux/arch/x86/boot/compressed/efi.h (revision e6a901a00822659181c93c86d8bbc2a17779fddc)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef BOOT_COMPRESSED_EFI_H
3 #define BOOT_COMPRESSED_EFI_H
4 
5 #if defined(_LINUX_EFI_H) || defined(_ASM_X86_EFI_H)
6 #error Please do not include kernel proper namespace headers
7 #endif
8 
9 typedef guid_t efi_guid_t __aligned(__alignof__(u32));
10 
11 #define EFI_GUID(a, b, c, d...) (efi_guid_t){ {					\
12 	(a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff,	\
13 	(b) & 0xff, ((b) >> 8) & 0xff,						\
14 	(c) & 0xff, ((c) >> 8) & 0xff, d } }
15 
16 #define ACPI_TABLE_GUID				EFI_GUID(0xeb9d2d30, 0x2d88, 0x11d3,  0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
17 #define ACPI_20_TABLE_GUID			EFI_GUID(0x8868e871, 0xe4f1, 0x11d3,  0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
18 #define EFI_CC_BLOB_GUID			EFI_GUID(0x067b1f5f, 0xcf26, 0x44c5, 0x85, 0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42)
19 #define LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID	EFI_GUID(0xd5d1de3c, 0x105c, 0x44f9,  0x9e, 0xa9, 0xbc, 0xef, 0x98, 0x12, 0x00, 0x31)
20 
21 #define EFI32_LOADER_SIGNATURE	"EL32"
22 #define EFI64_LOADER_SIGNATURE	"EL64"
23 
24 /*
25  * Generic EFI table header
26  */
27 typedef	struct {
28 	u64 signature;
29 	u32 revision;
30 	u32 headersize;
31 	u32 crc32;
32 	u32 reserved;
33 } efi_table_hdr_t;
34 
35 #define EFI_CONVENTIONAL_MEMORY		 7
36 #define EFI_UNACCEPTED_MEMORY		15
37 
38 #define EFI_MEMORY_MORE_RELIABLE \
39 				((u64)0x0000000000010000ULL)	/* higher reliability */
40 #define EFI_MEMORY_SP		((u64)0x0000000000040000ULL)	/* soft reserved */
41 
42 #define EFI_PAGE_SHIFT		12
43 
44 typedef struct {
45 	u32 type;
46 	u32 pad;
47 	u64 phys_addr;
48 	u64 virt_addr;
49 	u64 num_pages;
50 	u64 attribute;
51 } efi_memory_desc_t;
52 
53 #define efi_early_memdesc_ptr(map, desc_size, n)			\
54 	(efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
55 
56 typedef struct {
57 	efi_guid_t guid;
58 	u64 table;
59 } efi_config_table_64_t;
60 
61 typedef struct {
62 	efi_guid_t guid;
63 	u32 table;
64 } efi_config_table_32_t;
65 
66 typedef struct {
67 	efi_table_hdr_t hdr;
68 	u64 fw_vendor;	/* physical addr of CHAR16 vendor string */
69 	u32 fw_revision;
70 	u32 __pad1;
71 	u64 con_in_handle;
72 	u64 con_in;
73 	u64 con_out_handle;
74 	u64 con_out;
75 	u64 stderr_handle;
76 	u64 stderr;
77 	u64 runtime;
78 	u64 boottime;
79 	u32 nr_tables;
80 	u32 __pad2;
81 	u64 tables;
82 } efi_system_table_64_t;
83 
84 typedef struct {
85 	efi_table_hdr_t hdr;
86 	u32 fw_vendor;	/* physical addr of CHAR16 vendor string */
87 	u32 fw_revision;
88 	u32 con_in_handle;
89 	u32 con_in;
90 	u32 con_out_handle;
91 	u32 con_out;
92 	u32 stderr_handle;
93 	u32 stderr;
94 	u32 runtime;
95 	u32 boottime;
96 	u32 nr_tables;
97 	u32 tables;
98 } efi_system_table_32_t;
99 
100 struct efi_unaccepted_memory {
101 	u32 version;
102 	u32 unit_size;
103 	u64 phys_base;
104 	u64 size;
105 	unsigned long bitmap[];
106 };
107 
108 static inline int efi_guidcmp (efi_guid_t left, efi_guid_t right)
109 {
110 	return memcmp(&left, &right, sizeof (efi_guid_t));
111 }
112 
113 #ifdef CONFIG_EFI
114 bool __pure __efi_soft_reserve_enabled(void);
115 
116 static inline bool __pure efi_soft_reserve_enabled(void)
117 {
118 	return IS_ENABLED(CONFIG_EFI_SOFT_RESERVE)
119 		&& __efi_soft_reserve_enabled();
120 }
121 #else
122 static inline bool efi_soft_reserve_enabled(void)
123 {
124 	return false;
125 }
126 #endif /* CONFIG_EFI */
127 #endif /* BOOT_COMPRESSED_EFI_H */
128