]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/PiSmmCpuDxeSmm/SyncTimer.c
BaseTools/BinToPcd: Fix Python 2.7.x compatibility issue
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / SyncTimer.c
CommitLineData
529a5a86
MK
1/** @file\r
2SMM Timer feature support\r
3\r
4Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "PiSmmCpuDxeSmm.h"\r
16\r
17UINT64 mTimeoutTicker = 0;\r
18//\r
19// Number of counts in a roll-over cycle of the performance counter.\r
20//\r
21UINT64 mCycle = 0;\r
22//\r
23// Flag to indicate the performance counter is count-up or count-down.\r
24//\r
25BOOLEAN mCountDown;\r
26\r
27/**\r
28 Initialize Timer for SMM AP Sync.\r
29\r
30**/\r
31VOID\r
32InitializeSmmTimer (\r
33 VOID\r
34 )\r
35{\r
36 UINT64 TimerFrequency;\r
37 UINT64 Start;\r
38 UINT64 End;\r
39\r
40 TimerFrequency = GetPerformanceCounterProperties (&Start, &End);\r
41 mTimeoutTicker = DivU64x32 (\r
42 MultU64x64(TimerFrequency, PcdGet64 (PcdCpuSmmApSyncTimeout)),\r
43 1000 * 1000\r
44 );\r
45 if (End < Start) {\r
46 mCountDown = TRUE;\r
47 mCycle = Start - End;\r
48 } else {\r
49 mCountDown = FALSE;\r
50 mCycle = End - Start;\r
51 }\r
52}\r
53\r
54/**\r
55 Start Timer for SMM AP Sync.\r
56\r
57**/\r
58UINT64\r
59EFIAPI\r
60StartSyncTimer (\r
61 VOID\r
62 )\r
63{\r
64 return GetPerformanceCounter ();\r
65}\r
66\r
67\r
68/**\r
69 Check if the SMM AP Sync timer is timeout.\r
70\r
71 @param Timer The start timer from the begin.\r
72\r
73**/\r
74BOOLEAN\r
75EFIAPI\r
76IsSyncTimerTimeout (\r
77 IN UINT64 Timer\r
78 )\r
79{\r
80 UINT64 CurrentTimer;\r
81 UINT64 Delta;\r
82\r
83 CurrentTimer = GetPerformanceCounter ();\r
84 //\r
85 // We need to consider the case that CurrentTimer is equal to Timer\r
86 // when some timer runs too slow and CPU runs fast. We think roll over\r
87 // condition does not happen on this case.\r
88 //\r
89 if (mCountDown) {\r
90 //\r
91 // The performance counter counts down. Check for roll over condition.\r
92 //\r
93 if (CurrentTimer <= Timer) {\r
94 Delta = Timer - CurrentTimer;\r
95 } else {\r
96 //\r
97 // Handle one roll-over.\r
98 //\r
99 Delta = mCycle - (CurrentTimer - Timer) + 1;\r
100 }\r
101 } else {\r
102 //\r
103 // The performance counter counts up. Check for roll over condition.\r
104 //\r
105 if (CurrentTimer >= Timer) {\r
106 Delta = CurrentTimer - Timer;\r
107 } else {\r
108 //\r
109 // Handle one roll-over.\r
110 //\r
111 Delta = mCycle - (Timer - CurrentTimer) + 1;\r
112 }\r
113 }\r
114\r
115 return (BOOLEAN) (Delta >= mTimeoutTicker);\r
116}\r