OvmfPkg: Refactor QEMU_FW_CFG_CACHE_WORK_AREA

Move QemuFwCfgSupported and QemuFwCfgDmaSupported to the struct
since they will be used as global variables in the DXE phase
along with QEMU_FW_CFG_CACHE_WORK_AREA.

Additionally, change its name to QEMU_FW_CFG_WORK_AREA.

Cc: Erdem Aktas <erdemaktas@google.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Min Xu <min.m.xu@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Elena Reshetova <elena.reshetova@intel.com>
Signed-off-by: Ceping Sun <cepingx.sun@intel.com>
This commit is contained in:
Ceping Sun 2025-02-08 00:46:02 -05:00 committed by mergify[bot]
parent fb56dc78ef
commit 4d2af7b91a
8 changed files with 109 additions and 112 deletions

View File

@ -18,57 +18,57 @@ The work area is used to support reading from cache in QemuFwCfgLib.
It is also used as global variable in Dxe phase.
*/
typedef struct {
BOOLEAN QemuFwCfgSupported;
BOOLEAN QemuFwCfgDmaSupported;
UINT16 FwCfgItem;
UINT32 Offset;
BOOLEAN Reading;
} QEMU_FW_CFG_CACHE_WORK_AREA;
} QEMU_FW_CFG_WORK_AREA;
typedef struct {
EFI_HOB_GUID_TYPE GuidHeader;
UINT16 HostBridgeDevId;
EFI_HOB_GUID_TYPE GuidHeader;
UINT16 HostBridgeDevId;
UINT64 PcdConfidentialComputingGuestAttr;
BOOLEAN SevEsIsEnabled;
UINT64 PcdConfidentialComputingGuestAttr;
BOOLEAN SevEsIsEnabled;
UINT32 BootMode;
BOOLEAN S3Supported;
UINT32 BootMode;
BOOLEAN S3Supported;
BOOLEAN SmmSmramRequire;
BOOLEAN Q35SmramAtDefaultSmbase;
UINT16 Q35TsegMbytes;
BOOLEAN SmmSmramRequire;
BOOLEAN Q35SmramAtDefaultSmbase;
UINT16 Q35TsegMbytes;
UINT32 LowMemory;
UINT64 FirstNonAddress;
UINT8 PhysMemAddressWidth;
UINT32 Uc32Base;
UINT32 Uc32Size;
UINT32 LowMemory;
UINT64 FirstNonAddress;
UINT8 PhysMemAddressWidth;
UINT32 Uc32Base;
UINT32 Uc32Size;
BOOLEAN PcdSetNxForStack;
UINT64 PcdTdxSharedBitMask;
BOOLEAN PcdSetNxForStack;
UINT64 PcdTdxSharedBitMask;
UINT64 PcdPciMmio64Base;
UINT64 PcdPciMmio64Size;
BOOLEAN PcdPciMmio64Override;
UINT32 PcdPciMmio32Base;
UINT32 PcdPciMmio32Size;
UINT64 PcdPciIoBase;
UINT64 PcdPciIoSize;
UINT64 PcdPciMmio64Base;
UINT64 PcdPciMmio64Size;
BOOLEAN PcdPciMmio64Override;
UINT32 PcdPciMmio32Base;
UINT32 PcdPciMmio32Size;
UINT64 PcdPciIoBase;
UINT64 PcdPciIoSize;
UINT64 PcdEmuVariableNvStoreReserved;
UINT32 PcdCpuBootLogicalProcessorNumber;
UINT32 PcdCpuMaxLogicalProcessorNumber;
UINT32 DefaultMaxCpuNumber;
UINT64 PcdEmuVariableNvStoreReserved;
UINT32 PcdCpuBootLogicalProcessorNumber;
UINT32 PcdCpuMaxLogicalProcessorNumber;
UINT32 DefaultMaxCpuNumber;
UINT32 S3AcpiReservedMemoryBase;
UINT32 S3AcpiReservedMemorySize;
UINT32 S3AcpiReservedMemoryBase;
UINT32 S3AcpiReservedMemorySize;
UINT64 FeatureControlValue;
UINT64 FeatureControlValue;
BOOLEAN QemuFwCfgChecked;
BOOLEAN QemuFwCfgSupported;
BOOLEAN QemuFwCfgDmaSupported;
BOOLEAN QemuFwCfgChecked;
QEMU_FW_CFG_CACHE_WORK_AREA QemuFwCfgCacheWorkArea;
QEMU_FW_CFG_WORK_AREA QemuFwCfgWorkArea;
} EFI_HOB_PLATFORM_INFO;
#pragma pack()

View File

@ -57,20 +57,20 @@ InternalQemuFwCfgItemCached (
}
/**
Clear the QEMU_FW_CFG_CACHE_WORK_AREA.
Clear the QEMU_FW_CFG_WORK_AREA.
**/
VOID
InternalQemuFwCfgCacheResetWorkArea (
VOID
)
{
QEMU_FW_CFG_CACHE_WORK_AREA *QemuFwCfgCacheWorkArea;
QEMU_FW_CFG_WORK_AREA *QemuFwCfgWorkArea;
QemuFwCfgCacheWorkArea = InternalQemuFwCfgCacheGetWorkArea ();
if (QemuFwCfgCacheWorkArea != NULL) {
QemuFwCfgCacheWorkArea->FwCfgItem = 0;
QemuFwCfgCacheWorkArea->Offset = 0;
QemuFwCfgCacheWorkArea->Reading = FALSE;
QemuFwCfgWorkArea = InternalQemuFwCfgCacheGetWorkArea ();
if (QemuFwCfgWorkArea != NULL) {
QemuFwCfgWorkArea->FwCfgItem = 0;
QemuFwCfgWorkArea->Offset = 0;
QemuFwCfgWorkArea->Reading = FALSE;
}
}
@ -84,13 +84,13 @@ InternalQemuFwCfgCacheReading (
VOID
)
{
BOOLEAN Reading;
QEMU_FW_CFG_CACHE_WORK_AREA *QemuFwCfgCacheWorkArea;
BOOLEAN Reading;
QEMU_FW_CFG_WORK_AREA *QemuFwCfgWorkArea;
Reading = FALSE;
QemuFwCfgCacheWorkArea = InternalQemuFwCfgCacheGetWorkArea ();
if (QemuFwCfgCacheWorkArea != NULL) {
Reading = QemuFwCfgCacheWorkArea->Reading;
Reading = FALSE;
QemuFwCfgWorkArea = InternalQemuFwCfgCacheGetWorkArea ();
if (QemuFwCfgWorkArea != NULL) {
Reading = QemuFwCfgWorkArea->Reading;
}
return Reading;
@ -101,22 +101,22 @@ InternalQemuFwCfgCacheSelectItem (
IN FIRMWARE_CONFIG_ITEM Item
)
{
QEMU_FW_CFG_CACHE_WORK_AREA *QemuFwCfgCacheWorkArea;
QEMU_FW_CFG_WORK_AREA *QemuFwCfgWorkArea;
// Walk thru cached fw_items to see if Item is cached.
if (InternalQemuFwCfgItemCached (Item) == NULL) {
return FALSE;
}
QemuFwCfgCacheWorkArea = InternalQemuFwCfgCacheGetWorkArea ();
if (QemuFwCfgCacheWorkArea == NULL) {
QemuFwCfgWorkArea = InternalQemuFwCfgCacheGetWorkArea ();
if (QemuFwCfgWorkArea == NULL) {
DEBUG ((DEBUG_ERROR, "%a: Invalid FwCfg Cache Work Area\n", __func__));
return FALSE;
}
QemuFwCfgCacheWorkArea->FwCfgItem = (UINT16)Item;
QemuFwCfgCacheWorkArea->Offset = 0;
QemuFwCfgCacheWorkArea->Reading = TRUE;
QemuFwCfgWorkArea->FwCfgItem = (UINT16)Item;
QemuFwCfgWorkArea->Offset = 0;
QemuFwCfgWorkArea->Reading = TRUE;
return TRUE;
}
@ -134,43 +134,43 @@ InternalQemuFwCfgCacheReadBytes (
IN OUT VOID *Buffer
)
{
QEMU_FW_CFG_CACHE_WORK_AREA *QemuFwCfgCacheWorkArea;
FW_CFG_CACHED_ITEM *CachedItem;
UINTN ReadSize;
QEMU_FW_CFG_WORK_AREA *QemuFwCfgWorkArea;
FW_CFG_CACHED_ITEM *CachedItem;
UINTN ReadSize;
if (Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
QemuFwCfgCacheWorkArea = InternalQemuFwCfgCacheGetWorkArea ();
if (QemuFwCfgCacheWorkArea == NULL) {
QemuFwCfgWorkArea = InternalQemuFwCfgCacheGetWorkArea ();
if (QemuFwCfgWorkArea == NULL) {
return RETURN_NOT_FOUND;
}
if (!QemuFwCfgCacheWorkArea->Reading) {
if (!QemuFwCfgWorkArea->Reading) {
return RETURN_NOT_READY;
}
CachedItem = InternalQemuFwCfgItemCached (QemuFwCfgCacheWorkArea->FwCfgItem);
CachedItem = InternalQemuFwCfgItemCached (QemuFwCfgWorkArea->FwCfgItem);
if (CachedItem == NULL) {
return RETURN_NOT_FOUND;
}
if (QemuFwCfgCacheWorkArea->Offset >= CachedItem->DataSize) {
DEBUG ((DEBUG_ERROR, "%a: Invalid Item Offset(0x%x) in FwCfg Cache\n", __func__, QemuFwCfgCacheWorkArea->Offset));
if (QemuFwCfgWorkArea->Offset >= CachedItem->DataSize) {
DEBUG ((DEBUG_ERROR, "%a: Invalid Item Offset(0x%x) in FwCfg Cache\n", __func__, QemuFwCfgWorkArea->Offset));
ASSERT (FALSE);
return RETURN_ABORTED;
}
if (CachedItem->DataSize - QemuFwCfgCacheWorkArea->Offset > Size) {
if (CachedItem->DataSize - QemuFwCfgWorkArea->Offset > Size) {
ReadSize = Size;
} else {
ReadSize = CachedItem->DataSize - QemuFwCfgCacheWorkArea->Offset;
ReadSize = CachedItem->DataSize - QemuFwCfgWorkArea->Offset;
}
CopyMem (Buffer, (UINT8 *)CachedItem + sizeof (FW_CFG_CACHED_ITEM) + QemuFwCfgCacheWorkArea->Offset, ReadSize);
QemuFwCfgCacheWorkArea->Offset += (UINT32)ReadSize;
CopyMem (Buffer, (UINT8 *)CachedItem + sizeof (FW_CFG_CACHED_ITEM) + QemuFwCfgWorkArea->Offset, ReadSize);
QemuFwCfgWorkArea->Offset += (UINT32)ReadSize;
DEBUG ((DEBUG_VERBOSE, "%a: found Item 0x%x in FwCfg Cache\n", __func__, QemuFwCfgCacheWorkArea->FwCfgItem));
DEBUG ((DEBUG_VERBOSE, "%a: found Item 0x%x in FwCfg Cache\n", __func__, QemuFwCfgWorkArea->FwCfgItem));
return RETURN_SUCCESS;
}

View File

@ -240,9 +240,9 @@ InternalQemuFwCfgInitCache (
return EFI_INVALID_PARAMETER;
}
PlatformInfoHob->QemuFwCfgCacheWorkArea.FwCfgItem = INVALID_FW_CFG_ITEM;
PlatformInfoHob->QemuFwCfgCacheWorkArea.Offset = 0;
PlatformInfoHob->QemuFwCfgCacheWorkArea.Reading = FALSE;
PlatformInfoHob->QemuFwCfgWorkArea.FwCfgItem = INVALID_FW_CFG_ITEM;
PlatformInfoHob->QemuFwCfgWorkArea.Offset = 0;
PlatformInfoHob->QemuFwCfgWorkArea.Reading = FALSE;
if (!QemuFwCfgIsAvailable ()) {
return EFI_UNSUPPORTED;

View File

@ -24,12 +24,9 @@
#include "QemuFwCfgLibInternal.h"
STATIC BOOLEAN mQemuFwCfgSupported = FALSE;
STATIC BOOLEAN mQemuFwCfgDmaSupported;
STATIC EDKII_IOMMU_PROTOCOL *mIoMmuProtocol;
STATIC QEMU_FW_CFG_CACHE_WORK_AREA mFwCfgCacheWorkArea = { 0 };
STATIC QEMU_FW_CFG_WORK_AREA mQemuFwCfgWorkArea = { 0 };
/**
Returns a boolean indicating if the firmware configuration interface
@ -64,8 +61,8 @@ QemuFwCfgInitialize (
// Enable the access routines while probing to see if it is supported.
// For probing we always use the IO Port (IoReadFifo8()) access method.
//
mQemuFwCfgSupported = TRUE;
mQemuFwCfgDmaSupported = FALSE;
mQemuFwCfgWorkArea.QemuFwCfgSupported = TRUE;
mQemuFwCfgWorkArea.QemuFwCfgDmaSupported = FALSE;
QemuFwCfgSelectItem (QemuFwCfgItemSignature);
Signature = QemuFwCfgRead32 ();
@ -78,20 +75,20 @@ QemuFwCfgInitialize (
)
{
DEBUG ((DEBUG_INFO, "QemuFwCfg interface not supported.\n"));
mQemuFwCfgSupported = FALSE;
mQemuFwCfgWorkArea.QemuFwCfgSupported = FALSE;
return RETURN_SUCCESS;
}
if ((Revision & FW_CFG_F_DMA) == 0) {
DEBUG ((DEBUG_INFO, "QemuFwCfg interface (IO Port) is supported.\n"));
} else {
mQemuFwCfgDmaSupported = TRUE;
mQemuFwCfgWorkArea.QemuFwCfgDmaSupported = TRUE;
DEBUG ((DEBUG_INFO, "QemuFwCfg interface (DMA) is supported.\n"));
}
CcGuestAttr = PcdGet64 (PcdConfidentialComputingGuestAttr);
if (mQemuFwCfgDmaSupported && (CC_GUEST_IS_SEV (CcGuestAttr) ||
CC_GUEST_IS_TDX (CcGuestAttr)))
if (mQemuFwCfgWorkArea.QemuFwCfgDmaSupported && (CC_GUEST_IS_SEV (CcGuestAttr) ||
CC_GUEST_IS_TDX (CcGuestAttr)))
{
EFI_STATUS Status;
@ -133,7 +130,7 @@ InternalQemuFwCfgIsAvailable (
VOID
)
{
return mQemuFwCfgSupported;
return mQemuFwCfgWorkArea.QemuFwCfgSupported;
}
/**
@ -148,7 +145,7 @@ InternalQemuFwCfgDmaIsAvailable (
VOID
)
{
return mQemuFwCfgDmaSupported;
return mQemuFwCfgWorkArea.QemuFwCfgDmaSupported;
}
/**
@ -514,17 +511,17 @@ InternalQemuFwCfgCheckOvmfWorkArea (
}
/**
Get the pointer to the QEMU_FW_CFG_CACHE_WORK_AREA. This data is used as the
Get the pointer to the QEMU_FW_CFG_WORK_AREA. This data is used as the
workarea to record the ongoing fw_cfg item and offset.
@retval QEMU_FW_CFG_CACHE_WORK_AREA Pointer to the QEMU_FW_CFG_CACHE_WORK_AREA
@retval NULL QEMU_FW_CFG_CACHE_WORK_AREA doesn't exist
@retval QEMU_FW_CFG_WORK_AREA Pointer to the QEMU_FW_CFG_WORK_AREA
@retval NULL QEMU_FW_CFG_WORK_AREA doesn't exist
**/
QEMU_FW_CFG_CACHE_WORK_AREA *
QEMU_FW_CFG_WORK_AREA *
InternalQemuFwCfgCacheGetWorkArea (
VOID
)
{
return &mFwCfgCacheWorkArea;
return &mQemuFwCfgWorkArea;
}
RETURN_STATUS

View File

@ -135,19 +135,19 @@ InternalQemuFwCfgCacheSkipBytes (
IN UINT32 Size
)
{
QEMU_FW_CFG_CACHE_WORK_AREA *QemuFwCfgCacheWorkArea;
QEMU_FW_CFG_WORK_AREA *QemuFwCfgWorkArea;
if (Size == 0) {
return;
}
QemuFwCfgCacheWorkArea = InternalQemuFwCfgCacheGetWorkArea ();
if ((QemuFwCfgCacheWorkArea->Offset + Size) > MAX_UINT32) {
QemuFwCfgWorkArea = InternalQemuFwCfgCacheGetWorkArea ();
if ((QemuFwCfgWorkArea->Offset + Size) > MAX_UINT32) {
DEBUG ((DEBUG_ERROR, "%a: Integer overflow with invalid offset size\n", __func__));
ASSERT (FALSE);
QemuFwCfgCacheWorkArea->Offset = MAX_UINT32;
QemuFwCfgWorkArea->Offset = MAX_UINT32;
} else {
QemuFwCfgCacheWorkArea->Offset += Size;
QemuFwCfgWorkArea->Offset += Size;
}
}

View File

@ -130,18 +130,18 @@ InternalQemuFwCfgCacheSelectItem (
);
/**
Get the pointer to the QEMU_FW_CFG_CACHE_WORK_AREA. This data is used as the
Get the pointer to the QEMU_FW_CFG_WORK_AREA. This data is used as the
workarea to record the ongoing fw_cfg item and offset.
@retval QEMU_FW_CFG_CACHE_WORK_AREA Pointer to the QEMU_FW_CFG_CACHE_WORK_AREA
@retval NULL QEMU_FW_CFG_CACHE_WORK_AREA doesn't exist
@retval QEMU_FW_CFG_WORK_AREA Pointer to the QEMU_FW_CFG_WORK_AREA
@retval NULL QEMU_FW_CFG_WORK_AREA doesn't exist
**/
QEMU_FW_CFG_CACHE_WORK_AREA *
QEMU_FW_CFG_WORK_AREA *
InternalQemuFwCfgCacheGetWorkArea (
VOID
);
/**
Clear the QEMU_FW_CFG_CACHE_WORK_AREA.
Clear the QEMU_FW_CFG_WORK_AREA.
**/
VOID
InternalQemuFwCfgCacheResetWorkArea (

View File

@ -120,8 +120,8 @@ QemuFwCfgGetPlatformInfo (
if (!PlatformInfoHob->QemuFwCfgChecked) {
QemuFwCfgProbe (
&PlatformInfoHob->QemuFwCfgSupported,
&PlatformInfoHob->QemuFwCfgDmaSupported
&PlatformInfoHob->QemuFwCfgWorkArea.QemuFwCfgSupported,
&PlatformInfoHob->QemuFwCfgWorkArea.QemuFwCfgDmaSupported
);
PlatformInfoHob->QemuFwCfgChecked = TRUE;
}
@ -154,7 +154,7 @@ InternalQemuFwCfgIsAvailable (
{
EFI_HOB_PLATFORM_INFO *PlatformInfoHob = QemuFwCfgGetPlatformInfo ();
return PlatformInfoHob->QemuFwCfgSupported;
return PlatformInfoHob->QemuFwCfgWorkArea.QemuFwCfgSupported;
}
/**
@ -171,7 +171,7 @@ InternalQemuFwCfgDmaIsAvailable (
{
EFI_HOB_PLATFORM_INFO *PlatformInfoHob = QemuFwCfgGetPlatformInfo ();
return PlatformInfoHob->QemuFwCfgDmaSupported;
return PlatformInfoHob->QemuFwCfgWorkArea.QemuFwCfgDmaSupported;
}
/**
@ -253,12 +253,12 @@ InternalQemuFwCfgDmaBytes (
}
/**
Get the pointer to the QEMU_FW_CFG_CACHE_WORK_AREA. This data is used as the
Get the pointer to the QEMU_FW_CFG_WORK_AREA. This data is used as the
workarea to record the onging fw_cfg item and offset.
@retval QEMU_FW_CFG_CACHE_WORK_AREA Pointer to the QEMU_FW_CFG_CACHE_WORK_AREA
@retval NULL QEMU_FW_CFG_CACHE_WORK_AREA doesn't exist
@retval QEMU_FW_CFG_WORK_AREA Pointer to the QEMU_FW_CFG_WORK_AREA
@retval NULL QEMU_FW_CFG_WORK_AREA doesn't exist
**/
QEMU_FW_CFG_CACHE_WORK_AREA *
QEMU_FW_CFG_WORK_AREA *
InternalQemuFwCfgCacheGetWorkArea (
VOID
)
@ -272,7 +272,7 @@ InternalQemuFwCfgCacheGetWorkArea (
}
PlatformHobinfo = (EFI_HOB_PLATFORM_INFO *)(VOID *)GET_GUID_HOB_DATA (GuidHob);
return &(PlatformHobinfo->QemuFwCfgCacheWorkArea);
return &(PlatformHobinfo->QemuFwCfgWorkArea);
}
/**

View File

@ -150,12 +150,12 @@ InternalQemuFwCfgCheckOvmfWorkArea (
}
/**
Get the pointer to the QEMU_FW_CFG_CACHE_WORK_AREA. This data is used as the
Get the pointer to the QEMU_FW_CFG_WORK_AREA. This data is used as the
workarea to record the ongoing fw_cfg item and offset.
@retval QEMU_FW_CFG_CACHE_WORK_AREA Pointer to the QEMU_FW_CFG_CACHE_WORK_AREA
@retval NULL QEMU_FW_CFG_CACHE_WORK_AREA doesn't exist
@retval QEMU_FW_CFG_WORK_AREA Pointer to the QEMU_FW_CFG_WORK_AREA
@retval NULL QEMU_FW_CFG_WORK_AREA doesn't exist
**/
QEMU_FW_CFG_CACHE_WORK_AREA *
QEMU_FW_CFG_WORK_AREA *
InternalQemuFwCfgCacheGetWorkArea (
VOID
)
@ -173,7 +173,7 @@ InternalQemuFwCfgCacheGetWorkArea (
}
PlatformHobinfo = (EFI_HOB_PLATFORM_INFO *)(VOID *)GET_GUID_HOB_DATA (GuidHob);
return &(PlatformHobinfo->QemuFwCfgCacheWorkArea);
return &(PlatformHobinfo->QemuFwCfgWorkArea);
}
/**