]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Gcd/Gcd.c
UefiCpuPkg/CpuDxe: prevent recursive calling of InitializePageTablePool
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Gcd / Gcd.c
index 31ddf9c3bb516e7dd34b92813f408d993c36aa7a..d9c65a8045e2906ceaf6ae6d6e33b3fe51fbaf4a 100644 (file)
@@ -3,7 +3,7 @@
   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 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2018, 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
@@ -126,7 +126,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdIoTypeNames[] = {
   "NonExist",  // EfiGcdIoTypeNonExistent\r
   "Reserved",  // EfiGcdIoTypeReserved\r
   "I/O     ",  // EfiGcdIoTypeIo\r
-  "Unknown "   // EfiGcdIoTypeMaximum \r
+  "Unknown "   // EfiGcdIoTypeMaximum\r
 };\r
 \r
 ///\r
@@ -146,7 +146,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdAllocationTypeNames[] = {
   PcdDebugPrintErrorLevel has the DEBUG_GCD bit set.\r
 \r
   @param  InitialMap  TRUE if the initial GCD Memory Map is being dumped.  Otherwise, FALSE.\r
-  \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -159,7 +159,7 @@ CoreDumpGcdMemorySpaceMap (
     UINTN                            NumberOfDescriptors;\r
     EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *MemorySpaceMap;\r
     UINTN                            Index;\r
-   \r
+\r
     Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
     ASSERT (Status == EFI_SUCCESS && MemorySpaceMap != NULL);\r
 \r
@@ -169,11 +169,11 @@ CoreDumpGcdMemorySpaceMap (
     DEBUG ((DEBUG_GCD, "GCDMemType Range                             Capabilities     Attributes      \n"));\r
     DEBUG ((DEBUG_GCD, "========== ================================= ================ ================\n"));\r
     for (Index = 0; Index < NumberOfDescriptors; Index++) {\r
-      DEBUG ((DEBUG_GCD, "%a  %016lx-%016lx %016lx %016lx%c\n", \r
+      DEBUG ((DEBUG_GCD, "%a  %016lx-%016lx %016lx %016lx%c\n",\r
         mGcdMemoryTypeNames[MIN (MemorySpaceMap[Index].GcdMemoryType, EfiGcdMemoryTypeMaximum)],\r
-        MemorySpaceMap[Index].BaseAddress, \r
+        MemorySpaceMap[Index].BaseAddress,\r
         MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - 1,\r
-        MemorySpaceMap[Index].Capabilities, \r
+        MemorySpaceMap[Index].Capabilities,\r
         MemorySpaceMap[Index].Attributes,\r
         MemorySpaceMap[Index].ImageHandle == NULL ? ' ' : '*'\r
         ));\r
@@ -184,11 +184,11 @@ CoreDumpGcdMemorySpaceMap (
 }\r
 \r
 /**\r
-  Dump the entire contents if the GCD I/O Space Map using DEBUG() macros when \r
+  Dump the entire contents if the GCD I/O Space Map using DEBUG() macros when\r
   PcdDebugPrintErrorLevel has the DEBUG_GCD bit set.\r
 \r
   @param  InitialMap  TRUE if the initial GCD I/O Map is being dumped.  Otherwise, FALSE.\r
-  \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -201,20 +201,20 @@ CoreDumpGcdIoSpaceMap (
     UINTN                        NumberOfDescriptors;\r
     EFI_GCD_IO_SPACE_DESCRIPTOR  *IoSpaceMap;\r
     UINTN                        Index;\r
-    \r
+\r
     Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap);\r
     ASSERT (Status == EFI_SUCCESS && IoSpaceMap != NULL);\r
-    \r
+\r
     if (InitialMap) {\r
       DEBUG ((DEBUG_GCD, "GCD:Initial GCD I/O Space Map\n"));\r
-    }  \r
-    \r
+    }\r
+\r
     DEBUG ((DEBUG_GCD, "GCDIoType  Range                            \n"));\r
     DEBUG ((DEBUG_GCD, "========== =================================\n"));\r
     for (Index = 0; Index < NumberOfDescriptors; Index++) {\r
-      DEBUG ((DEBUG_GCD, "%a   %016lx-%016lx%c\n", \r
+      DEBUG ((DEBUG_GCD, "%a   %016lx-%016lx%c\n",\r
         mGcdIoTypeNames[MIN (IoSpaceMap[Index].GcdIoType, EfiGcdIoTypeMaximum)],\r
-        IoSpaceMap[Index].BaseAddress, \r
+        IoSpaceMap[Index].BaseAddress,\r
         IoSpaceMap[Index].BaseAddress + IoSpaceMap[Index].Length - 1,\r
         IoSpaceMap[Index].ImageHandle == NULL ? ' ' : '*'\r
         ));\r
@@ -223,11 +223,11 @@ CoreDumpGcdIoSpaceMap (
     FreePool (IoSpaceMap);\r
   );\r
 }\r
-  \r
+\r
 /**\r
   Validate resource descriptor HOB's attributes.\r
 \r
-  If Attributes includes some memory resource's settings, it should include \r
+  If Attributes includes some memory resource's settings, it should include\r
   the corresponding capabilites also.\r
 \r
   @param  Attributes  Resource descriptor HOB attributes.\r
@@ -866,19 +866,23 @@ CoreConvertSpace (
   }\r
   ASSERT (TopEntry != NULL && BottomEntry != NULL);\r
 \r
+  //\r
+  // Initialize CpuArchAttributes to suppress incorrect compiler/analyzer warnings.\r
+  //\r
+  CpuArchAttributes = 0;\r
   if (Operation == GCD_SET_ATTRIBUTES_MEMORY_OPERATION) {\r
     //\r
     // Call CPU Arch Protocol to attempt to set attributes on the range\r
     //\r
     CpuArchAttributes = ConverToCpuArchAttributes (Attributes);\r
     //\r
-    // CPU arch attributes include page attributes and cache attributes. \r
+    // CPU arch attributes include page attributes and cache attributes.\r
     // Only page attributes supports to be cleared, but not cache attributes.\r
     // Caller is expected to use GetMemorySpaceDescriptor() to get the current\r
     // attributes, AND/OR attributes, and then calls SetMemorySpaceAttributes()\r
     // to set the new attributes.\r
     // So 0 CPU arch attributes should not happen as memory should always have\r
-    // a cache attribute (no matter UC or WB, etc). \r
+    // a cache attribute (no matter UC or WB, etc).\r
     //\r
     // Here, 0 CPU arch attributes will be filtered to be compatible with the\r
     // case that caller just calls SetMemorySpaceAttributes() with none CPU\r
@@ -1289,7 +1293,7 @@ Done:
     DEBUG ((DEBUG_GCD, "  (BaseAddress = %016lx)", *BaseAddress));\r
   }\r
   DEBUG ((DEBUG_GCD, "\n"));\r
-  \r
+\r
   if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) {\r
     CoreReleaseGcdMemoryLock ();\r
     CoreDumpGcdMemorySpaceMap (FALSE);\r
@@ -1380,7 +1384,7 @@ CoreAllocateMemorySpace (
   DEBUG ((DEBUG_GCD, "  Alignment       = %016lx\n", LShiftU64 (1, Alignment)));\r
   DEBUG ((DEBUG_GCD, "  ImageHandle     = %p\n", ImageHandle));\r
   DEBUG ((DEBUG_GCD, "  DeviceHandle    = %p\n", DeviceHandle));\r
-  \r
+\r
   return CoreAllocateSpace (\r
            GCD_ALLOCATE_MEMORY_OPERATION,\r
            GcdAllocateType,\r
@@ -1512,7 +1516,7 @@ CoreRemoveMemorySpace (
   )\r
 {\r
   DEBUG ((DEBUG_GCD, "GCD:RemoveMemorySpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));\r
-  \r
+\r
   return CoreConvertSpace (GCD_REMOVE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);\r
 }\r
 \r
@@ -1601,7 +1605,7 @@ CoreGetMemorySpaceDescriptor (
   @param  Attributes             Specified attributes\r
 \r
   @retval EFI_SUCCESS           The attributes were set for the memory region.\r
-  @retval EFI_INVALID_PARAMETER Length is zero. \r
+  @retval EFI_INVALID_PARAMETER Length is zero.\r
   @retval EFI_UNSUPPORTED       The processor does not support one or more bytes of the memory\r
                                 resource range specified by BaseAddress and Length.\r
   @retval EFI_UNSUPPORTED       The bit mask of attributes is not support for the memory resource\r
@@ -1758,7 +1762,7 @@ CoreAddIoSpace (
 {\r
   DEBUG ((DEBUG_GCD, "GCD:AddIoSpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));\r
   DEBUG ((DEBUG_GCD, "  GcdIoType    = %a\n", mGcdIoTypeNames[MIN (GcdIoType, EfiGcdIoTypeMaximum)]));\r
-  \r
+\r
   //\r
   // Make sure parameters are valid\r
   //\r
@@ -1808,7 +1812,7 @@ CoreAllocateIoSpace (
   DEBUG ((DEBUG_GCD, "  Alignment       = %016lx\n", LShiftU64 (1, Alignment)));\r
   DEBUG ((DEBUG_GCD, "  ImageHandle     = %p\n", ImageHandle));\r
   DEBUG ((DEBUG_GCD, "  DeviceHandle    = %p\n", DeviceHandle));\r
-  \r
+\r
   return CoreAllocateSpace (\r
            GCD_ALLOCATE_IO_OPERATION,\r
            GcdAllocateType,\r
@@ -1864,7 +1868,7 @@ CoreRemoveIoSpace (
   )\r
 {\r
   DEBUG ((DEBUG_GCD, "GCD:RemoveIoSpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));\r
-  \r
+\r
   return CoreConvertSpace (GCD_REMOVE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);\r
 }\r
 \r
@@ -2134,15 +2138,15 @@ CoreInitializeMemoryServices (
   // Cache the PHIT HOB for later use\r
   //\r
   PhitHob = Hob.HandoffInformationTable;\r
-  \r
+\r
   if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0) {\r
-       ReservedCodePageNumber = PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);\r
-       ReservedCodePageNumber += PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);\r
-   \r
-       //\r
-       // cache the Top address for loading modules at Fixed Address \r
-       //\r
-    gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress = PhitHob->EfiMemoryTop \r
+    ReservedCodePageNumber = PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);\r
+    ReservedCodePageNumber += PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);\r
+\r
+    //\r
+    // cache the Top address for loading modules at Fixed Address\r
+    //\r
+    gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress = PhitHob->EfiMemoryTop\r
                                                                    + EFI_PAGES_TO_SIZE(ReservedCodePageNumber);\r
   }\r
   //\r
@@ -2209,14 +2213,14 @@ CoreInitializeMemoryServices (
     Length      = PageAlignLength  (ResourceHob->PhysicalStart + ResourceHob->ResourceLength - BaseAddress);\r
     if (Length < MinimalMemorySizeNeeded) {\r
       //\r
-      // If that range is not large enough to intialize the DXE Core, then \r
+      // If that range is not large enough to intialize the DXE Core, then\r
       // Compute range between PHIT EfiFreeMemoryBottom and PHIT EfiFreeMemoryTop\r
       //\r
       BaseAddress = PageAlignAddress (PhitHob->EfiFreeMemoryBottom);\r
       Length      = PageAlignLength  (PhitHob->EfiFreeMemoryTop - BaseAddress);\r
       if (Length < MinimalMemorySizeNeeded) {\r
         //\r
-        // If that range is not large enough to intialize the DXE Core, then \r
+        // If that range is not large enough to intialize the DXE Core, then\r
         // Compute range between the start of the Resource Descriptor HOB and the start of the HOB List\r
         //\r
         BaseAddress = PageAlignAddress (ResourceHob->PhysicalStart);\r
@@ -2293,7 +2297,7 @@ CoreInitializeMemoryServices (
       //\r
       BaseAddress = TestedMemoryBaseAddress;\r
       Length      = TestedMemoryLength;\r
-      Attributes  = ResourceHob->ResourceAttribute; \r
+      Attributes  = ResourceHob->ResourceAttribute;\r
       HighAddress = ResourceHob->PhysicalStart;\r
     }\r
   }\r
@@ -2399,7 +2403,7 @@ CoreInitializeGcdServices (
   InsertHeadList (&mGcdMemorySpaceMap, &Entry->Link);\r
 \r
   CoreDumpGcdMemorySpaceMap (TRUE);\r
-  \r
+\r
   //\r
   // Initialize the GCD I/O Space Map\r
   //\r
@@ -2411,7 +2415,7 @@ CoreInitializeGcdServices (
   InsertHeadList (&mGcdIoSpaceMap, &Entry->Link);\r
 \r
   CoreDumpGcdIoSpaceMap (TRUE);\r
-  \r
+\r
   //\r
   // Walk the HOB list and add all resource descriptors to the GCD\r
   //\r