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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. /* EFI headers rudely redefine NULL */
  23. #undef NULL
  24. /* EFI headers expect ICC to define __GNUC__ */
  25. #if defined ( __ICC ) && ! defined ( __GNUC__ )
  26. #define __GNUC__ 1
  27. #endif
  28. /* EFI headers think your compiler uses the MS ABI by default on X64 */
  29. #if __x86_64__
  30. #define EFIAPI __attribute__((ms_abi))
  31. #endif
  32. /* EFI headers assume regparm(0) on i386, but that is not the case for iPXE */
  33. #if __i386__
  34. #define EFIAPI __attribute__((cdecl,regparm(0)))
  35. #endif
  36. /* Include the top-level EFI header files */
  37. #include <ipxe/efi/Uefi.h>
  38. #include <ipxe/efi/PiDxe.h>
  39. #include <ipxe/efi/Protocol/LoadedImage.h>
  40. /* Reset any trailing #pragma pack directives */
  41. #pragma pack(1)
  42. #pragma pack()
  43. #include <ipxe/tables.h>
  44. #include <ipxe/uuid.h>
  45. /** An EFI protocol used by iPXE */
  46. struct efi_protocol {
  47. /** GUID */
  48. EFI_GUID guid;
  49. /** Variable containing pointer to protocol structure */
  50. void **protocol;
  51. };
  52. /** EFI protocol table */
  53. #define EFI_PROTOCOLS __table ( struct efi_protocol, "efi_protocols" )
  54. /** Declare an EFI protocol used by iPXE */
  55. #define __efi_protocol __table_entry ( EFI_PROTOCOLS, 01 )
  56. /** Declare an EFI protocol to be required by iPXE
  57. *
  58. * @v _protocol EFI protocol name
  59. * @v _ptr Pointer to protocol instance
  60. */
  61. #define EFI_REQUIRE_PROTOCOL( _protocol, _ptr ) \
  62. struct efi_protocol __ ## _protocol __efi_protocol = { \
  63. .guid = _protocol ## _GUID, \
  64. .protocol = ( ( void ** ) ( void * ) \
  65. ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ? \
  66. (_ptr) : (_ptr) ) ), \
  67. }
  68. /** An EFI configuration table used by iPXE */
  69. struct efi_config_table {
  70. /** GUID */
  71. EFI_GUID guid;
  72. /** Variable containing pointer to configuration table */
  73. void **table;
  74. /** Table is required for operation */
  75. int required;
  76. };
  77. /** EFI configuration table table */
  78. #define EFI_CONFIG_TABLES \
  79. __table ( struct efi_config_table, "efi_config_tables" )
  80. /** Declare an EFI configuration table used by iPXE */
  81. #define __efi_config_table __table_entry ( EFI_CONFIG_TABLES, 01 )
  82. /** Declare an EFI configuration table to be used by iPXE
  83. *
  84. * @v _table EFI configuration table name
  85. * @v _ptr Pointer to configuration table
  86. * @v _required Table is required for operation
  87. */
  88. #define EFI_USE_TABLE( _table, _ptr, _required ) \
  89. struct efi_config_table __ ## _table __efi_config_table = { \
  90. .guid = _table ## _GUID, \
  91. .table = ( ( void ** ) ( void * ) (_ptr) ), \
  92. .required = (_required), \
  93. }
  94. /** Convert a iPXE status code to an EFI status code
  95. *
  96. * FIXME: actually perform some kind of conversion. iPXE error codes
  97. * will be detected as EFI error codes; both have the top bit set, and
  98. * the success return code is zero for both. Anything that just
  99. * reports a numerical error will be OK, anything attempting to
  100. * interpret the value or to display a text equivalent will be
  101. * screwed.
  102. */
  103. #define RC_TO_EFIRC( rc ) (rc)
  104. /** Convert an EFI status code to a iPXE status code
  105. *
  106. * FIXME: as above
  107. */
  108. #define EFIRC_TO_RC( efirc ) (efirc)
  109. extern EFI_HANDLE efi_image_handle;
  110. extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
  111. extern EFI_SYSTEM_TABLE *efi_systab;
  112. extern const char * efi_strerror ( EFI_STATUS efirc );
  113. extern const char * efi_guid_ntoa ( EFI_GUID *guid );
  114. extern void dbg_efi_protocols ( EFI_HANDLE handle );
  115. extern void dbg_efi_devpath ( EFI_DEVICE_PATH_PROTOCOL *path );
  116. #define DBG_EFI_PROTOCOLS_IF( level, handle ) do { \
  117. if ( DBG_ ## level ) { \
  118. dbg_efi_protocols ( handle ); \
  119. } \
  120. } while ( 0 )
  121. #define DBG_EFI_DEVPATH_IF( level, path ) do { \
  122. if ( DBG_ ## level ) { \
  123. dbg_efi_devpath ( path ); \
  124. } \
  125. } while ( 0 )
  126. #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do { \
  127. DBG_AC_IF ( level, id ); \
  128. DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ ); \
  129. DBG_DC_IF ( level ); \
  130. } while ( 0 )
  131. #define DBGC_EFI_DEVPATH_IF( level, id, ... ) do { \
  132. DBG_AC_IF ( level, id ); \
  133. DBG_EFI_DEVPATH_IF ( level, __VA_ARGS__ ); \
  134. DBG_DC_IF ( level ); \
  135. } while ( 0 )
  136. #define DBGC_EFI_PROTOCOLS( ... ) \
  137. DBGC_EFI_PROTOCOLS_IF( LOG, ##__VA_ARGS__ )
  138. #define DBGC_EFI_DEVPATH( ... ) \
  139. DBGC_EFI_DEVPATH_IF( LOG, ##__VA_ARGS__ )
  140. extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
  141. EFI_SYSTEM_TABLE *systab );
  142. #endif /* _IPXE_EFI_H */