X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FPciBusDxe%2FPciResourceSupport.c;h=70e45040e2efb2777f3386c59f0a620e06302d91;hp=b0632d53b82b9ffba96cc3161b2430040b8d19cc;hb=0fa92d5839cddeb63a7e4583fdbca49b16599e3a;hpb=05070c1b471b0d2af759f582e3c305859cd36b23 diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c index b0632d53b8..70e45040e2 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. + PCI resources support functions implementation for PCI Bus module. -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2019, 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 @@ -134,11 +134,11 @@ InsertResourceNode ( /** This routine is used to merge two different resource trees in need of - resoure degradation. + resource degradation. For example, if an upstream PPB doesn't support, prefetchable memory decoding, the PCI bus driver will choose to call this function - to merge prefectchable memory resource list into normal memory list. + to merge prefetchable memory resource list into normal memory list. If the TypeMerge is TRUE, Res resource type is changed to the type of destination resource type. @@ -335,7 +335,7 @@ CalculateApertureIo16 ( This function is used to calculate the resource aperture for a given bridge device. - @param Bridge PCI resouce node for given bridge device. + @param Bridge PCI resource node for given bridge device. **/ VOID @@ -343,14 +343,9 @@ CalculateResourceAperture ( IN PCI_RESOURCE_NODE *Bridge ) { - UINT64 Aperture; + UINT64 Aperture[2]; LIST_ENTRY *CurrentLink; PCI_RESOURCE_NODE *Node; - UINT64 PaddingAperture; - UINT64 Offset; - - Aperture = 0; - PaddingAperture = 0; if (Bridge == NULL) { return ; @@ -362,6 +357,8 @@ CalculateResourceAperture ( return ; } + Aperture[PciResUsageTypical] = 0; + Aperture[PciResUsagePadding] = 0; // // Assume the bridge is aligned // @@ -369,58 +366,42 @@ CalculateResourceAperture ( ; !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 + // It's possible for a bridge to contain multiple padding resource + // nodes due to DegradeResource(). // - Offset = Aperture & (Node->Alignment); - - if (Offset != 0) { - - Aperture = Aperture + (Node->Alignment + 1) - Offset; - - } - + ASSERT ((Node->ResourceUsage == PciResUsageTypical) || + (Node->ResourceUsage == PciResUsagePadding)); + ASSERT (Node->ResourceUsage < ARRAY_SIZE (Aperture)); // // Recode current aperture as a offset - // this offset will be used in future real allocation + // Apply padding resource to meet alignment requirement + // Node offset will be used in future real allocation // - Node->Offset = Aperture; + Node->Offset = ALIGN_VALUE (Aperture[Node->ResourceUsage], Node->Alignment + 1); // - // Increment aperture by the length of node + // Record the total aperture. // - Aperture += Node->Length; + Aperture[Node->ResourceUsage] = Node->Offset + Node->Length; } // - // At last, adjust the aperture with the bridge's - // alignment + // Adjust the aperture with the bridge's alignment // - Offset = Aperture & (Bridge->Alignment); - if (Offset != 0) { - Aperture = Aperture + (Bridge->Alignment + 1) - Offset; - } + Aperture[PciResUsageTypical] = ALIGN_VALUE (Aperture[PciResUsageTypical], Bridge->Alignment + 1); + Aperture[PciResUsagePadding] = ALIGN_VALUE (Aperture[PciResUsagePadding], Bridge->Alignment + 1); // - // If the bridge has already padded the resource and the - // amount of padded resource is larger, then keep the - // padded resource + // Hotplug controller needs padding resources. + // Use the larger one between the padding resource and actual occupied resource. // - if (Bridge->Length < Aperture) { - Bridge->Length = Aperture; - } + Bridge->Length = MAX (Aperture[PciResUsageTypical], Aperture[PciResUsagePadding]); // - // Adjust the bridge's alignment to the first child's alignment - // if the bridge has at least one child + // Adjust the bridge's alignment to the MAX (first) alignment of all children. // CurrentLink = Bridge->ChildList.ForwardLink; if (CurrentLink != &Bridge->ChildList) { @@ -429,16 +410,10 @@ 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); } /** - Get IO/Memory resource infor for given PCI device. + Get IO/Memory resource info for given PCI device. @param PciDev Pci device instance. @param IoNode Resource info node for IO . @@ -471,13 +446,14 @@ GetResourceFromDevice ( switch ((PciDev->PciBar)[Index].BarType) { case PciBarTypeMem32: + case PciBarTypeOpRom: Node = CreateResourceNode ( PciDev, (PciDev->PciBar)[Index].Length, (PciDev->PciBar)[Index].Alignment, Index, - PciBarTypeMem32, + (PciDev->PciBar)[Index].BarType, PciResUsageTypical ); @@ -856,7 +832,7 @@ CreateResourceMap ( ); // - // Recursively create resouce map on this bridge + // Recursively create resource map on this bridge // CreateResourceMap ( Temp, @@ -1058,48 +1034,50 @@ DegradeResource ( LIST_ENTRY *NextChildNodeLink; 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) { - 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); + 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) { - 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); + 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; } // @@ -1139,7 +1117,7 @@ DegradeResource ( PMem64Node, TRUE ); - } + } // // if both PMEM64 and PMEM32 requests from child devices, which can not be satisfied @@ -1217,10 +1195,10 @@ BridgeSupportResourceDecode ( This function is used to program the resource allocated for each resource node under specified bridge. - @param Base Base address of resource to be progammed. + @param Base Base address of resource to be programmed. @param Bridge PCI resource node for the bridge device. - @retval EFI_SUCCESS Successfully to program all resouces + @retval EFI_SUCCESS Successfully to program all resources on given PCI bridge device. @retval EFI_OUT_OF_RESOURCES Base is all one. @@ -1279,8 +1257,8 @@ ProgramResource ( /** Program Bar register for PCI device. - @param Base Base address for PCI device resource to be progammed. - @param Node Point to resoure node structure. + @param Base Base address for PCI device resource to be programmed. + @param Node Point to resource node structure. **/ VOID @@ -1330,7 +1308,13 @@ ProgramBar ( 1, &Address ); + // + // Continue to the case PciBarTypeOpRom to set the BaseAddress. + // PciBarTypeOpRom is a virtual BAR only in root bridge, to capture + // the MEM32 resource requirement for Option ROM shadow. + // + case PciBarTypeOpRom: Node->PciDev->PciBar[Node->Bar].BaseAddress = Address; break; @@ -1370,8 +1354,8 @@ ProgramBar ( /** Program IOV VF Bar register for PCI device. - @param Base Base address for PCI device resource to be progammed. - @param Node Point to resoure node structure. + @param Base Base address for PCI device resource to be programmed. + @param Node Point to resource node structure. **/ EFI_STATUS @@ -1454,10 +1438,10 @@ ProgramVfBar ( } /** - Program PCI-PCI bridge apperture. + Program PCI-PCI bridge aperture. @param Base Base address for resource. - @param Node Point to resoure node structure. + @param Node Point to resource node structure. **/ VOID @@ -1473,7 +1457,7 @@ ProgramPpbApperture ( Address = 0; // // If no device resource of this PPB, return anyway - // Apperture is set default in the initialization code + // Aperture is set default in the initialization code // if (Node->Length == 0 || Node->ResourceUsage == PciResUsagePadding) { // @@ -1665,45 +1649,64 @@ ProgramPpbApperture ( /** Program parent bridge for Option Rom. - @param PciDevice Pci deivce instance. - @param OptionRomBase Base address for Optiona Rom. + @param PciDevice Pci device instance. + @param OptionRomBase Base address for Option Rom. @param Enable Enable or disable PCI memory. **/ VOID -ProgrameUpstreamBridgeForRom ( +ProgramUpstreamBridgeForRom ( IN PCI_IO_DEVICE *PciDevice, IN UINT32 OptionRomBase, IN BOOLEAN Enable ) { - PCI_IO_DEVICE *Parent; - PCI_RESOURCE_NODE Node; + PCI_IO_DEVICE *Parent; + EFI_PCI_IO_PROTOCOL *PciIo; + UINT16 Base; + UINT16 Limit; // // For root bridge, just return. // Parent = PciDevice->Parent; - ZeroMem (&Node, sizeof (Node)); while (Parent != NULL) { if (!IS_PCI_BRIDGE (&Parent->Pci)) { break; } - Node.PciDev = Parent; - Node.Length = PciDevice->RomSize; - Node.Alignment = 0; - Node.Bar = PPB_MEM32_RANGE; - Node.ResType = PciBarTypeMem32; - Node.Offset = 0; + PciIo = &Parent->PciIo; // - // Program PPB to only open a single <= 16MB apperture + // Program PPB to only open a single <= 16MB aperture // if (Enable) { - ProgramPpbApperture (OptionRomBase, &Node); + // + // Only cover MMIO for Option ROM. + // + Base = (UINT16) (OptionRomBase >> 16); + Limit = (UINT16) ((OptionRomBase + PciDevice->RomSize - 1) >> 16); + PciIo->Pci.Write (PciIo, EfiPciIoWidthUint16, OFFSET_OF (PCI_TYPE01, Bridge.MemoryBase), 1, &Base); + PciIo->Pci.Write (PciIo, EfiPciIoWidthUint16, OFFSET_OF (PCI_TYPE01, Bridge.MemoryLimit), 1, &Limit); + PCI_ENABLE_COMMAND_REGISTER (Parent, EFI_PCI_COMMAND_MEMORY_SPACE); } else { - InitializePpb (Parent); + // + // Cover 32bit MMIO for devices below the bridge. + // + if (Parent->PciBar[PPB_MEM32_RANGE].Length == 0) { + // + // When devices under the bridge contains Option ROM and doesn't require 32bit MMIO. + // + Base = (UINT16) gAllOne; + Limit = (UINT16) gAllZero; + } else { + Base = (UINT16) ((UINT32) Parent->PciBar[PPB_MEM32_RANGE].BaseAddress >> 16); + Limit = (UINT16) ((UINT32) (Parent->PciBar[PPB_MEM32_RANGE].BaseAddress + + Parent->PciBar[PPB_MEM32_RANGE].Length - 1) >> 16); + } + PciIo->Pci.Write (PciIo, EfiPciIoWidthUint16, OFFSET_OF (PCI_TYPE01, Bridge.MemoryBase), 1, &Base); + PciIo->Pci.Write (PciIo, EfiPciIoWidthUint16, OFFSET_OF (PCI_TYPE01, Bridge.MemoryLimit), 1, &Limit); + PCI_DISABLE_COMMAND_REGISTER (Parent, EFI_PCI_COMMAND_MEMORY_SPACE); } @@ -1755,7 +1758,7 @@ InitializeResourcePool ( } /** - Destory given resource tree. + Destroy given resource tree. @param Bridge PCI resource root node of resource tree. @@ -1812,7 +1815,7 @@ ResourcePaddingForCardBusBridge ( // // Memory Base/Limit Register 0 - // Bar 1 denodes memory range 0 + // Bar 1 decodes memory range 0 // Node = CreateResourceNode ( PciDev, @@ -1830,7 +1833,7 @@ ResourcePaddingForCardBusBridge ( // // Memory Base/Limit Register 1 - // Bar 2 denodes memory range1 + // Bar 2 decodes memory range1 // Node = CreateResourceNode ( PciDev, @@ -1848,7 +1851,7 @@ ResourcePaddingForCardBusBridge ( // // Io Base/Limit - // Bar 3 denodes io range 0 + // Bar 3 decodes io range 0 // Node = CreateResourceNode ( PciDev, @@ -1866,7 +1869,7 @@ ResourcePaddingForCardBusBridge ( // // Io Base/Limit - // Bar 4 denodes io range 0 + // Bar 4 decodes io range 0 // Node = CreateResourceNode ( PciDev, @@ -1970,7 +1973,7 @@ ProgramP2C ( } else { // - // Set pre-fetchable bit + // Set prefetchable bit // PciIo->Pci.Read ( PciIo, @@ -2040,7 +2043,7 @@ ProgramP2C ( } else { // - // Set pre-fetchable bit + // Set prefetchable bit // PciIo->Pci.Read ( PciIo, @@ -2173,7 +2176,7 @@ ApplyResourcePadding ( if (Ptr->AddrSpaceGranularity == 32) { // - // prefechable + // prefetchable // if (Ptr->SpecificFlag == 0x6) { if (Ptr->AddrLen != 0) { @@ -2196,7 +2199,7 @@ ApplyResourcePadding ( } // - // Non-prefechable + // Non-prefetchable // if (Ptr->SpecificFlag == 0) { if (Ptr->AddrLen != 0) { @@ -2222,7 +2225,7 @@ ApplyResourcePadding ( if (Ptr->AddrSpaceGranularity == 64) { // - // prefechable + // prefetchable // if (Ptr->SpecificFlag == 0x6) { if (Ptr->AddrLen != 0) { @@ -2245,7 +2248,7 @@ ApplyResourcePadding ( } // - // Non-prefechable + // Non-prefetchable // if (Ptr->SpecificFlag == 0) { if (Ptr->AddrLen != 0) {