]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
1. build.py's changes : include XXXEntryPointLib.h into the corresponding autogen...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / PeiMain / PeiMain.c
index 4dd7f26c3094feaae756868ced39bb980afff460..32f875b688dbc946fbcea9557bc9dc96b830d3fe 100644 (file)
@@ -1,5 +1,6 @@
-/*++\r
-\r
+/** @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
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -9,36 +10,20 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
-\r
-  PeiMain.c\r
-\r
-Abstract:\r
-\r
-  Pei Core Main Entry Point\r
-\r
-Revision History\r
-\r
---*/\r
+**/\r
 \r
 #include <PeiMain.h>\r
 \r
-//\r
-//CAR is filled with this initial value during SEC phase\r
-//\r
-#define INIT_CAR_VALUE 0x5AA55AA5\r
-\r
-static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
+STATIC EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r
   (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
   &gEfiPeiMemoryDiscoveredPpiGuid,\r
   NULL\r
 };\r
 \r
-//\r
-// Pei Core Module Variables\r
-//\r
-//\r
-static EFI_PEI_SERVICES  mPS = {\r
+///\r
+/// Pei service instance\r
+///\r
+STATIC EFI_PEI_SERVICES  gPs = {\r
   {\r
     PEI_SERVICES_SIGNATURE,\r
     PEI_SERVICES_REVISION,\r
@@ -79,88 +64,99 @@ static EFI_PEI_SERVICES  mPS = {
   PeiRegisterForShadow\r
 };\r
 \r
-EFI_STATUS\r
-EFIAPI\r
-PeiCore (\r
-  IN CONST EFI_SEC_PEI_HAND_OFF        *SecCoreData,\r
-  IN CONST EFI_PEI_PPI_DESCRIPTOR      *PpiList,\r
-  IN VOID                              *Data\r
-  )\r
-/*++\r
+/**\r
 \r
-Routine Description:\r
-\r
-  The entry routine to Pei Core, invoked by PeiMain during transition\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
-Arguments:\r
-\r
-  SecCoreData          - Points to a data structure containing information about the PEI core's operating\r
+  @param SecCoreData     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
-  PpiList              - Points to a list of one or more PPI descriptors to be installed initially by the PEI core.\r
+  @param PpiList         Points to a list of one or more PPI descriptors to be installed initially by the PEI core.\r
                          An empty PPI list consists of a single descriptor with the end-tag\r
                          EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization\r
                          phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such\r
                          that both the PEI Foundation and any modules can leverage the associated service\r
                          calls and/or code in these early PPIs\r
-  Data                 - Pointer to old core data that is used to initialize the\r
+  @param Data            Pointer to old core data that is used to initialize the\r
                          core's data areas.\r
+                         If NULL, it is first PeiCore entering.\r
 \r
-Returns:\r
-\r
-  This function never returns\r
-  EFI_NOT_FOUND        - Never reach\r
+  @retval EFI_NOT_FOUND  Never reach\r
 \r
---*/\r
+**/\r
+VOID\r
+EFIAPI\r
+PeiCore (\r
+  IN CONST EFI_SEC_PEI_HAND_OFF        *SecCoreData,\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                                                mTick;\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
-  mTick = 0;\r
+  Tick = 0;\r
   OldCoreData = (PEI_CORE_INSTANCE *) Data;\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
-      mTick = GetPerformanceCounter ();\r
+      Tick = GetPerformanceCounter ();\r
     }\r
   }\r
 \r
-  //\r
-  // For IPF in CAR mode the real memory access is uncached,in InstallPeiMemory()\r
-  //  the 63-bit of address is set to 1.\r
-  //\r
-  SWITCH_TO_CACHE_MODE (OldCoreData);\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
+    //\r
+    if (ShadowedPeiCore != NULL) {\r
+      OldCoreData->ShadowedPeiCore = NULL;\r
+      ShadowedPeiCore (\r
+        SecCoreData,\r
+        PpiList,\r
+        OldCoreData\r
+        );\r
+    }\r
+\r
     CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r
     \r
     CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r
     PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;\r
     \r
-    CopyMem (&PrivateData.ServiceTableShadow, &mPS, sizeof (mPS));\r
+    CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
     \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, &mPS, sizeof (mPS));\r
+    CopyMem (&PrivateData.ServiceTableShadow, &gPs, sizeof (gPs));\r
   }\r
 \r
   PrivateData.PS = &PrivateData.ServiceTableShadow;\r
 \r
   //\r
   // Initialize libraries that the PeiCore is linked against\r
-  // BUGBUG: The FileHandle is passed in as NULL.  Do we look it up or remove it from the lib init?\r
   //\r
-  ProcessLibraryConstructorList (NULL, &PrivateData.PS);\r
+  ProcessLibraryConstructorList (NULL, (CONST EFI_PEI_SERVICES **)&PrivateData.PS);\r
 \r
   InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);\r
 \r
@@ -169,41 +165,13 @@ Returns:
   //\r
   // Save PeiServicePointer so that it can be retrieved anywhere.\r
   //\r
-  SetPeiServicesTablePointer(&PrivateData.PS);\r
+  SetPeiServicesTablePointer((CONST EFI_PEI_SERVICES **) &PrivateData.PS);\r
   \r
   if (OldCoreData != NULL) {\r
 \r
     PERF_END (NULL,"PreMem", NULL, 0);\r
     PERF_START (NULL,"PostMem", NULL, 0);\r
 \r
-    //\r
-    // The following code dumps out interesting cache as RAM usage information\r
-    // so we can keep tabs on how the cache as RAM is being utilized.  The\r
-    // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled\r
-    // on a debug build.\r
-    //\r
-    DEBUG_CODE_BEGIN ();\r
-      UINTN  *StackPointer;\r
-      UINTN  StackValue;\r
-\r
-      StackValue = INIT_CAR_VALUE;\r
-      for (StackPointer = (UINTN *) OldCoreData->MaxTopOfCarHeap;\r
-           ((UINTN) StackPointer < ((UINTN) OldCoreData->BottomOfCarHeap + OldCoreData->SizeOfCacheAsRam))\r
-           && StackValue == INIT_CAR_VALUE;\r
-           StackPointer++) {\r
-        StackValue = *StackPointer;\r
-      }\r
-\r
-      DEBUG ((EFI_D_INFO, "Total Cache as RAM:    %d bytes.\n", OldCoreData->SizeOfCacheAsRam));\r
-      DEBUG ((EFI_D_INFO, "  CAR stack ever used: %d bytes.\n",\r
-        ((UINTN) OldCoreData->TopOfCarHeap - (UINTN) StackPointer)\r
-        ));\r
-      DEBUG ((EFI_D_INFO, "  CAR heap used:       %d bytes.\n",\r
-        ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -\r
-        (UINTN) OldCoreData->HobList.Raw)\r
-        ));\r
-    DEBUG_CODE_END ();\r
-\r
     //\r
     // Alert any listeners that there is permanent memory available\r
     //\r
@@ -219,14 +187,14 @@ Returns:
     //\r
     REPORT_STATUS_CODE (\r
       EFI_PROGRESS_CODE,\r
-      EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT\r
+      FixedPcdGet32 (PcdStatusCodeValuePeiCoreEntry)\r
       );\r
 \r
-    PERF_START (NULL,"PEI", NULL, mTick);\r
+    PERF_START (NULL,"PEI", NULL, Tick);\r
     //\r
     // If first pass, start performance measurement.\r
     //\r
-    PERF_START (NULL,"PreMem", NULL, mTick);\r
+    PERF_START (NULL,"PreMem", NULL, Tick);\r
 \r
     //\r
     // If SEC provided any PPI services to PEI, install them.\r
@@ -256,6 +224,10 @@ Returns:
   //\r
   ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r
 \r
+  //\r
+  // Till now, PEI phase will be finished, get performace count\r
+  // for computing duration of PEI phase\r
+  //\r
   PERF_END (NULL, "PostMem", NULL, 0);\r
 \r
   Status = PeiServicesLocatePpi (\r
@@ -266,15 +238,20 @@ Returns:
              );\r
   ASSERT_EFI_ERROR (Status);\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.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