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 
24 FILE_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 
57 typedef struct {
60 } __attribute__ (( packed )) BOFM_EPID_Results_t;
61 
62 typedef struct {
67  UINT8 Profile[32];
73  UINT8 Regions[911]; // For use by BOFM Driver
75 } __attribute__ (( packed )) BOFM_Parameters_t;
76 
77 typedef struct {
84  UINT8 EntryResults[32];
87  UINT8 FCTgtResults[2];
88  UINT8 SASTgtResults[2];
89  BOFM_EPID_Results_t EPIDResults[2];
90  UINT8 Results4[10];
91 } __attribute__ (( packed )) BOFM_Results_t;
92 
93 typedef struct {
98 } __attribute__ (( packed )) BOFM_DataStructure_t;
99 
100 #define IBM_BOFM_TABLE BOFM_DataStructure_t
101 
104 
107 
108 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT ) (
114 );
115 
116 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS ) (
121 );
122 
123 typedef 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  */
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",
183  efi_handle_name ( device ) );
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",
192  efi_handle_name ( device ) );
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",
203  efi_handle_name ( device ), strerror ( rc ) );
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  */
218 static int efi_bofm_start ( struct efi_device *efidev ) {
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",
239  efi_handle_name ( device ), strerror ( rc ) );
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",
247  efi_handle_name ( device ), strerror ( rc ) );
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",
256  efi_handle_name ( device ) );
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",
274  efi_handle_name ( device ) );
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",
281  efi_handle_name ( device ) );
282  DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
283  if ( bofmtab2 ) {
284  DBGC2 ( device, "EFIBOFM %s version 2 before processing:\n",
285  efi_handle_name ( device ) );
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",
292  efi_handle_name ( device ) );
293  DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
294  if ( bofmtab2 ) {
295  DBGC2 ( device, "EFIBOFM %s version 2 after processing:\n",
296  efi_handle_name ( device ) );
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  */
337 static void efi_bofm_stop ( struct efi_device *efidev __unused ) {
338 
339  /* Should never happen */
340  assert ( 0 );
341 }
342 
343 /** EFI BOFM driver */
344 struct 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 };
#define __attribute__(x)
Definition: compiler.h:10
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2098
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:174
int efipci_info(EFI_HANDLE device, struct efi_pci_device *efipci)
Get EFI PCI device information.
Definition: efi_pci.c:704
EFI driver interface.
#define IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID
Definition: efi_bofm.c:53
IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport
Definition: efi_bofm.c:133
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
EFI_LOCATE_PROTOCOL LocateProtocol
Definition: UefiSpec.h:2008
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
Error codes.
IBM_BOFM_DRIVER_CONFIGURATION_STATUS SetStatus
Definition: efi_bofm.c:132
static void efi_bofm_stop(struct efi_device *efidev __unused)
Detach driver from device.
Definition: efi_bofm.c:337
EFI_GUID efi_pci_io_protocol_guid
PCI I/O protocol GUID.
Definition: efi_guid.c:312
#define efi_open_unsafe(handle, protocol, interface)
Open protocol for unsafe persistent use.
Definition: efi.h:458
unsigned char BOOLEAN
BOFM_Parameters_t Parameters
Definition: efi_bofm.c:96
static int efi_bofm_start(struct efi_device *efidev)
Attach driver to device.
Definition: efi_bofm.c:218
#define IBM_BOFM_TABLE
Definition: efi_bofm.c:100
IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport
Definition: efi_bofm.c:141
#define DBGC(...)
Definition: compiler.h:505
UINT8 Level
Definition: efi_bofm.c:80
UINT8 GlobalOption0
Definition: efi_bofm.c:68
unsigned int UINT32
Definition: ProcessorBind.h:98
UINT8 GlobalOption2
Definition: efi_bofm.c:70
EFI_HANDLE BOOLEAN ResetRequired
Definition: efi_bofm.c:118
#define EFI_DRIVER_EARLY
Early drivers.
Definition: efi_driver.h:71
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
UINT32 SequenceStamp
Definition: efi_bofm.c:82
unsigned char UINT8
A hardware device.
Definition: device.h:76
void efi_close_unsafe(EFI_HANDLE handle, EFI_GUID *protocol)
Close protocol opened for unsafe persistent use.
Definition: efi_open.c:218
IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 SetStatus
Definition: efi_bofm.c:140
IBM BladeCenter Open Fabric Manager (BOFM)
UINT8 GlobalOption3
Definition: efi_bofm.c:71
#define IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID
Definition: efi_bofm.c:49
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
An object interface.
Definition: interface.h:124
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
struct efi_driver efi_bofm_driver __efi_driver(EFI_DRIVER_EARLY)
EFI BOFM driver.
static int efi_bofm_supported(EFI_HANDLE device)
Check if device is supported.
Definition: efi_bofm.c:166
unsigned short UINT16
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:652
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define EFIAPI
EFI Boot Services Table.
Definition: UefiSpec.h:1930
#define DBGC2_HD(...)
Definition: compiler.h:524
UINT32 Reserved1
Definition: efi_bofm.c:78
UINT8 Checksum
Definition: efi_bofm.c:81
EFI_HANDLE UINT8 UINT8 iSCSI_Parameter_Version
Definition: efi_bofm.c:110
UINT8 Reserved2
Definition: efi_bofm.c:85
UINT32 Reserved1
Definition: efi_bofm.c:74
An EFI device.
Definition: efi_driver.h:17
unsigned long long UINT64
Definition: ProcessorBind.h:96
const char * name
Name.
Definition: pci.h:176
EFI_HANDLE ControllerHandle
Definition: efi_bofm.c:110
#define EAGAIN
Resource temporarily unavailable.
Definition: errno.h:318
EFI API.
#define IN
Definition: mlx_utils.h:28
EFI_PCI_IO_PROTOCOL * io
PCI I/O protocol.
Definition: efi_pci.h:25
An EFI driver.
Definition: efi_driver.h:33
An EFI PCI device.
Definition: efi_pci.h:21
int bofm(void *bofmtab, struct pci_device *pci)
Process BOFM table.
Definition: bofm.c:235
EFI_HANDLE UINT8 UINT8 UINT8 BOFM_Parameter_Version
Definition: efi_bofm.c:110
static EFI_GUID bofm2_protocol_guid
BOFM2 protocol GUID.
Definition: efi_bofm.c:157
#define DBGC2(...)
Definition: compiler.h:522
BOFM_Results_t Results
Definition: efi_bofm.c:97
typedef EFI_STATUS(EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT)(IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:31
static EFI_GUID bofm1_protocol_guid
BOFM1 protocol GUID.
Definition: efi_bofm.c:153
EFI driver interface.
struct pci_device_id * id
Driver device ID.
Definition: pci.h:247
UINT32 SequenceStamp
Definition: efi_bofm.c:72
const char * name
Name.
Definition: efi_driver.h:35
#define DBGCP(...)
Definition: compiler.h:539
#define FALSE
Definition: tlan.h:45
UINT8 Reserved3
Definition: efi_bofm.c:86
int bofm_find_driver(struct pci_device *pci)
Find BOFM driver for PCI device.
Definition: bofm.c:89
EFI_SYSTEM_TABLE * efi_systab
EFI_HANDLE BOOLEAN UINT8 BOFMReturnCode
Definition: efi_bofm.c:118
EFI_HANDLE UINT8 SupporttedOptions
Definition: efi_bofm.c:110
UINT8 Version
Definition: efi_bofm.c:79
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
UINT8 GlobalOption1
Definition: efi_bofm.c:69
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
String functions.
Definition: efi.h:61
UINT8 SUIDResults
Definition: efi_bofm.c:83