efi_api.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  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_API_H
  15. #define _EFI_API_H
  16. #include <efi.h>
  17. #ifdef CONFIG_EFI_LOADER
  18. #include <asm/setjmp.h>
  19. #endif
  20. /* UEFI spec version 2.7 */
  21. #define EFI_SPECIFICATION_VERSION (2 << 16 | 70)
  22. /* Types and defines for EFI CreateEvent */
  23. enum efi_timer_delay {
  24. EFI_TIMER_STOP = 0,
  25. EFI_TIMER_PERIODIC = 1,
  26. EFI_TIMER_RELATIVE = 2
  27. };
  28. #define efi_intn_t ssize_t
  29. #define efi_uintn_t size_t
  30. typedef uint16_t *efi_string_t;
  31. #define EVT_TIMER 0x80000000
  32. #define EVT_RUNTIME 0x40000000
  33. #define EVT_NOTIFY_WAIT 0x00000100
  34. #define EVT_NOTIFY_SIGNAL 0x00000200
  35. #define EVT_SIGNAL_EXIT_BOOT_SERVICES 0x00000201
  36. #define EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202
  37. #define TPL_APPLICATION 0x04
  38. #define TPL_CALLBACK 0x08
  39. #define TPL_NOTIFY 0x10
  40. #define TPL_HIGH_LEVEL 0x1F
  41. struct efi_event;
  42. /* EFI Boot Services table */
  43. #define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42
  44. struct efi_boot_services {
  45. struct efi_table_hdr hdr;
  46. efi_status_t (EFIAPI *raise_tpl)(efi_uintn_t new_tpl);
  47. void (EFIAPI *restore_tpl)(efi_uintn_t old_tpl);
  48. efi_status_t (EFIAPI *allocate_pages)(int, int, efi_uintn_t,
  49. efi_physical_addr_t *);
  50. efi_status_t (EFIAPI *free_pages)(efi_physical_addr_t, efi_uintn_t);
  51. efi_status_t (EFIAPI *get_memory_map)(efi_uintn_t *memory_map_size,
  52. struct efi_mem_desc *desc,
  53. efi_uintn_t *key,
  54. efi_uintn_t *desc_size,
  55. u32 *desc_version);
  56. efi_status_t (EFIAPI *allocate_pool)(int, efi_uintn_t, void **);
  57. efi_status_t (EFIAPI *free_pool)(void *);
  58. efi_status_t (EFIAPI *create_event)(uint32_t type,
  59. efi_uintn_t notify_tpl,
  60. void (EFIAPI *notify_function) (
  61. struct efi_event *event,
  62. void *context),
  63. void *notify_context, struct efi_event **event);
  64. efi_status_t (EFIAPI *set_timer)(struct efi_event *event,
  65. enum efi_timer_delay type,
  66. uint64_t trigger_time);
  67. efi_status_t (EFIAPI *wait_for_event)(efi_uintn_t number_of_events,
  68. struct efi_event **event,
  69. efi_uintn_t *index);
  70. efi_status_t (EFIAPI *signal_event)(struct efi_event *event);
  71. efi_status_t (EFIAPI *close_event)(struct efi_event *event);
  72. efi_status_t (EFIAPI *check_event)(struct efi_event *event);
  73. #define EFI_NATIVE_INTERFACE 0x00000000
  74. efi_status_t (EFIAPI *install_protocol_interface)(
  75. void **handle, const efi_guid_t *protocol,
  76. int protocol_interface_type, void *protocol_interface);
  77. efi_status_t (EFIAPI *reinstall_protocol_interface)(
  78. void *handle, const efi_guid_t *protocol,
  79. void *old_interface, void *new_interface);
  80. efi_status_t (EFIAPI *uninstall_protocol_interface)(
  81. efi_handle_t handle, const efi_guid_t *protocol,
  82. void *protocol_interface);
  83. efi_status_t (EFIAPI *handle_protocol)(
  84. efi_handle_t handle, const efi_guid_t *protocol,
  85. void **protocol_interface);
  86. void *reserved;
  87. efi_status_t (EFIAPI *register_protocol_notify)(
  88. const efi_guid_t *protocol, struct efi_event *event,
  89. void **registration);
  90. efi_status_t (EFIAPI *locate_handle)(
  91. enum efi_locate_search_type search_type,
  92. const efi_guid_t *protocol, void *search_key,
  93. efi_uintn_t *buffer_size, efi_handle_t *buffer);
  94. efi_status_t (EFIAPI *locate_device_path)(const efi_guid_t *protocol,
  95. struct efi_device_path **device_path,
  96. efi_handle_t *device);
  97. efi_status_t (EFIAPI *install_configuration_table)(
  98. efi_guid_t *guid, void *table);
  99. efi_status_t (EFIAPI *load_image)(bool boot_policiy,
  100. efi_handle_t parent_image,
  101. struct efi_device_path *file_path, void *source_buffer,
  102. efi_uintn_t source_size, efi_handle_t *image);
  103. efi_status_t (EFIAPI *start_image)(efi_handle_t handle,
  104. unsigned long *exitdata_size,
  105. s16 **exitdata);
  106. efi_status_t (EFIAPI *exit)(efi_handle_t handle,
  107. efi_status_t exit_status,
  108. unsigned long exitdata_size, s16 *exitdata);
  109. efi_status_t (EFIAPI *unload_image)(efi_handle_t image_handle);
  110. efi_status_t (EFIAPI *exit_boot_services)(efi_handle_t, unsigned long);
  111. efi_status_t (EFIAPI *get_next_monotonic_count)(u64 *count);
  112. efi_status_t (EFIAPI *stall)(unsigned long usecs);
  113. efi_status_t (EFIAPI *set_watchdog_timer)(unsigned long timeout,
  114. uint64_t watchdog_code, unsigned long data_size,
  115. uint16_t *watchdog_data);
  116. efi_status_t(EFIAPI *connect_controller)(efi_handle_t controller_handle,
  117. efi_handle_t *driver_image_handle,
  118. struct efi_device_path *remaining_device_path,
  119. bool recursive);
  120. efi_status_t (EFIAPI *disconnect_controller)(
  121. efi_handle_t controller_handle,
  122. efi_handle_t driver_image_handle,
  123. efi_handle_t child_handle);
  124. #define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001
  125. #define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002
  126. #define EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004
  127. #define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
  128. #define EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010
  129. #define EFI_OPEN_PROTOCOL_EXCLUSIVE 0x00000020
  130. efi_status_t (EFIAPI *open_protocol)(efi_handle_t handle,
  131. const efi_guid_t *protocol, void **interface,
  132. efi_handle_t agent_handle,
  133. efi_handle_t controller_handle, u32 attributes);
  134. efi_status_t (EFIAPI *close_protocol)(
  135. efi_handle_t handle, const efi_guid_t *protocol,
  136. efi_handle_t agent_handle,
  137. efi_handle_t controller_handle);
  138. efi_status_t(EFIAPI *open_protocol_information)(efi_handle_t handle,
  139. const efi_guid_t *protocol,
  140. struct efi_open_protocol_info_entry **entry_buffer,
  141. efi_uintn_t *entry_count);
  142. efi_status_t (EFIAPI *protocols_per_handle)(efi_handle_t handle,
  143. efi_guid_t ***protocol_buffer,
  144. efi_uintn_t *protocols_buffer_count);
  145. efi_status_t (EFIAPI *locate_handle_buffer) (
  146. enum efi_locate_search_type search_type,
  147. const efi_guid_t *protocol, void *search_key,
  148. efi_uintn_t *no_handles, efi_handle_t **buffer);
  149. efi_status_t (EFIAPI *locate_protocol)(const efi_guid_t *protocol,
  150. void *registration, void **protocol_interface);
  151. efi_status_t (EFIAPI *install_multiple_protocol_interfaces)(
  152. void **handle, ...);
  153. efi_status_t (EFIAPI *uninstall_multiple_protocol_interfaces)(
  154. void *handle, ...);
  155. efi_status_t (EFIAPI *calculate_crc32)(const void *data,
  156. efi_uintn_t data_size,
  157. u32 *crc32);
  158. void (EFIAPI *copy_mem)(void *destination, const void *source,
  159. size_t length);
  160. void (EFIAPI *set_mem)(void *buffer, size_t size, uint8_t value);
  161. efi_status_t (EFIAPI *create_event_ex)(
  162. uint32_t type, efi_uintn_t notify_tpl,
  163. void (EFIAPI *notify_function) (
  164. struct efi_event *event,
  165. void *context),
  166. void *notify_context,
  167. efi_guid_t *event_group,
  168. struct efi_event **event);
  169. };
  170. /* Types and defines for EFI ResetSystem */
  171. enum efi_reset_type {
  172. EFI_RESET_COLD = 0,
  173. EFI_RESET_WARM = 1,
  174. EFI_RESET_SHUTDOWN = 2,
  175. EFI_RESET_PLATFORM_SPECIFIC = 3,
  176. };
  177. /* EFI Runtime Services table */
  178. #define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552ULL
  179. #define CAPSULE_FLAGS_PERSIST_ACROSS_RESET 0x00010000
  180. #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000
  181. #define CAPSULE_FLAGS_INITIATE_RESET 0x00040000
  182. struct efi_capsule_header {
  183. efi_guid_t *capsule_guid;
  184. u32 header_size;
  185. u32 flags;
  186. u32 capsule_image_size;
  187. };
  188. struct efi_runtime_services {
  189. struct efi_table_hdr hdr;
  190. efi_status_t (EFIAPI *get_time)(struct efi_time *time,
  191. struct efi_time_cap *capabilities);
  192. efi_status_t (EFIAPI *set_time)(struct efi_time *time);
  193. efi_status_t (EFIAPI *get_wakeup_time)(char *enabled, char *pending,
  194. struct efi_time *time);
  195. efi_status_t (EFIAPI *set_wakeup_time)(char enabled,
  196. struct efi_time *time);
  197. efi_status_t (EFIAPI *set_virtual_address_map)(
  198. unsigned long memory_map_size,
  199. unsigned long descriptor_size,
  200. uint32_t descriptor_version,
  201. struct efi_mem_desc *virtmap);
  202. efi_status_t (*convert_pointer)(unsigned long dbg, void **address);
  203. efi_status_t (EFIAPI *get_variable)(u16 *variable_name,
  204. efi_guid_t *vendor, u32 *attributes,
  205. efi_uintn_t *data_size, void *data);
  206. efi_status_t (EFIAPI *get_next_variable_name)(
  207. efi_uintn_t *variable_name_size,
  208. u16 *variable_name, efi_guid_t *vendor);
  209. efi_status_t (EFIAPI *set_variable)(u16 *variable_name,
  210. efi_guid_t *vendor, u32 attributes,
  211. efi_uintn_t data_size, void *data);
  212. efi_status_t (EFIAPI *get_next_high_mono_count)(
  213. uint32_t *high_count);
  214. void (EFIAPI *reset_system)(enum efi_reset_type reset_type,
  215. efi_status_t reset_status,
  216. unsigned long data_size, void *reset_data);
  217. efi_status_t (EFIAPI *update_capsule)(
  218. struct efi_capsule_header **capsule_header_array,
  219. efi_uintn_t capsule_count,
  220. u64 scatter_gather_list);
  221. efi_status_t (EFIAPI *query_capsule_caps)(
  222. struct efi_capsule_header **capsule_header_array,
  223. efi_uintn_t capsule_count,
  224. u64 maximum_capsule_size,
  225. u32 reset_type);
  226. efi_status_t (EFIAPI *query_variable_info)(
  227. u32 attributes,
  228. u64 *maximum_variable_storage_size,
  229. u64 *remaining_variable_storage_size,
  230. u64 *maximum_variable_size);
  231. };
  232. /* EFI event group GUID definitions */
  233. #define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
  234. EFI_GUID(0x27abf055, 0xb1b8, 0x4c26, 0x80, 0x48, \
  235. 0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf)
  236. #define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
  237. EFI_GUID(0x13fa7698, 0xc831, 0x49c7, 0x87, 0xea, \
  238. 0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96)
  239. #define EFI_EVENT_GROUP_MEMORY_MAP_CHANGE \
  240. EFI_GUID(0x78bee926, 0x692f, 0x48fd, 0x9e, 0xdb, \
  241. 0x01, 0x42, 0x2e, 0xf0, 0xd7, 0xab)
  242. #define EFI_EVENT_GROUP_READY_TO_BOOT \
  243. EFI_GUID(0x7ce88fb3, 0x4bd7, 0x4679, 0x87, 0xa8, \
  244. 0xa8, 0xd8, 0xde, 0xe5, 0x0d, 0x2b)
  245. #define EFI_EVENT_GROUP_RESET_SYSTEM \
  246. EFI_GUID(0x62da6a56, 0x13fb, 0x485a, 0xa8, 0xda, \
  247. 0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b)
  248. /* EFI Configuration Table and GUID definitions */
  249. #define NULL_GUID \
  250. EFI_GUID(0x00000000, 0x0000, 0x0000, 0x00, 0x00, \
  251. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
  252. #define EFI_GLOBAL_VARIABLE_GUID \
  253. EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, \
  254. 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)
  255. #define LOADED_IMAGE_PROTOCOL_GUID \
  256. EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, \
  257. 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  258. #define EFI_FDT_GUID \
  259. EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, \
  260. 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0)
  261. #define EFI_ACPI_TABLE_GUID \
  262. EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, \
  263. 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)
  264. #define SMBIOS_TABLE_GUID \
  265. EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, \
  266. 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  267. struct efi_configuration_table
  268. {
  269. efi_guid_t guid;
  270. void *table;
  271. };
  272. #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL)
  273. struct efi_system_table {
  274. struct efi_table_hdr hdr;
  275. u16 *fw_vendor; /* physical addr of wchar_t vendor string */
  276. u32 fw_revision;
  277. efi_handle_t con_in_handle;
  278. struct efi_simple_input_interface *con_in;
  279. efi_handle_t con_out_handle;
  280. struct efi_simple_text_output_protocol *con_out;
  281. efi_handle_t stderr_handle;
  282. struct efi_simple_text_output_protocol *std_err;
  283. struct efi_runtime_services *runtime;
  284. struct efi_boot_services *boottime;
  285. efi_uintn_t nr_tables;
  286. struct efi_configuration_table *tables;
  287. };
  288. #define LOADED_IMAGE_GUID \
  289. EFI_GUID(0x5b1b31a1, 0x9562, 0x11d2, \
  290. 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  291. #define EFI_LOADED_IMAGE_PROTOCOL_REVISION 0x1000
  292. struct efi_loaded_image {
  293. u32 revision;
  294. void *parent_handle;
  295. struct efi_system_table *system_table;
  296. efi_handle_t device_handle;
  297. struct efi_device_path *file_path;
  298. void *reserved;
  299. u32 load_options_size;
  300. void *load_options;
  301. void *image_base;
  302. aligned_u64 image_size;
  303. unsigned int image_code_type;
  304. unsigned int image_data_type;
  305. unsigned long unload;
  306. /* Below are efi loader private fields */
  307. #ifdef CONFIG_EFI_LOADER
  308. void *reloc_base;
  309. aligned_u64 reloc_size;
  310. efi_status_t exit_status;
  311. struct jmp_buf_data exit_jmp;
  312. #endif
  313. };
  314. #define DEVICE_PATH_GUID \
  315. EFI_GUID(0x09576e91, 0x6d3f, 0x11d2, \
  316. 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b )
  317. #define DEVICE_PATH_TYPE_END 0x7f
  318. # define DEVICE_PATH_SUB_TYPE_INSTANCE_END 0x01
  319. # define DEVICE_PATH_SUB_TYPE_END 0xff
  320. struct efi_device_path {
  321. u8 type;
  322. u8 sub_type;
  323. u16 length;
  324. } __packed;
  325. struct efi_mac_addr {
  326. u8 addr[32];
  327. } __packed;
  328. #define DEVICE_PATH_TYPE_HARDWARE_DEVICE 0x01
  329. # define DEVICE_PATH_SUB_TYPE_MEMORY 0x03
  330. # define DEVICE_PATH_SUB_TYPE_VENDOR 0x04
  331. struct efi_device_path_memory {
  332. struct efi_device_path dp;
  333. u32 memory_type;
  334. u64 start_address;
  335. u64 end_address;
  336. } __packed;
  337. struct efi_device_path_vendor {
  338. struct efi_device_path dp;
  339. efi_guid_t guid;
  340. u8 vendor_data[];
  341. } __packed;
  342. #define DEVICE_PATH_TYPE_ACPI_DEVICE 0x02
  343. # define DEVICE_PATH_SUB_TYPE_ACPI_DEVICE 0x01
  344. #define EFI_PNP_ID(ID) (u32)(((ID) << 16) | 0x41D0)
  345. #define EISA_PNP_ID(ID) EFI_PNP_ID(ID)
  346. #define EISA_PNP_NUM(ID) ((ID) >> 16)
  347. struct efi_device_path_acpi_path {
  348. struct efi_device_path dp;
  349. u32 hid;
  350. u32 uid;
  351. } __packed;
  352. #define DEVICE_PATH_TYPE_MESSAGING_DEVICE 0x03
  353. # define DEVICE_PATH_SUB_TYPE_MSG_ATAPI 0x01
  354. # define DEVICE_PATH_SUB_TYPE_MSG_SCSI 0x02
  355. # define DEVICE_PATH_SUB_TYPE_MSG_USB 0x05
  356. # define DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR 0x0b
  357. # define DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS 0x0f
  358. # define DEVICE_PATH_SUB_TYPE_MSG_SD 0x1a
  359. # define DEVICE_PATH_SUB_TYPE_MSG_MMC 0x1d
  360. struct efi_device_path_atapi {
  361. struct efi_device_path dp;
  362. u8 primary_secondary;
  363. u8 slave_master;
  364. u16 logical_unit_number;
  365. } __packed;
  366. struct efi_device_path_scsi {
  367. struct efi_device_path dp;
  368. u16 target_id;
  369. u16 logical_unit_number;
  370. } __packed;
  371. struct efi_device_path_usb {
  372. struct efi_device_path dp;
  373. u8 parent_port_number;
  374. u8 usb_interface;
  375. } __packed;
  376. struct efi_device_path_mac_addr {
  377. struct efi_device_path dp;
  378. struct efi_mac_addr mac;
  379. u8 if_type;
  380. } __packed;
  381. struct efi_device_path_usb_class {
  382. struct efi_device_path dp;
  383. u16 vendor_id;
  384. u16 product_id;
  385. u8 device_class;
  386. u8 device_subclass;
  387. u8 device_protocol;
  388. } __packed;
  389. struct efi_device_path_sd_mmc_path {
  390. struct efi_device_path dp;
  391. u8 slot_number;
  392. } __packed;
  393. #define DEVICE_PATH_TYPE_MEDIA_DEVICE 0x04
  394. # define DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH 0x01
  395. # define DEVICE_PATH_SUB_TYPE_CDROM_PATH 0x02
  396. # define DEVICE_PATH_SUB_TYPE_FILE_PATH 0x04
  397. struct efi_device_path_hard_drive_path {
  398. struct efi_device_path dp;
  399. u32 partition_number;
  400. u64 partition_start;
  401. u64 partition_end;
  402. u8 partition_signature[16];
  403. u8 partmap_type;
  404. u8 signature_type;
  405. } __packed;
  406. struct efi_device_path_cdrom_path {
  407. struct efi_device_path dp;
  408. u32 boot_entry;
  409. u64 partition_start;
  410. u64 partition_end;
  411. } __packed;
  412. struct efi_device_path_file_path {
  413. struct efi_device_path dp;
  414. u16 str[];
  415. } __packed;
  416. #define BLOCK_IO_GUID \
  417. EFI_GUID(0x964e5b21, 0x6459, 0x11d2, \
  418. 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  419. struct efi_block_io_media
  420. {
  421. u32 media_id;
  422. char removable_media;
  423. char media_present;
  424. char logical_partition;
  425. char read_only;
  426. char write_caching;
  427. u8 pad[3];
  428. u32 block_size;
  429. u32 io_align;
  430. u8 pad2[4];
  431. u64 last_block;
  432. /* Added in revision 2 of the protocol */
  433. u64 lowest_aligned_lba;
  434. u32 logical_blocks_per_physical_block;
  435. /* Added in revision 3 of the protocol */
  436. u32 optimal_transfer_length_granualarity;
  437. };
  438. #define EFI_BLOCK_IO_PROTOCOL_REVISION2 0x00020001
  439. #define EFI_BLOCK_IO_PROTOCOL_REVISION3 0x0002001f
  440. struct efi_block_io {
  441. u64 revision;
  442. struct efi_block_io_media *media;
  443. efi_status_t (EFIAPI *reset)(struct efi_block_io *this,
  444. char extended_verification);
  445. efi_status_t (EFIAPI *read_blocks)(struct efi_block_io *this,
  446. u32 media_id, u64 lba, efi_uintn_t buffer_size,
  447. void *buffer);
  448. efi_status_t (EFIAPI *write_blocks)(struct efi_block_io *this,
  449. u32 media_id, u64 lba, efi_uintn_t buffer_size,
  450. void *buffer);
  451. efi_status_t (EFIAPI *flush_blocks)(struct efi_block_io *this);
  452. };
  453. struct simple_text_output_mode {
  454. s32 max_mode;
  455. s32 mode;
  456. s32 attribute;
  457. s32 cursor_column;
  458. s32 cursor_row;
  459. bool cursor_visible;
  460. };
  461. #define EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID \
  462. EFI_GUID(0x387477c2, 0x69c7, 0x11d2, \
  463. 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  464. #define EFI_BLACK 0x00
  465. #define EFI_BLUE 0x01
  466. #define EFI_GREEN 0x02
  467. #define EFI_CYAN 0x03
  468. #define EFI_RED 0x04
  469. #define EFI_MAGENTA 0x05
  470. #define EFI_BROWN 0x06
  471. #define EFI_LIGHTGRAY 0x07
  472. #define EFI_BRIGHT 0x08
  473. #define EFI_DARKGRAY 0x08
  474. #define EFI_LIGHTBLUE 0x09
  475. #define EFI_LIGHTGREEN 0x0a
  476. #define EFI_LIGHTCYAN 0x0b
  477. #define EFI_LIGHTRED 0x0c
  478. #define EFI_LIGHTMAGENTA 0x0d
  479. #define EFI_YELLOW 0x0e
  480. #define EFI_WHITE 0x0f
  481. #define EFI_BACKGROUND_BLACK 0x00
  482. #define EFI_BACKGROUND_BLUE 0x10
  483. #define EFI_BACKGROUND_GREEN 0x20
  484. #define EFI_BACKGROUND_CYAN 0x30
  485. #define EFI_BACKGROUND_RED 0x40
  486. #define EFI_BACKGROUND_MAGENTA 0x50
  487. #define EFI_BACKGROUND_BROWN 0x60
  488. #define EFI_BACKGROUND_LIGHTGRAY 0x70
  489. /* extract foreground color from EFI attribute */
  490. #define EFI_ATTR_FG(attr) ((attr) & 0x07)
  491. /* treat high bit of FG as bright/bold (similar to edk2) */
  492. #define EFI_ATTR_BOLD(attr) (((attr) >> 3) & 0x01)
  493. /* extract background color from EFI attribute */
  494. #define EFI_ATTR_BG(attr) (((attr) >> 4) & 0x7)
  495. struct efi_simple_text_output_protocol {
  496. void *reset;
  497. efi_status_t (EFIAPI *output_string)(
  498. struct efi_simple_text_output_protocol *this,
  499. const efi_string_t str);
  500. efi_status_t (EFIAPI *test_string)(
  501. struct efi_simple_text_output_protocol *this,
  502. const efi_string_t str);
  503. efi_status_t(EFIAPI *query_mode)(
  504. struct efi_simple_text_output_protocol *this,
  505. unsigned long mode_number, unsigned long *columns,
  506. unsigned long *rows);
  507. efi_status_t(EFIAPI *set_mode)(
  508. struct efi_simple_text_output_protocol *this,
  509. unsigned long mode_number);
  510. efi_status_t(EFIAPI *set_attribute)(
  511. struct efi_simple_text_output_protocol *this,
  512. unsigned long attribute);
  513. efi_status_t(EFIAPI *clear_screen) (
  514. struct efi_simple_text_output_protocol *this);
  515. efi_status_t(EFIAPI *set_cursor_position) (
  516. struct efi_simple_text_output_protocol *this,
  517. unsigned long column, unsigned long row);
  518. efi_status_t(EFIAPI *enable_cursor)(
  519. struct efi_simple_text_output_protocol *this,
  520. bool enable);
  521. struct simple_text_output_mode *mode;
  522. };
  523. struct efi_input_key {
  524. u16 scan_code;
  525. s16 unicode_char;
  526. };
  527. #define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \
  528. EFI_GUID(0x387477c1, 0x69c7, 0x11d2, \
  529. 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  530. struct efi_simple_input_interface {
  531. efi_status_t(EFIAPI *reset)(struct efi_simple_input_interface *this,
  532. bool ExtendedVerification);
  533. efi_status_t(EFIAPI *read_key_stroke)(
  534. struct efi_simple_input_interface *this,
  535. struct efi_input_key *key);
  536. struct efi_event *wait_for_key;
  537. };
  538. #define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID \
  539. EFI_GUID(0x8b843e20, 0x8132, 0x4852, \
  540. 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c)
  541. struct efi_device_path_to_text_protocol
  542. {
  543. uint16_t *(EFIAPI *convert_device_node_to_text)(
  544. struct efi_device_path *device_node,
  545. bool display_only,
  546. bool allow_shortcuts);
  547. uint16_t *(EFIAPI *convert_device_path_to_text)(
  548. struct efi_device_path *device_path,
  549. bool display_only,
  550. bool allow_shortcuts);
  551. };
  552. #define EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID \
  553. EFI_GUID(0x0379be4e, 0xd706, 0x437d, \
  554. 0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4)
  555. struct efi_device_path_utilities_protocol {
  556. efi_uintn_t (EFIAPI *get_device_path_size)(
  557. const struct efi_device_path *device_path);
  558. struct efi_device_path *(EFIAPI *duplicate_device_path)(
  559. const struct efi_device_path *device_path);
  560. struct efi_device_path *(EFIAPI *append_device_path)(
  561. const struct efi_device_path *src1,
  562. const struct efi_device_path *src2);
  563. struct efi_device_path *(EFIAPI *append_device_node)(
  564. const struct efi_device_path *device_path,
  565. const struct efi_device_path *device_node);
  566. struct efi_device_path *(EFIAPI *append_device_path_instance)(
  567. const struct efi_device_path *device_path,
  568. const struct efi_device_path *device_path_instance);
  569. struct efi_device_path *(EFIAPI *get_next_device_path_instance)(
  570. struct efi_device_path **device_path_instance,
  571. efi_uintn_t *device_path_instance_size);
  572. bool (EFIAPI *is_device_path_multi_instance)(
  573. const struct efi_device_path *device_path);
  574. struct efi_device_path *(EFIAPI *create_device_node)(
  575. uint8_t node_type,
  576. uint8_t node_sub_type,
  577. uint16_t node_length);
  578. };
  579. #define EFI_GOP_GUID \
  580. EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, \
  581. 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
  582. #define EFI_GOT_RGBA8 0
  583. #define EFI_GOT_BGRA8 1
  584. #define EFI_GOT_BITMASK 2
  585. struct efi_gop_mode_info
  586. {
  587. u32 version;
  588. u32 width;
  589. u32 height;
  590. u32 pixel_format;
  591. u32 pixel_bitmask[4];
  592. u32 pixels_per_scanline;
  593. };
  594. struct efi_gop_mode
  595. {
  596. u32 max_mode;
  597. u32 mode;
  598. struct efi_gop_mode_info *info;
  599. unsigned long info_size;
  600. efi_physical_addr_t fb_base;
  601. unsigned long fb_size;
  602. };
  603. struct efi_gop_pixel {
  604. u8 blue;
  605. u8 green;
  606. u8 red;
  607. u8 reserved;
  608. };
  609. #define EFI_BLT_VIDEO_FILL 0
  610. #define EFI_BLT_VIDEO_TO_BLT_BUFFER 1
  611. #define EFI_BLT_BUFFER_TO_VIDEO 2
  612. #define EFI_BLT_VIDEO_TO_VIDEO 3
  613. struct efi_gop
  614. {
  615. efi_status_t (EFIAPI *query_mode)(struct efi_gop *this, u32 mode_number,
  616. efi_uintn_t *size_of_info,
  617. struct efi_gop_mode_info **info);
  618. efi_status_t (EFIAPI *set_mode)(struct efi_gop *this, u32 mode_number);
  619. efi_status_t (EFIAPI *blt)(struct efi_gop *this,
  620. struct efi_gop_pixel *buffer,
  621. u32 operation, efi_uintn_t sx,
  622. efi_uintn_t sy, efi_uintn_t dx,
  623. efi_uintn_t dy, efi_uintn_t width,
  624. efi_uintn_t height, efi_uintn_t delta);
  625. struct efi_gop_mode *mode;
  626. };
  627. #define EFI_SIMPLE_NETWORK_GUID \
  628. EFI_GUID(0xa19832b9, 0xac25, 0x11d3, \
  629. 0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  630. struct efi_mac_address {
  631. char mac_addr[32];
  632. };
  633. struct efi_ip_address {
  634. u8 ip_addr[16];
  635. } __attribute__((aligned(4)));
  636. enum efi_simple_network_state {
  637. EFI_NETWORK_STOPPED,
  638. EFI_NETWORK_STARTED,
  639. EFI_NETWORK_INITIALIZED,
  640. };
  641. struct efi_simple_network_mode {
  642. enum efi_simple_network_state state;
  643. u32 hwaddr_size;
  644. u32 media_header_size;
  645. u32 max_packet_size;
  646. u32 nvram_size;
  647. u32 nvram_access_size;
  648. u32 receive_filter_mask;
  649. u32 receive_filter_setting;
  650. u32 max_mcast_filter_count;
  651. u32 mcast_filter_count;
  652. struct efi_mac_address mcast_filter[16];
  653. struct efi_mac_address current_address;
  654. struct efi_mac_address broadcast_address;
  655. struct efi_mac_address permanent_address;
  656. u8 if_type;
  657. u8 mac_changeable;
  658. u8 multitx_supported;
  659. u8 media_present_supported;
  660. u8 media_present;
  661. };
  662. /* receive_filters bit mask */
  663. #define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST 0x01
  664. #define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST 0x02
  665. #define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST 0x04
  666. #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS 0x08
  667. #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10
  668. /* interrupt status bit mask */
  669. #define EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT 0x01
  670. #define EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT 0x02
  671. #define EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT 0x04
  672. #define EFI_SIMPLE_NETWORK_SOFTWARE_INTERRUPT 0x08
  673. /* revision of the simple network protocol */
  674. #define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION 0x00010000
  675. struct efi_simple_network
  676. {
  677. u64 revision;
  678. efi_status_t (EFIAPI *start)(struct efi_simple_network *this);
  679. efi_status_t (EFIAPI *stop)(struct efi_simple_network *this);
  680. efi_status_t (EFIAPI *initialize)(struct efi_simple_network *this,
  681. ulong extra_rx, ulong extra_tx);
  682. efi_status_t (EFIAPI *reset)(struct efi_simple_network *this,
  683. int extended_verification);
  684. efi_status_t (EFIAPI *shutdown)(struct efi_simple_network *this);
  685. efi_status_t (EFIAPI *receive_filters)(struct efi_simple_network *this,
  686. u32 enable, u32 disable, int reset_mcast_filter,
  687. ulong mcast_filter_count,
  688. struct efi_mac_address *mcast_filter);
  689. efi_status_t (EFIAPI *station_address)(struct efi_simple_network *this,
  690. int reset, struct efi_mac_address *new_mac);
  691. efi_status_t (EFIAPI *statistics)(struct efi_simple_network *this,
  692. int reset, ulong *stat_size, void *stat_table);
  693. efi_status_t (EFIAPI *mcastiptomac)(struct efi_simple_network *this,
  694. int ipv6, struct efi_ip_address *ip,
  695. struct efi_mac_address *mac);
  696. efi_status_t (EFIAPI *nvdata)(struct efi_simple_network *this,
  697. int read_write, ulong offset, ulong buffer_size,
  698. char *buffer);
  699. efi_status_t (EFIAPI *get_status)(struct efi_simple_network *this,
  700. u32 *int_status, void **txbuf);
  701. efi_status_t (EFIAPI *transmit)(struct efi_simple_network *this,
  702. size_t header_size, size_t buffer_size, void *buffer,
  703. struct efi_mac_address *src_addr,
  704. struct efi_mac_address *dest_addr, u16 *protocol);
  705. efi_status_t (EFIAPI *receive)(struct efi_simple_network *this,
  706. size_t *header_size, size_t *buffer_size, void *buffer,
  707. struct efi_mac_address *src_addr,
  708. struct efi_mac_address *dest_addr, u16 *protocol);
  709. struct efi_event *wait_for_packet;
  710. struct efi_simple_network_mode *mode;
  711. };
  712. #define EFI_PXE_GUID \
  713. EFI_GUID(0x03c4e603, 0xac28, 0x11d3, \
  714. 0x9a, 0x2d, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
  715. struct efi_pxe_packet {
  716. u8 packet[1472];
  717. };
  718. struct efi_pxe_mode
  719. {
  720. u8 started;
  721. u8 ipv6_available;
  722. u8 ipv6_supported;
  723. u8 using_ipv6;
  724. u8 bis_supported;
  725. u8 bis_detected;
  726. u8 auto_arp;
  727. u8 send_guid;
  728. u8 dhcp_discover_valid;
  729. u8 dhcp_ack_received;
  730. u8 proxy_offer_received;
  731. u8 pxe_discover_valid;
  732. u8 pxe_reply_received;
  733. u8 pxe_bis_reply_received;
  734. u8 icmp_error_received;
  735. u8 tftp_error_received;
  736. u8 make_callbacks;
  737. u8 ttl;
  738. u8 tos;
  739. u8 pad;
  740. struct efi_ip_address station_ip;
  741. struct efi_ip_address subnet_mask;
  742. struct efi_pxe_packet dhcp_discover;
  743. struct efi_pxe_packet dhcp_ack;
  744. struct efi_pxe_packet proxy_offer;
  745. struct efi_pxe_packet pxe_discover;
  746. struct efi_pxe_packet pxe_reply;
  747. };
  748. struct efi_pxe {
  749. u64 rev;
  750. void (EFIAPI *start)(void);
  751. void (EFIAPI *stop)(void);
  752. void (EFIAPI *dhcp)(void);
  753. void (EFIAPI *discover)(void);
  754. void (EFIAPI *mftp)(void);
  755. void (EFIAPI *udpwrite)(void);
  756. void (EFIAPI *udpread)(void);
  757. void (EFIAPI *setipfilter)(void);
  758. void (EFIAPI *arp)(void);
  759. void (EFIAPI *setparams)(void);
  760. void (EFIAPI *setstationip)(void);
  761. void (EFIAPI *setpackets)(void);
  762. struct efi_pxe_mode *mode;
  763. };
  764. #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
  765. EFI_GUID(0x964e5b22, 0x6459, 0x11d2, \
  766. 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  767. #define EFI_FILE_PROTOCOL_REVISION 0x00010000
  768. struct efi_file_handle {
  769. u64 rev;
  770. efi_status_t (EFIAPI *open)(struct efi_file_handle *file,
  771. struct efi_file_handle **new_handle,
  772. s16 *file_name, u64 open_mode, u64 attributes);
  773. efi_status_t (EFIAPI *close)(struct efi_file_handle *file);
  774. efi_status_t (EFIAPI *delete)(struct efi_file_handle *file);
  775. efi_status_t (EFIAPI *read)(struct efi_file_handle *file,
  776. efi_uintn_t *buffer_size, void *buffer);
  777. efi_status_t (EFIAPI *write)(struct efi_file_handle *file,
  778. efi_uintn_t *buffer_size, void *buffer);
  779. efi_status_t (EFIAPI *getpos)(struct efi_file_handle *file,
  780. efi_uintn_t *pos);
  781. efi_status_t (EFIAPI *setpos)(struct efi_file_handle *file,
  782. efi_uintn_t pos);
  783. efi_status_t (EFIAPI *getinfo)(struct efi_file_handle *file,
  784. const efi_guid_t *info_type, efi_uintn_t *buffer_size,
  785. void *buffer);
  786. efi_status_t (EFIAPI *setinfo)(struct efi_file_handle *file,
  787. const efi_guid_t *info_type, efi_uintn_t buffer_size,
  788. void *buffer);
  789. efi_status_t (EFIAPI *flush)(struct efi_file_handle *file);
  790. };
  791. #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
  792. EFI_GUID(0x964e5b22, 0x6459, 0x11d2, \
  793. 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  794. #define EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION 0x00010000
  795. struct efi_simple_file_system_protocol {
  796. u64 rev;
  797. efi_status_t (EFIAPI *open_volume)(struct efi_simple_file_system_protocol *this,
  798. struct efi_file_handle **root);
  799. };
  800. #define EFI_FILE_INFO_GUID \
  801. EFI_GUID(0x9576e92, 0x6d3f, 0x11d2, \
  802. 0x8e, 0x39, 0x0, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  803. #define EFI_FILE_SYSTEM_INFO_GUID \
  804. EFI_GUID(0x09576e93, 0x6d3f, 0x11d2, \
  805. 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
  806. #define EFI_FILE_MODE_READ 0x0000000000000001
  807. #define EFI_FILE_MODE_WRITE 0x0000000000000002
  808. #define EFI_FILE_MODE_CREATE 0x8000000000000000
  809. #define EFI_FILE_READ_ONLY 0x0000000000000001
  810. #define EFI_FILE_HIDDEN 0x0000000000000002
  811. #define EFI_FILE_SYSTEM 0x0000000000000004
  812. #define EFI_FILE_RESERVED 0x0000000000000008
  813. #define EFI_FILE_DIRECTORY 0x0000000000000010
  814. #define EFI_FILE_ARCHIVE 0x0000000000000020
  815. #define EFI_FILE_VALID_ATTR 0x0000000000000037
  816. struct efi_file_info {
  817. u64 size;
  818. u64 file_size;
  819. u64 physical_size;
  820. struct efi_time create_time;
  821. struct efi_time last_access_time;
  822. struct efi_time modification_time;
  823. u64 attribute;
  824. s16 file_name[0];
  825. };
  826. struct efi_file_system_info {
  827. u64 size;
  828. u8 read_only;
  829. u64 volume_size;
  830. u64 free_space;
  831. u32 block_size;
  832. u16 volume_label[0];
  833. };
  834. #define EFI_DRIVER_BINDING_PROTOCOL_GUID \
  835. EFI_GUID(0x18a031ab, 0xb443, 0x4d1a,\
  836. 0xa5, 0xc0, 0x0c, 0x09, 0x26, 0x1e, 0x9f, 0x71)
  837. struct efi_driver_binding_protocol {
  838. efi_status_t (EFIAPI * supported)(
  839. struct efi_driver_binding_protocol *this,
  840. efi_handle_t controller_handle,
  841. struct efi_device_path *remaining_device_path);
  842. efi_status_t (EFIAPI * start)(
  843. struct efi_driver_binding_protocol *this,
  844. efi_handle_t controller_handle,
  845. struct efi_device_path *remaining_device_path);
  846. efi_status_t (EFIAPI * stop)(
  847. struct efi_driver_binding_protocol *this,
  848. efi_handle_t controller_handle,
  849. efi_uintn_t number_of_children,
  850. efi_handle_t *child_handle_buffer);
  851. u32 version;
  852. efi_handle_t image_handle;
  853. efi_handle_t driver_binding_handle;
  854. };
  855. #define EFI_UNICODE_COLLATION_PROTOCOL2_GUID \
  856. EFI_GUID(0xa4c751fc, 0x23ae, 0x4c3e, \
  857. 0x92, 0xe9, 0x49, 0x64, 0xcf, 0x63, 0xf3, 0x49)
  858. struct efi_unicode_collation_protocol {
  859. efi_intn_t (EFIAPI *stri_coll)(
  860. struct efi_unicode_collation_protocol *this, u16 *s1, u16 *s2);
  861. bool (EFIAPI *metai_match)(struct efi_unicode_collation_protocol *this,
  862. const u16 *string, const u16 *patter);
  863. void (EFIAPI *str_lwr)(struct efi_unicode_collation_protocol
  864. *this, u16 *string);
  865. void (EFIAPI *str_upr)(struct efi_unicode_collation_protocol *this,
  866. u16 *string);
  867. void (EFIAPI *fat_to_str)(struct efi_unicode_collation_protocol *this,
  868. efi_uintn_t fat_size, char *fat, u16 *string);
  869. bool (EFIAPI *str_to_fat)(struct efi_unicode_collation_protocol *this,
  870. const u16 *string, efi_uintn_t fat_size,
  871. char *fat);
  872. char *supported_languages;
  873. };
  874. #endif