X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FPciBusDxe%2FPciLib.c;h=87ee61956ac92f501c181294b7cde4534fe1ab71;hb=306bbe82cb0bae51db9b4ee0a891fd97660be769;hp=f40000672fc63f4a9200676c6951053ab5cac03a;hpb=9060e3ec6dfd6048724832947933650cde873381;p=mirror_edk2.git diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c index f40000672f..87ee61956a 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c @@ -1,8 +1,8 @@ /** @file Internal library implementation for PCI Bus module. -Copyright (c) 2006 - 2009, 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 @@ -14,6 +14,19 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "PciBus.h" +GLOBAL_REMOVE_IF_UNREFERENCED +CHAR16 *mBarTypeStr[] = { + L"Unknow", + L" Io16", + L" Io32", + L" Mem32", + L"PMem32", + L" Mem64", + L"PMem64", + L" Io", + L" Mem", + L"Unknow" + }; /** Retrieve the PCI Card device BAR information via PciIo interface. @@ -153,6 +166,200 @@ RemoveRejectedPciDevices ( } } +/** + Dump the resourc map of the bridge device. + + @param[in] BridgeResource Resource descriptor of the bridge device. +**/ +VOID +DumpBridgeResource ( + IN PCI_RESOURCE_NODE *BridgeResource + ) +{ + LIST_ENTRY *Link; + PCI_RESOURCE_NODE *Resource; + PCI_BAR *Bar; + + if ((BridgeResource != NULL) && (BridgeResource->Length != 0)) { + DEBUG (( + EFI_D_INFO, "Type = %s; Base = 0x%x;\tLength = 0x%x;\tAlignment = 0x%x\n", + mBarTypeStr[MIN (BridgeResource->ResType, PciBarTypeMaxType)], + BridgeResource->PciDev->PciBar[BridgeResource->Bar].BaseAddress, + BridgeResource->Length, BridgeResource->Alignment + )); + for ( Link = BridgeResource->ChildList.ForwardLink + ; Link != &BridgeResource->ChildList + ; Link = Link->ForwardLink + ) { + Resource = RESOURCE_NODE_FROM_LINK (Link); + if (Resource->ResourceUsage == PciResUsageTypical) { + Bar = Resource->Virtual ? Resource->PciDev->VfPciBar : Resource->PciDev->PciBar; + DEBUG (( + EFI_D_INFO, " Base = 0x%x;\tLength = 0x%x;\tAlignment = 0x%x;\tOwner = %s ", + Bar[Resource->Bar].BaseAddress, Resource->Length, Resource->Alignment, + IS_PCI_BRIDGE (&Resource->PciDev->Pci) ? L"PPB" : + IS_CARDBUS_BRIDGE (&Resource->PciDev->Pci) ? L"P2C" : + L"PCI" + )); + + if ((!IS_PCI_BRIDGE (&Resource->PciDev->Pci) && !IS_CARDBUS_BRIDGE (&Resource->PciDev->Pci)) || + (IS_PCI_BRIDGE (&Resource->PciDev->Pci) && (Resource->Bar < PPB_IO_RANGE)) || + (IS_CARDBUS_BRIDGE (&Resource->PciDev->Pci) && (Resource->Bar < P2C_MEM_1)) + ) { + // + // The resource requirement comes from the device itself. + // + DEBUG (( + EFI_D_INFO, " [%02x|%02x|%02x:%02x]\n", + Resource->PciDev->BusNumber, Resource->PciDev->DeviceNumber, + Resource->PciDev->FunctionNumber, Bar[Resource->Bar].Offset + )); + } else { + // + // The resource requirement comes from the subordinate devices. + // + DEBUG (( + EFI_D_INFO, " [%02x|%02x|%02x:**]\n", + Resource->PciDev->BusNumber, Resource->PciDev->DeviceNumber, + Resource->PciDev->FunctionNumber + )); + } + } else { + DEBUG ((EFI_D_INFO, " Padding:Length = 0x%x;\tAlignment = 0x%x\n", Resource->Length, Resource->Alignment)); + } + } + } +} + +/** + Find the corresponding resource node for the Device in child list of BridgeResource. + + @param[in] Device Pointer to PCI_IO_DEVICE. + @param[in] BridgeResource Pointer to PCI_RESOURCE_NODE. + + @return !NULL The corresponding resource node for the Device. + @return NULL No corresponding resource node for the Device. +**/ +PCI_RESOURCE_NODE * +FindResourceNode ( + IN PCI_IO_DEVICE *Device, + IN PCI_RESOURCE_NODE *BridgeResource + ) +{ + LIST_ENTRY *Link; + PCI_RESOURCE_NODE *Resource; + + for ( Link = BridgeResource->ChildList.ForwardLink + ; Link != &BridgeResource->ChildList + ; Link = Link->ForwardLink + ) { + Resource = RESOURCE_NODE_FROM_LINK (Link); + if (Resource->PciDev == Device) { + return Resource; + } + } + + return NULL; +} + +/** + Dump the resource map of all the devices under Bridge. + + @param[in] Bridge Bridge device instance. + @param[in] IoNode IO resource descriptor for the bridge device. + @param[in] Mem32Node Mem32 resource descriptor for the bridge device. + @param[in] PMem32Node PMem32 resource descriptor for the bridge device. + @param[in] Mem64Node Mem64 resource descriptor for the bridge device. + @param[in] PMem64Node PMem64 resource descriptor for the bridge device. +**/ +VOID +DumpResourceMap ( + IN PCI_IO_DEVICE *Bridge, + IN PCI_RESOURCE_NODE *IoNode, + IN PCI_RESOURCE_NODE *Mem32Node, + IN PCI_RESOURCE_NODE *PMem32Node, + IN PCI_RESOURCE_NODE *Mem64Node, + IN PCI_RESOURCE_NODE *PMem64Node + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Link; + PCI_IO_DEVICE *Device; + PCI_RESOURCE_NODE *ChildIoNode; + PCI_RESOURCE_NODE *ChildMem32Node; + PCI_RESOURCE_NODE *ChildPMem32Node; + PCI_RESOURCE_NODE *ChildMem64Node; + PCI_RESOURCE_NODE *ChildPMem64Node; + EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *ToText; + CHAR16 *Str; + + DEBUG ((EFI_D_INFO, "PciBus: Resource Map for ")); + + Status = gBS->OpenProtocol ( + Bridge->Handle, + &gEfiPciRootBridgeIoProtocolGuid, + NULL, + NULL, + NULL, + EFI_OPEN_PROTOCOL_TEST_PROTOCOL + ); + if (EFI_ERROR (Status)) { + DEBUG (( + EFI_D_INFO, "Bridge [%02x|%02x|%02x]\n", + Bridge->BusNumber, Bridge->DeviceNumber, Bridge->FunctionNumber + )); + } else { + Status = gBS->LocateProtocol ( + &gEfiDevicePathToTextProtocolGuid, + NULL, + (VOID **) &ToText + ); + Str = NULL; + if (!EFI_ERROR (Status)) { + Str = ToText->ConvertDevicePathToText ( + DevicePathFromHandle (Bridge->Handle), + FALSE, + FALSE + ); + } + DEBUG ((EFI_D_INFO, "Root Bridge %s\n", Str != NULL ? Str : L"")); + if (Str != NULL) { + FreePool (Str); + } + } + + DumpBridgeResource (IoNode); + DumpBridgeResource (Mem32Node); + DumpBridgeResource (PMem32Node); + DumpBridgeResource (Mem64Node); + DumpBridgeResource (PMem64Node); + DEBUG ((EFI_D_INFO, "\n")); + + for ( Link = Bridge->ChildList.ForwardLink + ; Link != &Bridge->ChildList + ; Link = Link->ForwardLink + ) { + Device = PCI_IO_DEVICE_FROM_LINK (Link); + if (IS_PCI_BRIDGE (&Device->Pci)) { + + ChildIoNode = (IoNode == NULL ? NULL : FindResourceNode (Device, IoNode)); + ChildMem32Node = (Mem32Node == NULL ? NULL : FindResourceNode (Device, Mem32Node)); + ChildPMem32Node = (PMem32Node == NULL ? NULL : FindResourceNode (Device, PMem32Node)); + ChildMem64Node = (Mem64Node == NULL ? NULL : FindResourceNode (Device, Mem64Node)); + ChildPMem64Node = (PMem64Node == NULL ? NULL : FindResourceNode (Device, PMem64Node)); + + DumpResourceMap ( + Device, + ChildIoNode, + ChildMem32Node, + ChildPMem32Node, + ChildMem64Node, + ChildPMem64Node + ); + } + } +} + /** Submits the I/O and memory resource requirements for the specified PCI Host Bridge. @@ -236,11 +443,15 @@ PciHostBridgeResourceAllocator ( // enumerator. Several resource tree was created // + // + // If non-stardard PCI Bridge I/O window alignment is supported, + // set I/O aligment to minimum possible alignment for root bridge. + // IoBridge = CreateResourceNode ( RootBridgeDev, 0, - 0xFFF, - 0, + FeaturePcdGet (PcdPciBridgeIoAlignmentProbe) ? 0x1FF: 0xFFF, + RB_IO_RANGE, PciBarTypeIo16, PciResUsageTypical ); @@ -249,7 +460,7 @@ PciHostBridgeResourceAllocator ( RootBridgeDev, 0, 0xFFFFF, - 0, + RB_MEM32_RANGE, PciBarTypeMem32, PciResUsageTypical ); @@ -258,7 +469,7 @@ PciHostBridgeResourceAllocator ( RootBridgeDev, 0, 0xFFFFF, - 0, + RB_PMEM32_RANGE, PciBarTypePMem32, PciResUsageTypical ); @@ -267,7 +478,7 @@ PciHostBridgeResourceAllocator ( RootBridgeDev, 0, 0xFFFFF, - 0, + RB_MEM64_RANGE, PciBarTypeMem64, PciResUsageTypical ); @@ -276,7 +487,7 @@ PciHostBridgeResourceAllocator ( RootBridgeDev, 0, 0xFFFFF, - 0, + RB_PMEM64_RANGE, PciBarTypePMem64, PciResUsageTypical ); @@ -533,7 +744,7 @@ PciHostBridgeResourceAllocator ( // REPORT_STATUS_CODE_WITH_EXTENDED_DATA ( EFI_PROGRESS_CODE, - EFI_IO_BUS_PCI | EFI_IOB_PCI_PC_RES_ALLOC, + EFI_IO_BUS_PCI | EFI_IOB_PCI_RES_ALLOC, (VOID *) &HandleExtendedData, sizeof (HandleExtendedData) ); @@ -593,19 +804,17 @@ PciHostBridgeResourceAllocator ( // Create the entire system resource map from the information collected by // enumerator. Several resource tree was created // - GetResourceMap ( - RootBridgeDev, - &IoBridge, - &Mem32Bridge, - &PMem32Bridge, - &Mem64Bridge, - &PMem64Bridge, - &IoPool, - &Mem32Pool, - &PMem32Pool, - &Mem64Pool, - &PMem64Pool - ); + IoBridge = FindResourceNode (RootBridgeDev, &IoPool); + Mem32Bridge = FindResourceNode (RootBridgeDev, &Mem32Pool); + PMem32Bridge = FindResourceNode (RootBridgeDev, &PMem32Pool); + Mem64Bridge = FindResourceNode (RootBridgeDev, &Mem64Pool); + PMem64Bridge = FindResourceNode (RootBridgeDev, &PMem64Pool); + + ASSERT (IoBridge != NULL); + ASSERT (Mem32Bridge != NULL); + ASSERT (PMem32Bridge != NULL); + ASSERT (Mem64Bridge != NULL); + ASSERT (PMem64Bridge != NULL); // // Program IO resources @@ -647,6 +856,26 @@ PciHostBridgeResourceAllocator ( PMem64Bridge ); + IoBridge ->PciDev->PciBar[IoBridge ->Bar].BaseAddress = IoBase; + Mem32Bridge ->PciDev->PciBar[Mem32Bridge ->Bar].BaseAddress = Mem32Base; + PMem32Bridge->PciDev->PciBar[PMem32Bridge->Bar].BaseAddress = PMem32Base; + Mem64Bridge ->PciDev->PciBar[Mem64Bridge ->Bar].BaseAddress = Mem64Base; + PMem64Bridge->PciDev->PciBar[PMem64Bridge->Bar].BaseAddress = PMem64Base; + + // + // Dump the resource map for current root bridge + // + DEBUG_CODE ( + DumpResourceMap ( + RootBridgeDev, + IoBridge, + Mem32Bridge, + PMem32Bridge, + Mem64Bridge, + PMem64Bridge + ); + ); + FreePool (AcpiConfig); } @@ -667,6 +896,64 @@ PciHostBridgeResourceAllocator ( return EFI_SUCCESS; } +/** + Allocate NumberOfBuses buses and return the next available PCI bus number. + + @param Bridge Bridge device instance. + @param StartBusNumber Current available PCI bus number. + @param NumberOfBuses Number of buses enumerated below the StartBusNumber. + @param NextBusNumber Next available PCI bus number. + + @retval EFI_SUCCESS Available bus number resource is enough. Next available PCI bus number + is returned in NextBusNumber. + @retval EFI_OUT_OF_RESOURCES Available bus number resource is not enough for allocation. + +**/ +EFI_STATUS +PciAllocateBusNumber ( + IN PCI_IO_DEVICE *Bridge, + IN UINT8 StartBusNumber, + IN UINT8 NumberOfBuses, + OUT UINT8 *NextBusNumber + ) +{ + PCI_IO_DEVICE *RootBridge; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BusNumberRanges; + UINT8 NextNumber; + UINT64 MaxNumberInRange; + + // + // Get PCI Root Bridge device + // + RootBridge = Bridge; + while (RootBridge->Parent != NULL) { + RootBridge = RootBridge->Parent; + } + + // + // Get next available PCI bus number + // + BusNumberRanges = RootBridge->BusNumberRanges; + while (BusNumberRanges->Desc != ACPI_END_TAG_DESCRIPTOR) { + MaxNumberInRange = BusNumberRanges->AddrRangeMin + BusNumberRanges->AddrLen - 1; + if (StartBusNumber >= BusNumberRanges->AddrRangeMin && StartBusNumber <= MaxNumberInRange) { + NextNumber = StartBusNumber + NumberOfBuses; + while (NextNumber > MaxNumberInRange) { + ++BusNumberRanges; + if (BusNumberRanges->Desc == ACPI_END_TAG_DESCRIPTOR) { + return EFI_OUT_OF_RESOURCES; + } + NextNumber += (UINT8)(BusNumberRanges->AddrRangeMin - (MaxNumberInRange + 1)); + MaxNumberInRange = BusNumberRanges->AddrRangeMin + BusNumberRanges->AddrLen - 1; + } + *NextBusNumber = NextNumber; + return EFI_SUCCESS; + } + BusNumberRanges++; + } + return EFI_OUT_OF_RESOURCES; +} + /** Scan pci bus and assign bus number to the given PCI bus system. @@ -734,50 +1021,41 @@ PciScanBus ( ); if (EFI_ERROR (Status)) { - if (Func == 0) { - // - // Skip sub functions, this is not a multi function device - // - Func = PCI_MAX_FUNC; - } - continue; } - DEBUG((EFI_D_INFO, "Found DEV(%02d,%02d,%02d)\n", StartBusNumber, Device, Func )); - - if (FeaturePcdGet (PcdPciBusHotplugDeviceSupport)) { - // - // Get the PCI device information - // - Status = PciSearchDevice ( - Bridge, - &Pci, - StartBusNumber, - Device, - Func, - &PciDevice - ); + // + // Get the PCI device information + // + Status = PciSearchDevice ( + Bridge, + &Pci, + StartBusNumber, + Device, + Func, + &PciDevice + ); - ASSERT (!EFI_ERROR (Status)); + ASSERT (!EFI_ERROR (Status)); - PciAddress = EFI_PCI_ADDRESS (StartBusNumber, Device, Func, 0); + PciAddress = EFI_PCI_ADDRESS (StartBusNumber, Device, Func, 0); - if (!IS_PCI_BRIDGE (&Pci)) { - // - // PCI bridges will be called later - // Here just need for PCI device or PCI to cardbus controller - // EfiPciBeforeChildBusEnumeration for PCI Device Node - // - PreprocessController ( - PciDevice, - PciDevice->BusNumber, - PciDevice->DeviceNumber, - PciDevice->FunctionNumber, - EfiPciBeforeChildBusEnumeration - ); - } + if (!IS_PCI_BRIDGE (&Pci)) { + // + // PCI bridges will be called later + // Here just need for PCI device or PCI to cardbus controller + // EfiPciBeforeChildBusEnumeration for PCI Device Node + // + PreprocessController ( + PciDevice, + PciDevice->BusNumber, + PciDevice->DeviceNumber, + PciDevice->FunctionNumber, + EfiPciBeforeChildBusEnumeration + ); + } + if (FeaturePcdGet (PcdPciBusHotplugDeviceSupport)) { // // For Pci Hotplug controller devcie only // @@ -786,6 +1064,7 @@ PciScanBus ( // Check if it is a Hotplug PCI controller // if (IsRootPciHotPlugController (PciDevice->DevicePath, &HpIndex)) { + gPciRootHpcData[HpIndex].Found = TRUE; if (!gPciRootHpcData[HpIndex].Initialized) { @@ -879,15 +1158,10 @@ PciScanBus ( } } - // - // Add feature to support customized secondary bus number - // - if (*SubBusNumber == 0) { - *SubBusNumber = *PaddedBusRange; - *PaddedBusRange = 0; + Status = PciAllocateBusNumber (Bridge, *SubBusNumber, 1, SubBusNumber); + if (EFI_ERROR (Status)) { + return Status; } - - (*SubBusNumber)++; SecondBus = *SubBusNumber; Register = (UINT16) ((SecondBus << 8) | (UINT16) StartBusNumber); @@ -932,7 +1206,6 @@ PciScanBus ( EfiPciBeforeChildBusEnumeration ); - DEBUG((EFI_D_INFO, "Scan PPB(%02d,%02d,%02d)\n", PciDevice->BusNumber, PciDevice->DeviceNumber,PciDevice->FunctionNumber)); Status = PciScanBus ( PciDevice, (UINT8) (SecondBus), @@ -953,7 +1226,10 @@ PciScanBus ( (State & EFI_HPC_STATE_INITIALIZED) != 0) { *PaddedBusRange = (UINT8) ((UINT8) (BusRange) +*PaddedBusRange); } else { - *SubBusNumber = (UINT8) ((UINT8) (BusRange) +*SubBusNumber); + Status = PciAllocateBusNumber (PciDevice, *SubBusNumber, (UINT8) (BusRange), SubBusNumber); + if (EFI_ERROR (Status)) { + return Status; + } } } @@ -972,21 +1248,15 @@ PciScanBus ( } else { // // It is device. Check PCI IOV for Bus reservation - // - if (PciDevice == NULL) { - // - // No PciDevice found, conitue Scan - // - continue; - } - // // Go through each function, just reserve the MAX ReservedBusNum for one device // - if ((PciDevice->AriCapabilityOffset != 0) && ((FeaturePcdGet(PcdSrIovSupport)& EFI_PCI_IOV_POLICY_SRIOV) != 0)) { - + if (PcdGetBool (PcdSrIovSupport) && PciDevice->SrIovCapabilityOffset != 0) { if (TempReservedBusNum < PciDevice->ReservedBusNum) { - (*SubBusNumber) = (UINT8)((*SubBusNumber) + PciDevice->ReservedBusNum - TempReservedBusNum); + Status = PciAllocateBusNumber (PciDevice, *SubBusNumber, (UINT8) (PciDevice->ReservedBusNum - TempReservedBusNum), SubBusNumber); + if (EFI_ERROR (Status)) { + return Status; + } TempReservedBusNum = PciDevice->ReservedBusNum; if (Func == 0) { @@ -1047,7 +1317,7 @@ PciRootBridgeP2CProcess ( // REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, - EFI_IO_BUS_PCI | EFI_IOB_PCI_PC_HPC_INIT, + EFI_IO_BUS_PCI | EFI_IOB_PCI_HPC_INIT, Temp->DevicePath ); @@ -1237,7 +1507,7 @@ PciHostBridgeEnumerator ( ); FreePool (Configuration); - Link = GetNextNode (&RootBridgeList, Link); + Link = RemoveEntryList (Link); DestroyRootBridge (RootBridgeDev); } @@ -1247,6 +1517,7 @@ PciHostBridgeEnumerator ( Status = AllRootHPCInitialized (STALL_1_SECOND * 15); if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "Some root HPC failed to initialize\n")); return Status; }