efi_api.h 28 KB

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