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 | |
Alexander Graf | ff592b2 | 2018-06-22 01:38:26 -0700 | [diff] [blame] | 23 | /* |
| 24 | * EFI on x86_64 uses the Microsoft ABI which is not the default for GCC. |
| 25 | * |
| 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. |
| 30 | */ |
| 31 | #ifdef __x86_64__ |
Simon Glass | ce62a25 | 2015-08-04 12:33:56 -0600 | [diff] [blame] | 32 | #define EFIAPI __attribute__((ms_abi)) |
Alexander Graf | 404a7c8 | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 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 |
Simon Glass | ce62a25 | 2015-08-04 12:33:56 -0600 | [diff] [blame] | 37 | #else |
Simon Glass | cc02256 | 2016-09-25 15:27:31 -0600 | [diff] [blame] | 38 | #define EFIAPI asmlinkage |
Alexander Graf | 404a7c8 | 2018-06-18 17:23:05 +0200 | [diff] [blame] | 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 |
Alexander Graf | ff592b2 | 2018-06-22 01:38:26 -0700 | [diff] [blame] | 43 | #endif /* __x86_64__ */ |
Simon Glass | ce62a25 | 2015-08-04 12:33:56 -0600 | [diff] [blame] | 44 | |
Bin Meng | 106dcfc | 2018-08-23 08:24:10 -0700 | [diff] [blame] | 45 | #define EFI32_LOADER_SIGNATURE "EL32" |
| 46 | #define EFI64_LOADER_SIGNATURE "EL64" |
| 47 | |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 48 | struct efi_device_path; |
| 49 | |
Rob Clark | 224ee84 | 2017-09-13 18:05:24 -0400 | [diff] [blame] | 50 | typedef struct { |
| 51 | u8 b[16]; |
Heinrich Schuchardt | ebf3b17 | 2018-12-16 11:16:03 +0100 | [diff] [blame] | 52 | } efi_guid_t __attribute__((aligned(8))); |
Rob Clark | 224ee84 | 2017-09-13 18:05:24 -0400 | [diff] [blame] | 53 | |
Alexander Graf | ff592b2 | 2018-06-22 01:38:26 -0700 | [diff] [blame] | 54 | #define EFI_BITS_PER_LONG (sizeof(long) * 8) |
Bin Meng | e20a69c | 2016-08-25 01:47:18 -0700 | [diff] [blame] | 55 | |
xypron.glpk@gmx.de | b343d93 | 2017-07-04 23:15:22 +0200 | [diff] [blame] | 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 */ |
| 59 | #define EFI_SUCCESS 0 |
| 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) |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 93 | |
Heinrich Schuchardt | 91aab82 | 2020-01-03 22:47:19 +0100 | [diff] [blame] | 94 | #define EFI_WARN_UNKNOWN_GLYPH 1 |
| 95 | #define EFI_WARN_DELETE_FAILURE 2 |
| 96 | #define EFI_WARN_WRITE_FAILURE 3 |
| 97 | #define EFI_WARN_BUFFER_TOO_SMALL 4 |
| 98 | #define EFI_WARN_STALE_DATA 5 |
| 99 | #define EFI_WARN_FILE_SYSTEM 6 |
| 100 | #define EFI_WARN_RESET_REQUIRED 7 |
Rob Clark | 5314203 | 2017-09-13 18:05:34 -0400 | [diff] [blame] | 101 | |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 102 | typedef unsigned long efi_status_t; |
| 103 | typedef u64 efi_physical_addr_t; |
| 104 | typedef u64 efi_virtual_addr_t; |
Heinrich Schuchardt | 4f94ec5 | 2018-09-26 05:27:54 +0200 | [diff] [blame] | 105 | typedef struct efi_object *efi_handle_t; |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 106 | |
| 107 | #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] | 108 | {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \ |
| 109 | ((a) >> 24) & 0xff, \ |
| 110 | (b) & 0xff, ((b) >> 8) & 0xff, \ |
| 111 | (c) & 0xff, ((c) >> 8) & 0xff, \ |
Heinrich Schuchardt | fac7867 | 2018-06-09 17:50:18 +0200 | [diff] [blame] | 112 | (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } } |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 113 | |
| 114 | /* Generic EFI table header */ |
| 115 | struct efi_table_hdr { |
| 116 | u64 signature; |
| 117 | u32 revision; |
| 118 | u32 headersize; |
| 119 | u32 crc32; |
| 120 | u32 reserved; |
| 121 | }; |
| 122 | |
| 123 | /* Enumeration of memory types introduced in UEFI */ |
| 124 | enum efi_mem_type { |
| 125 | EFI_RESERVED_MEMORY_TYPE, |
| 126 | /* |
| 127 | * The code portions of a loaded application. |
| 128 | * (Note that UEFI OS loaders are UEFI applications.) |
| 129 | */ |
| 130 | EFI_LOADER_CODE, |
| 131 | /* |
| 132 | * The data portions of a loaded application and |
| 133 | * the default data allocation type used by an application |
| 134 | * to allocate pool memory. |
| 135 | */ |
| 136 | EFI_LOADER_DATA, |
| 137 | /* The code portions of a loaded Boot Services Driver */ |
| 138 | EFI_BOOT_SERVICES_CODE, |
| 139 | /* |
Heinrich Schuchardt | 514b91f | 2017-09-18 07:54:50 +0200 | [diff] [blame] | 140 | * The data portions of a loaded Boot Services Driver and |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 141 | * the default data allocation type used by a Boot Services |
| 142 | * Driver to allocate pool memory. |
| 143 | */ |
| 144 | EFI_BOOT_SERVICES_DATA, |
| 145 | /* The code portions of a loaded Runtime Services Driver */ |
| 146 | EFI_RUNTIME_SERVICES_CODE, |
| 147 | /* |
| 148 | * The data portions of a loaded Runtime Services Driver and |
| 149 | * the default data allocation type used by a Runtime Services |
| 150 | * Driver to allocate pool memory. |
| 151 | */ |
| 152 | EFI_RUNTIME_SERVICES_DATA, |
| 153 | /* Free (unallocated) memory */ |
| 154 | EFI_CONVENTIONAL_MEMORY, |
| 155 | /* Memory in which errors have been detected */ |
| 156 | EFI_UNUSABLE_MEMORY, |
| 157 | /* Memory that holds the ACPI tables */ |
| 158 | EFI_ACPI_RECLAIM_MEMORY, |
| 159 | /* Address space reserved for use by the firmware */ |
| 160 | EFI_ACPI_MEMORY_NVS, |
| 161 | /* |
| 162 | * Used by system firmware to request that a memory-mapped IO region |
| 163 | * be mapped by the OS to a virtual address so it can be accessed by |
| 164 | * EFI runtime services. |
| 165 | */ |
| 166 | EFI_MMAP_IO, |
| 167 | /* |
| 168 | * System memory-mapped IO region that is used to translate |
| 169 | * memory cycles to IO cycles by the processor. |
| 170 | */ |
| 171 | EFI_MMAP_IO_PORT, |
| 172 | /* |
| 173 | * Address space reserved by the firmware for code that is |
| 174 | * part of the processor. |
| 175 | */ |
| 176 | EFI_PAL_CODE, |
Heinrich Schuchardt | f727233 | 2019-04-23 00:30:53 +0200 | [diff] [blame] | 177 | /* |
| 178 | * Non-volatile memory. |
| 179 | */ |
| 180 | EFI_PERSISTENT_MEMORY_TYPE, |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 181 | |
| 182 | EFI_MAX_MEMORY_TYPE, |
| 183 | EFI_TABLE_END, /* For efi_build_mem_table() */ |
| 184 | }; |
| 185 | |
| 186 | /* Attribute values */ |
Eugeniu Rosca | c86c081 | 2018-07-14 22:53:30 +0200 | [diff] [blame] | 187 | #define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */ |
| 188 | #define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */ |
| 189 | #define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */ |
| 190 | #define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */ |
| 191 | #define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */ |
| 192 | #define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */ |
| 193 | #define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */ |
| 194 | #define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */ |
Eugeniu Rosca | 4e44233 | 2018-07-14 22:53:31 +0200 | [diff] [blame] | 195 | #define EFI_MEMORY_NV ((u64)0x0000000000008000ULL) /* non-volatile */ |
| 196 | #define EFI_MEMORY_MORE_RELIABLE \ |
| 197 | ((u64)0x0000000000010000ULL) /* higher reliability */ |
| 198 | #define EFI_MEMORY_RO ((u64)0x0000000000020000ULL) /* read-only */ |
Heinrich Schuchardt | e76f0e4 | 2020-05-19 07:20:46 +0200 | [diff] [blame] | 199 | #define EFI_MEMORY_SP ((u64)0x0000000000040000ULL) /* specific-purpose memory (SPM) */ |
Eugeniu Rosca | c86c081 | 2018-07-14 22:53:30 +0200 | [diff] [blame] | 200 | #define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */ |
| 201 | #define EFI_MEM_DESC_VERSION 1 |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 202 | |
| 203 | #define EFI_PAGE_SHIFT 12 |
Patrick Wildt | a98bd39 | 2019-04-09 22:58:30 +0200 | [diff] [blame] | 204 | #define EFI_PAGE_SIZE (1ULL << EFI_PAGE_SHIFT) |
Alexander Graf | 3ad57b4 | 2016-03-04 01:09:57 +0100 | [diff] [blame] | 205 | #define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1) |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 206 | |
| 207 | struct efi_mem_desc { |
| 208 | u32 type; |
| 209 | u32 reserved; |
| 210 | efi_physical_addr_t physical_start; |
| 211 | efi_virtual_addr_t virtual_start; |
| 212 | u64 num_pages; |
| 213 | u64 attribute; |
| 214 | }; |
| 215 | |
Mian Yousaf Kaukab | 338cf56 | 2016-09-05 23:59:22 +0200 | [diff] [blame] | 216 | #define EFI_MEMORY_DESCRIPTOR_VERSION 1 |
| 217 | |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 218 | /* Allocation types for calls to boottime->allocate_pages*/ |
| 219 | #define EFI_ALLOCATE_ANY_PAGES 0 |
| 220 | #define EFI_ALLOCATE_MAX_ADDRESS 1 |
| 221 | #define EFI_ALLOCATE_ADDRESS 2 |
| 222 | #define EFI_MAX_ALLOCATE_TYPE 3 |
| 223 | |
| 224 | /* Types and defines for Time Services */ |
| 225 | #define EFI_TIME_ADJUST_DAYLIGHT 0x1 |
| 226 | #define EFI_TIME_IN_DAYLIGHT 0x2 |
| 227 | #define EFI_UNSPECIFIED_TIMEZONE 0x07ff |
| 228 | |
| 229 | struct efi_time { |
| 230 | u16 year; |
| 231 | u8 month; |
| 232 | u8 day; |
| 233 | u8 hour; |
| 234 | u8 minute; |
| 235 | u8 second; |
| 236 | u8 pad1; |
| 237 | u32 nanosecond; |
| 238 | s16 timezone; |
| 239 | u8 daylight; |
| 240 | u8 pad2; |
| 241 | }; |
| 242 | |
| 243 | struct efi_time_cap { |
| 244 | u32 resolution; |
| 245 | u32 accuracy; |
| 246 | u8 sets_to_zero; |
| 247 | }; |
| 248 | |
| 249 | enum efi_locate_search_type { |
Heinrich Schuchardt | 68845f0 | 2017-11-06 21:17:42 +0100 | [diff] [blame] | 250 | ALL_HANDLES, |
| 251 | BY_REGISTER_NOTIFY, |
| 252 | BY_PROTOCOL |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | struct efi_open_protocol_info_entry { |
| 256 | efi_handle_t agent_handle; |
| 257 | efi_handle_t controller_handle; |
| 258 | u32 attributes; |
| 259 | u32 open_count; |
| 260 | }; |
| 261 | |
| 262 | enum efi_entry_t { |
| 263 | EFIET_END, /* Signals this is the last (empty) entry */ |
| 264 | EFIET_MEMORY_MAP, |
Bin Meng | cb787cb | 2018-06-12 08:36:21 -0700 | [diff] [blame] | 265 | EFIET_GOP_MODE, |
Bin Meng | 8839851 | 2018-08-23 08:24:09 -0700 | [diff] [blame] | 266 | EFIET_SYS_TABLE, |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 267 | |
| 268 | /* Number of entries */ |
| 269 | EFIET_MEMORY_COUNT, |
| 270 | }; |
| 271 | |
| 272 | #define EFI_TABLE_VERSION 1 |
| 273 | |
| 274 | /** |
| 275 | * struct efi_info_hdr - Header for the EFI info table |
| 276 | * |
| 277 | * @version: EFI_TABLE_VERSION |
| 278 | * @hdr_size: Size of this struct in bytes |
| 279 | * @total_size: Total size of this header plus following data |
| 280 | * @spare: Spare space for expansion |
| 281 | */ |
| 282 | struct efi_info_hdr { |
| 283 | u32 version; |
| 284 | u32 hdr_size; |
| 285 | u32 total_size; |
| 286 | u32 spare[5]; |
| 287 | }; |
| 288 | |
| 289 | /** |
| 290 | * struct efi_entry_hdr - Header for a table entry |
| 291 | * |
| 292 | * @type: enum eft_entry_t |
| 293 | * @size size of entry bytes excluding header and padding |
| 294 | * @addr: address of this entry (0 if it follows the header ) |
| 295 | * @link: size of entry including header and padding |
| 296 | * @spare1: Spare space for expansion |
| 297 | * @spare2: Spare space for expansion |
| 298 | */ |
| 299 | struct efi_entry_hdr { |
| 300 | u32 type; |
| 301 | u32 size; |
| 302 | u64 addr; |
| 303 | u32 link; |
| 304 | u32 spare1; |
| 305 | u64 spare2; |
| 306 | }; |
| 307 | |
| 308 | /** |
| 309 | * struct efi_entry_memmap - a memory map table passed to U-Boot |
| 310 | * |
| 311 | * @version: EFI's memory map table version |
| 312 | * @desc_size: EFI's size of each memory descriptor |
| 313 | * @spare: Spare space for expansion |
| 314 | * @desc: An array of descriptors, each @desc_size bytes apart |
| 315 | */ |
| 316 | struct efi_entry_memmap { |
| 317 | u32 version; |
| 318 | u32 desc_size; |
| 319 | u64 spare; |
| 320 | struct efi_mem_desc desc[]; |
| 321 | }; |
| 322 | |
Bin Meng | cb787cb | 2018-06-12 08:36:21 -0700 | [diff] [blame] | 323 | /** |
| 324 | * struct efi_entry_gopmode - a GOP mode table passed to U-Boot |
| 325 | * |
| 326 | * @fb_base: EFI's framebuffer base address |
| 327 | * @fb_size: EFI's framebuffer size |
| 328 | * @info_size: GOP mode info structure size |
| 329 | * @info: Start address of the GOP mode info structure |
| 330 | */ |
| 331 | struct efi_entry_gopmode { |
| 332 | efi_physical_addr_t fb_base; |
| 333 | /* |
| 334 | * Not like the ones in 'struct efi_gop_mode' which are 'unsigned |
| 335 | * long', @fb_size and @info_size have to be 'u64' here. As the EFI |
| 336 | * stub codes may have different bit size from the U-Boot payload, |
| 337 | * using 'long' will cause mismatch between the producer (stub) and |
| 338 | * the consumer (payload). |
| 339 | */ |
| 340 | u64 fb_size; |
| 341 | u64 info_size; |
| 342 | /* |
| 343 | * We cannot directly use 'struct efi_gop_mode_info info[]' here as |
| 344 | * it causes compiler to complain: array type has incomplete element |
| 345 | * type 'struct efi_gop_mode_info'. |
| 346 | */ |
| 347 | struct /* efi_gop_mode_info */ { |
| 348 | u32 version; |
| 349 | u32 width; |
| 350 | u32 height; |
| 351 | u32 pixel_format; |
| 352 | u32 pixel_bitmask[4]; |
| 353 | u32 pixels_per_scanline; |
| 354 | } info[]; |
| 355 | }; |
| 356 | |
Bin Meng | 8839851 | 2018-08-23 08:24:09 -0700 | [diff] [blame] | 357 | /** |
| 358 | * struct efi_entry_systable - system table passed to U-Boot |
| 359 | * |
| 360 | * @sys_table: EFI system table address |
| 361 | */ |
| 362 | struct efi_entry_systable { |
| 363 | efi_physical_addr_t sys_table; |
| 364 | }; |
| 365 | |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 366 | static inline struct efi_mem_desc *efi_get_next_mem_desc( |
| 367 | struct efi_entry_memmap *map, struct efi_mem_desc *desc) |
| 368 | { |
| 369 | return (struct efi_mem_desc *)((ulong)desc + map->desc_size); |
| 370 | } |
| 371 | |
| 372 | struct efi_priv { |
| 373 | efi_handle_t parent_image; |
| 374 | struct efi_device_path *device_path; |
| 375 | struct efi_system_table *sys_table; |
| 376 | struct efi_boot_services *boot; |
| 377 | struct efi_runtime_services *run; |
| 378 | bool use_pool_for_malloc; |
| 379 | unsigned long ram_base; |
| 380 | unsigned int image_data_type; |
| 381 | struct efi_info_hdr *info; |
| 382 | unsigned int info_size; |
| 383 | void *next_hdr; |
| 384 | }; |
| 385 | |
| 386 | /* Base address of the EFI image */ |
| 387 | extern char image_base[]; |
| 388 | |
Simon Glass | 63f581f | 2015-08-04 12:33:52 -0600 | [diff] [blame] | 389 | /* Start and end of U-Boot image (for payload) */ |
Bin Meng | 7c78bf9 | 2016-08-25 01:47:17 -0700 | [diff] [blame] | 390 | extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[]; |
Simon Glass | 63f581f | 2015-08-04 12:33:52 -0600 | [diff] [blame] | 391 | |
Rob Clark | 15f3d74 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 392 | /* |
| 393 | * Variable Attributes |
| 394 | */ |
| 395 | #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001 |
| 396 | #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002 |
| 397 | #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004 |
| 398 | #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008 |
| 399 | #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010 |
| 400 | #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020 |
| 401 | #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040 |
| 402 | |
| 403 | #define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \ |
| 404 | EFI_VARIABLE_BOOTSERVICE_ACCESS | \ |
| 405 | EFI_VARIABLE_RUNTIME_ACCESS | \ |
| 406 | EFI_VARIABLE_HARDWARE_ERROR_RECORD | \ |
| 407 | EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \ |
| 408 | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \ |
| 409 | EFI_VARIABLE_APPEND_WRITE) |
| 410 | |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 411 | /** |
| 412 | * efi_get_sys_table() - Get access to the main EFI system table |
| 413 | * |
| 414 | * @return pointer to EFI system table |
| 415 | */ |
Simon Glass | 63f581f | 2015-08-04 12:33:52 -0600 | [diff] [blame] | 416 | |
Simon Glass | 9539e69 | 2015-07-31 09:31:36 -0600 | [diff] [blame] | 417 | struct efi_system_table *efi_get_sys_table(void); |
| 418 | |
| 419 | /** |
| 420 | * efi_get_ram_base() - Find the base of RAM |
| 421 | * |
| 422 | * This is used when U-Boot is built as an EFI application. |
| 423 | * |
| 424 | * @return the base of RAM as known to U-Boot |
| 425 | */ |
| 426 | unsigned long efi_get_ram_base(void); |
| 427 | |
| 428 | /** |
| 429 | * efi_init() - Set up ready for use of EFI boot services |
| 430 | * |
| 431 | * @priv: Pointer to our private EFI structure to fill in |
| 432 | * @banner: Banner to display when starting |
| 433 | * @image: The image handle passed to efi_main() |
| 434 | * @sys_table: The EFI system table pointer passed to efi_main() |
| 435 | */ |
| 436 | int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image, |
| 437 | struct efi_system_table *sys_table); |
| 438 | |
| 439 | /** |
| 440 | * efi_malloc() - Allocate some memory from EFI |
| 441 | * |
| 442 | * @priv: Pointer to private EFI structure |
| 443 | * @size: Number of bytes to allocate |
| 444 | * @retp: Return EFI status result |
| 445 | * @return pointer to memory allocated, or NULL on error |
| 446 | */ |
| 447 | void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp); |
| 448 | |
| 449 | /** |
| 450 | * efi_free() - Free memory allocated from EFI |
| 451 | * |
| 452 | * @priv: Pointer to private EFI structure |
| 453 | * @ptr: Pointer to memory to free |
| 454 | */ |
| 455 | void efi_free(struct efi_priv *priv, void *ptr); |
| 456 | |
| 457 | /** |
| 458 | * efi_puts() - Write out a string to the EFI console |
| 459 | * |
| 460 | * @priv: Pointer to private EFI structure |
| 461 | * @str: String to write (note this is a ASCII, not unicode) |
| 462 | */ |
| 463 | void efi_puts(struct efi_priv *priv, const char *str); |
| 464 | |
| 465 | /** |
| 466 | * efi_putc() - Write out a character to the EFI console |
| 467 | * |
| 468 | * @priv: Pointer to private EFI structure |
| 469 | * @ch: Character to write (note this is not unicode) |
| 470 | */ |
| 471 | void efi_putc(struct efi_priv *priv, const char ch); |
| 472 | |
| 473 | /** |
| 474 | * efi_info_get() - get an entry from an EFI table |
| 475 | * |
| 476 | * @type: Entry type to search for |
| 477 | * @datap: Returns pointer to entry data |
| 478 | * @sizep: Returns pointer to entry size |
| 479 | * @return 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry |
| 480 | * of the requested type, -EPROTONOSUPPORT if the table has the wrong version |
| 481 | */ |
| 482 | int efi_info_get(enum efi_entry_t type, void **datap, int *sizep); |
| 483 | |
| 484 | /** |
| 485 | * efi_build_mem_table() - make a sorted copy of the memory table |
| 486 | * |
| 487 | * @map: Pointer to EFI memory map table |
| 488 | * @size: Size of table in bytes |
| 489 | * @skip_bs: True to skip boot-time memory and merge it with conventional |
| 490 | * memory. This will significantly reduce the number of table |
| 491 | * entries. |
| 492 | * @return pointer to the new table. It should be freed with free() by the |
| 493 | * caller |
| 494 | */ |
| 495 | void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs); |
| 496 | |
| 497 | #endif /* _LINUX_EFI_H */ |