diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c index 47dc9c5437..f32df937f9 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -33,6 +33,7 @@ Module Name: #include #include #include +#include #include "Platform.h" #include "Cmos.h" @@ -336,7 +337,7 @@ GetFirstNonAddress ( { UINT64 FirstNonAddress; UINT64 Pci64Base, Pci64Size; - CHAR8 MbString[7 + 1]; + UINT32 FwCfgPciMmio64Mb; EFI_STATUS Status; FIRMWARE_CONFIG_ITEM FwCfgItem; UINTN FwCfgSize; @@ -379,25 +380,30 @@ GetFirstNonAddress ( // // See if the user specified the number of megabytes for the 64-bit PCI host - // aperture. The number of non-NUL characters in MbString allows for - // 9,999,999 MB, which is approximately 10 TB. + // aperture. Accept an aperture size up to 16TB. // // As signaled by the "X-" prefix, this knob is experimental, and might go // away at any time. // - Status = QemuFwCfgFindFile ("opt/ovmf/X-PciMmio64Mb", &FwCfgItem, - &FwCfgSize); - if (!EFI_ERROR (Status)) { - if (FwCfgSize >= sizeof MbString) { - DEBUG ((EFI_D_WARN, - "%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n", - __FUNCTION__)); - } else { - QemuFwCfgSelectItem (FwCfgItem); - QemuFwCfgReadBytes (FwCfgSize, MbString); - MbString[FwCfgSize] = '\0'; - Pci64Size = LShiftU64 (AsciiStrDecimalToUint64 (MbString), 20); + Status = QemuFwCfgParseUint32 ("opt/ovmf/X-PciMmio64Mb", FALSE, + &FwCfgPciMmio64Mb); + switch (Status) { + case EFI_UNSUPPORTED: + case EFI_NOT_FOUND: + break; + case EFI_SUCCESS: + if (FwCfgPciMmio64Mb <= 0x1000000) { + Pci64Size = LShiftU64 (FwCfgPciMmio64Mb, 20); + break; } + // + // fall through + // + default: + DEBUG ((DEBUG_WARN, + "%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n", + __FUNCTION__)); + break; } if (Pci64Size == 0) { diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index 19f2424981..e72ef7963d 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -60,6 +60,7 @@ PeimEntryPoint QemuFwCfgLib QemuFwCfgS3Lib + QemuFwCfgSimpleParserLib MtrrLib MemEncryptSevLib PcdLib