iPXE
efi_bofm.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011 Michael Brown <mbrown@fensystems.co.uk>.
3 *
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.
8 *
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.
13 *
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
17 * 02110-1301, USA.
18 *
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.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26#include <string.h>
27#include <errno.h>
28#include <ipxe/bofm.h>
29#include <ipxe/efi/efi.h>
30#include <ipxe/efi/efi_pci.h>
31#include <ipxe/efi/efi_driver.h>
32
33/** @file
34 *
35 * IBM BladeCenter Open Fabric Manager (BOFM) EFI interface
36 *
37 */
38
39/***************************************************************************
40 *
41 * EFI BOFM definitions
42 *
43 ***************************************************************************
44 *
45 * Taken from the BOFM UEFI Vendor Specification document
46 *
47 */
48
49#define IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID \
50 { 0x03207ce2, 0xd9c7, 0x11dc, \
51 { 0xa9, 0x4d, 0x00, 0x19, 0x7d, 0x89, 0x02, 0x38 } }
52
53#define IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID \
54 { 0xe82a9763, 0x0584, 0x4e41, \
55 { 0xbb, 0x39, 0xe0, 0xcd, 0xb8, 0xc1, 0xf0, 0xfc } }
56
57typedef struct {
61
76
92
99
100#define IBM_BOFM_TABLE BOFM_DataStructure_t
101
104
107
108typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT ) (
114);
115
116typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS ) (
121);
122
123typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 ) (
128);
129
132 IBM_BOFM_DRIVER_CONFIGURATION_STATUS SetStatus;
133 IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
134};
135
140 IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 SetStatus;
141 IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
143};
144
145/***************************************************************************
146 *
147 * EFI BOFM interface
148 *
149 ***************************************************************************
150 */
151
152/** BOFM1 protocol GUID */
155
156/** BOFM2 protocol GUID */
159
160/**
161 * Check if device is supported
162 *
163 * @v device EFI device handle
164 * @ret rc Return status code
165 */
167 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
168 struct efi_pci_device efipci;
169 union {
171 void *interface;
172 } bofm1;
173 EFI_STATUS efirc;
174 int rc;
175
176 /* Get PCI device information */
177 if ( ( rc = efipci_info ( device, &efipci ) ) != 0 )
178 return rc;
179
180 /* Look for a BOFM driver */
181 if ( ( rc = bofm_find_driver ( &efipci.pci ) ) != 0 ) {
182 DBGCP ( device, "EFIBOFM %s has no driver\n",
184 return rc;
185 }
186
187 /* Locate BOFM protocol */
188 if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
189 &bofm1.interface ) ) != 0 ) {
190 rc = -EEFI ( efirc );
191 DBGC ( device, "EFIBOFM %s cannot find BOFM protocol\n",
193 return rc;
194 }
195
196 /* Register support for this device */
197 if ( ( efirc = bofm1.bofm1->RegisterSupport ( bofm1.bofm1, device,
198 0x04 /* Can change MAC */,
199 0x00 /* No iSCSI */,
200 0x02 /* Version */ ))!=0){
201 rc = -EEFI ( efirc );
202 DBGC ( device, "EFIBOFM %s could not register support: %s\n",
204 return rc;
205 }
206
207 DBGC ( device, "EFIBOFM %s has driver \"%s\"\n",
208 efi_handle_name ( device ), efipci.pci.id->name );
209 return 0;
210}
211
212/**
213 * Attach driver to device
214 *
215 * @v efidev EFI device
216 * @ret rc Return status code
217 */
218static int efi_bofm_start ( struct efi_device *efidev ) {
219 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
220 EFI_HANDLE device = efidev->device;
221 union {
223 void *interface;
224 } bofm1;
225 union {
227 void *interface;
228 } bofm2;
229 struct efi_pci_device efipci;
230 IBM_BOFM_TABLE *bofmtab;
231 IBM_BOFM_TABLE *bofmtab2;
232 int bofmrc;
233 EFI_STATUS efirc;
234 int rc;
235
236 /* Get PCI device information */
237 if ( ( rc = efipci_info ( device, &efipci ) ) != 0 ) {
238 DBGC ( device, "EFIBOFM %s cannot get PCI information: %s\n",
240 goto err_info;
241 }
242
243 /* Open PCI I/O protocol */
245 &efipci.io ) ) != 0 ) {
246 DBGC ( device, "EFIBOFM %s cannot open PCI device: %s\n",
248 goto err_open;
249 }
250
251 /* Locate BOFM protocol */
252 if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
253 &bofm1.interface ) ) != 0 ) {
254 rc = -EEFI ( efirc );
255 DBGC ( device, "EFIBOFM %s cannot find BOFM protocol\n",
257 goto err_locate_bofm;
258 }
259 bofmtab = &bofm1.bofm1->BofmTable;
260 DBGC ( device, "EFIBOFM %s found version 1 BOFM table at %p+%04x\n",
261 efi_handle_name ( device ), bofmtab, bofmtab->Parameters.Length);
262
263 /* Locate BOFM2 protocol, if available */
264 if ( ( efirc = bs->LocateProtocol ( &bofm2_protocol_guid, NULL,
265 &bofm2.interface ) ) == 0 ) {
266 bofmtab2 = &bofm2.bofm2->BofmTable;
267 DBGC ( device, "EFIBOFM %s found version 2 BOFM table at "
268 "%p+%04x\n", efi_handle_name ( device ), bofmtab2,
269 bofmtab2->Parameters.Length );
270 assert ( bofm2.bofm2->RegisterSupport ==
271 bofm1.bofm1->RegisterSupport );
272 } else {
273 DBGC ( device, "EFIBOFM %s cannot find BOFM2 protocol\n",
275 /* Not a fatal error; may be a BOFM1-only system */
276 bofmtab2 = NULL;
277 }
278
279 /* Process BOFM table */
280 DBGC2 ( device, "EFIBOFM %s version 1 before processing:\n",
282 DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
283 if ( bofmtab2 ) {
284 DBGC2 ( device, "EFIBOFM %s version 2 before processing:\n",
286 DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
287 }
288 bofmrc = bofm ( ( bofmtab2 ? bofmtab2 : bofmtab ), &efipci.pci );
289 DBGC ( device, "EFIBOFM %s status %08x\n",
290 efi_handle_name ( device ), bofmrc );
291 DBGC2 ( device, "EFIBOFM %s version 1 after processing:\n",
293 DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
294 if ( bofmtab2 ) {
295 DBGC2 ( device, "EFIBOFM %s version 2 after processing:\n",
297 DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
298 }
299
300 /* Return BOFM status */
301 if ( bofmtab2 ) {
302 if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device,
303 FALSE, bofmrc ) ) != 0){
304 rc = -EEFI ( efirc );
305 DBGC ( device, "EFIBOFM %s could not set BOFM2 "
306 "status: %s\n", efi_handle_name ( device ),
307 strerror ( rc ) );
308 goto err_set_status;
309 }
310 } else {
311 if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device,
312 FALSE, bofmrc ) ) != 0){
313 rc = -EEFI ( efirc );
314 DBGC ( device, "EFIBOFM %s could not set BOFM "
315 "status: %s\n", efi_handle_name ( device ),
316 strerror ( rc ) );
317 goto err_set_status;
318 }
319 }
320
321 /* BOFM (ab)uses the "start" method to mean "process and exit" */
322 rc = -EAGAIN;
323
324 err_set_status:
325 err_locate_bofm:
327 err_open:
328 err_info:
329 return rc;
330}
331
332/**
333 * Detach driver from device
334 *
335 * @v device EFI device
336 */
337static void efi_bofm_stop ( struct efi_device *efidev __unused ) {
338
339 /* Should never happen */
340 assert ( 0 );
341}
342
343/** EFI BOFM driver */
344struct efi_driver efi_bofm_driver __efi_driver ( EFI_DRIVER_EARLY ) = {
345 .name = "BOFM",
346 .supported = efi_bofm_supported,
347 .start = efi_bofm_start,
348 .stop = efi_bofm_stop,
349};
unsigned short UINT16
2-byte unsigned value.
unsigned char BOOLEAN
Logical Boolean.
unsigned long long UINT64
8-byte unsigned value.
#define EFIAPI
unsigned char UINT8
1-byte unsigned value.
unsigned int UINT32
4-byte unsigned value.
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
GUID EFI_GUID
128-bit buffer containing a unique identifier value.
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
int bofm_find_driver(struct pci_device *pci)
Find BOFM driver for PCI device.
Definition bofm.c:89
int bofm(void *bofmtab, struct pci_device *pci)
Process BOFM table.
Definition bofm.c:235
IBM BladeCenter Open Fabric Manager (BOFM)
EFI_HANDLE BOOLEAN UINT8 BOFMReturnCode
Definition efi_bofm.c:121
EFI_HANDLE UINT8 UINT8 UINT8 BOFM_Parameter_Version
Definition efi_bofm.c:114
#define IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID
Definition efi_bofm.c:49
static int efi_bofm_start(struct efi_device *efidev)
Attach driver to device.
Definition efi_bofm.c:218
EFI_HANDLE ControllerHandle
Definition efi_bofm.c:110
struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL
Definition efi_bofm.c:102
EFI_HANDLE UINT8 UINT8 iSCSI_Parameter_Version
Definition efi_bofm.c:112
struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2
Definition efi_bofm.c:105
EFI_HANDLE UINT8 SupporttedOptions
Definition efi_bofm.c:111
EFI_HANDLE BOOLEAN ResetRequired
Definition efi_bofm.c:119
static EFI_GUID bofm1_protocol_guid
BOFM1 protocol GUID.
Definition efi_bofm.c:153
static void efi_bofm_stop(struct efi_device *efidev __unused)
Detach driver from device.
Definition efi_bofm.c:337
static int efi_bofm_supported(EFI_HANDLE device)
Check if device is supported.
Definition efi_bofm.c:166
#define IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID
Definition efi_bofm.c:53
#define IBM_BOFM_TABLE
Definition efi_bofm.c:100
static EFI_GUID bofm2_protocol_guid
BOFM2 protocol GUID.
Definition efi_bofm.c:157
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition efi_debug.c:652
EFI driver interface.
#define __efi_driver(order)
Declare an EFI driver.
Definition efi_driver.h:70
#define EFI_DRIVER_EARLY
Early drivers.
Definition efi_driver.h:72
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition efi_guid.c:313
void efi_close_unsafe(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for unsafe persistent use.
Definition efi_open.c:219
int efipci_info(EFI_HANDLE device, struct efi_pci_device *efipci)
Get EFI PCI device information.
Definition efi_pci.c:711
EFI driver interface.
Error codes.
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define DBGC2(...)
Definition compiler.h:522
#define DBGC2_HD(...)
Definition compiler.h:524
#define DBGCP(...)
Definition compiler.h:539
#define DBGC(...)
Definition compiler.h:505
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define EAGAIN
Resource temporarily unavailable.
Definition errno.h:319
#define __attribute__(x)
Definition compiler.h:10
EFI API.
#define EFI_HANDLE
Definition efi.h:53
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:175
#define efi_open_unsafe(handle, protocol, interface)
Open protocol for unsafe persistent use.
Definition efi.h:459
EFI_SYSTEM_TABLE * efi_systab
String functions.
#define IN
Definition mlx_utils.h:28
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
BOFM_Results_t Results
Definition efi_bofm.c:97
BOFM_Parameters_t Parameters
Definition efi_bofm.c:96
UINT8 GlobalOption1
Definition efi_bofm.c:69
UINT8 Profile[32]
Definition efi_bofm.c:67
UINT8 Regions[911]
Definition efi_bofm.c:73
UINT32 SequenceStamp
Definition efi_bofm.c:72
UINT8 GlobalOption2
Definition efi_bofm.c:70
UINT8 GlobalOption3
Definition efi_bofm.c:71
UINT8 GlobalOption0
Definition efi_bofm.c:68
UINT8 SASTgtResults[2]
Definition efi_bofm.c:88
UINT8 Version
Definition efi_bofm.c:79
UINT8 Reserved2
Definition efi_bofm.c:85
UINT8 EntryResults[32]
Definition efi_bofm.c:84
BOFM_EPID_Results_t EPIDResults[2]
Definition efi_bofm.c:89
UINT32 SequenceStamp
Definition efi_bofm.c:82
UINT32 Reserved1
Definition efi_bofm.c:78
UINT8 FCTgtResults[2]
Definition efi_bofm.c:87
UINT8 Checksum
Definition efi_bofm.c:81
UINT8 Reserved3
Definition efi_bofm.c:86
UINT8 SUIDResults
Definition efi_bofm.c:83
UINT8 Results4[10]
Definition efi_bofm.c:90
EFI Boot Services Table.
Definition UefiSpec.h:1931
EFI_LOCATE_PROTOCOL LocateProtocol
Definition UefiSpec.h:2009
IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport
Definition efi_bofm.c:141
IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 SetStatus
Definition efi_bofm.c:140
IBM_BOFM_DRIVER_CONFIGURATION_STATUS SetStatus
Definition efi_bofm.c:132
IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport
Definition efi_bofm.c:133
A hardware device.
Definition device.h:77
An EFI device.
Definition efi_driver.h:18
EFI_HANDLE device
EFI device handle.
Definition efi_driver.h:22
An EFI driver.
Definition efi_driver.h:34
An EFI PCI device.
Definition efi_pci.h:22
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition efi_pci.h:26
struct pci_device pci
PCI device.
Definition efi_pci.h:24
An object interface.
Definition interface.h:125
const char * name
Name.
Definition pci.h:177
struct pci_device_id * id
Driver device ID.
Definition pci.h:248
#define FALSE
Definition tlan.h:45