]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Memory/MemoryServices.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Memory / MemoryServices.c
index 53c9eaceb05d8b733e5f1a2fd81a857bb32c79a0..3b2e15699fc3bf467cf7e60705b538ec2c193e98 100644 (file)
@@ -27,22 +27,20 @@ InitializeMemoryServices (
   IN PEI_CORE_INSTANCE           *OldCoreData\r
   )\r
 {\r
-\r
-  PrivateData->SwitchStackSignal    = FALSE;\r
+  PrivateData->SwitchStackSignal = FALSE;\r
 \r
   //\r
   // First entering PeiCore, following code will initialized some field\r
   // in PeiCore's private data according to hand off data from SEC core.\r
   //\r
   if (OldCoreData == NULL) {\r
-\r
     PrivateData->PeiMemoryInstalled = FALSE;\r
     PrivateData->HobList.Raw        = SecCoreData->PeiTemporaryRamBase;\r
 \r
     PeiCoreBuildHobHandoffInfoTable (\r
       BOOT_WITH_FULL_CONFIGURATION,\r
-      (EFI_PHYSICAL_ADDRESS) (UINTN) SecCoreData->PeiTemporaryRamBase,\r
-      (UINTN) SecCoreData->PeiTemporaryRamSize\r
+      (EFI_PHYSICAL_ADDRESS)(UINTN)SecCoreData->PeiTemporaryRamBase,\r
+      (UINTN)SecCoreData->PeiTemporaryRamSize\r
       );\r
 \r
     //\r
@@ -78,7 +76,7 @@ PeiInstallPeiMemory (
   IN UINT64                  MemoryLength\r
   )\r
 {\r
-  PEI_CORE_INSTANCE                     *PrivateData;\r
+  PEI_CORE_INSTANCE  *PrivateData;\r
 \r
   DEBUG ((DEBUG_INFO, "PeiInstallPeiMemory MemoryBegin 0x%LX, MemoryLength 0x%LX\n", MemoryBegin, MemoryLength));\r
   PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
@@ -98,7 +96,7 @@ PeiInstallPeiMemory (
   PrivateData->PhysicalMemoryLength  = MemoryLength;\r
   PrivateData->FreePhysicalMemoryTop = MemoryBegin + MemoryLength;\r
 \r
-  PrivateData->SwitchStackSignal      = TRUE;\r
+  PrivateData->SwitchStackSignal = TRUE;\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -113,25 +111,26 @@ PeiInstallPeiMemory (
 **/\r
 VOID\r
 MigrateMemoryPages (\r
-  IN PEI_CORE_INSTANCE      *Private,\r
-  IN BOOLEAN                TemporaryRamMigrated\r
+  IN PEI_CORE_INSTANCE  *Private,\r
+  IN BOOLEAN            TemporaryRamMigrated\r
   )\r
 {\r
-  EFI_PHYSICAL_ADDRESS      NewMemPagesBase;\r
-  EFI_PHYSICAL_ADDRESS      MemPagesBase;\r
+  EFI_PHYSICAL_ADDRESS  NewMemPagesBase;\r
+  EFI_PHYSICAL_ADDRESS  MemPagesBase;\r
 \r
-  Private->MemoryPages.Size = (UINTN) (Private->HobList.HandoffInformationTable->EfiMemoryTop -\r
-                                       Private->HobList.HandoffInformationTable->EfiFreeMemoryTop);\r
+  Private->MemoryPages.Size = (UINTN)(Private->HobList.HandoffInformationTable->EfiMemoryTop -\r
+                                      Private->HobList.HandoffInformationTable->EfiFreeMemoryTop);\r
   if (Private->MemoryPages.Size == 0) {\r
     //\r
     // No any memory page allocated in pre-memory phase.\r
     //\r
     return;\r
   }\r
+\r
   Private->MemoryPages.Base = Private->HobList.HandoffInformationTable->EfiFreeMemoryTop;\r
 \r
   ASSERT (Private->MemoryPages.Size <= Private->FreePhysicalMemoryTop);\r
-  NewMemPagesBase = Private->FreePhysicalMemoryTop - Private->MemoryPages.Size;\r
+  NewMemPagesBase  = Private->FreePhysicalMemoryTop - Private->MemoryPages.Size;\r
   NewMemPagesBase &= ~(UINT64)EFI_PAGE_MASK;\r
   ASSERT (NewMemPagesBase >= Private->PhysicalMemoryBegin);\r
   //\r
@@ -148,6 +147,7 @@ MigrateMemoryPages (
     } else {\r
       MemPagesBase -= Private->HeapOffset;\r
     }\r
+\r
     CopyMem ((VOID *)(UINTN)NewMemPagesBase, (VOID *)(UINTN)MemPagesBase, Private->MemoryPages.Size);\r
   } else {\r
     CopyMem ((VOID *)(UINTN)NewMemPagesBase, (VOID *)(UINTN)Private->MemoryPages.Base, Private->MemoryPages.Size);\r
@@ -155,13 +155,13 @@ MigrateMemoryPages (
 \r
   if (NewMemPagesBase >= Private->MemoryPages.Base) {\r
     Private->MemoryPages.OffsetPositive = TRUE;\r
-    Private->MemoryPages.Offset = (UINTN)(NewMemPagesBase - Private->MemoryPages.Base);\r
+    Private->MemoryPages.Offset         = (UINTN)(NewMemPagesBase - Private->MemoryPages.Base);\r
   } else {\r
     Private->MemoryPages.OffsetPositive = FALSE;\r
-    Private->MemoryPages.Offset = (UINTN)(Private->MemoryPages.Base - NewMemPagesBase);\r
+    Private->MemoryPages.Offset         = (UINTN)(Private->MemoryPages.Base - NewMemPagesBase);\r
   }\r
 \r
-  DEBUG ((DEBUG_INFO, "Pages Offset = 0x%lX\n", (UINT64) Private->MemoryPages.Offset));\r
+  DEBUG ((DEBUG_INFO, "Pages Offset = 0x%lX\n", (UINT64)Private->MemoryPages.Offset));\r
 \r
   Private->FreePhysicalMemoryTop = NewMemPagesBase;\r
 }\r
@@ -174,30 +174,31 @@ MigrateMemoryPages (
 **/\r
 VOID\r
 RemoveFvHobsInTemporaryMemory (\r
-  IN PEI_CORE_INSTANCE        *Private\r
+  IN PEI_CORE_INSTANCE  *Private\r
   )\r
 {\r
-  EFI_PEI_HOB_POINTERS        Hob;\r
-  EFI_HOB_FIRMWARE_VOLUME     *FirmwareVolumeHob;\r
+  EFI_PEI_HOB_POINTERS     Hob;\r
+  EFI_HOB_FIRMWARE_VOLUME  *FirmwareVolumeHob;\r
 \r
   DEBUG ((DEBUG_INFO, "Removing FVs in FV HOB not already migrated to permanent memory.\n"));\r
 \r
   for (Hob.Raw = GetHobList (); !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {\r
-    if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV || GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2 || GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3) {\r
+    if ((GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV) || (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV2) || (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_FV3)) {\r
       FirmwareVolumeHob = Hob.FirmwareVolume;\r
       DEBUG ((DEBUG_INFO, "  Found FV HOB.\n"));\r
       DEBUG ((\r
-          DEBUG_INFO,\r
-          "    BA=%016lx  L=%016lx\n",\r
-          FirmwareVolumeHob->BaseAddress,\r
-          FirmwareVolumeHob->Length\r
-          ));\r
+        DEBUG_INFO,\r
+        "    BA=%016lx  L=%016lx\n",\r
+        FirmwareVolumeHob->BaseAddress,\r
+        FirmwareVolumeHob->Length\r
+        ));\r
       if (\r
-        !(\r
-          ((EFI_PHYSICAL_ADDRESS) (UINTN) FirmwareVolumeHob->BaseAddress >= Private->PhysicalMemoryBegin) &&\r
-          (((EFI_PHYSICAL_ADDRESS) (UINTN) FirmwareVolumeHob->BaseAddress + (FirmwareVolumeHob->Length - 1)) < Private->FreePhysicalMemoryTop)\r
+          !(\r
+            ((EFI_PHYSICAL_ADDRESS)(UINTN)FirmwareVolumeHob->BaseAddress >= Private->PhysicalMemoryBegin) &&\r
+            (((EFI_PHYSICAL_ADDRESS)(UINTN)FirmwareVolumeHob->BaseAddress + (FirmwareVolumeHob->Length - 1)) < Private->FreePhysicalMemoryTop)\r
+            )\r
           )\r
-        ) {\r
+      {\r
         DEBUG ((DEBUG_INFO, "      Removing FV HOB to an FV in T-RAM (was not migrated).\n"));\r
         Hob.Header->HobType = EFI_HOB_TYPE_UNUSED;\r
       }\r
@@ -216,15 +217,15 @@ RemoveFvHobsInTemporaryMemory (
 **/\r
 VOID\r
 ConvertFvHob (\r
-  IN PEI_CORE_INSTANCE          *PrivateData,\r
-  IN UINTN                      OrgFvHandle,\r
-  IN UINTN                      FvHandle\r
+  IN PEI_CORE_INSTANCE  *PrivateData,\r
+  IN UINTN              OrgFvHandle,\r
+  IN UINTN              FvHandle\r
   )\r
 {\r
-  EFI_PEI_HOB_POINTERS        Hob;\r
-  EFI_HOB_FIRMWARE_VOLUME     *FirmwareVolumeHob;\r
-  EFI_HOB_FIRMWARE_VOLUME2    *FirmwareVolume2Hob;\r
-  EFI_HOB_FIRMWARE_VOLUME3    *FirmwareVolume3Hob;\r
+  EFI_PEI_HOB_POINTERS      Hob;\r
+  EFI_HOB_FIRMWARE_VOLUME   *FirmwareVolumeHob;\r
+  EFI_HOB_FIRMWARE_VOLUME2  *FirmwareVolume2Hob;\r
+  EFI_HOB_FIRMWARE_VOLUME3  *FirmwareVolume3Hob;\r
 \r
   DEBUG ((DEBUG_INFO, "Converting FVs in FV HOB.\n"));\r
 \r
@@ -257,13 +258,13 @@ ConvertFvHob (
 **/\r
 VOID\r
 ConvertMemoryAllocationHobs (\r
-  IN PEI_CORE_INSTANCE          *PrivateData\r
+  IN PEI_CORE_INSTANCE  *PrivateData\r
   )\r
 {\r
-  EFI_PEI_HOB_POINTERS          Hob;\r
-  EFI_HOB_MEMORY_ALLOCATION     *MemoryAllocationHob;\r
-  EFI_PHYSICAL_ADDRESS          OldMemPagesBase;\r
-  UINTN                         OldMemPagesSize;\r
+  EFI_PEI_HOB_POINTERS       Hob;\r
+  EFI_HOB_MEMORY_ALLOCATION  *MemoryAllocationHob;\r
+  EFI_PHYSICAL_ADDRESS       OldMemPagesBase;\r
+  UINTN                      OldMemPagesSize;\r
 \r
   if (PrivateData->MemoryPages.Size == 0) {\r
     //\r
@@ -276,12 +277,13 @@ ConvertMemoryAllocationHobs (
   OldMemPagesSize = PrivateData->MemoryPages.Size;\r
 \r
   MemoryAllocationHob = NULL;\r
-  Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
+  Hob.Raw             = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
   while (Hob.Raw != NULL) {\r
-    MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;\r
+    MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;\r
     if ((MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress >= OldMemPagesBase) &&\r
         (MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress < (OldMemPagesBase + OldMemPagesSize))\r
-        ) {\r
+        )\r
+    {\r
       if (PrivateData->MemoryPages.OffsetPositive) {\r
         MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress += PrivateData->MemoryPages.Offset;\r
       } else {\r
@@ -306,22 +308,22 @@ ConvertMemoryAllocationHobs (
 **/\r
 VOID\r
 InternalBuildMemoryAllocationHob (\r
-  IN EFI_PHYSICAL_ADDRESS       BaseAddress,\r
-  IN UINT64                     Length,\r
-  IN EFI_MEMORY_TYPE            MemoryType\r
+  IN EFI_PHYSICAL_ADDRESS  BaseAddress,\r
+  IN UINT64                Length,\r
+  IN EFI_MEMORY_TYPE       MemoryType\r
   )\r
 {\r
-  EFI_PEI_HOB_POINTERS          Hob;\r
-  EFI_HOB_MEMORY_ALLOCATION     *MemoryAllocationHob;\r
+  EFI_PEI_HOB_POINTERS       Hob;\r
+  EFI_HOB_MEMORY_ALLOCATION  *MemoryAllocationHob;\r
 \r
   //\r
   // Search unused(freed) memory allocation HOB.\r
   //\r
   MemoryAllocationHob = NULL;\r
-  Hob.Raw = GetFirstHob (EFI_HOB_TYPE_UNUSED);\r
+  Hob.Raw             = GetFirstHob (EFI_HOB_TYPE_UNUSED);\r
   while (Hob.Raw != NULL) {\r
     if (Hob.Header->HobLength == sizeof (EFI_HOB_MEMORY_ALLOCATION)) {\r
-      MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;\r
+      MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;\r
       break;\r
     }\r
 \r
@@ -370,14 +372,15 @@ InternalBuildMemoryAllocationHob (
 **/\r
 VOID\r
 UpdateOrSplitMemoryAllocationHob (\r
-  IN OUT EFI_HOB_MEMORY_ALLOCATION      *MemoryAllocationHob,\r
-  IN EFI_PHYSICAL_ADDRESS               Memory,\r
-  IN UINT64                             Bytes,\r
-  IN EFI_MEMORY_TYPE                    MemoryType\r
+  IN OUT EFI_HOB_MEMORY_ALLOCATION  *MemoryAllocationHob,\r
+  IN EFI_PHYSICAL_ADDRESS           Memory,\r
+  IN UINT64                         Bytes,\r
+  IN EFI_MEMORY_TYPE                MemoryType\r
   )\r
 {\r
   if ((Memory + Bytes) <\r
-      (MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress + MemoryAllocationHob->AllocDescriptor.MemoryLength)) {\r
+      (MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress + MemoryAllocationHob->AllocDescriptor.MemoryLength))\r
+  {\r
     //\r
     // Last pages need to be split out.\r
     //\r
@@ -403,8 +406,8 @@ UpdateOrSplitMemoryAllocationHob (
   // Update the memory allocation HOB.\r
   //\r
   MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress = Memory;\r
-  MemoryAllocationHob->AllocDescriptor.MemoryLength = Bytes;\r
-  MemoryAllocationHob->AllocDescriptor.MemoryType = MemoryType;\r
+  MemoryAllocationHob->AllocDescriptor.MemoryLength      = Bytes;\r
+  MemoryAllocationHob->AllocDescriptor.MemoryType        = MemoryType;\r
 }\r
 \r
 /**\r
@@ -419,34 +422,34 @@ MergeFreeMemoryInMemoryAllocationHob (
   VOID\r
   )\r
 {\r
-  EFI_PEI_HOB_POINTERS          Hob;\r
-  EFI_PEI_HOB_POINTERS          Hob2;\r
-  EFI_HOB_MEMORY_ALLOCATION     *MemoryHob;\r
-  EFI_HOB_MEMORY_ALLOCATION     *MemoryHob2;\r
-  UINT64                        Start;\r
-  UINT64                        End;\r
-  BOOLEAN                       Merged;\r
+  EFI_PEI_HOB_POINTERS       Hob;\r
+  EFI_PEI_HOB_POINTERS       Hob2;\r
+  EFI_HOB_MEMORY_ALLOCATION  *MemoryHob;\r
+  EFI_HOB_MEMORY_ALLOCATION  *MemoryHob2;\r
+  UINT64                     Start;\r
+  UINT64                     End;\r
+  BOOLEAN                    Merged;\r
 \r
   Merged = FALSE;\r
 \r
   Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
   while (Hob.Raw != NULL) {\r
     if (Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiConventionalMemory) {\r
-      MemoryHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;\r
-      Start = MemoryHob->AllocDescriptor.MemoryBaseAddress;\r
-      End = MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength;\r
+      MemoryHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;\r
+      Start     = MemoryHob->AllocDescriptor.MemoryBaseAddress;\r
+      End       = MemoryHob->AllocDescriptor.MemoryBaseAddress + MemoryHob->AllocDescriptor.MemoryLength;\r
 \r
       Hob2.Raw = GET_NEXT_HOB (Hob);\r
       Hob2.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw);\r
       while (Hob2.Raw != NULL) {\r
         if (Hob2.MemoryAllocation->AllocDescriptor.MemoryType == EfiConventionalMemory) {\r
-          MemoryHob2 = (EFI_HOB_MEMORY_ALLOCATION *) Hob2.Raw;\r
+          MemoryHob2 = (EFI_HOB_MEMORY_ALLOCATION *)Hob2.Raw;\r
           if (Start == (MemoryHob2->AllocDescriptor.MemoryBaseAddress + MemoryHob2->AllocDescriptor.MemoryLength)) {\r
             //\r
             // Merge adjacent two free memory ranges.\r
             //\r
             MemoryHob2->AllocDescriptor.MemoryLength += MemoryHob->AllocDescriptor.MemoryLength;\r
-            Merged = TRUE;\r
+            Merged                                    = TRUE;\r
             //\r
             // Mark MemoryHob to be unused(freed).\r
             //\r
@@ -457,8 +460,8 @@ MergeFreeMemoryInMemoryAllocationHob (
             // Merge adjacent two free memory ranges.\r
             //\r
             MemoryHob2->AllocDescriptor.MemoryBaseAddress = MemoryHob->AllocDescriptor.MemoryBaseAddress;\r
-            MemoryHob2->AllocDescriptor.MemoryLength += MemoryHob->AllocDescriptor.MemoryLength;\r
-            Merged = TRUE;\r
+            MemoryHob2->AllocDescriptor.MemoryLength     += MemoryHob->AllocDescriptor.MemoryLength;\r
+            Merged                                        = TRUE;\r
             //\r
             // Mark MemoryHob to be unused(freed).\r
             //\r
@@ -466,10 +469,12 @@ MergeFreeMemoryInMemoryAllocationHob (
             break;\r
           }\r
         }\r
+\r
         Hob2.Raw = GET_NEXT_HOB (Hob2);\r
         Hob2.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob2.Raw);\r
       }\r
     }\r
+\r
     Hob.Raw = GET_NEXT_HOB (Hob);\r
     Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw);\r
   }\r
@@ -492,41 +497,44 @@ MergeFreeMemoryInMemoryAllocationHob (
 **/\r
 EFI_STATUS\r
 FindFreeMemoryFromMemoryAllocationHob (\r
-  IN  EFI_MEMORY_TYPE           MemoryType,\r
-  IN  UINTN                     Pages,\r
-  IN  UINTN                     Granularity,\r
-  OUT EFI_PHYSICAL_ADDRESS      *Memory\r
+  IN  EFI_MEMORY_TYPE       MemoryType,\r
+  IN  UINTN                 Pages,\r
+  IN  UINTN                 Granularity,\r
+  OUT EFI_PHYSICAL_ADDRESS  *Memory\r
   )\r
 {\r
-  EFI_PEI_HOB_POINTERS          Hob;\r
-  EFI_HOB_MEMORY_ALLOCATION     *MemoryAllocationHob;\r
-  UINT64                        Bytes;\r
-  EFI_PHYSICAL_ADDRESS          BaseAddress;\r
+  EFI_PEI_HOB_POINTERS       Hob;\r
+  EFI_HOB_MEMORY_ALLOCATION  *MemoryAllocationHob;\r
+  UINT64                     Bytes;\r
+  EFI_PHYSICAL_ADDRESS       BaseAddress;\r
 \r
   Bytes = LShiftU64 (Pages, EFI_PAGE_SHIFT);\r
 \r
-  BaseAddress = 0;\r
+  BaseAddress         = 0;\r
   MemoryAllocationHob = NULL;\r
-  Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
+  Hob.Raw             = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
   while (Hob.Raw != NULL) {\r
     if ((Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiConventionalMemory) &&\r
-        (Hob.MemoryAllocation->AllocDescriptor.MemoryLength >= Bytes)) {\r
+        (Hob.MemoryAllocation->AllocDescriptor.MemoryLength >= Bytes))\r
+    {\r
       //\r
       // Found one memory allocation HOB with big enough free memory.\r
       //\r
-      MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;\r
-      BaseAddress = MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress +\r
-                    MemoryAllocationHob->AllocDescriptor.MemoryLength - Bytes;\r
+      MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;\r
+      BaseAddress         = MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress +\r
+                            MemoryAllocationHob->AllocDescriptor.MemoryLength - Bytes;\r
       //\r
       // Make sure the granularity could be satisfied.\r
       //\r
-      BaseAddress &= ~((EFI_PHYSICAL_ADDRESS) Granularity - 1);\r
+      BaseAddress &= ~((EFI_PHYSICAL_ADDRESS)Granularity - 1);\r
       if (BaseAddress >= MemoryAllocationHob->AllocDescriptor.MemoryBaseAddress) {\r
         break;\r
       }\r
-      BaseAddress = 0;\r
+\r
+      BaseAddress         = 0;\r
       MemoryAllocationHob = NULL;\r
     }\r
+\r
     //\r
     // Continue to find.\r
     //\r
@@ -545,6 +553,7 @@ FindFreeMemoryFromMemoryAllocationHob (
       //\r
       return FindFreeMemoryFromMemoryAllocationHob (MemoryType, Pages, Granularity, Memory);\r
     }\r
+\r
     return EFI_NOT_FOUND;\r
   }\r
 }\r
@@ -574,20 +583,20 @@ FindFreeMemoryFromMemoryAllocationHob (
 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
-  EFI_STATUS                              Status;\r
-  PEI_CORE_INSTANCE                       *PrivateData;\r
-  EFI_PEI_HOB_POINTERS                    Hob;\r
-  EFI_PHYSICAL_ADDRESS                    *FreeMemoryTop;\r
-  EFI_PHYSICAL_ADDRESS                    *FreeMemoryBottom;\r
-  UINTN                                   RemainingPages;\r
-  UINTN                                   Granularity;\r
-  UINTN                                   Padding;\r
+  EFI_STATUS            Status;\r
+  PEI_CORE_INSTANCE     *PrivateData;\r
+  EFI_PEI_HOB_POINTERS  Hob;\r
+  EFI_PHYSICAL_ADDRESS  *FreeMemoryTop;\r
+  EFI_PHYSICAL_ADDRESS  *FreeMemoryBottom;\r
+  UINTN                 RemainingPages;\r
+  UINTN                 Granularity;\r
+  UINTN                 Padding;\r
 \r
   if ((MemoryType != EfiLoaderCode) &&\r
       (MemoryType != EfiLoaderData) &&\r
@@ -597,7 +606,8 @@ PeiAllocatePages (
       (MemoryType != EfiBootServicesData) &&\r
       (MemoryType != EfiACPIReclaimMemory) &&\r
       (MemoryType != EfiReservedMemoryType) &&\r
-      (MemoryType != EfiACPIMemoryNVS)) {\r
+      (MemoryType != EfiACPIMemoryNVS))\r
+  {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -613,16 +623,19 @@ PeiAllocatePages (
     return EFI_NOT_AVAILABLE_YET;\r
   }\r
 \r
-  if  (RUNTIME_PAGE_ALLOCATION_GRANULARITY > DEFAULT_PAGE_ALLOCATION_GRANULARITY &&\r
-       (MemoryType == EfiACPIReclaimMemory   ||\r
-        MemoryType == EfiACPIMemoryNVS       ||\r
-        MemoryType == EfiRuntimeServicesCode ||\r
-        MemoryType == EfiRuntimeServicesData)) {\r
-\r
+  if ((RUNTIME_PAGE_ALLOCATION_GRANULARITY > DEFAULT_PAGE_ALLOCATION_GRANULARITY) &&\r
+      ((MemoryType == EfiACPIReclaimMemory) ||\r
+       (MemoryType == EfiACPIMemoryNVS) ||\r
+       (MemoryType == EfiRuntimeServicesCode) ||\r
+       (MemoryType == EfiRuntimeServicesData)))\r
+  {\r
     Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY;\r
 \r
-    DEBUG ((DEBUG_INFO, "AllocatePages: aligning allocation to %d KB\n",\r
-      Granularity / SIZE_1KB));\r
+    DEBUG ((\r
+      DEBUG_INFO,\r
+      "AllocatePages: aligning allocation to %d KB\n",\r
+      Granularity / SIZE_1KB\r
+      ));\r
   }\r
 \r
   if (!PrivateData->PeiMemoryInstalled && PrivateData->SwitchStackSignal) {\r
@@ -630,11 +643,11 @@ PeiAllocatePages (
     // When PeiInstallMemory is called but temporary memory has *not* been moved to permanent memory,\r
     // the AllocatePage will depend on the field of PEI_CORE_INSTANCE structure.\r
     //\r
-    FreeMemoryTop     = &(PrivateData->FreePhysicalMemoryTop);\r
-    FreeMemoryBottom  = &(PrivateData->PhysicalMemoryBegin);\r
+    FreeMemoryTop    = &(PrivateData->FreePhysicalMemoryTop);\r
+    FreeMemoryBottom = &(PrivateData->PhysicalMemoryBegin);\r
   } else {\r
-    FreeMemoryTop     = &(Hob.HandoffInformationTable->EfiFreeMemoryTop);\r
-    FreeMemoryBottom  = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom);\r
+    FreeMemoryTop    = &(Hob.HandoffInformationTable->EfiFreeMemoryTop);\r
+    FreeMemoryBottom = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom);\r
   }\r
 \r
   //\r
@@ -642,7 +655,7 @@ PeiAllocatePages (
   // If not aligned, make the allocation aligned.\r
   //\r
   Padding = *(FreeMemoryTop) & (Granularity - 1);\r
-  if ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom) < Padding) {\r
+  if ((UINTN)(*FreeMemoryTop - *FreeMemoryBottom) < Padding) {\r
     DEBUG ((DEBUG_ERROR, "AllocatePages failed: Out of space after padding.\n"));\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -676,9 +689,10 @@ PeiAllocatePages (
     if (!EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
-    DEBUG ((DEBUG_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64) Pages));\r
-    DEBUG ((DEBUG_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages));\r
-    return  EFI_OUT_OF_RESOURCES;\r
+\r
+    DEBUG ((DEBUG_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64)Pages));\r
+    DEBUG ((DEBUG_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64)RemainingPages));\r
+    return EFI_OUT_OF_RESOURCES;\r
   } else {\r
     //\r
     // Update the PHIT to reflect the memory usage\r
@@ -713,13 +727,13 @@ PeiAllocatePages (
 **/\r
 VOID\r
 FreeMemoryAllocationHob (\r
-  IN PEI_CORE_INSTANCE                  *PrivateData,\r
-  IN OUT EFI_HOB_MEMORY_ALLOCATION      *MemoryAllocationHobToFree\r
+  IN PEI_CORE_INSTANCE              *PrivateData,\r
+  IN OUT EFI_HOB_MEMORY_ALLOCATION  *MemoryAllocationHobToFree\r
   )\r
 {\r
-  EFI_PEI_HOB_POINTERS                  Hob;\r
-  EFI_PHYSICAL_ADDRESS                  *FreeMemoryTop;\r
-  EFI_HOB_MEMORY_ALLOCATION             *MemoryAllocationHob;\r
+  EFI_PEI_HOB_POINTERS       Hob;\r
+  EFI_PHYSICAL_ADDRESS       *FreeMemoryTop;\r
+  EFI_HOB_MEMORY_ALLOCATION  *MemoryAllocationHob;\r
 \r
   Hob.Raw = PrivateData->HobList.Raw;\r
 \r
@@ -744,20 +758,23 @@ FreeMemoryAllocationHob (
     MemoryAllocationHobToFree->Header.HobType = EFI_HOB_TYPE_UNUSED;\r
 \r
     MemoryAllocationHob = NULL;\r
-    Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
+    Hob.Raw             = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
     while (Hob.Raw != NULL) {\r
       if ((Hob.MemoryAllocation->AllocDescriptor.MemoryType == EfiConventionalMemory) &&\r
-          (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == *FreeMemoryTop)) {\r
+          (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == *FreeMemoryTop))\r
+      {\r
         //\r
         // Found memory allocation HOB that has EfiConventionalMemory MemoryType and\r
         // MemoryBaseAddress == new *FreeMemoryTop.\r
         //\r
-        MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;\r
+        MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;\r
         break;\r
       }\r
+\r
       Hob.Raw = GET_NEXT_HOB (Hob);\r
       Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw);\r
     }\r
+\r
     //\r
     // Free memory allocation HOB iteratively.\r
     //\r
@@ -783,23 +800,23 @@ FreeMemoryAllocationHob (
 EFI_STATUS\r
 EFIAPI\r
 PeiFreePages (\r
-  IN CONST EFI_PEI_SERVICES     **PeiServices,\r
-  IN EFI_PHYSICAL_ADDRESS       Memory,\r
-  IN UINTN                      Pages\r
+  IN CONST EFI_PEI_SERVICES  **PeiServices,\r
+  IN EFI_PHYSICAL_ADDRESS    Memory,\r
+  IN UINTN                   Pages\r
   )\r
 {\r
-  PEI_CORE_INSTANCE             *PrivateData;\r
-  UINT64                        Bytes;\r
-  UINT64                        Start;\r
-  UINT64                        End;\r
-  EFI_PEI_HOB_POINTERS          Hob;\r
-  EFI_HOB_MEMORY_ALLOCATION     *MemoryAllocationHob;\r
+  PEI_CORE_INSTANCE          *PrivateData;\r
+  UINT64                     Bytes;\r
+  UINT64                     Start;\r
+  UINT64                     End;\r
+  EFI_PEI_HOB_POINTERS       Hob;\r
+  EFI_HOB_MEMORY_ALLOCATION  *MemoryAllocationHob;\r
 \r
   Bytes = LShiftU64 (Pages, EFI_PAGE_SHIFT);\r
   Start = Memory;\r
-  End = Start + Bytes - 1;\r
+  End   = Start + Bytes - 1;\r
 \r
-  if (Pages == 0 || ((Start & EFI_PAGE_MASK) != 0) || (Start >= End)) {\r
+  if ((Pages == 0) || ((Start & EFI_PAGE_MASK) != 0) || (Start >= End)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -814,17 +831,19 @@ PeiFreePages (
   }\r
 \r
   MemoryAllocationHob = NULL;\r
-  Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
+  Hob.Raw             = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
   while (Hob.Raw != NULL) {\r
     if ((Hob.MemoryAllocation->AllocDescriptor.MemoryType != EfiConventionalMemory) &&\r
         (Memory >= Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress) &&\r
-        ((Memory + Bytes) <= (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength))) {\r
+        ((Memory + Bytes) <= (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress + Hob.MemoryAllocation->AllocDescriptor.MemoryLength)))\r
+    {\r
       //\r
       // Found the memory allocation HOB that includes the memory pages to be freed.\r
       //\r
-      MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *) Hob.Raw;\r
+      MemoryAllocationHob = (EFI_HOB_MEMORY_ALLOCATION *)Hob.Raw;\r
       break;\r
     }\r
+\r
     Hob.Raw = GET_NEXT_HOB (Hob);\r
     Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw);\r
   }\r
@@ -857,13 +876,13 @@ PeiFreePages (
 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
+  EFI_STATUS           Status;\r
+  EFI_HOB_MEMORY_POOL  *Hob;\r
 \r
   //\r
   // If some "post-memory" PEIM wishes to allocate larger pool,\r