]>
git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.c
69a4ceb62db616dfeaec9e54fe57679811778e11
3 Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
4 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
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
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.
16 #include <Library/ArmGenericTimerCounterLib.h>
17 #include <Library/ArmLib.h>
21 ArmGenericTimerEnableTimer (
27 TimerCtrlReg
= ArmReadCntvCtl ();
28 TimerCtrlReg
|= ARM_ARCH_TIMER_ENABLE
;
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.
38 TimerCtrlReg
&= ~ARM_ARCH_TIMER_IMASK
;
39 ArmWriteCntvCtl (TimerCtrlReg
);
44 ArmGenericTimerDisableTimer (
50 TimerCtrlReg
= ArmReadCntvCtl ();
51 TimerCtrlReg
&= ~ARM_ARCH_TIMER_ENABLE
;
52 ArmWriteCntvCtl (TimerCtrlReg
);
57 ArmGenericTimerSetTimerFreq (
61 ArmWriteCntFrq (FreqInHz
);
66 ArmGenericTimerGetTimerFreq (
70 return ArmReadCntFrq ();
75 ArmGenericTimerGetTimerVal (
79 return ArmReadCntvTval ();
85 ArmGenericTimerSetTimerVal (
89 ArmWriteCntvTval (Value
);
94 ArmGenericTimerGetSystemCount (
98 return ArmReadCntvCt ();
103 ArmGenericTimerGetTimerCtrlReg (
107 return ArmReadCntvCtl ();
112 ArmGenericTimerSetTimerCtrlReg (
116 ArmWriteCntvCtl (Value
);
121 ArmGenericTimerGetCompareVal (
125 return ArmReadCntvCval ();
130 ArmGenericTimerSetCompareVal (
134 ArmWriteCntvCval (Value
);