]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Memory/MemoryServices.c
Temporarily rollback the change from 5625 though 5628 for more investigation.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Memory / MemoryServices.c
index 7e841c3c461a7ef35888a6a518ca4b943ba9476e..d24897d7767b505022f074df42f25342b67881b3 100644 (file)
@@ -18,7 +18,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
   Initialize the memory services.\r
 \r
-  @param PrivateData     Points to PeiCore's private instance data.\r
+\r
+  @param PrivateData     Add parameter description\r
   @param SecCoreData     Points to a data structure containing information about the PEI core's operating\r
                          environment, such as the size and location of temporary RAM, the stack location and\r
                          the BFV location.\r
@@ -75,13 +76,9 @@ InitializeMemoryServices (
 \r
 /**\r
 \r
-  This function registers the found memory configuration with the PEI Foundation.\r
+  Install the permanent memory is now available.\r
+  Creates HOB (PHIT and Stack).\r
 \r
-  The usage model is that the PEIM that discovers the permanent memory shall invoke this service.\r
-  This routine will hold discoveried memory information into PeiCore's private data,\r
-  and set SwitchStackSignal flag. After PEIM who discovery memory is dispatched,\r
-  PeiDispatcher will migrate temporary memory to permenement memory.\r
-  \r
   @param PeiServices        An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
   @param MemoryBegin        Start of memory address.\r
   @param MemoryLength       Length of memory.\r
@@ -123,6 +120,7 @@ PeiInstallPeiMemory (
   @param Memory          Pointer of memory allocated.\r
 \r
   @retval EFI_SUCCESS              The allocation was successful\r
+  @retval EFI_INVALID_PARAMETER    Only AllocateAnyAddress is supported.\r
   @retval EFI_NOT_AVAILABLE_YET    Called with permanent memory not available\r
   @retval EFI_OUT_OF_RESOURCES     There is not enough HOB heap to satisfy the requirement\r
                                    to allocate the number of pages.\r
@@ -131,14 +129,15 @@ PeiInstallPeiMemory (
 EFI_STATUS\r
 EFIAPI\r
 PeiAllocatePages (\r
-  IN CONST EFI_PEI_SERVICES     **PeiServices,\r
-  IN       EFI_MEMORY_TYPE      MemoryType,\r
-  IN       UINTN                Pages,\r
-  OUT      EFI_PHYSICAL_ADDRESS *Memory\r
+  IN CONST EFI_PEI_SERVICES           **PeiServices,\r
+  IN EFI_MEMORY_TYPE            MemoryType,\r
+  IN UINTN                      Pages,\r
+  OUT EFI_PHYSICAL_ADDRESS      *Memory\r
   )\r
 {\r
   PEI_CORE_INSTANCE                       *PrivateData;\r
   EFI_PEI_HOB_POINTERS                    Hob;\r
+  EFI_PHYSICAL_ADDRESS                    Offset;\r
   EFI_PHYSICAL_ADDRESS                    *FreeMemoryTop;\r
   EFI_PHYSICAL_ADDRESS                    *FreeMemoryBottom;\r
 \r
@@ -151,7 +150,7 @@ PeiAllocatePages (
   if (!PrivateData->PeiMemoryInstalled) {\r
     //\r
     // When PeiInstallMemory is called but CAR has *not* been moved to temporary memory,\r
-    // the AllocatePage will dependent on the field of PEI_CORE_INSTANCE structure.\r
+    // the AllocatePage will dependent the field of PEI_CORE_INSTANCE structure.\r
     //\r
     if (!PrivateData->SwitchStackSignal) {\r
       return EFI_NOT_AVAILABLE_YET;\r
@@ -165,9 +164,16 @@ PeiAllocatePages (
   }\r
 \r
   //\r
-  // Check to see if on 4k boundary, If not aligned, make the allocation aligned.\r
+  // Check to see if on 4k boundary\r
   //\r
-  *(FreeMemoryTop) -= *(FreeMemoryTop) & 0xFFF;\r
+  Offset = *(FreeMemoryTop) & 0xFFF;\r
+  \r
+  //\r
+  // If not aligned, make the allocation aligned.\r
+  //\r
+  if (Offset != 0) {\r
+    *(FreeMemoryTop) -= Offset;\r
+  }\r
   \r
   //\r
   // Verify that there is sufficient memory to satisfy the allocation\r
@@ -204,14 +210,12 @@ PeiAllocatePages (
 \r
 /**\r
 \r
-  Pool allocation service. Before permenent memory is discoveried, the pool will \r
-  be allocated the heap in the CAR. Genenrally, the size of heap in temporary \r
-  memory does not exceed to 64K, so the biggest pool size could be allocated is \r
-  64K.\r
+  Memory allocation service on the CAR.\r
+\r
 \r
-  @param PeiServices               An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
-  @param Size                      Amount of memory required\r
-  @param Buffer                    Address of pointer to the buffer\r
+  @param PeiServices     An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation.\r
+  @param Size            Amount of memory required\r
+  @param Buffer          Address of pointer to the buffer\r
 \r
   @retval EFI_SUCCESS              The allocation was successful\r
   @retval EFI_OUT_OF_RESOURCES     There is not enough heap to satisfy the requirement\r
@@ -221,30 +225,26 @@ PeiAllocatePages (
 EFI_STATUS\r
 EFIAPI\r
 PeiAllocatePool (\r
-  IN CONST EFI_PEI_SERVICES     **PeiServices,\r
-  IN       UINTN                Size,\r
-  OUT      VOID                 **Buffer\r
+  IN CONST EFI_PEI_SERVICES           **PeiServices,\r
+  IN UINTN                      Size,\r
+  OUT VOID                      **Buffer\r
   )\r
 {\r
   EFI_STATUS               Status;\r
   EFI_HOB_MEMORY_POOL      *Hob;\r
 \r
-  //\r
-  // If some "post-memory" PEIM wishes to allocate larger pool,\r
-  // it should use AllocatePages service instead.\r
-  //\r
-  \r
-  //\r
-  // Generally, the size of heap in temporary memory does not exceed to 64K,\r
-  // so the maxmium size of pool is 0x10000 - sizeof (EFI_HOB_MEMORY_POOL)\r
-  //\r
-  ASSERT (Size < 0x10000 - sizeof (EFI_HOB_MEMORY_POOL));\r
-  Status = PeiServicesCreateHob (\r
+ //\r
+ // If some "post-memory" PEIM wishes to allocate larger pool,\r
+ // it should use AllocatePages service instead.\r
+ //\r
+ ASSERT (Size < 0x10000 - sizeof (EFI_HOB_MEMORY_POOL));\r
+ Status = PeiServicesCreateHob (\r
              EFI_HOB_TYPE_MEMORY_POOL,\r
              (UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + Size),\r
              (VOID **)&Hob\r
              );\r
   *Buffer = Hob+1;  \r
 \r
+\r
   return Status;\r
 }\r