X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FPciBusDxe%2FPciDeviceSupport.c;h=764845252faa8ec609899a3a86f4df8d88e590eb;hp=25387bd257c7707da4127a97906189d14a64c4f0;hb=fcdfcdbfc2e5dc6a96ce550a1f46edb4007f35a9;hpb=9060e3ec6dfd6048724832947933650cde873381 diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c index 25387bd257..764845252f 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c @@ -1,8 +1,9 @@ /** @file - Supporting functions implementaion for PCI devices management. + Supporting functions implementation for PCI devices management. -Copyright (c) 2006 - 2009, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+(C) Copyright 2018 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 http://opensource.org/licenses/bsd-license.php @@ -65,7 +66,7 @@ InsertPciDevice ( } /** - Destroy root bridge and remove it from deivce tree. + Destroy root bridge and remove it from device tree. @param RootBridge The bridge want to be removed. @@ -85,7 +86,7 @@ DestroyRootBridge ( All direct or indirect allocated resource for this node will be freed. - @param PciIoDevice A pointer to the PCI_IO_DEVICE to be destoried. + @param PciIoDevice A pointer to the PCI_IO_DEVICE to be destroyed. **/ VOID @@ -105,6 +106,10 @@ FreePciDevice ( FreePool (PciIoDevice->DevicePath); } + if (PciIoDevice->BusNumberRanges != NULL) { + FreePool (PciIoDevice->BusNumberRanges); + } + FreePool (PciIoDevice); } @@ -150,7 +155,7 @@ DestroyPciDeviceTree ( @param Controller Root bridge handle. - @retval EFI_SUCCESS Destory all devcie nodes successfully. + @retval EFI_SUCCESS Destroy all device nodes successfully. @retval EFI_NOT_FOUND Cannot find any PCI device under specified root bridge. @@ -211,14 +216,9 @@ RegisterPciDevice ( EFI_STATUS Status; VOID *PlatformOpRomBuffer; UINTN PlatformOpRomSize; - UINT8 PciExpressCapRegOffset; EFI_PCI_IO_PROTOCOL *PciIo; UINT8 Data8; BOOLEAN HasEfiImage; - PCI_IO_DEVICE *ParrentPciIoDevice; - EFI_PCI_IO_PROTOCOL *ParrentPciIo; - UINT16 Data16; - UINT32 Data32; // // Install the pciio protocol, device path protocol @@ -235,55 +235,13 @@ RegisterPciDevice ( return Status; } - // - // Detect if PCI Express Device - // - PciExpressCapRegOffset = 0; - Status = LocateCapabilityRegBlock ( - PciIoDevice, - EFI_PCI_CAPABILITY_ID_PCIEXP, - &PciExpressCapRegOffset, - NULL - ); - if (!EFI_ERROR (Status)) { - PciIoDevice->IsPciExp = TRUE; - } - // // Force Interrupt line to "Unknown" or "No Connection" // PciIo = &(PciIoDevice->PciIo); Data8 = PCI_INT_LINE_UNKNOWN; PciIo->Pci.Write (PciIo, EfiPciIoWidthUint8, 0x3C, 1, &Data8); - - // - // PCI-IOV programming - // - if (((FeaturePcdGet(PcdAriSupport) & EFI_PCI_IOV_POLICY_ARI) != 0) && (PciIoDevice->AriCapabilityOffset != 0) && ((FeaturePcdGet(PcdSrIovSupport) & EFI_PCI_IOV_POLICY_SRIOV) != 0) && - (PciIoDevice->SrIovCapabilityOffset != 0)) { - // - // Check its parrent ARI forwarding capability - // - ParrentPciIoDevice = PciIoDevice->Parent; - ParrentPciIo = &(ParrentPciIoDevice->PciIo); - ParrentPciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ParrentPciIoDevice->PciExpressCapabilityOffset + EFI_PCIE_CAPABILITY_DEVICE_CAPABILITIES_2_OFFSET, 1, &Data32); - if (Data32 & EFI_PCIE_CAPABILITY_DEVICE_CAPABILITIES_2_ARI_FORWARDING) { - // - // ARI forward support in bridge, so enable it. - // - ParrentPciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, ParrentPciIoDevice->PciExpressCapabilityOffset + EFI_PCIE_CAPABILITY_DEVICE_CONTROL_2_OFFSET, 1, &Data32); - Data32 |= EFI_PCIE_CAPABILITY_DEVICE_CONTROL_2_ARI_FORWARDING; - ParrentPciIo->Pci.Write (PciIo, EfiPciIoWidthUint32, ParrentPciIoDevice->PciExpressCapabilityOffset + EFI_PCIE_CAPABILITY_DEVICE_CONTROL_2_OFFSET, 1, &Data32); - // - // Set ARI Capable Hierarchy for device - // - PciIo->Pci.Read (PciIo, EfiPciIoWidthUint16, PciIoDevice->SrIovCapabilityOffset + EFI_PCIE_CAPABILITY_ID_SRIOV_CONTROL, 1, &Data16); - Data16 |= EFI_PCIE_CAPABILITY_ID_SRIOV_CONTROL_ARI_HIERARCHY; - PciIo->Pci.Write (PciIo, EfiPciIoWidthUint16, PciIoDevice->SrIovCapabilityOffset + EFI_PCIE_CAPABILITY_ID_SRIOV_CONTROL, 1, &Data16); - } - } - // // Process OpRom // @@ -300,7 +258,8 @@ RegisterPciDevice ( &PlatformOpRomSize ); if (!EFI_ERROR (Status)) { - PciIoDevice->RomSize = PlatformOpRomSize; + PciIoDevice->EmbeddedRom = FALSE; + PciIoDevice->RomSize = (UINT32) PlatformOpRomSize; PciIoDevice->PciIo.RomSize = PlatformOpRomSize; PciIoDevice->PciIo.RomImage = PlatformOpRomBuffer; // @@ -313,7 +272,7 @@ RegisterPciDevice ( PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber, - (UINT64) (UINTN) PciIoDevice->PciIo.RomImage, + PciIoDevice->PciIo.RomImage, PciIoDevice->PciIo.RomSize ); } @@ -325,7 +284,8 @@ RegisterPciDevice ( &PlatformOpRomSize ); if (!EFI_ERROR (Status)) { - PciIoDevice->RomSize = PlatformOpRomSize; + PciIoDevice->EmbeddedRom = FALSE; + PciIoDevice->RomSize = (UINT32) PlatformOpRomSize; PciIoDevice->PciIo.RomSize = PlatformOpRomSize; PciIoDevice->PciIo.RomImage = PlatformOpRomBuffer; // @@ -338,10 +298,10 @@ RegisterPciDevice ( PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber, - (UINT64) (UINTN) PciIoDevice->PciIo.RomImage, + PciIoDevice->PciIo.RomImage, PciIoDevice->PciIo.RomSize ); - } + } } } @@ -726,7 +686,7 @@ StartPciDevicesOnBridge ( // // If it is a PPB // - if (!IsListEmpty (&PciIoDevice->ChildList)) { + if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) { Status = StartPciDevicesOnBridge ( Controller, PciIoDevice, @@ -741,7 +701,7 @@ StartPciDevicesOnBridge ( 0, &Supports ); - Supports &= EFI_PCI_DEVICE_ENABLE; + Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE; PciIoDevice->PciIo.Attributes ( &(PciIoDevice->PciIo), EfiPciIoAttributeOperationEnable, @@ -778,7 +738,7 @@ StartPciDevicesOnBridge ( (*NumberOfChildren)++; } - if (!IsListEmpty (&PciIoDevice->ChildList)) { + if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) { Status = StartPciDevicesOnBridge ( Controller, PciIoDevice, @@ -793,7 +753,7 @@ StartPciDevicesOnBridge ( 0, &Supports ); - Supports &= EFI_PCI_DEVICE_ENABLE; + Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE; PciIoDevice->PciIo.Attributes ( &(PciIoDevice->PciIo), EfiPciIoAttributeOperationEnable, @@ -864,7 +824,7 @@ StartPciDevices ( /** Create root bridge device. - @param RootBridgeHandle Specified root bridge hanle. + @param RootBridgeHandle Specified root bridge handle. @return The crated root bridge device instance, NULL means no root bridge device instance created. @@ -977,9 +937,9 @@ GetRootBridgeByHandle ( } /** - Judege whether Pci device existed. + Judge whether Pci device existed. - @param Bridge Parent bridege instance. + @param Bridge Parent bridge instance. @param PciIoDevice Device instance. @retval TRUE Pci device existed. @@ -1019,33 +979,33 @@ PciDeviceExisted ( } /** - Get the active VGA device on the same segment. + Get the active VGA device on the specified Host Bridge. - @param VgaDevice PCI IO instance for the VGA device. + @param HostBridgeHandle Host Bridge handle. - @return The active VGA device on the same segment. + @return The active VGA device on the specified Host Bridge. **/ PCI_IO_DEVICE * -ActiveVGADeviceOnTheSameSegment ( - IN PCI_IO_DEVICE *VgaDevice +LocateVgaDeviceOnHostBridge ( + IN EFI_HANDLE HostBridgeHandle ) { LIST_ENTRY *CurrentLink; - PCI_IO_DEVICE *Temp; + PCI_IO_DEVICE *PciIoDevice; CurrentLink = mPciDevicePool.ForwardLink; while (CurrentLink != NULL && CurrentLink != &mPciDevicePool) { - Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink); + PciIoDevice = PCI_IO_DEVICE_FROM_LINK (CurrentLink); - if (Temp->PciRootBridgeIo->SegmentNumber == VgaDevice->PciRootBridgeIo->SegmentNumber) { + if (PciIoDevice->PciRootBridgeIo->ParentHandle== HostBridgeHandle) { - Temp = ActiveVGADeviceOnTheRootBridge (Temp); + PciIoDevice = LocateVgaDevice (PciIoDevice); - if (Temp != NULL) { - return Temp; + if (PciIoDevice != NULL) { + return PciIoDevice; } } @@ -1056,41 +1016,41 @@ ActiveVGADeviceOnTheSameSegment ( } /** - Get the active VGA device on the root bridge. + Locate the active VGA device under the bridge. - @param RootBridge PCI IO instance for the root bridge. + @param Bridge PCI IO instance for the bridge. @return The active VGA device. **/ PCI_IO_DEVICE * -ActiveVGADeviceOnTheRootBridge ( - IN PCI_IO_DEVICE *RootBridge +LocateVgaDevice ( + IN PCI_IO_DEVICE *Bridge ) { LIST_ENTRY *CurrentLink; - PCI_IO_DEVICE *Temp; + PCI_IO_DEVICE *PciIoDevice; - CurrentLink = RootBridge->ChildList.ForwardLink; + CurrentLink = Bridge->ChildList.ForwardLink; - while (CurrentLink != NULL && CurrentLink != &RootBridge->ChildList) { + while (CurrentLink != NULL && CurrentLink != &Bridge->ChildList) { - Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink); + PciIoDevice = PCI_IO_DEVICE_FROM_LINK (CurrentLink); - if (IS_PCI_VGA(&Temp->Pci) && - (Temp->Attributes & + if (IS_PCI_VGA(&PciIoDevice->Pci) && + (PciIoDevice->Attributes & (EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO | EFI_PCI_IO_ATTRIBUTE_VGA_IO_16)) != 0) { - return Temp; + return PciIoDevice; } - if (IS_PCI_BRIDGE (&Temp->Pci)) { + if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) { - Temp = ActiveVGADeviceOnTheRootBridge (Temp); + PciIoDevice = LocateVgaDevice (PciIoDevice); - if (Temp != NULL) { - return Temp; + if (PciIoDevice != NULL) { + return PciIoDevice; } } @@ -1100,86 +1060,3 @@ ActiveVGADeviceOnTheRootBridge ( return NULL; } - -/** - Get HPC PCI address according to its device path. - - @param RootBridge Root bridege Io instance. - @param RemainingDevicePath Given searching device path. - @param PciAddress Buffer holding searched result. - - @retval EFI_SUCCESS PCI address was stored in PciAddress - @retval EFI_NOT_FOUND Can not find the specific device path. - -**/ -EFI_STATUS -GetHpcPciAddressFromRootBridge ( - IN PCI_IO_DEVICE *RootBridge, - IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath, - OUT UINT64 *PciAddress - ) -{ - EFI_DEV_PATH_PTR Node; - PCI_IO_DEVICE *Temp; - EFI_DEVICE_PATH_PROTOCOL *CurrentDevicePath; - LIST_ENTRY *CurrentLink; - BOOLEAN MisMatch; - - MisMatch = FALSE; - - CurrentDevicePath = RemainingDevicePath; - Node.DevPath = CurrentDevicePath; - Temp = NULL; - - while (!IsDevicePathEnd (CurrentDevicePath)) { - - CurrentLink = RootBridge->ChildList.ForwardLink; - Node.DevPath = CurrentDevicePath; - - while (CurrentLink != NULL && CurrentLink != &RootBridge->ChildList) { - Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink); - - if (Node.Pci->Device == Temp->DeviceNumber && - Node.Pci->Function == Temp->FunctionNumber) { - RootBridge = Temp; - break; - } - - CurrentLink = CurrentLink->ForwardLink; - } - - // - // Check if we find the bridge - // - if (CurrentLink == &RootBridge->ChildList) { - - MisMatch = TRUE; - break; - - } - - CurrentDevicePath = NextDevicePathNode (CurrentDevicePath); - } - - if (MisMatch) { - - CurrentDevicePath = NextDevicePathNode (CurrentDevicePath); - - if (IsDevicePathEnd (CurrentDevicePath)) { - *PciAddress = EFI_PCI_ADDRESS (RootBridge->BusNumber, Node.Pci->Device, Node.Pci->Function, 0); - return EFI_SUCCESS; - } - - return EFI_NOT_FOUND; - } - - if (Temp != NULL) { - *PciAddress = EFI_PCI_ADDRESS (Temp->BusNumber, Temp->DeviceNumber, Temp->FunctionNumber, 0); - } else { - return EFI_NOT_FOUND; - } - - return EFI_SUCCESS; - -} -