* [edk2-devel] [PATCH v3 1/1] MdeModulePkg: Support customized FV Migration Information
@ 2023-10-27 7:27 Wang Fan
0 siblings, 0 replies; only message in thread
From: Wang Fan @ 2023-10-27 7:27 UTC (permalink / raw)
To: devel; +Cc: Fan Wang, Michael D Kinney, Liming Gao, Guomin Jiang, Dandan Bi
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4533
There are use cases which not all FVs need be migrated from TempRam to
permanent memory before TempRam tears down. This new guid is introduced
to avoid unnecessary FV migration to improve boot performance. Platform
can publish ToMigrateFvInfo hob with this guid to customize FV migration
info, and PeiCore will only migrate FVs indicated by this Hob info.
This is a backwards compatible change, PeiCore will check ToMigrateFvInfo
hob before migration. If ToMigrateFvInfo hobs exists, only migrate FVs
recorded by hobs. If ToMigrateFvInfo hobs not exists, migrate all FVs to
permanent memory.
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Signed-off-by: Fan Wang <fan.wang@intel.com>
---
MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 79 +++++++++++++------
MdeModulePkg/Core/Pei/PeiMain.inf | 1 +
MdeModulePkg/Include/Guid/MigratedFvInfo.h | 28 +++++++
MdeModulePkg/MdeModulePkg.dec | 3 +-
4 files changed, 84 insertions(+), 27 deletions(-)
diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
index 5f32ebb560ae..a50fa1ad586f 100644
--- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
+++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
@@ -1184,7 +1184,10 @@ EvacuateTempRam (
PEI_CORE_FV_HANDLE PeiCoreFvHandle;
EFI_PEI_CORE_FV_LOCATION_PPI *PeiCoreFvLocationPpi;
+ EDKII_TO_MIGRATE_FV_INFO *ToMigrateFvInfo;
EDKII_MIGRATED_FV_INFO MigratedFvInfo;
+ EFI_PEI_HOB_POINTERS Hob;
+ UINT32 MigrationFlags;
ASSERT (Private->PeiMemoryInstalled);
@@ -1225,7 +1228,32 @@ EvacuateTempRam (
)
{
//
- // Allocate page to save the rebased PEIMs, the PEIMs will get dispatched later.
+ // Check if platform defined hobs to indicate which FVs are expected to migrate or keep raw data.
+ // If ToMigrateFvInfo hobs exists, only migrate FVs recorded by hobs.
+ // If ToMigrateFvInfo hobs not exists, migrate all FVs to permanent memory.
+ //
+ Hob.Raw = GetFirstGuidHob (&gEdkiiToMigrateFvInfoGuid);
+ if (Hob.Raw == NULL) {
+ MigrationFlags = 0;
+ } else {
+ while (Hob.Raw != NULL) {
+ ToMigrateFvInfo = GET_GUID_HOB_DATA (Hob);
+ if (ToMigrateFvInfo->FvTemporaryRamBase == (UINT32)(UINTN)FvHeader) {
+ MigrationFlags = ToMigrateFvInfo->MigrationFlags;
+ break;
+ }
+
+ Hob.Raw = GET_NEXT_HOB (Hob);
+ Hob.Raw = GetNextGuidHob (&gEdkiiToMigrateFvInfoGuid, Hob.Raw);
+ }
+
+ if (Hob.Raw == NULL) {
+ continue;
+ }
+ }
+
+ //
+ // Allocate pages to save the rebased PEIMs, the PEIMs will get dispatched later.
//
Status = PeiServicesAllocatePages (
EfiBootServicesCode,
@@ -1234,18 +1262,7 @@ EvacuateTempRam (
);
ASSERT_EFI_ERROR (Status);
MigratedFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderAddress;
-
- //
- // Allocate pool to save the raw PEIMs, which is used to keep consistent context across
- // multiple boot and PCR0 will keep the same no matter if the address of allocated page is changed.
- //
- Status = PeiServicesAllocatePages (
- EfiBootServicesCode,
- EFI_SIZE_TO_PAGES ((UINTN)FvHeader->FvLength),
- &FvHeaderAddress
- );
- ASSERT_EFI_ERROR (Status);
- RawDataFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderAddress;
+ CopyMem (MigratedFvHeader, FvHeader, (UINTN)FvHeader->FvLength);
DEBUG ((
DEBUG_VERBOSE,
@@ -1256,18 +1273,30 @@ EvacuateTempRam (
));
//
- // Copy the context to the rebased pages and raw pages, and create hob to save the
- // information. The MigratedFvInfo HOB will never be produced when
- // PcdMigrateTemporaryRamFirmwareVolumes is FALSE, because the PCD control the
- // feature.
+ // Copy the context to the raw pages and create hob to save the information. The MigratedFvInfo
+ // HOB will never be produced when PcdMigrateTemporaryRamFirmwareVolumes is FALSE, because the PCD
+ // controls the feature. This copy can be skipped by FLAGS_SKIP_FV_RAW_DATA_COPY flag to optimize
+ // boot performance.
//
- CopyMem (MigratedFvHeader, FvHeader, (UINTN)FvHeader->FvLength);
- CopyMem (RawDataFvHeader, MigratedFvHeader, (UINTN)FvHeader->FvLength);
- MigratedFvInfo.FvOrgBase = (UINT32)(UINTN)FvHeader;
- MigratedFvInfo.FvNewBase = (UINT32)(UINTN)MigratedFvHeader;
- MigratedFvInfo.FvDataBase = (UINT32)(UINTN)RawDataFvHeader;
- MigratedFvInfo.FvLength = (UINT32)(UINTN)FvHeader->FvLength;
- BuildGuidDataHob (&gEdkiiMigratedFvInfoGuid, &MigratedFvInfo, sizeof (MigratedFvInfo));
+ if ((MigrationFlags & FLAGS_SKIP_FV_RAW_DATA_COPY) != FLAGS_SKIP_FV_RAW_DATA_COPY) {
+ //
+ // Allocate pages to save the raw PEIMs, which is used to keep consistent context across
+ // multiple boot and PCR0 will keep the same no matter if the address of allocated page is changed.
+ //
+ Status = PeiServicesAllocatePages (
+ EfiBootServicesCode,
+ EFI_SIZE_TO_PAGES ((UINTN)FvHeader->FvLength),
+ &FvHeaderAddress
+ );
+ ASSERT_EFI_ERROR (Status);
+ RawDataFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderAddress;
+ CopyMem (RawDataFvHeader, MigratedFvHeader, (UINTN)FvHeader->FvLength);
+ MigratedFvInfo.FvOrgBase = (UINT32)(UINTN)FvHeader;
+ MigratedFvInfo.FvNewBase = (UINT32)(UINTN)MigratedFvHeader;
+ MigratedFvInfo.FvDataBase = (UINT32)(UINTN)RawDataFvHeader;
+ MigratedFvInfo.FvLength = (UINT32)(UINTN)FvHeader->FvLength;
+ BuildGuidDataHob (&gEdkiiMigratedFvInfoGuid, &MigratedFvInfo, sizeof (MigratedFvInfo));
+ }
//
// Migrate any children for this FV now
@@ -1330,8 +1359,6 @@ EvacuateTempRam (
}
}
- RemoveFvHobsInTemporaryMemory (Private);
-
return Status;
}
diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiMain.inf
index 0cf357371a16..944b230b0e19 100644
--- a/MdeModulePkg/Core/Pei/PeiMain.inf
+++ b/MdeModulePkg/Core/Pei/PeiMain.inf
@@ -78,6 +78,7 @@
gEfiFirmwareFileSystem3Guid
gStatusCodeCallbackGuid
gEdkiiMigratedFvInfoGuid ## SOMETIMES_PRODUCES ## HOB
+ gEdkiiToMigrateFvInfoGuid ## SOMETIMES_CONSUMES ## HOB
[Ppis]
gEfiPeiStatusCodePpiGuid ## SOMETIMES_CONSUMES # PeiReportStatusService is not ready if this PPI doesn't exist
diff --git a/MdeModulePkg/Include/Guid/MigratedFvInfo.h b/MdeModulePkg/Include/Guid/MigratedFvInfo.h
index aca2332a0ec6..b019e9f20df1 100644
--- a/MdeModulePkg/Include/Guid/MigratedFvInfo.h
+++ b/MdeModulePkg/Include/Guid/MigratedFvInfo.h
@@ -9,6 +9,33 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#ifndef __EDKII_MIGRATED_FV_INFO_GUID_H__
#define __EDKII_MIGRATED_FV_INFO_GUID_H__
+//
+// FLAGS_SKIP_FV_RAW_DATA_COPY indicates FV raw data will be skipped copy to permanent
+// memory or not. When FV is migrated to permanent memory, it will be rebased and raw
+// data will be lost. This bit can be configured as below values:
+// 0: FV raw data will be copied to permanent memory for later phase use.
+// 1: FV raw data will not be consumed in later phase, and the copy will be skipped to
+// optimize boot performance.
+//
+#define FLAGS_SKIP_FV_RAW_DATA_COPY BIT0
+
+///
+/// In real use cases, not all FVs need migrate to permanent memory before TempRam tears
+/// down. EDKII_TO_MIGRATE_FV_INFO hob can be published by platform to indicate only selected
+/// FVs need migration, and other FVs should be skipped to optimize boot performance.
+/// If no such hobs are published, PEI Core should still migrate all FVs on TempRam when this
+/// feature is enabled.
+///
+typedef struct {
+ UINT32 FvTemporaryRamBase; // Original FV address on Temporary Ram
+ //
+ // Migration Flags:
+ // Bit0: Indicate to skip FV raw data copy or not
+ // Others: Reserved bits
+ //
+ UINT32 MigrationFlags;
+} EDKII_TO_MIGRATE_FV_INFO;
+
typedef struct {
UINT32 FvOrgBase; // original FV address
UINT32 FvNewBase; // new FV address
@@ -16,6 +43,7 @@ typedef struct {
UINT32 FvLength; // Fv Length
} EDKII_MIGRATED_FV_INFO;
+extern EFI_GUID gEdkiiToMigrateFvInfoGuid;
extern EFI_GUID gEdkiiMigratedFvInfoGuid;
#endif // #ifndef __EDKII_MIGRATED_FV_INFO_GUID_H__
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index dd182c02fdf6..d6cbcc721a5e 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -416,7 +416,8 @@
gEdkiiCapsuleOnDiskNameGuid = { 0x98c80a4f, 0xe16b, 0x4d11, { 0x93, 0x9a, 0xab, 0xe5, 0x61, 0x26, 0x3, 0x30 } }
## Include/Guid/MigratedFvInfo.h
- gEdkiiMigratedFvInfoGuid = { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf4, 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } }
+ gEdkiiToMigrateFvInfoGuid = { 0xb4b140a5, 0x72f6, 0x4c21, { 0x93, 0xe4, 0xac, 0xc4, 0xec, 0xcb, 0x23, 0x23 } }
+ gEdkiiMigratedFvInfoGuid = { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf4, 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } }
## Include/Guid/RngAlgorithm.h
gEdkiiRngAlgorithmUnSafe = { 0x869f728c, 0x409d, 0x4ab4, {0xac, 0x03, 0x71, 0xd3, 0x09, 0xc1, 0xb3, 0xf4 }}
--
2.29.2.windows.2
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110197): https://edk2.groups.io/g/devel/message/110197
Mute This Topic: https://groups.io/mt/102216459/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-10-27 7:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-27 7:27 [edk2-devel] [PATCH v3 1/1] MdeModulePkg: Support customized FV Migration Information Wang Fan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox