Revision: 18125
http://sourceforge.net/p/edk2/code/18125
Author: lgao4
Date: 2015-08-03 03:18:37 +0000 (Mon, 03 Aug 2015)
Log Message:
-----------
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 <[email protected]>
Modified Paths:
--------------
trunk/edk2/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
trunk/edk2/MdeModulePkg/Core/Pei/Image/Image.c
trunk/edk2/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.inf
trunk/edk2/MdeModulePkg/MdeModulePkg.dec
trunk/edk2/MdeModulePkg/MdeModulePkg.uni
Modified: trunk/edk2/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c 2015-08-03
02:59:55 UTC (rev 18124)
+++ trunk/edk2/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c 2015-08-03
03:18:37 UTC (rev 18125)
@@ -697,6 +697,9 @@
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 @@
// 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 @@
// 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);
Modified: trunk/edk2/MdeModulePkg/Core/Pei/Image/Image.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Pei/Image/Image.c 2015-08-03 02:59:55 UTC
(rev 18124)
+++ trunk/edk2/MdeModulePkg/Core/Pei/Image/Image.c 2015-08-03 03:18:37 UTC
(rev 18125)
@@ -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 @@
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 @@
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 @@
**/
EFI_STATUS
LoadAndRelocatePeCoffImage (
+ IN EFI_PEI_FILE_HANDLE FileHandle,
IN VOID *Pe32Data,
OUT EFI_PHYSICAL_ADDRESS *ImageAddress,
OUT UINT64 *ImageSize,
@@ -354,6 +357,8 @@
UINT64 AlignImageSize;
BOOLEAN IsXipImage;
EFI_STATUS ReturnStatus;
+ BOOLEAN IsS3Boot;
+ BOOLEAN IsRegisterForShadow;
Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
@@ -371,6 +376,19 @@
}
//
+ // 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.
//
if (ImageContext.ImageAddress == (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data) {
@@ -380,7 +398,8 @@
//
// 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 @@
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 @@
// If memory is installed, perform the shadow operations
//
Status = LoadAndRelocatePeCoffImage (
+ FileHandle,
Pe32Data,
&ImageAddress,
&ImageSize,
Modified: trunk/edk2/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c 2015-08-03 02:59:55 UTC
(rev 18124)
+++ trunk/edk2/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c 2015-08-03 03:18:37 UTC
(rev 18125)
@@ -259,7 +259,11 @@
// 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.
Modified: trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.inf
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.inf 2015-08-03 02:59:55 UTC
(rev 18124)
+++ trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.inf 2015-08-03 03:18:37 UTC
(rev 18125)
@@ -114,6 +114,7 @@
gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressRuntimeCodePageNumber ##
SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdLoadModuleAtFixAddressEnable ##
CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnS3Boot ##
CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot ##
CONSUMES
# [BootMode]
# S3_RESUME ## SOMETIMES_CONSUMES
Modified: trunk/edk2/MdeModulePkg/MdeModulePkg.dec
===================================================================
--- trunk/edk2/MdeModulePkg/MdeModulePkg.dec 2015-08-03 02:59:55 UTC (rev
18124)
+++ trunk/edk2/MdeModulePkg/MdeModulePkg.dec 2015-08-03 03:18:37 UTC (rev
18125)
@@ -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>
Modified: trunk/edk2/MdeModulePkg/MdeModulePkg.uni
===================================================================
--- trunk/edk2/MdeModulePkg/MdeModulePkg.uni 2015-08-03 02:59:55 UTC (rev
18124)
+++ trunk/edk2/MdeModulePkg/MdeModulePkg.uni 2015-08-03 03:18:37 UTC (rev
18125)
@@ -1694,6 +1694,18 @@
++++ ++ \ No newline at end of file
------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits