From 2034f514f61ab91c33294bc795d400896925a4c1 Mon Sep 17 00:00:00 2001 From: Hongbin1 Zhang Date: Tue, 17 Dec 2024 16:36:07 +0800 Subject: [PATCH] StandaloneMmPkg/MmIpl : Add MM core fv location PPI support MmIpl could locate MM core FV location PPI to find current MM FV location. Signed-off-by: Hongbin1 Zhang Cc: Jiewen Yao Cc: Ray Ni Cc: Star Zeng Cc: Jiaxin Wu Cc: Wei6 Xu Cc: Sami Mujawar Cc: Ard Biesheuvel Cc: Supreeth Venkatesh --- .../StandaloneMmIplPei/StandaloneMmIplPei.c | 44 ++++++++++++++++--- .../StandaloneMmIplPei/StandaloneMmIplPei.h | 1 + .../StandaloneMmIplPei/StandaloneMmIplPei.inf | 1 + 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c index 1a01d7a465c57..3d5c9c1e21be6 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c @@ -147,12 +147,44 @@ LocateMmCoreFv ( OUT VOID **MmCoreImageAddress ) { - EFI_STATUS Status; - UINTN FvIndex; - EFI_PEI_FV_HANDLE VolumeHandle; - EFI_PEI_FILE_HANDLE FileHandle; - EFI_PE32_SECTION *SectionData; - EFI_FV_INFO VolumeInfo; + EFI_STATUS Status; + UINTN FvIndex; + EFI_PEI_FV_HANDLE VolumeHandle; + EFI_PEI_FILE_HANDLE FileHandle; + EFI_PE32_SECTION *SectionData; + EFI_FV_INFO VolumeInfo; + MM_CORE_FV_LOCATION_PPI *MmCoreFvLocation; + + // + // MmIpl should locate MM Core FV location PPI to find the MM core FV. + // + Status = PeiServicesLocatePpi (&gMmCoreFvLocationPpiGuid, 0, NULL, (VOID **)&MmCoreFvLocation); + if (Status == EFI_SUCCESS) { + *MmFvBase = MmCoreFvLocation->Address; + *MmFvSize = MmCoreFvLocation->Size; + FileHandle = NULL; + Status = PeiServicesFfsFindNextFile (EFI_FV_FILETYPE_MM_CORE_STANDALONE, (VOID *)(UINTN)MmCoreFvLocation->Address, &FileHandle); + ASSERT_EFI_ERROR (Status); + if (Status == EFI_SUCCESS) { + ASSERT (FileHandle != NULL); + if (FileHandle != NULL) { + CopyGuid (MmCoreFileName, &((EFI_FFS_FILE_HEADER *)FileHandle)->Name); + // + // Search Section + // + Status = PeiServicesFfsFindSectionData (EFI_SECTION_PE32, FileHandle, MmCoreImageAddress); + ASSERT_EFI_ERROR (Status); + + // + // Get MM Core section data. + // + SectionData = (EFI_PE32_SECTION *)((UINT8 *)*MmCoreImageAddress - sizeof (EFI_PE32_SECTION)); + ASSERT (SectionData->Type == EFI_SECTION_PE32); + } + } + + return EFI_SUCCESS; + } // // Search all FV diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h index 9301b8f3f5c4b..e385c7768dd56 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf index dfc181218ed08..f07f26ee4144c 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf @@ -61,6 +61,7 @@ gEfiPeiMmControlPpiGuid gEfiPeiMmCommunicationPpiGuid gEfiEndOfPeiSignalPpiGuid + gMmCoreFvLocationPpiGuid [Protocols] gEfiMmEndOfPeiProtocol