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 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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_block_io_protocol_guid;
  135. extern EFI_GUID efi_bus_specific_driver_override_protocol_guid;
  136. extern EFI_GUID efi_component_name_protocol_guid;
  137. extern EFI_GUID efi_component_name2_protocol_guid;
  138. extern EFI_GUID efi_device_path_protocol_guid;
  139. extern EFI_GUID efi_disk_io_protocol_guid;
  140. extern EFI_GUID efi_driver_binding_protocol_guid;
  141. extern EFI_GUID efi_graphics_output_protocol_guid;
  142. extern EFI_GUID efi_hii_config_access_protocol_guid;
  143. extern EFI_GUID efi_load_file_protocol_guid;
  144. extern EFI_GUID efi_load_file2_protocol_guid;
  145. extern EFI_GUID efi_loaded_image_protocol_guid;
  146. extern EFI_GUID efi_loaded_image_device_path_protocol_guid;
  147. extern EFI_GUID efi_nii_protocol_guid;
  148. extern EFI_GUID efi_nii31_protocol_guid;
  149. extern EFI_GUID efi_pci_io_protocol_guid;
  150. extern EFI_GUID efi_pci_root_bridge_io_protocol_guid;
  151. extern EFI_GUID efi_pxe_base_code_protocol_guid;
  152. extern EFI_GUID efi_simple_file_system_protocol_guid;
  153. extern EFI_GUID efi_simple_network_protocol_guid;
  154. extern EFI_GUID efi_tcg_protocol_guid;
  155. extern EFI_HANDLE efi_image_handle;
  156. extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
  157. extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
  158. extern EFI_SYSTEM_TABLE *efi_systab;
  159. extern const char * efi_guid_ntoa ( EFI_GUID *guid );
  160. extern const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path );
  161. extern const char * efi_handle_name ( EFI_HANDLE handle );
  162. extern void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol );
  163. extern void dbg_efi_protocols ( EFI_HANDLE handle );
  164. #define DBG_EFI_OPENERS_IF( level, handle, protocol ) do { \
  165. if ( DBG_ ## level ) { \
  166. dbg_efi_openers ( handle, protocol ); \
  167. } \
  168. } while ( 0 )
  169. #define DBG_EFI_PROTOCOLS_IF( level, handle ) do { \
  170. if ( DBG_ ## level ) { \
  171. dbg_efi_protocols ( handle ); \
  172. } \
  173. } while ( 0 )
  174. #define DBGC_EFI_OPENERS_IF( level, id, ... ) do { \
  175. DBG_AC_IF ( level, id ); \
  176. DBG_EFI_OPENERS_IF ( level, __VA_ARGS__ ); \
  177. DBG_DC_IF ( level ); \
  178. } while ( 0 )
  179. #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do { \
  180. DBG_AC_IF ( level, id ); \
  181. DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ ); \
  182. DBG_DC_IF ( level ); \
  183. } while ( 0 )
  184. #define DBGC_EFI_OPENERS( ... ) \
  185. DBGC_EFI_OPENERS_IF ( LOG, ##__VA_ARGS__ )
  186. #define DBGC_EFI_PROTOCOLS( ... ) \
  187. DBGC_EFI_PROTOCOLS_IF ( LOG, ##__VA_ARGS__ )
  188. #define DBGC2_EFI_OPENERS( ... ) \
  189. DBGC_EFI_OPENERS_IF ( EXTRA, ##__VA_ARGS__ )
  190. #define DBGC2_EFI_PROTOCOLS( ... ) \
  191. DBGC_EFI_PROTOCOLS_IF ( EXTRA, ##__VA_ARGS__ )
  192. #define DBGCP_EFI_OPENERS( ... ) \
  193. DBGC_EFI_OPENERS_IF ( PROFILE, ##__VA_ARGS__ )
  194. #define DBGCP_EFI_PROTOCOLS( ... ) \
  195. DBGC_EFI_PROTOCOLS_IF ( PROFILE, ##__VA_ARGS__ )
  196. extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
  197. EFI_SYSTEM_TABLE *systab );
  198. #endif /* _IPXE_EFI_H */