X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FPciBusDxe%2FPciEnumerator.c;h=732914313607ec2d44f72e745b6a977abe206c4b;hp=189ce1360f37d03375f381f1699c0078ef970c13;hb=d838c7449faa02cc3a205b0efdcf40d6d4817dee;hpb=fe91c9921f8473c08d0b744c62b4cfba7dcc517f diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c index 189ce1360f..7329143136 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c @@ -1,7 +1,7 @@ /** @file PCI eunmeration implementation on entire PCI bus system for PCI Bus module. -Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2013, 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 @@ -29,7 +29,6 @@ PciEnumerator ( IN EFI_HANDLE Controller ) { - EFI_HANDLE Handle; EFI_HANDLE HostBridgeHandle; EFI_STATUS Status; EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *PciResAlloc; @@ -82,7 +81,11 @@ PciEnumerator ( // // Notify the pci bus enumeration is about to begin // - NotifyPhase (PciResAlloc, EfiPciHostBridgeBeginEnumeration); + Status = NotifyPhase (PciResAlloc, EfiPciHostBridgeBeginEnumeration); + + if (EFI_ERROR (Status)) { + return Status; + } // // Start the bus allocation phase @@ -105,7 +108,11 @@ PciEnumerator ( // // Notify the pci bus enumeration is about to complete // - NotifyPhase (PciResAlloc, EfiPciHostBridgeEndEnumeration); + Status = NotifyPhase (PciResAlloc, EfiPciHostBridgeEndEnumeration); + + if (EFI_ERROR (Status)) { + return Status; + } // // Process P2C @@ -126,9 +133,8 @@ PciEnumerator ( gFullEnumeration = FALSE; - Handle = NULL; Status = gBS->InstallProtocolInterface ( - &Handle, + &HostBridgeHandle, &gEfiPciEnumerationCompleteProtocolGuid, EFI_NATIVE_INTERFACE, NULL @@ -158,10 +164,16 @@ PciRootBridgeEnumerator ( { EFI_STATUS Status; EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration1; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration2; + EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration3; UINT8 SubBusNumber; UINT8 StartBusNumber; UINT8 PaddedBusRange; EFI_HANDLE RootBridgeHandle; + UINT8 Desc; + UINT64 AddrLen; + UINT64 AddrRangeMin; SubBusNumber = 0; StartBusNumber = 0; @@ -191,11 +203,40 @@ PciRootBridgeEnumerator ( return Status; } + if (Configuration == NULL || Configuration->Desc == ACPI_END_TAG_DESCRIPTOR) { + return EFI_INVALID_PARAMETER; + } + RootBridgeDev->BusNumberRanges = Configuration; + + // + // Sort the descriptors in ascending order + // + for (Configuration1 = Configuration; Configuration1->Desc != ACPI_END_TAG_DESCRIPTOR; Configuration1++) { + Configuration2 = Configuration1; + for (Configuration3 = Configuration1 + 1; Configuration3->Desc != ACPI_END_TAG_DESCRIPTOR; Configuration3++) { + if (Configuration2->AddrRangeMin > Configuration3->AddrRangeMin) { + Configuration2 = Configuration3; + } + } + // + // All other fields other than AddrRangeMin and AddrLen are ignored in a descriptor, + // so only need to swap these two fields. + // + if (Configuration2 != Configuration1) { + AddrRangeMin = Configuration1->AddrRangeMin; + Configuration1->AddrRangeMin = Configuration2->AddrRangeMin; + Configuration2->AddrRangeMin = AddrRangeMin; + + AddrLen = Configuration1->AddrLen; + Configuration1->AddrLen = Configuration2->AddrLen; + Configuration2->AddrLen = AddrLen; + } + } + // // Get the bus number to start with // StartBusNumber = (UINT8) (Configuration->AddrRangeMin); - PaddedBusRange = (UINT8) (Configuration->AddrRangeMax); // // Initialize the subordinate bus number @@ -215,7 +256,7 @@ PciRootBridgeEnumerator ( // Status = PciScanBus ( RootBridgeDev, - (UINT8) (Configuration->AddrRangeMin), + StartBusNumber, &SubBusNumber, &PaddedBusRange ); @@ -228,24 +269,45 @@ PciRootBridgeEnumerator ( // // Assign max bus number scanned // - Configuration->AddrLen = SubBusNumber - StartBusNumber + 1 + PaddedBusRange; + + Status = PciAllocateBusNumber (RootBridgeDev, SubBusNumber, PaddedBusRange, &SubBusNumber); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Find the bus range which contains the higest bus number, then returns the number of buses + // that should be decoded. + // + while (Configuration->AddrRangeMin + Configuration->AddrLen - 1 < SubBusNumber) { + Configuration++; + } + AddrLen = Configuration->AddrLen; + Configuration->AddrLen = SubBusNumber - Configuration->AddrRangeMin + 1; + // + // Save the Desc field of the next descriptor. Mark the next descriptor as an END descriptor. + // + Configuration++; + Desc = Configuration->Desc; + Configuration->Desc = ACPI_END_TAG_DESCRIPTOR; + // // Set bus number // Status = PciResAlloc->SetBusNumbers ( PciResAlloc, RootBridgeHandle, - Configuration + RootBridgeDev->BusNumberRanges ); - FreePool (Configuration); - - if (EFI_ERROR (Status)) { - return Status; - } - - return EFI_SUCCESS; + // + // Restore changed fields + // + Configuration->Desc = Desc; + (Configuration - 1)->AddrLen = AddrLen; + + return Status; } /** @@ -351,7 +413,11 @@ PciAssignBusNumber ( // // Reserved one bus for cardbus bridge // - SecondBus = ++(*SubBusNumber); + Status = PciAllocateBusNumber (Bridge, *SubBusNumber, 1, SubBusNumber); + if (EFI_ERROR (Status)) { + return Status; + } + SecondBus = *SubBusNumber; Register = (UINT16) ((SecondBus << 8) | (UINT16) StartBusNumber); @@ -734,7 +800,6 @@ RejectPciDevice ( if (Temp == PciDevice) { InitializePciDevice (Temp); RemoveEntryList (CurrentLink); - FreePciDevice (Temp); return EFI_SUCCESS; } @@ -975,6 +1040,11 @@ PciHostBridgeAdjustAllocation ( // Status = RejectPciDevice (PciResNode->PciDev); if (Status == EFI_SUCCESS) { + DEBUG (( + EFI_D_ERROR, + "PciBus: [%02x|%02x|%02x] was rejected due to resource confliction.\n", + PciResNode->PciDev->BusNumber, PciResNode->PciDev->DeviceNumber, PciResNode->PciDev->FunctionNumber + )); // // Raise the EFI_IOB_EC_RESOURCE_CONFLICT status code @@ -1807,7 +1877,7 @@ NotifyPhase ( ); } - return EFI_SUCCESS; + return Status; } /** @@ -2035,6 +2105,14 @@ PciHotPlugRequestNotify ( RootBridgeHandle = Temp->Handle; if (Operation == EfiPciHotPlugRequestAdd) { + // + // Report Status Code to indicate hot plug happens + // + REPORT_STATUS_CODE_WITH_DEVICE_PATH ( + EFI_PROGRESS_CODE, + (EFI_IO_BUS_PCI | EFI_IOB_PC_HOTPLUG), + Temp->DevicePath + ); if (NumberOfChildren != NULL) { *NumberOfChildren = 0;