]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PlatformPei: set 32-bit UC area at PciBase / PciExBarBase (pc/q35)
authorLaszlo Ersek <lersek@redhat.com>
Wed, 29 May 2019 12:49:55 +0000 (14:49 +0200)
committerLaszlo Ersek <lersek@redhat.com>
Mon, 3 Jun 2019 17:54:34 +0000 (19:54 +0200)
(This is a replacement for commit 39b9a5ffe661 ("OvmfPkg/PlatformPei: fix
MTRR for low-RAM sizes that have many bits clear", 2019-05-16).)

Reintroduce the same logic as seen in commit 39b9a5ffe661 for the pc
(i440fx) board type.

For q35, the same approach doesn't work any longer, given that (a) we'd
like to keep the PCIEXBAR in the platform DSC a fixed-at-build PCD, and
(b) QEMU expects the PCIEXBAR to reside at a lower address than the 32-bit
PCI MMIO aperture.

Therefore, introduce a helper function for determining the 32-bit
"uncacheable" (MMIO) area base address:

- On q35, this function behaves statically. Furthermore, the MTRR setup
  exploits that the range [0xB000_0000, 0xFFFF_FFFF] can be marked UC with
  just two variable MTRRs (one at 0xB000_0000 (size 256MB), another at
  0xC000_0000 (size 1GB)).

- On pc (i440fx), the function behaves dynamically, implementing the same
  logic as commit 39b9a5ffe661 did. The PciBase value is adjusted to the
  value calculated, similarly to commit 39b9a5ffe661. A further
  simplification is that we show that the UC32 area size truncation to a
  whole power of two automatically guarantees a >=2GB base address.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1859
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
OvmfPkg/PlatformPei/MemDetect.c
OvmfPkg/PlatformPei/Platform.c
OvmfPkg/PlatformPei/Platform.h

index e890e36408a6ad7530581995e926e18968d4f38b..d451989f31c9b20b2154f8d65be89f6b02e296ce 100644 (file)
@@ -14,6 +14,7 @@ Module Name:
 // The package level header files this module uses\r
 //\r
 #include <IndustryStandard/E820.h>\r
+#include <IndustryStandard/I440FxPiix4.h>\r
 #include <IndustryStandard/Q35MchIch9.h>\r
 #include <PiPei.h>\r
 \r
@@ -42,6 +43,8 @@ STATIC UINT32 mS3AcpiReservedMemorySize;
 \r
 STATIC UINT16 mQ35TsegMbytes;\r
 \r
+UINT32 mQemuUc32Base;\r
+\r
 VOID\r
 Q35TsegMbytesInitialization (\r
   VOID\r
@@ -98,6 +101,54 @@ Q35TsegMbytesInitialization (
 }\r
 \r
 \r
+VOID\r
+QemuUc32BaseInitialization (\r
+  VOID\r
+  )\r
+{\r
+  UINT32 LowerMemorySize;\r
+  UINT32 Uc32Size;\r
+\r
+  if (mXen) {\r
+    return;\r
+  }\r
+\r
+  if (mHostBridgeDevId == INTEL_Q35_MCH_DEVICE_ID) {\r
+    //\r
+    // On q35, the 32-bit area that we'll mark as UC, through variable MTRRs,\r
+    // starts at PcdPciExpressBaseAddress. The platform DSC is responsible for\r
+    // setting PcdPciExpressBaseAddress such that describing the\r
+    // [PcdPciExpressBaseAddress, 4GB) range require a very small number of\r
+    // variable MTRRs (preferably 1 or 2).\r
+    //\r
+    ASSERT (FixedPcdGet64 (PcdPciExpressBaseAddress) <= MAX_UINT32);\r
+    mQemuUc32Base = (UINT32)FixedPcdGet64 (PcdPciExpressBaseAddress);\r
+    return;\r
+  }\r
+\r
+  ASSERT (mHostBridgeDevId == INTEL_82441_DEVICE_ID);\r
+  //\r
+  // On i440fx, start with the [LowerMemorySize, 4GB) range. Make sure one\r
+  // variable MTRR suffices by truncating the size to a whole power of two,\r
+  // while keeping the end affixed to 4GB. This will round the base up.\r
+  //\r
+  LowerMemorySize = GetSystemMemorySizeBelow4gb ();\r
+  Uc32Size = GetPowerOfTwo32 ((UINT32)(SIZE_4GB - LowerMemorySize));\r
+  mQemuUc32Base = (UINT32)(SIZE_4GB - Uc32Size);\r
+  //\r
+  // Assuming that LowerMemorySize is at least 1 byte, Uc32Size is at most 2GB.\r
+  // Therefore mQemuUc32Base is at least 2GB.\r
+  //\r
+  ASSERT (mQemuUc32Base >= BASE_2GB);\r
+\r
+  if (mQemuUc32Base != LowerMemorySize) {\r
+    DEBUG ((DEBUG_VERBOSE, "%a: rounded UC32 base from 0x%x up to 0x%x, for "\r
+      "an UC32 size of 0x%x\n", __FUNCTION__, LowerMemorySize, mQemuUc32Base,\r
+      Uc32Size));\r
+  }\r
+}\r
+\r
+\r
 /**\r
   Iterate over the RAM entries in QEMU's fw_cfg E820 RAM map that start outside\r
   of the 32-bit address range.\r
@@ -688,11 +739,11 @@ QemuInitializeRam (
     ASSERT_EFI_ERROR (Status);\r
 \r
     //\r
-    // Set memory range from the "top of lower RAM" (RAM below 4GB) to 4GB as\r
-    // uncacheable\r
+    // Set the memory range from the start of the 32-bit MMIO area (32-bit PCI\r
+    // MMIO aperture on i440fx, PCIEXBAR on q35) to 4GB as uncacheable.\r
     //\r
-    Status = MtrrSetMemoryAttribute (LowerMemorySize,\r
-               SIZE_4GB - LowerMemorySize, CacheUncacheable);\r
+    Status = MtrrSetMemoryAttribute (mQemuUc32Base, SIZE_4GB - mQemuUc32Base,\r
+               CacheUncacheable);\r
     ASSERT_EFI_ERROR (Status);\r
   }\r
 }\r
index 0876316eefbc7643aade7f8b1028a3ddd7e87fb9..3ba2459872d93d48ca9258fb12c1587ad0751d20 100644 (file)
@@ -191,7 +191,8 @@ MemMapInitialization (
       ASSERT (PciExBarBase <= MAX_UINT32 - SIZE_256MB);\r
       PciBase = (UINT32)(PciExBarBase + SIZE_256MB);\r
     } else {\r
-      PciBase = (TopOfLowRam < BASE_2GB) ? BASE_2GB : TopOfLowRam;\r
+      ASSERT (TopOfLowRam <= mQemuUc32Base);\r
+      PciBase = mQemuUc32Base;\r
     }\r
 \r
     //\r
@@ -650,6 +651,8 @@ InitializePlatform (
 \r
   PublishPeiMemory ();\r
 \r
+  QemuUc32BaseInitialization ();\r
+\r
   InitializeRamRegions ();\r
 \r
   if (mXen) {\r
index 81af8b71480f72190882679e37f639169733084b..2f3cebcd3a6a983a93b459e9184e593d9f4baff9 100644 (file)
@@ -62,6 +62,11 @@ GetSystemMemorySizeBelow4gb (
   VOID\r
   );\r
 \r
+VOID\r
+QemuUc32BaseInitialization (\r
+  VOID\r
+  );\r
+\r
 VOID\r
 InitializeRamRegions (\r
   VOID\r
@@ -114,4 +119,6 @@ extern UINT32 mMaxCpuCount;
 \r
 extern UINT16 mHostBridgeDevId;\r
 \r
+extern UINT32 mQemuUc32Base;\r
+\r
 #endif // _PLATFORM_PEI_H_INCLUDED_\r