11#define IS_SMRAM_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT1) != 0)
12#define IS_UEFI_MEMORY_PROFILE_ENABLED ((PcdGet8 (PcdMemoryProfilePropertyMask) & BIT0) != 0)
14#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
15 ((ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1)))
41#define SMRAM_INFO_DUMP_PAGE_THRESHOLD 4
45 MEMORY_PROFILE_FREE_MEMORY_SIGNATURE,
47 MEMORY_PROFILE_FREE_MEMORY_REVISION
55 MEMORY_PROFILE_CONTEXT_SIGNATURE,
58 MEMORY_PROFILE_CONTEXT_SIGNATURE,
60 MEMORY_PROFILE_CONTEXT_REVISION
107 IN OUT UINT64 *ProfileSize,
131 IN PHYSICAL_ADDRESS ImageBase,
133 IN EFI_FV_FILETYPE FileType
155 IN PHYSICAL_ADDRESS ImageBase,
174 OUT BOOLEAN *RecordingState
191 IN BOOLEAN RecordingState
221 IN PHYSICAL_ADDRESS CallerAddress,
222 IN MEMORY_PROFILE_ACTION Action,
226 IN CHAR8 *ActionString OPTIONAL
249 return mSmramProfileContextPtr;
270 ASSERT (Pe32Data !=
NULL);
273 if (DosHdr->
e_magic == EFI_IMAGE_DOS_SIGNATURE) {
285 if (Hdr.Te->
Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
287 }
else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
288 Magic = Hdr.Pe32->OptionalHeader.
Magic;
290 return Hdr.Pe32->OptionalHeader.Subsystem;
292 return Hdr.Pe32Plus->OptionalHeader.Subsystem;
325 ASSERT (Pe32Data !=
NULL);
326 ASSERT (EntryPoint !=
NULL);
329 if (DosHdr->
e_magic == EFI_IMAGE_DOS_SIGNATURE) {
345 if (Hdr.Te->
Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
348 }
else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
349 *EntryPoint = (
VOID *)((
UINTN)Pe32Data + (
UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff));
374 IN PHYSICAL_ADDRESS ImageBase,
376 IN PHYSICAL_ADDRESS EntryPoint,
377 IN UINT16 ImageSubsystem,
378 IN EFI_FV_FILETYPE FileType
384 VOID *EntryPointInImage;
387 UINTN PdbOccupiedSize;
392 if (ImageBase != 0) {
393 PdbString = PeCoffLoaderGetPdbPointer ((
VOID *)(
UINTN)ImageBase);
394 if (PdbString !=
NULL) {
396 PdbOccupiedSize = GET_OCCUPIED_SIZE (PdbSize,
sizeof (UINT64));
405 sizeof (*DriverInfoData) +
sizeof (
LIST_ENTRY) + PdbSize,
406 (
VOID **)&DriverInfoData
408 if (EFI_ERROR (Status)) {
412 ASSERT (DriverInfoData !=
NULL);
414 ZeroMem (DriverInfoData,
sizeof (*DriverInfoData));
416 DriverInfo = &DriverInfoData->DriverInfo;
417 DriverInfoData->Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
418 DriverInfo->Header.Signature = MEMORY_PROFILE_DRIVER_INFO_SIGNATURE;
420 DriverInfo->Header.Revision = MEMORY_PROFILE_DRIVER_INFO_REVISION;
421 if (FileName !=
NULL) {
425 DriverInfo->ImageBase = ImageBase;
426 DriverInfo->ImageSize = ImageSize;
427 DriverInfo->EntryPoint = EntryPoint;
428 DriverInfo->ImageSubsystem = ImageSubsystem;
429 if ((EntryPoint != 0) && ((EntryPoint < ImageBase) || (EntryPoint >= (ImageBase + ImageSize)))) {
436 DriverInfo->ImageBase = ImageBase + EntryPoint - (PHYSICAL_ADDRESS)(
UINTN)EntryPointInImage;
439 DriverInfo->FileType = FileType;
440 DriverInfoData->AllocInfoList = (
LIST_ENTRY *)(DriverInfoData + 1);
442 DriverInfo->CurrentUsage = 0;
443 DriverInfo->PeakUsage = 0;
444 DriverInfo->AllocRecordCount = 0;
447 DriverInfoData->PdbString = (CHAR8 *)(DriverInfoData->AllocInfoList + 1);
448 CopyMem (DriverInfoData->PdbString, PdbString, PdbSize);
450 DriverInfo->PdbStringOffset = 0;
451 DriverInfoData->PdbString =
NULL;
454 InsertTailList (ContextData->DriverInfoList, &DriverInfoData->Link);
455 ContextData->Context.ImageCount++;
456 ContextData->Context.TotalImageSize += DriverInfo->ImageSize;
458 return DriverInfoData;
473 IN PHYSICAL_ADDRESS ImageBase,
475 IN EFI_FV_FILETYPE FileType
483 if (IS_UEFI_MEMORY_PROFILE_ENABLED) {
485 Status =
gBS->LocateProtocol (&gEdkiiMemoryProfileGuid,
NULL, (
VOID **)&ProfileProtocol);
486 if (!EFI_ERROR (Status)) {
490 Status = ProfileProtocol->RegisterImage (
512 IN PHYSICAL_ADDRESS ImageBase,
521 if (IS_UEFI_MEMORY_PROFILE_ENABLED) {
523 Status =
gBS->LocateProtocol (&gEdkiiMemoryProfileGuid,
NULL, (
VOID *)&ProfileProtocol);
524 if (!EFI_ERROR (Status)) {
528 Status = ProfileProtocol->UnregisterImage (
554 UINTN DevicePathSize;
569 DevicePathInstance = mSmramProfileDriverPath;
574 TmpDevicePath = DevicePathInstance;
582 DevicePathSize = (
UINTN)TmpDevicePath - (
UINTN)DevicePathInstance;
583 if ((FilePathSize == DevicePathSize) &&
584 (
CompareMem (DriverFilePath, DevicePathInstance, DevicePathSize) == 0))
613 PHYSICAL_ADDRESS ImageBase;
625 ImageBase = gSmmCorePrivate->PiSmmCoreImageBase;
630 gSmmCorePrivate->PiSmmCoreImageSize,
631 gSmmCorePrivate->PiSmmCoreEntryPoint,
633 EFI_FV_FILETYPE_SMM_CORE
635 if (DriverInfoData ==
NULL) {
655 gSmmCorePrivate->PiSmmCoreImageBase,
656 gSmmCorePrivate->PiSmmCoreImageSize,
657 EFI_FV_FILETYPE_SMM_CORE
660 if (!IS_SMRAM_PROFILE_ENABLED) {
665 if (SmramProfileContext !=
NULL) {
669 mSmramProfileGettingStatus =
FALSE;
670 if ((
PcdGet8 (PcdMemoryProfilePropertyMask) & BIT7) != 0) {
671 mSmramProfileRecordingEnable = MEMORY_PROFILE_RECORDING_DISABLE;
673 mSmramProfileRecordingEnable = MEMORY_PROFILE_RECORDING_ENABLE;
676 mSmramProfileDriverPathSize =
PcdGetSize (PcdMemoryProfileDriverPath);
678 mSmramProfileContextPtr = &mSmramProfileContext;
682 DEBUG ((DEBUG_INFO,
"SmramProfileInit SmramProfileContext - 0x%x\n", &mSmramProfileContext));
697 if (!IS_SMRAM_PROFILE_ENABLED) {
704 &gEdkiiSmmMemoryProfileGuid,
728 if (FilePath !=
NULL) {
732 if (FileName !=
NULL) {
758 IN BOOLEAN RegisterToDxe
775 if (!IS_SMRAM_PROFILE_ENABLED) {
776 return EFI_UNSUPPORTED;
784 return EFI_UNSUPPORTED;
788 if (ContextData ==
NULL) {
789 return EFI_UNSUPPORTED;
801 if (DriverInfoData ==
NULL) {
802 return EFI_OUT_OF_RESOURCES;
822 IN PHYSICAL_ADDRESS Address
830 DriverInfoList = ContextData->DriverInfoList;
832 for (DriverLink = DriverInfoList->ForwardLink;
833 DriverLink != DriverInfoList;
834 DriverLink = DriverLink->ForwardLink)
836 DriverInfoData =
CR (
840 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
842 DriverInfo = &DriverInfoData->DriverInfo;
843 if ((
CompareGuid (&DriverInfo->FileName, FileName)) &&
844 (Address >= DriverInfo->ImageBase) &&
845 (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize)))
847 return DriverInfoData;
867 IN PHYSICAL_ADDRESS Address
875 DriverInfoList = ContextData->DriverInfoList;
877 for (DriverLink = DriverInfoList->ForwardLink;
878 DriverLink != DriverInfoList;
879 DriverLink = DriverLink->ForwardLink)
881 DriverInfoData =
CR (
885 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
887 DriverInfo = &DriverInfoData->DriverInfo;
888 if ((Address >= DriverInfo->ImageBase) &&
889 (Address < (DriverInfo->ImageBase + DriverInfo->ImageSize)))
891 return DriverInfoData;
913 IN BOOLEAN UnregisterFromDxe
920 PHYSICAL_ADDRESS ImageAddress;
921 VOID *EntryPointInImage;
925 if (UnregisterFromDxe) {
933 if (!IS_SMRAM_PROFILE_ENABLED) {
934 return EFI_UNSUPPORTED;
942 return EFI_UNSUPPORTED;
946 if (ContextData ==
NULL) {
947 return EFI_UNSUPPORTED;
950 DriverInfoData =
NULL;
963 if (FileName !=
NULL) {
967 if (DriverInfoData ==
NULL) {
971 if (DriverInfoData ==
NULL) {
972 return EFI_NOT_FOUND;
975 ContextData->Context.TotalImageSize -= DriverInfoData->DriverInfo.ImageSize;
979 DriverInfoData->DriverInfo.ImageSize = 0;
981 if (DriverInfoData->DriverInfo.PeakUsage == 0) {
982 ContextData->Context.ImageCount--;
1018 if ((
PcdGet64 (PcdMemoryProfileMemoryType) & TestBit) != 0) {
1058 UINTN NumberOfPages;
1061 FreePageList = &mSmmMemoryMap;
1062 for (Node = FreePageList->BackLink;
1063 Node != FreePageList;
1064 Node = Node->BackLink)
1067 NumberOfPages += Pages->NumberOfPages;
1070 mSmramFreeMemory.TotalFreeMemoryPages = NumberOfPages;
1072 if (NumberOfPages <= SMRAM_INFO_DUMP_PAGE_THRESHOLD) {
1095 IN PHYSICAL_ADDRESS CallerAddress,
1096 IN MEMORY_PROFILE_ACTION Action,
1100 IN CHAR8 *ActionString OPTIONAL
1111 MEMORY_PROFILE_ACTION BasicAction;
1112 UINTN ActionStringSize;
1113 UINTN ActionStringOccupiedSize;
1115 BasicAction = Action & MEMORY_PROFILE_ACTION_BASIC_MASK;
1118 if (ContextData ==
NULL) {
1119 return EFI_UNSUPPORTED;
1123 if (DriverInfoData ==
NULL) {
1124 return EFI_UNSUPPORTED;
1127 ActionStringSize = 0;
1128 ActionStringOccupiedSize = 0;
1129 if (ActionString !=
NULL) {
1131 ActionStringOccupiedSize = GET_OCCUPIED_SIZE (ActionStringSize,
sizeof (UINT64));
1137 AllocInfoData =
NULL;
1140 sizeof (*AllocInfoData) + ActionStringSize,
1141 (
VOID **)&AllocInfoData
1143 if (EFI_ERROR (Status)) {
1144 return EFI_OUT_OF_RESOURCES;
1147 ASSERT (AllocInfoData !=
NULL);
1152 if (Action == BasicAction) {
1153 ContextData->Context.SequenceCount++;
1156 AllocInfo = &AllocInfoData->AllocInfo;
1157 AllocInfoData->Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
1158 AllocInfo->Header.Signature = MEMORY_PROFILE_ALLOC_INFO_SIGNATURE;
1160 AllocInfo->Header.Revision = MEMORY_PROFILE_ALLOC_INFO_REVISION;
1161 AllocInfo->CallerAddress = CallerAddress;
1162 AllocInfo->SequenceId = ContextData->Context.SequenceCount;
1163 AllocInfo->Action = Action;
1164 AllocInfo->MemoryType = MemoryType;
1165 AllocInfo->Buffer = (PHYSICAL_ADDRESS)(
UINTN)Buffer;
1166 AllocInfo->Size = Size;
1167 if (ActionString !=
NULL) {
1169 AllocInfoData->ActionString = (CHAR8 *)(AllocInfoData + 1);
1170 CopyMem (AllocInfoData->ActionString, ActionString, ActionStringSize);
1172 AllocInfo->ActionStringOffset = 0;
1173 AllocInfoData->ActionString =
NULL;
1176 InsertTailList (DriverInfoData->AllocInfoList, &AllocInfoData->Link);
1178 Context = &ContextData->Context;
1179 DriverInfo = &DriverInfoData->DriverInfo;
1180 DriverInfo->AllocRecordCount++;
1185 if (Action == BasicAction) {
1188 DriverInfo->CurrentUsage += Size;
1189 if (DriverInfo->PeakUsage < DriverInfo->CurrentUsage) {
1190 DriverInfo->PeakUsage = DriverInfo->CurrentUsage;
1193 DriverInfo->CurrentUsageByType[ProfileMemoryIndex] += Size;
1194 if (DriverInfo->PeakUsageByType[ProfileMemoryIndex] < DriverInfo->CurrentUsageByType[ProfileMemoryIndex]) {
1195 DriverInfo->PeakUsageByType[ProfileMemoryIndex] = DriverInfo->CurrentUsageByType[ProfileMemoryIndex];
1198 Context->CurrentTotalUsage += Size;
1199 if (Context->PeakTotalUsage < Context->CurrentTotalUsage) {
1200 Context->PeakTotalUsage = Context->CurrentTotalUsage;
1203 Context->CurrentTotalUsageByType[ProfileMemoryIndex] += Size;
1204 if (Context->PeakTotalUsageByType[ProfileMemoryIndex] < Context->CurrentTotalUsageByType[ProfileMemoryIndex]) {
1205 Context->PeakTotalUsageByType[ProfileMemoryIndex] = Context->CurrentTotalUsageByType[ProfileMemoryIndex];
1227 IN MEMORY_PROFILE_ACTION BasicAction,
1237 AllocInfoList = DriverInfoData->AllocInfoList;
1239 for (AllocLink = AllocInfoList->ForwardLink;
1240 AllocLink != AllocInfoList;
1241 AllocLink = AllocLink->ForwardLink)
1243 AllocInfoData =
CR (
1247 MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
1249 AllocInfo = &AllocInfoData->AllocInfo;
1250 if ((AllocInfo->Action & MEMORY_PROFILE_ACTION_BASIC_MASK) != BasicAction) {
1254 switch (BasicAction) {
1255 case MemoryProfileActionAllocatePages:
1256 if ((AllocInfo->Buffer <= (PHYSICAL_ADDRESS)(
UINTN)Buffer) &&
1257 ((AllocInfo->Buffer + AllocInfo->Size) >= ((PHYSICAL_ADDRESS)(
UINTN)Buffer + Size)))
1259 return AllocInfoData;
1263 case MemoryProfileActionAllocatePool:
1264 if (AllocInfo->Buffer == (PHYSICAL_ADDRESS)(
UINTN)Buffer) {
1265 return AllocInfoData;
1293 IN PHYSICAL_ADDRESS CallerAddress,
1294 IN MEMORY_PROFILE_ACTION Action,
1309 MEMORY_PROFILE_ACTION BasicAction;
1312 BasicAction = Action & MEMORY_PROFILE_ACTION_BASIC_MASK;
1315 if (ContextData ==
NULL) {
1316 return EFI_UNSUPPORTED;
1331 AllocInfoData =
NULL;
1333 if (DriverInfoData !=
NULL) {
1334 switch (BasicAction) {
1335 case MemoryProfileActionFreePages:
1338 case MemoryProfileActionFreePool:
1343 AllocInfoData =
NULL;
1348 if (AllocInfoData ==
NULL) {
1352 DriverInfoList = ContextData->DriverInfoList;
1354 for (DriverLink = DriverInfoList->ForwardLink;
1355 DriverLink != DriverInfoList;
1356 DriverLink = DriverLink->ForwardLink)
1358 ThisDriverInfoData =
CR (
1362 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
1364 switch (BasicAction) {
1365 case MemoryProfileActionFreePages:
1368 case MemoryProfileActionFreePool:
1373 AllocInfoData =
NULL;
1377 if (AllocInfoData !=
NULL) {
1378 DriverInfoData = ThisDriverInfoData;
1383 if (AllocInfoData ==
NULL) {
1396 if ((DriverInfoData ==
NULL) || (AllocInfoData ==
NULL)) {
1397 ASSERT (DriverInfoData !=
NULL);
1398 ASSERT (AllocInfoData !=
NULL);
1399 return EFI_NOT_FOUND;
1404 Context = &ContextData->Context;
1405 DriverInfo = &DriverInfoData->DriverInfo;
1406 AllocInfo = &AllocInfoData->AllocInfo;
1408 DriverInfo->AllocRecordCount--;
1412 if (AllocInfo->Action == (AllocInfo->Action & MEMORY_PROFILE_ACTION_BASIC_MASK)) {
1415 Context->CurrentTotalUsage -= AllocInfo->Size;
1416 Context->CurrentTotalUsageByType[ProfileMemoryIndex] -= AllocInfo->Size;
1418 DriverInfo->CurrentUsage -= AllocInfo->Size;
1419 DriverInfo->CurrentUsageByType[ProfileMemoryIndex] -= AllocInfo->Size;
1424 if (BasicAction == MemoryProfileActionFreePages) {
1425 if (AllocInfo->Buffer != (PHYSICAL_ADDRESS)(
UINTN)Buffer) {
1427 AllocInfo->CallerAddress,
1429 AllocInfo->MemoryType,
1430 (
UINTN)((PHYSICAL_ADDRESS)(
UINTN)Buffer - AllocInfo->Buffer),
1432 AllocInfoData->ActionString
1436 if (AllocInfo->Buffer + AllocInfo->Size != ((PHYSICAL_ADDRESS)(
UINTN)Buffer + Size)) {
1438 AllocInfo->CallerAddress,
1440 AllocInfo->MemoryType,
1441 (
UINTN)((AllocInfo->Buffer + AllocInfo->Size) - ((PHYSICAL_ADDRESS)(
UINTN)Buffer + Size)),
1443 AllocInfoData->ActionString
1480 IN PHYSICAL_ADDRESS CallerAddress,
1481 IN MEMORY_PROFILE_ACTION Action,
1485 IN CHAR8 *ActionString OPTIONAL
1490 MEMORY_PROFILE_ACTION BasicAction;
1492 if (!IS_SMRAM_PROFILE_ENABLED) {
1493 return EFI_UNSUPPORTED;
1496 if (mSmramProfileGettingStatus) {
1497 return EFI_ACCESS_DENIED;
1500 if (!mSmramProfileRecordingEnable) {
1507 BasicAction = Action & MEMORY_PROFILE_ACTION_BASIC_MASK;
1512 if ((BasicAction == MemoryProfileActionAllocatePages) || (BasicAction == MemoryProfileActionAllocatePool)) {
1517 return EFI_UNSUPPORTED;
1522 if (ContextData ==
NULL) {
1523 return EFI_UNSUPPORTED;
1526 switch (BasicAction) {
1527 case MemoryProfileActionAllocatePages:
1530 case MemoryProfileActionFreePages:
1533 case MemoryProfileActionAllocatePool:
1536 case MemoryProfileActionFreePool:
1541 Status = EFI_UNSUPPORTED;
1557 if (!IS_SMRAM_PROFILE_ENABLED) {
1561 DEBUG ((DEBUG_INFO,
"SmramProfileReadyToLock\n"));
1562 mSmramReadyToLock =
TRUE;
1590 UINTN PoolListIndex;
1592 UINTN SmmPoolTypeIndex;
1595 if (ContextData ==
NULL) {
1601 DriverInfoList = ContextData->DriverInfoList;
1602 for (DriverLink = DriverInfoList->ForwardLink;
1603 DriverLink != DriverInfoList;
1604 DriverLink = DriverLink->ForwardLink)
1606 DriverInfoData =
CR (
1610 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
1612 TotalSize += DriverInfoData->DriverInfo.Header.Length;
1614 AllocInfoList = DriverInfoData->AllocInfoList;
1615 for (AllocLink = AllocInfoList->ForwardLink;
1616 AllocLink != AllocInfoList;
1617 AllocLink = AllocLink->ForwardLink)
1619 AllocInfoData =
CR (
1623 MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
1625 TotalSize += AllocInfoData->AllocInfo.Header.Length;
1630 FreePageList = &mSmmMemoryMap;
1631 for (Node = FreePageList->BackLink;
1632 Node != FreePageList;
1633 Node = Node->BackLink)
1638 for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {
1639 for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {
1640 FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][PoolListIndex];
1641 for (Node = FreePoolList->BackLink;
1642 Node != FreePoolList;
1643 Node = Node->BackLink)
1646 if (Pool->Header.Available) {
1672 IN OUT UINT64 *ProfileSize,
1673 IN OUT UINT64 *ProfileOffset
1691 UINTN PoolListIndex;
1697 UINT64 RemainingSize;
1699 UINTN ActionStringSize;
1700 UINTN SmmPoolTypeIndex;
1703 if (ContextData ==
NULL) {
1707 RemainingSize = *ProfileSize;
1712 Context = ProfileBuffer;
1723 DriverInfoList = ContextData->DriverInfoList;
1724 for (DriverLink = DriverInfoList->ForwardLink;
1725 DriverLink != DriverInfoList;
1726 DriverLink = DriverLink->ForwardLink)
1728 DriverInfoData =
CR (
1732 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
1734 if (*ProfileOffset < (Offset + DriverInfoData->DriverInfo.Header.Length)) {
1735 if (RemainingSize >= DriverInfoData->DriverInfo.Header.Length) {
1736 DriverInfo = ProfileBuffer;
1738 if (DriverInfo->PdbStringOffset != 0) {
1740 CopyMem ((
VOID *)((
UINTN)DriverInfo + DriverInfo->PdbStringOffset), DriverInfoData->PdbString, PdbSize);
1743 RemainingSize -= DriverInfo->Header.Length;
1744 ProfileBuffer = (UINT8 *)ProfileBuffer + DriverInfo->Header.Length;
1750 Offset += DriverInfoData->DriverInfo.Header.Length;
1752 AllocInfoList = DriverInfoData->AllocInfoList;
1753 for (AllocLink = AllocInfoList->ForwardLink;
1754 AllocLink != AllocInfoList;
1755 AllocLink = AllocLink->ForwardLink)
1757 AllocInfoData =
CR (
1761 MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
1763 if (*ProfileOffset < (Offset + AllocInfoData->AllocInfo.Header.Length)) {
1764 if (RemainingSize >= AllocInfoData->AllocInfo.Header.Length) {
1765 AllocInfo = ProfileBuffer;
1767 if (AllocInfo->ActionStringOffset) {
1768 ActionStringSize =
AsciiStrSize (AllocInfoData->ActionString);
1769 CopyMem ((
VOID *)((
UINTN)AllocInfo + AllocInfo->ActionStringOffset), AllocInfoData->ActionString, ActionStringSize);
1772 RemainingSize -= AllocInfo->Header.Length;
1773 ProfileBuffer = (UINT8 *)ProfileBuffer + AllocInfo->Header.Length;
1779 Offset += AllocInfoData->AllocInfo.Header.Length;
1788 FreePageList = &mSmmMemoryMap;
1789 for (Node = FreePageList->BackLink;
1790 Node != FreePageList;
1791 Node = Node->BackLink)
1796 for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {
1797 for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {
1798 FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][MAX_POOL_INDEX - PoolListIndex - 1];
1799 for (Node = FreePoolList->BackLink;
1800 Node != FreePoolList;
1801 Node = Node->BackLink)
1804 if (Pool->Header.Available) {
1812 FreeMemory->FreeMemoryEntryCount = (UINT32)Index;
1822 FreePageList = &mSmmMemoryMap;
1823 for (Node = FreePageList->BackLink;
1824 Node != FreePageList;
1825 Node = Node->BackLink)
1830 MemoryProfileDescriptor = ProfileBuffer;
1831 MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;
1833 MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
1834 MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS)(
UINTN)Pages;
1847 for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {
1848 for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {
1849 FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][MAX_POOL_INDEX - PoolListIndex - 1];
1850 for (Node = FreePoolList->BackLink;
1851 Node != FreePoolList;
1852 Node = Node->BackLink)
1855 if (Pool->Header.Available) {
1858 MemoryProfileDescriptor = ProfileBuffer;
1859 MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;
1861 MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
1862 MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS)(
UINTN)Pool;
1863 MemoryProfileDescriptor->Size = Pool->Header.Size;
1880 MemoryRange = ProfileBuffer;
1881 MemoryRange->Header.Signature = MEMORY_PROFILE_MEMORY_RANGE_SIGNATURE;
1883 MemoryRange->Header.Revision = MEMORY_PROFILE_MEMORY_RANGE_REVISION;
1884 MemoryRange->MemoryRangeCount = (UINT32)mFullSmramRangeCount;
1894 for (Index = 0; Index < mFullSmramRangeCount; Index++) {
1897 MemoryProfileDescriptor = ProfileBuffer;
1898 MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;
1900 MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
1901 MemoryProfileDescriptor->Address = mFullSmramRanges[Index].
PhysicalStart;
1902 MemoryProfileDescriptor->Size = mFullSmramRanges[Index].
PhysicalSize;
1918 *ProfileSize -= RemainingSize;
1922 *ProfileOffset = Offset;
1943 IN OUT UINT64 *ProfileSize,
1950 BOOLEAN SmramProfileGettingStatus;
1953 if (ContextData ==
NULL) {
1954 return EFI_UNSUPPORTED;
1957 SmramProfileGettingStatus = mSmramProfileGettingStatus;
1958 mSmramProfileGettingStatus =
TRUE;
1962 if (*ProfileSize < Size) {
1963 *ProfileSize = Size;
1964 mSmramProfileGettingStatus = SmramProfileGettingStatus;
1965 return EFI_BUFFER_TOO_SMALL;
1970 *ProfileSize = Size;
1972 mSmramProfileGettingStatus = SmramProfileGettingStatus;
1996 IN PHYSICAL_ADDRESS ImageBase,
1997 IN UINT64 ImageSize,
1998 IN EFI_FV_FILETYPE FileType
2003 VOID *EntryPointInImage;
2040 IN PHYSICAL_ADDRESS ImageBase,
2046 VOID *EntryPointInImage;
2079 OUT BOOLEAN *RecordingState
2085 if (ContextData ==
NULL) {
2086 return EFI_UNSUPPORTED;
2089 if (RecordingState ==
NULL) {
2090 return EFI_INVALID_PARAMETER;
2093 *RecordingState = mSmramProfileRecordingEnable;
2111 IN BOOLEAN RecordingState
2117 if (ContextData ==
NULL) {
2118 return EFI_UNSUPPORTED;
2121 mSmramProfileRecordingEnable = RecordingState;
2152 IN PHYSICAL_ADDRESS CallerAddress,
2153 IN MEMORY_PROFILE_ACTION Action,
2157 IN CHAR8 *ActionString OPTIONAL
2175 BOOLEAN SmramProfileGettingStatus;
2178 if (ContextData ==
NULL) {
2182 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2183 mSmramProfileGettingStatus =
TRUE;
2186 SmramProfileParameterGetInfo->Header.ReturnStatus = 0;
2188 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2203 UINT64 ProfileOffset;
2206 BOOLEAN SmramProfileGettingStatus;
2209 if (ContextData ==
NULL) {
2213 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2214 mSmramProfileGettingStatus =
TRUE;
2216 CopyMem (&SmramProfileGetData, SmramProfileParameterGetData,
sizeof (SmramProfileGetData));
2224 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetData: SMM ProfileBuffer in SMRAM or overflow!\n"));
2225 SmramProfileParameterGetData->ProfileSize = ProfileSize;
2226 SmramProfileParameterGetData->Header.ReturnStatus = (UINT64)(INT64)(
INTN)EFI_ACCESS_DENIED;
2230 if (SmramProfileGetData.ProfileSize < ProfileSize) {
2231 SmramProfileParameterGetData->ProfileSize = ProfileSize;
2232 SmramProfileParameterGetData->Header.ReturnStatus = (UINT64)(INT64)(
INTN)EFI_BUFFER_TOO_SMALL;
2238 SmramProfileParameterGetData->ProfileSize = ProfileSize;
2239 SmramProfileParameterGetData->Header.ReturnStatus = 0;
2242 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2258 BOOLEAN SmramProfileGettingStatus;
2261 if (ContextData ==
NULL) {
2265 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2266 mSmramProfileGettingStatus =
TRUE;
2268 CopyMem (&SmramProfileGetDataByOffset, SmramProfileParameterGetDataByOffset,
sizeof (SmramProfileGetDataByOffset));
2274 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetDataByOffset: SMM ProfileBuffer in SMRAM or overflow!\n"));
2275 SmramProfileParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(
INTN)EFI_ACCESS_DENIED;
2279 SmramProfileCopyData ((
VOID *)(
UINTN)SmramProfileGetDataByOffset.ProfileBuffer, &SmramProfileGetDataByOffset.ProfileSize, &SmramProfileGetDataByOffset.ProfileOffset);
2280 CopyMem (SmramProfileParameterGetDataByOffset, &SmramProfileGetDataByOffset,
sizeof (SmramProfileGetDataByOffset));
2281 SmramProfileParameterGetDataByOffset->Header.ReturnStatus = 0;
2284 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2313 UINTN TempCommBufferSize;
2316 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler Enter\n"));
2321 if ((CommBuffer ==
NULL) || (CommBufferSize ==
NULL)) {
2325 TempCommBufferSize = *CommBufferSize;
2328 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2333 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer in SMRAM or overflow!\n"));
2339 SmramProfileParameterHeader->ReturnStatus = (UINT64)-1;
2342 SmramProfileParameterHeader->ReturnStatus = (UINT64)(INT64)(
INTN)EFI_UNSUPPORTED;
2346 switch (SmramProfileParameterHeader->Command) {
2347 case SMRAM_PROFILE_COMMAND_GET_PROFILE_INFO:
2348 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetInfo\n"));
2350 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2356 case SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA:
2357 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetData\n"));
2359 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2365 case SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA_BY_OFFSET:
2366 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetDataByOffset\n"));
2368 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2374 case SMRAM_PROFILE_COMMAND_GET_RECORDING_STATE:
2375 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetRecordingState\n"));
2377 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2382 ParameterRecordingState->RecordingState = mSmramProfileRecordingEnable;
2383 ParameterRecordingState->Header.ReturnStatus = 0;
2385 case SMRAM_PROFILE_COMMAND_SET_RECORDING_STATE:
2386 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerSetRecordingState\n"));
2388 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2393 mSmramProfileRecordingEnable = ParameterRecordingState->RecordingState;
2394 ParameterRecordingState->Header.ReturnStatus = 0;
2400 case SMRAM_PROFILE_COMMAND_DEPRECATED1:
2401 case SMRAM_PROFILE_COMMAND_DEPRECATED2:
2410 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler Exit\n"));
2427 if (!IS_SMRAM_PROFILE_ENABLED) {
2433 &gEdkiiMemoryProfileGuid,
2452 BOOLEAN SmramProfileGettingStatus;
2455 if (ContextData ==
NULL) {
2459 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2460 mSmramProfileGettingStatus =
TRUE;
2462 DEBUG ((DEBUG_INFO,
"FullSmramRange address - 0x%08x\n", mFullSmramRanges));
2464 DEBUG ((DEBUG_INFO,
"======= SmramProfile begin =======\n"));
2466 DEBUG ((DEBUG_INFO,
"FullSmramRange:\n"));
2467 for (Index = 0; Index < mFullSmramRangeCount; Index++) {
2468 DEBUG ((DEBUG_INFO,
" FullSmramRange (0x%x)\n", Index));
2469 DEBUG ((DEBUG_INFO,
" PhysicalStart - 0x%016lx\n", mFullSmramRanges[Index].PhysicalStart));
2470 DEBUG ((DEBUG_INFO,
" CpuStart - 0x%016lx\n", mFullSmramRanges[Index].CpuStart));
2471 DEBUG ((DEBUG_INFO,
" PhysicalSize - 0x%016lx\n", mFullSmramRanges[Index].PhysicalSize));
2472 DEBUG ((DEBUG_INFO,
" RegionState - 0x%016lx\n", mFullSmramRanges[Index].RegionState));
2475 DEBUG ((DEBUG_INFO,
"======= SmramProfile end =======\n"));
2477 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2494 BOOLEAN SmramProfileGettingStatus;
2497 if (ContextData ==
NULL) {
2501 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2502 mSmramProfileGettingStatus =
TRUE;
2504 DEBUG ((DEBUG_INFO,
"======= SmramProfile begin =======\n"));
2506 DEBUG ((DEBUG_INFO,
"FreePagesList:\n"));
2507 FreePageList = &mSmmMemoryMap;
2508 for (Node = FreePageList->BackLink, Index = 0;
2509 Node != FreePageList;
2510 Node = Node->BackLink, Index++)
2513 DEBUG ((DEBUG_INFO,
" Index - 0x%x\n", Index));
2514 DEBUG ((DEBUG_INFO,
" PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS)(
UINTN)Pages));
2515 DEBUG ((DEBUG_INFO,
" NumberOfPages - 0x%08x\n", Pages->NumberOfPages));
2518 DEBUG ((DEBUG_INFO,
"======= SmramProfile end =======\n"));
2520 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2536 UINTN PoolListIndex;
2538 BOOLEAN SmramProfileGettingStatus;
2539 UINTN SmmPoolTypeIndex;
2542 if (ContextData ==
NULL) {
2546 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2547 mSmramProfileGettingStatus =
TRUE;
2549 DEBUG ((DEBUG_INFO,
"======= SmramProfile begin =======\n"));
2551 for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {
2552 for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {
2553 DEBUG ((DEBUG_INFO,
"FreePoolList(%d)(%d):\n", SmmPoolTypeIndex, PoolListIndex));
2554 FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][PoolListIndex];
2555 for (Node = FreePoolList->BackLink, Index = 0;
2556 Node != FreePoolList;
2557 Node = Node->BackLink, Index++)
2560 DEBUG ((DEBUG_INFO,
" Index - 0x%x\n", Index));
2561 DEBUG ((DEBUG_INFO,
" PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS)(
UINTN)Pool));
2562 DEBUG ((DEBUG_INFO,
" Size - 0x%08x\n", Pool->Header.Size));
2563 DEBUG ((DEBUG_INFO,
" Available - 0x%02x\n", Pool->Header.Available));
2568 DEBUG ((DEBUG_INFO,
"======= SmramProfile end =======\n"));
2570 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2575 "gSmst->SmmAllocatePages",
2576 "gSmst->SmmFreePages",
2577 "gSmst->SmmAllocatePool",
2578 "gSmst->SmmFreePool",
2582 MEMORY_PROFILE_ACTION Action;
2587 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES,
"Lib:AllocatePages" },
2588 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES,
"Lib:AllocateRuntimePages" },
2589 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_PAGES,
"Lib:AllocateReservedPages" },
2590 { MEMORY_PROFILE_ACTION_LIB_FREE_PAGES,
"Lib:FreePages" },
2591 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_PAGES,
"Lib:AllocateAlignedPages" },
2592 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RUNTIME_PAGES,
"Lib:AllocateAlignedRuntimePages" },
2593 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RESERVED_PAGES,
"Lib:AllocateAlignedReservedPages" },
2594 { MEMORY_PROFILE_ACTION_LIB_FREE_ALIGNED_PAGES,
"Lib:FreeAlignedPages" },
2595 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_POOL,
"Lib:AllocatePool" },
2596 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_POOL,
"Lib:AllocateRuntimePool" },
2597 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_POOL,
"Lib:AllocateReservedPool" },
2598 { MEMORY_PROFILE_ACTION_LIB_FREE_POOL,
"Lib:FreePool" },
2599 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ZERO_POOL,
"Lib:AllocateZeroPool" },
2600 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_ZERO_POOL,
"Lib:AllocateRuntimeZeroPool" },
2601 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_ZERO_POOL,
"Lib:AllocateReservedZeroPool" },
2602 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_COPY_POOL,
"Lib:AllocateCopyPool" },
2603 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_COPY_POOL,
"Lib:AllocateRuntimeCopyPool" },
2604 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_COPY_POOL,
"Lib:AllocateReservedCopyPool" },
2605 { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_POOL,
"Lib:ReallocatePool" },
2606 { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RUNTIME_POOL,
"Lib:ReallocateRuntimePool" },
2607 { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL,
"Lib:ReallocateReservedPool" },
2612 CHAR8 *MemoryTypeStr;
2635 for (Index = 0; Index <
ARRAY_SIZE (mMemoryTypeString); Index++) {
2636 if (mMemoryTypeString[Index].MemoryType == MemoryType) {
2637 return mMemoryTypeString[Index].MemoryTypeStr;
2641 return "UnexpectedMemoryType";
2654 IN MEMORY_PROFILE_ACTION Action
2658 UINTN ActionStringCount;
2659 CHAR8 **ActionString;
2661 ActionString = mSmmActionString;
2662 ActionStringCount =
ARRAY_SIZE (mSmmActionString);
2664 if ((
UINTN)(UINT32)Action < ActionStringCount) {
2665 return ActionString[Action];
2668 for (Index = 0; Index <
ARRAY_SIZE (mExtActionString); Index++) {
2669 if (mExtActionString[Index].Action == Action) {
2670 return mExtActionString[Index].String;
2674 return ActionString[0];
2698 BOOLEAN SmramProfileGettingStatus;
2702 if (ContextData ==
NULL) {
2706 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2707 mSmramProfileGettingStatus =
TRUE;
2709 Context = &ContextData->Context;
2710 DEBUG ((DEBUG_INFO,
"======= SmramProfile begin =======\n"));
2711 DEBUG ((DEBUG_INFO,
"MEMORY_PROFILE_CONTEXT\n"));
2713 DEBUG ((DEBUG_INFO,
" CurrentTotalUsage - 0x%016lx\n", Context->CurrentTotalUsage));
2714 DEBUG ((DEBUG_INFO,
" PeakTotalUsage - 0x%016lx\n", Context->PeakTotalUsage));
2715 for (TypeIndex = 0; TypeIndex <
sizeof (Context->CurrentTotalUsageByType) /
sizeof (Context->CurrentTotalUsageByType[0]); TypeIndex++) {
2716 if ((Context->CurrentTotalUsageByType[TypeIndex] != 0) ||
2717 (Context->PeakTotalUsageByType[TypeIndex] != 0))
2719 DEBUG ((DEBUG_INFO,
" CurrentTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->CurrentTotalUsageByType[TypeIndex],
ProfileMemoryTypeToStr (TypeIndex)));
2720 DEBUG ((DEBUG_INFO,
" PeakTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->PeakTotalUsageByType[TypeIndex],
ProfileMemoryTypeToStr (TypeIndex)));
2724 DEBUG ((DEBUG_INFO,
" TotalImageSize - 0x%016lx\n", Context->TotalImageSize));
2725 DEBUG ((DEBUG_INFO,
" ImageCount - 0x%08x\n", Context->ImageCount));
2726 DEBUG ((DEBUG_INFO,
" SequenceCount - 0x%08x\n", Context->SequenceCount));
2728 SmramDriverInfoList = ContextData->DriverInfoList;
2729 for (DriverLink = SmramDriverInfoList->ForwardLink, DriverIndex = 0;
2730 DriverLink != SmramDriverInfoList;
2731 DriverLink = DriverLink->ForwardLink, DriverIndex++)
2733 DriverInfoData =
CR (
2737 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
2739 DriverInfo = &DriverInfoData->DriverInfo;
2740 DEBUG ((DEBUG_INFO,
" MEMORY_PROFILE_DRIVER_INFO (0x%x)\n", DriverIndex));
2741 DEBUG ((DEBUG_INFO,
" FileName - %g\n", &DriverInfo->FileName));
2742 DEBUG ((DEBUG_INFO,
" ImageBase - 0x%016lx\n", DriverInfo->ImageBase));
2743 DEBUG ((DEBUG_INFO,
" ImageSize - 0x%016lx\n", DriverInfo->ImageSize));
2744 DEBUG ((DEBUG_INFO,
" EntryPoint - 0x%016lx\n", DriverInfo->EntryPoint));
2745 DEBUG ((DEBUG_INFO,
" ImageSubsystem - 0x%04x\n", DriverInfo->ImageSubsystem));
2746 DEBUG ((DEBUG_INFO,
" FileType - 0x%02x\n", DriverInfo->FileType));
2747 DEBUG ((DEBUG_INFO,
" CurrentUsage - 0x%016lx\n", DriverInfo->CurrentUsage));
2748 DEBUG ((DEBUG_INFO,
" PeakUsage - 0x%016lx\n", DriverInfo->PeakUsage));
2749 for (TypeIndex = 0; TypeIndex <
sizeof (DriverInfo->CurrentUsageByType) /
sizeof (DriverInfo->CurrentUsageByType[0]); TypeIndex++) {
2750 if ((DriverInfo->CurrentUsageByType[TypeIndex] != 0) ||
2751 (DriverInfo->PeakUsageByType[TypeIndex] != 0))
2753 DEBUG ((DEBUG_INFO,
" CurrentUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->CurrentUsageByType[TypeIndex],
ProfileMemoryTypeToStr (TypeIndex)));
2754 DEBUG ((DEBUG_INFO,
" PeakUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->PeakUsageByType[TypeIndex],
ProfileMemoryTypeToStr (TypeIndex)));
2758 DEBUG ((DEBUG_INFO,
" AllocRecordCount - 0x%08x\n", DriverInfo->AllocRecordCount));
2760 AllocInfoList = DriverInfoData->AllocInfoList;
2761 for (AllocLink = AllocInfoList->ForwardLink, AllocIndex = 0;
2762 AllocLink != AllocInfoList;
2763 AllocLink = AllocLink->ForwardLink, AllocIndex++)
2765 AllocInfoData =
CR (
2769 MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
2771 AllocInfo = &AllocInfoData->AllocInfo;
2772 DEBUG ((DEBUG_INFO,
" MEMORY_PROFILE_ALLOC_INFO (0x%x)\n", AllocIndex));
2773 DEBUG ((DEBUG_INFO,
" CallerAddress - 0x%016lx (Offset: 0x%08x)\n", AllocInfo->CallerAddress, AllocInfo->CallerAddress - DriverInfo->ImageBase));
2774 DEBUG ((DEBUG_INFO,
" SequenceId - 0x%08x\n", AllocInfo->SequenceId));
2775 if ((AllocInfo->Action & MEMORY_PROFILE_ACTION_USER_DEFINED_MASK) != 0) {
2776 if (AllocInfoData->ActionString !=
NULL) {
2777 DEBUG ((DEBUG_INFO,
" Action - 0x%08x (%a)\n", AllocInfo->Action, AllocInfoData->ActionString));
2779 DEBUG ((DEBUG_INFO,
" Action - 0x%08x (UserDefined-0x%08x)\n", AllocInfo->Action, AllocInfo->Action));
2786 DEBUG ((DEBUG_INFO,
" Buffer - 0x%016lx\n", AllocInfo->Buffer));
2787 DEBUG ((DEBUG_INFO,
" Size - 0x%016lx\n", AllocInfo->Size));
2791 DEBUG ((DEBUG_INFO,
"======= SmramProfile end =======\n"));
2793 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2806 if (IS_SMRAM_PROFILE_ENABLED) {
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
UINTN EFIAPI DevicePathNodeLength(IN CONST VOID *Node)
UINT8 EFIAPI DevicePathSubType(IN CONST VOID *Node)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI NextDevicePathNode(IN CONST VOID *Node)
BOOLEAN EFIAPI IsDevicePathValid(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINTN MaxSize)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
BOOLEAN EFIAPI IsDevicePathEndType(IN CONST VOID *Node)
VOID EFIAPI SetDevicePathEndNode(OUT VOID *Node)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_STATUS EFIAPI SmmInstallProtocolInterface(IN OUT EFI_HANDLE *UserHandle, IN EFI_GUID *Protocol, IN EFI_INTERFACE_TYPE InterfaceType, IN VOID *Interface)
#define RETURN_UNSUPPORTED
#define ARRAY_SIZE(Array)
#define GLOBAL_REMOVE_IF_UNREFERENCED
#define BASE_CR(Record, TYPE, Field)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG_CODE_BEGIN()
#define DEBUG(Expression)
#define CR(Record, TYPE, Field, TestSignature)
#define PcdGetSize(TokenName)
#define PcdGet64(TokenName)
#define PcdGet8(TokenName)
#define PcdGetPtr(TokenName)
#define EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC
#define EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC
EFI_STATUS EFIAPI SmmInternalFreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI SmmInternalAllocatePool(IN EFI_MEMORY_TYPE PoolType, IN UINTN Size, OUT VOID **Buffer)
EFI_STATUS EFIAPI SmiHandlerRegister(IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler, IN CONST EFI_GUID *HandlerType OPTIONAL, OUT EFI_HANDLE *DispatchHandle)
BOOLEAN EFIAPI SmmIsBufferOutsideSmmValid(IN EFI_PHYSICAL_ADDRESS Buffer, IN UINT64 Length)
BOOLEAN RegisterSmmCore(IN MEMORY_PROFILE_CONTEXT_DATA *ContextData)
VOID SmramProfileReadyToLock(VOID)
EFI_GUID * GetFileNameFromFilePath(IN EFI_DEVICE_PATH_PROTOCOL *FilePath)
CHAR8 * ProfileActionToStr(IN MEMORY_PROFILE_ACTION Action)
EFI_MEMORY_TYPE GetProfileMemoryIndex(IN EFI_MEMORY_TYPE MemoryType)
CHAR8 * ProfileMemoryTypeToStr(IN EFI_MEMORY_TYPE MemoryType)
VOID SmramProfileInstallProtocol(VOID)
VOID RegisterImageToDxe(IN EFI_GUID *FileName, IN PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize, IN EFI_FV_FILETYPE FileType)
EFI_STATUS EFIAPI SmramProfileProtocolGetData(IN EDKII_SMM_MEMORY_PROFILE_PROTOCOL *This, IN OUT UINT64 *ProfileSize, OUT VOID *ProfileBuffer)
UINT16 InternalPeCoffGetSubsystem(IN VOID *Pe32Data)
MEMORY_PROFILE_ALLOC_INFO_DATA * GetMemoryProfileAllocInfoFromAddress(IN MEMORY_PROFILE_DRIVER_INFO_DATA *DriverInfoData, IN MEMORY_PROFILE_ACTION BasicAction, IN UINTN Size, IN VOID *Buffer)
BOOLEAN SmmCoreNeedRecordProfile(IN EFI_MEMORY_TYPE MemoryType)
EFI_STATUS SmmCoreUpdateProfileFree(IN PHYSICAL_ADDRESS CallerAddress, IN MEMORY_PROFILE_ACTION Action, IN UINTN Size, IN VOID *Buffer)
VOID DumpFreePoolList(VOID)
VOID DumpSmramRange(VOID)
VOID RegisterSmramProfileHandler(VOID)
VOID SmramProfileHandlerGetData(IN SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA *SmramProfileParameterGetData)
EFI_STATUS EFIAPI SmramProfileProtocolRecord(IN EDKII_SMM_MEMORY_PROFILE_PROTOCOL *This, IN PHYSICAL_ADDRESS CallerAddress, IN MEMORY_PROFILE_ACTION Action, IN EFI_MEMORY_TYPE MemoryType, IN VOID *Buffer, IN UINTN Size, IN CHAR8 *ActionString OPTIONAL)
VOID UnregisterImageFromDxe(IN EFI_GUID *FileName, IN PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize)
MEMORY_PROFILE_DRIVER_INFO_DATA * GetMemoryProfileDriverInfoFromAddress(IN MEMORY_PROFILE_CONTEXT_DATA *ContextData, IN PHYSICAL_ADDRESS Address)
MEMORY_PROFILE_DRIVER_INFO_DATA * GetMemoryProfileDriverInfoByFileNameAndAddress(IN MEMORY_PROFILE_CONTEXT_DATA *ContextData, IN EFI_GUID *FileName, IN PHYSICAL_ADDRESS Address)
EFI_STATUS UnregisterSmramProfileImage(IN EFI_SMM_DRIVER_ENTRY *DriverEntry, IN BOOLEAN UnregisterFromDxe)
EFI_STATUS EFIAPI SmramProfileProtocolUnregisterImage(IN EDKII_SMM_MEMORY_PROFILE_PROTOCOL *This, IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize)
UINTN SmramProfileGetDataSize(VOID)
VOID DumpFreePagesList(VOID)
VOID SmramProfileInit(VOID)
VOID SmramProfileHandlerGetDataByOffset(IN SMRAM_PROFILE_PARAMETER_GET_PROFILE_DATA_BY_OFFSET *SmramProfileParameterGetDataByOffset)
VOID DumpSmramProfile(VOID)
BOOLEAN NeedRecordThisDriver(IN EFI_DEVICE_PATH_PROTOCOL *DriverFilePath)
VOID SmramProfileUpdateFreePages(IN MEMORY_PROFILE_CONTEXT_DATA *ContextData)
EFI_STATUS EFIAPI SmramProfileHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context OPTIONAL, IN OUT VOID *CommBuffer OPTIONAL, IN OUT UINTN *CommBufferSize OPTIONAL)
MEMORY_PROFILE_DRIVER_INFO_DATA * BuildDriverInfo(IN MEMORY_PROFILE_CONTEXT_DATA *ContextData, IN EFI_GUID *FileName, IN PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize, IN PHYSICAL_ADDRESS EntryPoint, IN UINT16 ImageSubsystem, IN EFI_FV_FILETYPE FileType)
EFI_STATUS EFIAPI SmramProfileProtocolRegisterImage(IN EDKII_SMM_MEMORY_PROFILE_PROTOCOL *This, IN EFI_DEVICE_PATH_PROTOCOL *FilePath, IN PHYSICAL_ADDRESS ImageBase, IN UINT64 ImageSize, IN EFI_FV_FILETYPE FileType)
EFI_STATUS EFIAPI SmmCoreUpdateProfile(IN PHYSICAL_ADDRESS CallerAddress, IN MEMORY_PROFILE_ACTION Action, IN EFI_MEMORY_TYPE MemoryType, IN UINTN Size, IN VOID *Buffer, IN CHAR8 *ActionString OPTIONAL)
EFI_STATUS EFIAPI SmramProfileProtocolGetRecordingState(IN EDKII_SMM_MEMORY_PROFILE_PROTOCOL *This, OUT BOOLEAN *RecordingState)
MEMORY_PROFILE_CONTEXT_DATA * GetSmramProfileContext(VOID)
RETURN_STATUS InternalPeCoffGetEntryPoint(IN VOID *Pe32Data, OUT VOID **EntryPoint)
VOID SmramProfileCopyData(OUT VOID *ProfileBuffer, IN OUT UINT64 *ProfileSize, IN OUT UINT64 *ProfileOffset)
EFI_STATUS SmmCoreUpdateProfileAllocate(IN PHYSICAL_ADDRESS CallerAddress, IN MEMORY_PROFILE_ACTION Action, IN EFI_MEMORY_TYPE MemoryType, IN UINTN Size, IN VOID *Buffer, IN CHAR8 *ActionString OPTIONAL)
EFI_STATUS EFIAPI SmramProfileProtocolSetRecordingState(IN EDKII_SMM_MEMORY_PROFILE_PROTOCOL *This, IN BOOLEAN RecordingState)
VOID SmramProfileHandlerGetInfo(IN SMRAM_PROFILE_PARAMETER_GET_PROFILE_INFO *SmramProfileParameterGetInfo)
EFI_STATUS RegisterSmramProfileImage(IN EFI_SMM_DRIVER_ENTRY *DriverEntry, IN BOOLEAN RegisterToDxe)
EFI_STATUS EFIAPI DriverEntry(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)
VOID EFIAPI EfiInitializeFwVolDevicepathNode(IN OUT MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode, IN CONST EFI_GUID *NameGuid)
EFI_GUID *EFIAPI EfiGetNameGuidFromFwVolDevicePathNode(IN CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvDevicePathNode)
UINT32 e_lfanew
File address of new exe header.
UINT16 e_magic
Magic number.
EFI_PHYSICAL_ADDRESS PhysicalStart
UINT32 AddressOfEntryPoint
Offset to entry point – from original optional header.
UINT16 Signature
The signature for TE format = "VZ".
UINT8 Subsystem
From original optional header.
UINT16 StrippedSize
Number of bytes we removed from the header.