efi.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /*
  2. * Extensible Firmware Interface
  3. * Based on 'Extensible Firmware Interface Specification' version 0.9,
  4. * April 30, 1999
  5. *
  6. * Copyright (C) 1999 VA Linux Systems
  7. * Copyright (C) 1999 Walt Drummond <drummond@valinux.com>
  8. * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co.
  9. * David Mosberger-Tang <davidm@hpl.hp.com>
  10. * Stephane Eranian <eranian@hpl.hp.com>
  11. *
  12. * From include/linux/efi.h in kernel 4.1 with some additions/subtractions
  13. */
  14. #ifndef _EFI_H
  15. #define _EFI_H
  16. #include <linux/linkage.h>
  17. #include <linux/string.h>
  18. #include <linux/types.h>
  19. #ifdef CONFIG_EFI_STUB_64BIT
  20. /* EFI uses the Microsoft ABI which is not the default for GCC */
  21. #define EFIAPI __attribute__((ms_abi))
  22. #else
  23. #define EFIAPI asmlinkage
  24. #endif
  25. struct efi_device_path;
  26. #define EFI_BITS_PER_LONG BITS_PER_LONG
  27. /*
  28. * With 64-bit EFI stub, EFI_BITS_PER_LONG has to be 64. EFI_STUB is set
  29. * in lib/efi/Makefile, when building the stub.
  30. */
  31. #if defined(CONFIG_EFI_STUB_64BIT) && defined(EFI_STUB)
  32. #undef EFI_BITS_PER_LONG
  33. #define EFI_BITS_PER_LONG 64
  34. #endif
  35. #define EFI_SUCCESS 0
  36. #define EFI_LOAD_ERROR (1 | (1UL << (EFI_BITS_PER_LONG - 1)))
  37. #define EFI_INVALID_PARAMETER (2 | (1UL << (EFI_BITS_PER_LONG - 1)))
  38. #define EFI_UNSUPPORTED (3 | (1UL << (EFI_BITS_PER_LONG - 1)))
  39. #define EFI_BAD_BUFFER_SIZE (4 | (1UL << (EFI_BITS_PER_LONG - 1)))
  40. #define EFI_BUFFER_TOO_SMALL (5 | (1UL << (EFI_BITS_PER_LONG - 1)))
  41. #define EFI_NOT_READY (6 | (1UL << (EFI_BITS_PER_LONG - 1)))
  42. #define EFI_DEVICE_ERROR (7 | (1UL << (EFI_BITS_PER_LONG - 1)))
  43. #define EFI_WRITE_PROTECTED (8 | (1UL << (EFI_BITS_PER_LONG - 1)))
  44. #define EFI_OUT_OF_RESOURCES (9 | (1UL << (EFI_BITS_PER_LONG - 1)))
  45. #define EFI_NOT_FOUND (14 | (1UL << (EFI_BITS_PER_LONG - 1)))
  46. #define EFI_ACCESS_DENIED (15 | (1UL << (EFI_BITS_PER_LONG - 1)))
  47. #define EFI_SECURITY_VIOLATION (26 | (1UL << (EFI_BITS_PER_LONG - 1)))
  48. typedef unsigned long efi_status_t;
  49. typedef u64 efi_physical_addr_t;
  50. typedef u64 efi_virtual_addr_t;
  51. typedef void *efi_handle_t;
  52. #define EFI_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
  53. ((efi_guid_t) \
  54. {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, \
  55. ((a) >> 24) & 0xff, \
  56. (b) & 0xff, ((b) >> 8) & 0xff, \
  57. (c) & 0xff, ((c) >> 8) & 0xff, \
  58. (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) } })
  59. /* Generic EFI table header */
  60. struct efi_table_hdr {
  61. u64 signature;
  62. u32 revision;
  63. u32 headersize;
  64. u32 crc32;
  65. u32 reserved;
  66. };
  67. /* Enumeration of memory types introduced in UEFI */
  68. enum efi_mem_type {
  69. EFI_RESERVED_MEMORY_TYPE,
  70. /*
  71. * The code portions of a loaded application.
  72. * (Note that UEFI OS loaders are UEFI applications.)
  73. */
  74. EFI_LOADER_CODE,
  75. /*
  76. * The data portions of a loaded application and
  77. * the default data allocation type used by an application
  78. * to allocate pool memory.
  79. */
  80. EFI_LOADER_DATA,
  81. /* The code portions of a loaded Boot Services Driver */
  82. EFI_BOOT_SERVICES_CODE,
  83. /*
  84. * The data portions of a loaded Boot Serves Driver and
  85. * the default data allocation type used by a Boot Services
  86. * Driver to allocate pool memory.
  87. */
  88. EFI_BOOT_SERVICES_DATA,
  89. /* The code portions of a loaded Runtime Services Driver */
  90. EFI_RUNTIME_SERVICES_CODE,
  91. /*
  92. * The data portions of a loaded Runtime Services Driver and
  93. * the default data allocation type used by a Runtime Services
  94. * Driver to allocate pool memory.
  95. */
  96. EFI_RUNTIME_SERVICES_DATA,
  97. /* Free (unallocated) memory */
  98. EFI_CONVENTIONAL_MEMORY,
  99. /* Memory in which errors have been detected */
  100. EFI_UNUSABLE_MEMORY,
  101. /* Memory that holds the ACPI tables */
  102. EFI_ACPI_RECLAIM_MEMORY,
  103. /* Address space reserved for use by the firmware */
  104. EFI_ACPI_MEMORY_NVS,
  105. /*
  106. * Used by system firmware to request that a memory-mapped IO region
  107. * be mapped by the OS to a virtual address so it can be accessed by
  108. * EFI runtime services.
  109. */
  110. EFI_MMAP_IO,
  111. /*
  112. * System memory-mapped IO region that is used to translate
  113. * memory cycles to IO cycles by the processor.
  114. */
  115. EFI_MMAP_IO_PORT,
  116. /*
  117. * Address space reserved by the firmware for code that is
  118. * part of the processor.
  119. */
  120. EFI_PAL_CODE,
  121. EFI_MAX_MEMORY_TYPE,
  122. EFI_TABLE_END, /* For efi_build_mem_table() */
  123. };
  124. /* Attribute values */
  125. enum {
  126. EFI_MEMORY_UC_SHIFT = 0, /* uncached */
  127. EFI_MEMORY_WC_SHIFT = 1, /* write-coalescing */
  128. EFI_MEMORY_WT_SHIFT = 2, /* write-through */
  129. EFI_MEMORY_WB_SHIFT = 3, /* write-back */
  130. EFI_MEMORY_UCE_SHIFT = 4, /* uncached, exported */
  131. EFI_MEMORY_WP_SHIFT = 12, /* write-protect */
  132. EFI_MEMORY_RP_SHIFT = 13, /* read-protect */
  133. EFI_MEMORY_XP_SHIFT = 14, /* execute-protect */
  134. EFI_MEMORY_RUNTIME_SHIFT = 63, /* range requires runtime mapping */
  135. EFI_MEMORY_RUNTIME = 1ULL << EFI_MEMORY_RUNTIME_SHIFT,
  136. EFI_MEM_DESC_VERSION = 1,
  137. };
  138. #define EFI_PAGE_SHIFT 12
  139. #define EFI_PAGE_SIZE (1UL << EFI_PAGE_SHIFT)
  140. #define EFI_PAGE_MASK (EFI_PAGE_SIZE - 1)
  141. struct efi_mem_desc {
  142. u32 type;
  143. u32 reserved;
  144. efi_physical_addr_t physical_start;
  145. efi_virtual_addr_t virtual_start;
  146. u64 num_pages;
  147. u64 attribute;
  148. };
  149. #define EFI_MEMORY_DESCRIPTOR_VERSION 1
  150. /* Allocation types for calls to boottime->allocate_pages*/
  151. #define EFI_ALLOCATE_ANY_PAGES 0
  152. #define EFI_ALLOCATE_MAX_ADDRESS 1
  153. #define EFI_ALLOCATE_ADDRESS 2
  154. #define EFI_MAX_ALLOCATE_TYPE 3
  155. /* Types and defines for Time Services */
  156. #define EFI_TIME_ADJUST_DAYLIGHT 0x1
  157. #define EFI_TIME_IN_DAYLIGHT 0x2
  158. #define EFI_UNSPECIFIED_TIMEZONE 0x07ff
  159. struct efi_time {
  160. u16 year;
  161. u8 month;
  162. u8 day;
  163. u8 hour;
  164. u8 minute;
  165. u8 second;
  166. u8 pad1;
  167. u32 nanosecond;
  168. s16 timezone;
  169. u8 daylight;
  170. u8 pad2;
  171. };
  172. struct efi_time_cap {
  173. u32 resolution;
  174. u32 accuracy;
  175. u8 sets_to_zero;
  176. };
  177. enum efi_locate_search_type {
  178. all_handles,
  179. by_register_notify,
  180. by_protocol
  181. };
  182. struct efi_open_protocol_info_entry {
  183. efi_handle_t agent_handle;
  184. efi_handle_t controller_handle;
  185. u32 attributes;
  186. u32 open_count;
  187. };
  188. enum efi_entry_t {
  189. EFIET_END, /* Signals this is the last (empty) entry */
  190. EFIET_MEMORY_MAP,
  191. /* Number of entries */
  192. EFIET_MEMORY_COUNT,
  193. };
  194. #define EFI_TABLE_VERSION 1
  195. /**
  196. * struct efi_info_hdr - Header for the EFI info table
  197. *
  198. * @version: EFI_TABLE_VERSION
  199. * @hdr_size: Size of this struct in bytes
  200. * @total_size: Total size of this header plus following data
  201. * @spare: Spare space for expansion
  202. */
  203. struct efi_info_hdr {
  204. u32 version;
  205. u32 hdr_size;
  206. u32 total_size;
  207. u32 spare[5];
  208. };
  209. /**
  210. * struct efi_entry_hdr - Header for a table entry
  211. *
  212. * @type: enum eft_entry_t
  213. * @size size of entry bytes excluding header and padding
  214. * @addr: address of this entry (0 if it follows the header )
  215. * @link: size of entry including header and padding
  216. * @spare1: Spare space for expansion
  217. * @spare2: Spare space for expansion
  218. */
  219. struct efi_entry_hdr {
  220. u32 type;
  221. u32 size;
  222. u64 addr;
  223. u32 link;
  224. u32 spare1;
  225. u64 spare2;
  226. };
  227. /**
  228. * struct efi_entry_memmap - a memory map table passed to U-Boot
  229. *
  230. * @version: EFI's memory map table version
  231. * @desc_size: EFI's size of each memory descriptor
  232. * @spare: Spare space for expansion
  233. * @desc: An array of descriptors, each @desc_size bytes apart
  234. */
  235. struct efi_entry_memmap {
  236. u32 version;
  237. u32 desc_size;
  238. u64 spare;
  239. struct efi_mem_desc desc[];
  240. };
  241. static inline struct efi_mem_desc *efi_get_next_mem_desc(
  242. struct efi_entry_memmap *map, struct efi_mem_desc *desc)
  243. {
  244. return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
  245. }
  246. struct efi_priv {
  247. efi_handle_t parent_image;
  248. struct efi_device_path *device_path;
  249. struct efi_system_table *sys_table;
  250. struct efi_boot_services *boot;
  251. struct efi_runtime_services *run;
  252. bool use_pool_for_malloc;
  253. unsigned long ram_base;
  254. unsigned int image_data_type;
  255. struct efi_info_hdr *info;
  256. unsigned int info_size;
  257. void *next_hdr;
  258. };
  259. /* Base address of the EFI image */
  260. extern char image_base[];
  261. /* Start and end of U-Boot image (for payload) */
  262. extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
  263. /**
  264. * efi_get_sys_table() - Get access to the main EFI system table
  265. *
  266. * @return pointer to EFI system table
  267. */
  268. struct efi_system_table *efi_get_sys_table(void);
  269. /**
  270. * efi_get_ram_base() - Find the base of RAM
  271. *
  272. * This is used when U-Boot is built as an EFI application.
  273. *
  274. * @return the base of RAM as known to U-Boot
  275. */
  276. unsigned long efi_get_ram_base(void);
  277. /**
  278. * efi_init() - Set up ready for use of EFI boot services
  279. *
  280. * @priv: Pointer to our private EFI structure to fill in
  281. * @banner: Banner to display when starting
  282. * @image: The image handle passed to efi_main()
  283. * @sys_table: The EFI system table pointer passed to efi_main()
  284. */
  285. int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
  286. struct efi_system_table *sys_table);
  287. /**
  288. * efi_malloc() - Allocate some memory from EFI
  289. *
  290. * @priv: Pointer to private EFI structure
  291. * @size: Number of bytes to allocate
  292. * @retp: Return EFI status result
  293. * @return pointer to memory allocated, or NULL on error
  294. */
  295. void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
  296. /**
  297. * efi_free() - Free memory allocated from EFI
  298. *
  299. * @priv: Pointer to private EFI structure
  300. * @ptr: Pointer to memory to free
  301. */
  302. void efi_free(struct efi_priv *priv, void *ptr);
  303. /**
  304. * efi_puts() - Write out a string to the EFI console
  305. *
  306. * @priv: Pointer to private EFI structure
  307. * @str: String to write (note this is a ASCII, not unicode)
  308. */
  309. void efi_puts(struct efi_priv *priv, const char *str);
  310. /**
  311. * efi_putc() - Write out a character to the EFI console
  312. *
  313. * @priv: Pointer to private EFI structure
  314. * @ch: Character to write (note this is not unicode)
  315. */
  316. void efi_putc(struct efi_priv *priv, const char ch);
  317. /**
  318. * efi_info_get() - get an entry from an EFI table
  319. *
  320. * @type: Entry type to search for
  321. * @datap: Returns pointer to entry data
  322. * @sizep: Returns pointer to entry size
  323. * @return 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
  324. * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
  325. */
  326. int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
  327. /**
  328. * efi_build_mem_table() - make a sorted copy of the memory table
  329. *
  330. * @map: Pointer to EFI memory map table
  331. * @size: Size of table in bytes
  332. * @skip_bs: True to skip boot-time memory and merge it with conventional
  333. * memory. This will significantly reduce the number of table
  334. * entries.
  335. * @return pointer to the new table. It should be freed with free() by the
  336. * caller
  337. */
  338. void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs);
  339. #endif /* _LINUX_EFI_H */