efi_loader.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * EFI application loader
  4. *
  5. * Copyright (c) 2016 Alexander Graf
  6. */
  7. #ifndef _EFI_LOADER_H
  8. #define _EFI_LOADER_H 1
  9. #include <common.h>
  10. #include <part_efi.h>
  11. #include <efi_api.h>
  12. #include <image.h>
  13. #include <pe.h>
  14. static inline int guidcmp(const void *g1, const void *g2)
  15. {
  16. return memcmp(g1, g2, sizeof(efi_guid_t));
  17. }
  18. static inline void *guidcpy(void *dst, const void *src)
  19. {
  20. return memcpy(dst, src, sizeof(efi_guid_t));
  21. }
  22. /* No need for efi loader support in SPL */
  23. #if CONFIG_IS_ENABLED(EFI_LOADER)
  24. #include <linux/list.h>
  25. #include <linux/oid_registry.h>
  26. /* Maximum number of configuration tables */
  27. #define EFI_MAX_CONFIGURATION_TABLES 16
  28. /* GUID used by the root node */
  29. #define U_BOOT_GUID \
  30. EFI_GUID(0xe61d73b9, 0xa384, 0x4acc, \
  31. 0xae, 0xab, 0x82, 0xe8, 0x28, 0xf3, 0x62, 0x8b)
  32. /* GUID used as host device on sandbox */
  33. #define U_BOOT_HOST_DEV_GUID \
  34. EFI_GUID(0xbbe4e671, 0x5773, 0x4ea1, \
  35. 0x9a, 0xab, 0x3a, 0x7d, 0xbf, 0x40, 0xc4, 0x82)
  36. /* Use internal device tree when starting UEFI application */
  37. #define EFI_FDT_USE_INTERNAL NULL
  38. /* Root node */
  39. extern efi_handle_t efi_root;
  40. /* EFI system partition */
  41. extern struct efi_system_partition {
  42. enum if_type if_type;
  43. int devnum;
  44. u8 part;
  45. } efi_system_partition;
  46. int __efi_entry_check(void);
  47. int __efi_exit_check(void);
  48. const char *__efi_nesting(void);
  49. const char *__efi_nesting_inc(void);
  50. const char *__efi_nesting_dec(void);
  51. /*
  52. * Enter the u-boot world from UEFI:
  53. */
  54. #define EFI_ENTRY(format, ...) do { \
  55. assert(__efi_entry_check()); \
  56. debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \
  57. __func__, ##__VA_ARGS__); \
  58. } while(0)
  59. /*
  60. * Exit the u-boot world back to UEFI:
  61. */
  62. #define EFI_EXIT(ret) ({ \
  63. typeof(ret) _r = ret; \
  64. debug("%sEFI: Exit: %s: %u\n", __efi_nesting_dec(), \
  65. __func__, (u32)((uintptr_t) _r & ~EFI_ERROR_MASK)); \
  66. assert(__efi_exit_check()); \
  67. _r; \
  68. })
  69. /*
  70. * Call non-void UEFI function from u-boot and retrieve return value:
  71. */
  72. #define EFI_CALL(exp) ({ \
  73. debug("%sEFI: Call: %s\n", __efi_nesting_inc(), #exp); \
  74. assert(__efi_exit_check()); \
  75. typeof(exp) _r = exp; \
  76. assert(__efi_entry_check()); \
  77. debug("%sEFI: %lu returned by %s\n", __efi_nesting_dec(), \
  78. (unsigned long)((uintptr_t)_r & ~EFI_ERROR_MASK), #exp); \
  79. _r; \
  80. })
  81. /*
  82. * Call void UEFI function from u-boot:
  83. */
  84. #define EFI_CALL_VOID(exp) do { \
  85. debug("%sEFI: Call: %s\n", __efi_nesting_inc(), #exp); \
  86. assert(__efi_exit_check()); \
  87. exp; \
  88. assert(__efi_entry_check()); \
  89. debug("%sEFI: Return From: %s\n", __efi_nesting_dec(), #exp); \
  90. } while(0)
  91. /*
  92. * Write an indented message with EFI prefix
  93. */
  94. #define EFI_PRINT(format, ...) ({ \
  95. debug("%sEFI: " format, __efi_nesting(), \
  96. ##__VA_ARGS__); \
  97. })
  98. #ifdef CONFIG_SYS_CACHELINE_SIZE
  99. #define EFI_CACHELINE_SIZE CONFIG_SYS_CACHELINE_SIZE
  100. #else
  101. /* Just use the greatest cache flush alignment requirement I'm aware of */
  102. #define EFI_CACHELINE_SIZE 128
  103. #endif
  104. /* Key identifying current memory map */
  105. extern efi_uintn_t efi_memory_map_key;
  106. extern struct efi_runtime_services efi_runtime_services;
  107. extern struct efi_system_table systab;
  108. extern struct efi_simple_text_output_protocol efi_con_out;
  109. extern struct efi_simple_text_input_protocol efi_con_in;
  110. extern struct efi_console_control_protocol efi_console_control;
  111. extern const struct efi_device_path_to_text_protocol efi_device_path_to_text;
  112. /* implementation of the EFI_DEVICE_PATH_UTILITIES_PROTOCOL */
  113. extern const struct efi_device_path_utilities_protocol
  114. efi_device_path_utilities;
  115. /* deprecated version of the EFI_UNICODE_COLLATION_PROTOCOL */
  116. extern const struct efi_unicode_collation_protocol
  117. efi_unicode_collation_protocol;
  118. /* current version of the EFI_UNICODE_COLLATION_PROTOCOL */
  119. extern const struct efi_unicode_collation_protocol
  120. efi_unicode_collation_protocol2;
  121. extern const struct efi_hii_config_routing_protocol efi_hii_config_routing;
  122. extern const struct efi_hii_config_access_protocol efi_hii_config_access;
  123. extern const struct efi_hii_database_protocol efi_hii_database;
  124. extern const struct efi_hii_string_protocol efi_hii_string;
  125. extern const struct efi_rng_protocol efi_rng_protocol;
  126. uint16_t *efi_dp_str(struct efi_device_path *dp);
  127. /* GUID of the U-Boot root node */
  128. extern const efi_guid_t efi_u_boot_guid;
  129. #ifdef CONFIG_SANDBOX
  130. /* GUID of U-Boot host device on sandbox */
  131. extern const efi_guid_t efi_guid_host_dev;
  132. #endif
  133. /* GUID of the EFI_BLOCK_IO_PROTOCOL */
  134. extern const efi_guid_t efi_block_io_guid;
  135. extern const efi_guid_t efi_global_variable_guid;
  136. extern const efi_guid_t efi_guid_console_control;
  137. extern const efi_guid_t efi_guid_device_path;
  138. /* GUID of the EFI_DRIVER_BINDING_PROTOCOL */
  139. extern const efi_guid_t efi_guid_driver_binding_protocol;
  140. /* event group ExitBootServices() invoked */
  141. extern const efi_guid_t efi_guid_event_group_exit_boot_services;
  142. /* event group SetVirtualAddressMap() invoked */
  143. extern const efi_guid_t efi_guid_event_group_virtual_address_change;
  144. /* event group memory map changed */
  145. extern const efi_guid_t efi_guid_event_group_memory_map_change;
  146. /* event group boot manager about to boot */
  147. extern const efi_guid_t efi_guid_event_group_ready_to_boot;
  148. /* event group ResetSystem() invoked (before ExitBootServices) */
  149. extern const efi_guid_t efi_guid_event_group_reset_system;
  150. /* GUID of the device tree table */
  151. extern const efi_guid_t efi_guid_fdt;
  152. extern const efi_guid_t efi_guid_loaded_image;
  153. extern const efi_guid_t efi_guid_loaded_image_device_path;
  154. extern const efi_guid_t efi_guid_device_path_to_text_protocol;
  155. extern const efi_guid_t efi_simple_file_system_protocol_guid;
  156. extern const efi_guid_t efi_file_info_guid;
  157. /* GUID for file system information */
  158. extern const efi_guid_t efi_file_system_info_guid;
  159. extern const efi_guid_t efi_guid_device_path_utilities_protocol;
  160. /* GUID of the deprecated Unicode collation protocol */
  161. extern const efi_guid_t efi_guid_unicode_collation_protocol;
  162. /* GUID of the Unicode collation protocol */
  163. extern const efi_guid_t efi_guid_unicode_collation_protocol2;
  164. extern const efi_guid_t efi_guid_hii_config_routing_protocol;
  165. extern const efi_guid_t efi_guid_hii_config_access_protocol;
  166. extern const efi_guid_t efi_guid_hii_database_protocol;
  167. extern const efi_guid_t efi_guid_hii_string_protocol;
  168. /* GUIDs for authentication */
  169. extern const efi_guid_t efi_guid_image_security_database;
  170. extern const efi_guid_t efi_guid_sha256;
  171. extern const efi_guid_t efi_guid_cert_x509;
  172. extern const efi_guid_t efi_guid_cert_x509_sha256;
  173. extern const efi_guid_t efi_guid_cert_type_pkcs7;
  174. /* GUID of RNG protocol */
  175. extern const efi_guid_t efi_guid_rng_protocol;
  176. extern unsigned int __efi_runtime_start, __efi_runtime_stop;
  177. extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
  178. /**
  179. * struct efi_open_protocol_info_item - open protocol info item
  180. *
  181. * When a protocol is opened a open protocol info entry is created.
  182. * These are maintained in a list.
  183. *
  184. * @link: link to the list of open protocol info entries of a protocol
  185. * @info: information about the opening of a protocol
  186. */
  187. struct efi_open_protocol_info_item {
  188. struct list_head link;
  189. struct efi_open_protocol_info_entry info;
  190. };
  191. /**
  192. * struct efi_handler - single protocol interface of a handle
  193. *
  194. * When the UEFI payload wants to open a protocol on an object to get its
  195. * interface (usually a struct with callback functions), this struct maps the
  196. * protocol GUID to the respective protocol interface
  197. *
  198. * @link: link to the list of protocols of a handle
  199. * @guid: GUID of the protocol
  200. * @protocol_interface: protocol interface
  201. * @open_infos link to the list of open protocol info items
  202. */
  203. struct efi_handler {
  204. struct list_head link;
  205. const efi_guid_t *guid;
  206. void *protocol_interface;
  207. struct list_head open_infos;
  208. };
  209. /**
  210. * enum efi_object_type - type of EFI object
  211. *
  212. * In UnloadImage we must be able to identify if the handle relates to a
  213. * started image.
  214. */
  215. enum efi_object_type {
  216. EFI_OBJECT_TYPE_UNDEFINED = 0,
  217. EFI_OBJECT_TYPE_U_BOOT_FIRMWARE,
  218. EFI_OBJECT_TYPE_LOADED_IMAGE,
  219. EFI_OBJECT_TYPE_STARTED_IMAGE,
  220. };
  221. /**
  222. * struct efi_object - dereferenced EFI handle
  223. *
  224. * @link: pointers to put the handle into a linked list
  225. * @protocols: linked list with the protocol interfaces installed on this
  226. * handle
  227. *
  228. * UEFI offers a flexible and expandable object model. The objects in the UEFI
  229. * API are devices, drivers, and loaded images. struct efi_object is our storage
  230. * structure for these objects.
  231. *
  232. * When including this structure into a larger structure always put it first so
  233. * that when deleting a handle the whole encompassing structure can be freed.
  234. *
  235. * A pointer to this structure is referred to as a handle. Typedef efi_handle_t
  236. * has been created for such pointers.
  237. */
  238. struct efi_object {
  239. /* Every UEFI object is part of a global object list */
  240. struct list_head link;
  241. /* The list of protocols */
  242. struct list_head protocols;
  243. enum efi_object_type type;
  244. };
  245. enum efi_image_auth_status {
  246. EFI_IMAGE_AUTH_FAILED = 0,
  247. EFI_IMAGE_AUTH_PASSED,
  248. };
  249. /**
  250. * struct efi_loaded_image_obj - handle of a loaded image
  251. *
  252. * @header: EFI object header
  253. * @exit_status: exit status passed to Exit()
  254. * @exit_data_size: exit data size passed to Exit()
  255. * @exit_data: exit data passed to Exit()
  256. * @exit_jmp: long jump buffer for returning form started image
  257. * @entry: entry address of the relocated image
  258. */
  259. struct efi_loaded_image_obj {
  260. struct efi_object header;
  261. efi_status_t exit_status;
  262. efi_uintn_t *exit_data_size;
  263. u16 **exit_data;
  264. struct jmp_buf_data exit_jmp;
  265. EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,
  266. struct efi_system_table *st);
  267. u16 image_type;
  268. enum efi_image_auth_status auth_status;
  269. };
  270. /**
  271. * struct efi_event
  272. *
  273. * @link: Link to list of all events
  274. * @queue_link: Link to the list of queued events
  275. * @type: Type of event, see efi_create_event
  276. * @notify_tpl: Task priority level of notifications
  277. * @nofify_function: Function to call when the event is triggered
  278. * @notify_context: Data to be passed to the notify function
  279. * @group: Event group
  280. * @trigger_time: Period of the timer
  281. * @trigger_next: Next time to trigger the timer
  282. * @trigger_type: Type of timer, see efi_set_timer
  283. * @is_signaled: The event occurred. The event is in the signaled state.
  284. */
  285. struct efi_event {
  286. struct list_head link;
  287. struct list_head queue_link;
  288. uint32_t type;
  289. efi_uintn_t notify_tpl;
  290. void (EFIAPI *notify_function)(struct efi_event *event, void *context);
  291. void *notify_context;
  292. const efi_guid_t *group;
  293. u64 trigger_next;
  294. u64 trigger_time;
  295. enum efi_timer_delay trigger_type;
  296. bool is_signaled;
  297. };
  298. /* This list contains all UEFI objects we know of */
  299. extern struct list_head efi_obj_list;
  300. /* List of all events */
  301. extern struct list_head efi_events;
  302. /**
  303. * struct efi_protocol_notification - handle for notified protocol
  304. *
  305. * When a protocol interface is installed for which an event was registered with
  306. * the RegisterProtocolNotify() service this structure is used to hold the
  307. * handle on which the protocol interface was installed.
  308. *
  309. * @link: link to list of all handles notified for this event
  310. * @handle: handle on which the notified protocol interface was installed
  311. */
  312. struct efi_protocol_notification {
  313. struct list_head link;
  314. efi_handle_t handle;
  315. };
  316. /**
  317. * efi_register_notify_event - event registered by RegisterProtocolNotify()
  318. *
  319. * The address of this structure serves as registration value.
  320. *
  321. * @link: link to list of all registered events
  322. * @event: registered event. The same event may registered for multiple
  323. * GUIDs.
  324. * @protocol: protocol for which the event is registered
  325. * @handles: linked list of all handles on which the notified protocol was
  326. * installed
  327. */
  328. struct efi_register_notify_event {
  329. struct list_head link;
  330. struct efi_event *event;
  331. efi_guid_t protocol;
  332. struct list_head handles;
  333. };
  334. /* List of all events registered by RegisterProtocolNotify() */
  335. extern struct list_head efi_register_notify_events;
  336. /* Initialize efi execution environment */
  337. efi_status_t efi_init_obj_list(void);
  338. /* Install device tree */
  339. efi_status_t efi_install_fdt(void *fdt);
  340. /* Run loaded UEFI image */
  341. efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size);
  342. /* Initialize variable services */
  343. efi_status_t efi_init_variables(void);
  344. /* Notify ExitBootServices() is called */
  345. void efi_variables_boot_exit_notify(void);
  346. /* Called by bootefi to initialize root node */
  347. efi_status_t efi_root_node_register(void);
  348. /* Called by bootefi to initialize runtime */
  349. efi_status_t efi_initialize_system_table(void);
  350. /* efi_runtime_detach() - detach unimplemented runtime functions */
  351. void efi_runtime_detach(void);
  352. /* Called by bootefi to make console interface available */
  353. efi_status_t efi_console_register(void);
  354. /* Called by bootefi to make all disk storage accessible as EFI objects */
  355. efi_status_t efi_disk_register(void);
  356. /* Create handles and protocols for the partitions of a block device */
  357. int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc,
  358. const char *if_typename, int diskid,
  359. const char *pdevname);
  360. /* Called by bootefi to make GOP (graphical) interface available */
  361. efi_status_t efi_gop_register(void);
  362. /* Called by bootefi to make the network interface available */
  363. efi_status_t efi_net_register(void);
  364. /* Called by bootefi to make the watchdog available */
  365. efi_status_t efi_watchdog_register(void);
  366. efi_status_t efi_initrd_register(void);
  367. /* Called by bootefi to make SMBIOS tables available */
  368. /**
  369. * efi_acpi_register() - write out ACPI tables
  370. *
  371. * Called by bootefi to make ACPI tables available
  372. *
  373. * @return 0 if OK, -ENOMEM if no memory is available for the tables
  374. */
  375. efi_status_t efi_acpi_register(void);
  376. /**
  377. * efi_smbios_register() - write out SMBIOS tables
  378. *
  379. * Called by bootefi to make SMBIOS tables available
  380. *
  381. * @return 0 if OK, -ENOMEM if no memory is available for the tables
  382. */
  383. efi_status_t efi_smbios_register(void);
  384. struct efi_simple_file_system_protocol *
  385. efi_fs_from_path(struct efi_device_path *fp);
  386. /* Called by networking code to memorize the dhcp ack package */
  387. void efi_net_set_dhcp_ack(void *pkt, int len);
  388. /* Called by efi_set_watchdog_timer to reset the timer */
  389. efi_status_t efi_set_watchdog(unsigned long timeout);
  390. /* Called from places to check whether a timer expired */
  391. void efi_timer_check(void);
  392. /* PE loader implementation */
  393. efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
  394. void *efi, size_t efi_size,
  395. struct efi_loaded_image *loaded_image_info);
  396. /* Called once to store the pristine gd pointer */
  397. void efi_save_gd(void);
  398. /* Special case handler for error/abort that just tries to dtrt to get
  399. * back to u-boot world */
  400. void efi_restore_gd(void);
  401. /* Call this to relocate the runtime section to an address space */
  402. void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map);
  403. /* Call this to set the current device name */
  404. void efi_set_bootdev(const char *dev, const char *devnr, const char *path);
  405. /* Add a new object to the object list. */
  406. void efi_add_handle(efi_handle_t obj);
  407. /* Create handle */
  408. efi_status_t efi_create_handle(efi_handle_t *handle);
  409. /* Delete handle */
  410. void efi_delete_handle(efi_handle_t obj);
  411. /* Call this to validate a handle and find the EFI object for it */
  412. struct efi_object *efi_search_obj(const efi_handle_t handle);
  413. /* Load image */
  414. efi_status_t EFIAPI efi_load_image(bool boot_policy,
  415. efi_handle_t parent_image,
  416. struct efi_device_path *file_path,
  417. void *source_buffer,
  418. efi_uintn_t source_size,
  419. efi_handle_t *image_handle);
  420. /* Start image */
  421. efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
  422. efi_uintn_t *exit_data_size,
  423. u16 **exit_data);
  424. /* Unload image */
  425. efi_status_t EFIAPI efi_unload_image(efi_handle_t image_handle);
  426. /* Find a protocol on a handle */
  427. efi_status_t efi_search_protocol(const efi_handle_t handle,
  428. const efi_guid_t *protocol_guid,
  429. struct efi_handler **handler);
  430. /* Install new protocol on a handle */
  431. efi_status_t efi_add_protocol(const efi_handle_t handle,
  432. const efi_guid_t *protocol,
  433. void *protocol_interface);
  434. /* Delete protocol from a handle */
  435. efi_status_t efi_remove_protocol(const efi_handle_t handle,
  436. const efi_guid_t *protocol,
  437. void *protocol_interface);
  438. /* Delete all protocols from a handle */
  439. efi_status_t efi_remove_all_protocols(const efi_handle_t handle);
  440. /* Install multiple protocol interfaces */
  441. efi_status_t EFIAPI efi_install_multiple_protocol_interfaces
  442. (efi_handle_t *handle, ...);
  443. /* Get handles that support a given protocol */
  444. efi_status_t EFIAPI efi_locate_handle_buffer(
  445. enum efi_locate_search_type search_type,
  446. const efi_guid_t *protocol, void *search_key,
  447. efi_uintn_t *no_handles, efi_handle_t **buffer);
  448. /* Close an previously opened protocol interface */
  449. efi_status_t EFIAPI efi_close_protocol(efi_handle_t handle,
  450. const efi_guid_t *protocol,
  451. efi_handle_t agent_handle,
  452. efi_handle_t controller_handle);
  453. /* Open a protocol interface */
  454. efi_status_t EFIAPI efi_handle_protocol(efi_handle_t handle,
  455. const efi_guid_t *protocol,
  456. void **protocol_interface);
  457. /* Call this to create an event */
  458. efi_status_t efi_create_event(uint32_t type, efi_uintn_t notify_tpl,
  459. void (EFIAPI *notify_function) (
  460. struct efi_event *event,
  461. void *context),
  462. void *notify_context, efi_guid_t *group,
  463. struct efi_event **event);
  464. /* Call this to set a timer */
  465. efi_status_t efi_set_timer(struct efi_event *event, enum efi_timer_delay type,
  466. uint64_t trigger_time);
  467. /* Call this to signal an event */
  468. void efi_signal_event(struct efi_event *event);
  469. /* open file system: */
  470. struct efi_simple_file_system_protocol *efi_simple_file_system(
  471. struct blk_desc *desc, int part, struct efi_device_path *dp);
  472. /* open file from device-path: */
  473. struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);
  474. /**
  475. * efi_size_in_pages() - convert size in bytes to size in pages
  476. *
  477. * This macro returns the number of EFI memory pages required to hold 'size'
  478. * bytes.
  479. *
  480. * @size: size in bytes
  481. * Return: size in pages
  482. */
  483. #define efi_size_in_pages(size) ((size + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT)
  484. /* Generic EFI memory allocator, call this to get memory */
  485. void *efi_alloc(uint64_t len, int memory_type);
  486. /* More specific EFI memory allocator, called by EFI payloads */
  487. efi_status_t efi_allocate_pages(int type, int memory_type, efi_uintn_t pages,
  488. uint64_t *memory);
  489. /* EFI memory free function. */
  490. efi_status_t efi_free_pages(uint64_t memory, efi_uintn_t pages);
  491. /* EFI memory allocator for small allocations */
  492. efi_status_t efi_allocate_pool(int pool_type, efi_uintn_t size,
  493. void **buffer);
  494. /* EFI pool memory free function. */
  495. efi_status_t efi_free_pool(void *buffer);
  496. /* Returns the EFI memory map */
  497. efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
  498. struct efi_mem_desc *memory_map,
  499. efi_uintn_t *map_key,
  500. efi_uintn_t *descriptor_size,
  501. uint32_t *descriptor_version);
  502. /* Adds a range into the EFI memory map */
  503. efi_status_t efi_add_memory_map(uint64_t start, uint64_t pages, int memory_type,
  504. bool overlap_only_ram);
  505. /* Adds a conventional range into the EFI memory map */
  506. efi_status_t efi_add_conventional_memory_map(u64 ram_start, u64 ram_end,
  507. u64 ram_top);
  508. /* Called by board init to initialize the EFI drivers */
  509. efi_status_t efi_driver_init(void);
  510. /* Called by board init to initialize the EFI memory map */
  511. int efi_memory_init(void);
  512. /* Adds new or overrides configuration table entry to the system table */
  513. efi_status_t efi_install_configuration_table(const efi_guid_t *guid, void *table);
  514. /* Sets up a loaded image */
  515. efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path,
  516. struct efi_device_path *file_path,
  517. struct efi_loaded_image_obj **handle_ptr,
  518. struct efi_loaded_image **info_ptr);
  519. /* Print information about all loaded images */
  520. void efi_print_image_infos(void *pc);
  521. #ifdef CONFIG_EFI_LOADER_BOUNCE_BUFFER
  522. extern void *efi_bounce_buffer;
  523. #define EFI_LOADER_BOUNCE_BUFFER_SIZE (64 * 1024 * 1024)
  524. #endif
  525. struct efi_device_path *efi_dp_next(const struct efi_device_path *dp);
  526. int efi_dp_match(const struct efi_device_path *a,
  527. const struct efi_device_path *b);
  528. struct efi_object *efi_dp_find_obj(struct efi_device_path *dp,
  529. struct efi_device_path **rem);
  530. /* get size of the first device path instance excluding end node */
  531. efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp);
  532. /* size of multi-instance device path excluding end node */
  533. efi_uintn_t efi_dp_size(const struct efi_device_path *dp);
  534. struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp);
  535. struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
  536. const struct efi_device_path *dp2);
  537. struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,
  538. const struct efi_device_path *node);
  539. /* Create a device path node of given type, sub-type, length */
  540. struct efi_device_path *efi_dp_create_device_node(const u8 type,
  541. const u8 sub_type,
  542. const u16 length);
  543. /* Append device path instance */
  544. struct efi_device_path *efi_dp_append_instance(
  545. const struct efi_device_path *dp,
  546. const struct efi_device_path *dpi);
  547. /* Get next device path instance */
  548. struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp,
  549. efi_uintn_t *size);
  550. /* Check if a device path contains muliple instances */
  551. bool efi_dp_is_multi_instance(const struct efi_device_path *dp);
  552. struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part);
  553. /* Create a device node for a block device partition. */
  554. struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part);
  555. struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
  556. const char *path);
  557. struct efi_device_path *efi_dp_from_eth(void);
  558. struct efi_device_path *efi_dp_from_mem(uint32_t mem_type,
  559. uint64_t start_address,
  560. uint64_t end_address);
  561. /* Determine the last device path node that is not the end node. */
  562. const struct efi_device_path *efi_dp_last_node(
  563. const struct efi_device_path *dp);
  564. efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path,
  565. struct efi_device_path **device_path,
  566. struct efi_device_path **file_path);
  567. efi_status_t efi_dp_from_name(const char *dev, const char *devnr,
  568. const char *path,
  569. struct efi_device_path **device,
  570. struct efi_device_path **file);
  571. #define EFI_DP_TYPE(_dp, _type, _subtype) \
  572. (((_dp)->type == DEVICE_PATH_TYPE_##_type) && \
  573. ((_dp)->sub_type == DEVICE_PATH_SUB_TYPE_##_subtype))
  574. /*
  575. * Use these to indicate that your code / data should go into the EFI runtime
  576. * section and thus still be available when the OS is running
  577. */
  578. #define __efi_runtime_data __attribute__ ((section (".data.efi_runtime")))
  579. #define __efi_runtime __attribute__ ((section (".text.efi_runtime")))
  580. /* Indicate supported runtime services */
  581. efi_status_t efi_init_runtime_supported(void);
  582. /* Update CRC32 in table header */
  583. void __efi_runtime efi_update_table_header_crc32(struct efi_table_hdr *table);
  584. /* Call this with mmio_ptr as the _pointer_ to a pointer to an MMIO region
  585. * to make it available at runtime */
  586. efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len);
  587. /* Boards may provide the functions below to implement RTS functionality */
  588. void __efi_runtime EFIAPI efi_reset_system(
  589. enum efi_reset_type reset_type,
  590. efi_status_t reset_status,
  591. unsigned long data_size, void *reset_data);
  592. /* Architecture specific initialization of the EFI subsystem */
  593. efi_status_t efi_reset_system_init(void);
  594. efi_status_t __efi_runtime EFIAPI efi_get_time(
  595. struct efi_time *time,
  596. struct efi_time_cap *capabilities);
  597. efi_status_t __efi_runtime EFIAPI efi_set_time(struct efi_time *time);
  598. #ifdef CONFIG_CMD_BOOTEFI_SELFTEST
  599. /*
  600. * Entry point for the tests of the EFI API.
  601. * It is called by 'bootefi selftest'
  602. */
  603. efi_status_t EFIAPI efi_selftest(efi_handle_t image_handle,
  604. struct efi_system_table *systab);
  605. #endif
  606. efi_status_t EFIAPI efi_get_variable(u16 *variable_name,
  607. const efi_guid_t *vendor, u32 *attributes,
  608. efi_uintn_t *data_size, void *data);
  609. efi_status_t EFIAPI efi_get_next_variable_name(efi_uintn_t *variable_name_size,
  610. u16 *variable_name,
  611. efi_guid_t *vendor);
  612. efi_status_t EFIAPI efi_set_variable(u16 *variable_name,
  613. const efi_guid_t *vendor, u32 attributes,
  614. efi_uintn_t data_size, const void *data);
  615. efi_status_t EFIAPI efi_query_variable_info(
  616. u32 attributes, u64 *maximum_variable_storage_size,
  617. u64 *remaining_variable_storage_size,
  618. u64 *maximum_variable_size);
  619. /*
  620. * See section 3.1.3 in the v2.7 UEFI spec for more details on
  621. * the layout of EFI_LOAD_OPTION. In short it is:
  622. *
  623. * typedef struct _EFI_LOAD_OPTION {
  624. * UINT32 Attributes;
  625. * UINT16 FilePathListLength;
  626. * // CHAR16 Description[]; <-- variable length, NULL terminated
  627. * // EFI_DEVICE_PATH_PROTOCOL FilePathList[];
  628. * <-- FilePathListLength bytes
  629. * // UINT8 OptionalData[];
  630. * } EFI_LOAD_OPTION;
  631. */
  632. struct efi_load_option {
  633. u32 attributes;
  634. u16 file_path_length;
  635. u16 *label;
  636. struct efi_device_path *file_path;
  637. const u8 *optional_data;
  638. };
  639. void efi_deserialize_load_option(struct efi_load_option *lo, u8 *data);
  640. unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data);
  641. efi_status_t efi_bootmgr_load(efi_handle_t *handle);
  642. /**
  643. * efi_image_regions - A list of memory regions
  644. *
  645. * @max: Maximum number of regions
  646. * @num: Number of regions
  647. * @reg: array of regions
  648. */
  649. struct efi_image_regions {
  650. int max;
  651. int num;
  652. struct image_region reg[];
  653. };
  654. /**
  655. * efi_sig_data - A decoded data of struct efi_signature_data
  656. *
  657. * This structure represents an internal form of signature in
  658. * signature database. A listed list may represent a signature list.
  659. *
  660. * @next: Pointer to next entry
  661. * @onwer: Signature owner
  662. * @data: Pointer to signature data
  663. * @size: Size of signature data
  664. */
  665. struct efi_sig_data {
  666. struct efi_sig_data *next;
  667. efi_guid_t owner;
  668. void *data;
  669. size_t size;
  670. };
  671. /**
  672. * efi_signature_store - A decoded data of signature database
  673. *
  674. * This structure represents an internal form of signature database.
  675. *
  676. * @next: Pointer to next entry
  677. * @sig_type: Signature type
  678. * @sig_data_list: Pointer to signature list
  679. */
  680. struct efi_signature_store {
  681. struct efi_signature_store *next;
  682. efi_guid_t sig_type;
  683. struct efi_sig_data *sig_data_list;
  684. };
  685. struct x509_certificate;
  686. struct pkcs7_message;
  687. bool efi_signature_verify_cert(struct x509_certificate *cert,
  688. struct efi_signature_store *dbx);
  689. bool efi_signature_verify_signers(struct pkcs7_message *msg,
  690. struct efi_signature_store *dbx);
  691. bool efi_signature_verify_with_sigdb(struct efi_image_regions *regs,
  692. struct pkcs7_message *msg,
  693. struct efi_signature_store *db,
  694. struct x509_certificate **cert);
  695. efi_status_t efi_image_region_add(struct efi_image_regions *regs,
  696. const void *start, const void *end,
  697. int nocheck);
  698. void efi_sigstore_free(struct efi_signature_store *sigstore);
  699. struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name);
  700. bool efi_secure_boot_enabled(void);
  701. bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp,
  702. WIN_CERTIFICATE **auth, size_t *auth_len);
  703. #else /* CONFIG_IS_ENABLED(EFI_LOADER) */
  704. /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
  705. #define __efi_runtime_data
  706. #define __efi_runtime
  707. static inline efi_status_t efi_add_runtime_mmio(void *mmio_ptr, u64 len)
  708. {
  709. return EFI_SUCCESS;
  710. }
  711. /* No loader configured, stub out EFI_ENTRY */
  712. static inline void efi_restore_gd(void) { }
  713. static inline void efi_set_bootdev(const char *dev, const char *devnr,
  714. const char *path) { }
  715. static inline void efi_net_set_dhcp_ack(void *pkt, int len) { }
  716. static inline void efi_print_image_infos(void *pc) { }
  717. #endif /* CONFIG_IS_ENABLED(EFI_LOADER) */
  718. #endif /* _EFI_LOADER_H */