Revision: 14847
          http://sourceforge.net/p/edk2/code/14847
Author:   lgao4
Date:     2013-11-15 02:05:11 +0000 (Fri, 15 Nov 2013)
Log Message:
-----------
Add support for PI1.2.1 TempRam Done PPI.

Signed-off-by: Liming Gao <[email protected]>
Reviewed-by: Jeff Fan <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
    trunk/edk2/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
    trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.h
    trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.inf
    trunk/edk2/MdeModulePkg/Core/Pei/Ppi/Ppi.c

Modified: trunk/edk2/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c    2013-11-15 
02:04:57 UTC (rev 14846)
+++ trunk/edk2/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c    2013-11-15 
02:05:11 UTC (rev 14847)
@@ -606,7 +606,30 @@
   PrivateData->PhysicalMemoryBegin   = TopLoadingAddress - 
TotalReservedMemorySize;
   PrivateData->FreePhysicalMemoryTop = PrivateData->PhysicalMemoryBegin + 
PeiMemorySize;
 }
+
 /**
+  This routine is invoked in switch stack as PeiCore Entry.
+
+  @param SecCoreData     Points to a data structure containing information 
about the PEI core's operating
+                         environment, such as the size and location of 
temporary RAM, the stack location and
+                         the BFV location.
+  @param Private         Pointer to old core data that is used to initialize 
the
+                         core's data areas.
+**/
+VOID
+EFIAPI
+PeiCoreEntry (
+  IN CONST EFI_SEC_PEI_HAND_OFF    *SecCoreData,
+  IN PEI_CORE_INSTANCE             *Private
+  )
+{
+  //
+  // Entry PEI Phase 2
+  //
+  PeiCore (SecCoreData, NULL, Private);
+}
+
+/**
   Conduct PEIM dispatch.
 
   @param SecCoreData     Points to a data structure containing information 
about the PEI core's operating
@@ -637,17 +660,28 @@
   PEIM_FILE_HANDLE_EXTENDED_DATA      ExtendedData;
   EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI   *TemporaryRamSupportPpi;
   UINT64                              NewStackSize;
+  EFI_PHYSICAL_ADDRESS                BaseOfNewHeap;
   EFI_PHYSICAL_ADDRESS                TopOfNewStack;
   EFI_PHYSICAL_ADDRESS                TopOfOldStack;
   EFI_PHYSICAL_ADDRESS                TemporaryRamBase;
   UINTN                               TemporaryRamSize;
-  EFI_PHYSICAL_ADDRESS                TemporaryStackSize;
+  UINTN                               TemporaryStackSize;
+  VOID                                *TemporaryStackBase;
+  UINTN                               PeiTemporaryRamSize;
+  VOID                                *PeiTemporaryRamBase;
   UINTN                               StackOffset;
   BOOLEAN                             StackOffsetPositive;
+  EFI_PHYSICAL_ADDRESS                HoleMemBase;
+  UINTN                               HoleMemSize;
   EFI_FV_FILE_INFO                    FvFileInfo;
   PEI_CORE_FV_HANDLE                  *CoreFvHandle;
   VOID                                *LoadFixPeiCodeBegin;
-
+  EFI_PHYSICAL_ADDRESS                TempBase1;
+  UINTN                               TempSize1;
+  EFI_PHYSICAL_ADDRESS                TempBase2;
+  UINTN                               TempSize2;
+  UINTN                               Index;
+  
   PeiServices = (CONST EFI_PEI_SERVICES **) &Private->Ps;
   PeimEntryPoint = NULL;
   PeimFileHandle = NULL;
@@ -881,13 +915,6 @@
               //
               TopOfOldStack = (UINTN)SecCoreData->StackBase + 
SecCoreData->StackSize;
               TopOfNewStack = Private->PhysicalMemoryBegin + NewStackSize;
-              if (TopOfNewStack >= (UINTN)SecCoreData->PeiTemporaryRamBase) {
-                Private->HeapOffsetPositive = TRUE;
-                Private->HeapOffset = (UINTN)(TopOfNewStack - 
(UINTN)SecCoreData->PeiTemporaryRamBase);
-              } else {
-                Private->HeapOffsetPositive = FALSE;
-                Private->HeapOffset = 
(UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - TopOfNewStack);
-              }
               if (TopOfNewStack >= TopOfOldStack) {
                 StackOffsetPositive = TRUE;
                 StackOffset = (UINTN)(TopOfNewStack - TopOfOldStack);
@@ -909,22 +936,14 @@
               //
               // Cache information from SecCoreData into locals before 
SecCoreData is converted to a permanent memory address
               //
-              TemporaryRamBase   = 
(EFI_PHYSICAL_ADDRESS)(UINTN)SecCoreData->TemporaryRamBase;
-              TemporaryRamSize   = SecCoreData->TemporaryRamSize;
-              TemporaryStackSize = SecCoreData->StackSize;
-
+              TemporaryRamBase    = 
(EFI_PHYSICAL_ADDRESS)(UINTN)SecCoreData->TemporaryRamBase;
+              TemporaryRamSize    = SecCoreData->TemporaryRamSize;
+              TemporaryStackSize  = SecCoreData->StackSize;
+              TemporaryStackBase  = SecCoreData->StackBase;
+              PeiTemporaryRamSize = SecCoreData->PeiTemporaryRamSize;
+              PeiTemporaryRamBase = SecCoreData->PeiTemporaryRamBase;
+              
               //
-              // Caculate new HandOffTable and PrivateData address in 
permanent memory's stack
-              //
-              if (StackOffsetPositive) {
-                SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID 
*)SecCoreData + StackOffset);
-                Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private + 
StackOffset);
-              } else {
-                SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID 
*)SecCoreData - StackOffset);
-                Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private - 
StackOffset);
-              }
-
-              //
               // TemporaryRamSupportPpi is produced by platform's SEC
               //
               Status = PeiServicesLocatePpi (
@@ -935,6 +954,29 @@
                          );
               if (!EFI_ERROR (Status)) {
                 //
+                // Heap Offset
+                //
+                BaseOfNewHeap = TopOfNewStack;
+                if (BaseOfNewHeap >= (UINTN)SecCoreData->PeiTemporaryRamBase) {
+                  Private->HeapOffsetPositive = TRUE;
+                  Private->HeapOffset = (UINTN)(BaseOfNewHeap - 
(UINTN)SecCoreData->PeiTemporaryRamBase);
+                } else {
+                  Private->HeapOffsetPositive = FALSE;
+                  Private->HeapOffset = 
(UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - BaseOfNewHeap);
+                }
+                
+                //
+                // Caculate new HandOffTable and PrivateData address in 
permanent memory's stack
+                //
+                if (StackOffsetPositive) {
+                  SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID 
*)SecCoreData + StackOffset);
+                  Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private + 
StackOffset);
+                } else {
+                  SecCoreData = (CONST EFI_SEC_PEI_HAND_OFF *)((UINTN)(VOID 
*)SecCoreData - StackOffset);
+                  Private = (PEI_CORE_INSTANCE *)((UINTN)(VOID *)Private - 
StackOffset);
+                }
+
+                //
                 // Temporary Ram Support PPI is provided by platform, it will 
copy 
                 // temporary memory to permenent memory and do stack switching.
                 // After invoking Temporary Ram Support PPI, the following 
code's 
@@ -947,20 +989,100 @@
                                           TemporaryRamSize
                                           );
 
+                //
+                // Entry PEI Phase 2
+                //
+                PeiCore (SecCoreData, NULL, Private);
               } else {
                 //
-                // In IA32/x64/Itanium architecture, we need platform provide
-                // TEMPORARY_RAM_MIGRATION_PPI.
+                // Heap Offset
                 //
-                ASSERT (FALSE);
+                BaseOfNewHeap = TopOfNewStack;
+                HoleMemBase   = TopOfNewStack;
+                HoleMemSize   = TemporaryRamSize - PeiTemporaryRamSize - 
TemporaryStackSize;
+                if (HoleMemSize != 0) {
+                  BaseOfNewHeap = BaseOfNewHeap + HoleMemSize;
+                }
+                if (BaseOfNewHeap >= (UINTN)SecCoreData->PeiTemporaryRamBase) {
+                  Private->HeapOffsetPositive = TRUE;
+                  Private->HeapOffset = (UINTN)(BaseOfNewHeap - 
(UINTN)SecCoreData->PeiTemporaryRamBase);
+                } else {
+                  Private->HeapOffsetPositive = FALSE;
+                  Private->HeapOffset = 
(UINTN)((UINTN)SecCoreData->PeiTemporaryRamBase - BaseOfNewHeap);
+                }
+
+                //
+                // Migrate Heap
+                //
+                CopyMem ((UINT8 *) (UINTN) BaseOfNewHeap, (UINT8 *) 
PeiTemporaryRamBase, PeiTemporaryRamSize);
+                
+                //
+                // Migrate Stack
+                //
+                CopyMem ((UINT8 *) (UINTN) (TopOfNewStack - 
TemporaryStackSize), TemporaryStackBase, TemporaryStackSize);
+                
+                //
+                // Copy Hole Range Data
+                // Convert PPI from Hole. 
+                //
+                if (HoleMemSize != 0) {
+                  //
+                  // Prepare Hole
+                  //
+                  if (PeiTemporaryRamBase < TemporaryStackBase) {
+                    TempBase1 = (EFI_PHYSICAL_ADDRESS) (UINTN) 
PeiTemporaryRamBase;
+                    TempSize1 = PeiTemporaryRamSize;
+                    TempBase2 = (EFI_PHYSICAL_ADDRESS) (UINTN) 
TemporaryStackBase;
+                    TempSize2 = TemporaryStackSize;
+                  } else {
+                    TempBase1 = (EFI_PHYSICAL_ADDRESS) (UINTN) 
TemporaryStackBase;
+                    TempSize1 = TemporaryStackSize;
+                    TempBase2 =(EFI_PHYSICAL_ADDRESS) (UINTN) 
PeiTemporaryRamBase;
+                    TempSize2 = PeiTemporaryRamSize;
+                  }
+                  if (TemporaryRamBase < TempBase1) {
+                    Private->HoleData[0].Base = TemporaryRamBase;
+                    Private->HoleData[0].Size = (UINTN) (TempBase1 - 
TemporaryRamBase);
+                  }
+                  if (TempBase1 + TempSize1 < TempBase2) {
+                    Private->HoleData[1].Base = TempBase1 + TempSize1;
+                    Private->HoleData[1].Size = (UINTN) (TempBase2 - TempBase1 
- TempSize1);
+                  }
+                  if (TempBase2 + TempSize2 < TemporaryRamBase + 
TemporaryRamSize) {
+                    Private->HoleData[2].Base = TempBase2 + TempSize2;
+                    Private->HoleData[2].Size = (UINTN) (TemporaryRamBase + 
TemporaryRamSize - TempBase2 - TempSize2);
+                  }
+                  
+                  //
+                  // Copy Hole Range data.
+                  //
+                  for (Index = 0; Index < HOLE_MAX_NUMBER; Index ++) {
+                    if (Private->HoleData[Index].Size > 0) {
+                      if (HoleMemBase > Private->HoleData[Index].Base) {
+                        Private->HoleData[Index].OffsetPositive = TRUE;
+                        Private->HoleData[Index].Offset = (UINTN) (HoleMemBase 
- Private->HoleData[Index].Base);
+                      } else {
+                        Private->HoleData[Index].OffsetPositive = FALSE;
+                        Private->HoleData[Index].Offset = (UINTN) 
(Private->HoleData[Index].Base - HoleMemBase);
+                      }
+                      CopyMem ((VOID *) (UINTN) HoleMemBase, (VOID *) (UINTN) 
Private->HoleData[Index].Base, Private->HoleData[Index].Size);
+                      HoleMemBase = HoleMemBase + 
Private->HoleData[Index].Size;
+                    }
+                  }
+                }
+
+                //
+                // Switch new stack
+                //
+                SwitchStack (
+                  (SWITCH_STACK_ENTRY_POINT)(UINTN)PeiCoreEntry,
+                  (VOID *) SecCoreData,
+                  (VOID *) Private,
+                  (VOID *) (UINTN) TopOfNewStack
+                  );
               }
 
               //
-              // Entry PEI Phase 2
-              //
-              PeiCore (SecCoreData, NULL, Private);
-
-              //
               // Code should not come here
               //
               ASSERT (FALSE);

Modified: trunk/edk2/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c  2013-11-15 02:04:57 UTC 
(rev 14846)
+++ trunk/edk2/MdeModulePkg/Core/Pei/PeiMain/PeiMain.c  2013-11-15 02:05:11 UTC 
(rev 14847)
@@ -120,7 +120,7 @@
   from SEC to PEI. After switching stack in the PEI core, it will restart
   with the old core data.
 
-  @param SecCoreData     Points to a data structure containing information 
about the PEI core's operating
+  @param SecCoreDataPtr  Points to a data structure containing information 
about the PEI core's operating
                          environment, such as the size and location of 
temporary RAM, the stack location and
                          the BFV location.
   @param PpiList         Points to a list of one or more PPI descriptors to be 
installed initially by the PEI core.
@@ -137,23 +137,27 @@
 VOID
 EFIAPI
 PeiCore (
-  IN CONST EFI_SEC_PEI_HAND_OFF        *SecCoreData,
+  IN CONST EFI_SEC_PEI_HAND_OFF        *SecCoreDataPtr,
   IN CONST EFI_PEI_PPI_DESCRIPTOR      *PpiList,
   IN VOID                              *Data
   )
 {
   PEI_CORE_INSTANCE           PrivateData;
+  EFI_SEC_PEI_HAND_OFF        *SecCoreData;
+  EFI_SEC_PEI_HAND_OFF        NewSecCoreData;
   EFI_STATUS                  Status;
   PEI_CORE_TEMP_POINTERS      TempPtr;
   PEI_CORE_INSTANCE           *OldCoreData;
   EFI_PEI_CPU_IO_PPI          *CpuIo;
   EFI_PEI_PCI_CFG2_PPI        *PciCfg;
   EFI_HOB_HANDOFF_INFO_TABLE  *HandoffInformationTable;
-
+  EFI_PEI_TEMPORARY_RAM_DONE_PPI *TemporaryRamDonePpi;
+  
   //
   // Retrieve context passed into PEI Core
   //
-  OldCoreData = (PEI_CORE_INSTANCE *)Data;
+  OldCoreData = (PEI_CORE_INSTANCE *) Data;
+  SecCoreData = (EFI_SEC_PEI_HAND_OFF *) SecCoreDataPtr;
 
   //
   // Perform PEI Core phase specific actions.
@@ -250,9 +254,11 @@
     //
     // Memory is available to the PEI Core and the PEI Core has been shadowed 
to memory.
     //
-    
+    CopyMem (&NewSecCoreData, SecCoreDataPtr, sizeof (NewSecCoreData));
+    SecCoreData = &NewSecCoreData;
+
     CopyMem (&PrivateData, OldCoreData, sizeof (PrivateData));
-    
+
     CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;
     PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;
     
@@ -329,6 +335,22 @@
     }
   } else {
     //
+    // Try to locate Temporary RAM Done Ppi.
+    //
+    Status = PeiServicesLocatePpi (
+               &gEfiTemporaryRamDonePpiGuid,
+               0,
+               NULL,
+               (VOID**)&TemporaryRamDonePpi
+               );
+    if (!EFI_ERROR (Status)) {
+      //
+      // Disable the use of Temporary RAM after the transition from Temporary 
RAM to Permanent RAM is complete.
+      //
+      TemporaryRamDonePpi->TemporaryRamDone ();
+    }
+
+    //
     // Alert any listeners that there is permanent memory available
     //
     PERF_START (NULL,"DisMem", NULL, 0);

Modified: trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.h
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.h  2013-11-15 02:04:57 UTC (rev 
14846)
+++ trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.h  2013-11-15 02:05:11 UTC (rev 
14847)
@@ -28,6 +28,7 @@
 #include <Ppi/LoadFile.h>
 #include <Ppi/Security2.h>
 #include <Ppi/TemporaryRamSupport.h>
+#include <Ppi/TemporaryRamDone.h>
 #include <Library/DebugLib.h>
 #include <Library/PeiCoreEntryPoint.h>
 #include <Library/BaseLib.h>
@@ -132,6 +133,14 @@
   UINTN                               SectionIndex;
 } CACHE_SECTION_DATA;
 
+#define HOLE_MAX_NUMBER       0x3
+typedef struct {
+  EFI_PHYSICAL_ADDRESS               Base;
+  UINTN                              Size;
+  UINTN                              Offset;
+  BOOLEAN                            OffsetPositive;
+} HOLE_MEMORY_DATA;
+
 ///
 /// Forward declaration for PEI_CORE_INSTANCE
 ///
@@ -225,6 +234,11 @@
   // This field points to the shadowed image read function
   //
   PE_COFF_LOADER_READ_FILE          ShadowedImageRead;
+  //
+  // Temp Memory Range is not covered by PeiTempMem and Stack.
+  // Those Memory Range will be migrated into phisical memory. 
+  //
+  HOLE_MEMORY_DATA                  HoleData[HOLE_MAX_NUMBER];
 };
 
 ///

Modified: trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.inf
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.inf        2013-11-15 02:04:57 UTC 
(rev 14846)
+++ trunk/edk2/MdeModulePkg/Core/Pei/PeiMain.inf        2013-11-15 02:05:11 UTC 
(rev 14847)
@@ -84,7 +84,8 @@
   gEfiPeiFirmwareVolumeInfo2PpiGuid             ## NOTIFY   ## 
SOMETIMES_PRODUCES (Produce FvInfo2Ppi if the encapsulated FvImage is found)
   gEfiPeiLoadFilePpiGuid                        ## PRODUCES ## 
SOMETIMES_CONSUMES (The default load PeImage logic will be used when this PPI 
doesn't exist)
   gEfiPeiSecurity2PpiGuid                       ## NOTIFY
-  gEfiTemporaryRamSupportPpiGuid                ## CONSUMES
+  gEfiTemporaryRamSupportPpiGuid                ## SOMETIMES_CONSUMES
+  gEfiTemporaryRamDonePpiGuid                   ## SOMETIMES_CONSUMES
 
 [FixedPcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported             ## 
CONSUMES

Modified: trunk/edk2/MdeModulePkg/Core/Pei/Ppi/Ppi.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Pei/Ppi/Ppi.c  2013-11-15 02:04:57 UTC (rev 
14846)
+++ trunk/edk2/MdeModulePkg/Core/Pei/Ppi/Ppi.c  2013-11-15 02:05:11 UTC (rev 
14847)
@@ -1,7 +1,7 @@
 /** @file
   EFI PEI Core PPI services
   
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -38,8 +38,73 @@
 
 /**
 
-  Migrate the Hob list from the temporary memory stack to PEI installed memory.
+  Migrate Single PPI Pointer from the temporary memory to PEI installed memory.
 
+  @param PpiPointer      Pointer to Ppi
+  @param TempBottom      Base of old temporary memory
+  @param TempTop         Top of old temporary memory
+  @param Offset          Offset of new memory to old temporary memory.
+  @param OffsetPositive  Positive flag of Offset value. 
+
+**/
+VOID
+ConverSinglePpiPointer (
+  IN PEI_PPI_LIST_POINTERS *PpiPointer,
+  IN UINTN                 TempBottom,
+  IN UINTN                 TempTop,
+  IN UINTN                 Offset,
+  IN BOOLEAN               OffsetPositive
+  )
+{
+  if (((UINTN)PpiPointer->Raw < TempTop) &&
+      ((UINTN)PpiPointer->Raw >= TempBottom)) {
+    //
+    // Convert the pointer to the PPI descriptor from the old TempRam
+    // to the relocated physical memory.
+    //
+    if (OffsetPositive) {
+      PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw + Offset);
+    } else {
+      PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw - Offset);
+    }
+
+    //
+    // Only when the PEIM descriptor is in the old TempRam should it be 
necessary
+    // to try to convert the pointers in the PEIM descriptor
+    //
+
+    if (((UINTN)PpiPointer->Ppi->Guid < TempTop) &&
+        ((UINTN)PpiPointer->Ppi->Guid >= TempBottom)) {
+      //
+      // Convert the pointer to the GUID in the PPI or NOTIFY descriptor
+      // from the old TempRam to the relocated physical memory.
+      //
+      if (OffsetPositive) {
+        PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid + 
Offset);
+      } else {
+        PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid - 
Offset);
+      }
+    }
+
+    //
+    // Convert the pointer to the PPI interface structure in the PPI descriptor
+    // from the old TempRam to the relocated physical memory.
+    //
+    if ((UINTN)PpiPointer->Ppi->Ppi < TempTop &&
+        (UINTN)PpiPointer->Ppi->Ppi >= TempBottom) {
+      if (OffsetPositive) {
+        PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi + Offset);
+      } else {
+        PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi - Offset);
+      }
+    }
+  }
+}
+
+/**
+
+  Migrate PPI Pointers from the temporary memory stack to PEI installed memory.
+
   @param SecCoreData     Points to a data structure containing SEC to PEI 
handoff data, such as the size 
                          and location of temporary RAM, the stack location and 
the BFV location.
   @param PrivateData     Pointer to PeiCore's private data structure.
@@ -52,114 +117,47 @@
   )
 {
   UINT8                 Index;
-  PEI_PPI_LIST_POINTERS *PpiPointer;
-  UINTN                 OldHeapTop;
-  UINTN                 OldHeapBottom;
-  UINTN                 OldStackTop;
-  UINTN                 OldStackBottom;
+  UINT8                 IndexHole;
 
-  OldHeapBottom = (UINTN)SecCoreData->PeiTemporaryRamBase;
-  OldHeapTop = (UINTN)SecCoreData->PeiTemporaryRamBase + 
SecCoreData->PeiTemporaryRamSize;
-  OldStackBottom = (UINTN)SecCoreData->StackBase;
-  OldStackTop = (UINTN)SecCoreData->StackBase + SecCoreData->StackSize;
-
   for (Index = 0; Index < FixedPcdGet32 (PcdPeiCoreMaxPpiSupported); Index++) {
-    if (Index < PrivateData->PpiData.PpiListEnd ||
-        Index > PrivateData->PpiData.NotifyListEnd) {
-      PpiPointer = &PrivateData->PpiData.PpiListPtrs[Index];
-
-      if (((UINTN)PpiPointer->Raw < OldHeapTop) &&
-          ((UINTN)PpiPointer->Raw >= OldHeapBottom)) {
-        //
-        // Convert the pointer to the PPI descriptor from the old HOB heap
-        // to the relocated HOB heap.
-        //
-        if (PrivateData->HeapOffsetPositive) {
-          PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw + 
PrivateData->HeapOffset);
-        } else {
-          PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw - 
PrivateData->HeapOffset);
+    if (Index < PrivateData->PpiData.PpiListEnd || Index > 
PrivateData->PpiData.NotifyListEnd) {
+      //
+      // Convert PPI pointer in old Heap
+      //
+      ConverSinglePpiPointer (
+        &PrivateData->PpiData.PpiListPtrs[Index],
+        (UINTN)SecCoreData->PeiTemporaryRamBase,
+        (UINTN)SecCoreData->PeiTemporaryRamBase + 
SecCoreData->PeiTemporaryRamSize,
+        PrivateData->HeapOffset,
+        PrivateData->HeapOffsetPositive
+        );
+        
+      //
+      // Convert PPI pointer in old Stack
+      //
+      ConverSinglePpiPointer (
+        &PrivateData->PpiData.PpiListPtrs[Index],
+        (UINTN)SecCoreData->StackBase,
+        (UINTN)SecCoreData->StackBase + SecCoreData->StackSize,
+        PrivateData->StackOffset,
+        PrivateData->StackOffsetPositive
+        );
+        
+      //
+      // Convert PPI pointer in old TempRam Hole
+      //
+      for (IndexHole = 0; IndexHole < HOLE_MAX_NUMBER; IndexHole ++) {
+        if (PrivateData->HoleData[IndexHole].Size == 0) {
+          continue;
         }
-
-        //
-        // Only when the PEIM descriptor is in the old HOB should it be 
necessary
-        // to try to convert the pointers in the PEIM descriptor
-        //
-
-        if (((UINTN)PpiPointer->Ppi->Guid < OldHeapTop) &&
-            ((UINTN)PpiPointer->Ppi->Guid >= OldHeapBottom)) {
-          //
-          // Convert the pointer to the GUID in the PPI or NOTIFY descriptor
-          // from the old HOB heap to the relocated HOB heap.
-          //
-          if (PrivateData->HeapOffsetPositive) {
-            PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid + 
PrivateData->HeapOffset);
-          } else {
-            PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid - 
PrivateData->HeapOffset);
-          }
-        }
-
-        //
-        // Assume that no code is located in the temporary memory, so the 
pointer to
-        // the notification function in the NOTIFY descriptor needs not be 
converted.
-        //
-        if (Index < PrivateData->PpiData.PpiListEnd &&
-            (UINTN)PpiPointer->Ppi->Ppi < OldHeapTop &&
-            (UINTN)PpiPointer->Ppi->Ppi >= OldHeapBottom) {
-          //
-          // Convert the pointer to the PPI interface structure in the PPI 
descriptor
-          // from the old HOB heap to the relocated HOB heap.
-          //
-          if (PrivateData->HeapOffsetPositive) {
-            PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi + 
PrivateData->HeapOffset);
-          } else {
-            PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi - 
PrivateData->HeapOffset);
-          }
-        }
-      } else if (((UINTN)PpiPointer->Raw < OldStackTop) && 
((UINTN)PpiPointer->Raw >= OldStackBottom)) {
-        //
-        // Convert the pointer to the PPI descriptor from the temporary stack
-        // to the permanent PEI stack.
-        //
-        if (PrivateData->StackOffsetPositive) {
-          PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw + 
PrivateData->StackOffset);
-        } else {
-          PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw - 
PrivateData->StackOffset);
-        }
-
-        //
-        // Try to convert the pointers in the PEIM descriptor
-        //
-
-        if (((UINTN)PpiPointer->Ppi->Guid < OldStackTop) &&
-            ((UINTN)PpiPointer->Ppi->Guid >= OldStackBottom)) {
-          //
-          // Convert the pointer to the GUID in the PPI or NOTIFY descriptor
-          // from the the temporary stack to the permanent PEI stack.
-          //
-          if (PrivateData->StackOffsetPositive) {
-            PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid + 
PrivateData->StackOffset);
-          } else {
-            PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid - 
PrivateData->StackOffset);
-          }
-        }
-
-        //
-        // Assume that no code is located in the temporary memory, so the 
pointer to
-        // the notification function in the NOTIFY descriptor needs not be 
converted.
-        //
-        if (Index < PrivateData->PpiData.PpiListEnd &&
-            (UINTN)PpiPointer->Ppi->Ppi < OldStackTop &&
-            (UINTN)PpiPointer->Ppi->Ppi >= OldStackBottom) {
-          //
-          // Convert the pointer to the PPI interface structure in the PPI 
descriptor
-          // from the the temporary stack to the permanent PEI stack.
-          //
-          if (PrivateData->StackOffsetPositive) {
-            PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi + 
PrivateData->StackOffset);
-          } else {
-            PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi - 
PrivateData->StackOffset);
-          }
-        }
+        
+        ConverSinglePpiPointer (
+          &PrivateData->PpiData.PpiListPtrs[Index],
+          (UINTN)PrivateData->HoleData[IndexHole].Base,
+          (UINTN)PrivateData->HoleData[IndexHole].Base + 
PrivateData->HoleData[IndexHole].Size,
+          PrivateData->HoleData[IndexHole].Offset,
+          PrivateData->HoleData[IndexHole].OffsetPositive
+          );
       }
     }
   }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to