]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.c
ArmPkg/DefaultExceptionHandlerLib: put ASSERT (FALSE) last
[mirror_edk2.git] / ArmPkg / Library / ArmGenericTimerVirtCounterLib / ArmGenericTimerVirtCounterLib.c
CommitLineData
bcf37cf6
AB
1/** @file\r
2\r
3 Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>\r
4 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <Library/ArmGenericTimerCounterLib.h>\r
17#include <Library/ArmArchTimer.h>\r
18\r
19VOID\r
20EFIAPI\r
21ArmGenericTimerEnableTimer (\r
22 VOID\r
23 )\r
24{\r
25 UINTN TimerCtrlReg;\r
26\r
27 ArmArchTimerReadReg (CntvCtl, (VOID *)&TimerCtrlReg);\r
28 TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE;\r
29\r
30 //\r
31 // When running under KVM, we need to unmask the interrupt on the timer side\r
32 // as KVM will mask it when servicing the interrupt at the hypervisor level\r
33 // and delivering the virtual timer interrupt to the guest. Otherwise, the\r
34 // interrupt will fire again, trapping into the hypervisor again, etc. etc.\r
35 // This is scheduled to be fixed on the KVM side, but there is no harm in\r
36 // leaving this in once KVM gets fixed.\r
37 //\r
38 TimerCtrlReg &= ~ARM_ARCH_TIMER_IMASK;\r
39 ArmArchTimerWriteReg (CntvCtl, (VOID *)&TimerCtrlReg);\r
40}\r
41\r
42VOID\r
43EFIAPI\r
44ArmGenericTimerDisableTimer (\r
45 VOID\r
46 )\r
47{\r
48 UINTN TimerCtrlReg;\r
49\r
50 ArmArchTimerReadReg (CntvCtl, (VOID *)&TimerCtrlReg);\r
51 TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE;\r
52 ArmArchTimerWriteReg (CntvCtl, (VOID *)&TimerCtrlReg);\r
53}\r
54\r
55VOID\r
56EFIAPI\r
57ArmGenericTimerSetTimerFreq (\r
58 IN UINTN FreqInHz\r
59 )\r
60{\r
61 ArmArchTimerWriteReg (CntFrq, (VOID *)&FreqInHz);\r
62}\r
63\r
64UINTN\r
65EFIAPI\r
66ArmGenericTimerGetTimerFreq (\r
67 VOID\r
68 )\r
69{\r
70 UINTN ArchTimerFreq = 0;\r
71 ArmArchTimerReadReg (CntFrq, (VOID *)&ArchTimerFreq);\r
72 return ArchTimerFreq;\r
73}\r
74\r
75UINTN\r
76EFIAPI\r
77ArmGenericTimerGetTimerVal (\r
78 VOID\r
79 )\r
80{\r
81 UINTN ArchTimerValue;\r
82 ArmArchTimerReadReg (CntvTval, (VOID *)&ArchTimerValue);\r
83\r
84 return ArchTimerValue;\r
85}\r
86\r
87\r
88VOID\r
89EFIAPI\r
90ArmGenericTimerSetTimerVal (\r
91 IN UINTN Value\r
92 )\r
93{\r
94 ArmArchTimerWriteReg (CntvTval, (VOID *)&Value);\r
95}\r
96\r
97UINT64\r
98EFIAPI\r
99ArmGenericTimerGetSystemCount (\r
100 VOID\r
101 )\r
102{\r
103 UINT64 SystemCount;\r
104 ArmArchTimerReadReg (CntvCt, (VOID *)&SystemCount);\r
105\r
106 return SystemCount;\r
107}\r
108\r
109UINTN\r
110EFIAPI\r
111ArmGenericTimerGetTimerCtrlReg (\r
112 VOID\r
113 )\r
114{\r
115 UINTN Value;\r
116 ArmArchTimerReadReg (CntvCtl, (VOID *)&Value);\r
117\r
118 return Value;\r
119}\r
120\r
121VOID\r
122EFIAPI\r
123ArmGenericTimerSetTimerCtrlReg (\r
124 UINTN Value\r
125 )\r
126{\r
127 ArmArchTimerWriteReg (CntvCtl, (VOID *)&Value);\r
128}\r
129\r
130UINT64\r
131EFIAPI\r
132ArmGenericTimerGetCompareVal (\r
133 VOID\r
134 )\r
135{\r
136 UINT64 Value;\r
137 ArmArchTimerReadReg (CntvCval, (VOID *)&Value);\r
138\r
139 return Value;\r
140}\r
141\r
142VOID\r
143EFIAPI\r
144ArmGenericTimerSetCompareVal (\r
145 IN UINT64 Value\r
146 )\r
147{\r
148 ArmArchTimerWriteReg (CntvCval, (VOID *)&Value);\r
149}\r