diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c index 1a01d7a465c5..d8112b0fef42 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c @@ -147,12 +147,47 @@ 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; + + // + // The producer of the MmCoreFvLocation PPI is responsible for ensuring + // that it reports the correct Firmware Volume (FV) containing the MmCore. + // If the gMmCoreFvLocationPpiGuid is not found, the system will search + // all Firmware Volumes (FVs) to locate the FV that contains the MM Core. + // + 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 9301b8f3f5c4..e385c7768dd5 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 dfc181218ed0..f07f26ee4144 100644 --- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf +++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.inf @@ -61,6 +61,7 @@ gEfiPeiMmControlPpiGuid gEfiPeiMmCommunicationPpiGuid gEfiEndOfPeiSignalPpiGuid + gMmCoreFvLocationPpiGuid [Protocols] gEfiMmEndOfPeiProtocol diff --git a/StandaloneMmPkg/Include/Ppi/MmCoreFvLocationPpi.h b/StandaloneMmPkg/Include/Ppi/MmCoreFvLocationPpi.h new file mode 100644 index 000000000000..5769ac421211 --- /dev/null +++ b/StandaloneMmPkg/Include/Ppi/MmCoreFvLocationPpi.h @@ -0,0 +1,34 @@ +/** @file + MM Core FV location PPI header file. + + MM Core FV location PPI is used by StandaloneMm IPL to find MM Core. + + Copyright (c) 2024, Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MM_CORE_FV_LOCATION_PPI_H_ +#define MM_CORE_FV_LOCATION_PPI_H_ + +#pragma pack(1) + +/// +/// Global ID for the MM_CORE_FV_LOCATION_PPI. +/// +#define MM_CORE_FV_LOCATION_GUID \ + { \ + 0x47a00618, 0x237a, 0x4386, { 0x8f, 0xc5, 0x2a, 0x86, 0xd8, 0xac, 0x41, 0x05 } \ + } + +typedef struct { + EFI_PHYSICAL_ADDRESS Address; + UINT64 Size; +} MM_CORE_FV_LOCATION_PPI; + +extern EFI_GUID gMmCoreFvLocationPpiGuid; + +#pragma pack() + +#endif diff --git a/StandaloneMmPkg/StandaloneMmPkg.dec b/StandaloneMmPkg/StandaloneMmPkg.dec index 5ac57c1013c5..dc2313ea1218 100644 --- a/StandaloneMmPkg/StandaloneMmPkg.dec +++ b/StandaloneMmPkg/StandaloneMmPkg.dec @@ -51,6 +51,9 @@ gEventMmDispatchGuid = { 0x7e6efffa, 0x69b4, 0x4c1b, { 0xa4, 0xc7, 0xaf, 0xf9, 0xc9, 0x24, 0x4f, 0xee }} +[Ppis] + gMmCoreFvLocationPpiGuid = { 0x47a00618, 0x237a, 0x4386, { 0x8f, 0xc5, 0x2a, 0x86, 0xd8, 0xac, 0x41, 0x05 }} + [PcdsFixedAtBuild, PcdsPatchableInModule] ## Maximum permitted encapsulation levels of sections in a firmware volume, # in the MM phase. Minimum value is 1. Sections nested more deeply are rejected.