]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
MdeModulePkg/IntelFrameworkModulePkg: Update PeiCore, SmbiosDxe and IsaSerialDxe...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Dispatcher / Dispatcher.c
index 96381cd8c0281d3c73faf25287938686afae54cb..4004a3ad6286d7224bb1045ba4f8ae62ea638b32 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 - 2014, 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)];\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,32 +63,35 @@ 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
   //\r
   // Go ahead to scan this Fv, and cache FileHandles within it.\r
   //\r
-  for (PeimCount = 0; PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {\r
+  Status = EFI_NOT_FOUND;\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) {\r
+    if (Status != EFI_SUCCESS || PeimCount == PcdGet32 (PcdPeiCoreMaxPeimPerFv)) {\r
       break;\r
     }\r
 \r
     Private->CurrentFvFileHandles[PeimCount] = FileHandle;\r
   }\r
-  \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 (PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv));\r
+  ASSERT ((Status != EFI_SUCCESS) || (PeimCount < PcdGet32 (PcdPeiCoreMaxPeimPerFv)));\r
 \r
   //\r
   // Get Apriori File handle\r
@@ -114,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
@@ -175,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
@@ -183,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
@@ -660,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
@@ -697,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
@@ -783,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
@@ -925,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
@@ -964,7 +965,9 @@ 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
                 //\r
@@ -994,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
@@ -1001,7 +1009,10 @@ PeiDispatcher (
                 HoleMemBase   = TopOfNewStack;\r
                 HoleMemSize   = TemporaryRamSize - PeiTemporaryRamSize - TemporaryStackSize;\r
                 if (HoleMemSize != 0) {\r
-                  BaseOfNewHeap = BaseOfNewHeap + HoleMemSize;\r
+                  //\r
+                  // Make sure HOB List start address is 8 byte alignment.\r
+                  //\r
+                  BaseOfNewHeap = ALIGN_VALUE (BaseOfNewHeap + HoleMemSize, 8);\r
                 }\r
                 if (BaseOfNewHeap >= (UINTN)SecCoreData->PeiTemporaryRamBase) {\r
                   Private->HeapOffsetPositive = TRUE;\r
@@ -1011,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
@@ -1130,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