]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c
Read/Write memory space including MMIO range with the width requested from HOST.
[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
9d00d20e 19Copyright (c) 2011 - 2013, 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
54EFI_SMRAM_DESCRIPTOR *mSmramRanges;\r
55UINTN mSmramRangeCount;\r
56\r
57//\r
f0da4d7d 58// Interfaces for SMM Performance Protocol.\r
d042c6e8 59//\r
60PERFORMANCE_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
69PERFORMANCE_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
94UINT32\r
95SmmSearchForGaugeEntry (\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
159EFI_STATUS\r
160EFIAPI\r
f0da4d7d 161StartGaugeEx (\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
256EFI_STATUS\r
257EFIAPI\r
f0da4d7d 258EndGaugeEx (\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
308EFI_STATUS\r
309EFIAPI\r
f0da4d7d
SZ
310GetGaugeEx (\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
359EFI_STATUS\r
360EFIAPI\r
361StartGauge (\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
395EFI_STATUS\r
396EFIAPI\r
397EndGauge (\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
427EFI_STATUS\r
428EFIAPI\r
429GetGauge (\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
462BOOLEAN\r
463IsAddressInSmram (\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
489BOOLEAN\r
490IsAddressValid (\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
530EFI_STATUS\r
531EFIAPI\r
532SmmPerformanceHandlerEx (\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
543\r
544 GaugeEntryExArray = NULL;\r
545\r
ccd2f6b0 546 //\r
547 // If input is invalid, stop processing this SMI\r
548 //\r
549 if (CommBuffer == NULL || CommBufferSize == NULL) {\r
550 return EFI_SUCCESS;\r
551 }\r
552\r
553 if(*CommBufferSize < sizeof (SMM_PERF_COMMUNICATE_EX)) {\r
554 return EFI_SUCCESS;\r
555 }\r
f0da4d7d 556\r
9d00d20e
SZ
557 if (!IsAddressValid ((UINTN)CommBuffer, *CommBufferSize)) {\r
558 DEBUG ((EFI_D_ERROR, "SMM communcation data buffer in SMRAM or overflow!\n"));\r
ccd2f6b0 559 return EFI_SUCCESS;\r
560 }\r
561 \r
f0da4d7d
SZ
562 SmmPerfCommData = (SMM_PERF_COMMUNICATE_EX *)CommBuffer;\r
563\r
564 switch (SmmPerfCommData->Function) {\r
565 case SMM_PERF_FUNCTION_GET_GAUGE_ENTRY_NUMBER :\r
566 SmmPerfCommData->NumberOfEntries = mGaugeData->NumberOfEntries;\r
567 Status = EFI_SUCCESS;\r
568 break;\r
569\r
570 case SMM_PERF_FUNCTION_GET_GAUGE_DATA :\r
571 if ( SmmPerfCommData->GaugeDataEx == NULL || SmmPerfCommData->NumberOfEntries == 0 ||\r
572 (SmmPerfCommData->LogEntryKey + SmmPerfCommData->NumberOfEntries) > mGaugeData->NumberOfEntries) {\r
573 Status = EFI_INVALID_PARAMETER;\r
574 break;\r
575 }\r
576\r
577 //\r
578 // Sanity check\r
579 //\r
580 DataSize = SmmPerfCommData->NumberOfEntries * sizeof(GAUGE_DATA_ENTRY_EX);\r
9d00d20e
SZ
581 if (!IsAddressValid ((UINTN)SmmPerfCommData->GaugeDataEx, DataSize)) {\r
582 DEBUG ((EFI_D_ERROR, "SMM Performance Data buffer in SMRAM or overflow!\n"));\r
f0da4d7d 583 Status = EFI_ACCESS_DENIED;\r
ccd2f6b0 584 break;\r
f0da4d7d
SZ
585 }\r
586\r
587 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
588 CopyMem(\r
589 (UINT8 *) (SmmPerfCommData->GaugeDataEx),\r
590 (UINT8 *) &GaugeEntryExArray[SmmPerfCommData->LogEntryKey],\r
591 DataSize\r
592 );\r
593 Status = EFI_SUCCESS;\r
594 break;\r
595\r
596 default:\r
f0da4d7d
SZ
597 Status = EFI_UNSUPPORTED;\r
598 }\r
599\r
ccd2f6b0 600\r
f0da4d7d 601 SmmPerfCommData->ReturnStatus = Status;\r
ccd2f6b0 602 \r
f0da4d7d
SZ
603 return EFI_SUCCESS;\r
604}\r
605\r
606/**\r
607 Communication service SMI Handler entry.\r
608\r
609 This SMI handler provides services for the performance wrapper driver.\r
d042c6e8 610\r
ccd2f6b0 611 Caution: This function may receive untrusted input.\r
612 Communicate buffer and buffer size are external input, so this function will do basic validation.\r
613\r
d042c6e8 614 @param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().\r
615 @param[in] RegisterContext Points to an optional handler context which was specified when the\r
616 handler was registered.\r
617 @param[in, out] CommBuffer A pointer to a collection of data in memory that will\r
618 be conveyed from a non-SMM environment into an SMM environment.\r
619 @param[in, out] CommBufferSize The size of the CommBuffer.\r
620\r
621 @retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers \r
622 should still be called.\r
623 @retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should \r
624 still be called.\r
625 @retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still \r
626 be called.\r
627 @retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.\r
628**/\r
629EFI_STATUS\r
630EFIAPI\r
631SmmPerformanceHandler (\r
632 IN EFI_HANDLE DispatchHandle,\r
633 IN CONST VOID *RegisterContext,\r
f0da4d7d
SZ
634 IN OUT VOID *CommBuffer,\r
635 IN OUT UINTN *CommBufferSize\r
d042c6e8 636 )\r
637{\r
638 EFI_STATUS Status;\r
639 SMM_PERF_COMMUNICATE *SmmPerfCommData;\r
f0da4d7d 640 GAUGE_DATA_ENTRY_EX *GaugeEntryExArray;\r
d042c6e8 641 UINTN DataSize;\r
f0da4d7d
SZ
642 UINTN Index;\r
643 UINTN LogEntryKey;\r
ccd2f6b0 644 \r
f0da4d7d 645 GaugeEntryExArray = NULL;\r
d042c6e8 646\r
ccd2f6b0 647 //\r
648 // If input is invalid, stop processing this SMI\r
649 //\r
650 if (CommBuffer == NULL || CommBufferSize == NULL) {\r
651 return EFI_SUCCESS;\r
652 }\r
653\r
654 if(*CommBufferSize < sizeof (SMM_PERF_COMMUNICATE)) {\r
655 return EFI_SUCCESS;\r
656 }\r
657\r
9d00d20e
SZ
658 if (!IsAddressValid ((UINTN)CommBuffer, *CommBufferSize)) {\r
659 DEBUG ((EFI_D_ERROR, "SMM communcation data buffer in SMRAM or overflow!\n"));\r
ccd2f6b0 660 return EFI_SUCCESS;\r
661 }\r
d042c6e8 662\r
f0da4d7d 663 SmmPerfCommData = (SMM_PERF_COMMUNICATE *)CommBuffer;\r
d042c6e8 664\r
665 switch (SmmPerfCommData->Function) {\r
666 case SMM_PERF_FUNCTION_GET_GAUGE_ENTRY_NUMBER :\r
667 SmmPerfCommData->NumberOfEntries = mGaugeData->NumberOfEntries;\r
f0da4d7d 668 Status = EFI_SUCCESS;\r
d042c6e8 669 break;\r
670\r
671 case SMM_PERF_FUNCTION_GET_GAUGE_DATA :\r
f0da4d7d
SZ
672 if ( SmmPerfCommData->GaugeData == NULL || SmmPerfCommData->NumberOfEntries == 0 ||\r
673 (SmmPerfCommData->LogEntryKey + SmmPerfCommData->NumberOfEntries) > mGaugeData->NumberOfEntries) {\r
d042c6e8 674 Status = EFI_INVALID_PARAMETER;\r
675 break;\r
d042c6e8 676 }\r
f0da4d7d 677\r
d042c6e8 678 //\r
679 // Sanity check\r
680 //\r
681 DataSize = SmmPerfCommData->NumberOfEntries * sizeof(GAUGE_DATA_ENTRY);\r
9d00d20e
SZ
682 if (!IsAddressValid ((UINTN)SmmPerfCommData->GaugeData, DataSize)) {\r
683 DEBUG ((EFI_D_ERROR, "SMM Performance Data buffer in SMRAM or overflow!\n"));\r
d042c6e8 684 Status = EFI_ACCESS_DENIED;\r
ccd2f6b0 685 break;\r
d042c6e8 686 }\r
687\r
f0da4d7d
SZ
688 GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
689\r
690 LogEntryKey = SmmPerfCommData->LogEntryKey;\r
691 for (Index = 0; Index < SmmPerfCommData->NumberOfEntries; Index++) {\r
692 CopyMem(\r
693 (UINT8 *) &(SmmPerfCommData->GaugeData[Index]),\r
694 (UINT8 *) &GaugeEntryExArray[LogEntryKey++],\r
695 sizeof (GAUGE_DATA_ENTRY)\r
696 );\r
697 }\r
698 Status = EFI_SUCCESS;\r
d042c6e8 699 break;\r
700\r
701 default:\r
d042c6e8 702 Status = EFI_UNSUPPORTED;\r
f0da4d7d 703 }\r
d042c6e8 704\r
ccd2f6b0 705\r
d042c6e8 706 SmmPerfCommData->ReturnStatus = Status;\r
ccd2f6b0 707 \r
d042c6e8 708 return EFI_SUCCESS;\r
709}\r
710\r
711/**\r
712 SmmBase2 protocol notify callback function, when SMST and SMM memory service get initialized \r
f0da4d7d 713 this function is callbacked to initialize the Smm Performance Lib \r
d042c6e8 714\r
715 @param Event The event of notify protocol.\r
716 @param Context Notify event context.\r
717\r
718**/\r
719VOID\r
720EFIAPI\r
721InitializeSmmCorePerformanceLib (\r
722 IN EFI_EVENT Event,\r
723 IN VOID *Context\r
724 )\r
725{\r
726 EFI_STATUS Status;\r
727 EFI_HANDLE Handle;\r
728 EFI_SMM_ACCESS2_PROTOCOL *SmmAccess;\r
729 UINTN Size;\r
730\r
731\r
732 //\r
733 // Initialize spin lock\r
734 //\r
735 InitializeSpinLock (&mSmmPerfLock);\r
736\r
f0da4d7d 737 mMaxGaugeRecords = INIT_SMM_GAUGE_DATA_ENTRIES;\r
d042c6e8 738\r
f0da4d7d 739 mGaugeData = AllocateZeroPool (sizeof (GAUGE_DATA_HEADER) + (sizeof (GAUGE_DATA_ENTRY_EX) * mMaxGaugeRecords));\r
d042c6e8 740 ASSERT (mGaugeData != NULL);\r
741 \r
742 //\r
743 // Get SMRAM information\r
744 //\r
745 Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);\r
746 ASSERT_EFI_ERROR (Status);\r
747\r
748 Size = 0;\r
749 Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);\r
750 ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
751\r
752 Status = gSmst->SmmAllocatePool (\r
753 EfiRuntimeServicesData,\r
754 Size,\r
755 (VOID **)&mSmramRanges\r
756 );\r
757 ASSERT_EFI_ERROR (Status);\r
758\r
759 Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);\r
760 ASSERT_EFI_ERROR (Status);\r
761\r
762 mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);\r
763\r
764 //\r
765 // Install the protocol interfaces.\r
766 //\r
767 Status = gSmst->SmmInstallProtocolInterface (\r
768 &mHandle,\r
769 &gSmmPerformanceProtocolGuid,\r
770 EFI_NATIVE_INTERFACE,\r
771 &mPerformanceInterface\r
772 );\r
773 ASSERT_EFI_ERROR (Status);\r
774\r
f0da4d7d
SZ
775 Status = gSmst->SmmInstallProtocolInterface (\r
776 &mHandle,\r
777 &gSmmPerformanceExProtocolGuid,\r
778 EFI_NATIVE_INTERFACE,\r
779 &mPerformanceExInterface\r
780 );\r
781 ASSERT_EFI_ERROR (Status);\r
782\r
d042c6e8 783 ///\r
784 /// Register SMM Performance SMI handler\r
785 ///\r
786 Handle = NULL;\r
787 Status = gSmst->SmiHandlerRegister (SmmPerformanceHandler, &gSmmPerformanceProtocolGuid, &Handle);\r
788 ASSERT_EFI_ERROR (Status);\r
f0da4d7d
SZ
789 Status = gSmst->SmiHandlerRegister (SmmPerformanceHandlerEx, &gSmmPerformanceExProtocolGuid, &Handle);\r
790 ASSERT_EFI_ERROR (Status);\r
d042c6e8 791}\r
792\r
793/**\r
f0da4d7d
SZ
794 The constructor function initializes the Performance Measurement Enable flag and \r
795 registers SmmBase2 protocol notify callback.\r
d042c6e8 796 It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.\r
797\r
798 @param ImageHandle The firmware allocated handle for the EFI image.\r
799 @param SystemTable A pointer to the EFI System Table.\r
800\r
801 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
802\r
803**/\r
804EFI_STATUS\r
805EFIAPI\r
806SmmCorePerformanceLibConstructor (\r
807 IN EFI_HANDLE ImageHandle,\r
808 IN EFI_SYSTEM_TABLE *SystemTable\r
809 )\r
810{\r
811 EFI_STATUS Status;\r
812 EFI_EVENT Event;\r
813 VOID *Registration;\r
814\r
815 mPerformanceMeasurementEnabled = (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
816 if (!mPerformanceMeasurementEnabled) {\r
817 //\r
818 // Do not initialize performance infrastructure if not required.\r
819 //\r
820 return EFI_SUCCESS;\r
821 }\r
822\r
823 //\r
824 // Create the events to do the library init.\r
825 //\r
826 Status = gBS->CreateEvent (\r
827 EVT_NOTIFY_SIGNAL,\r
828 TPL_CALLBACK,\r
829 InitializeSmmCorePerformanceLib,\r
830 NULL,\r
831 &Event\r
832 );\r
833 ASSERT_EFI_ERROR (Status);\r
834\r
835 //\r
836 // Register for protocol notifications on this event\r
837 //\r
838 Status = gBS->RegisterProtocolNotify (\r
839 &gEfiSmmBase2ProtocolGuid,\r
840 Event,\r
841 &Registration\r
842 );\r
843\r
844 ASSERT_EFI_ERROR (Status);\r
845\r
846 return EFI_SUCCESS;\r
847}\r
848\r
849/**\r
850 Adds a record at the end of the performance measurement log\r
851 that records the start time of a performance measurement.\r
852\r
853 Adds a record to the end of the performance measurement log\r
f0da4d7d 854 that contains the Handle, Token, Module and Identifier.\r
d042c6e8 855 The end time of the new record must be set to zero.\r
856 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
857 If TimeStamp is zero, the start time in the record is filled in with the value\r
858 read from the current time stamp.\r
859\r
860 @param Handle Pointer to environment specific context used\r
861 to identify the component being measured.\r
862 @param Token Pointer to a Null-terminated ASCII string\r
863 that identifies the component being measured.\r
864 @param Module Pointer to a Null-terminated ASCII string\r
865 that identifies the module being measured.\r
866 @param TimeStamp 64-bit time stamp.\r
f0da4d7d
SZ
867 @param Identifier 32-bit identifier. If the value is 0, the created record\r
868 is same as the one created by StartPerformanceMeasurement.\r
d042c6e8 869\r
870 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
871 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
872\r
873**/\r
874RETURN_STATUS\r
875EFIAPI\r
f0da4d7d 876StartPerformanceMeasurementEx (\r
d042c6e8 877 IN CONST VOID *Handle, OPTIONAL\r
878 IN CONST CHAR8 *Token, OPTIONAL\r
879 IN CONST CHAR8 *Module, OPTIONAL\r
f0da4d7d
SZ
880 IN UINT64 TimeStamp,\r
881 IN UINT32 Identifier\r
d042c6e8 882 )\r
883{\r
f0da4d7d 884 return (RETURN_STATUS) StartGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
d042c6e8 885}\r
886\r
887/**\r
888 Searches the performance measurement log from the beginning of the log\r
889 for the first matching record that contains a zero end time and fills in a valid end time.\r
890\r
891 Searches the performance measurement log from the beginning of the log\r
f0da4d7d 892 for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.\r
d042c6e8 893 If the record can not be found then return RETURN_NOT_FOUND.\r
894 If the record is found and TimeStamp is not zero,\r
895 then the end time in the record is filled in with the value specified by TimeStamp.\r
896 If the record is found and TimeStamp is zero, then the end time in the matching record\r
897 is filled in with the current time stamp value.\r
898\r
899 @param Handle Pointer to environment specific context used\r
900 to identify the component being measured.\r
901 @param Token Pointer to a Null-terminated ASCII string\r
902 that identifies the component being measured.\r
903 @param Module Pointer to a Null-terminated ASCII string\r
904 that identifies the module being measured.\r
905 @param TimeStamp 64-bit time stamp.\r
f0da4d7d
SZ
906 @param Identifier 32-bit identifier. If the value is 0, the found record\r
907 is same as the one found by EndPerformanceMeasurement.\r
d042c6e8 908\r
909 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
910 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
911\r
912**/\r
913RETURN_STATUS\r
914EFIAPI\r
f0da4d7d 915EndPerformanceMeasurementEx (\r
d042c6e8 916 IN CONST VOID *Handle, OPTIONAL\r
917 IN CONST CHAR8 *Token, OPTIONAL\r
918 IN CONST CHAR8 *Module, OPTIONAL\r
f0da4d7d
SZ
919 IN UINT64 TimeStamp,\r
920 IN UINT32 Identifier\r
d042c6e8 921 )\r
922{\r
f0da4d7d 923 return (RETURN_STATUS) EndGaugeEx (Handle, Token, Module, TimeStamp, Identifier);\r
d042c6e8 924}\r
925\r
926/**\r
927 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
f0da4d7d
SZ
928 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
929 and then assign the Identifier with 0.\r
d042c6e8 930\r
931 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
932 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
933 and the key for the second entry in the log is returned. If the performance log is empty,\r
934 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
935 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
936 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
937 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
938 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
939 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
f0da4d7d 940 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
d042c6e8 941 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
942 If Handle is NULL, then ASSERT().\r
943 If Token is NULL, then ASSERT().\r
944 If Module is NULL, then ASSERT().\r
945 If StartTimeStamp is NULL, then ASSERT().\r
946 If EndTimeStamp is NULL, then ASSERT().\r
f0da4d7d 947 If Identifier is NULL, then ASSERT().\r
d042c6e8 948\r
949 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
950 0, then the first performance measurement log entry is retrieved.\r
951 On exit, the key of the next performance log entry.\r
952 @param Handle Pointer to environment specific context used to identify the component\r
953 being measured.\r
954 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
955 being measured.\r
956 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
957 being measured.\r
958 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
959 was started.\r
960 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
961 was ended.\r
f0da4d7d 962 @param Identifier Pointer to the 32-bit identifier that was recorded.\r
d042c6e8 963\r
964 @return The key for the next performance log entry (in general case).\r
965\r
966**/\r
967UINTN\r
968EFIAPI\r
f0da4d7d
SZ
969GetPerformanceMeasurementEx (\r
970 IN UINTN LogEntryKey, \r
d042c6e8 971 OUT CONST VOID **Handle,\r
972 OUT CONST CHAR8 **Token,\r
973 OUT CONST CHAR8 **Module,\r
974 OUT UINT64 *StartTimeStamp,\r
f0da4d7d
SZ
975 OUT UINT64 *EndTimeStamp,\r
976 OUT UINT32 *Identifier\r
d042c6e8 977 )\r
978{\r
f0da4d7d
SZ
979 EFI_STATUS Status;\r
980 GAUGE_DATA_ENTRY_EX *GaugeData;\r
d042c6e8 981\r
982 GaugeData = NULL;\r
983 \r
984 ASSERT (Handle != NULL);\r
985 ASSERT (Token != NULL);\r
986 ASSERT (Module != NULL);\r
987 ASSERT (StartTimeStamp != NULL);\r
988 ASSERT (EndTimeStamp != NULL);\r
f0da4d7d 989 ASSERT (Identifier != NULL);\r
d042c6e8 990\r
f0da4d7d 991 Status = GetGaugeEx (LogEntryKey++, &GaugeData);\r
d042c6e8 992\r
993 //\r
994 // Make sure that LogEntryKey is a valid log entry key,\r
995 //\r
996 ASSERT (Status != EFI_INVALID_PARAMETER);\r
997\r
998 if (EFI_ERROR (Status)) {\r
999 //\r
1000 // The LogEntryKey is the last entry (equals to the total entry number).\r
1001 //\r
1002 return 0;\r
1003 }\r
1004\r
1005 ASSERT (GaugeData != NULL);\r
1006\r
1007 *Handle = (VOID *) (UINTN) GaugeData->Handle;\r
1008 *Token = GaugeData->Token;\r
1009 *Module = GaugeData->Module;\r
1010 *StartTimeStamp = GaugeData->StartTimeStamp;\r
1011 *EndTimeStamp = GaugeData->EndTimeStamp;\r
f0da4d7d 1012 *Identifier = GaugeData->Identifier;\r
d042c6e8 1013\r
1014 return LogEntryKey;\r
1015}\r
1016\r
f0da4d7d
SZ
1017/**\r
1018 Adds a record at the end of the performance measurement log\r
1019 that records the start time of a performance measurement.\r
1020\r
1021 Adds a record to the end of the performance measurement log\r
1022 that contains the Handle, Token, and Module.\r
1023 The end time of the new record must be set to zero.\r
1024 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
1025 If TimeStamp is zero, the start time in the record is filled in with the value\r
1026 read from the current time stamp.\r
1027\r
1028 @param Handle Pointer to environment specific context used\r
1029 to identify the component being measured.\r
1030 @param Token Pointer to a Null-terminated ASCII string\r
1031 that identifies the component being measured.\r
1032 @param Module Pointer to a Null-terminated ASCII string\r
1033 that identifies the module being measured.\r
1034 @param TimeStamp 64-bit time stamp.\r
1035\r
1036 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
1037 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
1038\r
1039**/\r
1040RETURN_STATUS\r
1041EFIAPI\r
1042StartPerformanceMeasurement (\r
1043 IN CONST VOID *Handle, OPTIONAL\r
1044 IN CONST CHAR8 *Token, OPTIONAL\r
1045 IN CONST CHAR8 *Module, OPTIONAL\r
1046 IN UINT64 TimeStamp\r
1047 )\r
1048{\r
1049 return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
1050}\r
1051\r
1052/**\r
1053 Searches the performance measurement log from the beginning of the log\r
1054 for the first matching record that contains a zero end time and fills in a valid end time.\r
1055\r
1056 Searches the performance measurement log from the beginning of the log\r
1057 for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
1058 If the record can not be found then return RETURN_NOT_FOUND.\r
1059 If the record is found and TimeStamp is not zero,\r
1060 then the end time in the record is filled in with the value specified by TimeStamp.\r
1061 If the record is found and TimeStamp is zero, then the end time in the matching record\r
1062 is filled in with the current time stamp value.\r
1063\r
1064 @param Handle Pointer to environment specific context used\r
1065 to identify the component being measured.\r
1066 @param Token Pointer to a Null-terminated ASCII string\r
1067 that identifies the component being measured.\r
1068 @param Module Pointer to a Null-terminated ASCII string\r
1069 that identifies the module being measured.\r
1070 @param TimeStamp 64-bit time stamp.\r
1071\r
1072 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
1073 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
1074\r
1075**/\r
1076RETURN_STATUS\r
1077EFIAPI\r
1078EndPerformanceMeasurement (\r
1079 IN CONST VOID *Handle, OPTIONAL\r
1080 IN CONST CHAR8 *Token, OPTIONAL\r
1081 IN CONST CHAR8 *Module, OPTIONAL\r
1082 IN UINT64 TimeStamp\r
1083 )\r
1084{\r
1085 return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
1086}\r
1087\r
1088/**\r
1089 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
1090 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
1091 and then eliminate the Identifier.\r
1092\r
1093 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
1094 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
1095 and the key for the second entry in the log is returned. If the performance log is empty,\r
1096 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
1097 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
1098 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
1099 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
1100 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
1101 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
1102 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
1103 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
1104 If Handle is NULL, then ASSERT().\r
1105 If Token is NULL, then ASSERT().\r
1106 If Module is NULL, then ASSERT().\r
1107 If StartTimeStamp is NULL, then ASSERT().\r
1108 If EndTimeStamp is NULL, then ASSERT().\r
1109\r
1110 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
1111 0, then the first performance measurement log entry is retrieved.\r
1112 On exit, the key of the next performance log entry.\r
1113 @param Handle Pointer to environment specific context used to identify the component\r
1114 being measured.\r
1115 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
1116 being measured.\r
1117 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
1118 being measured.\r
1119 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
1120 was started.\r
1121 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
1122 was ended.\r
1123\r
1124 @return The key for the next performance log entry (in general case).\r
1125\r
1126**/\r
1127UINTN\r
1128EFIAPI\r
1129GetPerformanceMeasurement (\r
1130 IN UINTN LogEntryKey,\r
1131 OUT CONST VOID **Handle,\r
1132 OUT CONST CHAR8 **Token,\r
1133 OUT CONST CHAR8 **Module,\r
1134 OUT UINT64 *StartTimeStamp,\r
1135 OUT UINT64 *EndTimeStamp\r
1136 )\r
1137{\r
1138 UINT32 Identifier;\r
1139 return GetPerformanceMeasurementEx (LogEntryKey, Handle, Token, Module, StartTimeStamp, EndTimeStamp, &Identifier);\r
1140}\r
1141\r
d042c6e8 1142/**\r
1143 Returns TRUE if the performance measurement macros are enabled.\r
1144\r
1145 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
1146 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
1147\r
1148 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
1149 PcdPerformanceLibraryPropertyMask is set.\r
1150 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
1151 PcdPerformanceLibraryPropertyMask is clear.\r
1152\r
1153**/\r
1154BOOLEAN\r
1155EFIAPI\r
1156PerformanceMeasurementEnabled (\r
1157 VOID\r
1158 )\r
1159{\r
1160 return mPerformanceMeasurementEnabled;\r
1161}\r