]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmVirtPkg: implement FdtPciPcdProducerLib
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 12 Apr 2016 12:21:03 +0000 (14:21 +0200)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 12 Apr 2016 14:26:46 +0000 (16:26 +0200)
This implements a library FdtPciPcdProducerLib which is intended to
be incorporated into modules that consume the PCI related dynamic PCDs
PcdPciExpressBaseAddress and PcdPciDisableBusEnumeration, either via NULL
library class resolution or via a direct dependency (for other libraries
or modules in ArmVirtPkg). This allows us to make them depend on the FDT
client protocol, and populate these PCDs based on the presence and the
contents of a 'pci-host-ecam-generic' DT node.

This also overloads the meaning of PcdPciExpressBaseAddress, which we will
set to MAX_UINT64 to signify that the actual values of these two PCDs have
not been assigned yet.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c [new file with mode: 0644]
ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf [new file with mode: 0644]

diff --git a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c b/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c
new file mode 100644 (file)
index 0000000..cc60940
--- /dev/null
@@ -0,0 +1,62 @@
+/** @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
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\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
+RETURN_STATUS\r
+EFIAPI\r
+FdtPciPcdProducerLibConstructor (\r
+  VOID\r
+  )\r
+{\r
+  UINT64              PciExpressBaseAddress;\r
+  FDT_CLIENT_PROTOCOL *FdtClient;\r
+  CONST UINT64        *Reg;\r
+  UINT32              RegElemSize, RegSize;\r
+  EFI_STATUS          Status;\r
+\r
+  PciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress);\r
+  if (PciExpressBaseAddress != MAX_UINT64) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r
+                  (VOID **)&FdtClient);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = FdtClient->FindCompatibleNodeReg (FdtClient,\r
+                        "pci-host-ecam-generic", (CONST VOID **)&Reg,\r
+                        &RegElemSize, &RegSize);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    PciExpressBaseAddress = 0;\r
+  } else {\r
+    ASSERT (RegElemSize == sizeof (UINT64));\r
+    PciExpressBaseAddress = SwapBytes64 (*Reg);\r
+\r
+    PcdSetBool (PcdPciDisableBusEnumeration, FALSE);\r
+  }\r
+\r
+  PcdSet64 (PcdPciExpressBaseAddress, PciExpressBaseAddress);\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
diff --git a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf b/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
new file mode 100644 (file)
index 0000000..1ba71ab
--- /dev/null
@@ -0,0 +1,47 @@
+#/** @file\r
+#  FDT client library for consumers of PCI related dynamic PCDs\r
+#\r
+#  Copyright (c) 2016, Linaro Ltd. All rights reserved.\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\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
+  ArmVirtPkg/ArmVirtPkg.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.PcdPciExpressBaseAddress           ## PRODUCES\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration  ## PRODUCES\r
+\r
+[Depex]\r
+  gFdtClientProtocolGuid\r