]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.c
cc60940d487cb6e3929655fac6f192308d2faf05
[mirror_edk2.git] / ArmVirtPkg / Library / FdtPciPcdProducerLib / FdtPciPcdProducerLib.c
1 /** @file
2 FDT client library for consumers of PCI related dynamic PCDs
3
4 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include <Uefi.h>
17
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/PcdLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22
23 #include <Protocol/FdtClient.h>
24
25 RETURN_STATUS
26 EFIAPI
27 FdtPciPcdProducerLibConstructor (
28 VOID
29 )
30 {
31 UINT64 PciExpressBaseAddress;
32 FDT_CLIENT_PROTOCOL *FdtClient;
33 CONST UINT64 *Reg;
34 UINT32 RegElemSize, RegSize;
35 EFI_STATUS Status;
36
37 PciExpressBaseAddress = PcdGet64 (PcdPciExpressBaseAddress);
38 if (PciExpressBaseAddress != MAX_UINT64) {
39 return EFI_SUCCESS;
40 }
41
42 Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,
43 (VOID **)&FdtClient);
44 ASSERT_EFI_ERROR (Status);
45
46 Status = FdtClient->FindCompatibleNodeReg (FdtClient,
47 "pci-host-ecam-generic", (CONST VOID **)&Reg,
48 &RegElemSize, &RegSize);
49
50 if (EFI_ERROR (Status)) {
51 PciExpressBaseAddress = 0;
52 } else {
53 ASSERT (RegElemSize == sizeof (UINT64));
54 PciExpressBaseAddress = SwapBytes64 (*Reg);
55
56 PcdSetBool (PcdPciDisableBusEnumeration, FALSE);
57 }
58
59 PcdSet64 (PcdPciExpressBaseAddress, PciExpressBaseAddress);
60
61 return RETURN_SUCCESS;
62 }