X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FSecPeiDxeTimerLibCpu%2FIpfTimerLib.c;h=714b99eec41431a6fca7fedfd29098df2d9d9346;hb=32eb6739b961a5b4cc204b94220fa5ad15f79a9b;hp=de78606b5e4509d0d2525e25add0d197614a8970;hpb=8cefc2ee7000517970c0755e5e80de4fb243d5d5;p=mirror_edk2.git diff --git a/MdePkg/Library/SecPeiDxeTimerLibCpu/IpfTimerLib.c b/MdePkg/Library/SecPeiDxeTimerLibCpu/IpfTimerLib.c index de78606b5e..714b99eec4 100644 --- a/MdePkg/Library/SecPeiDxeTimerLibCpu/IpfTimerLib.c +++ b/MdePkg/Library/SecPeiDxeTimerLibCpu/IpfTimerLib.c @@ -1,11 +1,11 @@ /** @file Timer Library functions built upon ITC on IPF. - Copyright (c) 2006 - 2008, Intel Corporation
- All rights reserved. This program and the accompanying materials + Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php + http://opensource.org/licenses/bsd-license.php. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @@ -15,7 +15,7 @@ #include #include #include -#include +#include /** @@ -24,7 +24,7 @@ An internal function to perform a delay measured as number of ticks. It's invoked by MicroSecondDelay() and NanoSecondDelay(). - @param Delay Number of ticks to delay. + @param Delay The number of ticks to delay. **/ VOID @@ -97,8 +97,9 @@ NanoSecondDelay ( } /** - Retrieves the current value of a 64-bit free running performance counter. The - counter can either count up by 1 or count down by 1. If the physical + Retrieves the current value of a 64-bit free running performance counter. + + The counter can either count up by 1 or count down by 1. If the physical performance counter counts by a larger increment, then the counter values must be translated. The properties of the counter can be retrieved from GetPerformanceCounterProperties(). @@ -169,3 +170,47 @@ GetPerformanceCounterProperties ( return BaseFrequence * (PalRet.r11 >> 32) / (UINT32)PalRet.r11; } + +/** + 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 Frequency; + UINT64 NanoSeconds; + UINT64 Remainder; + INTN Shift; + + Frequency = GetPerformanceCounterProperties (NULL, NULL); + + // + // Ticks + // Time = --------- x 1,000,000,000 + // Frequency + // + NanoSeconds = MultU64x32 (DivU64x64Remainder (Ticks, Frequency, &Remainder), 1000000000u); + + // + // Ensure (Remainder * 1,000,000,000) will not overflow 64-bit. + // Since 2^29 < 1,000,000,000 = 0x3B9ACA00 < 2^30, Remainder should < 2^(64-30) = 2^34, + // i.e. highest bit set in Remainder should <= 33. + // + Shift = MAX (0, HighBitSet64 (Remainder) - 33); + Remainder = RShiftU64 (Remainder, (UINTN) Shift); + Frequency = RShiftU64 (Frequency, (UINTN) Shift); + NanoSeconds += DivU64x64Remainder (MultU64x32 (Remainder, 1000000000u), Frequency, NULL); + + return NanoSeconds; +}