X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FGcd%2FGcd.c;h=0ec75ca5021c48951b48ab555fdfc8cdac765226;hb=5d1cf216ed65e9d79f4158a0b8340c18dd5113a1;hp=6ac093162efb7513ac449ccd088bb042b38e1b58;hpb=852081fc68a3b8fe372cda5fb009058d8a077ab9;p=mirror_edk2.git diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 6ac093162e..0ec75ca502 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -3,8 +3,8 @@ The GCD services are used to manage the memory and I/O regions that are accessible to the CPU that is executing the DXE core. -Copyright (c) 2006 - 2008, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -95,6 +95,123 @@ GCD_ATTRIBUTE_CONVERSION_ENTRY mAttributeConversionTable[] = { { 0, 0, FALSE } }; +/// +/// Lookup table used to print GCD Memory Space Map +/// +GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdMemoryTypeNames[] = { + "NonExist ", // EfiGcdMemoryTypeNonExistent + "Reserved ", // EfiGcdMemoryTypeReserved + "SystemMem", // EfiGcdMemoryTypeSystemMemory + "MMIO ", // EfiGcdMemoryTypeMemoryMappedIo + "Unknown " // EfiGcdMemoryTypeMaximum +}; + +/// +/// Lookup table used to print GCD I/O Space Map +/// +GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdIoTypeNames[] = { + "NonExist", // EfiGcdIoTypeNonExistent + "Reserved", // EfiGcdIoTypeReserved + "I/O ", // EfiGcdIoTypeIo + "Unknown " // EfiGcdIoTypeMaximum +}; + +/// +/// Lookup table used to print GCD Allocation Types +/// +GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mGcdAllocationTypeNames[] = { + "AnySearchBottomUp ", // EfiGcdAllocateAnySearchBottomUp + "MaxAddressSearchBottomUp ", // EfiGcdAllocateMaxAddressSearchBottomUp + "AtAddress ", // EfiGcdAllocateAddress + "AnySearchTopDown ", // EfiGcdAllocateAnySearchTopDown + "MaxAddressSearchTopDown ", // EfiGcdAllocateMaxAddressSearchTopDown + "Unknown " // EfiGcdMaxAllocateType +}; + +/** + Dump the entire contents if the GCD Memory Space Map using DEBUG() macros when + PcdDebugPrintErrorLevel has the DEBUG_GCD bit set. + + @param InitialMap TRUE if the initial GCD Memory Map is being dumped. Otherwise, FALSE. + +**/ +VOID +EFIAPI +CoreDumpGcdMemorySpaceMap ( + BOOLEAN InitialMap + ) +{ + DEBUG_CODE ( + EFI_STATUS Status; + UINTN NumberOfDescriptors; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap; + UINTN Index; + + Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap); + ASSERT_EFI_ERROR (Status); + + if (InitialMap) { + DEBUG ((DEBUG_GCD, "GCD:Initial GCD Memory Space Map\n")); + } + DEBUG ((DEBUG_GCD, "GCDMemType Range Capabilities Attributes \n")); + DEBUG ((DEBUG_GCD, "========== ================================= ================ ================\n")); + for (Index = 0; Index < NumberOfDescriptors; Index++) { + DEBUG ((DEBUG_GCD, "%a %016lx-%016lx %016lx %016lx%c\n", + mGcdMemoryTypeNames[MIN (MemorySpaceMap[Index].GcdMemoryType, EfiGcdMemoryTypeMaximum)], + MemorySpaceMap[Index].BaseAddress, + MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length - 1, + MemorySpaceMap[Index].Capabilities, + MemorySpaceMap[Index].Attributes, + MemorySpaceMap[Index].ImageHandle == NULL ? ' ' : '*' + )); + } + DEBUG ((DEBUG_GCD, "\n")); + FreePool (MemorySpaceMap); + ); +} + +/** + Dump the entire contents if the GCD I/O Space Map using DEBUG() macros when + PcdDebugPrintErrorLevel has the DEBUG_GCD bit set. + + @param InitialMap TRUE if the initial GCD I/O Map is being dumped. Otherwise, FALSE. + +**/ +VOID +EFIAPI +CoreDumpGcdIoSpaceMap ( + BOOLEAN InitialMap + ) +{ + DEBUG_CODE ( + EFI_STATUS Status; + UINTN NumberOfDescriptors; + EFI_GCD_IO_SPACE_DESCRIPTOR *IoSpaceMap; + UINTN Index; + + Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap); + ASSERT_EFI_ERROR (Status); + + if (InitialMap) { + DEBUG ((DEBUG_GCD, "GCD:Initial GCD I/O Space Map\n")); + } + + DEBUG ((DEBUG_GCD, "GCDIoType Range \n")); + DEBUG ((DEBUG_GCD, "========== =================================\n")); + for (Index = 0; Index < NumberOfDescriptors; Index++) { + DEBUG ((DEBUG_GCD, "%a %016lx-%016lx%c\n", + mGcdIoTypeNames[MIN (IoSpaceMap[Index].GcdIoType, EfiGcdIoTypeMaximum)], + IoSpaceMap[Index].BaseAddress, + IoSpaceMap[Index].BaseAddress + IoSpaceMap[Index].Length - 1, + IoSpaceMap[Index].ImageHandle == NULL ? ' ' : '*' + )); + } + DEBUG ((DEBUG_GCD, "\n")); + FreePool (IoSpaceMap); + ); +} + + /** Acquire memory lock on mGcdMemorySpaceLock. @@ -571,11 +688,10 @@ CoreConvertSpace ( EFI_GCD_MAP_ENTRY *BottomEntry; LIST_ENTRY *StartLink; LIST_ENTRY *EndLink; - - EFI_CPU_ARCH_PROTOCOL *CpuArch; - UINT64 CpuArchAttributes; + UINT64 CpuArchAttributes; if (Length == 0) { + DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER)); return EFI_INVALID_PARAMETER; } @@ -599,6 +715,7 @@ CoreConvertSpace ( goto Done; } + ASSERT (StartLink != NULL && EndLink != NULL); // // Verify that the list of descriptors are unallocated non-existent memory. @@ -684,30 +801,26 @@ CoreConvertSpace ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + ASSERT (TopEntry != NULL && BottomEntry != NULL); if (Operation == GCD_SET_ATTRIBUTES_MEMORY_OPERATION) { // // Call CPU Arch Protocol to attempt to set attributes on the range // CpuArchAttributes = ConverToCpuArchAttributes (Attributes); - if ( CpuArchAttributes != INVALID_CPU_ARCH_ATTRIBUTES ) { - Status = CoreLocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&CpuArch); - if (EFI_ERROR (Status)) { - Status = EFI_ACCESS_DENIED; - goto Done; - } - - Status = CpuArch->SetMemoryAttributes ( - CpuArch, - BaseAddress, - Length, - CpuArchAttributes - ); - if (EFI_ERROR (Status)) { - goto Done; + if (CpuArchAttributes != INVALID_CPU_ARCH_ATTRIBUTES) { + if (gCpu != NULL) { + Status = gCpu->SetMemoryAttributes ( + gCpu, + BaseAddress, + Length, + CpuArchAttributes + ); + if (EFI_ERROR (Status)) { + goto Done; + } } } - } // @@ -766,11 +879,15 @@ CoreConvertSpace ( Status = CoreCleanupGcdMapEntry (TopEntry, BottomEntry, StartLink, EndLink, Map); Done: + DEBUG ((DEBUG_GCD, " Status = %r\n", Status)); + if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) { CoreReleaseGcdMemoryLock (); + CoreDumpGcdMemorySpaceMap (FALSE); } if ((Operation & GCD_IO_SPACE_OPERATION) != 0) { CoreReleaseGcdIoLock (); + CoreDumpGcdIoSpaceMap (FALSE); } return Status; @@ -869,24 +986,31 @@ CoreAllocateSpace ( // Make sure parameters are valid // if (GcdAllocateType < 0 || GcdAllocateType >= EfiGcdMaxAllocateType) { + DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER)); return EFI_INVALID_PARAMETER; } if (GcdMemoryType < 0 || GcdMemoryType >= EfiGcdMemoryTypeMaximum) { + DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER)); return EFI_INVALID_PARAMETER; } if (GcdIoType < 0 || GcdIoType >= EfiGcdIoTypeMaximum) { + DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER)); return EFI_INVALID_PARAMETER; } if (BaseAddress == NULL) { + DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER)); return EFI_INVALID_PARAMETER; } if (ImageHandle == NULL) { + DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER)); return EFI_INVALID_PARAMETER; } if (Alignment >= 64) { + DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_NOT_FOUND)); return EFI_NOT_FOUND; } if (Length == 0) { + DEBUG ((DEBUG_GCD, " Status = %r\n", EFI_INVALID_PARAMETER)); return EFI_INVALID_PARAMETER; } @@ -926,6 +1050,7 @@ CoreAllocateSpace ( Status = EFI_NOT_FOUND; goto Done; } + ASSERT (StartLink != NULL && EndLink != NULL); // // Verify that the list of descriptors are unallocated memory matching GcdMemoryType. @@ -1009,6 +1134,7 @@ CoreAllocateSpace ( Status = EFI_NOT_FOUND; goto Done; } + ASSERT (StartLink != NULL && EndLink != NULL); Link = StartLink; // @@ -1044,6 +1170,7 @@ CoreAllocateSpace ( Status = EFI_OUT_OF_RESOURCES; goto Done; } + ASSERT (TopEntry != NULL && BottomEntry != NULL); // // Convert/Insert the list of descriptors from StartLink to EndLink @@ -1063,11 +1190,19 @@ CoreAllocateSpace ( Status = CoreCleanupGcdMapEntry (TopEntry, BottomEntry, StartLink, EndLink, Map); Done: + DEBUG ((DEBUG_GCD, " Status = %r", Status)); + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_GCD, " (BaseAddress = %016lx)", *BaseAddress)); + } + DEBUG ((DEBUG_GCD, "\n")); + if ((Operation & GCD_MEMORY_SPACE_OPERATION) != 0) { CoreReleaseGcdMemoryLock (); + CoreDumpGcdMemorySpaceMap (FALSE); } if ((Operation & GCD_IO_SPACE_OPERATION) !=0) { CoreReleaseGcdIoLock (); + CoreDumpGcdIoSpaceMap (FALSE); } return Status; @@ -1094,6 +1229,10 @@ CoreInternalAddMemorySpace ( IN UINT64 Capabilities ) { + DEBUG ((DEBUG_GCD, "GCD:AddMemorySpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length)); + DEBUG ((DEBUG_GCD, " GcdMemoryType = %a\n", mGcdMemoryTypeNames[MIN (GcdMemoryType, EfiGcdMemoryTypeMaximum)])); + DEBUG ((DEBUG_GCD, " Capabilities = %016lx\n", Capabilities)); + // // Make sure parameters are valid // @@ -1137,6 +1276,13 @@ CoreAllocateMemorySpace ( IN EFI_HANDLE DeviceHandle OPTIONAL ) { + DEBUG ((DEBUG_GCD, "GCD:AllocateMemorySpace(Base=%016lx,Length=%016lx)\n", *BaseAddress, Length)); + DEBUG ((DEBUG_GCD, " GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)])); + DEBUG ((DEBUG_GCD, " GcdMemoryType = %a\n", mGcdMemoryTypeNames[MIN (GcdMemoryType, EfiGcdMemoryTypeMaximum)])); + DEBUG ((DEBUG_GCD, " Alignment = %016lx\n", LShiftU64 (1, Alignment))); + DEBUG ((DEBUG_GCD, " ImageHandle = %p\n", ImageHandle)); + DEBUG ((DEBUG_GCD, " DeviceHandle = %p\n", DeviceHandle)); + return CoreAllocateSpace ( GCD_ALLOCATE_MEMORY_OPERATION, GcdAllocateType, @@ -1244,6 +1390,8 @@ CoreFreeMemorySpace ( IN UINT64 Length ) { + DEBUG ((DEBUG_GCD, "GCD:FreeMemorySpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length)); + return CoreConvertSpace (GCD_FREE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0); } @@ -1265,6 +1413,8 @@ CoreRemoveMemorySpace ( IN UINT64 Length ) { + DEBUG ((DEBUG_GCD, "GCD:RemoveMemorySpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length)); + return CoreConvertSpace (GCD_REMOVE_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0); } @@ -1330,6 +1480,7 @@ CoreGetMemorySpaceDescriptor ( if (EFI_ERROR (Status)) { Status = EFI_NOT_FOUND; } else { + ASSERT (StartLink != NULL && EndLink != NULL); // // Copy the contents of the found descriptor into Descriptor // @@ -1363,6 +1514,9 @@ CoreSetMemorySpaceAttributes ( IN UINT64 Attributes ) { + DEBUG ((DEBUG_GCD, "GCD:SetMemorySpaceAttributes(Base=%016lx,Length=%016lx)\n", BaseAddress, Length)); + DEBUG ((DEBUG_GCD, " Attributes = %016lx\n", Attributes)); + return CoreConvertSpace (GCD_SET_ATTRIBUTES_MEMORY_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, Attributes); } @@ -1455,6 +1609,9 @@ CoreAddIoSpace ( IN UINT64 Length ) { + DEBUG ((DEBUG_GCD, "GCD:AddIoSpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length)); + DEBUG ((DEBUG_GCD, " GcdIoType = %a\n", mGcdIoTypeNames[MIN (GcdIoType, EfiGcdIoTypeMaximum)])); + // // Make sure parameters are valid // @@ -1494,6 +1651,13 @@ CoreAllocateIoSpace ( IN EFI_HANDLE DeviceHandle OPTIONAL ) { + DEBUG ((DEBUG_GCD, "GCD:AllocateIoSpace(Base=%016lx,Length=%016lx)\n", *BaseAddress, Length)); + DEBUG ((DEBUG_GCD, " GcdAllocateType = %a\n", mGcdAllocationTypeNames[MIN (GcdAllocateType, EfiGcdMaxAllocateType)])); + DEBUG ((DEBUG_GCD, " GcdIoType = %a\n", mGcdIoTypeNames[MIN (GcdIoType, EfiGcdIoTypeMaximum)])); + DEBUG ((DEBUG_GCD, " Alignment = %016lx\n", LShiftU64 (1, Alignment))); + DEBUG ((DEBUG_GCD, " ImageHandle = %p\n", ImageHandle)); + DEBUG ((DEBUG_GCD, " DeviceHandle = %p\n", DeviceHandle)); + return CoreAllocateSpace ( GCD_ALLOCATE_IO_OPERATION, GcdAllocateType, @@ -1525,6 +1689,8 @@ CoreFreeIoSpace ( IN UINT64 Length ) { + DEBUG ((DEBUG_GCD, "GCD:FreeIoSpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length)); + return CoreConvertSpace (GCD_FREE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0); } @@ -1546,6 +1712,8 @@ CoreRemoveIoSpace ( IN UINT64 Length ) { + DEBUG ((DEBUG_GCD, "GCD:RemoveIoSpace(Base=%016lx,Length=%016lx)\n", BaseAddress, Length)); + return CoreConvertSpace (GCD_REMOVE_IO_OPERATION, (EFI_GCD_MEMORY_TYPE) 0, (EFI_GCD_IO_TYPE) 0, BaseAddress, Length, 0, 0); } @@ -1609,6 +1777,7 @@ CoreGetIoSpaceDescriptor ( if (EFI_ERROR (Status)) { Status = EFI_NOT_FOUND; } else { + ASSERT (StartLink != NULL && EndLink != NULL); // // Copy the contents of the found descriptor into Descriptor // @@ -2013,6 +2182,8 @@ CoreInitializeGcdServices ( InsertHeadList (&mGcdMemorySpaceMap, &Entry->Link); + CoreDumpGcdMemorySpaceMap (TRUE); + // // Initialize the GCD I/O Space Map // @@ -2023,6 +2194,8 @@ CoreInitializeGcdServices ( InsertHeadList (&mGcdIoSpaceMap, &Entry->Link); + CoreDumpGcdIoSpaceMap (TRUE); + // // Walk the HOB list and add all resource descriptors to the GCD //