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