summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Core
diff options
context:
space:
mode:
authorCheng Sun <chengx.sun@intel.com>2023-12-21 10:45:22 +0800
committerLiming Gao <gaoliming@byosoft.com.cn>2023-12-25 12:57:18 +0800
commit1065536c64ab919ad5c207e50b82d4a88ac29ed8 (patch)
tree01e64774357fb4d95bf7d39250f89f8e34e79b73 /MdeModulePkg/Core
parentd01defe06b35eb3fe9c94e7b2e08a8762873f924 (diff)
downloadedk2-1065536c64ab919ad5c207e50b82d4a88ac29ed8.tar.gz
edk2-1065536c64ab919ad5c207e50b82d4a88ac29ed8.tar.bz2
edk2-1065536c64ab919ad5c207e50b82d4a88ac29ed8.zip
MdeModulePkg: Support customized FV Migration Information
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 MigrationInfo 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 MigrationInfo hob before migration. If MigrationInfo hobs exists, only migrate FVs recorded by hobs. If MigrationInfo 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: Ray Ni <ray.ni@intel.com> Cc: Guomin Jiang <guomin.jiang@intel.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn> Reviewed-by: Ray Ni <ray.ni@intel.com> Signed-off-by: Cheng Sun <chengx.sun@intel.com>
Diffstat (limited to 'MdeModulePkg/Core')
-rw-r--r--MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c84
-rw-r--r--MdeModulePkg/Core/Pei/Memory/MemoryServices.c40
-rw-r--r--MdeModulePkg/Core/Pei/PeiMain.h11
-rw-r--r--MdeModulePkg/Core/Pei/PeiMain.inf1
4 files changed, 63 insertions, 73 deletions
diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
index 5f32ebb560..4cd8c843cd 100644
--- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
+++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
@@ -1184,7 +1184,12 @@ EvacuateTempRam (
PEI_CORE_FV_HANDLE PeiCoreFvHandle;
EFI_PEI_CORE_FV_LOCATION_PPI *PeiCoreFvLocationPpi;
+ EFI_PEI_HOB_POINTERS Hob;
+ EDKII_MIGRATION_INFO *MigrationInfo;
+ TO_MIGRATE_FV_INFO *ToMigrateFvInfo;
+ UINT32 FvMigrationFlags;
EDKII_MIGRATED_FV_INFO MigratedFvInfo;
+ UINTN Index;
ASSERT (Private->PeiMemoryInstalled);
@@ -1211,6 +1216,13 @@ EvacuateTempRam (
ConvertPeiCorePpiPointers (Private, &PeiCoreFvHandle);
+ Hob.Raw = GetFirstGuidHob (&gEdkiiMigrationInfoGuid);
+ if (Hob.Raw != NULL) {
+ MigrationInfo = GET_GUID_HOB_DATA (Hob);
+ } else {
+ MigrationInfo = NULL;
+ }
+
for (FvIndex = 0; FvIndex < Private->FvCount; FvIndex++) {
FvHeader = Private->Fv[FvIndex].FvHeader;
ASSERT (FvHeader != NULL);
@@ -1224,20 +1236,33 @@ EvacuateTempRam (
)
)
{
- //
- // Allocate page to save the rebased PEIMs, the PEIMs will get dispatched later.
- //
- Status = PeiServicesAllocatePages (
- EfiBootServicesCode,
- EFI_SIZE_TO_PAGES ((UINTN)FvHeader->FvLength),
- &FvHeaderAddress
- );
- ASSERT_EFI_ERROR (Status);
- MigratedFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderAddress;
+ if ((MigrationInfo == NULL) || (MigrationInfo->MigrateAll == TRUE)) {
+ //
+ // Migrate all FVs and copy raw data
+ //
+ FvMigrationFlags = FLAGS_FV_RAW_DATA_COPY;
+ } else {
+ for (Index = 0; Index < MigrationInfo->ToMigrateFvCount; Index++) {
+ ToMigrateFvInfo = ((TO_MIGRATE_FV_INFO *)(MigrationInfo + 1)) + Index;
+ if (ToMigrateFvInfo->FvOrgBaseOnTempRam == (UINT32)(UINTN)FvHeader) {
+ //
+ // This FV is to migrate
+ //
+ FvMigrationFlags = ToMigrateFvInfo->FvMigrationFlags;
+ break;
+ }
+ }
+
+ if (Index == MigrationInfo->ToMigrateFvCount) {
+ //
+ // This FV is not expected to migrate
+ //
+ continue;
+ }
+ }
//
- // 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.
+ // Allocate pages to save the rebased PEIMs, the PEIMs will get dispatched later.
//
Status = PeiServicesAllocatePages (
EfiBootServicesCode,
@@ -1245,7 +1270,8 @@ EvacuateTempRam (
&FvHeaderAddress
);
ASSERT_EFI_ERROR (Status);
- RawDataFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderAddress;
+ MigratedFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)FvHeaderAddress;
+ CopyMem (MigratedFvHeader, FvHeader, (UINTN)FvHeader->FvLength);
DEBUG ((
DEBUG_VERBOSE,
@@ -1256,17 +1282,33 @@ 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.
+ // Create hob to save MigratedFvInfo, this hob will only be produced when
+ // Migration feature PCD PcdMigrateTemporaryRamFirmwareVolumes is set to TRUE.
//
- 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.FvDataBase = 0;
MigratedFvInfo.FvLength = (UINT32)(UINTN)FvHeader->FvLength;
+
+ //
+ // When FLAGS_FV_RAW_DATA_COPY bit is set, copy the context to the raw pages and
+ // reset raw data base address in MigratedFvInfo hob.
+ //
+ if ((FvMigrationFlags & FLAGS_FV_RAW_DATA_COPY) == FLAGS_FV_RAW_DATA_COPY) {
+ //
+ // Allocate pages to save the raw PEIMs
+ //
+ 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.FvDataBase = (UINT32)(UINTN)RawDataFvHeader;
+ }
+
BuildGuidDataHob (&gEdkiiMigratedFvInfoGuid, &MigratedFvInfo, sizeof (MigratedFvInfo));
//
@@ -1330,8 +1372,6 @@ EvacuateTempRam (
}
}
- RemoveFvHobsInTemporaryMemory (Private);
-
return Status;
}
diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
index 3b2e15699f..a30925da39 100644
--- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
+++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
@@ -167,46 +167,6 @@ MigrateMemoryPages (
}
/**
- Removes any FV HOBs whose base address is not in PEI installed memory.
-
- @param[in] Private Pointer to PeiCore's private data structure.
-
-**/
-VOID
-RemoveFvHobsInTemporaryMemory (
- IN PEI_CORE_INSTANCE *Private
- )
-{
- EFI_PEI_HOB_POINTERS Hob;
- EFI_HOB_FIRMWARE_VOLUME *FirmwareVolumeHob;
-
- DEBUG ((DEBUG_INFO, "Removing FVs in FV HOB not already migrated to permanent memory.\n"));
-
- for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
- if ((GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) || (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) || (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3)) {
- FirmwareVolumeHob = Hob.FirmwareVolume;
- DEBUG ((DEBUG_INFO, " Found FV HOB.\n"));
- DEBUG ((
- DEBUG_INFO,
- " BA=%016lx L=%016lx\n",
- FirmwareVolumeHob->BaseAddress,
- FirmwareVolumeHob->Length
- ));
- if (
- !(
- ((EFI_PHYSICAL_ADDRESS)(UINTN)FirmwareVolumeHob->BaseAddress >= Private->PhysicalMemoryBegin) &&
- (((EFI_PHYSICAL_ADDRESS)(UINTN)FirmwareVolumeHob->BaseAddress + (FirmwareVolumeHob->Length - 1)) < Private->FreePhysicalMemoryTop)
- )
- )
- {
- DEBUG ((DEBUG_INFO, " Removing FV HOB to an FV in T-RAM (was not migrated).\n"));
- Hob.Header->HobType = EFI_HOB_TYPE_UNUSED;
- }
- }
- }
-}
-
-/**
Migrate the base address in firmware volume allocation HOBs
from temporary memory to PEI installed memory.
diff --git a/MdeModulePkg/Core/Pei/PeiMain.h b/MdeModulePkg/Core/Pei/PeiMain.h
index 556beddad5..46b6c23014 100644
--- a/MdeModulePkg/Core/Pei/PeiMain.h
+++ b/MdeModulePkg/Core/Pei/PeiMain.h
@@ -1047,17 +1047,6 @@ MigrateMemoryPages (
);
/**
- Removes any FV HOBs whose base address is not in PEI installed memory.
-
- @param[in] Private Pointer to PeiCore's private data structure.
-
-**/
-VOID
-RemoveFvHobsInTemporaryMemory (
- IN PEI_CORE_INSTANCE *Private
- );
-
-/**
Migrate the base address in firmware volume allocation HOBs
from temporary memory to PEI installed memory.
diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiMain.inf
index 0cf357371a..893bdc0527 100644
--- a/MdeModulePkg/Core/Pei/PeiMain.inf
+++ b/MdeModulePkg/Core/Pei/PeiMain.inf
@@ -78,6 +78,7 @@
gEfiFirmwareFileSystem3Guid
gStatusCodeCallbackGuid
gEdkiiMigratedFvInfoGuid ## SOMETIMES_PRODUCES ## HOB
+ gEdkiiMigrationInfoGuid ## SOMETIMES_CONSUMES ## HOB
[Ppis]
gEfiPeiStatusCodePpiGuid ## SOMETIMES_CONSUMES # PeiReportStatusService is not ready if this PPI doesn't exist