mirror of https://github.com/acidanthera/audk.git
ArmPkg/ArchArmTimerLib: refactor MultU64xN and TimerFreq definitions
This refactors some timer code to define MultU64xN as a preprocessor symbol rather than a function pointer, and to factor out the code that obtains the timer frequency into GetPlatformTimerFreq (). Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Evan Lloyd <evan.lloyd@arm.com> Reviewed-by: Ryan Harkin <ryan.harkin@linaro.org> Contributed-under: TianoCore Contribution Agreement 1.0 [ard.biesheuvel: split off from 'add GetTimeInNanoSecond() to ArmArchTimerLib'] Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
This commit is contained in:
parent
37b680116d
commit
cbdece1769
|
@ -24,6 +24,14 @@
|
||||||
|
|
||||||
#define TICKS_PER_MICRO_SEC (PcdGet32 (PcdArmArchTimerFreqInHz)/1000000U)
|
#define TICKS_PER_MICRO_SEC (PcdGet32 (PcdArmArchTimerFreqInHz)/1000000U)
|
||||||
|
|
||||||
|
// Select appropriate multiply function for platform architecture.
|
||||||
|
#ifdef MDE_CPU_ARM
|
||||||
|
#define MultU64xN MultU64x32
|
||||||
|
#else
|
||||||
|
#define MultU64xN MultU64x64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
RETURN_STATUS
|
RETURN_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
TimerConstructor (
|
TimerConstructor (
|
||||||
|
@ -76,6 +84,28 @@ TimerConstructor (
|
||||||
return RETURN_SUCCESS;
|
return RETURN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
A local utility function that returns the PCD value, if specified.
|
||||||
|
Otherwise it defaults to ArmGenericTimerGetTimerFreq.
|
||||||
|
|
||||||
|
@return The timer frequency.
|
||||||
|
|
||||||
|
**/
|
||||||
|
STATIC
|
||||||
|
UINTN
|
||||||
|
EFIAPI
|
||||||
|
GetPlatformTimerFreq (
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINTN TimerFreq;
|
||||||
|
|
||||||
|
TimerFreq = PcdGet32 (PcdArmArchTimerFreqInHz);
|
||||||
|
if (TimerFreq == 0) {
|
||||||
|
TimerFreq = ArmGenericTimerGetTimerFreq ();
|
||||||
|
}
|
||||||
|
return TimerFreq;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Stalls the CPU for the number of microseconds specified by MicroSeconds.
|
Stalls the CPU for the number of microseconds specified by MicroSeconds.
|
||||||
|
@ -93,23 +123,6 @@ MicroSecondDelay (
|
||||||
{
|
{
|
||||||
UINT64 TimerTicks64;
|
UINT64 TimerTicks64;
|
||||||
UINT64 SystemCounterVal;
|
UINT64 SystemCounterVal;
|
||||||
UINT64 (EFIAPI
|
|
||||||
*MultU64xN) (
|
|
||||||
IN UINT64 Multiplicand,
|
|
||||||
IN UINTN Multiplier
|
|
||||||
);
|
|
||||||
UINTN TimerFreq;
|
|
||||||
|
|
||||||
#ifdef MDE_CPU_ARM
|
|
||||||
MultU64xN = MultU64x32;
|
|
||||||
#else
|
|
||||||
MultU64xN = MultU64x64;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TimerFreq = PcdGet32 (PcdArmArchTimerFreqInHz);
|
|
||||||
if (TimerFreq == 0) {
|
|
||||||
TimerFreq = ArmGenericTimerGetTimerFreq ();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate counter ticks that can represent requested delay:
|
// Calculate counter ticks that can represent requested delay:
|
||||||
// = MicroSeconds x TICKS_PER_MICRO_SEC
|
// = MicroSeconds x TICKS_PER_MICRO_SEC
|
||||||
|
@ -117,7 +130,7 @@ MicroSecondDelay (
|
||||||
TimerTicks64 = DivU64x32 (
|
TimerTicks64 = DivU64x32 (
|
||||||
MultU64xN (
|
MultU64xN (
|
||||||
MicroSeconds,
|
MicroSeconds,
|
||||||
TimerFreq
|
GetPlatformTimerFreq ()
|
||||||
),
|
),
|
||||||
1000000U
|
1000000U
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue