@@ -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);
@@ -52,6 +52,8 @@
gEmbeddedTokenSpaceGuid.PcdTimerPeriod
gArmTokenSpaceGuid.PcdArmArchTimerSecIntrNum
gArmTokenSpaceGuid.PcdArmArchTimerIntrNum
+ gArmTokenSpaceGuid.PcdArmArchTimerVirtIntrNum
+ gArmTokenSpaceGuid.PcdArmArchTimerHypIntrNum
gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz
[Depex]
@@ -106,6 +106,12 @@ ArmArchTimerSetTimerCtrlReg (
UINTN Val
);
+UINT64
+EFIAPI
+ArmArchTimerGetCompareVal (
+ VOID
+ );
+
VOID
EFIAPI
ArmArchTimerSetCompareVal (
@@ -265,6 +265,18 @@ ArmArchTimerSetTimerCtrlReg (
ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val);
}
+UINT64
+EFIAPI
+ArmArchTimerGetCompareVal (
+ VOID
+ )
+{
+ UINT64 Val;
+ ArmArchTimerReadReg (CntpCval, (VOID *)&Val);
+
+ return Val;
+}
+
VOID
EFIAPI
ArmArchTimerSetCompareVal (
@@ -265,6 +265,18 @@ ArmArchTimerSetTimerCtrlReg (
ArmArchTimerWriteReg (CntpCtl, (VOID *)&Val);
}
+UINT64
+EFIAPI
+ArmArchTimerGetCompareVal (
+ VOID
+ )
+{
+ UINT64 Val;
+ ArmArchTimerReadReg (CntpCval, (VOID *)&Val);
+
+ return Val;
+}
+
VOID
EFIAPI
ArmArchTimerSetCompareVal (
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(-)