mirror of https://github.com/acidanthera/audk.git
MdeModulePkg PeiCore: Add PCD to specify PEIM Shadow
v2 changelog: Check CurrentPeimHandle to check the matched PeimHandle. Add check point to ShadowPeiCore based on PCD. v1 changelog: PeiCore LoadImage always shadow itself and PEIM on normal boot after the physical memory is installed. On the emulator platform, the shadow may be not necessary. To support such usage, new PCD PcdShadowPeimOnBoot is introduced to specify whether loads PEIM in memory by default. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18125 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
496b0dd00c
commit
3d44658ca8
|
@ -697,6 +697,9 @@ PeiDispatcher (
|
|||
for (Index2 = 0; (Index2 < PcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {
|
||||
if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISITER_FOR_SHADOW) {
|
||||
PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2];
|
||||
Private->CurrentFileHandle = PeimFileHandle;
|
||||
Private->CurrentPeimFvCount = Index1;
|
||||
Private->CurrentPeimCount = Index2;
|
||||
Status = PeiLoadImage (
|
||||
(CONST EFI_PEI_SERVICES **) &Private->Ps,
|
||||
PeimFileHandle,
|
||||
|
@ -709,9 +712,6 @@ PeiDispatcher (
|
|||
// PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE
|
||||
//
|
||||
Private->Fv[Index1].PeimState[Index2]++;
|
||||
Private->CurrentFileHandle = PeimFileHandle;
|
||||
Private->CurrentPeimFvCount = Index1;
|
||||
Private->CurrentPeimCount = Index2;
|
||||
//
|
||||
// Call the PEIM entry point
|
||||
//
|
||||
|
@ -1108,6 +1108,21 @@ PeiDispatcher (
|
|||
// We call the entry point a 2nd time so the module knows it's shadowed.
|
||||
//
|
||||
//PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);
|
||||
if ((Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) && !PcdGetBool (PcdShadowPeimOnBoot)) {
|
||||
//
|
||||
// Load PEIM into Memory for Register for shadow PEIM.
|
||||
//
|
||||
Status = PeiLoadImage (
|
||||
PeiServices,
|
||||
PeimFileHandle,
|
||||
PEIM_STATE_REGISITER_FOR_SHADOW,
|
||||
&EntryPoint,
|
||||
&AuthenticationState
|
||||
);
|
||||
if (Status == EFI_SUCCESS) {
|
||||
PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;
|
||||
}
|
||||
}
|
||||
ASSERT (PeimEntryPoint != NULL);
|
||||
PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);
|
||||
//PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/** @file
|
||||
Pei Core Load Image Support
|
||||
|
||||
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -117,7 +117,8 @@ GetImageReadFunction (
|
|||
|
||||
Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
|
||||
|
||||
if (Private->PeiMemoryInstalled && ((Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) || PcdGetBool (PcdShadowPeimOnS3Boot)) &&
|
||||
if (Private->PeiMemoryInstalled && (((Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnBoot)) ||
|
||||
((Private->HobList.HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnS3Boot))) &&
|
||||
(EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_X64) || EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_IA32))) {
|
||||
//
|
||||
// Shadow algorithm makes lots of non ANSI C assumptions and only works for IA32 and X64
|
||||
|
@ -328,6 +329,7 @@ GetPeCoffImageFixLoadingAssignedAddress(
|
|||
Loads and relocates a PE/COFF image into memory.
|
||||
If the image is not relocatable, it will not be loaded into memory and be loaded as XIP image.
|
||||
|
||||
@param FileHandle - Pointer to the FFS file header of the image.
|
||||
@param Pe32Data - The base address of the PE/COFF file that is to be loaded and relocated
|
||||
@param ImageAddress - The base address of the relocated PE/COFF image
|
||||
@param ImageSize - The size of the relocated PE/COFF image
|
||||
|
@ -342,6 +344,7 @@ GetPeCoffImageFixLoadingAssignedAddress(
|
|||
**/
|
||||
EFI_STATUS
|
||||
LoadAndRelocatePeCoffImage (
|
||||
IN EFI_PEI_FILE_HANDLE FileHandle,
|
||||
IN VOID *Pe32Data,
|
||||
OUT EFI_PHYSICAL_ADDRESS *ImageAddress,
|
||||
OUT UINT64 *ImageSize,
|
||||
|
@ -354,6 +357,8 @@ LoadAndRelocatePeCoffImage (
|
|||
UINT64 AlignImageSize;
|
||||
BOOLEAN IsXipImage;
|
||||
EFI_STATUS ReturnStatus;
|
||||
BOOLEAN IsS3Boot;
|
||||
BOOLEAN IsRegisterForShadow;
|
||||
|
||||
Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
|
||||
|
||||
|
@ -370,6 +375,19 @@ LoadAndRelocatePeCoffImage (
|
|||
return Status;
|
||||
}
|
||||
|
||||
//
|
||||
// Initilize local IsS3Boot and IsRegisterForShadow variable
|
||||
//
|
||||
IsS3Boot = FALSE;
|
||||
if (Private->HobList.HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME) {
|
||||
IsS3Boot = TRUE;
|
||||
}
|
||||
IsRegisterForShadow = FALSE;
|
||||
if ((Private->CurrentFileHandle == FileHandle)
|
||||
&& (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW)) {
|
||||
IsRegisterForShadow = TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// XIP image that ImageAddress is same to Image handle.
|
||||
//
|
||||
|
@ -380,7 +398,8 @@ LoadAndRelocatePeCoffImage (
|
|||
//
|
||||
// When Image has no reloc section, it can't be relocated into memory.
|
||||
//
|
||||
if (ImageContext.RelocationsStripped && (Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {
|
||||
if (ImageContext.RelocationsStripped && (Private->PeiMemoryInstalled) && (
|
||||
(!IsS3Boot && (PcdGetBool (PcdShadowPeimOnBoot) || IsRegisterForShadow)) || (IsS3Boot && PcdGetBool (PcdShadowPeimOnS3Boot)))) {
|
||||
DEBUG ((EFI_D_INFO|EFI_D_LOAD, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN) Pe32Data));
|
||||
}
|
||||
|
||||
|
@ -390,9 +409,12 @@ LoadAndRelocatePeCoffImage (
|
|||
ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data;
|
||||
|
||||
//
|
||||
// Allocate Memory for the image when memory is ready, boot mode is not S3, and image is relocatable.
|
||||
// Allocate Memory for the image when memory is ready, and image is relocatable.
|
||||
// On normal boot, PcdShadowPeimOnBoot decides whether load PEIM or PeiCore into memory.
|
||||
// On S3 boot, PcdShadowPeimOnS3Boot decides whether load PEIM or PeiCore into memory.
|
||||
//
|
||||
if ((!ImageContext.RelocationsStripped) && (Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {
|
||||
if ((!ImageContext.RelocationsStripped) && (Private->PeiMemoryInstalled) && (
|
||||
(!IsS3Boot && (PcdGetBool (PcdShadowPeimOnBoot) || IsRegisterForShadow)) || (IsS3Boot && PcdGetBool (PcdShadowPeimOnS3Boot)))) {
|
||||
//
|
||||
// Allocate more buffer to avoid buffer overflow.
|
||||
//
|
||||
|
@ -571,6 +593,7 @@ PeiLoadImageLoadImage (
|
|||
// If memory is installed, perform the shadow operations
|
||||
//
|
||||
Status = LoadAndRelocatePeCoffImage (
|
||||
FileHandle,
|
||||
Pe32Data,
|
||||
&ImageAddress,
|
||||
&ImageSize,
|
||||
|
|
|
@ -114,6 +114,7 @@
|
|||
gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressRuntimeCodePageNumber ## SOMETIMES_CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdLoadModuleAtFixAddressEnable ## CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnS3Boot ## CONSUMES
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot ## CONSUMES
|
||||
|
||||
# [BootMode]
|
||||
# S3_RESUME ## SOMETIMES_CONSUMES
|
||||
|
|
|
@ -259,7 +259,11 @@ PeiCore (
|
|||
// Shadow PEI Core. When permanent memory is avaiable, shadow
|
||||
// PEI Core and PEIMs to get high performance.
|
||||
//
|
||||
OldCoreData->ShadowedPeiCore = ShadowPeiCore (OldCoreData);
|
||||
OldCoreData->ShadowedPeiCore = (PEICORE_FUNCTION_POINTER) (UINTN) PeiCore;
|
||||
if ((HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME && PcdGetBool (PcdShadowPeimOnS3Boot))
|
||||
|| (HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME && PcdGetBool (PcdShadowPeimOnBoot))) {
|
||||
OldCoreData->ShadowedPeiCore = ShadowPeiCore (OldCoreData);
|
||||
}
|
||||
|
||||
//
|
||||
// PEI Core has now been shadowed to memory. Restart PEI Core in memory.
|
||||
|
|
|
@ -889,6 +889,13 @@
|
|||
# @Prompt Shadow Peim On S3 Boot.
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnS3Boot|FALSE|BOOLEAN|0x30001028
|
||||
|
||||
## Indicates if to shadow PEIM and PeiCore after memory is ready.<BR><BR>
|
||||
# This PCD is used on other boot path except for S3 boot.
|
||||
# TRUE - Shadow PEIM and PeiCore after memory is ready.<BR>
|
||||
# FALSE - Not shadow PEIM after memory is ready.<BR>
|
||||
# @Prompt Shadow Peim and PeiCore on boot
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot|TRUE|BOOLEAN|0x30001029
|
||||
|
||||
## The mask is used to control memory profile behavior.<BR><BR>
|
||||
# BIT0 - Enable UEFI memory profile.<BR>
|
||||
# BIT1 - Enable SMRAM profile.<BR>
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue