From e543936a70179d3f10b4efc49705673495f78a4e Mon Sep 17 00:00:00 2001 From: Hongbin1 Zhang Date: Tue, 17 Dec 2024 16:30:19 +0800 Subject: [PATCH 1/2] StandaloneMmPkg : Add MM core fv location PPI Add MM core FV location PPI, it will include MM core FV location which could be in FSP-I or Bootloader MM FV. 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 --- .../Include/Ppi/MmCoreFvLocationPpi.h | 34 +++++++++++++++++++ StandaloneMmPkg/StandaloneMmPkg.dec | 3 ++ 2 files changed, 37 insertions(+) create mode 100644 StandaloneMmPkg/Include/Ppi/MmCoreFvLocationPpi.h 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. From 3ff61d1d535d522cc0a5ebfe13286a93dcac4f46 Mon Sep 17 00:00:00 2001 From: Hongbin1 Zhang Date: Tue, 17 Dec 2024 16:36:07 +0800 Subject: [PATCH 2/2] StandaloneMmPkg/MmIpl : Add MM core fv location PPI support MmIpl should 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 | 47 ++++++++++++++++--- .../StandaloneMmIplPei/StandaloneMmIplPei.h | 1 + .../StandaloneMmIplPei/StandaloneMmIplPei.inf | 1 + 3 files changed, 43 insertions(+), 6 deletions(-) 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