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>
23 /* Type INTN in UEFI specification */
24 #define efi_intn_t ssize_t
25 /* Type UINTN in UEFI specification*/
26 #define efi_uintn_t size_t
29 * EFI on x86_64 uses the Microsoft ABI which is not the default for GCC.
31 * There are two scenarios for EFI on x86_64: building a 64-bit EFI stub
32 * codes (CONFIG_EFI_STUB_64BIT) and building a 64-bit U-Boot (CONFIG_X86_64).
33 * Either needs to be properly built with the '-m64' compiler flag, and hence
34 * it is enough to only check the compiler provided define __x86_64__ here.
37 #define EFIAPI __attribute__((ms_abi))
38 #define efi_va_list __builtin_ms_va_list
39 #define efi_va_start __builtin_ms_va_start
40 #define efi_va_arg __builtin_va_arg
41 #define efi_va_end __builtin_ms_va_end
43 #define EFIAPI asmlinkage
44 #define efi_va_list va_list
45 #define efi_va_start va_start
46 #define efi_va_arg va_arg
47 #define efi_va_end va_end
48 #endif /* __x86_64__ */
50 #define EFI32_LOADER_SIGNATURE "EL32"
51 #define EFI64_LOADER_SIGNATURE "EL64"
53 struct efi_device_path;
57 } efi_guid_t __attribute__((aligned(8)));
59 #define EFI_BITS_PER_LONG (sizeof(long) * 8)
61 /* Bit mask for EFI status code with error */
62 #define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
63 /* Status codes returned by EFI protocols */
65 #define EFI_LOAD_ERROR (EFI_ERROR_MASK | 1)
66 #define EFI_INVALID_PARAMETER (EFI_ERROR_MASK | 2)
67 #define EFI_UNSUPPORTED (EFI_ERROR_MASK | 3)
68 #define EFI_BAD_BUFFER_SIZE (EFI_ERROR_MASK | 4)
69 #define EFI_BUFFER_TOO_SMALL (EFI_ERROR_MASK | 5)
70 #define EFI_NOT_READY (EFI_ERROR_MASK | 6)
71 #define EFI_DEVICE_ERROR (EFI_ERROR_MASK | 7)
72 #define EFI_WRITE_PROTECTED (EFI_ERROR_MASK | 8)
73 #define EFI_OUT_OF_RESOURCES (EFI_ERROR_MASK | 9)
74 #define EFI_VOLUME_CORRUPTED (EFI_ERROR_MASK | 10)
75 #define EFI_VOLUME_FULL (EFI_ERROR_MASK | 11)
76 #define EFI_NO_MEDIA (EFI_ERROR_MASK | 12)
77 #define EFI_MEDIA_CHANGED (EFI_ERROR_MASK | 13)
78 #define EFI_NOT_FOUND (EFI_ERROR_MASK | 14)
79 #define EFI_ACCESS_DENIED (EFI_ERROR_MASK | 15)
80 #define EFI_NO_RESPONSE (EFI_ERROR_MASK | 16)
81 #define EFI_NO_MAPPING (EFI_ERROR_MASK | 17)
82 #define EFI_TIMEOUT (EFI_ERROR_MASK | 18)
83 #define EFI_NOT_STARTED (EFI_ERROR_MASK | 19)
84 #define EFI_ALREADY_STARTED (EFI_ERROR_MASK | 20)
85 #define EFI_ABORTED (EFI_ERROR_MASK | 21)
86 #define EFI_ICMP_ERROR (EFI_ERROR_MASK | 22)
87 #define EFI_TFTP_ERROR (EFI_ERROR_MASK | 23)
88 #define EFI_PROTOCOL_ERROR (EFI_ERROR_MASK | 24)
89 #define EFI_INCOMPATIBLE_VERSION (EFI_ERROR_MASK | 25)
90 #define EFI_SECURITY_VIOLATION (EFI_ERROR_MASK | 26)
91 #define EFI_CRC_ERROR (EFI_ERROR_MASK | 27)
92 #define EFI_END_OF_MEDIA (EFI_ERROR_MASK | 28)
93 #define EFI_END_OF_FILE (EFI_ERROR_MASK | 31)
94 #define EFI_INVALID_LANGUAGE (EFI_ERROR_MASK | 32)
95 #define EFI_COMPROMISED_DATA (EFI_ERROR_MASK | 33)
96 #define EFI_IP_ADDRESS_CONFLICT (EFI_ERROR_MASK | 34)
97 #define EFI_HTTP_ERROR (EFI_ERROR_MASK | 35)
99 #define EFI_WARN_UNKNOWN_GLYPH 1
100 #define EFI_WARN_DELETE_FAILURE 2
101 #define EFI_WARN_WRITE_FAILURE 3
102 #define EFI_WARN_BUFFER_TOO_SMALL 4
103 #define EFI_WARN_STALE_DATA 5
104 #define EFI_WARN_FILE_SYSTEM 6
105 #define EFI_WARN_RESET_REQUIRED 7
107 typedef unsigned long efi_status_t;
108 typedef u64 efi_physical_addr_t;
109 typedef u64 efi_virtual_addr_t;
110 typedef struct efi_object *efi_handle_t;
112 #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
113 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
114 ((a) >> 24) & 0xff, \
115 (b) & 0xff, ((b) >> 8) & 0xff, \
116 (c) & 0xff, ((c) >> 8) & 0xff, \
117 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } }
119 /* Generic EFI table header */
120 struct efi_table_hdr {
128 /* Allocation types for calls to boottime->allocate_pages*/
130 * enum efi_allocate_type - address restriction for memory allocation
132 enum efi_allocate_type {
134 * @EFI_ALLOCATE_ANY_PAGES:
135 * Allocate any block of sufficient size. Ignore memory address.
137 EFI_ALLOCATE_ANY_PAGES,
139 * @EFI_ALLOCATE_MAX_ADDRESS:
140 * Allocate a memory block with an uppermost address less or equal
141 * to the indicated address.
143 EFI_ALLOCATE_MAX_ADDRESS,
145 * @EFI_ALLOCATE_ADDRESS:
146 * Allocate a memory block starting at the indicatged adress.
148 EFI_ALLOCATE_ADDRESS,
150 * @EFI_MAX_ALLOCATE_TYPE:
151 * Value use for range checking.
153 EFI_MAX_ALLOCATE_TYPE,
156 /* Enumeration of memory types introduced in UEFI */
157 enum efi_memory_type {
158 EFI_RESERVED_MEMORY_TYPE,
160 * The code portions of a loaded application.
161 * (Note that UEFI OS loaders are UEFI applications.)
165 * The data portions of a loaded application and
166 * the default data allocation type used by an application
167 * to allocate pool memory.
170 /* The code portions of a loaded Boot Services Driver */
171 EFI_BOOT_SERVICES_CODE,
173 * The data portions of a loaded Boot Services Driver and
174 * the default data allocation type used by a Boot Services
175 * Driver to allocate pool memory.
177 EFI_BOOT_SERVICES_DATA,
178 /* The code portions of a loaded Runtime Services Driver */
179 EFI_RUNTIME_SERVICES_CODE,
181 * The data portions of a loaded Runtime Services Driver and
182 * the default data allocation type used by a Runtime Services
183 * Driver to allocate pool memory.
185 EFI_RUNTIME_SERVICES_DATA,
186 /* Free (unallocated) memory */
187 EFI_CONVENTIONAL_MEMORY,
188 /* Memory in which errors have been detected */
190 /* Memory that holds the ACPI tables */
191 EFI_ACPI_RECLAIM_MEMORY,
192 /* Address space reserved for use by the firmware */
195 * Used by system firmware to request that a memory-mapped IO region
196 * be mapped by the OS to a virtual address so it can be accessed by
197 * EFI runtime services.
201 * System memory-mapped IO region that is used to translate
202 * memory cycles to IO cycles by the processor.
206 * Address space reserved by the firmware for code that is
207 * part of the processor.
211 * Byte addressable non-volatile memory.
213 EFI_PERSISTENT_MEMORY_TYPE,
215 * Unaccepted memory must be accepted by boot target before usage.
217 EFI_UNACCEPTED_MEMORY_TYPE,
222 /* Attribute values */
223 #define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */
224 #define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */
225 #define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */
226 #define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */
227 #define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */
228 #define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */
229 #define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */
230 #define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */
231 #define EFI_MEMORY_NV ((u64)0x0000000000008000ULL) /* non-volatile */
232 #define EFI_MEMORY_MORE_RELIABLE \
233 ((u64)0x0000000000010000ULL) /* higher reliability */
234 #define EFI_MEMORY_RO ((u64)0x0000000000020000ULL) /* read-only */
235 #define EFI_MEMORY_SP ((u64)0x0000000000040000ULL) /* specific-purpose memory (SPM) */
236 #define EFI_MEMORY_CPU_CRYPTO ((u64)0x0000000000080000ULL) /* cryptographically protectable */
237 #define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */
238 #define EFI_MEM_DESC_VERSION 1
240 #define EFI_PAGE_SHIFT 12
241 #define EFI_PAGE_SIZE (1ULL << EFI_PAGE_SHIFT)
242 #define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
244 struct efi_mem_desc {
247 efi_physical_addr_t physical_start;
248 efi_virtual_addr_t virtual_start;
253 #define EFI_MEMORY_DESCRIPTOR_VERSION 1
255 /* Types and defines for Time Services */
256 #define EFI_TIME_ADJUST_DAYLIGHT 0x1
257 #define EFI_TIME_IN_DAYLIGHT 0x2
258 #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
274 struct efi_time_cap {
280 enum efi_locate_search_type {
286 struct efi_open_protocol_info_entry {
287 efi_handle_t agent_handle;
288 efi_handle_t controller_handle;
294 EFIET_END, /* Signals this is the last (empty) entry */
299 /* Number of entries */
303 #define EFI_TABLE_VERSION 1
306 * struct efi_info_hdr - Header for the EFI info table
308 * @version: EFI_TABLE_VERSION
309 * @hdr_size: Size of this struct in bytes
310 * @total_size: Total size of this header plus following data
311 * @spare: Spare space for expansion
313 struct efi_info_hdr {
321 * struct efi_entry_hdr - Header for a table entry
323 * @type: enum eft_entry_t
324 * @size: size of entry bytes excluding header and padding
325 * @addr: address of this entry (0 if it follows the header )
326 * @link: size of entry including header and padding
327 * @spare1: Spare space for expansion
328 * @spare2: Spare space for expansion
330 struct efi_entry_hdr {
340 * struct efi_entry_memmap - a memory map table passed to U-Boot
342 * @version: EFI's memory map table version
343 * @desc_size: EFI's size of each memory descriptor
344 * @spare: Spare space for expansion
345 * @desc: An array of descriptors, each @desc_size bytes apart
347 struct efi_entry_memmap {
351 struct efi_mem_desc desc[];
355 * struct efi_entry_gopmode - a GOP mode table passed to U-Boot
357 * @fb_base: EFI's framebuffer base address
358 * @fb_size: EFI's framebuffer size
359 * @info_size: GOP mode info structure size
360 * @info: Start address of the GOP mode info structure
362 struct efi_entry_gopmode {
363 efi_physical_addr_t fb_base;
365 * Not like the ones in 'struct efi_gop_mode' which are 'unsigned
366 * long', @fb_size and @info_size have to be 'u64' here. As the EFI
367 * stub codes may have different bit size from the U-Boot payload,
368 * using 'long' will cause mismatch between the producer (stub) and
369 * the consumer (payload).
374 * We cannot directly use 'struct efi_gop_mode_info info[]' here as
375 * it causes compiler to complain: array type has incomplete element
376 * type 'struct efi_gop_mode_info'.
378 struct /* efi_gop_mode_info */ {
383 u32 pixel_bitmask[4];
384 u32 pixels_per_scanline;
389 * struct efi_entry_systable - system table passed to U-Boot
391 * @sys_table: EFI system table address
393 struct efi_entry_systable {
394 efi_physical_addr_t sys_table;
397 static inline struct efi_mem_desc *efi_get_next_mem_desc(
398 struct efi_entry_memmap *map, struct efi_mem_desc *desc)
400 return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
404 * struct efi_priv - Information about the environment provided by EFI
406 * @parent_image: image passed into the EFI app or stub
407 * @sys_table: Pointer to system table
408 * @boot: Pointer to boot-services table
409 * @run: Pointer to runtime-services table
411 * @use_pool_for_malloc: true if all allocation should go through the EFI 'pool'
412 * methods allocate_pool() and free_pool(); false to use 'pages' methods
413 * allocate_pages() and free_pages()
414 * @ram_base: Base address of RAM (size CONFIG_EFI_RAM_SIZE)
415 * @image_data_type: Type of the loaded image (e.g. EFI_LOADER_CODE)
417 * @info: Header of the info list, holding info collected by the stub and passed
419 * @info_size: Size of the info list @info in bytes
420 * @next_hdr: Pointer to where to put the next header when adding to the list
423 efi_handle_t parent_image;
424 struct efi_system_table *sys_table;
425 struct efi_boot_services *boot;
426 struct efi_runtime_services *run;
429 bool use_pool_for_malloc;
430 unsigned long ram_base;
431 unsigned int image_data_type;
434 struct efi_info_hdr *info;
435 unsigned int info_size;
440 * EFI attributes of the udevice handled by efi_media driver
442 * @handle: handle of the controller on which this driver is installed
443 * @blkio: block io protocol proxied by this driver
444 * @device_path: EFI path to the device
446 struct efi_media_plat {
448 struct efi_block_io *blkio;
449 struct efi_device_path *device_path;
452 /* Base address of the EFI image */
453 extern char image_base[];
455 /* Start and end of U-Boot image (for payload) */
456 extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
459 * Variable Attributes
461 #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
462 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
463 #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
464 #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
465 #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
466 #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
467 #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
469 #define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
470 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
471 EFI_VARIABLE_RUNTIME_ACCESS | \
472 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
473 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
474 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
475 EFI_VARIABLE_APPEND_WRITE)
478 * efi_get_priv() - Get access to the EFI-private information
480 * This struct it used by both the stub and the app to record things about the
481 * EFI environment. It is not available in U-Boot proper after the stub has
482 * jumped there. Use efi_info_get() to obtain info in that case.
484 * Return: pointer to private info
486 struct efi_priv *efi_get_priv(void);
489 * efi_set_priv() - Set up a pointer to the EFI-private information
491 * This is called in the stub and app to record the location of this
494 * @priv: New location of private data
496 void efi_set_priv(struct efi_priv *priv);
499 * efi_get_sys_table() - Get access to the main EFI system table
501 * @return pointer to EFI system table
503 struct efi_system_table *efi_get_sys_table(void);
506 * efi_get_boot() - Get access to the EFI boot services table
508 * @return pointer to EFI boot services table
510 struct efi_boot_services *efi_get_boot(void);
513 * efi_get_ram_base() - Find the base of RAM
515 * This is used when U-Boot is built as an EFI application.
517 * @return the base of RAM as known to U-Boot
519 unsigned long efi_get_ram_base(void);
522 * efi_init() - Set up ready for use of EFI boot services
524 * @priv: Pointer to our private EFI structure to fill in
525 * @banner: Banner to display when starting
526 * @image: The image handle passed to efi_main()
527 * @sys_table: The EFI system table pointer passed to efi_main()
529 int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
530 struct efi_system_table *sys_table);
533 * efi_malloc() - Allocate some memory from EFI
535 * @priv: Pointer to private EFI structure
536 * @size: Number of bytes to allocate
537 * @retp: Return EFI status result
538 * @return pointer to memory allocated, or NULL on error
540 void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
543 * efi_free() - Free memory allocated from EFI
545 * @priv: Pointer to private EFI structure
546 * @ptr: Pointer to memory to free
548 void efi_free(struct efi_priv *priv, void *ptr);
551 * efi_puts() - Write out a string to the EFI console
553 * @priv: Pointer to private EFI structure
554 * @str: String to write (note this is a ASCII, not unicode)
556 void efi_puts(struct efi_priv *priv, const char *str);
559 * efi_putc() - Write out a character to the EFI console
561 * @priv: Pointer to private EFI structure
562 * @ch: Character to write (note this is not unicode)
564 void efi_putc(struct efi_priv *priv, const char ch);
567 * efi_info_get() - get an entry from an EFI table
569 * @type: Entry type to search for
570 * @datap: Returns pointer to entry data
571 * @sizep: Returns pointer to entry size
572 * @return 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
573 * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
575 int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
577 #endif /* _LINUX_EFI_H */