efi_loader.h 22 KB

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