iPXE
efi_bofm.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <errno.h>
00027 #include <ipxe/bofm.h>
00028 #include <ipxe/efi/efi.h>
00029 #include <ipxe/efi/efi_pci.h>
00030 #include <ipxe/efi/efi_driver.h>
00031 
00032 /** @file
00033  *
00034  * IBM BladeCenter Open Fabric Manager (BOFM) EFI interface
00035  *
00036  */
00037 
00038 /***************************************************************************
00039  *
00040  * EFI BOFM definitions
00041  *
00042  ***************************************************************************
00043  *
00044  * Taken from the BOFM UEFI Vendor Specification document
00045  *
00046  */
00047 
00048 #define IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID                     \
00049         { 0x03207ce2, 0xd9c7, 0x11dc,                                   \
00050           { 0xa9, 0x4d, 0x00, 0x19, 0x7d, 0x89, 0x02, 0x38 } }
00051 
00052 #define IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID                    \
00053         { 0xe82a9763, 0x0584, 0x4e41,                                   \
00054           { 0xbb, 0x39, 0xe0, 0xcd, 0xb8, 0xc1, 0xf0, 0xfc } }
00055 
00056 typedef struct {
00057         UINT8 Id;
00058         UINT8 ResultByte;
00059 } __attribute__ (( packed )) BOFM_EPID_Results_t;
00060 
00061 typedef struct {
00062         UINT8 Version;
00063         UINT8 Level;
00064         UINT16 Length;
00065         UINT8 Checksum;
00066         UINT8 Profile[32];
00067         UINT8 GlobalOption0;
00068         UINT8 GlobalOption1;
00069         UINT8 GlobalOption2;
00070         UINT8 GlobalOption3;
00071         UINT32 SequenceStamp;
00072         UINT8 Regions[911]; // For use by BOFM Driver
00073         UINT32 Reserved1;
00074 } __attribute__ (( packed )) BOFM_Parameters_t;
00075 
00076 typedef struct {
00077         UINT32 Reserved1;
00078         UINT8 Version;
00079         UINT8 Level;
00080         UINT8 Checksum;
00081         UINT32 SequenceStamp;
00082         UINT8 SUIDResults;
00083         UINT8 EntryResults[32];
00084         UINT8 Reserved2;
00085         UINT8 Reserved3;
00086         UINT8 FCTgtResults[2];
00087         UINT8 SASTgtResults[2];
00088         BOFM_EPID_Results_t EPIDResults[2];
00089         UINT8 Results4[10];
00090 } __attribute__ (( packed )) BOFM_Results_t;
00091 
00092 typedef struct {
00093         UINT32 Signature;
00094         UINT32 SubSignature;
00095         BOFM_Parameters_t Parameters;
00096         BOFM_Results_t Results;
00097 } __attribute__ (( packed )) BOFM_DataStructure_t;
00098 
00099 #define IBM_BOFM_TABLE BOFM_DataStructure_t
00100 
00101 typedef struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL
00102         IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL;
00103 
00104 typedef struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2
00105         IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2;
00106 
00107 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT ) (
00108         IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This,
00109         EFI_HANDLE ControllerHandle,
00110         UINT8 SupporttedOptions,
00111         UINT8 iSCSI_Parameter_Version,
00112         UINT8 BOFM_Parameter_Version
00113 );
00114 
00115 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS ) (
00116         IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This,
00117         EFI_HANDLE ControllerHandle,
00118         BOOLEAN ResetRequired,
00119         UINT8 BOFMReturnCode
00120 );
00121 
00122 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 ) (
00123         IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *This,
00124         EFI_HANDLE ControllerHandle,
00125         BOOLEAN ResetRequired,
00126         UINT8 BOFMReturnCode
00127 );
00128 
00129 struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL {
00130         IBM_BOFM_TABLE BofmTable;
00131         IBM_BOFM_DRIVER_CONFIGURATION_STATUS SetStatus;
00132         IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
00133 };
00134 
00135 struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 {
00136         UINT32 Signature;
00137         UINT32 Reserved1;
00138         UINT64 Reserved2;
00139         IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 SetStatus;
00140         IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
00141         IBM_BOFM_TABLE BofmTable;
00142 };
00143 
00144 /***************************************************************************
00145  *
00146  * EFI BOFM interface
00147  *
00148  ***************************************************************************
00149  */
00150 
00151 /** BOFM1 protocol GUID */
00152 static EFI_GUID bofm1_protocol_guid =
00153         IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID;
00154 
00155 /** BOFM2 protocol GUID */
00156 static EFI_GUID bofm2_protocol_guid =
00157         IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID;
00158 
00159 /**
00160  * Check if device is supported
00161  *
00162  * @v device            EFI device handle
00163  * @ret rc              Return status code
00164  */
00165 static int efi_bofm_supported ( EFI_HANDLE device ) {
00166         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
00167         struct pci_device pci;
00168         union {
00169                 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
00170                 void *interface;
00171         } bofm1;
00172         EFI_STATUS efirc;
00173         int rc;
00174 
00175         /* Get PCI device information */
00176         if ( ( rc = efipci_info ( device, &pci ) ) != 0 )
00177                 return rc;
00178 
00179         /* Look for a BOFM driver */
00180         if ( ( rc = bofm_find_driver ( &pci ) ) != 0 ) {
00181                 DBGCP ( device, "EFIBOFM %s has no driver\n",
00182                         efi_handle_name ( device ) );
00183                 return rc;
00184         }
00185 
00186         /* Locate BOFM protocol */
00187         if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
00188                                             &bofm1.interface ) ) != 0 ) {
00189                 rc = -EEFI ( efirc );
00190                 DBGC ( device, "EFIBOFM %s cannot find BOFM protocol\n",
00191                        efi_handle_name ( device ) );
00192                 return rc;
00193         }
00194 
00195         /* Register support for this device */
00196         if ( ( efirc = bofm1.bofm1->RegisterSupport ( bofm1.bofm1, device,
00197                                                       0x04 /* Can change MAC */,
00198                                                       0x00 /* No iSCSI */,
00199                                                       0x02 /* Version */ ))!=0){
00200                 rc = -EEFI ( efirc );
00201                 DBGC ( device, "EFIBOFM %s could not register support: %s\n",
00202                        efi_handle_name ( device ), strerror ( rc ) );
00203                 return rc;
00204         }
00205 
00206         DBGC ( device, "EFIBOFM %s has driver \"%s\"\n",
00207                efi_handle_name ( device ), pci.id->name );
00208         return 0;
00209 }
00210 
00211 /**
00212  * Attach driver to device
00213  *
00214  * @v efidev            EFI device
00215  * @ret rc              Return status code
00216  */
00217 static int efi_bofm_start ( struct efi_device *efidev ) {
00218         EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
00219         EFI_HANDLE device = efidev->device;
00220         union {
00221                 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
00222                 void *interface;
00223         } bofm1;
00224         union {
00225                 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *bofm2;
00226                 void *interface;
00227         } bofm2;
00228         struct pci_device pci;
00229         IBM_BOFM_TABLE *bofmtab;
00230         IBM_BOFM_TABLE *bofmtab2;
00231         int bofmrc;
00232         EFI_STATUS efirc;
00233         int rc;
00234 
00235         /* Open PCI device, if possible */
00236         if ( ( rc = efipci_open ( device, EFI_OPEN_PROTOCOL_GET_PROTOCOL,
00237                                   &pci ) ) != 0 )
00238                 goto err_open;
00239 
00240         /* Locate BOFM protocol */
00241         if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
00242                                             &bofm1.interface ) ) != 0 ) {
00243                 rc = -EEFI ( efirc );
00244                 DBGC ( device, "EFIBOFM %s cannot find BOFM protocol\n",
00245                        efi_handle_name ( device ) );
00246                 goto err_locate_bofm;
00247         }
00248         bofmtab = &bofm1.bofm1->BofmTable;
00249         DBGC ( device, "EFIBOFM %s found version 1 BOFM table at %p+%04x\n",
00250                efi_handle_name ( device ), bofmtab, bofmtab->Parameters.Length);
00251 
00252         /* Locate BOFM2 protocol, if available */
00253         if ( ( efirc = bs->LocateProtocol ( &bofm2_protocol_guid, NULL,
00254                                             &bofm2.interface ) ) == 0 ) {
00255                 bofmtab2 = &bofm2.bofm2->BofmTable;
00256                 DBGC ( device, "EFIBOFM %s found version 2 BOFM table at "
00257                        "%p+%04x\n", efi_handle_name ( device ), bofmtab2,
00258                        bofmtab2->Parameters.Length );
00259                 assert ( bofm2.bofm2->RegisterSupport ==
00260                          bofm1.bofm1->RegisterSupport );
00261         } else {
00262                 DBGC ( device, "EFIBOFM %s cannot find BOFM2 protocol\n",
00263                        efi_handle_name ( device ) );
00264                 /* Not a fatal error; may be a BOFM1-only system */
00265                 bofmtab2 = NULL;
00266         }
00267 
00268         /* Process BOFM table */
00269         DBGC2 ( device, "EFIBOFM %s version 1 before processing:\n",
00270                 efi_handle_name ( device ) );
00271         DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
00272         if ( bofmtab2 ) {
00273                 DBGC2 ( device, "EFIBOFM %s version 2 before processing:\n",
00274                         efi_handle_name ( device ) );
00275                 DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
00276         }
00277         bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ), &pci );
00278         DBGC ( device, "EFIBOFM %s status %08x\n",
00279                efi_handle_name ( device ), bofmrc );
00280         DBGC2 ( device, "EFIBOFM %s version 1 after processing:\n",
00281                 efi_handle_name ( device ) );
00282         DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
00283         if ( bofmtab2 ) {
00284                 DBGC2 ( device, "EFIBOFM %s version 2 after processing:\n",
00285                         efi_handle_name ( device ) );
00286                 DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
00287         }
00288 
00289         /* Return BOFM status */
00290         if ( bofmtab2 ) {
00291                 if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device,
00292                                                         FALSE, bofmrc ) ) != 0){
00293                         rc = -EEFI ( efirc );
00294                         DBGC ( device, "EFIBOFM %s could not set BOFM2 "
00295                                "status: %s\n", efi_handle_name ( device ),
00296                                strerror ( rc ) );
00297                         goto err_set_status;
00298                 }
00299         } else {
00300                 if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device,
00301                                                         FALSE, bofmrc ) ) != 0){
00302                         rc = -EEFI ( efirc );
00303                         DBGC ( device, "EFIBOFM %s could not set BOFM "
00304                                "status: %s\n", efi_handle_name ( device ),
00305                                strerror ( rc ) );
00306                         goto err_set_status;
00307                 }
00308         }
00309 
00310         /* BOFM (ab)uses the "start" method to mean "process and exit" */
00311         rc = -EAGAIN;
00312 
00313  err_set_status:
00314  err_locate_bofm:
00315         efipci_close ( device );
00316  err_open:
00317         return rc;
00318 }
00319 
00320 /**
00321  * Detach driver from device
00322  *
00323  * @v device            EFI device
00324  */
00325 static void efi_bofm_stop ( struct efi_device *efidev __unused ) {
00326 
00327         /* Should never happen */
00328         assert ( 0 );
00329 }
00330 
00331 /** EFI BOFM driver */
00332 struct efi_driver efi_bofm_driver __efi_driver ( EFI_DRIVER_EARLY ) = {
00333         .name = "BOFM",
00334         .supported = efi_bofm_supported,
00335         .start = efi_bofm_start,
00336         .stop = efi_bofm_stop,
00337 };