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