]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg PeiCore: Add PCD to specify PEIM Shadow
authorLiming Gao <liming.gao@intel.com>
Mon, 3 Aug 2015 03:18:37 +0000 (03:18 +0000)
committerlgao4 <lgao4@Edk2>
Mon, 3 Aug 2015 03:18:37 +0000 (03:18 +0000)
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

MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
MdeModulePkg/Core/Pei/Image/Image.c
MdeModulePkg/Core/Pei/PeiMain.inf
MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/MdeModulePkg.uni

index 3a85502dbe5ff2c3c32f9c2ca43226a444711944..46e990d75df06532803d16ace2822e2861e55af2 100644 (file)
@@ -697,6 +697,9 @@ PeiDispatcher (
       for (Index2 = 0; (Index2 < PcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {\r
         if (Private->Fv[Index1].PeimState[Index2] == PEIM_STATE_REGISITER_FOR_SHADOW) {\r
           PeimFileHandle = Private->Fv[Index1].FvFileHandles[Index2];\r
+          Private->CurrentFileHandle   = PeimFileHandle;\r
+          Private->CurrentPeimFvCount  = Index1;\r
+          Private->CurrentPeimCount    = Index2;\r
           Status = PeiLoadImage (\r
                     (CONST EFI_PEI_SERVICES **) &Private->Ps,\r
                     PeimFileHandle,\r
@@ -709,9 +712,6 @@ PeiDispatcher (
             // PEIM_STATE_REGISITER_FOR_SHADOW move to PEIM_STATE_DONE\r
             //\r
             Private->Fv[Index1].PeimState[Index2]++;\r
-            Private->CurrentFileHandle   = PeimFileHandle;\r
-            Private->CurrentPeimFvCount  = Index1;\r
-            Private->CurrentPeimCount    = Index2;\r
             //\r
             // Call the PEIM entry point\r
             //\r
@@ -1108,6 +1108,21 @@ PeiDispatcher (
               // We call the entry point a 2nd time so the module knows it's shadowed.\r
               //\r
               //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r
+              if ((Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) && !PcdGetBool (PcdShadowPeimOnBoot)) {\r
+                //\r
+                // Load PEIM into Memory for Register for shadow PEIM.\r
+                //\r
+                Status = PeiLoadImage (\r
+                           PeiServices,\r
+                           PeimFileHandle,\r
+                           PEIM_STATE_REGISITER_FOR_SHADOW,\r
+                           &EntryPoint,\r
+                           &AuthenticationState\r
+                           );\r
+                if (Status == EFI_SUCCESS) {\r
+                  PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r
+                }\r
+              }\r
               ASSERT (PeimEntryPoint != NULL);\r
               PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r
               //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);\r
index cab08fed91db52dfb2699e665f18d3e765f1165f..9c54192d86b7366c3ccedc608207e6c26b75ee4c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Pei Core Load Image Support\r
 \r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -117,7 +117,8 @@ GetImageReadFunction (
 \r
   Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
   \r
-  if (Private->PeiMemoryInstalled  && ((Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) || PcdGetBool (PcdShadowPeimOnS3Boot))  &&\r
+  if (Private->PeiMemoryInstalled  && (((Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnBoot)) || \r
+      ((Private->HobList.HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME) && PcdGetBool (PcdShadowPeimOnS3Boot))) &&\r
       (EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_X64) || EFI_IMAGE_MACHINE_TYPE_SUPPORTED(EFI_IMAGE_MACHINE_IA32))) {\r
     // \r
     // Shadow algorithm makes lots of non ANSI C assumptions and only works for IA32 and X64 \r
@@ -328,6 +329,7 @@ GetPeCoffImageFixLoadingAssignedAddress(
   Loads and relocates a PE/COFF image into memory.\r
   If the image is not relocatable, it will not be loaded into memory and be loaded as XIP image.\r
 \r
+  @param FileHandle      - Pointer to the FFS file header of the image.\r
   @param Pe32Data        - The base address of the PE/COFF file that is to be loaded and relocated\r
   @param ImageAddress    - The base address of the relocated PE/COFF image\r
   @param ImageSize       - The size of the relocated PE/COFF image\r
@@ -342,6 +344,7 @@ GetPeCoffImageFixLoadingAssignedAddress(
 **/\r
 EFI_STATUS\r
 LoadAndRelocatePeCoffImage (\r
+  IN  EFI_PEI_FILE_HANDLE                       FileHandle,\r
   IN  VOID                                      *Pe32Data,\r
   OUT EFI_PHYSICAL_ADDRESS                      *ImageAddress,\r
   OUT UINT64                                    *ImageSize,\r
@@ -354,6 +357,8 @@ LoadAndRelocatePeCoffImage (
   UINT64                                AlignImageSize;\r
   BOOLEAN                               IsXipImage;\r
   EFI_STATUS                            ReturnStatus;\r
+  BOOLEAN                               IsS3Boot;\r
+  BOOLEAN                               IsRegisterForShadow;\r
 \r
   Private = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
 \r
@@ -370,6 +375,19 @@ LoadAndRelocatePeCoffImage (
     return Status;\r
   }\r
   \r
+  //\r
+  // Initilize local IsS3Boot and IsRegisterForShadow variable\r
+  //\r
+  IsS3Boot = FALSE;\r
+  if (Private->HobList.HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME) {\r
+    IsS3Boot = TRUE;\r
+  }\r
+  IsRegisterForShadow = FALSE;\r
+  if ((Private->CurrentFileHandle == FileHandle) \r
+    && (Private->Fv[Private->CurrentPeimFvCount].PeimState[Private->CurrentPeimCount] == PEIM_STATE_REGISITER_FOR_SHADOW)) {\r
+    IsRegisterForShadow = TRUE;\r
+  }\r
+\r
   //\r
   // XIP image that ImageAddress is same to Image handle.\r
   //\r
@@ -380,7 +398,8 @@ LoadAndRelocatePeCoffImage (
   //\r
   // When Image has no reloc section, it can't be relocated into memory.\r
   //\r
-  if (ImageContext.RelocationsStripped && (Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {\r
+  if (ImageContext.RelocationsStripped && (Private->PeiMemoryInstalled) && (\r
+      (!IsS3Boot && (PcdGetBool (PcdShadowPeimOnBoot) || IsRegisterForShadow)) || (IsS3Boot && PcdGetBool (PcdShadowPeimOnS3Boot)))) {\r
     DEBUG ((EFI_D_INFO|EFI_D_LOAD, "The image at 0x%08x without reloc section can't be loaded into memory\n", (UINTN) Pe32Data));\r
   }\r
 \r
@@ -390,9 +409,12 @@ LoadAndRelocatePeCoffImage (
   ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Pe32Data;\r
 \r
   //\r
-  // Allocate Memory for the image when memory is ready, boot mode is not S3, and image is relocatable.\r
+  // Allocate Memory for the image when memory is ready, and image is relocatable.\r
+  // On normal boot, PcdShadowPeimOnBoot decides whether load PEIM or PeiCore into memory.\r
+  // On S3 boot, PcdShadowPeimOnS3Boot decides whether load PEIM or PeiCore into memory.\r
   //\r
-  if ((!ImageContext.RelocationsStripped) && (Private->PeiMemoryInstalled) && (Private->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME || PcdGetBool (PcdShadowPeimOnS3Boot))) {\r
+  if ((!ImageContext.RelocationsStripped) && (Private->PeiMemoryInstalled) && (\r
+      (!IsS3Boot && (PcdGetBool (PcdShadowPeimOnBoot) || IsRegisterForShadow)) || (IsS3Boot && PcdGetBool (PcdShadowPeimOnS3Boot)))) {\r
     //\r
     // Allocate more buffer to avoid buffer overflow.\r
     //\r
@@ -571,6 +593,7 @@ PeiLoadImageLoadImage (
   // If memory is installed, perform the shadow operations\r
   //\r
   Status = LoadAndRelocatePeCoffImage (\r
+    FileHandle,\r
     Pe32Data,\r
     &ImageAddress,\r
     &ImageSize,\r
index 0acac47c1f91da1a860836497bd608a35852e042..39a464f32633a35343fed10c533f80c022d9c903 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressRuntimeCodePageNumber     ## SOMETIMES_CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadModuleAtFixAddressEnable            ## CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnS3Boot                      ## CONSUMES \r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot                        ## CONSUMES \r
 \r
 # [BootMode]\r
 # S3_RESUME             ## SOMETIMES_CONSUMES\r
index 05e0d0fda47494485a9ecec1f882e54f77185e17..d36f89c3dd0d99eefca999a897ef0ab984d1fdf1 100644 (file)
@@ -259,7 +259,11 @@ PeiCore (
       // Shadow PEI Core. When permanent memory is avaiable, shadow\r
       // PEI Core and PEIMs to get high performance.\r
       //\r
-      OldCoreData->ShadowedPeiCore = ShadowPeiCore (OldCoreData);\r
+      OldCoreData->ShadowedPeiCore = (PEICORE_FUNCTION_POINTER) (UINTN) PeiCore;\r
+      if ((HandoffInformationTable->BootMode == BOOT_ON_S3_RESUME && PcdGetBool (PcdShadowPeimOnS3Boot))\r
+          || (HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME && PcdGetBool (PcdShadowPeimOnBoot))) {\r
+        OldCoreData->ShadowedPeiCore = ShadowPeiCore (OldCoreData);\r
+      }\r
       \r
       //\r
       // PEI Core has now been shadowed to memory.  Restart PEI Core in memory.\r
index 25e3e1d019ad5ea66756e3e6a8fc24c66f5d7f1b..9b47a947ddb912308acf7b608f0fc99384ca4a05 100644 (file)
   # @Prompt Shadow Peim On S3 Boot. \r
   gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnS3Boot|FALSE|BOOLEAN|0x30001028\r
 \r
+  ## Indicates if to shadow PEIM and PeiCore after memory is ready.<BR><BR>\r
+  #  This PCD is used on other boot path except for S3 boot. \r
+  #   TRUE  - Shadow PEIM and PeiCore after memory is ready.<BR>\r
+  #   FALSE - Not shadow PEIM after memory is ready.<BR>\r
+  # @Prompt Shadow Peim and PeiCore on boot\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot|TRUE|BOOLEAN|0x30001029\r
+\r
   ## The mask is used to control memory profile behavior.<BR><BR>\r
   #  BIT0 - Enable UEFI memory profile.<BR>\r
   #  BIT1 - Enable SMRAM profile.<BR>\r
index 77422a3465507d8a1d5f866b4d9853f7388052c5..ec2750f44b2c4338982cc795fbd2b494bff8baf1 100644 (file)
Binary files a/MdeModulePkg/MdeModulePkg.uni and b/MdeModulePkg/MdeModulePkg.uni differ