Skip to content

Commit

Permalink
OvmfPkg/QemuFwCfgLib: remove mQemuFwCfgSupported + mQemuFwCfgDmaSuppo…
Browse files Browse the repository at this point in the history
…rted

Remove global variables, store the state in PlatformInfoHob instead.
Probing for fw_cfg happens on first use, at library initialization
time the Hob might not be present yet.

Signed-off-by: Gerd Hoffmann <[email protected]>
Tested-by: Tom Lendacky <[email protected]>
Acked-by: Ard Biesheuvel <[email protected]>
  • Loading branch information
kraxel authored and mergify[bot] committed Dec 14, 2022
1 parent 81bbc14 commit cda98df
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
4 changes: 4 additions & 0 deletions OvmfPkg/Include/Library/PlatformInitLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ typedef struct {
UINT32 S3AcpiReservedMemorySize;

UINT64 FeatureControlValue;

BOOLEAN QemuFwCfgChecked;
BOOLEAN QemuFwCfgSupported;
BOOLEAN QemuFwCfgDmaSupported;
} EFI_HOB_PLATFORM_INFO;
#pragma pack()

Expand Down
44 changes: 37 additions & 7 deletions OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <PiPei.h>
#include <Library/BaseLib.h>
#include <Library/IoLib.h>
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Library/IoLib.h>
#include <Library/PlatformInitLib.h>
#include <Library/QemuFwCfgLib.h>
#include <WorkArea.h>

#include "QemuFwCfgLibInternal.h"

STATIC BOOLEAN mQemuFwCfgSupported = FALSE;
STATIC BOOLEAN mQemuFwCfgDmaSupported;

/**
Check if it is Tdx guest
Expand Down Expand Up @@ -93,13 +93,39 @@ QemuFwCfgProbe (
));
}

STATIC
EFI_HOB_PLATFORM_INFO *
QemuFwCfgGetPlatformInfo (
VOID
)
{
EFI_HOB_PLATFORM_INFO *PlatformInfoHob;
EFI_HOB_GUID_TYPE *GuidHob;

GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid);
if (GuidHob == NULL) {
return NULL;
}

PlatformInfoHob = (EFI_HOB_PLATFORM_INFO *)GET_GUID_HOB_DATA (GuidHob);

if (!PlatformInfoHob->QemuFwCfgChecked) {
QemuFwCfgProbe (
&PlatformInfoHob->QemuFwCfgSupported,
&PlatformInfoHob->QemuFwCfgDmaSupported
);
PlatformInfoHob->QemuFwCfgChecked = TRUE;
}

return PlatformInfoHob;
}

RETURN_STATUS
EFIAPI
QemuFwCfgInitialize (
VOID
)
{
QemuFwCfgProbe (&mQemuFwCfgSupported, &mQemuFwCfgDmaSupported);
return RETURN_SUCCESS;
}

Expand All @@ -117,7 +143,9 @@ InternalQemuFwCfgIsAvailable (
VOID
)
{
return mQemuFwCfgSupported;
EFI_HOB_PLATFORM_INFO *PlatformInfoHob = QemuFwCfgGetPlatformInfo ();

return PlatformInfoHob->QemuFwCfgSupported;
}

/**
Expand All @@ -132,7 +160,9 @@ InternalQemuFwCfgDmaIsAvailable (
VOID
)
{
return mQemuFwCfgDmaSupported;
EFI_HOB_PLATFORM_INFO *PlatformInfoHob = QemuFwCfgGetPlatformInfo ();

return PlatformInfoHob->QemuFwCfgDmaSupported;
}

/**
Expand Down
4 changes: 4 additions & 0 deletions OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@
BaseLib
BaseMemoryLib
DebugLib
HobLib
IoLib
MemoryAllocationLib

[Guids]
gUefiOvmfPkgPlatformInfoGuid

[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase

0 comments on commit cda98df

Please sign in to comment.