]>
Commit | Line | Data |
---|---|---|
867a6ac8 SG |
1 | /* |
2 | * Extensible Firmware Interface | |
3 | * Based on 'Extensible Firmware Interface Specification' version 0.9, | |
4 | * April 30, 1999 | |
5 | * | |
6 | * Copyright (C) 1999 VA Linux Systems | |
7 | * Copyright (C) 1999 Walt Drummond <[email protected]> | |
8 | * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co. | |
9 | * David Mosberger-Tang <[email protected]> | |
10 | * Stephane Eranian <[email protected]> | |
11 | * | |
12 | * From include/linux/efi.h in kernel 4.1 with some additions/subtractions | |
13 | */ | |
14 | ||
15 | #ifndef _EFI_H | |
16 | #define _EFI_H | |
17 | ||
18 | #include <linux/string.h> | |
19 | #include <linux/types.h> | |
20 | ||
21 | struct efi_device_path; | |
22 | ||
23 | #define EFI_SUCCESS 0 | |
24 | #define EFI_LOAD_ERROR (1 | (1UL << (BITS_PER_LONG - 1))) | |
25 | #define EFI_INVALID_PARAMETER (2 | (1UL << (BITS_PER_LONG - 1))) | |
26 | #define EFI_UNSUPPORTED (3 | (1UL << (BITS_PER_LONG - 1))) | |
27 | #define EFI_BAD_BUFFER_SIZE (4 | (1UL << (BITS_PER_LONG - 1))) | |
28 | #define EFI_BUFFER_TOO_SMALL (5 | (1UL << (BITS_PER_LONG - 1))) | |
29 | #define EFI_NOT_READY (6 | (1UL << (BITS_PER_LONG - 1))) | |
30 | #define EFI_DEVICE_ERROR (7 | (1UL << (BITS_PER_LONG - 1))) | |
31 | #define EFI_WRITE_PROTECTED (8 | (1UL << (BITS_PER_LONG - 1))) | |
32 | #define EFI_OUT_OF_RESOURCES (9 | (1UL << (BITS_PER_LONG - 1))) | |
33 | #define EFI_NOT_FOUND (14 | (1UL << (BITS_PER_LONG - 1))) | |
34 | #define EFI_SECURITY_VIOLATION (26 | (1UL << (BITS_PER_LONG - 1))) | |
35 | ||
36 | typedef unsigned long efi_status_t; | |
37 | typedef u64 efi_physical_addr_t; | |
38 | typedef u64 efi_virtual_addr_t; | |
39 | typedef void *efi_handle_t; | |
40 | ||
41 | #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ | |
42 | ((efi_guid_t) \ | |
43 | {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \ | |
44 | ((a) >> 24) & 0xff, \ | |
45 | (b) & 0xff, ((b) >> 8) & 0xff, \ | |
46 | (c) & 0xff, ((c) >> 8) & 0xff, \ | |
47 | (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } }) | |
48 | ||
49 | /* Generic EFI table header */ | |
50 | struct efi_table_hdr { | |
51 | u64 signature; | |
52 | u32 revision; | |
53 | u32 headersize; | |
54 | u32 crc32; | |
55 | u32 reserved; | |
56 | }; | |
57 | ||
58 | /* Enumeration of memory types introduced in UEFI */ | |
59 | enum efi_mem_type { | |
60 | EFI_RESERVED_MEMORY_TYPE, | |
61 | /* | |
62 | * The code portions of a loaded application. | |
63 | * (Note that UEFI OS loaders are UEFI applications.) | |
64 | */ | |
65 | EFI_LOADER_CODE, | |
66 | /* | |
67 | * The data portions of a loaded application and | |
68 | * the default data allocation type used by an application | |
69 | * to allocate pool memory. | |
70 | */ | |
71 | EFI_LOADER_DATA, | |
72 | /* The code portions of a loaded Boot Services Driver */ | |
73 | EFI_BOOT_SERVICES_CODE, | |
74 | /* | |
75 | * The data portions of a loaded Boot Serves Driver and | |
76 | * the default data allocation type used by a Boot Services | |
77 | * Driver to allocate pool memory. | |
78 | */ | |
79 | EFI_BOOT_SERVICES_DATA, | |
80 | /* The code portions of a loaded Runtime Services Driver */ | |
81 | EFI_RUNTIME_SERVICES_CODE, | |
82 | /* | |
83 | * The data portions of a loaded Runtime Services Driver and | |
84 | * the default data allocation type used by a Runtime Services | |
85 | * Driver to allocate pool memory. | |
86 | */ | |
87 | EFI_RUNTIME_SERVICES_DATA, | |
88 | /* Free (unallocated) memory */ | |
89 | EFI_CONVENTIONAL_MEMORY, | |
90 | /* Memory in which errors have been detected */ | |
91 | EFI_UNUSABLE_MEMORY, | |
92 | /* Memory that holds the ACPI tables */ | |
93 | EFI_ACPI_RECLAIM_MEMORY, | |
94 | /* Address space reserved for use by the firmware */ | |
95 | EFI_ACPI_MEMORY_NVS, | |
96 | /* | |
97 | * Used by system firmware to request that a memory-mapped IO region | |
98 | * be mapped by the OS to a virtual address so it can be accessed by | |
99 | * EFI runtime services. | |
100 | */ | |
101 | EFI_MMAP_IO, | |
102 | /* | |
103 | * System memory-mapped IO region that is used to translate | |
104 | * memory cycles to IO cycles by the processor. | |
105 | */ | |
106 | EFI_MMAP_IO_PORT, | |
107 | /* | |
108 | * Address space reserved by the firmware for code that is | |
109 | * part of the processor. | |
110 | */ | |
111 | EFI_PAL_CODE, | |
112 | ||
113 | EFI_MAX_MEMORY_TYPE, | |
114 | EFI_TABLE_END, /* For efi_build_mem_table() */ | |
115 | }; | |
116 | ||
117 | /* Attribute values */ | |
118 | enum { | |
119 | EFI_MEMORY_UC_SHIFT = 0, /* uncached */ | |
120 | EFI_MEMORY_WC_SHIFT = 1, /* write-coalescing */ | |
121 | EFI_MEMORY_WT_SHIFT = 2, /* write-through */ | |
122 | EFI_MEMORY_WB_SHIFT = 3, /* write-back */ | |
123 | EFI_MEMORY_UCE_SHIFT = 4, /* uncached, exported */ | |
124 | EFI_MEMORY_WP_SHIFT = 12, /* write-protect */ | |
125 | EFI_MEMORY_RP_SHIFT = 13, /* read-protect */ | |
126 | EFI_MEMORY_XP_SHIFT = 14, /* execute-protect */ | |
127 | EFI_MEMORY_RUNTIME_SHIFT = 63, /* range requires runtime mapping */ | |
128 | ||
129 | EFI_MEMORY_RUNTIME = 1ULL << EFI_MEMORY_RUNTIME_SHIFT, | |
130 | EFI_MEM_DESC_VERSION = 1, | |
131 | }; | |
132 | ||
133 | #define EFI_PAGE_SHIFT 12 | |
134 | #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT) | |
135 | ||
136 | struct efi_mem_desc { | |
137 | u32 type; | |
138 | u32 reserved; | |
139 | efi_physical_addr_t physical_start; | |
140 | efi_virtual_addr_t virtual_start; | |
141 | u64 num_pages; | |
142 | u64 attribute; | |
143 | }; | |
144 | ||
145 | /* Allocation types for calls to boottime->allocate_pages*/ | |
146 | #define EFI_ALLOCATE_ANY_PAGES 0 | |
147 | #define EFI_ALLOCATE_MAX_ADDRESS 1 | |
148 | #define EFI_ALLOCATE_ADDRESS 2 | |
149 | #define EFI_MAX_ALLOCATE_TYPE 3 | |
150 | ||
151 | /* Types and defines for Time Services */ | |
152 | #define EFI_TIME_ADJUST_DAYLIGHT 0x1 | |
153 | #define EFI_TIME_IN_DAYLIGHT 0x2 | |
154 | #define EFI_UNSPECIFIED_TIMEZONE 0x07ff | |
155 | ||
156 | struct efi_time { | |
157 | u16 year; | |
158 | u8 month; | |
159 | u8 day; | |
160 | u8 hour; | |
161 | u8 minute; | |
162 | u8 second; | |
163 | u8 pad1; | |
164 | u32 nanosecond; | |
165 | s16 timezone; | |
166 | u8 daylight; | |
167 | u8 pad2; | |
168 | }; | |
169 | ||
170 | struct efi_time_cap { | |
171 | u32 resolution; | |
172 | u32 accuracy; | |
173 | u8 sets_to_zero; | |
174 | }; | |
175 | ||
176 | enum efi_locate_search_type { | |
177 | all_handles, | |
178 | by_register_notify, | |
179 | by_protocol | |
180 | }; | |
181 | ||
182 | struct efi_open_protocol_info_entry { | |
183 | efi_handle_t agent_handle; | |
184 | efi_handle_t controller_handle; | |
185 | u32 attributes; | |
186 | u32 open_count; | |
187 | }; | |
188 | ||
189 | enum efi_entry_t { | |
190 | EFIET_END, /* Signals this is the last (empty) entry */ | |
191 | EFIET_MEMORY_MAP, | |
192 | ||
193 | /* Number of entries */ | |
194 | EFIET_MEMORY_COUNT, | |
195 | }; | |
196 | ||
197 | #define EFI_TABLE_VERSION 1 | |
198 | ||
199 | /** | |
200 | * struct efi_info_hdr - Header for the EFI info table | |
201 | * | |
202 | * @version: EFI_TABLE_VERSION | |
203 | * @hdr_size: Size of this struct in bytes | |
204 | * @total_size: Total size of this header plus following data | |
205 | * @spare: Spare space for expansion | |
206 | */ | |
207 | struct efi_info_hdr { | |
208 | u32 version; | |
209 | u32 hdr_size; | |
210 | u32 total_size; | |
211 | u32 spare[5]; | |
212 | }; | |
213 | ||
214 | /** | |
215 | * struct efi_entry_hdr - Header for a table entry | |
216 | * | |
217 | * @type: enum eft_entry_t | |
218 | * @size size of entry bytes excluding header and padding | |
219 | * @addr: address of this entry (0 if it follows the header ) | |
220 | * @link: size of entry including header and padding | |
221 | * @spare1: Spare space for expansion | |
222 | * @spare2: Spare space for expansion | |
223 | */ | |
224 | struct efi_entry_hdr { | |
225 | u32 type; | |
226 | u32 size; | |
227 | u64 addr; | |
228 | u32 link; | |
229 | u32 spare1; | |
230 | u64 spare2; | |
231 | }; | |
232 | ||
233 | /** | |
234 | * struct efi_entry_memmap - a memory map table passed to U-Boot | |
235 | * | |
236 | * @version: EFI's memory map table version | |
237 | * @desc_size: EFI's size of each memory descriptor | |
238 | * @spare: Spare space for expansion | |
239 | * @desc: An array of descriptors, each @desc_size bytes apart | |
240 | */ | |
241 | struct efi_entry_memmap { | |
242 | u32 version; | |
243 | u32 desc_size; | |
244 | u64 spare; | |
245 | struct efi_mem_desc desc[]; | |
246 | }; | |
247 | ||
248 | static inline struct efi_mem_desc *efi_get_next_mem_desc( | |
249 | struct efi_entry_memmap *map, struct efi_mem_desc *desc) | |
250 | { | |
251 | return (struct efi_mem_desc *)((ulong)desc + map->desc_size); | |
252 | } | |
253 | ||
254 | struct efi_priv { | |
255 | efi_handle_t parent_image; | |
256 | struct efi_device_path *device_path; | |
257 | struct efi_system_table *sys_table; | |
258 | struct efi_boot_services *boot; | |
259 | struct efi_runtime_services *run; | |
260 | bool use_pool_for_malloc; | |
261 | unsigned long ram_base; | |
262 | unsigned int image_data_type; | |
263 | struct efi_info_hdr *info; | |
264 | unsigned int info_size; | |
265 | void *next_hdr; | |
266 | }; | |
267 | ||
268 | /* Base address of the EFI image */ | |
269 | extern char image_base[]; | |
270 | ||
271 | /** | |
272 | * efi_get_sys_table() - Get access to the main EFI system table | |
273 | * | |
274 | * @return pointer to EFI system table | |
275 | */ | |
276 | struct efi_system_table *efi_get_sys_table(void); | |
277 | ||
278 | /** | |
279 | * efi_get_ram_base() - Find the base of RAM | |
280 | * | |
281 | * This is used when U-Boot is built as an EFI application. | |
282 | * | |
283 | * @return the base of RAM as known to U-Boot | |
284 | */ | |
285 | unsigned long efi_get_ram_base(void); | |
286 | ||
287 | /** | |
288 | * efi_init() - Set up ready for use of EFI boot services | |
289 | * | |
290 | * @priv: Pointer to our private EFI structure to fill in | |
291 | * @banner: Banner to display when starting | |
292 | * @image: The image handle passed to efi_main() | |
293 | * @sys_table: The EFI system table pointer passed to efi_main() | |
294 | */ | |
295 | int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image, | |
296 | struct efi_system_table *sys_table); | |
297 | ||
298 | /** | |
299 | * efi_malloc() - Allocate some memory from EFI | |
300 | * | |
301 | * @priv: Pointer to private EFI structure | |
302 | * @size: Number of bytes to allocate | |
303 | * @retp: Return EFI status result | |
304 | * @return pointer to memory allocated, or NULL on error | |
305 | */ | |
306 | void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp); | |
307 | ||
308 | /** | |
309 | * efi_free() - Free memory allocated from EFI | |
310 | * | |
311 | * @priv: Pointer to private EFI structure | |
312 | * @ptr: Pointer to memory to free | |
313 | */ | |
314 | void efi_free(struct efi_priv *priv, void *ptr); | |
315 | ||
316 | /** | |
317 | * efi_puts() - Write out a string to the EFI console | |
318 | * | |
319 | * @priv: Pointer to private EFI structure | |
320 | * @str: String to write (note this is a ASCII, not unicode) | |
321 | */ | |
322 | void efi_puts(struct efi_priv *priv, const char *str); | |
323 | ||
324 | /** | |
325 | * efi_putc() - Write out a character to the EFI console | |
326 | * | |
327 | * @priv: Pointer to private EFI structure | |
328 | * @ch: Character to write (note this is not unicode) | |
329 | */ | |
330 | void efi_putc(struct efi_priv *priv, const char ch); | |
331 | ||
332 | /** | |
333 | * efi_info_get() - get an entry from an EFI table | |
334 | * | |
335 | * @type: Entry type to search for | |
336 | * @datap: Returns pointer to entry data | |
337 | * @sizep: Returns pointer to entry size | |
338 | * @return 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry | |
339 | * of the requested type, -EPROTONOSUPPORT if the table has the wrong version | |
340 | */ | |
341 | int efi_info_get(enum efi_entry_t type, void **datap, int *sizep); | |
342 | ||
343 | /** | |
344 | * efi_build_mem_table() - make a sorted copy of the memory table | |
345 | * | |
346 | * @map: Pointer to EFI memory map table | |
347 | * @size: Size of table in bytes | |
348 | * @skip_bs: True to skip boot-time memory and merge it with conventional | |
349 | * memory. This will significantly reduce the number of table | |
350 | * entries. | |
351 | * @return pointer to the new table. It should be freed with free() by the | |
352 | * caller | |
353 | */ | |
354 | void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs); | |
355 | ||
356 | #endif /* _LINUX_EFI_H */ |