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