efi_api.h 29 KB

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