]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
MdeModulePkg: Allow DxeIpl to load without permanent memory
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain / PeiMain.c
index 8055659129e367b9aeb8ba6e6bea9a1464e1c931..10db496140ad0d6f5820f72c08fedb63572d6019 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Pei Core Main Entry Point\r
   \r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2016, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -12,9 +12,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include <PeiMain.h>\r
+#include "PeiMain.h"\r
 \r
-STATIC EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
+EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
   (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
   &gEfiPeiMemoryDiscoveredPpiGuid,\r
   NULL\r
@@ -23,7 +23,7 @@ STATIC EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {
 ///\r
 /// Pei service instance\r
 ///\r
-STATIC EFI_PEI_SERVICES  gPs = {\r
+EFI_PEI_SERVICES  gPs = {\r
   {\r
     PEI_SERVICES_SIGNATURE,\r
     PEI_SERVICES_REVISION,\r
@@ -42,7 +42,7 @@ STATIC EFI_PEI_SERVICES  gPs = {
   PeiGetHobList,\r
   PeiCreateHob,\r
 \r
-  PeiFvFindNextVolume,\r
+  PeiFfsFindNextVolume,\r
   PeiFfsFindNextFile,\r
   PeiFfsFindSectionData,\r
 \r
@@ -55,22 +55,73 @@ STATIC EFI_PEI_SERVICES  gPs = {
   PeiReportStatusCode,\r
   PeiResetSystem,\r
 \r
-  NULL,\r
-  NULL,\r
+  &gPeiDefaultCpuIoPpi,\r
+  &gPeiDefaultPciCfg2Ppi,\r
 \r
   PeiFfsFindFileByName,\r
   PeiFfsGetFileInfo,\r
   PeiFfsGetVolumeInfo,\r
-  PeiRegisterForShadow\r
+  PeiRegisterForShadow,\r
+  PeiFfsFindSectionData3,\r
+  PeiFfsGetFileInfo2,\r
+  PeiResetSystem2\r
 };\r
 \r
 /**\r
+  Shadow PeiCore module from flash to installed memory.\r
+  \r
+  @param PrivateData    PeiCore's private data structure\r
+\r
+  @return PeiCore function address after shadowing.\r
+**/\r
+PEICORE_FUNCTION_POINTER\r
+ShadowPeiCore (\r
+  IN PEI_CORE_INSTANCE  *PrivateData\r
+  )\r
+{\r
+  EFI_PEI_FILE_HANDLE  PeiCoreFileHandle;\r
+  EFI_PHYSICAL_ADDRESS EntryPoint;\r
+  EFI_STATUS           Status;\r
+  UINT32               AuthenticationState;\r
+\r
+  PeiCoreFileHandle = NULL;\r
+\r
+  //\r
+  // Find the PEI Core in the BFV\r
+  //\r
+  Status = PrivateData->Fv[0].FvPpi->FindFileByType (\r
+                                       PrivateData->Fv[0].FvPpi,\r
+                                       EFI_FV_FILETYPE_PEI_CORE,\r
+                                       PrivateData->Fv[0].FvHandle,\r
+                                       &PeiCoreFileHandle\r
+                                       );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Shadow PEI Core into memory so it will run faster\r
+  //\r
+  Status = PeiLoadImage (\r
+              GetPeiServicesTablePointer (),\r
+              *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),\r
+              PEIM_STATE_REGISITER_FOR_SHADOW,\r
+              &EntryPoint,\r
+              &AuthenticationState\r
+              );\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Compute the PeiCore's function address after shaowed PeiCore.\r
+  // _ModuleEntryPoint is PeiCore main function entry\r
+  //\r
+  return (PEICORE_FUNCTION_POINTER)((UINTN) EntryPoint + (UINTN) PeiCore - (UINTN) _ModuleEntryPoint);\r
+}\r
+\r
+/**\r
   This routine is invoked by main entry of PeiMain module during transition\r
   from SEC to PEI. After switching stack in the PEI core, it will restart\r
   with the old core data.\r
 \r
-  @param SecCoreData     Points to a data structure containing information about the PEI core's operating\r
+  @param SecCoreDataPtr  Points to a data structure containing information about the PEI core's operating\r
                          environment, such as the size and location of temporary RAM, the stack location and\r
                          the BFV location.\r
   @param PpiList         Points to a list of one or more PPI descriptors to be installed initially by the PEI core.\r
@@ -83,57 +134,157 @@ STATIC EFI_PEI_SERVICES  gPs = {
                          core's data areas.\r
                          If NULL, it is first PeiCore entering.\r
 \r
-  @retval EFI_NOT_FOUND  Never reach\r
-\r
 **/\r
-EFI_STATUS\r
+VOID\r
 EFIAPI\r
 PeiCore (\r
-  IN CONST EFI_SEC_PEI_HAND_OFF        *SecCoreData,\r
+  IN CONST EFI_SEC_PEI_HAND_OFF        *SecCoreDataPtr,\r
   IN CONST EFI_PEI_PPI_DESCRIPTOR      *PpiList,\r
   IN VOID                              *Data\r
   )\r
 {\r
-  PEI_CORE_INSTANCE                                     PrivateData;\r
-  EFI_STATUS                                            Status;\r
-  PEI_CORE_TEMP_POINTERS                                TempPtr;\r
-  UINT64                                                Tick;\r
-  PEI_CORE_INSTANCE                                     *OldCoreData;\r
-  EFI_PEI_CPU_IO_PPI                                    *CpuIo;\r
-  EFI_PEI_PCI_CFG2_PPI                                  *PciCfg;\r
-  PEICORE_FUNCTION_POINTER                              ShadowedPeiCore;\r
-\r
-  Tick = 0;\r
+  PEI_CORE_INSTANCE           PrivateData;\r
+  EFI_SEC_PEI_HAND_OFF        *SecCoreData;\r
+  EFI_SEC_PEI_HAND_OFF        NewSecCoreData;\r
+  EFI_STATUS                  Status;\r
+  PEI_CORE_TEMP_POINTERS      TempPtr;\r
+  PEI_CORE_INSTANCE           *OldCoreData;\r
+  EFI_PEI_CPU_IO_PPI          *CpuIo;\r
+  EFI_PEI_PCI_CFG2_PPI        *PciCfg;\r
+  EFI_HOB_HANDOFF_INFO_TABLE  *HandoffInformationTable;\r
+  EFI_PEI_TEMPORARY_RAM_DONE_PPI *TemporaryRamDonePpi;\r
+  UINTN                       Index;\r
+  \r
+  //\r
+  // Retrieve context passed into PEI Core\r
+  //\r
   OldCoreData = (PEI_CORE_INSTANCE *) Data;\r
+  SecCoreData = (EFI_SEC_PEI_HAND_OFF *) SecCoreDataPtr;\r
 \r
   //\r
-  // Record the system tick for first entering PeiCore.\r
-  // This tick is duration of executing platform seccore module.\r
-  // \r
-  if (PerformanceMeasurementEnabled()) {\r
-    if (OldCoreData == NULL) {\r
-      Tick = GetPerformanceCounter ();\r
+  // Perform PEI Core phase specific actions.\r
+  //\r
+  if (OldCoreData == NULL) {\r
+    //\r
+    // If OldCoreData is NULL, means current is the first entry into the PEI Core before memory is available.\r
+    //\r
+    ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
+    PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
+    CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
+  } else {\r
+    //\r
+    // Memory is available to the PEI Core.  See if the PEI Core has been shadowed to memory yet.\r
+    //\r
+    if (OldCoreData->ShadowedPeiCore == NULL) {\r
+      //\r
+      // Fixup the PeiCore's private data\r
+      //\r
+      OldCoreData->Ps    = &OldCoreData->ServiceTableShadow;\r
+      OldCoreData->CpuIo = &OldCoreData->ServiceTableShadow.CpuIo;\r
+      if (OldCoreData->HeapOffsetPositive) {\r
+        OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw + OldCoreData->HeapOffset);\r
+        OldCoreData->UnknownFvInfo        = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData->UnknownFvInfo + OldCoreData->HeapOffset);\r
+        OldCoreData->CurrentFvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->CurrentFvFileHandles + OldCoreData->HeapOffset);\r
+        OldCoreData->PpiData.PpiListPtrs  = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.PpiListPtrs + OldCoreData->HeapOffset);\r
+        OldCoreData->Fv                   = (PEI_CORE_FV_HANDLE *) ((UINT8 *) OldCoreData->Fv + OldCoreData->HeapOffset);\r
+        for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r
+          OldCoreData->Fv[Index].PeimState     = (UINT8 *) OldCoreData->Fv[Index].PeimState + OldCoreData->HeapOffset;\r
+          OldCoreData->Fv[Index].FvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->Fv[Index].FvFileHandles + OldCoreData->HeapOffset);\r
+        }\r
+        OldCoreData->FileGuid             = (EFI_GUID *) ((UINT8 *) OldCoreData->FileGuid + OldCoreData->HeapOffset);\r
+        OldCoreData->FileHandles          = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->FileHandles + OldCoreData->HeapOffset);\r
+      } else {\r
+        OldCoreData->HobList.Raw = (VOID *)(OldCoreData->HobList.Raw - OldCoreData->HeapOffset);\r
+        OldCoreData->UnknownFvInfo        = (PEI_CORE_UNKNOW_FORMAT_FV_INFO *) ((UINT8 *) OldCoreData->UnknownFvInfo - OldCoreData->HeapOffset);\r
+        OldCoreData->CurrentFvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->CurrentFvFileHandles - OldCoreData->HeapOffset);\r
+        OldCoreData->PpiData.PpiListPtrs  = (PEI_PPI_LIST_POINTERS *) ((UINT8 *) OldCoreData->PpiData.PpiListPtrs - OldCoreData->HeapOffset);\r
+        OldCoreData->Fv                   = (PEI_CORE_FV_HANDLE *) ((UINT8 *) OldCoreData->Fv - OldCoreData->HeapOffset);\r
+        for (Index = 0; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r
+          OldCoreData->Fv[Index].PeimState     = (UINT8 *) OldCoreData->Fv[Index].PeimState - OldCoreData->HeapOffset;\r
+          OldCoreData->Fv[Index].FvFileHandles = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->Fv[Index].FvFileHandles - OldCoreData->HeapOffset);\r
+        }\r
+        OldCoreData->FileGuid             = (EFI_GUID *) ((UINT8 *) OldCoreData->FileGuid - OldCoreData->HeapOffset);\r
+        OldCoreData->FileHandles          = (EFI_PEI_FILE_HANDLE *) ((UINT8 *) OldCoreData->FileHandles - OldCoreData->HeapOffset);\r
+      }\r
+\r
+      //\r
+      // Initialize libraries that the PEI Core is linked against\r
+      //\r
+      ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&OldCoreData->Ps);\r
+      \r
+      //\r
+      // Fixup for PeiService's address\r
+      //\r
+      SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES **)&OldCoreData->Ps);\r
+\r
+      //\r
+      // Update HandOffHob for new installed permenent memory\r
+      //\r
+      HandoffInformationTable = OldCoreData->HobList.HandoffInformationTable;\r
+      if (OldCoreData->HeapOffsetPositive) {\r
+        HandoffInformationTable->EfiEndOfHobList   = HandoffInformationTable->EfiEndOfHobList + OldCoreData->HeapOffset;\r
+      } else {\r
+        HandoffInformationTable->EfiEndOfHobList   = HandoffInformationTable->EfiEndOfHobList - OldCoreData->HeapOffset;\r
+      }\r
+      HandoffInformationTable->EfiMemoryTop        = OldCoreData->PhysicalMemoryBegin + OldCoreData->PhysicalMemoryLength;\r
+      HandoffInformationTable->EfiMemoryBottom     = OldCoreData->PhysicalMemoryBegin;\r
+      HandoffInformationTable->EfiFreeMemoryTop    = OldCoreData->FreePhysicalMemoryTop;\r
+      HandoffInformationTable->EfiFreeMemoryBottom = HandoffInformationTable->EfiEndOfHobList + sizeof (EFI_HOB_GENERIC_HEADER);\r
+\r
+      //\r
+      // We need convert the PPI descriptor's pointer\r
+      //\r
+      ConvertPpiPointers (SecCoreData, OldCoreData);\r
+\r
+      //\r
+      // After the whole temporary memory is migrated, then we can allocate page in\r
+      // permenent memory.\r
+      //\r
+      OldCoreData->PeiMemoryInstalled = TRUE;\r
+\r
+      //\r
+      // Indicate that PeiCore reenter\r
+      //\r
+      OldCoreData->PeimDispatcherReenter = TRUE;\r
+      \r
+      if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 && (OldCoreData->HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME)) {\r
+        //\r
+        // if Loading Module at Fixed Address is enabled, allocate the PEI code memory range usage bit map array.\r
+        // Every bit in the array indicate the status of the corresponding memory page available or not\r
+        //\r
+        OldCoreData->PeiCodeMemoryRangeUsageBitMap = AllocateZeroPool (((PcdGet32(PcdLoadFixAddressPeiCodePageNumber)>>6) + 1)*sizeof(UINT64));\r
+      }\r
+\r
+      //\r
+      // Shadow PEI Core. When permanent memory is avaiable, shadow\r
+      // PEI Core and PEIMs to get high performance.\r
+      //\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
+      //\r
+      OldCoreData->ShadowedPeiCore (SecCoreData, PpiList, OldCoreData);\r
+      \r
+      //\r
+      // Should never reach here.\r
+      //\r
+      ASSERT (FALSE);\r
+      CpuDeadLoop();\r
     }\r
-  }\r
 \r
-  if (OldCoreData != NULL) {\r
-    ShadowedPeiCore = (PEICORE_FUNCTION_POINTER) (UINTN) OldCoreData->ShadowedPeiCore;\r
-    \r
     //\r
-    // PeiCore has been shadowed to memory for first entering, so\r
-    // just jump to PeiCore in memory here.\r
+    // Memory is available to the PEI Core and the PEI Core has been shadowed to memory.\r
     //\r
-    if (ShadowedPeiCore != NULL) {\r
-      OldCoreData->ShadowedPeiCore = NULL;\r
-      ShadowedPeiCore (\r
-        SecCoreData,\r
-        PpiList,\r
-        OldCoreData\r
-        );\r
-    }\r
+    CopyMem (&NewSecCoreData, SecCoreDataPtr, sizeof (NewSecCoreData));\r
+    SecCoreData = &NewSecCoreData;\r
+\r
+    CopyMem (&PrivateData, OldCoreData, sizeof (PrivateData));\r
 \r
-    CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
-    \r
     CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r
     PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;\r
     \r
@@ -141,61 +292,91 @@ PeiCore (
     \r
     PrivateData.ServiceTableShadow.CpuIo  = CpuIo;\r
     PrivateData.ServiceTableShadow.PciCfg = PciCfg;\r
-  } else {\r
-    //\r
-    // If OldCoreData is NULL, means current is first Peicore's entering.\r
-    //\r
-    \r
-    ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r
-    PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r
-    CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
   }\r
-\r
-  PrivateData.PS = &PrivateData.ServiceTableShadow;\r
-\r
+  \r
   //\r
-  // Initialize libraries that the PeiCore is linked against\r
+  // Cache a pointer to the PEI Services Table that is either in temporary memory or permanent memory\r
   //\r
-  ProcessLibraryConstructorList (NULL, &PrivateData.PS);\r
-\r
-  InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);\r
+  PrivateData.Ps = &PrivateData.ServiceTableShadow;\r
 \r
-  InitializePpiServices (&PrivateData, OldCoreData);\r
+  //\r
+  // Initialize libraries that the PEI Core is linked against\r
+  //\r
+  ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r
 \r
   //\r
   // Save PeiServicePointer so that it can be retrieved anywhere.\r
   //\r
-  SetPeiServicesTablePointer((CONST EFI_PEI_SERVICES **) &PrivateData.PS);\r
-  \r
-  if (OldCoreData != NULL) {\r
+  SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r
 \r
-    PERF_END (NULL,"PreMem", NULL, 0);\r
-    PERF_START (NULL,"PostMem", NULL, 0);\r
+  //\r
+  // Initialize PEI Core Services\r
+  //\r
+  InitializeMemoryServices   (&PrivateData,    SecCoreData, OldCoreData);\r
+  if (OldCoreData == NULL) {\r
+    //\r
+    // Initialize PEI Core Private Data Buffer\r
+    //\r
+    PrivateData.PpiData.PpiListPtrs  = AllocateZeroPool (sizeof (PEI_PPI_LIST_POINTERS) * PcdGet32 (PcdPeiCoreMaxPpiSupported));\r
+    ASSERT (PrivateData.PpiData.PpiListPtrs != NULL);\r
+    PrivateData.Fv                   = AllocateZeroPool (sizeof (PEI_CORE_FV_HANDLE) * PcdGet32 (PcdPeiCoreMaxFvSupported));\r
+    ASSERT (PrivateData.Fv != NULL);\r
+    PrivateData.Fv[0].PeimState      = AllocateZeroPool (sizeof (UINT8) * PcdGet32 (PcdPeiCoreMaxPeimPerFv) * PcdGet32 (PcdPeiCoreMaxFvSupported));\r
+    ASSERT (PrivateData.Fv[0].PeimState != NULL);\r
+    PrivateData.Fv[0].FvFileHandles  = AllocateZeroPool (sizeof (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv) * PcdGet32 (PcdPeiCoreMaxFvSupported));\r
+    ASSERT (PrivateData.Fv[0].FvFileHandles != NULL);\r
+    for (Index = 1; Index < PcdGet32 (PcdPeiCoreMaxFvSupported); Index ++) {\r
+      PrivateData.Fv[Index].PeimState     = PrivateData.Fv[Index - 1].PeimState + PcdGet32 (PcdPeiCoreMaxPeimPerFv);\r
+      PrivateData.Fv[Index].FvFileHandles = PrivateData.Fv[Index - 1].FvFileHandles + PcdGet32 (PcdPeiCoreMaxPeimPerFv);\r
+    }\r
+    PrivateData.UnknownFvInfo        = AllocateZeroPool (sizeof (PEI_CORE_UNKNOW_FORMAT_FV_INFO) * PcdGet32 (PcdPeiCoreMaxFvSupported));\r
+    ASSERT (PrivateData.UnknownFvInfo != NULL);\r
+    PrivateData.CurrentFvFileHandles = AllocateZeroPool (sizeof (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv));\r
+    ASSERT (PrivateData.CurrentFvFileHandles != NULL);\r
+    PrivateData.FileGuid             = AllocatePool (sizeof (EFI_GUID) * PcdGet32 (PcdPeiCoreMaxPeimPerFv));\r
+    ASSERT (PrivateData.FileGuid != NULL);\r
+    PrivateData.FileHandles          = AllocatePool (sizeof (EFI_PEI_FILE_HANDLE) * (PcdGet32 (PcdPeiCoreMaxPeimPerFv) + 1));\r
+    ASSERT (PrivateData.FileHandles != NULL);\r
+  }\r
+  InitializePpiServices      (&PrivateData,    OldCoreData);\r
+  \r
+  //\r
+  // Update performance measurements \r
+  //\r
+  if (OldCoreData == NULL) {\r
+    PERF_START (NULL, "SEC", NULL, 1);\r
+    PERF_END   (NULL, "SEC", NULL, 0);\r
 \r
     //\r
-    // Alert any listeners that there is permanent memory available\r
+    // If first pass, start performance measurement.\r
     //\r
-    \r
-    PERF_START (NULL,"DisMem", NULL, 0);\r
-    Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r
-    PERF_END (NULL,"DisMem", NULL, 0);\r
+    PERF_START (NULL,"PEI",    NULL, 0);\r
+    PERF_START (NULL,"PreMem", NULL, 0);\r
 \r
   } else {\r
+    PERF_END   (NULL,"PreMem",  NULL, 0);\r
+    PERF_START (NULL,"PostMem", NULL, 0);\r
+  }\r
+\r
+  //\r
+  // Complete PEI Core Service initialization\r
+  //  \r
+  InitializeSecurityServices (&PrivateData.Ps, OldCoreData);\r
+  InitializeDispatcherData   (&PrivateData,    OldCoreData, SecCoreData);\r
+  InitializeImageServices    (&PrivateData,    OldCoreData);\r
 \r
+  //\r
+  // Perform PEI Core Phase specific actions\r
+  //  \r
+  if (OldCoreData == NULL) {\r
     //\r
     // Report Status Code EFI_SW_PC_INIT\r
     //\r
     REPORT_STATUS_CODE (\r
       EFI_PROGRESS_CODE,\r
-      FixedPcdGet32 (PcdStatusCodeValuePeiCoreEntry)\r
+      (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT)\r
       );\r
-\r
-    PERF_START (NULL,"PEI", NULL, Tick);\r
-    //\r
-    // If first pass, start performance measurement.\r
-    //\r
-    PERF_START (NULL,"PreMem", NULL, Tick);\r
-\r
+      \r
     //\r
     // If SEC provided any PPI services to PEI, install them.\r
     //\r
@@ -203,33 +384,57 @@ PeiCore (
       Status = PeiServicesInstallPpi (PpiList);\r
       ASSERT_EFI_ERROR (Status);\r
     }\r
-  }\r
+  } else {\r
+    //\r
+    // Try to locate Temporary RAM Done Ppi.\r
+    //\r
+    Status = PeiServicesLocatePpi (\r
+               &gEfiTemporaryRamDonePpiGuid,\r
+               0,\r
+               NULL,\r
+               (VOID**)&TemporaryRamDonePpi\r
+               );\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Disable the use of Temporary RAM after the transition from Temporary RAM to Permanent RAM is complete.\r
+      //\r
+      TemporaryRamDonePpi->TemporaryRamDone ();\r
+    }\r
 \r
-  InitializeSecurityServices (&PrivateData.PS, OldCoreData);\r
+    //\r
+    // Alert any listeners that there is permanent memory available\r
+    //\r
+    PERF_START (NULL,"DisMem", NULL, 0);\r
+    Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r
 \r
-  InitializeDispatcherData (&PrivateData, OldCoreData, SecCoreData);\r
+    //\r
+    // Process the Notify list and dispatch any notifies for the Memory Discovered PPI\r
+    //\r
+    ProcessNotifyList (&PrivateData);\r
 \r
-  //\r
-  // Install Pei Load File PPI. \r
-  //\r
-  InitializeImageServices (&PrivateData, OldCoreData);\r
+    PERF_END (NULL,"DisMem", NULL, 0);\r
+  }\r
 \r
   //\r
   // Call PEIM dispatcher\r
   //\r
   PeiDispatcher (SecCoreData, &PrivateData);\r
 \r
-  //\r
-  // Check if InstallPeiMemory service was called.\r
-  //\r
-  ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
+  if (PrivateData.HobList.HandoffInformationTable->BootMode != BOOT_ON_S3_RESUME) {\r
+    //\r
+    // Check if InstallPeiMemory service was called on non-S3 resume boot path.\r
+    //\r
+    ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
+  }\r
 \r
   //\r
-  // Till now, PEI phase will be finished, get performace count\r
-  // for computing duration of PEI phase\r
+  // Measure PEI Core execution time.\r
   //\r
   PERF_END (NULL, "PostMem", NULL, 0);\r
 \r
+  //\r
+  // Lookup DXE IPL PPI\r
+  //\r
   Status = PeiServicesLocatePpi (\r
              &gEfiDxeIplPpiGuid,\r
              0,\r
@@ -238,19 +443,29 @@ PeiCore (
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Report status code to indicate DXE IPL PPI could not be found.\r
+    //\r
+    REPORT_STATUS_CODE (\r
+      EFI_ERROR_CODE | EFI_ERROR_MAJOR,\r
+      (EFI_SOFTWARE_PEI_CORE | EFI_SW_PEI_CORE_EC_DXEIPL_NOT_FOUND)\r
+      );\r
+    CpuDeadLoop ();\r
+  }\r
+\r
   //\r
   // Enter DxeIpl to load Dxe core.\r
   //\r
   DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r
   Status = TempPtr.DxeIpl->Entry (\r
                              TempPtr.DxeIpl,\r
-                             &PrivateData.PS,\r
+                             &PrivateData.Ps,\r
                              PrivateData.HobList\r
                              );\r
-\r
+  //\r
+  // Should never reach here.\r
+  //\r
   ASSERT_EFI_ERROR (Status);\r
-\r
-  return EFI_NOT_FOUND;\r
+  CpuDeadLoop();\r
 }\r
-\r
-\r