Skip to content
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
91 changes: 88 additions & 3 deletions StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ CreatMmHobList (
MmProfileDataHob,
Block
);
FreePages (PlatformHobList, EFI_SIZE_TO_PAGES (PlatformHobSize));
if (PlatformHobSize != 0) {
FreePages (PlatformHobList, EFI_SIZE_TO_PAGES (PlatformHobSize));
}

ASSERT (Status == RETURN_BUFFER_TOO_SMALL);
ASSERT (FoundationHobSize != 0);

Expand Down Expand Up @@ -652,6 +655,7 @@ ExecuteMmCoreFromMmram (
)
{
EFI_STATUS Status;
EFI_STATUS AccessStatus; // MU_CHANGE: Separate variable to avoid overwriting Status
UINTN PageCount;
VOID *MmHobList;
UINTN MmHobSize;
Expand All @@ -661,6 +665,10 @@ ExecuteMmCoreFromMmram (
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
STANDALONE_MM_FOUNDATION_ENTRY_POINT Entry;
EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *Block;
EFI_PEI_MM_ACCESS_PPI *MmAccess;
UINTN Size;
UINTN Index;
UINTN MmramRangeCount;

MmFvBase = 0;
MmFvSize = 0;
Expand All @@ -670,6 +678,40 @@ ExecuteMmCoreFromMmram (
Status = LocateMmCoreFv (&MmFvBase, &MmFvSize, &MmCoreFileName, &ImageContext.Handle);
ASSERT_EFI_ERROR (Status);

//
// Prepare an MM access PPI for MM RAM.
//
MmAccess = NULL;
MmramRangeCount = 0;
Status = PeiServicesLocatePpi (
&gEfiPeiMmAccessPpiGuid,
0,
NULL,
(VOID **)&MmAccess
);
if (!EFI_ERROR (Status)) {
//
// Open all MMRAM ranges, if MmAccess is available.
//
Size = 0;
Status = MmAccess->GetCapabilities ((EFI_PEI_SERVICES **)GetPeiServicesTablePointer (), MmAccess, &Size, NULL);
if (Status != EFI_BUFFER_TOO_SMALL) {
// This is not right...
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
return EFI_DEVICE_ERROR;
}

MmramRangeCount = Size / sizeof (EFI_MMRAM_DESCRIPTOR);
for (Index = 0; Index < MmramRangeCount; Index++) {
Status = MmAccess->Open ((EFI_PEI_SERVICES **)GetPeiServicesTablePointer (), MmAccess, Index);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "MM IPL failed to open MMRAM windows index %d - %r\n", Index, Status));
ASSERT_EFI_ERROR (Status);
goto Done;
}
}
}

//
// Initialize ImageContext
//
Expand All @@ -680,7 +722,7 @@ ExecuteMmCoreFromMmram (
//
Status = PeCoffLoaderGetImageInfo (&ImageContext);
if (EFI_ERROR (Status)) {
return Status;
goto Done;
}

PageCount = (UINTN)EFI_SIZE_TO_PAGES ((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
Expand All @@ -690,7 +732,8 @@ ExecuteMmCoreFromMmram (
//
ImageContext.ImageAddress = MmIplAllocateMmramPage (PageCount, &Block);
if (ImageContext.ImageAddress == 0) {
return EFI_NOT_FOUND;
Status = EFI_NOT_FOUND;
goto Done;
}

//
Expand Down Expand Up @@ -753,6 +796,48 @@ ExecuteMmCoreFromMmram (
}
}

Done:
if (MmAccess != NULL) {
//
// Close all MMRAM ranges, if MmAccess is available.
//
for (Index = 0; Index < MmramRangeCount; Index++) {
// MU_CHANGE START: Will not return if error occurs
AccessStatus = MmAccess->Close ((EFI_PEI_SERVICES **)GetPeiServicesTablePointer (), MmAccess, Index);
if (EFI_ERROR (AccessStatus)) {
DEBUG ((DEBUG_ERROR, "MM IPL failed to close MMRAM windows index %d - %r\n", Index, AccessStatus));
ASSERT (FALSE);
}

// MU_CHANGE END: Will not return if error occurs

//
// Print debug message that the MMRAM window is now closed.
//
DEBUG ((DEBUG_INFO, "MM IPL closed MMRAM window index %d\n", Index));

//
// Lock the MMRAM (Note: Locking MMRAM may not be supported on all platforms)
//
// MU_CHANGE START: Will not return if error occurs and allow UNSUPPORTED
AccessStatus = MmAccess->Lock ((EFI_PEI_SERVICES **)GetPeiServicesTablePointer (), MmAccess, Index);
if (EFI_ERROR (AccessStatus) && (AccessStatus != EFI_UNSUPPORTED)) {
//
// Print error message that the MMRAM failed to lock...
//
DEBUG ((DEBUG_ERROR, "MM IPL could not lock MMRAM (Index %d) after executing MM Core %r\n", Index, AccessStatus));
ASSERT (FALSE);
}

// MU_CHANGE END: Will not return if error occurs and allow UNSUPPORTED

//
// Print debug message that the MMRAM window is now locked.
//
DEBUG ((DEBUG_INFO, "MM IPL locked MMRAM window index %d\n", Index));
}
}

return Status;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <Library/PeCoffLib.h>
#include <Library/CacheMaintenanceLib.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Ppi/MmAccess.h>
#include <Ppi/MmControl.h>
#include <Ppi/MmCommunication.h>
#include <Ppi/MmCommunication3.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
gEfiPeiMmCommunication3PpiGuid
gEfiEndOfPeiSignalPpiGuid
gMmCoreFvLocationPpiGuid
gEfiPeiMmAccessPpiGuid

[Protocols]
gEfiMmEndOfPeiProtocol
Expand Down