]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg: add ArmGenericTimerCounterLib implementation using physical timer
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 9 Sep 2014 16:06:10 +0000 (16:06 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 9 Sep 2014 16:06:10 +0000 (16:06 +0000)
This adds an implementation of ArmGenericTimerCounterLib using the physical
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@16075 6f19259b-4bc3-4df7-8a09-765794883524

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

index 4f9a1fbc55004bd5f1993e819a0cc2a67d285baf..c031f21e7ce3de88e1be9499e37f03f0f48e066a 100644 (file)
   ArmPkg/Drivers/ArmGic/ArmGicSecLib.inf\r
   ArmPkg/Drivers/TimerDxe/TimerDxe.inf\r
 \r
+  ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf\r
+\r
   ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf\r
   ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf\r
 \r
diff --git a/ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.c b/ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.c
new file mode 100644 (file)
index 0000000..826827f
--- /dev/null
@@ -0,0 +1,139 @@
+/** @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 (CntpCtl, (VOID *)&TimerCtrlReg);\r
+  TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE;\r
+  ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmGenericTimerDisableTimer (\r
+  VOID\r
+  )\r
+{\r
+  UINTN TimerCtrlReg;\r
+\r
+  ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg);\r
+  TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE;\r
+  ArmArchTimerWriteReg (CntpCtl, (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 (CntpTval, (VOID *)&ArchTimerValue);\r
+\r
+  return ArchTimerValue;\r
+}\r
+\r
+\r
+VOID\r
+EFIAPI\r
+ArmGenericTimerSetTimerVal (\r
+  IN   UINTN   Value\r
+  )\r
+{\r
+  ArmArchTimerWriteReg (CntpTval, (VOID *)&Value);\r
+}\r
+\r
+UINT64\r
+EFIAPI\r
+ArmGenericTimerGetSystemCount (\r
+  VOID\r
+  )\r
+{\r
+  UINT64 SystemCount;\r
+  ArmArchTimerReadReg (CntPct, (VOID *)&SystemCount);\r
+\r
+  return SystemCount;\r
+}\r
+\r
+UINTN\r
+EFIAPI\r
+ArmGenericTimerGetTimerCtrlReg (\r
+  VOID\r
+  )\r
+{\r
+  UINTN  Value;\r
+  ArmArchTimerReadReg (CntpCtl, (VOID *)&Value);\r
+\r
+  return Value;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmGenericTimerSetTimerCtrlReg (\r
+  UINTN Value\r
+  )\r
+{\r
+  ArmArchTimerWriteReg (CntpCtl, (VOID *)&Value);\r
+}\r
+\r
+UINT64\r
+EFIAPI\r
+ArmGenericTimerGetCompareVal (\r
+  VOID\r
+  )\r
+{\r
+  UINT64  Value;\r
+  ArmArchTimerReadReg (CntpCval, (VOID *)&Value);\r
+\r
+  return Value;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+ArmGenericTimerSetCompareVal (\r
+  IN   UINT64   Value\r
+  )\r
+{\r
+  ArmArchTimerWriteReg (CntpCval, (VOID *)&Value);\r
+}\r
diff --git a/ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf b/ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf
new file mode 100644 (file)
index 0000000..5420608
--- /dev/null
@@ -0,0 +1,33 @@
+#/** @file\r
+#  Implement ArmGenericTimerCounterLib using the physical 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                      = ArmGenericTimerPhyCounterLib\r
+  FILE_GUID                      = 7A07E61D-9967-407F-AE85-2EB0B50BEF2C\r
+  MODULE_TYPE                    = BASE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmGenericTimerCounterLib\r
+\r
+[Sources]\r
+  ArmGenericTimerPhyCounterLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  ArmPkg/ArmPkg.dec\r
+\r
+[LibraryClasses]\r
+  ArmLib\r
+  BaseLib\r