1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef _EFI_H
16#define _EFI_H
17
18#include <linux/linkage.h>
19#include <linux/string.h>
20#include <linux/types.h>
21
22#if CONFIG_EFI_STUB_64BIT || (!defined(CONFIG_EFI_STUB) && defined(__x86_64__))
23
24#define EFIAPI __attribute__((ms_abi))
25#else
26#define EFIAPI asmlinkage
27#endif
28
29struct efi_device_path;
30
31typedef struct {
32 u8 b[16];
33} efi_guid_t;
34
35#define EFI_BITS_PER_LONG BITS_PER_LONG
36
37
38
39
40
41#if defined(CONFIG_EFI_STUB_64BIT) && defined(EFI_STUB)
42#undef EFI_BITS_PER_LONG
43#define EFI_BITS_PER_LONG 64
44#endif
45
46
47#define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
48
49#define EFI_SUCCESS 0
50#define EFI_LOAD_ERROR (EFI_ERROR_MASK | 1)
51#define EFI_INVALID_PARAMETER (EFI_ERROR_MASK | 2)
52#define EFI_UNSUPPORTED (EFI_ERROR_MASK | 3)
53#define EFI_BAD_BUFFER_SIZE (EFI_ERROR_MASK | 4)
54#define EFI_BUFFER_TOO_SMALL (EFI_ERROR_MASK | 5)
55#define EFI_NOT_READY (EFI_ERROR_MASK | 6)
56#define EFI_DEVICE_ERROR (EFI_ERROR_MASK | 7)
57#define EFI_WRITE_PROTECTED (EFI_ERROR_MASK | 8)
58#define EFI_OUT_OF_RESOURCES (EFI_ERROR_MASK | 9)
59#define EFI_VOLUME_CORRUPTED (EFI_ERROR_MASK | 10)
60#define EFI_VOLUME_FULL (EFI_ERROR_MASK | 11)
61#define EFI_NO_MEDIA (EFI_ERROR_MASK | 12)
62#define EFI_MEDIA_CHANGED (EFI_ERROR_MASK | 13)
63#define EFI_NOT_FOUND (EFI_ERROR_MASK | 14)
64#define EFI_ACCESS_DENIED (EFI_ERROR_MASK | 15)
65#define EFI_NO_RESPONSE (EFI_ERROR_MASK | 16)
66#define EFI_NO_MAPPING (EFI_ERROR_MASK | 17)
67#define EFI_TIMEOUT (EFI_ERROR_MASK | 18)
68#define EFI_NOT_STARTED (EFI_ERROR_MASK | 19)
69#define EFI_ALREADY_STARTED (EFI_ERROR_MASK | 20)
70#define EFI_ABORTED (EFI_ERROR_MASK | 21)
71#define EFI_ICMP_ERROR (EFI_ERROR_MASK | 22)
72#define EFI_TFTP_ERROR (EFI_ERROR_MASK | 23)
73#define EFI_PROTOCOL_ERROR (EFI_ERROR_MASK | 24)
74#define EFI_INCOMPATIBLE_VERSION (EFI_ERROR_MASK | 25)
75#define EFI_SECURITY_VIOLATION (EFI_ERROR_MASK | 26)
76#define EFI_CRC_ERROR (EFI_ERROR_MASK | 27)
77#define EFI_END_OF_MEDIA (EFI_ERROR_MASK | 28)
78#define EFI_END_OF_FILE (EFI_ERROR_MASK | 31)
79#define EFI_INVALID_LANGUAGE (EFI_ERROR_MASK | 32)
80#define EFI_COMPROMISED_DATA (EFI_ERROR_MASK | 33)
81#define EFI_IP_ADDRESS_CONFLICT (EFI_ERROR_MASK | 34)
82#define EFI_HTTP_ERROR (EFI_ERROR_MASK | 35)
83
84#define EFI_WARN_DELETE_FAILURE 2
85
86typedef unsigned long efi_status_t;
87typedef u64 efi_physical_addr_t;
88typedef u64 efi_virtual_addr_t;
89typedef void *efi_handle_t;
90
91#define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
92 ((efi_guid_t) \
93 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
94 ((a) >> 24) & 0xff, \
95 (b) & 0xff, ((b) >> 8) & 0xff, \
96 (c) & 0xff, ((c) >> 8) & 0xff, \
97 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } })
98
99
100struct efi_table_hdr {
101 u64 signature;
102 u32 revision;
103 u32 headersize;
104 u32 crc32;
105 u32 reserved;
106};
107
108
109enum efi_mem_type {
110 EFI_RESERVED_MEMORY_TYPE,
111
112
113
114
115 EFI_LOADER_CODE,
116
117
118
119
120
121 EFI_LOADER_DATA,
122
123 EFI_BOOT_SERVICES_CODE,
124
125
126
127
128
129 EFI_BOOT_SERVICES_DATA,
130
131 EFI_RUNTIME_SERVICES_CODE,
132
133
134
135
136
137 EFI_RUNTIME_SERVICES_DATA,
138
139 EFI_CONVENTIONAL_MEMORY,
140
141 EFI_UNUSABLE_MEMORY,
142
143 EFI_ACPI_RECLAIM_MEMORY,
144
145 EFI_ACPI_MEMORY_NVS,
146
147
148
149
150
151 EFI_MMAP_IO,
152
153
154
155
156 EFI_MMAP_IO_PORT,
157
158
159
160
161 EFI_PAL_CODE,
162
163 EFI_MAX_MEMORY_TYPE,
164 EFI_TABLE_END,
165};
166
167
168enum {
169 EFI_MEMORY_UC_SHIFT = 0,
170 EFI_MEMORY_WC_SHIFT = 1,
171 EFI_MEMORY_WT_SHIFT = 2,
172 EFI_MEMORY_WB_SHIFT = 3,
173 EFI_MEMORY_UCE_SHIFT = 4,
174 EFI_MEMORY_WP_SHIFT = 12,
175 EFI_MEMORY_RP_SHIFT = 13,
176 EFI_MEMORY_XP_SHIFT = 14,
177 EFI_MEMORY_RUNTIME_SHIFT = 63,
178
179 EFI_MEMORY_RUNTIME = 1ULL << EFI_MEMORY_RUNTIME_SHIFT,
180 EFI_MEM_DESC_VERSION = 1,
181};
182
183#define EFI_PAGE_SHIFT 12
184#define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
185#define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
186
187struct efi_mem_desc {
188 u32 type;
189 u32 reserved;
190 efi_physical_addr_t physical_start;
191 efi_virtual_addr_t virtual_start;
192 u64 num_pages;
193 u64 attribute;
194};
195
196#define EFI_MEMORY_DESCRIPTOR_VERSION 1
197
198
199#define EFI_ALLOCATE_ANY_PAGES 0
200#define EFI_ALLOCATE_MAX_ADDRESS 1
201#define EFI_ALLOCATE_ADDRESS 2
202#define EFI_MAX_ALLOCATE_TYPE 3
203
204
205#define EFI_TIME_ADJUST_DAYLIGHT 0x1
206#define EFI_TIME_IN_DAYLIGHT 0x2
207#define EFI_UNSPECIFIED_TIMEZONE 0x07ff
208
209struct efi_time {
210 u16 year;
211 u8 month;
212 u8 day;
213 u8 hour;
214 u8 minute;
215 u8 second;
216 u8 pad1;
217 u32 nanosecond;
218 s16 timezone;
219 u8 daylight;
220 u8 pad2;
221};
222
223struct efi_time_cap {
224 u32 resolution;
225 u32 accuracy;
226 u8 sets_to_zero;
227};
228
229enum efi_locate_search_type {
230 ALL_HANDLES,
231 BY_REGISTER_NOTIFY,
232 BY_PROTOCOL
233};
234
235struct efi_open_protocol_info_entry {
236 efi_handle_t agent_handle;
237 efi_handle_t controller_handle;
238 u32 attributes;
239 u32 open_count;
240};
241
242enum efi_entry_t {
243 EFIET_END,
244 EFIET_MEMORY_MAP,
245
246
247 EFIET_MEMORY_COUNT,
248};
249
250#define EFI_TABLE_VERSION 1
251
252
253
254
255
256
257
258
259
260struct efi_info_hdr {
261 u32 version;
262 u32 hdr_size;
263 u32 total_size;
264 u32 spare[5];
265};
266
267
268
269
270
271
272
273
274
275
276
277struct efi_entry_hdr {
278 u32 type;
279 u32 size;
280 u64 addr;
281 u32 link;
282 u32 spare1;
283 u64 spare2;
284};
285
286
287
288
289
290
291
292
293
294struct efi_entry_memmap {
295 u32 version;
296 u32 desc_size;
297 u64 spare;
298 struct efi_mem_desc desc[];
299};
300
301static inline struct efi_mem_desc *efi_get_next_mem_desc(
302 struct efi_entry_memmap *map, struct efi_mem_desc *desc)
303{
304 return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
305}
306
307struct efi_priv {
308 efi_handle_t parent_image;
309 struct efi_device_path *device_path;
310 struct efi_system_table *sys_table;
311 struct efi_boot_services *boot;
312 struct efi_runtime_services *run;
313 bool use_pool_for_malloc;
314 unsigned long ram_base;
315 unsigned int image_data_type;
316 struct efi_info_hdr *info;
317 unsigned int info_size;
318 void *next_hdr;
319};
320
321
322extern char image_base[];
323
324
325extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
326
327
328
329
330#define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
331#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
332#define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
333#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
334#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
335#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
336#define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
337
338#define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
339 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
340 EFI_VARIABLE_RUNTIME_ACCESS | \
341 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
342 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
343 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
344 EFI_VARIABLE_APPEND_WRITE)
345
346
347
348
349
350
351
352struct efi_system_table *efi_get_sys_table(void);
353
354
355
356
357
358
359
360
361unsigned long efi_get_ram_base(void);
362
363
364
365
366
367
368
369
370
371int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
372 struct efi_system_table *sys_table);
373
374
375
376
377
378
379
380
381
382void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
383
384
385
386
387
388
389
390void efi_free(struct efi_priv *priv, void *ptr);
391
392
393
394
395
396
397
398void efi_puts(struct efi_priv *priv, const char *str);
399
400
401
402
403
404
405
406void efi_putc(struct efi_priv *priv, const char ch);
407
408
409
410
411
412
413
414
415
416
417int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
418
419
420
421
422
423
424
425
426
427
428
429
430void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs);
431
432#endif
433