]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg: add ArmGenericTimerCounterLib implementation using virtual timer
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 9 Sep 2014 16:07:43 +0000 (16:07 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 9 Sep 2014 16:07:43 +0000 (16:07 +0000)
This adds an implementation of ArmGenericTimerCounterLib using the virtual
architected generic timer.

Contributed-under: TianoCore Contribution Agreement 1.0
Acked-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16076 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/ArmPkg.dsc
ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.c [new file with mode: 0644]
ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf [new file with mode: 0644]

index c031f21e7ce3de88e1be9499e37f03f0f48e066a..4a02517c4be771db712499b864244b670b6c7744 100644 (file)
   ArmPkg/Drivers/TimerDxe/TimerDxe.inf\r
 \r
   ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf\r
+  ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf\r
 \r
   ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf\r
   ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf\r
diff --git a/ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.c b/ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.c
new file mode 100644 (file)
index 0000000..f99c852
--- /dev/null
@@ -0,0 +1,149 @@
+/** @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
diff --git a/ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf b/ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterLib.inf
new file mode 100644 (file)
index 0000000..9267dc3
--- /dev/null
@@ -0,0 +1,33 @@
+#/** @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