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#define efi_intn_t ssize_t
25
26#define efi_uintn_t size_t
27
28
29
30
31
32
33
34
35
36#ifdef __x86_64__
37#define EFIAPI __attribute__((ms_abi))
38#define efi_va_list __builtin_ms_va_list
39#define efi_va_start __builtin_ms_va_start
40#define efi_va_copy __builtin_ms_va_copy
41#define efi_va_arg __builtin_va_arg
42#define efi_va_end __builtin_ms_va_end
43#else
44#define EFIAPI asmlinkage
45#define efi_va_list va_list
46#define efi_va_start va_start
47#define efi_va_copy va_copy
48#define efi_va_arg va_arg
49#define efi_va_end va_end
50#endif
51
52#define EFI32_LOADER_SIGNATURE "EL32"
53#define EFI64_LOADER_SIGNATURE "EL64"
54
55struct efi_device_path;
56
57typedef struct {
58 u8 b[16];
59} efi_guid_t __attribute__((aligned(8)));
60
61#define EFI_BITS_PER_LONG (sizeof(long) * 8)
62
63
64#define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
65
66#define EFI_SUCCESS 0
67#define EFI_LOAD_ERROR (EFI_ERROR_MASK | 1)
68#define EFI_INVALID_PARAMETER (EFI_ERROR_MASK | 2)
69#define EFI_UNSUPPORTED (EFI_ERROR_MASK | 3)
70#define EFI_BAD_BUFFER_SIZE (EFI_ERROR_MASK | 4)
71#define EFI_BUFFER_TOO_SMALL (EFI_ERROR_MASK | 5)
72#define EFI_NOT_READY (EFI_ERROR_MASK | 6)
73#define EFI_DEVICE_ERROR (EFI_ERROR_MASK | 7)
74#define EFI_WRITE_PROTECTED (EFI_ERROR_MASK | 8)
75#define EFI_OUT_OF_RESOURCES (EFI_ERROR_MASK | 9)
76#define EFI_VOLUME_CORRUPTED (EFI_ERROR_MASK | 10)
77#define EFI_VOLUME_FULL (EFI_ERROR_MASK | 11)
78#define EFI_NO_MEDIA (EFI_ERROR_MASK | 12)
79#define EFI_MEDIA_CHANGED (EFI_ERROR_MASK | 13)
80#define EFI_NOT_FOUND (EFI_ERROR_MASK | 14)
81#define EFI_ACCESS_DENIED (EFI_ERROR_MASK | 15)
82#define EFI_NO_RESPONSE (EFI_ERROR_MASK | 16)
83#define EFI_NO_MAPPING (EFI_ERROR_MASK | 17)
84#define EFI_TIMEOUT (EFI_ERROR_MASK | 18)
85#define EFI_NOT_STARTED (EFI_ERROR_MASK | 19)
86#define EFI_ALREADY_STARTED (EFI_ERROR_MASK | 20)
87#define EFI_ABORTED (EFI_ERROR_MASK | 21)
88#define EFI_ICMP_ERROR (EFI_ERROR_MASK | 22)
89#define EFI_TFTP_ERROR (EFI_ERROR_MASK | 23)
90#define EFI_PROTOCOL_ERROR (EFI_ERROR_MASK | 24)
91#define EFI_INCOMPATIBLE_VERSION (EFI_ERROR_MASK | 25)
92#define EFI_SECURITY_VIOLATION (EFI_ERROR_MASK | 26)
93#define EFI_CRC_ERROR (EFI_ERROR_MASK | 27)
94#define EFI_END_OF_MEDIA (EFI_ERROR_MASK | 28)
95#define EFI_END_OF_FILE (EFI_ERROR_MASK | 31)
96#define EFI_INVALID_LANGUAGE (EFI_ERROR_MASK | 32)
97#define EFI_COMPROMISED_DATA (EFI_ERROR_MASK | 33)
98#define EFI_IP_ADDRESS_CONFLICT (EFI_ERROR_MASK | 34)
99#define EFI_HTTP_ERROR (EFI_ERROR_MASK | 35)
100
101#define EFI_WARN_UNKNOWN_GLYPH 1
102#define EFI_WARN_DELETE_FAILURE 2
103#define EFI_WARN_WRITE_FAILURE 3
104#define EFI_WARN_BUFFER_TOO_SMALL 4
105#define EFI_WARN_STALE_DATA 5
106#define EFI_WARN_FILE_SYSTEM 6
107#define EFI_WARN_RESET_REQUIRED 7
108
109typedef unsigned long efi_status_t;
110typedef u64 efi_physical_addr_t;
111typedef u64 efi_virtual_addr_t;
112typedef struct efi_object *efi_handle_t;
113
114#define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
115 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
116 ((a) >> 24) & 0xff, \
117 (b) & 0xff, ((b) >> 8) & 0xff, \
118 (c) & 0xff, ((c) >> 8) & 0xff, \
119 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } }
120
121
122struct efi_table_hdr {
123 u64 signature;
124 u32 revision;
125 u32 headersize;
126 u32 crc32;
127 u32 reserved;
128};
129
130
131
132
133
134enum efi_allocate_type {
135
136
137
138
139 EFI_ALLOCATE_ANY_PAGES,
140
141
142
143
144
145 EFI_ALLOCATE_MAX_ADDRESS,
146
147
148
149
150 EFI_ALLOCATE_ADDRESS,
151
152
153
154
155 EFI_MAX_ALLOCATE_TYPE,
156};
157
158
159enum efi_memory_type {
160 EFI_RESERVED_MEMORY_TYPE,
161
162
163
164
165 EFI_LOADER_CODE,
166
167
168
169
170
171 EFI_LOADER_DATA,
172
173 EFI_BOOT_SERVICES_CODE,
174
175
176
177
178
179 EFI_BOOT_SERVICES_DATA,
180
181 EFI_RUNTIME_SERVICES_CODE,
182
183
184
185
186
187 EFI_RUNTIME_SERVICES_DATA,
188
189 EFI_CONVENTIONAL_MEMORY,
190
191 EFI_UNUSABLE_MEMORY,
192
193 EFI_ACPI_RECLAIM_MEMORY,
194
195 EFI_ACPI_MEMORY_NVS,
196
197
198
199
200
201 EFI_MMAP_IO,
202
203
204
205
206 EFI_MMAP_IO_PORT,
207
208
209
210
211 EFI_PAL_CODE,
212
213
214
215 EFI_PERSISTENT_MEMORY_TYPE,
216
217
218
219 EFI_UNACCEPTED_MEMORY_TYPE,
220
221 EFI_MAX_MEMORY_TYPE,
222};
223
224
225#define EFI_MEMORY_UC ((u64)0x0000000000000001ULL)
226#define EFI_MEMORY_WC ((u64)0x0000000000000002ULL)
227#define EFI_MEMORY_WT ((u64)0x0000000000000004ULL)
228#define EFI_MEMORY_WB ((u64)0x0000000000000008ULL)
229#define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL)
230#define EFI_MEMORY_WP ((u64)0x0000000000001000ULL)
231#define EFI_MEMORY_RP ((u64)0x0000000000002000ULL)
232#define EFI_MEMORY_XP ((u64)0x0000000000004000ULL)
233#define EFI_MEMORY_NV ((u64)0x0000000000008000ULL)
234#define EFI_MEMORY_MORE_RELIABLE \
235 ((u64)0x0000000000010000ULL)
236#define EFI_MEMORY_RO ((u64)0x0000000000020000ULL)
237#define EFI_MEMORY_SP ((u64)0x0000000000040000ULL)
238#define EFI_MEMORY_CPU_CRYPTO ((u64)0x0000000000080000ULL)
239#define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL)
240#define EFI_MEM_DESC_VERSION 1
241
242#define EFI_PAGE_SHIFT 12
243#define EFI_PAGE_SIZE (1ULL << EFI_PAGE_SHIFT)
244#define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
245
246struct efi_mem_desc {
247 u32 type;
248 u32 reserved;
249 efi_physical_addr_t physical_start;
250 efi_virtual_addr_t virtual_start;
251 u64 num_pages;
252 u64 attribute;
253};
254
255#define EFI_MEMORY_DESCRIPTOR_VERSION 1
256
257
258#define EFI_TIME_ADJUST_DAYLIGHT 0x1
259#define EFI_TIME_IN_DAYLIGHT 0x2
260#define EFI_UNSPECIFIED_TIMEZONE 0x07ff
261
262struct efi_time {
263 u16 year;
264 u8 month;
265 u8 day;
266 u8 hour;
267 u8 minute;
268 u8 second;
269 u8 pad1;
270 u32 nanosecond;
271 s16 timezone;
272 u8 daylight;
273 u8 pad2;
274};
275
276struct efi_time_cap {
277 u32 resolution;
278 u32 accuracy;
279 u8 sets_to_zero;
280};
281
282enum efi_locate_search_type {
283 ALL_HANDLES,
284 BY_REGISTER_NOTIFY,
285 BY_PROTOCOL
286};
287
288struct efi_open_protocol_info_entry {
289 efi_handle_t agent_handle;
290 efi_handle_t controller_handle;
291 u32 attributes;
292 u32 open_count;
293};
294
295enum efi_entry_t {
296 EFIET_END,
297 EFIET_MEMORY_MAP,
298 EFIET_GOP_MODE,
299 EFIET_SYS_TABLE,
300
301
302 EFIET_MEMORY_COUNT,
303};
304
305#define EFI_TABLE_VERSION 1
306
307
308
309
310
311
312
313
314
315struct efi_info_hdr {
316 u32 version;
317 u32 hdr_size;
318 u32 total_size;
319 u32 spare[5];
320};
321
322
323
324
325
326
327
328
329
330
331
332struct efi_entry_hdr {
333 u32 type;
334 u32 size;
335 u64 addr;
336 u32 link;
337 u32 spare1;
338 u64 spare2;
339};
340
341
342
343
344
345
346
347
348
349struct efi_entry_memmap {
350 u32 version;
351 u32 desc_size;
352 u64 spare;
353 struct efi_mem_desc desc[];
354};
355
356
357
358
359
360
361
362
363
364struct efi_entry_gopmode {
365 efi_physical_addr_t fb_base;
366
367
368
369
370
371
372
373 u64 fb_size;
374 u64 info_size;
375
376
377
378
379
380 struct {
381 u32 version;
382 u32 width;
383 u32 height;
384 u32 pixel_format;
385 u32 pixel_bitmask[4];
386 u32 pixels_per_scanline;
387 } info[];
388};
389
390
391
392
393
394
395struct efi_entry_systable {
396 efi_physical_addr_t sys_table;
397};
398
399static inline struct efi_mem_desc *efi_get_next_mem_desc(
400 struct efi_mem_desc *desc, int desc_size)
401{
402 return (struct efi_mem_desc *)((ulong)desc + desc_size);
403}
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430struct efi_priv {
431 efi_handle_t parent_image;
432 struct efi_system_table *sys_table;
433 struct efi_boot_services *boot;
434 struct efi_runtime_services *run;
435 efi_uintn_t memmap_key;
436 struct efi_mem_desc *memmap_desc;
437 efi_uintn_t memmap_alloc;
438 efi_uintn_t memmap_size;
439 efi_uintn_t memmap_desc_size;
440 u32 memmap_version;
441
442
443 bool use_pool_for_malloc;
444 unsigned long ram_base;
445 unsigned int image_data_type;
446
447
448 struct efi_info_hdr *info;
449 unsigned int info_size;
450 void *next_hdr;
451};
452
453
454
455
456
457
458
459
460struct efi_media_plat {
461 efi_handle_t handle;
462 struct efi_block_io *blkio;
463 struct efi_device_path *device_path;
464};
465
466
467extern char image_base[];
468
469
470extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
471
472
473
474
475#define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
476#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
477#define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
478#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
479#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
480#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
481#define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
482
483#define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
484 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
485 EFI_VARIABLE_RUNTIME_ACCESS | \
486 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
487 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
488 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
489 EFI_VARIABLE_APPEND_WRITE)
490
491
492
493
494
495
496
497
498
499
500struct efi_priv *efi_get_priv(void);
501
502
503
504
505
506
507
508
509
510void efi_set_priv(struct efi_priv *priv);
511
512
513
514
515
516
517struct efi_system_table *efi_get_sys_table(void);
518
519
520
521
522
523
524struct efi_boot_services *efi_get_boot(void);
525
526
527
528
529
530
531
532
533unsigned long efi_get_ram_base(void);
534
535
536
537
538
539
540
541
542
543
544int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
545 struct efi_system_table *sys_table);
546
547
548
549
550
551
552
553
554
555void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
556
557
558
559
560
561
562
563void efi_free(struct efi_priv *priv, void *ptr);
564
565
566
567
568
569
570
571void efi_puts(struct efi_priv *priv, const char *str);
572
573
574
575
576
577
578
579void efi_putc(struct efi_priv *priv, const char ch);
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
595
596
597
598
599
600
601
602
603
604
605int efi_store_memory_map(struct efi_priv *priv);
606
607
608
609
610
611
612
613
614int efi_call_exit_boot_services(void);
615
616
617
618
619
620
621
622
623
624
625
626
627
628int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
629 int *desc_sizep, uint *versionp);
630
631#endif
632