2 * Extensible Firmware Interface
3 * Based on 'Extensible Firmware Interface Specification' version 0.9,
6 * Copyright (C) 1999 VA Linux Systems
8 * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
12 * From include/linux/efi.h in kernel 4.1 with some additions/subtractions
18 #include <linux/string.h>
19 #include <linux/types.h>
21 struct efi_device_path;
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)))
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;
41 #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
43 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
45 (b) & 0xff, ((b) >> 8) & 0xff, \
46 (c) & 0xff, ((c) >> 8) & 0xff, \
47 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } })
49 /* Generic EFI table header */
50 struct efi_table_hdr {
58 /* Enumeration of memory types introduced in UEFI */
60 EFI_RESERVED_MEMORY_TYPE,
62 * The code portions of a loaded application.
63 * (Note that UEFI OS loaders are UEFI applications.)
67 * The data portions of a loaded application and
68 * the default data allocation type used by an application
69 * to allocate pool memory.
72 /* The code portions of a loaded Boot Services Driver */
73 EFI_BOOT_SERVICES_CODE,
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.
79 EFI_BOOT_SERVICES_DATA,
80 /* The code portions of a loaded Runtime Services Driver */
81 EFI_RUNTIME_SERVICES_CODE,
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.
87 EFI_RUNTIME_SERVICES_DATA,
88 /* Free (unallocated) memory */
89 EFI_CONVENTIONAL_MEMORY,
90 /* Memory in which errors have been detected */
92 /* Memory that holds the ACPI tables */
93 EFI_ACPI_RECLAIM_MEMORY,
94 /* Address space reserved for use by the firmware */
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.
103 * System memory-mapped IO region that is used to translate
104 * memory cycles to IO cycles by the processor.
108 * Address space reserved by the firmware for code that is
109 * part of the processor.
114 EFI_TABLE_END, /* For efi_build_mem_table() */
117 /* Attribute values */
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 */
129 EFI_MEMORY_RUNTIME = 1ULL << EFI_MEMORY_RUNTIME_SHIFT,
130 EFI_MEM_DESC_VERSION = 1,
133 #define EFI_PAGE_SHIFT 12
134 #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
136 struct efi_mem_desc {
139 efi_physical_addr_t physical_start;
140 efi_virtual_addr_t virtual_start;
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
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
170 struct efi_time_cap {
176 enum efi_locate_search_type {
182 struct efi_open_protocol_info_entry {
183 efi_handle_t agent_handle;
184 efi_handle_t controller_handle;
190 EFIET_END, /* Signals this is the last (empty) entry */
193 /* Number of entries */
197 #define EFI_TABLE_VERSION 1
200 * struct efi_info_hdr - Header for the EFI info table
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
207 struct efi_info_hdr {
215 * struct efi_entry_hdr - Header for a table entry
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
224 struct efi_entry_hdr {
234 * struct efi_entry_memmap - a memory map table passed to U-Boot
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
241 struct efi_entry_memmap {
245 struct efi_mem_desc desc[];
248 static inline struct efi_mem_desc *efi_get_next_mem_desc(
249 struct efi_entry_memmap *map, struct efi_mem_desc *desc)
251 return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
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;
268 /* Base address of the EFI image */
269 extern char image_base[];
272 * efi_get_sys_table() - Get access to the main EFI system table
274 * @return pointer to EFI system table
276 struct efi_system_table *efi_get_sys_table(void);
279 * efi_get_ram_base() - Find the base of RAM
281 * This is used when U-Boot is built as an EFI application.
283 * @return the base of RAM as known to U-Boot
285 unsigned long efi_get_ram_base(void);
288 * efi_init() - Set up ready for use of EFI boot services
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()
295 int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
296 struct efi_system_table *sys_table);
299 * efi_malloc() - Allocate some memory from EFI
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
306 void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
309 * efi_free() - Free memory allocated from EFI
311 * @priv: Pointer to private EFI structure
312 * @ptr: Pointer to memory to free
314 void efi_free(struct efi_priv *priv, void *ptr);
317 * efi_puts() - Write out a string to the EFI console
319 * @priv: Pointer to private EFI structure
320 * @str: String to write (note this is a ASCII, not unicode)
322 void efi_puts(struct efi_priv *priv, const char *str);
325 * efi_putc() - Write out a character to the EFI console
327 * @priv: Pointer to private EFI structure
328 * @ch: Character to write (note this is not unicode)
330 void efi_putc(struct efi_priv *priv, const char ch);
333 * efi_info_get() - get an entry from an EFI table
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
341 int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
344 * efi_build_mem_table() - make a sorted copy of the memory table
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
351 * @return pointer to the new table. It should be freed with free() by the
354 void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs);
356 #endif /* _LINUX_EFI_H */