X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FPciBusDxe%2FPciDeviceSupport.c;h=7fb8e596f535eab0bad31a05feba1c6126cfb449;hp=0ff39a56c4ceb63884aea80add915476a17be213;hb=1f6785c4b77d04bca9ce6205c63bd76264ec7789;hpb=7d921075b454dcd4af7b8b2dc705bff83edb2275 diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c index 0ff39a56c4..7fb8e596f5 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c @@ -1,7 +1,8 @@ /** @file Supporting functions implementaion for PCI devices management. -Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+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 @@ -105,6 +106,10 @@ FreePciDevice ( FreePool (PciIoDevice->DevicePath); } + if (PciIoDevice->BusNumberRanges != NULL) { + FreePool (PciIoDevice->BusNumberRanges); + } + FreePool (PciIoDevice); } @@ -211,9 +216,9 @@ RegisterPciDevice ( EFI_STATUS Status; VOID *PlatformOpRomBuffer; UINTN PlatformOpRomSize; - UINT8 PciExpressCapRegOffset; EFI_PCI_IO_PROTOCOL *PciIo; UINT8 Data8; + BOOLEAN HasEfiImage; // // Install the pciio protocol, device path protocol @@ -230,27 +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); - + // // Process OpRom // @@ -268,7 +259,7 @@ RegisterPciDevice ( ); if (!EFI_ERROR (Status)) { PciIoDevice->EmbeddedRom = FALSE; - PciIoDevice->RomSize = PlatformOpRomSize; + PciIoDevice->RomSize = (UINT32) PlatformOpRomSize; PciIoDevice->PciIo.RomSize = PlatformOpRomSize; PciIoDevice->PciIo.RomImage = PlatformOpRomBuffer; // @@ -281,7 +272,7 @@ RegisterPciDevice ( PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber, - (UINT64) (UINTN) PciIoDevice->PciIo.RomImage, + PciIoDevice->PciIo.RomImage, PciIoDevice->PciIo.RomSize ); } @@ -294,7 +285,7 @@ RegisterPciDevice ( ); if (!EFI_ERROR (Status)) { PciIoDevice->EmbeddedRom = FALSE; - PciIoDevice->RomSize = PlatformOpRomSize; + PciIoDevice->RomSize = (UINT32) PlatformOpRomSize; PciIoDevice->PciIo.RomSize = PlatformOpRomSize; PciIoDevice->PciIo.RomImage = PlatformOpRomBuffer; // @@ -307,14 +298,19 @@ RegisterPciDevice ( PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice->FunctionNumber, - (UINT64) (UINTN) PciIoDevice->PciIo.RomImage, + PciIoDevice->PciIo.RomImage, PciIoDevice->PciIo.RomSize ); - } + } } } - if (PciIoDevice->HasEfiOpRom) { + // + // Determine if there are EFI images in the option rom + // + HasEfiImage = ContainEfiImage (PciIoDevice->PciIo.RomImage, PciIoDevice->PciIo.RomSize); + + if (HasEfiImage) { Status = gBS->InstallMultipleProtocolInterfaces ( &PciIoDevice->Handle, &gEfiLoadFile2ProtocolGuid, @@ -344,7 +340,7 @@ RegisterPciDevice ( // The OpRom is got from platform in the above code // or loaded from device in the previous round of bus enumeration // - if (PciIoDevice->HasEfiOpRom) { + if (HasEfiImage) { ProcessOpRomImage (PciIoDevice); } } @@ -368,7 +364,7 @@ RegisterPciDevice ( &PciIoDevice->PciIo, NULL ); - if (PciIoDevice->HasEfiOpRom) { + if (HasEfiImage) { gBS->UninstallMultipleProtocolInterfaces ( &PciIoDevice->Handle, &gEfiLoadFile2ProtocolGuid, @@ -705,7 +701,7 @@ StartPciDevicesOnBridge ( 0, &Supports ); - Supports &= EFI_PCI_DEVICE_ENABLE; + Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE; PciIoDevice->PciIo.Attributes ( &(PciIoDevice->PciIo), EfiPciIoAttributeOperationEnable, @@ -757,7 +753,7 @@ StartPciDevicesOnBridge ( 0, &Supports ); - Supports &= EFI_PCI_DEVICE_ENABLE; + Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE; PciIoDevice->PciIo.Attributes ( &(PciIoDevice->PciIo), EfiPciIoAttributeOperationEnable, @@ -983,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; } } @@ -1020,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; } } @@ -1064,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; - -} -