]>
Commit | Line | Data |
---|---|---|
529a5a86 MK |
1 | /** @file\r |
2 | SMM Timer feature support\r | |
3 | \r | |
4 | Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "PiSmmCpuDxeSmm.h"\r | |
16 | \r | |
17 | UINT64 mTimeoutTicker = 0;\r | |
18 | //\r | |
19 | // Number of counts in a roll-over cycle of the performance counter.\r | |
20 | //\r | |
21 | UINT64 mCycle = 0;\r | |
22 | //\r | |
23 | // Flag to indicate the performance counter is count-up or count-down.\r | |
24 | //\r | |
25 | BOOLEAN mCountDown;\r | |
26 | \r | |
27 | /**\r | |
28 | Initialize Timer for SMM AP Sync.\r | |
29 | \r | |
30 | **/\r | |
31 | VOID\r | |
32 | InitializeSmmTimer (\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 | |
58 | UINT64\r | |
59 | EFIAPI\r | |
60 | StartSyncTimer (\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 | |
74 | BOOLEAN\r | |
75 | EFIAPI\r | |
76 | IsSyncTimerTimeout (\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 |