summaryrefslogtreecommitdiff
path: root/UefiCpuPkg/Library
diff options
context:
space:
mode:
authorJeff Fan <jeff.fan@intel.com>2013-08-27 07:29:45 +0000
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2013-08-27 07:29:45 +0000
commit253fcc8bdc94cc77f043c63b02071fb173413a6c (patch)
tree701e29f002c3be9c24bf0ff342d1914db3fa7edc /UefiCpuPkg/Library
parent3eb695cfb71b9ef0cb7de2a1d18c324fa7eb244e (diff)
downloadedk2-platforms-253fcc8bdc94cc77f043c63b02071fb173413a6c.tar.xz
Removed the assumption on APIC timer initial Count is all 1s and updated it to handle the long delay that timer initial count.
Signed-off-by: Jeff Fan <jeff.fan@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14604 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'UefiCpuPkg/Library')
-rw-r--r--UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/X86TimerLib.c53
1 files changed, 38 insertions, 15 deletions
diff --git a/UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/X86TimerLib.c b/UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/X86TimerLib.c
index 99f8121eed..52ae7717dd 100644
--- a/UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/X86TimerLib.c
+++ b/UefiCpuPkg/Library/SecPeiDxeTimerLibUefiCpu/X86TimerLib.c
@@ -3,7 +3,7 @@
This library uses the local APIC library so that it supports x2APIC mode.
- Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
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
@@ -55,22 +55,49 @@ InternalX86Delay (
)
{
INT32 Ticks;
- UINT32 PowerOfTwoCounter;
+ UINT32 Times;
+ UINT32 InitCount;
+ UINT32 StartTick;
//
- // The target timer count is calculated here
+ // In case Delay is too larger, separate it into several small delay slot.
+ // Devided Delay by half value of Init Count is to avoid Delay close to
+ // the Init Count, timeout maybe missing if the time consuming between 2
+ // GetApicTimerCurrentCount() invoking is larger than the time gap between
+ // Delay and the Init Count.
//
- Ticks = GetApicTimerCurrentCount () - Delay;
+ InitCount = GetApicTimerInitCount ();
+ Times = Delay / (InitCount / 2);
+ Delay = Delay % (InitCount / 2);
//
- // Wait until time out
- // Delay > 2^31 could not be handled by this function
- // Timer wrap-arounds are handled correctly by this function
+ // Get Start Tick and do delay
//
- PowerOfTwoCounter = GetPowerOfTwo32 (GetApicTimerInitCount ());
- while (((UINT32)(GetApicTimerCurrentCount () - Ticks) & PowerOfTwoCounter) == 0) {
- CpuPause ();
- }
+ StartTick = GetApicTimerCurrentCount ();
+ do {
+ //
+ // Wait until time out by Delay value
+ //
+ do {
+ CpuPause ();
+ //
+ // Get Ticks from Start to Current.
+ //
+ Ticks = StartTick - GetApicTimerCurrentCount ();
+ //
+ // Ticks < 0 means Timer wrap-arounds happens.
+ //
+ if (Ticks < 0) {
+ Ticks += InitCount;
+ }
+ } while ((UINT32)Ticks < Delay);
+
+ //
+ // Update StartTick and Delay for next delay slot
+ //
+ StartTick -= (StartTick > Delay) ? Delay : (Delay - InitCount);
+ Delay = InitCount / 2;
+ } while (Times-- > 0);
}
/**
@@ -181,10 +208,6 @@ GetPerformanceCounterProperties (
{
if (StartValue != NULL) {
*StartValue = (UINT64)GetApicTimerInitCount ();
- //
- // make sure StartValue is all 1s from High Bit
- //
- ASSERT ((*StartValue & (*StartValue + 1)) == 0);
}
if (EndValue != NULL) {