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,
108 OUT VOID *ProfileBuffer
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;
319 OUT VOID **EntryPoint
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 ASSERT (DriverInfoData !=
NULL);
1397 ASSERT (AllocInfoData !=
NULL);
1401 Context = &ContextData->Context;
1402 DriverInfo = &DriverInfoData->DriverInfo;
1403 AllocInfo = &AllocInfoData->AllocInfo;
1405 DriverInfo->AllocRecordCount--;
1409 if (AllocInfo->Action == (AllocInfo->Action & MEMORY_PROFILE_ACTION_BASIC_MASK)) {
1412 Context->CurrentTotalUsage -= AllocInfo->Size;
1413 Context->CurrentTotalUsageByType[ProfileMemoryIndex] -= AllocInfo->Size;
1415 DriverInfo->CurrentUsage -= AllocInfo->Size;
1416 DriverInfo->CurrentUsageByType[ProfileMemoryIndex] -= AllocInfo->Size;
1421 if (BasicAction == MemoryProfileActionFreePages) {
1422 if (AllocInfo->Buffer != (PHYSICAL_ADDRESS)(
UINTN)Buffer) {
1424 AllocInfo->CallerAddress,
1426 AllocInfo->MemoryType,
1427 (
UINTN)((PHYSICAL_ADDRESS)(
UINTN)Buffer - AllocInfo->Buffer),
1428 (VOID *)(
UINTN)AllocInfo->Buffer,
1429 AllocInfoData->ActionString
1433 if (AllocInfo->Buffer + AllocInfo->Size != ((PHYSICAL_ADDRESS)(
UINTN)Buffer + Size)) {
1435 AllocInfo->CallerAddress,
1437 AllocInfo->MemoryType,
1438 (
UINTN)((AllocInfo->Buffer + AllocInfo->Size) - ((PHYSICAL_ADDRESS)(
UINTN)Buffer + Size)),
1439 (VOID *)((
UINTN)Buffer + Size),
1440 AllocInfoData->ActionString
1477 IN PHYSICAL_ADDRESS CallerAddress,
1478 IN MEMORY_PROFILE_ACTION Action,
1482 IN CHAR8 *ActionString OPTIONAL
1487 MEMORY_PROFILE_ACTION BasicAction;
1489 if (!IS_SMRAM_PROFILE_ENABLED) {
1490 return EFI_UNSUPPORTED;
1493 if (mSmramProfileGettingStatus) {
1494 return EFI_ACCESS_DENIED;
1497 if (!mSmramProfileRecordingEnable) {
1504 BasicAction = Action & MEMORY_PROFILE_ACTION_BASIC_MASK;
1509 if ((BasicAction == MemoryProfileActionAllocatePages) || (BasicAction == MemoryProfileActionAllocatePool)) {
1514 return EFI_UNSUPPORTED;
1519 if (ContextData ==
NULL) {
1520 return EFI_UNSUPPORTED;
1523 switch (BasicAction) {
1524 case MemoryProfileActionAllocatePages:
1527 case MemoryProfileActionFreePages:
1530 case MemoryProfileActionAllocatePool:
1533 case MemoryProfileActionFreePool:
1538 Status = EFI_UNSUPPORTED;
1554 if (!IS_SMRAM_PROFILE_ENABLED) {
1558 DEBUG ((DEBUG_INFO,
"SmramProfileReadyToLock\n"));
1559 mSmramReadyToLock =
TRUE;
1587 UINTN PoolListIndex;
1589 UINTN SmmPoolTypeIndex;
1592 if (ContextData ==
NULL) {
1598 DriverInfoList = ContextData->DriverInfoList;
1599 for (DriverLink = DriverInfoList->ForwardLink;
1600 DriverLink != DriverInfoList;
1601 DriverLink = DriverLink->ForwardLink)
1603 DriverInfoData =
CR (
1607 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
1609 TotalSize += DriverInfoData->DriverInfo.Header.Length;
1611 AllocInfoList = DriverInfoData->AllocInfoList;
1612 for (AllocLink = AllocInfoList->ForwardLink;
1613 AllocLink != AllocInfoList;
1614 AllocLink = AllocLink->ForwardLink)
1616 AllocInfoData =
CR (
1620 MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
1622 TotalSize += AllocInfoData->AllocInfo.Header.Length;
1627 FreePageList = &mSmmMemoryMap;
1628 for (Node = FreePageList->BackLink;
1629 Node != FreePageList;
1630 Node = Node->BackLink)
1635 for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {
1636 for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {
1637 FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][PoolListIndex];
1638 for (Node = FreePoolList->BackLink;
1639 Node != FreePoolList;
1640 Node = Node->BackLink)
1643 if (Pool->Header.Available) {
1668 OUT VOID *ProfileBuffer,
1669 IN OUT UINT64 *ProfileSize,
1670 IN OUT UINT64 *ProfileOffset
1688 UINTN PoolListIndex;
1694 UINT64 RemainingSize;
1696 UINTN ActionStringSize;
1697 UINTN SmmPoolTypeIndex;
1700 if (ContextData ==
NULL) {
1704 RemainingSize = *ProfileSize;
1709 Context = ProfileBuffer;
1720 DriverInfoList = ContextData->DriverInfoList;
1721 for (DriverLink = DriverInfoList->ForwardLink;
1722 DriverLink != DriverInfoList;
1723 DriverLink = DriverLink->ForwardLink)
1725 DriverInfoData =
CR (
1729 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
1731 if (*ProfileOffset < (Offset + DriverInfoData->DriverInfo.Header.Length)) {
1732 if (RemainingSize >= DriverInfoData->DriverInfo.Header.Length) {
1733 DriverInfo = ProfileBuffer;
1735 if (DriverInfo->PdbStringOffset != 0) {
1737 CopyMem ((VOID *)((
UINTN)DriverInfo + DriverInfo->PdbStringOffset), DriverInfoData->PdbString, PdbSize);
1740 RemainingSize -= DriverInfo->Header.Length;
1741 ProfileBuffer = (UINT8 *)ProfileBuffer + DriverInfo->Header.Length;
1747 Offset += DriverInfoData->DriverInfo.Header.Length;
1749 AllocInfoList = DriverInfoData->AllocInfoList;
1750 for (AllocLink = AllocInfoList->ForwardLink;
1751 AllocLink != AllocInfoList;
1752 AllocLink = AllocLink->ForwardLink)
1754 AllocInfoData =
CR (
1758 MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
1760 if (*ProfileOffset < (Offset + AllocInfoData->AllocInfo.Header.Length)) {
1761 if (RemainingSize >= AllocInfoData->AllocInfo.Header.Length) {
1762 AllocInfo = ProfileBuffer;
1764 if (AllocInfo->ActionStringOffset) {
1765 ActionStringSize =
AsciiStrSize (AllocInfoData->ActionString);
1766 CopyMem ((VOID *)((
UINTN)AllocInfo + AllocInfo->ActionStringOffset), AllocInfoData->ActionString, ActionStringSize);
1769 RemainingSize -= AllocInfo->Header.Length;
1770 ProfileBuffer = (UINT8 *)ProfileBuffer + AllocInfo->Header.Length;
1776 Offset += AllocInfoData->AllocInfo.Header.Length;
1785 FreePageList = &mSmmMemoryMap;
1786 for (Node = FreePageList->BackLink;
1787 Node != FreePageList;
1788 Node = Node->BackLink)
1793 for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {
1794 for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {
1795 FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][MAX_POOL_INDEX - PoolListIndex - 1];
1796 for (Node = FreePoolList->BackLink;
1797 Node != FreePoolList;
1798 Node = Node->BackLink)
1801 if (Pool->Header.Available) {
1818 FreePageList = &mSmmMemoryMap;
1819 for (Node = FreePageList->BackLink;
1820 Node != FreePageList;
1821 Node = Node->BackLink)
1826 MemoryProfileDescriptor = ProfileBuffer;
1827 MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;
1829 MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
1830 MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS)(
UINTN)Pages;
1843 for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {
1844 for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {
1845 FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][MAX_POOL_INDEX - PoolListIndex - 1];
1846 for (Node = FreePoolList->BackLink;
1847 Node != FreePoolList;
1848 Node = Node->BackLink)
1851 if (Pool->Header.Available) {
1854 MemoryProfileDescriptor = ProfileBuffer;
1855 MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;
1857 MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
1858 MemoryProfileDescriptor->Address = (PHYSICAL_ADDRESS)(
UINTN)Pool;
1859 MemoryProfileDescriptor->Size = Pool->Header.Size;
1876 MemoryRange = ProfileBuffer;
1877 MemoryRange->Header.Signature = MEMORY_PROFILE_MEMORY_RANGE_SIGNATURE;
1879 MemoryRange->Header.Revision = MEMORY_PROFILE_MEMORY_RANGE_REVISION;
1880 MemoryRange->MemoryRangeCount = (UINT32)mFullSmramRangeCount;
1890 for (Index = 0; Index < mFullSmramRangeCount; Index++) {
1893 MemoryProfileDescriptor = ProfileBuffer;
1894 MemoryProfileDescriptor->Header.Signature = MEMORY_PROFILE_DESCRIPTOR_SIGNATURE;
1896 MemoryProfileDescriptor->Header.Revision = MEMORY_PROFILE_DESCRIPTOR_REVISION;
1897 MemoryProfileDescriptor->Address = mFullSmramRanges[Index].
PhysicalStart;
1898 MemoryProfileDescriptor->Size = mFullSmramRanges[Index].
PhysicalSize;
1914 *ProfileSize -= RemainingSize;
1918 *ProfileOffset = Offset;
1939 IN OUT UINT64 *ProfileSize,
1940 OUT VOID *ProfileBuffer
1946 BOOLEAN SmramProfileGettingStatus;
1949 if (ContextData ==
NULL) {
1950 return EFI_UNSUPPORTED;
1953 SmramProfileGettingStatus = mSmramProfileGettingStatus;
1954 mSmramProfileGettingStatus =
TRUE;
1958 if (*ProfileSize < Size) {
1959 *ProfileSize = Size;
1960 mSmramProfileGettingStatus = SmramProfileGettingStatus;
1961 return EFI_BUFFER_TOO_SMALL;
1966 *ProfileSize = Size;
1968 mSmramProfileGettingStatus = SmramProfileGettingStatus;
1992 IN PHYSICAL_ADDRESS ImageBase,
1993 IN UINT64 ImageSize,
1994 IN EFI_FV_FILETYPE FileType
1999 VOID *EntryPointInImage;
2036 IN PHYSICAL_ADDRESS ImageBase,
2042 VOID *EntryPointInImage;
2075 OUT BOOLEAN *RecordingState
2081 if (ContextData ==
NULL) {
2082 return EFI_UNSUPPORTED;
2085 if (RecordingState ==
NULL) {
2086 return EFI_INVALID_PARAMETER;
2089 *RecordingState = mSmramProfileRecordingEnable;
2107 IN BOOLEAN RecordingState
2113 if (ContextData ==
NULL) {
2114 return EFI_UNSUPPORTED;
2117 mSmramProfileRecordingEnable = RecordingState;
2148 IN PHYSICAL_ADDRESS CallerAddress,
2149 IN MEMORY_PROFILE_ACTION Action,
2153 IN CHAR8 *ActionString OPTIONAL
2171 BOOLEAN SmramProfileGettingStatus;
2174 if (ContextData ==
NULL) {
2178 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2179 mSmramProfileGettingStatus =
TRUE;
2182 SmramProfileParameterGetInfo->Header.ReturnStatus = 0;
2184 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2199 UINT64 ProfileOffset;
2202 BOOLEAN SmramProfileGettingStatus;
2205 if (ContextData ==
NULL) {
2209 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2210 mSmramProfileGettingStatus =
TRUE;
2212 CopyMem (&SmramProfileGetData, SmramProfileParameterGetData,
sizeof (SmramProfileGetData));
2220 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetData: SMM ProfileBuffer in SMRAM or overflow!\n"));
2221 SmramProfileParameterGetData->ProfileSize = ProfileSize;
2222 SmramProfileParameterGetData->Header.ReturnStatus = (UINT64)(INT64)(
INTN)EFI_ACCESS_DENIED;
2226 if (SmramProfileGetData.ProfileSize < ProfileSize) {
2227 SmramProfileParameterGetData->ProfileSize = ProfileSize;
2228 SmramProfileParameterGetData->Header.ReturnStatus = (UINT64)(INT64)(
INTN)EFI_BUFFER_TOO_SMALL;
2234 SmramProfileParameterGetData->ProfileSize = ProfileSize;
2235 SmramProfileParameterGetData->Header.ReturnStatus = 0;
2238 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2254 BOOLEAN SmramProfileGettingStatus;
2257 if (ContextData ==
NULL) {
2261 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2262 mSmramProfileGettingStatus =
TRUE;
2264 CopyMem (&SmramProfileGetDataByOffset, SmramProfileParameterGetDataByOffset,
sizeof (SmramProfileGetDataByOffset));
2270 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetDataByOffset: SMM ProfileBuffer in SMRAM or overflow!\n"));
2271 SmramProfileParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(
INTN)EFI_ACCESS_DENIED;
2275 SmramProfileCopyData ((VOID *)(
UINTN)SmramProfileGetDataByOffset.ProfileBuffer, &SmramProfileGetDataByOffset.ProfileSize, &SmramProfileGetDataByOffset.ProfileOffset);
2276 CopyMem (SmramProfileParameterGetDataByOffset, &SmramProfileGetDataByOffset,
sizeof (SmramProfileGetDataByOffset));
2277 SmramProfileParameterGetDataByOffset->Header.ReturnStatus = 0;
2280 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2303 IN CONST VOID *Context OPTIONAL,
2304 IN OUT VOID *CommBuffer OPTIONAL,
2309 UINTN TempCommBufferSize;
2312 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler Enter\n"));
2317 if ((CommBuffer ==
NULL) || (CommBufferSize ==
NULL)) {
2321 TempCommBufferSize = *CommBufferSize;
2324 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2329 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer in SMRAM or overflow!\n"));
2335 SmramProfileParameterHeader->ReturnStatus = (UINT64)-1;
2338 SmramProfileParameterHeader->ReturnStatus = (UINT64)(INT64)(
INTN)EFI_UNSUPPORTED;
2342 switch (SmramProfileParameterHeader->Command) {
2343 case SMRAM_PROFILE_COMMAND_GET_PROFILE_INFO:
2344 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetInfo\n"));
2346 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2352 case SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA:
2353 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetData\n"));
2355 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2361 case SMRAM_PROFILE_COMMAND_GET_PROFILE_DATA_BY_OFFSET:
2362 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetDataByOffset\n"));
2364 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2370 case SMRAM_PROFILE_COMMAND_GET_RECORDING_STATE:
2371 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerGetRecordingState\n"));
2373 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2378 ParameterRecordingState->RecordingState = mSmramProfileRecordingEnable;
2379 ParameterRecordingState->Header.ReturnStatus = 0;
2381 case SMRAM_PROFILE_COMMAND_SET_RECORDING_STATE:
2382 DEBUG ((DEBUG_ERROR,
"SmramProfileHandlerSetRecordingState\n"));
2384 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler: SMM communication buffer size invalid!\n"));
2389 mSmramProfileRecordingEnable = ParameterRecordingState->RecordingState;
2390 ParameterRecordingState->Header.ReturnStatus = 0;
2396 case SMRAM_PROFILE_COMMAND_DEPRECATED1:
2397 case SMRAM_PROFILE_COMMAND_DEPRECATED2:
2406 DEBUG ((DEBUG_ERROR,
"SmramProfileHandler Exit\n"));
2423 if (!IS_SMRAM_PROFILE_ENABLED) {
2429 &gEdkiiMemoryProfileGuid,
2448 BOOLEAN SmramProfileGettingStatus;
2451 if (ContextData ==
NULL) {
2455 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2456 mSmramProfileGettingStatus =
TRUE;
2458 DEBUG ((DEBUG_INFO,
"FullSmramRange address - 0x%08x\n", mFullSmramRanges));
2460 DEBUG ((DEBUG_INFO,
"======= SmramProfile begin =======\n"));
2462 DEBUG ((DEBUG_INFO,
"FullSmramRange:\n"));
2463 for (Index = 0; Index < mFullSmramRangeCount; Index++) {
2464 DEBUG ((DEBUG_INFO,
" FullSmramRange (0x%x)\n", Index));
2465 DEBUG ((DEBUG_INFO,
" PhysicalStart - 0x%016lx\n", mFullSmramRanges[Index].PhysicalStart));
2466 DEBUG ((DEBUG_INFO,
" CpuStart - 0x%016lx\n", mFullSmramRanges[Index].CpuStart));
2467 DEBUG ((DEBUG_INFO,
" PhysicalSize - 0x%016lx\n", mFullSmramRanges[Index].PhysicalSize));
2468 DEBUG ((DEBUG_INFO,
" RegionState - 0x%016lx\n", mFullSmramRanges[Index].RegionState));
2471 DEBUG ((DEBUG_INFO,
"======= SmramProfile end =======\n"));
2473 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2490 BOOLEAN SmramProfileGettingStatus;
2493 if (ContextData ==
NULL) {
2497 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2498 mSmramProfileGettingStatus =
TRUE;
2500 DEBUG ((DEBUG_INFO,
"======= SmramProfile begin =======\n"));
2502 DEBUG ((DEBUG_INFO,
"FreePagesList:\n"));
2503 FreePageList = &mSmmMemoryMap;
2504 for (Node = FreePageList->BackLink, Index = 0;
2505 Node != FreePageList;
2506 Node = Node->BackLink, Index++)
2509 DEBUG ((DEBUG_INFO,
" Index - 0x%x\n", Index));
2510 DEBUG ((DEBUG_INFO,
" PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS)(
UINTN)Pages));
2511 DEBUG ((DEBUG_INFO,
" NumberOfPages - 0x%08x\n", Pages->NumberOfPages));
2514 DEBUG ((DEBUG_INFO,
"======= SmramProfile end =======\n"));
2516 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2532 UINTN PoolListIndex;
2534 BOOLEAN SmramProfileGettingStatus;
2535 UINTN SmmPoolTypeIndex;
2538 if (ContextData ==
NULL) {
2542 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2543 mSmramProfileGettingStatus =
TRUE;
2545 DEBUG ((DEBUG_INFO,
"======= SmramProfile begin =======\n"));
2547 for (SmmPoolTypeIndex = 0; SmmPoolTypeIndex < SmmPoolTypeMax; SmmPoolTypeIndex++) {
2548 for (PoolListIndex = 0; PoolListIndex < MAX_POOL_INDEX; PoolListIndex++) {
2549 DEBUG ((DEBUG_INFO,
"FreePoolList(%d)(%d):\n", SmmPoolTypeIndex, PoolListIndex));
2550 FreePoolList = &mSmmPoolLists[SmmPoolTypeIndex][PoolListIndex];
2551 for (Node = FreePoolList->BackLink, Index = 0;
2552 Node != FreePoolList;
2553 Node = Node->BackLink, Index++)
2556 DEBUG ((DEBUG_INFO,
" Index - 0x%x\n", Index));
2557 DEBUG ((DEBUG_INFO,
" PhysicalStart - 0x%016lx\n", (PHYSICAL_ADDRESS)(
UINTN)Pool));
2558 DEBUG ((DEBUG_INFO,
" Size - 0x%08x\n", Pool->Header.Size));
2559 DEBUG ((DEBUG_INFO,
" Available - 0x%02x\n", Pool->Header.Available));
2564 DEBUG ((DEBUG_INFO,
"======= SmramProfile end =======\n"));
2566 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2571 "gSmst->SmmAllocatePages",
2572 "gSmst->SmmFreePages",
2573 "gSmst->SmmAllocatePool",
2574 "gSmst->SmmFreePool",
2578 MEMORY_PROFILE_ACTION Action;
2583 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES,
"Lib:AllocatePages" },
2584 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES,
"Lib:AllocateRuntimePages" },
2585 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_PAGES,
"Lib:AllocateReservedPages" },
2586 { MEMORY_PROFILE_ACTION_LIB_FREE_PAGES,
"Lib:FreePages" },
2587 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_PAGES,
"Lib:AllocateAlignedPages" },
2588 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RUNTIME_PAGES,
"Lib:AllocateAlignedRuntimePages" },
2589 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RESERVED_PAGES,
"Lib:AllocateAlignedReservedPages" },
2590 { MEMORY_PROFILE_ACTION_LIB_FREE_ALIGNED_PAGES,
"Lib:FreeAlignedPages" },
2591 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_POOL,
"Lib:AllocatePool" },
2592 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_POOL,
"Lib:AllocateRuntimePool" },
2593 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_POOL,
"Lib:AllocateReservedPool" },
2594 { MEMORY_PROFILE_ACTION_LIB_FREE_POOL,
"Lib:FreePool" },
2595 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ZERO_POOL,
"Lib:AllocateZeroPool" },
2596 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_ZERO_POOL,
"Lib:AllocateRuntimeZeroPool" },
2597 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_ZERO_POOL,
"Lib:AllocateReservedZeroPool" },
2598 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_COPY_POOL,
"Lib:AllocateCopyPool" },
2599 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_COPY_POOL,
"Lib:AllocateRuntimeCopyPool" },
2600 { MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RESERVED_COPY_POOL,
"Lib:AllocateReservedCopyPool" },
2601 { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_POOL,
"Lib:ReallocatePool" },
2602 { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RUNTIME_POOL,
"Lib:ReallocateRuntimePool" },
2603 { MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RESERVED_POOL,
"Lib:ReallocateReservedPool" },
2608 CHAR8 *MemoryTypeStr;
2631 for (Index = 0; Index <
ARRAY_SIZE (mMemoryTypeString); Index++) {
2632 if (mMemoryTypeString[Index].MemoryType == MemoryType) {
2633 return mMemoryTypeString[Index].MemoryTypeStr;
2637 return "UnexpectedMemoryType";
2650 IN MEMORY_PROFILE_ACTION Action
2654 UINTN ActionStringCount;
2655 CHAR8 **ActionString;
2657 ActionString = mSmmActionString;
2658 ActionStringCount =
ARRAY_SIZE (mSmmActionString);
2660 if ((
UINTN)(UINT32)Action < ActionStringCount) {
2661 return ActionString[Action];
2664 for (Index = 0; Index <
ARRAY_SIZE (mExtActionString); Index++) {
2665 if (mExtActionString[Index].Action == Action) {
2666 return mExtActionString[Index].String;
2670 return ActionString[0];
2694 BOOLEAN SmramProfileGettingStatus;
2698 if (ContextData ==
NULL) {
2702 SmramProfileGettingStatus = mSmramProfileGettingStatus;
2703 mSmramProfileGettingStatus =
TRUE;
2705 Context = &ContextData->Context;
2706 DEBUG ((DEBUG_INFO,
"======= SmramProfile begin =======\n"));
2707 DEBUG ((DEBUG_INFO,
"MEMORY_PROFILE_CONTEXT\n"));
2709 DEBUG ((DEBUG_INFO,
" CurrentTotalUsage - 0x%016lx\n", Context->CurrentTotalUsage));
2710 DEBUG ((DEBUG_INFO,
" PeakTotalUsage - 0x%016lx\n", Context->PeakTotalUsage));
2711 for (TypeIndex = 0; TypeIndex <
sizeof (Context->CurrentTotalUsageByType) /
sizeof (Context->CurrentTotalUsageByType[0]); TypeIndex++) {
2712 if ((Context->CurrentTotalUsageByType[TypeIndex] != 0) ||
2713 (Context->PeakTotalUsageByType[TypeIndex] != 0))
2715 DEBUG ((DEBUG_INFO,
" CurrentTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->CurrentTotalUsageByType[TypeIndex],
ProfileMemoryTypeToStr (TypeIndex)));
2716 DEBUG ((DEBUG_INFO,
" PeakTotalUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, Context->PeakTotalUsageByType[TypeIndex],
ProfileMemoryTypeToStr (TypeIndex)));
2720 DEBUG ((DEBUG_INFO,
" TotalImageSize - 0x%016lx\n", Context->TotalImageSize));
2721 DEBUG ((DEBUG_INFO,
" ImageCount - 0x%08x\n", Context->ImageCount));
2722 DEBUG ((DEBUG_INFO,
" SequenceCount - 0x%08x\n", Context->SequenceCount));
2724 SmramDriverInfoList = ContextData->DriverInfoList;
2725 for (DriverLink = SmramDriverInfoList->ForwardLink, DriverIndex = 0;
2726 DriverLink != SmramDriverInfoList;
2727 DriverLink = DriverLink->ForwardLink, DriverIndex++)
2729 DriverInfoData =
CR (
2733 MEMORY_PROFILE_DRIVER_INFO_SIGNATURE
2735 DriverInfo = &DriverInfoData->DriverInfo;
2736 DEBUG ((DEBUG_INFO,
" MEMORY_PROFILE_DRIVER_INFO (0x%x)\n", DriverIndex));
2737 DEBUG ((DEBUG_INFO,
" FileName - %g\n", &DriverInfo->FileName));
2738 DEBUG ((DEBUG_INFO,
" ImageBase - 0x%016lx\n", DriverInfo->ImageBase));
2739 DEBUG ((DEBUG_INFO,
" ImageSize - 0x%016lx\n", DriverInfo->ImageSize));
2740 DEBUG ((DEBUG_INFO,
" EntryPoint - 0x%016lx\n", DriverInfo->EntryPoint));
2741 DEBUG ((DEBUG_INFO,
" ImageSubsystem - 0x%04x\n", DriverInfo->ImageSubsystem));
2742 DEBUG ((DEBUG_INFO,
" FileType - 0x%02x\n", DriverInfo->FileType));
2743 DEBUG ((DEBUG_INFO,
" CurrentUsage - 0x%016lx\n", DriverInfo->CurrentUsage));
2744 DEBUG ((DEBUG_INFO,
" PeakUsage - 0x%016lx\n", DriverInfo->PeakUsage));
2745 for (TypeIndex = 0; TypeIndex <
sizeof (DriverInfo->CurrentUsageByType) /
sizeof (DriverInfo->CurrentUsageByType[0]); TypeIndex++) {
2746 if ((DriverInfo->CurrentUsageByType[TypeIndex] != 0) ||
2747 (DriverInfo->PeakUsageByType[TypeIndex] != 0))
2749 DEBUG ((DEBUG_INFO,
" CurrentUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->CurrentUsageByType[TypeIndex],
ProfileMemoryTypeToStr (TypeIndex)));
2750 DEBUG ((DEBUG_INFO,
" PeakUsage[0x%02x] - 0x%016lx (%a)\n", TypeIndex, DriverInfo->PeakUsageByType[TypeIndex],
ProfileMemoryTypeToStr (TypeIndex)));
2754 DEBUG ((DEBUG_INFO,
" AllocRecordCount - 0x%08x\n", DriverInfo->AllocRecordCount));
2756 AllocInfoList = DriverInfoData->AllocInfoList;
2757 for (AllocLink = AllocInfoList->ForwardLink, AllocIndex = 0;
2758 AllocLink != AllocInfoList;
2759 AllocLink = AllocLink->ForwardLink, AllocIndex++)
2761 AllocInfoData =
CR (
2765 MEMORY_PROFILE_ALLOC_INFO_SIGNATURE
2767 AllocInfo = &AllocInfoData->AllocInfo;
2768 DEBUG ((DEBUG_INFO,
" MEMORY_PROFILE_ALLOC_INFO (0x%x)\n", AllocIndex));
2769 DEBUG ((DEBUG_INFO,
" CallerAddress - 0x%016lx (Offset: 0x%08x)\n", AllocInfo->CallerAddress, AllocInfo->CallerAddress - DriverInfo->ImageBase));
2770 DEBUG ((DEBUG_INFO,
" SequenceId - 0x%08x\n", AllocInfo->SequenceId));
2771 if ((AllocInfo->Action & MEMORY_PROFILE_ACTION_USER_DEFINED_MASK) != 0) {
2772 if (AllocInfoData->ActionString !=
NULL) {
2773 DEBUG ((DEBUG_INFO,
" Action - 0x%08x (%a)\n", AllocInfo->Action, AllocInfoData->ActionString));
2775 DEBUG ((DEBUG_INFO,
" Action - 0x%08x (UserDefined-0x%08x)\n", AllocInfo->Action, AllocInfo->Action));
2782 DEBUG ((DEBUG_INFO,
" Buffer - 0x%016lx\n", AllocInfo->Buffer));
2783 DEBUG ((DEBUG_INFO,
" Size - 0x%016lx\n", AllocInfo->Size));
2787 DEBUG ((DEBUG_INFO,
"======= SmramProfile end =======\n"));
2789 mSmramProfileGettingStatus = SmramProfileGettingStatus;
2802 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.