You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

efi_bofm.c 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <errno.h>
  25. #include <ipxe/bofm.h>
  26. #include <ipxe/efi/efi.h>
  27. #include <ipxe/efi/efi_pci.h>
  28. #include <ipxe/efi/efi_driver.h>
  29. /** @file
  30. *
  31. * IBM BladeCenter Open Fabric Manager (BOFM) EFI interface
  32. *
  33. */
  34. /***************************************************************************
  35. *
  36. * EFI BOFM definitions
  37. *
  38. ***************************************************************************
  39. *
  40. * Taken from the BOFM UEFI Vendor Specification document
  41. *
  42. */
  43. #define IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID \
  44. { 0x03207ce2, 0xd9c7, 0x11dc, \
  45. { 0xa9, 0x4d, 0x00, 0x19, 0x7d, 0x89, 0x02, 0x38 } }
  46. #define IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID \
  47. { 0xe82a9763, 0x0584, 0x4e41, \
  48. { 0xbb, 0x39, 0xe0, 0xcd, 0xb8, 0xc1, 0xf0, 0xfc } }
  49. typedef struct {
  50. UINT8 Id;
  51. UINT8 ResultByte;
  52. } __attribute__ (( packed )) BOFM_EPID_Results_t;
  53. typedef struct {
  54. UINT8 Version;
  55. UINT8 Level;
  56. UINT16 Length;
  57. UINT8 Checksum;
  58. UINT8 Profile[32];
  59. UINT8 GlobalOption0;
  60. UINT8 GlobalOption1;
  61. UINT8 GlobalOption2;
  62. UINT8 GlobalOption3;
  63. UINT32 SequenceStamp;
  64. UINT8 Regions[911]; // For use by BOFM Driver
  65. UINT32 Reserved1;
  66. } __attribute__ (( packed )) BOFM_Parameters_t;
  67. typedef struct {
  68. UINT32 Reserved1;
  69. UINT8 Version;
  70. UINT8 Level;
  71. UINT8 Checksum;
  72. UINT32 SequenceStamp;
  73. UINT8 SUIDResults;
  74. UINT8 EntryResults[32];
  75. UINT8 Reserved2;
  76. UINT8 Reserved3;
  77. UINT8 FCTgtResults[2];
  78. UINT8 SASTgtResults[2];
  79. BOFM_EPID_Results_t EPIDResults[2];
  80. UINT8 Results4[10];
  81. } __attribute__ (( packed )) BOFM_Results_t;
  82. typedef struct {
  83. UINT32 Signature;
  84. UINT32 SubSignature;
  85. BOFM_Parameters_t Parameters;
  86. BOFM_Results_t Results;
  87. } __attribute__ (( packed )) BOFM_DataStructure_t;
  88. #define IBM_BOFM_TABLE BOFM_DataStructure_t
  89. typedef struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL
  90. IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL;
  91. typedef struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2
  92. IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2;
  93. typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT ) (
  94. IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This,
  95. EFI_HANDLE ControllerHandle,
  96. UINT8 SupporttedOptions,
  97. UINT8 iSCSI_Parameter_Version,
  98. UINT8 BOFM_Parameter_Version
  99. );
  100. typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS ) (
  101. IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *This,
  102. EFI_HANDLE ControllerHandle,
  103. BOOLEAN ResetRequired,
  104. UINT8 BOFMReturnCode
  105. );
  106. typedef EFI_STATUS ( EFIAPI *IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 ) (
  107. IN IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *This,
  108. EFI_HANDLE ControllerHandle,
  109. BOOLEAN ResetRequired,
  110. UINT8 BOFMReturnCode
  111. );
  112. struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL {
  113. IBM_BOFM_TABLE BofmTable;
  114. IBM_BOFM_DRIVER_CONFIGURATION_STATUS SetStatus;
  115. IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
  116. };
  117. struct _IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 {
  118. UINT32 Signature;
  119. UINT32 Reserved1;
  120. UINT64 Reserved2;
  121. IBM_BOFM_DRIVER_CONFIGURATION_STATUS2 SetStatus;
  122. IBM_BOFM_DRIVER_CONFIGURATION_SUPPORT RegisterSupport;
  123. IBM_BOFM_TABLE BofmTable;
  124. };
  125. /***************************************************************************
  126. *
  127. * EFI BOFM interface
  128. *
  129. ***************************************************************************
  130. */
  131. /** BOFM1 protocol GUID */
  132. static EFI_GUID bofm1_protocol_guid =
  133. IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL_GUID;
  134. /** BOFM2 protocol GUID */
  135. static EFI_GUID bofm2_protocol_guid =
  136. IBM_BOFM_DRIVER_CONFIGURATION2_PROTOCOL_GUID;
  137. /**
  138. * Check if device is supported
  139. *
  140. * @v device EFI device handle
  141. * @ret rc Return status code
  142. */
  143. static int efi_bofm_supported ( EFI_HANDLE device ) {
  144. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  145. struct pci_device pci;
  146. union {
  147. IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
  148. void *interface;
  149. } bofm1;
  150. EFI_STATUS efirc;
  151. int rc;
  152. /* Get PCI device information */
  153. if ( ( rc = efipci_info ( device, &pci ) ) != 0 )
  154. return rc;
  155. /* Look for a BOFM driver */
  156. if ( ( rc = bofm_find_driver ( &pci ) ) != 0 ) {
  157. DBGCP ( device, "EFIBOFM %s has no driver\n",
  158. efi_handle_name ( device ) );
  159. return rc;
  160. }
  161. /* Locate BOFM protocol */
  162. if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
  163. &bofm1.interface ) ) != 0 ) {
  164. rc = -EEFI ( efirc );
  165. DBGC ( device, "EFIBOFM %s cannot find BOFM protocol\n",
  166. efi_handle_name ( device ) );
  167. return rc;
  168. }
  169. /* Register support for this device */
  170. if ( ( efirc = bofm1.bofm1->RegisterSupport ( bofm1.bofm1, device,
  171. 0x04 /* Can change MAC */,
  172. 0x00 /* No iSCSI */,
  173. 0x02 /* Version */ ))!=0){
  174. rc = -EEFI ( efirc );
  175. DBGC ( device, "EFIBOFM %s could not register support: %s\n",
  176. efi_handle_name ( device ), strerror ( rc ) );
  177. return rc;
  178. }
  179. DBGC ( device, "EFIBOFM %s has driver \"%s\"\n",
  180. efi_handle_name ( device ), pci.id->name );
  181. return 0;
  182. }
  183. /**
  184. * Attach driver to device
  185. *
  186. * @v efidev EFI device
  187. * @ret rc Return status code
  188. */
  189. static int efi_bofm_start ( struct efi_device *efidev ) {
  190. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  191. EFI_HANDLE device = efidev->device;
  192. union {
  193. IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
  194. void *interface;
  195. } bofm1;
  196. union {
  197. IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *bofm2;
  198. void *interface;
  199. } bofm2;
  200. struct pci_device pci;
  201. IBM_BOFM_TABLE *bofmtab;
  202. IBM_BOFM_TABLE *bofmtab2;
  203. int bofmrc;
  204. EFI_STATUS efirc;
  205. int rc;
  206. /* Open PCI device, if possible */
  207. if ( ( rc = efipci_open ( device, EFI_OPEN_PROTOCOL_GET_PROTOCOL,
  208. &pci ) ) != 0 )
  209. goto err_open;
  210. /* Locate BOFM protocol */
  211. if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
  212. &bofm1.interface ) ) != 0 ) {
  213. rc = -EEFI ( efirc );
  214. DBGC ( device, "EFIBOFM %s cannot find BOFM protocol\n",
  215. efi_handle_name ( device ) );
  216. goto err_locate_bofm;
  217. }
  218. bofmtab = &bofm1.bofm1->BofmTable;
  219. DBGC ( device, "EFIBOFM %s found version 1 BOFM table at %p+%04x\n",
  220. efi_handle_name ( device ), bofmtab, bofmtab->Parameters.Length);
  221. /* Locate BOFM2 protocol, if available */
  222. if ( ( efirc = bs->LocateProtocol ( &bofm2_protocol_guid, NULL,
  223. &bofm2.interface ) ) == 0 ) {
  224. bofmtab2 = &bofm2.bofm2->BofmTable;
  225. DBGC ( device, "EFIBOFM %s found version 2 BOFM table at "
  226. "%p+%04x\n", efi_handle_name ( device ), bofmtab2,
  227. bofmtab2->Parameters.Length );
  228. assert ( bofm2.bofm2->RegisterSupport ==
  229. bofm1.bofm1->RegisterSupport );
  230. } else {
  231. DBGC ( device, "EFIBOFM %s cannot find BOFM2 protocol\n",
  232. efi_handle_name ( device ) );
  233. /* Not a fatal error; may be a BOFM1-only system */
  234. bofmtab2 = NULL;
  235. }
  236. /* Process BOFM table */
  237. DBGC2 ( device, "EFIBOFM %s version 1 before processing:\n",
  238. efi_handle_name ( device ) );
  239. DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
  240. if ( bofmtab2 ) {
  241. DBGC2 ( device, "EFIBOFM %s version 2 before processing:\n",
  242. efi_handle_name ( device ) );
  243. DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
  244. }
  245. bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ), &pci );
  246. DBGC ( device, "EFIBOFM %s status %08x\n",
  247. efi_handle_name ( device ), bofmrc );
  248. DBGC2 ( device, "EFIBOFM %s version 1 after processing:\n",
  249. efi_handle_name ( device ) );
  250. DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
  251. if ( bofmtab2 ) {
  252. DBGC2 ( device, "EFIBOFM %s version 2 after processing:\n",
  253. efi_handle_name ( device ) );
  254. DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
  255. }
  256. /* Return BOFM status */
  257. if ( bofmtab2 ) {
  258. if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device,
  259. FALSE, bofmrc ) ) != 0){
  260. rc = -EEFI ( efirc );
  261. DBGC ( device, "EFIBOFM %s could not set BOFM2 "
  262. "status: %s\n", efi_handle_name ( device ),
  263. strerror ( rc ) );
  264. goto err_set_status;
  265. }
  266. } else {
  267. if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device,
  268. FALSE, bofmrc ) ) != 0){
  269. rc = -EEFI ( efirc );
  270. DBGC ( device, "EFIBOFM %s could not set BOFM "
  271. "status: %s\n", efi_handle_name ( device ),
  272. strerror ( rc ) );
  273. goto err_set_status;
  274. }
  275. }
  276. /* BOFM (ab)uses the "start" method to mean "process and exit" */
  277. rc = -EAGAIN;
  278. err_set_status:
  279. err_locate_bofm:
  280. efipci_close ( device );
  281. err_open:
  282. return rc;
  283. }
  284. /**
  285. * Detach driver from device
  286. *
  287. * @v device EFI device
  288. */
  289. static void efi_bofm_stop ( struct efi_device *efidev __unused ) {
  290. /* Should never happen */
  291. assert ( 0 );
  292. }
  293. /** EFI BOFM driver */
  294. struct efi_driver efi_bofm_driver __efi_driver ( EFI_DRIVER_EARLY ) = {
  295. .name = "BOFM",
  296. .supported = efi_bofm_supported,
  297. .start = efi_bofm_start,
  298. .stop = efi_bofm_stop,
  299. };