From aedcb46e6fd260ab39cf0fc63a85c7f8da8aa476 Mon Sep 17 00:00:00 2001 From: Kun Qin Date: Fri, 4 Apr 2025 16:43:53 -0700 Subject: [PATCH] OvmfPkg: QemuFlashFvbServicesRuntimeDxe: Abstract out SMM/DXE functions This update refactors QemuFlashFvbServicesRuntimeDxe to abstract out direct calls to SMM and DXE specific functions. Specifically, dynamic PCD usage and gBS references have been moved to SMM specific files. The constructor functionality has been relocated to a common implementation and is invoked from their respective entry points. These changes lay the groundwork for supporting a Standalone MM-based solution in the future. Signed-off-by: Kun Qin --- .../QemuFlashFvbServicesRuntimeDxe/FwBlockService.c | 8 +++----- .../QemuFlashFvbServicesRuntimeDxe/FwBlockService.h | 5 +++++ .../FwBlockServiceDxe.c | 11 +++++++++++ .../FwBlockServiceSmm.c | 11 +++++++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c index b34298faf8..83051a568f 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c @@ -27,9 +27,7 @@ #include #include #include -#include #include -#include #include "FwBlockService.h" #include "QemuFlash.h" @@ -976,7 +974,6 @@ FvbInitialize ( EFI_PHYSICAL_ADDRESS BaseAddress; UINTN Length; UINTN NumOfBlocks; - RETURN_STATUS PcdStatus; if (EFI_ERROR (QemuFlashInitialize ())) { // @@ -1129,7 +1126,8 @@ FvbInitialize ( // InstallVirtualAddressChangeHandler (); - PcdStatus = PcdSetBoolS (PcdOvmfFlashVariablesEnable, TRUE); - ASSERT_RETURN_ERROR (PcdStatus); + // Abstract dynamic PCD set to support Standalone MM + UpdateQemuFlashVariablesEnable (); + return EFI_SUCCESS; } diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.h b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.h index 639ad0471c..dda3bc5feb 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.h +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.h @@ -194,4 +194,9 @@ SetPcdFlashNvStorageBaseAddresses ( VOID ); +VOID +UpdateQemuFlashVariablesEnable ( + VOID + ); + #endif diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c index 61e1f2e196..27812fc02e 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c @@ -244,3 +244,14 @@ SetPcdFlashNvStorageBaseAddresses ( ); ASSERT_RETURN_ERROR (PcdStatus); } + +VOID +UpdateQemuFlashVariablesEnable ( + VOID + ) +{ + RETURN_STATUS PcdStatus; + + PcdStatus = PcdSetBoolS (PcdOvmfFlashVariablesEnable, TRUE); + ASSERT_RETURN_ERROR (PcdStatus); +} diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceSmm.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceSmm.c index 19bd5aab7c..6acd4b7afe 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceSmm.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceSmm.c @@ -84,3 +84,14 @@ SetPcdFlashNvStorageBaseAddresses ( // Do nothing. // } + +VOID +UpdateQemuFlashVariablesEnable ( + VOID + ) +{ + RETURN_STATUS PcdStatus; + + PcdStatus = PcdSetBoolS (PcdOvmfFlashVariablesEnable, TRUE); + ASSERT_RETURN_ERROR (PcdStatus); +}