ArmPkg/ArmLib: remove indirection layer from timer register accessors

The generic timer support libraries call the actual system register
accessor function via a single pair of functions ArmArchTimerReadReg()
and ArmArchTimerWriteReg(), which take an enum argument to identify
the register, and return output values by pointer reference.

Since these functions are never called with a non-immediate argument,
we can simply replace each invocation with the underlying system register
accessor instead. This is mostly functionally equivalent, with the
exception of the bounds check for the enum (which is pointless given the
fact that we never pass a variable), the check for the presence of the
architected timer (which only makes sense for ARMv7, but is highly unlikely
to vary between platforms that are similar enough to run the same firmware
image), and a check for enum values that refer to the HYP view of the timer,
which we never referred to anywhere in the code in the first place.

So get rid of the middle man, and update the ArmGenericTimerPhyCounterLib
and ArmGenericTimerVirtCounterLib implementations to call the system
register accessors directly.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Tested-by: Ryan Harkin <ryan.harkin@linaro.org>
This commit is contained in:
Ard Biesheuvel
2017-01-20 11:58:37 +00:00
parent 90d1f671cd
commit 734bd6cc41
11 changed files with 156 additions and 589 deletions

View File

@@ -14,7 +14,7 @@
**/
#include <Library/ArmGenericTimerCounterLib.h>
#include <Library/ArmArchTimer.h>
#include <Library/ArmLib.h>
VOID
EFIAPI
@@ -24,9 +24,9 @@ ArmGenericTimerEnableTimer (
{
UINTN TimerCtrlReg;
ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg);
TimerCtrlReg = ArmReadCntpCtl ();
TimerCtrlReg |= ARM_ARCH_TIMER_ENABLE;
ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg);
ArmWriteCntpCtl (TimerCtrlReg);
}
VOID
@@ -37,9 +37,9 @@ ArmGenericTimerDisableTimer (
{
UINTN TimerCtrlReg;
ArmArchTimerReadReg (CntpCtl, (VOID *)&TimerCtrlReg);
TimerCtrlReg = ArmReadCntpCtl ();
TimerCtrlReg &= ~ARM_ARCH_TIMER_ENABLE;
ArmArchTimerWriteReg (CntpCtl, (VOID *)&TimerCtrlReg);
ArmWriteCntpCtl (TimerCtrlReg);
}
VOID
@@ -48,7 +48,7 @@ ArmGenericTimerSetTimerFreq (
IN UINTN FreqInHz
)
{
ArmArchTimerWriteReg (CntFrq, (VOID *)&FreqInHz);
ArmWriteCntFrq (FreqInHz);
}
UINTN
@@ -57,9 +57,7 @@ ArmGenericTimerGetTimerFreq (
VOID
)
{
UINTN ArchTimerFreq = 0;
ArmArchTimerReadReg (CntFrq, (VOID *)&ArchTimerFreq);
return ArchTimerFreq;
return ArmReadCntFrq ();
}
UINTN
@@ -68,10 +66,7 @@ ArmGenericTimerGetTimerVal (
VOID
)
{
UINTN ArchTimerValue;
ArmArchTimerReadReg (CntpTval, (VOID *)&ArchTimerValue);
return ArchTimerValue;
return ArmReadCntpTval ();
}
@@ -81,7 +76,7 @@ ArmGenericTimerSetTimerVal (
IN UINTN Value
)
{
ArmArchTimerWriteReg (CntpTval, (VOID *)&Value);
ArmWriteCntpTval (Value);
}
UINT64
@@ -90,10 +85,7 @@ ArmGenericTimerGetSystemCount (
VOID
)
{
UINT64 SystemCount;
ArmArchTimerReadReg (CntPct, (VOID *)&SystemCount);
return SystemCount;
return ArmReadCntPct ();
}
UINTN
@@ -102,10 +94,7 @@ ArmGenericTimerGetTimerCtrlReg (
VOID
)
{
UINTN Value;
ArmArchTimerReadReg (CntpCtl, (VOID *)&Value);
return Value;
return ArmReadCntpCtl ();
}
VOID
@@ -114,7 +103,7 @@ ArmGenericTimerSetTimerCtrlReg (
UINTN Value
)
{
ArmArchTimerWriteReg (CntpCtl, (VOID *)&Value);
ArmWriteCntpCtl (Value);
}
UINT64
@@ -123,10 +112,7 @@ ArmGenericTimerGetCompareVal (
VOID
)
{
UINT64 Value;
ArmArchTimerReadReg (CntpCval, (VOID *)&Value);
return Value;
return ArmReadCntpCval ();
}
VOID
@@ -135,5 +121,5 @@ ArmGenericTimerSetCompareVal (
IN UINT64 Value
)
{
ArmArchTimerWriteReg (CntpCval, (VOID *)&Value);
ArmWriteCntpCval (Value);
}