1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Extensible Firmware Interface
4 * Based on 'Extensible Firmware Interface Specification' version 0.9,
7 * Copyright (C) 1999 VA Linux Systems
8 * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
9 * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
10 * David Mosberger-Tang <davidm@hpl.hp.com>
11 * Stephane Eranian <eranian@hpl.hp.com>
13 * From include/linux/efi.h in kernel 4.1 with some additions/subtractions
19 #include <linux/linkage.h>
20 #include <linux/string.h>
21 #include <linux/types.h>
24 * EFI on x86_64 uses the Microsoft ABI which is not the default for GCC.
26 * There are two scenarios for EFI on x86_64: building a 64-bit EFI stub
27 * codes (CONFIG_EFI_STUB_64BIT) and building a 64-bit U-Boot (CONFIG_X86_64).
28 * Either needs to be properly built with the '-m64' compiler flag, and hence
29 * it is enough to only check the compiler provided define __x86_64__ here.
32 #define EFIAPI __attribute__((ms_abi))
33 #define efi_va_list __builtin_ms_va_list
34 #define efi_va_start __builtin_ms_va_start
35 #define efi_va_arg __builtin_va_arg
36 #define efi_va_end __builtin_ms_va_end
38 #define EFIAPI asmlinkage
39 #define efi_va_list va_list
40 #define efi_va_start va_start
41 #define efi_va_arg va_arg
42 #define efi_va_end va_end
43 #endif /* __x86_64__ */
45 #define EFI32_LOADER_SIGNATURE "EL32"
46 #define EFI64_LOADER_SIGNATURE "EL64"
48 struct efi_device_path;
52 } efi_guid_t __attribute__((aligned(8)));
54 #define EFI_BITS_PER_LONG (sizeof(long) * 8)
56 /* Bit mask for EFI status code with error */
57 #define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
58 /* Status codes returned by EFI protocols */
60 #define EFI_LOAD_ERROR (EFI_ERROR_MASK | 1)
61 #define EFI_INVALID_PARAMETER (EFI_ERROR_MASK | 2)
62 #define EFI_UNSUPPORTED (EFI_ERROR_MASK | 3)
63 #define EFI_BAD_BUFFER_SIZE (EFI_ERROR_MASK | 4)
64 #define EFI_BUFFER_TOO_SMALL (EFI_ERROR_MASK | 5)
65 #define EFI_NOT_READY (EFI_ERROR_MASK | 6)
66 #define EFI_DEVICE_ERROR (EFI_ERROR_MASK | 7)
67 #define EFI_WRITE_PROTECTED (EFI_ERROR_MASK | 8)
68 #define EFI_OUT_OF_RESOURCES (EFI_ERROR_MASK | 9)
69 #define EFI_VOLUME_CORRUPTED (EFI_ERROR_MASK | 10)
70 #define EFI_VOLUME_FULL (EFI_ERROR_MASK | 11)
71 #define EFI_NO_MEDIA (EFI_ERROR_MASK | 12)
72 #define EFI_MEDIA_CHANGED (EFI_ERROR_MASK | 13)
73 #define EFI_NOT_FOUND (EFI_ERROR_MASK | 14)
74 #define EFI_ACCESS_DENIED (EFI_ERROR_MASK | 15)
75 #define EFI_NO_RESPONSE (EFI_ERROR_MASK | 16)
76 #define EFI_NO_MAPPING (EFI_ERROR_MASK | 17)
77 #define EFI_TIMEOUT (EFI_ERROR_MASK | 18)
78 #define EFI_NOT_STARTED (EFI_ERROR_MASK | 19)
79 #define EFI_ALREADY_STARTED (EFI_ERROR_MASK | 20)
80 #define EFI_ABORTED (EFI_ERROR_MASK | 21)
81 #define EFI_ICMP_ERROR (EFI_ERROR_MASK | 22)
82 #define EFI_TFTP_ERROR (EFI_ERROR_MASK | 23)
83 #define EFI_PROTOCOL_ERROR (EFI_ERROR_MASK | 24)
84 #define EFI_INCOMPATIBLE_VERSION (EFI_ERROR_MASK | 25)
85 #define EFI_SECURITY_VIOLATION (EFI_ERROR_MASK | 26)
86 #define EFI_CRC_ERROR (EFI_ERROR_MASK | 27)
87 #define EFI_END_OF_MEDIA (EFI_ERROR_MASK | 28)
88 #define EFI_END_OF_FILE (EFI_ERROR_MASK | 31)
89 #define EFI_INVALID_LANGUAGE (EFI_ERROR_MASK | 32)
90 #define EFI_COMPROMISED_DATA (EFI_ERROR_MASK | 33)
91 #define EFI_IP_ADDRESS_CONFLICT (EFI_ERROR_MASK | 34)
92 #define EFI_HTTP_ERROR (EFI_ERROR_MASK | 35)
94 #define EFI_WARN_DELETE_FAILURE 2
96 typedef unsigned long efi_status_t;
97 typedef u64 efi_physical_addr_t;
98 typedef u64 efi_virtual_addr_t;
99 typedef struct efi_object *efi_handle_t;
101 #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
102 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
103 ((a) >> 24) & 0xff, \
104 (b) & 0xff, ((b) >> 8) & 0xff, \
105 (c) & 0xff, ((c) >> 8) & 0xff, \
106 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } }
108 /* Generic EFI table header */
109 struct efi_table_hdr {
117 /* Enumeration of memory types introduced in UEFI */
119 EFI_RESERVED_MEMORY_TYPE,
121 * The code portions of a loaded application.
122 * (Note that UEFI OS loaders are UEFI applications.)
126 * The data portions of a loaded application and
127 * the default data allocation type used by an application
128 * to allocate pool memory.
131 /* The code portions of a loaded Boot Services Driver */
132 EFI_BOOT_SERVICES_CODE,
134 * The data portions of a loaded Boot Services Driver and
135 * the default data allocation type used by a Boot Services
136 * Driver to allocate pool memory.
138 EFI_BOOT_SERVICES_DATA,
139 /* The code portions of a loaded Runtime Services Driver */
140 EFI_RUNTIME_SERVICES_CODE,
142 * The data portions of a loaded Runtime Services Driver and
143 * the default data allocation type used by a Runtime Services
144 * Driver to allocate pool memory.
146 EFI_RUNTIME_SERVICES_DATA,
147 /* Free (unallocated) memory */
148 EFI_CONVENTIONAL_MEMORY,
149 /* Memory in which errors have been detected */
151 /* Memory that holds the ACPI tables */
152 EFI_ACPI_RECLAIM_MEMORY,
153 /* Address space reserved for use by the firmware */
156 * Used by system firmware to request that a memory-mapped IO region
157 * be mapped by the OS to a virtual address so it can be accessed by
158 * EFI runtime services.
162 * System memory-mapped IO region that is used to translate
163 * memory cycles to IO cycles by the processor.
167 * Address space reserved by the firmware for code that is
168 * part of the processor.
173 EFI_TABLE_END, /* For efi_build_mem_table() */
176 /* Attribute values */
177 #define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */
178 #define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */
179 #define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */
180 #define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */
181 #define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */
182 #define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */
183 #define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */
184 #define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */
185 #define EFI_MEMORY_NV ((u64)0x0000000000008000ULL) /* non-volatile */
186 #define EFI_MEMORY_MORE_RELIABLE \
187 ((u64)0x0000000000010000ULL) /* higher reliability */
188 #define EFI_MEMORY_RO ((u64)0x0000000000020000ULL) /* read-only */
189 #define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */
190 #define EFI_MEM_DESC_VERSION 1
192 #define EFI_PAGE_SHIFT 12
193 #define EFI_PAGE_SIZE (1ULL << EFI_PAGE_SHIFT)
194 #define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
196 struct efi_mem_desc {
199 efi_physical_addr_t physical_start;
200 efi_virtual_addr_t virtual_start;
205 #define EFI_MEMORY_DESCRIPTOR_VERSION 1
207 /* Allocation types for calls to boottime->allocate_pages*/
208 #define EFI_ALLOCATE_ANY_PAGES 0
209 #define EFI_ALLOCATE_MAX_ADDRESS 1
210 #define EFI_ALLOCATE_ADDRESS 2
211 #define EFI_MAX_ALLOCATE_TYPE 3
213 /* Types and defines for Time Services */
214 #define EFI_TIME_ADJUST_DAYLIGHT 0x1
215 #define EFI_TIME_IN_DAYLIGHT 0x2
216 #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
232 struct efi_time_cap {
238 enum efi_locate_search_type {
244 struct efi_open_protocol_info_entry {
245 efi_handle_t agent_handle;
246 efi_handle_t controller_handle;
252 EFIET_END, /* Signals this is the last (empty) entry */
257 /* Number of entries */
261 #define EFI_TABLE_VERSION 1
264 * struct efi_info_hdr - Header for the EFI info table
266 * @version: EFI_TABLE_VERSION
267 * @hdr_size: Size of this struct in bytes
268 * @total_size: Total size of this header plus following data
269 * @spare: Spare space for expansion
271 struct efi_info_hdr {
279 * struct efi_entry_hdr - Header for a table entry
281 * @type: enum eft_entry_t
282 * @size size of entry bytes excluding header and padding
283 * @addr: address of this entry (0 if it follows the header )
284 * @link: size of entry including header and padding
285 * @spare1: Spare space for expansion
286 * @spare2: Spare space for expansion
288 struct efi_entry_hdr {
298 * struct efi_entry_memmap - a memory map table passed to U-Boot
300 * @version: EFI's memory map table version
301 * @desc_size: EFI's size of each memory descriptor
302 * @spare: Spare space for expansion
303 * @desc: An array of descriptors, each @desc_size bytes apart
305 struct efi_entry_memmap {
309 struct efi_mem_desc desc[];
313 * struct efi_entry_gopmode - a GOP mode table passed to U-Boot
315 * @fb_base: EFI's framebuffer base address
316 * @fb_size: EFI's framebuffer size
317 * @info_size: GOP mode info structure size
318 * @info: Start address of the GOP mode info structure
320 struct efi_entry_gopmode {
321 efi_physical_addr_t fb_base;
323 * Not like the ones in 'struct efi_gop_mode' which are 'unsigned
324 * long', @fb_size and @info_size have to be 'u64' here. As the EFI
325 * stub codes may have different bit size from the U-Boot payload,
326 * using 'long' will cause mismatch between the producer (stub) and
327 * the consumer (payload).
332 * We cannot directly use 'struct efi_gop_mode_info info[]' here as
333 * it causes compiler to complain: array type has incomplete element
334 * type 'struct efi_gop_mode_info'.
336 struct /* efi_gop_mode_info */ {
341 u32 pixel_bitmask[4];
342 u32 pixels_per_scanline;
347 * struct efi_entry_systable - system table passed to U-Boot
349 * @sys_table: EFI system table address
351 struct efi_entry_systable {
352 efi_physical_addr_t sys_table;
355 static inline struct efi_mem_desc *efi_get_next_mem_desc(
356 struct efi_entry_memmap *map, struct efi_mem_desc *desc)
358 return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
362 efi_handle_t parent_image;
363 struct efi_device_path *device_path;
364 struct efi_system_table *sys_table;
365 struct efi_boot_services *boot;
366 struct efi_runtime_services *run;
367 bool use_pool_for_malloc;
368 unsigned long ram_base;
369 unsigned int image_data_type;
370 struct efi_info_hdr *info;
371 unsigned int info_size;
375 /* Base address of the EFI image */
376 extern char image_base[];
378 /* Start and end of U-Boot image (for payload) */
379 extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
382 * Variable Attributes
384 #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
385 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
386 #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
387 #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
388 #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
389 #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
390 #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
392 #define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
393 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
394 EFI_VARIABLE_RUNTIME_ACCESS | \
395 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
396 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
397 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
398 EFI_VARIABLE_APPEND_WRITE)
401 * efi_get_sys_table() - Get access to the main EFI system table
403 * @return pointer to EFI system table
406 struct efi_system_table *efi_get_sys_table(void);
409 * efi_get_ram_base() - Find the base of RAM
411 * This is used when U-Boot is built as an EFI application.
413 * @return the base of RAM as known to U-Boot
415 unsigned long efi_get_ram_base(void);
418 * efi_init() - Set up ready for use of EFI boot services
420 * @priv: Pointer to our private EFI structure to fill in
421 * @banner: Banner to display when starting
422 * @image: The image handle passed to efi_main()
423 * @sys_table: The EFI system table pointer passed to efi_main()
425 int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
426 struct efi_system_table *sys_table);
429 * efi_malloc() - Allocate some memory from EFI
431 * @priv: Pointer to private EFI structure
432 * @size: Number of bytes to allocate
433 * @retp: Return EFI status result
434 * @return pointer to memory allocated, or NULL on error
436 void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
439 * efi_free() - Free memory allocated from EFI
441 * @priv: Pointer to private EFI structure
442 * @ptr: Pointer to memory to free
444 void efi_free(struct efi_priv *priv, void *ptr);
447 * efi_puts() - Write out a string to the EFI console
449 * @priv: Pointer to private EFI structure
450 * @str: String to write (note this is a ASCII, not unicode)
452 void efi_puts(struct efi_priv *priv, const char *str);
455 * efi_putc() - Write out a character to the EFI console
457 * @priv: Pointer to private EFI structure
458 * @ch: Character to write (note this is not unicode)
460 void efi_putc(struct efi_priv *priv, const char ch);
463 * efi_info_get() - get an entry from an EFI table
465 * @type: Entry type to search for
466 * @datap: Returns pointer to entry data
467 * @sizep: Returns pointer to entry size
468 * @return 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
469 * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
471 int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
474 * efi_build_mem_table() - make a sorted copy of the memory table
476 * @map: Pointer to EFI memory map table
477 * @size: Size of table in bytes
478 * @skip_bs: True to skip boot-time memory and merge it with conventional
479 * memory. This will significantly reduce the number of table
481 * @return pointer to the new table. It should be freed with free() by the
484 void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs);
486 #endif /* _LINUX_EFI_H */