Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
86 changes: 83 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 @@ -661,6 +664,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 +677,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 +721,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 +731,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 +795,44 @@ ExecuteMmCoreFromMmram (
}
}

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

//
// 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)
//
Status = MmAccess->Lock ((EFI_PEI_SERVICES **)GetPeiServicesTablePointer (), MmAccess, Index);
if (EFI_ERROR (Status)) {
//
// 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, Status));
ASSERT (FALSE);
return Status;
}

//
// Print debug message that the MMRAM window is now closed.
//
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