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 
20 #define EFI32_LOADER_SIGNATURE	"EL32"
21 #define EFI64_LOADER_SIGNATURE	"EL64"
22 
23 /*
24  * Generic EFI table header
25  */
26 typedef	struct {
27 	u64 signature;
28 	u32 revision;
29 	u32 headersize;
30 	u32 crc32;
31 	u32 reserved;
32 } efi_table_hdr_t;
33 
34 #define EFI_CONVENTIONAL_MEMORY		 7
35 
36 #define EFI_MEMORY_MORE_RELIABLE \
37 				((u64)0x0000000000010000ULL)	/* higher reliability */
38 #define EFI_MEMORY_SP		((u64)0x0000000000040000ULL)	/* soft reserved */
39 
40 #define EFI_PAGE_SHIFT		12
41 
42 typedef struct {
43 	u32 type;
44 	u32 pad;
45 	u64 phys_addr;
46 	u64 virt_addr;
47 	u64 num_pages;
48 	u64 attribute;
49 } efi_memory_desc_t;
50 
51 #define efi_early_memdesc_ptr(map, desc_size, n)			\
52 	(efi_memory_desc_t *)((void *)(map) + ((n) * (desc_size)))
53 
54 typedef struct {
55 	efi_guid_t guid;
56 	u64 table;
57 } efi_config_table_64_t;
58 
59 typedef struct {
60 	efi_guid_t guid;
61 	u32 table;
62 } efi_config_table_32_t;
63 
64 typedef struct {
65 	efi_table_hdr_t hdr;
66 	u64 fw_vendor;	/* physical addr of CHAR16 vendor string */
67 	u32 fw_revision;
68 	u32 __pad1;
69 	u64 con_in_handle;
70 	u64 con_in;
71 	u64 con_out_handle;
72 	u64 con_out;
73 	u64 stderr_handle;
74 	u64 stderr;
75 	u64 runtime;
76 	u64 boottime;
77 	u32 nr_tables;
78 	u32 __pad2;
79 	u64 tables;
80 } efi_system_table_64_t;
81 
82 typedef struct {
83 	efi_table_hdr_t hdr;
84 	u32 fw_vendor;	/* physical addr of CHAR16 vendor string */
85 	u32 fw_revision;
86 	u32 con_in_handle;
87 	u32 con_in;
88 	u32 con_out_handle;
89 	u32 con_out;
90 	u32 stderr_handle;
91 	u32 stderr;
92 	u32 runtime;
93 	u32 boottime;
94 	u32 nr_tables;
95 	u32 tables;
96 } efi_system_table_32_t;
97 
98 /* kexec external ABI */
99 struct efi_setup_data {
100 	u64 fw_vendor;
101 	u64 __unused;
102 	u64 tables;
103 	u64 smbios;
104 	u64 reserved[8];
105 };
106 
efi_guidcmp(efi_guid_t left,efi_guid_t right)107 static inline int efi_guidcmp (efi_guid_t left, efi_guid_t right)
108 {
109 	return memcmp(&left, &right, sizeof (efi_guid_t));
110 }
111 
112 #ifdef CONFIG_EFI
113 bool __pure __efi_soft_reserve_enabled(void);
114 
efi_soft_reserve_enabled(void)115 static inline bool __pure efi_soft_reserve_enabled(void)
116 {
117 	return IS_ENABLED(CONFIG_EFI_SOFT_RESERVE)
118 		&& __efi_soft_reserve_enabled();
119 }
120 #else
efi_soft_reserve_enabled(void)121 static inline bool efi_soft_reserve_enabled(void)
122 {
123 	return false;
124 }
125 #endif /* CONFIG_EFI */
126 #endif /* BOOT_COMPRESSED_EFI_H */
127