]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add DEBUG() macros to all GCD services to monitor all changes to the GCD Memory and...
authormdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 6 Jan 2011 02:51:08 +0000 (02:51 +0000)
committermdkinney <mdkinney@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 6 Jan 2011 02:51:08 +0000 (02:51 +0000)
If DEBUG_PROPERTY_DEBUG_CODE_ENABLED is also set in PcdDebugPropertyMask, then the GCD Memory and I/O Maps will be dumped every time there is a GCD change.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11230 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Core/Dxe/Gcd/Gcd.c

index f9ad44609e5397f34b9964e9db26a8ee2557ec5d..467e4a00793e8dbae029ff4c365fa3841d9b4709 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 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2011, 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
@@ -95,6 +95,108 @@ GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = {
   { 0,                                              0,                      FALSE }\r
 };\r
 \r
+///\r
+/// Lookup table used to print GCD Memory Space Map\r
+///\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryTypeNames[] = {\r
+  "NonExist ",  // EfiGcdMemoryTypeNonExistent\r
+  "Reserved ",  // EfiGcdMemoryTypeReserved\r
+  "SystemMem",  // EfiGcdMemoryTypeSystemMemory\r
+  "MMIO     ",  // EfiGcdMemoryTypeMemoryMappedIo\r
+  "Unknown  "   // EfiGcdMemoryTypeMaximum\r
+};\r
+\r
+///\r
+/// Lookup table used to print GCD I/O Space Map\r
+///\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdIoTypeNames[] = {\r
+  "NonExist",  // EfiGcdIoTypeNonExistent\r
+  "Reserved",  // EfiGcdIoTypeReserved\r
+  "I/O     ",  // EfiGcdIoTypeIo\r
+  "Unknown "   // EfiGcdIoTypeMaximum \r
+};\r
+\r
+///\r
+/// Lookup table used to print GCD Allocation Types\r
+///\r
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdAllocationTypeNames[] = {\r
+  "AnySearchBottomUp        ",  // EfiGcdAllocateAnySearchBottomUp\r
+  "MaxAddressSearchBottomUp ",  // EfiGcdAllocateMaxAddressSearchBottomUp\r
+  "AtAddress                ",  // EfiGcdAllocateAddress\r
+  "AnySearchTopDown         ",  // EfiGcdAllocateAnySearchTopDown\r
+  "MaxAddressSearchTopDown  ",  // EfiGcdAllocateMaxAddressSearchTopDown\r
+  "Unknown                  "   // EfiGcdMaxAllocateType\r
+};\r
+\r
+/**\r
+  Dump the entire contents if the GCD Memory Space Map using DEBUG() macros when\r
+  PcdDebugPrintErrorLevel has the DEBUG_GCD bit set.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+CoreDumpGcdMemorySpaceMap (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  UINTN                            NumberOfDescriptors;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR  *MemorySpaceMap;\r
+  UINTN                            Index;\r
+  \r
+  Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  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
+      mGcdMemoryTypeNames[MIN (MemorySpaceMap[Index].GcdMemoryType, EfiGcdMemoryTypeMaximum)],\r
+      MemorySpaceMap[Index].BaseAddress, \r
+      MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - 1,\r
+      MemorySpaceMap[Index].Capabilities, \r
+      MemorySpaceMap[Index].Attributes,\r
+      MemorySpaceMap[Index].ImageHandle == NULL ? ' ' : '*'\r
+      ));\r
+  }\r
+  DEBUG ((DEBUG_GCD, "\n"));\r
+  FreePool (MemorySpaceMap);\r
+}\r
+\r
+/**\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
+**/\r
+VOID\r
+EFIAPI\r
+CoreDumpGcdIoSpaceMap (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  UINTN                        NumberOfDescriptors;\r
+  EFI_GCD_IO_SPACE_DESCRIPTOR  *IoSpaceMap;\r
+  UINTN                        Index;\r
+  \r
+  Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap);\r
+  ASSERT_EFI_ERROR (Status);\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
+      mGcdIoTypeNames[MIN (IoSpaceMap[Index].GcdIoType, EfiGcdIoTypeMaximum)],\r
+      IoSpaceMap[Index].BaseAddress, \r
+      IoSpaceMap[Index].BaseAddress + IoSpaceMap[Index].Length - 1,\r
+      IoSpaceMap[Index].ImageHandle == NULL ? ' ' : '*'\r
+      ));\r
+  }\r
+  DEBUG ((DEBUG_GCD, "\n"));\r
+  FreePool (IoSpaceMap);\r
+}\r
+  \r
+\r
 \r
 /**\r
   Acquire memory lock on mGcdMemorySpaceLock.\r
@@ -571,11 +673,12 @@ CoreConvertSpace (
   EFI_GCD_MAP_ENTRY  *BottomEntry;\r
   LIST_ENTRY         *StartLink;\r
   LIST_ENTRY         *EndLink;\r
-\r
-  EFI_CPU_ARCH_PROTOCOL           *CpuArch;\r
-  UINT64                          CpuArchAttributes;\r
+  UINT64             CpuArchAttributes;\r
 \r
   if (Length == 0) {\r
+    DEBUG_CODE_BEGIN ();\r
+      DEBUG ((DEBUG_GCD, "  Status = %r\n", EFI_INVALID_PARAMETER));\r
+    DEBUG_CODE_END ();\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -692,24 +795,19 @@ CoreConvertSpace (
     // Call CPU Arch Protocol to attempt to set attributes on the range\r
     //\r
     CpuArchAttributes = ConverToCpuArchAttributes (Attributes);\r
-    if ( CpuArchAttributes != INVALID_CPU_ARCH_ATTRIBUTES ) {\r
-      Status = CoreLocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuArch);\r
-      if (EFI_ERROR (Status) || CpuArch == NULL) {\r
-        Status = EFI_ACCESS_DENIED;\r
-        goto Done;\r
-      }\r
-\r
-      Status = CpuArch->SetMemoryAttributes (\r
-                          CpuArch,\r
-                          BaseAddress,\r
-                          Length,\r
-                          CpuArchAttributes\r
-                          );\r
-      if (EFI_ERROR (Status)) {\r
-        goto Done;\r
+    if (CpuArchAttributes != INVALID_CPU_ARCH_ATTRIBUTES) {\r
+      if (gCpu != NULL) {\r
+        Status = gCpu->SetMemoryAttributes (\r
+                         gCpu,\r
+                         BaseAddress,\r
+                         Length,\r
+                         CpuArchAttributes\r
+                         );\r
+        if (EFI_ERROR (Status)) {\r
+          goto Done;\r
+        }\r
       }\r
     }\r
-\r
   }\r
 \r
   //\r
@@ -768,11 +866,26 @@ CoreConvertSpace (
   Status = CoreCleanupGcdMapEntry (TopEntry, BottomEntry, StartLink, EndLink, Map);\r
 \r
 Done:\r
+  DEBUG_CODE_BEGIN ();\r
+    DEBUG ((DEBUG_GCD, "  Status = %r\n", Status));\r
+  DEBUG_CODE_END ();\r
+\r
   if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) {\r
     CoreReleaseGcdMemoryLock ();\r
+    DEBUG_CODE_BEGIN ();\r
+      //\r
+      // Do not dump GCD Memory Space Map for GCD changes below 16 MB  \r
+      //\r
+      if (BaseAddress >= BASE_16MB) {\r
+        CoreDumpGcdMemorySpaceMap ();\r
+      }\r
+    DEBUG_CODE_END ();\r
   }\r
   if ((Operation & GCD_IO_SPACE_OPERATION) != 0) {\r
     CoreReleaseGcdIoLock ();\r
+    DEBUG_CODE_BEGIN ();\r
+      CoreDumpGcdIoSpaceMap ();\r
+    DEBUG_CODE_END ();\r
   }\r
 \r
   return Status;\r
@@ -871,24 +984,45 @@ CoreAllocateSpace (
   // Make sure parameters are valid\r
   //\r
   if (GcdAllocateType < 0 || GcdAllocateType >= EfiGcdMaxAllocateType) {\r
+    DEBUG_CODE_BEGIN ();\r
+      DEBUG ((DEBUG_GCD, "  Status = %r\n", EFI_INVALID_PARAMETER));\r
+    DEBUG_CODE_END ();\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (GcdMemoryType < 0 || GcdMemoryType >= EfiGcdMemoryTypeMaximum) {\r
+    DEBUG_CODE_BEGIN ();\r
+      DEBUG ((DEBUG_GCD, "  Status = %r\n", EFI_INVALID_PARAMETER));\r
+    DEBUG_CODE_END ();\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (GcdIoType < 0 || GcdIoType >= EfiGcdIoTypeMaximum) {\r
+    DEBUG_CODE_BEGIN ();\r
+      DEBUG ((DEBUG_GCD, "  Status = %r\n", EFI_INVALID_PARAMETER));\r
+    DEBUG_CODE_END ();\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (BaseAddress == NULL) {\r
+    DEBUG_CODE_BEGIN ();\r
+      DEBUG ((DEBUG_GCD, "  Status = %r\n", EFI_INVALID_PARAMETER));\r
+    DEBUG_CODE_END ();\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (ImageHandle == NULL) {\r
+    DEBUG_CODE_BEGIN ();\r
+      DEBUG ((DEBUG_GCD, "  Status = %r\n", EFI_INVALID_PARAMETER));\r
+    DEBUG_CODE_END ();\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (Alignment >= 64) {\r
+    DEBUG_CODE_BEGIN ();\r
+      DEBUG ((DEBUG_GCD, "  Status = %r\n", EFI_NOT_FOUND));\r
+    DEBUG_CODE_END ();\r
     return EFI_NOT_FOUND;\r
   }\r
   if (Length == 0) {\r
+    DEBUG_CODE_BEGIN ();\r
+      DEBUG ((DEBUG_GCD, "  Status = %r\n", EFI_INVALID_PARAMETER));\r
+    DEBUG_CODE_END ();\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -1068,13 +1202,32 @@ CoreAllocateSpace (
   Status = CoreCleanupGcdMapEntry (TopEntry, BottomEntry, StartLink, EndLink, Map);\r
 \r
 Done:\r
+  DEBUG_CODE_BEGIN ();\r
+    DEBUG ((DEBUG_GCD, "  Status = %r", Status));\r
+    if (!EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_GCD, "  (BaseAddress = %016lx)\n", *BaseAddress));\r
+    }\r
+    DEBUG ((DEBUG_GCD, "\n"));\r
+  DEBUG_CODE_END ();\r
+  \r
   if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) {\r
     CoreReleaseGcdMemoryLock ();\r
+    DEBUG_CODE_BEGIN ();\r
+      //\r
+      // Do not dump GCD Memory Space Map for GCD changes below 16 MB  \r
+      //\r
+      if (*BaseAddress >= BASE_16MB) {\r
+        CoreDumpGcdMemorySpaceMap ();\r
+      }\r
+    DEBUG_CODE_END ();\r
   }\r
   if ((Operation & GCD_IO_SPACE_OPERATION) !=0) {\r
     CoreReleaseGcdIoLock ();\r
+    DEBUG_CODE_BEGIN ();\r
+      CoreDumpGcdIoSpaceMap ();\r
+    DEBUG_CODE_END ();\r
   }\r
-\r
+  \r
   return Status;\r
 }\r
 \r
@@ -1099,6 +1252,10 @@ CoreInternalAddMemorySpace (
   IN UINT64                Capabilities\r
   )\r
 {\r
+  DEBUG ((DEBUG_GCD, "GCD:AddMemorySpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));\r
+  DEBUG ((DEBUG_GCD, "  GcdMemoryType   = %a\n", mGcdMemoryTypeNames[MIN (GcdMemoryType, EfiGcdMemoryTypeMaximum)]));\r
+  DEBUG ((DEBUG_GCD, "  Capabilities    = %016lx\n", Capabilities));\r
+\r
   //\r
   // Make sure parameters are valid\r
   //\r
@@ -1142,6 +1299,13 @@ CoreAllocateMemorySpace (
   IN     EFI_HANDLE             DeviceHandle OPTIONAL\r
   )\r
 {\r
+  DEBUG ((DEBUG_GCD, "GCD:AllocateMemorySpace(Base=%016lx,Length=%016lx)\n", *BaseAddress, Length));\r
+  DEBUG ((DEBUG_GCD, "  GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)]));\r
+  DEBUG ((DEBUG_GCD, "  GcdMemoryType   = %a\n", mGcdMemoryTypeNames[MIN (GcdMemoryType, EfiGcdMemoryTypeMaximum)]));\r
+  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
   return CoreAllocateSpace (\r
            GCD_ALLOCATE_MEMORY_OPERATION,\r
            GcdAllocateType,\r
@@ -1249,6 +1413,8 @@ CoreFreeMemorySpace (
   IN UINT64                Length\r
   )\r
 {\r
+  DEBUG ((DEBUG_GCD, "GCD:FreeMemorySpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));\r
+\r
   return CoreConvertSpace (GCD_FREE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);\r
 }\r
 \r
@@ -1270,6 +1436,8 @@ CoreRemoveMemorySpace (
   IN UINT64                Length\r
   )\r
 {\r
+  DEBUG ((DEBUG_GCD, "GCD:RemoveMemorySpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));\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
@@ -1369,6 +1537,9 @@ CoreSetMemorySpaceAttributes (
   IN UINT64                Attributes\r
   )\r
 {\r
+  DEBUG ((DEBUG_GCD, "GCD:SetMemorySpaceAttributes(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));\r
+  DEBUG ((DEBUG_GCD, "  Attributes  = %016lx\n", Attributes));\r
+\r
   return CoreConvertSpace (GCD_SET_ATTRIBUTES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, Attributes);\r
 }\r
 \r
@@ -1461,6 +1632,9 @@ CoreAddIoSpace (
   IN UINT64                Length\r
   )\r
 {\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
   // Make sure parameters are valid\r
   //\r
@@ -1500,6 +1674,13 @@ CoreAllocateIoSpace (
   IN     EFI_HANDLE             DeviceHandle OPTIONAL\r
   )\r
 {\r
+  DEBUG ((DEBUG_GCD, "GCD:AllocateIoSpace(Base=%016lx,Length=%016lx)\n", *BaseAddress, Length));\r
+  DEBUG ((DEBUG_GCD, "  GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)]));\r
+  DEBUG ((DEBUG_GCD, "  GcdMemoryType   = %a\n", mGcdIoTypeNames[MIN (GcdIoType, EfiGcdMemoryTypeMaximum)]));\r
+  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
   return CoreAllocateSpace (\r
            GCD_ALLOCATE_IO_OPERATION,\r
            GcdAllocateType,\r
@@ -1531,6 +1712,8 @@ CoreFreeIoSpace (
   IN UINT64                Length\r
   )\r
 {\r
+  DEBUG ((DEBUG_GCD, "GCD:FreeIoSpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));\r
+\r
   return CoreConvertSpace (GCD_FREE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0);\r
 }\r
 \r
@@ -1552,6 +1735,8 @@ CoreRemoveIoSpace (
   IN UINT64                Length\r
   )\r
 {\r
+  DEBUG ((DEBUG_GCD, "GCD:RemoveIoSpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length));\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
@@ -1696,7 +1881,6 @@ Done:
   return Status;\r
 }\r
 \r
-\r
 /**\r
   Converts a Resource Descriptor HOB attributes mask to an EFI Memory Descriptor\r
   capabilities mask\r
@@ -2020,6 +2204,11 @@ CoreInitializeGcdServices (
 \r
   InsertHeadList (&mGcdMemorySpaceMap, &Entry->Link);\r
 \r
+  DEBUG_CODE_BEGIN ();\r
+    DEBUG ((DEBUG_GCD, "GCD:Initial GCD Memory Space Map\n"));\r
+    CoreDumpGcdMemorySpaceMap ();\r
+  DEBUG_CODE_END ();\r
+  \r
   //\r
   // Initialize the GCD I/O Space Map\r
   //\r
@@ -2030,6 +2219,11 @@ CoreInitializeGcdServices (
 \r
   InsertHeadList (&mGcdIoSpaceMap, &Entry->Link);\r
 \r
+  DEBUG_CODE_BEGIN ();\r
+    DEBUG ((DEBUG_GCD, "GCD:Initial GCD I/O Space Map\n"));\r
+    CoreDumpGcdIoSpaceMap ();\r
+  DEBUG_CODE_END ();\r
+  \r
   //\r
   // Walk the HOB list and add all resource descriptors to the GCD\r
   //\r