2 * Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
27 #include <ipxe/bofm.h>
28 #include <ipxe/efi/efi.h>
29 #include <ipxe/efi/efi_pci.h>
30 #include <ipxe/efi/efi_driver.h>
34 * IBM BladeCenter Open Fabric Manager (BOFM) EFI interface
38 /***************************************************************************
40 * EFI BOFM definitions
42 ***************************************************************************
44 * Taken from the BOFM UEFI Vendor Specification document
48 #define IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID \
49 { 0x03207ce2, 0xd9c7, 0x11dc, \
50 { 0xa9, 0x4d, 0x00, 0x19, 0x7d, 0x89, 0x02, 0x38 } }
52 #define IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID \
53 { 0xe82a9763, 0x0584, 0x4e41, \
54 { 0xbb, 0x39, 0xe0, 0xcd, 0xb8, 0xc1, 0xf0, 0xfc } }
59 } __attribute__ (( packed )) BOFM_EPID_Results_t;
72 UINT8 Regions[911]; // For use by BOFM Driver
74 } __attribute__ (( packed )) BOFM_Parameters_t;
83 UINT8 EntryResults[32];
86 UINT8 FCTgtResults[2];
87 UINT8 SASTgtResults[2];
88 BOFM_EPID_Results_t EPIDResults[2];
90 } __attribute__ (( packed )) BOFM_Results_t;
95 BOFM_Parameters_t Parameters;
96 BOFM_Results_t Results;
97 } __attribute__ (( packed )) BOFM_DataStructure_t;
99 #define IBM_BOFM_TABLE BOFM_DataStructure_t
101 typedef struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL
102 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL;
104 typedef struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2
105 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2;
107 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT ) (
108 IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This,
109 EFI_HANDLE ControllerHandle,
110 UINT8 SupporttedOptions,
111 UINT8 iSCSI_Parameter_Version,
112 UINT8 BOFM_Parameter_Version
115 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS ) (
116 IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This,
117 EFI_HANDLE ControllerHandle,
118 BOOLEAN ResetRequired,
122 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 ) (
123 IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *This,
124 EFI_HANDLE ControllerHandle,
125 BOOLEAN ResetRequired,
129 struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL {
130 IBM_BOFM_TABLE BofmTable;
131 IBM_BOFM_DRIVER_CONFIGURATION_STATUS SetStatus;
132 IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
135 struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 {
139 IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 SetStatus;
140 IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
141 IBM_BOFM_TABLE BofmTable;
144 /***************************************************************************
148 ***************************************************************************
151 /** BOFM1 protocol GUID */
152 static EFI_GUID bofm1_protocol_guid =
153 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID;
155 /** BOFM2 protocol GUID */
156 static EFI_GUID bofm2_protocol_guid =
157 IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID;
160 * Check if device is supported
162 * @v device EFI device handle
163 * @ret rc Return status code
165 static int efi_bofm_supported ( EFI_HANDLE device ) {
166 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
167 struct pci_device pci;
169 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
175 /* Get PCI device information */
176 if ( ( rc = efipci_info ( device, &pci ) ) != 0 )
179 /* Look for a BOFM driver */
180 if ( ( rc = bofm_find_driver ( &pci ) ) != 0 ) {
181 DBGCP ( device, "EFIBOFM %p %s has no driver\n",
182 device, efi_handle_name ( device ) );
186 /* Locate BOFM protocol */
187 if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
188 &bofm1.interface ) ) != 0 ) {
189 rc = -EEFI ( efirc );
190 DBGC ( device, "EFIBOFM %p %s cannot find BOFM protocol\n",
191 device, efi_handle_name ( device ) );
195 /* Register support for this device */
196 if ( ( efirc = bofm1.bofm1->RegisterSupport ( bofm1.bofm1, device,
197 0x04 /* Can change MAC */,
199 0x02 /* Version */ ))!=0){
200 rc = -EEFI ( efirc );
201 DBGC ( device, "EFIBOFM %p %s could not register support: %s\n",
202 device, efi_handle_name ( device ), strerror ( rc ) );
206 DBGC ( device, "EFIBOFM %p %s has driver \"%s\"\n",
207 device, efi_handle_name ( device ), pci.id->name );
212 * Attach driver to device
214 * @v efidev EFI device
215 * @ret rc Return status code
217 static int efi_bofm_start ( struct efi_device *efidev ) {
218 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
219 EFI_HANDLE device = efidev->device;
221 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
225 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *bofm2;
228 struct pci_device pci;
229 IBM_BOFM_TABLE *bofmtab;
230 IBM_BOFM_TABLE *bofmtab2;
235 /* Open PCI device, if possible */
236 if ( ( rc = efipci_open ( device, EFI_OPEN_PROTOCOL_GET_PROTOCOL,
240 /* Locate BOFM protocol */
241 if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
242 &bofm1.interface ) ) != 0 ) {
243 rc = -EEFI ( efirc );
244 DBGC ( device, "EFIBOFM %p %s cannot find BOFM protocol\n",
245 device, efi_handle_name ( device ) );
246 goto err_locate_bofm;
248 bofmtab = &bofm1.bofm1->BofmTable;
249 DBGC ( device, "EFIBOFM %p %s found version 1 BOFM table at %p+%04x\n",
250 device, efi_handle_name ( device ), bofmtab,
251 bofmtab->Parameters.Length );
253 /* Locate BOFM2 protocol, if available */
254 if ( ( efirc = bs->LocateProtocol ( &bofm2_protocol_guid, NULL,
255 &bofm2.interface ) ) == 0 ) {
256 bofmtab2 = &bofm2.bofm2->BofmTable;
257 DBGC ( device, "EFIBOFM %p %s found version 2 BOFM table at "
258 "%p+%04x\n", device, efi_handle_name ( device ),
259 bofmtab2, bofmtab2->Parameters.Length );
260 assert ( bofm2.bofm2->RegisterSupport ==
261 bofm1.bofm1->RegisterSupport );
263 DBGC ( device, "EFIBOFM %p %s cannot find BOFM2 protocol\n",
264 device, efi_handle_name ( device ) );
265 /* Not a fatal error; may be a BOFM1-only system */
269 /* Process BOFM table */
270 DBGC2 ( device, "EFIBOFM %p %s version 1 before processing:\n",
271 device, efi_handle_name ( device ) );
272 DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
274 DBGC2 ( device, "EFIBOFM %p %s version 2 before processing:\n",
275 device, efi_handle_name ( device ) );
276 DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
278 bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ), &pci );
279 DBGC ( device, "EFIBOFM %p %s status %08x\n",
280 device, efi_handle_name ( device ), bofmrc );
281 DBGC2 ( device, "EFIBOFM %p %s version 1 after processing:\n",
282 device, efi_handle_name ( device ) );
283 DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
285 DBGC2 ( device, "EFIBOFM %p %s version 2 after processing:\n",
286 device, efi_handle_name ( device ) );
287 DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
290 /* Return BOFM status */
292 if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device,
293 FALSE, bofmrc ) ) != 0){
294 rc = -EEFI ( efirc );
295 DBGC ( device, "EFIBOFM %p %s could not set BOFM2 "
296 "status: %s\n", device,
297 efi_handle_name ( device ), strerror ( rc ) );
301 if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device,
302 FALSE, bofmrc ) ) != 0){
303 rc = -EEFI ( efirc );
304 DBGC ( device, "EFIBOFM %p %s could not set BOFM "
305 "status: %s\n", device,
306 efi_handle_name ( device ), strerror ( rc ) );
311 /* BOFM (ab)uses the "start" method to mean "process and exit" */
316 efipci_close ( device );
322 * Detach driver from device
324 * @v device EFI device
326 static void efi_bofm_stop ( struct efi_device *efidev __unused ) {
328 /* Should never happen */
332 /** EFI BOFM driver */
333 struct efi_driver efi_bofm_driver __efi_driver ( EFI_DRIVER_EARLY ) = {
335 .supported = efi_bofm_supported,
336 .start = efi_bofm_start,
337 .stop = efi_bofm_stop,