public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, lersek@redhat.com
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH 2/3] ArmVirtPkg/FdtPciPcdProducerLib: add discovery of PcdPciMmio64Size
Date: Mon, 12 Sep 2016 11:01:18 +0100	[thread overview]
Message-ID: <1473674479-20207-3-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1473674479-20207-1-git-send-email-ard.biesheuvel@linaro.org>

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(-)

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
 
-- 
2.7.4



  parent reply	other threads:[~2016-09-12 10:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-12 10:01 [PATCH 0/3] ArmPkg ArmVirtPkg: prevent 64-bit MMIO BAR degradation Ard Biesheuvel
2016-09-12 10:01 ` [PATCH 1/3] ArmPkg: add driver to force 64-bit MMIO BARs to be allocated above 4 GB Ard Biesheuvel
2016-09-12 10:23   ` Leif Lindholm
2016-09-12 12:29     ` Laszlo Ersek
2016-09-12 13:06       ` Ard Biesheuvel
2016-09-12 10:01 ` Ard Biesheuvel [this message]
2016-09-12 10:01 ` [PATCH 3/3] ArmVirtPkg/ArmVirtQemu: add IncompatiblePciDeviceSupportDxe Ard Biesheuvel
2016-09-12 11:57 ` [PATCH 0/3] ArmPkg ArmVirtPkg: prevent 64-bit MMIO BAR degradation Laszlo Ersek
2016-09-26 12:54   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1473674479-20207-3-git-send-email-ard.biesheuvel@linaro.org \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox