Heinrich Schuchardt | 04a0f56 | 2018-09-08 10:57:59 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Extensible Firmware Interface |
| 4 | * Based on 'Extensible Firmware Interface Specification' version 0.9, |
| 5 | * April 30, 1999 |
| 6 | * |
| 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> |
| 12 | * |
| 13 | * From include/linux/efi.h in kernel 4.1 with some additions/subtractions |
| 14 | */ |
| 15 | |
| 16 | #ifndef _EFI_H |
| 17 | #define _EFI_H |
| 18 | |
Simon Glass | a0b49bc | 2016-09-25 15:27:31 -0600 | [diff] [blame] | 19 | #include <linux/linkage.h> |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 20 | #include <linux/string.h> |
| 21 | #include <linux/types.h> |
| 22 | |
Heinrich Schuchardt | 85fc2ad | 2021-01-05 07:52:48 +0100 | [diff] [blame] | 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 |
| 27 | |
Alexander Graf | 0186644 | 2018-06-22 01:38:26 -0700 | [diff] [blame] | 28 | /* |
| 29 | * EFI on x86_64 uses the Microsoft ABI which is not the default for GCC. |
| 30 | * |
| 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. |
| 35 | */ |
| 36 | #ifdef __x86_64__ |
Simon Glass | 96a8d40 | 2015-08-04 12:33:56 -0600 | [diff] [blame] | 37 | #define EFIAPI __attribute__((ms_abi)) |
Alexander Graf | beb077a | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 38 | #define efi_va_list __builtin_ms_va_list |
| 39 | #define efi_va_start __builtin_ms_va_start |
Ilias Apalodimas | 05c4c9e | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 40 | #define efi_va_copy __builtin_ms_va_copy |
Alexander Graf | beb077a | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 41 | #define efi_va_arg __builtin_va_arg |
| 42 | #define efi_va_end __builtin_ms_va_end |
Simon Glass | 96a8d40 | 2015-08-04 12:33:56 -0600 | [diff] [blame] | 43 | #else |
Simon Glass | a0b49bc | 2016-09-25 15:27:31 -0600 | [diff] [blame] | 44 | #define EFIAPI asmlinkage |
Alexander Graf | beb077a | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 45 | #define efi_va_list va_list |
| 46 | #define efi_va_start va_start |
Ilias Apalodimas | 05c4c9e | 2022-10-06 16:08:46 +0300 | [diff] [blame] | 47 | #define efi_va_copy va_copy |
Alexander Graf | beb077a | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 48 | #define efi_va_arg va_arg |
| 49 | #define efi_va_end va_end |
Alexander Graf | 0186644 | 2018-06-22 01:38:26 -0700 | [diff] [blame] | 50 | #endif /* __x86_64__ */ |
Simon Glass | 96a8d40 | 2015-08-04 12:33:56 -0600 | [diff] [blame] | 51 | |
Bin Meng | 1fdeacd | 2018-08-23 08:24:10 -0700 | [diff] [blame] | 52 | #define EFI32_LOADER_SIGNATURE "EL32" |
| 53 | #define EFI64_LOADER_SIGNATURE "EL64" |
| 54 | |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 55 | struct efi_device_path; |
| 56 | |
Rob Clark | 0d6ab32 | 2017-09-13 18:05:24 -0400 | [diff] [blame] | 57 | typedef struct { |
| 58 | u8 b[16]; |
Heinrich Schuchardt | 4b05fe9 | 2018-12-16 11:16:03 +0100 | [diff] [blame] | 59 | } efi_guid_t __attribute__((aligned(8))); |
Rob Clark | 0d6ab32 | 2017-09-13 18:05:24 -0400 | [diff] [blame] | 60 | |
Alexander Graf | 0186644 | 2018-06-22 01:38:26 -0700 | [diff] [blame] | 61 | #define EFI_BITS_PER_LONG (sizeof(long) * 8) |
Bin Meng | 3e6cc35 | 2016-08-25 01:47:18 -0700 | [diff] [blame] | 62 | |
xypron.glpk@gmx.de | 3c8ffb6 | 2017-07-04 23:15:22 +0200 | [diff] [blame] | 63 | /* Bit mask for EFI status code with error */ |
| 64 | #define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1)) |
| 65 | /* Status codes returned by EFI protocols */ |
| 66 | #define EFI_SUCCESS 0 |
| 67 | #define EFI_LOAD_ERROR (EFI_ERROR_MASK | 1) |
| 68 | #define EFI_INVALID_PARAMETER (EFI_ERROR_MASK | 2) |
| 69 | #define EFI_UNSUPPORTED (EFI_ERROR_MASK | 3) |
| 70 | #define EFI_BAD_BUFFER_SIZE (EFI_ERROR_MASK | 4) |
| 71 | #define EFI_BUFFER_TOO_SMALL (EFI_ERROR_MASK | 5) |
| 72 | #define EFI_NOT_READY (EFI_ERROR_MASK | 6) |
| 73 | #define EFI_DEVICE_ERROR (EFI_ERROR_MASK | 7) |
| 74 | #define EFI_WRITE_PROTECTED (EFI_ERROR_MASK | 8) |
| 75 | #define EFI_OUT_OF_RESOURCES (EFI_ERROR_MASK | 9) |
| 76 | #define EFI_VOLUME_CORRUPTED (EFI_ERROR_MASK | 10) |
| 77 | #define EFI_VOLUME_FULL (EFI_ERROR_MASK | 11) |
| 78 | #define EFI_NO_MEDIA (EFI_ERROR_MASK | 12) |
| 79 | #define EFI_MEDIA_CHANGED (EFI_ERROR_MASK | 13) |
| 80 | #define EFI_NOT_FOUND (EFI_ERROR_MASK | 14) |
| 81 | #define EFI_ACCESS_DENIED (EFI_ERROR_MASK | 15) |
| 82 | #define EFI_NO_RESPONSE (EFI_ERROR_MASK | 16) |
| 83 | #define EFI_NO_MAPPING (EFI_ERROR_MASK | 17) |
| 84 | #define EFI_TIMEOUT (EFI_ERROR_MASK | 18) |
| 85 | #define EFI_NOT_STARTED (EFI_ERROR_MASK | 19) |
| 86 | #define EFI_ALREADY_STARTED (EFI_ERROR_MASK | 20) |
| 87 | #define EFI_ABORTED (EFI_ERROR_MASK | 21) |
| 88 | #define EFI_ICMP_ERROR (EFI_ERROR_MASK | 22) |
| 89 | #define EFI_TFTP_ERROR (EFI_ERROR_MASK | 23) |
| 90 | #define EFI_PROTOCOL_ERROR (EFI_ERROR_MASK | 24) |
| 91 | #define EFI_INCOMPATIBLE_VERSION (EFI_ERROR_MASK | 25) |
| 92 | #define EFI_SECURITY_VIOLATION (EFI_ERROR_MASK | 26) |
| 93 | #define EFI_CRC_ERROR (EFI_ERROR_MASK | 27) |
| 94 | #define EFI_END_OF_MEDIA (EFI_ERROR_MASK | 28) |
| 95 | #define EFI_END_OF_FILE (EFI_ERROR_MASK | 31) |
| 96 | #define EFI_INVALID_LANGUAGE (EFI_ERROR_MASK | 32) |
| 97 | #define EFI_COMPROMISED_DATA (EFI_ERROR_MASK | 33) |
| 98 | #define EFI_IP_ADDRESS_CONFLICT (EFI_ERROR_MASK | 34) |
| 99 | #define EFI_HTTP_ERROR (EFI_ERROR_MASK | 35) |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 100 | |
Heinrich Schuchardt | 7b31efc | 2020-01-03 22:47:19 +0100 | [diff] [blame] | 101 | #define EFI_WARN_UNKNOWN_GLYPH 1 |
| 102 | #define EFI_WARN_DELETE_FAILURE 2 |
| 103 | #define EFI_WARN_WRITE_FAILURE 3 |
| 104 | #define EFI_WARN_BUFFER_TOO_SMALL 4 |
| 105 | #define EFI_WARN_STALE_DATA 5 |
| 106 | #define EFI_WARN_FILE_SYSTEM 6 |
| 107 | #define EFI_WARN_RESET_REQUIRED 7 |
Rob Clark | 2a92080 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 108 | |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 109 | typedef unsigned long efi_status_t; |
| 110 | typedef u64 efi_physical_addr_t; |
| 111 | typedef u64 efi_virtual_addr_t; |
Heinrich Schuchardt | faea104 | 2018-09-26 05:27:54 +0200 | [diff] [blame] | 112 | typedef struct efi_object *efi_handle_t; |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 113 | |
| 114 | #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \ |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 115 | {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \ |
| 116 | ((a) >> 24) & 0xff, \ |
| 117 | (b) & 0xff, ((b) >> 8) & 0xff, \ |
| 118 | (c) & 0xff, ((c) >> 8) & 0xff, \ |
Heinrich Schuchardt | 44ab2d3 | 2018-06-09 17:50:18 +0200 | [diff] [blame] | 119 | (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } } |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 120 | |
| 121 | /* Generic EFI table header */ |
| 122 | struct efi_table_hdr { |
| 123 | u64 signature; |
| 124 | u32 revision; |
| 125 | u32 headersize; |
| 126 | u32 crc32; |
| 127 | u32 reserved; |
| 128 | }; |
| 129 | |
Heinrich Schuchardt | 3ced574 | 2021-08-17 14:52:16 +0200 | [diff] [blame] | 130 | /* Allocation types for calls to boottime->allocate_pages*/ |
| 131 | /** |
| 132 | * enum efi_allocate_type - address restriction for memory allocation |
| 133 | */ |
| 134 | enum efi_allocate_type { |
| 135 | /** |
| 136 | * @EFI_ALLOCATE_ANY_PAGES: |
| 137 | * Allocate any block of sufficient size. Ignore memory address. |
| 138 | */ |
| 139 | EFI_ALLOCATE_ANY_PAGES, |
| 140 | /** |
| 141 | * @EFI_ALLOCATE_MAX_ADDRESS: |
| 142 | * Allocate a memory block with an uppermost address less or equal |
| 143 | * to the indicated address. |
| 144 | */ |
| 145 | EFI_ALLOCATE_MAX_ADDRESS, |
| 146 | /** |
| 147 | * @EFI_ALLOCATE_ADDRESS: |
| 148 | * Allocate a memory block starting at the indicatged adress. |
| 149 | */ |
| 150 | EFI_ALLOCATE_ADDRESS, |
| 151 | /** |
| 152 | * @EFI_MAX_ALLOCATE_TYPE: |
| 153 | * Value use for range checking. |
| 154 | */ |
| 155 | EFI_MAX_ALLOCATE_TYPE, |
| 156 | }; |
| 157 | |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 158 | /* Enumeration of memory types introduced in UEFI */ |
Heinrich Schuchardt | c91737b | 2021-08-17 15:02:23 +0200 | [diff] [blame] | 159 | enum efi_memory_type { |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 160 | EFI_RESERVED_MEMORY_TYPE, |
| 161 | /* |
| 162 | * The code portions of a loaded application. |
| 163 | * (Note that UEFI OS loaders are UEFI applications.) |
| 164 | */ |
| 165 | EFI_LOADER_CODE, |
| 166 | /* |
| 167 | * The data portions of a loaded application and |
| 168 | * the default data allocation type used by an application |
| 169 | * to allocate pool memory. |
| 170 | */ |
| 171 | EFI_LOADER_DATA, |
| 172 | /* The code portions of a loaded Boot Services Driver */ |
| 173 | EFI_BOOT_SERVICES_CODE, |
| 174 | /* |
Heinrich Schuchardt | 29f1a36 | 2017-09-18 07:54:50 +0200 | [diff] [blame] | 175 | * The data portions of a loaded Boot Services Driver and |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 176 | * the default data allocation type used by a Boot Services |
| 177 | * Driver to allocate pool memory. |
| 178 | */ |
| 179 | EFI_BOOT_SERVICES_DATA, |
| 180 | /* The code portions of a loaded Runtime Services Driver */ |
| 181 | EFI_RUNTIME_SERVICES_CODE, |
| 182 | /* |
| 183 | * The data portions of a loaded Runtime Services Driver and |
| 184 | * the default data allocation type used by a Runtime Services |
| 185 | * Driver to allocate pool memory. |
| 186 | */ |
| 187 | EFI_RUNTIME_SERVICES_DATA, |
| 188 | /* Free (unallocated) memory */ |
| 189 | EFI_CONVENTIONAL_MEMORY, |
| 190 | /* Memory in which errors have been detected */ |
| 191 | EFI_UNUSABLE_MEMORY, |
| 192 | /* Memory that holds the ACPI tables */ |
| 193 | EFI_ACPI_RECLAIM_MEMORY, |
| 194 | /* Address space reserved for use by the firmware */ |
| 195 | EFI_ACPI_MEMORY_NVS, |
| 196 | /* |
| 197 | * Used by system firmware to request that a memory-mapped IO region |
| 198 | * be mapped by the OS to a virtual address so it can be accessed by |
| 199 | * EFI runtime services. |
| 200 | */ |
| 201 | EFI_MMAP_IO, |
| 202 | /* |
| 203 | * System memory-mapped IO region that is used to translate |
| 204 | * memory cycles to IO cycles by the processor. |
| 205 | */ |
| 206 | EFI_MMAP_IO_PORT, |
| 207 | /* |
| 208 | * Address space reserved by the firmware for code that is |
| 209 | * part of the processor. |
| 210 | */ |
| 211 | EFI_PAL_CODE, |
Heinrich Schuchardt | f12bcc9 | 2019-04-23 00:30:53 +0200 | [diff] [blame] | 212 | /* |
Heinrich Schuchardt | 9933eb4 | 2021-04-02 22:16:22 +0200 | [diff] [blame] | 213 | * Byte addressable non-volatile memory. |
Heinrich Schuchardt | f12bcc9 | 2019-04-23 00:30:53 +0200 | [diff] [blame] | 214 | */ |
| 215 | EFI_PERSISTENT_MEMORY_TYPE, |
Heinrich Schuchardt | 9933eb4 | 2021-04-02 22:16:22 +0200 | [diff] [blame] | 216 | /* |
| 217 | * Unaccepted memory must be accepted by boot target before usage. |
| 218 | */ |
| 219 | EFI_UNACCEPTED_MEMORY_TYPE, |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 220 | |
| 221 | EFI_MAX_MEMORY_TYPE, |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | /* Attribute values */ |
Eugeniu Rosca | 9b89183 | 2018-07-14 22:53:30 +0200 | [diff] [blame] | 225 | #define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */ |
| 226 | #define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */ |
| 227 | #define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */ |
| 228 | #define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */ |
| 229 | #define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */ |
| 230 | #define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */ |
| 231 | #define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */ |
| 232 | #define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */ |
Eugeniu Rosca | c3a40cc | 2018-07-14 22:53:31 +0200 | [diff] [blame] | 233 | #define EFI_MEMORY_NV ((u64)0x0000000000008000ULL) /* non-volatile */ |
| 234 | #define EFI_MEMORY_MORE_RELIABLE \ |
| 235 | ((u64)0x0000000000010000ULL) /* higher reliability */ |
| 236 | #define EFI_MEMORY_RO ((u64)0x0000000000020000ULL) /* read-only */ |
Heinrich Schuchardt | 255a473 | 2020-05-19 07:20:46 +0200 | [diff] [blame] | 237 | #define EFI_MEMORY_SP ((u64)0x0000000000040000ULL) /* specific-purpose memory (SPM) */ |
Heinrich Schuchardt | 9933eb4 | 2021-04-02 22:16:22 +0200 | [diff] [blame] | 238 | #define EFI_MEMORY_CPU_CRYPTO ((u64)0x0000000000080000ULL) /* cryptographically protectable */ |
Eugeniu Rosca | 9b89183 | 2018-07-14 22:53:30 +0200 | [diff] [blame] | 239 | #define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */ |
| 240 | #define EFI_MEM_DESC_VERSION 1 |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 241 | |
| 242 | #define EFI_PAGE_SHIFT 12 |
Patrick Wildt | 60fd884 | 2019-04-09 22:58:30 +0200 | [diff] [blame] | 243 | #define EFI_PAGE_SIZE (1ULL << EFI_PAGE_SHIFT) |
Alexander Graf | 2bb9b79 | 2016-03-04 01:09:57 +0100 | [diff] [blame] | 244 | #define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1) |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 245 | |
| 246 | struct efi_mem_desc { |
| 247 | u32 type; |
| 248 | u32 reserved; |
| 249 | efi_physical_addr_t physical_start; |
| 250 | efi_virtual_addr_t virtual_start; |
| 251 | u64 num_pages; |
| 252 | u64 attribute; |
| 253 | }; |
| 254 | |
Mian Yousaf Kaukab | 4c02c11 | 2016-09-05 23:59:22 +0200 | [diff] [blame] | 255 | #define EFI_MEMORY_DESCRIPTOR_VERSION 1 |
| 256 | |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 257 | /* Types and defines for Time Services */ |
| 258 | #define EFI_TIME_ADJUST_DAYLIGHT 0x1 |
| 259 | #define EFI_TIME_IN_DAYLIGHT 0x2 |
| 260 | #define EFI_UNSPECIFIED_TIMEZONE 0x07ff |
| 261 | |
| 262 | struct efi_time { |
| 263 | u16 year; |
| 264 | u8 month; |
| 265 | u8 day; |
| 266 | u8 hour; |
| 267 | u8 minute; |
| 268 | u8 second; |
| 269 | u8 pad1; |
| 270 | u32 nanosecond; |
| 271 | s16 timezone; |
| 272 | u8 daylight; |
| 273 | u8 pad2; |
| 274 | }; |
| 275 | |
| 276 | struct efi_time_cap { |
| 277 | u32 resolution; |
| 278 | u32 accuracy; |
| 279 | u8 sets_to_zero; |
| 280 | }; |
| 281 | |
| 282 | enum efi_locate_search_type { |
Heinrich Schuchardt | 9f0770f | 2017-11-06 21:17:42 +0100 | [diff] [blame] | 283 | ALL_HANDLES, |
| 284 | BY_REGISTER_NOTIFY, |
| 285 | BY_PROTOCOL |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | struct efi_open_protocol_info_entry { |
| 289 | efi_handle_t agent_handle; |
| 290 | efi_handle_t controller_handle; |
| 291 | u32 attributes; |
| 292 | u32 open_count; |
| 293 | }; |
| 294 | |
| 295 | enum efi_entry_t { |
| 296 | EFIET_END, /* Signals this is the last (empty) entry */ |
| 297 | EFIET_MEMORY_MAP, |
Bin Meng | d1fe992 | 2018-06-12 08:36:21 -0700 | [diff] [blame] | 298 | EFIET_GOP_MODE, |
Bin Meng | cbe503f | 2018-08-23 08:24:09 -0700 | [diff] [blame] | 299 | EFIET_SYS_TABLE, |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 300 | |
| 301 | /* Number of entries */ |
| 302 | EFIET_MEMORY_COUNT, |
| 303 | }; |
| 304 | |
| 305 | #define EFI_TABLE_VERSION 1 |
| 306 | |
| 307 | /** |
| 308 | * struct efi_info_hdr - Header for the EFI info table |
| 309 | * |
| 310 | * @version: EFI_TABLE_VERSION |
| 311 | * @hdr_size: Size of this struct in bytes |
| 312 | * @total_size: Total size of this header plus following data |
| 313 | * @spare: Spare space for expansion |
| 314 | */ |
| 315 | struct efi_info_hdr { |
| 316 | u32 version; |
| 317 | u32 hdr_size; |
| 318 | u32 total_size; |
| 319 | u32 spare[5]; |
| 320 | }; |
| 321 | |
| 322 | /** |
| 323 | * struct efi_entry_hdr - Header for a table entry |
| 324 | * |
| 325 | * @type: enum eft_entry_t |
Heinrich Schuchardt | 40e5b53 | 2021-12-21 09:09:48 +0100 | [diff] [blame] | 326 | * @size: size of entry bytes excluding header and padding |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 327 | * @addr: address of this entry (0 if it follows the header ) |
| 328 | * @link: size of entry including header and padding |
| 329 | * @spare1: Spare space for expansion |
| 330 | * @spare2: Spare space for expansion |
| 331 | */ |
| 332 | struct efi_entry_hdr { |
| 333 | u32 type; |
| 334 | u32 size; |
| 335 | u64 addr; |
| 336 | u32 link; |
| 337 | u32 spare1; |
| 338 | u64 spare2; |
| 339 | }; |
| 340 | |
| 341 | /** |
| 342 | * struct efi_entry_memmap - a memory map table passed to U-Boot |
| 343 | * |
| 344 | * @version: EFI's memory map table version |
| 345 | * @desc_size: EFI's size of each memory descriptor |
| 346 | * @spare: Spare space for expansion |
| 347 | * @desc: An array of descriptors, each @desc_size bytes apart |
| 348 | */ |
| 349 | struct efi_entry_memmap { |
| 350 | u32 version; |
| 351 | u32 desc_size; |
| 352 | u64 spare; |
| 353 | struct efi_mem_desc desc[]; |
| 354 | }; |
| 355 | |
Bin Meng | d1fe992 | 2018-06-12 08:36:21 -0700 | [diff] [blame] | 356 | /** |
| 357 | * struct efi_entry_gopmode - a GOP mode table passed to U-Boot |
| 358 | * |
| 359 | * @fb_base: EFI's framebuffer base address |
| 360 | * @fb_size: EFI's framebuffer size |
| 361 | * @info_size: GOP mode info structure size |
| 362 | * @info: Start address of the GOP mode info structure |
| 363 | */ |
| 364 | struct efi_entry_gopmode { |
| 365 | efi_physical_addr_t fb_base; |
| 366 | /* |
| 367 | * Not like the ones in 'struct efi_gop_mode' which are 'unsigned |
| 368 | * long', @fb_size and @info_size have to be 'u64' here. As the EFI |
| 369 | * stub codes may have different bit size from the U-Boot payload, |
| 370 | * using 'long' will cause mismatch between the producer (stub) and |
| 371 | * the consumer (payload). |
| 372 | */ |
| 373 | u64 fb_size; |
| 374 | u64 info_size; |
| 375 | /* |
| 376 | * We cannot directly use 'struct efi_gop_mode_info info[]' here as |
| 377 | * it causes compiler to complain: array type has incomplete element |
| 378 | * type 'struct efi_gop_mode_info'. |
| 379 | */ |
| 380 | struct /* efi_gop_mode_info */ { |
| 381 | u32 version; |
| 382 | u32 width; |
| 383 | u32 height; |
| 384 | u32 pixel_format; |
| 385 | u32 pixel_bitmask[4]; |
| 386 | u32 pixels_per_scanline; |
| 387 | } info[]; |
| 388 | }; |
| 389 | |
Bin Meng | cbe503f | 2018-08-23 08:24:09 -0700 | [diff] [blame] | 390 | /** |
| 391 | * struct efi_entry_systable - system table passed to U-Boot |
| 392 | * |
| 393 | * @sys_table: EFI system table address |
| 394 | */ |
| 395 | struct efi_entry_systable { |
| 396 | efi_physical_addr_t sys_table; |
| 397 | }; |
| 398 | |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 399 | static inline struct efi_mem_desc *efi_get_next_mem_desc( |
Simon Glass | ce1dc0c | 2022-01-04 03:51:11 -0700 | [diff] [blame] | 400 | struct efi_mem_desc *desc, int desc_size) |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 401 | { |
Simon Glass | ce1dc0c | 2022-01-04 03:51:11 -0700 | [diff] [blame] | 402 | return (struct efi_mem_desc *)((ulong)desc + desc_size); |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 403 | } |
| 404 | |
Simon Glass | efd35c7 | 2021-12-29 11:57:42 -0700 | [diff] [blame] | 405 | /** |
| 406 | * struct efi_priv - Information about the environment provided by EFI |
| 407 | * |
| 408 | * @parent_image: image passed into the EFI app or stub |
| 409 | * @sys_table: Pointer to system table |
| 410 | * @boot: Pointer to boot-services table |
| 411 | * @run: Pointer to runtime-services table |
Simon Glass | 866e2ac | 2022-01-04 03:51:10 -0700 | [diff] [blame] | 412 | * @memmap_key: Key returned from get_memory_map() |
| 413 | * @memmap_desc: List of memory-map records |
| 414 | * @memmap_alloc: Amount of memory allocated for memory map list |
| 415 | * @memmap_size Size of memory-map list in bytes |
| 416 | * @memmap_desc_size: Size of an individual memory-map record, in bytes |
| 417 | * @memmap_version: Memory-map version |
Simon Glass | efd35c7 | 2021-12-29 11:57:42 -0700 | [diff] [blame] | 418 | * |
| 419 | * @use_pool_for_malloc: true if all allocation should go through the EFI 'pool' |
| 420 | * methods allocate_pool() and free_pool(); false to use 'pages' methods |
| 421 | * allocate_pages() and free_pages() |
| 422 | * @ram_base: Base address of RAM (size CONFIG_EFI_RAM_SIZE) |
| 423 | * @image_data_type: Type of the loaded image (e.g. EFI_LOADER_CODE) |
| 424 | * |
| 425 | * @info: Header of the info list, holding info collected by the stub and passed |
| 426 | * to U-Boot |
| 427 | * @info_size: Size of the info list @info in bytes |
| 428 | * @next_hdr: Pointer to where to put the next header when adding to the list |
| 429 | */ |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 430 | struct efi_priv { |
| 431 | efi_handle_t parent_image; |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 432 | struct efi_system_table *sys_table; |
| 433 | struct efi_boot_services *boot; |
| 434 | struct efi_runtime_services *run; |
Simon Glass | 866e2ac | 2022-01-04 03:51:10 -0700 | [diff] [blame] | 435 | efi_uintn_t memmap_key; |
| 436 | struct efi_mem_desc *memmap_desc; |
| 437 | efi_uintn_t memmap_alloc; |
| 438 | efi_uintn_t memmap_size; |
| 439 | efi_uintn_t memmap_desc_size; |
| 440 | u32 memmap_version; |
Simon Glass | efd35c7 | 2021-12-29 11:57:42 -0700 | [diff] [blame] | 441 | |
| 442 | /* app: */ |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 443 | bool use_pool_for_malloc; |
| 444 | unsigned long ram_base; |
| 445 | unsigned int image_data_type; |
Simon Glass | efd35c7 | 2021-12-29 11:57:42 -0700 | [diff] [blame] | 446 | |
| 447 | /* stub: */ |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 448 | struct efi_info_hdr *info; |
| 449 | unsigned int info_size; |
| 450 | void *next_hdr; |
| 451 | }; |
| 452 | |
Simon Glass | d8063dc | 2021-12-04 08:56:32 -0700 | [diff] [blame] | 453 | /* |
| 454 | * EFI attributes of the udevice handled by efi_media driver |
| 455 | * |
| 456 | * @handle: handle of the controller on which this driver is installed |
| 457 | * @blkio: block io protocol proxied by this driver |
Simon Glass | 613cd0c | 2021-12-29 11:57:36 -0700 | [diff] [blame] | 458 | * @device_path: EFI path to the device |
Simon Glass | d8063dc | 2021-12-04 08:56:32 -0700 | [diff] [blame] | 459 | */ |
| 460 | struct efi_media_plat { |
Simon Glass | 613cd0c | 2021-12-29 11:57:36 -0700 | [diff] [blame] | 461 | efi_handle_t handle; |
| 462 | struct efi_block_io *blkio; |
| 463 | struct efi_device_path *device_path; |
Simon Glass | d8063dc | 2021-12-04 08:56:32 -0700 | [diff] [blame] | 464 | }; |
| 465 | |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 466 | /* Base address of the EFI image */ |
| 467 | extern char image_base[]; |
| 468 | |
Simon Glass | 476476e | 2015-08-04 12:33:52 -0600 | [diff] [blame] | 469 | /* Start and end of U-Boot image (for payload) */ |
Bin Meng | 3dc51ab | 2016-08-25 01:47:17 -0700 | [diff] [blame] | 470 | extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[]; |
Simon Glass | 476476e | 2015-08-04 12:33:52 -0600 | [diff] [blame] | 471 | |
Rob Clark | ad644e7 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 472 | /* |
| 473 | * Variable Attributes |
| 474 | */ |
| 475 | #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001 |
| 476 | #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002 |
| 477 | #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004 |
| 478 | #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008 |
| 479 | #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010 |
| 480 | #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020 |
| 481 | #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040 |
| 482 | |
| 483 | #define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \ |
| 484 | EFI_VARIABLE_BOOTSERVICE_ACCESS | \ |
| 485 | EFI_VARIABLE_RUNTIME_ACCESS | \ |
| 486 | EFI_VARIABLE_HARDWARE_ERROR_RECORD | \ |
| 487 | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \ |
| 488 | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \ |
| 489 | EFI_VARIABLE_APPEND_WRITE) |
| 490 | |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 491 | /** |
Simon Glass | 2a1cf03 | 2021-12-29 11:57:45 -0700 | [diff] [blame] | 492 | * efi_get_priv() - Get access to the EFI-private information |
| 493 | * |
| 494 | * This struct it used by both the stub and the app to record things about the |
| 495 | * EFI environment. It is not available in U-Boot proper after the stub has |
| 496 | * jumped there. Use efi_info_get() to obtain info in that case. |
| 497 | * |
| 498 | * Return: pointer to private info |
| 499 | */ |
| 500 | struct efi_priv *efi_get_priv(void); |
| 501 | |
| 502 | /** |
| 503 | * efi_set_priv() - Set up a pointer to the EFI-private information |
| 504 | * |
| 505 | * This is called in the stub and app to record the location of this |
| 506 | * information. |
| 507 | * |
| 508 | * @priv: New location of private data |
| 509 | */ |
| 510 | void efi_set_priv(struct efi_priv *priv); |
| 511 | |
| 512 | /** |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 513 | * efi_get_sys_table() - Get access to the main EFI system table |
| 514 | * |
Simon Glass | 6b3873c | 2022-01-04 03:51:18 -0700 | [diff] [blame] | 515 | * Returns: pointer to EFI system table |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 516 | */ |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 517 | struct efi_system_table *efi_get_sys_table(void); |
| 518 | |
| 519 | /** |
Simon Glass | f844573 | 2021-11-03 21:09:09 -0600 | [diff] [blame] | 520 | * efi_get_boot() - Get access to the EFI boot services table |
| 521 | * |
Simon Glass | 6b3873c | 2022-01-04 03:51:18 -0700 | [diff] [blame] | 522 | * Returns: pointer to EFI boot services table |
Simon Glass | f844573 | 2021-11-03 21:09:09 -0600 | [diff] [blame] | 523 | */ |
| 524 | struct efi_boot_services *efi_get_boot(void); |
| 525 | |
| 526 | /** |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 527 | * efi_get_ram_base() - Find the base of RAM |
| 528 | * |
| 529 | * This is used when U-Boot is built as an EFI application. |
| 530 | * |
Simon Glass | 6b3873c | 2022-01-04 03:51:18 -0700 | [diff] [blame] | 531 | * Returns: the base of RAM as known to U-Boot |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 532 | */ |
| 533 | unsigned long efi_get_ram_base(void); |
| 534 | |
| 535 | /** |
| 536 | * efi_init() - Set up ready for use of EFI boot services |
| 537 | * |
| 538 | * @priv: Pointer to our private EFI structure to fill in |
| 539 | * @banner: Banner to display when starting |
| 540 | * @image: The image handle passed to efi_main() |
| 541 | * @sys_table: The EFI system table pointer passed to efi_main() |
Simon Glass | 6b3873c | 2022-01-04 03:51:18 -0700 | [diff] [blame] | 542 | * Return: 0 on succcess, EFI error code on failure |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 543 | */ |
| 544 | int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image, |
| 545 | struct efi_system_table *sys_table); |
| 546 | |
| 547 | /** |
| 548 | * efi_malloc() - Allocate some memory from EFI |
| 549 | * |
| 550 | * @priv: Pointer to private EFI structure |
| 551 | * @size: Number of bytes to allocate |
| 552 | * @retp: Return EFI status result |
Simon Glass | 6b3873c | 2022-01-04 03:51:18 -0700 | [diff] [blame] | 553 | * Returns: pointer to memory allocated, or NULL on error |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 554 | */ |
| 555 | void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp); |
| 556 | |
| 557 | /** |
| 558 | * efi_free() - Free memory allocated from EFI |
| 559 | * |
| 560 | * @priv: Pointer to private EFI structure |
| 561 | * @ptr: Pointer to memory to free |
| 562 | */ |
| 563 | void efi_free(struct efi_priv *priv, void *ptr); |
| 564 | |
| 565 | /** |
| 566 | * efi_puts() - Write out a string to the EFI console |
| 567 | * |
| 568 | * @priv: Pointer to private EFI structure |
| 569 | * @str: String to write (note this is a ASCII, not unicode) |
| 570 | */ |
| 571 | void efi_puts(struct efi_priv *priv, const char *str); |
| 572 | |
| 573 | /** |
| 574 | * efi_putc() - Write out a character to the EFI console |
| 575 | * |
| 576 | * @priv: Pointer to private EFI structure |
| 577 | * @ch: Character to write (note this is not unicode) |
| 578 | */ |
| 579 | void efi_putc(struct efi_priv *priv, const char ch); |
| 580 | |
| 581 | /** |
| 582 | * efi_info_get() - get an entry from an EFI table |
| 583 | * |
Simon Glass | cf37603 | 2021-12-29 11:57:48 -0700 | [diff] [blame] | 584 | * This function is called from U-Boot proper to read information set up by the |
| 585 | * EFI stub. It can only be used when running from the EFI stub, not when U-Boot |
| 586 | * is running as an app. |
| 587 | * |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 588 | * @type: Entry type to search for |
| 589 | * @datap: Returns pointer to entry data |
Simon Glass | 6b3873c | 2022-01-04 03:51:18 -0700 | [diff] [blame] | 590 | * @sizep: Returns entry size |
| 591 | * Return: 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 592 | * of the requested type, -EPROTONOSUPPORT if the table has the wrong version |
| 593 | */ |
| 594 | int efi_info_get(enum efi_entry_t type, void **datap, int *sizep); |
| 595 | |
Simon Glass | 866e2ac | 2022-01-04 03:51:10 -0700 | [diff] [blame] | 596 | /** |
| 597 | * efi_store_memory_map() - Collect the memory-map info from EFI |
| 598 | * |
| 599 | * Collect the memory info and store it for later use, e.g. in calling |
| 600 | * exit_boot_services() |
| 601 | * |
| 602 | * @priv: Pointer to private EFI structure |
Simon Glass | 6b3873c | 2022-01-04 03:51:18 -0700 | [diff] [blame] | 603 | * Returns: 0 if OK, non-zero on error |
Simon Glass | 866e2ac | 2022-01-04 03:51:10 -0700 | [diff] [blame] | 604 | */ |
| 605 | int efi_store_memory_map(struct efi_priv *priv); |
| 606 | |
| 607 | /** |
| 608 | * efi_call_exit_boot_services() - Handle the exit-boot-service procedure |
| 609 | * |
| 610 | * Tell EFI we don't want their boot services anymore |
| 611 | * |
| 612 | * Return: 0 if OK, non-zero on error |
| 613 | */ |
| 614 | int efi_call_exit_boot_services(void); |
| 615 | |
Simon Glass | 25a326b | 2022-01-04 03:51:12 -0700 | [diff] [blame] | 616 | /** |
| 617 | * efi_get_mmap() - Get the memory map from EFI |
| 618 | * |
| 619 | * This is used in the app. The caller must free *@descp when done |
| 620 | * |
| 621 | * @descp: Returns allocated pointer to EFI memory map table |
| 622 | * @sizep: Returns size of table in bytes |
| 623 | * @keyp: Returns memory-map key |
| 624 | * @desc_sizep: Returns size of each @desc_base record |
| 625 | * @versionp: Returns version number of memory map |
Simon Glass | 6b3873c | 2022-01-04 03:51:18 -0700 | [diff] [blame] | 626 | * Returns: 0 on success, -ve on error |
Simon Glass | 25a326b | 2022-01-04 03:51:12 -0700 | [diff] [blame] | 627 | */ |
| 628 | int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp, |
| 629 | int *desc_sizep, uint *versionp); |
| 630 | |
Simon Glass | 867a6ac | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 631 | #endif /* _LINUX_EFI_H */ |