2 The common code of EDKII Redfish Configuration Handler driver.
4 (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "RedfishConfigHandlerCommon.h"
12 REDFISH_CONFIG_DRIVER_DATA gRedfishConfigData
; // Only one Redfish service supproted
13 // on platform for the BIOS
14 // Redfish configuration.
15 EFI_EVENT gEndOfDxeEvent
= NULL
;
16 EFI_EVENT gExitBootServiceEvent
= NULL
;
17 EDKII_REDFISH_CREDENTIAL_PROTOCOL
*gCredential
= NULL
;
20 Callback function executed when the EndOfDxe event group is signaled.
22 @param[in] Event Event whose notification function is being invoked.
23 @param[out] Context Pointer to the Context buffer.
28 RedfishConfigOnEndOfDxe (
35 Status
= gCredential
->StopService (gCredential
, ServiceStopTypeSecureBootDisabled
);
36 if (EFI_ERROR (Status
) && (Status
!= EFI_UNSUPPORTED
)) {
37 DEBUG ((DEBUG_ERROR
, "Redfish credential protocol faied to stop service on EndOfDxe: %r", Status
));
41 // Close event, so it will not be invoked again.
43 gBS
->CloseEvent (gEndOfDxeEvent
);
44 gEndOfDxeEvent
= NULL
;
48 Callback function executed when the ExitBootService event group is signaled.
50 @param[in] Event Event whose notification function is being invoked.
51 @param[out] Context Pointer to the Context buffer
56 RedfishConfigOnExitBootService (
63 Status
= gCredential
->StopService (gCredential
, ServiceStopTypeExitBootService
);
64 if (EFI_ERROR (Status
) && (Status
!= EFI_UNSUPPORTED
)) {
65 DEBUG ((DEBUG_ERROR
, "Redfish credential protocol faied to stop service on ExitBootService: %r", Status
));
72 @param[in] ImageHandle Handle that identifies the image to be unloaded.
74 @retval EFI_SUCCESS The image has been unloaded.
78 RedfishConfigDriverCommonUnload (
79 IN EFI_HANDLE ImageHandle
82 if (gEndOfDxeEvent
!= NULL
) {
83 gBS
->CloseEvent (gEndOfDxeEvent
);
84 gEndOfDxeEvent
= NULL
;
87 if (gExitBootServiceEvent
!= NULL
) {
88 gBS
->CloseEvent (gExitBootServiceEvent
);
89 gExitBootServiceEvent
= NULL
;
92 if (gRedfishConfigData
.Event
!= NULL
) {
93 gBS
->CloseEvent (gRedfishConfigData
.Event
);
94 gRedfishConfigData
.Event
= NULL
;
101 This is the common code for Redfish configuration UEFI and DXE driver
104 @param[in] ImageHandle The firmware allocated handle for the UEFI image.
105 @param[in] SystemTable A pointer to the EFI System Table.
107 @retval EFI_SUCCESS The operation completed successfully.
108 @retval Others An unexpected error occurred.
111 RedfishConfigCommonInit (
112 IN EFI_HANDLE ImageHandle
,
113 IN EFI_SYSTEM_TABLE
*SystemTable
119 // Locate Redfish Credential Protocol to get credential for
120 // accessing to Redfish service.
122 Status
= gBS
->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid
, NULL
, (VOID
**)&gCredential
);
123 if (EFI_ERROR (Status
)) {
124 DEBUG ((DEBUG_INFO
, "%a: No Redfish Credential Protocol is installed on system.", __FUNCTION__
));
129 // Create EndOfDxe Event.
131 Status
= gBS
->CreateEventEx (
134 RedfishConfigOnEndOfDxe
,
136 &gEfiEndOfDxeEventGroupGuid
,
139 if (EFI_ERROR (Status
)) {
140 DEBUG ((DEBUG_ERROR
, "%a: Fail to register End Of DXE event.", __FUNCTION__
));
145 // Create Exit Boot Service event.
147 Status
= gBS
->CreateEventEx (
150 RedfishConfigOnExitBootService
,
152 &gEfiEventExitBootServicesGuid
,
153 &gExitBootServiceEvent
155 if (EFI_ERROR (Status
)) {
156 gBS
->CloseEvent (gEndOfDxeEvent
);
157 gEndOfDxeEvent
= NULL
;
158 DEBUG ((DEBUG_ERROR
, "%a: Fail to register Exit Boot Service event.", __FUNCTION__
));
166 This is the common code to stop EDK2 Redfish feature driver.
168 @retval EFI_SUCCESS All EDK2 Redfish feature drivers are
170 @retval Others An unexpected error occurred.
173 RedfishConfigCommonStop (
178 EFI_HANDLE
*HandleBuffer
;
179 UINTN NumberOfHandles
;
181 EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL
*ConfigHandler
;
183 Status
= gBS
->LocateHandleBuffer (
185 &gEdkIIRedfishConfigHandlerProtocolGuid
,
190 if (EFI_ERROR (Status
) && (Status
!= EFI_NOT_FOUND
)) {
194 Status
= EFI_SUCCESS
;
195 for (Index
= 0; Index
< NumberOfHandles
; Index
++) {
196 Status
= gBS
->HandleProtocol (
198 &gEdkIIRedfishConfigHandlerProtocolGuid
,
199 (VOID
**)&ConfigHandler
201 ASSERT_EFI_ERROR (Status
);
203 Status
= ConfigHandler
->Stop (ConfigHandler
);
204 if (EFI_ERROR (Status
) && (Status
!= EFI_UNSUPPORTED
)) {
205 DEBUG ((DEBUG_ERROR
, "ERROR: Failed to stop Redfish config handler %p.\n", ConfigHandler
));
214 Callback function executed when a Redfish Config Handler Protocol is installed
215 by EDK2 Redfish Feature Drivers.
219 RedfishConfigHandlerInitialization (
224 EFI_HANDLE
*HandleBuffer
;
225 UINTN NumberOfHandles
;
226 EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL
*ConfigHandler
;
230 Status
= gBS
->LocateHandleBuffer (
232 &gEdkIIRedfishConfigHandlerProtocolGuid
,
237 if (EFI_ERROR (Status
)) {
241 for (Index
= 0; Index
< NumberOfHandles
; Index
++) {
242 Status
= gBS
->HandleProtocol (
247 if (!EFI_ERROR (Status
)) {
251 Status
= gBS
->HandleProtocol (
253 &gEdkIIRedfishConfigHandlerProtocolGuid
,
254 (VOID
**)&ConfigHandler
256 ASSERT_EFI_ERROR (Status
);
257 Status
= ConfigHandler
->Init (ConfigHandler
, &gRedfishConfigData
.RedfishServiceInfo
);
258 if (EFI_ERROR (Status
) && (Status
!= EFI_ALREADY_STARTED
)) {
259 DEBUG ((DEBUG_ERROR
, "ERROR: Failed to init Redfish config handler %p.\n", ConfigHandler
));
263 // Install caller ID to indicate Redfish Configure Handler is initialized.
265 Status
= gBS
->InstallProtocolInterface (
266 &HandleBuffer
[Index
],
268 EFI_NATIVE_INTERFACE
,
269 (VOID
*)&gRedfishConfigData
.CallerId
271 ASSERT_EFI_ERROR (Status
);