From 77e9b3a7c68cea4eeb64af85e4f695f278172314 Mon Sep 17 00:00:00 2001 From: Abner Chang Date: Mon, 11 Oct 2021 21:27:00 +0800 Subject: ArmVirtPkg/FdtPciPcdProducerLib: Relocate PciPcdProducerLib to OvmfPkg 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 Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Sami Mujawar Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Daniel Schaefer Cc: Sunil V L Reviewed-by: Daniel Schaefer Reviewed-by: Sunil V L Acked-by: Gerd Hoffmann Cc: Jiewen Yao --- ArmVirtPkg/ArmVirtCloudHv.dsc | 8 +- ArmVirtPkg/ArmVirtKvmTool.dsc | 8 +- ArmVirtPkg/ArmVirtQemu.dsc | 8 +- ArmVirtPkg/ArmVirtQemuKernel.dsc | 8 +- .../FdtPciPcdProducerLib/FdtPciPcdProducerLib.c | 149 --------------------- .../FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf | 44 ------ Maintainers.txt | 6 + .../FdtPciPcdProducerLib/FdtPciPcdProducerLib.c | 149 +++++++++++++++++++++ .../FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf | 42 ++++++ 9 files changed, 213 insertions(+), 209 deletions(-) delete mode 100644 ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c delete mode 100644 ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf create mode 100644 OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c create mode 100644 OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf diff --git a/ArmVirtPkg/ArmVirtCloudHv.dsc b/ArmVirtPkg/ArmVirtCloudHv.dsc index a6ceef6faf..9ad88e981b 100644 --- a/ArmVirtPkg/ArmVirtCloudHv.dsc +++ b/ArmVirtPkg/ArmVirtCloudHv.dsc @@ -49,7 +49,7 @@ FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf - PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf PciHostBridgeUtilityLib|ArmVirtPkg/Library/ArmVirtPciHostBridgeUtilityLib/ArmVirtPciHostBridgeUtilityLib.inf @@ -342,12 +342,12 @@ # ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf @@ -361,5 +361,5 @@ MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf ArmVirtPkg/CloudHvAcpiPlatformDxe/CloudHvAcpiPlatformDxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index ff70509542..3cc182545c 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -57,7 +57,7 @@ FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf - PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf PciHostBridgeUtilityLib|ArmVirtPkg/Library/ArmVirtPciHostBridgeUtilityLib/ArmVirtPciHostBridgeUtilityLib.inf @@ -338,17 +338,17 @@ # ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf NULL|ArmVirtPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf } MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf NULL|ArmVirtPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf } MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf NULL|ArmVirtPkg/Library/BaseCachingPciExpressLib/BaseCachingPciExpressLib.inf } OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index f7e5ea8f74..2f1a3cea05 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -77,7 +77,7 @@ FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf - PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf @@ -489,12 +489,12 @@ # ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf @@ -545,5 +545,5 @@ MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc index 146b5731fe..3a0c3fb4f0 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -75,7 +75,7 @@ FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf - PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + PciPcdProducerLib|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf @@ -424,12 +424,12 @@ # ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf @@ -460,5 +460,5 @@ MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf { - NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf + NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf } diff --git a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c b/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c deleted file mode 100644 index 2520101017..0000000000 --- a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c +++ /dev/null @@ -1,149 +0,0 @@ -/** @file - FDT client library for consumers of PCI related dynamic PCDs - - Copyright (c) 2016, Linaro Ltd. All rights reserved.
- - SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#include - -#include -#include -#include -#include - -#include - -// -// We expect the "ranges" property of "pci-host-ecam-generic" to consist of -// records like this. -// -#pragma pack (1) -typedef struct { - UINT32 Type; - UINT64 ChildBase; - UINT64 CpuBase; - UINT64 Size; -} DTB_PCI_HOST_RANGE_RECORD; -#pragma pack () - -#define DTB_PCI_HOST_RANGE_RELOCATABLE BIT31 -#define DTB_PCI_HOST_RANGE_PREFETCHABLE BIT30 -#define DTB_PCI_HOST_RANGE_ALIASED BIT29 -#define DTB_PCI_HOST_RANGE_MMIO32 BIT25 -#define DTB_PCI_HOST_RANGE_MMIO64 (BIT25 | BIT24) -#define DTB_PCI_HOST_RANGE_IO BIT24 -#define DTB_PCI_HOST_RANGE_TYPEMASK (BIT31 | BIT30 | BIT29 | BIT25 | BIT24) - -STATIC -RETURN_STATUS -GetPciIoTranslation ( - IN FDT_CLIENT_PROTOCOL *FdtClient, - IN INT32 Node, - OUT UINT64 *IoTranslation - ) -{ - UINT32 RecordIdx; - CONST VOID *Prop; - UINT32 Len; - EFI_STATUS Status; - UINT64 IoBase; - - // - // Iterate over "ranges". - // - Status = FdtClient->GetNodeProperty (FdtClient, Node, "ranges", &Prop, &Len); - 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; - } - - 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) { - IoBase = SwapBytes64 (Record->ChildBase); - *IoTranslation = SwapBytes64 (Record->CpuBase) - IoBase; - - return RETURN_SUCCESS; - } - } - return RETURN_NOT_FOUND; -} - -RETURN_STATUS -EFIAPI -FdtPciPcdProducerLibConstructor ( - VOID - ) -{ - UINT64 PciExpressBaseAddress; - FDT_CLIENT_PROTOCOL *FdtClient; - CONST UINT64 *Reg; - UINT32 RegSize; - EFI_STATUS Status; - INT32 Node; - RETURN_STATUS RetStatus; - UINT64 IoTranslation; - RETURN_STATUS PcdStatus; - - PciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress); - if (PciExpressBaseAddress != MAX_UINT64) { - // - // Assume that the fact that PciExpressBaseAddress has been changed from - // its default value of MAX_UINT64 implies that this code has been - // executed already, in the context of another module. That means we can - // assume that PcdPciIoTranslation has been discovered from the DT node - // as well. - // - return EFI_SUCCESS; - } - - Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, - (VOID **)&FdtClient); - ASSERT_EFI_ERROR (Status); - - PciExpressBaseAddress = 0; - Status = FdtClient->FindCompatibleNode (FdtClient, "pci-host-ecam-generic", - &Node); - - if (!EFI_ERROR (Status)) { - Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", - (CONST VOID **)&Reg, &RegSize); - - if (!EFI_ERROR (Status) && RegSize == 2 * sizeof (UINT64)) { - PciExpressBaseAddress = SwapBytes64 (*Reg); - - PcdStatus = PcdSetBoolS (PcdPciDisableBusEnumeration, FALSE); - ASSERT_RETURN_ERROR (PcdStatus); - - IoTranslation = 0; - RetStatus = GetPciIoTranslation (FdtClient, Node, &IoTranslation); - if (!RETURN_ERROR (RetStatus)) { - PcdStatus = PcdSet64S (PcdPciIoTranslation, IoTranslation); - ASSERT_RETURN_ERROR (PcdStatus); - } else { - // - // Support for I/O BARs is not mandatory, and so it does not make sense - // to abort in the general case. So leave it up to the actual driver to - // complain about this if it wants to, and just issue a warning here. - // - DEBUG ((EFI_D_WARN, - "%a: 'pci-host-ecam-generic' device encountered with no I/O range\n", - __FUNCTION__)); - } - } - } - - PcdStatus = PcdSet64S (PcdPciExpressBaseAddress, PciExpressBaseAddress); - ASSERT_RETURN_ERROR (PcdStatus); - - return RETURN_SUCCESS; -} diff --git a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf b/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf deleted file mode 100644 index 1dfe779f6c..0000000000 --- a/ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf +++ /dev/null @@ -1,44 +0,0 @@ -#/** @file -# FDT client library for consumers of PCI related dynamic PCDs -# -# Copyright (c) 2016, Linaro Ltd. All rights reserved. -# -# SPDX-License-Identifier: BSD-2-Clause-Patent -# -#**/ - -[Defines] - INF_VERSION = 0x00010005 - BASE_NAME = FdtPciPcdProducerLib - FILE_GUID = D584275B-BF1E-4DF8-A53D-980F5645C5E7 - MODULE_TYPE = BASE - VERSION_STRING = 1.0 - LIBRARY_CLASS = PciPcdProducerLib|DXE_DRIVER UEFI_DRIVER - CONSTRUCTOR = FdtPciPcdProducerLibConstructor - -[Sources] - FdtPciPcdProducerLib.c - -[Packages] - ArmPkg/ArmPkg.dec - ArmVirtPkg/ArmVirtPkg.dec - EmbeddedPkg/EmbeddedPkg.dec - MdeModulePkg/MdeModulePkg.dec - MdePkg/MdePkg.dec - -[LibraryClasses] - BaseLib - DebugLib - PcdLib - UefiBootServicesTableLib - -[Protocols] - gFdtClientProtocolGuid ## CONSUMES - -[Pcd] - gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation ## PRODUCES - gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## PRODUCES - gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration ## PRODUCES - -[Depex] - gFdtClientProtocolGuid diff --git a/Maintainers.txt b/Maintainers.txt index 52f9aa99ac..71c42bddae 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -469,6 +469,12 @@ R: Jiewen Yao [jyao1] R: Min Xu [mxu9] R: Tom Lendacky [tlendacky] +OvmfPkg: FDT related modules +F: OvmfPkg/Fdt +R: Leif Lindholm +R: Gerd Hoffmann +R: Abner Chang + OvmfPkg: LsiScsi driver F: OvmfPkg/LsiScsiDxe/ R: Gary Lin diff --git a/OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c b/OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c new file mode 100644 index 0000000000..2520101017 --- /dev/null +++ b/OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c @@ -0,0 +1,149 @@ +/** @file + FDT client library for consumers of PCI related dynamic PCDs + + Copyright (c) 2016, Linaro Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include + +#include + +// +// We expect the "ranges" property of "pci-host-ecam-generic" to consist of +// records like this. +// +#pragma pack (1) +typedef struct { + UINT32 Type; + UINT64 ChildBase; + UINT64 CpuBase; + UINT64 Size; +} DTB_PCI_HOST_RANGE_RECORD; +#pragma pack () + +#define DTB_PCI_HOST_RANGE_RELOCATABLE BIT31 +#define DTB_PCI_HOST_RANGE_PREFETCHABLE BIT30 +#define DTB_PCI_HOST_RANGE_ALIASED BIT29 +#define DTB_PCI_HOST_RANGE_MMIO32 BIT25 +#define DTB_PCI_HOST_RANGE_MMIO64 (BIT25 | BIT24) +#define DTB_PCI_HOST_RANGE_IO BIT24 +#define DTB_PCI_HOST_RANGE_TYPEMASK (BIT31 | BIT30 | BIT29 | BIT25 | BIT24) + +STATIC +RETURN_STATUS +GetPciIoTranslation ( + IN FDT_CLIENT_PROTOCOL *FdtClient, + IN INT32 Node, + OUT UINT64 *IoTranslation + ) +{ + UINT32 RecordIdx; + CONST VOID *Prop; + UINT32 Len; + EFI_STATUS Status; + UINT64 IoBase; + + // + // Iterate over "ranges". + // + Status = FdtClient->GetNodeProperty (FdtClient, Node, "ranges", &Prop, &Len); + 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; + } + + 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) { + IoBase = SwapBytes64 (Record->ChildBase); + *IoTranslation = SwapBytes64 (Record->CpuBase) - IoBase; + + return RETURN_SUCCESS; + } + } + return RETURN_NOT_FOUND; +} + +RETURN_STATUS +EFIAPI +FdtPciPcdProducerLibConstructor ( + VOID + ) +{ + UINT64 PciExpressBaseAddress; + FDT_CLIENT_PROTOCOL *FdtClient; + CONST UINT64 *Reg; + UINT32 RegSize; + EFI_STATUS Status; + INT32 Node; + RETURN_STATUS RetStatus; + UINT64 IoTranslation; + RETURN_STATUS PcdStatus; + + PciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress); + if (PciExpressBaseAddress != MAX_UINT64) { + // + // Assume that the fact that PciExpressBaseAddress has been changed from + // its default value of MAX_UINT64 implies that this code has been + // executed already, in the context of another module. That means we can + // assume that PcdPciIoTranslation has been discovered from the DT node + // as well. + // + return EFI_SUCCESS; + } + + Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL, + (VOID **)&FdtClient); + ASSERT_EFI_ERROR (Status); + + PciExpressBaseAddress = 0; + Status = FdtClient->FindCompatibleNode (FdtClient, "pci-host-ecam-generic", + &Node); + + if (!EFI_ERROR (Status)) { + Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", + (CONST VOID **)&Reg, &RegSize); + + if (!EFI_ERROR (Status) && RegSize == 2 * sizeof (UINT64)) { + PciExpressBaseAddress = SwapBytes64 (*Reg); + + PcdStatus = PcdSetBoolS (PcdPciDisableBusEnumeration, FALSE); + ASSERT_RETURN_ERROR (PcdStatus); + + IoTranslation = 0; + RetStatus = GetPciIoTranslation (FdtClient, Node, &IoTranslation); + if (!RETURN_ERROR (RetStatus)) { + PcdStatus = PcdSet64S (PcdPciIoTranslation, IoTranslation); + ASSERT_RETURN_ERROR (PcdStatus); + } else { + // + // Support for I/O BARs is not mandatory, and so it does not make sense + // to abort in the general case. So leave it up to the actual driver to + // complain about this if it wants to, and just issue a warning here. + // + DEBUG ((EFI_D_WARN, + "%a: 'pci-host-ecam-generic' device encountered with no I/O range\n", + __FUNCTION__)); + } + } + } + + PcdStatus = PcdSet64S (PcdPciExpressBaseAddress, PciExpressBaseAddress); + ASSERT_RETURN_ERROR (PcdStatus); + + return RETURN_SUCCESS; +} diff --git a/OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf b/OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf new file mode 100644 index 0000000000..0f5156615b --- /dev/null +++ b/OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf @@ -0,0 +1,42 @@ +#/** @file +# FDT client library for consumers of PCI related dynamic PCDs +# +# Copyright (c) 2016, Linaro Ltd. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = FdtPciPcdProducerLib + FILE_GUID = D584275B-BF1E-4DF8-A53D-980F5645C5E7 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = PciPcdProducerLib|DXE_DRIVER UEFI_DRIVER + CONSTRUCTOR = FdtPciPcdProducerLibConstructor + +[Sources] + FdtPciPcdProducerLib.c + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PcdLib + UefiBootServicesTableLib + +[Protocols] + gFdtClientProtocolGuid ## CONSUMES + +[Pcd] + gEfiMdePkgTokenSpaceGuid.PcdPciIoTranslation ## PRODUCES + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## PRODUCES + gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration ## PRODUCES + +[Depex] + gFdtClientProtocolGuid -- cgit v1.2.3