]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmGicArchLib/Arm/ArmGicArchLib.c
ArmPkg: use ID register helper for ArmGicArch(Sec)Lib
[mirror_edk2.git] / ArmPkg / Library / ArmGicArchLib / Arm / ArmGicArchLib.c
CommitLineData
5f525769
OM
1/** @file\r
2*\r
3* Copyright (c) 2014, ARM Limited. All rights reserved.\r
4*\r
4059386c 5* SPDX-License-Identifier: BSD-2-Clause-Patent\r
5f525769
OM
6*\r
7**/\r
8\r
9#include <Library/ArmLib.h>\r
10#include <Library/ArmGicLib.h>\r
11\r
f94522c8
AB
12STATIC ARM_GIC_ARCH_REVISION mGicArchRevision;\r
13\r
14RETURN_STATUS\r
5f525769 15EFIAPI\r
f94522c8 16ArmGicArchLibInitialize (\r
5f525769
OM
17 VOID\r
18 )\r
19{\r
eadbec01
AB
20 UINT32 IccSre;\r
21\r
5f525769
OM
22 // Ideally we would like to use the GICC IIDR Architecture version here, but\r
23 // this does not seem to be very reliable as the implementation could easily\r
24 // get it wrong. It is more reliable to check if the GICv3 System Register\r
25 // feature is implemented on the CPU. This is also convenient as our GICv3\r
26 // driver requires SRE. If only Memory mapped access is available we try to\r
27 // drive the GIC as a v2.\r
b7ae5efb 28 if (ArmHasGicSystemRegisters ()) {\r
37ec4d9a
AB
29 // Make sure System Register access is enabled (SRE). This depends on the\r
30 // higher privilege level giving us permission, otherwise we will either\r
31 // cause an exception here, or the write doesn't stick in which case we need\r
32 // to fall back to the GICv2 MMIO interface.\r
33 // Note: We do not need to set ICC_SRE_EL2.Enable because the OS is started\r
34 // at the same exception level.\r
35 // It is the OS responsibility to set this bit.\r
eadbec01
AB
36 IccSre = ArmGicV3GetControlSystemRegisterEnable ();\r
37 if (!(IccSre & ICC_SRE_EL2_SRE)) {\r
38 ArmGicV3SetControlSystemRegisterEnable (IccSre| ICC_SRE_EL2_SRE);\r
39 IccSre = ArmGicV3GetControlSystemRegisterEnable ();\r
40 }\r
41 if (IccSre & ICC_SRE_EL2_SRE) {\r
f94522c8
AB
42 mGicArchRevision = ARM_GIC_ARCH_REVISION_3;\r
43 goto Done;\r
37ec4d9a 44 }\r
5f525769
OM
45 }\r
46\r
f94522c8
AB
47 mGicArchRevision = ARM_GIC_ARCH_REVISION_2;\r
48\r
49Done:\r
50 return RETURN_SUCCESS;\r
51}\r
52\r
53ARM_GIC_ARCH_REVISION\r
54EFIAPI\r
55ArmGicGetSupportedArchRevision (\r
56 VOID\r
57 )\r
58{\r
59 return mGicArchRevision;\r
5f525769 60}\r