You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

efi.h 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #ifndef _IPXE_EFI_H
  2. #define _IPXE_EFI_H
  3. /** @file
  4. *
  5. * EFI API
  6. *
  7. * The intention is to include near-verbatim copies of the EFI headers
  8. * required by iPXE. This is achieved using the import.pl script in
  9. * this directory. Run the import script to update the local copies
  10. * of the headers:
  11. *
  12. * ./import.pl /path/to/edk2/edk2
  13. *
  14. * where /path/to/edk2/edk2 is the path to your local checkout of the
  15. * EFI Development Kit.
  16. *
  17. * Note that import.pl will modify any #include lines in each imported
  18. * header to reflect its new location within the iPXE tree. It will
  19. * also tidy up the file by removing carriage return characters and
  20. * trailing whitespace.
  21. */
  22. FILE_LICENCE ( GPL2_OR_LATER );
  23. /* EFI headers rudely redefine NULL */
  24. #undef NULL
  25. /* EFI headers redefine ARRAY_SIZE */
  26. #undef ARRAY_SIZE
  27. /* EFI headers expect ICC to define __GNUC__ */
  28. #if defined ( __ICC ) && ! defined ( __GNUC__ )
  29. #define __GNUC__ 1
  30. #endif
  31. /* EFI headers think your compiler uses the MS ABI by default on X64 */
  32. #if __x86_64__
  33. #define EFIAPI __attribute__((ms_abi))
  34. #endif
  35. /* EFI headers assume regparm(0) on i386, but that is not the case for iPXE */
  36. #if __i386__
  37. #define EFIAPI __attribute__((cdecl,regparm(0)))
  38. #endif
  39. /* EFI headers define EFI_HANDLE as a void pointer, which renders type
  40. * checking somewhat useless. Work around this bizarre sabotage
  41. * attempt by redefining EFI_HANDLE as a pointer to an anonymous
  42. * structure.
  43. */
  44. #define EFI_HANDLE STUPID_EFI_HANDLE
  45. #include <ipxe/efi/Uefi/UefiBaseType.h>
  46. #undef EFI_HANDLE
  47. typedef struct {} *EFI_HANDLE;
  48. /* Include the top-level EFI header files */
  49. #include <ipxe/efi/Uefi.h>
  50. #include <ipxe/efi/PiDxe.h>
  51. #include <ipxe/efi/Protocol/LoadedImage.h>
  52. /* Reset any trailing #pragma pack directives */
  53. #pragma pack(1)
  54. #pragma pack()
  55. #include <ipxe/tables.h>
  56. #include <ipxe/uuid.h>
  57. /** An EFI protocol used by iPXE */
  58. struct efi_protocol {
  59. /** GUID */
  60. EFI_GUID guid;
  61. /** Variable containing pointer to protocol structure */
  62. void **protocol;
  63. /** Protocol is required */
  64. int required;
  65. };
  66. /** EFI protocol table */
  67. #define EFI_PROTOCOLS __table ( struct efi_protocol, "efi_protocols" )
  68. /** Declare an EFI protocol used by iPXE */
  69. #define __efi_protocol __table_entry ( EFI_PROTOCOLS, 01 )
  70. /** Declare an EFI protocol to be required by iPXE
  71. *
  72. * @v _protocol EFI protocol name
  73. * @v _ptr Pointer to protocol instance
  74. */
  75. #define EFI_REQUIRE_PROTOCOL( _protocol, _ptr ) \
  76. struct efi_protocol __ ## _protocol __efi_protocol = { \
  77. .guid = _protocol ## _GUID, \
  78. .protocol = ( ( void ** ) ( void * ) \
  79. ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ? \
  80. (_ptr) : (_ptr) ) ), \
  81. .required = 1, \
  82. }
  83. /** Declare an EFI protocol to be requested by iPXE
  84. *
  85. * @v _protocol EFI protocol name
  86. * @v _ptr Pointer to protocol instance
  87. */
  88. #define EFI_REQUEST_PROTOCOL( _protocol, _ptr ) \
  89. struct efi_protocol __ ## _protocol __efi_protocol = { \
  90. .guid = _protocol ## _GUID, \
  91. .protocol = ( ( void ** ) ( void * ) \
  92. ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ? \
  93. (_ptr) : (_ptr) ) ), \
  94. .required = 0, \
  95. }
  96. /** An EFI configuration table used by iPXE */
  97. struct efi_config_table {
  98. /** GUID */
  99. EFI_GUID guid;
  100. /** Variable containing pointer to configuration table */
  101. void **table;
  102. /** Table is required for operation */
  103. int required;
  104. };
  105. /** EFI configuration table table */
  106. #define EFI_CONFIG_TABLES \
  107. __table ( struct efi_config_table, "efi_config_tables" )
  108. /** Declare an EFI configuration table used by iPXE */
  109. #define __efi_config_table __table_entry ( EFI_CONFIG_TABLES, 01 )
  110. /** Declare an EFI configuration table to be used by iPXE
  111. *
  112. * @v _table EFI configuration table name
  113. * @v _ptr Pointer to configuration table
  114. * @v _required Table is required for operation
  115. */
  116. #define EFI_USE_TABLE( _table, _ptr, _required ) \
  117. struct efi_config_table __ ## _table __efi_config_table = { \
  118. .guid = _table ## _GUID, \
  119. .table = ( ( void ** ) ( void * ) (_ptr) ), \
  120. .required = (_required), \
  121. }
  122. /**
  123. * Convert an iPXE status code to an EFI status code
  124. *
  125. * @v rc iPXE status code
  126. * @ret efirc EFI status code
  127. */
  128. #define EFIRC( rc ) ERRNO_TO_PLATFORM ( -(rc) )
  129. /**
  130. * Convert an EFI status code to an iPXE status code
  131. *
  132. * @v efirc EFI status code
  133. * @ret rc iPXE status code (before negation)
  134. */
  135. #define EEFI( efirc ) EPLATFORM ( EINFO_EPLATFORM, efirc )
  136. extern EFI_GUID efi_absolute_pointer_protocol_guid;
  137. extern EFI_GUID efi_apple_net_boot_protocol_guid;
  138. extern EFI_GUID efi_arp_protocol_guid;
  139. extern EFI_GUID efi_arp_service_binding_protocol_guid;
  140. extern EFI_GUID efi_block_io_protocol_guid;
  141. extern EFI_GUID efi_block_io2_protocol_guid;
  142. extern EFI_GUID efi_bus_specific_driver_override_protocol_guid;
  143. extern EFI_GUID efi_component_name_protocol_guid;
  144. extern EFI_GUID efi_component_name2_protocol_guid;
  145. extern EFI_GUID efi_console_control_protocol_guid;
  146. extern EFI_GUID efi_device_path_protocol_guid;
  147. extern EFI_GUID efi_dhcp4_protocol_guid;
  148. extern EFI_GUID efi_dhcp4_service_binding_protocol_guid;
  149. extern EFI_GUID efi_disk_io_protocol_guid;
  150. extern EFI_GUID efi_driver_binding_protocol_guid;
  151. extern EFI_GUID efi_graphics_output_protocol_guid;
  152. extern EFI_GUID efi_hii_config_access_protocol_guid;
  153. extern EFI_GUID efi_hii_font_protocol_guid;
  154. extern EFI_GUID efi_ip4_protocol_guid;
  155. extern EFI_GUID efi_ip4_config_protocol_guid;
  156. extern EFI_GUID efi_ip4_service_binding_protocol_guid;
  157. extern EFI_GUID efi_load_file_protocol_guid;
  158. extern EFI_GUID efi_load_file2_protocol_guid;
  159. extern EFI_GUID efi_loaded_image_protocol_guid;
  160. extern EFI_GUID efi_loaded_image_device_path_protocol_guid;
  161. extern EFI_GUID efi_managed_network_protocol_guid;
  162. extern EFI_GUID efi_managed_network_service_binding_protocol_guid;
  163. extern EFI_GUID efi_mtftp4_protocol_guid;
  164. extern EFI_GUID efi_mtftp4_service_binding_protocol_guid;
  165. extern EFI_GUID efi_nii_protocol_guid;
  166. extern EFI_GUID efi_nii31_protocol_guid;
  167. extern EFI_GUID efi_pci_io_protocol_guid;
  168. extern EFI_GUID efi_pci_root_bridge_io_protocol_guid;
  169. extern EFI_GUID efi_pxe_base_code_protocol_guid;
  170. extern EFI_GUID efi_serial_io_protocol_guid;
  171. extern EFI_GUID efi_simple_file_system_protocol_guid;
  172. extern EFI_GUID efi_simple_network_protocol_guid;
  173. extern EFI_GUID efi_simple_pointer_protocol_guid;
  174. extern EFI_GUID efi_simple_text_input_protocol_guid;
  175. extern EFI_GUID efi_simple_text_input_ex_protocol_guid;
  176. extern EFI_GUID efi_simple_text_output_protocol_guid;
  177. extern EFI_GUID efi_tcg_protocol_guid;
  178. extern EFI_GUID efi_tcp4_protocol_guid;
  179. extern EFI_GUID efi_tcp4_service_binding_protocol_guid;
  180. extern EFI_GUID efi_tree_protocol_guid;
  181. extern EFI_GUID efi_udp4_protocol_guid;
  182. extern EFI_GUID efi_udp4_service_binding_protocol_guid;
  183. extern EFI_GUID efi_uga_draw_protocol_guid;
  184. extern EFI_GUID efi_unicode_collation_protocol_guid;
  185. extern EFI_GUID efi_usb_hc_protocol_guid;
  186. extern EFI_GUID efi_usb2_hc_protocol_guid;
  187. extern EFI_GUID efi_usb_io_protocol_guid;
  188. extern EFI_GUID efi_vlan_config_protocol_guid;
  189. extern EFI_GUID efi_file_info_id;
  190. extern EFI_GUID efi_file_system_info_id;
  191. extern EFI_HANDLE efi_image_handle;
  192. extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
  193. extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
  194. extern EFI_SYSTEM_TABLE *efi_systab;
  195. extern int efi_shutdown_in_progress;
  196. extern const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid );
  197. extern const __attribute__ (( pure )) char *
  198. efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type );
  199. extern const __attribute__ (( pure )) char *
  200. efi_open_attributes_name ( unsigned int attributes );
  201. extern const __attribute__ (( pure )) char *
  202. efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path );
  203. extern const __attribute__ (( pure )) char *
  204. efi_handle_name ( EFI_HANDLE handle );
  205. extern void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol );
  206. extern void dbg_efi_protocols ( EFI_HANDLE handle );
  207. #define DBG_EFI_OPENERS_IF( level, handle, protocol ) do { \
  208. if ( DBG_ ## level ) { \
  209. dbg_efi_openers ( handle, protocol ); \
  210. } \
  211. } while ( 0 )
  212. #define DBG_EFI_PROTOCOLS_IF( level, handle ) do { \
  213. if ( DBG_ ## level ) { \
  214. dbg_efi_protocols ( handle ); \
  215. } \
  216. } while ( 0 )
  217. #define DBGC_EFI_OPENERS_IF( level, id, ... ) do { \
  218. DBG_AC_IF ( level, id ); \
  219. DBG_EFI_OPENERS_IF ( level, __VA_ARGS__ ); \
  220. DBG_DC_IF ( level ); \
  221. } while ( 0 )
  222. #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do { \
  223. DBG_AC_IF ( level, id ); \
  224. DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ ); \
  225. DBG_DC_IF ( level ); \
  226. } while ( 0 )
  227. #define DBGC_EFI_OPENERS( ... ) \
  228. DBGC_EFI_OPENERS_IF ( LOG, ##__VA_ARGS__ )
  229. #define DBGC_EFI_PROTOCOLS( ... ) \
  230. DBGC_EFI_PROTOCOLS_IF ( LOG, ##__VA_ARGS__ )
  231. #define DBGC2_EFI_OPENERS( ... ) \
  232. DBGC_EFI_OPENERS_IF ( EXTRA, ##__VA_ARGS__ )
  233. #define DBGC2_EFI_PROTOCOLS( ... ) \
  234. DBGC_EFI_PROTOCOLS_IF ( EXTRA, ##__VA_ARGS__ )
  235. #define DBGCP_EFI_OPENERS( ... ) \
  236. DBGC_EFI_OPENERS_IF ( PROFILE, ##__VA_ARGS__ )
  237. #define DBGCP_EFI_PROTOCOLS( ... ) \
  238. DBGC_EFI_PROTOCOLS_IF ( PROFILE, ##__VA_ARGS__ )
  239. extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
  240. EFI_SYSTEM_TABLE *systab );
  241. #endif /* _IPXE_EFI_H */