diff mbox

[edk2,v7,09/24] ArmPkg/TimerDxe: respect layering of ARM timer libraries

Message ID 1409918214-29584-10-git-send-email-ard.biesheuvel@linaro.org
State New
Headers show

Commit Message

Ard Biesheuvel Sept. 5, 2014, 11:56 a.m. UTC
Replace direct calls to the physical timer system registers with calls into
ArmArchTimer.h functions so we can swap in the virtual timer later. Also,
register the virt and hyp timer interrupts at init time.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 ArmPkg/Drivers/TimerDxe/TimerDxe.c               | 18 ++++++++++++------
 ArmPkg/Drivers/TimerDxe/TimerDxe.inf             |  2 ++
 ArmPkg/Include/Library/ArmArchTimer.h            |  6 ++++++
 ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c | 12 ++++++++++++
 ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c     | 12 ++++++++++++
 5 files changed, 44 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/ArmPkg/Drivers/TimerDxe/TimerDxe.c b/ArmPkg/Drivers/TimerDxe/TimerDxe.c
index 40ccf161be63..6c4494ed4ce6 100644
--- a/ArmPkg/Drivers/TimerDxe/TimerDxe.c
+++ b/ArmPkg/Drivers/TimerDxe/TimerDxe.c
@@ -163,10 +163,10 @@  TimerDriverSetTimerPeriod (
 
     gBS->RestoreTPL (OriginalTPL);
 
-    // Get value of the current physical timer
-    CounterValue = ArmReadCntPct ();
+    // Get value of the current timer
+    CounterValue = ArmArchTimerGetSystemCount ();
     // Set the interrupt in Current Time + mTimerTick
-    ArmWriteCntpCval (CounterValue + mTimerTicks);
+    ArmArchTimerSetCompareVal (CounterValue + mTimerTicks);
 
     // Enable the timer
     ArmArchTimerEnableTimer ();
@@ -321,9 +321,9 @@  TimerInterruptHandler (
     //
 
     // Get current counter value
-    CurrentValue = ArmReadCntPct ();
+    CurrentValue = ArmArchTimerGetSystemCount ();
     // Get the counter value to compare with
-    CompareValue = ArmReadCntpCval ();
+    CompareValue = ArmArchTimerGetCompareVal ();
 
     // This loop is needed in case we missed interrupts (eg: case when the interrupt handling
     // has taken longer than mTickPeriod).
@@ -335,7 +335,7 @@  TimerInterruptHandler (
     } while (CompareValue < CurrentValue);
 
     // Set next compare value
-    ArmWriteCntpCval (CompareValue);
+    ArmArchTimerSetCompareVal (CompareValue);
   }
 
   // Enable timer interrupts
@@ -390,6 +390,12 @@  TimerInitialize (
   // Note: Because it is not possible to determine the security state of the
   // CPU dynamically, we just install interrupt handler for both sec and non-sec
   // timer PPI
+  Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerVirtIntrNum), TimerInterruptHandler);
+  ASSERT_EFI_ERROR (Status);
+
+  Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerHypIntrNum), TimerInterruptHandler);
+  ASSERT_EFI_ERROR (Status);
+
   Status = gInterrupt->RegisterInterruptSource (gInterrupt, PcdGet32 (PcdArmArchTimerSecIntrNum), TimerInterruptHandler);
   ASSERT_EFI_ERROR (Status);
 
diff --git a/ArmPkg/Drivers/TimerDxe/TimerDxe.inf b/ArmPkg/Drivers/TimerDxe/TimerDxe.inf
index 50477ba42a7a..161d286d9c57 100644
--- a/ArmPkg/Drivers/TimerDxe/TimerDxe.inf
+++ b/ArmPkg/Drivers/TimerDxe/TimerDxe.inf
@@ -52,6 +52,8 @@ 
   gEmbeddedTokenSpaceGuid.PcdTimerPeriod
   gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum
   gArmTokenSpaceGuid.PcdArmArchTimerIntrNum
+  gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum
+  gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum
   gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz
 
 [Depex]
diff --git a/ArmPkg/Include/Library/ArmArchTimer.h b/ArmPkg/Include/Library/ArmArchTimer.h
index eb7e87d3c4fc..c41b53ee4143 100644
--- a/ArmPkg/Include/Library/ArmArchTimer.h
+++ b/ArmPkg/Include/Library/ArmArchTimer.h
@@ -106,6 +106,12 @@  ArmArchTimerSetTimerCtrlReg (
   UINTN Val
   );
 
+UINT64
+EFIAPI
+ArmArchTimerGetCompareVal (
+  VOID
+  );
+
 VOID
 EFIAPI
 ArmArchTimerSetCompareVal (
diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c b/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c
index 6a461eb2e43e..66a979f7046a 100644
--- a/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c
+++ b/ArmPkg/Library/ArmLib/AArch64/AArch64ArchTimer.c
@@ -265,6 +265,18 @@  ArmArchTimerSetTimerCtrlReg (
   ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val);
 }
 
+UINT64
+EFIAPI
+ArmArchTimerGetCompareVal (
+    VOID
+    )
+{
+  UINT64  Val;
+  ArmArchTimerReadReg (CntpCval, (VOID *)&Val);
+
+  return Val;
+}
+
 VOID
 EFIAPI
 ArmArchTimerSetCompareVal (
diff --git a/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c b/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c
index bebdafce7dba..836c27329eca 100644
--- a/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c
+++ b/ArmPkg/Library/ArmLib/ArmV7/ArmV7ArchTimer.c
@@ -265,6 +265,18 @@  ArmArchTimerSetTimerCtrlReg (
   ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val);
 }
 
+UINT64
+EFIAPI
+ArmArchTimerGetCompareVal (
+    VOID
+    )
+{
+  UINT64  Val;
+  ArmArchTimerReadReg (CntpCval, (VOID *)&Val);
+
+  return Val;
+}
+
 VOID
 EFIAPI
 ArmArchTimerSetCompareVal (