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
118 // Locate Redfish Credential Protocol to get credential for
119 // accessing to Redfish service.
121 Status
= gBS
->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid
, NULL
, (VOID
**) &gCredential
);
122 if (EFI_ERROR (Status
)) {
123 DEBUG ((DEBUG_INFO
, "%a: No Redfish Credential Protocol is installed on system.", __FUNCTION__
));
127 // Create EndOfDxe Event.
129 Status
= gBS
->CreateEventEx (
132 RedfishConfigOnEndOfDxe
,
134 &gEfiEndOfDxeEventGroupGuid
,
137 if (EFI_ERROR (Status
)) {
138 DEBUG ((DEBUG_ERROR
, "%a: Fail to register End Of DXE event.", __FUNCTION__
));
142 // Create Exit Boot Service event.
144 Status
= gBS
->CreateEventEx (
147 RedfishConfigOnExitBootService
,
149 &gEfiEventExitBootServicesGuid
,
150 &gExitBootServiceEvent
152 if (EFI_ERROR (Status
)) {
153 gBS
->CloseEvent (gEndOfDxeEvent
);
154 gEndOfDxeEvent
= NULL
;
155 DEBUG ((DEBUG_ERROR
, "%a: Fail to register Exit Boot Service event.", __FUNCTION__
));
161 This is the common code to stop EDK2 Redfish feature driver.
163 @retval EFI_SUCCESS All EDK2 Redfish feature drivers are
165 @retval Others An unexpected error occurred.
168 RedfishConfigCommonStop (
173 EFI_HANDLE
*HandleBuffer
;
174 UINTN NumberOfHandles
;
176 EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL
*ConfigHandler
;
178 Status
= gBS
->LocateHandleBuffer (
180 &gEdkIIRedfishConfigHandlerProtocolGuid
,
185 if (EFI_ERROR (Status
) && Status
!= EFI_NOT_FOUND
) {
189 Status
= EFI_SUCCESS
;
190 for (Index
= 0; Index
< NumberOfHandles
; Index
++) {
191 Status
= gBS
->HandleProtocol (
193 &gEdkIIRedfishConfigHandlerProtocolGuid
,
194 (VOID
**) &ConfigHandler
196 ASSERT_EFI_ERROR (Status
);
198 Status
= ConfigHandler
->Stop (ConfigHandler
);
199 if (EFI_ERROR (Status
) && Status
!= EFI_UNSUPPORTED
) {
200 DEBUG ((DEBUG_ERROR
, "ERROR: Failed to stop Redfish config handler %p.\n", ConfigHandler
));
207 Callback function executed when a Redfish Config Handler Protocol is installed
208 by EDK2 Redfish Feature Drivers.
212 RedfishConfigHandlerInitialization (
217 EFI_HANDLE
*HandleBuffer
;
218 UINTN NumberOfHandles
;
219 EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL
*ConfigHandler
;
223 Status
= gBS
->LocateHandleBuffer (
225 &gEdkIIRedfishConfigHandlerProtocolGuid
,
230 if (EFI_ERROR (Status
)) {
234 for (Index
= 0; Index
< NumberOfHandles
; Index
++) {
235 Status
= gBS
->HandleProtocol (
236 HandleBuffer
[Index
],
240 if (!EFI_ERROR (Status
)) {
244 Status
= gBS
->HandleProtocol (
245 HandleBuffer
[Index
],
246 &gEdkIIRedfishConfigHandlerProtocolGuid
,
247 (VOID
**) &ConfigHandler
249 ASSERT_EFI_ERROR (Status
);
250 Status
= ConfigHandler
->Init (ConfigHandler
, &gRedfishConfigData
.RedfishServiceInfo
);
251 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
252 DEBUG ((DEBUG_ERROR
, "ERROR: Failed to init Redfish config handler %p.\n", ConfigHandler
));
255 // Install caller ID to indicate Redfish Configure Handler is initialized.
257 Status
= gBS
->InstallProtocolInterface (
258 &HandleBuffer
[Index
],
260 EFI_NATIVE_INTERFACE
,
261 (VOID
*)&gRedfishConfigData
.CallerId
263 ASSERT_EFI_ERROR (Status
);