Skip to content

Commit

Permalink
MdeModulePkg: Add Standalone MM Core performance support
Browse files Browse the repository at this point in the history
Adds a new library instance to support MM core functionality for
performance in Standalone MM.

- Add StandaloneMmCorePerformanceLib instance
- Move common MM logic to a new file `MmCorePerformanceLib.c`
- Define interfaces with implementation specific to MM environment
  type in `SmmCorePerformanceLibInternal.h` and implement those
  functions in the Standalone MM and Traditional MM specific C files

Note: StandaloneMmCorePerformanceLib supports both
      `MM_CORE_STANDALONE` and `MM_STANDALONE` as some Standalone MM
	  environments need to link this functionality in a ring 3 driver
	  that is outside the ring 0 core driver.

Signed-off-by: Michael Kubacki <[email protected]>
  • Loading branch information
makubacki committed Feb 3, 2025
1 parent fabbe77 commit f919dd1
Show file tree
Hide file tree
Showing 8 changed files with 1,856 additions and 1,385 deletions.
66 changes: 44 additions & 22 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 *SmmCommBufferHeader; // 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,7 +282,7 @@ InternalGetSmmPerfData (
//
if (ReservedMemSize > SMM_BOOT_RECORD_COMM_SIZE) {
SmmBootRecordCommBuffer = (VOID *)(UINTN)SmmCommMemRegion->PhysicalStart;
SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER *)SmmBootRecordCommBuffer;
SmmCommBufferHeader = (EFI_MM_COMMUNICATE_HEADER *)SmmBootRecordCommBuffer;
SmmCommData = (SMM_BOOT_RECORD_COMMUNICATE *)SmmCommBufferHeader->Data;
ZeroMem ((UINT8 *)SmmCommData, sizeof (SMM_BOOT_RECORD_COMMUNICATE));

Expand All @@ -292,7 +296,14 @@ InternalGetSmmPerfData (
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,37 @@ 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
);
SmmCommBufferHeader->MessageLength = sizeof (SMM_BOOT_RECORD_COMMUNICATE) + BootRecordDataPayloadSize;
CommSize = sizeof (EFI_MM_COMMUNICATE_HEADER) + (UINTN)SmmCommBufferHeader->MessageLength;
Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);
ASSERT_EFI_ERROR (Status);
ASSERT_EFI_ERROR (SmmCommData->ReturnStatus);
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

0 comments on commit f919dd1

Please sign in to comment.