X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FPciBusDxe%2FPciEnumerator.c;h=f6aa327493fb32986bb6574022ce598fb307013a;hp=fca00840164cc11b140968d5843623b3aed8d440;hb=2632981783683f5c37b430c3e8ac2df067810d3a;hpb=cd5ebaa06dca3e6ef3c464081e6defe00d358c69 diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c index fca0084016..f6aa327493 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c @@ -1,7 +1,8 @@ /** @file PCI eunmeration implementation on entire PCI bus system for PCI Bus module. -Copyright (c) 2006 - 2009, 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 @@ -18,7 +19,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. This routine is used to enumerate entire pci bus system in a given platform. - @param Controller Parent controller handle. + @param Controller Parent controller handle. + @param HostBridgeHandle Host bridge handle. @retval EFI_SUCCESS PCI enumeration finished successfully. @retval other Some error occurred when enumerating the pci bus system. @@ -26,42 +28,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ EFI_STATUS PciEnumerator ( - IN EFI_HANDLE Controller + IN EFI_HANDLE Controller, + IN EFI_HANDLE HostBridgeHandle ) { - EFI_HANDLE Handle; - EFI_HANDLE HostBridgeHandle; EFI_STATUS Status; EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *PciResAlloc; - EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo; - - // - // If PCI bus has already done the full enumeration, never do it again - // - if (!gFullEnumeration) { - return PciEnumeratorLight (Controller); - } - - // - // Get the rootbridge Io protocol to find the host bridge handle - // - Status = gBS->OpenProtocol ( - Controller, - &gEfiPciRootBridgeIoProtocolGuid, - (VOID **) &PciRootBridgeIo, - gPciBusDriverBinding.DriverBindingHandle, - Controller, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - - if (EFI_ERROR (Status)) { - return Status; - } - - // - // Get the host bridge handle - // - HostBridgeHandle = PciRootBridgeIo->ParentHandle; // // Get the pci host bridge resource allocation protocol @@ -82,7 +54,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 +81,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 @@ -124,11 +104,8 @@ PciEnumerator ( return Status; } - gFullEnumeration = FALSE; - - Handle = NULL; Status = gBS->InstallProtocolInterface ( - &Handle, + &HostBridgeHandle, &gEfiPciEnumerationCompleteProtocolGuid, EFI_NATIVE_INTERFACE, NULL @@ -158,10 +135,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; @@ -174,7 +157,7 @@ PciRootBridgeEnumerator ( REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_PROGRESS_CODE, - EFI_IO_BUS_PCI | EFI_IOB_PCI_PC_BUS_ENUM, + EFI_IO_BUS_PCI | EFI_IOB_PCI_BUS_ENUM, RootBridgeDev->DevicePath ); @@ -191,11 +174,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 +227,7 @@ PciRootBridgeEnumerator ( // Status = PciScanBus ( RootBridgeDev, - (UINT8) (Configuration->AddrRangeMin), + StartBusNumber, &SubBusNumber, &PaddedBusRange ); @@ -228,24 +240,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; } /** @@ -345,13 +378,24 @@ PciAssignBusNumber ( Func ); + if (EFI_ERROR (Status) && Func == 0) { + // + // go to next device if there is no Function 0 + // + break; + } + if (!EFI_ERROR (Status) && (IS_PCI_BRIDGE (&Pci) || IS_CARDBUS_BRIDGE (&Pci))) { // // 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 +778,6 @@ RejectPciDevice ( if (Temp == PciDevice) { InitializePciDevice (Temp); RemoveEntryList (CurrentLink); - FreePciDevice (Temp); return EFI_SUCCESS; } @@ -889,7 +932,7 @@ GetMaxResourceConsumerDevice ( @param Mem64ResStatus Status of 64-bit memory resource node. @param PMem64ResStatus Status of 64-bit Prefetchable memory resource node. - @retval EFI_SUCCESS Successfully adjusted resoruce on host bridge. + @retval EFI_SUCCESS Successfully adjusted resource on host bridge. @retval EFI_ABORTED Host bridge hasn't this resource type or no resource be adjusted. **/ @@ -975,6 +1018,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 @@ -983,7 +1031,7 @@ PciHostBridgeAdjustAllocation ( // Have no way to get ReqRes, AllocRes & Bar here // ZeroMem (&AllocFailExtendedData, sizeof (AllocFailExtendedData)); - AllocFailExtendedData.DevicePathSize = sizeof (EFI_DEVICE_PATH_PROTOCOL); + AllocFailExtendedData.DevicePathSize = (UINT16) sizeof (EFI_DEVICE_PATH_PROTOCOL); AllocFailExtendedData.DevicePath = (UINT8 *) PciResNode->PciDev->DevicePath; AllocFailExtendedData.Bar = PciResNode->Bar; @@ -1013,7 +1061,7 @@ PciHostBridgeAdjustAllocation ( } /** - Summary requests for all resource type, and contruct ACPI resource + Summary requests for all resource type, and construct ACPI resource requestor instance. @param Bridge detecting bridge @@ -1025,7 +1073,7 @@ PciHostBridgeAdjustAllocation ( @param Config Output buffer holding new constructed APCI resource requestor @retval EFI_SUCCESS Successfully constructed ACPI resource. - @retval EFI_OUT_OF_RESOURCES No memory availabe. + @retval EFI_OUT_OF_RESOURCES No memory available. **/ EFI_STATUS @@ -1108,7 +1156,7 @@ ConstructAcpiResourceRequestor ( // if ((Aperture & 0x01) != 0) { Ptr->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR; - Ptr->Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3; + Ptr->Len = (UINT16) (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3); // // Io // @@ -1127,7 +1175,7 @@ ConstructAcpiResourceRequestor ( // if ((Aperture & 0x02) != 0) { Ptr->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR; - Ptr->Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3; + Ptr->Len = (UINT16) (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3); // // Mem // @@ -1151,7 +1199,7 @@ ConstructAcpiResourceRequestor ( // if ((Aperture & 0x04) != 0) { Ptr->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR; - Ptr->Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3; + Ptr->Len = (UINT16) (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3); // // Mem // @@ -1174,7 +1222,7 @@ ConstructAcpiResourceRequestor ( // if ((Aperture & 0x08) != 0) { Ptr->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR; - Ptr->Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3; + Ptr->Len = (UINT16) (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3); // // Mem // @@ -1197,7 +1245,7 @@ ConstructAcpiResourceRequestor ( // if ((Aperture & 0x10) != 0) { Ptr->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR; - Ptr->Len = sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3; + Ptr->Len = (UINT16) (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) - 3); // // Mem // @@ -1229,15 +1277,12 @@ ConstructAcpiResourceRequestor ( // // If there is no resource request // - Configuration = AllocateZeroPool (sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + sizeof (EFI_ACPI_END_TAG_DESCRIPTOR)); + Configuration = AllocateZeroPool (sizeof (EFI_ACPI_END_TAG_DESCRIPTOR)); if (Configuration == NULL) { return EFI_OUT_OF_RESOURCES; } - Ptr = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) (Configuration); - Ptr->Desc = ACPI_ADDRESS_SPACE_DESCRIPTOR; - - PtrEnd = (EFI_ACPI_END_TAG_DESCRIPTOR *) (Ptr + 1); + PtrEnd = (EFI_ACPI_END_TAG_DESCRIPTOR *) (Configuration); PtrEnd->Desc = ACPI_END_TAG_DESCRIPTOR; PtrEnd->Checksum = 0; } @@ -1807,7 +1852,7 @@ NotifyPhase ( ); } - return EFI_SUCCESS; + return Status; } /** @@ -2035,6 +2080,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;