]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArchArmTimerLib: refactor MultU64xN and TimerFreq definitions
authorSami Mujawar <sami.mujawar@arm.com>
Thu, 3 Mar 2016 15:28:16 +0000 (15:28 +0000)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Fri, 1 Apr 2016 13:52:16 +0000 (15:52 +0200)
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>
ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c

index a0e4f5804b57e04e9bad55d9a5e81d728c7664a5..4361905e143f7963cd64e2a8d35abcb7688fa91b 100644 (file)
 \r
 #define TICKS_PER_MICRO_SEC     (PcdGet32 (PcdArmArchTimerFreqInHz)/1000000U)\r
 \r
+// Select appropriate multiply function for platform architecture.\r
+#ifdef MDE_CPU_ARM\r
+#define MultU64xN MultU64x32\r
+#else\r
+#define MultU64xN MultU64x64\r
+#endif\r
+\r
+\r
 RETURN_STATUS\r
 EFIAPI\r
 TimerConstructor (\r
@@ -76,6 +84,28 @@ TimerConstructor (
   return RETURN_SUCCESS;\r
 }\r
 \r
+/**\r
+  A local utility function that returns the PCD value, if specified.\r
+  Otherwise it defaults to ArmGenericTimerGetTimerFreq.\r
+\r
+  @return The timer frequency.\r
+\r
+**/\r
+STATIC\r
+UINTN\r
+EFIAPI\r
+GetPlatformTimerFreq (\r
+  )\r
+{\r
+  UINTN TimerFreq;\r
+\r
+  TimerFreq = PcdGet32 (PcdArmArchTimerFreqInHz);\r
+  if (TimerFreq == 0) {\r
+    TimerFreq = ArmGenericTimerGetTimerFreq ();\r
+  }\r
+  return TimerFreq;\r
+}\r
+\r
 \r
 /**\r
   Stalls the CPU for the number of microseconds specified by MicroSeconds.\r
@@ -93,23 +123,6 @@ MicroSecondDelay (
 {\r
   UINT64 TimerTicks64;\r
   UINT64 SystemCounterVal;\r
-  UINT64 (EFIAPI\r
-          *MultU64xN) (\r
-            IN UINT64 Multiplicand,\r
-            IN UINTN  Multiplier\r
-            );\r
-  UINTN TimerFreq;\r
-\r
-#ifdef MDE_CPU_ARM\r
-  MultU64xN = MultU64x32;\r
-#else\r
-  MultU64xN = MultU64x64;\r
-#endif\r
-\r
-  TimerFreq = PcdGet32 (PcdArmArchTimerFreqInHz);\r
-  if (TimerFreq == 0) {\r
-    TimerFreq = ArmGenericTimerGetTimerFreq ();\r
-  }\r
 \r
   // Calculate counter ticks that can represent requested delay:\r
   //  = MicroSeconds x TICKS_PER_MICRO_SEC\r
@@ -117,7 +130,7 @@ MicroSecondDelay (
   TimerTicks64 = DivU64x32 (\r
                    MultU64xN (\r
                      MicroSeconds,\r
-                     TimerFreq\r
+                     GetPlatformTimerFreq ()\r
                      ),\r
                    1000000U\r
                    );\r