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>
22 #ifdef CONFIG_EFI_STUB_64BIT
23 /* EFI uses the Microsoft ABI which is not the default for GCC */
24 #define EFIAPI __attribute__((ms_abi))
26 #define EFIAPI asmlinkage
29 struct efi_device_path;
31 #define EFI_BITS_PER_LONG BITS_PER_LONG
34 * With 64-bit EFI stub, EFI_BITS_PER_LONG has to be 64. EFI_STUB is set
35 * in lib/efi/Makefile, when building the stub.
37 #if defined(CONFIG_EFI_STUB_64BIT) && defined(EFI_STUB)
38 #undef EFI_BITS_PER_LONG
39 #define EFI_BITS_PER_LONG 64
42 /* Bit mask for EFI status code with error */
43 #define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
44 /* Status codes returned by EFI protocols */
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)
80 typedef unsigned long efi_status_t;
81 typedef u64 efi_physical_addr_t;
82 typedef u64 efi_virtual_addr_t;
83 typedef void *efi_handle_t;
85 #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
87 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
89 (b) & 0xff, ((b) >> 8) & 0xff, \
90 (c) & 0xff, ((c) >> 8) & 0xff, \
91 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } })
93 /* Generic EFI table header */
94 struct efi_table_hdr {
102 /* Enumeration of memory types introduced in UEFI */
104 EFI_RESERVED_MEMORY_TYPE,
106 * The code portions of a loaded application.
107 * (Note that UEFI OS loaders are UEFI applications.)
111 * The data portions of a loaded application and
112 * the default data allocation type used by an application
113 * to allocate pool memory.
116 /* The code portions of a loaded Boot Services Driver */
117 EFI_BOOT_SERVICES_CODE,
119 * The data portions of a loaded Boot Serves Driver and
120 * the default data allocation type used by a Boot Services
121 * Driver to allocate pool memory.
123 EFI_BOOT_SERVICES_DATA,
124 /* The code portions of a loaded Runtime Services Driver */
125 EFI_RUNTIME_SERVICES_CODE,
127 * The data portions of a loaded Runtime Services Driver and
128 * the default data allocation type used by a Runtime Services
129 * Driver to allocate pool memory.
131 EFI_RUNTIME_SERVICES_DATA,
132 /* Free (unallocated) memory */
133 EFI_CONVENTIONAL_MEMORY,
134 /* Memory in which errors have been detected */
136 /* Memory that holds the ACPI tables */
137 EFI_ACPI_RECLAIM_MEMORY,
138 /* Address space reserved for use by the firmware */
141 * Used by system firmware to request that a memory-mapped IO region
142 * be mapped by the OS to a virtual address so it can be accessed by
143 * EFI runtime services.
147 * System memory-mapped IO region that is used to translate
148 * memory cycles to IO cycles by the processor.
152 * Address space reserved by the firmware for code that is
153 * part of the processor.
158 EFI_TABLE_END, /* For efi_build_mem_table() */
161 /* Attribute values */
163 EFI_MEMORY_UC_SHIFT = 0, /* uncached */
164 EFI_MEMORY_WC_SHIFT = 1, /* write-coalescing */
165 EFI_MEMORY_WT_SHIFT = 2, /* write-through */
166 EFI_MEMORY_WB_SHIFT = 3, /* write-back */
167 EFI_MEMORY_UCE_SHIFT = 4, /* uncached, exported */
168 EFI_MEMORY_WP_SHIFT = 12, /* write-protect */
169 EFI_MEMORY_RP_SHIFT = 13, /* read-protect */
170 EFI_MEMORY_XP_SHIFT = 14, /* execute-protect */
171 EFI_MEMORY_RUNTIME_SHIFT = 63, /* range requires runtime mapping */
173 EFI_MEMORY_RUNTIME = 1ULL << EFI_MEMORY_RUNTIME_SHIFT,
174 EFI_MEM_DESC_VERSION = 1,
177 #define EFI_PAGE_SHIFT 12
178 #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
179 #define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
181 struct efi_mem_desc {
184 efi_physical_addr_t physical_start;
185 efi_virtual_addr_t virtual_start;
190 #define EFI_MEMORY_DESCRIPTOR_VERSION 1
192 /* Allocation types for calls to boottime->allocate_pages*/
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
198 /* Types and defines for Time Services */
199 #define EFI_TIME_ADJUST_DAYLIGHT 0x1
200 #define EFI_TIME_IN_DAYLIGHT 0x2
201 #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
217 struct efi_time_cap {
223 enum efi_locate_search_type {
229 struct efi_open_protocol_info_entry {
230 efi_handle_t agent_handle;
231 efi_handle_t controller_handle;
237 EFIET_END, /* Signals this is the last (empty) entry */
240 /* Number of entries */
244 #define EFI_TABLE_VERSION 1
247 * struct efi_info_hdr - Header for the EFI info table
249 * @version: EFI_TABLE_VERSION
250 * @hdr_size: Size of this struct in bytes
251 * @total_size: Total size of this header plus following data
252 * @spare: Spare space for expansion
254 struct efi_info_hdr {
262 * struct efi_entry_hdr - Header for a table entry
264 * @type: enum eft_entry_t
265 * @size size of entry bytes excluding header and padding
266 * @addr: address of this entry (0 if it follows the header )
267 * @link: size of entry including header and padding
268 * @spare1: Spare space for expansion
269 * @spare2: Spare space for expansion
271 struct efi_entry_hdr {
281 * struct efi_entry_memmap - a memory map table passed to U-Boot
283 * @version: EFI's memory map table version
284 * @desc_size: EFI's size of each memory descriptor
285 * @spare: Spare space for expansion
286 * @desc: An array of descriptors, each @desc_size bytes apart
288 struct efi_entry_memmap {
292 struct efi_mem_desc desc[];
295 static inline struct efi_mem_desc *efi_get_next_mem_desc(
296 struct efi_entry_memmap *map, struct efi_mem_desc *desc)
298 return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
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;
315 /* Base address of the EFI image */
316 extern char image_base[];
318 /* Start and end of U-Boot image (for payload) */
319 extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
322 * efi_get_sys_table() - Get access to the main EFI system table
324 * @return pointer to EFI system table
327 struct efi_system_table *efi_get_sys_table(void);
330 * efi_get_ram_base() - Find the base of RAM
332 * This is used when U-Boot is built as an EFI application.
334 * @return the base of RAM as known to U-Boot
336 unsigned long efi_get_ram_base(void);
339 * efi_init() - Set up ready for use of EFI boot services
341 * @priv: Pointer to our private EFI structure to fill in
342 * @banner: Banner to display when starting
343 * @image: The image handle passed to efi_main()
344 * @sys_table: The EFI system table pointer passed to efi_main()
346 int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
347 struct efi_system_table *sys_table);
350 * efi_malloc() - Allocate some memory from EFI
352 * @priv: Pointer to private EFI structure
353 * @size: Number of bytes to allocate
354 * @retp: Return EFI status result
355 * @return pointer to memory allocated, or NULL on error
357 void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
360 * efi_free() - Free memory allocated from EFI
362 * @priv: Pointer to private EFI structure
363 * @ptr: Pointer to memory to free
365 void efi_free(struct efi_priv *priv, void *ptr);
368 * efi_puts() - Write out a string to the EFI console
370 * @priv: Pointer to private EFI structure
371 * @str: String to write (note this is a ASCII, not unicode)
373 void efi_puts(struct efi_priv *priv, const char *str);
376 * efi_putc() - Write out a character to the EFI console
378 * @priv: Pointer to private EFI structure
379 * @ch: Character to write (note this is not unicode)
381 void efi_putc(struct efi_priv *priv, const char ch);
384 * efi_info_get() - get an entry from an EFI table
386 * @type: Entry type to search for
387 * @datap: Returns pointer to entry data
388 * @sizep: Returns pointer to entry size
389 * @return 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
390 * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
392 int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
395 * efi_build_mem_table() - make a sorted copy of the memory table
397 * @map: Pointer to EFI memory map table
398 * @size: Size of table in bytes
399 * @skip_bs: True to skip boot-time memory and merge it with conventional
400 * memory. This will significantly reduce the number of table
402 * @return pointer to the new table. It should be freed with free() by the
405 void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs);
407 #endif /* _LINUX_EFI_H */