From cbdece176953cf2be63b322f53600e2136b94744 Mon Sep 17 00:00:00 2001 From: Sami Mujawar Date: Thu, 3 Mar 2016 15:28:16 +0000 Subject: [PATCH] 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 Reviewed-by: Ryan Harkin Contributed-under: TianoCore Contribution Agreement 1.0 [ard.biesheuvel: split off from 'add GetTimeInNanoSecond() to ArmArchTimerLib'] Signed-off-by: Ard Biesheuvel --- .../Library/ArmArchTimerLib/ArmArchTimerLib.c | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c index a0e4f5804b..4361905e14 100644 --- a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c +++ b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c @@ -24,6 +24,14 @@ #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 EFIAPI TimerConstructor ( @@ -76,6 +84,28 @@ TimerConstructor ( 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. @@ -93,23 +123,6 @@ MicroSecondDelay ( { UINT64 TimerTicks64; 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: // = MicroSeconds x TICKS_PER_MICRO_SEC @@ -117,7 +130,7 @@ MicroSecondDelay ( TimerTicks64 = DivU64x32 ( MultU64xN ( MicroSeconds, - TimerFreq + GetPlatformTimerFreq () ), 1000000U );