]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtPkg/FdtPciPcdProducerLib: Relocate PciPcdProducerLib to OvmfPkg
authorAbner Chang <abner.chang@hpe.com>
Mon, 11 Oct 2021 13:27:00 +0000 (21:27 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 14 Oct 2021 06:25:52 +0000 (06:25 +0000)
Relocate PciPcdProducerLib to OvmfPkg/Fdt, this library is
leverage by both ARM and RISC-V archs.

Add OvmfPkg/Fdt maintainers in Maintainers.txt

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Daniel Schaefer <daniel.schaefer@hpe.com>
Cc: Sunil V L <sunilvl@ventanamicro.com>
Reviewed-by: Daniel Schaefer <daniel.schaefer@hpe.com>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
ArmVirtPkg/ArmVirtCloudHv.dsc
ArmVirtPkg/ArmVirtKvmTool.dsc
ArmVirtPkg/ArmVirtQemu.dsc
ArmVirtPkg/ArmVirtQemuKernel.dsc
ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c [deleted file]
ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf [deleted file]
Maintainers.txt
OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c [new file with mode: 0644]
OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf [new file with mode: 0644]

index a6ceef6faf38bd4b2f571cc36dcc52ff05c1af5f..9ad88e981b42f7453e81eda7990af5dc59024961 100644 (file)
@@ -49,7 +49,7 @@
   FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf\r
   QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf\r
   FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf\r
-  PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+  PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf\r
   PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf\r
   PciHostBridgeUtilityLib|ArmVirtPkg/Library/ArmVirtPciHostBridgeUtilityLib/ArmVirtPciHostBridgeUtilityLib.inf\r
   #\r
   ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   }\r
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf\r
   MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   }\r
   OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf\r
   OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf\r
   MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf\r
   ArmVirtPkg/CloudHvAcpiPlatformDxe/CloudHvAcpiPlatformDxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   }\r
index ff7050954271cdd931588f9b025cdefaa32d3c3a..3cc182545c52c5096d0b9e31a2b1b78a80a20c49 100644 (file)
@@ -57,7 +57,7 @@
 \r
   FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf\r
 \r
-  PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+  PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf\r
   PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf\r
   PciHostBridgeUtilityLib|ArmVirtPkg/Library/ArmVirtPciHostBridgeUtilityLib/ArmVirtPciHostBridgeUtilityLib.inf\r
   #\r
   ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
       NULL|ArmVirtPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf\r
   }\r
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
       NULL|ArmVirtPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf\r
   }\r
   MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
       NULL|ArmVirtPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf\r
   }\r
   OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf\r
index f7e5ea8f744c895785c3a40bcf41a1530aa2549a..2f1a3cea05ef180f462f3aa14eaa2ca199d49e56 100644 (file)
@@ -77,7 +77,7 @@
   FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf\r
   QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf\r
   FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf\r
-  PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+  PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf\r
   PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf\r
   PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf\r
   #\r
   ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   }\r
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf\r
   MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   }\r
   OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf\r
   OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf\r
   MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf\r
   OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   }\r
index 146b5731fe04490111c64aaa1421c5808f93e1c3..3a0c3fb4f00cbe2d55e7630bbe82ce5a11662568 100644 (file)
@@ -75,7 +75,7 @@
   FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf\r
   QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf\r
   FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf\r
-  PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+  PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf\r
   PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf\r
   PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf\r
   #\r
   ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   }\r
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf\r
   MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   }\r
   OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf\r
   OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf\r
   MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf\r
   OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf {\r
     <LibraryClasses>\r
-      NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
+      NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf\r
   }\r
diff --git a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c b/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c
deleted file mode 100644 (file)
index 2520101..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/** @file\r
-  FDT client library for consumers of PCI related dynamic PCDs\r
-\r
-  Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
-\r
-  SPDX-License-Identifier: BSD-2-Clause-Patent\r
-\r
-**/\r
-\r
-#include <Uefi.h>\r
-\r
-#include <Library/BaseLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-\r
-#include <Protocol/FdtClient.h>\r
-\r
-//\r
-// We expect the "ranges" property of "pci-host-ecam-generic" to consist of\r
-// records like this.\r
-//\r
-#pragma pack (1)\r
-typedef struct {\r
-  UINT32 Type;\r
-  UINT64 ChildBase;\r
-  UINT64 CpuBase;\r
-  UINT64 Size;\r
-} DTB_PCI_HOST_RANGE_RECORD;\r
-#pragma pack ()\r
-\r
-#define DTB_PCI_HOST_RANGE_RELOCATABLE  BIT31\r
-#define DTB_PCI_HOST_RANGE_PREFETCHABLE BIT30\r
-#define DTB_PCI_HOST_RANGE_ALIASED      BIT29\r
-#define DTB_PCI_HOST_RANGE_MMIO32       BIT25\r
-#define DTB_PCI_HOST_RANGE_MMIO64       (BIT25 | BIT24)\r
-#define DTB_PCI_HOST_RANGE_IO           BIT24\r
-#define DTB_PCI_HOST_RANGE_TYPEMASK     (BIT31 | BIT30 | BIT29 | BIT25 | BIT24)\r
-\r
-STATIC\r
-RETURN_STATUS\r
-GetPciIoTranslation (\r
-  IN  FDT_CLIENT_PROTOCOL *FdtClient,\r
-  IN  INT32               Node,\r
-  OUT UINT64              *IoTranslation\r
-  )\r
-{\r
-  UINT32        RecordIdx;\r
-  CONST VOID    *Prop;\r
-  UINT32        Len;\r
-  EFI_STATUS    Status;\r
-  UINT64        IoBase;\r
-\r
-  //\r
-  // Iterate over "ranges".\r
-  //\r
-  Status = FdtClient->GetNodeProperty (FdtClient, Node, "ranges", &Prop, &Len);\r
-  if (EFI_ERROR (Status) || Len == 0 ||\r
-      Len % sizeof (DTB_PCI_HOST_RANGE_RECORD) != 0) {\r
-    DEBUG ((EFI_D_ERROR, "%a: 'ranges' not found or invalid\n", __FUNCTION__));\r
-    return RETURN_PROTOCOL_ERROR;\r
-  }\r
-\r
-  for (RecordIdx = 0; RecordIdx < Len / sizeof (DTB_PCI_HOST_RANGE_RECORD);\r
-       ++RecordIdx) {\r
-    CONST DTB_PCI_HOST_RANGE_RECORD *Record;\r
-    UINT32                          Type;\r
-\r
-    Record = (CONST DTB_PCI_HOST_RANGE_RECORD *)Prop + RecordIdx;\r
-    Type = SwapBytes32 (Record->Type) & DTB_PCI_HOST_RANGE_TYPEMASK;\r
-    if (Type == DTB_PCI_HOST_RANGE_IO) {\r
-      IoBase = SwapBytes64 (Record->ChildBase);\r
-      *IoTranslation = SwapBytes64 (Record->CpuBase) - IoBase;\r
-\r
-      return RETURN_SUCCESS;\r
-    }\r
-  }\r
-  return RETURN_NOT_FOUND;\r
-}\r
-\r
-RETURN_STATUS\r
-EFIAPI\r
-FdtPciPcdProducerLibConstructor (\r
-  VOID\r
-  )\r
-{\r
-  UINT64              PciExpressBaseAddress;\r
-  FDT_CLIENT_PROTOCOL *FdtClient;\r
-  CONST UINT64        *Reg;\r
-  UINT32              RegSize;\r
-  EFI_STATUS          Status;\r
-  INT32               Node;\r
-  RETURN_STATUS       RetStatus;\r
-  UINT64              IoTranslation;\r
-  RETURN_STATUS       PcdStatus;\r
-\r
-  PciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress);\r
-  if (PciExpressBaseAddress != MAX_UINT64) {\r
-    //\r
-    // Assume that the fact that PciExpressBaseAddress has been changed from\r
-    // its default value of MAX_UINT64 implies that this code has been\r
-    // executed already, in the context of another module. That means we can\r
-    // assume that PcdPciIoTranslation has been discovered from the DT node\r
-    // as well.\r
-    //\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r
-                  (VOID **)&FdtClient);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  PciExpressBaseAddress = 0;\r
-  Status = FdtClient->FindCompatibleNode (FdtClient, "pci-host-ecam-generic",\r
-                        &Node);\r
-\r
-  if (!EFI_ERROR (Status)) {\r
-    Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",\r
-                          (CONST VOID **)&Reg, &RegSize);\r
-\r
-    if (!EFI_ERROR (Status) && RegSize == 2 * sizeof (UINT64)) {\r
-      PciExpressBaseAddress = SwapBytes64 (*Reg);\r
-\r
-      PcdStatus = PcdSetBoolS (PcdPciDisableBusEnumeration, FALSE);\r
-      ASSERT_RETURN_ERROR (PcdStatus);\r
-\r
-      IoTranslation = 0;\r
-      RetStatus = GetPciIoTranslation (FdtClient, Node, &IoTranslation);\r
-      if (!RETURN_ERROR (RetStatus)) {\r
-          PcdStatus = PcdSet64S (PcdPciIoTranslation, IoTranslation);\r
-          ASSERT_RETURN_ERROR (PcdStatus);\r
-      } else {\r
-        //\r
-        // Support for I/O BARs is not mandatory, and so it does not make sense\r
-        // to abort in the general case. So leave it up to the actual driver to\r
-        // complain about this if it wants to, and just issue a warning here.\r
-        //\r
-        DEBUG ((EFI_D_WARN,\r
-          "%a: 'pci-host-ecam-generic' device encountered with no I/O range\n",\r
-          __FUNCTION__));\r
-      }\r
-    }\r
-  }\r
-\r
-  PcdStatus = PcdSet64S (PcdPciExpressBaseAddress, PciExpressBaseAddress);\r
-  ASSERT_RETURN_ERROR (PcdStatus);\r
-\r
-  return RETURN_SUCCESS;\r
-}\r
diff --git a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf b/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
deleted file mode 100644 (file)
index 1dfe779..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-#/** @file\r
-#  FDT client library for consumers of PCI related dynamic PCDs\r
-#\r
-#  Copyright (c) 2016, Linaro Ltd. All rights reserved.\r
-#\r
-#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
-#\r
-#**/\r
-\r
-[Defines]\r
-  INF_VERSION                    = 0x00010005\r
-  BASE_NAME                      = FdtPciPcdProducerLib\r
-  FILE_GUID                      = D584275B-BF1E-4DF8-A53D-980F5645C5E7\r
-  MODULE_TYPE                    = BASE\r
-  VERSION_STRING                 = 1.0\r
-  LIBRARY_CLASS                  = PciPcdProducerLib|DXE_DRIVER UEFI_DRIVER\r
-  CONSTRUCTOR                    = FdtPciPcdProducerLibConstructor\r
-\r
-[Sources]\r
-  FdtPciPcdProducerLib.c\r
-\r
-[Packages]\r
-  ArmPkg/ArmPkg.dec\r
-  ArmVirtPkg/ArmVirtPkg.dec\r
-  EmbeddedPkg/EmbeddedPkg.dec\r
-  MdeModulePkg/MdeModulePkg.dec\r
-  MdePkg/MdePkg.dec\r
-\r
-[LibraryClasses]\r
-  BaseLib\r
-  DebugLib\r
-  PcdLib\r
-  UefiBootServicesTableLib\r
-\r
-[Protocols]\r
-  gFdtClientProtocolGuid                                      ## CONSUMES\r
-\r
-[Pcd]\r
-  gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation                ## PRODUCES\r
-  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress           ## PRODUCES\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration  ## PRODUCES\r
-\r
-[Depex]\r
-  gFdtClientProtocolGuid\r
index 52f9aa99ac7df79aa47cecff15d99938e6f03824..71c42bddae697b2473f851983085e5436666feb6 100644 (file)
@@ -469,6 +469,12 @@ R: Jiewen Yao <jiewen.yao@intel.com> [jyao1]
 R: Min Xu <min.m.xu@intel.com> [mxu9]\r
 R: Tom Lendacky <thomas.lendacky@amd.com> [tlendacky]\r
 \r
+OvmfPkg: FDT related modules\r
+F: OvmfPkg/Fdt\r
+R: Leif Lindholm <leif@nuviainc.com>\r
+R: Gerd Hoffmann <kraxel@redhat.com>\r
+R: Abner Chang <abner.chang@hpe.com>\r
+\r
 OvmfPkg: LsiScsi driver\r
 F: OvmfPkg/LsiScsiDxe/\r
 R: Gary Lin <glin@suse.com>\r
diff --git a/OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c b/OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c
new file mode 100644 (file)
index 0000000..2520101
--- /dev/null
@@ -0,0 +1,149 @@
+/** @file\r
+  FDT client library for consumers of PCI related dynamic PCDs\r
+\r
+  Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#include <Protocol/FdtClient.h>\r
+\r
+//\r
+// We expect the "ranges" property of "pci-host-ecam-generic" to consist of\r
+// records like this.\r
+//\r
+#pragma pack (1)\r
+typedef struct {\r
+  UINT32 Type;\r
+  UINT64 ChildBase;\r
+  UINT64 CpuBase;\r
+  UINT64 Size;\r
+} DTB_PCI_HOST_RANGE_RECORD;\r
+#pragma pack ()\r
+\r
+#define DTB_PCI_HOST_RANGE_RELOCATABLE  BIT31\r
+#define DTB_PCI_HOST_RANGE_PREFETCHABLE BIT30\r
+#define DTB_PCI_HOST_RANGE_ALIASED      BIT29\r
+#define DTB_PCI_HOST_RANGE_MMIO32       BIT25\r
+#define DTB_PCI_HOST_RANGE_MMIO64       (BIT25 | BIT24)\r
+#define DTB_PCI_HOST_RANGE_IO           BIT24\r
+#define DTB_PCI_HOST_RANGE_TYPEMASK     (BIT31 | BIT30 | BIT29 | BIT25 | BIT24)\r
+\r
+STATIC\r
+RETURN_STATUS\r
+GetPciIoTranslation (\r
+  IN  FDT_CLIENT_PROTOCOL *FdtClient,\r
+  IN  INT32               Node,\r
+  OUT UINT64              *IoTranslation\r
+  )\r
+{\r
+  UINT32        RecordIdx;\r
+  CONST VOID    *Prop;\r
+  UINT32        Len;\r
+  EFI_STATUS    Status;\r
+  UINT64        IoBase;\r
+\r
+  //\r
+  // Iterate over "ranges".\r
+  //\r
+  Status = FdtClient->GetNodeProperty (FdtClient, Node, "ranges", &Prop, &Len);\r
+  if (EFI_ERROR (Status) || Len == 0 ||\r
+      Len % sizeof (DTB_PCI_HOST_RANGE_RECORD) != 0) {\r
+    DEBUG ((EFI_D_ERROR, "%a: 'ranges' not found or invalid\n", __FUNCTION__));\r
+    return RETURN_PROTOCOL_ERROR;\r
+  }\r
+\r
+  for (RecordIdx = 0; RecordIdx < Len / sizeof (DTB_PCI_HOST_RANGE_RECORD);\r
+       ++RecordIdx) {\r
+    CONST DTB_PCI_HOST_RANGE_RECORD *Record;\r
+    UINT32                          Type;\r
+\r
+    Record = (CONST DTB_PCI_HOST_RANGE_RECORD *)Prop + RecordIdx;\r
+    Type = SwapBytes32 (Record->Type) & DTB_PCI_HOST_RANGE_TYPEMASK;\r
+    if (Type == DTB_PCI_HOST_RANGE_IO) {\r
+      IoBase = SwapBytes64 (Record->ChildBase);\r
+      *IoTranslation = SwapBytes64 (Record->CpuBase) - IoBase;\r
+\r
+      return RETURN_SUCCESS;\r
+    }\r
+  }\r
+  return RETURN_NOT_FOUND;\r
+}\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+FdtPciPcdProducerLibConstructor (\r
+  VOID\r
+  )\r
+{\r
+  UINT64              PciExpressBaseAddress;\r
+  FDT_CLIENT_PROTOCOL *FdtClient;\r
+  CONST UINT64        *Reg;\r
+  UINT32              RegSize;\r
+  EFI_STATUS          Status;\r
+  INT32               Node;\r
+  RETURN_STATUS       RetStatus;\r
+  UINT64              IoTranslation;\r
+  RETURN_STATUS       PcdStatus;\r
+\r
+  PciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress);\r
+  if (PciExpressBaseAddress != MAX_UINT64) {\r
+    //\r
+    // Assume that the fact that PciExpressBaseAddress has been changed from\r
+    // its default value of MAX_UINT64 implies that this code has been\r
+    // executed already, in the context of another module. That means we can\r
+    // assume that PcdPciIoTranslation has been discovered from the DT node\r
+    // as well.\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r
+                  (VOID **)&FdtClient);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  PciExpressBaseAddress = 0;\r
+  Status = FdtClient->FindCompatibleNode (FdtClient, "pci-host-ecam-generic",\r
+                        &Node);\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",\r
+                          (CONST VOID **)&Reg, &RegSize);\r
+\r
+    if (!EFI_ERROR (Status) && RegSize == 2 * sizeof (UINT64)) {\r
+      PciExpressBaseAddress = SwapBytes64 (*Reg);\r
+\r
+      PcdStatus = PcdSetBoolS (PcdPciDisableBusEnumeration, FALSE);\r
+      ASSERT_RETURN_ERROR (PcdStatus);\r
+\r
+      IoTranslation = 0;\r
+      RetStatus = GetPciIoTranslation (FdtClient, Node, &IoTranslation);\r
+      if (!RETURN_ERROR (RetStatus)) {\r
+          PcdStatus = PcdSet64S (PcdPciIoTranslation, IoTranslation);\r
+          ASSERT_RETURN_ERROR (PcdStatus);\r
+      } else {\r
+        //\r
+        // Support for I/O BARs is not mandatory, and so it does not make sense\r
+        // to abort in the general case. So leave it up to the actual driver to\r
+        // complain about this if it wants to, and just issue a warning here.\r
+        //\r
+        DEBUG ((EFI_D_WARN,\r
+          "%a: 'pci-host-ecam-generic' device encountered with no I/O range\n",\r
+          __FUNCTION__));\r
+      }\r
+    }\r
+  }\r
+\r
+  PcdStatus = PcdSet64S (PcdPciExpressBaseAddress, PciExpressBaseAddress);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
diff --git a/OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf b/OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
new file mode 100644 (file)
index 0000000..0f51566
--- /dev/null
@@ -0,0 +1,42 @@
+#/** @file\r
+#  FDT client library for consumers of PCI related dynamic PCDs\r
+#\r
+#  Copyright (c) 2016, Linaro Ltd. All rights reserved.\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = FdtPciPcdProducerLib\r
+  FILE_GUID                      = D584275B-BF1E-4DF8-A53D-980F5645C5E7\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PciPcdProducerLib|DXE_DRIVER UEFI_DRIVER\r
+  CONSTRUCTOR                    = FdtPciPcdProducerLibConstructor\r
+\r
+[Sources]\r
+  FdtPciPcdProducerLib.c\r
+\r
+[Packages]\r
+  EmbeddedPkg/EmbeddedPkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  BaseLib\r
+  DebugLib\r
+  PcdLib\r
+  UefiBootServicesTableLib\r
+\r
+[Protocols]\r
+  gFdtClientProtocolGuid                                      ## CONSUMES\r
+\r
+[Pcd]\r
+  gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation                ## PRODUCES\r
+  gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress           ## PRODUCES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration  ## PRODUCES\r
+\r
+[Depex]\r
+  gFdtClientProtocolGuid\r