27CHAR8 *mActionString[] = {
35CHAR8 *mSmmActionString[] = {
37 "gSmst->SmmAllocatePages",
38 "gSmst->SmmFreePages",
39 "gSmst->SmmAllocatePool",
44 MEMORY_PROFILE_ACTION Action;
49 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES,
"Lib:AllocatePages" },
50 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES,
"Lib:AllocateRuntimePages" },
51 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_PAGES,
"Lib:AllocateReservedPages" },
52 { MEMORY_PROFILE_ACTION_LIB_FREE_PAGES,
"Lib:FreePages" },
53 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_PAGES,
"Lib:AllocateAlignedPages" },
54 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RUNTIME_PAGES,
"Lib:AllocateAlignedRuntimePages" },
55 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RESERVED_PAGES,
"Lib:AllocateAlignedReservedPages" },
56 { MEMORY_PROFILE_ACTION_LIB_FREE_ALIGNED_PAGES,
"Lib:FreeAlignedPages" },
57 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_POOL,
"Lib:AllocatePool" },
58 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_POOL,
"Lib:AllocateRuntimePool" },
59 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_POOL,
"Lib:AllocateReservedPool" },
60 { MEMORY_PROFILE_ACTION_LIB_FREE_POOL,
"Lib:FreePool" },
61 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ZERO_POOL,
"Lib:AllocateZeroPool" },
62 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_ZERO_POOL,
"Lib:AllocateRuntimeZeroPool" },
63 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_ZERO_POOL,
"Lib:AllocateReservedZeroPool" },
64 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_COPY_POOL,
"Lib:AllocateCopyPool" },
65 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_COPY_POOL,
"Lib:AllocateRuntimeCopyPool" },
66 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_COPY_POOL,
"Lib:AllocateReservedCopyPool" },
67 { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_POOL,
"Lib:ReallocatePool" },
68 { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RUNTIME_POOL,
"Lib:ReallocateRuntimePool" },
69 { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL,
"Lib:ReallocateReservedPool" },
72CHAR8 mUserDefinedActionString[] = {
"UserDefined-0x80000000" };
74CHAR8 *mMemoryTypeString[] = {
75 "EfiReservedMemoryType",
78 "EfiBootServicesCode",
79 "EfiBootServicesData",
80 "EfiRuntimeServicesCode",
81 "EfiRuntimeServicesData",
82 "EfiConventionalMemory",
84 "EfiACPIReclaimMemory",
87 "EfiMemoryMappedIOPortSpace",
89 "EfiPersistentMemory",
94CHAR8 *mSubsystemString[] = {
106 "EFI_BOOT_SERVICE_DRIVER",
107 "EFI_RUNTIME_DRIVER",
113CHAR8 *mFileTypeString[] = {
122 "COMBINED_PEIM_DRIVER",
125 "FIRMWARE_VOLUME_IMAGE",
130#define PROFILE_NAME_STRING_LENGTH 64
131CHAR8 mNameString[PROFILE_NAME_STRING_LENGTH + 1];
136#define MEMORY_PROFILE_ALLOC_SUMMARY_INFO_SIGNATURE SIGNATURE_32 ('M','P','A','S')
137#define MEMORY_PROFILE_ALLOC_SUMMARY_INFO_REVISION 0x0001
141 PHYSICAL_ADDRESS CallerAddress;
142 MEMORY_PROFILE_ACTION Action;
144 UINT32 AllocateCount;
184 IN CHAR8 *PdbFileName,
185 OUT CHAR8 *AsciiBuffer
193 ZeroMem (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1);
195 if (PdbFileName ==
NULL) {
196 AsciiStrnCpyS (AsciiBuffer, PROFILE_NAME_STRING_LENGTH + 1,
" ", 1);
199 for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++) {
202 for (IndexPdb = 0; PdbFileName[IndexPdb] != 0; IndexPdb++) {
203 if ((PdbFileName[IndexPdb] ==
'\\') || (PdbFileName[IndexPdb] ==
'/')) {
204 StartIndex = IndexPdb + 1;
207 if (PdbFileName[IndexPdb] ==
'.') {
213 for (IndexPdb = StartIndex; IndexPdb < EndIndex; IndexPdb++) {
214 AsciiBuffer[IndexBuffer] = PdbFileName[IndexPdb];
216 if (IndexBuffer >= PROFILE_NAME_STRING_LENGTH) {
217 AsciiBuffer[PROFILE_NAME_STRING_LENGTH] = 0;
248 if (DriverInfo->PdbStringOffset != 0) {
260 &DriverInfo->FileName,
261 EFI_SECTION_USER_INTERFACE,
263 (VOID **)&NameString,
266 if (!EFI_ERROR (Status)) {
270 if (
StrLen (NameString) > PROFILE_NAME_STRING_LENGTH) {
271 NameString[PROFILE_NAME_STRING_LENGTH] = 0;
283 AsciiSPrint (mNameString,
sizeof (mNameString),
"%g", &DriverInfo->FileName);
302 if ((UINT32)MemoryType >= 0x80000000) {
306 Index = EfiMaxMemoryType;
307 }
else if ((UINT32)MemoryType >= 0x70000000) {
311 Index = EfiMaxMemoryType + 1;
316 return mMemoryTypeString[Index];
332 IN MEMORY_PROFILE_ACTION Action,
333 IN CHAR8 *UserDefinedActionString,
338 UINTN ActionStringCount;
339 CHAR8 **ActionString;
342 ActionString = mSmmActionString;
343 ActionStringCount =
ARRAY_SIZE (mSmmActionString);
345 ActionString = mActionString;
346 ActionStringCount =
ARRAY_SIZE (mActionString);
349 if ((
UINTN)(UINT32)Action < ActionStringCount) {
350 return ActionString[Action];
353 for (Index = 0; Index <
ARRAY_SIZE (mExtActionString); Index++) {
354 if (mExtActionString[Index].Action == Action) {
355 return mExtActionString[Index].String;
359 if ((Action & MEMORY_PROFILE_ACTION_USER_DEFINED_MASK) != 0) {
360 if (UserDefinedActionString !=
NULL) {
361 return UserDefinedActionString;
364 AsciiSPrint (mUserDefinedActionString,
sizeof (mUserDefinedActionString),
"UserDefined-0x%08x", Action);
365 return mUserDefinedActionString;
368 return ActionString[0];
393 if (AllocInfo->Header.Signature != MEMORY_PROFILE_ALLOC_INFO_SIGNATURE) {
397 if (AllocInfo->ActionStringOffset != 0) {
398 ActionString = (CHAR8 *)((
UINTN)AllocInfo + AllocInfo->ActionStringOffset);
403 Print (L
" MEMORY_PROFILE_ALLOC_INFO (0x%x)\n", AllocIndex);
404 Print (L
" Signature - 0x%08x\n", AllocInfo->Header.Signature);
405 Print (L
" Length - 0x%04x\n", AllocInfo->Header.Length);
406 Print (L
" Revision - 0x%04x\n", AllocInfo->Header.Revision);
407 Print (L
" CallerAddress - 0x%016lx (Offset: 0x%08x)\n", AllocInfo->CallerAddress, (
UINTN)(AllocInfo->CallerAddress - DriverInfo->ImageBase));
408 Print (L
" SequenceId - 0x%08x\n", AllocInfo->SequenceId);
409 Print (L
" Action - 0x%08x (%a)\n", AllocInfo->Action,
ProfileActionToStr (AllocInfo->Action, ActionString, IsForSmm));
411 Print (L
" Buffer - 0x%016lx\n", AllocInfo->Buffer);
412 Print (L
" Size - 0x%016lx\n", AllocInfo->Size);
440 if (DriverInfo->Header.Signature != MEMORY_PROFILE_DRIVER_INFO_SIGNATURE) {
444 Print (L
" MEMORY_PROFILE_DRIVER_INFO (0x%x)\n", DriverIndex);
445 Print (L
" Signature - 0x%08x\n", DriverInfo->Header.Signature);
446 Print (L
" Length - 0x%04x\n", DriverInfo->Header.Length);
447 Print (L
" Revision - 0x%04x\n", DriverInfo->Header.Revision);
449 Print (L
" FileName - %a\n", NameString);
450 if (DriverInfo->PdbStringOffset != 0) {
451 Print (L
" Pdb - %a\n", (CHAR8 *)((
UINTN)DriverInfo + DriverInfo->PdbStringOffset));
454 Print (L
" ImageBase - 0x%016lx\n", DriverInfo->ImageBase);
455 Print (L
" ImageSize - 0x%016lx\n", DriverInfo->ImageSize);
456 Print (L
" EntryPoint - 0x%016lx\n", DriverInfo->EntryPoint);
457 Print (L
" ImageSubsystem - 0x%04x (%a)\n", DriverInfo->ImageSubsystem, mSubsystemString[(DriverInfo->ImageSubsystem < sizeof (mSubsystemString)/
sizeof (mSubsystemString[0])) ? DriverInfo->ImageSubsystem : 0]);
458 Print (L
" FileType - 0x%02x (%a)\n", DriverInfo->FileType, mFileTypeString[(DriverInfo->FileType < sizeof (mFileTypeString)/
sizeof (mFileTypeString[0])) ? DriverInfo->FileType : 0]);
459 Print (L
" CurrentUsage - 0x%016lx\n", DriverInfo->CurrentUsage);
460 Print (L
" PeakUsage - 0x%016lx\n", DriverInfo->PeakUsage);
461 for (TypeIndex = 0; TypeIndex <
sizeof (DriverInfo->CurrentUsageByType) /
sizeof (DriverInfo->CurrentUsageByType[0]); TypeIndex++) {
462 if ((DriverInfo->CurrentUsageByType[TypeIndex] != 0) ||
463 (DriverInfo->PeakUsageByType[TypeIndex] != 0))
465 Print (L
" CurrentUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->CurrentUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]);
466 Print (L
" PeakUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->PeakUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]);
470 Print (L
" AllocRecordCount - 0x%08x\n", DriverInfo->AllocRecordCount);
473 for (AllocIndex = 0; AllocIndex < DriverInfo->AllocRecordCount; AllocIndex++) {
475 if (AllocInfo ==
NULL) {
503 if (Context->Header.Signature != MEMORY_PROFILE_CONTEXT_SIGNATURE) {
507 Print (L
"MEMORY_PROFILE_CONTEXT\n");
508 Print (L
" Signature - 0x%08x\n", Context->Header.Signature);
509 Print (L
" Length - 0x%04x\n", Context->Header.Length);
510 Print (L
" Revision - 0x%04x\n", Context->Header.Revision);
511 Print (L
" CurrentTotalUsage - 0x%016lx\n", Context->CurrentTotalUsage);
512 Print (L
" PeakTotalUsage - 0x%016lx\n", Context->PeakTotalUsage);
513 for (TypeIndex = 0; TypeIndex <
sizeof (Context->CurrentTotalUsageByType) /
sizeof (Context->CurrentTotalUsageByType[0]); TypeIndex++) {
514 if ((Context->CurrentTotalUsageByType[TypeIndex] != 0) ||
515 (Context->PeakTotalUsageByType[TypeIndex] != 0))
517 Print (L
" CurrentTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->CurrentTotalUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]);
518 Print (L
" PeakTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->PeakTotalUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]);
522 Print (L
" TotalImageSize - 0x%016lx\n", Context->TotalImageSize);
523 Print (L
" ImageCount - 0x%08x\n", Context->ImageCount);
524 Print (L
" SequenceCount - 0x%08x\n", Context->SequenceCount);
527 for (DriverIndex = 0; DriverIndex < Context->ImageCount; DriverIndex++) {
529 if (DriverInfo ==
NULL) {
534 return (VOID *)DriverInfo;
552 if (Descriptor->Header.Signature != MEMORY_PROFILE_DESCRIPTOR_SIGNATURE) {
556 Print (L
" MEMORY_PROFILE_DESCRIPTOR (0x%x)\n", DescriptorIndex);
557 Print (L
" Signature - 0x%08x\n", Descriptor->Header.Signature);
558 Print (L
" Length - 0x%04x\n", Descriptor->Header.Length);
559 Print (L
" Revision - 0x%04x\n", Descriptor->Header.Revision);
560 Print (L
" Address - 0x%016lx\n", Descriptor->Address);
561 Print (L
" Size - 0x%016lx\n", Descriptor->Size);
580 UINTN DescriptorIndex;
582 if (
FreeMemory->Header.Signature != MEMORY_PROFILE_FREE_MEMORY_SIGNATURE) {
586 Print (L
"MEMORY_PROFILE_FREE_MEMORY\n");
590 Print (L
" TotalFreeMemoryPages - 0x%016lx\n",
FreeMemory->TotalFreeMemoryPages);
591 Print (L
" FreeMemoryEntryCount - 0x%08x\n",
FreeMemory->FreeMemoryEntryCount);
594 for (DescriptorIndex = 0; DescriptorIndex <
FreeMemory->FreeMemoryEntryCount; DescriptorIndex++) {
596 if (Descriptor ==
NULL) {
601 return (VOID *)Descriptor;
618 UINTN DescriptorIndex;
620 if (MemoryRange->Header.Signature != MEMORY_PROFILE_MEMORY_RANGE_SIGNATURE) {
624 Print (L
"MEMORY_PROFILE_MEMORY_RANGE\n");
625 Print (L
" Signature - 0x%08x\n", MemoryRange->Header.Signature);
626 Print (L
" Length - 0x%04x\n", MemoryRange->Header.Length);
627 Print (L
" Revision - 0x%04x\n", MemoryRange->Header.Revision);
628 Print (L
" MemoryRangeCount - 0x%08x\n", MemoryRange->MemoryRangeCount);
631 for (DescriptorIndex = 0; DescriptorIndex < MemoryRange->MemoryRangeCount; DescriptorIndex++) {
633 if (Descriptor ==
NULL) {
638 return (VOID *)Descriptor;
653 IN PHYSICAL_ADDRESS ProfileBuffer,
654 IN UINT64 ProfileSize,
661 ProfileEnd = (
UINTN)(ProfileBuffer + ProfileSize);
663 while ((
UINTN)CommonHeader < ProfileEnd) {
664 if (CommonHeader->Signature == Signature) {
668 return (VOID *)CommonHeader;
671 if (CommonHeader->Length == 0) {
693 IN PHYSICAL_ADDRESS ProfileBuffer,
694 IN UINT64 ProfileSize,
703 if (Context !=
NULL) {
713 if (MemoryRange !=
NULL) {
729 IN PHYSICAL_ADDRESS CallerAddress,
738 AllocSummaryInfoList = DriverSummaryInfoData->AllocSummaryInfoList;
740 for (AllocSummaryLink = AllocSummaryInfoList->ForwardLink;
741 AllocSummaryLink != AllocSummaryInfoList;
742 AllocSummaryLink = AllocSummaryLink->ForwardLink)
744 AllocSummaryInfoData =
CR (
748 MEMORY_PROFILE_ALLOC_SUMMARY_INFO_SIGNATURE
750 AllocSummaryInfo = &AllocSummaryInfoData->AllocSummaryInfo;
751 if (AllocSummaryInfo->CallerAddress == CallerAddress) {
752 return AllocSummaryInfoData;
778 if (AllocInfo->Header.Signature != MEMORY_PROFILE_ALLOC_INFO_SIGNATURE) {
783 if (AllocSummaryInfoData ==
NULL) {
784 AllocSummaryInfoData =
AllocatePool (
sizeof (*AllocSummaryInfoData));
785 if (AllocSummaryInfoData ==
NULL) {
789 AllocSummaryInfoData->Signature = MEMORY_PROFILE_ALLOC_SUMMARY_INFO_SIGNATURE;
790 AllocSummaryInfo = &AllocSummaryInfoData->AllocSummaryInfo;
791 AllocSummaryInfo->Header.Signature = MEMORY_PROFILE_ALLOC_SUMMARY_INFO_SIGNATURE;
792 AllocSummaryInfo->Header.Length =
sizeof (*AllocSummaryInfo);
793 AllocSummaryInfo->Header.Revision = MEMORY_PROFILE_ALLOC_SUMMARY_INFO_REVISION;
794 AllocSummaryInfo->CallerAddress = AllocInfo->CallerAddress;
795 AllocSummaryInfo->Action = AllocInfo->Action;
796 if (AllocInfo->ActionStringOffset != 0) {
797 AllocSummaryInfo->ActionString = (CHAR8 *)((
UINTN)AllocInfo + AllocInfo->ActionStringOffset);
799 AllocSummaryInfo->ActionString =
NULL;
802 AllocSummaryInfo->AllocateCount = 0;
803 AllocSummaryInfo->TotalSize = 0;
804 InsertTailList (DriverSummaryInfoData->AllocSummaryInfoList, &AllocSummaryInfoData->Link);
807 AllocSummaryInfo = &AllocSummaryInfoData->AllocSummaryInfo;
808 AllocSummaryInfo->AllocateCount++;
809 AllocSummaryInfo->TotalSize += AllocInfo->Size;
834 if (DriverInfo->Header.Signature != MEMORY_PROFILE_DRIVER_INFO_SIGNATURE) {
839 if (DriverSummaryInfoData ==
NULL) {
843 DriverSummaryInfoData->Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
844 DriverSummaryInfoData->DriverInfo = DriverInfo;
845 DriverSummaryInfoData->AllocSummaryInfoList = (
LIST_ENTRY *)(DriverSummaryInfoData + 1);
847 InsertTailList (ContextSummaryData->DriverSummaryInfoList, &DriverSummaryInfoData->Link);
850 for (AllocIndex = 0; AllocIndex < DriverInfo->AllocRecordCount; AllocIndex++) {
852 if (AllocInfo ==
NULL) {
871 IN PHYSICAL_ADDRESS ProfileBuffer,
872 IN UINT64 ProfileSize
880 if (Context ==
NULL) {
884 mMemoryProfileContextSummary.Signature = MEMORY_PROFILE_CONTEXT_SIGNATURE;
885 mMemoryProfileContextSummary.Context = Context;
886 mMemoryProfileContextSummary.DriverSummaryInfoList = &mImageSummaryQueue;
889 for (DriverIndex = 0; DriverIndex < Context->ImageCount; DriverIndex++) {
891 if (DriverInfo ==
NULL) {
896 return &mMemoryProfileContextSummary;
923 if (ContextSummaryData ==
NULL) {
927 Print (L
"\nSummary Data:\n");
929 DriverSummaryInfoList = ContextSummaryData->DriverSummaryInfoList;
930 for (DriverSummaryLink = DriverSummaryInfoList->ForwardLink;
931 DriverSummaryLink != DriverSummaryInfoList;
932 DriverSummaryLink = DriverSummaryLink->ForwardLink)
934 DriverSummaryInfoData =
CR (
938 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
940 DriverInfo = DriverSummaryInfoData->DriverInfo;
943 Print (L
"\nDriver - %a (Usage - 0x%08x)", NameString, DriverInfo->CurrentUsage);
944 if (DriverInfo->CurrentUsage == 0) {
949 if (DriverInfo->PdbStringOffset != 0) {
950 Print (L
" (Pdb - %a)\n", (CHAR8 *)((
UINTN)DriverInfo + DriverInfo->PdbStringOffset));
955 Print (L
"Caller List:\n");
956 Print (L
" Count Size RVA Action\n");
957 Print (L
"========== ================== ================== (================================)\n");
958 AllocSummaryInfoList = DriverSummaryInfoData->AllocSummaryInfoList;
959 for (AllocSummaryLink = AllocSummaryInfoList->ForwardLink;
960 AllocSummaryLink != AllocSummaryInfoList;
961 AllocSummaryLink = AllocSummaryLink->ForwardLink)
963 AllocSummaryInfoData =
CR (
967 MEMORY_PROFILE_ALLOC_SUMMARY_INFO_SIGNATURE
969 AllocSummaryInfo = &AllocSummaryInfoData->AllocSummaryInfo;
972 L
"0x%08x 0x%016lx <== 0x%016lx",
973 AllocSummaryInfo->AllocateCount,
974 AllocSummaryInfo->TotalSize,
975 AllocSummaryInfo->CallerAddress - DriverInfo->ImageBase
1002 if (ContextSummaryData ==
NULL) {
1006 DriverSummaryInfoList = ContextSummaryData->DriverSummaryInfoList;
1007 for (DriverSummaryLink = DriverSummaryInfoList->ForwardLink;
1008 DriverSummaryLink != DriverSummaryInfoList;
1011 DriverSummaryInfoData =
CR (
1015 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
1017 DriverSummaryLink = DriverSummaryLink->ForwardLink;
1019 AllocSummaryInfoList = DriverSummaryInfoData->AllocSummaryInfoList;
1020 for (AllocSummaryLink = AllocSummaryInfoList->ForwardLink;
1021 AllocSummaryLink != AllocSummaryInfoList;
1024 AllocSummaryInfoData =
CR (
1028 MEMORY_PROFILE_ALLOC_SUMMARY_INFO_SIGNATURE
1030 AllocSummaryLink = AllocSummaryLink->ForwardLink;
1060 BOOLEAN RecordingState;
1062 Status =
gBS->LocateProtocol (&gEdkiiMemoryProfileGuid,
NULL, (VOID **)&ProfileProtocol);
1063 if (EFI_ERROR (Status)) {
1064 DEBUG ((DEBUG_ERROR,
"UefiMemoryProfile: Locate MemoryProfile protocol - %r\n", Status));
1071 RecordingState = MEMORY_PROFILE_RECORDING_DISABLE;
1072 Status = ProfileProtocol->GetRecordingState (ProfileProtocol, &RecordingState);
1073 if (RecordingState == MEMORY_PROFILE_RECORDING_ENABLE) {
1074 ProfileProtocol->SetRecordingState (ProfileProtocol, MEMORY_PROFILE_RECORDING_DISABLE);
1079 Status = ProfileProtocol->GetData (
1084 if (Status != EFI_BUFFER_TOO_SMALL) {
1085 Print (L
"UefiMemoryProfile: GetData - %r\n", Status);
1091 Status = EFI_OUT_OF_RESOURCES;
1092 Print (L
"UefiMemoryProfile: AllocateZeroPool (0x%x) - %r\n", Size, Status);
1096 Status = ProfileProtocol->GetData (
1101 if (EFI_ERROR (Status)) {
1102 Print (L
"UefiMemoryProfile: GetData - %r\n", Status);
1106 Print (L
"UefiMemoryProfileSize - 0x%x\n", Size);
1107 Print (L
"======= UefiMemoryProfile begin =======\n");
1114 if (MemoryProfileContextSummaryData !=
NULL) {
1119 Print (L
"======= UefiMemoryProfile end =======\n\n\n");
1129 if (RecordingState == MEMORY_PROFILE_RECORDING_ENABLE) {
1130 ProfileProtocol->SetRecordingState (ProfileProtocol, MEMORY_PROFILE_RECORDING_ENABLE);
1156 VOID *ProfileBuffer;
1158 UINTN MinimalSizeNeeded;
1166 BOOLEAN RecordingState;
1168 ProfileBuffer =
NULL;
1170 Status =
gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid,
NULL, (VOID **)&SmmCommunication);
1171 if (EFI_ERROR (Status)) {
1172 DEBUG ((DEBUG_ERROR,
"SmramProfile: Locate SmmCommunication protocol - %r\n", Status));
1176 MinimalSizeNeeded =
sizeof (
EFI_GUID) +
1185 MinimalSizeNeeded +=
MAX (
1203 &gEdkiiPiSmmCommunicationRegionTableGuid,
1204 (VOID **)&PiSmmCommunicationRegionTable
1206 if (EFI_ERROR (Status)) {
1207 DEBUG ((DEBUG_ERROR,
"SmramProfile: Get PiSmmCommunicationRegionTable - %r\n", Status));
1211 ASSERT (PiSmmCommunicationRegionTable !=
NULL);
1214 for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) {
1217 if (Size >= MinimalSizeNeeded) {
1225 ASSERT (Index < PiSmmCommunicationRegionTable->NumberOfEntries);
1226 CommBuffer = (UINT8 *)(
UINTN)Entry->PhysicalStart;
1231 RecordingState = MEMORY_PROFILE_RECORDING_DISABLE;
1234 CopyMem (&CommHeader->
HeaderGuid, &gEdkiiMemoryProfileGuid, sizeof (gEdkiiMemoryProfileGuid));
1238 CommRecordingState->Header.Command = SMRAM_PROFILE_COMMAND_GET_RECORDING_STATE;
1239 CommRecordingState->Header.DataLength =
sizeof (*CommRecordingState);
1240 CommRecordingState->Header.ReturnStatus = (UINT64)-1;
1241 CommRecordingState->RecordingState = MEMORY_PROFILE_RECORDING_DISABLE;
1244 Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
1245 if (EFI_ERROR (Status)) {
1246 DEBUG ((DEBUG_ERROR,
"SmramProfile: SmmCommunication - %r\n", Status));
1250 if (CommRecordingState->Header.ReturnStatus != 0) {
1251 Print (L
"SmramProfile: GetRecordingState - 0x%0x\n", CommRecordingState->Header.ReturnStatus);
1255 RecordingState = CommRecordingState->RecordingState;
1256 if (RecordingState == MEMORY_PROFILE_RECORDING_ENABLE) {
1258 CopyMem (&CommHeader->
HeaderGuid, &gEdkiiMemoryProfileGuid, sizeof (gEdkiiMemoryProfileGuid));
1262 CommRecordingState->Header.Command = SMRAM_PROFILE_COMMAND_SET_RECORDING_STATE;
1263 CommRecordingState->Header.DataLength =
sizeof (*CommRecordingState);
1264 CommRecordingState->Header.ReturnStatus = (UINT64)-1;
1265 CommRecordingState->RecordingState = MEMORY_PROFILE_RECORDING_DISABLE;
1268 SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
1275 CopyMem (&CommHeader->
HeaderGuid, &gEdkiiMemoryProfileGuid, sizeof (gEdkiiMemoryProfileGuid));
1279 CommGetProfileInfo->Header.Command = SMRAM_PROFILE_COMMAND_GET_PROFILE_INFO;
1280 CommGetProfileInfo->Header.DataLength =
sizeof (*CommGetProfileInfo);
1281 CommGetProfileInfo->Header.ReturnStatus = (UINT64)-1;
1282 CommGetProfileInfo->ProfileSize = 0;
1285 Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
1288 if (CommGetProfileInfo->Header.ReturnStatus != 0) {
1290 Print (L
"SmramProfile: GetProfileInfo - 0x%0x\n", CommGetProfileInfo->Header.ReturnStatus);
1294 ProfileSize = (
UINTN)CommGetProfileInfo->ProfileSize;
1300 if (ProfileBuffer ==
NULL) {
1301 Status = EFI_OUT_OF_RESOURCES;
1302 Print (L
"SmramProfile: AllocateZeroPool (0x%x) for profile buffer - %r\n", ProfileSize, Status);
1307 CopyMem (&CommHeader->
HeaderGuid, &gEdkiiMemoryProfileGuid, sizeof (gEdkiiMemoryProfileGuid));
1311 CommGetProfileData->Header.Command = SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA_BY_OFFSET;
1312 CommGetProfileData->Header.DataLength =
sizeof (*CommGetProfileData);
1313 CommGetProfileData->Header.ReturnStatus = (UINT64)-1;
1316 Buffer = (UINT8 *)CommHeader + CommSize;
1319 CommGetProfileData->ProfileBuffer = (PHYSICAL_ADDRESS)(
UINTN)Buffer;
1320 CommGetProfileData->ProfileOffset = 0;
1321 while (CommGetProfileData->ProfileOffset < ProfileSize) {
1322 Offset = (
UINTN)CommGetProfileData->ProfileOffset;
1323 if (Size <= (ProfileSize - CommGetProfileData->ProfileOffset)) {
1324 CommGetProfileData->ProfileSize = (UINT64)Size;
1326 CommGetProfileData->ProfileSize = (UINT64)(ProfileSize - CommGetProfileData->ProfileOffset);
1329 Status = SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
1332 if (CommGetProfileData->Header.ReturnStatus != 0) {
1334 Print (L
"GetProfileData - 0x%x\n", CommGetProfileData->Header.ReturnStatus);
1338 CopyMem ((UINT8 *)ProfileBuffer + Offset, (VOID *)(
UINTN)CommGetProfileData->ProfileBuffer, (
UINTN)CommGetProfileData->ProfileSize);
1341 Print (L
"SmramProfileSize - 0x%x\n", ProfileSize);
1342 Print (L
"======= SmramProfile begin =======\n");
1349 if (MemoryProfileContextSummaryData !=
NULL) {
1354 Print (L
"======= SmramProfile end =======\n\n\n");
1357 if (ProfileBuffer !=
NULL) {
1364 if (RecordingState == MEMORY_PROFILE_RECORDING_ENABLE) {
1366 CopyMem (&CommHeader->
HeaderGuid, &gEdkiiMemoryProfileGuid, sizeof (gEdkiiMemoryProfileGuid));
1370 CommRecordingState->Header.Command = SMRAM_PROFILE_COMMAND_SET_RECORDING_STATE;
1371 CommRecordingState->Header.DataLength =
sizeof (*CommRecordingState);
1372 CommRecordingState->Header.ReturnStatus = (UINT64)-1;
1373 CommRecordingState->RecordingState = MEMORY_PROFILE_RECORDING_ENABLE;
1376 SmmCommunication->Communicate (SmmCommunication, CommBuffer, &CommSize);
1403 if (EFI_ERROR (Status)) {
1404 DEBUG ((DEBUG_ERROR,
"GetUefiMemoryProfileData - %r\n", Status));
1408 if (EFI_ERROR (Status)) {
1409 DEBUG ((DEBUG_ERROR,
"GetSmramProfileData - %r\n", Status));
RETURN_STATUS EFIAPI AsciiStrnCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)
RETURN_STATUS EFIAPI UnicodeStrToAsciiStrS(IN CONST CHAR16 *Source, OUT CHAR8 *Destination, IN UINTN DestMax)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
BOOLEAN EFIAPI IsZeroGuid(IN CONST GUID *Guid)
EFI_STATUS EFIAPI GetSectionFromAnyFv(IN CONST EFI_GUID *NameGuid, IN EFI_SECTION_TYPE SectionType, IN UINTN SectionInstance, OUT VOID **Buffer, OUT UINTN *Size)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
#define ARRAY_SIZE(Array)
#define OFFSET_OF(TYPE, Field)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define CR(Record, TYPE, Field, TestSignature)
MEMORY_PROFILE_DRIVER_INFO * CreateDriverSummaryInfo(IN OUT MEMORY_PROFILE_CONTEXT_SUMMARY_DATA *ContextSummaryData, IN MEMORY_PROFILE_DRIVER_INFO *DriverInfo)
CHAR8 * GetDriverNameString(IN MEMORY_PROFILE_DRIVER_INFO *DriverInfo)
VOID * ScanMemoryProfileBySignature(IN PHYSICAL_ADDRESS ProfileBuffer, IN UINT64 ProfileSize, IN UINT32 Signature)
CHAR8 * ProfileMemoryTypeToStr(IN EFI_MEMORY_TYPE MemoryType)
MEMORY_PROFILE_ALLOC_INFO * CreateAllocSummaryInfo(IN OUT MEMORY_PROFILE_DRIVER_SUMMARY_INFO_DATA *DriverSummaryInfoData, IN MEMORY_PROFILE_ALLOC_INFO *AllocInfo)
MEMORY_PROFILE_DRIVER_INFO * DumpMemoryProfileDriverInfo(IN UINTN DriverIndex, IN MEMORY_PROFILE_DRIVER_INFO *DriverInfo, IN BOOLEAN IsForSmm)
VOID DumpContextSummaryData(IN MEMORY_PROFILE_CONTEXT_SUMMARY_DATA *ContextSummaryData, IN BOOLEAN IsForSmm)
EFI_STATUS GetUefiMemoryProfileData(VOID)
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID * DumpMemoryProfileMemoryRange(IN MEMORY_PROFILE_MEMORY_RANGE *MemoryRange)
MEMORY_PROFILE_DESCRIPTOR * DumpMemoryProfileDescriptor(IN UINTN DescriptorIndex, IN MEMORY_PROFILE_DESCRIPTOR *Descriptor)
VOID * DumpMemoryProfileFreeMemory(IN MEMORY_PROFILE_FREE_MEMORY *FreeMemory)
CHAR8 * ProfileActionToStr(IN MEMORY_PROFILE_ACTION Action, IN CHAR8 *UserDefinedActionString, IN BOOLEAN IsForSmm)
MEMORY_PROFILE_ALLOC_SUMMARY_INFO_DATA * GetAllocSummaryInfoByCallerAddress(IN PHYSICAL_ADDRESS CallerAddress, IN MEMORY_PROFILE_DRIVER_SUMMARY_INFO_DATA *DriverSummaryInfoData)
VOID DumpMemoryProfile(IN PHYSICAL_ADDRESS ProfileBuffer, IN UINT64 ProfileSize, IN BOOLEAN IsForSmm)
EFI_STATUS GetSmramProfileData(VOID)
VOID DestroyContextSummaryData(IN OUT MEMORY_PROFILE_CONTEXT_SUMMARY_DATA *ContextSummaryData)
VOID * DumpMemoryProfileContext(IN MEMORY_PROFILE_CONTEXT *Context, IN BOOLEAN IsForSmm)
MEMORY_PROFILE_CONTEXT_SUMMARY_DATA * CreateContextSummaryData(IN PHYSICAL_ADDRESS ProfileBuffer, IN UINT64 ProfileSize)
VOID GetShortPdbFileName(IN CHAR8 *PdbFileName, OUT CHAR8 *AsciiBuffer)
MEMORY_PROFILE_ALLOC_INFO * DumpMemoryProfileAllocInfo(IN MEMORY_PROFILE_DRIVER_INFO *DriverInfo, IN UINTN AllocIndex, IN MEMORY_PROFILE_ALLOC_INFO *AllocInfo, IN BOOLEAN IsForSmm)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
#define EFI_PAGES_TO_SIZE(Pages)
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)