]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmGicArchLib/Arm/ArmGicArchLib.c
ArmPkg: cache detected revision in ArmGicArchLib
[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
5* This program and the accompanying materials are licensed and made available\r
6* under the terms and conditions of the BSD License which accompanies this\r
7* distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12*\r
13**/\r
14\r
15#include <Library/ArmLib.h>\r
16#include <Library/ArmGicLib.h>\r
17\r
f94522c8
AB
18STATIC ARM_GIC_ARCH_REVISION mGicArchRevision;\r
19\r
20RETURN_STATUS\r
5f525769 21EFIAPI\r
f94522c8 22ArmGicArchLibInitialize (\r
5f525769
OM
23 VOID\r
24 )\r
25{\r
eadbec01
AB
26 UINT32 IccSre;\r
27\r
5f525769
OM
28 // Ideally we would like to use the GICC IIDR Architecture version here, but\r
29 // this does not seem to be very reliable as the implementation could easily\r
30 // get it wrong. It is more reliable to check if the GICv3 System Register\r
31 // feature is implemented on the CPU. This is also convenient as our GICv3\r
32 // driver requires SRE. If only Memory mapped access is available we try to\r
33 // drive the GIC as a v2.\r
34 if (ArmReadIdPfr1 () & ARM_PFR1_GIC) {\r
37ec4d9a
AB
35 // Make sure System Register access is enabled (SRE). This depends on the\r
36 // higher privilege level giving us permission, otherwise we will either\r
37 // cause an exception here, or the write doesn't stick in which case we need\r
38 // to fall back to the GICv2 MMIO interface.\r
39 // Note: We do not need to set ICC_SRE_EL2.Enable because the OS is started\r
40 // at the same exception level.\r
41 // It is the OS responsibility to set this bit.\r
eadbec01
AB
42 IccSre = ArmGicV3GetControlSystemRegisterEnable ();\r
43 if (!(IccSre & ICC_SRE_EL2_SRE)) {\r
44 ArmGicV3SetControlSystemRegisterEnable (IccSre| ICC_SRE_EL2_SRE);\r
45 IccSre = ArmGicV3GetControlSystemRegisterEnable ();\r
46 }\r
47 if (IccSre & ICC_SRE_EL2_SRE) {\r
f94522c8
AB
48 mGicArchRevision = ARM_GIC_ARCH_REVISION_3;\r
49 goto Done;\r
37ec4d9a 50 }\r
5f525769
OM
51 }\r
52\r
f94522c8
AB
53 mGicArchRevision = ARM_GIC_ARCH_REVISION_2;\r
54\r
55Done:\r
56 return RETURN_SUCCESS;\r
57}\r
58\r
59ARM_GIC_ARCH_REVISION\r
60EFIAPI\r
61ArmGicGetSupportedArchRevision (\r
62 VOID\r
63 )\r
64{\r
65 return mGicArchRevision;\r
5f525769 66}\r