]>
Commit | Line | Data |
---|---|---|
d042c6e8 | 1 | /** @file\r |
2 | Performance library instance used by SMM Core.\r | |
3 | \r | |
4 | This library provides the performance measurement interfaces and initializes performance\r | |
5 | logging for the SMM phase.\r | |
f0da4d7d | 6 | It initializes SMM phase performance logging by publishing the SMM Performance and PerformanceEx Protocol,\r |
d042c6e8 | 7 | which is consumed by SmmPerformanceLib to logging performance data in SMM phase.\r |
8 | \r | |
9 | This library is mainly used by SMM Core to start performance logging to ensure that\r | |
f0da4d7d | 10 | SMM Performance and PerformanceEx Protocol are installed at the very beginning of SMM phase.\r |
d042c6e8 | 11 | \r |
ccd2f6b0 | 12 | Caution: This module requires additional review when modified.\r |
13 | This driver will have external input - performance data and communicate buffer in SMM mode.\r | |
14 | This external input must be validated carefully to avoid security issue like\r | |
15 | buffer overflow, integer overflow.\r | |
16 | \r | |
17 | SmmPerformanceHandlerEx(), SmmPerformanceHandler() will receive untrusted input and do basic validation.\r | |
18 | \r | |
9d00d20e | 19 | Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\r |
d042c6e8 | 20 | This program and the accompanying materials\r |
21 | are licensed and made available under the terms and conditions of the BSD License\r | |
22 | which accompanies this distribution. The full text of the license may be found at\r | |
23 | http://opensource.org/licenses/bsd-license.php\r | |
24 | \r | |
25 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
26 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
27 | \r | |
28 | **/\r | |
29 | \r | |
30 | \r | |
31 | #include "SmmCorePerformanceLibInternal.h"\r | |
32 | \r | |
33 | //\r | |
34 | // The data structure to hold global performance data.\r | |
35 | //\r | |
36 | GAUGE_DATA_HEADER *mGaugeData;\r | |
37 | \r | |
38 | //\r | |
39 | // The current maximum number of logging entries. If current number of \r | |
40 | // entries exceeds this value, it will re-allocate a larger array and\r | |
41 | // migration the old data to the larger array.\r | |
42 | //\r | |
43 | UINT32 mMaxGaugeRecords;\r | |
44 | \r | |
45 | //\r | |
46 | // The handle to install Performance Protocol instance.\r | |
47 | //\r | |
48 | EFI_HANDLE mHandle = NULL;\r | |
49 | \r | |
50 | BOOLEAN mPerformanceMeasurementEnabled;\r | |
51 | \r | |
52 | SPIN_LOCK mSmmPerfLock;\r | |
53 | \r | |
54 | EFI_SMRAM_DESCRIPTOR *mSmramRanges;\r | |
55 | UINTN mSmramRangeCount;\r | |
56 | \r | |
57 | //\r | |
f0da4d7d | 58 | // Interfaces for SMM Performance Protocol.\r |
d042c6e8 | 59 | //\r |
60 | PERFORMANCE_PROTOCOL mPerformanceInterface = {\r | |
61 | StartGauge,\r | |
62 | EndGauge,\r | |
63 | GetGauge\r | |
64 | };\r | |
65 | \r | |
f0da4d7d SZ |
66 | //\r |
67 | // Interfaces for SMM PerformanceEx Protocol.\r | |
68 | //\r | |
69 | PERFORMANCE_EX_PROTOCOL mPerformanceExInterface = {\r | |
70 | StartGaugeEx,\r | |
71 | EndGaugeEx,\r | |
72 | GetGaugeEx\r | |
73 | };\r | |
74 | \r | |
d042c6e8 | 75 | /**\r |
f0da4d7d | 76 | Searches in the gauge array with keyword Handle, Token, Module and Identfier.\r |
d042c6e8 | 77 | \r |
78 | This internal function searches for the gauge entry in the gauge array.\r | |
f0da4d7d | 79 | If there is an entry that exactly matches the given keywords\r |
d042c6e8 | 80 | and its end time stamp is zero, then the index of that gauge entry is returned;\r |
81 | otherwise, the the number of gauge entries in the array is returned.\r | |
82 | \r | |
83 | @param Handle Pointer to environment specific context used\r | |
84 | to identify the component being measured.\r | |
85 | @param Token Pointer to a Null-terminated ASCII string\r | |
86 | that identifies the component being measured.\r | |
87 | @param Module Pointer to a Null-terminated ASCII string\r | |
88 | that identifies the module being measured.\r | |
f0da4d7d | 89 | @param Identifier 32-bit identifier.\r |
d042c6e8 | 90 | \r |
91 | @retval The index of gauge entry in the array.\r | |
92 | \r | |
93 | **/\r | |
94 | UINT32\r | |
95 | SmmSearchForGaugeEntry (\r | |
96 | IN CONST VOID *Handle, OPTIONAL\r | |
97 | IN CONST CHAR8 *Token, OPTIONAL\r | |
f0da4d7d SZ |
98 | IN CONST CHAR8 *Module, OPTIONAL\r |
99 | IN CONST UINT32 Identifier\r | |
d042c6e8 | 100 | )\r |
101 | {\r | |
102 | UINT32 Index;\r | |
b504f519 | 103 | UINT32 Index2;\r |
d042c6e8 | 104 | UINT32 NumberOfEntries;\r |
f0da4d7d | 105 | GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r |
d042c6e8 | 106 | \r |
107 | if (Token == NULL) {\r | |
108 | Token = "";\r | |
109 | }\r | |
110 | if (Module == NULL) {\r | |
111 | Module = "";\r | |
112 | }\r | |
113 | \r | |
114 | NumberOfEntries = mGaugeData->NumberOfEntries;\r | |
f0da4d7d | 115 | GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r |
d042c6e8 | 116 | \r |
b504f519 SZ |
117 | Index2 = 0;\r |
118 | \r | |
d042c6e8 | 119 | for (Index = 0; Index < NumberOfEntries; Index++) {\r |
b504f519 SZ |
120 | Index2 = NumberOfEntries - 1 - Index;\r |
121 | if (GaugeEntryExArray[Index2].EndTimeStamp == 0 &&\r | |
122 | (GaugeEntryExArray[Index2].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r | |
123 | AsciiStrnCmp (GaugeEntryExArray[Index2].Token, Token, SMM_PERFORMANCE_STRING_LENGTH) == 0 &&\r | |
124 | AsciiStrnCmp (GaugeEntryExArray[Index2].Module, Module, SMM_PERFORMANCE_STRING_LENGTH) == 0 &&\r | |
125 | (GaugeEntryExArray[Index2].Identifier == Identifier)) {\r | |
126 | Index = Index2;\r | |
d042c6e8 | 127 | break;\r |
128 | }\r | |
129 | }\r | |
130 | \r | |
131 | return Index;\r | |
132 | }\r | |
133 | \r | |
134 | /**\r | |
135 | Adds a record at the end of the performance measurement log\r | |
136 | that records the start time of a performance measurement.\r | |
137 | \r | |
138 | Adds a record to the end of the performance measurement log\r | |
f0da4d7d | 139 | that contains the Handle, Token, Module and Identifier.\r |
d042c6e8 | 140 | The end time of the new record must be set to zero.\r |
141 | If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r | |
142 | If TimeStamp is zero, the start time in the record is filled in with the value\r | |
143 | read from the current time stamp.\r | |
144 | \r | |
145 | @param Handle Pointer to environment specific context used\r | |
146 | to identify the component being measured.\r | |
147 | @param Token Pointer to a Null-terminated ASCII string\r | |
148 | that identifies the component being measured.\r | |
149 | @param Module Pointer to a Null-terminated ASCII string\r | |
150 | that identifies the module being measured.\r | |
151 | @param TimeStamp 64-bit time stamp.\r | |
f0da4d7d SZ |
152 | @param Identifier 32-bit identifier. If the value is 0, the created record\r |
153 | is same as the one created by StartGauge of PERFORMANCE_PROTOCOL.\r | |
d042c6e8 | 154 | \r |
155 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
156 | @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r | |
157 | \r | |
158 | **/\r | |
159 | EFI_STATUS\r | |
160 | EFIAPI\r | |
f0da4d7d | 161 | StartGaugeEx (\r |
d042c6e8 | 162 | IN CONST VOID *Handle, OPTIONAL\r |
163 | IN CONST CHAR8 *Token, OPTIONAL\r | |
164 | IN CONST CHAR8 *Module, OPTIONAL\r | |
f0da4d7d SZ |
165 | IN UINT64 TimeStamp,\r |
166 | IN UINT32 Identifier\r | |
d042c6e8 | 167 | )\r |
168 | {\r | |
f0da4d7d | 169 | GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r |
d042c6e8 | 170 | UINTN GaugeDataSize;\r |
f0da4d7d | 171 | GAUGE_DATA_HEADER *NewGaugeData;\r |
d042c6e8 | 172 | UINTN OldGaugeDataSize;\r |
173 | GAUGE_DATA_HEADER *OldGaugeData;\r | |
174 | UINT32 Index;\r | |
175 | \r | |
176 | AcquireSpinLock (&mSmmPerfLock);\r | |
177 | \r | |
178 | Index = mGaugeData->NumberOfEntries;\r | |
179 | if (Index >= mMaxGaugeRecords) {\r | |
180 | //\r | |
181 | // Try to enlarge the scale of gauge array.\r | |
182 | //\r | |
183 | OldGaugeData = mGaugeData;\r | |
f0da4d7d | 184 | OldGaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords;\r |
d042c6e8 | 185 | \r |
f0da4d7d | 186 | GaugeDataSize = sizeof (GAUGE_DATA_HEADER) + sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords * 2;\r |
d042c6e8 | 187 | \r |
f0da4d7d SZ |
188 | NewGaugeData = AllocateZeroPool (GaugeDataSize);\r |
189 | if (NewGaugeData == NULL) {\r | |
190 | ReleaseSpinLock (&mSmmPerfLock);\r | |
d042c6e8 | 191 | return EFI_OUT_OF_RESOURCES;\r |
192 | }\r | |
f0da4d7d SZ |
193 | \r |
194 | mGaugeData = NewGaugeData;\r | |
195 | mMaxGaugeRecords *= 2;\r | |
196 | \r | |
d042c6e8 | 197 | //\r |
198 | // Initialize new data array and migrate old data one.\r | |
199 | //\r | |
200 | mGaugeData = CopyMem (mGaugeData, OldGaugeData, OldGaugeDataSize);\r | |
201 | \r | |
202 | FreePool (OldGaugeData);\r | |
203 | }\r | |
204 | \r | |
f0da4d7d SZ |
205 | GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r |
206 | GaugeEntryExArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r | |
d042c6e8 | 207 | \r |
208 | if (Token != NULL) {\r | |
f0da4d7d | 209 | AsciiStrnCpy (GaugeEntryExArray[Index].Token, Token, SMM_PERFORMANCE_STRING_LENGTH);\r |
d042c6e8 | 210 | }\r |
211 | if (Module != NULL) {\r | |
f0da4d7d | 212 | AsciiStrnCpy (GaugeEntryExArray[Index].Module, Module, SMM_PERFORMANCE_STRING_LENGTH);\r |
d042c6e8 | 213 | }\r |
214 | \r | |
f0da4d7d SZ |
215 | GaugeEntryExArray[Index].EndTimeStamp = 0;\r |
216 | GaugeEntryExArray[Index].Identifier = Identifier;\r | |
217 | \r | |
d042c6e8 | 218 | if (TimeStamp == 0) {\r |
219 | TimeStamp = GetPerformanceCounter ();\r | |
220 | }\r | |
f0da4d7d | 221 | GaugeEntryExArray[Index].StartTimeStamp = TimeStamp;\r |
d042c6e8 | 222 | \r |
223 | mGaugeData->NumberOfEntries++;\r | |
224 | \r | |
225 | ReleaseSpinLock (&mSmmPerfLock);\r | |
226 | \r | |
227 | return EFI_SUCCESS;\r | |
228 | }\r | |
229 | \r | |
230 | /**\r | |
231 | Searches the performance measurement log from the beginning of the log\r | |
232 | for the first matching record that contains a zero end time and fills in a valid end time.\r | |
233 | \r | |
234 | Searches the performance measurement log from the beginning of the log\r | |
f0da4d7d | 235 | for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.\r |
d042c6e8 | 236 | If the record can not be found then return EFI_NOT_FOUND.\r |
237 | If the record is found and TimeStamp is not zero,\r | |
238 | then the end time in the record is filled in with the value specified by TimeStamp.\r | |
239 | If the record is found and TimeStamp is zero, then the end time in the matching record\r | |
240 | is filled in with the current time stamp value.\r | |
241 | \r | |
242 | @param Handle Pointer to environment specific context used\r | |
243 | to identify the component being measured.\r | |
244 | @param Token Pointer to a Null-terminated ASCII string\r | |
245 | that identifies the component being measured.\r | |
246 | @param Module Pointer to a Null-terminated ASCII string\r | |
247 | that identifies the module being measured.\r | |
248 | @param TimeStamp 64-bit time stamp.\r | |
f0da4d7d SZ |
249 | @param Identifier 32-bit identifier. If the value is 0, the found record\r |
250 | is same as the one found by EndGauge of PERFORMANCE_PROTOCOL.\r | |
d042c6e8 | 251 | \r |
252 | @retval EFI_SUCCESS The end of the measurement was recorded.\r | |
253 | @retval EFI_NOT_FOUND The specified measurement record could not be found.\r | |
254 | \r | |
255 | **/\r | |
256 | EFI_STATUS\r | |
257 | EFIAPI\r | |
f0da4d7d | 258 | EndGaugeEx (\r |
d042c6e8 | 259 | IN CONST VOID *Handle, OPTIONAL\r |
260 | IN CONST CHAR8 *Token, OPTIONAL\r | |
261 | IN CONST CHAR8 *Module, OPTIONAL\r | |
f0da4d7d SZ |
262 | IN UINT64 TimeStamp,\r |
263 | IN UINT32 Identifier\r | |
d042c6e8 | 264 | )\r |
265 | {\r | |
f0da4d7d SZ |
266 | GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r |
267 | UINT32 Index;\r | |
268 | \r | |
269 | AcquireSpinLock (&mSmmPerfLock);\r | |
d042c6e8 | 270 | \r |
271 | if (TimeStamp == 0) {\r | |
272 | TimeStamp = GetPerformanceCounter ();\r | |
273 | }\r | |
274 | \r | |
f0da4d7d | 275 | Index = SmmSearchForGaugeEntry (Handle, Token, Module, Identifier);\r |
d042c6e8 | 276 | if (Index >= mGaugeData->NumberOfEntries) {\r |
f0da4d7d | 277 | ReleaseSpinLock (&mSmmPerfLock);\r |
d042c6e8 | 278 | return EFI_NOT_FOUND;\r |
279 | }\r | |
f0da4d7d SZ |
280 | GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r |
281 | GaugeEntryExArray[Index].EndTimeStamp = TimeStamp;\r | |
282 | \r | |
283 | ReleaseSpinLock (&mSmmPerfLock);\r | |
d042c6e8 | 284 | \r |
285 | return EFI_SUCCESS;\r | |
286 | }\r | |
287 | \r | |
288 | /**\r | |
289 | Retrieves a previously logged performance measurement.\r | |
f0da4d7d SZ |
290 | It can also retrieve the log created by StartGauge and EndGauge of PERFORMANCE_PROTOCOL,\r |
291 | and then assign the Identifier with 0.\r | |
d042c6e8 | 292 | \r |
293 | Retrieves the performance log entry from the performance log specified by LogEntryKey.\r | |
294 | If it stands for a valid entry, then EFI_SUCCESS is returned and\r | |
f0da4d7d | 295 | GaugeDataEntryEx stores the pointer to that entry.\r |
d042c6e8 | 296 | \r |
297 | @param LogEntryKey The key for the previous performance measurement log entry.\r | |
298 | If 0, then the first performance measurement log entry is retrieved.\r | |
f0da4d7d | 299 | @param GaugeDataEntryEx The indirect pointer to the extended gauge data entry specified by LogEntryKey\r |
d042c6e8 | 300 | if the retrieval is successful.\r |
301 | \r | |
f0da4d7d | 302 | @retval EFI_SUCCESS The GuageDataEntryEx is successfully found based on LogEntryKey.\r |
d042c6e8 | 303 | @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).\r |
304 | @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).\r | |
f0da4d7d | 305 | @retval EFI_INVALIDE_PARAMETER GaugeDataEntryEx is NULL.\r |
d042c6e8 | 306 | \r |
307 | **/\r | |
308 | EFI_STATUS\r | |
309 | EFIAPI\r | |
f0da4d7d SZ |
310 | GetGaugeEx (\r |
311 | IN UINTN LogEntryKey,\r | |
312 | OUT GAUGE_DATA_ENTRY_EX **GaugeDataEntryEx\r | |
d042c6e8 | 313 | )\r |
314 | {\r | |
315 | UINTN NumberOfEntries;\r | |
f0da4d7d | 316 | GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r |
d042c6e8 | 317 | \r |
318 | NumberOfEntries = (UINTN) (mGaugeData->NumberOfEntries);\r | |
319 | if (LogEntryKey > NumberOfEntries) {\r | |
320 | return EFI_INVALID_PARAMETER;\r | |
321 | }\r | |
322 | if (LogEntryKey == NumberOfEntries) {\r | |
323 | return EFI_NOT_FOUND;\r | |
324 | }\r | |
325 | \r | |
f0da4d7d | 326 | GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r |
d042c6e8 | 327 | \r |
f0da4d7d | 328 | if (GaugeDataEntryEx == NULL) {\r |
d042c6e8 | 329 | return EFI_INVALID_PARAMETER;\r |
330 | }\r | |
f0da4d7d | 331 | *GaugeDataEntryEx = &GaugeEntryExArray[LogEntryKey];\r |
d042c6e8 | 332 | \r |
333 | return EFI_SUCCESS;\r | |
334 | }\r | |
335 | \r | |
f0da4d7d SZ |
336 | /**\r |
337 | Adds a record at the end of the performance measurement log\r | |
338 | that records the start time of a performance measurement.\r | |
339 | \r | |
340 | Adds a record to the end of the performance measurement log\r | |
341 | that contains the Handle, Token, and Module.\r | |
342 | The end time of the new record must be set to zero.\r | |
343 | If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r | |
344 | If TimeStamp is zero, the start time in the record is filled in with the value\r | |
345 | read from the current time stamp.\r | |
346 | \r | |
347 | @param Handle Pointer to environment specific context used\r | |
348 | to identify the component being measured.\r | |
349 | @param Token Pointer to a Null-terminated ASCII string\r | |
350 | that identifies the component being measured.\r | |
351 | @param Module Pointer to a Null-terminated ASCII string\r | |
352 | that identifies the module being measured.\r | |
353 | @param TimeStamp 64-bit time stamp.\r | |
354 | \r | |
355 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
356 | @retval EFI_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r | |
357 | \r | |
358 | **/\r | |
359 | EFI_STATUS\r | |
360 | EFIAPI\r | |
361 | StartGauge (\r | |
362 | IN CONST VOID *Handle, OPTIONAL\r | |
363 | IN CONST CHAR8 *Token, OPTIONAL\r | |
364 | IN CONST CHAR8 *Module, OPTIONAL\r | |
365 | IN UINT64 TimeStamp\r | |
366 | )\r | |
367 | {\r | |
368 | return StartGaugeEx (Handle, Token, Module, TimeStamp, 0);\r | |
369 | }\r | |
370 | \r | |
371 | /**\r | |
372 | Searches the performance measurement log from the beginning of the log\r | |
373 | for the first matching record that contains a zero end time and fills in a valid end time.\r | |
374 | \r | |
375 | Searches the performance measurement log from the beginning of the log\r | |
376 | for the first record that matches Handle, Token, and Module and has an end time value of zero.\r | |
377 | If the record can not be found then return EFI_NOT_FOUND.\r | |
378 | If the record is found and TimeStamp is not zero,\r | |
379 | then the end time in the record is filled in with the value specified by TimeStamp.\r | |
380 | If the record is found and TimeStamp is zero, then the end time in the matching record\r | |
381 | is filled in with the current time stamp value.\r | |
382 | \r | |
383 | @param Handle Pointer to environment specific context used\r | |
384 | to identify the component being measured.\r | |
385 | @param Token Pointer to a Null-terminated ASCII string\r | |
386 | that identifies the component being measured.\r | |
387 | @param Module Pointer to a Null-terminated ASCII string\r | |
388 | that identifies the module being measured.\r | |
389 | @param TimeStamp 64-bit time stamp.\r | |
390 | \r | |
391 | @retval EFI_SUCCESS The end of the measurement was recorded.\r | |
392 | @retval EFI_NOT_FOUND The specified measurement record could not be found.\r | |
393 | \r | |
394 | **/\r | |
395 | EFI_STATUS\r | |
396 | EFIAPI\r | |
397 | EndGauge (\r | |
398 | IN CONST VOID *Handle, OPTIONAL\r | |
399 | IN CONST CHAR8 *Token, OPTIONAL\r | |
400 | IN CONST CHAR8 *Module, OPTIONAL\r | |
401 | IN UINT64 TimeStamp\r | |
402 | )\r | |
403 | {\r | |
404 | return EndGaugeEx (Handle, Token, Module, TimeStamp, 0);\r | |
405 | }\r | |
406 | \r | |
407 | /**\r | |
408 | Retrieves a previously logged performance measurement.\r | |
409 | It can also retrieve the log created by StartGaugeEx and EndGaugeEx of PERFORMANCE_EX_PROTOCOL,\r | |
410 | and then eliminate the Identifier.\r | |
411 | \r | |
412 | Retrieves the performance log entry from the performance log specified by LogEntryKey.\r | |
413 | If it stands for a valid entry, then EFI_SUCCESS is returned and\r | |
414 | GaugeDataEntry stores the pointer to that entry.\r | |
415 | \r | |
416 | @param LogEntryKey The key for the previous performance measurement log entry.\r | |
417 | If 0, then the first performance measurement log entry is retrieved.\r | |
418 | @param GaugeDataEntry The indirect pointer to the gauge data entry specified by LogEntryKey\r | |
419 | if the retrieval is successful.\r | |
420 | \r | |
421 | @retval EFI_SUCCESS The GuageDataEntry is successfully found based on LogEntryKey.\r | |
422 | @retval EFI_NOT_FOUND The LogEntryKey is the last entry (equals to the total entry number).\r | |
423 | @retval EFI_INVALIDE_PARAMETER The LogEntryKey is not a valid entry (greater than the total entry number).\r | |
424 | @retval EFI_INVALIDE_PARAMETER GaugeDataEntry is NULL.\r | |
425 | \r | |
426 | **/\r | |
427 | EFI_STATUS\r | |
428 | EFIAPI\r | |
429 | GetGauge (\r | |
430 | IN UINTN LogEntryKey,\r | |
431 | OUT GAUGE_DATA_ENTRY **GaugeDataEntry\r | |
432 | )\r | |
433 | {\r | |
434 | EFI_STATUS Status;\r | |
435 | GAUGE_DATA_ENTRY_EX *GaugeEntryEx;\r | |
436 | \r | |
1658440e SZ |
437 | GaugeEntryEx = NULL;\r |
438 | \r | |
f0da4d7d SZ |
439 | Status = GetGaugeEx (LogEntryKey, &GaugeEntryEx);\r |
440 | if (EFI_ERROR (Status)) {\r | |
441 | return Status;\r | |
442 | }\r | |
443 | \r | |
444 | if (GaugeDataEntry == NULL) {\r | |
445 | return EFI_INVALID_PARAMETER;\r | |
446 | }\r | |
447 | \r | |
448 | *GaugeDataEntry = (GAUGE_DATA_ENTRY *) GaugeEntryEx;\r | |
449 | \r | |
450 | return EFI_SUCCESS;\r | |
451 | }\r | |
d042c6e8 | 452 | \r |
453 | /**\r | |
454 | This function check if the address is in SMRAM.\r | |
455 | \r | |
456 | @param Buffer the buffer address to be checked.\r | |
457 | @param Length the buffer length to be checked.\r | |
458 | \r | |
459 | @retval TRUE this address is in SMRAM.\r | |
460 | @retval FALSE this address is NOT in SMRAM.\r | |
461 | **/\r | |
462 | BOOLEAN\r | |
463 | IsAddressInSmram (\r | |
464 | IN EFI_PHYSICAL_ADDRESS Buffer,\r | |
465 | IN UINT64 Length\r | |
466 | )\r | |
467 | {\r | |
468 | UINTN Index;\r | |
469 | \r | |
470 | for (Index = 0; Index < mSmramRangeCount; Index ++) {\r | |
471 | if (((Buffer >= mSmramRanges[Index].CpuStart) && (Buffer < mSmramRanges[Index].CpuStart + mSmramRanges[Index].PhysicalSize)) ||\r | |
472 | ((mSmramRanges[Index].CpuStart >= Buffer) && (mSmramRanges[Index].CpuStart < Buffer + Length))) {\r | |
473 | return TRUE;\r | |
474 | }\r | |
475 | }\r | |
476 | \r | |
477 | return FALSE;\r | |
478 | }\r | |
479 | \r | |
9d00d20e SZ |
480 | /**\r |
481 | This function check if the address refered by Buffer and Length is valid.\r | |
482 | \r | |
483 | @param Buffer the buffer address to be checked.\r | |
484 | @param Length the buffer length to be checked.\r | |
485 | \r | |
486 | @retval TRUE this address is valid.\r | |
487 | @retval FALSE this address is NOT valid.\r | |
488 | **/\r | |
489 | BOOLEAN\r | |
490 | IsAddressValid (\r | |
491 | IN UINTN Buffer,\r | |
492 | IN UINTN Length\r | |
493 | )\r | |
494 | {\r | |
495 | if (Buffer > (MAX_ADDRESS - Length)) {\r | |
496 | //\r | |
497 | // Overflow happen\r | |
498 | //\r | |
499 | return FALSE;\r | |
500 | }\r | |
501 | if (IsAddressInSmram ((EFI_PHYSICAL_ADDRESS)Buffer, (UINT64)Length)) {\r | |
502 | return FALSE;\r | |
503 | }\r | |
504 | return TRUE;\r | |
505 | }\r | |
506 | \r | |
d042c6e8 | 507 | /**\r |
508 | Communication service SMI Handler entry.\r | |
509 | \r | |
f0da4d7d | 510 | This SMI handler provides services for the performance wrapper driver.\r |
ccd2f6b0 | 511 | \r |
512 | Caution: This function may receive untrusted input.\r | |
513 | Communicate buffer and buffer size are external input, so this function will do basic validation.\r | |
f0da4d7d SZ |
514 | \r |
515 | @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r | |
516 | @param[in] RegisterContext Points to an optional handler context which was specified when the\r | |
517 | handler was registered.\r | |
518 | @param[in, out] CommBuffer A pointer to a collection of data in memory that will\r | |
519 | be conveyed from a non-SMM environment into an SMM environment.\r | |
520 | @param[in, out] CommBufferSize The size of the CommBuffer.\r | |
521 | \r | |
522 | @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers \r | |
523 | should still be called.\r | |
524 | @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should \r | |
525 | still be called.\r | |
526 | @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still \r | |
527 | be called.\r | |
528 | @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.\r | |
529 | **/\r | |
530 | EFI_STATUS\r | |
531 | EFIAPI\r | |
532 | SmmPerformanceHandlerEx (\r | |
533 | IN EFI_HANDLE DispatchHandle,\r | |
534 | IN CONST VOID *RegisterContext,\r | |
535 | IN OUT VOID *CommBuffer,\r | |
536 | IN OUT UINTN *CommBufferSize\r | |
537 | )\r | |
538 | {\r | |
539 | EFI_STATUS Status;\r | |
540 | SMM_PERF_COMMUNICATE_EX *SmmPerfCommData;\r | |
541 | GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r | |
542 | UINTN DataSize;\r | |
5e5bb2a9 SZ |
543 | GAUGE_DATA_ENTRY_EX *GaugeDataEx;\r |
544 | UINTN NumberOfEntries;\r | |
545 | UINTN LogEntryKey;\r | |
f0da4d7d SZ |
546 | \r |
547 | GaugeEntryExArray = NULL;\r | |
548 | \r | |
ccd2f6b0 | 549 | //\r |
550 | // If input is invalid, stop processing this SMI\r | |
551 | //\r | |
552 | if (CommBuffer == NULL || CommBufferSize == NULL) {\r | |
553 | return EFI_SUCCESS;\r | |
554 | }\r | |
555 | \r | |
556 | if(*CommBufferSize < sizeof (SMM_PERF_COMMUNICATE_EX)) {\r | |
557 | return EFI_SUCCESS;\r | |
558 | }\r | |
f0da4d7d | 559 | \r |
9d00d20e | 560 | if (!IsAddressValid ((UINTN)CommBuffer, *CommBufferSize)) {\r |
5e5bb2a9 | 561 | DEBUG ((EFI_D_ERROR, "SmmPerformanceHandlerEx: SMM communcation data buffer in SMRAM or overflow!\n"));\r |
ccd2f6b0 | 562 | return EFI_SUCCESS;\r |
563 | }\r | |
564 | \r | |
f0da4d7d SZ |
565 | SmmPerfCommData = (SMM_PERF_COMMUNICATE_EX *)CommBuffer;\r |
566 | \r | |
567 | switch (SmmPerfCommData->Function) {\r | |
568 | case SMM_PERF_FUNCTION_GET_GAUGE_ENTRY_NUMBER :\r | |
569 | SmmPerfCommData->NumberOfEntries = mGaugeData->NumberOfEntries;\r | |
570 | Status = EFI_SUCCESS;\r | |
571 | break;\r | |
572 | \r | |
573 | case SMM_PERF_FUNCTION_GET_GAUGE_DATA :\r | |
5e5bb2a9 SZ |
574 | GaugeDataEx = SmmPerfCommData->GaugeDataEx;\r |
575 | NumberOfEntries = SmmPerfCommData->NumberOfEntries;\r | |
576 | LogEntryKey = SmmPerfCommData->LogEntryKey;\r | |
577 | if (GaugeDataEx == NULL || NumberOfEntries == 0 || LogEntryKey > mGaugeData->NumberOfEntries ||\r | |
578 | NumberOfEntries > mGaugeData->NumberOfEntries || (LogEntryKey + NumberOfEntries) > mGaugeData->NumberOfEntries) {\r | |
f0da4d7d SZ |
579 | Status = EFI_INVALID_PARAMETER;\r |
580 | break;\r | |
581 | }\r | |
582 | \r | |
583 | //\r | |
584 | // Sanity check\r | |
585 | //\r | |
5e5bb2a9 SZ |
586 | DataSize = NumberOfEntries * sizeof(GAUGE_DATA_ENTRY_EX);\r |
587 | if (!IsAddressValid ((UINTN)GaugeDataEx, DataSize)) {\r | |
588 | DEBUG ((EFI_D_ERROR, "SmmPerformanceHandlerEx: SMM Performance Data buffer in SMRAM or overflow!\n"));\r | |
f0da4d7d | 589 | Status = EFI_ACCESS_DENIED;\r |
ccd2f6b0 | 590 | break;\r |
f0da4d7d SZ |
591 | }\r |
592 | \r | |
593 | GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r | |
594 | CopyMem(\r | |
5e5bb2a9 SZ |
595 | (UINT8 *) GaugeDataEx,\r |
596 | (UINT8 *) &GaugeEntryExArray[LogEntryKey],\r | |
f0da4d7d SZ |
597 | DataSize\r |
598 | );\r | |
599 | Status = EFI_SUCCESS;\r | |
600 | break;\r | |
601 | \r | |
602 | default:\r | |
f0da4d7d SZ |
603 | Status = EFI_UNSUPPORTED;\r |
604 | }\r | |
605 | \r | |
ccd2f6b0 | 606 | \r |
f0da4d7d | 607 | SmmPerfCommData->ReturnStatus = Status;\r |
ccd2f6b0 | 608 | \r |
f0da4d7d SZ |
609 | return EFI_SUCCESS;\r |
610 | }\r | |
611 | \r | |
612 | /**\r | |
613 | Communication service SMI Handler entry.\r | |
614 | \r | |
615 | This SMI handler provides services for the performance wrapper driver.\r | |
d042c6e8 | 616 | \r |
ccd2f6b0 | 617 | Caution: This function may receive untrusted input.\r |
618 | Communicate buffer and buffer size are external input, so this function will do basic validation.\r | |
619 | \r | |
d042c6e8 | 620 | @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r |
621 | @param[in] RegisterContext Points to an optional handler context which was specified when the\r | |
622 | handler was registered.\r | |
623 | @param[in, out] CommBuffer A pointer to a collection of data in memory that will\r | |
624 | be conveyed from a non-SMM environment into an SMM environment.\r | |
625 | @param[in, out] CommBufferSize The size of the CommBuffer.\r | |
626 | \r | |
627 | @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers \r | |
628 | should still be called.\r | |
629 | @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should \r | |
630 | still be called.\r | |
631 | @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still \r | |
632 | be called.\r | |
633 | @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.\r | |
634 | **/\r | |
635 | EFI_STATUS\r | |
636 | EFIAPI\r | |
637 | SmmPerformanceHandler (\r | |
638 | IN EFI_HANDLE DispatchHandle,\r | |
639 | IN CONST VOID *RegisterContext,\r | |
f0da4d7d SZ |
640 | IN OUT VOID *CommBuffer,\r |
641 | IN OUT UINTN *CommBufferSize\r | |
d042c6e8 | 642 | )\r |
643 | {\r | |
644 | EFI_STATUS Status;\r | |
645 | SMM_PERF_COMMUNICATE *SmmPerfCommData;\r | |
f0da4d7d | 646 | GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r |
d042c6e8 | 647 | UINTN DataSize;\r |
f0da4d7d | 648 | UINTN Index;\r |
5e5bb2a9 SZ |
649 | GAUGE_DATA_ENTRY *GaugeData;\r |
650 | UINTN NumberOfEntries;\r | |
f0da4d7d | 651 | UINTN LogEntryKey;\r |
ccd2f6b0 | 652 | \r |
f0da4d7d | 653 | GaugeEntryExArray = NULL;\r |
d042c6e8 | 654 | \r |
ccd2f6b0 | 655 | //\r |
656 | // If input is invalid, stop processing this SMI\r | |
657 | //\r | |
658 | if (CommBuffer == NULL || CommBufferSize == NULL) {\r | |
659 | return EFI_SUCCESS;\r | |
660 | }\r | |
661 | \r | |
662 | if(*CommBufferSize < sizeof (SMM_PERF_COMMUNICATE)) {\r | |
663 | return EFI_SUCCESS;\r | |
664 | }\r | |
665 | \r | |
9d00d20e | 666 | if (!IsAddressValid ((UINTN)CommBuffer, *CommBufferSize)) {\r |
5e5bb2a9 | 667 | DEBUG ((EFI_D_ERROR, "SmmPerformanceHandler: SMM communcation data buffer in SMRAM or overflow!\n"));\r |
ccd2f6b0 | 668 | return EFI_SUCCESS;\r |
669 | }\r | |
d042c6e8 | 670 | \r |
f0da4d7d | 671 | SmmPerfCommData = (SMM_PERF_COMMUNICATE *)CommBuffer;\r |
d042c6e8 | 672 | \r |
673 | switch (SmmPerfCommData->Function) {\r | |
674 | case SMM_PERF_FUNCTION_GET_GAUGE_ENTRY_NUMBER :\r | |
675 | SmmPerfCommData->NumberOfEntries = mGaugeData->NumberOfEntries;\r | |
f0da4d7d | 676 | Status = EFI_SUCCESS;\r |
d042c6e8 | 677 | break;\r |
678 | \r | |
679 | case SMM_PERF_FUNCTION_GET_GAUGE_DATA :\r | |
5e5bb2a9 SZ |
680 | GaugeData = SmmPerfCommData->GaugeData;\r |
681 | NumberOfEntries = SmmPerfCommData->NumberOfEntries;\r | |
682 | LogEntryKey = SmmPerfCommData->LogEntryKey;\r | |
683 | if (GaugeData == NULL || NumberOfEntries == 0 || LogEntryKey > mGaugeData->NumberOfEntries ||\r | |
684 | NumberOfEntries > mGaugeData->NumberOfEntries || (LogEntryKey + NumberOfEntries) > mGaugeData->NumberOfEntries) {\r | |
d042c6e8 | 685 | Status = EFI_INVALID_PARAMETER;\r |
686 | break;\r | |
d042c6e8 | 687 | }\r |
f0da4d7d | 688 | \r |
d042c6e8 | 689 | //\r |
690 | // Sanity check\r | |
691 | //\r | |
5e5bb2a9 SZ |
692 | DataSize = NumberOfEntries * sizeof(GAUGE_DATA_ENTRY);\r |
693 | if (!IsAddressValid ((UINTN)GaugeData, DataSize)) {\r | |
694 | DEBUG ((EFI_D_ERROR, "SmmPerformanceHandler: SMM Performance Data buffer in SMRAM or overflow!\n"));\r | |
d042c6e8 | 695 | Status = EFI_ACCESS_DENIED;\r |
ccd2f6b0 | 696 | break;\r |
d042c6e8 | 697 | }\r |
698 | \r | |
f0da4d7d SZ |
699 | GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r |
700 | \r | |
5e5bb2a9 | 701 | for (Index = 0; Index < NumberOfEntries; Index++) {\r |
f0da4d7d | 702 | CopyMem(\r |
5e5bb2a9 | 703 | (UINT8 *) &GaugeData[Index],\r |
f0da4d7d SZ |
704 | (UINT8 *) &GaugeEntryExArray[LogEntryKey++],\r |
705 | sizeof (GAUGE_DATA_ENTRY)\r | |
706 | );\r | |
707 | }\r | |
708 | Status = EFI_SUCCESS;\r | |
d042c6e8 | 709 | break;\r |
710 | \r | |
711 | default:\r | |
d042c6e8 | 712 | Status = EFI_UNSUPPORTED;\r |
f0da4d7d | 713 | }\r |
d042c6e8 | 714 | \r |
ccd2f6b0 | 715 | \r |
d042c6e8 | 716 | SmmPerfCommData->ReturnStatus = Status;\r |
ccd2f6b0 | 717 | \r |
d042c6e8 | 718 | return EFI_SUCCESS;\r |
719 | }\r | |
720 | \r | |
721 | /**\r | |
722 | SmmBase2 protocol notify callback function, when SMST and SMM memory service get initialized \r | |
f0da4d7d | 723 | this function is callbacked to initialize the Smm Performance Lib \r |
d042c6e8 | 724 | \r |
725 | @param Event The event of notify protocol.\r | |
726 | @param Context Notify event context.\r | |
727 | \r | |
728 | **/\r | |
729 | VOID\r | |
730 | EFIAPI\r | |
731 | InitializeSmmCorePerformanceLib (\r | |
732 | IN EFI_EVENT Event,\r | |
733 | IN VOID *Context\r | |
734 | )\r | |
735 | {\r | |
736 | EFI_STATUS Status;\r | |
737 | EFI_HANDLE Handle;\r | |
738 | EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;\r | |
739 | UINTN Size;\r | |
740 | \r | |
741 | \r | |
742 | //\r | |
743 | // Initialize spin lock\r | |
744 | //\r | |
745 | InitializeSpinLock (&mSmmPerfLock);\r | |
746 | \r | |
f0da4d7d | 747 | mMaxGaugeRecords = INIT_SMM_GAUGE_DATA_ENTRIES;\r |
d042c6e8 | 748 | \r |
f0da4d7d | 749 | mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords));\r |
d042c6e8 | 750 | ASSERT (mGaugeData != NULL);\r |
751 | \r | |
752 | //\r | |
753 | // Get SMRAM information\r | |
754 | //\r | |
755 | Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);\r | |
756 | ASSERT_EFI_ERROR (Status);\r | |
757 | \r | |
758 | Size = 0;\r | |
759 | Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);\r | |
760 | ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r | |
761 | \r | |
762 | Status = gSmst->SmmAllocatePool (\r | |
763 | EfiRuntimeServicesData,\r | |
764 | Size,\r | |
765 | (VOID **)&mSmramRanges\r | |
766 | );\r | |
767 | ASSERT_EFI_ERROR (Status);\r | |
768 | \r | |
769 | Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);\r | |
770 | ASSERT_EFI_ERROR (Status);\r | |
771 | \r | |
772 | mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);\r | |
773 | \r | |
774 | //\r | |
775 | // Install the protocol interfaces.\r | |
776 | //\r | |
777 | Status = gSmst->SmmInstallProtocolInterface (\r | |
778 | &mHandle,\r | |
779 | &gSmmPerformanceProtocolGuid,\r | |
780 | EFI_NATIVE_INTERFACE,\r | |
781 | &mPerformanceInterface\r | |
782 | );\r | |
783 | ASSERT_EFI_ERROR (Status);\r | |
784 | \r | |
f0da4d7d SZ |
785 | Status = gSmst->SmmInstallProtocolInterface (\r |
786 | &mHandle,\r | |
787 | &gSmmPerformanceExProtocolGuid,\r | |
788 | EFI_NATIVE_INTERFACE,\r | |
789 | &mPerformanceExInterface\r | |
790 | );\r | |
791 | ASSERT_EFI_ERROR (Status);\r | |
792 | \r | |
d042c6e8 | 793 | ///\r |
794 | /// Register SMM Performance SMI handler\r | |
795 | ///\r | |
796 | Handle = NULL;\r | |
797 | Status = gSmst->SmiHandlerRegister (SmmPerformanceHandler, &gSmmPerformanceProtocolGuid, &Handle);\r | |
798 | ASSERT_EFI_ERROR (Status);\r | |
f0da4d7d SZ |
799 | Status = gSmst->SmiHandlerRegister (SmmPerformanceHandlerEx, &gSmmPerformanceExProtocolGuid, &Handle);\r |
800 | ASSERT_EFI_ERROR (Status);\r | |
d042c6e8 | 801 | }\r |
802 | \r | |
803 | /**\r | |
f0da4d7d SZ |
804 | The constructor function initializes the Performance Measurement Enable flag and \r |
805 | registers SmmBase2 protocol notify callback.\r | |
d042c6e8 | 806 | It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.\r |
807 | \r | |
808 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
809 | @param SystemTable A pointer to the EFI System Table.\r | |
810 | \r | |
811 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
812 | \r | |
813 | **/\r | |
814 | EFI_STATUS\r | |
815 | EFIAPI\r | |
816 | SmmCorePerformanceLibConstructor (\r | |
817 | IN EFI_HANDLE ImageHandle,\r | |
818 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
819 | )\r | |
820 | {\r | |
821 | EFI_STATUS Status;\r | |
822 | EFI_EVENT Event;\r | |
823 | VOID *Registration;\r | |
824 | \r | |
825 | mPerformanceMeasurementEnabled = (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r | |
826 | if (!mPerformanceMeasurementEnabled) {\r | |
827 | //\r | |
828 | // Do not initialize performance infrastructure if not required.\r | |
829 | //\r | |
830 | return EFI_SUCCESS;\r | |
831 | }\r | |
832 | \r | |
833 | //\r | |
834 | // Create the events to do the library init.\r | |
835 | //\r | |
836 | Status = gBS->CreateEvent (\r | |
837 | EVT_NOTIFY_SIGNAL,\r | |
838 | TPL_CALLBACK,\r | |
839 | InitializeSmmCorePerformanceLib,\r | |
840 | NULL,\r | |
841 | &Event\r | |
842 | );\r | |
843 | ASSERT_EFI_ERROR (Status);\r | |
844 | \r | |
845 | //\r | |
846 | // Register for protocol notifications on this event\r | |
847 | //\r | |
848 | Status = gBS->RegisterProtocolNotify (\r | |
849 | &gEfiSmmBase2ProtocolGuid,\r | |
850 | Event,\r | |
851 | &Registration\r | |
852 | );\r | |
853 | \r | |
854 | ASSERT_EFI_ERROR (Status);\r | |
855 | \r | |
856 | return EFI_SUCCESS;\r | |
857 | }\r | |
858 | \r | |
859 | /**\r | |
860 | Adds a record at the end of the performance measurement log\r | |
861 | that records the start time of a performance measurement.\r | |
862 | \r | |
863 | Adds a record to the end of the performance measurement log\r | |
f0da4d7d | 864 | that contains the Handle, Token, Module and Identifier.\r |
d042c6e8 | 865 | The end time of the new record must be set to zero.\r |
866 | If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r | |
867 | If TimeStamp is zero, the start time in the record is filled in with the value\r | |
868 | read from the current time stamp.\r | |
869 | \r | |
870 | @param Handle Pointer to environment specific context used\r | |
871 | to identify the component being measured.\r | |
872 | @param Token Pointer to a Null-terminated ASCII string\r | |
873 | that identifies the component being measured.\r | |
874 | @param Module Pointer to a Null-terminated ASCII string\r | |
875 | that identifies the module being measured.\r | |
876 | @param TimeStamp 64-bit time stamp.\r | |
f0da4d7d SZ |
877 | @param Identifier 32-bit identifier. If the value is 0, the created record\r |
878 | is same as the one created by StartPerformanceMeasurement.\r | |
d042c6e8 | 879 | \r |
880 | @retval RETURN_SUCCESS The start of the measurement was recorded.\r | |
881 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r | |
882 | \r | |
883 | **/\r | |
884 | RETURN_STATUS\r | |
885 | EFIAPI\r | |
f0da4d7d | 886 | StartPerformanceMeasurementEx (\r |
d042c6e8 | 887 | IN CONST VOID *Handle, OPTIONAL\r |
888 | IN CONST CHAR8 *Token, OPTIONAL\r | |
889 | IN CONST CHAR8 *Module, OPTIONAL\r | |
f0da4d7d SZ |
890 | IN UINT64 TimeStamp,\r |
891 | IN UINT32 Identifier\r | |
d042c6e8 | 892 | )\r |
893 | {\r | |
f0da4d7d | 894 | return (RETURN_STATUS) StartGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r |
d042c6e8 | 895 | }\r |
896 | \r | |
897 | /**\r | |
898 | Searches the performance measurement log from the beginning of the log\r | |
899 | for the first matching record that contains a zero end time and fills in a valid end time.\r | |
900 | \r | |
901 | Searches the performance measurement log from the beginning of the log\r | |
f0da4d7d | 902 | for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.\r |
d042c6e8 | 903 | If the record can not be found then return RETURN_NOT_FOUND.\r |
904 | If the record is found and TimeStamp is not zero,\r | |
905 | then the end time in the record is filled in with the value specified by TimeStamp.\r | |
906 | If the record is found and TimeStamp is zero, then the end time in the matching record\r | |
907 | is filled in with the current time stamp value.\r | |
908 | \r | |
909 | @param Handle Pointer to environment specific context used\r | |
910 | to identify the component being measured.\r | |
911 | @param Token Pointer to a Null-terminated ASCII string\r | |
912 | that identifies the component being measured.\r | |
913 | @param Module Pointer to a Null-terminated ASCII string\r | |
914 | that identifies the module being measured.\r | |
915 | @param TimeStamp 64-bit time stamp.\r | |
f0da4d7d SZ |
916 | @param Identifier 32-bit identifier. If the value is 0, the found record\r |
917 | is same as the one found by EndPerformanceMeasurement.\r | |
d042c6e8 | 918 | \r |
919 | @retval RETURN_SUCCESS The end of the measurement was recorded.\r | |
920 | @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r | |
921 | \r | |
922 | **/\r | |
923 | RETURN_STATUS\r | |
924 | EFIAPI\r | |
f0da4d7d | 925 | EndPerformanceMeasurementEx (\r |
d042c6e8 | 926 | IN CONST VOID *Handle, OPTIONAL\r |
927 | IN CONST CHAR8 *Token, OPTIONAL\r | |
928 | IN CONST CHAR8 *Module, OPTIONAL\r | |
f0da4d7d SZ |
929 | IN UINT64 TimeStamp,\r |
930 | IN UINT32 Identifier\r | |
d042c6e8 | 931 | )\r |
932 | {\r | |
f0da4d7d | 933 | return (RETURN_STATUS) EndGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r |
d042c6e8 | 934 | }\r |
935 | \r | |
936 | /**\r | |
937 | Attempts to retrieve a performance measurement log entry from the performance measurement log.\r | |
f0da4d7d SZ |
938 | It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r |
939 | and then assign the Identifier with 0.\r | |
d042c6e8 | 940 | \r |
941 | Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r | |
942 | zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r | |
943 | and the key for the second entry in the log is returned. If the performance log is empty,\r | |
944 | then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r | |
945 | log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r | |
946 | returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r | |
947 | retrieved and an implementation specific non-zero key value that specifies the end of the performance\r | |
948 | log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r | |
949 | is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r | |
f0da4d7d | 950 | the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r |
d042c6e8 | 951 | If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r |
952 | If Handle is NULL, then ASSERT().\r | |
953 | If Token is NULL, then ASSERT().\r | |
954 | If Module is NULL, then ASSERT().\r | |
955 | If StartTimeStamp is NULL, then ASSERT().\r | |
956 | If EndTimeStamp is NULL, then ASSERT().\r | |
f0da4d7d | 957 | If Identifier is NULL, then ASSERT().\r |
d042c6e8 | 958 | \r |
959 | @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r | |
960 | 0, then the first performance measurement log entry is retrieved.\r | |
961 | On exit, the key of the next performance log entry.\r | |
962 | @param Handle Pointer to environment specific context used to identify the component\r | |
963 | being measured.\r | |
964 | @param Token Pointer to a Null-terminated ASCII string that identifies the component\r | |
965 | being measured.\r | |
966 | @param Module Pointer to a Null-terminated ASCII string that identifies the module\r | |
967 | being measured.\r | |
968 | @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
969 | was started.\r | |
970 | @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
971 | was ended.\r | |
f0da4d7d | 972 | @param Identifier Pointer to the 32-bit identifier that was recorded.\r |
d042c6e8 | 973 | \r |
974 | @return The key for the next performance log entry (in general case).\r | |
975 | \r | |
976 | **/\r | |
977 | UINTN\r | |
978 | EFIAPI\r | |
f0da4d7d SZ |
979 | GetPerformanceMeasurementEx (\r |
980 | IN UINTN LogEntryKey, \r | |
d042c6e8 | 981 | OUT CONST VOID **Handle,\r |
982 | OUT CONST CHAR8 **Token,\r | |
983 | OUT CONST CHAR8 **Module,\r | |
984 | OUT UINT64 *StartTimeStamp,\r | |
f0da4d7d SZ |
985 | OUT UINT64 *EndTimeStamp,\r |
986 | OUT UINT32 *Identifier\r | |
d042c6e8 | 987 | )\r |
988 | {\r | |
f0da4d7d SZ |
989 | EFI_STATUS Status;\r |
990 | GAUGE_DATA_ENTRY_EX *GaugeData;\r | |
d042c6e8 | 991 | \r |
992 | GaugeData = NULL;\r | |
993 | \r | |
994 | ASSERT (Handle != NULL);\r | |
995 | ASSERT (Token != NULL);\r | |
996 | ASSERT (Module != NULL);\r | |
997 | ASSERT (StartTimeStamp != NULL);\r | |
998 | ASSERT (EndTimeStamp != NULL);\r | |
f0da4d7d | 999 | ASSERT (Identifier != NULL);\r |
d042c6e8 | 1000 | \r |
f0da4d7d | 1001 | Status = GetGaugeEx (LogEntryKey++, &GaugeData);\r |
d042c6e8 | 1002 | \r |
1003 | //\r | |
1004 | // Make sure that LogEntryKey is a valid log entry key,\r | |
1005 | //\r | |
1006 | ASSERT (Status != EFI_INVALID_PARAMETER);\r | |
1007 | \r | |
1008 | if (EFI_ERROR (Status)) {\r | |
1009 | //\r | |
1010 | // The LogEntryKey is the last entry (equals to the total entry number).\r | |
1011 | //\r | |
1012 | return 0;\r | |
1013 | }\r | |
1014 | \r | |
1015 | ASSERT (GaugeData != NULL);\r | |
1016 | \r | |
1017 | *Handle = (VOID *) (UINTN) GaugeData->Handle;\r | |
1018 | *Token = GaugeData->Token;\r | |
1019 | *Module = GaugeData->Module;\r | |
1020 | *StartTimeStamp = GaugeData->StartTimeStamp;\r | |
1021 | *EndTimeStamp = GaugeData->EndTimeStamp;\r | |
f0da4d7d | 1022 | *Identifier = GaugeData->Identifier;\r |
d042c6e8 | 1023 | \r |
1024 | return LogEntryKey;\r | |
1025 | }\r | |
1026 | \r | |
f0da4d7d SZ |
1027 | /**\r |
1028 | Adds a record at the end of the performance measurement log\r | |
1029 | that records the start time of a performance measurement.\r | |
1030 | \r | |
1031 | Adds a record to the end of the performance measurement log\r | |
1032 | that contains the Handle, Token, and Module.\r | |
1033 | The end time of the new record must be set to zero.\r | |
1034 | If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r | |
1035 | If TimeStamp is zero, the start time in the record is filled in with the value\r | |
1036 | read from the current time stamp.\r | |
1037 | \r | |
1038 | @param Handle Pointer to environment specific context used\r | |
1039 | to identify the component being measured.\r | |
1040 | @param Token Pointer to a Null-terminated ASCII string\r | |
1041 | that identifies the component being measured.\r | |
1042 | @param Module Pointer to a Null-terminated ASCII string\r | |
1043 | that identifies the module being measured.\r | |
1044 | @param TimeStamp 64-bit time stamp.\r | |
1045 | \r | |
1046 | @retval RETURN_SUCCESS The start of the measurement was recorded.\r | |
1047 | @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r | |
1048 | \r | |
1049 | **/\r | |
1050 | RETURN_STATUS\r | |
1051 | EFIAPI\r | |
1052 | StartPerformanceMeasurement (\r | |
1053 | IN CONST VOID *Handle, OPTIONAL\r | |
1054 | IN CONST CHAR8 *Token, OPTIONAL\r | |
1055 | IN CONST CHAR8 *Module, OPTIONAL\r | |
1056 | IN UINT64 TimeStamp\r | |
1057 | )\r | |
1058 | {\r | |
1059 | return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r | |
1060 | }\r | |
1061 | \r | |
1062 | /**\r | |
1063 | Searches the performance measurement log from the beginning of the log\r | |
1064 | for the first matching record that contains a zero end time and fills in a valid end time.\r | |
1065 | \r | |
1066 | Searches the performance measurement log from the beginning of the log\r | |
1067 | for the first record that matches Handle, Token, and Module and has an end time value of zero.\r | |
1068 | If the record can not be found then return RETURN_NOT_FOUND.\r | |
1069 | If the record is found and TimeStamp is not zero,\r | |
1070 | then the end time in the record is filled in with the value specified by TimeStamp.\r | |
1071 | If the record is found and TimeStamp is zero, then the end time in the matching record\r | |
1072 | is filled in with the current time stamp value.\r | |
1073 | \r | |
1074 | @param Handle Pointer to environment specific context used\r | |
1075 | to identify the component being measured.\r | |
1076 | @param Token Pointer to a Null-terminated ASCII string\r | |
1077 | that identifies the component being measured.\r | |
1078 | @param Module Pointer to a Null-terminated ASCII string\r | |
1079 | that identifies the module being measured.\r | |
1080 | @param TimeStamp 64-bit time stamp.\r | |
1081 | \r | |
1082 | @retval RETURN_SUCCESS The end of the measurement was recorded.\r | |
1083 | @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r | |
1084 | \r | |
1085 | **/\r | |
1086 | RETURN_STATUS\r | |
1087 | EFIAPI\r | |
1088 | EndPerformanceMeasurement (\r | |
1089 | IN CONST VOID *Handle, OPTIONAL\r | |
1090 | IN CONST CHAR8 *Token, OPTIONAL\r | |
1091 | IN CONST CHAR8 *Module, OPTIONAL\r | |
1092 | IN UINT64 TimeStamp\r | |
1093 | )\r | |
1094 | {\r | |
1095 | return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r | |
1096 | }\r | |
1097 | \r | |
1098 | /**\r | |
1099 | Attempts to retrieve a performance measurement log entry from the performance measurement log.\r | |
1100 | It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r | |
1101 | and then eliminate the Identifier.\r | |
1102 | \r | |
1103 | Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r | |
1104 | zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r | |
1105 | and the key for the second entry in the log is returned. If the performance log is empty,\r | |
1106 | then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r | |
1107 | log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r | |
1108 | returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r | |
1109 | retrieved and an implementation specific non-zero key value that specifies the end of the performance\r | |
1110 | log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r | |
1111 | is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r | |
1112 | the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r | |
1113 | If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r | |
1114 | If Handle is NULL, then ASSERT().\r | |
1115 | If Token is NULL, then ASSERT().\r | |
1116 | If Module is NULL, then ASSERT().\r | |
1117 | If StartTimeStamp is NULL, then ASSERT().\r | |
1118 | If EndTimeStamp is NULL, then ASSERT().\r | |
1119 | \r | |
1120 | @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r | |
1121 | 0, then the first performance measurement log entry is retrieved.\r | |
1122 | On exit, the key of the next performance log entry.\r | |
1123 | @param Handle Pointer to environment specific context used to identify the component\r | |
1124 | being measured.\r | |
1125 | @param Token Pointer to a Null-terminated ASCII string that identifies the component\r | |
1126 | being measured.\r | |
1127 | @param Module Pointer to a Null-terminated ASCII string that identifies the module\r | |
1128 | being measured.\r | |
1129 | @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
1130 | was started.\r | |
1131 | @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r | |
1132 | was ended.\r | |
1133 | \r | |
1134 | @return The key for the next performance log entry (in general case).\r | |
1135 | \r | |
1136 | **/\r | |
1137 | UINTN\r | |
1138 | EFIAPI\r | |
1139 | GetPerformanceMeasurement (\r | |
1140 | IN UINTN LogEntryKey,\r | |
1141 | OUT CONST VOID **Handle,\r | |
1142 | OUT CONST CHAR8 **Token,\r | |
1143 | OUT CONST CHAR8 **Module,\r | |
1144 | OUT UINT64 *StartTimeStamp,\r | |
1145 | OUT UINT64 *EndTimeStamp\r | |
1146 | )\r | |
1147 | {\r | |
1148 | UINT32 Identifier;\r | |
1149 | return GetPerformanceMeasurementEx (LogEntryKey, Handle, Token, Module, StartTimeStamp, EndTimeStamp, &Identifier);\r | |
1150 | }\r | |
1151 | \r | |
d042c6e8 | 1152 | /**\r |
1153 | Returns TRUE if the performance measurement macros are enabled.\r | |
1154 | \r | |
1155 | This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
1156 | PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r | |
1157 | \r | |
1158 | @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
1159 | PcdPerformanceLibraryPropertyMask is set.\r | |
1160 | @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r | |
1161 | PcdPerformanceLibraryPropertyMask is clear.\r | |
1162 | \r | |
1163 | **/\r | |
1164 | BOOLEAN\r | |
1165 | EFIAPI\r | |
1166 | PerformanceMeasurementEnabled (\r | |
1167 | VOID\r | |
1168 | )\r | |
1169 | {\r | |
1170 | return mPerformanceMeasurementEnabled;\r | |
1171 | }\r |