diff mbox

[edk2,2/3] ArmVirtPkg/FdtPciPcdProducerLib: add discovery of PcdPciMmio64Size

Message ID 1473674479-20207-3-git-send-email-ard.biesheuvel@linaro.org
State New
Headers show

Commit Message

Ard Biesheuvel Sept. 12, 2016, 10:01 a.m. UTC
In preparation of adding IncompatibleDeviceSupportDxe to ArmVirtQemu,
in order to lure the PCI code into allocating all 64-bit BARs in the
64-bit region, update FdtPciPcdProducerLib so it sets the PcdPciMmio64Size
based on the DT description of the PCIe root complex.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 ArmVirtPkg/ArmVirtQemu.dsc                                       |  1 +
 ArmVirtPkg/ArmVirtQemuKernel.dsc                                 |  1 +
 ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c   | 31 ++++++++++++--------
 ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf |  1 +
 4 files changed, 21 insertions(+), 13 deletions(-)

-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox

Patch

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index a3beb4654072..fa2b547ac486 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -206,6 +206,7 @@  [PcdsDynamicDefault.common]
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xFFFFFFFFFFFFFFFF
 
   gArmTokenSpaceGuid.PcdPciIoTranslation|0x0
+  gArmTokenSpaceGuid.PcdPciMmio64Size|0x0
 
   #
   # Set video resolution for boot options and for text setup.
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index e0dcf4300338..d80079c45c28 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -202,6 +202,7 @@  [PcdsDynamicDefault.common]
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0xFFFFFFFFFFFFFFFF
 
   gArmTokenSpaceGuid.PcdPciIoTranslation|0x0
+  gArmTokenSpaceGuid.PcdPciMmio64Size|0x0
 
   #
   # Set video resolution for boot options and for text setup.
diff --git a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c b/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c
index ea27cda7b77c..ea35c6df2546 100644
--- a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c
+++ b/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c
@@ -44,11 +44,12 @@  typedef struct {
 #define DTB_PCI_HOST_RANGE_TYPEMASK     (BIT31 | BIT30 | BIT29 | BIT25 | BIT24)
 
 STATIC
-RETURN_STATUS
-GetPciIoTranslation (
+VOID
+GetPciIoTranslationAndMmio64Size (
   IN  FDT_CLIENT_PROTOCOL *FdtClient,
   IN  INT32               Node,
-  OUT UINT64              *IoTranslation
+  OUT UINT64              *IoTranslation,
+  OUT UINT64              *Mmio64Size
   )
 {
   UINT32        RecordIdx;
@@ -64,24 +65,25 @@  GetPciIoTranslation (
   if (EFI_ERROR (Status) || Len == 0 ||
       Len % sizeof (DTB_PCI_HOST_RANGE_RECORD) != 0) {
     DEBUG ((EFI_D_ERROR, "%a: 'ranges' not found or invalid\n", __FUNCTION__));
-    return RETURN_PROTOCOL_ERROR;
+    return;
   }
 
   for (RecordIdx = 0; RecordIdx < Len / sizeof (DTB_PCI_HOST_RANGE_RECORD);
        ++RecordIdx) {
     CONST DTB_PCI_HOST_RANGE_RECORD *Record;
-    UINT32                          Type;
 
     Record = (CONST DTB_PCI_HOST_RANGE_RECORD *)Prop + RecordIdx;
-    Type = SwapBytes32 (Record->Type) & DTB_PCI_HOST_RANGE_TYPEMASK;
-    if (Type == DTB_PCI_HOST_RANGE_IO) {
+    switch (SwapBytes32 (Record->Type) & DTB_PCI_HOST_RANGE_TYPEMASK) {
+    case DTB_PCI_HOST_RANGE_IO:
       IoBase = SwapBytes64 (Record->ChildBase);
       *IoTranslation = SwapBytes64 (Record->CpuBase) - IoBase;
+      break;
 
-      return RETURN_SUCCESS;
+    case DTB_PCI_HOST_RANGE_MMIO64:
+      *Mmio64Size = SwapBytes64 (Record->Size);
+      break;
     }
   }
-  return RETURN_NOT_FOUND;
 }
 
 RETURN_STATUS
@@ -96,8 +98,8 @@  FdtPciPcdProducerLibConstructor (
   UINT32              RegSize;
   EFI_STATUS          Status;
   INT32               Node;
-  RETURN_STATUS       RetStatus;
   UINT64              IoTranslation;
+  UINT64              Mmio64Size;
 
   PciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress);
   if (PciExpressBaseAddress != MAX_UINT64) {
@@ -128,9 +130,11 @@  FdtPciPcdProducerLibConstructor (
 
       PcdSetBool (PcdPciDisableBusEnumeration, FALSE);
 
-      IoTranslation = 0;
-      RetStatus = GetPciIoTranslation (FdtClient, Node, &IoTranslation);
-      if (!RETURN_ERROR (RetStatus)) {
+      IoTranslation = MAX_UINT64;
+      Mmio64Size = 0;
+      GetPciIoTranslationAndMmio64Size (FdtClient, Node, &IoTranslation,
+        &Mmio64Size);
+      if (IoTranslation != MAX_UINT64) {
           PcdSet64 (PcdPciIoTranslation, IoTranslation);
       } else {
         //
@@ -142,6 +146,7 @@  FdtPciPcdProducerLibConstructor (
           "%a: 'pci-host-ecam-generic' device encountered with no I/O range\n",
           __FUNCTION__));
       }
+      PcdSet64 (PcdPciMmio64Size, Mmio64Size);
     }
   }
 
diff --git a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf b/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
index cd138fa1aa6e..d29bcb0a801b 100644
--- a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
+++ b/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
@@ -42,6 +42,7 @@  [Protocols]
 
 [Pcd]
   gArmTokenSpaceGuid.PcdPciIoTranslation                      ## PRODUCES
+  gArmTokenSpaceGuid.PcdPciMmio64Size                         ## PRODUCES
   gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress           ## PRODUCES
   gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration  ## PRODUCES