OvmfPkg: CloudHv: Rely on PVH memmap instead of CMOS

Instead of using the CMOS, the CloudHv platform relies on the list of
memmap entries provided through the PVH boot protocol to determine the
last RAM address below 4G.

Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
This commit is contained in:
Sebastien Boeuf 2022-03-02 21:31:36 +08:00 committed by mergify[bot]
parent d50d9e5549
commit 82bfd2e86d
2 changed files with 75 additions and 0 deletions

View File

@ -17,6 +17,7 @@ Module Name:
#include <IndustryStandard/I440FxPiix4.h>
#include <IndustryStandard/Q35MchIch9.h>
#include <IndustryStandard/CloudHv.h>
#include <IndustryStandard/Xen/arch-x86/hvm/start_info.h>
#include <PiPei.h>
#include <Register/Intel/SmramSaveStateMap.h>
@ -315,6 +316,73 @@ ScanOrAdd64BitE820Ram (
return EFI_SUCCESS;
}
/**
Returns PVH memmap
@param Entries Pointer to PVH memmap
@param Count Number of entries
@return EFI_STATUS
**/
EFI_STATUS
GetPvhMemmapEntries (
struct hvm_memmap_table_entry **Entries,
UINT32 *Count
)
{
UINT32 *PVHResetVectorData;
struct hvm_start_info *pvh_start_info;
PVHResetVectorData = (VOID *)(UINTN)PcdGet32 (PcdXenPvhStartOfDayStructPtr);
if (PVHResetVectorData == 0) {
return EFI_NOT_FOUND;
}
pvh_start_info = (struct hvm_start_info *)(UINTN)PVHResetVectorData[0];
*Entries = (struct hvm_memmap_table_entry *)(UINTN)pvh_start_info->memmap_paddr;
*Count = pvh_start_info->memmap_entries;
return EFI_SUCCESS;
}
STATIC
UINT64
GetHighestSystemMemoryAddressFromPvhMemmap (
BOOLEAN Below4gb
)
{
struct hvm_memmap_table_entry *Memmap;
UINT32 MemmapEntriesCount;
struct hvm_memmap_table_entry *Entry;
EFI_STATUS Status;
UINT32 Loop;
UINT64 HighestAddress;
UINT64 EntryEnd;
HighestAddress = 0;
Status = GetPvhMemmapEntries (&Memmap, &MemmapEntriesCount);
ASSERT_EFI_ERROR (Status);
for (Loop = 0; Loop < MemmapEntriesCount; Loop++) {
Entry = Memmap + Loop;
EntryEnd = Entry->addr + Entry->size;
if ((Entry->type == XEN_HVM_MEMMAP_TYPE_RAM) &&
(EntryEnd > HighestAddress))
{
if (Below4gb && (EntryEnd <= BASE_4GB)) {
HighestAddress = EntryEnd;
} else if (!Below4gb && (EntryEnd >= BASE_4GB)) {
HighestAddress = EntryEnd;
}
}
}
return HighestAddress;
}
UINT32
GetSystemMemorySizeBelow4gb (
VOID
@ -325,6 +393,11 @@ GetSystemMemorySizeBelow4gb (
UINT8 Cmos0x34;
UINT8 Cmos0x35;
if (mHostBridgeDevId == CLOUDHV_DEVICE_ID) {
// Get the information from PVH memmap
return (UINT32)GetHighestSystemMemoryAddressFromPvhMemmap (TRUE);
}
Status = ScanOrAdd64BitE820Ram (FALSE, &LowerMemorySize, NULL);
if ((Status == EFI_SUCCESS) && (LowerMemorySize > 0)) {
return (UINT32)LowerMemorySize;

View File

@ -91,6 +91,8 @@
gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDecompressionScratchEnd
gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes
gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase
gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtr
gUefiOvmfPkgTokenSpaceGuid.PcdXenPvhStartOfDayStructPtrSize
gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize