]>
git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.c
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/ArmArchTimer.h>
21 ArmGenericTimerEnableTimer (
27 ArmArchTimerReadReg (CntvCtl
, (VOID
*)&TimerCtrlReg
);
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 ArmArchTimerWriteReg (CntvCtl
, (VOID
*)&TimerCtrlReg
);
44 ArmGenericTimerDisableTimer (
50 ArmArchTimerReadReg (CntvCtl
, (VOID
*)&TimerCtrlReg
);
51 TimerCtrlReg
&= ~ARM_ARCH_TIMER_ENABLE
;
52 ArmArchTimerWriteReg (CntvCtl
, (VOID
*)&TimerCtrlReg
);
57 ArmGenericTimerSetTimerFreq (
61 ArmArchTimerWriteReg (CntFrq
, (VOID
*)&FreqInHz
);
66 ArmGenericTimerGetTimerFreq (
70 UINTN ArchTimerFreq
= 0;
71 ArmArchTimerReadReg (CntFrq
, (VOID
*)&ArchTimerFreq
);
77 ArmGenericTimerGetTimerVal (
82 ArmArchTimerReadReg (CntvTval
, (VOID
*)&ArchTimerValue
);
84 return ArchTimerValue
;
90 ArmGenericTimerSetTimerVal (
94 ArmArchTimerWriteReg (CntvTval
, (VOID
*)&Value
);
99 ArmGenericTimerGetSystemCount (
104 ArmArchTimerReadReg (CntvCt
, (VOID
*)&SystemCount
);
111 ArmGenericTimerGetTimerCtrlReg (
116 ArmArchTimerReadReg (CntvCtl
, (VOID
*)&Value
);
123 ArmGenericTimerSetTimerCtrlReg (
127 ArmArchTimerWriteReg (CntvCtl
, (VOID
*)&Value
);
132 ArmGenericTimerGetCompareVal (
137 ArmArchTimerReadReg (CntvCval
, (VOID
*)&Value
);
144 ArmGenericTimerSetCompareVal (
148 ArmArchTimerWriteReg (CntvCval
, (VOID
*)&Value
);