]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
MdeModulePkg/S3SmmInitDone.h: Fix copyright coding style error.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain / PeiMain.c
index d105fce28d61a5830a5fe8ce7050bf2c1fd587c6..e3a301dfe0f22d0d227d8dd9157580bde6247eba 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Pei Core Main Entry Point\r
-  \r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+\r
+Copyright (c) 2006 - 2018, 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
@@ -46,7 +46,7 @@ EFI_PEI_SERVICES  gPs = {
   PeiFfsFindNextFile,\r
   PeiFfsFindSectionData,\r
 \r
-  PeiInstallPeiMemory,      \r
+  PeiInstallPeiMemory,\r
   PeiAllocatePages,\r
   PeiAllocatePool,\r
   (EFI_PEI_COPY_MEM)CopyMem,\r
@@ -63,12 +63,14 @@ EFI_PEI_SERVICES  gPs = {
   PeiFfsGetVolumeInfo,\r
   PeiRegisterForShadow,\r
   PeiFfsFindSectionData3,\r
-  PeiFfsGetFileInfo2\r
+  PeiFfsGetFileInfo2,\r
+  PeiResetSystem2,\r
+  PeiFreePages,\r
 };\r
 \r
 /**\r
   Shadow PeiCore module from flash to installed memory.\r
-  \r
+\r
   @param PrivateData    PeiCore's private data structure\r
 \r
   @return PeiCore function address after shadowing.\r
@@ -102,7 +104,7 @@ ShadowPeiCore (
   Status = PeiLoadImage (\r
               GetPeiServicesTablePointer (),\r
               *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),\r
-              PEIM_STATE_REGISITER_FOR_SHADOW,\r
+              PEIM_STATE_REGISTER_FOR_SHADOW,\r
               &EntryPoint,\r
               &AuthenticationState\r
               );\r
@@ -153,7 +155,7 @@ PeiCore (
   EFI_HOB_HANDOFF_INFO_TABLE  *HandoffInformationTable;\r
   EFI_PEI_TEMPORARY_RAM_DONE_PPI *TemporaryRamDonePpi;\r
   UINTN                       Index;\r
-  \r
+\r
   //\r
   // Retrieve context passed into PEI Core\r
   //\r
@@ -206,18 +208,18 @@ PeiCore (
         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
+      // Initialize libraries that the PEI Core is linked against\r
+      //\r
+      ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&OldCoreData->Ps);\r
+\r
+      //\r
+      // Update HandOffHob for new installed permanent memory\r
       //\r
       HandoffInformationTable = OldCoreData->HobList.HandoffInformationTable;\r
       if (OldCoreData->HeapOffsetPositive) {\r
@@ -230,6 +232,11 @@ PeiCore (
       HandoffInformationTable->EfiFreeMemoryTop    = OldCoreData->FreePhysicalMemoryTop;\r
       HandoffInformationTable->EfiFreeMemoryBottom = HandoffInformationTable->EfiEndOfHobList + sizeof (EFI_HOB_GENERIC_HEADER);\r
 \r
+      //\r
+      // We need convert MemoryBaseAddress in memory allocation HOBs\r
+      //\r
+      ConvertMemoryAllocationHobs (OldCoreData);\r
+\r
       //\r
       // We need convert the PPI descriptor's pointer\r
       //\r
@@ -237,7 +244,7 @@ PeiCore (
 \r
       //\r
       // After the whole temporary memory is migrated, then we can allocate page in\r
-      // permenent memory.\r
+      // permanent memory.\r
       //\r
       OldCoreData->PeiMemoryInstalled = TRUE;\r
 \r
@@ -245,7 +252,7 @@ PeiCore (
       // Indicate that PeiCore reenter\r
       //\r
       OldCoreData->PeimDispatcherReenter = TRUE;\r
-      \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
@@ -258,18 +265,24 @@ 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
-      \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
       //\r
       // Should never reach here.\r
       //\r
       ASSERT (FALSE);\r
       CpuDeadLoop();\r
+\r
+      UNREACHABLE ();\r
     }\r
 \r
     //\r
@@ -282,27 +295,27 @@ PeiCore (
 \r
     CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r
     PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;\r
-    \r
+\r
     CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
-    \r
+\r
     PrivateData.ServiceTableShadow.CpuIo  = CpuIo;\r
     PrivateData.ServiceTableShadow.PciCfg = PciCfg;\r
   }\r
-  \r
+\r
   //\r
   // Cache a pointer to the PEI Services Table that is either in temporary memory or permanent memory\r
   //\r
   PrivateData.Ps = &PrivateData.ServiceTableShadow;\r
 \r
   //\r
-  // Initialize libraries that the PEI Core is linked against\r
+  // Save PeiServicePointer so that it can be retrieved anywhere.\r
   //\r
-  ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r
+  SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r
 \r
   //\r
-  // Save PeiServicePointer so that it can be retrieved anywhere.\r
+  // Initialize libraries that the PEI Core is linked against\r
   //\r
-  SetPeiServicesTablePointer ((CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r
+  ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&PrivateData.Ps);\r
 \r
   //\r
   // Initialize PEI Core Services\r
@@ -313,48 +326,55 @@ PeiCore (
     // 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
   //\r
-  // Update performance measurements \r
+  // Update performance measurements\r
   //\r
   if (OldCoreData == NULL) {\r
-    PERF_START (NULL, "SEC", NULL, 1);\r
-    PERF_END   (NULL, "SEC", NULL, 0);\r
+    PERF_EVENT ("SEC"); // Means the end of SEC phase.\r
 \r
     //\r
     // If first pass, start performance measurement.\r
     //\r
-    PERF_START (NULL,"PEI",    NULL, 0);\r
-    PERF_START (NULL,"PreMem", NULL, 0);\r
+    PERF_CROSSMODULE_BEGIN ("PEI");\r
+    PERF_INMODULE_BEGIN ("PreMem");\r
 \r
   } else {\r
-    PERF_END   (NULL,"PreMem",  NULL, 0);\r
-    PERF_START (NULL,"PostMem", NULL, 0);\r
+    PERF_INMODULE_END ("PreMem");\r
+    PERF_INMODULE_BEGIN ("PostMem");\r
   }\r
 \r
   //\r
   // Complete PEI Core Service initialization\r
-  //  \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
+  //\r
   if (OldCoreData == NULL) {\r
     //\r
     // Report Status Code EFI_SW_PC_INIT\r
@@ -363,13 +383,12 @@ PeiCore (
       EFI_PROGRESS_CODE,\r
       (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT)\r
       );\r
-      \r
+\r
     //\r
-    // If SEC provided any PPI services to PEI, install them.\r
+    // If SEC provided the PpiList, process it.\r
     //\r
     if (PpiList != NULL) {\r
-      Status = PeiServicesInstallPpi (PpiList);\r
-      ASSERT_EFI_ERROR (Status);\r
+      ProcessPpiListFromSec ((CONST EFI_PEI_SERVICES **) &PrivateData.Ps, PpiList);\r
     }\r
   } else {\r
     //\r
@@ -391,7 +410,7 @@ PeiCore (
     //\r
     // Alert any listeners that there is permanent memory available\r
     //\r
-    PERF_START (NULL,"DisMem", NULL, 0);\r
+    PERF_INMODULE_BEGIN ("DisMem");\r
     Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r
 \r
     //\r
@@ -399,7 +418,7 @@ PeiCore (
     //\r
     ProcessNotifyList (&PrivateData);\r
 \r
-    PERF_END (NULL,"DisMem", NULL, 0);\r
+    PERF_INMODULE_END ("DisMem");\r
   }\r
 \r
   //\r
@@ -407,15 +426,17 @@ PeiCore (
   //\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
   // Measure PEI Core execution time.\r
   //\r
-  PERF_END (NULL, "PostMem", NULL, 0);\r
+  PERF_INMODULE_END ("PostMem");\r
 \r
   //\r
   // Lookup DXE IPL PPI\r
@@ -428,6 +449,17 @@ 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
@@ -442,4 +474,6 @@ PeiCore (
   //\r
   ASSERT_EFI_ERROR (Status);\r
   CpuDeadLoop();\r
+\r
+  UNREACHABLE ();\r
 }\r