#include <Library/ResourcePublicationLib.h>\r
#include <Library/MtrrLib.h>\r
#include <Library/QemuFwCfgLib.h>\r
+#include <Library/QemuFwCfgSimpleParserLib.h>\r
\r
#include "Platform.h"\r
#include "Cmos.h"\r
{\r
UINT64 FirstNonAddress;\r
UINT64 Pci64Base, Pci64Size;\r
- CHAR8 MbString[7 + 1];\r
+ UINT32 FwCfgPciMmio64Mb;\r
EFI_STATUS Status;\r
FIRMWARE_CONFIG_ITEM FwCfgItem;\r
UINTN FwCfgSize;\r
\r
//\r
// See if the user specified the number of megabytes for the 64-bit PCI host\r
- // aperture. The number of non-NUL characters in MbString allows for\r
- // 9,999,999 MB, which is approximately 10 TB.\r
+ // aperture. Accept an aperture size up to 16TB.\r
//\r
// As signaled by the "X-" prefix, this knob is experimental, and might go\r
// away at any time.\r
//\r
- Status = QemuFwCfgFindFile ("opt/ovmf/X-PciMmio64Mb", &FwCfgItem,\r
- &FwCfgSize);\r
- if (!EFI_ERROR (Status)) {\r
- if (FwCfgSize >= sizeof MbString) {\r
- DEBUG ((EFI_D_WARN,\r
- "%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n",\r
- __FUNCTION__));\r
- } else {\r
- QemuFwCfgSelectItem (FwCfgItem);\r
- QemuFwCfgReadBytes (FwCfgSize, MbString);\r
- MbString[FwCfgSize] = '\0';\r
- Pci64Size = LShiftU64 (AsciiStrDecimalToUint64 (MbString), 20);\r
+ Status = QemuFwCfgParseUint32 ("opt/ovmf/X-PciMmio64Mb", FALSE,\r
+ &FwCfgPciMmio64Mb);\r
+ switch (Status) {\r
+ case EFI_UNSUPPORTED:\r
+ case EFI_NOT_FOUND:\r
+ break;\r
+ case EFI_SUCCESS:\r
+ if (FwCfgPciMmio64Mb <= 0x1000000) {\r
+ Pci64Size = LShiftU64 (FwCfgPciMmio64Mb, 20);\r
+ break;\r
}\r
+ //\r
+ // fall through\r
+ //\r
+ default:\r
+ DEBUG ((DEBUG_WARN,\r
+ "%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n",\r
+ __FUNCTION__));\r
+ break;\r
}\r
\r
if (Pci64Size == 0) {\r