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 <errno.h>
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>
31 
32 /** @file
33  *
34  * IBM BladeCenter Open Fabric Manager (BOFM) EFI interface
35  *
36  */
37 
38 /***************************************************************************
39  *
40  * EFI BOFM definitions
41  *
42  ***************************************************************************
43  *
44  * Taken from the BOFM UEFI Vendor Specification document
45  *
46  */
47 
48 #define IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID \
49  { 0x03207ce2, 0xd9c7, 0x11dc, \
50  { 0xa9, 0x4d, 0x00, 0x19, 0x7d, 0x89, 0x02, 0x38 } }
51 
52 #define IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID \
53  { 0xe82a9763, 0x0584, 0x4e41, \
54  { 0xbb, 0x39, 0xe0, 0xcd, 0xb8, 0xc1, 0xf0, 0xfc } }
55 
56 typedef struct {
59 } __attribute__ (( packed )) BOFM_EPID_Results_t;
60 
61 typedef struct {
66  UINT8 Profile[32];
72  UINT8 Regions[911]; // For use by BOFM Driver
74 } __attribute__ (( packed )) BOFM_Parameters_t;
75 
76 typedef struct {
83  UINT8 EntryResults[32];
86  UINT8 FCTgtResults[2];
87  UINT8 SASTgtResults[2];
88  BOFM_EPID_Results_t EPIDResults[2];
89  UINT8 Results4[10];
90 } __attribute__ (( packed )) BOFM_Results_t;
91 
92 typedef struct {
97 } __attribute__ (( packed )) BOFM_DataStructure_t;
98 
99 #define IBM_BOFM_TABLE BOFM_DataStructure_t
100 
103 
106 
107 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT ) (
113 );
114 
115 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS ) (
120 );
121 
122 typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 ) (
127 );
128 
131  IBM_BOFM_DRIVER_CONFIGURATION_STATUS SetStatus;
132  IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
133 };
134 
139  IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 SetStatus;
140  IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
142 };
143 
144 /***************************************************************************
145  *
146  * EFI BOFM interface
147  *
148  ***************************************************************************
149  */
150 
151 /** BOFM1 protocol GUID */
154 
155 /** BOFM2 protocol GUID */
158 
159 /**
160  * Check if device is supported
161  *
162  * @v device EFI device handle
163  * @ret rc Return status code
164  */
167  struct efi_pci_device efipci;
168  union {
170  void *interface;
171  } bofm1;
172  EFI_STATUS efirc;
173  int rc;
174 
175  /* Get PCI device information */
176  if ( ( rc = efipci_info ( device, &efipci ) ) != 0 )
177  return rc;
178 
179  /* Look for a BOFM driver */
180  if ( ( rc = bofm_find_driver ( &efipci.pci ) ) != 0 ) {
181  DBGCP ( device, "EFIBOFM %s has no driver\n",
182  efi_handle_name ( device ) );
183  return rc;
184  }
185 
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 %s cannot find BOFM protocol\n",
191  efi_handle_name ( device ) );
192  return rc;
193  }
194 
195  /* Register support for this device */
196  if ( ( efirc = bofm1.bofm1->RegisterSupport ( bofm1.bofm1, device,
197  0x04 /* Can change MAC */,
198  0x00 /* No iSCSI */,
199  0x02 /* Version */ ))!=0){
200  rc = -EEFI ( efirc );
201  DBGC ( device, "EFIBOFM %s could not register support: %s\n",
202  efi_handle_name ( device ), strerror ( rc ) );
203  return rc;
204  }
205 
206  DBGC ( device, "EFIBOFM %s has driver \"%s\"\n",
207  efi_handle_name ( device ), efipci.pci.id->name );
208  return 0;
209 }
210 
211 /**
212  * Attach driver to device
213  *
214  * @v efidev EFI device
215  * @ret rc Return status code
216  */
217 static int efi_bofm_start ( struct efi_device *efidev ) {
219  EFI_HANDLE device = efidev->device;
220  union {
222  void *interface;
223  } bofm1;
224  union {
226  void *interface;
227  } bofm2;
228  struct efi_pci_device efipci;
229  IBM_BOFM_TABLE *bofmtab;
230  IBM_BOFM_TABLE *bofmtab2;
231  int bofmrc;
232  EFI_STATUS efirc;
233  int rc;
234 
235  /* Open PCI device, if possible */
237  &efipci ) ) != 0 )
238  goto err_open;
239 
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 %s cannot find BOFM protocol\n",
245  efi_handle_name ( device ) );
246  goto err_locate_bofm;
247  }
248  bofmtab = &bofm1.bofm1->BofmTable;
249  DBGC ( device, "EFIBOFM %s found version 1 BOFM table at %p+%04x\n",
250  efi_handle_name ( device ), bofmtab, bofmtab->Parameters.Length);
251 
252  /* Locate BOFM2 protocol, if available */
253  if ( ( efirc = bs->LocateProtocol ( &bofm2_protocol_guid, NULL,
254  &bofm2.interface ) ) == 0 ) {
255  bofmtab2 = &bofm2.bofm2->BofmTable;
256  DBGC ( device, "EFIBOFM %s found version 2 BOFM table at "
257  "%p+%04x\n", efi_handle_name ( device ), bofmtab2,
258  bofmtab2->Parameters.Length );
259  assert ( bofm2.bofm2->RegisterSupport ==
260  bofm1.bofm1->RegisterSupport );
261  } else {
262  DBGC ( device, "EFIBOFM %s cannot find BOFM2 protocol\n",
263  efi_handle_name ( device ) );
264  /* Not a fatal error; may be a BOFM1-only system */
265  bofmtab2 = NULL;
266  }
267 
268  /* Process BOFM table */
269  DBGC2 ( device, "EFIBOFM %s version 1 before processing:\n",
270  efi_handle_name ( device ) );
271  DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
272  if ( bofmtab2 ) {
273  DBGC2 ( device, "EFIBOFM %s version 2 before processing:\n",
274  efi_handle_name ( device ) );
275  DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
276  }
277  bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ),
278  &efipci.pci );
279  DBGC ( device, "EFIBOFM %s status %08x\n",
280  efi_handle_name ( device ), bofmrc );
281  DBGC2 ( device, "EFIBOFM %s version 1 after processing:\n",
282  efi_handle_name ( device ) );
283  DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
284  if ( bofmtab2 ) {
285  DBGC2 ( device, "EFIBOFM %s version 2 after processing:\n",
286  efi_handle_name ( device ) );
287  DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
288  }
289 
290  /* Return BOFM status */
291  if ( bofmtab2 ) {
292  if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device,
293  FALSE, bofmrc ) ) != 0){
294  rc = -EEFI ( efirc );
295  DBGC ( device, "EFIBOFM %s could not set BOFM2 "
296  "status: %s\n", efi_handle_name ( device ),
297  strerror ( rc ) );
298  goto err_set_status;
299  }
300  } else {
301  if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device,
302  FALSE, bofmrc ) ) != 0){
303  rc = -EEFI ( efirc );
304  DBGC ( device, "EFIBOFM %s could not set BOFM "
305  "status: %s\n", efi_handle_name ( device ),
306  strerror ( rc ) );
307  goto err_set_status;
308  }
309  }
310 
311  /* BOFM (ab)uses the "start" method to mean "process and exit" */
312  rc = -EAGAIN;
313 
314  err_set_status:
315  err_locate_bofm:
316  efipci_close ( device );
317  err_open:
318  return rc;
319 }
320 
321 /**
322  * Detach driver from device
323  *
324  * @v device EFI device
325  */
326 static void efi_bofm_stop ( struct efi_device *efidev __unused ) {
327 
328  /* Should never happen */
329  assert ( 0 );
330 }
331 
332 /** EFI BOFM driver */
333 struct efi_driver efi_bofm_driver __efi_driver ( EFI_DRIVER_EARLY ) = {
334  .name = "BOFM",
335  .supported = efi_bofm_supported,
336  .start = efi_bofm_start,
337  .stop = efi_bofm_stop,
338 };
#define __attribute__(x)
Definition: compiler.h:10
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2081
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:171
int efipci_info(EFI_HANDLE device, struct efi_pci_device *efipci)
Get EFI PCI device information.
Definition: efi_pci.c:872
EFI driver interface.
#define IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID
Definition: efi_bofm.c:52
IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport
Definition: efi_bofm.c:132
struct pci_device pci
PCI device.
Definition: efi_pci.h:23
EFI_LOCATE_PROTOCOL LocateProtocol
Definition: UefiSpec.h:1995
128 bit buffer containing a unique identifier value.
Definition: Base.h:215
Error codes.
IBM_BOFM_DRIVER_CONFIGURATION_STATUS SetStatus
Definition: efi_bofm.c:131
static void efi_bofm_stop(struct efi_device *efidev __unused)
Detach driver from device.
Definition: efi_bofm.c:326
unsigned char BOOLEAN
BOFM_Parameters_t Parameters
Definition: efi_bofm.c:95
static int efi_bofm_start(struct efi_device *efidev)
Attach driver to device.
Definition: efi_bofm.c:217
#define IBM_BOFM_TABLE
Definition: efi_bofm.c:99
IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport
Definition: efi_bofm.c:140
int efipci_open(EFI_HANDLE device, UINT32 attributes, struct efi_pci_device *efipci)
Open EFI PCI device.
Definition: efi_pci.c:781
#define DBGC(...)
Definition: compiler.h:505
UINT8 Level
Definition: efi_bofm.c:79
UINT8 GlobalOption0
Definition: efi_bofm.c:67
unsigned int UINT32
Definition: ProcessorBind.h:98
UINT8 GlobalOption2
Definition: efi_bofm.c:69
EFI_HANDLE BOOLEAN ResetRequired
Definition: efi_bofm.c:117
#define EFI_DRIVER_EARLY
Early drivers.
Definition: efi_driver.h:64
EFI_HANDLE device
EFI device handle.
Definition: efi_driver.h:21
UINT32 SequenceStamp
Definition: efi_bofm.c:81
unsigned char UINT8
A hardware device.
Definition: device.h:73
IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 SetStatus
Definition: efi_bofm.c:139
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
IBM BladeCenter Open Fabric Manager (BOFM)
UINT8 GlobalOption3
Definition: efi_bofm.c:70
#define IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID
Definition: efi_bofm.c:48
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
An object interface.
Definition: interface.h:124
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:165
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL
Definition: UefiSpec.h:1344
unsigned short UINT16
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:808
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define EFIAPI
EFI Boot Services Table.
Definition: UefiSpec.h:1917
#define DBGC2_HD(...)
Definition: compiler.h:524
UINT32 Reserved1
Definition: efi_bofm.c:77
UINT8 Checksum
Definition: efi_bofm.c:80
EFI_HANDLE UINT8 UINT8 iSCSI_Parameter_Version
Definition: efi_bofm.c:109
UINT8 Reserved2
Definition: efi_bofm.c:84
UINT32 Reserved1
Definition: efi_bofm.c:73
An EFI device.
Definition: efi_driver.h:17
unsigned long long UINT64
Definition: ProcessorBind.h:96
const char * name
Name.
Definition: pci.h:172
EFI_HANDLE ControllerHandle
Definition: efi_bofm.c:109
#define EAGAIN
Resource temporarily unavailable.
Definition: errno.h:318
EFI API.
#define IN
Definition: mlx_utils.h:28
An EFI driver.
Definition: efi_driver.h:33
An EFI PCI device.
Definition: efi_pci.h:21
EFI_HANDLE UINT8 UINT8 UINT8 BOFM_Parameter_Version
Definition: efi_bofm.c:109
static EFI_GUID bofm2_protocol_guid
BOFM2 protocol GUID.
Definition: efi_bofm.c:156
#define DBGC2(...)
Definition: compiler.h:522
int bofm(userptr_t bofmtab, struct pci_device *pci)
Process BOFM table.
Definition: bofm.c:238
BOFM_Results_t Results
Definition: efi_bofm.c:96
typedef EFI_STATUS(EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT)(IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This
void efipci_close(EFI_HANDLE device)
Close EFI PCI device.
Definition: efi_pci.c:858
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:152
EFI driver interface.
struct pci_device_id * id
Driver device ID.
Definition: pci.h:243
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
UINT32 SequenceStamp
Definition: efi_bofm.c:71
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:85
int bofm_find_driver(struct pci_device *pci)
Find BOFM driver for PCI device.
Definition: bofm.c:90
EFI_SYSTEM_TABLE * efi_systab
EFI_HANDLE BOOLEAN UINT8 BOFMReturnCode
Definition: efi_bofm.c:117
EFI_HANDLE UINT8 SupporttedOptions
Definition: efi_bofm.c:109
UINT8 Version
Definition: efi_bofm.c:78
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
UINT8 GlobalOption1
Definition: efi_bofm.c:68
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
Definition: efi.h:59
UINT8 SUIDResults
Definition: efi_bofm.c:82