RedfishConfigHandlerDriver.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /** @file
  2. The UEFI driver model driver which is responsible for locating the
  3. Redfish service through Redfish host interface and executing EDKII
  4. Redfish feature drivers.
  5. Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
  6. (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
  7. SPDX-License-Identifier: BSD-2-Clause-Patent
  8. **/
  9. #include "RedfishConfigHandlerDriver.h"
  10. EFI_EVENT gEfiRedfishDiscoverProtocolEvent = NULL;
  11. //
  12. // Variables for using RFI Redfish Discover Protocol
  13. //
  14. VOID *gEfiRedfishDiscoverRegistration;
  15. EFI_HANDLE gEfiRedfishDiscoverControllerHandle = NULL;
  16. EFI_REDFISH_DISCOVER_PROTOCOL *gEfiRedfishDiscoverProtocol = NULL;
  17. BOOLEAN gRedfishDiscoverActivated = FALSE;
  18. BOOLEAN gRedfishServiceDiscovered = FALSE;
  19. //
  20. // Network interfaces discovered by EFI Redfish Discover Protocol.
  21. //
  22. UINTN gNumberOfNetworkInterfaces;
  23. EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *gNetworkInterfaceInstances = NULL;
  24. EFI_REDFISH_DISCOVERED_TOKEN *gRedfishDiscoveredToken = NULL;
  25. ///
  26. /// Driver Binding Protocol instance
  27. ///
  28. EFI_DRIVER_BINDING_PROTOCOL gRedfishConfigDriverBinding = {
  29. RedfishConfigDriverBindingSupported,
  30. RedfishConfigDriverBindingStart,
  31. RedfishConfigDriverBindingStop,
  32. REDFISH_CONFIG_VERSION,
  33. NULL,
  34. NULL
  35. };
  36. /**
  37. Stop acquiring Redfish service.
  38. **/
  39. VOID
  40. RedfishConfigStopRedfishDiscovery (
  41. VOID
  42. )
  43. {
  44. if (gRedfishDiscoverActivated) {
  45. //
  46. // No more EFI Discover Protocol.
  47. //
  48. if (gEfiRedfishDiscoverProtocolEvent != NULL) {
  49. gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent);
  50. }
  51. //
  52. // Stop Redfish service discovery.
  53. //
  54. gEfiRedfishDiscoverProtocol->AbortAcquireRedfishService (
  55. gEfiRedfishDiscoverProtocol,
  56. gNetworkInterfaceInstances
  57. );
  58. gEfiRedfishDiscoverControllerHandle = NULL;
  59. gEfiRedfishDiscoverProtocol = NULL;
  60. gRedfishDiscoverActivated = FALSE;
  61. gRedfishServiceDiscovered = FALSE;
  62. }
  63. }
  64. /**
  65. Callback function executed when a Redfish Config Handler Protocol is installed.
  66. @param[in] Event Event whose notification function is being invoked.
  67. @param[in] Context Pointer to the REDFISH_CONFIG_DRIVER_DATA buffer.
  68. **/
  69. VOID
  70. EFIAPI
  71. RedfishConfigHandlerInstalledCallback (
  72. IN EFI_EVENT Event,
  73. IN VOID *Context
  74. )
  75. {
  76. if (!gRedfishDiscoverActivated) {
  77. //
  78. // No Redfish service is discovered yet.
  79. //
  80. return;
  81. }
  82. RedfishConfigHandlerInitialization ();
  83. }
  84. /**
  85. Tests to see if this driver supports a given controller. If a child device is provided,
  86. it further tests to see if this driver supports creating a handle for the specified child device.
  87. This function checks to see if the driver specified by This supports the device specified by
  88. ControllerHandle. Drivers will typically use the device path attached to
  89. ControllerHandle and/or the services from the bus I/O abstraction attached to
  90. ControllerHandle to determine if the driver supports ControllerHandle. This function
  91. may be called many times during platform initialization. In order to reduce boot times, the tests
  92. performed by this function must be very small, and take as little time as possible to execute. This
  93. function must not change the state of any hardware devices, and this function must be aware that the
  94. device specified by ControllerHandle may already be managed by the same driver or a
  95. different driver. This function must match its calls to AllocatePages() with FreePages(),
  96. AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
  97. Because ControllerHandle may have been previously started by the same driver, if a protocol is
  98. already in the opened state, then it must not be closed with CloseProtocol(). This is required
  99. to guarantee the state of ControllerHandle is not modified by this function.
  100. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
  101. @param[in] ControllerHandle The handle of the controller to test. This handle
  102. must support a protocol interface that supplies
  103. an I/O abstraction to the driver.
  104. @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
  105. parameter is ignored by device drivers, and is optional for bus
  106. drivers. For bus drivers, if this parameter is not NULL, then
  107. the bus driver must determine if the bus controller specified
  108. by ControllerHandle and the child controller specified
  109. by RemainingDevicePath are both supported by this
  110. bus driver.
  111. @retval EFI_SUCCESS The device specified by ControllerHandle and
  112. RemainingDevicePath is supported by the driver specified by This.
  113. @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
  114. RemainingDevicePath is not supported by the driver specified by This.
  115. **/
  116. EFI_STATUS
  117. EFIAPI
  118. RedfishConfigDriverBindingSupported (
  119. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  120. IN EFI_HANDLE ControllerHandle,
  121. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
  122. )
  123. {
  124. EFI_REST_EX_PROTOCOL *RestEx;
  125. EFI_STATUS Status;
  126. EFI_HANDLE ChildHandle;
  127. ChildHandle = NULL;
  128. //
  129. // Check if REST EX is ready. This just makes sure
  130. // the network stack is brought up.
  131. //
  132. Status = NetLibCreateServiceChild (
  133. ControllerHandle,
  134. This->ImageHandle,
  135. &gEfiRestExServiceBindingProtocolGuid,
  136. &ChildHandle
  137. );
  138. if (EFI_ERROR (Status)) {
  139. return EFI_UNSUPPORTED;
  140. }
  141. //
  142. // Test if REST EX protocol is ready.
  143. //
  144. Status = gBS->OpenProtocol(
  145. ChildHandle,
  146. &gEfiRestExProtocolGuid,
  147. (VOID**) &RestEx,
  148. This->DriverBindingHandle,
  149. ControllerHandle,
  150. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  151. );
  152. if (EFI_ERROR (Status)) {
  153. Status = EFI_UNSUPPORTED;
  154. }
  155. NetLibDestroyServiceChild (
  156. ControllerHandle,
  157. This->ImageHandle,
  158. &gEfiRestExServiceBindingProtocolGuid,
  159. ChildHandle
  160. );
  161. return Status;
  162. }
  163. /**
  164. Starts a device controller or a bus controller.
  165. The Start() function is designed to be invoked from the EFI boot service ConnectController().
  166. As a result, much of the error checking on the parameters to Start() has been moved into this
  167. common boot service. It is legal to call Start() from other locations,
  168. but the following calling restrictions must be followed, or the system behavior will not be deterministic.
  169. 1. ControllerHandle must be a valid EFI_HANDLE.
  170. 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
  171. EFI_DEVICE_PATH_PROTOCOL.
  172. 3. Prior to calling Start(), the Supported() function for the driver specified by This must
  173. have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
  174. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
  175. @param[in] ControllerHandle The handle of the controller to start. This handle
  176. must support a protocol interface that supplies
  177. an I/O abstraction to the driver.
  178. @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
  179. parameter is ignored by device drivers, and is optional for bus
  180. drivers. For a bus driver, if this parameter is NULL, then handles
  181. for all the children of Controller are created by this driver.
  182. If this parameter is not NULL and the first Device Path Node is
  183. not the End of Device Path Node, then only the handle for the
  184. child device specified by the first Device Path Node of
  185. RemainingDevicePath is created by this driver.
  186. If the first Device Path Node of RemainingDevicePath is
  187. the End of Device Path Node, no child handle is created by this
  188. driver.
  189. @retval EFI_SUCCESS The driver is started.
  190. @retval EFI_ALREADY_STARTED The driver was already started.
  191. **/
  192. EFI_STATUS
  193. EFIAPI
  194. RedfishConfigDriverBindingStart (
  195. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  196. IN EFI_HANDLE ControllerHandle,
  197. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
  198. )
  199. {
  200. VOID *ConfigHandlerRegistration;
  201. if (gRedfishConfigData.Event != NULL) {
  202. return EFI_ALREADY_STARTED;
  203. }
  204. gRedfishConfigData.Event = EfiCreateProtocolNotifyEvent (
  205. &gEdkIIRedfishConfigHandlerProtocolGuid,
  206. TPL_CALLBACK,
  207. RedfishConfigHandlerInstalledCallback,
  208. (VOID *)&gRedfishConfigData,
  209. &ConfigHandlerRegistration
  210. );
  211. return EFI_SUCCESS;
  212. }
  213. /**
  214. Stops a device controller or a bus controller.
  215. The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
  216. As a result, much of the error checking on the parameters to Stop() has been moved
  217. into this common boot service. It is legal to call Stop() from other locations,
  218. but the following calling restrictions must be followed, or the system behavior will not be deterministic.
  219. 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
  220. same driver's Start() function.
  221. 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
  222. EFI_HANDLE. In addition, all of these handles must have been created in this driver's
  223. Start() function, and the Start() function must have called OpenProtocol() on
  224. ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
  225. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
  226. @param[in] ControllerHandle A handle to the device being stopped. The handle must
  227. support a bus specific I/O protocol for the driver
  228. to use to stop the device.
  229. @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
  230. @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
  231. if NumberOfChildren is 0.
  232. @retval EFI_SUCCESS The device was stopped.
  233. @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
  234. **/
  235. EFI_STATUS
  236. EFIAPI
  237. RedfishConfigDriverBindingStop (
  238. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  239. IN EFI_HANDLE ControllerHandle,
  240. IN UINTN NumberOfChildren,
  241. IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
  242. )
  243. {
  244. EFI_STATUS Status;
  245. if (ControllerHandle == gEfiRedfishDiscoverControllerHandle) {
  246. RedfishConfigStopRedfishDiscovery ();
  247. }
  248. gBS->CloseProtocol (
  249. ControllerHandle,
  250. &gEfiRedfishDiscoverProtocolGuid,
  251. gRedfishConfigData.Image,
  252. gRedfishConfigData.Image
  253. );
  254. Status = RedfishConfigCommonStop ();
  255. if (EFI_ERROR (Status)) {
  256. return EFI_DEVICE_ERROR;
  257. }
  258. if (gRedfishConfigData.Event != NULL) {
  259. gBS->CloseEvent (gRedfishConfigData.Event);
  260. gRedfishConfigData.Event = NULL;
  261. }
  262. return EFI_SUCCESS;
  263. }
  264. /**
  265. Callback function when Redfish service is discovered.
  266. @param[in] Event Event whose notification function is being invoked.
  267. @param[out] Context Pointer to the Context buffer
  268. **/
  269. VOID
  270. EFIAPI
  271. RedfishServiceDiscoveredCallback (
  272. IN EFI_EVENT Event,
  273. OUT VOID *Context
  274. )
  275. {
  276. EFI_REDFISH_DISCOVERED_TOKEN *RedfishDiscoveredToken;
  277. EFI_REDFISH_DISCOVERED_INSTANCE *RedfishInstance;
  278. if (gRedfishServiceDiscovered) {
  279. //
  280. // Only support one Redfish service on platform.
  281. //
  282. return;
  283. }
  284. RedfishDiscoveredToken = (EFI_REDFISH_DISCOVERED_TOKEN *)Context;
  285. RedfishInstance = RedfishDiscoveredToken->DiscoverList.RedfishInstances;
  286. //
  287. // Only pick up the first found Redfish service.
  288. //
  289. if (RedfishInstance->Status == EFI_SUCCESS) {
  290. gRedfishConfigData.RedfishServiceInfo.RedfishServiceRestExHandle = RedfishInstance->Information.RedfishRestExHandle;
  291. gRedfishConfigData.RedfishServiceInfo.RedfishServiceVersion = RedfishInstance->Information.RedfishVersion;
  292. gRedfishConfigData.RedfishServiceInfo.RedfishServiceLocation = RedfishInstance->Information.Location;
  293. gRedfishConfigData.RedfishServiceInfo.RedfishServiceUuid = RedfishInstance->Information.Uuid;
  294. gRedfishConfigData.RedfishServiceInfo.RedfishServiceOs = RedfishInstance->Information.Os;
  295. gRedfishConfigData.RedfishServiceInfo.RedfishServiceOsVersion = RedfishInstance->Information.OsVersion;
  296. gRedfishConfigData.RedfishServiceInfo.RedfishServiceProduct = RedfishInstance->Information.Product;
  297. gRedfishConfigData.RedfishServiceInfo.RedfishServiceProductVer = RedfishInstance->Information.ProductVer;
  298. gRedfishConfigData.RedfishServiceInfo.RedfishServiceUseHttps = RedfishInstance->Information.UseHttps;
  299. gRedfishServiceDiscovered = TRUE;
  300. }
  301. //
  302. // Invoke RedfishConfigHandlerInstalledCallback to execute
  303. // the initialization of Redfish Configure Handler instance.
  304. //
  305. RedfishConfigHandlerInstalledCallback (gRedfishConfigData.Event, &gRedfishConfigData);
  306. }
  307. /**
  308. Callback function executed when the EFI_REDFISH_DISCOVER_PROTOCOL
  309. protocol interface is installed.
  310. @param[in] Event Event whose notification function is being invoked.
  311. @param[out] Context Pointer to the Context buffer
  312. **/
  313. VOID
  314. EFIAPI
  315. RedfishDiscoverProtocolInstalled (
  316. IN EFI_EVENT Event,
  317. OUT VOID *Context
  318. )
  319. {
  320. EFI_STATUS Status;
  321. UINTN BufferSize;
  322. EFI_HANDLE HandleBuffer;
  323. UINTN NetworkInterfaceIndex;
  324. EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *ThisNetworkInterface;
  325. EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken;
  326. DEBUG((DEBUG_INFO, "%a: New network interface is installed on system by EFI Redfish discover driver.\n", __FUNCTION__));
  327. BufferSize = sizeof (EFI_HANDLE);
  328. Status = gBS->LocateHandle (
  329. ByRegisterNotify,
  330. NULL,
  331. gEfiRedfishDiscoverRegistration,
  332. &BufferSize,
  333. &HandleBuffer
  334. );
  335. if (EFI_ERROR (Status)) {
  336. DEBUG((DEBUG_ERROR, "%a: Can't locate handle with EFI_REDFISH_DISCOVER_PROTOCOL installed.\n", __FUNCTION__));
  337. }
  338. gRedfishDiscoverActivated = TRUE;
  339. if (gEfiRedfishDiscoverProtocol == NULL) {
  340. gEfiRedfishDiscoverControllerHandle = HandleBuffer;
  341. //
  342. // First time to open EFI_REDFISH_DISCOVER_PROTOCOL.
  343. //
  344. Status = gBS->OpenProtocol(
  345. gEfiRedfishDiscoverControllerHandle,
  346. &gEfiRedfishDiscoverProtocolGuid,
  347. (VOID **)&gEfiRedfishDiscoverProtocol,
  348. gRedfishConfigData.Image,
  349. gRedfishConfigData.Image,
  350. EFI_OPEN_PROTOCOL_BY_DRIVER
  351. );
  352. if (EFI_ERROR (Status)) {
  353. gEfiRedfishDiscoverProtocol = NULL;
  354. gRedfishDiscoverActivated = FALSE;
  355. DEBUG((DEBUG_ERROR, "%a: Can't locate EFI_REDFISH_DISCOVER_PROTOCOL.\n", __FUNCTION__));
  356. return;
  357. }
  358. }
  359. //
  360. // Check the new found network interface.
  361. //
  362. if (gNetworkInterfaceInstances != NULL) {
  363. FreePool (gNetworkInterfaceInstances);
  364. }
  365. Status = gEfiRedfishDiscoverProtocol->GetNetworkInterfaceList(
  366. gEfiRedfishDiscoverProtocol,
  367. gRedfishConfigData.Image,
  368. &gNumberOfNetworkInterfaces,
  369. &gNetworkInterfaceInstances
  370. );
  371. if (EFI_ERROR (Status) || gNumberOfNetworkInterfaces == 0) {
  372. DEBUG((DEBUG_ERROR, "%a: No network interfaces found on the handle.\n", __FUNCTION__));
  373. return;
  374. }
  375. gRedfishDiscoveredToken = AllocateZeroPool (gNumberOfNetworkInterfaces * sizeof (EFI_REDFISH_DISCOVERED_TOKEN));
  376. if (gRedfishDiscoveredToken == NULL) {
  377. DEBUG((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVERED_TOKEN.\n", __FUNCTION__));
  378. return;
  379. }
  380. ThisNetworkInterface = gNetworkInterfaceInstances;
  381. ThisRedfishDiscoveredToken = gRedfishDiscoveredToken;
  382. //
  383. // Loop to discover Redfish service on each network interface.
  384. //
  385. for (NetworkInterfaceIndex = 0; NetworkInterfaceIndex < gNumberOfNetworkInterfaces; NetworkInterfaceIndex ++) {
  386. //
  387. // Initial this Redfish Discovered Token
  388. //
  389. Status = gBS->CreateEvent (
  390. EVT_NOTIFY_SIGNAL,
  391. TPL_CALLBACK,
  392. RedfishServiceDiscoveredCallback,
  393. (VOID *)ThisRedfishDiscoveredToken,
  394. &ThisRedfishDiscoveredToken->Event
  395. );
  396. if (EFI_ERROR (Status)) {
  397. DEBUG((DEBUG_ERROR, "%a: Failed to create event for Redfish discovered token.\n", __FUNCTION__));
  398. goto ErrorReturn;
  399. }
  400. ThisRedfishDiscoveredToken->Signature = REDFISH_DISCOVER_TOKEN_SIGNATURE;
  401. ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound = 0;
  402. ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances = NULL;
  403. //
  404. // Acquire for Redfish service which is reported by
  405. // Redfish Host Interface.
  406. //
  407. Status = gEfiRedfishDiscoverProtocol->AcquireRedfishService(
  408. gEfiRedfishDiscoverProtocol,
  409. gRedfishConfigData.Image,
  410. ThisNetworkInterface,
  411. EFI_REDFISH_DISCOVER_HOST_INTERFACE,
  412. ThisRedfishDiscoveredToken
  413. );
  414. ThisNetworkInterface ++;
  415. ThisRedfishDiscoveredToken ++;
  416. }
  417. if (EFI_ERROR (Status)) {
  418. DEBUG((DEBUG_ERROR, "%a: Acquire Redfish service fail.\n", __FUNCTION__));
  419. goto ErrorReturn;
  420. }
  421. return;
  422. ErrorReturn:
  423. if (gRedfishDiscoveredToken != NULL) {
  424. FreePool(gRedfishDiscoveredToken);
  425. }
  426. }
  427. /**
  428. Unloads an image.
  429. @param[in] ImageHandle Handle that identifies the image to be unloaded.
  430. @retval EFI_SUCCESS The image has been unloaded.
  431. **/
  432. EFI_STATUS
  433. EFIAPI
  434. RedfishConfigHandlerDriverUnload (
  435. IN EFI_HANDLE ImageHandle
  436. )
  437. {
  438. EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken;
  439. UINTN NumberOfNetworkInterfacesIndex;
  440. RedfishConfigDriverCommonUnload (ImageHandle);
  441. RedfishConfigStopRedfishDiscovery ();
  442. if (gRedfishDiscoveredToken != NULL) {
  443. ThisRedfishDiscoveredToken = gRedfishDiscoveredToken;
  444. for (NumberOfNetworkInterfacesIndex = 0; NumberOfNetworkInterfacesIndex < gNumberOfNetworkInterfaces; NumberOfNetworkInterfacesIndex ++) {
  445. if (ThisRedfishDiscoveredToken->Event != NULL) {
  446. gBS->CloseEvent (ThisRedfishDiscoveredToken->Event);
  447. }
  448. FreePool (ThisRedfishDiscoveredToken);
  449. ThisRedfishDiscoveredToken ++;
  450. }
  451. gRedfishDiscoveredToken = NULL;
  452. }
  453. return EFI_SUCCESS;
  454. }
  455. /**
  456. This is the declaration of an EFI image entry point. This entry point is
  457. the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
  458. both device drivers and bus drivers.
  459. @param[in] ImageHandle The firmware allocated handle for the UEFI image.
  460. @param[in] SystemTable A pointer to the EFI System Table.
  461. @retval EFI_SUCCESS The operation completed successfully.
  462. @retval Others An unexpected error occurred.
  463. **/
  464. EFI_STATUS
  465. EFIAPI
  466. RedfishConfigHandlerDriverEntryPoint (
  467. IN EFI_HANDLE ImageHandle,
  468. IN EFI_SYSTEM_TABLE *SystemTable
  469. )
  470. {
  471. EFI_STATUS Status;
  472. ZeroMem ((VOID *)&gRedfishConfigData, sizeof (REDFISH_CONFIG_DRIVER_DATA));
  473. gRedfishConfigData.Image = ImageHandle;
  474. //
  475. // Register event for EFI_REDFISH_DISCOVER_PROTOCOL protocol install
  476. // notification.
  477. //
  478. Status = gBS->CreateEventEx (
  479. EVT_NOTIFY_SIGNAL,
  480. TPL_CALLBACK,
  481. RedfishDiscoverProtocolInstalled,
  482. NULL,
  483. &gEfiRedfishDiscoverProtocolGuid,
  484. &gEfiRedfishDiscoverProtocolEvent
  485. );
  486. if (EFI_ERROR (Status)) {
  487. DEBUG ((DEBUG_ERROR, "%a: Fail to create event for the installation of EFI_REDFISH_DISCOVER_PROTOCOL.", __FUNCTION__));
  488. return Status;
  489. }
  490. Status = gBS->RegisterProtocolNotify (
  491. &gEfiRedfishDiscoverProtocolGuid,
  492. gEfiRedfishDiscoverProtocolEvent,
  493. &gEfiRedfishDiscoverRegistration
  494. );
  495. if (EFI_ERROR (Status)) {
  496. DEBUG ((DEBUG_ERROR, "%a: Fail to register event for the installation of EFI_REDFISH_DISCOVER_PROTOCOL.", __FUNCTION__));
  497. return Status;
  498. }
  499. Status = RedfishConfigCommonInit (ImageHandle, SystemTable);
  500. if (EFI_ERROR (Status)) {
  501. gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent);
  502. gEfiRedfishDiscoverProtocolEvent = NULL;
  503. return Status;
  504. }
  505. //
  506. // Install UEFI Driver Model protocol(s).
  507. //
  508. Status = EfiLibInstallDriverBinding (
  509. ImageHandle,
  510. SystemTable,
  511. &gRedfishConfigDriverBinding,
  512. ImageHandle
  513. );
  514. if (EFI_ERROR (Status)) {
  515. gBS->CloseEvent (gEndOfDxeEvent);
  516. gEndOfDxeEvent = NULL;
  517. gBS->CloseEvent (gExitBootServiceEvent);
  518. gExitBootServiceEvent = NULL;
  519. gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent);
  520. gEfiRedfishDiscoverProtocolEvent = NULL;
  521. DEBUG ((DEBUG_ERROR, "%a: Fail to install EFI Binding Protocol of EFI Redfish Config driver.", __FUNCTION__));
  522. return Status;
  523. }
  524. return Status;
  525. }