]>
Commit | Line | Data |
---|---|---|
1ef41207 | 1 | /** @file\r |
2 | A non-functional instance of the Timer Library.\r | |
3 | \r | |
4 | Copyright (c) 2007 - 2010, 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 <PiPei.h>\r | |
16 | #include <Library/TimerLib.h>\r | |
17 | #include <Library/DebugLib.h>\r | |
18 | #include <Library/PeiServicesLib.h>\r | |
19 | \r | |
20 | #include <Ppi/EmuThunk.h>\r | |
21 | #include <Protocol/EmuThunk.h>\r | |
22 | \r | |
23 | /**\r | |
24 | Stalls the CPU for at least the given number of microseconds.\r | |
25 | \r | |
26 | Stalls the CPU for the number of microseconds specified by MicroSeconds.\r | |
27 | \r | |
28 | @param MicroSeconds The minimum number of microseconds to delay.\r | |
29 | \r | |
30 | @return The value of MicroSeconds inputted.\r | |
31 | \r | |
32 | **/\r | |
33 | UINTN\r | |
34 | EFIAPI\r | |
35 | MicroSecondDelay (\r | |
36 | IN UINTN MicroSeconds\r | |
37 | )\r | |
38 | {\r | |
39 | return NanoSecondDelay (MicroSeconds * 1000);\r | |
40 | }\r | |
41 | \r | |
42 | /**\r | |
43 | Stalls the CPU for at least the given number of nanoseconds.\r | |
44 | \r | |
45 | Stalls the CPU for the number of nanoseconds specified by NanoSeconds.\r | |
46 | \r | |
47 | @param NanoSeconds The minimum number of nanoseconds to delay.\r | |
48 | \r | |
49 | @return The value of NanoSeconds inputted.\r | |
50 | \r | |
51 | **/\r | |
52 | UINTN\r | |
53 | EFIAPI\r | |
54 | NanoSecondDelay (\r | |
55 | IN UINTN NanoSeconds\r | |
56 | )\r | |
57 | {\r | |
58 | EMU_THUNK_PPI *ThunkPpi;\r | |
59 | EFI_STATUS Status;\r | |
60 | EMU_THUNK_PROTOCOL *Thunk;\r | |
61 | \r | |
62 | //\r | |
d18d8a1d | 63 | // Locate EmuThunkPpi for\r |
1ef41207 | 64 | //\r |
65 | Status = PeiServicesLocatePpi (\r | |
66 | &gEmuThunkPpiGuid,\r | |
67 | 0,\r | |
68 | NULL,\r | |
69 | (VOID **) &ThunkPpi\r | |
70 | );\r | |
d18d8a1d | 71 | if (!EFI_ERROR (Status)) {\r |
1ef41207 | 72 | Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();\r |
73 | Thunk->Sleep (NanoSeconds * 100);\r | |
74 | return NanoSeconds;\r | |
75 | }\r | |
76 | \r | |
77 | return 0;\r | |
78 | }\r | |
79 | \r | |
80 | /**\r | |
81 | Retrieves the current value of a 64-bit free running performance counter.\r | |
82 | \r | |
83 | The counter can either count up by 1 or count down by 1. If the physical\r | |
84 | performance counter counts by a larger increment, then the counter values\r | |
85 | must be translated. The properties of the counter can be retrieved from\r | |
86 | GetPerformanceCounterProperties().\r | |
87 | \r | |
88 | @return The current value of the free running performance counter.\r | |
89 | \r | |
90 | **/\r | |
91 | UINT64\r | |
92 | EFIAPI\r | |
93 | GetPerformanceCounter (\r | |
94 | VOID\r | |
95 | )\r | |
96 | {\r | |
97 | EMU_THUNK_PPI *ThunkPpi;\r | |
98 | EFI_STATUS Status;\r | |
99 | EMU_THUNK_PROTOCOL *Thunk;\r | |
100 | \r | |
101 | //\r | |
d18d8a1d | 102 | // Locate EmuThunkPpi for\r |
1ef41207 | 103 | //\r |
104 | Status = PeiServicesLocatePpi (\r | |
105 | &gEmuThunkPpiGuid,\r | |
106 | 0,\r | |
107 | NULL,\r | |
108 | (VOID **) &ThunkPpi\r | |
109 | );\r | |
d18d8a1d | 110 | if (!EFI_ERROR (Status)) {\r |
1ef41207 | 111 | Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();\r |
112 | return Thunk->QueryPerformanceCounter ();\r | |
113 | }\r | |
114 | \r | |
115 | return 0;\r | |
116 | }\r | |
117 | \r | |
118 | /**\r | |
119 | Retrieves the 64-bit frequency in Hz and the range of performance counter\r | |
120 | values.\r | |
121 | \r | |
122 | If StartValue is not NULL, then the value that the performance counter starts\r | |
123 | with immediately after is it rolls over is returned in StartValue. If\r | |
124 | EndValue is not NULL, then the value that the performance counter end with\r | |
125 | immediately before it rolls over is returned in EndValue. The 64-bit\r | |
126 | frequency of the performance counter in Hz is always returned. If StartValue\r | |
127 | is less than EndValue, then the performance counter counts up. If StartValue\r | |
128 | is greater than EndValue, then the performance counter counts down. For\r | |
129 | example, a 64-bit free running counter that counts up would have a StartValue\r | |
130 | of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter\r | |
131 | that counts down would have a StartValue of 0xFFFFFF and an EndValue of 0.\r | |
132 | \r | |
133 | @param StartValue The value the performance counter starts with when it\r | |
134 | rolls over.\r | |
135 | @param EndValue The value that the performance counter ends with before\r | |
136 | it rolls over.\r | |
137 | \r | |
138 | @return The frequency in Hz.\r | |
139 | \r | |
140 | **/\r | |
141 | UINT64\r | |
142 | EFIAPI\r | |
143 | GetPerformanceCounterProperties (\r | |
144 | OUT UINT64 *StartValue, OPTIONAL\r | |
145 | OUT UINT64 *EndValue OPTIONAL\r | |
146 | )\r | |
147 | {\r | |
148 | EMU_THUNK_PPI *ThunkPpi;\r | |
149 | EFI_STATUS Status;\r | |
150 | EMU_THUNK_PROTOCOL *Thunk;\r | |
151 | \r | |
152 | //\r | |
d18d8a1d | 153 | // Locate EmuThunkPpi for\r |
1ef41207 | 154 | //\r |
155 | Status = PeiServicesLocatePpi (\r | |
156 | &gEmuThunkPpiGuid,\r | |
157 | 0,\r | |
158 | NULL,\r | |
159 | (VOID **) &ThunkPpi\r | |
160 | );\r | |
161 | if (!EFI_ERROR (Status)) {\r | |
162 | if (StartValue != NULL) {\r | |
163 | *StartValue = 0ULL;\r | |
164 | }\r | |
165 | if (EndValue != NULL) {\r | |
166 | *EndValue = (UINT64)-1LL;\r | |
167 | }\r | |
d18d8a1d | 168 | \r |
1ef41207 | 169 | Thunk = (EMU_THUNK_PROTOCOL *)ThunkPpi->Thunk ();\r |
170 | return Thunk->QueryPerformanceFrequency ();\r | |
171 | }\r | |
172 | \r | |
173 | return 0;\r | |
174 | }\r |