diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c index 972f0a32f2..eda47b93ef 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c @@ -684,6 +684,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; @@ -693,6 +697,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 // @@ -703,7 +741,7 @@ ExecuteMmCoreFromMmram ( // Status = PeCoffLoaderGetImageInfo (&ImageContext); if (EFI_ERROR (Status)) { - return Status; + goto Done; } PageCount = (UINTN)EFI_SIZE_TO_PAGES ((UINTN)ImageContext.ImageSize + ImageContext.SectionAlignment); @@ -713,7 +751,8 @@ ExecuteMmCoreFromMmram ( // ImageContext.ImageAddress = MmIplAllocateMmramPage (PageCount, &Block); if (ImageContext.ImageAddress == 0) { - return EFI_NOT_FOUND; + Status = EFI_NOT_FOUND; + goto Done; } // @@ -776,6 +815,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; } diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h index 01b947c8ce..430e7c578b 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf index 9f446e82a0..c06899e8ae 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf @@ -65,6 +65,7 @@ gEfiPeiMmCommunication3PpiGuid gEfiEndOfPeiSignalPpiGuid gMmCoreFvLocationPpiGuid + gEfiPeiMmAccessPpiGuid [Protocols] gEfiMmEndOfPeiProtocol