2021-03-26 05:59:54 +01:00
|
|
|
/** @file
|
|
|
|
The common code of EDKII Redfish Configuration Handler driver.
|
|
|
|
|
|
|
|
(C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "RedfishConfigHandlerCommon.h"
|
|
|
|
|
2021-12-05 23:54:11 +01:00
|
|
|
REDFISH_CONFIG_DRIVER_DATA gRedfishConfigData; // Only one Redfish service supproted
|
2021-03-26 05:59:54 +01:00
|
|
|
// on platform for the BIOS
|
|
|
|
// Redfish configuration.
|
2021-12-05 23:54:11 +01:00
|
|
|
EFI_EVENT gEndOfDxeEvent = NULL;
|
|
|
|
EFI_EVENT gExitBootServiceEvent = NULL;
|
|
|
|
EDKII_REDFISH_CREDENTIAL_PROTOCOL *gCredential = NULL;
|
2021-03-26 05:59:54 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
Callback function executed when the EndOfDxe event group is signaled.
|
|
|
|
|
|
|
|
@param[in] Event Event whose notification function is being invoked.
|
|
|
|
@param[out] Context Pointer to the Context buffer.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
RedfishConfigOnEndOfDxe (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
OUT VOID *Context
|
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:11 +01:00
|
|
|
EFI_STATUS Status;
|
2021-03-26 05:59:54 +01:00
|
|
|
|
|
|
|
Status = gCredential->StopService (gCredential, ServiceStopTypeSecureBootDisabled);
|
2021-12-05 23:54:11 +01:00
|
|
|
if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {
|
2021-03-26 05:59:54 +01:00
|
|
|
DEBUG ((DEBUG_ERROR, "Redfish credential protocol faied to stop service on EndOfDxe: %r", Status));
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Close event, so it will not be invoked again.
|
|
|
|
//
|
|
|
|
gBS->CloseEvent (gEndOfDxeEvent);
|
|
|
|
gEndOfDxeEvent = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Callback function executed when the ExitBootService event group is signaled.
|
|
|
|
|
|
|
|
@param[in] Event Event whose notification function is being invoked.
|
|
|
|
@param[out] Context Pointer to the Context buffer
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
RedfishConfigOnExitBootService (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
OUT VOID *Context
|
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:11 +01:00
|
|
|
EFI_STATUS Status;
|
2021-03-26 05:59:54 +01:00
|
|
|
|
|
|
|
Status = gCredential->StopService (gCredential, ServiceStopTypeExitBootService);
|
2021-12-05 23:54:11 +01:00
|
|
|
if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {
|
2021-03-26 05:59:54 +01:00
|
|
|
DEBUG ((DEBUG_ERROR, "Redfish credential protocol faied to stop service on ExitBootService: %r", Status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Unloads an image.
|
|
|
|
|
|
|
|
@param[in] ImageHandle Handle that identifies the image to be unloaded.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The image has been unloaded.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
RedfishConfigDriverCommonUnload (
|
|
|
|
IN EFI_HANDLE ImageHandle
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (gEndOfDxeEvent != NULL) {
|
|
|
|
gBS->CloseEvent (gEndOfDxeEvent);
|
|
|
|
gEndOfDxeEvent = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gExitBootServiceEvent != NULL) {
|
|
|
|
gBS->CloseEvent (gExitBootServiceEvent);
|
|
|
|
gExitBootServiceEvent = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gRedfishConfigData.Event != NULL) {
|
|
|
|
gBS->CloseEvent (gRedfishConfigData.Event);
|
|
|
|
gRedfishConfigData.Event = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
This is the common code for Redfish configuration UEFI and DXE driver
|
|
|
|
initialization.
|
|
|
|
|
|
|
|
@param[in] ImageHandle The firmware allocated handle for the UEFI image.
|
|
|
|
@param[in] SystemTable A pointer to the EFI System Table.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The operation completed successfully.
|
|
|
|
@retval Others An unexpected error occurred.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
RedfishConfigCommonInit (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:11 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2021-03-26 05:59:54 +01:00
|
|
|
//
|
|
|
|
// Locate Redfish Credential Protocol to get credential for
|
|
|
|
// accessing to Redfish service.
|
|
|
|
//
|
2021-12-05 23:54:11 +01:00
|
|
|
Status = gBS->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid, NULL, (VOID **)&gCredential);
|
2021-03-26 05:59:54 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((DEBUG_INFO, "%a: No Redfish Credential Protocol is installed on system.", __FUNCTION__));
|
|
|
|
return Status;
|
|
|
|
}
|
2021-12-05 23:54:11 +01:00
|
|
|
|
2021-03-26 05:59:54 +01:00
|
|
|
//
|
|
|
|
// Create EndOfDxe Event.
|
|
|
|
//
|
|
|
|
Status = gBS->CreateEventEx (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_CALLBACK,
|
|
|
|
RedfishConfigOnEndOfDxe,
|
|
|
|
NULL,
|
|
|
|
&gEfiEndOfDxeEventGroupGuid,
|
|
|
|
&gEndOfDxeEvent
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((DEBUG_ERROR, "%a: Fail to register End Of DXE event.", __FUNCTION__));
|
|
|
|
return Status;
|
|
|
|
}
|
2021-12-05 23:54:11 +01:00
|
|
|
|
2021-03-26 05:59:54 +01:00
|
|
|
//
|
|
|
|
// Create Exit Boot Service event.
|
|
|
|
//
|
|
|
|
Status = gBS->CreateEventEx (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_CALLBACK,
|
|
|
|
RedfishConfigOnExitBootService,
|
|
|
|
NULL,
|
|
|
|
&gEfiEventExitBootServicesGuid,
|
|
|
|
&gExitBootServiceEvent
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
gBS->CloseEvent (gEndOfDxeEvent);
|
|
|
|
gEndOfDxeEvent = NULL;
|
|
|
|
DEBUG ((DEBUG_ERROR, "%a: Fail to register Exit Boot Service event.", __FUNCTION__));
|
|
|
|
return Status;
|
|
|
|
}
|
2021-12-05 23:54:11 +01:00
|
|
|
|
2021-03-26 05:59:54 +01:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2021-12-05 23:54:11 +01:00
|
|
|
|
2021-03-26 05:59:54 +01:00
|
|
|
/**
|
|
|
|
This is the common code to stop EDK2 Redfish feature driver.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS All EDK2 Redfish feature drivers are
|
|
|
|
stopped.
|
|
|
|
@retval Others An unexpected error occurred.
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
RedfishConfigCommonStop (
|
|
|
|
VOID
|
2021-12-05 23:54:11 +01:00
|
|
|
)
|
2021-03-26 05:59:54 +01:00
|
|
|
{
|
2021-12-05 23:54:11 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE *HandleBuffer;
|
|
|
|
UINTN NumberOfHandles;
|
|
|
|
UINTN Index;
|
|
|
|
EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
|
2021-03-26 05:59:54 +01:00
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
ByProtocol,
|
|
|
|
&gEdkIIRedfishConfigHandlerProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
&NumberOfHandles,
|
|
|
|
&HandleBuffer
|
|
|
|
);
|
2021-12-05 23:54:11 +01:00
|
|
|
if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
|
2021-03-26 05:59:54 +01:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
for (Index = 0; Index < NumberOfHandles; Index++) {
|
|
|
|
Status = gBS->HandleProtocol (
|
2021-12-05 23:54:11 +01:00
|
|
|
HandleBuffer[Index],
|
|
|
|
&gEdkIIRedfishConfigHandlerProtocolGuid,
|
|
|
|
(VOID **)&ConfigHandler
|
|
|
|
);
|
2021-03-26 05:59:54 +01:00
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
Status = ConfigHandler->Stop (ConfigHandler);
|
2021-12-05 23:54:11 +01:00
|
|
|
if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {
|
2021-03-26 05:59:54 +01:00
|
|
|
DEBUG ((DEBUG_ERROR, "ERROR: Failed to stop Redfish config handler %p.\n", ConfigHandler));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-12-05 23:54:11 +01:00
|
|
|
|
2021-03-26 05:59:54 +01:00
|
|
|
return Status;
|
|
|
|
}
|
2021-12-05 23:54:11 +01:00
|
|
|
|
2021-03-26 05:59:54 +01:00
|
|
|
/**
|
|
|
|
Callback function executed when a Redfish Config Handler Protocol is installed
|
|
|
|
by EDK2 Redfish Feature Drivers.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
RedfishConfigHandlerInitialization (
|
|
|
|
VOID
|
|
|
|
)
|
|
|
|
{
|
2021-12-05 23:54:11 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_HANDLE *HandleBuffer;
|
|
|
|
UINTN NumberOfHandles;
|
|
|
|
EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
|
|
|
|
UINTN Index;
|
|
|
|
UINT32 Id;
|
2021-03-26 05:59:54 +01:00
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
ByProtocol,
|
|
|
|
&gEdkIIRedfishConfigHandlerProtocolGuid,
|
|
|
|
NULL,
|
|
|
|
&NumberOfHandles,
|
|
|
|
&HandleBuffer
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Index = 0; Index < NumberOfHandles; Index++) {
|
|
|
|
Status = gBS->HandleProtocol (
|
2021-12-05 23:54:11 +01:00
|
|
|
HandleBuffer[Index],
|
2021-03-26 05:59:54 +01:00
|
|
|
&gEfiCallerIdGuid,
|
2021-12-05 23:54:11 +01:00
|
|
|
(VOID **)&Id
|
2021-03-26 05:59:54 +01:00
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = gBS->HandleProtocol (
|
2021-12-05 23:54:11 +01:00
|
|
|
HandleBuffer[Index],
|
|
|
|
&gEdkIIRedfishConfigHandlerProtocolGuid,
|
|
|
|
(VOID **)&ConfigHandler
|
|
|
|
);
|
2021-03-26 05:59:54 +01:00
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
Status = ConfigHandler->Init (ConfigHandler, &gRedfishConfigData.RedfishServiceInfo);
|
2021-12-05 23:54:11 +01:00
|
|
|
if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
|
2021-03-26 05:59:54 +01:00
|
|
|
DEBUG ((DEBUG_ERROR, "ERROR: Failed to init Redfish config handler %p.\n", ConfigHandler));
|
|
|
|
}
|
2021-12-05 23:54:11 +01:00
|
|
|
|
2021-03-26 05:59:54 +01:00
|
|
|
//
|
|
|
|
// Install caller ID to indicate Redfish Configure Handler is initialized.
|
|
|
|
//
|
|
|
|
Status = gBS->InstallProtocolInterface (
|
2021-12-05 23:54:11 +01:00
|
|
|
&HandleBuffer[Index],
|
|
|
|
&gEfiCallerIdGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
(VOID *)&gRedfishConfigData.CallerId
|
|
|
|
);
|
2021-03-26 05:59:54 +01:00
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
}
|
|
|
|
}
|