Skip to content

Commit 3e1d4a9

Browse files
committed
[CHERRY-PICK] StandaloneMmPkg: StandaloneMmIplPei: Use MM access to open the regions
Current MM IPL in PEI phase does not open the MMRAM regions through MM access PPI. This is causing some platforms like OVMF reading all `0xFF`s when trying to relocate the Standalone MM core. This change opens all the MMRAM regions provided by MM access PPI and closes + locks the regions after initial MM foundation setup, when MM Access PPI is available. Platforms that require MM access PPI can inject depex through libraries. Signed-off-by: Kun Qin <[email protected]> (cherry picked from commit 73b0b5e)
1 parent 0059b31 commit 3e1d4a9

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,10 @@ ExecuteMmCoreFromMmram (
664664
PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
665665
STANDALONE_MM_FOUNDATION_ENTRY_POINT Entry;
666666
EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *Block;
667+
EFI_PEI_MM_ACCESS_PPI *MmAccess;
668+
UINTN Size;
669+
UINTN Index;
670+
UINTN MmramRangeCount;
667671

668672
MmFvBase = 0;
669673
MmFvSize = 0;
@@ -673,6 +677,40 @@ ExecuteMmCoreFromMmram (
673677
Status = LocateMmCoreFv (&MmFvBase, &MmFvSize, &MmCoreFileName, &ImageContext.Handle);
674678
ASSERT_EFI_ERROR (Status);
675679

680+
//
681+
// Prepare an MM access PPI for MM RAM.
682+
//
683+
MmAccess = NULL;
684+
MmramRangeCount = 0;
685+
Status = PeiServicesLocatePpi (
686+
&gEfiPeiMmAccessPpiGuid,
687+
0,
688+
NULL,
689+
(VOID **)&MmAccess
690+
);
691+
if (!EFI_ERROR (Status)) {
692+
//
693+
// Open all MMRAM ranges, if MmAccess is available.
694+
//
695+
Size = 0;
696+
Status = MmAccess->GetCapabilities ((EFI_PEI_SERVICES **)GetPeiServicesTablePointer (), MmAccess, &Size, NULL);
697+
if (Status != EFI_BUFFER_TOO_SMALL) {
698+
// This is not right...
699+
ASSERT (Status == EFI_BUFFER_TOO_SMALL);
700+
return EFI_DEVICE_ERROR;
701+
}
702+
703+
MmramRangeCount = Size / sizeof (EFI_MMRAM_DESCRIPTOR);
704+
for (Index = 0; Index < MmramRangeCount; Index++) {
705+
Status = MmAccess->Open ((EFI_PEI_SERVICES **)GetPeiServicesTablePointer (), MmAccess, Index);
706+
if (EFI_ERROR (Status)) {
707+
DEBUG ((DEBUG_ERROR, "MM IPL failed to open MMRAM windows index %d - %r\n", Index, Status));
708+
ASSERT_EFI_ERROR (Status);
709+
goto Done;
710+
}
711+
}
712+
}
713+
676714
//
677715
// Initialize ImageContext
678716
//
@@ -683,7 +721,7 @@ ExecuteMmCoreFromMmram (
683721
//
684722
Status = PeCoffLoaderGetImageInfo (&ImageContext);
685723
if (EFI_ERROR (Status)) {
686-
return Status;
724+
goto Done;
687725
}
688726

689727
PageCount = (UINTN)EFI_SIZE_TO_PAGES ((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment);
@@ -693,7 +731,8 @@ ExecuteMmCoreFromMmram (
693731
//
694732
ImageContext.ImageAddress = MmIplAllocateMmramPage (PageCount, &Block);
695733
if (ImageContext.ImageAddress == 0) {
696-
return EFI_NOT_FOUND;
734+
Status = EFI_NOT_FOUND;
735+
goto Done;
697736
}
698737

699738
//
@@ -756,6 +795,44 @@ ExecuteMmCoreFromMmram (
756795
}
757796
}
758797

798+
Done:
799+
if (MmAccess != NULL) {
800+
//
801+
// Close all MMRAM ranges, if MmAccess is available.
802+
//
803+
for (Index = 0; Index < MmramRangeCount; Index++) {
804+
Status = MmAccess->Close ((EFI_PEI_SERVICES **)GetPeiServicesTablePointer (), MmAccess, Index);
805+
if (EFI_ERROR (Status)) {
806+
DEBUG ((DEBUG_ERROR, "MM IPL failed to close MMRAM windows index %d - %r\n", Index, Status));
807+
ASSERT (FALSE);
808+
return Status;
809+
}
810+
811+
//
812+
// Print debug message that the MMRAM window is now closed.
813+
//
814+
DEBUG ((DEBUG_INFO, "MM IPL closed MMRAM window index %d\n", Index));
815+
816+
//
817+
// Lock the MMRAM (Note: Locking MMRAM may not be supported on all platforms)
818+
//
819+
Status = MmAccess->Lock ((EFI_PEI_SERVICES **)GetPeiServicesTablePointer (), MmAccess, Index);
820+
if (EFI_ERROR (Status)) {
821+
//
822+
// Print error message that the MMRAM failed to lock...
823+
//
824+
DEBUG ((DEBUG_ERROR, "MM IPL could not lock MMRAM (Index %d) after executing MM Core %r\n", Index, Status));
825+
ASSERT (FALSE);
826+
return Status;
827+
}
828+
829+
//
830+
// Print debug message that the MMRAM window is now closed.
831+
//
832+
DEBUG ((DEBUG_INFO, "MM IPL locked MMRAM window index %d\n", Index));
833+
}
834+
}
835+
759836
return Status;
760837
}
761838

StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <Library/PeCoffLib.h>
2222
#include <Library/CacheMaintenanceLib.h>
2323
#include <Library/PeiServicesTablePointerLib.h>
24+
#include <Ppi/MmAccess.h>
2425
#include <Ppi/MmControl.h>
2526
#include <Ppi/MmCommunication.h>
2627
#include <Ppi/MmCommunication3.h>

StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
gEfiPeiMmCommunication3PpiGuid
6666
gEfiEndOfPeiSignalPpiGuid
6767
gMmCoreFvLocationPpiGuid
68+
gEfiPeiMmAccessPpiGuid
6869

6970
[Protocols]
7071
gEfiMmEndOfPeiProtocol

0 commit comments

Comments
 (0)