]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c
ArmPkg ArmPlatformPkg ArmVirtPkg: ARM GICv2/v3 Base Address width fix-up
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtGicArchLib / ArmVirtGicArchLib.c
1 /** @file
2 ArmGicArchLib library class implementation for DT based virt platforms
3
4 Copyright (c) 2015 - 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 <Base.h>
17 #include <Uefi.h>
18
19 #include <Library/ArmGicLib.h>
20 #include <Library/ArmGicArchLib.h>
21 #include <Library/BaseLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/PcdLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
25
26 #include <Protocol/FdtClient.h>
27
28 STATIC ARM_GIC_ARCH_REVISION mGicArchRevision;
29
30 RETURN_STATUS
31 EFIAPI
32 ArmVirtGicArchLibConstructor (
33 VOID
34 )
35 {
36 UINT32 IccSre;
37 FDT_CLIENT_PROTOCOL *FdtClient;
38 CONST UINT64 *Reg;
39 UINT32 RegElemSize, RegSize;
40 UINTN GicRevision;
41 EFI_STATUS Status;
42 UINT64 DistBase, CpuBase, RedistBase;
43
44 Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,
45 (VOID **)&FdtClient);
46 ASSERT_EFI_ERROR (Status);
47
48 GicRevision = 2;
49 Status = FdtClient->FindCompatibleNodeReg (FdtClient, "arm,cortex-a15-gic",
50 (CONST VOID **)&Reg, &RegElemSize, &RegSize);
51 if (Status == EFI_NOT_FOUND) {
52 GicRevision = 3;
53 Status = FdtClient->FindCompatibleNodeReg (FdtClient, "arm,gic-v3",
54 (CONST VOID **)&Reg, &RegElemSize, &RegSize);
55 }
56 if (EFI_ERROR (Status)) {
57 return Status;
58 }
59
60 switch (GicRevision) {
61
62 case 3:
63 //
64 // The GIC v3 DT binding describes a series of at least 3 physical (base
65 // addresses, size) pairs: the distributor interface (GICD), at least one
66 // redistributor region (GICR) containing dedicated redistributor
67 // interfaces for all individual CPUs, and the CPU interface (GICC).
68 // Under virtualization, we assume that the first redistributor region
69 // listed covers the boot CPU. Also, our GICv3 driver only supports the
70 // system register CPU interface, so we can safely ignore the MMIO version
71 // which is listed after the sequence of redistributor interfaces.
72 // This means we are only interested in the first two memory regions
73 // supplied, and ignore everything else.
74 //
75 ASSERT (RegSize >= 32);
76
77 // RegProp[0..1] == { GICD base, GICD size }
78 DistBase = SwapBytes64 (Reg[0]);
79 ASSERT (DistBase < MAX_UINT32);
80
81 // RegProp[2..3] == { GICR base, GICR size }
82 RedistBase = SwapBytes64 (Reg[2]);
83 ASSERT (RedistBase < MAX_UINT32);
84
85 PcdSet64 (PcdGicDistributorBase, DistBase);
86 PcdSet64 (PcdGicRedistributorsBase, RedistBase);
87
88 DEBUG ((EFI_D_INFO, "Found GIC v3 (re)distributor @ 0x%Lx (0x%Lx)\n",
89 DistBase, RedistBase));
90
91 //
92 // The default implementation of ArmGicArchLib is responsible for enabling
93 // the system register interface on the GICv3 if one is found. So let's do
94 // the same here.
95 //
96 IccSre = ArmGicV3GetControlSystemRegisterEnable ();
97 if (!(IccSre & ICC_SRE_EL2_SRE)) {
98 ArmGicV3SetControlSystemRegisterEnable (IccSre | ICC_SRE_EL2_SRE);
99 IccSre = ArmGicV3GetControlSystemRegisterEnable ();
100 }
101
102 //
103 // Unlike the default implementation, there is no fall through to GICv2
104 // mode if this GICv3 cannot be driven in native mode due to the fact
105 // that the System Register interface is unavailable.
106 //
107 ASSERT (IccSre & ICC_SRE_EL2_SRE);
108
109 mGicArchRevision = ARM_GIC_ARCH_REVISION_3;
110 break;
111
112 case 2:
113 ASSERT (RegSize == 32);
114
115 DistBase = SwapBytes64 (Reg[0]);
116 CpuBase = SwapBytes64 (Reg[2]);
117 ASSERT (DistBase < MAX_UINT32);
118 ASSERT (CpuBase < MAX_UINT32);
119
120 PcdSet64 (PcdGicDistributorBase, DistBase);
121 PcdSet64 (PcdGicInterruptInterfaceBase, CpuBase);
122
123 DEBUG ((EFI_D_INFO, "Found GIC @ 0x%Lx/0x%Lx\n", DistBase, CpuBase));
124
125 mGicArchRevision = ARM_GIC_ARCH_REVISION_2;
126 break;
127
128 default:
129 DEBUG ((EFI_D_ERROR, "%a: No GIC revision specified!\n", __FUNCTION__));
130 return RETURN_NOT_FOUND;
131 }
132 return RETURN_SUCCESS;
133 }
134
135 ARM_GIC_ARCH_REVISION
136 EFIAPI
137 ArmGicGetSupportedArchRevision (
138 VOID
139 )
140 {
141 return mGicArchRevision;
142 }