]> git.ipfire.org Git - thirdparty/u-boot.git/blame - include/efi_loader.h
Merge tag 'efi-2025-07-rc6' of https://source.denx.de/u-boot/custodians/u-boot-efi
[thirdparty/u-boot.git] / include / efi_loader.h
CommitLineData
f739fcd8 1/* SPDX-License-Identifier: GPL-2.0+ */
cb149c66
AG
2/*
3 * EFI application loader
4 *
5 * Copyright (c) 2016 Alexander Graf
cb149c66
AG
6 */
7
cd9e18de
HS
8#ifndef _EFI_LOADER_H
9#define _EFI_LOADER_H 1
10
e6f6f9e6 11#include <blk.h>
f4bbd7b9 12#include <efi_device_path.h>
f05911a1 13#include <event.h>
f7ae49fc 14#include <log.h>
cb149c66
AG
15#include <part_efi.h>
16#include <efi_api.h>
d9f3307a 17#include <image.h>
4540dabd 18#include <pe.h>
f2806157 19#include <setjmp.h>
6e3c6544 20#include <linux/list.h>
5a5c5bf4 21#include <linux/sizes.h>
6e3c6544 22#include <linux/oid_registry.h>
bee91169 23
e6f6f9e6 24struct blk_desc;
a2338955 25struct bootflow;
e6f6f9e6 26
9b5e6396 27#if CONFIG_IS_ENABLED(EFI_LOADER)
bee91169 28
6e3c6544
SG
29/**
30 * __efi_runtime_data - declares a non-const variable for EFI runtime section
31 *
32 * This macro indicates that a variable is non-const and should go into the
33 * EFI runtime section, and thus still be available when the OS is running.
34 *
35 * Only use on variables not declared const.
36 *
37 * Example:
38 *
39 * ::
40 *
41 * static __efi_runtime_data my_computed_table[256];
42 */
43#define __efi_runtime_data __section(".data.efi_runtime")
44
45/**
46 * __efi_runtime_rodata - declares a read-only variable for EFI runtime section
47 *
48 * This macro indicates that a variable is read-only (const) and should go into
49 * the EFI runtime section, and thus still be available when the OS is running.
50 *
51 * Only use on variables also declared const.
52 *
53 * Example:
54 *
55 * ::
56 *
57 * static const __efi_runtime_rodata my_const_table[] = { 1, 2, 3 };
58 */
59#define __efi_runtime_rodata __section(".rodata.efi_runtime")
60
61/**
62 * __efi_runtime - declares a function for EFI runtime section
63 *
64 * This macro indicates that a function should go into the EFI runtime section,
65 * and thus still be available when the OS is running.
66 *
67 * Example:
68 *
69 * ::
70 *
71 * static __efi_runtime compute_my_table(void);
72 */
73#define __efi_runtime __section(".text.efi_runtime")
74
75/*
76 * Call this with mmio_ptr as the _pointer_ to a pointer to an MMIO region
77 * to make it available at runtime
78 */
79efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len);
80
81/*
82 * Special case handler for error/abort that just tries to dtrt to get
83 * back to u-boot world
84 */
85void efi_restore_gd(void);
6422820a 86
6e3c6544
SG
87/* Called by networking code to memorize the dhcp ack package */
88void efi_net_set_dhcp_ack(void *pkt, int len);
89/* Print information about all loaded images */
90void efi_print_image_infos(void *pc);
91
92/* Hook at initialization */
93efi_status_t efi_launch_capsules(void);
94
95#else /* CONFIG_IS_ENABLED(EFI_LOADER) */
96
97/* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
98#define __efi_runtime_data
99#define __efi_runtime_rodata
100#define __efi_runtime
101static inline efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len)
102{
103 return EFI_SUCCESS;
104}
105
106/* No loader configured, stub out EFI_ENTRY */
107static inline void efi_restore_gd(void) { }
6e3c6544
SG
108static inline void efi_net_set_dhcp_ack(void *pkt, int len) { }
109static inline void efi_print_image_infos(void *pc) { }
110static inline efi_status_t efi_launch_capsules(void)
111{
112 return EFI_SUCCESS;
113}
114
115#endif /* CONFIG_IS_ENABLED(EFI_LOADER) */
cb149c66 116
6422820a
AT
117#if CONFIG_IS_ENABLED(EFI_BINARY_EXEC)
118/* Call this to unset the current device name */
119void efi_clear_bootdev(void);
120/* Call this to set the current device name */
121void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
122 void *buffer, size_t buffer_size);
123#else
124static inline void efi_clear_bootdev(void) { }
125
126static inline void efi_set_bootdev(const char *dev, const char *devnr,
127 const char *path, void *buffer,
128 size_t buffer_size) { }
129#endif
130
b20f497f 131#if CONFIG_IS_ENABLED(NETDEVICES) && CONFIG_IS_ENABLED(EFI_LOADER)
e55a4acb 132/* Call this to update the current device path of the efi net device */
dd5d82a5 133efi_status_t efi_net_new_dp(const char *dev, const char *server, struct udevice *udev);
e55a4acb 134/* Call this to get the current device path of the efi net device */
dd5d82a5 135void efi_net_dp_from_dev(struct efi_device_path **dp, struct udevice *udev, bool cache_only);
b20f497f
AC
136void efi_net_get_addr(struct efi_ipv4_address *ip,
137 struct efi_ipv4_address *mask,
dd5d82a5
AC
138 struct efi_ipv4_address *gw,
139 struct udevice *dev);
b20f497f
AC
140void efi_net_set_addr(struct efi_ipv4_address *ip,
141 struct efi_ipv4_address *mask,
dd5d82a5
AC
142 struct efi_ipv4_address *gw,
143 struct udevice *dev);
79aec250 144#if IS_ENABLED(CONFIG_EFI_HTTP_PROTOCOL)
5a5c5bf4 145efi_status_t efi_net_do_request(u8 *url, enum efi_http_method method, void **buffer,
79aec250
AC
146 u32 *status_code, ulong *file_size, char *headers_buffer,
147 struct efi_service_binding_protocol *parent);
148#endif
5a5c5bf4
AC
149#define MAX_HTTP_HEADERS_SIZE SZ_64K
150#define MAX_HTTP_HEADERS 100
151#define MAX_HTTP_HEADER_NAME 128
152#define MAX_HTTP_HEADER_VALUE 512
153struct http_header {
154 uchar name[MAX_HTTP_HEADER_NAME];
155 uchar value[MAX_HTTP_HEADER_VALUE];
156};
157
158void efi_net_parse_headers(ulong *num_headers, struct http_header *headers);
b20f497f 159#else
dd5d82a5
AC
160static inline void efi_net_dp_from_dev(struct efi_device_path **dp,
161 struct udevice *udev, bool cache_only) { }
b20f497f
AC
162static inline void efi_net_get_addr(struct efi_ipv4_address *ip,
163 struct efi_ipv4_address *mask,
dd5d82a5
AC
164 struct efi_ipv4_address *gw,
165 struct udevice *dev) { }
b20f497f
AC
166static inline void efi_net_set_addr(struct efi_ipv4_address *ip,
167 struct efi_ipv4_address *mask,
dd5d82a5
AC
168 struct efi_ipv4_address *gw,
169 struct udevice *dev) { }
b20f497f
AC
170#endif
171
4182a129
HS
172/* Maximum number of configuration tables */
173#define EFI_MAX_CONFIGURATION_TABLES 16
174
4e6b5d65
HS
175/* GUID used by the root node */
176#define U_BOOT_GUID \
177 EFI_GUID(0xe61d73b9, 0xa384, 0x4acc, \
178 0xae, 0xab, 0x82, 0xe8, 0x28, 0xf3, 0x62, 0x8b)
272ec6b4
TW
179/* GUID used as root for blkmap devices */
180#define U_BOOT_BLKMAP_DEV_GUID \
181 EFI_GUID(0x4cad859d, 0xd644, 0x42ff, \
182 0x87, 0x0b, 0xc0, 0x2e, 0xac, 0x05, 0x58, 0x63)
23ad52ff
AT
183/* GUID used as host device on sandbox */
184#define U_BOOT_HOST_DEV_GUID \
185 EFI_GUID(0xbbe4e671, 0x5773, 0x4ea1, \
186 0x9a, 0xab, 0x3a, 0x7d, 0xbf, 0x40, 0xc4, 0x82)
19ecced7
HS
187/* GUID used as root for virtio devices */
188#define U_BOOT_VIRTIO_DEV_GUID \
189 EFI_GUID(0x63293792, 0xadf5, 0x9325, \
190 0xb9, 0x9f, 0x4e, 0x0e, 0x45, 0x5c, 0x1b, 0x1e)
4e6b5d65 191
87d79142
MK
192/* GUID for the auto generated boot menu entry */
193#define EFICONFIG_AUTO_GENERATED_ENTRY_GUID \
c1ab0462
MK
194 EFI_GUID(0x8108ac4e, 0x9f11, 0x4d59, \
195 0x85, 0x0e, 0xe2, 0x1a, 0x52, 0x2c, 0x59, 0xb2)
bc3dd249
IA
196#define U_BOOT_EFI_RT_VAR_FILE_GUID \
197 EFI_GUID(0xb2ac5fc9, 0x92b7, 0x4acd, \
198 0xae, 0xac, 0x11, 0xe8, 0x18, 0xc3, 0x13, 0x0c)
199
7a597259 200/* Use internal device tree when starting UEFI application */
f64f2232 201#define EFI_FDT_USE_INTERNAL NULL
7a597259 202
a2a4bc3b
AT
203/* Root node */
204extern efi_handle_t efi_root;
205
15b1bf10
HS
206/* Set to EFI_SUCCESS when initialized */
207extern efi_status_t efi_obj_list_initialized;
208
fccd3d9c
HS
209/* Flag used by the selftest to avoid detaching devices in ExitBootServices() */
210extern bool efi_st_keep_devices;
211
11078bb2
HS
212/* EFI system partition */
213extern struct efi_system_partition {
8149b150 214 enum uclass_id uclass_id;
11078bb2
HS
215 int devnum;
216 u8 part;
217} efi_system_partition;
218
c160d2f5
RC
219int __efi_entry_check(void);
220int __efi_exit_check(void);
ae0bd3a9 221const char *__efi_nesting(void);
af65db85
RC
222const char *__efi_nesting_inc(void);
223const char *__efi_nesting_dec(void);
c160d2f5 224
a095aadf
RC
225/*
226 * Enter the u-boot world from UEFI:
227 */
bee91169 228#define EFI_ENTRY(format, ...) do { \
c160d2f5 229 assert(__efi_entry_check()); \
af65db85
RC
230 debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \
231 __func__, ##__VA_ARGS__); \
bee91169 232 } while(0)
bee91169 233
a095aadf
RC
234/*
235 * Exit the u-boot world back to UEFI:
236 */
804b1d73 237#define EFI_EXIT(ret) ({ \
c81883df 238 typeof(ret) _r = ret; \
af65db85 239 debug("%sEFI: Exit: %s: %u\n", __efi_nesting_dec(), \
c81883df 240 __func__, (u32)((uintptr_t) _r & ~EFI_ERROR_MASK)); \
c160d2f5
RC
241 assert(__efi_exit_check()); \
242 _r; \
804b1d73 243 })
bee91169 244
a095aadf 245/*
ea630ce9 246 * Call non-void UEFI function from u-boot and retrieve return value:
a095aadf 247 */
ea630ce9
HS
248#define EFI_CALL(exp) ({ \
249 debug("%sEFI: Call: %s\n", __efi_nesting_inc(), #exp); \
250 assert(__efi_exit_check()); \
251 typeof(exp) _r = exp; \
252 assert(__efi_entry_check()); \
253 debug("%sEFI: %lu returned by %s\n", __efi_nesting_dec(), \
254 (unsigned long)((uintptr_t)_r & ~EFI_ERROR_MASK), #exp); \
255 _r; \
256})
257
9f00d38c
HS
258/**
259 * define EFI_RETURN() - return from EFI_CALL in efi_start_image()
260 *
261 * @ret: status code
262 */
263#define EFI_RETURN(ret) ({ \
264 typeof(ret) _r = ret; \
265 assert(__efi_entry_check()); \
266 debug("%sEFI: %lu returned by started image", __efi_nesting_dec(), \
267 (unsigned long)((uintptr_t)_r & ~EFI_ERROR_MASK)); \
268})
269
ea630ce9
HS
270/*
271 * Call void UEFI function from u-boot:
272 */
273#define EFI_CALL_VOID(exp) do { \
af65db85 274 debug("%sEFI: Call: %s\n", __efi_nesting_inc(), #exp); \
c160d2f5 275 assert(__efi_exit_check()); \
a095aadf 276 exp; \
c160d2f5 277 assert(__efi_entry_check()); \
af65db85 278 debug("%sEFI: Return From: %s\n", __efi_nesting_dec(), #exp); \
a095aadf
RC
279 } while(0)
280
ae0bd3a9 281/*
d5504144 282 * Write an indented message with EFI prefix
ae0bd3a9 283 */
d5504144
HS
284#define EFI_PRINT(format, ...) ({ \
285 debug("%sEFI: " format, __efi_nesting(), \
286 ##__VA_ARGS__); \
ae0bd3a9
HS
287 })
288
89aea436
AG
289#ifdef CONFIG_SYS_CACHELINE_SIZE
290#define EFI_CACHELINE_SIZE CONFIG_SYS_CACHELINE_SIZE
291#else
292/* Just use the greatest cache flush alignment requirement I'm aware of */
293#define EFI_CACHELINE_SIZE 128
294#endif
295
87d79142
MK
296/* max bootmenu title size for volume selection */
297#define BOOTMENU_DEVICE_NAME_MAX 16
298
1fcb7ea2
HS
299/* Key identifying current memory map */
300extern efi_uintn_t efi_memory_map_key;
301
50149ea3 302extern struct efi_runtime_services efi_runtime_services;
bee91169
AG
303extern struct efi_system_table systab;
304
ebb4dd5b 305extern struct efi_simple_text_output_protocol efi_con_out;
3e603ec7 306extern struct efi_simple_text_input_protocol efi_con_in;
ebb4dd5b 307extern struct efi_console_control_protocol efi_console_control;
cc5b7081 308extern const struct efi_device_path_to_text_protocol efi_device_path_to_text;
e70f8dfa
LL
309/* implementation of the EFI_DEVICE_PATH_UTILITIES_PROTOCOL */
310extern const struct efi_device_path_utilities_protocol
311 efi_device_path_utilities;
b1b782d3 312/* current version of the EFI_UNICODE_COLLATION_PROTOCOL */
0bc4b0da 313extern const struct efi_unicode_collation_protocol
95ab3816 314 efi_unicode_collation_protocol2;
cb728e51
AT
315extern const struct efi_hii_config_routing_protocol efi_hii_config_routing;
316extern const struct efi_hii_config_access_protocol efi_hii_config_access;
c9bfb222
LL
317extern const struct efi_hii_database_protocol efi_hii_database;
318extern const struct efi_hii_string_protocol efi_hii_string;
c1311ad4 319
adae4313
RC
320uint16_t *efi_dp_str(struct efi_device_path *dp);
321
87d79142
MK
322/* GUID for the auto generated boot menu entry */
323extern const efi_guid_t efi_guid_bootmenu_auto_generated;
324
4e6b5d65
HS
325/* GUID of the U-Boot root node */
326extern const efi_guid_t efi_u_boot_guid;
23ad52ff
AT
327#ifdef CONFIG_SANDBOX
328/* GUID of U-Boot host device on sandbox */
329extern const efi_guid_t efi_guid_host_dev;
330#endif
b3dd14b6
HS
331/* GUID of the EFI_BLOCK_IO_PROTOCOL */
332extern const efi_guid_t efi_block_io_guid;
74829b4d
AC
333/* GUID of the EFI_SIMPLE_NETWORK_PROTOCOL */
334extern const efi_guid_t efi_net_guid;
9975fe96 335extern const efi_guid_t efi_global_variable_guid;
c1311ad4 336extern const efi_guid_t efi_guid_console_control;
cb149c66 337extern const efi_guid_t efi_guid_device_path;
90dcd9b2
HS
338/* GUID of the EFI system partition */
339extern const efi_guid_t efi_system_partition_guid;
f0959dbe
HS
340/* GUID of the EFI_DRIVER_BINDING_PROTOCOL */
341extern const efi_guid_t efi_guid_driver_binding_protocol;
a3a28f5f
HS
342/* event group ExitBootServices() invoked */
343extern const efi_guid_t efi_guid_event_group_exit_boot_services;
344/* event group SetVirtualAddressMap() invoked */
345extern const efi_guid_t efi_guid_event_group_virtual_address_change;
346/* event group memory map changed */
347extern const efi_guid_t efi_guid_event_group_memory_map_change;
348/* event group boot manager about to boot */
349extern const efi_guid_t efi_guid_event_group_ready_to_boot;
350/* event group ResetSystem() invoked (before ExitBootServices) */
351extern const efi_guid_t efi_guid_event_group_reset_system;
e0d1a1ea
MK
352/* event group return to efibootmgr */
353extern const efi_guid_t efi_guid_event_group_return_to_efibootmgr;
bc4f9133
HS
354/* GUID of the device tree table */
355extern const efi_guid_t efi_guid_fdt;
cb149c66 356extern const efi_guid_t efi_guid_loaded_image;
bc8fc328 357extern const efi_guid_t efi_guid_loaded_image_device_path;
cc5b7081 358extern const efi_guid_t efi_guid_device_path_to_text_protocol;
2a92080d
RC
359extern const efi_guid_t efi_simple_file_system_protocol_guid;
360extern const efi_guid_t efi_file_info_guid;
9e6835e6
HS
361/* GUID for file system information */
362extern const efi_guid_t efi_file_system_info_guid;
e70f8dfa 363extern const efi_guid_t efi_guid_device_path_utilities_protocol;
b1b782d3
HS
364/* GUID of the deprecated Unicode collation protocol */
365extern const efi_guid_t efi_guid_unicode_collation_protocol;
b6f11098
HS
366/* GUIDs of the Load File and Load File2 protocol */
367extern const efi_guid_t efi_guid_load_file_protocol;
368extern const efi_guid_t efi_guid_load_file2_protocol;
0bc4b0da 369/* GUID of the Unicode collation protocol */
95ab3816 370extern const efi_guid_t efi_guid_unicode_collation_protocol2;
cb728e51
AT
371extern const efi_guid_t efi_guid_hii_config_routing_protocol;
372extern const efi_guid_t efi_guid_hii_config_access_protocol;
c9bfb222
LL
373extern const efi_guid_t efi_guid_hii_database_protocol;
374extern const efi_guid_t efi_guid_hii_string_protocol;
593e17d6
AT
375/* GUIDs for authentication */
376extern const efi_guid_t efi_guid_image_security_database;
377extern const efi_guid_t efi_guid_sha256;
378extern const efi_guid_t efi_guid_cert_x509;
379extern const efi_guid_t efi_guid_cert_x509_sha256;
b436cc6a
IA
380extern const efi_guid_t efi_guid_cert_x509_sha384;
381extern const efi_guid_t efi_guid_cert_x509_sha512;
767f6eeb 382extern const efi_guid_t efi_guid_cert_type_pkcs7;
cb149c66 383
33c37d97
SG
384/* GUID of RNG protocol */
385extern const efi_guid_t efi_guid_rng_protocol;
2bc27ca8
AT
386/* GUID of capsule update result */
387extern const efi_guid_t efi_guid_capsule_report;
8d99026f
AT
388/* GUID of firmware management protocol */
389extern const efi_guid_t efi_guid_firmware_management_protocol;
64a8aae1
JM
390/* GUID for the ESRT */
391extern const efi_guid_t efi_esrt_guid;
3d49ee85
MK
392/* GUID of the SMBIOS table */
393extern const efi_guid_t smbios_guid;
2497f6a8 394extern const efi_guid_t smbios3_guid;
87d79142
MK
395/*GUID of console */
396extern const efi_guid_t efi_guid_text_input_protocol;
8dbd0a0f 397extern const efi_guid_t efi_guid_text_output_protocol;
33c37d97 398
1f1075c6
HS
399/**
400 * struct efi_open_protocol_info_item - open protocol info item
401 *
fe1599da
HS
402 * When a protocol is opened a open protocol info entry is created.
403 * These are maintained in a list.
1f1075c6
HS
404 *
405 * @link: link to the list of open protocol info entries of a protocol
406 * @info: information about the opening of a protocol
fe1599da
HS
407 */
408struct efi_open_protocol_info_item {
fe1599da
HS
409 struct list_head link;
410 struct efi_open_protocol_info_entry info;
411};
412
1f1075c6
HS
413/**
414 * struct efi_handler - single protocol interface of a handle
415 *
bee91169
AG
416 * When the UEFI payload wants to open a protocol on an object to get its
417 * interface (usually a struct with callback functions), this struct maps the
fe1599da 418 * protocol GUID to the respective protocol interface
1f1075c6
HS
419 *
420 * @link: link to the list of protocols of a handle
421 * @guid: GUID of the protocol
422 * @protocol_interface: protocol interface
c6f077a2 423 * @open_infos: link to the list of open protocol info items
fe1599da 424 */
bee91169 425struct efi_handler {
69fb6b1a 426 struct list_head link;
66028930 427 const efi_guid_t guid;
b5349f74 428 void *protocol_interface;
fe1599da 429 struct list_head open_infos;
bee91169
AG
430};
431
cd73aba6
HS
432/**
433 * enum efi_object_type - type of EFI object
434 *
435 * In UnloadImage we must be able to identify if the handle relates to a
436 * started image.
437 */
438enum efi_object_type {
c6f077a2 439 /** @EFI_OBJECT_TYPE_UNDEFINED: undefined image type */
cd73aba6 440 EFI_OBJECT_TYPE_UNDEFINED = 0,
c6f077a2 441 /** @EFI_OBJECT_TYPE_U_BOOT_FIRMWARE: U-Boot firmware */
84a918e8 442 EFI_OBJECT_TYPE_U_BOOT_FIRMWARE,
c6f077a2 443 /** @EFI_OBJECT_TYPE_LOADED_IMAGE: loaded image (not started) */
cd73aba6 444 EFI_OBJECT_TYPE_LOADED_IMAGE,
c6f077a2 445 /** @EFI_OBJECT_TYPE_STARTED_IMAGE: started image */
cd73aba6
HS
446 EFI_OBJECT_TYPE_STARTED_IMAGE,
447};
448
fae0118e
HS
449/**
450 * struct efi_object - dereferenced EFI handle
451 *
452 * @link: pointers to put the handle into a linked list
453 * @protocols: linked list with the protocol interfaces installed on this
454 * handle
c6f077a2 455 * @type: image type if the handle relates to an image
ee576662 456 * @dev: pointer to the DM device which is associated with this EFI handle
fae0118e
HS
457 *
458 * UEFI offers a flexible and expandable object model. The objects in the UEFI
459 * API are devices, drivers, and loaded images. struct efi_object is our storage
460 * structure for these objects.
461 *
462 * When including this structure into a larger structure always put it first so
463 * that when deleting a handle the whole encompassing structure can be freed.
bee91169 464 *
fae0118e
HS
465 * A pointer to this structure is referred to as a handle. Typedef efi_handle_t
466 * has been created for such pointers.
bee91169
AG
467 */
468struct efi_object {
469 /* Every UEFI object is part of a global object list */
470 struct list_head link;
69fb6b1a
HS
471 /* The list of protocols */
472 struct list_head protocols;
cd73aba6 473 enum efi_object_type type;
ee576662 474 struct udevice *dev;
bee91169
AG
475};
476
4540dabd
AT
477enum efi_image_auth_status {
478 EFI_IMAGE_AUTH_FAILED = 0,
479 EFI_IMAGE_AUTH_PASSED,
480};
481
c982874e
HS
482/**
483 * struct efi_loaded_image_obj - handle of a loaded image
d39646a3
HS
484 *
485 * @header: EFI object header
556d8dc9
HS
486 * @exit_status: exit status passed to Exit()
487 * @exit_data_size: exit data size passed to Exit()
488 * @exit_data: exit data passed to Exit()
0ce3fb55 489 * @exit_jmp: long jump buffer for returning from started image
d39646a3 490 * @entry: entry address of the relocated image
0ce3fb55
HS
491 * @image_type: indicates if the image is an applicition or a driver
492 * @auth_status: indicates if the image is authenticated
c982874e
HS
493 */
494struct efi_loaded_image_obj {
d39646a3 495 struct efi_object header;
f8212f09 496 efi_status_t *exit_status;
556d8dc9
HS
497 efi_uintn_t *exit_data_size;
498 u16 **exit_data;
f2806157 499 jmp_buf *exit_jmp;
c982874e
HS
500 EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,
501 struct efi_system_table *st);
126a43f1 502 u16 image_type;
4540dabd 503 enum efi_image_auth_status auth_status;
c982874e
HS
504};
505
c6841592
HS
506/**
507 * struct efi_event
508 *
43bce442 509 * @link: Link to list of all events
7a69e97b 510 * @queue_link: Link to the list of queued events
c6841592
HS
511 * @type: Type of event, see efi_create_event
512 * @notify_tpl: Task priority level of notifications
c6f077a2 513 * @notify_function: Function to call when the event is triggered
c6841592 514 * @notify_context: Data to be passed to the notify function
b095f3c8 515 * @group: Event group
43bce442
HS
516 * @trigger_time: Period of the timer
517 * @trigger_next: Next time to trigger the timer
c6841592 518 * @trigger_type: Type of timer, see efi_set_timer
43bce442 519 * @is_signaled: The event occurred. The event is in the signaled state.
c6841592
HS
520 */
521struct efi_event {
43bce442 522 struct list_head link;
7a69e97b 523 struct list_head queue_link;
b521d29e 524 uint32_t type;
152cade3 525 efi_uintn_t notify_tpl;
c6841592
HS
526 void (EFIAPI *notify_function)(struct efi_event *event, void *context);
527 void *notify_context;
b095f3c8 528 const efi_guid_t *group;
c6841592
HS
529 u64 trigger_next;
530 u64 trigger_time;
b521d29e 531 enum efi_timer_delay trigger_type;
e190e897 532 bool is_signaled;
c6841592
HS
533};
534
bee91169
AG
535/* This list contains all UEFI objects we know of */
536extern struct list_head efi_obj_list;
b095f3c8
HS
537/* List of all events */
538extern struct list_head efi_events;
bee91169 539
f09cea36
HS
540/**
541 * struct efi_protocol_notification - handle for notified protocol
542 *
543 * When a protocol interface is installed for which an event was registered with
544 * the RegisterProtocolNotify() service this structure is used to hold the
545 * handle on which the protocol interface was installed.
546 *
547 * @link: link to list of all handles notified for this event
548 * @handle: handle on which the notified protocol interface was installed
549 */
550struct efi_protocol_notification {
551 struct list_head link;
552 efi_handle_t handle;
553};
554
ab15d414 555/**
c6f077a2
HS
556 * struct efi_register_notify_event - event registered by
557 * RegisterProtocolNotify()
ab15d414
HS
558 *
559 * The address of this structure serves as registration value.
560 *
f09cea36
HS
561 * @link: link to list of all registered events
562 * @event: registered event. The same event may registered for multiple
563 * GUIDs.
564 * @protocol: protocol for which the event is registered
565 * @handles: linked list of all handles on which the notified protocol was
566 * installed
ab15d414
HS
567 */
568struct efi_register_notify_event {
569 struct list_head link;
570 struct efi_event *event;
571 efi_guid_t protocol;
f09cea36 572 struct list_head handles;
ab15d414
HS
573};
574
a57ad20d
AT
575/* called at pre-initialization */
576int efi_init_early(void);
056b45bc
AT
577/* Initialize efi execution environment */
578efi_status_t efi_init_obj_list(void);
339b527b
RM
579/* Append new boot option in BootOrder variable */
580efi_status_t efi_bootmgr_append_bootorder(u16 index);
581/* Get unused "Boot####" index */
582efi_status_t efi_bootmgr_get_unused_bootoption(u16 *buf,
583 efi_uintn_t buf_size, u32 *index);
584/* Generate the media device boot option */
585efi_status_t efi_bootmgr_update_media_device_boot_option(void);
586/* Delete selected boot option */
587efi_status_t efi_bootmgr_delete_boot_option(u16 boot_index);
0bef4b01
AT
588/* Invoke EFI boot manager */
589efi_status_t efi_bootmgr_run(void *fdt);
339b527b
RM
590/* search the boot option index in BootOrder */
591bool efi_search_bootorder(u16 *bootorder, efi_uintn_t num, u32 target, u32 *index);
4cb72436
SG
592
593/**
594 * efi_setup_console_size() - update the mode table.
595 *
596 * By default the only mode available is 80x25. If the console has at least 50
597 * lines, enable mode 80x50. If we can query the console size and it is neither
598 * 80x25 nor 80x50, set it as an additional mode.
599 */
68edbed4 600void efi_setup_console_size(void);
4cb72436
SG
601
602/**
603 * efi_console_set_ansi() - Set whether ANSI escape-characters should be emitted
604 *
605 * These characters mess up tests which use ut_assert_nextline(). Call this
606 * function to tell efi_loader not to emit these characters when starting up the
607 * terminal
608 *
609 * @allow_ansi: Allow emitting ANSI escape-characters
610 */
611void efi_console_set_ansi(bool allow_ansi);
612
0bef4b01
AT
613/* Set up load options from environment variable */
614efi_status_t efi_env_set_load_options(efi_handle_t handle, const char *env_var,
615 u16 **load_options);
fa077218
HS
616/* Get EFI configuration table */
617void *efi_get_configuration_table(const efi_guid_t *guid);
f64f2232
HS
618/* Install device tree */
619efi_status_t efi_install_fdt(void *fdt);
24600fd0
AC
620/* Install initrd */
621efi_status_t efi_install_initrd(void *initrd, size_t initd_sz);
6422820a
AT
622/* Execute loaded UEFI image */
623efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options);
0bef4b01 624/* Run loaded UEFI image with given fdt */
36835a91 625efi_status_t efi_binary_run(void *image, size_t size, void *fdt, void *initrd, size_t initrd_sz);
a2338955
SG
626
627/**
628 * efi_bootflow_run() - Run a bootflow containing an EFI application
629 *
630 * @bootflow: Bootflow to run
631 * Return: Status code, something went wrong
632 */
633efi_status_t efi_bootflow_run(struct bootflow *bootflow);
634
88192098
HS
635/* Initialize variable services */
636efi_status_t efi_init_variables(void);
29018abb
HS
637/* Notify ExitBootServices() is called */
638void efi_variables_boot_exit_notify(void);
fdff03e5 639efi_status_t efi_tcg2_notify_exit_boot_services_failed(void);
8fc4e0b4 640/* Measure efi application invocation */
ce3dbc5d 641efi_status_t efi_tcg2_measure_efi_app_invocation(struct efi_loaded_image_obj *handle);
8fc4e0b4
MK
642/* Measure efi application exit */
643efi_status_t efi_tcg2_measure_efi_app_exit(void);
aa2d3945
EC
644/* Measure DTB */
645efi_status_t efi_tcg2_measure_dtb(void *dtb);
4e6b5d65
HS
646/* Called by bootefi to initialize root node */
647efi_status_t efi_root_node_register(void);
640adadf
HS
648/* Called by bootefi to initialize runtime */
649efi_status_t efi_initialize_system_table(void);
7f95104d
HS
650/* efi_runtime_detach() - detach unimplemented runtime functions */
651void efi_runtime_detach(void);
a44d2a23
HS
652/* efi_convert_pointer() - convert pointer to virtual address */
653efi_status_t EFIAPI efi_convert_pointer(efi_uintn_t debug_disposition,
654 void **address);
94686f60
HS
655/* Carve out DT reserved memory ranges */
656void efi_carve_out_dt_rsv(void *fdt);
a2f1482f 657/* Purge unused kaslr-seed */
b03b2a45 658void efi_try_purge_rng_seed(void *fdt);
91be9a77 659/* Called by bootefi to make console interface available */
6f566c23 660efi_status_t efi_console_register(void);
d5391bf0
HS
661/* Called by efi_init_obj_list() to proble all block devices */
662efi_status_t efi_disks_register(void);
b59c13d4
HS
663/* Called by efi_init_obj_list() to install EFI_RNG_PROTOCOL */
664efi_status_t efi_rng_register(void);
c1c02105
IA
665/* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */
666efi_status_t efi_tcg2_register(void);
1ccf8716
S
667/* Called by efi_init_obj_list() to install RISCV_EFI_BOOT_PROTOCOL */
668efi_status_t efi_riscv_register(void);
54bec17f
MK
669/* Called by efi_init_obj_list() to do initial measurement */
670efi_status_t efi_tcg2_do_initial_measurement(void);
163a0d7e
MK
671/* measure the pe-coff image, extend PCR and add Event Log */
672efi_status_t tcg2_measure_pe_image(void *efi, u64 efi_size,
673 struct efi_loaded_image_obj *handle,
674 struct efi_loaded_image *loaded_image_info);
64e4db0f
HS
675/* Create handles and protocols for the partitions of a block device */
676int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
8149b150 677 const char *uclass_idname, int diskid,
64e4db0f 678 const char *pdevname);
be8d3241 679/* Called by bootefi to make GOP (graphical) interface available */
80ea9b09 680efi_status_t efi_gop_register(void);
0efe1bcf 681/* Called by bootefi to make the network interface available */
dd5d82a5
AC
682efi_status_t efi_net_register(struct udevice *dev);
683efi_status_t efi_net_do_start(struct udevice *dev);
929363cb
AC
684/* Called by efi_net_register to make the ip4 config2 protocol available */
685efi_status_t efi_ipconfig_register(const efi_handle_t handle,
686 struct efi_ip4_config2_protocol *ip4config);
238e0269
AC
687/* Called by efi_net_register to make the http protocol available */
688efi_status_t efi_http_register(const efi_handle_t handle,
689 struct efi_service_binding_protocol *http_service_binding);
b3d60900 690/* Called by bootefi to make the watchdog available */
d7b181d5 691efi_status_t efi_watchdog_register(void);
73c9a352 692efi_status_t efi_initrd_register(struct efi_device_path *dp_initrd);
70089c13 693efi_status_t efi_initrd_deregister(void);
e663b350 694/* Called by bootefi to make SMBIOS tables available */
86df34d4
BM
695/**
696 * efi_acpi_register() - write out ACPI tables
697 *
698 * Called by bootefi to make ACPI tables available
699 *
185f812c 700 * Return: 0 if OK, -ENOMEM if no memory is available for the tables
86df34d4
BM
701 */
702efi_status_t efi_acpi_register(void);
0864c565
SG
703/**
704 * efi_smbios_register() - write out SMBIOS tables
705 *
706 * Called by bootefi to make SMBIOS tables available
707 *
185f812c 708 * Return: 0 if OK, -ENOMEM if no memory is available for the tables
0864c565 709 */
7657152b 710efi_status_t efi_smbios_register(void);
0efe1bcf 711
2a92080d
RC
712struct efi_simple_file_system_protocol *
713efi_fs_from_path(struct efi_device_path *fp);
714
b3d60900
HS
715/* Called by efi_set_watchdog_timer to reset the timer */
716efi_status_t efi_set_watchdog(unsigned long timeout);
0efe1bcf 717
bee91169
AG
718/* Called from places to check whether a timer expired */
719void efi_timer_check(void);
5dad05a0
HS
720/* Check if a buffer contains a PE-COFF image */
721efi_status_t efi_check_pe(void *buffer, size_t size, void **nt_header);
bee91169 722/* PE loader implementation */
4540dabd
AT
723efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
724 void *efi, size_t efi_size,
8f7e2b29 725 struct efi_loaded_image *loaded_image_info);
bee91169
AG
726/* Called once to store the pristine gd pointer */
727void efi_save_gd(void);
50149ea3
AG
728/* Call this to relocate the runtime section to an address space */
729void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map);
bfef72e4
RMS
730/* Call this to get image parameters */
731void efi_get_image_parameters(void **img_addr, size_t *img_size);
44549d62 732/* Add a new object to the object list. */
fae0118e 733void efi_add_handle(efi_handle_t obj);
2edab5e2 734/* Create handle */
2074f700 735efi_status_t efi_create_handle(efi_handle_t *handle);
678e03a0 736/* Delete handle */
54edc37a 737efi_status_t efi_delete_handle(efi_handle_t obj);
1b68153a 738/* Call this to validate a handle and find the EFI object for it */
2074f700 739struct efi_object *efi_search_obj(const efi_handle_t handle);
d8465ffc
AT
740/* Locate device_path handle */
741efi_status_t EFIAPI efi_locate_device_path(const efi_guid_t *protocol,
742 struct efi_device_path **device_path,
743 efi_handle_t *device);
d7e0b010
AT
744/* Load image */
745efi_status_t EFIAPI efi_load_image(bool boot_policy,
746 efi_handle_t parent_image,
747 struct efi_device_path *file_path,
748 void *source_buffer,
749 efi_uintn_t source_size,
750 efi_handle_t *image_handle);
8deb5d85
HS
751/* Load image from path */
752efi_status_t efi_load_image_from_path(bool boot_policy,
753 struct efi_device_path *file_path,
754 void **buffer, efi_uintn_t *size);
f69d63fa
HS
755/* Start image */
756efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
757 efi_uintn_t *exit_data_size,
758 u16 **exit_data);
d7e0b010
AT
759/* Unload image */
760efi_status_t EFIAPI efi_unload_image(efi_handle_t image_handle);
3f79a2b5 761/* Find a protocol on a handle */
2074f700 762efi_status_t efi_search_protocol(const efi_handle_t handle,
3f79a2b5
HS
763 const efi_guid_t *protocol_guid,
764 struct efi_handler **handler);
765/* Install new protocol on a handle */
2074f700
HS
766efi_status_t efi_add_protocol(const efi_handle_t handle,
767 const efi_guid_t *protocol,
3f79a2b5 768 void *protocol_interface);
74829b4d
AC
769/* Uninstall new protocol on a handle */
770efi_status_t efi_uninstall_protocol
771 (efi_handle_t handle, const efi_guid_t *protocol,
772 void *protocol_interface, bool preserve);
c3cf134a
AC
773/* Reinstall a protocol on a handle */
774efi_status_t EFIAPI efi_reinstall_protocol_interface(
775 efi_handle_t handle,
776 const efi_guid_t *protocol,
777 void *old_interface, void *new_interface);
f9ad240e
HS
778/* Open protocol */
779efi_status_t efi_protocol_open(struct efi_handler *handler,
780 void **protocol_interface, void *agent_handle,
781 void *controller_handle, uint32_t attributes);
782
7657ae12 783/* Install multiple protocol interfaces */
05c4c9e2
IA
784efi_status_t EFIAPI
785efi_install_multiple_protocol_interfaces(efi_handle_t *handle, ...);
786efi_status_t EFIAPI
787efi_uninstall_multiple_protocol_interfaces(efi_handle_t handle, ...);
74829b4d
AC
788/* Connect and disconnect controller */
789efi_status_t EFIAPI efi_connect_controller(efi_handle_t controller_handle,
790 efi_handle_t *driver_image_handle,
791 struct efi_device_path *remain_device_path,
792 bool recursive);
793efi_status_t EFIAPI efi_disconnect_controller(
794 efi_handle_t controller_handle,
795 efi_handle_t driver_image_handle,
796 efi_handle_t child_handle);
b51ec639
AT
797/* Get handles that support a given protocol */
798efi_status_t EFIAPI efi_locate_handle_buffer(
799 enum efi_locate_search_type search_type,
800 const efi_guid_t *protocol, void *search_key,
801 efi_uintn_t *no_handles, efi_handle_t **buffer);
ef185764
HS
802/* Close a previously opened protocol interface */
803efi_status_t efi_close_protocol(efi_handle_t handle, const efi_guid_t *protocol,
804 efi_handle_t agent_handle,
805 efi_handle_t controller_handle);
b51ec639
AT
806/* Open a protocol interface */
807efi_status_t EFIAPI efi_handle_protocol(efi_handle_t handle,
808 const efi_guid_t *protocol,
809 void **protocol_interface);
49deb455 810/* Call this to create an event */
152cade3 811efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl,
49deb455
HS
812 void (EFIAPI *notify_function) (
813 struct efi_event *event,
814 void *context),
e23c8e81 815 void *notify_context, const efi_guid_t *group,
b095f3c8 816 struct efi_event **event);
74829b4d
AC
817/* Call this to close an event */
818efi_status_t EFIAPI efi_close_event(struct efi_event *event);
bfc72462 819/* Call this to set a timer */
b521d29e 820efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
bfc72462 821 uint64_t trigger_time);
91be9a77 822/* Call this to signal an event */
7eaa900e 823void efi_signal_event(struct efi_event *event);
50149ea3 824
05f391e2
AT
825/* return true if the device is removable */
826bool efi_disk_is_removable(efi_handle_t handle);
827
cff77001
HS
828/**
829 * efi_create_simple_file_system() - create simple file system protocol
830 *
831 * Create a simple file system protocol for a partition.
832 *
833 * @desc: block device descriptor
834 * @part: partition number
835 * @dp: device path
836 * @fsp: simple file system protocol
837 * Return: status code
838 */
839efi_status_t
840efi_create_simple_file_system(struct blk_desc *desc, int part,
841 struct efi_device_path *dp,
842 struct efi_simple_file_system_protocol **fsp);
2a92080d
RC
843
844/* open file from device-path: */
845struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);
846
64a8aae1
JM
847/* Registers a callback function for a notification event. */
848efi_status_t EFIAPI efi_register_protocol_notify(const efi_guid_t *protocol,
849 struct efi_event *event,
850 void **registration);
37c3ca5c
IA
851efi_status_t efi_file_size(struct efi_file_handle *fh, efi_uintn_t *size);
852
853/* get a device path from a Boot#### option */
8745f13f 854struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t *guid);
37c3ca5c 855
b436cc6a
IA
856/* get len, string (used in u-boot crypto from a guid */
857const char *guid_to_sha_str(const efi_guid_t *guid);
858int algo_to_len(const char *algo);
859
ee576662 860int efi_link_dev(efi_handle_t handle, struct udevice *dev);
16b27b67 861int efi_unlink_dev(efi_handle_t handle);
3ac026ae 862bool efi_varname_is_load_option(u16 *var_name16, int *index);
ce327084
MK
863efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf,
864 efi_guid_t *guid);
ee576662 865
c3772ca1
HS
866/**
867 * efi_size_in_pages() - convert size in bytes to size in pages
868 *
869 * This macro returns the number of EFI memory pages required to hold 'size'
870 * bytes.
871 *
872 * @size: size in bytes
873 * Return: size in pages
874 */
0a7e5165 875#define efi_size_in_pages(size) (((size) + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT)
f606fab8
HS
876/* Allocate boot service data pool memory */
877void *efi_alloc(size_t len);
ebdea88d
IA
878/* Allocate pages on the specified alignment */
879void *efi_alloc_aligned_pages(u64 len, int memory_type, size_t align);
5d00995c 880/* More specific EFI memory allocator, called by EFI payloads */
49d225e7
HS
881efi_status_t efi_allocate_pages(enum efi_allocate_type type,
882 enum efi_memory_type memory_type,
883 efi_uintn_t pages, uint64_t *memory);
b61d857b 884/* EFI memory free function. */
f5a2a938 885efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages);
ead1274b 886/* EFI memory allocator for small allocations */
49d225e7
HS
887efi_status_t efi_allocate_pool(enum efi_memory_type pool_type,
888 efi_uintn_t size, void **buffer);
42417bc8
SB
889/* EFI pool memory free function. */
890efi_status_t efi_free_pool(void *buffer);
eff44401
HS
891/* Allocate and retrieve EFI memory map */
892efi_status_t efi_get_memory_map_alloc(efi_uintn_t *map_size,
893 struct efi_mem_desc **memory_map);
5d00995c 894/* Returns the EFI memory map */
f5a2a938 895efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
5d00995c 896 struct efi_mem_desc *memory_map,
f5a2a938
HS
897 efi_uintn_t *map_key,
898 efi_uintn_t *descriptor_size,
5d00995c
AG
899 uint32_t *descriptor_version);
900/* Adds a range into the EFI memory map */
714497e3 901efi_status_t efi_add_memory_map(u64 start, u64 size, int memory_type);
2f619152 902
c5f6542a
IA
903/**
904 * efi_update_memory_map() - update the memory map by adding/removing pages
905 *
906 * @start: start address, must be a multiple of
907 * EFI_PAGE_SIZE
908 * @pages: number of pages to add
909 * @memory_type: type of memory added
910 * @overlap_conventional: region may only overlap free(conventional)
911 * memory
912 * @remove: remove memory map
913 * Return: status code
914 */
915efi_status_t efi_update_memory_map(u64 start, u64 pages, int memory_type,
916 bool overlap_conventional, bool remove);
917
05ef48a2 918/* Called by board init to initialize the EFI drivers */
038782a2 919efi_status_t efi_driver_init(void);
f05911a1
HS
920/* Called when a block device is added */
921int efi_disk_probe(void *ctx, struct event *event);
922/* Called when a block device is removed */
923int efi_disk_remove(void *ctx, struct event *event);
5d00995c
AG
924/* Called by board init to initialize the EFI memory map */
925int efi_memory_init(void);
488bf12d
AG
926/* Adds new or overrides configuration table entry to the system table */
927efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table);
56d92888 928/* Sets up a loaded image */
c982874e
HS
929efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path,
930 struct efi_device_path *file_path,
931 struct efi_loaded_image_obj **handle_ptr,
932 struct efi_loaded_image **info_ptr);
5d00995c 933
51735ae0
AG
934#ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
935extern void *efi_bounce_buffer;
936#define EFI_LOADER_BOUNCE_BUFFER_SIZE (64 * 1024 * 1024)
937#endif
938
b66c60dd
RC
939#define EFI_DP_TYPE(_dp, _type, _subtype) \
940 (((_dp)->type == DEVICE_PATH_TYPE_##_type) && \
941 ((_dp)->sub_type == DEVICE_PATH_SUB_TYPE_##_subtype))
942
e771b4b3
AT
943/* Indicate supported runtime services */
944efi_status_t efi_init_runtime_supported(void);
945
a39f39cd
HS
946/* Update CRC32 in table header */
947void __efi_runtime efi_update_table_header_crc32(struct efi_table_hdr *table);
948
80a4800e
AG
949/* Boards may provide the functions below to implement RTS functionality */
950
3c63db9c 951void __efi_runtime EFIAPI efi_reset_system(
80a4800e
AG
952 enum efi_reset_type reset_type,
953 efi_status_t reset_status,
954 unsigned long data_size, void *reset_data);
22c793e6
HS
955
956/* Architecture specific initialization of the EFI subsystem */
957efi_status_t efi_reset_system_init(void);
80a4800e 958
3c63db9c 959efi_status_t __efi_runtime EFIAPI efi_get_time(
80a4800e
AG
960 struct efi_time *time,
961 struct efi_time_cap *capabilities);
80a4800e 962
656f1710
HS
963efi_status_t __efi_runtime EFIAPI efi_set_time(struct efi_time *time);
964
623b3a57
HS
965/*
966 * Entry point for the tests of the EFI API.
967 * It is called by 'bootefi selftest'
968 */
969efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
970 struct efi_system_table *systab);
623b3a57 971
0bda81bf
HS
972efi_status_t EFIAPI efi_get_variable(u16 *variable_name,
973 const efi_guid_t *vendor, u32 *attributes,
974 efi_uintn_t *data_size, void *data);
45c66f9c
HS
975efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size,
976 u16 *variable_name,
7a4e717b 977 efi_guid_t *vendor);
0bda81bf
HS
978efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
979 const efi_guid_t *vendor, u32 attributes,
452257a3 980 efi_uintn_t data_size, const void *data);
ad644e7c 981
ce43528d
HS
982efi_status_t EFIAPI efi_query_variable_info(
983 u32 attributes, u64 *maximum_variable_storage_size,
984 u64 *remaining_variable_storage_size,
985 u64 *maximum_variable_size);
986
d47671c6 987void *efi_get_var(const u16 *name, const efi_guid_t *vendor, efi_uintn_t *size);
37c3ca5c 988
1a82b341
AT
989/*
990 * See section 3.1.3 in the v2.7 UEFI spec for more details on
991 * the layout of EFI_LOAD_OPTION. In short it is:
992 *
993 * typedef struct _EFI_LOAD_OPTION {
994 * UINT32 Attributes;
995 * UINT16 FilePathListLength;
996 * // CHAR16 Description[]; <-- variable length, NULL terminated
997 * // EFI_DEVICE_PATH_PROTOCOL FilePathList[];
998 * <-- FilePathListLength bytes
999 * // UINT8 OptionalData[];
1000 * } EFI_LOAD_OPTION;
1001 */
1002struct efi_load_option {
1003 u32 attributes;
1004 u16 file_path_length;
1005 u16 *label;
1006 struct efi_device_path *file_path;
39a1ff8c 1007 const u8 *optional_data;
1a82b341
AT
1008};
1009
76e8acce 1010struct efi_device_path *efi_dp_from_lo(struct efi_load_option *lo,
0421735d 1011 const efi_guid_t *guid);
76e8acce 1012struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
f19171c9 1013 const struct efi_device_path *dp2,
bf03333d 1014 size_t split_end_node);
ce3dbc5d 1015struct efi_device_path *search_gpt_dp_node(struct efi_device_path *device_path);
0e69bcfb
HS
1016efi_status_t efi_deserialize_load_option(struct efi_load_option *lo, u8 *data,
1017 efi_uintn_t *size);
1a82b341 1018unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data);
1064d049
HS
1019efi_status_t efi_set_load_options(efi_handle_t handle,
1020 efi_uintn_t load_options_size,
1021 void *load_options);
0ad64007 1022efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options);
9975fe96 1023
593e17d6 1024/**
c6f077a2 1025 * struct efi_image_regions - A list of memory regions
593e17d6
AT
1026 *
1027 * @max: Maximum number of regions
1028 * @num: Number of regions
1029 * @reg: array of regions
1030 */
1031struct efi_image_regions {
1032 int max;
1033 int num;
1034 struct image_region reg[];
1035};
1036
1037/**
c6f077a2 1038 * struct efi_sig_data - A decoded data of struct efi_signature_data
593e17d6
AT
1039 *
1040 * This structure represents an internal form of signature in
1041 * signature database. A listed list may represent a signature list.
1042 *
1043 * @next: Pointer to next entry
c6f077a2 1044 * @owner: Signature owner
593e17d6
AT
1045 * @data: Pointer to signature data
1046 * @size: Size of signature data
1047 */
1048struct efi_sig_data {
1049 struct efi_sig_data *next;
1050 efi_guid_t owner;
1051 void *data;
1052 size_t size;
1053};
1054
1055/**
c6f077a2 1056 * struct efi_signature_store - A decoded data of signature database
593e17d6
AT
1057 *
1058 * This structure represents an internal form of signature database.
1059 *
1060 * @next: Pointer to next entry
1061 * @sig_type: Signature type
1062 * @sig_data_list: Pointer to signature list
1063 */
1064struct efi_signature_store {
1065 struct efi_signature_store *next;
1066 efi_guid_t sig_type;
1067 struct efi_sig_data *sig_data_list;
1068};
1069
1070struct x509_certificate;
1071struct pkcs7_message;
1072
c416f1c0
MK
1073/**
1074 * struct eficonfig_media_boot_option - boot option for (removable) media device
1075 *
1076 * This structure is used to enumerate possible boot option
1077 *
1078 * @lo: Serialized load option data
1079 * @size: Size of serialized load option data
1080 * @exist: Flag to indicate the load option already exists
1081 * in Non-volatile load option
1082 */
1083struct eficonfig_media_boot_option {
1084 void *lo;
1085 efi_uintn_t size;
1086 bool exist;
1087};
1088
b3301406
AT
1089bool efi_hash_regions(struct image_region *regs, int count,
1090 void **hash, const char *hash_algo, int *len);
7926dfb5 1091bool efi_signature_lookup_digest(struct efi_image_regions *regs,
4b634313
IA
1092 struct efi_signature_store *db,
1093 bool dbx);
1115edd8
AT
1094bool efi_signature_verify(struct efi_image_regions *regs,
1095 struct pkcs7_message *msg,
1096 struct efi_signature_store *db,
1097 struct efi_signature_store *dbx);
52956e53
AT
1098static inline bool efi_signature_verify_one(struct efi_image_regions *regs,
1099 struct pkcs7_message *msg,
1100 struct efi_signature_store *db)
1101{
1102 return efi_signature_verify(regs, msg, db, NULL);
1103}
11bafb25
AT
1104bool efi_signature_check_signers(struct pkcs7_message *msg,
1105 struct efi_signature_store *dbx);
593e17d6
AT
1106
1107efi_status_t efi_image_region_add(struct efi_image_regions *regs,
1108 const void *start, const void *end,
1109 int nocheck);
be6296d0
AT
1110
1111void efi_sigstore_free(struct efi_signature_store *sigstore);
b4f20a5d
SG
1112struct efi_signature_store *efi_build_signature_store(void *sig_list,
1113 efi_uintn_t size);
be6296d0 1114struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name);
767f6eeb
AT
1115
1116bool efi_secure_boot_enabled(void);
4540dabd 1117
04be98bd
SG
1118bool efi_capsule_auth_enabled(void);
1119
163a0d7e
MK
1120void *efi_prepare_aligned_image(void *efi, u64 *efi_size);
1121
4540dabd
AT
1122bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
1123 WIN_CERTIFICATE **auth, size_t *auth_len);
593e17d6 1124
201b8068
SG
1125struct pkcs7_message *efi_parse_pkcs7_header(const void *buf,
1126 size_t buflen,
1127 u8 **tmpbuf);
1128
b0dd8cb4
HS
1129/* runtime implementation of memcpy() */
1130void efi_memcpy_runtime(void *dest, const void *src, size_t n);
1131
39434a9b 1132/* commonly used helper functions */
fe179d7f
IA
1133u16 *efi_create_indexed_name(u16 *buffer, size_t buffer_size, const char *name,
1134 unsigned int index);
39434a9b 1135efi_string_t efi_convert_string(const char *str);
077153e0 1136
f27c2014 1137extern const struct efi_firmware_management_protocol efi_fmp_fit;
bb7e71d3 1138extern const struct efi_firmware_management_protocol efi_fmp_raw;
f27c2014 1139
2bc27ca8
AT
1140/* Capsule update */
1141efi_status_t EFIAPI efi_update_capsule(
1142 struct efi_capsule_header **capsule_header_array,
1143 efi_uintn_t capsule_count,
1144 u64 scatter_gather_list);
1145efi_status_t EFIAPI efi_query_capsule_caps(
1146 struct efi_capsule_header **capsule_header_array,
1147 efi_uintn_t capsule_count,
1148 u64 *maximum_capsule_size,
1149 u32 *reset_type);
1150
04be98bd
SG
1151efi_status_t efi_capsule_authenticate(const void *capsule,
1152 efi_uintn_t capsule_size,
1153 void **image, efi_uintn_t *image_size);
1154
156ccbc3 1155#define EFI_CAPSULE_DIR u"\\EFI\\UpdateCapsule\\"
c74cd8bd 1156
741ef867
SG
1157/**
1158 * struct efi_fw_image - Information on firmware images updatable through
1159 * capsule update
1160 *
1161 * This structure gives information about the firmware images on the platform
1162 * which can be updated through the capsule update mechanism
1163 *
1164 * @image_type_id: Image GUID. Same value is to be used in the capsule
1165 * @fw_name: Name of the firmware image
1166 * @image_index: Image Index, same as value passed to SetImage FMP
1167 * function
1168 */
1169struct efi_fw_image {
1170 efi_guid_t image_type_id;
1171 u16 *fw_name;
1172 u8 image_index;
1173};
1174
1175/**
1176 * struct efi_capsule_update_info - Information needed for capsule updates
1177 *
1178 * This structure provides information needed for performing firmware
1179 * updates. The structure needs to be initialised per platform, for all
1180 * platforms which enable capsule updates
1181 *
1182 * @dfu_string: String used to populate dfu_alt_info
cccea188 1183 * @num_images: The number of images array entries
741ef867
SG
1184 * @images: Pointer to an array of updatable images
1185 */
1186struct efi_capsule_update_info {
1187 const char *dfu_string;
cccea188 1188 int num_images;
741ef867
SG
1189 struct efi_fw_image *images;
1190};
1191
1192extern struct efi_capsule_update_info update_info;
741ef867 1193
64a8aae1
JM
1194/**
1195 * Install the ESRT system table.
1196 *
185f812c 1197 * Return: status code
64a8aae1
JM
1198 */
1199efi_status_t efi_esrt_register(void);
1200
6b92c173
JM
1201/**
1202 * efi_ecpt_register() - Install the ECPT system table.
1203 *
1204 * Return: status code
1205 */
1206efi_status_t efi_ecpt_register(void);
1207
64a8aae1
JM
1208/**
1209 * efi_esrt_populate() - Populates the ESRT entries from the FMP instances
1210 * present in the system.
1211 * If an ESRT already exists, the old ESRT is replaced in the system table.
1212 * The memory of the old ESRT is deallocated.
1213 *
1214 * Return:
1215 * - EFI_SUCCESS if the ESRT is correctly created
1216 * - error code otherwise.
1217 */
1218efi_status_t efi_esrt_populate(void);
6e0184b8 1219efi_status_t efi_load_capsule_drivers(void);
34287efd
RG
1220
1221efi_status_t platform_get_eventlog(struct udevice *dev, u64 *addr, u32 *sz);
87d79142
MK
1222
1223efi_status_t efi_locate_handle_buffer_int(enum efi_locate_search_type search_type,
1224 const efi_guid_t *protocol, void *search_key,
1225 efi_uintn_t *no_handles, efi_handle_t **buffer);
1226
1227efi_status_t efi_open_volume_int(struct efi_simple_file_system_protocol *this,
1228 struct efi_file_handle **root);
1229efi_status_t efi_file_open_int(struct efi_file_handle *this,
1230 struct efi_file_handle **new_handle,
1231 u16 *file_name, u64 open_mode,
1232 u64 attributes);
1233efi_status_t efi_file_close_int(struct efi_file_handle *file);
1234efi_status_t efi_file_read_int(struct efi_file_handle *this,
1235 efi_uintn_t *buffer_size, void *buffer);
1236efi_status_t efi_file_setpos_int(struct efi_file_handle *file, u64 pos);
1237
1238typedef efi_status_t (*efi_console_filter_func)(struct efi_input_key *key);
1239efi_status_t efi_console_get_u16_string
1240 (struct efi_simple_text_input_protocol *cin,
1241 u16 *buf, efi_uintn_t count, efi_console_filter_func filer_func,
1242 int row, int col);
1243
1244efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int size);
1245
a9f20ef3 1246/**
e1b6822d
SG
1247 * efi_add_known_memory() - add memory types to the EFI memory map
1248 *
1249 * This function is to be used to add different memory types other
1250 * than EFI_CONVENTIONAL_MEMORY to the EFI memory map. The conventional
1251 * memory is handled by the LMB module and gets added to the memory
1252 * map through the LMB module.
a9f20ef3 1253 *
e1b6822d 1254 * This function may be overridden for architectures specific purposes.
a9f20ef3
HS
1255 */
1256void efi_add_known_memory(void);
1257
41d57344
HS
1258/**
1259 * efi_map_update_notify() - notify EFI of memory map changes
1260 *
1261 * @addr: start of memory area
1262 * @size: size of memory area
1263 * @op: type of change
1264 * Return: 0 if change could be processed
1265 */
1266#ifdef CONFIG_EFI_LOADER
1267int efi_map_update_notify(phys_addr_t addr, phys_size_t size,
1268 enum lmb_map_op op);
1269#else
1270#define efi_map_update_notify(addr, size, op) (0)
1271#endif
1272
58bef195
HS
1273/**
1274 * efi_load_option_dp_join() - join device-paths for load option
1275 *
1276 * @dp: in: binary device-path, out: joined device-path
1277 * @dp_size: size of joined device-path
1278 * @initrd_dp: initrd device-path or NULL
1279 * @fdt_dp: device-tree device-path or NULL
1280 * Return: status_code
1281 */
1282efi_status_t efi_load_option_dp_join(struct efi_device_path **dp,
1283 size_t *dp_size,
1284 struct efi_device_path *initrd_dp,
1285 struct efi_device_path *fdt_dp);
1286
c9463859
HS
1287int efi_get_distro_fdt_name(char *fname, int size, int seq);
1288
5c1b5e6b 1289void efi_load_distro_fdt(efi_handle_t handle, void **fdt, efi_uintn_t *fdt_size);
e91b68fd 1290
cd9e18de 1291#endif /* _EFI_LOADER_H */