]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c
ArmVirtPkg: implement FdtPciPcdProducerLib
[mirror_edk2.git] / ArmVirtPkg / Library / FdtPciPcdProducerLib / FdtPciPcdProducerLib.c
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