]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtPkg/FdtPciHostBridgeLib: map ECAM and I/O spaces in GCD memory map
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 27 Nov 2018 14:18:38 +0000 (15:18 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 29 Nov 2018 17:52:22 +0000 (18:52 +0100)
Up until now, we have been getting away with not declaring the ECAM
and translated I/O spaces at all in the GCD memory map, simply because
we map the entire address space with device attributes in the early PEI
code, and so the ECAM space will be mapped wherever it ends up.

Now that we are about to make changes to how ArmVirtQemu reasons
about the size of the address space, it would be better to get rid
of this mapping of the entire address space, since it can get
arbitrarily large without real benefit.

So start by mapping the ECAM and translated I/O spaces explicitly,
instead of relying on the early PEI mapping.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf

index 5b9c887db35df2f5b359df017be5860c6953bc82..ebfa14a349f4aad62c25e18ee888211a9432ccd7 100644 (file)
@@ -17,6 +17,7 @@
 #include <Library/PciHostBridgeLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/DevicePathLib.h>\r
 #include <Library/PciHostBridgeLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/DevicePathLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
@@ -82,6 +83,33 @@ typedef struct {
 #define DTB_PCI_HOST_RANGE_IO           BIT24\r
 #define DTB_PCI_HOST_RANGE_TYPEMASK     (BIT31 | BIT30 | BIT29 | BIT25 | BIT24)\r
 \r
 #define DTB_PCI_HOST_RANGE_IO           BIT24\r
 #define DTB_PCI_HOST_RANGE_TYPEMASK     (BIT31 | BIT30 | BIT29 | BIT25 | BIT24)\r
 \r
+STATIC\r
+EFI_STATUS\r
+MapGcdMmioSpace (\r
+  IN    UINT64    Base,\r
+  IN    UINT64    Size\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+\r
+  Status = gDS->AddMemorySpace (EfiGcdMemoryTypeMemoryMappedIo, Base, Size,\r
+                  EFI_MEMORY_UC);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR,\r
+      "%a: failed to add GCD memory space for region [0x%Lx+0x%Lx)\n",\r
+      __FUNCTION__, Base, Size));\r
+    return Status;\r
+  }\r
+\r
+  Status = gDS->SetMemorySpaceAttributes (Base, Size, EFI_MEMORY_UC);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR,\r
+      "%a: failed to set memory space attributes for region [0x%Lx+0x%Lx)\n",\r
+      __FUNCTION__, Base, Size));\r
+  }\r
+  return Status;\r
+}\r
+\r
 STATIC\r
 EFI_STATUS\r
 ProcessPciHost (\r
 STATIC\r
 EFI_STATUS\r
 ProcessPciHost (\r
@@ -266,7 +294,23 @@ ProcessPciHost (
     "Io[0x%Lx+0x%Lx)@0x%Lx Mem32[0x%Lx+0x%Lx)@0x0 Mem64[0x%Lx+0x%Lx)@0x0\n",\r
     __FUNCTION__, ConfigBase, ConfigSize, *BusMin, *BusMax, *IoBase, *IoSize,\r
     IoTranslation, *Mmio32Base, *Mmio32Size, *Mmio64Base, *Mmio64Size));\r
     "Io[0x%Lx+0x%Lx)@0x%Lx Mem32[0x%Lx+0x%Lx)@0x0 Mem64[0x%Lx+0x%Lx)@0x0\n",\r
     __FUNCTION__, ConfigBase, ConfigSize, *BusMin, *BusMax, *IoBase, *IoSize,\r
     IoTranslation, *Mmio32Base, *Mmio32Size, *Mmio64Base, *Mmio64Size));\r
-  return EFI_SUCCESS;\r
+\r
+  // Map the ECAM space in the GCD memory map\r
+  Status = MapGcdMmioSpace (ConfigBase, ConfigSize);\r
+  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Map the MMIO window that provides I/O access - the PCI host bridge code\r
+  // is not aware of this translation and so it will only map the I/O view\r
+  // in the GCD I/O map.\r
+  //\r
+  Status = MapGcdMmioSpace (*IoBase + IoTranslation, *IoSize);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
 }\r
 \r
 STATIC PCI_ROOT_BRIDGE mRootBridge;\r
 }\r
 \r
 STATIC PCI_ROOT_BRIDGE mRootBridge;\r
index 0995f4b7a156ea9c38db86f0593d86d31d98a39a..4011336a353ba06c0a84d6e5961e94c001c7517b 100644 (file)
@@ -42,6 +42,7 @@
 [LibraryClasses]\r
   DebugLib\r
   DevicePathLib\r
 [LibraryClasses]\r
   DebugLib\r
   DevicePathLib\r
+  DxeServicesTableLib\r
   MemoryAllocationLib\r
   PciPcdProducerLib\r
 \r
   MemoryAllocationLib\r
   PciPcdProducerLib\r
 \r