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