RedfishConfigHandlerCommon.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /** @file
  2. The common code of EDKII Redfish Configuration Handler driver.
  3. (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "RedfishConfigHandlerCommon.h"
  7. REDFISH_CONFIG_DRIVER_DATA gRedfishConfigData; // Only one Redfish service supproted
  8. // on platform for the BIOS
  9. // Redfish configuration.
  10. EFI_EVENT gEndOfDxeEvent = NULL;
  11. EFI_EVENT gExitBootServiceEvent = NULL;
  12. EDKII_REDFISH_CREDENTIAL_PROTOCOL *gCredential = NULL;
  13. /**
  14. Callback function executed when the EndOfDxe event group is signaled.
  15. @param[in] Event Event whose notification function is being invoked.
  16. @param[out] Context Pointer to the Context buffer.
  17. **/
  18. VOID
  19. EFIAPI
  20. RedfishConfigOnEndOfDxe (
  21. IN EFI_EVENT Event,
  22. OUT VOID *Context
  23. )
  24. {
  25. EFI_STATUS Status;
  26. Status = gCredential->StopService (gCredential, ServiceStopTypeSecureBootDisabled);
  27. if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {
  28. DEBUG ((DEBUG_ERROR, "Redfish credential protocol faied to stop service on EndOfDxe: %r", Status));
  29. }
  30. //
  31. // Close event, so it will not be invoked again.
  32. //
  33. gBS->CloseEvent (gEndOfDxeEvent);
  34. gEndOfDxeEvent = NULL;
  35. }
  36. /**
  37. Callback function executed when the ExitBootService event group is signaled.
  38. @param[in] Event Event whose notification function is being invoked.
  39. @param[out] Context Pointer to the Context buffer
  40. **/
  41. VOID
  42. EFIAPI
  43. RedfishConfigOnExitBootService (
  44. IN EFI_EVENT Event,
  45. OUT VOID *Context
  46. )
  47. {
  48. EFI_STATUS Status;
  49. Status = gCredential->StopService (gCredential, ServiceStopTypeExitBootService);
  50. if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {
  51. DEBUG ((DEBUG_ERROR, "Redfish credential protocol faied to stop service on ExitBootService: %r", Status));
  52. }
  53. }
  54. /**
  55. Unloads an image.
  56. @param[in] ImageHandle Handle that identifies the image to be unloaded.
  57. @retval EFI_SUCCESS The image has been unloaded.
  58. **/
  59. EFI_STATUS
  60. RedfishConfigDriverCommonUnload (
  61. IN EFI_HANDLE ImageHandle
  62. )
  63. {
  64. if (gEndOfDxeEvent != NULL) {
  65. gBS->CloseEvent (gEndOfDxeEvent);
  66. gEndOfDxeEvent = NULL;
  67. }
  68. if (gExitBootServiceEvent != NULL) {
  69. gBS->CloseEvent (gExitBootServiceEvent);
  70. gExitBootServiceEvent = NULL;
  71. }
  72. if (gRedfishConfigData.Event != NULL) {
  73. gBS->CloseEvent (gRedfishConfigData.Event);
  74. gRedfishConfigData.Event = NULL;
  75. }
  76. return EFI_SUCCESS;
  77. }
  78. /**
  79. This is the common code for Redfish configuration UEFI and DXE driver
  80. initialization.
  81. @param[in] ImageHandle The firmware allocated handle for the UEFI image.
  82. @param[in] SystemTable A pointer to the EFI System Table.
  83. @retval EFI_SUCCESS The operation completed successfully.
  84. @retval Others An unexpected error occurred.
  85. **/
  86. EFI_STATUS
  87. RedfishConfigCommonInit (
  88. IN EFI_HANDLE ImageHandle,
  89. IN EFI_SYSTEM_TABLE *SystemTable
  90. )
  91. {
  92. EFI_STATUS Status;
  93. //
  94. // Locate Redfish Credential Protocol to get credential for
  95. // accessing to Redfish service.
  96. //
  97. Status = gBS->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid, NULL, (VOID **)&gCredential);
  98. if (EFI_ERROR (Status)) {
  99. DEBUG ((DEBUG_INFO, "%a: No Redfish Credential Protocol is installed on system.", __FUNCTION__));
  100. return Status;
  101. }
  102. //
  103. // Create EndOfDxe Event.
  104. //
  105. Status = gBS->CreateEventEx (
  106. EVT_NOTIFY_SIGNAL,
  107. TPL_CALLBACK,
  108. RedfishConfigOnEndOfDxe,
  109. NULL,
  110. &gEfiEndOfDxeEventGroupGuid,
  111. &gEndOfDxeEvent
  112. );
  113. if (EFI_ERROR (Status)) {
  114. DEBUG ((DEBUG_ERROR, "%a: Fail to register End Of DXE event.", __FUNCTION__));
  115. return Status;
  116. }
  117. //
  118. // Create Exit Boot Service event.
  119. //
  120. Status = gBS->CreateEventEx (
  121. EVT_NOTIFY_SIGNAL,
  122. TPL_CALLBACK,
  123. RedfishConfigOnExitBootService,
  124. NULL,
  125. &gEfiEventExitBootServicesGuid,
  126. &gExitBootServiceEvent
  127. );
  128. if (EFI_ERROR (Status)) {
  129. gBS->CloseEvent (gEndOfDxeEvent);
  130. gEndOfDxeEvent = NULL;
  131. DEBUG ((DEBUG_ERROR, "%a: Fail to register Exit Boot Service event.", __FUNCTION__));
  132. return Status;
  133. }
  134. return EFI_SUCCESS;
  135. }
  136. /**
  137. This is the common code to stop EDK2 Redfish feature driver.
  138. @retval EFI_SUCCESS All EDK2 Redfish feature drivers are
  139. stopped.
  140. @retval Others An unexpected error occurred.
  141. **/
  142. EFI_STATUS
  143. RedfishConfigCommonStop (
  144. VOID
  145. )
  146. {
  147. EFI_STATUS Status;
  148. EFI_HANDLE *HandleBuffer;
  149. UINTN NumberOfHandles;
  150. UINTN Index;
  151. EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
  152. Status = gBS->LocateHandleBuffer (
  153. ByProtocol,
  154. &gEdkIIRedfishConfigHandlerProtocolGuid,
  155. NULL,
  156. &NumberOfHandles,
  157. &HandleBuffer
  158. );
  159. if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
  160. return Status;
  161. }
  162. Status = EFI_SUCCESS;
  163. for (Index = 0; Index < NumberOfHandles; Index++) {
  164. Status = gBS->HandleProtocol (
  165. HandleBuffer[Index],
  166. &gEdkIIRedfishConfigHandlerProtocolGuid,
  167. (VOID **)&ConfigHandler
  168. );
  169. ASSERT_EFI_ERROR (Status);
  170. Status = ConfigHandler->Stop (ConfigHandler);
  171. if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {
  172. DEBUG ((DEBUG_ERROR, "ERROR: Failed to stop Redfish config handler %p.\n", ConfigHandler));
  173. break;
  174. }
  175. }
  176. return Status;
  177. }
  178. /**
  179. Callback function executed when a Redfish Config Handler Protocol is installed
  180. by EDK2 Redfish Feature Drivers.
  181. **/
  182. VOID
  183. RedfishConfigHandlerInitialization (
  184. VOID
  185. )
  186. {
  187. EFI_STATUS Status;
  188. EFI_HANDLE *HandleBuffer;
  189. UINTN NumberOfHandles;
  190. EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
  191. UINTN Index;
  192. UINT32 Id;
  193. Status = gBS->LocateHandleBuffer (
  194. ByProtocol,
  195. &gEdkIIRedfishConfigHandlerProtocolGuid,
  196. NULL,
  197. &NumberOfHandles,
  198. &HandleBuffer
  199. );
  200. if (EFI_ERROR (Status)) {
  201. return;
  202. }
  203. for (Index = 0; Index < NumberOfHandles; Index++) {
  204. Status = gBS->HandleProtocol (
  205. HandleBuffer[Index],
  206. &gEfiCallerIdGuid,
  207. (VOID **)&Id
  208. );
  209. if (!EFI_ERROR (Status)) {
  210. continue;
  211. }
  212. Status = gBS->HandleProtocol (
  213. HandleBuffer[Index],
  214. &gEdkIIRedfishConfigHandlerProtocolGuid,
  215. (VOID **)&ConfigHandler
  216. );
  217. ASSERT_EFI_ERROR (Status);
  218. Status = ConfigHandler->Init (ConfigHandler, &gRedfishConfigData.RedfishServiceInfo);
  219. if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
  220. DEBUG ((DEBUG_ERROR, "ERROR: Failed to init Redfish config handler %p.\n", ConfigHandler));
  221. }
  222. //
  223. // Install caller ID to indicate Redfish Configure Handler is initialized.
  224. //
  225. Status = gBS->InstallProtocolInterface (
  226. &HandleBuffer[Index],
  227. &gEfiCallerIdGuid,
  228. EFI_NATIVE_INTERFACE,
  229. (VOID *)&gRedfishConfigData.CallerId
  230. );
  231. ASSERT_EFI_ERROR (Status);
  232. }
  233. }