efi_api.h 29 KB

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