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