efi_loader.h 24 KB

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