]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/ArmVirtGicArchLib/ArmVirtGicArchLib.c
ArmVirtPkg: Change use of EFI_D_* to DEBUG_*
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtGicArchLib / ArmVirtGicArchLib.c
CommitLineData
15c9b25e
AB
1/** @file\r
2 ArmGicArchLib library class implementation for DT based virt platforms\r
3\r
22486318 4 Copyright (c) 2015 - 2016, Linaro Ltd. All rights reserved.<BR>\r
15c9b25e 5\r
9792fb0e 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
15c9b25e
AB
7\r
8**/\r
9\r
10#include <Base.h>\r
22486318 11#include <Uefi.h>\r
15c9b25e
AB
12\r
13#include <Library/ArmGicLib.h>\r
14#include <Library/ArmGicArchLib.h>\r
22486318 15#include <Library/BaseLib.h>\r
15c9b25e 16#include <Library/DebugLib.h>\r
22486318
AB
17#include <Library/PcdLib.h>\r
18#include <Library/UefiBootServicesTableLib.h>\r
19\r
20#include <Protocol/FdtClient.h>\r
15c9b25e
AB
21\r
22STATIC ARM_GIC_ARCH_REVISION mGicArchRevision;\r
23\r
24RETURN_STATUS\r
25EFIAPI\r
26ArmVirtGicArchLibConstructor (\r
27 VOID\r
28 )\r
29{\r
22486318
AB
30 UINT32 IccSre;\r
31 FDT_CLIENT_PROTOCOL *FdtClient;\r
32 CONST UINT64 *Reg;\r
cfc8d51c
AB
33 UINT32 RegSize;\r
34 UINTN AddressCells, SizeCells;\r
22486318
AB
35 UINTN GicRevision;\r
36 EFI_STATUS Status;\r
37 UINT64 DistBase, CpuBase, RedistBase;\r
65ebe6e6 38 RETURN_STATUS PcdStatus;\r
15c9b25e 39\r
22486318
AB
40 Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r
41 (VOID **)&FdtClient);\r
42 ASSERT_EFI_ERROR (Status);\r
43\r
44 GicRevision = 2;\r
45 Status = FdtClient->FindCompatibleNodeReg (FdtClient, "arm,cortex-a15-gic",\r
cfc8d51c
AB
46 (CONST VOID **)&Reg, &AddressCells, &SizeCells,\r
47 &RegSize);\r
22486318
AB
48 if (Status == EFI_NOT_FOUND) {\r
49 GicRevision = 3;\r
50 Status = FdtClient->FindCompatibleNodeReg (FdtClient, "arm,gic-v3",\r
cfc8d51c
AB
51 (CONST VOID **)&Reg, &AddressCells, &SizeCells,\r
52 &RegSize);\r
22486318
AB
53 }\r
54 if (EFI_ERROR (Status)) {\r
55 return Status;\r
56 }\r
57\r
58 switch (GicRevision) {\r
15c9b25e
AB
59\r
60 case 3:\r
22486318
AB
61 //\r
62 // The GIC v3 DT binding describes a series of at least 3 physical (base\r
63 // addresses, size) pairs: the distributor interface (GICD), at least one\r
64 // redistributor region (GICR) containing dedicated redistributor\r
65 // interfaces for all individual CPUs, and the CPU interface (GICC).\r
66 // Under virtualization, we assume that the first redistributor region\r
67 // listed covers the boot CPU. Also, our GICv3 driver only supports the\r
68 // system register CPU interface, so we can safely ignore the MMIO version\r
69 // which is listed after the sequence of redistributor interfaces.\r
70 // This means we are only interested in the first two memory regions\r
71 // supplied, and ignore everything else.\r
72 //\r
73 ASSERT (RegSize >= 32);\r
74\r
75 // RegProp[0..1] == { GICD base, GICD size }\r
76 DistBase = SwapBytes64 (Reg[0]);\r
041e842a 77 ASSERT (DistBase < MAX_UINTN);\r
22486318
AB
78\r
79 // RegProp[2..3] == { GICR base, GICR size }\r
80 RedistBase = SwapBytes64 (Reg[2]);\r
041e842a 81 ASSERT (RedistBase < MAX_UINTN);\r
22486318 82\r
65ebe6e6
LE
83 PcdStatus = PcdSet64S (PcdGicDistributorBase, DistBase);\r
84 ASSERT_RETURN_ERROR (PcdStatus);\r
85 PcdStatus = PcdSet64S (PcdGicRedistributorsBase, RedistBase);\r
86 ASSERT_RETURN_ERROR (PcdStatus);\r
22486318 87\r
c5b3a56e 88 DEBUG ((DEBUG_INFO, "Found GIC v3 (re)distributor @ 0x%Lx (0x%Lx)\n",\r
22486318
AB
89 DistBase, RedistBase));\r
90\r
15c9b25e
AB
91 //\r
92 // The default implementation of ArmGicArchLib is responsible for enabling\r
93 // the system register interface on the GICv3 if one is found. So let's do\r
94 // the same here.\r
95 //\r
96 IccSre = ArmGicV3GetControlSystemRegisterEnable ();\r
97 if (!(IccSre & ICC_SRE_EL2_SRE)) {\r
98 ArmGicV3SetControlSystemRegisterEnable (IccSre | ICC_SRE_EL2_SRE);\r
99 IccSre = ArmGicV3GetControlSystemRegisterEnable ();\r
100 }\r
101\r
102 //\r
103 // Unlike the default implementation, there is no fall through to GICv2\r
104 // mode if this GICv3 cannot be driven in native mode due to the fact\r
105 // that the System Register interface is unavailable.\r
106 //\r
107 ASSERT (IccSre & ICC_SRE_EL2_SRE);\r
108\r
109 mGicArchRevision = ARM_GIC_ARCH_REVISION_3;\r
110 break;\r
111\r
112 case 2:\r
01ce8727
LL
113 //\r
114 // When the GICv2 is emulated with virtualization=on, it adds a virtual\r
115 // set of control registers. This means the register property can be\r
116 // either 32 or 64 bytes in size.\r
117 //\r
118 ASSERT ((RegSize == 32) || (RegSize == 64));\r
22486318
AB
119\r
120 DistBase = SwapBytes64 (Reg[0]);\r
121 CpuBase = SwapBytes64 (Reg[2]);\r
041e842a
DC
122 ASSERT (DistBase < MAX_UINTN);\r
123 ASSERT (CpuBase < MAX_UINTN);\r
22486318 124\r
65ebe6e6
LE
125 PcdStatus = PcdSet64S (PcdGicDistributorBase, DistBase);\r
126 ASSERT_RETURN_ERROR (PcdStatus);\r
127 PcdStatus = PcdSet64S (PcdGicInterruptInterfaceBase, CpuBase);\r
128 ASSERT_RETURN_ERROR (PcdStatus);\r
22486318 129\r
c5b3a56e 130 DEBUG ((DEBUG_INFO, "Found GIC @ 0x%Lx/0x%Lx\n", DistBase, CpuBase));\r
22486318 131\r
15c9b25e
AB
132 mGicArchRevision = ARM_GIC_ARCH_REVISION_2;\r
133 break;\r
134\r
135 default:\r
c5b3a56e 136 DEBUG ((DEBUG_ERROR, "%a: No GIC revision specified!\n", __FUNCTION__));\r
15c9b25e
AB
137 return RETURN_NOT_FOUND;\r
138 }\r
139 return RETURN_SUCCESS;\r
140}\r
141\r
142ARM_GIC_ARCH_REVISION\r
143EFIAPI\r
144ArmGicGetSupportedArchRevision (\r
145 VOID\r
146 )\r
147{\r
148 return mGicArchRevision;\r
149}\r