Home | History | Annotate | Download | only in efi
      1 #ifndef _EFI_H
      2 #define _EFI_H
      3 
      4 /** @file
      5  *
      6  * EFI API
      7  *
      8  * The intention is to include near-verbatim copies of the EFI headers
      9  * required by gPXE.  This is achieved using the import.pl script in
     10  * this directory.  Run the import script to update the local copies
     11  * of the headers:
     12  *
     13  *     ./import.pl /path/to/edk2/edk2
     14  *
     15  * where /path/to/edk2/edk2 is the path to your local checkout of the
     16  * EFI Development Kit.
     17  *
     18  * Note that import.pl will modify any #include lines in each imported
     19  * header to reflect its new location within the gPXE tree.  It will
     20  * also tidy up the file by removing carriage return characters and
     21  * trailing whitespace.
     22  *
     23  *
     24  * At the time of writing, there are a few other modifications to
     25  * these headers that are present in my personal edk2 tree, that are
     26  * not yet committed back to the main edk2 repository.  These
     27  * modifications are fixes for compilation on case-dependent
     28  * filesystems, compilation under -mrtd and -mregparm=3, etc.
     29  */
     30 
     31 /* EFI headers rudely redefine NULL */
     32 #undef NULL
     33 
     34 /* EFI headers expect ICC to define __GNUC__ */
     35 #if defined ( __ICC ) && ! defined ( __GNUC__ )
     36 #define __GNUC__ 1
     37 #endif
     38 
     39 /* Include the top-level EFI header files */
     40 #include <gpxe/efi/Uefi.h>
     41 #include <gpxe/efi/PiDxe.h>
     42 
     43 /* Reset any trailing #pragma pack directives */
     44 #pragma pack(1)
     45 #pragma pack()
     46 
     47 #include <gpxe/tables.h>
     48 #include <gpxe/uuid.h>
     49 
     50 /** An EFI protocol used by gPXE */
     51 struct efi_protocol {
     52 	/** GUID */
     53 	union {
     54 		/** EFI protocol GUID */
     55 		EFI_GUID guid;
     56 		/** UUID structure understood by gPXE */
     57 		union uuid uuid;
     58 	} u;
     59 	/** Variable containing pointer to protocol structure */
     60 	void **protocol;
     61 };
     62 
     63 /** EFI protocol table */
     64 #define EFI_PROTOCOLS __table ( struct efi_protocol, "efi_protocols" )
     65 
     66 /** Declare an EFI protocol used by gPXE */
     67 #define __efi_protocol __table_entry ( EFI_PROTOCOLS, 01 )
     68 
     69 /** Declare an EFI protocol to be required by gPXE
     70  *
     71  * @v _protocol		EFI protocol name
     72  * @v _ptr		Pointer to protocol instance
     73  */
     74 #define EFI_REQUIRE_PROTOCOL( _protocol, _ptr )				     \
     75 	struct efi_protocol __ ## _protocol __efi_protocol = {		     \
     76 		.u.guid = _protocol ## _GUID,				     \
     77 		.protocol = ( ( void ** ) ( void * )			     \
     78 			      ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ?  \
     79 				(_ptr) : (_ptr) ) ),			     \
     80 	}
     81 
     82 /** An EFI configuration table used by gPXE */
     83 struct efi_config_table {
     84 	/** GUID */
     85 	union {
     86 		/** EFI configuration table GUID */
     87 		EFI_GUID guid;
     88 		/** UUID structure understood by gPXE */
     89 		union uuid uuid;
     90 	} u;
     91 	/** Variable containing pointer to configuration table */
     92 	void **table;
     93 	/** Table is required for operation */
     94 	int required;
     95 };
     96 
     97 /** EFI configuration table table */
     98 #define EFI_CONFIG_TABLES \
     99 	__table ( struct efi_config_table, "efi_config_tables" )
    100 
    101 /** Declare an EFI configuration table used by gPXE */
    102 #define __efi_config_table __table_entry ( EFI_CONFIG_TABLES, 01 )
    103 
    104 /** Declare an EFI configuration table to be used by gPXE
    105  *
    106  * @v _table		EFI configuration table name
    107  * @v _ptr		Pointer to configuration table
    108  * @v _required		Table is required for operation
    109  */
    110 #define EFI_USE_TABLE( _table, _ptr, _required )			     \
    111 	struct efi_config_table __ ## _table __efi_config_table = {	     \
    112 		.u.guid = _table ## _GUID,				     \
    113 		.table = ( ( void ** ) ( void * ) (_ptr) ),		     \
    114 		.required = (_required),				     \
    115 	}
    116 
    117 /** Convert a gPXE status code to an EFI status code
    118  *
    119  * FIXME: actually perform some kind of conversion.  gPXE error codes
    120  * will be detected as EFI error codes; both have the top bit set, and
    121  * the success return code is zero for both.  Anything that just
    122  * reports a numerical error will be OK, anything attempting to
    123  * interpret the value or to display a text equivalent will be
    124  * screwed.
    125  */
    126 #define RC_TO_EFIRC( rc ) (rc)
    127 
    128 /** Convert an EFI status code to a gPXE status code
    129  *
    130  * FIXME: as above
    131  */
    132 #define EFIRC_TO_RC( efirc ) (efirc)
    133 
    134 extern EFI_HANDLE efi_image_handle;
    135 extern EFI_SYSTEM_TABLE *efi_systab;
    136 
    137 extern const char * efi_strerror ( EFI_STATUS efirc );
    138 extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
    139 			     EFI_SYSTEM_TABLE *systab );
    140 extern int efi_snp_install ( void );
    141 
    142 #endif /* _EFI_H */
    143