+///\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
+ "PersisMem", // EfiGcdMemoryTypePersistentMemory\r
+ "MoreRelia", // EfiGcdMemoryTypeMoreReliable\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
+ @param InitialMap TRUE if the initial GCD Memory Map is being dumped. Otherwise, FALSE.\r
+ \r
+**/\r
+VOID\r
+EFIAPI\r
+CoreDumpGcdMemorySpaceMap (\r
+ BOOLEAN InitialMap\r
+ )\r
+{\r
+ DEBUG_CODE (\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 (Status == EFI_SUCCESS && MemorySpaceMap != NULL);\r
+\r
+ if (InitialMap) {\r
+ DEBUG ((DEBUG_GCD, "GCD:Initial GCD Memory Space Map\n"));\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
+/**\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
+VOID\r
+EFIAPI\r
+CoreDumpGcdIoSpaceMap (\r
+ BOOLEAN InitialMap\r
+ )\r
+{\r
+ DEBUG_CODE (\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 (Status == EFI_SUCCESS && IoSpaceMap != NULL);\r
+ \r
+ if (InitialMap) {\r
+ DEBUG ((DEBUG_GCD, "GCD:Initial GCD I/O Space Map\n"));\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
+ 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
+ Validate resource descriptor HOB's attributes.\r
+\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
+\r
+**/\r
+VOID\r
+CoreValidateResourceDescriptorHobAttributes (\r
+ IN UINT64 Attributes\r
+ )\r
+{\r
+ ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED) == 0) ||\r
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_PROTECTABLE) != 0));\r
+ ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED) == 0) ||\r
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTABLE) != 0));\r
+ ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED) == 0) ||\r
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTABLE) != 0));\r
+ ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED) == 0) ||\r
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTABLE) != 0));\r
+ ASSERT (((Attributes & EFI_RESOURCE_ATTRIBUTE_PERSISTENT) == 0) ||\r
+ ((Attributes & EFI_RESOURCE_ATTRIBUTE_PERSISTABLE) != 0));\r
+}\r