efi_api.h 29 KB

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