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.5KB

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. 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_devpath_text ( 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_devpath_text ( 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_devpath_text ( device ),
  173. strerror ( rc ) );
  174. return rc;
  175. }
  176. DBGC ( device, "EFIBOFM %p %s has driver \"%s\"\n",
  177. device, efi_handle_devpath_text ( device ), pci.id->name );
  178. return 0;
  179. }
  180. /**
  181. * Attach driver to device
  182. *
  183. * @v efidev EFI device
  184. * @ret rc Return status code
  185. */
  186. static int efi_bofm_start ( struct efi_device *efidev ) {
  187. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  188. EFI_HANDLE device = efidev->device;
  189. union {
  190. IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL *bofm1;
  191. void *interface;
  192. } bofm1;
  193. union {
  194. IBM_BOFM_DRIVER_CONFIGURATION_PROTOCOL2 *bofm2;
  195. void *interface;
  196. } bofm2;
  197. struct pci_device pci;
  198. IBM_BOFM_TABLE *bofmtab;
  199. IBM_BOFM_TABLE *bofmtab2;
  200. int bofmrc;
  201. EFI_STATUS efirc;
  202. int rc;
  203. /* Open PCI device, if possible */
  204. if ( ( rc = efipci_open ( device, EFI_OPEN_PROTOCOL_GET_PROTOCOL,
  205. &pci ) ) != 0 )
  206. goto err_open;
  207. /* Locate BOFM protocol */
  208. if ( ( efirc = bs->LocateProtocol ( &bofm1_protocol_guid, NULL,
  209. &bofm1.interface ) ) != 0 ) {
  210. rc = -EEFI ( efirc );
  211. DBGC ( device, "EFIBOFM %p %s cannot find BOFM protocol\n",
  212. device, efi_devpath_text ( efidev->path ) );
  213. goto err_locate_bofm;
  214. }
  215. bofmtab = &bofm1.bofm1->BofmTable;
  216. DBGC ( device, "EFIBOFM %p %s found version 1 BOFM table at %p+%04x\n",
  217. device, efi_devpath_text ( efidev->path ), bofmtab,
  218. bofmtab->Parameters.Length );
  219. /* Locate BOFM2 protocol, if available */
  220. if ( ( efirc = bs->LocateProtocol ( &bofm2_protocol_guid, NULL,
  221. &bofm2.interface ) ) == 0 ) {
  222. bofmtab2 = &bofm2.bofm2->BofmTable;
  223. DBGC ( device, "EFIBOFM %p %s found version 2 BOFM table at "
  224. "%p+%04x\n", device, efi_devpath_text ( efidev->path ),
  225. bofmtab2, bofmtab2->Parameters.Length );
  226. assert ( bofm2.bofm2->RegisterSupport ==
  227. bofm1.bofm1->RegisterSupport );
  228. } else {
  229. DBGC ( device, "EFIBOFM %p %s cannot find BOFM2 protocol\n",
  230. device, efi_devpath_text ( efidev->path ) );
  231. /* Not a fatal error; may be a BOFM1-only system */
  232. bofmtab2 = NULL;
  233. }
  234. /* Process BOFM table */
  235. DBGC2 ( device, "EFIBOFM %p %s version 1 before processing:\n",
  236. device, efi_devpath_text ( efidev->path ) );
  237. DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
  238. if ( bofmtab2 ) {
  239. DBGC2 ( device, "EFIBOFM %p %s version 2 before processing:\n",
  240. device, efi_devpath_text ( efidev->path ) );
  241. DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
  242. }
  243. bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ), &pci );
  244. DBGC ( device, "EFIBOFM %p %s status %08x\n",
  245. device, efi_devpath_text ( efidev->path ), bofmrc );
  246. DBGC2 ( device, "EFIBOFM %p %s version 1 after processing:\n",
  247. device, efi_devpath_text ( efidev->path ) );
  248. DBGC2_HD ( device, bofmtab, bofmtab->Parameters.Length );
  249. if ( bofmtab2 ) {
  250. DBGC2 ( device, "EFIBOFM %p %s version 2 after processing:\n",
  251. device, efi_devpath_text ( efidev->path ) );
  252. DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length );
  253. }
  254. /* Return BOFM status */
  255. if ( bofmtab2 ) {
  256. if ( ( efirc = bofm2.bofm2->SetStatus ( bofm2.bofm2, device,
  257. FALSE, bofmrc ) ) != 0){
  258. rc = -EEFI ( efirc );
  259. DBGC ( device, "EFIBOFM %p %s could not set BOFM2 "
  260. "status: %s\n",
  261. device, efi_devpath_text ( efidev->path ),
  262. strerror ( rc ) );
  263. goto err_set_status;
  264. }
  265. } else {
  266. if ( ( efirc = bofm1.bofm1->SetStatus ( bofm1.bofm1, device,
  267. FALSE, bofmrc ) ) != 0){
  268. rc = -EEFI ( efirc );
  269. DBGC ( device, "EFIBOFM %p %s could not set BOFM "
  270. "status: %s\n",
  271. device, efi_devpath_text ( efidev->path ),
  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. };