Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Standalone MM Performance Support [Rebase & FF] #1268

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Data for FPDT performance records.
//
#define SMM_BOOT_RECORD_COMM_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE))
#define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
#define FIRMWARE_RECORD_BUFFER 0x10000
#define CACHE_HANDLE_GUID_COUNT 0x800
// MU_CHANGE [BEGIN] - Standalone MM Perf Support
#define SMM_BOOT_RECORD_COMM_SIZE (OFFSET_OF (EFI_MM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE))
// MU_CHANGE [END] - Standalone MM Perf Support
#define STRING_SIZE (FPDT_STRING_EVENT_RECORD_NAME_LENGTH * sizeof (CHAR8))
#define FIRMWARE_RECORD_BUFFER 0x10000
#define CACHE_HANDLE_GUID_COUNT 0x800

BOOT_PERFORMANCE_TABLE *mAcpiBootPerformanceTable = NULL;
BOOT_PERFORMANCE_TABLE mBootPerformanceTableTemplate = {
Expand Down Expand Up @@ -228,16 +230,18 @@ InternalGetSmmPerfData (
{
EFI_STATUS Status;
UINT8 *SmmBootRecordCommBuffer;
EFI_SMM_COMMUNICATE_HEADER *SmmCommBufferHeader;
EFI_MM_COMMUNICATE_HEADER *MmCommBufferHeader; // MU_CHANGE - Standalone MM Perf Support
SMM_BOOT_RECORD_COMMUNICATE *SmmCommData;
UINTN CommSize;
EFI_SMM_COMMUNICATION_PROTOCOL *Communication;
EDKII_PI_SMM_COMMUNICATION_REGION_TABLE *SmmCommRegionTable;
EFI_MEMORY_DESCRIPTOR *SmmCommMemRegion;
UINTN Index;
VOID *CurrentBootRecordData; // MU_CHANGE - Standalone MM Perf Support
VOID *SmmBootRecordData;
UINTN SmmBootRecordDataSize;
UINTN ReservedMemSize;
UINTN BootRecordDataPayloadSize; // MU_CHANGE - Standalone MM Perf Support
UINTN SmmBootRecordDataRetrieved;

//
Expand Down Expand Up @@ -278,21 +282,28 @@ InternalGetSmmPerfData (
//
if (ReservedMemSize > SMM_BOOT_RECORD_COMM_SIZE) {
SmmBootRecordCommBuffer = (VOID *)(UINTN)SmmCommMemRegion->PhysicalStart;
SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER *)SmmBootRecordCommBuffer;
SmmCommData = (SMM_BOOT_RECORD_COMMUNICATE *)SmmCommBufferHeader->Data;
MmCommBufferHeader = (EFI_MM_COMMUNICATE_HEADER *)SmmBootRecordCommBuffer; // MU_CHANGE - Standalone MM Perf Support
SmmCommData = (SMM_BOOT_RECORD_COMMUNICATE *)MmCommBufferHeader->Data; // MU_CHANGE - Standalone MM Perf Support
ZeroMem ((UINT8 *)SmmCommData, sizeof (SMM_BOOT_RECORD_COMMUNICATE));

CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gEfiFirmwarePerformanceGuid);
SmmCommBufferHeader->MessageLength = sizeof (SMM_BOOT_RECORD_COMMUNICATE);
CommSize = SMM_BOOT_RECORD_COMM_SIZE;
CopyGuid (&MmCommBufferHeader->HeaderGuid, &gEfiFirmwarePerformanceGuid); // MU_CHANGE - Standalone MM Perf Support
MmCommBufferHeader->MessageLength = sizeof (SMM_BOOT_RECORD_COMMUNICATE); // MU_CHANGE - Standalone MM Perf Support
CommSize = SMM_BOOT_RECORD_COMM_SIZE;

//
// Get the size of boot records.
//
SmmCommData->Function = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE;
SmmCommData->BootRecordData = NULL;
Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);
// MU_CHANGE [BEGIN] - Standalone MM Perf Support
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "Perf handler MMI not found or communicate failed. Status = %r.\n", Status));
} else if (EFI_ERROR (SmmCommData->ReturnStatus)) {
DEBUG ((DEBUG_ERROR, "Perf handler MMI returned an error. Status = %r.\n", SmmCommData->ReturnStatus));
}

// MU_CHANGE [END] - Standalone MM Perf Support
if (!EFI_ERROR (Status) && !EFI_ERROR (SmmCommData->ReturnStatus) && (SmmCommData->BootRecordSize != 0)) {
if (SkipGetPerfData) {
*SmmPerfDataSize = SmmCommData->BootRecordSize;
Expand All @@ -308,26 +319,42 @@ InternalGetSmmPerfData (
SmmBootRecordData = AllocateZeroPool (SmmBootRecordDataSize);
SmmBootRecordDataRetrieved = 0;
ASSERT (SmmBootRecordData != NULL);
SmmCommData->BootRecordData = (VOID *)((UINTN)SmmCommMemRegion->PhysicalStart + SMM_BOOT_RECORD_COMM_SIZE);
SmmCommData->BootRecordSize = ReservedMemSize - SMM_BOOT_RECORD_COMM_SIZE;
while (SmmBootRecordDataRetrieved < SmmBootRecordDataSize) {
Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);
ASSERT_EFI_ERROR (Status);
ASSERT_EFI_ERROR (SmmCommData->ReturnStatus);
if (SmmBootRecordDataRetrieved + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {
CopyMem ((UINT8 *)SmmBootRecordData + SmmBootRecordDataRetrieved, SmmCommData->BootRecordData, SmmBootRecordDataSize - SmmBootRecordDataRetrieved);
} else {
CopyMem ((UINT8 *)SmmBootRecordData + SmmBootRecordDataRetrieved, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);
// MU_CHANGE [BEGIN] - Standalone MM Perf Support
if (SmmBootRecordData != NULL) {
CurrentBootRecordData = (VOID *)((UINTN)SmmCommMemRegion->PhysicalStart + SMM_BOOT_RECORD_COMM_SIZE);
while (SmmBootRecordDataRetrieved < SmmBootRecordDataSize) {
// Note: Maximum comm buffer data payload size is ReservedMemSize - SMM_BOOT_RECORD_COMM_SIZE
BootRecordDataPayloadSize = MIN (
ReservedMemSize - SMM_BOOT_RECORD_COMM_SIZE,
SmmBootRecordDataSize - SmmBootRecordDataRetrieved
);

MmCommBufferHeader->MessageLength = sizeof (SMM_BOOT_RECORD_COMMUNICATE) + BootRecordDataPayloadSize;
CommSize = sizeof (EFI_MM_COMMUNICATE_HEADER) + (UINTN)MmCommBufferHeader->MessageLength;

Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status) || EFI_ERROR (SmmCommData->ReturnStatus)) {
break;
}

if (SmmBootRecordDataRetrieved + SmmCommData->BootRecordSize > SmmBootRecordDataSize) {
CopyMem ((UINT8 *)SmmBootRecordData + SmmBootRecordDataRetrieved, CurrentBootRecordData, SmmBootRecordDataSize - SmmBootRecordDataRetrieved);
} else {
CopyMem ((UINT8 *)SmmBootRecordData + SmmBootRecordDataRetrieved, CurrentBootRecordData, SmmCommData->BootRecordSize);
}

SmmBootRecordDataRetrieved += SmmCommData->BootRecordSize;
SmmCommData->BootRecordOffset += SmmCommData->BootRecordSize;
}

SmmBootRecordDataRetrieved += SmmCommData->BootRecordSize;
SmmCommData->BootRecordOffset += SmmCommData->BootRecordSize;
}
mSmmBootRecordOffset = SmmCommData->BootRecordOffset;

mSmmBootRecordOffset = SmmCommData->BootRecordOffset;
*SmmPerfData = SmmBootRecordData;
*SmmPerfDataSize = SmmBootRecordDataSize;
}

*SmmPerfData = SmmBootRecordData;
*SmmPerfDataSize = SmmBootRecordDataSize;
// MU_CHANGE [END] - Standalone MM Perf Support
}
}
}
Expand Down
Loading