]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PlatformPei: parse "X-PciMmio64Mb" with QemuFwCfgSimpleParserLib
authorLaszlo Ersek <lersek@redhat.com>
Fri, 24 Apr 2020 07:53:48 +0000 (09:53 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 28 Apr 2020 22:37:35 +0000 (22:37 +0000)
Replace the

- QemuFwCfgFindFile(),
- QemuFwCfgSelectItem(),
- QemuFwCfgReadBytes(),
- AsciiStrDecimalToUint64()

sequence in the GetFirstNonAddress() function with a call to
QemuFwCfgSimpleParserLib.

This change is compatible with valid strings accepted previously.

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Per Sundstrom <per_sundstrom@yahoo.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2681
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20200424075353.8489-3-lersek@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
OvmfPkg/PlatformPei/MemDetect.c
OvmfPkg/PlatformPei/PlatformPei.inf

index 47dc9c543719a0f55c4279140d23a8d5822b57f2..f32df937f9bad96ed92413a9ecbda7c3141608fb 100644 (file)
@@ -33,6 +33,7 @@ Module Name:
 #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
@@ -336,7 +337,7 @@ GetFirstNonAddress (
 {\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
@@ -379,25 +380,30 @@ GetFirstNonAddress (
 \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
index 19f2424981bca6352f4d4ce94bfb132215bc3bbd..e72ef7963d97247aa165381ca461c47c75aa05f0 100644 (file)
@@ -60,6 +60,7 @@
   PeimEntryPoint\r
   QemuFwCfgLib\r
   QemuFwCfgS3Lib\r
+  QemuFwCfgSimpleParserLib\r
   MtrrLib\r
   MemEncryptSevLib\r
   PcdLib\r