]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/DxeSmmPerformanceLib/DxeSmmPerformanceLib.c
MdeModulePkg-FPDT(3): Use SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET in FpdtDxe.
[mirror_edk2.git] / MdeModulePkg / Library / DxeSmmPerformanceLib / DxeSmmPerformanceLib.c
CommitLineData
d042c6e8 1/** @file\r
dccfb097 2 Performance library instance used in DXE phase to dump both PEI/DXE and SMM performance data.\r
d042c6e8 3\r
dccfb097 4 This library instance allows a DXE driver or UEFI application to dump both PEI/DXE and SMM performance data.\r
f0da4d7d
SZ
5 StartPerformanceMeasurement(), EndPerformanceMeasurement(), StartPerformanceMeasurementEx()\r
6 and EndPerformanceMeasurementEx() are not implemented.\r
d042c6e8 7\r
7a9395cd 8 Copyright (c) 2011 - 2016, Intel Corporation. All rights reserved.<BR>\r
d042c6e8 9This program and the accompanying materials\r
10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13\r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
16\r
17**/\r
18\r
19\r
20#include <PiDxe.h>\r
21\r
22#include <Guid/Performance.h>\r
23\r
24#include <Library/PerformanceLib.h>\r
25#include <Library/DebugLib.h>\r
26#include <Library/UefiBootServicesTableLib.h>\r
27#include <Library/UefiRuntimeServicesTableLib.h>\r
28#include <Library/PcdLib.h>\r
29#include <Library/BaseMemoryLib.h>\r
30#include <Library/BaseLib.h>\r
31#include <Library/MemoryAllocationLib.h>\r
32\r
33#include <Protocol/SmmCommunication.h>\r
34\r
35#define SMM_PERFORMANCE_COMMUNICATION_BUFFER_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof (SMM_PERF_COMMUNICATE))\r
dccfb097 36\r
d042c6e8 37EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication = NULL;\r
38UINT8 mSmmPerformanceBuffer[SMM_PERFORMANCE_COMMUNICATION_BUFFER_SIZE];\r
39GAUGE_DATA_ENTRY *mGaugeData = NULL;\r
40UINTN mGaugeNumberOfEntries = 0;\r
f0da4d7d
SZ
41GAUGE_DATA_ENTRY_EX *mGaugeDataEx = NULL;\r
42UINTN mGaugeNumberOfEntriesEx = 0;\r
d042c6e8 43\r
11948471
SZ
44BOOLEAN mNoSmmPerfHandler = FALSE;\r
45BOOLEAN mNoSmmPerfExHandler = FALSE;\r
46\r
dccfb097
SZ
47//\r
48// The cached Performance Protocol and PerformanceEx Protocol interface.\r
49//\r
50PERFORMANCE_PROTOCOL *mPerformance = NULL;\r
51PERFORMANCE_EX_PROTOCOL *mPerformanceEx = NULL;\r
52\r
d042c6e8 53/**\r
f0da4d7d 54 The function caches the pointer to SMM Communication protocol.\r
d042c6e8 55\r
f0da4d7d 56 The function locates SMM Communication protocol from protocol database.\r
d042c6e8 57\r
f0da4d7d
SZ
58 @retval EFI_SUCCESS SMM Communication protocol is successfully located.\r
59 @retval Other SMM Communication protocol is not located to log performance.\r
d042c6e8 60\r
61**/\r
62EFI_STATUS\r
63GetCommunicationProtocol (\r
64 VOID\r
65 )\r
66{\r
67 EFI_STATUS Status;\r
68 EFI_SMM_COMMUNICATION_PROTOCOL *Communication;\r
69\r
70 if (mSmmCommunication != NULL) {\r
71 return EFI_SUCCESS;\r
72 }\r
73\r
74 Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &Communication);\r
75 if (!EFI_ERROR (Status)) {\r
76 ASSERT (Communication != NULL);\r
77 //\r
78 // Cache SMM Communication protocol.\r
79 //\r
80 mSmmCommunication = Communication;\r
81 }\r
82\r
83 return Status;\r
84}\r
85\r
dccfb097
SZ
86/**\r
87 The function caches the pointers to PerformanceEx protocol and Performance Protocol.\r
88\r
89 The function locates PerformanceEx protocol and Performance Protocol from protocol database.\r
90\r
91 @retval EFI_SUCCESS PerformanceEx protocol or Performance Protocol is successfully located.\r
92 @retval EFI_NOT_FOUND Both PerformanceEx protocol and Performance Protocol are not located to log performance.\r
93\r
94**/\r
95EFI_STATUS\r
96GetPerformanceProtocol (\r
97 VOID\r
98 )\r
99{\r
100 EFI_STATUS Status;\r
101 PERFORMANCE_PROTOCOL *Performance;\r
102 PERFORMANCE_EX_PROTOCOL *PerformanceEx;\r
103\r
104 if (mPerformanceEx != NULL || mPerformance != NULL) {\r
105 return EFI_SUCCESS;\r
106 }\r
107\r
108 Status = gBS->LocateProtocol (&gPerformanceExProtocolGuid, NULL, (VOID **) &PerformanceEx);\r
109 if (!EFI_ERROR (Status)) {\r
110 ASSERT (PerformanceEx != NULL);\r
111 //\r
112 // Cache PerformanceEx Protocol.\r
113 //\r
114 mPerformanceEx = PerformanceEx;\r
115 return EFI_SUCCESS;\r
116 }\r
117\r
118 Status = gBS->LocateProtocol (&gPerformanceProtocolGuid, NULL, (VOID **) &Performance);\r
119 if (!EFI_ERROR (Status)) {\r
120 ASSERT (Performance != NULL);\r
121 //\r
122 // Cache performance protocol.\r
123 //\r
124 mPerformance = Performance;\r
125 return EFI_SUCCESS;\r
126 }\r
127\r
128 return EFI_NOT_FOUND;\r
129}\r
130\r
f0da4d7d
SZ
131/**\r
132 Creates a record for the beginning of a performance measurement.\r
133\r
134 Creates a record that contains the Handle, Token, Module and Identifier.\r
135 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
136 If TimeStamp is zero, then this function reads the current time stamp\r
137 and adds that time stamp value to the record as the start time.\r
138\r
139 @param Handle Pointer to environment specific context used\r
140 to identify the component being measured.\r
141 @param Token Pointer to a Null-terminated ASCII string\r
142 that identifies the component being measured.\r
143 @param Module Pointer to a Null-terminated ASCII string\r
144 that identifies the module being measured.\r
145 @param TimeStamp 64-bit time stamp.\r
146 @param Identifier 32-bit identifier. If the value is 0, the created record\r
147 is same as the one created by StartPerformanceMeasurement.\r
148\r
149 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
150 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
151\r
152**/\r
153RETURN_STATUS\r
154EFIAPI\r
155StartPerformanceMeasurementEx (\r
156 IN CONST VOID *Handle, OPTIONAL\r
157 IN CONST CHAR8 *Token, OPTIONAL\r
158 IN CONST CHAR8 *Module, OPTIONAL\r
159 IN UINT64 TimeStamp,\r
160 IN UINT32 Identifier\r
161 )\r
162{\r
163 return RETURN_SUCCESS;\r
164}\r
165\r
166/**\r
167 Fills in the end time of a performance measurement.\r
168\r
7a9395cd 169 Looks up the record that matches Handle, Token and Module.\r
f0da4d7d
SZ
170 If the record can not be found then return RETURN_NOT_FOUND.\r
171 If the record is found and TimeStamp is not zero,\r
172 then TimeStamp is added to the record as the end time.\r
173 If the record is found and TimeStamp is zero, then this function reads\r
174 the current time stamp and adds that time stamp value to the record as the end time.\r
175\r
176 @param Handle Pointer to environment specific context used\r
177 to identify the component being measured.\r
178 @param Token Pointer to a Null-terminated ASCII string\r
179 that identifies the component being measured.\r
180 @param Module Pointer to a Null-terminated ASCII string\r
181 that identifies the module being measured.\r
182 @param TimeStamp 64-bit time stamp.\r
183 @param Identifier 32-bit identifier. If the value is 0, the found record\r
184 is same as the one found by EndPerformanceMeasurement.\r
185\r
186 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
187 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
188\r
189**/\r
190RETURN_STATUS\r
191EFIAPI\r
192EndPerformanceMeasurementEx (\r
193 IN CONST VOID *Handle, OPTIONAL\r
194 IN CONST CHAR8 *Token, OPTIONAL\r
195 IN CONST CHAR8 *Module, OPTIONAL\r
196 IN UINT64 TimeStamp,\r
197 IN UINT32 Identifier\r
198 )\r
199{\r
200 return RETURN_SUCCESS;\r
201}\r
202\r
d042c6e8 203/**\r
204 Creates a record for the beginning of a performance measurement.\r
205\r
206 Creates a record that contains the Handle, Token, and Module.\r
207 If TimeStamp is not zero, then TimeStamp is added to the record as the start time.\r
208 If TimeStamp is zero, then this function reads the current time stamp\r
209 and adds that time stamp value to the record as the start time.\r
210\r
211 @param Handle Pointer to environment specific context used\r
212 to identify the component being measured.\r
213 @param Token Pointer to a Null-terminated ASCII string\r
214 that identifies the component being measured.\r
215 @param Module Pointer to a Null-terminated ASCII string\r
216 that identifies the module being measured.\r
217 @param TimeStamp 64-bit time stamp.\r
218\r
219 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
220 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
221\r
222**/\r
223RETURN_STATUS\r
224EFIAPI\r
225StartPerformanceMeasurement (\r
226 IN CONST VOID *Handle, OPTIONAL\r
227 IN CONST CHAR8 *Token, OPTIONAL\r
228 IN CONST CHAR8 *Module, OPTIONAL\r
229 IN UINT64 TimeStamp\r
230 )\r
231{\r
f0da4d7d 232 return RETURN_SUCCESS;\r
d042c6e8 233}\r
234\r
235/**\r
236 Fills in the end time of a performance measurement.\r
237\r
238 Looks up the record that matches Handle, Token, and Module.\r
239 If the record can not be found then return RETURN_NOT_FOUND.\r
240 If the record is found and TimeStamp is not zero,\r
241 then TimeStamp is added to the record as the end time.\r
242 If the record is found and TimeStamp is zero, then this function reads\r
243 the current time stamp and adds that time stamp value to the record as the end time.\r
d042c6e8 244\r
245 @param Handle Pointer to environment specific context used\r
246 to identify the component being measured.\r
247 @param Token Pointer to a Null-terminated ASCII string\r
248 that identifies the component being measured.\r
249 @param Module Pointer to a Null-terminated ASCII string\r
250 that identifies the module being measured.\r
251 @param TimeStamp 64-bit time stamp.\r
252\r
253 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
254 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
255\r
256**/\r
257RETURN_STATUS\r
258EFIAPI\r
259EndPerformanceMeasurement (\r
260 IN CONST VOID *Handle, OPTIONAL\r
261 IN CONST CHAR8 *Token, OPTIONAL\r
262 IN CONST CHAR8 *Module, OPTIONAL\r
263 IN UINT64 TimeStamp\r
264 )\r
265{\r
f0da4d7d 266 return RETURN_SUCCESS;\r
d042c6e8 267}\r
268\r
dccfb097
SZ
269/**\r
270 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
271 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
272 and then assign the Identifier with 0.\r
273\r
274 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
275 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
276 and the key for the second entry in the log is returned. If the performance log is empty,\r
277 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
278 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
279 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
280 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
281 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
282 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
283 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
284 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
285 If Handle is NULL, then ASSERT().\r
286 If Token is NULL, then ASSERT().\r
287 If Module is NULL, then ASSERT().\r
288 If StartTimeStamp is NULL, then ASSERT().\r
289 If EndTimeStamp is NULL, then ASSERT().\r
290 If Identifier is NULL, then ASSERT().\r
291\r
292 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
293 0, then the first performance measurement log entry is retrieved.\r
294 On exit, the key of the next performance log entry.\r
295 @param Handle Pointer to environment specific context used to identify the component\r
296 being measured.\r
297 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
298 being measured.\r
299 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
300 being measured.\r
301 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
302 was started.\r
303 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
304 was ended.\r
305 @param Identifier Pointer to the 32-bit identifier that was recorded.\r
306\r
307 @return The key for the next performance log entry (in general case).\r
308\r
309**/\r
310UINTN\r
311EFIAPI\r
312GetByPerformanceProtocol (\r
313 IN UINTN LogEntryKey, \r
314 OUT CONST VOID **Handle,\r
315 OUT CONST CHAR8 **Token,\r
316 OUT CONST CHAR8 **Module,\r
317 OUT UINT64 *StartTimeStamp,\r
318 OUT UINT64 *EndTimeStamp,\r
319 OUT UINT32 *Identifier\r
320 )\r
321{\r
322 EFI_STATUS Status;\r
323 GAUGE_DATA_ENTRY_EX *GaugeData;\r
324\r
325 Status = GetPerformanceProtocol ();\r
326 if (EFI_ERROR (Status)) {\r
327 return 0;\r
328 }\r
329\r
330 if (mPerformanceEx != NULL) {\r
331 Status = mPerformanceEx->GetGaugeEx (LogEntryKey++, &GaugeData);\r
332 } else if (mPerformance != NULL) {\r
333 Status = mPerformance->GetGauge (LogEntryKey++, (GAUGE_DATA_ENTRY **) &GaugeData);\r
334 } else {\r
335 ASSERT (FALSE);\r
336 return 0;\r
337 }\r
338\r
339 //\r
340 // Make sure that LogEntryKey is a valid log entry key,\r
341 //\r
342 ASSERT (Status != EFI_INVALID_PARAMETER);\r
343\r
344 if (EFI_ERROR (Status)) {\r
345 //\r
346 // The LogEntryKey is the last entry (equals to the total entry number).\r
347 //\r
348 return 0;\r
349 }\r
350\r
351 ASSERT (GaugeData != NULL);\r
352\r
353 *Handle = (VOID *) (UINTN) GaugeData->Handle;\r
354 *Token = GaugeData->Token;\r
355 *Module = GaugeData->Module;\r
356 *StartTimeStamp = GaugeData->StartTimeStamp;\r
357 *EndTimeStamp = GaugeData->EndTimeStamp;\r
358 if (mPerformanceEx != NULL) {\r
359 *Identifier = GaugeData->Identifier;\r
360 } else {\r
361 *Identifier = 0;\r
362 }\r
363\r
364 return LogEntryKey;\r
365}\r
366\r
367\r
d042c6e8 368/**\r
369 Retrieves all previous logged performance measurement.\r
370 Function will use SMM communicate protocol to get all previous SMM performance measurement data.\r
371 If success, data buffer will be returned. If fail function will return NULL.\r
372\r
dccfb097
SZ
373 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
374 0, then the first performance measurement log entry is retrieved.\r
375 On exit, the key of the next performance log entry.\r
376\r
d042c6e8 377 @retval !NULL Get all gauge data success.\r
11948471 378 @retval NULL Get all gauge data failed.\r
d042c6e8 379**/\r
f0da4d7d 380GAUGE_DATA_ENTRY *\r
d042c6e8 381EFIAPI\r
dccfb097
SZ
382GetAllSmmGaugeData (\r
383 IN UINTN LogEntryKey\r
384 )\r
d042c6e8 385{\r
386 EFI_STATUS Status;\r
387 EFI_SMM_COMMUNICATE_HEADER *SmmCommBufferHeader;\r
388 SMM_PERF_COMMUNICATE *SmmPerfCommData;\r
389 UINTN CommSize;\r
390 UINTN DataSize;\r
391\r
11948471
SZ
392 if (mNoSmmPerfHandler) {\r
393 //\r
394 // Not try to get the SMM gauge data again\r
395 // if no SMM Performance handler found.\r
396 //\r
397 return NULL;\r
398 }\r
399\r
dccfb097
SZ
400 if (LogEntryKey != 0) {\r
401 if (mGaugeData != NULL) {\r
402 return mGaugeData;\r
403 }\r
404 } else {\r
405 //\r
11948471 406 // Reget the SMM gauge data at the first entry get.\r
dccfb097
SZ
407 //\r
408 if (mGaugeData != NULL) {\r
409 FreePool (mGaugeData);\r
410 mGaugeData = NULL;\r
411 mGaugeNumberOfEntries = 0;\r
412 }\r
d042c6e8 413 }\r
414\r
415 Status = GetCommunicationProtocol ();\r
416 if (EFI_ERROR (Status)) {\r
417 return NULL;\r
418 }\r
419\r
420 //\r
421 // Initialize communicate buffer \r
422 //\r
f0da4d7d
SZ
423 SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER *)mSmmPerformanceBuffer;\r
424 SmmPerfCommData = (SMM_PERF_COMMUNICATE *)SmmCommBufferHeader->Data;\r
d042c6e8 425 ZeroMem((UINT8*)SmmPerfCommData, sizeof(SMM_PERF_COMMUNICATE));\r
426 \r
427 CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gSmmPerformanceProtocolGuid);\r
428 SmmCommBufferHeader->MessageLength = sizeof(SMM_PERF_COMMUNICATE);\r
f0da4d7d 429 CommSize = SMM_PERFORMANCE_COMMUNICATION_BUFFER_SIZE;\r
d042c6e8 430\r
431 //\r
11948471 432 // Get total number of SMM gauge entries\r
d042c6e8 433 //\r
434 SmmPerfCommData->Function = SMM_PERF_FUNCTION_GET_GAUGE_ENTRY_NUMBER;\r
435 Status = mSmmCommunication->Communicate (mSmmCommunication, mSmmPerformanceBuffer, &CommSize);\r
11948471
SZ
436 if (Status == EFI_NOT_FOUND) {\r
437 mNoSmmPerfHandler = TRUE;\r
438 }\r
f0da4d7d 439 if (EFI_ERROR (Status) || EFI_ERROR (SmmPerfCommData->ReturnStatus) || SmmPerfCommData->NumberOfEntries == 0) {\r
d042c6e8 440 return NULL;\r
441 }\r
442\r
443 mGaugeNumberOfEntries = SmmPerfCommData->NumberOfEntries;\r
444 \r
445 DataSize = mGaugeNumberOfEntries * sizeof(GAUGE_DATA_ENTRY);\r
446 mGaugeData = AllocateZeroPool(DataSize);\r
f0da4d7d 447 ASSERT (mGaugeData != NULL);\r
d042c6e8 448 \r
449 //\r
450 // Get all SMM gauge data\r
451 // \r
452 SmmPerfCommData->Function = SMM_PERF_FUNCTION_GET_GAUGE_DATA;\r
453 SmmPerfCommData->LogEntryKey = 0;\r
454 SmmPerfCommData->NumberOfEntries = mGaugeNumberOfEntries;\r
455 SmmPerfCommData->GaugeData = mGaugeData;\r
456 Status = mSmmCommunication->Communicate (mSmmCommunication, mSmmPerformanceBuffer, &CommSize);\r
f0da4d7d
SZ
457 if (EFI_ERROR (Status) || EFI_ERROR (SmmPerfCommData->ReturnStatus)) {\r
458 FreePool (mGaugeData);\r
459 mGaugeData = NULL;\r
460 mGaugeNumberOfEntries = 0;\r
461 }\r
d042c6e8 462\r
f0da4d7d 463 return mGaugeData;\r
d042c6e8 464}\r
465\r
466/**\r
f0da4d7d
SZ
467 Retrieves all previous logged performance measurement.\r
468 Function will use SMM communicate protocol to get all previous SMM performance measurement data.\r
469 If success, data buffer will be returned. If fail function will return NULL.\r
d042c6e8 470\r
dccfb097
SZ
471 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
472 0, then the first performance measurement log entry is retrieved.\r
473 On exit, the key of the next performance log entry.\r
474\r
f0da4d7d 475 @retval !NULL Get all gauge data success.\r
11948471 476 @retval NULL Get all gauge data failed.\r
d042c6e8 477**/\r
f0da4d7d 478GAUGE_DATA_ENTRY_EX *\r
d042c6e8 479EFIAPI\r
dccfb097
SZ
480GetAllSmmGaugeDataEx (\r
481 IN UINTN LogEntryKey\r
482 )\r
d042c6e8 483{\r
f0da4d7d
SZ
484 EFI_STATUS Status;\r
485 EFI_SMM_COMMUNICATE_HEADER *SmmCommBufferHeader;\r
486 SMM_PERF_COMMUNICATE_EX *SmmPerfCommData;\r
487 UINTN CommSize;\r
488 UINTN DataSize;\r
489\r
11948471
SZ
490 if (mNoSmmPerfExHandler) {\r
491 //\r
492 // Not try to get the SMM gauge data again\r
493 // if no SMM PerformanceEx handler found.\r
494 //\r
495 return NULL;\r
496 }\r
497\r
dccfb097
SZ
498 if (LogEntryKey != 0) {\r
499 if (mGaugeDataEx != NULL) {\r
500 return mGaugeDataEx;\r
501 }\r
502 } else {\r
503 //\r
11948471 504 // Reget the SMM gauge data at the first entry get.\r
dccfb097
SZ
505 //\r
506 if (mGaugeDataEx != NULL) {\r
507 FreePool (mGaugeDataEx);\r
508 mGaugeDataEx = NULL;\r
509 mGaugeNumberOfEntriesEx = 0;\r
510 }\r
d042c6e8 511 }\r
f0da4d7d
SZ
512\r
513 Status = GetCommunicationProtocol ();\r
514 if (EFI_ERROR (Status)) {\r
515 return NULL;\r
d042c6e8 516 }\r
517\r
f0da4d7d
SZ
518 //\r
519 // Initialize communicate buffer \r
520 //\r
521 SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER *)mSmmPerformanceBuffer;\r
522 SmmPerfCommData = (SMM_PERF_COMMUNICATE_EX *)SmmCommBufferHeader->Data;\r
523 ZeroMem((UINT8*)SmmPerfCommData, sizeof(SMM_PERF_COMMUNICATE_EX));\r
524 \r
525 CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gSmmPerformanceExProtocolGuid);\r
526 SmmCommBufferHeader->MessageLength = sizeof(SMM_PERF_COMMUNICATE_EX);\r
527 CommSize = SMM_PERFORMANCE_COMMUNICATION_BUFFER_SIZE;\r
528\r
529 //\r
11948471 530 // Get total number of SMM gauge entries\r
f0da4d7d
SZ
531 //\r
532 SmmPerfCommData->Function = SMM_PERF_FUNCTION_GET_GAUGE_ENTRY_NUMBER;\r
533 Status = mSmmCommunication->Communicate (mSmmCommunication, mSmmPerformanceBuffer, &CommSize);\r
11948471
SZ
534 if (Status == EFI_NOT_FOUND) {\r
535 mNoSmmPerfExHandler = TRUE;\r
536 }\r
f0da4d7d
SZ
537 if (EFI_ERROR (Status) || EFI_ERROR (SmmPerfCommData->ReturnStatus) || SmmPerfCommData->NumberOfEntries == 0) {\r
538 return NULL;\r
d042c6e8 539 }\r
d042c6e8 540\r
f0da4d7d
SZ
541 mGaugeNumberOfEntriesEx = SmmPerfCommData->NumberOfEntries;\r
542 \r
543 DataSize = mGaugeNumberOfEntriesEx * sizeof(GAUGE_DATA_ENTRY_EX);\r
544 mGaugeDataEx = AllocateZeroPool(DataSize);\r
545 ASSERT (mGaugeDataEx != NULL);\r
546 \r
547 //\r
548 // Get all SMM gauge data\r
549 // \r
550 SmmPerfCommData->Function = SMM_PERF_FUNCTION_GET_GAUGE_DATA;\r
551 SmmPerfCommData->LogEntryKey = 0;\r
552 SmmPerfCommData->NumberOfEntries = mGaugeNumberOfEntriesEx;\r
553 SmmPerfCommData->GaugeDataEx = mGaugeDataEx;\r
554 Status = mSmmCommunication->Communicate (mSmmCommunication, mSmmPerformanceBuffer, &CommSize);\r
555 if (EFI_ERROR (Status) || EFI_ERROR (SmmPerfCommData->ReturnStatus)) {\r
556 FreePool (mGaugeDataEx);\r
557 mGaugeDataEx = NULL;\r
558 mGaugeNumberOfEntriesEx = 0;\r
559 }\r
560 \r
561 return mGaugeDataEx;\r
d042c6e8 562}\r
563\r
564/**\r
565 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
f0da4d7d
SZ
566 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
567 and then assign the Identifier with 0.\r
d042c6e8 568\r
569 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
570 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
571 and the key for the second entry in the log is returned. If the performance log is empty,\r
572 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
573 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
574 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
575 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
576 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
577 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
f0da4d7d 578 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
d042c6e8 579 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
580 If Handle is NULL, then ASSERT().\r
581 If Token is NULL, then ASSERT().\r
582 If Module is NULL, then ASSERT().\r
583 If StartTimeStamp is NULL, then ASSERT().\r
584 If EndTimeStamp is NULL, then ASSERT().\r
f0da4d7d 585 If Identifier is NULL, then ASSERT().\r
d042c6e8 586\r
587 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
588 0, then the first performance measurement log entry is retrieved.\r
589 On exit, the key of the next performance log entry.\r
590 @param Handle Pointer to environment specific context used to identify the component\r
591 being measured.\r
592 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
593 being measured.\r
594 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
595 being measured.\r
596 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
597 was started.\r
598 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
599 was ended.\r
f0da4d7d 600 @param Identifier Pointer to the 32-bit identifier that was recorded.\r
d042c6e8 601\r
602 @return The key for the next performance log entry (in general case).\r
603\r
604**/\r
605UINTN\r
606EFIAPI\r
f0da4d7d
SZ
607GetPerformanceMeasurementEx (\r
608 IN UINTN LogEntryKey, \r
d042c6e8 609 OUT CONST VOID **Handle,\r
610 OUT CONST CHAR8 **Token,\r
611 OUT CONST CHAR8 **Module,\r
612 OUT UINT64 *StartTimeStamp,\r
f0da4d7d
SZ
613 OUT UINT64 *EndTimeStamp,\r
614 OUT UINT32 *Identifier\r
d042c6e8 615 )\r
616{\r
f0da4d7d 617 GAUGE_DATA_ENTRY_EX *GaugeData;\r
d042c6e8 618\r
619 GaugeData = NULL;\r
620\r
621 ASSERT (Handle != NULL);\r
622 ASSERT (Token != NULL);\r
623 ASSERT (Module != NULL);\r
624 ASSERT (StartTimeStamp != NULL);\r
625 ASSERT (EndTimeStamp != NULL);\r
f0da4d7d 626 ASSERT (Identifier != NULL);\r
d042c6e8 627\r
dccfb097 628 mGaugeDataEx = GetAllSmmGaugeDataEx (LogEntryKey);\r
f0da4d7d 629 if (mGaugeDataEx != NULL) {\r
dccfb097
SZ
630 if (LogEntryKey >= mGaugeNumberOfEntriesEx) {\r
631 //\r
632 // Try to get the data by Performance Protocol.\r
633 //\r
634 LogEntryKey = LogEntryKey - mGaugeNumberOfEntriesEx;\r
635 LogEntryKey = GetByPerformanceProtocol (\r
636 LogEntryKey,\r
637 Handle,\r
638 Token,\r
639 Module,\r
640 StartTimeStamp,\r
641 EndTimeStamp,\r
642 Identifier\r
643 );\r
644 if (LogEntryKey == 0) {\r
645 //\r
646 // Last entry.\r
647 //\r
648 return LogEntryKey;\r
649 } else {\r
650 return (LogEntryKey + mGaugeNumberOfEntriesEx);\r
651 }\r
f0da4d7d
SZ
652 }\r
653\r
654 GaugeData = &mGaugeDataEx[LogEntryKey++];\r
655 *Identifier = GaugeData->Identifier;\r
656 } else {\r
dccfb097 657 mGaugeData = GetAllSmmGaugeData (LogEntryKey);\r
f0da4d7d 658 if (mGaugeData != NULL) {\r
dccfb097
SZ
659 if (LogEntryKey >= mGaugeNumberOfEntries) {\r
660 //\r
661 // Try to get the data by Performance Protocol.\r
662 //\r
663 LogEntryKey = LogEntryKey - mGaugeNumberOfEntries;\r
664 LogEntryKey = GetByPerformanceProtocol (\r
665 LogEntryKey,\r
666 Handle,\r
667 Token,\r
668 Module,\r
669 StartTimeStamp,\r
670 EndTimeStamp,\r
671 Identifier\r
672 );\r
673 if (LogEntryKey == 0) {\r
674 //\r
675 // Last entry.\r
676 //\r
677 return LogEntryKey;\r
678 } else {\r
679 return (LogEntryKey + mGaugeNumberOfEntries);\r
680 }\r
f0da4d7d
SZ
681 }\r
682\r
683 GaugeData = (GAUGE_DATA_ENTRY_EX *) &mGaugeData[LogEntryKey++];\r
684 *Identifier = 0;\r
685 } else {\r
11948471
SZ
686 return GetByPerformanceProtocol (\r
687 LogEntryKey,\r
688 Handle,\r
689 Token,\r
690 Module,\r
691 StartTimeStamp,\r
692 EndTimeStamp,\r
693 Identifier\r
694 );\r
f0da4d7d 695 }\r
d042c6e8 696 }\r
697\r
d042c6e8 698 *Handle = (VOID *) (UINTN) GaugeData->Handle;\r
699 *Token = GaugeData->Token;\r
700 *Module = GaugeData->Module;\r
701 *StartTimeStamp = GaugeData->StartTimeStamp;\r
702 *EndTimeStamp = GaugeData->EndTimeStamp;\r
703\r
704 return LogEntryKey;\r
705}\r
706\r
f0da4d7d
SZ
707/**\r
708 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
709 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
710 and then eliminate the Identifier.\r
711\r
712 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
713 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
714 and the key for the second entry in the log is returned. If the performance log is empty,\r
715 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
716 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
717 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
718 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
719 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
720 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
721 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
722 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
723 If Handle is NULL, then ASSERT().\r
724 If Token is NULL, then ASSERT().\r
725 If Module is NULL, then ASSERT().\r
726 If StartTimeStamp is NULL, then ASSERT().\r
727 If EndTimeStamp is NULL, then ASSERT().\r
728\r
729 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
730 0, then the first performance measurement log entry is retrieved.\r
731 On exit, the key of the next performance log entry.\r
732 @param Handle Pointer to environment specific context used to identify the component\r
733 being measured.\r
734 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
735 being measured.\r
736 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
737 being measured.\r
738 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
739 was started.\r
740 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
741 was ended.\r
742\r
743 @return The key for the next performance log entry (in general case).\r
744\r
745**/\r
746UINTN\r
747EFIAPI\r
748GetPerformanceMeasurement (\r
749 IN UINTN LogEntryKey,\r
750 OUT CONST VOID **Handle,\r
751 OUT CONST CHAR8 **Token,\r
752 OUT CONST CHAR8 **Module,\r
753 OUT UINT64 *StartTimeStamp,\r
754 OUT UINT64 *EndTimeStamp\r
755 )\r
756{\r
757 UINT32 Identifier;\r
758 return GetPerformanceMeasurementEx (LogEntryKey, Handle, Token, Module, StartTimeStamp, EndTimeStamp, &Identifier);\r
759}\r
760\r
d042c6e8 761/**\r
762 Returns TRUE if the performance measurement macros are enabled.\r
763\r
764 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
765 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
766\r
767 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
768 PcdPerformanceLibraryPropertyMask is set.\r
769 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
770 PcdPerformanceLibraryPropertyMask is clear.\r
771\r
772**/\r
773BOOLEAN\r
774EFIAPI\r
775PerformanceMeasurementEnabled (\r
776 VOID\r
777 )\r
778{\r
779 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
780}\r