]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Ppi/Ppi.c
Add support for PI1.2.1 TempRam Done PPI.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Ppi / Ppi.c
index 6664b5b898c2169b78bac16815ab1aab2320ce12..9fe95acb86d3e34f5c7fcf59c12cdefb07c624c1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI PEI Core PPI services\r
   \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, 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
@@ -38,7 +38,72 @@ InitializePpiServices (
 \r
 /**\r
 \r
-  Migrate the Hob list from the temporary memory stack to PEI installed memory.\r
+  Migrate Single PPI Pointer from the temporary memory to PEI installed memory.\r
+\r
+  @param PpiPointer      Pointer to Ppi\r
+  @param TempBottom      Base of old temporary memory\r
+  @param TempTop         Top of old temporary memory\r
+  @param Offset          Offset of new memory to old temporary memory.\r
+  @param OffsetPositive  Positive flag of Offset value. \r
+\r
+**/\r
+VOID\r
+ConverSinglePpiPointer (\r
+  IN PEI_PPI_LIST_POINTERS *PpiPointer,\r
+  IN UINTN                 TempBottom,\r
+  IN UINTN                 TempTop,\r
+  IN UINTN                 Offset,\r
+  IN BOOLEAN               OffsetPositive\r
+  )\r
+{\r
+  if (((UINTN)PpiPointer->Raw < TempTop) &&\r
+      ((UINTN)PpiPointer->Raw >= TempBottom)) {\r
+    //\r
+    // Convert the pointer to the PPI descriptor from the old TempRam\r
+    // to the relocated physical memory.\r
+    //\r
+    if (OffsetPositive) {\r
+      PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw + Offset);\r
+    } else {\r
+      PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw - Offset);\r
+    }\r
+\r
+    //\r
+    // Only when the PEIM descriptor is in the old TempRam should it be necessary\r
+    // to try to convert the pointers in the PEIM descriptor\r
+    //\r
+\r
+    if (((UINTN)PpiPointer->Ppi->Guid < TempTop) &&\r
+        ((UINTN)PpiPointer->Ppi->Guid >= TempBottom)) {\r
+      //\r
+      // Convert the pointer to the GUID in the PPI or NOTIFY descriptor\r
+      // from the old TempRam to the relocated physical memory.\r
+      //\r
+      if (OffsetPositive) {\r
+        PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid + Offset);\r
+      } else {\r
+        PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid - Offset);\r
+      }\r
+    }\r
+\r
+    //\r
+    // Convert the pointer to the PPI interface structure in the PPI descriptor\r
+    // from the old TempRam to the relocated physical memory.\r
+    //\r
+    if ((UINTN)PpiPointer->Ppi->Ppi < TempTop &&\r
+        (UINTN)PpiPointer->Ppi->Ppi >= TempBottom) {\r
+      if (OffsetPositive) {\r
+        PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi + Offset);\r
+      } else {\r
+        PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi - Offset);\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+/**\r
+\r
+  Migrate PPI Pointers from the temporary memory stack to PEI installed memory.\r
 \r
   @param SecCoreData     Points to a data structure containing SEC to PEI handoff data, such as the size \r
                          and location of temporary RAM, the stack location and the BFV location.\r
@@ -52,114 +117,47 @@ ConvertPpiPointers (
   )\r
 {\r
   UINT8                 Index;\r
-  PEI_PPI_LIST_POINTERS *PpiPointer;\r
-  UINTN                 OldHeapTop;\r
-  UINTN                 OldHeapBottom;\r
-  UINTN                 OldStackTop;\r
-  UINTN                 OldStackBottom;\r
-\r
-  OldHeapBottom = (UINTN)SecCoreData->PeiTemporaryRamBase;\r
-  OldHeapTop = (UINTN)SecCoreData->PeiTemporaryRamBase + SecCoreData->PeiTemporaryRamSize;\r
-  OldStackBottom = (UINTN)SecCoreData->StackBase;\r
-  OldStackTop = (UINTN)SecCoreData->StackBase + SecCoreData->StackSize;\r
+  UINT8                 IndexHole;\r
 \r
   for (Index = 0; Index < FixedPcdGet32 (PcdPeiCoreMaxPpiSupported); Index++) {\r
-    if (Index < PrivateData->PpiData.PpiListEnd ||\r
-        Index > PrivateData->PpiData.NotifyListEnd) {\r
-      PpiPointer = &PrivateData->PpiData.PpiListPtrs[Index];\r
-\r
-      if (((UINTN)PpiPointer->Raw < OldHeapTop) &&\r
-          ((UINTN)PpiPointer->Raw >= OldHeapBottom)) {\r
-        //\r
-        // Convert the pointer to the PPI descriptor from the old HOB heap\r
-        // to the relocated HOB heap.\r
-        //\r
-        if (PrivateData->HeapOffsetPositive) {\r
-          PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw + PrivateData->HeapOffset);\r
-        } else {\r
-          PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw - PrivateData->HeapOffset);\r
-        }\r
-\r
-        //\r
-        // Only when the PEIM descriptor is in the old HOB should it be necessary\r
-        // to try to convert the pointers in the PEIM descriptor\r
-        //\r
-\r
-        if (((UINTN)PpiPointer->Ppi->Guid < OldHeapTop) &&\r
-            ((UINTN)PpiPointer->Ppi->Guid >= OldHeapBottom)) {\r
-          //\r
-          // Convert the pointer to the GUID in the PPI or NOTIFY descriptor\r
-          // from the old HOB heap to the relocated HOB heap.\r
-          //\r
-          if (PrivateData->HeapOffsetPositive) {\r
-            PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid + PrivateData->HeapOffset);\r
-          } else {\r
-            PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid - PrivateData->HeapOffset);\r
-          }\r
-        }\r
-\r
-        //\r
-        // Assume that no code is located in the temporary memory, so the pointer to\r
-        // the notification function in the NOTIFY descriptor needs not be converted.\r
-        //\r
-        if (Index < PrivateData->PpiData.PpiListEnd &&\r
-            (UINTN)PpiPointer->Ppi->Ppi < OldHeapTop &&\r
-            (UINTN)PpiPointer->Ppi->Ppi >= OldHeapBottom) {\r
-          //\r
-          // Convert the pointer to the PPI interface structure in the PPI descriptor\r
-          // from the old HOB heap to the relocated HOB heap.\r
-          //\r
-          if (PrivateData->HeapOffsetPositive) {\r
-            PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi + PrivateData->HeapOffset);\r
-          } else {\r
-            PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi - PrivateData->HeapOffset);\r
-          }\r
-        }\r
-      } else if (((UINTN)PpiPointer->Raw < OldStackTop) && ((UINTN)PpiPointer->Raw >= OldStackBottom)) {\r
-        //\r
-        // Convert the pointer to the PPI descriptor from the temporary stack\r
-        // to the permanent PEI stack.\r
-        //\r
-        if (PrivateData->StackOffsetPositive) {\r
-          PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw + PrivateData->StackOffset);\r
-        } else {\r
-          PpiPointer->Raw = (VOID *) ((UINTN)PpiPointer->Raw - PrivateData->StackOffset);\r
-        }\r
-\r
-        //\r
-        // Try to convert the pointers in the PEIM descriptor\r
-        //\r
-\r
-        if (((UINTN)PpiPointer->Ppi->Guid < OldStackTop) &&\r
-            ((UINTN)PpiPointer->Ppi->Guid >= OldStackBottom)) {\r
-          //\r
-          // Convert the pointer to the GUID in the PPI or NOTIFY descriptor\r
-          // from the the temporary stack to the permanent PEI stack.\r
-          //\r
-          if (PrivateData->StackOffsetPositive) {\r
-            PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid + PrivateData->StackOffset);\r
-          } else {\r
-            PpiPointer->Ppi->Guid = (VOID *) ((UINTN)PpiPointer->Ppi->Guid - PrivateData->StackOffset);\r
-          }\r
-        }\r
-\r
-        //\r
-        // Assume that no code is located in the temporary memory, so the pointer to\r
-        // the notification function in the NOTIFY descriptor needs not be converted.\r
-        //\r
-        if (Index < PrivateData->PpiData.PpiListEnd &&\r
-            (UINTN)PpiPointer->Ppi->Ppi < OldStackTop &&\r
-            (UINTN)PpiPointer->Ppi->Ppi >= OldStackBottom) {\r
-          //\r
-          // Convert the pointer to the PPI interface structure in the PPI descriptor\r
-          // from the the temporary stack to the permanent PEI stack.\r
-          //\r
-          if (PrivateData->StackOffsetPositive) {\r
-            PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi + PrivateData->StackOffset);\r
-          } else {\r
-            PpiPointer->Ppi->Ppi = (VOID *) ((UINTN)PpiPointer->Ppi->Ppi - PrivateData->StackOffset);\r
-          }\r
+    if (Index < PrivateData->PpiData.PpiListEnd || Index > PrivateData->PpiData.NotifyListEnd) {\r
+      //\r
+      // Convert PPI pointer in old Heap\r
+      //\r
+      ConverSinglePpiPointer (\r
+        &PrivateData->PpiData.PpiListPtrs[Index],\r
+        (UINTN)SecCoreData->PeiTemporaryRamBase,\r
+        (UINTN)SecCoreData->PeiTemporaryRamBase + SecCoreData->PeiTemporaryRamSize,\r
+        PrivateData->HeapOffset,\r
+        PrivateData->HeapOffsetPositive\r
+        );\r
+        \r
+      //\r
+      // Convert PPI pointer in old Stack\r
+      //\r
+      ConverSinglePpiPointer (\r
+        &PrivateData->PpiData.PpiListPtrs[Index],\r
+        (UINTN)SecCoreData->StackBase,\r
+        (UINTN)SecCoreData->StackBase + SecCoreData->StackSize,\r
+        PrivateData->StackOffset,\r
+        PrivateData->StackOffsetPositive\r
+        );\r
+        \r
+      //\r
+      // Convert PPI pointer in old TempRam Hole\r
+      //\r
+      for (IndexHole = 0; IndexHole < HOLE_MAX_NUMBER; IndexHole ++) {\r
+        if (PrivateData->HoleData[IndexHole].Size == 0) {\r
+          continue;\r
         }\r
+        \r
+        ConverSinglePpiPointer (\r
+          &PrivateData->PpiData.PpiListPtrs[Index],\r
+          (UINTN)PrivateData->HoleData[IndexHole].Base,\r
+          (UINTN)PrivateData->HoleData[IndexHole].Base + PrivateData->HoleData[IndexHole].Size,\r
+          PrivateData->HoleData[IndexHole].Offset,\r
+          PrivateData->HoleData[IndexHole].OffsetPositive\r
+          );\r
       }\r
     }\r
   }\r