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....@intel.com>
---
 MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c |  21 ++++++++++++++++++---
 MdeModulePkg/Core/Pei/Image/Image.c           |  25 +++++++++++++++++++++----
 MdeModulePkg/Core/Pei/PeiMain.inf             |   1 +
 MdeModulePkg/MdeModulePkg.dec                 |   7 +++++++
 MdeModulePkg/MdeModulePkg.uni                 | Bin 166792 -> 168226 bytes
 5 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c 
b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
index 3a85502..46e990d 100644
--- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
+++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
@@ -695,10 +695,13 @@ PeiDispatcher (
 
     for (Index1 = 0; Index1 <= SaveCurrentFvCount; Index1++) {
       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,
                     PEIM_STATE_REGISITER_FOR_SHADOW,
                     &EntryPoint,
@@ -707,13 +710,10 @@ PeiDispatcher (
           if (Status == EFI_SUCCESS) {
             //
             // 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
             //
             PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;
 
@@ -1106,10 +1106,25 @@ PeiDispatcher (
               //
               // If memory is availble we shadow images by default for 
performance reasons.
               // 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 cab08fe..865c92e 100644
--- a/MdeModulePkg/Core/Pei/Image/Image.c
+++ b/MdeModulePkg/Core/Pei/Image/Image.c
@@ -1,9 +1,9 @@
 /** @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
 http://opensource.org/licenses/bsd-license.php
 
@@ -115,11 +115,12 @@ GetImageReadFunction (
   PEI_CORE_INSTANCE  *Private;
   VOID*  MemoryBuffer;
 
   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 
     //  compilers that have been tested
     //
@@ -352,10 +353,12 @@ LoadAndRelocatePeCoffImage (
   PE_COFF_LOADER_IMAGE_CONTEXT          ImageContext;
   PEI_CORE_INSTANCE                     *Private;
   UINT64                                AlignImageSize;
   BOOLEAN                               IsXipImage;
   EFI_STATUS                            ReturnStatus;
+  BOOLEAN                               IsS3Boot;
+  BOOLEAN                               IsRegisterForShadow;
 
   Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());
 
   ReturnStatus = EFI_SUCCESS;
   IsXipImage   = FALSE;
@@ -369,20 +372,33 @@ LoadAndRelocatePeCoffImage (
   if (EFI_ERROR (Status)) {
     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->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) {
     IsXipImage = TRUE;
   }
 
   //
   // 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));
   }
 
   //
   // Set default base address to current image address.
@@ -390,11 +406,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.
   //
-  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.
     //
     if (ImageContext.IsTeImage) {
       AlignImageSize = ImageContext.ImageSize + ((EFI_TE_IMAGE_HEADER *) 
Pe32Data)->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER);
diff --git a/MdeModulePkg/Core/Pei/PeiMain.inf 
b/MdeModulePkg/Core/Pei/PeiMain.inf
index 0acac47..39a464f 100644
--- a/MdeModulePkg/Core/Pei/PeiMain.inf
+++ b/MdeModulePkg/Core/Pei/PeiMain.inf
@@ -112,10 +112,11 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressPeiCodePageNumber         ## 
SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressBootTimeCodePageNumber    ## 
SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressRuntimeCodePageNumber     ## 
SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadModuleAtFixAddressEnable            ## 
CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnS3Boot                      ## 
CONSUMES 
+  gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot                        ## 
CONSUMES 
 
 # [BootMode]
 # S3_RESUME             ## SOMETIMES_CONSUMES
 
 # [Hob]
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 4a1acac..11e2b5d 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -884,10 +884,17 @@
   #   TRUE  - Shadow PEIM on S3 boot path after memory is ready.<BR>
   #   FALSE - Not shadow PEIM on S3 boot path after memory is ready.<BR>
   # @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>
   # @Prompt Memory Profile Property.
   # @Expression  0x80000002 | 
(gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryProfilePropertyMask & 0xFC) == 0
diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni
index 
e90e7d1e8fdeb0ead04bf689ddf83c1237aba855..53368aefe50901fc5ef837d5ed3fb11cf4ee8a32
 100644
GIT binary patch
delta 247
zcmeB}&b4R}S3?Wq7N(Bw=?+~?Nt1u96r22KRe@+CLmop4g91YULn=cigEK=uLlHyj
z<j&QulbwXtOm2v0n|^CIBj5A|rHlgn`9QS_Kounn89>!VlRvH%*G^@qU`Ph?3V@;t
z3~6Bf3Jk#v#z0;YkOxw&#}EV5sWjP9Xzk>NHCj0BG@tx$4I9|r3H3sgPpnm#+_Tz*
hS&4yba^tG<$wI3_^su@X>?V-QVD>37@G@`#Apmo=M7;n2

delta 13
UcmZ3qh^u2dS3?Wq7N(AF047QWMgRZ+

-- 
1.9.5.msysgit.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to