]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Gcd/Gcd.c
Clean up DxeCore to remove duplicate memory allocation & device path utility services...
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Gcd / Gcd.c
index 8536647fe7eb6025ec89b7e70d22cebef41966c6..4927c67c18c6567e0371dac37b835f1c47d453de 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The file contains the GCD related services in the EFI Boot Services Table.\r
-    The GCD services are used to manage the memory and I/O regions that \r
-    are accessible to the CPU that is executing the DXE core.\r
+  The GCD services are used to manage the memory and I/O regions that\r
+  are accessible to the CPU that is executing the DXE core.\r
 \r
 Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
 All rights reserved. This program and the accompanying materials\r
@@ -14,7 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include <DxeMain.h>\r
+#include "DxeMain.h"\r
 \r
 #define MINIMUM_INITIAL_MEMORY_SIZE 0x10000\r
 \r
@@ -26,7 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
                                        EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED | \\r
                                        EFI_RESOURCE_ATTRIBUTE_16_BIT_IO           | \\r
                                        EFI_RESOURCE_ATTRIBUTE_32_BIT_IO           | \\r
-                                       EFI_RESOURCE_ATTRIBUTE_64_BIT_IO           ) \r
+                                       EFI_RESOURCE_ATTRIBUTE_64_BIT_IO           )\r
 \r
 #define TESTED_MEMORY_ATTRIBUTES      (EFI_RESOURCE_ATTRIBUTE_PRESENT     | \\r
                                        EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \\r
@@ -49,7 +49,10 @@ LIST_ENTRY         mGcdIoSpaceMap      = INITIALIZE_LIST_HEAD_VARIABLE (mGcdIoSp
 \r
 EFI_GCD_MAP_ENTRY mGcdMemorySpaceMapEntryTemplate = {\r
   EFI_GCD_MAP_SIGNATURE,\r
-  { NULL, NULL },\r
+  {\r
+    NULL,\r
+    NULL\r
+  },\r
   0,\r
   0,\r
   0,\r
@@ -62,7 +65,10 @@ EFI_GCD_MAP_ENTRY mGcdMemorySpaceMapEntryTemplate = {
 \r
 EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate = {\r
   EFI_GCD_MAP_SIGNATURE,\r
-  { NULL, NULL },\r
+  {\r
+    NULL,\r
+    NULL\r
+  },\r
   0,\r
   0,\r
   0,\r
@@ -75,7 +81,7 @@ EFI_GCD_MAP_ENTRY mGcdIoSpaceMapEntryTemplate = {
 \r
 GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = {\r
   { EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE,             EFI_MEMORY_UC,          TRUE  },\r
-  { EFI_RESOURCE_ATTRIBUTE_UNCACHED_EXPORTED,       EFI_MEMORY_UCE,         TRUE  },   \r
+  { EFI_RESOURCE_ATTRIBUTE_UNCACHED_EXPORTED,       EFI_MEMORY_UCE,         TRUE  },\r
   { EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE,       EFI_MEMORY_WC,          TRUE  },\r
   { EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE, EFI_MEMORY_WT,          TRUE  },\r
   { EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE,    EFI_MEMORY_WB,          TRUE  },\r
@@ -85,7 +91,7 @@ GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = {
   { EFI_RESOURCE_ATTRIBUTE_PRESENT,                 EFI_MEMORY_PRESENT,     FALSE },\r
   { EFI_RESOURCE_ATTRIBUTE_INITIALIZED,             EFI_MEMORY_INITIALIZED, FALSE },\r
   { EFI_RESOURCE_ATTRIBUTE_TESTED,                  EFI_MEMORY_TESTED,      FALSE },\r
-  { 0, 0, FALSE }\r
+  { 0,                                              0,                      FALSE }\r
 };\r
 \r
 \r
@@ -147,15 +153,14 @@ CoreReleaseGcdIoLock (
 //\r
 // GCD Initialization Worker Functions\r
 //\r
-\r
 /**\r
   Aligns a value to the specified boundary.\r
 \r
-  @param  Value                  64 bit value to align \r
-  @param  Alignment              Log base 2 of the boundary to align Value to \r
-  @param  RoundUp                TRUE if Value is to be rounded up to the nearest \r
-                                 aligned boundary.  FALSE is Value is to be \r
-                                 rounded down to the nearest aligned boundary. \r
+  @param  Value                  64 bit value to align\r
+  @param  Alignment              Log base 2 of the boundary to align Value to\r
+  @param  RoundUp                TRUE if Value is to be rounded up to the nearest\r
+                                 aligned boundary.  FALSE is Value is to be\r
+                                 rounded down to the nearest aligned boundary.\r
 \r
   @return A 64 bit value is the aligned to the value nearest Value with an alignment by Alignment.\r
 \r
@@ -180,7 +185,7 @@ AlignValue (
 /**\r
   Aligns address to the page boundary.\r
 \r
-  @param  Value                  64 bit address to align \r
+  @param  Value                  64 bit address to align\r
 \r
   @return A 64 bit value is the aligned to the value nearest Value with an alignment by Alignment.\r
 \r
@@ -197,7 +202,7 @@ PageAlignAddress (
 /**\r
   Aligns length to the page boundary.\r
 \r
-  @param  Value                  64 bit length to align \r
+  @param  Value                  64 bit length to align\r
 \r
   @return A 64 bit value is the aligned to the value nearest Value with an alignment by Alignment.\r
 \r
@@ -217,10 +222,10 @@ PageAlignLength (
 /**\r
   Allocate pool for two entries.\r
 \r
-  @param  TopEntry               An entry of GCD map \r
-  @param  BottomEntry            An entry of GCD map \r
+  @param  TopEntry               An entry of GCD map\r
+  @param  BottomEntry            An entry of GCD map\r
 \r
-  @retval EFI_OUT_OF_RESOURCES   No enough buffer to be allocated. \r
+  @retval EFI_OUT_OF_RESOURCES   No enough buffer to be allocated.\r
   @retval EFI_SUCCESS            Both entries successfully allocated.\r
 \r
 **/\r
@@ -230,12 +235,12 @@ CoreAllocateGcdMapEntry (
   IN OUT EFI_GCD_MAP_ENTRY  **BottomEntry\r
   )\r
 {\r
-  *TopEntry = CoreAllocateZeroBootServicesPool (sizeof (EFI_GCD_MAP_ENTRY));\r
+  *TopEntry = AllocateZeroPool (sizeof (EFI_GCD_MAP_ENTRY));\r
   if (*TopEntry == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  *BottomEntry = CoreAllocateZeroBootServicesPool (sizeof (EFI_GCD_MAP_ENTRY));\r
+  *BottomEntry = AllocateZeroPool (sizeof (EFI_GCD_MAP_ENTRY));\r
   if (*BottomEntry == NULL) {\r
     CoreFreePool (*TopEntry);\r
     return EFI_OUT_OF_RESOURCES;\r
@@ -248,13 +253,13 @@ CoreAllocateGcdMapEntry (
 /**\r
   Internal function.  Inserts a new descriptor into a sorted list\r
 \r
-  @param  Link                   The linked list to insert the range BaseAddress \r
-                                 and Length into \r
-  @param  Entry                  A pointer to the entry that is inserted \r
-  @param  BaseAddress            The base address of the new range \r
-  @param  Length                 The length of the new range in bytes \r
-  @param  TopEntry               Top pad entry to insert if needed. \r
-  @param  BottomEntry            Bottom pad entry to insert if needed. \r
+  @param  Link                   The linked list to insert the range BaseAddress\r
+                                 and Length into\r
+  @param  Entry                  A pointer to the entry that is inserted\r
+  @param  BaseAddress            The base address of the new range\r
+  @param  Length                 The length of the new range in bytes\r
+  @param  TopEntry               Top pad entry to insert if needed.\r
+  @param  BottomEntry            Bottom pad entry to insert if needed.\r
 \r
   @retval EFI_SUCCESS            The new range was inserted into the linked list\r
 \r
@@ -278,7 +283,7 @@ CoreInsertGcdMapEntry (
     Entry->BaseAddress      = BaseAddress;\r
     BottomEntry->EndAddress = BaseAddress - 1;\r
     InsertTailList (Link, &BottomEntry->Link);\r
-  } \r
+  }\r
 \r
   if ((BaseAddress + Length - 1) < Entry->EndAddress) {\r
     CopyMem (TopEntry, Entry, sizeof (EFI_GCD_MAP_ENTRY));\r
@@ -292,14 +297,14 @@ CoreInsertGcdMapEntry (
 \r
 \r
 /**\r
-  Merge the Gcd region specified by Link and its adjacent entry\r
+  Merge the Gcd region specified by Link and its adjacent entry.\r
 \r
-  @param  Link                   Specify the entry to be merged (with its \r
-                                 adjacent entry). \r
-  @param  Forward                Direction (forward or backward). \r
-  @param  Map                    Boundary. \r
+  @param  Link                   Specify the entry to be merged (with its\r
+                                 adjacent entry).\r
+  @param  Forward                Direction (forward or backward).\r
+  @param  Map                    Boundary.\r
 \r
-  @retval EFI_SUCCESS            Successfully returned. \r
+  @retval EFI_SUCCESS            Successfully returned.\r
   @retval EFI_UNSUPPORTED        These adjacent regions could not merge.\r
 \r
 **/\r
@@ -367,11 +372,11 @@ CoreMergeGcdMapEntry (
 /**\r
   Merge adjacent entries on total chain.\r
 \r
-  @param  TopEntry               Top entry of GCD map. \r
-  @param  BottomEntry            Bottom entry of GCD map. \r
-  @param  StartLink              Start link of the list for this loop. \r
-  @param  EndLink                End link of the list for this loop. \r
-  @param  Map                    Boundary. \r
+  @param  TopEntry               Top entry of GCD map.\r
+  @param  BottomEntry            Bottom entry of GCD map.\r
+  @param  StartLink              Start link of the list for this loop.\r
+  @param  EndLink                End link of the list for this loop.\r
+  @param  Map                    Boundary.\r
 \r
   @retval EFI_SUCCESS            GCD map successfully cleaned up.\r
 \r
@@ -408,15 +413,15 @@ CoreCleanupGcdMapEntry (
 /**\r
   Search a segment of memory space in GCD map. The result is a range of GCD entry list.\r
 \r
-  @param  BaseAddress            The start address of the segment. \r
-  @param  Length                 The length of the segment. \r
-  @param  StartLink              The first GCD entry involves this segment of \r
-                                 memory space. \r
-  @param  EndLink                The first GCD entry involves this segment of \r
-                                 memory space. \r
-  @param  Map                    Points to the start entry to search. \r
+  @param  BaseAddress            The start address of the segment.\r
+  @param  Length                 The length of the segment.\r
+  @param  StartLink              The first GCD entry involves this segment of\r
+                                 memory space.\r
+  @param  EndLink                The first GCD entry involves this segment of\r
+                                 memory space.\r
+  @param  Map                    Points to the start entry to search.\r
 \r
-  @retval EFI_SUCCESS            Successfully found the entry. \r
+  @retval EFI_SUCCESS            Successfully found the entry.\r
   @retval EFI_NOT_FOUND          Not found.\r
 \r
 **/\r
@@ -444,7 +449,7 @@ CoreSearchGcdMapEntry (
       *StartLink = Link;\r
     }\r
     if (*StartLink != NULL) {\r
-      if ((BaseAddress + Length - 1) >= Entry->BaseAddress && \r
+      if ((BaseAddress + Length - 1) >= Entry->BaseAddress &&\r
           (BaseAddress + Length - 1) <= Entry->EndAddress     ) {\r
         *EndLink = Link;\r
         return EFI_SUCCESS;\r
@@ -452,6 +457,7 @@ CoreSearchGcdMapEntry (
     }\r
     Link = Link->ForwardLink;\r
   }\r
+\r
   return EFI_NOT_FOUND;\r
 }\r
 \r
@@ -459,7 +465,7 @@ CoreSearchGcdMapEntry (
 /**\r
   Count the amount of GCD map entries.\r
 \r
-  @param  Map                    Points to the start entry to do the count loop. \r
+  @param  Map                    Points to the start entry to do the count loop.\r
 \r
   @return The count.\r
 \r
@@ -478,6 +484,7 @@ CoreCountGcdMapEntry (
     Count++;\r
     Link = Link->ForwardLink;\r
   }\r
+\r
   return Count;\r
 }\r
 \r
@@ -486,7 +493,7 @@ CoreCountGcdMapEntry (
 /**\r
   Return the memory attribute specified by Attributes\r
 \r
-  @param  Attributes             A num with some attribute bits on. \r
+  @param  Attributes             A num with some attribute bits on.\r
 \r
   @return The enum value of memory attribute.\r
 \r
@@ -524,23 +531,23 @@ ConverToCpuArchAttributes (
 /**\r
   Do operation on a segment of memory space specified (add, free, remove, change attribute ...).\r
 \r
-  @param  Operation              The type of the operation \r
-  @param  GcdMemoryType          Additional information for the operation \r
-  @param  GcdIoType              Additional information for the operation \r
-  @param  BaseAddress            Start address of the segment \r
-  @param  Length                 length of the segment \r
-  @param  Capabilities           The alterable attributes of a newly added entry \r
-  @param  Attributes             The attributes needs to be set \r
-\r
-  @retval EFI_INVALID_PARAMETER  Length is 0 or address (length) not aligned when \r
-                                 setting attribute. \r
-  @retval EFI_SUCCESS            Action successfully done. \r
-  @retval EFI_UNSUPPORTED        Could not find the proper descriptor on this \r
-                                 segment or  set an upsupported attribute. \r
-  @retval EFI_ACCESS_DENIED      Operate on an space non-exist or is used for an \r
-                                 image. \r
-  @retval EFI_NOT_FOUND          Free a non-using space or remove a non-exist \r
-                                 space, and so on. \r
+  @param  Operation              The type of the operation\r
+  @param  GcdMemoryType          Additional information for the operation\r
+  @param  GcdIoType              Additional information for the operation\r
+  @param  BaseAddress            Start address of the segment\r
+  @param  Length                 length of the segment\r
+  @param  Capabilities           The alterable attributes of a newly added entry\r
+  @param  Attributes             The attributes needs to be set\r
+\r
+  @retval EFI_INVALID_PARAMETER  Length is 0 or address (length) not aligned when\r
+                                 setting attribute.\r
+  @retval EFI_SUCCESS            Action successfully done.\r
+  @retval EFI_UNSUPPORTED        Could not find the proper descriptor on this\r
+                                 segment or  set an upsupported attribute.\r
+  @retval EFI_ACCESS_DENIED      Operate on an space non-exist or is used for an\r
+                                 image.\r
+  @retval EFI_NOT_FOUND          Free a non-using space or remove a non-exist\r
+                                 space, and so on.\r
   @retval EFI_OUT_OF_RESOURCES   No buffer could be allocated.\r
 \r
 **/\r
@@ -563,7 +570,7 @@ CoreConvertSpace (
   EFI_GCD_MAP_ENTRY  *BottomEntry;\r
   LIST_ENTRY         *StartLink;\r
   LIST_ENTRY         *EndLink;\r
-  \r
+\r
   EFI_CPU_ARCH_PROTOCOL           *CpuArch;\r
   UINT64                          CpuArchAttributes;\r
 \r
@@ -655,7 +662,6 @@ CoreConvertSpace (
       if ((Attributes & EFI_MEMORY_RUNTIME) != 0) {\r
         if ((BaseAddress & EFI_PAGE_MASK) != 0 || (Length & EFI_PAGE_MASK) != 0) {\r
           Status = EFI_INVALID_PARAMETER;\r
-\r
           goto Done;\r
         }\r
       }\r
@@ -677,9 +683,6 @@ CoreConvertSpace (
     goto Done;\r
   }\r
 \r
-  //\r
-  //\r
-  //\r
   if (Operation == GCD_SET_ATTRIBUTES_MEMORY_OPERATION) {\r
     //\r
     // Call CPU Arch Protocol to attempt to set attributes on the range\r
@@ -775,15 +778,15 @@ Done:
 /**\r
   Check whether an entry could be used to allocate space.\r
 \r
-  @param  Operation              Allocate memory or IO \r
-  @param  Entry                  The entry to be tested \r
-  @param  GcdMemoryType          The desired memory type \r
-  @param  GcdIoType              The desired IO type \r
+  @param  Operation              Allocate memory or IO\r
+  @param  Entry                  The entry to be tested\r
+  @param  GcdMemoryType          The desired memory type\r
+  @param  GcdIoType              The desired IO type\r
 \r
-  @retval EFI_NOT_FOUND          The memory type does not match or there's an \r
-                                 image handle on the entry. \r
-  @retval EFI_UNSUPPORTED        The operation unsupported. \r
-  @retval EFI_SUCCESS            It's ok for this entry to be used to allocate \r
+  @retval EFI_NOT_FOUND          The memory type does not match or there's an\r
+                                 image handle on the entry.\r
+  @retval EFI_UNSUPPORTED        The operation unsupported.\r
+  @retval EFI_SUCCESS            It's ok for this entry to be used to allocate\r
                                  space.\r
 \r
 **/\r
@@ -819,18 +822,18 @@ CoreAllocateSpaceCheckEntry (
 /**\r
   Allocate space on specified address and length.\r
 \r
-  @param  Operation              The type of operation (memory or IO) \r
-  @param  GcdAllocateType        The type of allocate operation \r
-  @param  GcdMemoryType          The desired memory type \r
-  @param  GcdIoType              The desired IO type \r
-  @param  Alignment              Align with 2^Alignment \r
-  @param  Length                 Length to allocate \r
-  @param  BaseAddress            Base address to allocate \r
-  @param  ImageHandle            The image handle consume the allocated space. \r
-  @param  DeviceHandle           The device handle consume the allocated space. \r
-\r
-  @retval EFI_INVALID_PARAMETER  Invalid parameter. \r
-  @retval EFI_NOT_FOUND          No descriptor for the desired space exists. \r
+  @param  Operation              The type of operation (memory or IO)\r
+  @param  GcdAllocateType        The type of allocate operation\r
+  @param  GcdMemoryType          The desired memory type\r
+  @param  GcdIoType              The desired IO type\r
+  @param  Alignment              Align with 2^Alignment\r
+  @param  Length                 Length to allocate\r
+  @param  BaseAddress            Base address to allocate\r
+  @param  ImageHandle            The image handle consume the allocated space.\r
+  @param  DeviceHandle           The device handle consume the allocated space.\r
+\r
+  @retval EFI_INVALID_PARAMETER  Invalid parameter.\r
+  @retval EFI_NOT_FOUND          No descriptor for the desired space exists.\r
   @retval EFI_SUCCESS            Space successfully allocated.\r
 \r
 **/\r
@@ -973,7 +976,7 @@ CoreAllocateSpace (
       }\r
 \r
       if (GcdAllocateType == EfiGcdAllocateMaxAddressSearchTopDown ||\r
-          GcdAllocateType == EfiGcdAllocateAnySearchTopDown           ) {\r
+          GcdAllocateType == EfiGcdAllocateAnySearchTopDown) {\r
         if ((Entry->BaseAddress + Length) > MaxAddress) {\r
           continue;\r
         }\r
@@ -1071,12 +1074,12 @@ Done:
 /**\r
   Add a segment of memory to GCD map.\r
 \r
-  @param  GcdMemoryType          Memory type of the segment. \r
-  @param  BaseAddress            Base address of the segment. \r
-  @param  Length                 Length of the segment. \r
-  @param  Capabilities           alterable attributes of the segment. \r
+  @param  GcdMemoryType          Memory type of the segment.\r
+  @param  BaseAddress            Base address of the segment.\r
+  @param  Length                 Length of the segment.\r
+  @param  Capabilities           alterable attributes of the segment.\r
 \r
-  @retval EFI_INVALID_PARAMETER  Invalid parameters. \r
+  @retval EFI_INVALID_PARAMETER  Invalid parameters.\r
   @retval EFI_SUCCESS            Successfully add a segment of memory space.\r
 \r
 **/\r
@@ -1106,16 +1109,16 @@ CoreInternalAddMemorySpace (
   Allocates nonexistent memory, reserved memory, system memory, or memorymapped\r
   I/O resources from the global coherency domain of the processor.\r
 \r
-  @param  GcdAllocateType        The type of allocate operation \r
-  @param  GcdMemoryType          The desired memory type \r
-  @param  Alignment              Align with 2^Alignment \r
-  @param  Length                 Length to allocate \r
-  @param  BaseAddress            Base address to allocate \r
-  @param  ImageHandle            The image handle consume the allocated space. \r
-  @param  DeviceHandle           The device handle consume the allocated space. \r
+  @param  GcdAllocateType        The type of allocate operation\r
+  @param  GcdMemoryType          The desired memory type\r
+  @param  Alignment              Align with 2^Alignment\r
+  @param  Length                 Length to allocate\r
+  @param  BaseAddress            Base address to allocate\r
+  @param  ImageHandle            The image handle consume the allocated space.\r
+  @param  DeviceHandle           The device handle consume the allocated space.\r
 \r
-  @retval EFI_INVALID_PARAMETER  Invalid parameter. \r
-  @retval EFI_NOT_FOUND          No descriptor contains the desired space. \r
+  @retval EFI_INVALID_PARAMETER  Invalid parameter.\r
+  @retval EFI_NOT_FOUND          No descriptor contains the desired space.\r
   @retval EFI_SUCCESS            Memory space successfully allocated.\r
 \r
 **/\r
@@ -1131,14 +1134,14 @@ CoreAllocateMemorySpace (
   )\r
 {\r
   return CoreAllocateSpace (\r
-           GCD_ALLOCATE_MEMORY_OPERATION, \r
-           GcdAllocateType, \r
-           GcdMemoryType, \r
-           (EFI_GCD_IO_TYPE) 0, \r
-           Alignment, \r
-           Length, \r
-           BaseAddress, \r
-           ImageHandle, \r
+           GCD_ALLOCATE_MEMORY_OPERATION,\r
+           GcdAllocateType,\r
+           GcdMemoryType,\r
+           (EFI_GCD_IO_TYPE) 0,\r
+           Alignment,\r
+           Length,\r
+           BaseAddress,\r
+           ImageHandle,\r
            DeviceHandle\r
            );\r
 }\r
@@ -1148,10 +1151,10 @@ CoreAllocateMemorySpace (
   Adds reserved memory, system memory, or memory-mapped I/O resources to the\r
   global coherency domain of the processor.\r
 \r
-  @param  GcdMemoryType          Memory type of the memory space. \r
-  @param  BaseAddress            Base address of the memory space. \r
-  @param  Length                 Length of the memory space. \r
-  @param  Capabilities           alterable attributes of the memory space. \r
+  @param  GcdMemoryType          Memory type of the memory space.\r
+  @param  BaseAddress            Base address of the memory space.\r
+  @param  Length                 Length of the memory space.\r
+  @param  Capabilities           alterable attributes of the memory space.\r
 \r
   @retval EFI_SUCCESS            Merged this memory space into GCD map.\r
 \r
@@ -1178,7 +1181,7 @@ CoreAddMemorySpace (
     Status = CoreAllocateMemorySpace (\r
                EfiGcdAllocateAddress,\r
                GcdMemoryType,\r
-               EFI_PAGE_SHIFT,         \r
+               EFI_PAGE_SHIFT,\r
                PageLength,\r
                &PageBaseAddress,\r
                gDxeCoreImageHandle,\r
@@ -1197,7 +1200,7 @@ CoreAddMemorySpace (
         Status = CoreAllocateMemorySpace (\r
                    EfiGcdAllocateAddress,\r
                    GcdMemoryType,\r
-                   EFI_PAGE_SHIFT,         \r
+                   EFI_PAGE_SHIFT,\r
                    EFI_PAGE_SIZE,\r
                    &PageBaseAddress,\r
                    gDxeCoreImageHandle,\r
@@ -1223,8 +1226,8 @@ CoreAddMemorySpace (
   Frees nonexistent memory, reserved memory, system memory, or memory-mapped\r
   I/O resources from the global coherency domain of the processor.\r
 \r
-  @param  BaseAddress            Base address of the memory space. \r
-  @param  Length                 Length of the memory space. \r
+  @param  BaseAddress            Base address of the memory space.\r
+  @param  Length                 Length of the memory space.\r
 \r
   @retval EFI_SUCCESS            Space successfully freed.\r
 \r
@@ -1243,8 +1246,8 @@ CoreFreeMemorySpace (
   Removes reserved memory, system memory, or memory-mapped I/O resources from\r
   the global coherency domain of the processor.\r
 \r
-  @param  BaseAddress            Base address of the memory space. \r
-  @param  Length                 Length of the memory space. \r
+  @param  BaseAddress            Base address of the memory space.\r
+  @param  Length                 Length of the memory space.\r
 \r
   @retval EFI_SUCCESS            Successfully remove a segment of memory space.\r
 \r
@@ -1262,7 +1265,7 @@ CoreRemoveMemorySpace (
 /**\r
   Build a memory descriptor according to an entry.\r
 \r
-  @param  Descriptor             The descriptor to be built \r
+  @param  Descriptor             The descriptor to be built\r
   @param  Entry                  According to this entry\r
 \r
 **/\r
@@ -1285,10 +1288,10 @@ BuildMemoryDescriptor (
 /**\r
   Retrieves the descriptor for a memory region containing a specified address.\r
 \r
-  @param  BaseAddress            Specified start address \r
-  @param  Descriptor             Specified length \r
+  @param  BaseAddress            Specified start address\r
+  @param  Descriptor             Specified length\r
 \r
-  @retval EFI_INVALID_PARAMETER  Invalid parameter \r
+  @retval EFI_INVALID_PARAMETER  Invalid parameter\r
   @retval EFI_SUCCESS            Successfully get memory space descriptor.\r
 \r
 **/\r
@@ -1313,7 +1316,7 @@ CoreGetMemorySpaceDescriptor (
   CoreAcquireGcdMemoryLock ();\r
 \r
   //\r
-  // Search for the list of descriptors that contain BaseAddress \r
+  // Search for the list of descriptors that contain BaseAddress\r
   //\r
   Status = CoreSearchGcdMapEntry (BaseAddress, 1, &StartLink, &EndLink, &mGcdMemorySpaceMap);\r
   if (EFI_ERROR (Status)) {\r
@@ -1336,11 +1339,11 @@ CoreGetMemorySpaceDescriptor (
   Modifies the attributes for a memory region in the global coherency domain of the\r
   processor.\r
 \r
-  @param  BaseAddress            Specified start address \r
-  @param  Length                 Specified length \r
-  @param  Attributes             Specified attributes \r
+  @param  BaseAddress            Specified start address\r
+  @param  Length                 Specified length\r
+  @param  Attributes             Specified attributes\r
 \r
-  @retval EFI_SUCCESS            Successfully set attribute of a segment of \r
+  @retval EFI_SUCCESS            Successfully set attribute of a segment of\r
                                  memory space.\r
 \r
 **/\r
@@ -1359,11 +1362,11 @@ CoreSetMemorySpaceAttributes (
   Returns a map of the memory resources in the global coherency domain of the\r
   processor.\r
 \r
-  @param  NumberOfDescriptors    Number of descriptors. \r
-  @param  MemorySpaceMap         Descriptor array \r
+  @param  NumberOfDescriptors    Number of descriptors.\r
+  @param  MemorySpaceMap         Descriptor array\r
 \r
-  @retval EFI_INVALID_PARAMETER  Invalid parameter \r
-  @retval EFI_OUT_OF_RESOURCES   No enough buffer to allocate \r
+  @retval EFI_INVALID_PARAMETER  Invalid parameter\r
+  @retval EFI_OUT_OF_RESOURCES   No enough buffer to allocate\r
   @retval EFI_SUCCESS            Successfully get memory space map.\r
 \r
 **/\r
@@ -1398,7 +1401,7 @@ CoreGetMemorySpaceMap (
   //\r
   // Allocate the MemorySpaceMap\r
   //\r
-  *MemorySpaceMap = CoreAllocateBootServicesPool (*NumberOfDescriptors * sizeof (EFI_GCD_MEMORY_SPACE_DESCRIPTOR));\r
+  *MemorySpaceMap = AllocatePool (*NumberOfDescriptors * sizeof (EFI_GCD_MEMORY_SPACE_DESCRIPTOR));\r
   if (*MemorySpaceMap == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
@@ -1426,11 +1429,11 @@ Done:
 /**\r
   Adds reserved I/O or I/O resources to the global coherency domain of the processor.\r
 \r
-  @param  GcdIoType              IO type of the segment. \r
-  @param  BaseAddress            Base address of the segment. \r
-  @param  Length                 Length of the segment. \r
+  @param  GcdIoType              IO type of the segment.\r
+  @param  BaseAddress            Base address of the segment.\r
+  @param  Length                 Length of the segment.\r
 \r
-  @retval EFI_SUCCESS            Merged this segment into GCD map. \r
+  @retval EFI_SUCCESS            Merged this segment into GCD map.\r
   @retval EFI_INVALID_PARAMETER  Parameter not valid\r
 \r
 **/\r
@@ -1455,16 +1458,16 @@ CoreAddIoSpace (
   Allocates nonexistent I/O, reserved I/O, or I/O resources from the global coherency\r
   domain of the processor.\r
 \r
-  @param  GcdAllocateType        The type of allocate operation \r
-  @param  GcdIoType              The desired IO type \r
-  @param  Alignment              Align with 2^Alignment \r
-  @param  Length                 Length to allocate \r
-  @param  BaseAddress            Base address to allocate \r
-  @param  ImageHandle            The image handle consume the allocated space. \r
-  @param  DeviceHandle           The device handle consume the allocated space. \r
+  @param  GcdAllocateType        The type of allocate operation\r
+  @param  GcdIoType              The desired IO type\r
+  @param  Alignment              Align with 2^Alignment\r
+  @param  Length                 Length to allocate\r
+  @param  BaseAddress            Base address to allocate\r
+  @param  ImageHandle            The image handle consume the allocated space.\r
+  @param  DeviceHandle           The device handle consume the allocated space.\r
 \r
-  @retval EFI_INVALID_PARAMETER  Invalid parameter. \r
-  @retval EFI_NOT_FOUND          No descriptor contains the desired space. \r
+  @retval EFI_INVALID_PARAMETER  Invalid parameter.\r
+  @retval EFI_NOT_FOUND          No descriptor contains the desired space.\r
   @retval EFI_SUCCESS            IO space successfully allocated.\r
 \r
 **/\r
@@ -1480,14 +1483,14 @@ CoreAllocateIoSpace (
   )\r
 {\r
   return CoreAllocateSpace (\r
-           GCD_ALLOCATE_IO_OPERATION, \r
-           GcdAllocateType, \r
-           (EFI_GCD_MEMORY_TYPE) 0, \r
-           GcdIoType, \r
-           Alignment, \r
-           Length, \r
-           BaseAddress, \r
-           ImageHandle, \r
+           GCD_ALLOCATE_IO_OPERATION,\r
+           GcdAllocateType,\r
+           (EFI_GCD_MEMORY_TYPE) 0,\r
+           GcdIoType,\r
+           Alignment,\r
+           Length,\r
+           BaseAddress,\r
+           ImageHandle,\r
            DeviceHandle\r
            );\r
 }\r
@@ -1497,8 +1500,8 @@ CoreAllocateIoSpace (
   Frees nonexistent I/O, reserved I/O, or I/O resources from the global coherency\r
   domain of the processor.\r
 \r
-  @param  BaseAddress            Base address of the segment. \r
-  @param  Length                 Length of the segment. \r
+  @param  BaseAddress            Base address of the segment.\r
+  @param  Length                 Length of the segment.\r
 \r
   @retval EFI_SUCCESS            Space successfully freed.\r
 \r
@@ -1517,8 +1520,8 @@ CoreFreeIoSpace (
   Removes reserved I/O or I/O resources from the global coherency domain of the\r
   processor.\r
 \r
-  @param  BaseAddress            Base address of the segment. \r
-  @param  Length                 Length of the segment. \r
+  @param  BaseAddress            Base address of the segment.\r
+  @param  Length                 Length of the segment.\r
 \r
   @retval EFI_SUCCESS            Successfully removed a segment of IO space.\r
 \r
@@ -1536,7 +1539,7 @@ CoreRemoveIoSpace (
 /**\r
   Build a IO descriptor according to an entry.\r
 \r
-  @param  Descriptor             The descriptor to be built \r
+  @param  Descriptor             The descriptor to be built\r
   @param  Entry                  According to this entry\r
 \r
 **/\r
@@ -1557,10 +1560,10 @@ BuildIoDescriptor (
 /**\r
   Retrieves the descriptor for an I/O region containing a specified address.\r
 \r
-  @param  BaseAddress            Specified start address \r
-  @param  Descriptor             Specified length \r
+  @param  BaseAddress            Specified start address\r
+  @param  Descriptor             Specified length\r
 \r
-  @retval EFI_INVALID_PARAMETER  Descriptor is NULL. \r
+  @retval EFI_INVALID_PARAMETER  Descriptor is NULL.\r
   @retval EFI_SUCCESS            Successfully get the IO space descriptor.\r
 \r
 **/\r
@@ -1585,7 +1588,7 @@ CoreGetIoSpaceDescriptor (
   CoreAcquireGcdIoLock ();\r
 \r
   //\r
-  // Search for the list of descriptors that contain BaseAddress \r
+  // Search for the list of descriptors that contain BaseAddress\r
   //\r
   Status = CoreSearchGcdMapEntry (BaseAddress, 1, &StartLink, &EndLink, &mGcdIoSpaceMap);\r
   if (EFI_ERROR (Status)) {\r
@@ -1607,11 +1610,11 @@ CoreGetIoSpaceDescriptor (
 /**\r
   Returns a map of the I/O resources in the global coherency domain of the processor.\r
 \r
-  @param  NumberOfDescriptors    Number of descriptors. \r
-  @param  IoSpaceMap             Descriptor array \r
+  @param  NumberOfDescriptors    Number of descriptors.\r
+  @param  IoSpaceMap             Descriptor array\r
 \r
-  @retval EFI_INVALID_PARAMETER  Invalid parameter \r
-  @retval EFI_OUT_OF_RESOURCES   No enough buffer to allocate \r
+  @retval EFI_INVALID_PARAMETER  Invalid parameter\r
+  @retval EFI_OUT_OF_RESOURCES   No enough buffer to allocate\r
   @retval EFI_SUCCESS            Successfully get IO space map.\r
 \r
 **/\r
@@ -1646,7 +1649,7 @@ CoreGetIoSpaceMap (
   //\r
   // Allocate the IoSpaceMap\r
   //\r
-  *IoSpaceMap = CoreAllocateBootServicesPool (*NumberOfDescriptors * sizeof (EFI_GCD_IO_SPACE_DESCRIPTOR));\r
+  *IoSpaceMap = AllocatePool (*NumberOfDescriptors * sizeof (EFI_GCD_IO_SPACE_DESCRIPTOR));\r
   if (*IoSpaceMap == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
@@ -1668,16 +1671,16 @@ CoreGetIoSpaceMap (
 Done:\r
   CoreReleaseGcdIoLock ();\r
   return Status;\r
-}  \r
+}\r
 \r
 \r
 /**\r
   Converts a Resource Descriptor HOB attributes mask to an EFI Memory Descriptor\r
   capabilities mask\r
 \r
-  @param  GcdMemoryType          Type of resource in the GCD memory map. \r
-  @param  Attributes             The attribute mask in the Resource Descriptor \r
-                                 HOB. \r
+  @param  GcdMemoryType          Type of resource in the GCD memory map.\r
+  @param  Attributes             The attribute mask in the Resource Descriptor\r
+                                 HOB.\r
 \r
   @return The capabilities mask for an EFI Memory Descriptor.\r
 \r
@@ -1690,7 +1693,7 @@ CoreConvertResourceDescriptorHobAttributesToCapabilities (
 {\r
   UINT64                          Capabilities;\r
   GCD_ATTRIBUTE_CONVERSION_ENTRY  *Conversion;\r
-  \r
+\r
   //\r
   // Convert the Resource HOB Attributes to an EFI Memory Capabilities mask\r
   //\r
@@ -1701,7 +1704,7 @@ CoreConvertResourceDescriptorHobAttributesToCapabilities (
       }\r
     }\r
   }\r
-  \r
+\r
   return Capabilities;\r
 }\r
 \r
@@ -1714,10 +1717,10 @@ CoreConvertResourceDescriptorHobAttributesToCapabilities (
   memory descriptor is provided to the memory services.  Then the memory services\r
   can be used to intialize the GCD map.\r
 \r
-  @param  HobStart               The start address of the HOB. \r
-  @param  MemoryBaseAddress      Start address of memory region found to init DXE \r
-                                 core. \r
-  @param  MemoryLength           Length of memory region found to init DXE core. \r
+  @param  HobStart               The start address of the HOB.\r
+  @param  MemoryBaseAddress      Start address of memory region found to init DXE\r
+                                 core.\r
+  @param  MemoryLength           Length of memory region found to init DXE core.\r
 \r
   @retval EFI_SUCCESS            Memory services successfully initialized.\r
 \r
@@ -1804,7 +1807,7 @@ CoreInitializeMemoryServices (
       if (ResourceHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY                                       &&\r
           (ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == TESTED_MEMORY_ATTRIBUTES    ) {\r
 \r
-        if (PhitHob->EfiFreeMemoryBottom >= ResourceHob->PhysicalStart                         && \r
+        if (PhitHob->EfiFreeMemoryBottom >= ResourceHob->PhysicalStart                         &&\r
             PhitHob->EfiFreeMemoryTop    <= (ResourceHob->PhysicalStart + ResourceHob->ResourceLength)    ) {\r
 \r
           //\r
@@ -1859,10 +1862,9 @@ CoreInitializeMemoryServices (
         //\r
         // See if this resource descrior HOB describes tested system memory below MaxAddress\r
         //\r
-        if (ResourceHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY                                       &&\r
-            (ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == TESTED_MEMORY_ATTRIBUTES &&\r
-            ResourceHob->PhysicalStart + ResourceHob->ResourceLength <= MaxAddress                            ) {\r
-\r
+        if (ResourceHob->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY &&\r
+           (ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) == TESTED_MEMORY_ATTRIBUTES &&\r
+            ResourceHob->PhysicalStart + ResourceHob->ResourceLength <= MaxAddress) {\r
           //\r
           // See if this is the highest tested system memory region below MaxAddress\r
           //\r
@@ -1886,11 +1888,8 @@ CoreInitializeMemoryServices (
     MaxAddress = ResourceHob->PhysicalStart;\r
   } while (Found && MaxMemoryLength < MINIMUM_INITIAL_MEMORY_SIZE);\r
 \r
-  //\r
-  //\r
-  //\r
-  if ((Length < MINIMUM_INITIAL_MEMORY_SIZE)                                                 ||\r
-      (MaxMemoryBaseAddress > BaseAddress && MaxMemoryLength >= MINIMUM_INITIAL_MEMORY_SIZE)    ) {\r
+  if ((Length < MINIMUM_INITIAL_MEMORY_SIZE) ||\r
+      (MaxMemoryBaseAddress > BaseAddress && MaxMemoryLength >= MINIMUM_INITIAL_MEMORY_SIZE)) {\r
     BaseAddress = MaxMemoryBaseAddress;\r
     Length      = MaxMemoryLength;\r
     Attributes  = MaxMemoryAttributes;\r
@@ -1932,24 +1931,24 @@ CoreInitializeMemoryServices (
   can be used to intialize the GCD map. The HobStart will be relocated to a pool\r
   buffer.\r
 \r
-  @param  HobStart               The start address of the HOB \r
-  @param  MemoryBaseAddress      Start address of memory region found to init DXE \r
-                                 core. \r
-  @param  MemoryLength           Length of memory region found to init DXE core. \r
+  @param  HobStart               The start address of the HOB\r
+  @param  MemoryBaseAddress      Start address of memory region found to init DXE\r
+                                 core.\r
+  @param  MemoryLength           Length of memory region found to init DXE core.\r
 \r
   @retval EFI_SUCCESS            GCD services successfully initialized.\r
 \r
 **/\r
 EFI_STATUS\r
 CoreInitializeGcdServices (\r
-  IN OUT VOID                  **HobStart,\r
+  IN OUT VOID              **HobStart,\r
   IN EFI_PHYSICAL_ADDRESS  MemoryBaseAddress,\r
   IN UINT64                MemoryLength\r
   )\r
 {\r
-  EFI_PEI_HOB_POINTERS                   Hob;\r
+  EFI_PEI_HOB_POINTERS               Hob;\r
   VOID                               *NewHobList;\r
-  EFI_HOB_HANDOFF_INFO_TABLE  *PhitHob;\r
+  EFI_HOB_HANDOFF_INFO_TABLE         *PhitHob;\r
   UINT8                              SizeOfMemorySpace;\r
   UINT8                              SizeOfIoSpace;\r
   EFI_HOB_RESOURCE_DESCRIPTOR        *ResourceHob;\r
@@ -1967,6 +1966,7 @@ CoreInitializeGcdServices (
   UINTN                              Index;\r
   UINT64                             Capabilities;\r
   EFI_HOB_CPU *                      CpuHob;\r
+\r
   //\r
   // Cache the PHIT HOB for later use\r
   //\r
@@ -1979,11 +1979,11 @@ CoreInitializeGcdServices (
   ASSERT (CpuHob != NULL);\r
   SizeOfMemorySpace = CpuHob->SizeOfMemorySpace;\r
   SizeOfIoSpace     = CpuHob->SizeOfIoSpace;\r
\r
+\r
   //\r
   // Initialize the GCD Memory Space Map\r
   //\r
-  Entry = CoreAllocateCopyPool (sizeof (EFI_GCD_MAP_ENTRY), &mGcdMemorySpaceMapEntryTemplate);\r
+  Entry = AllocateCopyPool (sizeof (EFI_GCD_MAP_ENTRY), &mGcdMemorySpaceMapEntryTemplate);\r
   ASSERT (Entry != NULL);\r
 \r
   Entry->EndAddress = LShiftU64 (1, SizeOfMemorySpace) - 1;\r
@@ -1993,7 +1993,7 @@ CoreInitializeGcdServices (
   //\r
   // Initialize the GCD I/O Space Map\r
   //\r
-  Entry = CoreAllocateCopyPool (sizeof (EFI_GCD_MAP_ENTRY), &mGcdIoSpaceMapEntryTemplate);\r
+  Entry = AllocateCopyPool (sizeof (EFI_GCD_MAP_ENTRY), &mGcdIoSpaceMapEntryTemplate);\r
   ASSERT (Entry != NULL);\r
 \r
   Entry->EndAddress = LShiftU64 (1, SizeOfIoSpace) - 1;\r
@@ -2001,7 +2001,7 @@ CoreInitializeGcdServices (
   InsertHeadList (&mGcdIoSpaceMap, &Entry->Link);\r
 \r
   //\r
-  // Walk the HOB list and add all resource descriptors to the GCD \r
+  // Walk the HOB list and add all resource descriptors to the GCD\r
   //\r
   for (Hob.Raw = *HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) {\r
 \r
@@ -2041,7 +2041,6 @@ CoreInitializeGcdServices (
       }\r
 \r
       if (GcdMemoryType != EfiGcdMemoryTypeNonExistent) {\r
-\r
         //\r
         // Convert the Resource HOB Attributes to an EFI Memory Capabilities mask\r
         //\r
@@ -2093,7 +2092,7 @@ CoreInitializeGcdServices (
       if (!EFI_ERROR (Status)) {\r
         Status = CoreAllocateMemorySpace (\r
                    EfiGcdAllocateAddress,\r
-                   Descriptor.GcdMemoryType, \r
+                   Descriptor.GcdMemoryType,\r
                    0,\r
                    MemoryHob->AllocDescriptor.MemoryLength,\r
                    &BaseAddress,\r
@@ -2116,7 +2115,7 @@ CoreInitializeGcdServices (
       BaseAddress = FirmwareVolumeHob->BaseAddress;\r
       Status = CoreAllocateMemorySpace (\r
                  EfiGcdAllocateAddress,\r
-                 EfiGcdMemoryTypeMemoryMappedIo, \r
+                 EfiGcdMemoryTypeMemoryMappedIo,\r
                  0,\r
                  FirmwareVolumeHob->Length,\r
                  &BaseAddress,\r
@@ -2129,8 +2128,8 @@ CoreInitializeGcdServices (
   //\r
   // Relocate HOB List to an allocated pool buffer.\r
   //\r
-  NewHobList = CoreAllocateCopyPool (\r
-                 (UINTN)PhitHob->EfiFreeMemoryBottom - (UINTN)(*HobStart), \r
+  NewHobList = AllocateCopyPool (\r
+                 (UINTN)PhitHob->EfiFreeMemoryBottom - (UINTN)(*HobStart),\r
                  *HobStart\r
                  );\r
   ASSERT (NewHobList != NULL);\r