2 * Extensible Firmware Interface
3 * Based on 'Extensible Firmware Interface Specification' version 0.9,
6 * Copyright (C) 1999 VA Linux Systems
7 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
8 * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
9 * David Mosberger-Tang <davidm@hpl.hp.com>
10 * Stephane Eranian <eranian@hpl.hp.com>
12 * From include/linux/efi.h in kernel 4.1 with some additions/subtractions
18 #include <linux/linkage.h>
19 #include <linux/string.h>
20 #include <linux/types.h>
23 * EFI on x86_64 uses the Microsoft ABI which is not the default for GCC.
25 * There are two scenarios for EFI on x86_64: building a 64-bit EFI stub
26 * codes (CONFIG_EFI_STUB_64BIT) and building a 64-bit U-Boot (CONFIG_X86_64).
27 * Either needs to be properly built with the '-m64' compiler flag, and hence
28 * it is enough to only check the compiler provided define __x86_64__ here.
31 #define EFIAPI __attribute__((ms_abi))
33 #define EFIAPI asmlinkage
34 #endif /* __x86_64__ */
36 struct efi_device_path;
42 #define EFI_BITS_PER_LONG (sizeof(long) * 8)
44 /* Bit mask for EFI status code with error */
45 #define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
46 /* Status codes returned by EFI protocols */
48 #define EFI_LOAD_ERROR (EFI_ERROR_MASK | 1)
49 #define EFI_INVALID_PARAMETER (EFI_ERROR_MASK | 2)
50 #define EFI_UNSUPPORTED (EFI_ERROR_MASK | 3)
51 #define EFI_BAD_BUFFER_SIZE (EFI_ERROR_MASK | 4)
52 #define EFI_BUFFER_TOO_SMALL (EFI_ERROR_MASK | 5)
53 #define EFI_NOT_READY (EFI_ERROR_MASK | 6)
54 #define EFI_DEVICE_ERROR (EFI_ERROR_MASK | 7)
55 #define EFI_WRITE_PROTECTED (EFI_ERROR_MASK | 8)
56 #define EFI_OUT_OF_RESOURCES (EFI_ERROR_MASK | 9)
57 #define EFI_VOLUME_CORRUPTED (EFI_ERROR_MASK | 10)
58 #define EFI_VOLUME_FULL (EFI_ERROR_MASK | 11)
59 #define EFI_NO_MEDIA (EFI_ERROR_MASK | 12)
60 #define EFI_MEDIA_CHANGED (EFI_ERROR_MASK | 13)
61 #define EFI_NOT_FOUND (EFI_ERROR_MASK | 14)
62 #define EFI_ACCESS_DENIED (EFI_ERROR_MASK | 15)
63 #define EFI_NO_RESPONSE (EFI_ERROR_MASK | 16)
64 #define EFI_NO_MAPPING (EFI_ERROR_MASK | 17)
65 #define EFI_TIMEOUT (EFI_ERROR_MASK | 18)
66 #define EFI_NOT_STARTED (EFI_ERROR_MASK | 19)
67 #define EFI_ALREADY_STARTED (EFI_ERROR_MASK | 20)
68 #define EFI_ABORTED (EFI_ERROR_MASK | 21)
69 #define EFI_ICMP_ERROR (EFI_ERROR_MASK | 22)
70 #define EFI_TFTP_ERROR (EFI_ERROR_MASK | 23)
71 #define EFI_PROTOCOL_ERROR (EFI_ERROR_MASK | 24)
72 #define EFI_INCOMPATIBLE_VERSION (EFI_ERROR_MASK | 25)
73 #define EFI_SECURITY_VIOLATION (EFI_ERROR_MASK | 26)
74 #define EFI_CRC_ERROR (EFI_ERROR_MASK | 27)
75 #define EFI_END_OF_MEDIA (EFI_ERROR_MASK | 28)
76 #define EFI_END_OF_FILE (EFI_ERROR_MASK | 31)
77 #define EFI_INVALID_LANGUAGE (EFI_ERROR_MASK | 32)
78 #define EFI_COMPROMISED_DATA (EFI_ERROR_MASK | 33)
79 #define EFI_IP_ADDRESS_CONFLICT (EFI_ERROR_MASK | 34)
80 #define EFI_HTTP_ERROR (EFI_ERROR_MASK | 35)
82 #define EFI_WARN_DELETE_FAILURE 2
84 typedef unsigned long efi_status_t;
85 typedef u64 efi_physical_addr_t;
86 typedef u64 efi_virtual_addr_t;
87 typedef void *efi_handle_t;
89 #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
90 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
92 (b) & 0xff, ((b) >> 8) & 0xff, \
93 (c) & 0xff, ((c) >> 8) & 0xff, \
94 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } }
96 /* Generic EFI table header */
97 struct efi_table_hdr {
105 /* Enumeration of memory types introduced in UEFI */
107 EFI_RESERVED_MEMORY_TYPE,
109 * The code portions of a loaded application.
110 * (Note that UEFI OS loaders are UEFI applications.)
114 * The data portions of a loaded application and
115 * the default data allocation type used by an application
116 * to allocate pool memory.
119 /* The code portions of a loaded Boot Services Driver */
120 EFI_BOOT_SERVICES_CODE,
122 * The data portions of a loaded Boot Services Driver and
123 * the default data allocation type used by a Boot Services
124 * Driver to allocate pool memory.
126 EFI_BOOT_SERVICES_DATA,
127 /* The code portions of a loaded Runtime Services Driver */
128 EFI_RUNTIME_SERVICES_CODE,
130 * The data portions of a loaded Runtime Services Driver and
131 * the default data allocation type used by a Runtime Services
132 * Driver to allocate pool memory.
134 EFI_RUNTIME_SERVICES_DATA,
135 /* Free (unallocated) memory */
136 EFI_CONVENTIONAL_MEMORY,
137 /* Memory in which errors have been detected */
139 /* Memory that holds the ACPI tables */
140 EFI_ACPI_RECLAIM_MEMORY,
141 /* Address space reserved for use by the firmware */
144 * Used by system firmware to request that a memory-mapped IO region
145 * be mapped by the OS to a virtual address so it can be accessed by
146 * EFI runtime services.
150 * System memory-mapped IO region that is used to translate
151 * memory cycles to IO cycles by the processor.
155 * Address space reserved by the firmware for code that is
156 * part of the processor.
161 EFI_TABLE_END, /* For efi_build_mem_table() */
164 /* Attribute values */
166 EFI_MEMORY_UC_SHIFT = 0, /* uncached */
167 EFI_MEMORY_WC_SHIFT = 1, /* write-coalescing */
168 EFI_MEMORY_WT_SHIFT = 2, /* write-through */
169 EFI_MEMORY_WB_SHIFT = 3, /* write-back */
170 EFI_MEMORY_UCE_SHIFT = 4, /* uncached, exported */
171 EFI_MEMORY_WP_SHIFT = 12, /* write-protect */
172 EFI_MEMORY_RP_SHIFT = 13, /* read-protect */
173 EFI_MEMORY_XP_SHIFT = 14, /* execute-protect */
174 EFI_MEMORY_RUNTIME_SHIFT = 63, /* range requires runtime mapping */
176 EFI_MEMORY_RUNTIME = 1ULL << EFI_MEMORY_RUNTIME_SHIFT,
177 EFI_MEM_DESC_VERSION = 1,
180 #define EFI_PAGE_SHIFT 12
181 #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
182 #define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
184 struct efi_mem_desc {
187 efi_physical_addr_t physical_start;
188 efi_virtual_addr_t virtual_start;
193 #define EFI_MEMORY_DESCRIPTOR_VERSION 1
195 /* Allocation types for calls to boottime->allocate_pages*/
196 #define EFI_ALLOCATE_ANY_PAGES 0
197 #define EFI_ALLOCATE_MAX_ADDRESS 1
198 #define EFI_ALLOCATE_ADDRESS 2
199 #define EFI_MAX_ALLOCATE_TYPE 3
201 /* Types and defines for Time Services */
202 #define EFI_TIME_ADJUST_DAYLIGHT 0x1
203 #define EFI_TIME_IN_DAYLIGHT 0x2
204 #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
220 struct efi_time_cap {
226 enum efi_locate_search_type {
232 struct efi_open_protocol_info_entry {
233 efi_handle_t agent_handle;
234 efi_handle_t controller_handle;
240 EFIET_END, /* Signals this is the last (empty) entry */
244 /* Number of entries */
248 #define EFI_TABLE_VERSION 1
251 * struct efi_info_hdr - Header for the EFI info table
253 * @version: EFI_TABLE_VERSION
254 * @hdr_size: Size of this struct in bytes
255 * @total_size: Total size of this header plus following data
256 * @spare: Spare space for expansion
258 struct efi_info_hdr {
266 * struct efi_entry_hdr - Header for a table entry
268 * @type: enum eft_entry_t
269 * @size size of entry bytes excluding header and padding
270 * @addr: address of this entry (0 if it follows the header )
271 * @link: size of entry including header and padding
272 * @spare1: Spare space for expansion
273 * @spare2: Spare space for expansion
275 struct efi_entry_hdr {
285 * struct efi_entry_memmap - a memory map table passed to U-Boot
287 * @version: EFI's memory map table version
288 * @desc_size: EFI's size of each memory descriptor
289 * @spare: Spare space for expansion
290 * @desc: An array of descriptors, each @desc_size bytes apart
292 struct efi_entry_memmap {
296 struct efi_mem_desc desc[];
300 * struct efi_entry_gopmode - a GOP mode table passed to U-Boot
302 * @fb_base: EFI's framebuffer base address
303 * @fb_size: EFI's framebuffer size
304 * @info_size: GOP mode info structure size
305 * @info: Start address of the GOP mode info structure
307 struct efi_entry_gopmode {
308 efi_physical_addr_t fb_base;
310 * Not like the ones in 'struct efi_gop_mode' which are 'unsigned
311 * long', @fb_size and @info_size have to be 'u64' here. As the EFI
312 * stub codes may have different bit size from the U-Boot payload,
313 * using 'long' will cause mismatch between the producer (stub) and
314 * the consumer (payload).
319 * We cannot directly use 'struct efi_gop_mode_info info[]' here as
320 * it causes compiler to complain: array type has incomplete element
321 * type 'struct efi_gop_mode_info'.
323 struct /* efi_gop_mode_info */ {
328 u32 pixel_bitmask[4];
329 u32 pixels_per_scanline;
333 static inline struct efi_mem_desc *efi_get_next_mem_desc(
334 struct efi_entry_memmap *map, struct efi_mem_desc *desc)
336 return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
340 efi_handle_t parent_image;
341 struct efi_device_path *device_path;
342 struct efi_system_table *sys_table;
343 struct efi_boot_services *boot;
344 struct efi_runtime_services *run;
345 bool use_pool_for_malloc;
346 unsigned long ram_base;
347 unsigned int image_data_type;
348 struct efi_info_hdr *info;
349 unsigned int info_size;
353 /* Base address of the EFI image */
354 extern char image_base[];
356 /* Start and end of U-Boot image (for payload) */
357 extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
360 * Variable Attributes
362 #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
363 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
364 #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
365 #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
366 #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
367 #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
368 #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
370 #define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
371 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
372 EFI_VARIABLE_RUNTIME_ACCESS | \
373 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
374 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
375 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
376 EFI_VARIABLE_APPEND_WRITE)
379 * efi_get_sys_table() - Get access to the main EFI system table
381 * @return pointer to EFI system table
384 struct efi_system_table *efi_get_sys_table(void);
387 * efi_get_ram_base() - Find the base of RAM
389 * This is used when U-Boot is built as an EFI application.
391 * @return the base of RAM as known to U-Boot
393 unsigned long efi_get_ram_base(void);
396 * efi_init() - Set up ready for use of EFI boot services
398 * @priv: Pointer to our private EFI structure to fill in
399 * @banner: Banner to display when starting
400 * @image: The image handle passed to efi_main()
401 * @sys_table: The EFI system table pointer passed to efi_main()
403 int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
404 struct efi_system_table *sys_table);
407 * efi_malloc() - Allocate some memory from EFI
409 * @priv: Pointer to private EFI structure
410 * @size: Number of bytes to allocate
411 * @retp: Return EFI status result
412 * @return pointer to memory allocated, or NULL on error
414 void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
417 * efi_free() - Free memory allocated from EFI
419 * @priv: Pointer to private EFI structure
420 * @ptr: Pointer to memory to free
422 void efi_free(struct efi_priv *priv, void *ptr);
425 * efi_puts() - Write out a string to the EFI console
427 * @priv: Pointer to private EFI structure
428 * @str: String to write (note this is a ASCII, not unicode)
430 void efi_puts(struct efi_priv *priv, const char *str);
433 * efi_putc() - Write out a character to the EFI console
435 * @priv: Pointer to private EFI structure
436 * @ch: Character to write (note this is not unicode)
438 void efi_putc(struct efi_priv *priv, const char ch);
441 * efi_info_get() - get an entry from an EFI table
443 * @type: Entry type to search for
444 * @datap: Returns pointer to entry data
445 * @sizep: Returns pointer to entry size
446 * @return 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
447 * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
449 int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
452 * efi_build_mem_table() - make a sorted copy of the memory table
454 * @map: Pointer to EFI memory map table
455 * @size: Size of table in bytes
456 * @skip_bs: True to skip boot-time memory and merge it with conventional
457 * memory. This will significantly reduce the number of table
459 * @return pointer to the new table. It should be freed with free() by the
462 void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs);
464 #endif /* _LINUX_EFI_H */