iPXE
efi.h
Go to the documentation of this file.
00001 #ifndef _IPXE_EFI_H
00002 #define _IPXE_EFI_H
00003 
00004 /** @file
00005  *
00006  * EFI API
00007  *
00008  * The intention is to include near-verbatim copies of the EFI headers
00009  * required by iPXE.  This is achieved using the import.pl script in
00010  * this directory.  Run the import script to update the local copies
00011  * of the headers:
00012  *
00013  *     ./import.pl /path/to/edk2/edk2
00014  *
00015  * where /path/to/edk2/edk2 is the path to your local checkout of the
00016  * EFI Development Kit.
00017  *
00018  * Note that import.pl will modify any #include lines in each imported
00019  * header to reflect its new location within the iPXE tree.  It will
00020  * also tidy up the file by removing carriage return characters and
00021  * trailing whitespace.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER );
00025 
00026 /* EFI headers rudely redefine NULL */
00027 #undef NULL
00028 
00029 /* EFI headers redefine ARRAY_SIZE */
00030 #undef ARRAY_SIZE
00031 
00032 /* EFI headers expect ICC to define __GNUC__ */
00033 #if defined ( __ICC ) && ! defined ( __GNUC__ )
00034 #define __GNUC__ 1
00035 #endif
00036 
00037 /* EFI headers think your compiler uses the MS ABI by default on X64 */
00038 #if __x86_64__
00039 #define EFIAPI __attribute__((ms_abi))
00040 #endif
00041 
00042 /* EFI headers assume regparm(0) on i386, but that is not the case for iPXE */
00043 #if __i386__
00044 #define EFIAPI __attribute__((cdecl,regparm(0)))
00045 #endif
00046 
00047 /* EFI headers define EFI_HANDLE as a void pointer, which renders type
00048  * checking somewhat useless.  Work around this bizarre sabotage
00049  * attempt by redefining EFI_HANDLE as a pointer to an anonymous
00050  * structure.
00051  */
00052 #define EFI_HANDLE STUPID_EFI_HANDLE
00053 #include <ipxe/efi/Uefi/UefiBaseType.h>
00054 #undef EFI_HANDLE
00055 typedef struct {} *EFI_HANDLE;
00056 
00057 /* Include the top-level EFI header files */
00058 #include <ipxe/efi/Uefi.h>
00059 #include <ipxe/efi/PiDxe.h>
00060 #include <ipxe/efi/Protocol/LoadedImage.h>
00061 
00062 /* Reset any trailing #pragma pack directives */
00063 #pragma pack(1)
00064 #pragma pack()
00065 
00066 #include <ipxe/tables.h>
00067 #include <ipxe/uuid.h>
00068 
00069 /** An EFI protocol used by iPXE */
00070 struct efi_protocol {
00071         /** GUID */
00072         EFI_GUID guid;
00073         /** Variable containing pointer to protocol structure */
00074         void **protocol;
00075         /** Protocol is required */
00076         int required;
00077 };
00078 
00079 /** EFI protocol table */
00080 #define EFI_PROTOCOLS __table ( struct efi_protocol, "efi_protocols" )
00081 
00082 /** Declare an EFI protocol used by iPXE */
00083 #define __efi_protocol __table_entry ( EFI_PROTOCOLS, 01 )
00084 
00085 /** Declare an EFI protocol to be required by iPXE
00086  *
00087  * @v _protocol         EFI protocol name
00088  * @v _ptr              Pointer to protocol instance
00089  */
00090 #define EFI_REQUIRE_PROTOCOL( _protocol, _ptr )                              \
00091         struct efi_protocol __ ## _protocol __efi_protocol = {               \
00092                 .guid = _protocol ## _GUID,                                  \
00093                 .protocol = ( ( void ** ) ( void * )                         \
00094                               ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ?  \
00095                                 (_ptr) : (_ptr) ) ),                         \
00096                 .required = 1,                                               \
00097         }
00098 
00099 /** Declare an EFI protocol to be requested by iPXE
00100  *
00101  * @v _protocol         EFI protocol name
00102  * @v _ptr              Pointer to protocol instance
00103  */
00104 #define EFI_REQUEST_PROTOCOL( _protocol, _ptr )                              \
00105         struct efi_protocol __ ## _protocol __efi_protocol = {               \
00106                 .guid = _protocol ## _GUID,                                  \
00107                 .protocol = ( ( void ** ) ( void * )                         \
00108                               ( ( (_ptr) == ( ( _protocol ** ) (_ptr) ) ) ?  \
00109                                 (_ptr) : (_ptr) ) ),                         \
00110                 .required = 0,                                               \
00111         }
00112 
00113 /** An EFI configuration table used by iPXE */
00114 struct efi_config_table {
00115         /** GUID */
00116         EFI_GUID guid;
00117         /** Variable containing pointer to configuration table */
00118         void **table;
00119         /** Table is required for operation */
00120         int required;
00121 };
00122 
00123 /** EFI configuration table table */
00124 #define EFI_CONFIG_TABLES \
00125         __table ( struct efi_config_table, "efi_config_tables" )
00126 
00127 /** Declare an EFI configuration table used by iPXE */
00128 #define __efi_config_table __table_entry ( EFI_CONFIG_TABLES, 01 )
00129 
00130 /** Declare an EFI configuration table to be used by iPXE
00131  *
00132  * @v _table            EFI configuration table name
00133  * @v _ptr              Pointer to configuration table
00134  * @v _required         Table is required for operation
00135  */
00136 #define EFI_USE_TABLE( _table, _ptr, _required )                             \
00137         struct efi_config_table __ ## _table __efi_config_table = {          \
00138                 .guid = _table ## _GUID,                                     \
00139                 .table = ( ( void ** ) ( void * ) (_ptr) ),                  \
00140                 .required = (_required),                                     \
00141         }
00142 
00143 /**
00144  * Convert an iPXE status code to an EFI status code
00145  *
00146  * @v rc                iPXE status code
00147  * @ret efirc           EFI status code
00148  */
00149 #define EFIRC( rc ) ERRNO_TO_PLATFORM ( -(rc) )
00150 
00151 /**
00152  * Convert an EFI status code to an iPXE status code
00153  *
00154  * @v efirc             EFI status code
00155  * @ret rc              iPXE status code (before negation)
00156  */
00157 #define EEFI( efirc ) EPLATFORM ( EINFO_EPLATFORM, efirc )
00158 
00159 extern EFI_GUID efi_absolute_pointer_protocol_guid;
00160 extern EFI_GUID efi_acpi_table_protocol_guid;
00161 extern EFI_GUID efi_apple_net_boot_protocol_guid;
00162 extern EFI_GUID efi_arp_protocol_guid;
00163 extern EFI_GUID efi_arp_service_binding_protocol_guid;
00164 extern EFI_GUID efi_block_io_protocol_guid;
00165 extern EFI_GUID efi_block_io2_protocol_guid;
00166 extern EFI_GUID efi_bus_specific_driver_override_protocol_guid;
00167 extern EFI_GUID efi_component_name_protocol_guid;
00168 extern EFI_GUID efi_component_name2_protocol_guid;
00169 extern EFI_GUID efi_console_control_protocol_guid;
00170 extern EFI_GUID efi_device_path_protocol_guid;
00171 extern EFI_GUID efi_dhcp4_protocol_guid;
00172 extern EFI_GUID efi_dhcp4_service_binding_protocol_guid;
00173 extern EFI_GUID efi_disk_io_protocol_guid;
00174 extern EFI_GUID efi_driver_binding_protocol_guid;
00175 extern EFI_GUID efi_graphics_output_protocol_guid;
00176 extern EFI_GUID efi_hii_config_access_protocol_guid;
00177 extern EFI_GUID efi_hii_font_protocol_guid;
00178 extern EFI_GUID efi_ip4_protocol_guid;
00179 extern EFI_GUID efi_ip4_config_protocol_guid;
00180 extern EFI_GUID efi_ip4_service_binding_protocol_guid;
00181 extern EFI_GUID efi_load_file_protocol_guid;
00182 extern EFI_GUID efi_load_file2_protocol_guid;
00183 extern EFI_GUID efi_loaded_image_protocol_guid;
00184 extern EFI_GUID efi_loaded_image_device_path_protocol_guid;
00185 extern EFI_GUID efi_managed_network_protocol_guid;
00186 extern EFI_GUID efi_managed_network_service_binding_protocol_guid;
00187 extern EFI_GUID efi_mtftp4_protocol_guid;
00188 extern EFI_GUID efi_mtftp4_service_binding_protocol_guid;
00189 extern EFI_GUID efi_nii_protocol_guid;
00190 extern EFI_GUID efi_nii31_protocol_guid;
00191 extern EFI_GUID efi_pci_io_protocol_guid;
00192 extern EFI_GUID efi_pci_root_bridge_io_protocol_guid;
00193 extern EFI_GUID efi_pxe_base_code_protocol_guid;
00194 extern EFI_GUID efi_serial_io_protocol_guid;
00195 extern EFI_GUID efi_simple_file_system_protocol_guid;
00196 extern EFI_GUID efi_simple_network_protocol_guid;
00197 extern EFI_GUID efi_simple_pointer_protocol_guid;
00198 extern EFI_GUID efi_simple_text_input_protocol_guid;
00199 extern EFI_GUID efi_simple_text_input_ex_protocol_guid;
00200 extern EFI_GUID efi_simple_text_output_protocol_guid;
00201 extern EFI_GUID efi_tcg_protocol_guid;
00202 extern EFI_GUID efi_tcp4_protocol_guid;
00203 extern EFI_GUID efi_tcp4_service_binding_protocol_guid;
00204 extern EFI_GUID efi_tree_protocol_guid;
00205 extern EFI_GUID efi_udp4_protocol_guid;
00206 extern EFI_GUID efi_udp4_service_binding_protocol_guid;
00207 extern EFI_GUID efi_uga_draw_protocol_guid;
00208 extern EFI_GUID efi_unicode_collation_protocol_guid;
00209 extern EFI_GUID efi_usb_hc_protocol_guid;
00210 extern EFI_GUID efi_usb2_hc_protocol_guid;
00211 extern EFI_GUID efi_usb_io_protocol_guid;
00212 extern EFI_GUID efi_vlan_config_protocol_guid;
00213 
00214 extern EFI_GUID efi_file_info_id;
00215 extern EFI_GUID efi_file_system_info_id;
00216 
00217 extern EFI_HANDLE efi_image_handle;
00218 extern EFI_LOADED_IMAGE_PROTOCOL *efi_loaded_image;
00219 extern EFI_DEVICE_PATH_PROTOCOL *efi_loaded_image_path;
00220 extern EFI_SYSTEM_TABLE *efi_systab;
00221 extern int efi_shutdown_in_progress;
00222 
00223 extern const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid );
00224 extern const __attribute__ (( pure )) char *
00225 efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type );
00226 extern const __attribute__ (( pure )) char *
00227 efi_open_attributes_name ( unsigned int attributes );
00228 extern const __attribute__ (( pure )) char *
00229 efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path );
00230 extern const __attribute__ (( pure )) char *
00231 efi_handle_name ( EFI_HANDLE handle );
00232 
00233 extern void dbg_efi_openers ( EFI_HANDLE handle, EFI_GUID *protocol );
00234 extern void dbg_efi_protocols ( EFI_HANDLE handle );
00235 
00236 #define DBG_EFI_OPENERS_IF( level, handle, protocol ) do {      \
00237                 if ( DBG_ ## level ) {                          \
00238                         dbg_efi_openers ( handle, protocol );   \
00239                 }                                               \
00240         } while ( 0 )
00241 
00242 #define DBG_EFI_PROTOCOLS_IF( level, handle ) do {              \
00243                 if ( DBG_ ## level ) {                          \
00244                         dbg_efi_protocols ( handle );           \
00245                 }                                               \
00246         } while ( 0 )
00247 
00248 #define DBGC_EFI_OPENERS_IF( level, id, ... ) do {              \
00249                 DBG_AC_IF ( level, id );                        \
00250                 DBG_EFI_OPENERS_IF ( level, __VA_ARGS__ );      \
00251                 DBG_DC_IF ( level );                            \
00252         } while ( 0 )
00253 
00254 #define DBGC_EFI_PROTOCOLS_IF( level, id, ... ) do {            \
00255                 DBG_AC_IF ( level, id );                        \
00256                 DBG_EFI_PROTOCOLS_IF ( level, __VA_ARGS__ );    \
00257                 DBG_DC_IF ( level );                            \
00258         } while ( 0 )
00259 
00260 #define DBGC_EFI_OPENERS( ... )                                 \
00261         DBGC_EFI_OPENERS_IF ( LOG, ##__VA_ARGS__ )
00262 #define DBGC_EFI_PROTOCOLS( ... )                               \
00263         DBGC_EFI_PROTOCOLS_IF ( LOG, ##__VA_ARGS__ )
00264 
00265 #define DBGC2_EFI_OPENERS( ... )                                \
00266         DBGC_EFI_OPENERS_IF ( EXTRA, ##__VA_ARGS__ )
00267 #define DBGC2_EFI_PROTOCOLS( ... )                              \
00268         DBGC_EFI_PROTOCOLS_IF ( EXTRA, ##__VA_ARGS__ )
00269 
00270 #define DBGCP_EFI_OPENERS( ... )                                \
00271         DBGC_EFI_OPENERS_IF ( PROFILE, ##__VA_ARGS__ )
00272 #define DBGCP_EFI_PROTOCOLS( ... )                              \
00273         DBGC_EFI_PROTOCOLS_IF ( PROFILE, ##__VA_ARGS__ )
00274 
00275 extern EFI_STATUS efi_init ( EFI_HANDLE image_handle,
00276                              EFI_SYSTEM_TABLE *systab );
00277 
00278 #endif /* _IPXE_EFI_H */