efi_loader.h 24 KB

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