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.0KB

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