summaryrefslogtreecommitdiffstats
path: root/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c
diff options
context:
space:
mode:
authorAbner Chang <abner.chang@hpe.com>2021-03-26 12:59:54 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-04-12 07:40:31 +0000
commit2072c22a0d63c780b0cc6377f6d4ffb116ad6144 (patch)
treed2a60699fc91c0408aa6fa249f3075c4e46103f4 /RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c
parent7e7b729f6cf97c6e3df8ac36a2bf3d6189bde24c (diff)
downloadedk2-2072c22a0d63c780b0cc6377f6d4ffb116ad6144.tar.gz
edk2-2072c22a0d63c780b0cc6377f6d4ffb116ad6144.tar.bz2
edk2-2072c22a0d63c780b0cc6377f6d4ffb116ad6144.zip
RedfishPkg/RedfishConfigHandler: EDKII RedfishConfigHandler Protocol
BZ:2919 The driver is used to manage EDK2 Redfish Configuration Handler Protocol installed by EDK2 Redfish feature drivers. This is the EDK2 Redfish client driver written based on the EDK2 Redfish foundation to initialize EDK2 Redfish feature drivers. EDK2 Redfish feature drivers are used to provision/consume/update the firmware owns Redfish properties during system power on initialization. RedfishConfigHandlerCommon.c has the common code for the driver instances used in different EDK2 boot phases or used by different driver models in the future contribution. Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com> Signed-off-by: Siyuan Fu <siyuan.fu@intel.com> Signed-off-by: Fan Wang <fan.wang@intel.com> Signed-off-by: Abner Chang <abner.chang@hpe.com> Cc: Nickle Wang <nickle.wang@hpe.com> Reviewed-by: Nickle Wang <nickle.wang@hpe.com>
Diffstat (limited to 'RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c')
-rw-r--r--RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c265
1 files changed, 265 insertions, 0 deletions
diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c
new file mode 100644
index 0000000000..ff465d9ff3
--- /dev/null
+++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c
@@ -0,0 +1,265 @@
+/** @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"
+
+REDFISH_CONFIG_DRIVER_DATA gRedfishConfigData; // Only one Redfish service supproted
+ // on platform for the BIOS
+ // Redfish configuration.
+EFI_EVENT gEndOfDxeEvent = NULL;
+EFI_EVENT gExitBootServiceEvent = NULL;
+EDKII_REDFISH_CREDENTIAL_PROTOCOL *gCredential = NULL;
+
+/**
+ 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
+ )
+{
+ EFI_STATUS Status;
+
+ Status = gCredential->StopService (gCredential, ServiceStopTypeSecureBootDisabled);
+ if (EFI_ERROR(Status) && Status != EFI_UNSUPPORTED) {
+ 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
+ )
+{
+ EFI_STATUS Status;
+
+ Status = gCredential->StopService (gCredential, ServiceStopTypeExitBootService);
+ if (EFI_ERROR(Status) && Status != EFI_UNSUPPORTED) {
+ 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
+ )
+{
+ EFI_STATUS Status;
+ //
+ // Locate Redfish Credential Protocol to get credential for
+ // accessing to Redfish service.
+ //
+ Status = gBS->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid, NULL, (VOID **) &gCredential);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_INFO, "%a: No Redfish Credential Protocol is installed on system.", __FUNCTION__));
+ return Status;
+ }
+ //
+ // 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;
+ }
+ //
+ // 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;
+ }
+ return EFI_SUCCESS;
+}
+/**
+ 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
+)
+{
+ EFI_STATUS Status;
+ EFI_HANDLE *HandleBuffer;
+ UINTN NumberOfHandles;
+ UINTN Index;
+ EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
+
+ Status = gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gEdkIIRedfishConfigHandlerProtocolGuid,
+ NULL,
+ &NumberOfHandles,
+ &HandleBuffer
+ );
+ if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {
+ return Status;
+ }
+
+ Status = EFI_SUCCESS;
+ for (Index = 0; Index < NumberOfHandles; Index++) {
+ Status = gBS->HandleProtocol (
+ HandleBuffer[Index],
+ &gEdkIIRedfishConfigHandlerProtocolGuid,
+ (VOID**) &ConfigHandler
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ Status = ConfigHandler->Stop (ConfigHandler);
+ if (EFI_ERROR (Status) && Status != EFI_UNSUPPORTED) {
+ DEBUG ((DEBUG_ERROR, "ERROR: Failed to stop Redfish config handler %p.\n", ConfigHandler));
+ break;
+ }
+ }
+ return Status;
+}
+/**
+ Callback function executed when a Redfish Config Handler Protocol is installed
+ by EDK2 Redfish Feature Drivers.
+
+**/
+VOID
+RedfishConfigHandlerInitialization (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_HANDLE *HandleBuffer;
+ UINTN NumberOfHandles;
+ EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler;
+ UINTN Index;
+ UINT32 Id;
+
+ Status = gBS->LocateHandleBuffer (
+ ByProtocol,
+ &gEdkIIRedfishConfigHandlerProtocolGuid,
+ NULL,
+ &NumberOfHandles,
+ &HandleBuffer
+ );
+ if (EFI_ERROR (Status)) {
+ return;
+ }
+
+ for (Index = 0; Index < NumberOfHandles; Index++) {
+ Status = gBS->HandleProtocol (
+ HandleBuffer [Index],
+ &gEfiCallerIdGuid,
+ (VOID **) &Id
+ );
+ if (!EFI_ERROR (Status)) {
+ continue;
+ }
+
+ Status = gBS->HandleProtocol (
+ HandleBuffer [Index],
+ &gEdkIIRedfishConfigHandlerProtocolGuid,
+ (VOID**) &ConfigHandler
+ );
+ ASSERT_EFI_ERROR (Status);
+ Status = ConfigHandler->Init (ConfigHandler, &gRedfishConfigData.RedfishServiceInfo);
+ if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
+ DEBUG ((DEBUG_ERROR, "ERROR: Failed to init Redfish config handler %p.\n", ConfigHandler));
+ }
+ //
+ // Install caller ID to indicate Redfish Configure Handler is initialized.
+ //
+ Status = gBS->InstallProtocolInterface (
+ &HandleBuffer [Index],
+ &gEfiCallerIdGuid,
+ EFI_NATIVE_INTERFACE,
+ (VOID *)&gRedfishConfigData.CallerId
+ );
+ ASSERT_EFI_ERROR (Status);
+ }
+}