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

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