TianoCore EDK2 master
Loading...
Searching...
No Matches
SyncTimer.c
Go to the documentation of this file.
1
9#include "PiSmmCpuCommon.h"
10
11UINT64 mTimeoutTicker = 0;
12
13UINT64 mTimeoutTicker2 = 0;
14
15//
16// Number of counts in a roll-over cycle of the performance counter.
17//
18UINT64 mCycle = 0;
19//
20// Flag to indicate the performance counter is count-up or count-down.
21//
22BOOLEAN mCountDown;
23
28VOID
30 VOID
31 )
32{
33 UINT64 TimerFrequency;
34 UINT64 SyncTimeout;
35 UINT64 SyncTimeout2;
36 UINT64 Start;
37 UINT64 End;
38
39 SyncTimeout = 0;
40 SyncTimeout2 = 0;
41 GetSmmCpuSyncConfigData (NULL, &SyncTimeout, &SyncTimeout2);
42
43 TimerFrequency = GetPerformanceCounterProperties (&Start, &End);
44 mTimeoutTicker = DivU64x32 (
45 MultU64x64 (TimerFrequency, SyncTimeout),
46 1000 * 1000
47 );
48 mTimeoutTicker2 = DivU64x32 (
49 MultU64x64 (TimerFrequency, SyncTimeout2),
50 1000 * 1000
51 );
52 if (End < Start) {
53 mCountDown = TRUE;
54 mCycle = Start - End;
55 } else {
56 mCountDown = FALSE;
57 mCycle = End - Start;
58 }
59}
60
65UINT64
66EFIAPI
68 VOID
69 )
70{
71 return GetPerformanceCounter ();
72}
73
81BOOLEAN
82EFIAPI
84 IN UINT64 Timer,
85 IN UINT64 Timeout
86 )
87{
88 UINT64 CurrentTimer;
89 UINT64 Delta;
90
91 CurrentTimer = GetPerformanceCounter ();
92 //
93 // We need to consider the case that CurrentTimer is equal to Timer
94 // when some timer runs too slow and CPU runs fast. We think roll over
95 // condition does not happen on this case.
96 //
97 if (mCountDown) {
98 //
99 // The performance counter counts down. Check for roll over condition.
100 //
101 if (CurrentTimer <= Timer) {
102 Delta = Timer - CurrentTimer;
103 } else {
104 //
105 // Handle one roll-over.
106 //
107 Delta = mCycle - (CurrentTimer - Timer) + 1;
108 }
109 } else {
110 //
111 // The performance counter counts up. Check for roll over condition.
112 //
113 if (CurrentTimer >= Timer) {
114 Delta = CurrentTimer - Timer;
115 } else {
116 //
117 // Handle one roll-over.
118 //
119 Delta = mCycle - (Timer - CurrentTimer) + 1;
120 }
121 }
122
123 return (BOOLEAN)(Delta >= Timeout);
124}
UINT64 EFIAPI GetPerformanceCounterProperties(OUT UINT64 *StartValue OPTIONAL, OUT UINT64 *EndValue OPTIONAL)
UINT64 EFIAPI GetPerformanceCounter(VOID)
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: DivU64x32.c:29
UINT64 EFIAPI MultU64x64(IN UINT64 Multiplicand, IN UINT64 Multiplier)
Definition: MultU64x64.c:27
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
VOID GetSmmCpuSyncConfigData(IN OUT BOOLEAN *RelaxedMode, OPTIONAL IN OUT UINT64 *SyncTimeout, OPTIONAL IN OUT UINT64 *SyncTimeout2 OPTIONAL)
UINT64 EFIAPI StartSyncTimer(VOID)
Definition: SyncTimer.c:67
VOID InitializeSmmTimer(VOID)
Definition: SyncTimer.c:29
BOOLEAN EFIAPI IsSyncTimerTimeout(IN UINT64 Timer, IN UINT64 Timeout)
Definition: SyncTimer.c:83