]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
MdeModulePkg: Change OPTIONAL keyword usage style
[mirror_edk2.git] / MdeModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
CommitLineData
8dbae30d 1/** @file\r
857dfc45 2 Performance library instance mainly used by DxeCore.\r
3\r
4 This library provides the performance measurement interfaces and initializes performance\r
5 logging for DXE phase. It first initializes its private global data structure for\r
d1102dba 6 performance logging and saves the performance GUIDed HOB passed from PEI phase.\r
f0da4d7d
SZ
7 It initializes DXE phase performance logging by publishing the Performance and PerformanceEx Protocol,\r
8 which are consumed by DxePerformanceLib to logging performance data in DXE phase.\r
857dfc45 9\r
10 This library is mainly used by DxeCore to start performance logging to ensure that\r
11 Performance Protocol is installed at the very beginning of DXE phase.\r
a0afd019 12\r
466ebdd2 13Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>\r
7c50b343 14(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
9d510e61 15SPDX-License-Identifier: BSD-2-Clause-Patent\r
a0afd019 16\r
8dbae30d 17**/\r
a0afd019 18\r
ed7748fe 19\r
aa79b0b3 20#include "DxeCorePerformanceLibInternal.h"\r
ed7748fe 21\r
a0afd019 22//\r
9609d24b 23// Data for FPDT performance records.\r
a0afd019 24//\r
9609d24b
DB
25#define SMM_BOOT_RECORD_COMM_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE))\r
26#define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))\r
27#define FIRMWARE_RECORD_BUFFER 0x10000\r
28#define CACHE_HANDLE_GUID_COUNT 0x800\r
29\r
30BOOT_PERFORMANCE_TABLE *mAcpiBootPerformanceTable = NULL;\r
31BOOT_PERFORMANCE_TABLE mBootPerformanceTableTemplate = {\r
32 {\r
33 EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE,\r
34 sizeof (BOOT_PERFORMANCE_TABLE)\r
35 },\r
36 {\r
37 {\r
38 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT, // Type\r
39 sizeof (EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD), // Length\r
40 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT // Revision\r
41 },\r
42 0, // Reserved\r
43 //\r
44 // These values will be updated at runtime.\r
45 //\r
46 0, // ResetEnd\r
47 0, // OsLoaderLoadImageStart\r
48 0, // OsLoaderStartImageStart\r
49 0, // ExitBootServicesEntry\r
50 0 // ExitBootServicesExit\r
51 }\r
52};\r
857dfc45 53\r
9609d24b
DB
54typedef struct {\r
55 EFI_HANDLE Handle;\r
56 CHAR8 NameString[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];\r
57 EFI_GUID ModuleGuid;\r
58} HANDLE_GUID_MAP;\r
a0afd019 59\r
9609d24b
DB
60HANDLE_GUID_MAP mCacheHandleGuidTable[CACHE_HANDLE_GUID_COUNT];\r
61UINTN mCachePairCount = 0;\r
62\r
63UINT32 mLoadImageCount = 0;\r
64UINT32 mPerformanceLength = 0;\r
65UINT32 mMaxPerformanceLength = 0;\r
66UINT32 mBootRecordSize = 0;\r
466ebdd2 67UINTN mBootRecordMaxSize = 0;\r
6b4d58a1 68UINT32 mCachedLength = 0;\r
9609d24b
DB
69\r
70BOOLEAN mFpdtBufferIsReported = FALSE;\r
71BOOLEAN mLackSpaceIsReported = FALSE;\r
72CHAR8 *mPlatformLanguage = NULL;\r
73UINT8 *mPerformancePointer = NULL;\r
74UINT8 *mBootRecordBuffer = NULL;\r
75BOOLEAN mLockInsertRecord = FALSE;\r
6b4d58a1 76CHAR8 *mDevicePathString = NULL;\r
9609d24b
DB
77\r
78EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *mDevicePathToText = NULL;\r
857dfc45 79\r
80//\r
137fb13d 81// Interfaces for PerformanceMeasurement Protocol.\r
857dfc45 82//\r
137fb13d
BD
83EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {\r
84 CreatePerformanceMeasurement,\r
f0da4d7d
SZ
85 };\r
86\r
cfb0aba7
SZ
87PERFORMANCE_PROPERTY mPerformanceProperty;\r
88\r
6b4d58a1
BD
89/**\r
90 Return the pointer to the FPDT record in the allocated memory.\r
91\r
92 @param RecordSize The size of FPDT record.\r
93 @param FpdtRecordPtr Pointer the FPDT record in the allocated memory.\r
94\r
95 @retval EFI_SUCCESS Successfully get the pointer to the FPDT record.\r
96 @retval EFI_OUT_OF_RESOURCES Ran out of space to store the records.\r
97**/\r
98EFI_STATUS\r
99GetFpdtRecordPtr (\r
100 IN UINT8 RecordSize,\r
101 IN OUT FPDT_RECORD_PTR *FpdtRecordPtr\r
102)\r
103{\r
104 if (mFpdtBufferIsReported) {\r
105 //\r
106 // Append Boot records to the boot performance table.\r
107 //\r
108 if (mBootRecordSize + RecordSize > mBootRecordMaxSize) {\r
109 if (!mLackSpaceIsReported) {\r
110 DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: No enough space to save boot records\n"));\r
111 mLackSpaceIsReported = TRUE;\r
112 }\r
113 return EFI_OUT_OF_RESOURCES;\r
114 } else {\r
115 //\r
116 // Save boot record into BootPerformance table\r
117 //\r
118 FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mBootRecordSize);\r
119 }\r
120 } else {\r
121 //\r
122 // Check if pre-allocated buffer is full\r
123 //\r
124 if (mPerformanceLength + RecordSize > mMaxPerformanceLength) {\r
125 mPerformancePointer = ReallocatePool (\r
126 mPerformanceLength,\r
127 mPerformanceLength + RecordSize + FIRMWARE_RECORD_BUFFER,\r
128 mPerformancePointer\r
129 );\r
130 if (mPerformancePointer == NULL) {\r
131 return EFI_OUT_OF_RESOURCES;\r
132 }\r
133 mMaxPerformanceLength = mPerformanceLength + RecordSize + FIRMWARE_RECORD_BUFFER;\r
134 }\r
135 //\r
136 // Covert buffer to FPDT Ptr Union type.\r
137 //\r
138 FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mPerformanceLength);\r
139 }\r
140 return EFI_SUCCESS;\r
141}\r
142\r
9609d24b
DB
143/**\r
144Check whether the Token is a known one which is uesed by core.\r
145\r
146@param Token Pointer to a Null-terminated ASCII string\r
147\r
148@retval TRUE Is a known one used by core.\r
149@retval FALSE Not a known one.\r
150\r
151**/\r
152BOOLEAN\r
153IsKnownTokens (\r
154 IN CONST CHAR8 *Token\r
155 )\r
156{\r
c9faac27
DB
157 if (Token == NULL) {\r
158 return FALSE;\r
159 }\r
160\r
9609d24b
DB
161 if (AsciiStrCmp (Token, SEC_TOK) == 0 ||\r
162 AsciiStrCmp (Token, PEI_TOK) == 0 ||\r
163 AsciiStrCmp (Token, DXE_TOK) == 0 ||\r
164 AsciiStrCmp (Token, BDS_TOK) == 0 ||\r
165 AsciiStrCmp (Token, DRIVERBINDING_START_TOK) == 0 ||\r
166 AsciiStrCmp (Token, DRIVERBINDING_SUPPORT_TOK) == 0 ||\r
167 AsciiStrCmp (Token, DRIVERBINDING_STOP_TOK) == 0 ||\r
168 AsciiStrCmp (Token, LOAD_IMAGE_TOK) == 0 ||\r
169 AsciiStrCmp (Token, START_IMAGE_TOK) == 0 ||\r
170 AsciiStrCmp (Token, PEIM_TOK) == 0) {\r
171 return TRUE;\r
172 } else {\r
173 return FALSE;\r
174 }\r
175}\r
f1f7190b 176\r
a0afd019 177/**\r
9609d24b
DB
178Check whether the ID is a known one which map to the known Token.\r
179\r
180@param Identifier 32-bit identifier.\r
181\r
182@retval TRUE Is a known one used by core.\r
183@retval FALSE Not a known one.\r
184\r
185**/\r
186BOOLEAN\r
187IsKnownID (\r
188 IN UINT32 Identifier\r
189 )\r
190{\r
191 if (Identifier == MODULE_START_ID ||\r
192 Identifier == MODULE_END_ID ||\r
193 Identifier == MODULE_LOADIMAGE_START_ID ||\r
194 Identifier == MODULE_LOADIMAGE_END_ID ||\r
195 Identifier == MODULE_DB_START_ID ||\r
196 Identifier == MODULE_DB_END_ID ||\r
197 Identifier == MODULE_DB_SUPPORT_START_ID ||\r
198 Identifier == MODULE_DB_SUPPORT_END_ID ||\r
199 Identifier == MODULE_DB_STOP_START_ID ||\r
200 Identifier == MODULE_DB_STOP_END_ID) {\r
201 return TRUE;\r
202 } else {\r
203 return FALSE;\r
204 }\r
205}\r
206\r
9609d24b 207/**\r
466ebdd2 208 This internal function dumps all the SMM performance data and size.\r
9609d24b 209\r
466ebdd2
DB
210 @param SmmPerfData Smm Performance data. The buffer contain the SMM perf data is allocated by this function and caller needs to free it.\r
211 @param SmmPerfDataSize Smm Performance data size.\r
212 @param SkipGetPerfData Skip to get performance data, just get the size.\r
9609d24b
DB
213\r
214**/\r
466ebdd2
DB
215VOID\r
216InternalGetSmmPerfData (\r
217 OUT VOID **SmmPerfData,\r
218 OUT UINTN *SmmPerfDataSize,\r
219 IN BOOLEAN SkipGetPerfData\r
9609d24b
DB
220 )\r
221{\r
222 EFI_STATUS Status;\r
9609d24b
DB
223 UINT8 *SmmBootRecordCommBuffer;\r
224 EFI_SMM_COMMUNICATE_HEADER *SmmCommBufferHeader;\r
225 SMM_BOOT_RECORD_COMMUNICATE *SmmCommData;\r
226 UINTN CommSize;\r
9609d24b 227 EFI_SMM_COMMUNICATION_PROTOCOL *Communication;\r
9609d24b
DB
228 EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *SmmCommRegionTable;\r
229 EFI_MEMORY_DESCRIPTOR *SmmCommMemRegion;\r
230 UINTN Index;\r
231 VOID *SmmBootRecordData;\r
232 UINTN SmmBootRecordDataSize;\r
233 UINTN ReservedMemSize;\r
a0afd019 234\r
9609d24b
DB
235 //\r
236 // Collect boot records from SMM drivers.\r
237 //\r
238 SmmBootRecordCommBuffer = NULL;\r
239 SmmCommData = NULL;\r
240 SmmBootRecordData = NULL;\r
9609d24b
DB
241 ReservedMemSize = 0;\r
242 Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &Communication);\r
243 if (!EFI_ERROR (Status)) {\r
244 //\r
245 // Initialize communicate buffer\r
246 // Get the prepared Reserved Memory Range\r
247 //\r
248 Status = EfiGetSystemConfigurationTable (\r
249 &gEdkiiPiSmmCommunicationRegionTableGuid,\r
250 (VOID **) &SmmCommRegionTable\r
251 );\r
252 if (!EFI_ERROR (Status)) {\r
253 ASSERT (SmmCommRegionTable != NULL);\r
254 SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) (SmmCommRegionTable + 1);\r
255 for (Index = 0; Index < SmmCommRegionTable->NumberOfEntries; Index ++) {\r
256 if (SmmCommMemRegion->Type == EfiConventionalMemory) {\r
257 break;\r
258 }\r
259 SmmCommMemRegion = (EFI_MEMORY_DESCRIPTOR *) ((UINT8 *) SmmCommMemRegion + SmmCommRegionTable->DescriptorSize);\r
260 }\r
261 ASSERT (Index < SmmCommRegionTable->NumberOfEntries);\r
262 ASSERT (SmmCommMemRegion->PhysicalStart > 0);\r
263 ASSERT (SmmCommMemRegion->NumberOfPages > 0);\r
264 ReservedMemSize = (UINTN) SmmCommMemRegion->NumberOfPages * EFI_PAGE_SIZE;\r
265\r
266 //\r
267 // Check enough reserved memory space\r
268 //\r
269 if (ReservedMemSize > SMM_BOOT_RECORD_COMM_SIZE) {\r
270 SmmBootRecordCommBuffer = (VOID *) (UINTN) SmmCommMemRegion->PhysicalStart;\r
271 SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER*)SmmBootRecordCommBuffer;\r
272 SmmCommData = (SMM_BOOT_RECORD_COMMUNICATE*)SmmCommBufferHeader->Data;\r
273 ZeroMem((UINT8*)SmmCommData, sizeof(SMM_BOOT_RECORD_COMMUNICATE));\r
274\r
275 CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gEfiFirmwarePerformanceGuid);\r
276 SmmCommBufferHeader->MessageLength = sizeof(SMM_BOOT_RECORD_COMMUNICATE);\r
277 CommSize = SMM_BOOT_RECORD_COMM_SIZE;\r
278\r
279 //\r
280 // Get the size of boot records.\r
281 //\r
282 SmmCommData->Function = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE;\r
283 SmmCommData->BootRecordData = NULL;\r
284 Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
9609d24b 285\r
c9f02a96 286 if (!EFI_ERROR (Status) && !EFI_ERROR (SmmCommData->ReturnStatus) && SmmCommData->BootRecordSize != 0) {\r
466ebdd2
DB
287 if (SkipGetPerfData) {\r
288 *SmmPerfDataSize = SmmCommData->BootRecordSize;\r
289 return;\r
290 }\r
9609d24b
DB
291 //\r
292 // Get all boot records\r
293 //\r
294 SmmCommData->Function = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA_BY_OFFSET;\r
295 SmmBootRecordDataSize = SmmCommData->BootRecordSize;\r
296 SmmBootRecordData = AllocateZeroPool(SmmBootRecordDataSize);\r
297 ASSERT (SmmBootRecordData != NULL);\r
298 SmmCommData->BootRecordOffset = 0;\r
299 SmmCommData->BootRecordData = (VOID *) ((UINTN) SmmCommMemRegion->PhysicalStart + SMM_BOOT_RECORD_COMM_SIZE);\r
300 SmmCommData->BootRecordSize = ReservedMemSize - SMM_BOOT_RECORD_COMM_SIZE;\r
301 while (SmmCommData->BootRecordOffset < SmmBootRecordDataSize) {\r
302 Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
303 ASSERT_EFI_ERROR (Status);\r
304 ASSERT_EFI_ERROR(SmmCommData->ReturnStatus);\r
305 if (SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {\r
306 CopyMem ((UINT8 *) SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmBootRecordDataSize - SmmCommData->BootRecordOffset);\r
307 } else {\r
308 CopyMem ((UINT8 *) SmmBootRecordData + SmmCommData->BootRecordOffset, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);\r
309 }\r
310 SmmCommData->BootRecordOffset = SmmCommData->BootRecordOffset + SmmCommData->BootRecordSize;\r
311 }\r
466ebdd2
DB
312 *SmmPerfData = SmmBootRecordData;\r
313 *SmmPerfDataSize = SmmBootRecordDataSize;\r
9609d24b
DB
314 }\r
315 }\r
316 }\r
317 }\r
466ebdd2
DB
318}\r
319\r
320/**\r
321 Allocate buffer for Boot Performance table.\r
322\r
323 @return Status code.\r
324\r
325**/\r
326EFI_STATUS\r
327AllocateBootPerformanceTable (\r
328 VOID\r
329 )\r
330{\r
331 EFI_STATUS Status;\r
332 UINTN Size;\r
333 UINTN BootPerformanceDataSize;\r
334 UINT8 *BootPerformanceData;\r
335 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;\r
336 UINTN SmmBootRecordDataSize;\r
337\r
338 SmmBootRecordDataSize = 0;\r
339\r
340 //\r
341 // Get SMM performance data size at the point of EndOfDxe in order to allocate the boot performance table.\r
342 // Will Get all the data at ReadyToBoot.\r
343 //\r
344 InternalGetSmmPerfData (NULL, &SmmBootRecordDataSize, TRUE);\r
a0afd019 345\r
9609d24b
DB
346 //\r
347 // Prepare memory for Boot Performance table.\r
348 // Boot Performance table includes BasicBoot record, and one or more appended Boot Records.\r
349 //\r
466ebdd2 350 BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE) + mPerformanceLength + SmmBootRecordDataSize + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
9609d24b
DB
351\r
352 //\r
353 // Try to allocate the same runtime buffer as last time boot.\r
354 //\r
355 ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));\r
356 Size = sizeof (PerformanceVariable);\r
357 Status = gRT->GetVariable (\r
358 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,\r
359 &gEfiFirmwarePerformanceGuid,\r
360 NULL,\r
361 &Size,\r
362 &PerformanceVariable\r
363 );\r
364 if (!EFI_ERROR (Status)) {\r
365 Status = gBS->AllocatePages (\r
366 AllocateAddress,\r
367 EfiReservedMemoryType,\r
368 EFI_SIZE_TO_PAGES (BootPerformanceDataSize),\r
369 &PerformanceVariable.BootPerformanceTablePointer\r
370 );\r
371 if (!EFI_ERROR (Status)) {\r
372 mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.BootPerformanceTablePointer;\r
373 }\r
374 }\r
375\r
376 if (mAcpiBootPerformanceTable == NULL) {\r
377 //\r
378 // Fail to allocate at specified address, continue to allocate at any address.\r
379 //\r
d79d7b58
AB
380 mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) AllocatePeiAccessiblePages (\r
381 EfiReservedMemoryType,\r
382 EFI_SIZE_TO_PAGES (BootPerformanceDataSize)\r
383 );\r
384 if (mAcpiBootPerformanceTable != NULL) {\r
385 ZeroMem (mAcpiBootPerformanceTable, BootPerformanceDataSize);\r
386 }\r
9609d24b
DB
387 }\r
388 DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
389\r
390 if (mAcpiBootPerformanceTable == NULL) {\r
9609d24b
DB
391 return EFI_OUT_OF_RESOURCES;\r
392 }\r
393\r
394 //\r
395 // Prepare Boot Performance Table.\r
396 //\r
397 BootPerformanceData = (UINT8 *) mAcpiBootPerformanceTable;\r
398 //\r
399 // Fill Basic Boot record to Boot Performance Table.\r
400 //\r
401 CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate));\r
402 BootPerformanceData = BootPerformanceData + mAcpiBootPerformanceTable->Header.Length;\r
403 //\r
404 // Fill Boot records from boot drivers.\r
405 //\r
406 if (mPerformancePointer != NULL) {\r
407 CopyMem (BootPerformanceData, mPerformancePointer, mPerformanceLength);\r
408 mAcpiBootPerformanceTable->Header.Length += mPerformanceLength;\r
409 BootPerformanceData = BootPerformanceData + mPerformanceLength;\r
410 FreePool (mPerformancePointer);\r
411 mPerformancePointer = NULL;\r
412 mPerformanceLength = 0;\r
413 mMaxPerformanceLength = 0;\r
414 }\r
9609d24b
DB
415\r
416 mBootRecordBuffer = (UINT8 *) mAcpiBootPerformanceTable;\r
417 mBootRecordSize = mAcpiBootPerformanceTable->Header.Length;\r
466ebdd2 418 mBootRecordMaxSize = BootPerformanceDataSize;\r
9609d24b
DB
419\r
420 return EFI_SUCCESS;\r
421}\r
422\r
423/**\r
424 Get a human readable module name and module guid for the given image handle.\r
425 If module name can't be found, "" string will return.\r
426 If module guid can't be found, Zero Guid will return.\r
427\r
428 @param Handle Image handle or Controller handle.\r
429 @param NameString The ascii string will be filled into it. If not found, null string will return.\r
430 @param BufferSize Size of the input NameString buffer.\r
431 @param ModuleGuid Point to the guid buffer to store the got module guid value.\r
432\r
433 @retval EFI_SUCCESS Successfully get module name and guid.\r
434 @retval EFI_INVALID_PARAMETER The input parameter NameString is NULL.\r
435 @retval other value Module Name can't be got.\r
436**/\r
437EFI_STATUS\r
438GetModuleInfoFromHandle (\r
439 IN EFI_HANDLE Handle,\r
440 OUT CHAR8 *NameString,\r
441 IN UINTN BufferSize,\r
442 OUT EFI_GUID *ModuleGuid OPTIONAL\r
443 )\r
444{\r
445 EFI_STATUS Status;\r
446 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
447 EFI_DRIVER_BINDING_PROTOCOL *DriverBinding;\r
448 CHAR8 *PdbFileName;\r
449 EFI_GUID *TempGuid;\r
450 UINTN StartIndex;\r
451 UINTN Index;\r
452 INTN Count;\r
453 BOOLEAN ModuleGuidIsGet;\r
454 UINTN StringSize;\r
455 CHAR16 *StringPtr;\r
456 EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;\r
457 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath;\r
458\r
459 if (NameString == NULL || BufferSize == 0) {\r
460 return EFI_INVALID_PARAMETER;\r
461 }\r
462 //\r
463 // Try to get the ModuleGuid and name string form the caached array.\r
464 //\r
465 if (mCachePairCount > 0) {\r
466 for (Count = mCachePairCount -1; Count >= 0; Count--) {\r
467 if (Handle == mCacheHandleGuidTable[Count].Handle) {\r
468 CopyGuid (ModuleGuid, &mCacheHandleGuidTable[Count].ModuleGuid);\r
469 AsciiStrCpyS (NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, mCacheHandleGuidTable[Count].NameString);\r
470 return EFI_SUCCESS;\r
471 }\r
472 }\r
473 }\r
474\r
475 Status = EFI_INVALID_PARAMETER;\r
476 LoadedImage = NULL;\r
477 ModuleGuidIsGet = FALSE;\r
478\r
479 //\r
480 // Initialize GUID as zero value.\r
481 //\r
482 TempGuid = &gZeroGuid;\r
483 //\r
484 // Initialize it as "" string.\r
485 //\r
486 NameString[0] = 0;\r
487\r
488 if (Handle != NULL) {\r
489 //\r
490 // Try Handle as ImageHandle.\r
491 //\r
492 Status = gBS->HandleProtocol (\r
493 Handle,\r
494 &gEfiLoadedImageProtocolGuid,\r
495 (VOID**) &LoadedImage\r
496 );\r
497\r
498 if (EFI_ERROR (Status)) {\r
499 //\r
500 // Try Handle as Controller Handle\r
501 //\r
502 Status = gBS->OpenProtocol (\r
503 Handle,\r
504 &gEfiDriverBindingProtocolGuid,\r
505 (VOID **) &DriverBinding,\r
506 NULL,\r
507 NULL,\r
508 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
509 );\r
510 if (!EFI_ERROR (Status)) {\r
511 //\r
512 // Get Image protocol from ImageHandle\r
513 //\r
514 Status = gBS->HandleProtocol (\r
515 DriverBinding->ImageHandle,\r
516 &gEfiLoadedImageProtocolGuid,\r
517 (VOID**) &LoadedImage\r
518 );\r
519 }\r
520 }\r
521 }\r
522\r
523 if (!EFI_ERROR (Status) && LoadedImage != NULL) {\r
524 //\r
525 // Get Module Guid from DevicePath.\r
526 //\r
527 if (LoadedImage->FilePath != NULL &&\r
528 LoadedImage->FilePath->Type == MEDIA_DEVICE_PATH &&\r
529 LoadedImage->FilePath->SubType == MEDIA_PIWG_FW_FILE_DP\r
530 ) {\r
531 //\r
532 // Determine GUID associated with module logging performance\r
533 //\r
534 ModuleGuidIsGet = TRUE;\r
535 FvFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LoadedImage->FilePath;\r
536 TempGuid = &FvFilePath->FvFileName;\r
537 }\r
538\r
539 //\r
540 // Method 1 Get Module Name from PDB string.\r
541 //\r
542 PdbFileName = PeCoffLoaderGetPdbPointer (LoadedImage->ImageBase);\r
543 if (PdbFileName != NULL && BufferSize > 0) {\r
544 StartIndex = 0;\r
545 for (Index = 0; PdbFileName[Index] != 0; Index++) {\r
546 if ((PdbFileName[Index] == '\\') || (PdbFileName[Index] == '/')) {\r
547 StartIndex = Index + 1;\r
548 }\r
549 }\r
550 //\r
551 // Copy the PDB file name to our temporary string.\r
552 // If the length is bigger than BufferSize, trim the redudant characters to avoid overflow in array boundary.\r
553 //\r
554 for (Index = 0; Index < BufferSize - 1; Index++) {\r
555 NameString[Index] = PdbFileName[Index + StartIndex];\r
556 if (NameString[Index] == 0 || NameString[Index] == '.') {\r
557 NameString[Index] = 0;\r
558 break;\r
559 }\r
560 }\r
561\r
562 if (Index == BufferSize - 1) {\r
563 NameString[Index] = 0;\r
564 }\r
565 //\r
566 // Module Name is got.\r
567 //\r
568 goto Done;\r
569 }\r
570 }\r
571\r
572 //\r
573 // Method 2: Get the name string from ComponentName2 protocol\r
574 //\r
575 Status = gBS->HandleProtocol (\r
576 Handle,\r
577 &gEfiComponentName2ProtocolGuid,\r
578 (VOID **) &ComponentName2\r
579 );\r
580 if (!EFI_ERROR (Status)) {\r
581 //\r
582 // Get the current platform language setting\r
583 //\r
584 if (mPlatformLanguage == NULL) {\r
585 GetEfiGlobalVariable2 (L"PlatformLang", (VOID **) &mPlatformLanguage, NULL);\r
586 }\r
587 if (mPlatformLanguage != NULL) {\r
588 Status = ComponentName2->GetDriverName (\r
589 ComponentName2,\r
590 mPlatformLanguage != NULL ? mPlatformLanguage : "en-US",\r
591 &StringPtr\r
592 );\r
593 if (!EFI_ERROR (Status)) {\r
594 for (Index = 0; Index < BufferSize - 1 && StringPtr[Index] != 0; Index++) {\r
595 NameString[Index] = (CHAR8) StringPtr[Index];\r
596 }\r
597 NameString[Index] = 0;\r
598 //\r
599 // Module Name is got.\r
600 //\r
601 goto Done;\r
602 }\r
603 }\r
604 }\r
605\r
606 if (ModuleGuidIsGet) {\r
607 //\r
608 // Method 3 Try to get the image's FFS UI section by image GUID\r
609 //\r
610 StringPtr = NULL;\r
611 StringSize = 0;\r
612 Status = GetSectionFromAnyFv (\r
613 TempGuid,\r
614 EFI_SECTION_USER_INTERFACE,\r
615 0,\r
616 (VOID **) &StringPtr,\r
617 &StringSize\r
618 );\r
619\r
620 if (!EFI_ERROR (Status)) {\r
621 //\r
622 // Method 3. Get the name string from FFS UI section\r
623 //\r
624 for (Index = 0; Index < BufferSize - 1 && StringPtr[Index] != 0; Index++) {\r
625 NameString[Index] = (CHAR8) StringPtr[Index];\r
626 }\r
627 NameString[Index] = 0;\r
628 FreePool (StringPtr);\r
629 }\r
630 }\r
631\r
632Done:\r
633 //\r
634 // Copy Module Guid\r
635 //\r
636 if (ModuleGuid != NULL) {\r
637 CopyGuid (ModuleGuid, TempGuid);\r
638 if (IsZeroGuid(TempGuid) && (Handle != NULL) && !ModuleGuidIsGet) {\r
639 // Handle is GUID\r
640 CopyGuid (ModuleGuid, (EFI_GUID *) Handle);\r
641 }\r
642 }\r
643\r
644 //\r
645 // Cache the Handle and Guid pairs.\r
646 //\r
647 if (mCachePairCount < CACHE_HANDLE_GUID_COUNT) {\r
648 mCacheHandleGuidTable[mCachePairCount].Handle = Handle;\r
649 CopyGuid (&mCacheHandleGuidTable[mCachePairCount].ModuleGuid, ModuleGuid);\r
650 AsciiStrCpyS (mCacheHandleGuidTable[mCachePairCount].NameString, FPDT_STRING_EVENT_RECORD_NAME_LENGTH, NameString);\r
651 mCachePairCount ++;\r
652 }\r
653\r
654 return Status;\r
655}\r
656\r
657/**\r
6b4d58a1 658 Get the FPDT record identifier.\r
9609d24b 659\r
6b4d58a1
BD
660 @param Attribute The attribute of the Record.\r
661 PerfStartEntry: Start Record.\r
662 PerfEndEntry: End Record.\r
663 @param Handle Pointer to environment specific context used to identify the component being measured.\r
664 @param String Pointer to a Null-terminated ASCII string that identifies the component being measured.\r
665 @param ProgressID On return, pointer to the ProgressID.\r
a0afd019 666\r
6b4d58a1
BD
667 @retval EFI_SUCCESS Get record info successfully.\r
668 @retval EFI_INVALID_PARAMETER No matched FPDT record.\r
a0afd019 669\r
670**/\r
9609d24b 671EFI_STATUS\r
6b4d58a1
BD
672GetFpdtRecordId (\r
673 IN PERF_MEASUREMENT_ATTRIBUTE Attribute,\r
674 IN CONST VOID *Handle,\r
675 IN CONST CHAR8 *String,\r
676 OUT UINT16 *ProgressID\r
a0afd019 677 )\r
678{\r
9609d24b 679 //\r
6b4d58a1 680 // Token to PerfId.\r
9609d24b 681 //\r
6b4d58a1
BD
682 if (String != NULL) {\r
683 if (AsciiStrCmp (String, START_IMAGE_TOK) == 0) { // "StartImage:"\r
684 if (Attribute == PerfStartEntry) {\r
685 *ProgressID = MODULE_START_ID;\r
9609d24b 686 } else {\r
6b4d58a1 687 *ProgressID = MODULE_END_ID;\r
9609d24b 688 }\r
6b4d58a1
BD
689 } else if (AsciiStrCmp (String, LOAD_IMAGE_TOK) == 0) { // "LoadImage:"\r
690 if (Attribute == PerfStartEntry) {\r
691 *ProgressID = MODULE_LOADIMAGE_START_ID;\r
9609d24b 692 } else {\r
6b4d58a1 693 *ProgressID = MODULE_LOADIMAGE_END_ID;\r
9609d24b 694 }\r
6b4d58a1
BD
695 } else if (AsciiStrCmp (String, DRIVERBINDING_START_TOK) == 0) { // "DB:Start:"\r
696 if (Attribute == PerfStartEntry) {\r
697 *ProgressID = MODULE_DB_START_ID;\r
9609d24b 698 } else {\r
6b4d58a1 699 *ProgressID = MODULE_DB_END_ID;\r
9609d24b 700 }\r
6b4d58a1 701 } else if (AsciiStrCmp (String, DRIVERBINDING_SUPPORT_TOK) == 0) { // "DB:Support:"\r
9609d24b
DB
702 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
703 return RETURN_UNSUPPORTED;\r
704 }\r
6b4d58a1
BD
705 if (Attribute == PerfStartEntry) {\r
706 *ProgressID = MODULE_DB_SUPPORT_START_ID;\r
9609d24b 707 } else {\r
6b4d58a1 708 *ProgressID = MODULE_DB_SUPPORT_END_ID;\r
9609d24b 709 }\r
6b4d58a1 710 } else if (AsciiStrCmp (String, DRIVERBINDING_STOP_TOK) == 0) { // "DB:Stop:"\r
9609d24b
DB
711 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
712 return RETURN_UNSUPPORTED;\r
713 }\r
6b4d58a1
BD
714 if (Attribute == PerfStartEntry) {\r
715 *ProgressID = MODULE_DB_STOP_START_ID;\r
9609d24b 716 } else {\r
6b4d58a1 717 *ProgressID = MODULE_DB_STOP_END_ID;\r
9609d24b 718 }\r
6b4d58a1
BD
719 } else if (AsciiStrCmp (String, PEI_TOK) == 0 || // "PEI"\r
720 AsciiStrCmp (String, DXE_TOK) == 0 || // "DXE"\r
721 AsciiStrCmp (String, BDS_TOK) == 0) { // "BDS"\r
722 if (Attribute == PerfStartEntry) {\r
723 *ProgressID = PERF_CROSSMODULE_START_ID;\r
9609d24b 724 } else {\r
6b4d58a1 725 *ProgressID = PERF_CROSSMODULE_END_ID;\r
9609d24b
DB
726 }\r
727 } else { // Pref used in Modules.\r
6b4d58a1
BD
728 if (Attribute == PerfStartEntry) {\r
729 *ProgressID = PERF_INMODULE_START_ID;\r
9609d24b 730 } else {\r
6b4d58a1 731 *ProgressID = PERF_INMODULE_END_ID;\r
9609d24b
DB
732 }\r
733 }\r
6b4d58a1
BD
734 } else if (Handle!= NULL) { // Pref used in Modules.\r
735 if (Attribute == PerfStartEntry) {\r
736 *ProgressID = PERF_INMODULE_START_ID;\r
9609d24b 737 } else {\r
6b4d58a1 738 *ProgressID = PERF_INMODULE_END_ID;\r
9609d24b
DB
739 }\r
740 } else {\r
6b4d58a1 741 return EFI_INVALID_PARAMETER;\r
a0afd019 742 }\r
6b4d58a1
BD
743 return EFI_SUCCESS;\r
744}\r
745\r
746/**\r
747 Copies the string from Source into Destination and updates Length with the\r
748 size of the string.\r
749\r
750 @param Destination - destination of the string copy\r
751 @param Source - pointer to the source string which will get copied\r
752 @param Length - pointer to a length variable to be updated\r
753\r
754**/\r
755VOID\r
756CopyStringIntoPerfRecordAndUpdateLength (\r
757 IN OUT CHAR8 *Destination,\r
758 IN CONST CHAR8 *Source,\r
759 IN OUT UINT8 *Length\r
760 )\r
761{\r
762 UINTN StringLen;\r
763 UINTN DestMax;\r
764\r
765 ASSERT (Source != NULL);\r
a0afd019 766\r
9609d24b 767 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
6b4d58a1 768 DestMax = STRING_SIZE;\r
9609d24b 769 } else {\r
6b4d58a1
BD
770 DestMax = AsciiStrSize (Source);\r
771 if (DestMax > STRING_SIZE) {\r
772 DestMax = STRING_SIZE;\r
773 }\r
774 }\r
775 StringLen = AsciiStrLen (Source);\r
776 if (StringLen >= DestMax) {\r
777 StringLen = DestMax -1;\r
778 }\r
779\r
780 AsciiStrnCpyS(Destination, DestMax, Source, StringLen);\r
781 *Length += (UINT8)DestMax;\r
782\r
783 return;\r
784}\r
785\r
786/**\r
787 Get a string description for device for the given controller handle and update record\r
788 length. If ComponentName2 GetControllerName is supported, the value is included in the string,\r
789 followed by device path, otherwise just device path.\r
a0afd019 790\r
6b4d58a1
BD
791 @param Handle - Image handle\r
792 @param ControllerHandle - Controller handle.\r
793 @param ComponentNameString - Pointer to a location where the string will be saved\r
794 @param Length - Pointer to record length to be updated\r
b504f519 795\r
6b4d58a1
BD
796 @retval EFI_SUCCESS - Successfully got string description for device\r
797 @retval EFI_UNSUPPORTED - Neither ComponentName2 ControllerName nor DevicePath were found\r
9609d24b 798\r
6b4d58a1
BD
799**/\r
800EFI_STATUS\r
801GetDeviceInfoFromHandleAndUpdateLength (\r
802 IN CONST VOID *Handle,\r
803 IN EFI_HANDLE ControllerHandle,\r
804 OUT CHAR8 *ComponentNameString,\r
805 IN OUT UINT8 *Length\r
806 )\r
807{\r
808 EFI_DEVICE_PATH_PROTOCOL *DevicePathProtocol;\r
809 EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2;\r
810 EFI_STATUS Status;\r
811 CHAR16 *StringPtr;\r
812 CHAR8 *AsciiStringPtr;\r
813 UINTN ControllerNameStringSize;\r
814 UINTN DevicePathStringSize;\r
815\r
816 ControllerNameStringSize = 0;\r
817\r
818 Status = gBS->HandleProtocol (\r
819 (EFI_HANDLE) Handle,\r
820 &gEfiComponentName2ProtocolGuid,\r
821 (VOID **) &ComponentName2\r
822 );\r
823\r
824 if (!EFI_ERROR(Status)) {\r
825 //\r
826 // Get the current platform language setting\r
827 //\r
828 if (mPlatformLanguage == NULL) {\r
829 GetEfiGlobalVariable2 (L"PlatformLang", (VOID **)&mPlatformLanguage, NULL);\r
830 }\r
831\r
832 Status = ComponentName2->GetControllerName (\r
833 ComponentName2,\r
834 ControllerHandle,\r
835 NULL,\r
836 mPlatformLanguage != NULL ? mPlatformLanguage : "en-US",\r
837 &StringPtr\r
838 );\r
839 }\r
840\r
841 if (!EFI_ERROR (Status)) {\r
842 //\r
843 // This will produce the size of the unicode string, which is twice as large as the ASCII one\r
844 // This must be an even number, so ok to divide by 2\r
845 //\r
846 ControllerNameStringSize = StrSize(StringPtr) / 2;\r
847\r
848 //\r
849 // The + 1 is because we want to add a space between the ControllerName and the device path\r
850 //\r
851 if ((ControllerNameStringSize + (*Length) + 1) > FPDT_MAX_PERF_RECORD_SIZE) {\r
9609d24b 852 //\r
6b4d58a1 853 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record\r
9609d24b 854 //\r
6b4d58a1 855 ControllerNameStringSize = FPDT_MAX_PERF_RECORD_SIZE - (*Length) - 1;\r
a0afd019 856 }\r
6b4d58a1 857\r
9132a31b 858 UnicodeStrnToAsciiStrS(StringPtr, ControllerNameStringSize - 1, ComponentNameString, ControllerNameStringSize, &ControllerNameStringSize);\r
6b4d58a1
BD
859\r
860 //\r
861 // Add a space in the end of the ControllerName\r
862 //\r
863 AsciiStringPtr = ComponentNameString + ControllerNameStringSize - 1;\r
864 *AsciiStringPtr = 0x20;\r
865 AsciiStringPtr++;\r
866 *AsciiStringPtr = 0;\r
867 ControllerNameStringSize++;\r
868\r
869 *Length += (UINT8)ControllerNameStringSize;\r
a0afd019 870 }\r
871\r
6b4d58a1
BD
872 //\r
873 // This function returns the device path protocol from the handle specified by Handle. If Handle is\r
874 // NULL or Handle does not contain a device path protocol, then NULL is returned.\r
875 //\r
876 DevicePathProtocol = DevicePathFromHandle(ControllerHandle);\r
877\r
878 if (DevicePathProtocol != NULL) {\r
879 StringPtr = ConvertDevicePathToText (DevicePathProtocol, TRUE, FALSE);\r
880 if (StringPtr != NULL) {\r
881 //\r
882 // This will produce the size of the unicode string, which is twice as large as the ASCII one\r
883 // This must be an even number, so ok to divide by 2\r
884 //\r
885 DevicePathStringSize = StrSize(StringPtr) / 2;\r
886\r
887 if ((DevicePathStringSize + (*Length)) > FPDT_MAX_PERF_RECORD_SIZE) {\r
888 //\r
889 // Only copy enough to fill FPDT_MAX_PERF_RECORD_SIZE worth of the record\r
890 //\r
891 DevicePathStringSize = FPDT_MAX_PERF_RECORD_SIZE - (*Length);\r
892 }\r
893\r
894 if (ControllerNameStringSize != 0) {\r
895 AsciiStringPtr = ComponentNameString + ControllerNameStringSize - 1;\r
896 } else {\r
897 AsciiStringPtr = ComponentNameString;\r
898 }\r
899\r
9132a31b 900 UnicodeStrnToAsciiStrS(StringPtr, DevicePathStringSize - 1, AsciiStringPtr, DevicePathStringSize, &DevicePathStringSize);\r
6b4d58a1
BD
901 *Length += (UINT8)DevicePathStringSize;\r
902 return EFI_SUCCESS;\r
903 }\r
904 }\r
905\r
906 return EFI_UNSUPPORTED;\r
a0afd019 907}\r
908\r
909/**\r
6b4d58a1 910 Create performance record with event description and a timestamp.\r
a0afd019 911\r
6b4d58a1
BD
912 @param CallerIdentifier - Image handle or pointer to caller ID GUID.\r
913 @param Guid - Pointer to a GUID.\r
914 @param String - Pointer to a string describing the measurement.\r
915 @param Ticker - 64-bit time stamp.\r
916 @param Address - Pointer to a location in memory relevant to the measurement.\r
917 @param PerfId - Performance identifier describing the type of measurement.\r
918 @param Attribute - The attribute of the measurement. According to attribute can create a start\r
919 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,\r
920 or a general record for other Perf macros.\r
a0afd019 921\r
6b4d58a1
BD
922 @retval EFI_SUCCESS - Successfully created performance record.\r
923 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.\r
924 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
925 pointer or invalid PerfId.\r
926\r
927 @retval EFI_SUCCESS - Successfully created performance record\r
928 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records\r
929 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
930 pointer or invalid PerfId\r
a0afd019 931\r
932**/\r
a0afd019 933EFI_STATUS\r
6b4d58a1 934InsertFpdtRecord (\r
e3917e22
MK
935 IN CONST VOID *CallerIdentifier OPTIONAL,\r
936 IN CONST VOID *Guid OPTIONAL,\r
937 IN CONST CHAR8 *String OPTIONAL,\r
6b4d58a1 938 IN UINT64 Ticker,\r
e3917e22 939 IN UINT64 Address OPTIONAL,\r
6b4d58a1
BD
940 IN UINT16 PerfId,\r
941 IN PERF_MEASUREMENT_ATTRIBUTE Attribute\r
a0afd019 942 )\r
943{\r
9609d24b
DB
944 EFI_GUID ModuleGuid;\r
945 CHAR8 ModuleName[FPDT_STRING_EVENT_RECORD_NAME_LENGTH];\r
9609d24b 946 FPDT_RECORD_PTR FpdtRecordPtr;\r
6b4d58a1 947 FPDT_RECORD_PTR CachedFpdtRecordPtr;\r
9609d24b 948 UINT64 TimeStamp;\r
9609d24b 949 CONST CHAR8 *StringPtr;\r
6b4d58a1
BD
950 UINTN DestMax;\r
951 UINTN StringLen;\r
952 EFI_STATUS Status;\r
953 UINT16 ProgressId;\r
9609d24b
DB
954\r
955 StringPtr = NULL;\r
6b4d58a1 956 ProgressId = 0;\r
9609d24b
DB
957 ZeroMem (ModuleName, sizeof (ModuleName));\r
958\r
9609d24b 959 //\r
6b4d58a1
BD
960 // 1. Get the Perf Id for records from PERF_START/PERF_END, PERF_START_EX/PERF_END_EX.\r
961 // notes: For other Perf macros (Attribute == PerfEntry), their Id is known.\r
9609d24b 962 //\r
6b4d58a1 963 if (Attribute != PerfEntry) {\r
9609d24b 964 //\r
6b4d58a1
BD
965 // If PERF_START_EX()/PERF_END_EX() have specified the ProgressID,it has high priority.\r
966 // !!! Note: If the Perf is not the known Token used in the core but have same\r
967 // ID with the core Token, this case will not be supported.\r
968 // And in currtnt usage mode, for the unkown ID, there is a general rule:\r
969 // If it is start pref: the lower 4 bits of the ID should be 0.\r
970 // If it is end pref: the lower 4 bits of the ID should not be 0.\r
971 // If input ID doesn't follow the rule, we will adjust it.\r
a0afd019 972 //\r
6b4d58a1
BD
973 if ((PerfId != 0) && (IsKnownID (PerfId)) && (!IsKnownTokens (String))) {\r
974 return EFI_INVALID_PARAMETER;\r
975 } else if ((PerfId != 0) && (!IsKnownID (PerfId)) && (!IsKnownTokens (String))) {\r
976 if ((Attribute == PerfStartEntry) && ((PerfId & 0x000F) != 0)) {\r
977 PerfId &= 0xFFF0;\r
978 } else if ((Attribute == PerfEndEntry) && ((PerfId & 0x000F) == 0)) {\r
979 PerfId += 1;\r
9609d24b 980 }\r
6b4d58a1 981 } else if (PerfId == 0) {\r
9609d24b 982 //\r
6b4d58a1 983 // Get ProgressID form the String Token.\r
9609d24b 984 //\r
6b4d58a1
BD
985 Status = GetFpdtRecordId (Attribute, CallerIdentifier, String, &ProgressId);\r
986 if (EFI_ERROR (Status)) {\r
987 return Status;\r
9609d24b 988 }\r
6b4d58a1 989 PerfId = ProgressId;\r
9609d24b 990 }\r
9609d24b 991 }\r
a0afd019 992\r
9609d24b 993 //\r
6b4d58a1
BD
994 // 2. Get the buffer to store the FPDT record.\r
995 //\r
996 Status = GetFpdtRecordPtr (FPDT_MAX_PERF_RECORD_SIZE, &FpdtRecordPtr);\r
997 if (EFI_ERROR (Status)) {\r
998 return Status;\r
999 }\r
1000\r
1001 //\r
1002 //3. Get the TimeStamp.\r
9609d24b
DB
1003 //\r
1004 if (Ticker == 0) {\r
1005 Ticker = GetPerformanceCounter ();\r
1006 TimeStamp = GetTimeInNanoSecond (Ticker);\r
1007 } else if (Ticker == 1) {\r
1008 TimeStamp = 0;\r
1009 } else {\r
1010 TimeStamp = GetTimeInNanoSecond (Ticker);\r
1011 }\r
a0afd019 1012\r
9609d24b 1013 //\r
6b4d58a1 1014 // 4. Fill in the FPDT record according to different Performance Identifier.\r
9609d24b 1015 //\r
6b4d58a1
BD
1016 switch (PerfId) {\r
1017 case MODULE_START_ID:\r
1018 case MODULE_END_ID:\r
3522ea73 1019 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
6b4d58a1
BD
1020 StringPtr = ModuleName;\r
1021 //\r
1022 // Cache the offset of start image start record and use to update the start image end record if needed.\r
1023 //\r
1024 if (Attribute == PerfEntry && PerfId == MODULE_START_ID) {\r
1025 if (mFpdtBufferIsReported) {\r
1026 mCachedLength = mBootRecordSize;\r
1027 } else {\r
1028 mCachedLength = mPerformanceLength;\r
1029 }\r
1030 }\r
1031 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
1032 FpdtRecordPtr.GuidEvent->Header.Type = FPDT_GUID_EVENT_TYPE;\r
1033 FpdtRecordPtr.GuidEvent->Header.Length = sizeof (FPDT_GUID_EVENT_RECORD);\r
1034 FpdtRecordPtr.GuidEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
1035 FpdtRecordPtr.GuidEvent->ProgressID = PerfId;\r
1036 FpdtRecordPtr.GuidEvent->Timestamp = TimeStamp;\r
1037 CopyMem (&FpdtRecordPtr.GuidEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidEvent->Guid));\r
1038 if (CallerIdentifier == NULL && PerfId == MODULE_END_ID && mCachedLength != 0) {\r
1039 if (mFpdtBufferIsReported) {\r
1040 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mCachedLength);\r
1041 } else {\r
1042 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mCachedLength);\r
1043 }\r
1044 CopyMem (&FpdtRecordPtr.GuidEvent->Guid, &CachedFpdtRecordPtr.GuidEvent->Guid, sizeof (FpdtRecordPtr.GuidEvent->Guid));\r
1045 mCachedLength = 0;\r
1046 }\r
1047 }\r
9609d24b
DB
1048 break;\r
1049\r
6b4d58a1
BD
1050 case MODULE_LOADIMAGE_START_ID:\r
1051 case MODULE_LOADIMAGE_END_ID:\r
3522ea73 1052 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
6b4d58a1
BD
1053 StringPtr = ModuleName;\r
1054 if (PerfId == MODULE_LOADIMAGE_START_ID) {\r
1055 mLoadImageCount ++;\r
1056 //\r
1057 // Cache the offset of load image start record and use to be updated by the load image end record if needed.\r
1058 //\r
1059 if (CallerIdentifier == NULL && Attribute == PerfEntry) {\r
1060 if (mFpdtBufferIsReported) {\r
1061 mCachedLength = mBootRecordSize;\r
1062 } else {\r
1063 mCachedLength = mPerformanceLength;\r
1064 }\r
1065 }\r
9609d24b 1066 }\r
6b4d58a1
BD
1067 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
1068 FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE;\r
1069 FpdtRecordPtr.GuidQwordEvent->Header.Length = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);\r
1070 FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
1071 FpdtRecordPtr.GuidQwordEvent->ProgressID = PerfId;\r
1072 FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp;\r
1073 FpdtRecordPtr.GuidQwordEvent->Qword = mLoadImageCount;\r
1074 CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordEvent->Guid));\r
1075 if (PerfId == MODULE_LOADIMAGE_END_ID && mCachedLength != 0) {\r
1076 if (mFpdtBufferIsReported) {\r
1077 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mCachedLength);\r
1078 } else {\r
1079 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mCachedLength);\r
1080 }\r
1081 CopyMem (&CachedFpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (CachedFpdtRecordPtr.GuidQwordEvent->Guid));\r
1082 mCachedLength = 0;\r
9609d24b 1083 }\r
a0afd019 1084 }\r
9609d24b
DB
1085 break;\r
1086\r
6b4d58a1
BD
1087 case MODULE_DB_START_ID:\r
1088 case MODULE_DB_SUPPORT_START_ID:\r
1089 case MODULE_DB_SUPPORT_END_ID:\r
1090 case MODULE_DB_STOP_START_ID:\r
1091 case MODULE_DB_STOP_END_ID:\r
3522ea73 1092 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
6b4d58a1
BD
1093 StringPtr = ModuleName;\r
1094 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
1095 FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE;\r
1096 FpdtRecordPtr.GuidQwordEvent->Header.Length = sizeof (FPDT_GUID_QWORD_EVENT_RECORD);\r
1097 FpdtRecordPtr.GuidQwordEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
1098 FpdtRecordPtr.GuidQwordEvent->ProgressID = PerfId;\r
1099 FpdtRecordPtr.GuidQwordEvent->Timestamp = TimeStamp;\r
1100 FpdtRecordPtr.GuidQwordEvent->Qword = Address;\r
1101 CopyMem (&FpdtRecordPtr.GuidQwordEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordEvent->Guid));\r
9609d24b
DB
1102 }\r
1103 break;\r
1104\r
6b4d58a1 1105 case MODULE_DB_END_ID:\r
3522ea73 1106 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
6b4d58a1
BD
1107 StringPtr = ModuleName;\r
1108 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
1109 FpdtRecordPtr.GuidQwordStringEvent->Header.Type = FPDT_GUID_QWORD_STRING_EVENT_TYPE;\r
1110 FpdtRecordPtr.GuidQwordStringEvent->Header.Length = sizeof (FPDT_GUID_QWORD_STRING_EVENT_RECORD);;\r
1111 FpdtRecordPtr.GuidQwordStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
1112 FpdtRecordPtr.GuidQwordStringEvent->ProgressID = PerfId;\r
1113 FpdtRecordPtr.GuidQwordStringEvent->Timestamp = TimeStamp;\r
1114 FpdtRecordPtr.GuidQwordStringEvent->Qword = Address;\r
1115 CopyMem (&FpdtRecordPtr.GuidQwordStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.GuidQwordStringEvent->Guid));\r
1116 if (Address != 0) {\r
1117 GetDeviceInfoFromHandleAndUpdateLength(CallerIdentifier, (EFI_HANDLE)(UINTN)Address, FpdtRecordPtr.GuidQwordStringEvent->String, &FpdtRecordPtr.GuidQwordStringEvent->Header.Length);\r
1118 }\r
1119 }\r
9609d24b
DB
1120 break;\r
1121\r
6b4d58a1
BD
1122 case PERF_EVENTSIGNAL_START_ID:\r
1123 case PERF_EVENTSIGNAL_END_ID:\r
1124 case PERF_CALLBACK_START_ID:\r
1125 case PERF_CALLBACK_END_ID:\r
981b7edc 1126 if (String == NULL || Guid == NULL) {\r
6b4d58a1
BD
1127 return EFI_INVALID_PARAMETER;\r
1128 }\r
6b4d58a1 1129 StringPtr = String;\r
981b7edc
DB
1130 if (AsciiStrLen (String) == 0) {\r
1131 StringPtr = "unknown name";\r
1132 }\r
6b4d58a1
BD
1133 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
1134 FpdtRecordPtr.DualGuidStringEvent->Header.Type = FPDT_DUAL_GUID_STRING_EVENT_TYPE;\r
1135 FpdtRecordPtr.DualGuidStringEvent->Header.Length = sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD);\r
1136 FpdtRecordPtr.DualGuidStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
1137 FpdtRecordPtr.DualGuidStringEvent->ProgressID = PerfId;\r
1138 FpdtRecordPtr.DualGuidStringEvent->Timestamp = TimeStamp;\r
1139 CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid1, CallerIdentifier, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid1));\r
1140 CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid2, Guid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid2));\r
1141 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DualGuidStringEvent->String, StringPtr, &FpdtRecordPtr.DualGuidStringEvent->Header.Length);\r
1142 }\r
1143 break;\r
1144\r
1145 case PERF_EVENT_ID:\r
1146 case PERF_FUNCTION_START_ID:\r
1147 case PERF_FUNCTION_END_ID:\r
1148 case PERF_INMODULE_START_ID:\r
1149 case PERF_INMODULE_END_ID:\r
1150 case PERF_CROSSMODULE_START_ID:\r
1151 case PERF_CROSSMODULE_END_ID:\r
3522ea73 1152 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
6b4d58a1
BD
1153 if (String != NULL) {\r
1154 StringPtr = String;\r
1155 } else {\r
1156 StringPtr = ModuleName;\r
1157 }\r
1158 if (AsciiStrLen (StringPtr) == 0) {\r
1159 StringPtr = "unknown name";\r
1160 }\r
1161 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
1162 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
1163 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
1164 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
1165 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;\r
1166 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;\r
1167 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));\r
1168 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
1169 }\r
1170 break;\r
1171\r
1172 default:\r
1173 if (Attribute != PerfEntry) {\r
3522ea73 1174 GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid);\r
6b4d58a1
BD
1175 if (String != NULL) {\r
1176 StringPtr = String;\r
1177 } else {\r
1178 StringPtr = ModuleName;\r
1179 }\r
1180 if (AsciiStrLen (StringPtr) == 0) {\r
1181 StringPtr = "unknown name";\r
1182 }\r
1183 if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
1184 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
1185 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
1186 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
1187 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;\r
1188 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;\r
1189 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));\r
1190 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
1191 }\r
1192 } else {\r
1193 return EFI_INVALID_PARAMETER;\r
1194 }\r
1195 break;\r
1196 }\r
1197\r
1198 //\r
1199 // 4.2 When PcdEdkiiFpdtStringRecordEnableOnly==TRUE, create string record for all Perf entries.\r
1200 //\r
1201 if (PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {\r
1202 if (StringPtr == NULL ||PerfId == MODULE_DB_SUPPORT_START_ID || PerfId == MODULE_DB_SUPPORT_END_ID) {\r
1203 return EFI_INVALID_PARAMETER;\r
1204 }\r
1205 FpdtRecordPtr.DynamicStringEvent->Header.Type = FPDT_DYNAMIC_STRING_EVENT_TYPE;\r
1206 FpdtRecordPtr.DynamicStringEvent->Header.Length = sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
1207 FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;\r
1208 FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;\r
1209 FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;\r
981b7edc
DB
1210 if (Guid != NULL) {\r
1211 //\r
1212 // Cache the event guid in string event record.\r
1213 //\r
1214 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, Guid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));\r
1215 } else {\r
1216 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));\r
1217 }\r
6b4d58a1
BD
1218 if (AsciiStrLen (StringPtr) == 0) {\r
1219 StringPtr = "unknown name";\r
1220 }\r
1221 CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DynamicStringEvent->String, StringPtr, &FpdtRecordPtr.DynamicStringEvent->Header.Length);\r
1222\r
1223 if ((PerfId == MODULE_LOADIMAGE_START_ID) || (PerfId == MODULE_END_ID)) {\r
1224 FpdtRecordPtr.DynamicStringEvent->Header.Length = (UINT8)(sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD)+ STRING_SIZE);\r
1225 }\r
1226 if ((PerfId == MODULE_LOADIMAGE_END_ID || PerfId == MODULE_END_ID) && mCachedLength != 0) {\r
1227 if (mFpdtBufferIsReported) {\r
1228 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mBootRecordBuffer + mCachedLength);\r
1229 } else {\r
1230 CachedFpdtRecordPtr.RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(mPerformancePointer + mCachedLength);\r
1231 }\r
1232 if (PerfId == MODULE_LOADIMAGE_END_ID) {\r
1233 DestMax = CachedFpdtRecordPtr.DynamicStringEvent->Header.Length - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
1234 StringLen = AsciiStrLen (StringPtr);\r
1235 if (StringLen >= DestMax) {\r
1236 StringLen = DestMax -1;\r
1237 }\r
1238 CopyMem (&CachedFpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (CachedFpdtRecordPtr.DynamicStringEvent->Guid));\r
1239 AsciiStrnCpyS (CachedFpdtRecordPtr.DynamicStringEvent->String, DestMax, StringPtr, StringLen);\r
1240 } else if (PerfId == MODULE_END_ID) {\r
1241 DestMax = FpdtRecordPtr.DynamicStringEvent->Header.Length - sizeof (FPDT_DYNAMIC_STRING_EVENT_RECORD);\r
1242 StringLen = AsciiStrLen (CachedFpdtRecordPtr.DynamicStringEvent->String);\r
1243 if (StringLen >= DestMax) {\r
1244 StringLen = DestMax -1;\r
1245 }\r
1246 CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &CachedFpdtRecordPtr.DynamicStringEvent->Guid, sizeof (CachedFpdtRecordPtr.DynamicStringEvent->Guid));\r
1247 AsciiStrnCpyS (FpdtRecordPtr.DynamicStringEvent->String, DestMax, CachedFpdtRecordPtr.DynamicStringEvent->String, StringLen);\r
1248 }\r
1249 mCachedLength = 0;\r
1250 }\r
9609d24b
DB
1251 }\r
1252\r
6b4d58a1
BD
1253 //\r
1254 // 5. Update the length of the used buffer after fill in the record.\r
1255 //\r
1256 if (mFpdtBufferIsReported) {\r
1257 mBootRecordSize += FpdtRecordPtr.RecordHeader->Length;\r
1258 mAcpiBootPerformanceTable->Header.Length += FpdtRecordPtr.RecordHeader->Length;\r
1259 } else {\r
1260 mPerformanceLength += FpdtRecordPtr.RecordHeader->Length;\r
1261 }\r
9609d24b
DB
1262 return EFI_SUCCESS;\r
1263}\r
1264\r
1265/**\r
1266 Dumps all the PEI performance.\r
1267\r
1268 @param HobStart A pointer to a Guid.\r
1269\r
1270 This internal function dumps all the PEI performance log to the DXE performance gauge array.\r
1271 It retrieves the optional GUID HOB for PEI performance and then saves the performance data\r
1272 to DXE performance data structures.\r
f0da4d7d 1273\r
9609d24b
DB
1274**/\r
1275VOID\r
1276InternalGetPeiPerformance (\r
1277 VOID *HobStart\r
1278 )\r
1279{\r
1280 UINT8 *FirmwarePerformanceHob;\r
1281 FPDT_PEI_EXT_PERF_HEADER *PeiPerformanceLogHeader;\r
1282 UINT8 *EventRec;\r
1283 EFI_HOB_GUID_TYPE *GuidHob;\r
1284\r
1285 GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, HobStart);\r
1286 while (GuidHob != NULL) {\r
1287 FirmwarePerformanceHob = GET_GUID_HOB_DATA (GuidHob);\r
1288 PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)FirmwarePerformanceHob;\r
1289\r
1290 if (mPerformanceLength + PeiPerformanceLogHeader->SizeOfAllEntries > mMaxPerformanceLength) {\r
1291 mPerformancePointer = ReallocatePool (\r
1292 mPerformanceLength,\r
1293 mPerformanceLength +\r
1294 (UINTN)PeiPerformanceLogHeader->SizeOfAllEntries +\r
1295 FIRMWARE_RECORD_BUFFER,\r
1296 mPerformancePointer\r
1297 );\r
1298 ASSERT (mPerformancePointer != NULL);\r
1299 mMaxPerformanceLength = mPerformanceLength +\r
1300 (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries) +\r
1301 FIRMWARE_RECORD_BUFFER;\r
1302 }\r
f0da4d7d 1303\r
9609d24b
DB
1304 EventRec = mPerformancePointer + mPerformanceLength;\r
1305 CopyMem (EventRec, FirmwarePerformanceHob + sizeof (FPDT_PEI_EXT_PERF_HEADER), (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries));\r
a0afd019 1306 //\r
9609d24b 1307 // Update the used buffer size.\r
a0afd019 1308 //\r
9609d24b
DB
1309 mPerformanceLength += (UINTN)(PeiPerformanceLogHeader->SizeOfAllEntries);\r
1310 mLoadImageCount += PeiPerformanceLogHeader->LoadImageCount;\r
a0afd019 1311\r
9609d24b
DB
1312 //\r
1313 // Get next performance guid hob\r
1314 //\r
1315 GuidHob = GetNextGuidHob (&gEdkiiFpdtExtendedFirmwarePerformanceGuid, GET_NEXT_HOB (GuidHob));\r
a0afd019 1316 }\r
9609d24b 1317}\r
a0afd019 1318\r
9609d24b
DB
1319/**\r
1320 Report Boot Perforamnce table address as report status code.\r
a0afd019 1321\r
9609d24b
DB
1322 @param Event The event of notify protocol.\r
1323 @param Context Notify event context.\r
1324\r
1325**/\r
1326VOID\r
1327EFIAPI\r
1328ReportFpdtRecordBuffer (\r
1329 IN EFI_EVENT Event,\r
1330 IN VOID *Context\r
1331 )\r
1332{\r
1333 EFI_STATUS Status;\r
1334 UINT64 BPDTAddr;\r
1335\r
1336 if (!mFpdtBufferIsReported) {\r
1337 Status = AllocateBootPerformanceTable ();\r
1338 if (!EFI_ERROR(Status)) {\r
1339 BPDTAddr = (UINT64)(UINTN)mAcpiBootPerformanceTable;\r
1340 REPORT_STATUS_CODE_EX (\r
1341 EFI_PROGRESS_CODE,\r
1342 EFI_SOFTWARE_DXE_BS_DRIVER,\r
1343 0,\r
1344 NULL,\r
1345 &gEdkiiFpdtExtendedFirmwarePerformanceGuid,\r
1346 &BPDTAddr,\r
1347 sizeof (UINT64)\r
1348 );\r
1349 }\r
1350 //\r
1351 // Set FPDT report state to TRUE.\r
1352 //\r
1353 mFpdtBufferIsReported = TRUE;\r
a0afd019 1354 }\r
9609d24b 1355}\r
a0afd019 1356\r
466ebdd2
DB
1357/**\r
1358 Update Boot Performance table.\r
1359\r
1360 @param Event The event of notify protocol.\r
1361 @param Context Notify event context.\r
1362\r
1363**/\r
1364VOID\r
1365EFIAPI\r
1366UpdateBootPerformanceTable (\r
1367 IN EFI_EVENT Event,\r
1368 IN VOID *Context\r
1369 )\r
1370{\r
1371 VOID *SmmBootRecordData;\r
1372 UINTN SmmBootRecordDataSize;\r
1373 UINTN AppendSize;\r
1374 UINT8 *FirmwarePerformanceTablePtr;\r
1375\r
dfafa8e4 1376 SmmBootRecordDataSize = 0;\r
1377\r
466ebdd2
DB
1378 //\r
1379 // Get SMM performance data.\r
1380 //\r
1381 SmmBootRecordData = NULL;\r
1382 InternalGetSmmPerfData (&SmmBootRecordData, &SmmBootRecordDataSize, FALSE);\r
1383\r
1384 FirmwarePerformanceTablePtr = (UINT8 *) mAcpiBootPerformanceTable + mAcpiBootPerformanceTable->Header.Length;\r
1385\r
1386 if (mAcpiBootPerformanceTable->Header.Length + SmmBootRecordDataSize > mBootRecordMaxSize) {\r
1387 DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: No enough space to save all SMM boot performance data\n"));\r
1388 AppendSize = mBootRecordMaxSize - mAcpiBootPerformanceTable->Header.Length;\r
1389 } else {\r
1390 AppendSize = SmmBootRecordDataSize;\r
1391 }\r
1392 if (SmmBootRecordData != NULL) {\r
1393 CopyMem (FirmwarePerformanceTablePtr, SmmBootRecordData, AppendSize);\r
1394 mAcpiBootPerformanceTable->Header.Length += (UINT32) AppendSize;\r
1395 mBootRecordSize += (UINT32) AppendSize;\r
1396 FreePool (SmmBootRecordData);\r
1397 }\r
1398}\r
1399\r
a0afd019 1400/**\r
1401 The constructor function initializes Performance infrastructure for DXE phase.\r
1402\r
f0da4d7d 1403 The constructor function publishes Performance and PerformanceEx protocol, allocates memory to log DXE performance\r
a0afd019 1404 and merges PEI performance data to DXE performance log.\r
1405 It will ASSERT() if one of these operations fails and it will always return EFI_SUCCESS.\r
1406\r
1407 @param ImageHandle The firmware allocated handle for the EFI image.\r
1408 @param SystemTable A pointer to the EFI System Table.\r
1409\r
1410 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
1411\r
1412**/\r
1413EFI_STATUS\r
1414EFIAPI\r
1415DxeCorePerformanceLibConstructor (\r
1416 IN EFI_HANDLE ImageHandle,\r
1417 IN EFI_SYSTEM_TABLE *SystemTable\r
1418 )\r
1419{\r
1420 EFI_STATUS Status;\r
9609d24b 1421 EFI_HANDLE Handle;\r
466ebdd2 1422 EFI_EVENT EndOfDxeEvent;\r
9609d24b 1423 EFI_EVENT ReadyToBootEvent;\r
cfb0aba7
SZ
1424 PERFORMANCE_PROPERTY *PerformanceProperty;\r
1425\r
a0afd019 1426 if (!PerformanceMeasurementEnabled ()) {\r
1427 //\r
1428 // Do not initialize performance infrastructure if not required.\r
1429 //\r
1430 return EFI_SUCCESS;\r
1431 }\r
9609d24b
DB
1432\r
1433 //\r
1434 // Dump normal PEI performance records\r
1435 //\r
1436 InternalGetPeiPerformance (GetHobList());\r
1437\r
a0afd019 1438 //\r
9609d24b 1439 // Install the protocol interfaces for DXE performance library instance.\r
a0afd019 1440 //\r
9609d24b 1441 Handle = NULL;\r
f0da4d7d 1442 Status = gBS->InstallMultipleProtocolInterfaces (\r
9609d24b 1443 &Handle,\r
137fb13d
BD
1444 &gEdkiiPerformanceMeasurementProtocolGuid,\r
1445 &mPerformanceMeasurementInterface,\r
f0da4d7d 1446 NULL\r
a0afd019 1447 );\r
1448 ASSERT_EFI_ERROR (Status);\r
1449\r
9609d24b 1450 //\r
466ebdd2 1451 // Register EndOfDxe event to allocate the boot performance table and report the table address through status code.\r
9609d24b
DB
1452 //\r
1453 Status = gBS->CreateEventEx (\r
1454 EVT_NOTIFY_SIGNAL,\r
466ebdd2 1455 TPL_NOTIFY,\r
9609d24b
DB
1456 ReportFpdtRecordBuffer,\r
1457 NULL,\r
466ebdd2
DB
1458 &gEfiEndOfDxeEventGroupGuid,\r
1459 &EndOfDxeEvent\r
1460 );\r
1461\r
1462 //\r
1463 // Register ReadyToBoot event to update the boot performance table for SMM performance data.\r
1464 //\r
1465 Status = gBS->CreateEventEx (\r
1466 EVT_NOTIFY_SIGNAL,\r
1467 TPL_CALLBACK,\r
1468 UpdateBootPerformanceTable,\r
1469 NULL,\r
9609d24b
DB
1470 &gEfiEventReadyToBootGuid,\r
1471 &ReadyToBootEvent\r
1472 );\r
a0afd019 1473\r
9609d24b 1474 ASSERT_EFI_ERROR (Status);\r
a0afd019 1475\r
9802d6d5 1476 Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **) &PerformanceProperty);\r
cfb0aba7
SZ
1477 if (EFI_ERROR (Status)) {\r
1478 //\r
1479 // Install configuration table for performance property.\r
1480 //\r
1481 mPerformanceProperty.Revision = PERFORMANCE_PROPERTY_REVISION;\r
1482 mPerformanceProperty.Reserved = 0;\r
1483 mPerformanceProperty.Frequency = GetPerformanceCounterProperties (\r
1484 &mPerformanceProperty.TimerStartValue,\r
1485 &mPerformanceProperty.TimerEndValue\r
1486 );\r
1487 Status = gBS->InstallConfigurationTable (&gPerformanceProtocolGuid, &mPerformanceProperty);\r
1488 ASSERT_EFI_ERROR (Status);\r
1489 }\r
1490\r
1491 return EFI_SUCCESS;\r
a0afd019 1492}\r
1493\r
137fb13d
BD
1494/**\r
1495 Create performance record with event description and a timestamp.\r
1496\r
1497 @param CallerIdentifier - Image handle or pointer to caller ID GUID.\r
1498 @param Guid - Pointer to a GUID.\r
1499 @param String - Pointer to a string describing the measurement.\r
1500 @param TimeStamp - 64-bit time stamp.\r
1501 @param Address - Pointer to a location in memory relevant to the measurement.\r
1502 @param Identifier - Performance identifier describing the type of measurement.\r
1503 @param Attribute - The attribute of the measurement. According to attribute can create a start\r
1504 record for PERF_START/PERF_START_EX, or a end record for PERF_END/PERF_END_EX,\r
1505 or a general record for other Perf macros.\r
1506\r
1507 @retval EFI_SUCCESS - Successfully created performance record.\r
1508 @retval EFI_OUT_OF_RESOURCES - Ran out of space to store the records.\r
1509 @retval EFI_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
1510 pointer or invalid PerfId.\r
1511**/\r
1512EFI_STATUS\r
1513EFIAPI\r
1514CreatePerformanceMeasurement (\r
1515 IN CONST VOID *CallerIdentifier,\r
e3917e22
MK
1516 IN CONST VOID *Guid OPTIONAL,\r
1517 IN CONST CHAR8 *String OPTIONAL,\r
137fb13d 1518 IN UINT64 TimeStamp,\r
e3917e22 1519 IN UINT64 Address OPTIONAL,\r
137fb13d
BD
1520 IN UINT32 Identifier,\r
1521 IN PERF_MEASUREMENT_ATTRIBUTE Attribute\r
1522 )\r
1523{\r
1524 EFI_STATUS Status;\r
1525\r
1526 Status = EFI_SUCCESS;\r
1527\r
1528 if (mLockInsertRecord) {\r
1529 return EFI_INVALID_PARAMETER;\r
1530 }\r
1531 mLockInsertRecord = TRUE;\r
1532\r
6b4d58a1
BD
1533 Status = InsertFpdtRecord (CallerIdentifier, Guid, String, TimeStamp, Address, (UINT16)Identifier, Attribute);\r
1534\r
137fb13d
BD
1535 mLockInsertRecord = FALSE;\r
1536\r
1537 return Status;\r
1538}\r
1539\r
a0afd019 1540/**\r
1541 Adds a record at the end of the performance measurement log\r
1542 that records the start time of a performance measurement.\r
1543\r
1544 Adds a record to the end of the performance measurement log\r
f0da4d7d 1545 that contains the Handle, Token, Module and Identifier.\r
a0afd019 1546 The end time of the new record must be set to zero.\r
1547 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
1548 If TimeStamp is zero, the start time in the record is filled in with the value\r
1549 read from the current time stamp.\r
1550\r
1551 @param Handle Pointer to environment specific context used\r
1552 to identify the component being measured.\r
1553 @param Token Pointer to a Null-terminated ASCII string\r
1554 that identifies the component being measured.\r
1555 @param Module Pointer to a Null-terminated ASCII string\r
1556 that identifies the module being measured.\r
1557 @param TimeStamp 64-bit time stamp.\r
f0da4d7d
SZ
1558 @param Identifier 32-bit identifier. If the value is 0, the created record\r
1559 is same as the one created by StartPerformanceMeasurement.\r
a0afd019 1560\r
1561 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
1562 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
1563\r
1564**/\r
1565RETURN_STATUS\r
1566EFIAPI\r
f0da4d7d 1567StartPerformanceMeasurementEx (\r
e3917e22
MK
1568 IN CONST VOID *Handle OPTIONAL,\r
1569 IN CONST CHAR8 *Token OPTIONAL,\r
1570 IN CONST CHAR8 *Module OPTIONAL,\r
f0da4d7d
SZ
1571 IN UINT64 TimeStamp,\r
1572 IN UINT32 Identifier\r
a0afd019 1573 )\r
1574{\r
137fb13d
BD
1575 CONST CHAR8 *String;\r
1576\r
1577 if (Token != NULL) {\r
1578 String = Token;\r
1579 } else if (Module != NULL) {\r
1580 String = Module;\r
1581 } else {\r
1582 String = NULL;\r
1583 }\r
1584\r
1585 return (RETURN_STATUS)CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfStartEntry);\r
a0afd019 1586}\r
1587\r
1588/**\r
1589 Searches the performance measurement log from the beginning of the log\r
1590 for the first matching record that contains a zero end time and fills in a valid end time.\r
1591\r
1592 Searches the performance measurement log from the beginning of the log\r
9609d24b 1593 for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.\r
a0afd019 1594 If the record can not be found then return RETURN_NOT_FOUND.\r
1595 If the record is found and TimeStamp is not zero,\r
1596 then the end time in the record is filled in with the value specified by TimeStamp.\r
1597 If the record is found and TimeStamp is zero, then the end time in the matching record\r
1598 is filled in with the current time stamp value.\r
1599\r
1600 @param Handle Pointer to environment specific context used\r
1601 to identify the component being measured.\r
1602 @param Token Pointer to a Null-terminated ASCII string\r
1603 that identifies the component being measured.\r
1604 @param Module Pointer to a Null-terminated ASCII string\r
1605 that identifies the module being measured.\r
1606 @param TimeStamp 64-bit time stamp.\r
f0da4d7d
SZ
1607 @param Identifier 32-bit identifier. If the value is 0, the found record\r
1608 is same as the one found by EndPerformanceMeasurement.\r
a0afd019 1609\r
1610 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
1611 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
1612\r
1613**/\r
1614RETURN_STATUS\r
1615EFIAPI\r
f0da4d7d 1616EndPerformanceMeasurementEx (\r
e3917e22
MK
1617 IN CONST VOID *Handle OPTIONAL,\r
1618 IN CONST CHAR8 *Token OPTIONAL,\r
1619 IN CONST CHAR8 *Module OPTIONAL,\r
f0da4d7d
SZ
1620 IN UINT64 TimeStamp,\r
1621 IN UINT32 Identifier\r
a0afd019 1622 )\r
1623{\r
137fb13d
BD
1624 CONST CHAR8 *String;\r
1625\r
1626 if (Token != NULL) {\r
1627 String = Token;\r
1628 } else if (Module != NULL) {\r
1629 String = Module;\r
1630 } else {\r
1631 String = NULL;\r
1632 }\r
1633\r
1634 return (RETURN_STATUS)CreatePerformanceMeasurement (Handle, NULL, String, TimeStamp, 0, Identifier, PerfEndEntry);\r
a0afd019 1635}\r
1636\r
1637/**\r
1638 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
f0da4d7d
SZ
1639 It can also retrieve the log created by StartPerformanceMeasurement and EndPerformanceMeasurement,\r
1640 and then assign the Identifier with 0.\r
a0afd019 1641\r
9609d24b
DB
1642 !!! Not support!!!\r
1643\r
a0afd019 1644 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
1645 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
1646 and the key for the second entry in the log is returned. If the performance log is empty,\r
1647 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
1648 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
1649 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
1650 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
1651 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
1652 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
f0da4d7d 1653 the log entry is returned in Handle, Token, Module, StartTimeStamp, EndTimeStamp and Identifier.\r
a0afd019 1654 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
1655 If Handle is NULL, then ASSERT().\r
1656 If Token is NULL, then ASSERT().\r
1657 If Module is NULL, then ASSERT().\r
1658 If StartTimeStamp is NULL, then ASSERT().\r
1659 If EndTimeStamp is NULL, then ASSERT().\r
f0da4d7d 1660 If Identifier is NULL, then ASSERT().\r
a0afd019 1661\r
1662 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
1663 0, then the first performance measurement log entry is retrieved.\r
857dfc45 1664 On exit, the key of the next performance log entry.\r
a0afd019 1665 @param Handle Pointer to environment specific context used to identify the component\r
1666 being measured.\r
1667 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
1668 being measured.\r
1669 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
1670 being measured.\r
1671 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
1672 was started.\r
1673 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
1674 was ended.\r
9609d24b
DB
1675 @param Identifier Pointer to the 32-bit identifier that was recorded when the measurement\r
1676 was ended.\r
a0afd019 1677\r
1678 @return The key for the next performance log entry (in general case).\r
1679\r
1680**/\r
1681UINTN\r
1682EFIAPI\r
f0da4d7d 1683GetPerformanceMeasurementEx (\r
9609d24b 1684 IN UINTN LogEntryKey,\r
a0afd019 1685 OUT CONST VOID **Handle,\r
1686 OUT CONST CHAR8 **Token,\r
1687 OUT CONST CHAR8 **Module,\r
1688 OUT UINT64 *StartTimeStamp,\r
f0da4d7d
SZ
1689 OUT UINT64 *EndTimeStamp,\r
1690 OUT UINT32 *Identifier\r
a0afd019 1691 )\r
1692{\r
9609d24b 1693 return 0;\r
a0afd019 1694}\r
1695\r
f0da4d7d
SZ
1696/**\r
1697 Adds a record at the end of the performance measurement log\r
1698 that records the start time of a performance measurement.\r
1699\r
1700 Adds a record to the end of the performance measurement log\r
1701 that contains the Handle, Token, and Module.\r
1702 The end time of the new record must be set to zero.\r
1703 If TimeStamp is not zero, then TimeStamp is used to fill in the start time in the record.\r
1704 If TimeStamp is zero, the start time in the record is filled in with the value\r
1705 read from the current time stamp.\r
1706\r
1707 @param Handle Pointer to environment specific context used\r
1708 to identify the component being measured.\r
1709 @param Token Pointer to a Null-terminated ASCII string\r
1710 that identifies the component being measured.\r
1711 @param Module Pointer to a Null-terminated ASCII string\r
1712 that identifies the module being measured.\r
1713 @param TimeStamp 64-bit time stamp.\r
1714\r
1715 @retval RETURN_SUCCESS The start of the measurement was recorded.\r
1716 @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement.\r
1717\r
1718**/\r
1719RETURN_STATUS\r
1720EFIAPI\r
1721StartPerformanceMeasurement (\r
e3917e22
MK
1722 IN CONST VOID *Handle OPTIONAL,\r
1723 IN CONST CHAR8 *Token OPTIONAL,\r
1724 IN CONST CHAR8 *Module OPTIONAL,\r
f0da4d7d
SZ
1725 IN UINT64 TimeStamp\r
1726 )\r
1727{\r
137fb13d 1728 return StartPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
f0da4d7d
SZ
1729}\r
1730\r
1731/**\r
1732 Searches the performance measurement log from the beginning of the log\r
1733 for the first matching record that contains a zero end time and fills in a valid end time.\r
1734\r
1735 Searches the performance measurement log from the beginning of the log\r
1736 for the first record that matches Handle, Token, and Module and has an end time value of zero.\r
1737 If the record can not be found then return RETURN_NOT_FOUND.\r
1738 If the record is found and TimeStamp is not zero,\r
1739 then the end time in the record is filled in with the value specified by TimeStamp.\r
1740 If the record is found and TimeStamp is zero, then the end time in the matching record\r
1741 is filled in with the current time stamp value.\r
1742\r
1743 @param Handle Pointer to environment specific context used\r
1744 to identify the component being measured.\r
1745 @param Token Pointer to a Null-terminated ASCII string\r
1746 that identifies the component being measured.\r
1747 @param Module Pointer to a Null-terminated ASCII string\r
1748 that identifies the module being measured.\r
1749 @param TimeStamp 64-bit time stamp.\r
1750\r
1751 @retval RETURN_SUCCESS The end of the measurement was recorded.\r
1752 @retval RETURN_NOT_FOUND The specified measurement record could not be found.\r
1753\r
1754**/\r
1755RETURN_STATUS\r
1756EFIAPI\r
1757EndPerformanceMeasurement (\r
e3917e22
MK
1758 IN CONST VOID *Handle OPTIONAL,\r
1759 IN CONST CHAR8 *Token OPTIONAL,\r
1760 IN CONST CHAR8 *Module OPTIONAL,\r
f0da4d7d
SZ
1761 IN UINT64 TimeStamp\r
1762 )\r
1763{\r
137fb13d 1764 return EndPerformanceMeasurementEx (Handle, Token, Module, TimeStamp, 0);\r
f0da4d7d
SZ
1765}\r
1766\r
1767/**\r
1768 Attempts to retrieve a performance measurement log entry from the performance measurement log.\r
1769 It can also retrieve the log created by StartPerformanceMeasurementEx and EndPerformanceMeasurementEx,\r
1770 and then eliminate the Identifier.\r
1771\r
9609d24b
DB
1772 !!! Not support!!!\r
1773\r
f0da4d7d
SZ
1774 Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is\r
1775 zero on entry, then an attempt is made to retrieve the first entry from the performance log,\r
1776 and the key for the second entry in the log is returned. If the performance log is empty,\r
1777 then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance\r
1778 log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is\r
1779 returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is\r
1780 retrieved and an implementation specific non-zero key value that specifies the end of the performance\r
1781 log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry\r
1782 is retrieved and zero is returned. In the cases where a performance log entry can be returned,\r
1783 the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp.\r
1784 If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT().\r
1785 If Handle is NULL, then ASSERT().\r
1786 If Token is NULL, then ASSERT().\r
1787 If Module is NULL, then ASSERT().\r
1788 If StartTimeStamp is NULL, then ASSERT().\r
1789 If EndTimeStamp is NULL, then ASSERT().\r
1790\r
1791 @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve.\r
1792 0, then the first performance measurement log entry is retrieved.\r
1793 On exit, the key of the next performance log entry.\r
1794 @param Handle Pointer to environment specific context used to identify the component\r
1795 being measured.\r
1796 @param Token Pointer to a Null-terminated ASCII string that identifies the component\r
1797 being measured.\r
1798 @param Module Pointer to a Null-terminated ASCII string that identifies the module\r
1799 being measured.\r
1800 @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
1801 was started.\r
1802 @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement\r
1803 was ended.\r
1804\r
1805 @return The key for the next performance log entry (in general case).\r
1806\r
1807**/\r
1808UINTN\r
1809EFIAPI\r
1810GetPerformanceMeasurement (\r
1811 IN UINTN LogEntryKey,\r
1812 OUT CONST VOID **Handle,\r
1813 OUT CONST CHAR8 **Token,\r
1814 OUT CONST CHAR8 **Module,\r
1815 OUT UINT64 *StartTimeStamp,\r
1816 OUT UINT64 *EndTimeStamp\r
1817 )\r
1818{\r
9609d24b 1819 return 0;\r
f0da4d7d
SZ
1820}\r
1821\r
a0afd019 1822/**\r
1823 Returns TRUE if the performance measurement macros are enabled.\r
1824\r
1825 This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
1826 PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned.\r
1827\r
1828 @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
1829 PcdPerformanceLibraryPropertyMask is set.\r
1830 @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of\r
1831 PcdPerformanceLibraryPropertyMask is clear.\r
1832\r
1833**/\r
1834BOOLEAN\r
1835EFIAPI\r
1836PerformanceMeasurementEnabled (\r
1837 VOID\r
1838 )\r
1839{\r
1840 return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
1841}\r
6b4d58a1
BD
1842\r
1843/**\r
1844 Create performance record with event description and a timestamp.\r
1845\r
1846 @param CallerIdentifier - Image handle or pointer to caller ID GUID\r
1847 @param Guid - Pointer to a GUID\r
1848 @param String - Pointer to a string describing the measurement\r
1849 @param Address - Pointer to a location in memory relevant to the measurement\r
1850 @param Identifier - Performance identifier describing the type of measurement\r
1851\r
1852 @retval RETURN_SUCCESS - Successfully created performance record\r
1853 @retval RETURN_OUT_OF_RESOURCES - Ran out of space to store the records\r
1854 @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
1855 pointer or invalid PerfId\r
1856\r
1857**/\r
1858RETURN_STATUS\r
1859EFIAPI\r
1860LogPerformanceMeasurement (\r
1861 IN CONST VOID *CallerIdentifier,\r
e3917e22
MK
1862 IN CONST VOID *Guid OPTIONAL,\r
1863 IN CONST CHAR8 *String OPTIONAL,\r
1864 IN UINT64 Address OPTIONAL,\r
6b4d58a1
BD
1865 IN UINT32 Identifier\r
1866 )\r
1867{\r
1868 return (RETURN_STATUS)CreatePerformanceMeasurement (CallerIdentifier, Guid, String, 0, Address, Identifier, PerfEntry);\r
1869}\r
1870\r
1871/**\r
1872 Check whether the specified performance measurement can be logged.\r
1873\r
1874 This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set\r
1875 and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.\r
1876\r
1877 @param Type - Type of the performance measurement entry.\r
1878\r
1879 @retval TRUE The performance measurement can be logged.\r
1880 @retval FALSE The performance measurement can NOT be logged.\r
1881\r
1882**/\r
1883BOOLEAN\r
1884EFIAPI\r
1885LogPerformanceMeasurementEnabled (\r
1886 IN CONST UINTN Type\r
1887 )\r
1888{\r
1889 //\r
1890 // When Performance measurement is enabled and the type is not filtered, the performance can be logged.\r
1891 //\r
1892 if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask) & Type) == 0) {\r
1893 return TRUE;\r
1894 }\r
1895 return FALSE;\r
1896}\r