X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FPciBusDxe%2FPciLib.c;h=7255bcfbbcea2d06f95deaeafdc4817386b13ded;hb=0176af142ef632c82f37cd3616f0184241f4fcbb;hp=4717140255c1bce3970c4e71a9ca160d601d2b88;hpb=d40483911c83dbcff1cb25ae4c9b9c26cf213973;p=mirror_edk2.git diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c index 4717140255..7255bcfbbc 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c @@ -1,7 +1,8 @@ /** @file Internal library implementation for PCI Bus module. -Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP
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 +15,57 @@ 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" OpRom", + L" Io", + L" Mem", + L"Unknow" + }; + +/** + Retrieve the max bus number that is assigned to the Root Bridge hierarchy. + It can support the case that there are multiple bus ranges. + + @param Bridge Bridge device instance. + + @retval The max bus number that is assigned to this Root Bridge hierarchy. + +**/ +UINT16 +PciGetMaxBusNumber ( + IN PCI_IO_DEVICE *Bridge + ) +{ + PCI_IO_DEVICE *RootBridge; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *BusNumberRanges; + UINT64 MaxNumberInRange; + + // + // Get PCI Root Bridge device + // + RootBridge = Bridge; + while (RootBridge->Parent != NULL) { + RootBridge = RootBridge->Parent; + } + MaxNumberInRange = 0; + // + // Iterate the bus number ranges to get max PCI bus number + // + BusNumberRanges = RootBridge->BusNumberRanges; + while (BusNumberRanges->Desc != ACPI_END_TAG_DESCRIPTOR) { + MaxNumberInRange = BusNumberRanges->AddrRangeMin + BusNumberRanges->AddrLen - 1; + BusNumberRanges++; + } + return (UINT16) MaxNumberInRange; +} /** Retrieve the PCI Card device BAR information via PciIo interface. @@ -153,6 +205,184 @@ 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%lx;\tLength = 0x%lx;\tAlignment = 0x%lx\n", + mBarTypeStr[MIN (BridgeResource->ResType, PciBarTypeMaxType)], + BridgeResource->PciDev->PciBar[BridgeResource->Bar].BaseAddress, + BridgeResource->Length, BridgeResource->Alignment + )); + for ( Link = GetFirstNode (&BridgeResource->ChildList) + ; !IsNull (&BridgeResource->ChildList, Link) + ; Link = GetNextNode (&BridgeResource->ChildList, Link) + ) { + 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%lx;\tLength = 0x%lx;\tAlignment = 0x%lx;\tOwner = %s [%02x|%02x|%02x:", + 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", + Resource->PciDev->BusNumber, Resource->PciDev->DeviceNumber, + Resource->PciDev->FunctionNumber + )); + + 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]", Bar[Resource->Bar].Offset)); + } else { + // + // The resource requirement comes from the subordinate devices. + // + DEBUG ((EFI_D_INFO, "**]")); + } + } else { + DEBUG ((EFI_D_INFO, " Base = Padding;\tLength = 0x%lx;\tAlignment = 0x%lx", Resource->Length, Resource->Alignment)); + } + if (BridgeResource->ResType != Resource->ResType) { + DEBUG ((EFI_D_INFO, "; Type = %s", mBarTypeStr[MIN (Resource->ResType, PciBarTypeMaxType)])); + } + DEBUG ((EFI_D_INFO, "\n")); + } + } +} + +/** + 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. + @param[out] DeviceResources Pointer to a buffer to receive resources for the Device. + + @return Count of the resource descriptors returned. +**/ +UINTN +FindResourceNode ( + IN PCI_IO_DEVICE *Device, + IN PCI_RESOURCE_NODE *BridgeResource, + OUT PCI_RESOURCE_NODE **DeviceResources OPTIONAL + ) +{ + LIST_ENTRY *Link; + PCI_RESOURCE_NODE *Resource; + UINTN Count; + + Count = 0; + for ( Link = BridgeResource->ChildList.ForwardLink + ; Link != &BridgeResource->ChildList + ; Link = Link->ForwardLink + ) { + Resource = RESOURCE_NODE_FROM_LINK (Link); + if (Resource->PciDev == Device) { + if (DeviceResources != NULL) { + DeviceResources[Count] = Resource; + } + Count++; + } + } + + return Count; +} + +/** + Dump the resource map of all the devices under Bridge. + + @param[in] Bridge Bridge device instance. + @param[in] Resources Resource descriptors for the bridge device. + @param[in] ResourceCount Count of resource descriptors. +**/ +VOID +DumpResourceMap ( + IN PCI_IO_DEVICE *Bridge, + IN PCI_RESOURCE_NODE **Resources, + IN UINTN ResourceCount + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Link; + PCI_IO_DEVICE *Device; + UINTN Index; + CHAR16 *Str; + PCI_RESOURCE_NODE **ChildResources; + UINTN ChildResourceCount; + + 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 { + Str = ConvertDevicePathToText ( + DevicePathFromHandle (Bridge->Handle), + FALSE, + FALSE + ); + DEBUG ((EFI_D_INFO, "Root Bridge %s\n", Str != NULL ? Str : L"")); + if (Str != NULL) { + FreePool (Str); + } + } + + for (Index = 0; Index < ResourceCount; Index++) { + DumpBridgeResource (Resources[Index]); + } + 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)) { + + ChildResourceCount = 0; + for (Index = 0; Index < ResourceCount; Index++) { + ChildResourceCount += FindResourceNode (Device, Resources[Index], NULL); + } + ChildResources = AllocatePool (sizeof (PCI_RESOURCE_NODE *) * ChildResourceCount); + ASSERT (ChildResources != NULL); + ChildResourceCount = 0; + for (Index = 0; Index < ResourceCount; Index++) { + ChildResourceCount += FindResourceNode (Device, Resources[Index], &ChildResources[ChildResourceCount]); + } + + DumpResourceMap (Device, ChildResources, ChildResourceCount); + FreePool (ChildResources); + } + } +} + /** Submits the I/O and memory resource requirements for the specified PCI Host Bridge. @@ -196,15 +426,9 @@ PciHostBridgeResourceAllocator ( PCI_RESOURCE_NODE PMem32Pool; PCI_RESOURCE_NODE Mem64Pool; PCI_RESOURCE_NODE PMem64Pool; - BOOLEAN ReAllocate; EFI_DEVICE_HANDLE_EXTENDED_DATA_PAYLOAD HandleExtendedData; EFI_RESOURCE_ALLOC_FAILURE_ERROR_DATA_PAYLOAD AllocFailExtendedData; - // - // Reallocate flag - // - ReAllocate = FALSE; - // // It may try several times if the resource allocation fails // @@ -237,14 +461,14 @@ PciHostBridgeResourceAllocator ( // // - // If non-stardard PCI Bridge I/O window alignment is supported, + // If non-standard PCI Bridge I/O window alignment is supported, // set I/O aligment to minimum possible alignment for root bridge. // IoBridge = CreateResourceNode ( RootBridgeDev, 0, FeaturePcdGet (PcdPciBridgeIoAlignmentProbe) ? 0x1FF: 0xFFF, - 0, + RB_IO_RANGE, PciBarTypeIo16, PciResUsageTypical ); @@ -253,7 +477,7 @@ PciHostBridgeResourceAllocator ( RootBridgeDev, 0, 0xFFFFF, - 0, + RB_MEM32_RANGE, PciBarTypeMem32, PciResUsageTypical ); @@ -262,7 +486,7 @@ PciHostBridgeResourceAllocator ( RootBridgeDev, 0, 0xFFFFF, - 0, + RB_PMEM32_RANGE, PciBarTypePMem32, PciResUsageTypical ); @@ -271,7 +495,7 @@ PciHostBridgeResourceAllocator ( RootBridgeDev, 0, 0xFFFFF, - 0, + RB_MEM64_RANGE, PciBarTypeMem64, PciResUsageTypical ); @@ -280,11 +504,22 @@ PciHostBridgeResourceAllocator ( RootBridgeDev, 0, 0xFFFFF, - 0, + RB_PMEM64_RANGE, PciBarTypePMem64, PciResUsageTypical ); + // + // Get the max ROM size that the root bridge can process + // Insert to resource map so that there will be dedicate MEM32 resource range for Option ROM. + // All devices' Option ROM share the same MEM32 resource. + // + MaxOptionRomSize = GetMaxOptionRomSize (RootBridgeDev); + RootBridgeDev->PciBar[0].BarType = PciBarTypeOpRom; + RootBridgeDev->PciBar[0].Length = MaxOptionRomSize; + RootBridgeDev->PciBar[0].Alignment = MaxOptionRomSize - 1; + GetResourceFromDevice (RootBridgeDev, IoBridge, Mem32Bridge, PMem32Bridge, Mem64Bridge, PMem64Bridge); + // // Create resourcemap by going through all the devices subject to this root bridge // @@ -298,39 +533,7 @@ PciHostBridgeResourceAllocator ( ); // - // Get the max ROM size that the root bridge can process - // - RootBridgeDev->RomSize = Mem32Bridge->Length; - - // - // Skip to enlarge the resource request during realloction - // - if (!ReAllocate) { - // - // Get Max Option Rom size for current root bridge - // - MaxOptionRomSize = GetMaxOptionRomSize (RootBridgeDev); - - // - // Enlarger the mem32 resource to accomdate the option rom - // if the mem32 resource is not enough to hold the rom - // - if (MaxOptionRomSize > Mem32Bridge->Length) { - - Mem32Bridge->Length = MaxOptionRomSize; - RootBridgeDev->RomSize = MaxOptionRomSize; - - // - // Alignment should be adjusted as well - // - if (Mem32Bridge->Alignment < MaxOptionRomSize - 1) { - Mem32Bridge->Alignment = MaxOptionRomSize - 1; - } - } - } - - // - // Based on the all the resource tree, contruct ACPI resource node to + // Based on the all the resource tree, construct ACPI resource node to // submit the resource aperture to pci host bridge protocol // Status = ConstructAcpiResourceRequestor ( @@ -361,6 +564,12 @@ PciHostBridgeResourceAllocator ( RootBridgeDev->Handle, AcpiConfig ); + // + // If SubmitResources returns error, PciBus isn't able to start. + // It's a fatal error so assertion is added. + // + DEBUG ((EFI_D_INFO, "PciBus: HostBridge->SubmitResources() - %r\n", Status)); + ASSERT_EFI_ERROR (Status); } // @@ -391,6 +600,7 @@ PciHostBridgeResourceAllocator ( // Notify platform to start to program the resource // Status = NotifyPhase (PciResAlloc, EfiPciHostBridgeAllocateResources); + DEBUG ((EFI_D_INFO, "PciBus: HostBridge->NotifyPhase(AllocateResources) - %r\n", Status)); if (!FeaturePcdGet (PcdPciBusHotplugDeviceSupport)) { // // If Hot Plug is not supported @@ -524,8 +734,6 @@ PciHostBridgeResourceAllocator ( if (EFI_ERROR (Status)) { return Status; } - - ReAllocate = TRUE; } } // @@ -537,7 +745,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) ); @@ -545,7 +753,11 @@ PciHostBridgeResourceAllocator ( // // Notify pci bus driver starts to program the resource // - NotifyPhase (PciResAlloc, EfiPciHostBridgeSetResources); + Status = NotifyPhase (PciResAlloc, EfiPciHostBridgeSetResources); + + if (EFI_ERROR (Status)) { + return Status; + } RootBridgeDev = NULL; @@ -588,28 +800,21 @@ PciHostBridgeResourceAllocator ( &PMem64Base ); - // - // Process option rom for this root bridge - // - ProcessOptionRom (RootBridgeDev, Mem32Base, RootBridgeDev->RomSize); - // // 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 - ); + FindResourceNode (RootBridgeDev, &IoPool, &IoBridge); + FindResourceNode (RootBridgeDev, &Mem32Pool, &Mem32Bridge); + FindResourceNode (RootBridgeDev, &PMem32Pool, &PMem32Bridge); + FindResourceNode (RootBridgeDev, &Mem64Pool, &Mem64Bridge); + FindResourceNode (RootBridgeDev, &PMem64Pool, &PMem64Bridge); + + ASSERT (IoBridge != NULL); + ASSERT (Mem32Bridge != NULL); + ASSERT (PMem32Bridge != NULL); + ASSERT (Mem64Bridge != NULL); + ASSERT (PMem64Bridge != NULL); // // Program IO resources @@ -651,6 +856,39 @@ PciHostBridgeResourceAllocator ( PMem64Bridge ); + // + // Process Option ROM for this root bridge after all BARs are programmed. + // The PPB's MEM32 RANGE BAR is re-programmed to the Option ROM BAR Base in order to + // shadow the Option ROM of the devices under the PPB. + // After the shadow, Option ROM BAR decoding is turned off and the PPB's MEM32 RANGE + // BAR is restored back to the original value. + // The original value is programmed by ProgramResource() above. + // + DEBUG (( + DEBUG_INFO, "Process Option ROM: BAR Base/Length = %lx/%lx\n", + RootBridgeDev->PciBar[0].BaseAddress, RootBridgeDev->PciBar[0].Length + )); + ProcessOptionRom (RootBridgeDev, RootBridgeDev->PciBar[0].BaseAddress, RootBridgeDev->PciBar[0].Length); + + 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 ( + PCI_RESOURCE_NODE *Resources[5]; + Resources[0] = IoBridge; + Resources[1] = Mem32Bridge; + Resources[2] = PMem32Bridge; + Resources[3] = Mem64Bridge; + Resources[4] = PMem64Bridge; + DumpResourceMap (RootBridgeDev, Resources, ARRAY_SIZE (Resources)); + ); + FreePool (AcpiConfig); } @@ -666,9 +904,67 @@ PciHostBridgeResourceAllocator ( // // Notify the resource allocation phase is to end // - NotifyPhase (PciResAlloc, EfiPciHostBridgeEndResourceAllocation); + Status = NotifyPhase (PciResAlloc, EfiPciHostBridgeEndResourceAllocation); - return EFI_SUCCESS; + return Status; +} + +/** + 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 = (UINT8)(StartBusNumber + NumberOfBuses); + while (NextNumber > MaxNumberInRange) { + ++BusNumberRanges; + if (BusNumberRanges->Desc == ACPI_END_TAG_DESCRIPTOR) { + return EFI_OUT_OF_RESOURCES; + } + NextNumber = (UINT8)(NextNumber + (BusNumberRanges->AddrRangeMin - (MaxNumberInRange + 1))); + MaxNumberInRange = BusNumberRanges->AddrRangeMin + BusNumberRanges->AddrLen - 1; + } + *NextBusNumber = NextNumber; + return EFI_SUCCESS; + } + BusNumberRanges++; + } + return EFI_OUT_OF_RESOURCES; } /** @@ -698,7 +994,8 @@ PciScanBus ( UINT8 Device; UINT8 Func; UINT64 Address; - UINTN SecondBus; + UINT8 SecondBus; + UINT8 PaddedSubBus; UINT16 Register; UINTN HpIndex; PCI_IO_DEVICE *PciDevice; @@ -707,6 +1004,7 @@ PciScanBus ( UINT64 PciAddress; EFI_HPC_PADDING_ATTRIBUTES Attributes; EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *NextDescriptors; UINT16 BusRange; EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo; BOOLEAN BusPadding; @@ -737,12 +1035,17 @@ PciScanBus ( Func ); + if (EFI_ERROR (Status) && Func == 0) { + // + // go to next device if there is no Function 0 + // + break; + } + if (EFI_ERROR (Status)) { continue; } - DEBUG((EFI_D_INFO, "Found DEV(%02d,%02d,%02d)\n", StartBusNumber, Device, Func )); - // // Get the PCI device information // @@ -783,6 +1086,7 @@ PciScanBus ( // Check if it is a Hotplug PCI controller // if (IsRootPciHotPlugController (PciDevice->DevicePath, &HpIndex)) { + gPciRootHpcData[HpIndex].Found = TRUE; if (!gPciRootHpcData[HpIndex].Initialized) { @@ -839,14 +1143,14 @@ PciScanBus ( BusPadding = FALSE; if (gPciHotPlugInit != NULL) { - if (IsRootPciHotPlugBus (PciDevice->DevicePath, &HpIndex)) { + if (IsPciHotPlugBus (PciDevice)) { // // If it is initialized, get the padded bus range // Status = gPciHotPlugInit->GetResourcePadding ( gPciHotPlugInit, - gPciRootHpcPool[HpIndex].HpbDevicePath, + PciDevice->DevicePath, PciAddress, &State, (VOID **) &Descriptors, @@ -858,8 +1162,9 @@ PciScanBus ( } BusRange = 0; + NextDescriptors = Descriptors; Status = PciGetBusRange ( - &Descriptors, + &NextDescriptors, NULL, NULL, &BusRange @@ -867,24 +1172,22 @@ PciScanBus ( FreePool (Descriptors); - if (EFI_ERROR (Status)) { + if (!EFI_ERROR (Status)) { + BusPadding = TRUE; + } else if (Status != EFI_NOT_FOUND) { + // + // EFI_NOT_FOUND is not a real error. It indicates no bus number padding requested. + // return Status; } - - BusPadding = TRUE; } } } - // - // 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); @@ -908,7 +1211,7 @@ PciScanBus ( // Temporarily initialize SubBusNumber to maximum bus number to ensure the // PCI configuration transaction to go through any PPB // - Register = 0xFF; + Register = PciGetMaxBusNumber (Bridge); Address = EFI_PCI_ADDRESS (StartBusNumber, Device, Func, PCI_BRIDGE_SUBORDINATE_BUS_REGISTER_OFFSET); Status = PciRootBridgeIo->Pci.Write ( PciRootBridgeIo, @@ -929,10 +1232,9 @@ PciScanBus ( EfiPciBeforeChildBusEnumeration ); - DEBUG((EFI_D_INFO, "Scan PPB(%02d,%02d,%02d)\n", PciDevice->BusNumber, PciDevice->DeviceNumber,PciDevice->FunctionNumber)); Status = PciScanBus ( PciDevice, - (UINT8) (SecondBus), + SecondBus, SubBusNumber, PaddedBusRange ); @@ -948,9 +1250,16 @@ PciScanBus ( if ((Attributes == EfiPaddingPciRootBridge) && (State & EFI_HPC_STATE_ENABLED) != 0 && (State & EFI_HPC_STATE_INITIALIZED) != 0) { - *PaddedBusRange = (UINT8) ((UINT8) (BusRange) +*PaddedBusRange); + *PaddedBusRange = (UINT8) ((UINT8) (BusRange) + *PaddedBusRange); } else { - *SubBusNumber = (UINT8) ((UINT8) (BusRange) +*SubBusNumber); + // + // Reserve the larger one between the actual occupied bus number and padded bus number + // + Status = PciAllocateBusNumber (PciDevice, SecondBus, (UINT8) (BusRange), &PaddedSubBus); + if (EFI_ERROR (Status)) { + return Status; + } + *SubBusNumber = MAX (PaddedSubBus, *SubBusNumber); } } @@ -974,7 +1283,10 @@ PciScanBus ( 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) { @@ -1035,7 +1347,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 ); @@ -1154,7 +1466,11 @@ PciHostBridgeEnumerator ( // // Notify the bus allocation phase is about to start // - NotifyPhase (PciResAlloc, EfiPciHostBridgeBeginBusAllocation); + Status = NotifyPhase (PciResAlloc, EfiPciHostBridgeBeginBusAllocation); + + if (EFI_ERROR (Status)) { + return Status; + } DEBUG((EFI_D_INFO, "PCI Bus First Scanning\n")); RootBridgeHandle = NULL; @@ -1235,13 +1551,18 @@ PciHostBridgeEnumerator ( Status = AllRootHPCInitialized (STALL_1_SECOND * 15); if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "Some root HPC failed to initialize\n")); return Status; } // // Notify the bus allocation phase is about to start for the 2nd time // - NotifyPhase (PciResAlloc, EfiPciHostBridgeBeginBusAllocation); + Status = NotifyPhase (PciResAlloc, EfiPciHostBridgeBeginBusAllocation); + + if (EFI_ERROR (Status)) { + return Status; + } DEBUG((EFI_D_INFO, "PCI Bus Second Scanning\n")); RootBridgeHandle = NULL; @@ -1279,7 +1600,11 @@ PciHostBridgeEnumerator ( // // Notify the resource allocation phase is to start // - NotifyPhase (PciResAlloc, EfiPciHostBridgeBeginResourceAllocation); + Status = NotifyPhase (PciResAlloc, EfiPciHostBridgeBeginResourceAllocation); + + if (EFI_ERROR (Status)) { + return Status; + } RootBridgeHandle = NULL; while (PciResAlloc->GetNextRootBridge (PciResAlloc, &RootBridgeHandle) == EFI_SUCCESS) {