]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/XenArmGenericTimerVirtCounterLib/XenArmGenericTimerVirtCounterLib.c
FmpDevicePkg FmpDxe: Initialize DeviceLibLowestSupportedVersion
[mirror_edk2.git] / ArmVirtPkg / Library / XenArmGenericTimerVirtCounterLib / XenArmGenericTimerVirtCounterLib.c
1 /** @file
2
3 Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
4 Copyright (c) 2014 - 2018, 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 ArmWriteCntvCtl (TimerCtrlReg);
30 }
31
32 VOID
33 EFIAPI
34 ArmGenericTimerReenableTimer (
35 VOID
36 )
37 {
38 UINTN TimerCtrlReg;
39
40 TimerCtrlReg = ArmReadCntvCtl ();
41 TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE;
42
43 //
44 // When running under Xen, we need to unmask the interrupt on the timer side
45 // as Xen will mask it when servicing the interrupt at the hypervisor level
46 // and delivering the virtual timer interrupt to the guest. Otherwise, the
47 // interrupt will fire again, trapping into the hypervisor again, etc. etc.
48 //
49 TimerCtrlReg &= ~ARM_ARCH_TIMER_IMASK;
50 ArmWriteCntvCtl (TimerCtrlReg);
51 }
52
53 VOID
54 EFIAPI
55 ArmGenericTimerDisableTimer (
56 VOID
57 )
58 {
59 UINTN TimerCtrlReg;
60
61 TimerCtrlReg = ArmReadCntvCtl ();
62 TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE;
63 ArmWriteCntvCtl (TimerCtrlReg);
64 }
65
66 VOID
67 EFIAPI
68 ArmGenericTimerSetTimerFreq (
69 IN UINTN FreqInHz
70 )
71 {
72 ArmWriteCntFrq (FreqInHz);
73 }
74
75 UINTN
76 EFIAPI
77 ArmGenericTimerGetTimerFreq (
78 VOID
79 )
80 {
81 return ArmReadCntFrq ();
82 }
83
84 UINTN
85 EFIAPI
86 ArmGenericTimerGetTimerVal (
87 VOID
88 )
89 {
90 return ArmReadCntvTval ();
91 }
92
93
94 VOID
95 EFIAPI
96 ArmGenericTimerSetTimerVal (
97 IN UINTN Value
98 )
99 {
100 ArmWriteCntvTval (Value);
101 }
102
103 UINT64
104 EFIAPI
105 ArmGenericTimerGetSystemCount (
106 VOID
107 )
108 {
109 return ArmReadCntvCt ();
110 }
111
112 UINTN
113 EFIAPI
114 ArmGenericTimerGetTimerCtrlReg (
115 VOID
116 )
117 {
118 return ArmReadCntvCtl ();
119 }
120
121 VOID
122 EFIAPI
123 ArmGenericTimerSetTimerCtrlReg (
124 UINTN Value
125 )
126 {
127 ArmWriteCntvCtl (Value);
128 }
129
130 UINT64
131 EFIAPI
132 ArmGenericTimerGetCompareVal (
133 VOID
134 )
135 {
136 return ArmReadCntvCval ();
137 }
138
139 VOID
140 EFIAPI
141 ArmGenericTimerSetCompareVal (
142 IN UINT64 Value
143 )
144 {
145 ArmWriteCntvCval (Value);
146 }