Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

efi.h 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. /* Include the top-level EFI header files */
  38. #include <ipxe/efi/Uefi.h>
  39. #include <ipxe/efi/PiDxe.h>
  40. #include <ipxe/efi/Protocol/LoadedImage.h>
  41. /* Reset any trailing #pragma pack directives */
  42. #pragma pack(1)
  43. #pragma pack()
  44. #include <ipxe/tables.h>
  45. #include <ipxe/uuid.h>
  46. /** An EFI protocol used by iPXE */
  47. struct efi_protocol {
  48. /** GUID */
  49. EFI_GUID guid;
  50. /** Variable containing pointer to protocol structure */
  51. void **protocol;
  52. /** Protocol is required */
  53. int required;
  54. };
  55. /** EFI protocol table */
  56. #define EFI_PROTOCOLS __table ( struct efi_protocol, "efi_protocols" )
  57. /** Declare an EFI protocol used by iPXE */
  58. #define __efi_protocol __table_entry ( EFI_PROTOCOLS, 01 )
  59. /** Declare an EFI protocol to be required by iPXE
  60. *
  61. * @v _protocol EFI protocol name
  62. * @v _ptr Pointer to protocol instance
  63. */
  64. #define EFI_REQUIRE_PROTOCOL( _protocol, _ptr ) \
  65. struct efi_protocol __ ## _protocol __efi_protocol = { \
  66. .guid = _protocol ## _GUID, \
  67. .protocol = ( ( void ** ) ( void * ) \
  68. ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ? \
  69. (_ptr) : (_ptr) ) ), \
  70. .required = 1, \
  71. }
  72. /** Declare an EFI protocol to be requested by iPXE
  73. *
  74. * @v _protocol EFI protocol name
  75. * @v _ptr Pointer to protocol instance
  76. */
  77. #define EFI_REQUEST_PROTOCOL( _protocol, _ptr ) \
  78. struct efi_protocol __ ## _protocol __efi_protocol = { \
  79. .guid = _protocol ## _GUID, \
  80. .protocol = ( ( void ** ) ( void * ) \
  81. ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ? \
  82. (_ptr) : (_ptr) ) ), \
  83. .required = 0, \
  84. }
  85. /** An EFI configuration table used by iPXE */
  86. struct efi_config_table {
  87. /** GUID */
  88. EFI_GUID guid;
  89. /** Variable containing pointer to configuration table */
  90. void **table;
  91. /** Table is required for operation */
  92. int required;
  93. };
  94. /** EFI configuration table table */
  95. #define EFI_CONFIG_TABLES \
  96. __table ( struct efi_config_table, "efi_config_tables" )
  97. /** Declare an EFI configuration table used by iPXE */
  98. #define __efi_config_table __table_entry ( EFI_CONFIG_TABLES, 01 )
  99. /** Declare an EFI configuration table to be used by iPXE
  100. *
  101. * @v _table EFI configuration table name
  102. * @v _ptr Pointer to configuration table
  103. * @v _required Table is required for operation
  104. */
  105. #define EFI_USE_TABLE( _table, _ptr, _required ) \
  106. struct efi_config_table __ ## _table __efi_config_table = { \
  107. .guid = _table ## _GUID, \
  108. .table = ( ( void ** ) ( void * ) (_ptr) ), \
  109. .required = (_required), \
  110. }
  111. /**
  112. * Convert an iPXE status code to an EFI status code
  113. *
  114. * @v rc iPXE status code
  115. * @ret efirc EFI status code
  116. */
  117. #define EFIRC( rc ) ERRNO_TO_PLATFORM ( -(rc) )
  118. /**
  119. * Convert an EFI status code to an iPXE status code
  120. *
  121. * @v efirc EFI status code
  122. * @ret rc iPXE status code (before negation)
  123. */
  124. #define EEFI( efirc ) EPLATFORM ( EINFO_EPLATFORM, efirc )
  125. extern EFI_HANDLE efi_image_handle;
  126. extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
  127. extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
  128. extern EFI_SYSTEM_TABLE *efi_systab;
  129. extern const char * efi_guid_ntoa ( EFI_GUID *guid );
  130. extern const char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path );
  131. extern const char * efi_handle_name ( EFI_HANDLE handle );
  132. extern void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol );
  133. extern void dbg_efi_protocols ( EFI_HANDLE handle );
  134. #define DBG_EFI_OPENERS_IF( level, handle, protocol ) do { \
  135. if ( DBG_ ## level ) { \
  136. dbg_efi_openers ( handle, protocol ); \
  137. } \
  138. } while ( 0 )
  139. #define DBG_EFI_PROTOCOLS_IF( level, handle ) do { \
  140. if ( DBG_ ## level ) { \
  141. dbg_efi_protocols ( handle ); \
  142. } \
  143. } while ( 0 )
  144. #define DBGC_EFI_OPENERS_IF( level, id, ... ) do { \
  145. DBG_AC_IF ( level, id ); \
  146. DBG_EFI_OPENERS_IF ( level, __VA_ARGS__ ); \
  147. DBG_DC_IF ( level ); \
  148. } while ( 0 )
  149. #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do { \
  150. DBG_AC_IF ( level, id ); \
  151. DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ ); \
  152. DBG_DC_IF ( level ); \
  153. } while ( 0 )
  154. #define DBGC_EFI_OPENERS( ... ) \
  155. DBGC_EFI_OPENERS_IF ( LOG, ##__VA_ARGS__ )
  156. #define DBGC_EFI_PROTOCOLS( ... ) \
  157. DBGC_EFI_PROTOCOLS_IF ( LOG, ##__VA_ARGS__ )
  158. #define DBGC2_EFI_OPENERS( ... ) \
  159. DBGC_EFI_OPENERS_IF ( EXTRA, ##__VA_ARGS__ )
  160. #define DBGC2_EFI_PROTOCOLS( ... ) \
  161. DBGC_EFI_PROTOCOLS_IF ( EXTRA, ##__VA_ARGS__ )
  162. #define DBGCP_EFI_OPENERS( ... ) \
  163. DBGC_EFI_OPENERS_IF ( PROFILE, ##__VA_ARGS__ )
  164. #define DBGCP_EFI_PROTOCOLS( ... ) \
  165. DBGC_EFI_PROTOCOLS_IF ( PROFILE, ##__VA_ARGS__ )
  166. extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
  167. EFI_SYSTEM_TABLE *systab );
  168. #endif /* _IPXE_EFI_H */