diff options
author | Kun Qin <kuqin@microsoft.com> | 2025-04-04 16:54:38 -0700 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2025-06-19 06:17:18 +0000 |
commit | 73b0b5edaef19beb08b04869bc2e0f6328c9e604 (patch) | |
tree | 92622b167290903bea74656a40f7af070e1e9992 | |
parent | c72d6384347bc57109d75fd56f2a5cdb8a40d132 (diff) | |
download | edk2-73b0b5edaef19beb08b04869bc2e0f6328c9e604.zip edk2-73b0b5edaef19beb08b04869bc2e0f6328c9e604.tar.gz edk2-73b0b5edaef19beb08b04869bc2e0f6328c9e604.tar.bz2 |
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 <kun.qin@microsoft.com>
3 files changed, 81 insertions, 2 deletions
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c index 972f0a3..eda47b9 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;
@@ -694,6 +698,40 @@ ExecuteMmCoreFromMmram ( 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
//
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
@@ -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 01b947c..430e7c5 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h @@ -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>
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf index 9f446e8..c06899e 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf @@ -65,6 +65,7 @@ gEfiPeiMmCommunication3PpiGuid
gEfiEndOfPeiSignalPpiGuid
gMmCoreFvLocationPpiGuid
+ gEfiPeiMmAccessPpiGuid
[Protocols]
gEfiMmEndOfPeiProtocol
|