]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
Update input of disasmembler to support IfThen construct. Add prototype dos script...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Dispatcher / Dispatcher.c
index 5d9226fc7ec376d187ef2fdb00f32e2ad12ffe45..bdbb00b205f86dcec674c108743fe5a830811168 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI PEI Core dispatch services\r
   \r
-Copyright (c) 2006, Intel Corporation\r
+Copyright (c) 2006 - 2010, 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
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -12,10 +12,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include <PeiMain.h>\r
+#include "PeiMain.h"\r
 \r
 ///\r
-/// CAR is filled with this initial value during SEC phase\r
+/// temporary memory is filled with this initial value during SEC phase\r
 ///\r
 #define INIT_CAR_VALUE 0x5AA55AA5\r
 \r
@@ -30,14 +30,14 @@ typedef struct {
   Apriori file in one FV.\r
 \r
 \r
-  @param Private         - Pointer to the private data passed in from caller\r
-  @param VolumeHandle    - Fv handle.\r
+  @param Private          Pointer to the private data passed in from caller\r
+  @param CoreFileHandle   The instance of PEI_CORE_FV_HANDLE.\r
 \r
 **/\r
 VOID\r
 DiscoverPeimsAndOrderWithApriori (\r
   IN  PEI_CORE_INSTANCE    *Private,\r
-  IN  EFI_PEI_FV_HANDLE    VolumeHandle\r
+  IN  PEI_CORE_FV_HANDLE   *CoreFileHandle\r
   )\r
 {\r
   EFI_STATUS                          Status;\r
@@ -51,7 +51,11 @@ DiscoverPeimsAndOrderWithApriori (
   EFI_GUID                            *Guid;\r
   EFI_PEI_FV_HANDLE                   TempFileHandles[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];\r
   EFI_GUID                            FileGuid[FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv)];\r
-\r
+  EFI_PEI_FIRMWARE_VOLUME_PPI         *FvPpi;\r
+  EFI_FV_FILE_INFO                    FileInfo;\r
+  \r
+  FvPpi = CoreFileHandle->FvPpi;\r
+  \r
   //\r
   // Walk the FV and find all the PEIMs and the Apriori file.\r
   //\r
@@ -71,33 +75,39 @@ DiscoverPeimsAndOrderWithApriori (
   //\r
   // Go ahead to scan this Fv, and cache FileHandles within it.\r
   //\r
-  for (PeimCount = 0; PeimCount < FixedPcdGet32 (PcdPeiCoreMaxPeimPerFv); PeimCount++) {\r
-    Status = PeiFindFileEx (\r
-                VolumeHandle,\r
-                NULL,\r
-                PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE,\r
-                &FileHandle,\r
-                &AprioriFileHandle\r
-                );\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
       break;\r
     }\r
 \r
     Private->CurrentFvFileHandles[PeimCount] = FileHandle;\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
+  //\r
+  ASSERT (PeimCount < PcdGet32 (PcdPeiCoreMaxPeimPerFv));\r
 \r
+  //\r
+  // Get Apriori File handle\r
+  //\r
   Private->AprioriCount = 0;\r
-  if (AprioriFileHandle != NULL) {\r
+  Status = FvPpi->FindFileByName (FvPpi, &gPeiAprioriFileNameGuid, &CoreFileHandle->FvHandle, &AprioriFileHandle);\r
+  if (!EFI_ERROR(Status) && AprioriFileHandle != NULL) {\r
     //\r
     // Read the Apriori file\r
     //\r
-    Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, AprioriFileHandle, (VOID **) &Apriori);\r
+    Status = FvPpi->FindSectionByType (FvPpi, EFI_SECTION_RAW, AprioriFileHandle, (VOID **) &Apriori);\r
     if (!EFI_ERROR (Status)) {\r
       //\r
       // Calculate the number of PEIMs in the A Priori list\r
       //\r
-      Private->AprioriCount = *(UINT32 *)(((EFI_FFS_FILE_HEADER *)AprioriFileHandle)->Size) & 0x00FFFFFF;\r
-      Private->AprioriCount -= sizeof (EFI_FFS_FILE_HEADER) - sizeof (EFI_COMMON_SECTION_HEADER);\r
+      Status = FvPpi->GetFileInfo (FvPpi, AprioriFileHandle, &FileInfo);\r
+      ASSERT_EFI_ERROR (Status);\r
+      Private->AprioriCount = FileInfo.BufferSize & 0x00FFFFFF;\r
+      Private->AprioriCount -= sizeof (EFI_COMMON_SECTION_HEADER);\r
       Private->AprioriCount /= sizeof (EFI_GUID);\r
 \r
       ZeroMem (FileGuid, sizeof (FileGuid));\r
@@ -106,7 +116,8 @@ DiscoverPeimsAndOrderWithApriori (
         // Make an array of file name guids that matches the FileHandle array so we can convert\r
         // quickly from file name to file handle\r
         //\r
-        CopyMem (&FileGuid[Index], &((EFI_FFS_FILE_HEADER *)Private->CurrentFvFileHandles[Index])->Name,sizeof(EFI_GUID));\r
+        Status = FvPpi->GetFileInfo (FvPpi, Private->CurrentFvFileHandles[Index], &FileInfo);\r
+        CopyMem (&FileGuid[Index], &FileInfo.FileName, sizeof(EFI_GUID));\r
       }\r
 \r
       //\r
@@ -182,8 +193,8 @@ DiscoverPeimsAndOrderWithApriori (
 **/\r
 VOID*\r
 ShadowPeiCore(\r
-  EFI_PEI_SERVICES     **PeiServices,\r
-  PEI_CORE_INSTANCE    *PrivateInMem\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices,\r
+  IN       PEI_CORE_INSTANCE    *PrivateInMem\r
   )\r
 {\r
   EFI_PEI_FILE_HANDLE  PeiCoreFileHandle;\r
@@ -196,13 +207,12 @@ ShadowPeiCore(
   //\r
   // Find the PEI Core in the BFV\r
   //\r
-  Status = PeiFindFileEx (\r
-             (EFI_PEI_FV_HANDLE)PrivateInMem->Fv[0].FvHeader,\r
-             NULL,\r
-             EFI_FV_FILETYPE_PEI_CORE,\r
-             &PeiCoreFileHandle,\r
-             NULL\r
-             );\r
+  Status = PrivateInMem->Fv[0].FvPpi->FindFileByType (\r
+                                        PrivateInMem->Fv[0].FvPpi,\r
+                                        EFI_FV_FILETYPE_PEI_CORE,\r
+                                        PrivateInMem->Fv[0].FvHandle,\r
+                                        &PeiCoreFileHandle\r
+                                        );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
@@ -211,6 +221,7 @@ ShadowPeiCore(
   Status = PeiLoadImage (\r
               PeiServices,\r
               *((EFI_PEI_FILE_HANDLE*)&PeiCoreFileHandle),\r
+              PEIM_STATE_REGISITER_FOR_SHADOW,\r
               &EntryPoint,\r
               &AuthenticationState\r
               );\r
@@ -231,9 +242,6 @@ ShadowPeiCore(
                          the BFV location.\r
   @param Private         Pointer to the private data passed in from caller\r
 \r
-  @retval EFI_SUCCESS   - Successfully dispatched PEIM.\r
-  @retval EFI_NOT_FOUND - The dispatch failed.\r
-\r
 **/\r
 VOID\r
 PeiDispatcher (\r
@@ -244,8 +252,7 @@ PeiDispatcher (
   EFI_STATUS                          Status;\r
   UINT32                              Index1;\r
   UINT32                              Index2;\r
-  EFI_PEI_SERVICES                    **PeiServices;\r
-  EFI_PEI_FV_HANDLE                   VolumeHandle;\r
+  CONST EFI_PEI_SERVICES              **PeiServices;\r
   EFI_PEI_FILE_HANDLE                 PeimFileHandle;\r
   UINTN                               FvCount;\r
   UINTN                               PeimCount;\r
@@ -269,9 +276,9 @@ PeiDispatcher (
   EFI_FV_FILE_INFO                    FvFileInfo;\r
   UINTN                               OldCheckingTop;\r
   UINTN                               OldCheckingBottom;\r
+  PEI_CORE_FV_HANDLE                  *CoreFvHandle;\r
 \r
-\r
-  PeiServices = &Private->PS;\r
+  PeiServices = (CONST EFI_PEI_SERVICES **) &Private->PS;\r
   PeimEntryPoint = NULL;\r
   PeimFileHandle = NULL;\r
   EntryPoint     = 0;\r
@@ -286,12 +293,13 @@ 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
-                    &Private->PS,\r
+                    (CONST EFI_PEI_SERVICES **) &Private->PS,\r
                     PeimFileHandle,\r
+                    PEIM_STATE_REGISITER_FOR_SHADOW,\r
                     &EntryPoint,\r
                     &AuthenticationState\r
                     );\r
@@ -308,9 +316,9 @@ PeiDispatcher (
             //\r
             PeimEntryPoint = (EFI_PEIM_ENTRY_POINT2)(UINTN)EntryPoint;\r
 \r
-            PERF_START (0, "PEIM", NULL, 0);\r
+            PERF_START (PeimFileHandle, "PEIM", NULL, 0);\r
             PeimEntryPoint(PeimFileHandle, (const EFI_PEI_SERVICES **) &Private->PS);\r
-            PERF_END (0, "PEIM", NULL, 0);\r
+            PERF_END (PeimFileHandle, "PEIM", NULL, 0);\r
           }\r
 \r
           //\r
@@ -346,11 +354,17 @@ PeiDispatcher (
     }\r
     \r
     for (FvCount = Private->CurrentPeimFvCount; FvCount < Private->FvCount; FvCount++) {\r
-      Private->CurrentPeimFvCount = FvCount;\r
+      CoreFvHandle = FindNextCoreFvHandle (Private, FvCount);\r
+      ASSERT (CoreFvHandle != NULL);\r
+      \r
       //\r
-      // Get this Fv Handle by PeiService FvFindNextVolume.\r
+      // If the FV has corresponding EFI_PEI_FIRMWARE_VOLUME_PPI instance, then dispatch it.\r
       //\r
-      PeiFvFindNextVolume ((CONST EFI_PEI_SERVICES **) PeiServices, FvCount, &VolumeHandle);\r
+      if (CoreFvHandle->FvPpi == NULL) {\r
+        continue;\r
+      }\r
+      \r
+      Private->CurrentPeimFvCount = FvCount;\r
 \r
       if (Private->CurrentPeimCount == 0) {\r
         //\r
@@ -358,14 +372,14 @@ PeiDispatcher (
         // reorder all PEIMs to ensure the PEIMs in Apriori file to get\r
         // dispatch at first.\r
         //\r
-        DiscoverPeimsAndOrderWithApriori (Private, VolumeHandle);\r
+        DiscoverPeimsAndOrderWithApriori (Private, CoreFvHandle);\r
       }\r
 \r
       //\r
       // 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
@@ -374,13 +388,14 @@ PeiDispatcher (
           if (!DepexSatisfied (Private, PeimFileHandle, PeimCount)) {\r
             Private->PeimNeedingDispatch = TRUE;\r
           } else {\r
-            Status = PeiFfsGetFileInfo (PeimFileHandle, &FvFileInfo);\r
+            Status = CoreFvHandle->FvPpi->GetFileInfo (CoreFvHandle->FvPpi, PeimFileHandle, &FvFileInfo);\r
             ASSERT_EFI_ERROR (Status);\r
             if (FvFileInfo.FileType == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r
               //\r
               // For Fv type file, Produce new FV PPI and FV hob\r
               //\r
-              Status = ProcessFvFile (PeiServices, PeimFileHandle, &AuthenticationState);\r
+              Status = ProcessFvFile (&Private->Fv[FvCount], PeimFileHandle);\r
+              AuthenticationState = 0;\r
             } else {\r
               //\r
               // For PEIM driver, Load its entry point\r
@@ -388,6 +403,7 @@ PeiDispatcher (
               Status = PeiLoadImage (\r
                          PeiServices,\r
                          PeimFileHandle,\r
+                         PEIM_STATE_NOT_DISPATCHED,\r
                          &EntryPoint,\r
                          &AuthenticationState\r
                          );\r
@@ -398,18 +414,18 @@ PeiDispatcher (
               // The PEIM has its dependencies satisfied, and its entry point\r
               // has been found, so invoke it.\r
               //\r
-              PERF_START (0, "PEIM", NULL, 0);\r
+              PERF_START (PeimFileHandle, "PEIM", NULL, 0);\r
 \r
               ExtendedData.Handle = (EFI_HANDLE)PeimFileHandle;\r
 \r
               REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
                 EFI_PROGRESS_CODE,\r
-                FixedPcdGet32(PcdStatusCodeValuePeimDispatch),\r
+                (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN),\r
                 (VOID *)(&ExtendedData),\r
                 sizeof (ExtendedData)\r
                 );\r
 \r
-              Status = VerifyPeim (Private, VolumeHandle, PeimFileHandle);\r
+              Status = VerifyPeim (Private, CoreFvHandle->FvHandle, PeimFileHandle);\r
               if (Status != EFI_SECURITY_VIOLATION && (AuthenticationState == 0)) {\r
                 //\r
                 // PEIM_STATE_NOT_DISPATCHED move to PEIM_STATE_DISPATCHED\r
@@ -429,17 +445,17 @@ PeiDispatcher (
 \r
               REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
                 EFI_PROGRESS_CODE,\r
-                FixedPcdGet32(PcdStatusCodeValuePeimDispatch),\r
+                (EFI_SOFTWARE_PEI_CORE | EFI_SW_PC_INIT_BEGIN),\r
                 (VOID *)(&ExtendedData),\r
                 sizeof (ExtendedData)\r
                 );\r
-              PERF_END (0, "PEIM", NULL, 0);\r
+              PERF_END (PeimFileHandle, "PEIM", NULL, 0);\r
 \r
             }\r
 \r
             if (Private->SwitchStackSignal) {\r
               //\r
-              // Before switch stack from CAR to permenent memory, caculate the heap and stack\r
+              // Before switch stack from temporary memory to permenent memory, caculate the heap and stack\r
               // usage in temporary memory for debuging.\r
               //\r
               DEBUG_CODE_BEGIN ();\r
@@ -450,11 +466,11 @@ PeiDispatcher (
                      && (*StackPointer == INIT_CAR_VALUE);\r
                      StackPointer ++);\r
                      \r
-                DEBUG ((EFI_D_INFO, "Total Cache as RAM:    %d bytes.\n", SecCoreData->TemporaryRamSize));\r
-                DEBUG ((EFI_D_INFO, "  CAR stack ever used: %d bytes.\n",\r
+                DEBUG ((EFI_D_INFO, "Total temporary memory:    %d bytes.\n", (UINT32)SecCoreData->TemporaryRamSize));\r
+                DEBUG ((EFI_D_INFO, "  temporary memory stack ever used: %d bytes.\n",\r
                        (SecCoreData->StackSize - ((UINTN) StackPointer - (UINTN)SecCoreData->StackBase))\r
                       ));\r
-                DEBUG ((EFI_D_INFO, "  CAR heap used:       %d bytes.\n",\r
+                DEBUG ((EFI_D_INFO, "  temporary memory heap used:       %d bytes.\n",\r
                        ((UINTN) Private->HobList.HandoffInformationTable->EfiFreeMemoryBottom -\r
                        (UINTN) Private->HobList.Raw)\r
                       ));\r
@@ -465,10 +481,10 @@ PeiDispatcher (
               //\r
               OldPeiStackSize = (UINT64) SecCoreData->StackSize;\r
               NewPeiStackSize = (RShiftU64 (Private->PhysicalMemoryLength, 1) + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;\r
-              if (FixedPcdGet32(PcdPeiCoreMaxPeiStackSize) > (UINT32) NewPeiStackSize) {\r
+              if (PcdGet32(PcdPeiCoreMaxPeiStackSize) > (UINT32) NewPeiStackSize) {\r
                 Private->StackSize = NewPeiStackSize;\r
               } else {\r
-                Private->StackSize = FixedPcdGet32(PcdPeiCoreMaxPeiStackSize);\r
+                Private->StackSize = PcdGet32(PcdPeiCoreMaxPeiStackSize);\r
               }\r
 \r
               //\r
@@ -477,10 +493,9 @@ PeiDispatcher (
               // But if new stack is smaller than the size of old stack, we also reserve\r
               // the size of old stack at bottom of permenent memory.\r
               //\r
-              StackGap = 0;\r
-              if (Private->StackSize > OldPeiStackSize) {\r
-                StackGap = Private->StackSize - OldPeiStackSize;\r
-              }\r
+              DEBUG ((EFI_D_INFO, "Old Stack size %d, New stack size %d\n", (INT32) OldPeiStackSize, (INT32) Private->StackSize));\r
+              ASSERT (Private->StackSize >= OldPeiStackSize);\r
+              StackGap = Private->StackSize - OldPeiStackSize;\r
 \r
               //\r
               // Update HandOffHob for new installed permenent memory\r
@@ -496,13 +511,13 @@ PeiDispatcher (
               NewPermenentMemoryBase = Private->PhysicalMemoryBegin + StackGap;\r
               \r
               //\r
-              // Caculate stack offset and heap offset between CAR and new permement \r
+              // Caculate stack offset and heap offset between temporary memory and new permement \r
               // memory seperately.\r
               //\r
               StackOffset            = (UINTN) NewPermenentMemoryBase - (UINTN) SecCoreData->StackBase;\r
               HeapOffset             = (INTN) ((UINTN) Private->PhysicalMemoryBegin + Private->StackSize - \\r
                                                (UINTN) SecCoreData->PeiTemporaryRamBase);\r
-              DEBUG ((EFI_D_INFO, "Heap Offset = 0x%X Stack Offset = 0x%X\n", HeapOffset, StackOffset));\r
+              DEBUG ((EFI_D_INFO, "Heap Offset = 0x%lX Stack Offset = 0x%lX\n", (INT64)HeapOffset, (INT64)StackOffset));\r
               \r
               //\r
               // Caculate new HandOffTable and PrivateData address in permenet memory's stack\r
@@ -527,7 +542,7 @@ PeiDispatcher (
                 // Temporary Ram support Ppi is provided by platform, it will copy \r
                 // temporary memory to permenent memory and do stack switching.\r
                 // After invoken temporary Ram support, following code's stack is in \r
-                // memory but not in CAR.\r
+                // memory but not in temporary memory.\r
                 //\r
                 TemporaryRamSupportPpi->TemporaryRamMigration (\r
                                           (CONST EFI_PEI_SERVICES **) PeiServices,\r
@@ -554,7 +569,7 @@ PeiDispatcher (
               PrivateInMem->HobList.Raw = (VOID*) ((UINTN) PrivateInMem->HobList.Raw + HeapOffset);\r
               PrivateInMem->StackBase   = (EFI_PHYSICAL_ADDRESS)(((UINTN)PrivateInMem->PhysicalMemoryBegin + EFI_PAGE_MASK) & ~EFI_PAGE_MASK);\r
 \r
-              PeiServices = &PrivateInMem->PS;\r
+              PeiServices = (CONST EFI_PEI_SERVICES **) &PrivateInMem->PS;\r
 \r
               //\r
               // Fixup for PeiService's address\r
@@ -582,8 +597,8 @@ PeiDispatcher (
                                   HeapOffset\r
                                   );\r
 \r
-              DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%X Length=0x%X\n",\r
-                                  (UINTN)PrivateInMem->StackBase,\r
+              DEBUG ((EFI_D_INFO, "Stack Hob: BaseAddress=0x%lX Length=0x%lX\n",\r
+                                  PrivateInMem->StackBase,\r
                                   PrivateInMem->StackSize));\r
               BuildStackHob (PrivateInMem->StackBase, PrivateInMem->StackSize);\r
 \r
@@ -636,6 +651,7 @@ PeiDispatcher (
               // We call the entry point a 2nd time so the module knows it's shadowed.\r
               //\r
               //PERF_START (PeiServices, L"PEIM", PeimFileHandle, 0);\r
+              ASSERT (PeimEntryPoint != NULL);\r
               PeimEntryPoint (PeimFileHandle, (const EFI_PEI_SERVICES **) PeiServices);\r
               //PERF_END (PeiServices, L"PEIM", PeimFileHandle, 0);\r
 \r
@@ -708,6 +724,8 @@ InitializeDispatcherData (
   if (OldCoreData == NULL) {\r
     PrivateData->PeimDispatcherReenter = FALSE;\r
     PeiInitializeFv (PrivateData, SecCoreData);\r
+  } else {\r
+    PeiReinitializeFv (PrivateData);\r
   }\r
 \r
   return;\r
@@ -804,3 +822,5 @@ PeiRegisterForShadow (
   return EFI_SUCCESS;\r
 }\r
 \r
+\r
+\r