efi.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Extensible Firmware Interface
  4. * Based on 'Extensible Firmware Interface Specification' version 0.9,
  5. * April 30, 1999
  6. *
  7. * Copyright (C) 1999 VA Linux Systems
  8. * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
  9. * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
  10. * David Mosberger-Tang <davidm@hpl.hp.com>
  11. * Stephane Eranian <eranian@hpl.hp.com>
  12. *
  13. * From include/linux/efi.h in kernel 4.1 with some additions/subtractions
  14. */
  15. #ifndef _EFI_H
  16. #define _EFI_H
  17. #include <linux/linkage.h>
  18. #include <linux/string.h>
  19. #include <linux/types.h>
  20. /* Type INTN in UEFI specification */
  21. #define efi_intn_t ssize_t
  22. /* Type UINTN in UEFI specification*/
  23. #define efi_uintn_t size_t
  24. /*
  25. * EFI on x86_64 uses the Microsoft ABI which is not the default for GCC.
  26. *
  27. * There are two scenarios for EFI on x86_64: building a 64-bit EFI stub
  28. * codes (CONFIG_EFI_STUB_64BIT) and building a 64-bit U-Boot (CONFIG_X86_64).
  29. * Either needs to be properly built with the '-m64' compiler flag, and hence
  30. * it is enough to only check the compiler provided define __x86_64__ here.
  31. */
  32. #ifdef __x86_64__
  33. #define EFIAPI __attribute__((ms_abi))
  34. #define efi_va_list __builtin_ms_va_list
  35. #define efi_va_start __builtin_ms_va_start
  36. #define efi_va_copy __builtin_ms_va_copy
  37. #define efi_va_arg __builtin_va_arg
  38. #define efi_va_end __builtin_ms_va_end
  39. #else
  40. #define EFIAPI asmlinkage
  41. #define efi_va_list va_list
  42. #define efi_va_start va_start
  43. #define efi_va_copy va_copy
  44. #define efi_va_arg va_arg
  45. #define efi_va_end va_end
  46. #endif /* __x86_64__ */
  47. #define EFI32_LOADER_SIGNATURE "EL32"
  48. #define EFI64_LOADER_SIGNATURE "EL64"
  49. /**
  50. * struct efi_device_path - device path protocol
  51. *
  52. * @type: device path type
  53. * @sub_type: device path sub-type
  54. * @length: length of the device path node including the header
  55. */
  56. struct efi_device_path {
  57. u8 type;
  58. u8 sub_type;
  59. u16 length;
  60. } __packed;
  61. /*
  62. * The EFI spec defines the EFI_GUID as
  63. * "128-bit buffer containing a unique identifier value. Unless otherwise specified,
  64. * aligned on a 64-bit boundary".
  65. * Page 163 of the UEFI specification v2.10 and
  66. * EDK2 reference implementation both define EFI_GUID as
  67. * struct { u32 a; u16; b; u16 c; u8 d[8]; }; which is 4-byte
  68. * aligned.
  69. */
  70. typedef struct {
  71. u8 b[16];
  72. } efi_guid_t __attribute__((aligned(4)));
  73. #define EFI_BITS_PER_LONG (sizeof(long) * 8)
  74. /* Bit mask for EFI status code with error */
  75. #define EFI_ERROR_MASK (1UL << (EFI_BITS_PER_LONG - 1))
  76. /* Status codes returned by EFI protocols */
  77. #define EFI_SUCCESS 0
  78. #define EFI_LOAD_ERROR (EFI_ERROR_MASK | 1)
  79. #define EFI_INVALID_PARAMETER (EFI_ERROR_MASK | 2)
  80. #define EFI_UNSUPPORTED (EFI_ERROR_MASK | 3)
  81. #define EFI_BAD_BUFFER_SIZE (EFI_ERROR_MASK | 4)
  82. #define EFI_BUFFER_TOO_SMALL (EFI_ERROR_MASK | 5)
  83. #define EFI_NOT_READY (EFI_ERROR_MASK | 6)
  84. #define EFI_DEVICE_ERROR (EFI_ERROR_MASK | 7)
  85. #define EFI_WRITE_PROTECTED (EFI_ERROR_MASK | 8)
  86. #define EFI_OUT_OF_RESOURCES (EFI_ERROR_MASK | 9)
  87. #define EFI_VOLUME_CORRUPTED (EFI_ERROR_MASK | 10)
  88. #define EFI_VOLUME_FULL (EFI_ERROR_MASK | 11)
  89. #define EFI_NO_MEDIA (EFI_ERROR_MASK | 12)
  90. #define EFI_MEDIA_CHANGED (EFI_ERROR_MASK | 13)
  91. #define EFI_NOT_FOUND (EFI_ERROR_MASK | 14)
  92. #define EFI_ACCESS_DENIED (EFI_ERROR_MASK | 15)
  93. #define EFI_NO_RESPONSE (EFI_ERROR_MASK | 16)
  94. #define EFI_NO_MAPPING (EFI_ERROR_MASK | 17)
  95. #define EFI_TIMEOUT (EFI_ERROR_MASK | 18)
  96. #define EFI_NOT_STARTED (EFI_ERROR_MASK | 19)
  97. #define EFI_ALREADY_STARTED (EFI_ERROR_MASK | 20)
  98. #define EFI_ABORTED (EFI_ERROR_MASK | 21)
  99. #define EFI_ICMP_ERROR (EFI_ERROR_MASK | 22)
  100. #define EFI_TFTP_ERROR (EFI_ERROR_MASK | 23)
  101. #define EFI_PROTOCOL_ERROR (EFI_ERROR_MASK | 24)
  102. #define EFI_INCOMPATIBLE_VERSION (EFI_ERROR_MASK | 25)
  103. #define EFI_SECURITY_VIOLATION (EFI_ERROR_MASK | 26)
  104. #define EFI_CRC_ERROR (EFI_ERROR_MASK | 27)
  105. #define EFI_END_OF_MEDIA (EFI_ERROR_MASK | 28)
  106. #define EFI_END_OF_FILE (EFI_ERROR_MASK | 31)
  107. #define EFI_INVALID_LANGUAGE (EFI_ERROR_MASK | 32)
  108. #define EFI_COMPROMISED_DATA (EFI_ERROR_MASK | 33)
  109. #define EFI_IP_ADDRESS_CONFLICT (EFI_ERROR_MASK | 34)
  110. #define EFI_HTTP_ERROR (EFI_ERROR_MASK | 35)
  111. #define EFI_WARN_UNKNOWN_GLYPH 1
  112. #define EFI_WARN_DELETE_FAILURE 2
  113. #define EFI_WARN_WRITE_FAILURE 3
  114. #define EFI_WARN_BUFFER_TOO_SMALL 4
  115. #define EFI_WARN_STALE_DATA 5
  116. #define EFI_WARN_FILE_SYSTEM 6
  117. #define EFI_WARN_RESET_REQUIRED 7
  118. typedef unsigned long efi_status_t;
  119. typedef u64 efi_physical_addr_t;
  120. typedef u64 efi_virtual_addr_t;
  121. typedef struct efi_object *efi_handle_t;
  122. #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
  123. {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
  124. ((a) >> 24) & 0xff, \
  125. (b) & 0xff, ((b) >> 8) & 0xff, \
  126. (c) & 0xff, ((c) >> 8) & 0xff, \
  127. (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } }
  128. /* Generic EFI table header */
  129. struct efi_table_hdr {
  130. u64 signature;
  131. u32 revision;
  132. u32 headersize;
  133. u32 crc32;
  134. u32 reserved;
  135. };
  136. /* Allocation types for calls to boottime->allocate_pages*/
  137. /**
  138. * enum efi_allocate_type - address restriction for memory allocation
  139. */
  140. enum efi_allocate_type {
  141. /**
  142. * @EFI_ALLOCATE_ANY_PAGES:
  143. * Allocate any block of sufficient size. Ignore memory address.
  144. */
  145. EFI_ALLOCATE_ANY_PAGES,
  146. /**
  147. * @EFI_ALLOCATE_MAX_ADDRESS:
  148. * Allocate a memory block with an uppermost address less or equal
  149. * to the indicated address.
  150. */
  151. EFI_ALLOCATE_MAX_ADDRESS,
  152. /**
  153. * @EFI_ALLOCATE_ADDRESS:
  154. * Allocate a memory block starting at the indicatged adress.
  155. */
  156. EFI_ALLOCATE_ADDRESS,
  157. /**
  158. * @EFI_MAX_ALLOCATE_TYPE:
  159. * Value use for range checking.
  160. */
  161. EFI_MAX_ALLOCATE_TYPE,
  162. };
  163. /* Enumeration of memory types introduced in UEFI */
  164. enum efi_memory_type {
  165. EFI_RESERVED_MEMORY_TYPE,
  166. /*
  167. * The code portions of a loaded application.
  168. * (Note that UEFI OS loaders are UEFI applications.)
  169. */
  170. EFI_LOADER_CODE,
  171. /*
  172. * The data portions of a loaded application and
  173. * the default data allocation type used by an application
  174. * to allocate pool memory.
  175. */
  176. EFI_LOADER_DATA,
  177. /* The code portions of a loaded Boot Services Driver */
  178. EFI_BOOT_SERVICES_CODE,
  179. /*
  180. * The data portions of a loaded Boot Services Driver and
  181. * the default data allocation type used by a Boot Services
  182. * Driver to allocate pool memory.
  183. */
  184. EFI_BOOT_SERVICES_DATA,
  185. /* The code portions of a loaded Runtime Services Driver */
  186. EFI_RUNTIME_SERVICES_CODE,
  187. /*
  188. * The data portions of a loaded Runtime Services Driver and
  189. * the default data allocation type used by a Runtime Services
  190. * Driver to allocate pool memory.
  191. */
  192. EFI_RUNTIME_SERVICES_DATA,
  193. /* Free (unallocated) memory */
  194. EFI_CONVENTIONAL_MEMORY,
  195. /* Memory in which errors have been detected */
  196. EFI_UNUSABLE_MEMORY,
  197. /* Memory that holds the ACPI tables */
  198. EFI_ACPI_RECLAIM_MEMORY,
  199. /* Address space reserved for use by the firmware */
  200. EFI_ACPI_MEMORY_NVS,
  201. /*
  202. * Used by system firmware to request that a memory-mapped IO region
  203. * be mapped by the OS to a virtual address so it can be accessed by
  204. * EFI runtime services.
  205. */
  206. EFI_MMAP_IO,
  207. /*
  208. * System memory-mapped IO region that is used to translate
  209. * memory cycles to IO cycles by the processor.
  210. */
  211. EFI_MMAP_IO_PORT,
  212. /*
  213. * Address space reserved by the firmware for code that is
  214. * part of the processor.
  215. */
  216. EFI_PAL_CODE,
  217. /*
  218. * Byte addressable non-volatile memory.
  219. */
  220. EFI_PERSISTENT_MEMORY_TYPE,
  221. /*
  222. * Unaccepted memory must be accepted by boot target before usage.
  223. */
  224. EFI_UNACCEPTED_MEMORY_TYPE,
  225. EFI_MAX_MEMORY_TYPE,
  226. };
  227. /* Attribute values */
  228. #define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */
  229. #define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */
  230. #define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */
  231. #define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */
  232. #define EFI_MEMORY_UCE ((u64)0x0000000000000010ULL) /* uncached, exported */
  233. #define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */
  234. #define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */
  235. #define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */
  236. #define EFI_MEMORY_NV ((u64)0x0000000000008000ULL) /* non-volatile */
  237. #define EFI_MEMORY_MORE_RELIABLE \
  238. ((u64)0x0000000000010000ULL) /* higher reliability */
  239. #define EFI_MEMORY_RO ((u64)0x0000000000020000ULL) /* read-only */
  240. #define EFI_MEMORY_SP ((u64)0x0000000000040000ULL) /* specific-purpose memory (SPM) */
  241. #define EFI_MEMORY_CPU_CRYPTO ((u64)0x0000000000080000ULL) /* cryptographically protectable */
  242. #define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */
  243. #define EFI_MEM_DESC_VERSION 1
  244. #define EFI_PAGE_SHIFT 12
  245. #define EFI_PAGE_SIZE (1ULL << EFI_PAGE_SHIFT)
  246. #define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
  247. struct efi_mem_desc {
  248. u32 type;
  249. u32 reserved;
  250. efi_physical_addr_t physical_start;
  251. efi_virtual_addr_t virtual_start;
  252. u64 num_pages;
  253. u64 attribute;
  254. };
  255. #define EFI_MEMORY_DESCRIPTOR_VERSION 1
  256. /* Types and defines for Time Services */
  257. #define EFI_TIME_ADJUST_DAYLIGHT 0x1
  258. #define EFI_TIME_IN_DAYLIGHT 0x2
  259. #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
  260. struct efi_time {
  261. u16 year;
  262. u8 month;
  263. u8 day;
  264. u8 hour;
  265. u8 minute;
  266. u8 second;
  267. u8 pad1;
  268. u32 nanosecond;
  269. s16 timezone;
  270. u8 daylight;
  271. u8 pad2;
  272. };
  273. struct efi_time_cap {
  274. u32 resolution;
  275. u32 accuracy;
  276. u8 sets_to_zero;
  277. };
  278. enum efi_locate_search_type {
  279. ALL_HANDLES,
  280. BY_REGISTER_NOTIFY,
  281. BY_PROTOCOL
  282. };
  283. struct efi_open_protocol_info_entry {
  284. efi_handle_t agent_handle;
  285. efi_handle_t controller_handle;
  286. u32 attributes;
  287. u32 open_count;
  288. };
  289. enum efi_entry_t {
  290. EFIET_END, /* Signals this is the last (empty) entry */
  291. EFIET_MEMORY_MAP,
  292. EFIET_GOP_MODE,
  293. EFIET_SYS_TABLE,
  294. /* Number of entries */
  295. EFIET_MEMORY_COUNT,
  296. };
  297. #define EFI_TABLE_VERSION 1
  298. /**
  299. * struct efi_info_hdr - Header for the EFI info table
  300. *
  301. * @version: EFI_TABLE_VERSION
  302. * @hdr_size: Size of this struct in bytes
  303. * @total_size: Total size of this header plus following data
  304. * @spare: Spare space for expansion
  305. */
  306. struct efi_info_hdr {
  307. u32 version;
  308. u32 hdr_size;
  309. u32 total_size;
  310. u32 spare[5];
  311. };
  312. /**
  313. * struct efi_entry_hdr - Header for a table entry
  314. *
  315. * @type: enum eft_entry_t
  316. * @size: size of entry bytes excluding header and padding
  317. * @addr: address of this entry (0 if it follows the header )
  318. * @link: size of entry including header and padding
  319. * @spare1: Spare space for expansion
  320. * @spare2: Spare space for expansion
  321. */
  322. struct efi_entry_hdr {
  323. u32 type;
  324. u32 size;
  325. u64 addr;
  326. u32 link;
  327. u32 spare1;
  328. u64 spare2;
  329. };
  330. /**
  331. * struct efi_entry_memmap - a memory map table passed to U-Boot
  332. *
  333. * @version: EFI's memory map table version
  334. * @desc_size: EFI's size of each memory descriptor
  335. * @spare: Spare space for expansion
  336. * @desc: An array of descriptors, each @desc_size bytes apart
  337. */
  338. struct efi_entry_memmap {
  339. u32 version;
  340. u32 desc_size;
  341. u64 spare;
  342. struct efi_mem_desc desc[];
  343. };
  344. /**
  345. * struct efi_entry_gopmode - a GOP mode table passed to U-Boot
  346. *
  347. * @fb_base: EFI's framebuffer base address
  348. * @fb_size: EFI's framebuffer size
  349. * @info_size: GOP mode info structure size
  350. * @info: Start address of the GOP mode info structure
  351. */
  352. struct efi_entry_gopmode {
  353. efi_physical_addr_t fb_base;
  354. /*
  355. * Not like the ones in 'struct efi_gop_mode' which are 'unsigned
  356. * long', @fb_size and @info_size have to be 'u64' here. As the EFI
  357. * stub codes may have different bit size from the U-Boot payload,
  358. * using 'long' will cause mismatch between the producer (stub) and
  359. * the consumer (payload).
  360. */
  361. u64 fb_size;
  362. u64 info_size;
  363. /*
  364. * We cannot directly use 'struct efi_gop_mode_info info[]' here as
  365. * it causes compiler to complain: array type has incomplete element
  366. * type 'struct efi_gop_mode_info'.
  367. */
  368. struct /* efi_gop_mode_info */ {
  369. u32 version;
  370. u32 width;
  371. u32 height;
  372. u32 pixel_format;
  373. u32 pixel_bitmask[4];
  374. u32 pixels_per_scanline;
  375. } info[];
  376. };
  377. /**
  378. * struct efi_entry_systable - system table passed to U-Boot
  379. *
  380. * @sys_table: EFI system table address
  381. */
  382. struct efi_entry_systable {
  383. efi_physical_addr_t sys_table;
  384. };
  385. static inline struct efi_mem_desc *efi_get_next_mem_desc(
  386. struct efi_mem_desc *desc, int desc_size)
  387. {
  388. return (struct efi_mem_desc *)((ulong)desc + desc_size);
  389. }
  390. /**
  391. * struct efi_priv - Information about the environment provided by EFI
  392. *
  393. * @parent_image: image passed into the EFI app or stub
  394. * @sys_table: Pointer to system table
  395. * @boot: Pointer to boot-services table
  396. * @run: Pointer to runtime-services table
  397. * @memmap_key: Key returned from get_memory_map()
  398. * @memmap_desc: List of memory-map records
  399. * @memmap_alloc: Amount of memory allocated for memory map list
  400. * @memmap_size Size of memory-map list in bytes
  401. * @memmap_desc_size: Size of an individual memory-map record, in bytes
  402. * @memmap_version: Memory-map version
  403. *
  404. * @use_pool_for_malloc: true if all allocation should go through the EFI 'pool'
  405. * methods allocate_pool() and free_pool(); false to use 'pages' methods
  406. * allocate_pages() and free_pages()
  407. * @ram_base: Base address of RAM (size CONFIG_EFI_RAM_SIZE)
  408. * @image_data_type: Type of the loaded image (e.g. EFI_LOADER_CODE)
  409. *
  410. * @info: Header of the info list, holding info collected by the stub and passed
  411. * to U-Boot
  412. * @info_size: Size of the info list @info in bytes
  413. * @next_hdr: Pointer to where to put the next header when adding to the list
  414. */
  415. struct efi_priv {
  416. efi_handle_t parent_image;
  417. struct efi_system_table *sys_table;
  418. struct efi_boot_services *boot;
  419. struct efi_runtime_services *run;
  420. efi_uintn_t memmap_key;
  421. struct efi_mem_desc *memmap_desc;
  422. efi_uintn_t memmap_alloc;
  423. efi_uintn_t memmap_size;
  424. efi_uintn_t memmap_desc_size;
  425. u32 memmap_version;
  426. /* app: */
  427. bool use_pool_for_malloc;
  428. unsigned long ram_base;
  429. unsigned int image_data_type;
  430. /* stub: */
  431. struct efi_info_hdr *info;
  432. unsigned int info_size;
  433. void *next_hdr;
  434. };
  435. /*
  436. * EFI attributes of the udevice handled by efi_media driver
  437. *
  438. * @handle: handle of the controller on which this driver is installed
  439. * @blkio: block io protocol proxied by this driver
  440. * @device_path: EFI path to the device
  441. */
  442. struct efi_media_plat {
  443. efi_handle_t handle;
  444. struct efi_block_io *blkio;
  445. struct efi_device_path *device_path;
  446. };
  447. /* Base address of the EFI image */
  448. extern char image_base[];
  449. /* Start and end of U-Boot image (for payload) */
  450. extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
  451. /*
  452. * Variable Attributes
  453. */
  454. #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
  455. #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
  456. #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
  457. #define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x0000000000000008
  458. #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x0000000000000010
  459. #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x0000000000000020
  460. #define EFI_VARIABLE_APPEND_WRITE 0x0000000000000040
  461. #define EFI_VARIABLE_MASK (EFI_VARIABLE_NON_VOLATILE | \
  462. EFI_VARIABLE_BOOTSERVICE_ACCESS | \
  463. EFI_VARIABLE_RUNTIME_ACCESS | \
  464. EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
  465. EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS | \
  466. EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
  467. EFI_VARIABLE_APPEND_WRITE)
  468. /**
  469. * efi_get_priv() - Get access to the EFI-private information
  470. *
  471. * This struct it used by both the stub and the app to record things about the
  472. * EFI environment. It is not available in U-Boot proper after the stub has
  473. * jumped there. Use efi_info_get() to obtain info in that case.
  474. *
  475. * Return: pointer to private info
  476. */
  477. struct efi_priv *efi_get_priv(void);
  478. /**
  479. * efi_set_priv() - Set up a pointer to the EFI-private information
  480. *
  481. * This is called in the stub and app to record the location of this
  482. * information.
  483. *
  484. * @priv: New location of private data
  485. */
  486. void efi_set_priv(struct efi_priv *priv);
  487. /**
  488. * efi_get_sys_table() - Get access to the main EFI system table
  489. *
  490. * Returns: pointer to EFI system table
  491. */
  492. struct efi_system_table *efi_get_sys_table(void);
  493. /**
  494. * efi_get_boot() - Get access to the EFI boot services table
  495. *
  496. * Returns: pointer to EFI boot services table
  497. */
  498. struct efi_boot_services *efi_get_boot(void);
  499. /**
  500. * efi_get_ram_base() - Find the base of RAM
  501. *
  502. * This is used when U-Boot is built as an EFI application.
  503. *
  504. * Returns: the base of RAM as known to U-Boot
  505. */
  506. unsigned long efi_get_ram_base(void);
  507. /**
  508. * efi_init() - Set up ready for use of EFI boot services
  509. *
  510. * @priv: Pointer to our private EFI structure to fill in
  511. * @banner: Banner to display when starting
  512. * @image: The image handle passed to efi_main()
  513. * @sys_table: The EFI system table pointer passed to efi_main()
  514. * Return: 0 on succcess, EFI error code on failure
  515. */
  516. int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
  517. struct efi_system_table *sys_table);
  518. /**
  519. * efi_malloc() - Allocate some memory from EFI
  520. *
  521. * @priv: Pointer to private EFI structure
  522. * @size: Number of bytes to allocate
  523. * @retp: Return EFI status result
  524. * Returns: pointer to memory allocated, or NULL on error
  525. */
  526. void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
  527. /**
  528. * efi_free() - Free memory allocated from EFI
  529. *
  530. * @priv: Pointer to private EFI structure
  531. * @ptr: Pointer to memory to free
  532. */
  533. void efi_free(struct efi_priv *priv, void *ptr);
  534. /**
  535. * efi_puts() - Write out a string to the EFI console
  536. *
  537. * @priv: Pointer to private EFI structure
  538. * @str: String to write (note this is a ASCII, not unicode)
  539. */
  540. void efi_puts(struct efi_priv *priv, const char *str);
  541. /**
  542. * efi_putc() - Write out a character to the EFI console
  543. *
  544. * @priv: Pointer to private EFI structure
  545. * @ch: Character to write (note this is not unicode)
  546. */
  547. void efi_putc(struct efi_priv *priv, const char ch);
  548. /**
  549. * efi_info_get() - get an entry from an EFI table
  550. *
  551. * This function is called from U-Boot proper to read information set up by the
  552. * EFI stub. It can only be used when running from the EFI stub, not when U-Boot
  553. * is running as an app.
  554. *
  555. * @type: Entry type to search for
  556. * @datap: Returns pointer to entry data
  557. * @sizep: Returns entry size
  558. * Return: 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
  559. * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
  560. */
  561. int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
  562. /**
  563. * efi_store_memory_map() - Collect the memory-map info from EFI
  564. *
  565. * Collect the memory info and store it for later use, e.g. in calling
  566. * exit_boot_services()
  567. *
  568. * @priv: Pointer to private EFI structure
  569. * Returns: 0 if OK, non-zero on error
  570. */
  571. int efi_store_memory_map(struct efi_priv *priv);
  572. /**
  573. * efi_call_exit_boot_services() - Handle the exit-boot-service procedure
  574. *
  575. * Tell EFI we don't want their boot services anymore
  576. *
  577. * Return: 0 if OK, non-zero on error
  578. */
  579. int efi_call_exit_boot_services(void);
  580. /**
  581. * efi_get_mmap() - Get the memory map from EFI
  582. *
  583. * This is used in the app. The caller must free *@descp when done
  584. *
  585. * @descp: Returns allocated pointer to EFI memory map table
  586. * @sizep: Returns size of table in bytes
  587. * @keyp: Returns memory-map key
  588. * @desc_sizep: Returns size of each @desc_base record
  589. * @versionp: Returns version number of memory map
  590. * Returns: 0 on success, -ve on error
  591. */
  592. int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
  593. int *desc_sizep, uint *versionp);
  594. /**
  595. * efi_show_tables() - Show a list of available tables
  596. *
  597. * Shows the address, GUID (and name where known) for each table
  598. *
  599. * @systab: System table containing the list of tables
  600. */
  601. void efi_show_tables(struct efi_system_table *systab);
  602. #endif /* _LINUX_EFI_H */