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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. union {
  49. /** EFI protocol GUID */
  50. EFI_GUID guid;
  51. /** UUID structure understood by iPXE */
  52. union uuid uuid;
  53. } u;
  54. /** Variable containing pointer to protocol structure */
  55. void **protocol;
  56. };
  57. /** EFI protocol table */
  58. #define EFI_PROTOCOLS __table ( struct efi_protocol, "efi_protocols" )
  59. /** Declare an EFI protocol used by iPXE */
  60. #define __efi_protocol __table_entry ( EFI_PROTOCOLS, 01 )
  61. /** Declare an EFI protocol to be required by iPXE
  62. *
  63. * @v _protocol EFI protocol name
  64. * @v _ptr Pointer to protocol instance
  65. */
  66. #define EFI_REQUIRE_PROTOCOL( _protocol, _ptr ) \
  67. struct efi_protocol __ ## _protocol __efi_protocol = { \
  68. .u.guid = _protocol ## _GUID, \
  69. .protocol = ( ( void ** ) ( void * ) \
  70. ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ? \
  71. (_ptr) : (_ptr) ) ), \
  72. }
  73. /** An EFI configuration table used by iPXE */
  74. struct efi_config_table {
  75. /** GUID */
  76. union {
  77. /** EFI configuration table GUID */
  78. EFI_GUID guid;
  79. /** UUID structure understood by iPXE */
  80. union uuid uuid;
  81. } u;
  82. /** Variable containing pointer to configuration table */
  83. void **table;
  84. /** Table is required for operation */
  85. int required;
  86. };
  87. /** EFI configuration table table */
  88. #define EFI_CONFIG_TABLES \
  89. __table ( struct efi_config_table, "efi_config_tables" )
  90. /** Declare an EFI configuration table used by iPXE */
  91. #define __efi_config_table __table_entry ( EFI_CONFIG_TABLES, 01 )
  92. /** Declare an EFI configuration table to be used by iPXE
  93. *
  94. * @v _table EFI configuration table name
  95. * @v _ptr Pointer to configuration table
  96. * @v _required Table is required for operation
  97. */
  98. #define EFI_USE_TABLE( _table, _ptr, _required ) \
  99. struct efi_config_table __ ## _table __efi_config_table = { \
  100. .u.guid = _table ## _GUID, \
  101. .table = ( ( void ** ) ( void * ) (_ptr) ), \
  102. .required = (_required), \
  103. }
  104. /** Convert a iPXE status code to an EFI status code
  105. *
  106. * FIXME: actually perform some kind of conversion. iPXE error codes
  107. * will be detected as EFI error codes; both have the top bit set, and
  108. * the success return code is zero for both. Anything that just
  109. * reports a numerical error will be OK, anything attempting to
  110. * interpret the value or to display a text equivalent will be
  111. * screwed.
  112. */
  113. #define RC_TO_EFIRC( rc ) (rc)
  114. /** Convert an EFI status code to a iPXE status code
  115. *
  116. * FIXME: as above
  117. */
  118. #define EFIRC_TO_RC( efirc ) (efirc)
  119. extern EFI_HANDLE efi_image_handle;
  120. extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
  121. extern EFI_SYSTEM_TABLE *efi_systab;
  122. extern const char * efi_strerror ( EFI_STATUS efirc );
  123. extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
  124. EFI_SYSTEM_TABLE *systab );
  125. extern int efi_snp_install ( void );
  126. #endif /* _IPXE_EFI_H */