]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.c
69a4ceb62db616dfeaec9e54fe57679811778e11
[mirror_edk2.git] / ArmPkg / Library / ArmGenericTimerVirtCounterLib / ArmGenericTimerVirtCounterLib.c
1 /** @file
2
3 Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
4 Copyright (c) 2014, 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 <Library/ArmGenericTimerCounterLib.h>
17 #include <Library/ArmLib.h>
18
19 VOID
20 EFIAPI
21 ArmGenericTimerEnableTimer (
22 VOID
23 )
24 {
25 UINTN TimerCtrlReg;
26
27 TimerCtrlReg = ArmReadCntvCtl ();
28 TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE;
29
30 //
31 // When running under KVM, we need to unmask the interrupt on the timer side
32 // as KVM will mask it when servicing the interrupt at the hypervisor level
33 // and delivering the virtual timer interrupt to the guest. Otherwise, the
34 // interrupt will fire again, trapping into the hypervisor again, etc. etc.
35 // This is scheduled to be fixed on the KVM side, but there is no harm in
36 // leaving this in once KVM gets fixed.
37 //
38 TimerCtrlReg &= ~ARM_ARCH_TIMER_IMASK;
39 ArmWriteCntvCtl (TimerCtrlReg);
40 }
41
42 VOID
43 EFIAPI
44 ArmGenericTimerDisableTimer (
45 VOID
46 )
47 {
48 UINTN TimerCtrlReg;
49
50 TimerCtrlReg = ArmReadCntvCtl ();
51 TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE;
52 ArmWriteCntvCtl (TimerCtrlReg);
53 }
54
55 VOID
56 EFIAPI
57 ArmGenericTimerSetTimerFreq (
58 IN UINTN FreqInHz
59 )
60 {
61 ArmWriteCntFrq (FreqInHz);
62 }
63
64 UINTN
65 EFIAPI
66 ArmGenericTimerGetTimerFreq (
67 VOID
68 )
69 {
70 return ArmReadCntFrq ();
71 }
72
73 UINTN
74 EFIAPI
75 ArmGenericTimerGetTimerVal (
76 VOID
77 )
78 {
79 return ArmReadCntvTval ();
80 }
81
82
83 VOID
84 EFIAPI
85 ArmGenericTimerSetTimerVal (
86 IN UINTN Value
87 )
88 {
89 ArmWriteCntvTval (Value);
90 }
91
92 UINT64
93 EFIAPI
94 ArmGenericTimerGetSystemCount (
95 VOID
96 )
97 {
98 return ArmReadCntvCt ();
99 }
100
101 UINTN
102 EFIAPI
103 ArmGenericTimerGetTimerCtrlReg (
104 VOID
105 )
106 {
107 return ArmReadCntvCtl ();
108 }
109
110 VOID
111 EFIAPI
112 ArmGenericTimerSetTimerCtrlReg (
113 UINTN Value
114 )
115 {
116 ArmWriteCntvCtl (Value);
117 }
118
119 UINT64
120 EFIAPI
121 ArmGenericTimerGetCompareVal (
122 VOID
123 )
124 {
125 return ArmReadCntvCval ();
126 }
127
128 VOID
129 EFIAPI
130 ArmGenericTimerSetCompareVal (
131 IN UINT64 Value
132 )
133 {
134 ArmWriteCntvCval (Value);
135 }