]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
Pkg-Module: CorebootModulePkg
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Dispatcher / Dispatcher.c
index b5e2a824553f22253938542817db1c10cabd7e94..b9c3fb3bdb4bc47737a569764c5b75bce9efcd9f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI PEI Core dispatch services\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
@@ -49,8 +49,8 @@ DiscoverPeimsAndOrderWithApriori (
   UINTN                               PeimIndex;\r
   UINTN                               PeimCount;\r
   EFI_GUID                            *Guid;\r
-  EFI_PEI_FILE_HANDLE                 TempFileHandles[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv) + 1];\r
-  EFI_GUID                            FileGuid[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];\r
+  EFI_PEI_FILE_HANDLE                 *TempFileHandles;\r
+  EFI_GUID                            *FileGuid;\r
   EFI_PEI_FIRMWARE_VOLUME_PPI         *FvPpi;\r
   EFI_FV_FILE_INFO                    FileInfo;\r
   \r
@@ -63,12 +63,14 @@ DiscoverPeimsAndOrderWithApriori (
   Private->CurrentFvFileHandles[0] = NULL;\r
   Guid = NULL;\r
   FileHandle = NULL;\r
+  TempFileHandles = Private->FileHandles;\r
+  FileGuid        = Private->FileGuid;\r
 \r
   //\r
   // If the current Fv has been scanned, directly get its cachable record.\r
   //\r
   if (Private->Fv[Private->CurrentPeimFvCount].ScanFv) {\r
-    CopyMem (Private->CurrentFvFileHandles, Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, sizeof (Private->CurrentFvFileHandles));\r
+    CopyMem (Private->CurrentFvFileHandles, Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, sizeof (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv));\r
     return;\r
   }\r
 \r
@@ -76,9 +78,9 @@ DiscoverPeimsAndOrderWithApriori (
   // Go ahead to scan this Fv, and cache FileHandles within it.\r
   //\r
   Status = EFI_NOT_FOUND;\r
-  for (PeimCount = 0; PeimCount <= FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {\r
+  for (PeimCount = 0; PeimCount <= PcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {\r
     Status = FvPpi->FindFileByType (FvPpi, PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE, CoreFileHandle->FvHandle, &FileHandle);\r
-    if (Status != EFI_SUCCESS || PeimCount == FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) {\r
+    if (Status != EFI_SUCCESS || PeimCount == PcdGet32 (PcdPeiCoreMaxPeimPerFv)) {\r
       break;\r
     }\r
 \r
@@ -86,10 +88,10 @@ DiscoverPeimsAndOrderWithApriori (
   }\r
 \r
   //\r
-  // Check whether the count of Peims exceeds the max support PEIMs in a FV image\r
-  // If more Peims are required in a FV image, PcdPeiCoreMaxPeimPerFv can be set to a larger value in DSC file.\r
+  // Check whether the count of files exceeds the max support files in a FV image\r
+  // If more files are required in a FV image, PcdPeiCoreMaxPeimPerFv can be set to a larger value in DSC file.\r
   //\r
-  ASSERT ((Status != EFI_SUCCESS) || (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)));\r
+  ASSERT ((Status != EFI_SUCCESS) || (PeimCount < PcdGet32 (PcdPeiCoreMaxPeimPerFv)));\r
 \r
   //\r
   // Get Apriori File handle\r
@@ -115,7 +117,6 @@ DiscoverPeimsAndOrderWithApriori (
       }\r
       Private->AprioriCount /= sizeof (EFI_GUID);\r
 \r
-      ZeroMem (FileGuid, sizeof (FileGuid));\r
       for (Index = 0; Index < PeimCount; Index++) {\r
         //\r
         // Make an array of file name guids that matches the FileHandle array so we can convert\r
@@ -176,7 +177,7 @@ DiscoverPeimsAndOrderWithApriori (
       // We need to update it to start with files in the A Priori list and\r
       // then the remaining files in PEIM order.\r
       //\r
-      CopyMem (Private->CurrentFvFileHandles, TempFileHandles, sizeof (Private->CurrentFvFileHandles));\r
+      CopyMem (Private->CurrentFvFileHandles, TempFileHandles, sizeof (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv));\r
     }\r
   }\r
   //\r
@@ -184,7 +185,7 @@ DiscoverPeimsAndOrderWithApriori (
   // Instead, we can retrieve the file handles within this Fv from cachable data.\r
   //\r
   Private->Fv[Private->CurrentPeimFvCount].ScanFv = TRUE;\r
-  CopyMem (Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles));\r
+  CopyMem (Private->Fv[Private->CurrentPeimFvCount].FvFileHandles, Private->CurrentFvFileHandles, sizeof (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv));\r
 \r
 }\r
 \r
@@ -661,6 +662,7 @@ PeiDispatcher (
   PEIM_FILE_HANDLE_EXTENDED_DATA      ExtendedData;\r
   EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI   *TemporaryRamSupportPpi;\r
   UINT64                              NewStackSize;\r
+  UINTN                               HeapTemporaryRamSize;\r
   EFI_PHYSICAL_ADDRESS                BaseOfNewHeap;\r
   EFI_PHYSICAL_ADDRESS                TopOfNewStack;\r
   EFI_PHYSICAL_ADDRESS                TopOfOldStack;\r
@@ -698,7 +700,7 @@ PeiDispatcher (
     SaveCurrentFileHandle =  Private->CurrentFileHandle;\r
 \r
     for (Index1 = 0; Index1 <= SaveCurrentFvCount; Index1++) {\r
-      for (Index2 = 0; (Index2 < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->Fv[Index1].FvFileHandles[Index2] != NULL); Index2++) {\r
+      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
           Status = PeiLoadImage (\r
@@ -784,7 +786,7 @@ PeiDispatcher (
       // Start to dispatch all modules within the current Fv.\r
       //\r
       for (PeimCount = Private->CurrentPeimCount;\r
-           (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL);\r
+           (PeimCount < PcdGet32 (PcdPeiCoreMaxPeimPerFv)) && (Private->CurrentFvFileHandles[PeimCount] != NULL);\r
            PeimCount++) {\r
         Private->CurrentPeimCount  = PeimCount;\r
         PeimFileHandle = Private->CurrentFileHandle = Private->CurrentFvFileHandles[PeimCount];\r
@@ -861,7 +863,7 @@ PeiDispatcher (
 \r
             if (Private->SwitchStackSignal) {\r
               //\r
-              // Before switch stack from temporary memory to permenent memory, caculate the heap and stack\r
+              // Before switch stack from temporary memory to permenent memory, calculate the heap and stack\r
               // usage in temporary memory for debuging.\r
               //\r
               DEBUG_CODE_BEGIN ();\r
@@ -911,7 +913,7 @@ PeiDispatcher (
               ASSERT (NewStackSize >= SecCoreData->StackSize);\r
 \r
               //\r
-              // Caculate stack offset and heap offset between temporary memory and new permement \r
+              // Calculate stack offset and heap offset between temporary memory and new permement \r
               // memory seperately.\r
               //\r
               TopOfOldStack = (UINTN)SecCoreData->StackBase + SecCoreData->StackSize;\r
@@ -926,8 +928,6 @@ PeiDispatcher (
               Private->StackOffsetPositive = StackOffsetPositive;\r
               Private->StackOffset = StackOffset;\r
 \r
-              DEBUG ((EFI_D_INFO, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (UINT64)Private->HeapOffset, (UINT64)(StackOffset)));\r
-\r
               //\r
               // Build Stack HOB that describes the permanent memory stack\r
               //\r
@@ -965,9 +965,11 @@ PeiDispatcher (
                   Private->HeapOffsetPositive = FALSE;\r
                   Private->HeapOffset = (UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - BaseOfNewHeap);\r
                 }\r
-                \r
+\r
+                DEBUG ((EFI_D_INFO, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (UINT64) Private->HeapOffset, (UINT64) Private->StackOffset));\r
+\r
                 //\r
-                // Caculate new HandOffTable and PrivateData address in permanent memory's stack\r
+                // Calculate new HandOffTable and PrivateData address in permanent memory's stack\r
                 //\r
                 if (StackOffsetPositive) {\r
                   SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID *)SecCoreData + StackOffset);\r
@@ -995,6 +997,11 @@ PeiDispatcher (
                 //\r
                 PeiCore (SecCoreData, NULL, Private);\r
               } else {\r
+                //\r
+                // Migrate the PEI Services Table pointer from temporary RAM to permanent RAM.\r
+                //\r
+                MigratePeiServicesTablePointer ();\r
+                \r
                 //\r
                 // Heap Offset\r
                 //\r
@@ -1015,10 +1022,14 @@ PeiDispatcher (
                   Private->HeapOffset = (UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - BaseOfNewHeap);\r
                 }\r
 \r
+                DEBUG ((EFI_D_INFO, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (UINT64) Private->HeapOffset, (UINT64) Private->StackOffset));\r
+\r
                 //\r
                 // Migrate Heap\r
                 //\r
-                CopyMem ((UINT8 *) (UINTN) BaseOfNewHeap, (UINT8 *) PeiTemporaryRamBase, PeiTemporaryRamSize);\r
+                HeapTemporaryRamSize = (UINTN) (Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom - Private->HobList.HandoffInformationTable->EfiMemoryBottom);\r
+                ASSERT (BaseOfNewHeap + HeapTemporaryRamSize <= Private->FreePhysicalMemoryTop);\r
+                CopyMem ((UINT8 *) (UINTN) BaseOfNewHeap, (UINT8 *) PeiTemporaryRamBase, HeapTemporaryRamSize);\r
                 \r
                 //\r
                 // Migrate Stack\r
@@ -1134,7 +1145,7 @@ PeiDispatcher (
       //\r
       // Before walking through the next FV,Private->CurrentFvFileHandles[]should set to NULL\r
       //\r
-      SetMem (Private->CurrentFvFileHandles, sizeof (Private->CurrentFvFileHandles), 0);\r
+      SetMem (Private->CurrentFvFileHandles, sizeof (EFI_PEI_FILE_HANDLE) * PcdGet32 (PcdPeiCoreMaxPeimPerFv), 0);\r
     }\r
 \r
     //\r