xref: /openbsd/sys/dev/efi/efi.h (revision f2f88681)
1 /* $OpenBSD: efi.h,v 1.4 2023/01/14 12:11:11 kettenis Exp $ */
2 
3 /* Public Domain */
4 
5 #ifndef _MACHINE_EFI_H_
6 #define _MACHINE_EFI_H_
7 
8 #ifdef __amd64__
9 #define EFIAPI		__attribute__((ms_abi))
10 #else
11 #define EFIAPI
12 #endif
13 
14 #ifdef __LP64__
15 #define EFIERR(x)	(0x8000000000000000 | (x))
16 #else
17 #define EFIERR(x)	(0x80000000 | (x))
18 #endif
19 
20 typedef uint8_t		UINT8;
21 typedef int16_t		INT16;
22 typedef uint16_t	UINT16;
23 typedef uint32_t	UINT32;
24 typedef uint64_t	UINT64;
25 typedef u_long		UINTN;
26 typedef uint16_t	CHAR16;
27 typedef void		VOID;
28 typedef uint64_t	EFI_PHYSICAL_ADDRESS;
29 typedef uint64_t	EFI_VIRTUAL_ADDRESS;
30 typedef UINTN		EFI_STATUS;
31 typedef VOID		*EFI_HANDLE;
32 
33 typedef VOID		*EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
34 typedef VOID		*EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
35 typedef VOID		*EFI_BOOT_SERVICES;
36 
37 typedef struct {
38 	UINT32	Data1;
39 	UINT16	Data2;
40 	UINT16	Data3;
41 	UINT8	Data4[8];
42 } EFI_GUID;
43 
44 #define EFI_ACPI_20_TABLE_GUID \
45   { 0x8868e871, 0xe4f1, 0x11d3, \
46     { 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81 } }
47 
48 #define SMBIOS_TABLE_GUID \
49   { 0xeb9d2d31, 0x2d88, 0x11d3, \
50     { 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }
51 
52 #define SMBIOS3_TABLE_GUID \
53   { 0xf2fd1544, 0x9794, 0x4a2c, \
54     { 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 } }
55 
56 #define EFI_SYSTEM_RESOURCE_TABLE_GUID \
57   { 0xb122a263, 0x3661, 0x4f68, \
58     { 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80 } }
59 
60 #define EFI_GLOBAL_VARIABLE \
61   { 0x8be4df61, 0x93ca, 0x11d2, \
62     { 0xaa,0x0d,0x00,0xe0,0x98,0x03,0x2b,0x8c } }
63 
64 typedef enum {
65 	EfiReservedMemoryType,
66 	EfiLoaderCode,
67 	EfiLoaderData,
68 	EfiBootServicesCode,
69 	EfiBootServicesData,
70 	EfiRuntimeServicesCode,
71 	EfiRuntimeServicesData,
72 	EfiConventionalMemory,
73 	EfiUnusableMemory,
74 	EfiACPIReclaimMemory,
75 	EfiACPIMemoryNVS,
76 	EfiMemoryMappedIO,
77 	EfiMemoryMappedIOPortSpace,
78 	EfiPalCode,
79 	EfiPersistentMemory,
80         EfiMaxMemoryType
81 } EFI_MEMORY_TYPE;
82 
83 #define EFI_MEMORY_UC			0x0000000000000001
84 #define EFI_MEMORY_WC			0x0000000000000002
85 #define EFI_MEMORY_WT			0x0000000000000004
86 #define EFI_MEMORY_WB			0x0000000000000008
87 #define EFI_MEMORY_UCE			0x0000000000000010
88 #define EFI_MEMORY_WP			0x0000000000001000
89 #define EFI_MEMORY_RP			0x0000000000002000
90 #define EFI_MEMORY_XP			0x0000000000004000
91 #define EFI_MEMORY_NV			0x0000000000008000
92 #define EFI_MEMORY_MORE_RELIABLE	0x0000000000010000
93 #define EFI_MEMORY_RO			0x0000000000020000
94 #define EFI_MEMORY_RUNTIME		0x8000000000000000
95 
96 #define EFI_MEMORY_DESCRIPTOR_VERSION  1
97 
98 typedef struct {
99 	UINT32			Type;
100 	UINT32			Pad;
101 	EFI_PHYSICAL_ADDRESS	PhysicalStart;
102 	EFI_VIRTUAL_ADDRESS	VirtualStart;
103 	UINT64			NumberOfPages;
104 	UINT64			Attribute;
105 } EFI_MEMORY_DESCRIPTOR;
106 
107 #define NextMemoryDescriptor(Ptr, Size) \
108 	((EFI_MEMORY_DESCRIPTOR *)(((UINT8 *)Ptr) + Size))
109 
110 typedef enum {
111 	EfiResetCold,
112 	EfiResetWarm,
113 	EfiResetShutdown,
114 	EfiResetPlatformSpecific
115 } EFI_RESET_TYPE;
116 
117 typedef struct {
118 	UINT64				Signature;
119 	UINT32				Revision;
120 	UINT32				HeaderSize;
121 	UINT32				CRC32;
122 	UINT32				Reserved;
123 } EFI_TABLE_HEADER;
124 
125 typedef struct {
126 	UINT16				Year;
127 	UINT8				Month;
128 	UINT8				Day;
129 	UINT8				Hour;
130 	UINT8				Minute;
131 	UINT8				Second;
132 	UINT8				Pad1;
133 	UINT32				Nanosecond;
134 	INT16				TimeZone;
135 	UINT8				Daylight;
136 	UINT8				Pad2;
137 } EFI_TIME;
138 
139 typedef VOID		*EFI_TIME_CAPABILITIES;
140 
141 typedef EFI_STATUS (EFIAPI *EFI_GET_TIME)(EFI_TIME *, EFI_TIME_CAPABILITIES *);
142 typedef EFI_STATUS (EFIAPI *EFI_SET_TIME)(EFI_TIME *);
143 typedef EFI_STATUS (EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP)(UINTN, UINTN, UINT32, EFI_MEMORY_DESCRIPTOR *);
144 typedef EFI_STATUS (EFIAPI *EFI_GET_VARIABLE)(CHAR16 *, EFI_GUID *, UINT32 *, UINTN *, VOID *);
145 typedef EFI_STATUS (EFIAPI *EFI_GET_NEXT_VARIABLE_NAME)(UINTN *, CHAR16 *, EFI_GUID *);
146 typedef EFI_STATUS (EFIAPI *EFI_SET_VARIABLE)(CHAR16 *, EFI_GUID *, UINT32, UINTN, VOID *);
147 typedef VOID (EFIAPI *EFI_RESET_SYSTEM)(EFI_RESET_TYPE, EFI_STATUS, UINTN, VOID *);
148 
149 typedef struct {
150 	EFI_TABLE_HEADER		Hdr;
151 	EFI_GET_TIME			GetTime;
152 	EFI_SET_TIME			SetTime;
153 	VOID				*GetWakeupTime;
154 	VOID				*SetWakeupTime;
155 
156 	EFI_SET_VIRTUAL_ADDRESS_MAP	SetVirtualAddressMap;
157 	VOID				*ConvertPointer;
158 
159 	EFI_GET_VARIABLE		GetVariable;
160 	EFI_GET_NEXT_VARIABLE_NAME	GetNextVariableName;
161 	EFI_SET_VARIABLE		SetVariable;
162 
163 	VOID				*GetNextHighMonotonicCount;
164 	EFI_RESET_SYSTEM		ResetSystem;
165 } EFI_RUNTIME_SERVICES;
166 
167 typedef struct {
168 	EFI_GUID			VendorGuid;
169 	VOID				*VendorTable;
170 } EFI_CONFIGURATION_TABLE;
171 
172 typedef struct {
173 	EFI_TABLE_HEADER		Hdr;
174 	CHAR16				*FirmwareVendor;
175 	UINT32				FirmwareRevision;
176 	EFI_HANDLE			ConsoleInHandle;
177 	EFI_SIMPLE_TEXT_INPUT_PROTOCOL	*ConIn;
178 	EFI_HANDLE			ConsoleOutHandle;
179 	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL	*ConOut;
180 	EFI_HANDLE			StandardErrorHandle;
181 	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL	*StdErr;
182 	EFI_RUNTIME_SERVICES		*RuntimeServices;
183 	EFI_BOOT_SERVICES		*BootServices;
184 	UINTN				NumberOfTableEntries;
185 	EFI_CONFIGURATION_TABLE		*ConfigurationTable;
186 } EFI_SYSTEM_TABLE;
187 
188 typedef struct {
189 	EFI_GUID			FwClass;
190 	UINT32				FwType;
191 	UINT32				FwVersion;
192 	UINT32				LowestSupportedFwVersion;
193 	UINT32				CapsuleFlags;
194 	UINT32				LastAttemptVersion;
195 	UINT32				LastAttemptStatus;
196 } EFI_SYSTEM_RESOURCE_ENTRY;
197 
198 typedef struct {
199 	UINT32				FwResourceCount;
200 	UINT32				FwResourceCountMax;
201 	UINT64				FwResourceVersion;
202 	EFI_SYSTEM_RESOURCE_ENTRY	Entries[];
203 } EFI_SYSTEM_RESOURCE_TABLE;
204 
205 #define EFI_SUCCESS	0
206 
207 #define EFI_INVALID_PARAMETER	EFIERR(2)
208 #define EFI_UNSUPPORTED		EFIERR(3)
209 #define EFI_BUFFER_TOO_SMALL	EFIERR(5)
210 #define EFI_DEVICE_ERROR	EFIERR(7)
211 #define EFI_WRITE_PROTECTED	EFIERR(8)
212 #define EFI_OUT_OF_RESOURCES	EFIERR(9)
213 #define EFI_NOT_FOUND		EFIERR(14)
214 #define EFI_SECURITY_VIOLATION	EFIERR(26)
215 
216 #define	efi_guidcmp(_a, _b)	memcmp((_a), (_b), sizeof(EFI_GUID))
217 
218 #endif /* _DEV_ACPI_EFI_H_ */
219