From 3d44658ca89b36a492ba2ab648617d53be2693fd Mon Sep 17 00:00:00 2001 From: Liming Gao Date: Mon, 3 Aug 2015 03:18:37 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18125 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 21 +++++++++-- MdeModulePkg/Core/Pei/Image/Image.c | 33 +++++++++++++++--- MdeModulePkg/Core/Pei/PeiMain.inf | 1 + MdeModulePkg/Core/Pei/PeiMain/PeiMain.c | 6 +++- MdeModulePkg/MdeModulePkg.dec | 7 ++++ MdeModulePkg/MdeModulePkg.uni | Bin 178908 -> 180322 bytes 6 files changed, 59 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c index 3a85502dbe..46e990d75d 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -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); diff --git a/MdeModulePkg/Core/Pei/Image/Image.c b/MdeModulePkg/Core/Pei/Image/Image.c index cab08fed91..9c54192d86 100644 --- a/MdeModulePkg/Core/Pei/Image/Image.c +++ b/MdeModulePkg/Core/Pei/Image/Image.c @@ -1,7 +1,7 @@ /** @file Pei Core Load Image Support -Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
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, diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf b/MdeModulePkg/Core/Pei/PeiMain.inf index 0acac47c1f..39a464f326 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.inf +++ b/MdeModulePkg/Core/Pei/PeiMain.inf @@ -114,6 +114,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressRuntimeCodePageNumber ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdLoadModuleAtFixAddressEnable ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnS3Boot ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot ## CONSUMES # [BootMode] # S3_RESUME ## SOMETIMES_CONSUMES diff --git a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c index 05e0d0fda4..d36f89c3dd 100644 --- a/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c +++ b/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c @@ -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. diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 25e3e1d019..9b47a947dd 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -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.

+ # This PCD is used on other boot path except for S3 boot. + # TRUE - Shadow PEIM and PeiCore after memory is ready.
+ # FALSE - Not shadow PEIM after memory is ready.
+ # @Prompt Shadow Peim and PeiCore on boot + gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot|TRUE|BOOLEAN|0x30001029 + ## The mask is used to control memory profile behavior.

# BIT0 - Enable UEFI memory profile.
# BIT1 - Enable SMRAM profile.
diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index 77422a3465507d8a1d5f866b4d9853f7388052c5..ec2750f44b2c4338982cc795fbd2b494bff8baf1 100644 GIT binary patch delta 205 zcmccfmFrOhcS8%~7N#4!CbN~rP5!Y`Z1SH~1)_-zc?>BG3Jd`ZsSKG6&J6hsMGUEv zJ6C_6+z`(;{nlfT9WvX<)qy z48aV>Kwc6<{`C4qOuHvHtkJ@0iTUJzYqm_DP%kw3#9D>PJ*!P7%QR$wohGy@L;_+Z P&>*n2N({UVTwn|UzM?=L delta 18 ZcmaFVz