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
20 FILE_LICENCE ( GPL2_OR_LATER );
23 #include <ipxe/bofm.h>
24 #include <ipxe/efi/efi.h>
25 #include <ipxe/efi/efi_pci.h>
26 #include <ipxe/efi/efi_driver.h>
30 * IBM BladeCenter Open Fabric Manager (BOFM) EFI interface
34 /***************************************************************************
36 * EFI BOFM definitions
38 ***************************************************************************
40 * Taken from the BOFM UEFI Vendor Specification document
44 #define IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID \
45 { 0x03207ce2, 0xd9c7, 0x11dc, \
46 { 0xa9, 0x4d, 0x00, 0x19, 0x7d, 0x89, 0x02, 0x38 } }
48 #define IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID \
49 { 0xe82a9763, 0x0584, 0x4e41, \
50 { 0xbb, 0x39, 0xe0, 0xcd, 0xb8, 0xc1, 0xf0, 0xfc } }
55 } __attribute__ (( packed )) BOFM_EPID_Results_t;
68 UINT8 Regions[911]; // For use by BOFM Driver
70 } __attribute__ (( packed )) BOFM_Parameters_t;
79 UINT8 EntryResults[32];
82 UINT8 FCTgtResults[2];
83 UINT8 SASTgtResults[2];
84 BOFM_EPID_Results_t EPIDResults[2];
86 } __attribute__ (( packed )) BOFM_Results_t;
91 BOFM_Parameters_t Parameters;
92 BOFM_Results_t Results;
93 } __attribute__ (( packed )) BOFM_DataStructure_t;
95 #define IBM_BOFM_TABLE BOFM_DataStructure_t
97 typedef struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL
98 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL;
100 typedef struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2
101 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2;
103 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT ) (
104 IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This,
105 EFI_HANDLE ControllerHandle,
106 UINT8 SupporttedOptions,
107 UINT8 iSCSI_Parameter_Version,
108 UINT8 BOFM_Parameter_Version
111 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS ) (
112 IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This,
113 EFI_HANDLE ControllerHandle,
114 BOOLEAN ResetRequired,
118 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 ) (
119 IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *This,
120 EFI_HANDLE ControllerHandle,
121 BOOLEAN ResetRequired,
125 struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL {
126 IBM_BOFM_TABLE BofmTable;
127 IBM_BOFM_DRIVER_CONFIGURATION_STATUS SetStatus;
128 IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
131 struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 {
135 IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 SetStatus;
136 IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
137 IBM_BOFM_TABLE BofmTable;
140 /***************************************************************************
144 ***************************************************************************
147 /** BOFM1 protocol GUID */
148 static EFI_GUID bofm1_protocol_guid =
149 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID;
151 /** BOFM2 protocol GUID */
152 static EFI_GUID bofm2_protocol_guid =
153 IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID;
156 * Check if device is supported
158 * @v device EFI device handle
159 * @ret rc Return status code
161 static int efi_bofm_supported ( EFI_HANDLE device ) {
162 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
163 struct pci_device pci;
165 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
171 /* Get PCI device information */
172 if ( ( rc = efipci_info ( device, &pci ) ) != 0 )
175 /* Look for a BOFM driver */
176 if ( ( rc = bofm_find_driver ( &pci ) ) != 0 ) {
177 DBGCP ( device, "EFIBOFM %p %s has no driver\n",
178 device, efi_handle_name ( device ) );
182 /* Locate BOFM protocol */
183 if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
184 &bofm1.interface ) ) != 0 ) {
185 rc = -EEFI ( efirc );
186 DBGC ( device, "EFIBOFM %p %s cannot find BOFM protocol\n",
187 device, efi_handle_name ( device ) );
191 /* Register support for this device */
192 if ( ( efirc = bofm1.bofm1->RegisterSupport ( bofm1.bofm1, device,
193 0x04 /* Can change MAC */,
195 0x02 /* Version */ ))!=0){
196 rc = -EEFI ( efirc );
197 DBGC ( device, "EFIBOFM %p %s could not register support: %s\n",
198 device, efi_handle_name ( device ), strerror ( rc ) );
202 DBGC ( device, "EFIBOFM %p %s has driver \"%s\"\n",
203 device, efi_handle_name ( device ), pci.id->name );
208 * Attach driver to device
210 * @v efidev EFI device
211 * @ret rc Return status code
213 static int efi_bofm_start ( struct efi_device *efidev ) {
214 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
215 EFI_HANDLE device = efidev->device;
217 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
221 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *bofm2;
224 struct pci_device pci;
225 IBM_BOFM_TABLE *bofmtab;
226 IBM_BOFM_TABLE *bofmtab2;
231 /* Open PCI device, if possible */
232 if ( ( rc = efipci_open ( device, EFI_OPEN_PROTOCOL_GET_PROTOCOL,
236 /* Locate BOFM protocol */
237 if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
238 &bofm1.interface ) ) != 0 ) {
239 rc = -EEFI ( efirc );
240 DBGC ( device, "EFIBOFM %p %s cannot find BOFM protocol\n",
241 device, efi_handle_name ( device ) );
242 goto err_locate_bofm;
244 bofmtab = &bofm1.bofm1->BofmTable;
245 DBGC ( device, "EFIBOFM %p %s found version 1 BOFM table at %p+%04x\n",
246 device, efi_handle_name ( device ), bofmtab,
247 bofmtab->Parameters.Length );
249 /* Locate BOFM2 protocol, if available */
250 if ( ( efirc = bs->LocateProtocol ( &bofm2_protocol_guid, NULL,
251 &bofm2.interface ) ) == 0 ) {
252 bofmtab2 = &bofm2.bofm2->BofmTable;
253 DBGC ( device, "EFIBOFM %p %s found version 2 BOFM table at "
254 "%p+%04x\n", device, efi_handle_name ( device ),
255 bofmtab2, bofmtab2->Parameters.Length );
256 assert ( bofm2.bofm2->RegisterSupport ==
257 bofm1.bofm1->RegisterSupport );
259 DBGC ( device, "EFIBOFM %p %s cannot find BOFM2 protocol\n",
260 device, efi_handle_name ( device ) );
261 /* Not a fatal error; may be a BOFM1-only system */
265 /* Process BOFM table */
266 DBGC2 ( device, "EFIBOFM %p %s version 1 before processing:\n",
267 device, efi_handle_name ( device ) );
268 DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
270 DBGC2 ( device, "EFIBOFM %p %s version 2 before processing:\n",
271 device, efi_handle_name ( device ) );
272 DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
274 bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ), &pci );
275 DBGC ( device, "EFIBOFM %p %s status %08x\n",
276 device, efi_handle_name ( device ), bofmrc );
277 DBGC2 ( device, "EFIBOFM %p %s version 1 after processing:\n",
278 device, efi_handle_name ( device ) );
279 DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
281 DBGC2 ( device, "EFIBOFM %p %s version 2 after processing:\n",
282 device, efi_handle_name ( device ) );
283 DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
286 /* Return BOFM status */
288 if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device,
289 FALSE, bofmrc ) ) != 0){
290 rc = -EEFI ( efirc );
291 DBGC ( device, "EFIBOFM %p %s could not set BOFM2 "
292 "status: %s\n", device,
293 efi_handle_name ( device ), strerror ( rc ) );
297 if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device,
298 FALSE, bofmrc ) ) != 0){
299 rc = -EEFI ( efirc );
300 DBGC ( device, "EFIBOFM %p %s could not set BOFM "
301 "status: %s\n", device,
302 efi_handle_name ( device ), strerror ( rc ) );
307 /* BOFM (ab)uses the "start" method to mean "process and exit" */
312 efipci_close ( device );
318 * Detach driver from device
320 * @v device EFI device
322 static void efi_bofm_stop ( struct efi_device *efidev __unused ) {
324 /* Should never happen */
328 /** EFI BOFM driver */
329 struct efi_driver efi_bofm_driver __efi_driver ( EFI_DRIVER_EARLY ) = {
331 .supported = efi_bofm_supported,
332 .start = efi_bofm_start,
333 .stop = efi_bofm_stop,