--- /dev/null
+/** @file\r
+\r
+ Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>\r
+ Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
+\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/ArmGenericTimerCounterLib.h>\r
+#include <Library/ArmArchTimer.h>\r
+\r
+VOID\r
+EFIAPI\r
+ArmGenericTimerEnableTimer (\r
+ VOID\r
+ )\r
+{\r
+ UINTN TimerCtrlReg;\r
+\r
+ ArmArchTimerReadReg (CntvCtl, (VOID *)&TimerCtrlReg);\r
+ TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE;\r
+\r
+ //\r
+ // When running under KVM, we need to unmask the interrupt on the timer side\r
+ // as KVM will mask it when servicing the interrupt at the hypervisor level\r
+ // and delivering the virtual timer interrupt to the guest. Otherwise, the\r
+ // interrupt will fire again, trapping into the hypervisor again, etc. etc.\r
+ // This is scheduled to be fixed on the KVM side, but there is no harm in\r
+ // leaving this in once KVM gets fixed.\r
+ //\r
+ TimerCtrlReg &= ~ARM_ARCH_TIMER_IMASK;\r
+ ArmArchTimerWriteReg (CntvCtl, (VOID *)&TimerCtrlReg);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmGenericTimerDisableTimer (\r
+ VOID\r
+ )\r
+{\r
+ UINTN TimerCtrlReg;\r
+\r
+ ArmArchTimerReadReg (CntvCtl, (VOID *)&TimerCtrlReg);\r
+ TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE;\r
+ ArmArchTimerWriteReg (CntvCtl, (VOID *)&TimerCtrlReg);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmGenericTimerSetTimerFreq (\r
+ IN UINTN FreqInHz\r
+ )\r
+{\r
+ ArmArchTimerWriteReg (CntFrq, (VOID *)&FreqInHz);\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+ArmGenericTimerGetTimerFreq (\r
+ VOID\r
+ )\r
+{\r
+ UINTN ArchTimerFreq = 0;\r
+ ArmArchTimerReadReg (CntFrq, (VOID *)&ArchTimerFreq);\r
+ return ArchTimerFreq;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+ArmGenericTimerGetTimerVal (\r
+ VOID\r
+ )\r
+{\r
+ UINTN ArchTimerValue;\r
+ ArmArchTimerReadReg (CntvTval, (VOID *)&ArchTimerValue);\r
+\r
+ return ArchTimerValue;\r
+}\r
+\r
+\r
+VOID\r
+EFIAPI\r
+ArmGenericTimerSetTimerVal (\r
+ IN UINTN Value\r
+ )\r
+{\r
+ ArmArchTimerWriteReg (CntvTval, (VOID *)&Value);\r
+}\r
+\r
+UINT64\r
+EFIAPI\r
+ArmGenericTimerGetSystemCount (\r
+ VOID\r
+ )\r
+{\r
+ UINT64 SystemCount;\r
+ ArmArchTimerReadReg (CntvCt, (VOID *)&SystemCount);\r
+\r
+ return SystemCount;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+ArmGenericTimerGetTimerCtrlReg (\r
+ VOID\r
+ )\r
+{\r
+ UINTN Value;\r
+ ArmArchTimerReadReg (CntvCtl, (VOID *)&Value);\r
+\r
+ return Value;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmGenericTimerSetTimerCtrlReg (\r
+ UINTN Value\r
+ )\r
+{\r
+ ArmArchTimerWriteReg (CntvCtl, (VOID *)&Value);\r
+}\r
+\r
+UINT64\r
+EFIAPI\r
+ArmGenericTimerGetCompareVal (\r
+ VOID\r
+ )\r
+{\r
+ UINT64 Value;\r
+ ArmArchTimerReadReg (CntvCval, (VOID *)&Value);\r
+\r
+ return Value;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmGenericTimerSetCompareVal (\r
+ IN UINT64 Value\r
+ )\r
+{\r
+ ArmArchTimerWriteReg (CntvCval, (VOID *)&Value);\r
+}\r
--- /dev/null
+#/** @file\r
+# Implement ArmGenericTimerCounterLib using the virtual timer\r
+#\r
+# Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = ArmGenericTimerVirtCounterLib\r
+ FILE_GUID = 3C0D77CC-4F27-49C8-B25C-2D01D81ED4D8\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = ArmGenericTimerCounterLib\r
+\r
+[Sources]\r
+ ArmGenericTimerVirtCounterLib.c\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ ArmPkg/ArmPkg.dec\r
+\r
+[LibraryClasses]\r
+ ArmLib\r
+ BaseLib\r