https://bugzilla.tianocore.org/show_bug.cgi?id=1373 Replace BSD 2-Clause License with BSD+Patent License. This change is based on the following emails: https://lists.01.org/pipermail/edk2-devel/2019-February/036260.html https://lists.01.org/pipermail/edk2-devel/2018-October/030385.html RFCs with detailed process for the license change: V3: https://lists.01.org/pipermail/edk2-devel/2019-March/038116.html V2: https://lists.01.org/pipermail/edk2-devel/2019-March/037669.html V1: https://lists.01.org/pipermail/edk2-devel/2019-March/037500.html Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Eric Dong <eric.dong@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
		
			
				
	
	
		
			111 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			111 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/** @file
 | 
						|
SMM Timer feature support
 | 
						|
 | 
						|
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
 | 
						|
SPDX-License-Identifier: BSD-2-Clause-Patent
 | 
						|
 | 
						|
**/
 | 
						|
 | 
						|
#include "PiSmmCpuDxeSmm.h"
 | 
						|
 | 
						|
UINT64   mTimeoutTicker = 0;
 | 
						|
//
 | 
						|
//  Number of counts in a roll-over cycle of the performance counter.
 | 
						|
//
 | 
						|
UINT64   mCycle = 0;
 | 
						|
//
 | 
						|
// Flag to indicate the performance counter is count-up or count-down.
 | 
						|
//
 | 
						|
BOOLEAN  mCountDown;
 | 
						|
 | 
						|
/**
 | 
						|
  Initialize Timer for SMM AP Sync.
 | 
						|
 | 
						|
**/
 | 
						|
VOID
 | 
						|
InitializeSmmTimer (
 | 
						|
  VOID
 | 
						|
  )
 | 
						|
{
 | 
						|
  UINT64  TimerFrequency;
 | 
						|
  UINT64  Start;
 | 
						|
  UINT64  End;
 | 
						|
 | 
						|
  TimerFrequency = GetPerformanceCounterProperties (&Start, &End);
 | 
						|
  mTimeoutTicker = DivU64x32 (
 | 
						|
                     MultU64x64(TimerFrequency, PcdGet64 (PcdCpuSmmApSyncTimeout)),
 | 
						|
                     1000 * 1000
 | 
						|
                     );
 | 
						|
  if (End < Start) {
 | 
						|
    mCountDown = TRUE;
 | 
						|
    mCycle = Start - End;
 | 
						|
  } else {
 | 
						|
    mCountDown = FALSE;
 | 
						|
    mCycle = End - Start;
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
/**
 | 
						|
  Start Timer for SMM AP Sync.
 | 
						|
 | 
						|
**/
 | 
						|
UINT64
 | 
						|
EFIAPI
 | 
						|
StartSyncTimer (
 | 
						|
  VOID
 | 
						|
  )
 | 
						|
{
 | 
						|
  return GetPerformanceCounter ();
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/**
 | 
						|
  Check if the SMM AP Sync timer is timeout.
 | 
						|
 | 
						|
  @param Timer  The start timer from the begin.
 | 
						|
 | 
						|
**/
 | 
						|
BOOLEAN
 | 
						|
EFIAPI
 | 
						|
IsSyncTimerTimeout (
 | 
						|
  IN      UINT64                    Timer
 | 
						|
  )
 | 
						|
{
 | 
						|
  UINT64  CurrentTimer;
 | 
						|
  UINT64  Delta;
 | 
						|
 | 
						|
  CurrentTimer = GetPerformanceCounter ();
 | 
						|
  //
 | 
						|
  // We need to consider the case that CurrentTimer is equal to Timer
 | 
						|
  // when some timer runs too slow and CPU runs fast. We think roll over
 | 
						|
  // condition does not happen on this case.
 | 
						|
  //
 | 
						|
  if (mCountDown) {
 | 
						|
    //
 | 
						|
    // The performance counter counts down.  Check for roll over condition.
 | 
						|
    //
 | 
						|
    if (CurrentTimer <= Timer) {
 | 
						|
      Delta = Timer - CurrentTimer;
 | 
						|
    } else {
 | 
						|
      //
 | 
						|
      // Handle one roll-over.
 | 
						|
      //
 | 
						|
      Delta = mCycle - (CurrentTimer - Timer) + 1;
 | 
						|
    }
 | 
						|
  } else {
 | 
						|
    //
 | 
						|
    // The performance counter counts up.  Check for roll over condition.
 | 
						|
    //
 | 
						|
    if (CurrentTimer >= Timer) {
 | 
						|
      Delta = CurrentTimer - Timer;
 | 
						|
    } else {
 | 
						|
      //
 | 
						|
      // Handle one roll-over.
 | 
						|
      //
 | 
						|
      Delta = mCycle - (Timer - CurrentTimer) + 1;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  return (BOOLEAN) (Delta >= mTimeoutTicker);
 | 
						|
}
 |