blob: 6159f34ad2beffcda6c4d7ebcf042fc6d627ff6b [file] [log] [blame]
Heinrich Schuchardt1fce3c02018-09-08 10:57:59 +02001/* SPDX-License-Identifier: GPL-2.0 */
Simon Glass9539e692015-07-31 09:31:36 -06002/*
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 Glasscc022562016-09-25 15:27:31 -060019#include <linux/linkage.h>
Simon Glass9539e692015-07-31 09:31:36 -060020#include <linux/string.h>
21#include <linux/types.h>
22
Heinrich Schuchardt546a52f2021-01-05 07:52:48 +010023/* 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 Grafff592b22018-06-22 01:38:26 -070028/*
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 Glassce62a252015-08-04 12:33:56 -060037#define EFIAPI __attribute__((ms_abi))
Alexander Graf404a7c82018-06-18 17:23:05 +020038#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
Simon Glassce62a252015-08-04 12:33:56 -060042#else
Simon Glasscc022562016-09-25 15:27:31 -060043#define EFIAPI asmlinkage
Alexander Graf404a7c82018-06-18 17:23:05 +020044#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
Alexander Grafff592b22018-06-22 01:38:26 -070048#endif /* __x86_64__ */
Simon Glassce62a252015-08-04 12:33:56 -060049
Bin Meng106dcfc2018-08-23 08:24:10 -070050#define EFI32_LOADER_SIGNATURE "EL32"
51#define EFI64_LOADER_SIGNATURE "EL64"
52
Simon Glass9539e692015-07-31 09:31:36 -060053struct efi_device_path;
54
Rob Clark224ee842017-09-13 18:05:24 -040055typedef struct {
56 u8 b[16];
Heinrich Schuchardtebf3b172018-12-16 11:16:03 +010057} efi_guid_t __attribute__((aligned(8)));
Rob Clark224ee842017-09-13 18:05:24 -040058
Alexander Grafff592b22018-06-22 01:38:26 -070059#define EFI_BITS_PER_LONG (sizeof(long) * 8)
Bin Menge20a69c2016-08-25 01:47:18 -070060
xypron.glpk@gmx.deb343d932017-07-04 23:15:22 +020061/* 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 */
64#define EFI_SUCCESS 0
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)
Simon Glass9539e692015-07-31 09:31:36 -060098
Heinrich Schuchardt91aab822020-01-03 22:47:19 +010099#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
Rob Clark53142032017-09-13 18:05:34 -0400106
Simon Glass9539e692015-07-31 09:31:36 -0600107typedef unsigned long efi_status_t;
108typedef u64 efi_physical_addr_t;
109typedef u64 efi_virtual_addr_t;
Heinrich Schuchardt4f94ec52018-09-26 05:27:54 +0200110typedef struct efi_object *efi_handle_t;
Simon Glass9539e692015-07-31 09:31:36 -0600111
112#define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
Simon Glass9539e692015-07-31 09:31:36 -0600113 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
114 ((a) >> 24) & 0xff, \
115 (b) & 0xff, ((b) >> 8) & 0xff, \
116 (c) & 0xff, ((c) >> 8) & 0xff, \
Heinrich Schuchardtfac78672018-06-09 17:50:18 +0200117 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } }
Simon Glass9539e692015-07-31 09:31:36 -0600118
119/* Generic EFI table header */
120struct efi_table_hdr {
121 u64 signature;
122 u32 revision;
123 u32 headersize;
124 u32 crc32;
125 u32 reserved;
126};
127
Heinrich Schuchardt05824ee2021-08-17 14:52:16 +0200128/* Allocation types for calls to boottime->allocate_pages*/
129/**
130 * enum efi_allocate_type - address restriction for memory allocation
131 */
132enum efi_allocate_type {
133 /**
134 * @EFI_ALLOCATE_ANY_PAGES:
135 * Allocate any block of sufficient size. Ignore memory address.
136 */
137 EFI_ALLOCATE_ANY_PAGES,
138 /**
139 * @EFI_ALLOCATE_MAX_ADDRESS:
140 * Allocate a memory block with an uppermost address less or equal
141 * to the indicated address.
142 */
143 EFI_ALLOCATE_MAX_ADDRESS,
144 /**
145 * @EFI_ALLOCATE_ADDRESS:
146 * Allocate a memory block starting at the indicatged adress.
147 */
148 EFI_ALLOCATE_ADDRESS,
149 /**
150 * @EFI_MAX_ALLOCATE_TYPE:
151 * Value use for range checking.
152 */
153 EFI_MAX_ALLOCATE_TYPE,
154};
155
Simon Glass9539e692015-07-31 09:31:36 -0600156/* Enumeration of memory types introduced in UEFI */
Heinrich Schuchardt96066462021-08-17 15:02:23 +0200157enum efi_memory_type {
Simon Glass9539e692015-07-31 09:31:36 -0600158 EFI_RESERVED_MEMORY_TYPE,
159 /*
160 * The code portions of a loaded application.
161 * (Note that UEFI OS loaders are UEFI applications.)
162 */
163 EFI_LOADER_CODE,
164 /*
165 * The data portions of a loaded application and
166 * the default data allocation type used by an application
167 * to allocate pool memory.
168 */
169 EFI_LOADER_DATA,
170 /* The code portions of a loaded Boot Services Driver */
171 EFI_BOOT_SERVICES_CODE,
172 /*
Heinrich Schuchardt514b91f2017-09-18 07:54:50 +0200173 * The data portions of a loaded Boot Services Driver and
Simon Glass9539e692015-07-31 09:31:36 -0600174 * the default data allocation type used by a Boot Services
175 * Driver to allocate pool memory.
176 */
177 EFI_BOOT_SERVICES_DATA,
178 /* The code portions of a loaded Runtime Services Driver */
179 EFI_RUNTIME_SERVICES_CODE,
180 /*
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.
184 */
185 EFI_RUNTIME_SERVICES_DATA,
186 /* Free (unallocated) memory */
187 EFI_CONVENTIONAL_MEMORY,
188 /* Memory in which errors have been detected */
189 EFI_UNUSABLE_MEMORY,
190 /* Memory that holds the ACPI tables */
191 EFI_ACPI_RECLAIM_MEMORY,
192 /* Address space reserved for use by the firmware */
193 EFI_ACPI_MEMORY_NVS,
194 /*
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.
198 */
199 EFI_MMAP_IO,
200 /*
201 * System memory-mapped IO region that is used to translate
202 * memory cycles to IO cycles by the processor.
203 */
204 EFI_MMAP_IO_PORT,
205 /*
206 * Address space reserved by the firmware for code that is
207 * part of the processor.
208 */
209 EFI_PAL_CODE,
Heinrich Schuchardtf7272332019-04-23 00:30:53 +0200210 /*
Heinrich Schuchardt61e44662021-04-02 22:16:22 +0200211 * Byte addressable non-volatile memory.
Heinrich Schuchardtf7272332019-04-23 00:30:53 +0200212 */
213 EFI_PERSISTENT_MEMORY_TYPE,
Heinrich Schuchardt61e44662021-04-02 22:16:22 +0200214 /*
215 * Unaccepted memory must be accepted by boot target before usage.
216 */
217 EFI_UNACCEPTED_MEMORY_TYPE,
Simon Glass9539e692015-07-31 09:31:36 -0600218
219 EFI_MAX_MEMORY_TYPE,
Simon Glass9539e692015-07-31 09:31:36 -0600220};
221
222/* Attribute values */
Eugeniu Roscac86c0812018-07-14 22:53:30 +0200223#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 */
Eugeniu Rosca4e442332018-07-14 22:53:31 +0200231#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 */
Heinrich Schuchardte76f0e42020-05-19 07:20:46 +0200235#define EFI_MEMORY_SP ((u64)0x0000000000040000ULL) /* specific-purpose memory (SPM) */
Heinrich Schuchardt61e44662021-04-02 22:16:22 +0200236#define EFI_MEMORY_CPU_CRYPTO ((u64)0x0000000000080000ULL) /* cryptographically protectable */
Eugeniu Roscac86c0812018-07-14 22:53:30 +0200237#define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */
238#define EFI_MEM_DESC_VERSION 1
Simon Glass9539e692015-07-31 09:31:36 -0600239
240#define EFI_PAGE_SHIFT 12
Patrick Wildta98bd392019-04-09 22:58:30 +0200241#define EFI_PAGE_SIZE (1ULL << EFI_PAGE_SHIFT)
Alexander Graf3ad57b42016-03-04 01:09:57 +0100242#define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
Simon Glass9539e692015-07-31 09:31:36 -0600243
244struct efi_mem_desc {
245 u32 type;
246 u32 reserved;
247 efi_physical_addr_t physical_start;
248 efi_virtual_addr_t virtual_start;
249 u64 num_pages;
250 u64 attribute;
251};
252
Mian Yousaf Kaukab338cf562016-09-05 23:59:22 +0200253#define EFI_MEMORY_DESCRIPTOR_VERSION 1
254
Simon Glass9539e692015-07-31 09:31:36 -0600255/* 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
259
260struct efi_time {
261 u16 year;
262 u8 month;
263 u8 day;
264 u8 hour;
265 u8 minute;
266 u8 second;
267 u8 pad1;
268 u32 nanosecond;
269 s16 timezone;
270 u8 daylight;
271 u8 pad2;
272};
273
274struct efi_time_cap {
275 u32 resolution;
276 u32 accuracy;
277 u8 sets_to_zero;
278};
279
280enum efi_locate_search_type {
Heinrich Schuchardt68845f02017-11-06 21:17:42 +0100281 ALL_HANDLES,
282 BY_REGISTER_NOTIFY,
283 BY_PROTOCOL
Simon Glass9539e692015-07-31 09:31:36 -0600284};
285
286struct efi_open_protocol_info_entry {
287 efi_handle_t agent_handle;
288 efi_handle_t controller_handle;
289 u32 attributes;
290 u32 open_count;
291};
292
293enum efi_entry_t {
294 EFIET_END, /* Signals this is the last (empty) entry */
295 EFIET_MEMORY_MAP,
Bin Mengcb787cb2018-06-12 08:36:21 -0700296 EFIET_GOP_MODE,
Bin Meng88398512018-08-23 08:24:09 -0700297 EFIET_SYS_TABLE,
Simon Glass9539e692015-07-31 09:31:36 -0600298
299 /* Number of entries */
300 EFIET_MEMORY_COUNT,
301};
302
303#define EFI_TABLE_VERSION 1
304
305/**
306 * struct efi_info_hdr - Header for the EFI info table
307 *
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
312 */
313struct efi_info_hdr {
314 u32 version;
315 u32 hdr_size;
316 u32 total_size;
317 u32 spare[5];
318};
319
320/**
321 * struct efi_entry_hdr - Header for a table entry
322 *
323 * @type: enum eft_entry_t
Heinrich Schuchardtef476882021-12-21 09:09:48 +0100324 * @size: size of entry bytes excluding header and padding
Simon Glass9539e692015-07-31 09:31:36 -0600325 * @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
329 */
330struct efi_entry_hdr {
331 u32 type;
332 u32 size;
333 u64 addr;
334 u32 link;
335 u32 spare1;
336 u64 spare2;
337};
338
339/**
340 * struct efi_entry_memmap - a memory map table passed to U-Boot
341 *
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
346 */
347struct efi_entry_memmap {
348 u32 version;
349 u32 desc_size;
350 u64 spare;
351 struct efi_mem_desc desc[];
352};
353
Bin Mengcb787cb2018-06-12 08:36:21 -0700354/**
355 * struct efi_entry_gopmode - a GOP mode table passed to U-Boot
356 *
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
361 */
362struct efi_entry_gopmode {
363 efi_physical_addr_t fb_base;
364 /*
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).
370 */
371 u64 fb_size;
372 u64 info_size;
373 /*
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'.
377 */
378 struct /* efi_gop_mode_info */ {
379 u32 version;
380 u32 width;
381 u32 height;
382 u32 pixel_format;
383 u32 pixel_bitmask[4];
384 u32 pixels_per_scanline;
385 } info[];
386};
387
Bin Meng88398512018-08-23 08:24:09 -0700388/**
389 * struct efi_entry_systable - system table passed to U-Boot
390 *
391 * @sys_table: EFI system table address
392 */
393struct efi_entry_systable {
394 efi_physical_addr_t sys_table;
395};
396
Simon Glass9539e692015-07-31 09:31:36 -0600397static inline struct efi_mem_desc *efi_get_next_mem_desc(
Simon Glass6f4d7aa2022-01-04 03:51:11 -0700398 struct efi_mem_desc *desc, int desc_size)
Simon Glass9539e692015-07-31 09:31:36 -0600399{
Simon Glass6f4d7aa2022-01-04 03:51:11 -0700400 return (struct efi_mem_desc *)((ulong)desc + desc_size);
Simon Glass9539e692015-07-31 09:31:36 -0600401}
402
Simon Glass26ae0c52021-12-29 11:57:42 -0700403/**
404 * struct efi_priv - Information about the environment provided by EFI
405 *
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
Simon Glass029f48e2022-01-04 03:51:10 -0700410 * @memmap_key: Key returned from get_memory_map()
411 * @memmap_desc: List of memory-map records
412 * @memmap_alloc: Amount of memory allocated for memory map list
413 * @memmap_size Size of memory-map list in bytes
414 * @memmap_desc_size: Size of an individual memory-map record, in bytes
415 * @memmap_version: Memory-map version
Simon Glass26ae0c52021-12-29 11:57:42 -0700416 *
417 * @use_pool_for_malloc: true if all allocation should go through the EFI 'pool'
418 * methods allocate_pool() and free_pool(); false to use 'pages' methods
419 * allocate_pages() and free_pages()
420 * @ram_base: Base address of RAM (size CONFIG_EFI_RAM_SIZE)
421 * @image_data_type: Type of the loaded image (e.g. EFI_LOADER_CODE)
422 *
423 * @info: Header of the info list, holding info collected by the stub and passed
424 * to U-Boot
425 * @info_size: Size of the info list @info in bytes
426 * @next_hdr: Pointer to where to put the next header when adding to the list
427 */
Simon Glass9539e692015-07-31 09:31:36 -0600428struct efi_priv {
429 efi_handle_t parent_image;
Simon Glass9539e692015-07-31 09:31:36 -0600430 struct efi_system_table *sys_table;
431 struct efi_boot_services *boot;
432 struct efi_runtime_services *run;
Simon Glass029f48e2022-01-04 03:51:10 -0700433 efi_uintn_t memmap_key;
434 struct efi_mem_desc *memmap_desc;
435 efi_uintn_t memmap_alloc;
436 efi_uintn_t memmap_size;
437 efi_uintn_t memmap_desc_size;
438 u32 memmap_version;
Simon Glass26ae0c52021-12-29 11:57:42 -0700439
440 /* app: */
Simon Glass9539e692015-07-31 09:31:36 -0600441 bool use_pool_for_malloc;
442 unsigned long ram_base;
443 unsigned int image_data_type;
Simon Glass26ae0c52021-12-29 11:57:42 -0700444
445 /* stub: */
Simon Glass9539e692015-07-31 09:31:36 -0600446 struct efi_info_hdr *info;
447 unsigned int info_size;
448 void *next_hdr;
449};
450
Simon Glassc4688392021-12-04 08:56:32 -0700451/*
452 * EFI attributes of the udevice handled by efi_media driver
453 *
454 * @handle: handle of the controller on which this driver is installed
455 * @blkio: block io protocol proxied by this driver
Simon Glass2d4b33e2021-12-29 11:57:36 -0700456 * @device_path: EFI path to the device
Simon Glassc4688392021-12-04 08:56:32 -0700457 */
458struct efi_media_plat {
Simon Glass2d4b33e2021-12-29 11:57:36 -0700459 efi_handle_t handle;
460 struct efi_block_io *blkio;
461 struct efi_device_path *device_path;
Simon Glassc4688392021-12-04 08:56:32 -0700462};
463
Simon Glass9539e692015-07-31 09:31:36 -0600464/* Base address of the EFI image */
465extern char image_base[];
466
Simon Glass63f581f2015-08-04 12:33:52 -0600467/* Start and end of U-Boot image (for payload) */
Bin Meng7c78bf92016-08-25 01:47:17 -0700468extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
Simon Glass63f581f2015-08-04 12:33:52 -0600469
Rob Clark15f3d742017-09-13 18:05:37 -0400470/*
471 * Variable Attributes
472 */
473#define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
474#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
475#define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
476#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
477#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
478#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
479#define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
480
481#define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
482 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
483 EFI_VARIABLE_RUNTIME_ACCESS | \
484 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
485 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
486 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
487 EFI_VARIABLE_APPEND_WRITE)
488
Simon Glass9539e692015-07-31 09:31:36 -0600489/**
Simon Glassb13771f2021-12-29 11:57:45 -0700490 * efi_get_priv() - Get access to the EFI-private information
491 *
492 * This struct it used by both the stub and the app to record things about the
493 * EFI environment. It is not available in U-Boot proper after the stub has
494 * jumped there. Use efi_info_get() to obtain info in that case.
495 *
496 * Return: pointer to private info
497 */
498struct efi_priv *efi_get_priv(void);
499
500/**
501 * efi_set_priv() - Set up a pointer to the EFI-private information
502 *
503 * This is called in the stub and app to record the location of this
504 * information.
505 *
506 * @priv: New location of private data
507 */
508void efi_set_priv(struct efi_priv *priv);
509
510/**
Simon Glass9539e692015-07-31 09:31:36 -0600511 * efi_get_sys_table() - Get access to the main EFI system table
512 *
Simon Glass50f31422022-01-04 03:51:18 -0700513 * Returns: pointer to EFI system table
Simon Glass9539e692015-07-31 09:31:36 -0600514 */
Simon Glass9539e692015-07-31 09:31:36 -0600515struct efi_system_table *efi_get_sys_table(void);
516
517/**
Simon Glass0a3e7b32021-11-03 21:09:09 -0600518 * efi_get_boot() - Get access to the EFI boot services table
519 *
Simon Glass50f31422022-01-04 03:51:18 -0700520 * Returns: pointer to EFI boot services table
Simon Glass0a3e7b32021-11-03 21:09:09 -0600521 */
522struct efi_boot_services *efi_get_boot(void);
523
524/**
Simon Glass9539e692015-07-31 09:31:36 -0600525 * efi_get_ram_base() - Find the base of RAM
526 *
527 * This is used when U-Boot is built as an EFI application.
528 *
Simon Glass50f31422022-01-04 03:51:18 -0700529 * Returns: the base of RAM as known to U-Boot
Simon Glass9539e692015-07-31 09:31:36 -0600530 */
531unsigned long efi_get_ram_base(void);
532
533/**
534 * efi_init() - Set up ready for use of EFI boot services
535 *
536 * @priv: Pointer to our private EFI structure to fill in
537 * @banner: Banner to display when starting
538 * @image: The image handle passed to efi_main()
539 * @sys_table: The EFI system table pointer passed to efi_main()
Simon Glass50f31422022-01-04 03:51:18 -0700540 * Return: 0 on succcess, EFI error code on failure
Simon Glass9539e692015-07-31 09:31:36 -0600541 */
542int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
543 struct efi_system_table *sys_table);
544
545/**
546 * efi_malloc() - Allocate some memory from EFI
547 *
548 * @priv: Pointer to private EFI structure
549 * @size: Number of bytes to allocate
550 * @retp: Return EFI status result
Simon Glass50f31422022-01-04 03:51:18 -0700551 * Returns: pointer to memory allocated, or NULL on error
Simon Glass9539e692015-07-31 09:31:36 -0600552 */
553void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
554
555/**
556 * efi_free() - Free memory allocated from EFI
557 *
558 * @priv: Pointer to private EFI structure
559 * @ptr: Pointer to memory to free
560 */
561void efi_free(struct efi_priv *priv, void *ptr);
562
563/**
564 * efi_puts() - Write out a string to the EFI console
565 *
566 * @priv: Pointer to private EFI structure
567 * @str: String to write (note this is a ASCII, not unicode)
568 */
569void efi_puts(struct efi_priv *priv, const char *str);
570
571/**
572 * efi_putc() - Write out a character to the EFI console
573 *
574 * @priv: Pointer to private EFI structure
575 * @ch: Character to write (note this is not unicode)
576 */
577void efi_putc(struct efi_priv *priv, const char ch);
578
579/**
580 * efi_info_get() - get an entry from an EFI table
581 *
Simon Glasse5232582021-12-29 11:57:48 -0700582 * This function is called from U-Boot proper to read information set up by the
583 * EFI stub. It can only be used when running from the EFI stub, not when U-Boot
584 * is running as an app.
585 *
Simon Glass9539e692015-07-31 09:31:36 -0600586 * @type: Entry type to search for
587 * @datap: Returns pointer to entry data
Simon Glass50f31422022-01-04 03:51:18 -0700588 * @sizep: Returns entry size
589 * Return: 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
Simon Glass9539e692015-07-31 09:31:36 -0600590 * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
591 */
592int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
593
Simon Glass029f48e2022-01-04 03:51:10 -0700594/**
595 * efi_store_memory_map() - Collect the memory-map info from EFI
596 *
597 * Collect the memory info and store it for later use, e.g. in calling
598 * exit_boot_services()
599 *
600 * @priv: Pointer to private EFI structure
Simon Glass50f31422022-01-04 03:51:18 -0700601 * Returns: 0 if OK, non-zero on error
Simon Glass029f48e2022-01-04 03:51:10 -0700602 */
603int efi_store_memory_map(struct efi_priv *priv);
604
605/**
606 * efi_call_exit_boot_services() - Handle the exit-boot-service procedure
607 *
608 * Tell EFI we don't want their boot services anymore
609 *
610 * Return: 0 if OK, non-zero on error
611 */
612int efi_call_exit_boot_services(void);
613
Simon Glassba042532022-01-04 03:51:12 -0700614/**
615 * efi_get_mmap() - Get the memory map from EFI
616 *
617 * This is used in the app. The caller must free *@descp when done
618 *
619 * @descp: Returns allocated pointer to EFI memory map table
620 * @sizep: Returns size of table in bytes
621 * @keyp: Returns memory-map key
622 * @desc_sizep: Returns size of each @desc_base record
623 * @versionp: Returns version number of memory map
Simon Glass50f31422022-01-04 03:51:18 -0700624 * Returns: 0 on success, -ve on error
Simon Glassba042532022-01-04 03:51:12 -0700625 */
626int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
627 int *desc_sizep, uint *versionp);
628
Simon Glass9539e692015-07-31 09:31:36 -0600629#endif /* _LINUX_EFI_H */