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