summaryrefslogtreecommitdiffstats
path: root/ArmPkg
diff options
context:
space:
mode:
authorSami Mujawar <sami.mujawar@arm.com>2016-03-03 15:28:16 +0000
committerArd Biesheuvel <ard.biesheuvel@linaro.org>2016-04-01 15:52:17 +0200
commit96a80ae3ce24905539e0fbd55b398e4d8ec9f410 (patch)
treedf154826656dc754e50f725e1392bb4170b93e86 /ArmPkg
parentcbdece176953cf2be63b322f53600e2136b94744 (diff)
downloadedk2-96a80ae3ce24905539e0fbd55b398e4d8ec9f410.tar.gz
edk2-96a80ae3ce24905539e0fbd55b398e4d8ec9f410.tar.bz2
edk2-96a80ae3ce24905539e0fbd55b398e4d8ec9f410.zip
ArmPkg/ArmArchTimerLib: add GetTimeInNanoSecond() to ArmArchTimerLib
FirmwarePerformanceDxe.c utilizes the Timer Library function GetTimeInNanoSecond() which was not implemented by the ArmArchTimerLib. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Evan Lloyd <evan.lloyd@arm.com> Reviewed-by: Ryan Harkin <ryan.harkin@linaro.org> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Diffstat (limited to 'ArmPkg')
-rw-r--r--ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c
index 4361905e14..1be90c515c 100644
--- a/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c
+++ b/ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.c
@@ -1,7 +1,7 @@
/** @file
Generic ARM implementation of TimerLib.h
- Copyright (c) 2011-2014, ARM Limited. All rights reserved.
+ Copyright (c) 2011-2016, ARM Limited. All rights reserved.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -242,3 +242,52 @@ GetPerformanceCounterProperties (
return (UINT64)ArmGenericTimerGetTimerFreq ();
}
+
+/**
+ Converts elapsed ticks of performance counter to time in nanoseconds.
+
+ This function converts the elapsed ticks of running performance counter to
+ time value in unit of nanoseconds.
+
+ @param Ticks The number of elapsed ticks of running performance counter.
+
+ @return The elapsed time in nanoseconds.
+
+**/
+UINT64
+EFIAPI
+GetTimeInNanoSecond (
+ IN UINT64 Ticks
+ )
+{
+ UINT64 NanoSeconds;
+ UINT32 Remainder;
+ UINT32 TimerFreq;
+
+ TimerFreq = GetPlatformTimerFreq ();
+ //
+ // Ticks
+ // Time = --------- x 1,000,000,000
+ // Frequency
+ //
+ NanoSeconds = MultU64xN (
+ DivU64x32Remainder (
+ Ticks,
+ TimerFreq,
+ &Remainder),
+ 1000000000U
+ );
+
+ //
+ // Frequency < 0x100000000, so Remainder < 0x100000000, then (Remainder * 1,000,000,000)
+ // will not overflow 64-bit.
+ //
+ NanoSeconds += DivU64x32 (
+ MultU64xN (
+ (UINT64) Remainder,
+ 1000000000U),
+ TimerFreq
+ );
+
+ return NanoSeconds;
+}