]> git.ipfire.org Git - thirdparty/u-boot.git/blame - include/efi.h
Prepare v2025.07
[thirdparty/u-boot.git] / include / efi.h
CommitLineData
04a0f563 1/* SPDX-License-Identifier: GPL-2.0 */
867a6ac8
SG
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
a0b49bc3 19#include <linux/linkage.h>
867a6ac8
SG
20#include <linux/string.h>
21#include <linux/types.h>
22
85fc2ad4
HS
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
01866446
AG
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__
96a8d409 37#define EFIAPI __attribute__((ms_abi))
beb077a2
AG
38#define efi_va_list __builtin_ms_va_list
39#define efi_va_start __builtin_ms_va_start
05c4c9e2 40#define efi_va_copy __builtin_ms_va_copy
beb077a2
AG
41#define efi_va_arg __builtin_va_arg
42#define efi_va_end __builtin_ms_va_end
96a8d409 43#else
a0b49bc3 44#define EFIAPI asmlinkage
beb077a2
AG
45#define efi_va_list va_list
46#define efi_va_start va_start
05c4c9e2 47#define efi_va_copy va_copy
beb077a2
AG
48#define efi_va_arg va_arg
49#define efi_va_end va_end
01866446 50#endif /* __x86_64__ */
96a8d409 51
1fdeacd3
BM
52#define EFI32_LOADER_SIGNATURE "EL32"
53#define EFI64_LOADER_SIGNATURE "EL64"
54
92b931b8
HS
55/**
56 * struct efi_device_path - device path protocol
57 *
58 * @type: device path type
59 * @sub_type: device path sub-type
60 * @length: length of the device path node including the header
61 */
62struct efi_device_path {
63 u8 type;
64 u8 sub_type;
65 u16 length;
66} __packed;
867a6ac8 67
1dd705cf
MK
68/*
69 * The EFI spec defines the EFI_GUID as
70 * "128-bit buffer containing a unique identifier value. Unless otherwise specified,
71 * aligned on a 64-bit boundary".
72 * Page 163 of the UEFI specification v2.10 and
73 * EDK2 reference implementation both define EFI_GUID as
74 * struct { u32 a; u16; b; u16 c; u8 d[8]; }; which is 4-byte
75 * aligned.
76 */
3cc3bc08 77typedef struct efi_guid {
0d6ab32e 78 u8 b[16];
1dd705cf 79} efi_guid_t __attribute__((aligned(4)));
0d6ab32e 80
0a1bf35f
VS
81static inline int guidcmp(const void *g1, const void *g2)
82{
83 return memcmp(g1, g2, sizeof(efi_guid_t));
84}
85
86static inline void *guidcpy(void *dst, const void *src)
87{
88 return memcpy(dst, src, sizeof(efi_guid_t));
89}
90
01866446 91#define EFI_BITS_PER_LONG (sizeof(long) * 8)
3e6cc35f 92
3c8ffb68
HS
93/* Bit mask for EFI status code with error */
94#define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
95/* Status codes returned by EFI protocols */
96#define EFI_SUCCESS 0
97#define EFI_LOAD_ERROR (EFI_ERROR_MASK | 1)
98#define EFI_INVALID_PARAMETER (EFI_ERROR_MASK | 2)
99#define EFI_UNSUPPORTED (EFI_ERROR_MASK | 3)
100#define EFI_BAD_BUFFER_SIZE (EFI_ERROR_MASK | 4)
101#define EFI_BUFFER_TOO_SMALL (EFI_ERROR_MASK | 5)
102#define EFI_NOT_READY (EFI_ERROR_MASK | 6)
103#define EFI_DEVICE_ERROR (EFI_ERROR_MASK | 7)
104#define EFI_WRITE_PROTECTED (EFI_ERROR_MASK | 8)
105#define EFI_OUT_OF_RESOURCES (EFI_ERROR_MASK | 9)
106#define EFI_VOLUME_CORRUPTED (EFI_ERROR_MASK | 10)
107#define EFI_VOLUME_FULL (EFI_ERROR_MASK | 11)
108#define EFI_NO_MEDIA (EFI_ERROR_MASK | 12)
109#define EFI_MEDIA_CHANGED (EFI_ERROR_MASK | 13)
110#define EFI_NOT_FOUND (EFI_ERROR_MASK | 14)
111#define EFI_ACCESS_DENIED (EFI_ERROR_MASK | 15)
112#define EFI_NO_RESPONSE (EFI_ERROR_MASK | 16)
113#define EFI_NO_MAPPING (EFI_ERROR_MASK | 17)
114#define EFI_TIMEOUT (EFI_ERROR_MASK | 18)
115#define EFI_NOT_STARTED (EFI_ERROR_MASK | 19)
116#define EFI_ALREADY_STARTED (EFI_ERROR_MASK | 20)
117#define EFI_ABORTED (EFI_ERROR_MASK | 21)
118#define EFI_ICMP_ERROR (EFI_ERROR_MASK | 22)
119#define EFI_TFTP_ERROR (EFI_ERROR_MASK | 23)
120#define EFI_PROTOCOL_ERROR (EFI_ERROR_MASK | 24)
121#define EFI_INCOMPATIBLE_VERSION (EFI_ERROR_MASK | 25)
122#define EFI_SECURITY_VIOLATION (EFI_ERROR_MASK | 26)
123#define EFI_CRC_ERROR (EFI_ERROR_MASK | 27)
124#define EFI_END_OF_MEDIA (EFI_ERROR_MASK | 28)
125#define EFI_END_OF_FILE (EFI_ERROR_MASK | 31)
126#define EFI_INVALID_LANGUAGE (EFI_ERROR_MASK | 32)
127#define EFI_COMPROMISED_DATA (EFI_ERROR_MASK | 33)
128#define EFI_IP_ADDRESS_CONFLICT (EFI_ERROR_MASK | 34)
129#define EFI_HTTP_ERROR (EFI_ERROR_MASK | 35)
867a6ac8 130
7b31efc5
HS
131#define EFI_WARN_UNKNOWN_GLYPH 1
132#define EFI_WARN_DELETE_FAILURE 2
133#define EFI_WARN_WRITE_FAILURE 3
134#define EFI_WARN_BUFFER_TOO_SMALL 4
135#define EFI_WARN_STALE_DATA 5
136#define EFI_WARN_FILE_SYSTEM 6
137#define EFI_WARN_RESET_REQUIRED 7
2a92080d 138
867a6ac8
SG
139typedef unsigned long efi_status_t;
140typedef u64 efi_physical_addr_t;
141typedef u64 efi_virtual_addr_t;
faea1041 142typedef struct efi_object *efi_handle_t;
867a6ac8
SG
143
144#define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
867a6ac8
SG
145 {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
146 ((a) >> 24) & 0xff, \
147 (b) & 0xff, ((b) >> 8) & 0xff, \
148 (c) & 0xff, ((c) >> 8) & 0xff, \
44ab2d32 149 (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } }
867a6ac8
SG
150
151/* Generic EFI table header */
152struct efi_table_hdr {
153 u64 signature;
154 u32 revision;
155 u32 headersize;
156 u32 crc32;
157 u32 reserved;
158};
159
3ced5745
HS
160/* Allocation types for calls to boottime->allocate_pages*/
161/**
162 * enum efi_allocate_type - address restriction for memory allocation
163 */
164enum efi_allocate_type {
165 /**
166 * @EFI_ALLOCATE_ANY_PAGES:
167 * Allocate any block of sufficient size. Ignore memory address.
168 */
169 EFI_ALLOCATE_ANY_PAGES,
170 /**
171 * @EFI_ALLOCATE_MAX_ADDRESS:
172 * Allocate a memory block with an uppermost address less or equal
173 * to the indicated address.
174 */
175 EFI_ALLOCATE_MAX_ADDRESS,
176 /**
177 * @EFI_ALLOCATE_ADDRESS:
920e165e 178 * Allocate a memory block starting at the indicated address.
3ced5745
HS
179 */
180 EFI_ALLOCATE_ADDRESS,
181 /**
182 * @EFI_MAX_ALLOCATE_TYPE:
183 * Value use for range checking.
184 */
185 EFI_MAX_ALLOCATE_TYPE,
186};
187
867a6ac8 188/* Enumeration of memory types introduced in UEFI */
c91737b7 189enum efi_memory_type {
867a6ac8
SG
190 EFI_RESERVED_MEMORY_TYPE,
191 /*
192 * The code portions of a loaded application.
193 * (Note that UEFI OS loaders are UEFI applications.)
194 */
195 EFI_LOADER_CODE,
196 /*
197 * The data portions of a loaded application and
198 * the default data allocation type used by an application
199 * to allocate pool memory.
200 */
201 EFI_LOADER_DATA,
202 /* The code portions of a loaded Boot Services Driver */
203 EFI_BOOT_SERVICES_CODE,
204 /*
29f1a367 205 * The data portions of a loaded Boot Services Driver and
867a6ac8
SG
206 * the default data allocation type used by a Boot Services
207 * Driver to allocate pool memory.
208 */
209 EFI_BOOT_SERVICES_DATA,
210 /* The code portions of a loaded Runtime Services Driver */
211 EFI_RUNTIME_SERVICES_CODE,
212 /*
213 * The data portions of a loaded Runtime Services Driver and
214 * the default data allocation type used by a Runtime Services
215 * Driver to allocate pool memory.
216 */
217 EFI_RUNTIME_SERVICES_DATA,
218 /* Free (unallocated) memory */
219 EFI_CONVENTIONAL_MEMORY,
220 /* Memory in which errors have been detected */
221 EFI_UNUSABLE_MEMORY,
222 /* Memory that holds the ACPI tables */
223 EFI_ACPI_RECLAIM_MEMORY,
224 /* Address space reserved for use by the firmware */
225 EFI_ACPI_MEMORY_NVS,
226 /*
227 * Used by system firmware to request that a memory-mapped IO region
228 * be mapped by the OS to a virtual address so it can be accessed by
229 * EFI runtime services.
230 */
231 EFI_MMAP_IO,
232 /*
233 * System memory-mapped IO region that is used to translate
234 * memory cycles to IO cycles by the processor.
235 */
236 EFI_MMAP_IO_PORT,
237 /*
238 * Address space reserved by the firmware for code that is
239 * part of the processor.
240 */
241 EFI_PAL_CODE,
f12bcc91 242 /*
9933eb47 243 * Byte addressable non-volatile memory.
f12bcc91
HS
244 */
245 EFI_PERSISTENT_MEMORY_TYPE,
9933eb47
HS
246 /*
247 * Unaccepted memory must be accepted by boot target before usage.
248 */
249 EFI_UNACCEPTED_MEMORY_TYPE,
867a6ac8
SG
250
251 EFI_MAX_MEMORY_TYPE,
867a6ac8
SG
252};
253
254/* Attribute values */
9b89183b
ER
255#define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */
256#define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */
257#define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */
258#define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */
259#define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */
260#define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */
261#define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */
262#define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */
c3a40cce
ER
263#define EFI_MEMORY_NV ((u64)0x0000000000008000ULL) /* non-volatile */
264#define EFI_MEMORY_MORE_RELIABLE \
265 ((u64)0x0000000000010000ULL) /* higher reliability */
266#define EFI_MEMORY_RO ((u64)0x0000000000020000ULL) /* read-only */
255a4733 267#define EFI_MEMORY_SP ((u64)0x0000000000040000ULL) /* specific-purpose memory (SPM) */
9933eb47 268#define EFI_MEMORY_CPU_CRYPTO ((u64)0x0000000000080000ULL) /* cryptographically protectable */
6a87a5d0
HS
269#define EFI_MEMORY_HOT_PLUGGABLE \
270 ((u64)0x0000000000100000ULL) /* hot pluggable */
9b89183b
ER
271#define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */
272#define EFI_MEM_DESC_VERSION 1
867a6ac8
SG
273
274#define EFI_PAGE_SHIFT 12
60fd8844 275#define EFI_PAGE_SIZE (1ULL << EFI_PAGE_SHIFT)
2bb9b79d 276#define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
867a6ac8
SG
277
278struct efi_mem_desc {
279 u32 type;
280 u32 reserved;
281 efi_physical_addr_t physical_start;
282 efi_virtual_addr_t virtual_start;
283 u64 num_pages;
284 u64 attribute;
285};
286
4c02c11d
MYK
287#define EFI_MEMORY_DESCRIPTOR_VERSION 1
288
867a6ac8
SG
289/* Types and defines for Time Services */
290#define EFI_TIME_ADJUST_DAYLIGHT 0x1
291#define EFI_TIME_IN_DAYLIGHT 0x2
292#define EFI_UNSPECIFIED_TIMEZONE 0x07ff
293
294struct efi_time {
295 u16 year;
296 u8 month;
297 u8 day;
298 u8 hour;
299 u8 minute;
300 u8 second;
301 u8 pad1;
302 u32 nanosecond;
303 s16 timezone;
304 u8 daylight;
305 u8 pad2;
306};
307
308struct efi_time_cap {
309 u32 resolution;
310 u32 accuracy;
311 u8 sets_to_zero;
312};
313
314enum efi_locate_search_type {
9f0770ff
HS
315 ALL_HANDLES,
316 BY_REGISTER_NOTIFY,
317 BY_PROTOCOL
867a6ac8
SG
318};
319
320struct efi_open_protocol_info_entry {
321 efi_handle_t agent_handle;
322 efi_handle_t controller_handle;
323 u32 attributes;
324 u32 open_count;
325};
326
327enum efi_entry_t {
328 EFIET_END, /* Signals this is the last (empty) entry */
329 EFIET_MEMORY_MAP,
d1fe9927 330 EFIET_GOP_MODE,
cbe503fb 331 EFIET_SYS_TABLE,
867a6ac8
SG
332
333 /* Number of entries */
334 EFIET_MEMORY_COUNT,
335};
336
337#define EFI_TABLE_VERSION 1
338
339/**
340 * struct efi_info_hdr - Header for the EFI info table
341 *
342 * @version: EFI_TABLE_VERSION
343 * @hdr_size: Size of this struct in bytes
344 * @total_size: Total size of this header plus following data
345 * @spare: Spare space for expansion
346 */
347struct efi_info_hdr {
348 u32 version;
349 u32 hdr_size;
350 u32 total_size;
351 u32 spare[5];
352};
353
354/**
355 * struct efi_entry_hdr - Header for a table entry
356 *
357 * @type: enum eft_entry_t
40e5b53e 358 * @size: size of entry bytes excluding header and padding
867a6ac8
SG
359 * @addr: address of this entry (0 if it follows the header )
360 * @link: size of entry including header and padding
361 * @spare1: Spare space for expansion
362 * @spare2: Spare space for expansion
363 */
364struct efi_entry_hdr {
365 u32 type;
366 u32 size;
367 u64 addr;
368 u32 link;
369 u32 spare1;
370 u64 spare2;
371};
372
373/**
374 * struct efi_entry_memmap - a memory map table passed to U-Boot
375 *
376 * @version: EFI's memory map table version
377 * @desc_size: EFI's size of each memory descriptor
378 * @spare: Spare space for expansion
379 * @desc: An array of descriptors, each @desc_size bytes apart
380 */
381struct efi_entry_memmap {
382 u32 version;
383 u32 desc_size;
384 u64 spare;
385 struct efi_mem_desc desc[];
386};
387
d1fe9927
BM
388/**
389 * struct efi_entry_gopmode - a GOP mode table passed to U-Boot
390 *
391 * @fb_base: EFI's framebuffer base address
392 * @fb_size: EFI's framebuffer size
393 * @info_size: GOP mode info structure size
394 * @info: Start address of the GOP mode info structure
395 */
396struct efi_entry_gopmode {
397 efi_physical_addr_t fb_base;
398 /*
399 * Not like the ones in 'struct efi_gop_mode' which are 'unsigned
400 * long', @fb_size and @info_size have to be 'u64' here. As the EFI
401 * stub codes may have different bit size from the U-Boot payload,
402 * using 'long' will cause mismatch between the producer (stub) and
403 * the consumer (payload).
404 */
405 u64 fb_size;
406 u64 info_size;
407 /*
408 * We cannot directly use 'struct efi_gop_mode_info info[]' here as
409 * it causes compiler to complain: array type has incomplete element
410 * type 'struct efi_gop_mode_info'.
411 */
412 struct /* efi_gop_mode_info */ {
413 u32 version;
414 u32 width;
415 u32 height;
416 u32 pixel_format;
417 u32 pixel_bitmask[4];
418 u32 pixels_per_scanline;
419 } info[];
420};
421
cbe503fb
BM
422/**
423 * struct efi_entry_systable - system table passed to U-Boot
424 *
425 * @sys_table: EFI system table address
426 */
427struct efi_entry_systable {
428 efi_physical_addr_t sys_table;
429};
430
867a6ac8 431static inline struct efi_mem_desc *efi_get_next_mem_desc(
ce1dc0cc 432 struct efi_mem_desc *desc, int desc_size)
867a6ac8 433{
ce1dc0cc 434 return (struct efi_mem_desc *)((ulong)desc + desc_size);
867a6ac8
SG
435}
436
efd35c7d
SG
437/**
438 * struct efi_priv - Information about the environment provided by EFI
439 *
440 * @parent_image: image passed into the EFI app or stub
441 * @sys_table: Pointer to system table
442 * @boot: Pointer to boot-services table
443 * @run: Pointer to runtime-services table
866e2ac5
SG
444 * @memmap_key: Key returned from get_memory_map()
445 * @memmap_desc: List of memory-map records
446 * @memmap_alloc: Amount of memory allocated for memory map list
447 * @memmap_size Size of memory-map list in bytes
448 * @memmap_desc_size: Size of an individual memory-map record, in bytes
449 * @memmap_version: Memory-map version
efd35c7d
SG
450 *
451 * @use_pool_for_malloc: true if all allocation should go through the EFI 'pool'
452 * methods allocate_pool() and free_pool(); false to use 'pages' methods
453 * allocate_pages() and free_pages()
454 * @ram_base: Base address of RAM (size CONFIG_EFI_RAM_SIZE)
455 * @image_data_type: Type of the loaded image (e.g. EFI_LOADER_CODE)
456 *
457 * @info: Header of the info list, holding info collected by the stub and passed
458 * to U-Boot
459 * @info_size: Size of the info list @info in bytes
460 * @next_hdr: Pointer to where to put the next header when adding to the list
461 */
867a6ac8
SG
462struct efi_priv {
463 efi_handle_t parent_image;
867a6ac8
SG
464 struct efi_system_table *sys_table;
465 struct efi_boot_services *boot;
466 struct efi_runtime_services *run;
866e2ac5
SG
467 efi_uintn_t memmap_key;
468 struct efi_mem_desc *memmap_desc;
469 efi_uintn_t memmap_alloc;
470 efi_uintn_t memmap_size;
471 efi_uintn_t memmap_desc_size;
472 u32 memmap_version;
efd35c7d
SG
473
474 /* app: */
867a6ac8
SG
475 bool use_pool_for_malloc;
476 unsigned long ram_base;
477 unsigned int image_data_type;
efd35c7d
SG
478
479 /* stub: */
867a6ac8
SG
480 struct efi_info_hdr *info;
481 unsigned int info_size;
482 void *next_hdr;
483};
484
d8063dc3
SG
485/*
486 * EFI attributes of the udevice handled by efi_media driver
487 *
488 * @handle: handle of the controller on which this driver is installed
489 * @blkio: block io protocol proxied by this driver
613cd0c4 490 * @device_path: EFI path to the device
d8063dc3
SG
491 */
492struct efi_media_plat {
613cd0c4
SG
493 efi_handle_t handle;
494 struct efi_block_io *blkio;
495 struct efi_device_path *device_path;
d8063dc3
SG
496};
497
867a6ac8
SG
498/* Base address of the EFI image */
499extern char image_base[];
500
476476e7 501/* Start and end of U-Boot image (for payload) */
3dc51ab0 502extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
476476e7 503
ad644e7c
RC
504/*
505 * Variable Attributes
506 */
19327c1f
HS
507#define EFI_VARIABLE_NON_VOLATILE 0x00000001
508#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
509#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004
510#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008
511#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010
512#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
513#define EFI_VARIABLE_APPEND_WRITE 0x00000040
514#define EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS 0x00000080
ad644e7c
RC
515
516#define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
517 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
518 EFI_VARIABLE_RUNTIME_ACCESS | \
519 EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
520 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
521 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
e0fa2cf3
HS
522 EFI_VARIABLE_APPEND_WRITE | \
523 EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS)
ad644e7c 524
2a1cf03e
SG
525/**
526 * efi_get_priv() - Get access to the EFI-private information
527 *
528 * This struct it used by both the stub and the app to record things about the
529 * EFI environment. It is not available in U-Boot proper after the stub has
530 * jumped there. Use efi_info_get() to obtain info in that case.
531 *
532 * Return: pointer to private info
533 */
534struct efi_priv *efi_get_priv(void);
535
536/**
537 * efi_set_priv() - Set up a pointer to the EFI-private information
538 *
539 * This is called in the stub and app to record the location of this
540 * information.
541 *
542 * @priv: New location of private data
543 */
544void efi_set_priv(struct efi_priv *priv);
545
867a6ac8
SG
546/**
547 * efi_get_sys_table() - Get access to the main EFI system table
548 *
6b3873c5 549 * Returns: pointer to EFI system table
867a6ac8
SG
550 */
551struct efi_system_table *efi_get_sys_table(void);
552
f8445737
SG
553/**
554 * efi_get_boot() - Get access to the EFI boot services table
555 *
6b3873c5 556 * Returns: pointer to EFI boot services table
f8445737
SG
557 */
558struct efi_boot_services *efi_get_boot(void);
559
867a6ac8
SG
560/**
561 * efi_get_ram_base() - Find the base of RAM
562 *
563 * This is used when U-Boot is built as an EFI application.
564 *
6b3873c5 565 * Returns: the base of RAM as known to U-Boot
867a6ac8
SG
566 */
567unsigned long efi_get_ram_base(void);
568
569/**
570 * efi_init() - Set up ready for use of EFI boot services
571 *
572 * @priv: Pointer to our private EFI structure to fill in
573 * @banner: Banner to display when starting
574 * @image: The image handle passed to efi_main()
575 * @sys_table: The EFI system table pointer passed to efi_main()
6b3873c5 576 * Return: 0 on succcess, EFI error code on failure
867a6ac8
SG
577 */
578int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
579 struct efi_system_table *sys_table);
580
581/**
582 * efi_malloc() - Allocate some memory from EFI
583 *
584 * @priv: Pointer to private EFI structure
585 * @size: Number of bytes to allocate
586 * @retp: Return EFI status result
6b3873c5 587 * Returns: pointer to memory allocated, or NULL on error
867a6ac8
SG
588 */
589void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
590
591/**
592 * efi_free() - Free memory allocated from EFI
593 *
594 * @priv: Pointer to private EFI structure
595 * @ptr: Pointer to memory to free
596 */
597void efi_free(struct efi_priv *priv, void *ptr);
598
599/**
600 * efi_puts() - Write out a string to the EFI console
601 *
602 * @priv: Pointer to private EFI structure
603 * @str: String to write (note this is a ASCII, not unicode)
604 */
605void efi_puts(struct efi_priv *priv, const char *str);
606
607/**
608 * efi_putc() - Write out a character to the EFI console
609 *
610 * @priv: Pointer to private EFI structure
611 * @ch: Character to write (note this is not unicode)
612 */
613void efi_putc(struct efi_priv *priv, const char ch);
614
615/**
616 * efi_info_get() - get an entry from an EFI table
617 *
cf376037
SG
618 * This function is called from U-Boot proper to read information set up by the
619 * EFI stub. It can only be used when running from the EFI stub, not when U-Boot
620 * is running as an app.
621 *
867a6ac8
SG
622 * @type: Entry type to search for
623 * @datap: Returns pointer to entry data
6b3873c5
SG
624 * @sizep: Returns entry size
625 * Return: 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
867a6ac8
SG
626 * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
627 */
628int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
629
866e2ac5
SG
630/**
631 * efi_store_memory_map() - Collect the memory-map info from EFI
632 *
633 * Collect the memory info and store it for later use, e.g. in calling
634 * exit_boot_services()
635 *
636 * @priv: Pointer to private EFI structure
6b3873c5 637 * Returns: 0 if OK, non-zero on error
866e2ac5
SG
638 */
639int efi_store_memory_map(struct efi_priv *priv);
640
641/**
642 * efi_call_exit_boot_services() - Handle the exit-boot-service procedure
643 *
644 * Tell EFI we don't want their boot services anymore
645 *
646 * Return: 0 if OK, non-zero on error
647 */
648int efi_call_exit_boot_services(void);
649
25a326b0
SG
650/**
651 * efi_get_mmap() - Get the memory map from EFI
652 *
653 * This is used in the app. The caller must free *@descp when done
654 *
655 * @descp: Returns allocated pointer to EFI memory map table
656 * @sizep: Returns size of table in bytes
657 * @keyp: Returns memory-map key
658 * @desc_sizep: Returns size of each @desc_base record
659 * @versionp: Returns version number of memory map
6b3873c5 660 * Returns: 0 on success, -ve on error
25a326b0
SG
661 */
662int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
663 int *desc_sizep, uint *versionp);
664
041840ee
SG
665/**
666 * efi_show_tables() - Show a list of available tables
667 *
668 * Shows the address, GUID (and name where known) for each table
669 *
670 * @systab: System table containing the list of tables
671 */
672void efi_show_tables(struct efi_system_table *systab);
673
9fd623af
SG
674/**
675 * efi_get_basename() - Get the default filename to use when loading
676 *
677 * E.g. this function returns BOOTAA64.EFI for an aarch target
678 *
679 * Return: Default EFI filename
680 */
681const char *efi_get_basename(void);
682
7506c156
SG
683#ifdef CONFIG_SANDBOX
684#include <asm/state.h>
685#endif
686
687static inline bool efi_use_host_arch(void)
688{
689#ifdef CONFIG_SANDBOX
690 struct sandbox_state *state = state_get_current();
691
692 return state->native;
693#else
694 return false;
695#endif
696}
697
8aa8a336
SG
698/**
699 * efi_get_pxe_arch() - Get the architecture value for PXE
700 *
701 * See:
702 * http://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xml
703 *
704 * Return: Architecture value
705 */
706int efi_get_pxe_arch(void);
707
61e0a20a
SG
708/**
709 * fdt_efi_pmem_setup() - Pmem setup in DT and EFI memory map
710 * @fdt: Devicetree to add the pmem nodes to
711 *
712 * Iterate through all the blkmap devices, look for BLKMAP_MEM devices,
713 * and add pmem nodes corresponding to the blkmap slice to the
714 * devicetree along with removing the corresponding region from the
715 * EFI memory map.
716 *
717 * Returns: 0 on success, negative error on failure
718 */
719int fdt_efi_pmem_setup(void *fdt);
720
867a6ac8 721#endif /* _LINUX_EFI_H */