efi_loader.h 28 KB

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