X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FPciBusDxe%2FPciResourceSupport.c;h=e93134613b488aad1b8c4fa5069500760769d562;hp=cca365370faf9a9ffaa727e0316b08e9f011b7f5;hb=065ae7d717f9e49c3be12dada109d60dead0bb90;hpb=05399810c5c015c3d83381518989dac238c5d55a diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c index cca365370f..e93134613b 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c @@ -1,7 +1,7 @@ /** @file PCI resouces support functions implemntation for PCI Bus module. -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, 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 @@ -14,6 +14,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "PciBus.h" +// +// The default policy for the PCI bus driver is NOT to reserve I/O ranges for both ISA aliases and VGA aliases. +// +BOOLEAN mReserveIsaAliases = FALSE; +BOOLEAN mReserveVgaAliases = FALSE; +BOOLEAN mPolicyDetermined = FALSE; + /** The function is used to skip VGA range. @@ -188,63 +195,61 @@ CalculateApertureIo16 ( LIST_ENTRY *CurrentLink; PCI_RESOURCE_NODE *Node; UINT64 Offset; - BOOLEAN IsaEnable; - BOOLEAN VGAEnable; EFI_PCI_PLATFORM_POLICY PciPolicy; + UINT64 PaddingAperture; - // - // Always assume there is ISA device and VGA device on the platform - // will be customized later - // - IsaEnable = FALSE; - VGAEnable = FALSE; + if (!mPolicyDetermined) { + // + // Check PciPlatform policy + // + Status = EFI_NOT_FOUND; + PciPolicy = 0; + if (gPciPlatformProtocol != NULL) { + Status = gPciPlatformProtocol->GetPlatformPolicy ( + gPciPlatformProtocol, + &PciPolicy + ); + } - // - // Check PciPlatform policy - // - if (gPciPlatformProtocol != NULL) { - Status = gPciPlatformProtocol->GetPlatformPolicy ( - gPciPlatformProtocol, - &PciPolicy - ); - if (!EFI_ERROR (Status)) { - if ((PciPolicy & EFI_RESERVE_ISA_IO_ALIAS) != 0) { - IsaEnable = TRUE; - } - if ((PciPolicy & EFI_RESERVE_VGA_IO_ALIAS) != 0) { - VGAEnable = TRUE; - } + if (EFI_ERROR (Status) && gPciOverrideProtocol != NULL) { + Status = gPciOverrideProtocol->GetPlatformPolicy ( + gPciOverrideProtocol, + &PciPolicy + ); } - } else if (gPciOverrideProtocol != NULL) { - Status = gPciOverrideProtocol->GetPlatformPolicy ( - gPciOverrideProtocol, - &PciPolicy - ); + if (!EFI_ERROR (Status)) { if ((PciPolicy & EFI_RESERVE_ISA_IO_ALIAS) != 0) { - IsaEnable = TRUE; + mReserveIsaAliases = TRUE; } if ((PciPolicy & EFI_RESERVE_VGA_IO_ALIAS) != 0) { - VGAEnable = TRUE; + mReserveVgaAliases = TRUE; } } + mPolicyDetermined = TRUE; } - Aperture = 0; + Aperture = 0; + PaddingAperture = 0; if (Bridge == NULL) { return ; } - CurrentLink = Bridge->ChildList.ForwardLink; - // // Assume the bridge is aligned // - while (CurrentLink != &Bridge->ChildList) { + for ( CurrentLink = GetFirstNode (&Bridge->ChildList) + ; !IsNull (&Bridge->ChildList, CurrentLink) + ; CurrentLink = GetNextNode (&Bridge->ChildList, CurrentLink) + ) { Node = RESOURCE_NODE_FROM_LINK (CurrentLink); - + if (Node->ResourceUsage == PciResUsagePadding) { + ASSERT (PaddingAperture == 0); + PaddingAperture = Node->Length; + continue; + } // // Consider the aperture alignment // @@ -261,13 +266,13 @@ CalculateApertureIo16 ( // If both of them are enabled, then the IO resource would // become too limited to meet the requirement of most of devices. // - if (IsaEnable || VGAEnable) { + if (mReserveIsaAliases || mReserveVgaAliases) { if (!IS_PCI_BRIDGE (&(Node->PciDev->Pci)) && !IS_CARDBUS_BRIDGE (&(Node->PciDev->Pci))) { // // Check if there is need to support ISA/VGA decoding // If so, we need to avoid isa/vga aliasing range // - if (IsaEnable) { + if (mReserveIsaAliases) { SkipIsaAliasAperture ( &Aperture, Node->Length @@ -276,7 +281,7 @@ CalculateApertureIo16 ( if (Offset != 0) { Aperture = Aperture + (Node->Alignment + 1) - Offset; } - } else if (VGAEnable) { + } else if (mReserveVgaAliases) { SkipVGAAperture ( &Aperture, Node->Length @@ -295,13 +300,10 @@ CalculateApertureIo16 ( // Increment aperture by the length of node // Aperture += Node->Length; - - CurrentLink = CurrentLink->ForwardLink; } // - // At last, adjust the aperture with the bridge's - // alignment + // Adjust the aperture with the bridge's alignment // Offset = Aperture & (Bridge->Alignment); @@ -321,6 +323,12 @@ CalculateApertureIo16 ( Bridge->Alignment = Node->Alignment; } } + + // + // Hotplug controller needs padding resources. + // Use the larger one between the padding resource and actual occupied resource. + // + Bridge->Length = MAX (Bridge->Length, PaddingAperture); } /** @@ -338,10 +346,11 @@ CalculateResourceAperture ( UINT64 Aperture; LIST_ENTRY *CurrentLink; PCI_RESOURCE_NODE *Node; - + UINT64 PaddingAperture; UINT64 Offset; - Aperture = 0; + Aperture = 0; + PaddingAperture = 0; if (Bridge == NULL) { return ; @@ -353,14 +362,20 @@ CalculateResourceAperture ( return ; } - CurrentLink = Bridge->ChildList.ForwardLink; - // // Assume the bridge is aligned // - while (CurrentLink != &Bridge->ChildList) { + for ( CurrentLink = GetFirstNode (&Bridge->ChildList) + ; !IsNull (&Bridge->ChildList, CurrentLink) + ; CurrentLink = GetNextNode (&Bridge->ChildList, CurrentLink) + ) { Node = RESOURCE_NODE_FROM_LINK (CurrentLink); + if (Node->ResourceUsage == PciResUsagePadding) { + ASSERT (PaddingAperture == 0); + PaddingAperture = Node->Length; + continue; + } // // Apply padding resource if available @@ -383,11 +398,6 @@ CalculateResourceAperture ( // Increment aperture by the length of node // Aperture += Node->Length; - - // - // Consider the aperture alignment - // - CurrentLink = CurrentLink->ForwardLink; } // @@ -409,7 +419,7 @@ CalculateResourceAperture ( } // - // At last, adjust the bridge's alignment to the first child's alignment + // Adjust the bridge's alignment to the first child's alignment // if the bridge has at least one child // CurrentLink = Bridge->ChildList.ForwardLink; @@ -419,6 +429,12 @@ CalculateResourceAperture ( Bridge->Alignment = Node->Alignment; } } + + // + // Hotplug controller needs padding resources. + // Use the larger one between the padding resource and actual occupied resource. + // + Bridge->Length = MAX (Bridge->Length, PaddingAperture); } /** @@ -726,17 +742,6 @@ CreateVfResourceNode ( { PCI_RESOURCE_NODE *Node; - DEBUG (( - EFI_D_INFO, - "PCI-IOV B%x.D%x.F%x - VfResource (Bar - 0x%x) (Type - 0x%x) (Length - 0x%x)\n", - (UINTN)PciDev->BusNumber, - (UINTN)PciDev->DeviceNumber, - (UINTN)PciDev->FunctionNumber, - (UINTN)Bar, - (UINTN)ResType, - (UINTN)Length - )); - Node = CreateResourceNode (PciDev, Length, Alignment, Bar, ResType, ResUsage); if (Node == NULL) { return Node; @@ -1047,50 +1052,56 @@ DegradeResource ( IN PCI_RESOURCE_NODE *PMem64Node ) { - PCI_IO_DEVICE *Temp; + PCI_IO_DEVICE *PciIoDevice; LIST_ENTRY *ChildDeviceLink; LIST_ENTRY *ChildNodeLink; LIST_ENTRY *NextChildNodeLink; - PCI_RESOURCE_NODE *TempNode; + PCI_RESOURCE_NODE *ResourceNode; - // - // If any child device has both option ROM and 64-bit BAR, degrade its PMEM64/MEM64 - // requests in case that if a legacy option ROM image can not access 64-bit resources. - // - ChildDeviceLink = Bridge->ChildList.ForwardLink; - while (ChildDeviceLink != NULL && ChildDeviceLink != &Bridge->ChildList) { - Temp = PCI_IO_DEVICE_FROM_LINK (ChildDeviceLink); - if (Temp->RomSize != 0) { - if (!IsListEmpty (&Mem64Node->ChildList)) { - ChildNodeLink = Mem64Node->ChildList.ForwardLink; - while (ChildNodeLink != &Mem64Node->ChildList) { - TempNode = RESOURCE_NODE_FROM_LINK (ChildNodeLink); - NextChildNodeLink = ChildNodeLink->ForwardLink; - - if (TempNode->PciDev == Temp) { - RemoveEntryList (ChildNodeLink); - InsertResourceNode (Mem32Node, TempNode); + if (FeaturePcdGet (PcdPciDegradeResourceForOptionRom)) { + // + // If any child device has both option ROM and 64-bit BAR, degrade its PMEM64/MEM64 + // requests in case that if a legacy option ROM image can not access 64-bit resources. + // + ChildDeviceLink = Bridge->ChildList.ForwardLink; + while (ChildDeviceLink != NULL && ChildDeviceLink != &Bridge->ChildList) { + PciIoDevice = PCI_IO_DEVICE_FROM_LINK (ChildDeviceLink); + if (PciIoDevice->RomSize != 0) { + if (!IsListEmpty (&Mem64Node->ChildList)) { + ChildNodeLink = Mem64Node->ChildList.ForwardLink; + while (ChildNodeLink != &Mem64Node->ChildList) { + ResourceNode = RESOURCE_NODE_FROM_LINK (ChildNodeLink); + NextChildNodeLink = ChildNodeLink->ForwardLink; + + if ((ResourceNode->PciDev == PciIoDevice) && + (ResourceNode->Virtual || !PciIoDevice->PciBar[ResourceNode->Bar].BarTypeFixed) + ) { + RemoveEntryList (ChildNodeLink); + InsertResourceNode (Mem32Node, ResourceNode); + } + ChildNodeLink = NextChildNodeLink; } - ChildNodeLink = NextChildNodeLink; - } - } - - if (!IsListEmpty (&PMem64Node->ChildList)) { - ChildNodeLink = PMem64Node->ChildList.ForwardLink; - while (ChildNodeLink != &PMem64Node->ChildList) { - TempNode = RESOURCE_NODE_FROM_LINK (ChildNodeLink); - NextChildNodeLink = ChildNodeLink->ForwardLink; + } - if (TempNode->PciDev == Temp) { - RemoveEntryList (ChildNodeLink); - InsertResourceNode (PMem32Node, TempNode); + if (!IsListEmpty (&PMem64Node->ChildList)) { + ChildNodeLink = PMem64Node->ChildList.ForwardLink; + while (ChildNodeLink != &PMem64Node->ChildList) { + ResourceNode = RESOURCE_NODE_FROM_LINK (ChildNodeLink); + NextChildNodeLink = ChildNodeLink->ForwardLink; + + if ((ResourceNode->PciDev == PciIoDevice) && + (ResourceNode->Virtual || !PciIoDevice->PciBar[ResourceNode->Bar].BarTypeFixed) + ) { + RemoveEntryList (ChildNodeLink); + InsertResourceNode (PMem32Node, ResourceNode); + } + ChildNodeLink = NextChildNodeLink; } - ChildNodeLink = NextChildNodeLink; - } - } + } + } + ChildDeviceLink = ChildDeviceLink->ForwardLink; } - ChildDeviceLink = ChildDeviceLink->ForwardLink; } // @@ -1405,17 +1416,6 @@ ProgramVfBar ( ); Node->PciDev->VfPciBar[Node->Bar].BaseAddress = Address; - - DEBUG (( - EFI_D_INFO, - "PCI-IOV B%x.D%x.F%x - VF Bar (Offset - 0x%x) 32Mem (Address - 0x%x)\n", - (UINTN)Node->PciDev->BusNumber, - (UINTN)Node->PciDev->DeviceNumber, - (UINTN)Node->PciDev->FunctionNumber, - (UINTN)(Node->PciDev->VfPciBar[Node->Bar]).Offset, - (UINTN)Address - )); - break; case PciBarTypeMem64: @@ -1442,17 +1442,6 @@ ProgramVfBar ( ); Node->PciDev->VfPciBar[Node->Bar].BaseAddress = Address; - - DEBUG (( - EFI_D_INFO, - "PCI-IOV B%x.D%x.F%x - VF Bar (Offset - 0x%x) 64Mem (Address - 0x%lx)\n", - (UINTN)Node->PciDev->BusNumber, - (UINTN)Node->PciDev->DeviceNumber, - (UINTN)Node->PciDev->FunctionNumber, - (UINTN)(Node->PciDev->VfPciBar[Node->Bar]).Offset, - (UINT64)Address - )); - break; case PciBarTypeIo16: @@ -1507,7 +1496,14 @@ ProgramPpbApperture ( case PPB_BAR_0: case PPB_BAR_1: - PciIo->Pci.Write ( + switch ((Node->PciDev->PciBar[Node->Bar]).BarType) { + + case PciBarTypeIo16: + case PciBarTypeIo32: + case PciBarTypeMem32: + case PciBarTypePMem32: + + PciIo->Pci.Write ( PciIo, EfiPciIoWidthUint32, (Node->PciDev->PciBar[Node->Bar]).Offset, @@ -1515,9 +1511,40 @@ ProgramPpbApperture ( &Address ); - Node->PciDev->PciBar[Node->Bar].BaseAddress = Address; - Node->PciDev->PciBar[Node->Bar].Length = Node->Length; + Node->PciDev->PciBar[Node->Bar].BaseAddress = Address; + Node->PciDev->PciBar[Node->Bar].Length = Node->Length; + break; + + case PciBarTypeMem64: + case PciBarTypePMem64: + + Address32 = (UINT32) (Address & 0x00000000FFFFFFFF); + PciIo->Pci.Write ( + PciIo, + EfiPciIoWidthUint32, + (Node->PciDev->PciBar[Node->Bar]).Offset, + 1, + &Address32 + ); + + Address32 = (UINT32) RShiftU64 (Address, 32); + + PciIo->Pci.Write ( + PciIo, + EfiPciIoWidthUint32, + (UINT8) ((Node->PciDev->PciBar[Node->Bar]).Offset + 4), + 1, + &Address32 + ); + + Node->PciDev->PciBar[Node->Bar].BaseAddress = Address; + Node->PciDev->PciBar[Node->Bar].Length = Node->Length; + break; + + default: + break; + } break; case PPB_IO_RANGE: @@ -1729,123 +1756,6 @@ InitializeResourcePool ( InitializeListHead (&ResourcePool->ChildList); } - -/** - Get all resource information for given Pci device. - - @param PciDev Pci device instance. - @param IoBridge Io resource node. - @param Mem32Bridge 32-bit memory node. - @param PMem32Bridge 32-bit Pmemory node. - @param Mem64Bridge 64-bit memory node. - @param PMem64Bridge 64-bit PMemory node. - @param IoPool Link list header for Io resource. - @param Mem32Pool Link list header for 32-bit memory. - @param PMem32Pool Link list header for 32-bit Prefetchable memory. - @param Mem64Pool Link list header for 64-bit memory. - @param PMem64Pool Link list header for 64-bit Prefetchable memory. - -**/ -VOID -GetResourceMap ( - IN PCI_IO_DEVICE *PciDev, - IN PCI_RESOURCE_NODE **IoBridge, - IN PCI_RESOURCE_NODE **Mem32Bridge, - IN PCI_RESOURCE_NODE **PMem32Bridge, - IN PCI_RESOURCE_NODE **Mem64Bridge, - IN PCI_RESOURCE_NODE **PMem64Bridge, - IN PCI_RESOURCE_NODE *IoPool, - IN PCI_RESOURCE_NODE *Mem32Pool, - IN PCI_RESOURCE_NODE *PMem32Pool, - IN PCI_RESOURCE_NODE *Mem64Pool, - IN PCI_RESOURCE_NODE *PMem64Pool - ) -{ - - PCI_RESOURCE_NODE *Temp; - LIST_ENTRY *CurrentLink; - - CurrentLink = IoPool->ChildList.ForwardLink; - - // - // Get Io resource map - // - while (CurrentLink != &IoPool->ChildList) { - - Temp = RESOURCE_NODE_FROM_LINK (CurrentLink); - - if (Temp->PciDev == PciDev) { - *IoBridge = Temp; - } - - CurrentLink = CurrentLink->ForwardLink; - } - - // - // Get Mem32 resource map - // - CurrentLink = Mem32Pool->ChildList.ForwardLink; - - while (CurrentLink != &Mem32Pool->ChildList) { - - Temp = RESOURCE_NODE_FROM_LINK (CurrentLink); - - if (Temp->PciDev == PciDev) { - *Mem32Bridge = Temp; - } - - CurrentLink = CurrentLink->ForwardLink; - } - - // - // Get Pmem32 resource map - // - CurrentLink = PMem32Pool->ChildList.ForwardLink; - - while (CurrentLink != &PMem32Pool->ChildList) { - - Temp = RESOURCE_NODE_FROM_LINK (CurrentLink); - - if (Temp->PciDev == PciDev) { - *PMem32Bridge = Temp; - } - - CurrentLink = CurrentLink->ForwardLink; - } - - // - // Get Mem64 resource map - // - CurrentLink = Mem64Pool->ChildList.ForwardLink; - - while (CurrentLink != &Mem64Pool->ChildList) { - - Temp = RESOURCE_NODE_FROM_LINK (CurrentLink); - - if (Temp->PciDev == PciDev) { - *Mem64Bridge = Temp; - } - - CurrentLink = CurrentLink->ForwardLink; - } - - // - // Get Pmem64 resource map - // - CurrentLink = PMem64Pool->ChildList.ForwardLink; - - while (CurrentLink != &PMem64Pool->ChildList) { - - Temp = RESOURCE_NODE_FROM_LINK (CurrentLink); - - if (Temp->PciDev == PciDev) { - *PMem64Bridge = Temp; - } - - CurrentLink = CurrentLink->ForwardLink; - } -} - /** Destory given resource tree.