X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=IntelFrameworkModulePkg%2FBus%2FPci%2FPciBusDxe%2FPciDeviceSupport.c;h=e205fe9dc88cb696d32f9b4dcbb350f18aee7f73;hp=584f4f5c9ef07dffa556e22d0a4b7ce4dbf97078;hb=0170af58e038038d4bbe6c9b9b5436f5456dafaf;hpb=2067710de051070c1eb0fce033adcb9f6c23b1dc diff --git a/IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c b/IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c index 584f4f5c9e..e205fe9dc8 100644 --- a/IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c +++ b/IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciDeviceSupport.c @@ -1,6 +1,6 @@ -/**@file +/** @file -Copyright (c) 2006, Intel Corporation +Copyright (c) 2006 - 2009, 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 @@ -22,7 +22,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. LIST_ENTRY gPciDevicePool; /** - Initialize the gPciDevicePool + Initialize the gPciDevicePool. **/ EFI_STATUS InitializePciDevicePool ( @@ -75,7 +75,7 @@ InsertPciDevice ( /** Destroy root bridge and remove it from deivce tree. - @param RootBridge The bridge want to be removed + @param RootBridge The bridge want to be removed. **/ EFI_STATUS @@ -174,7 +174,7 @@ DestroyRootBridgeByHandle ( CurrentLink = gPciDevicePool.ForwardLink; - while (CurrentLink && CurrentLink != &gPciDevicePool) { + while (CurrentLink != NULL && CurrentLink != &gPciDevicePool) { Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink); if (Temp->Handle == Controller) { @@ -220,6 +220,7 @@ RegisterPciDevice ( UINT8 PciExpressCapRegOffset; EFI_PCI_IO_PROTOCOL *PciIo; UINT8 Data8; + BOOLEAN HasEfiImage; // // Install the pciio protocol, device path protocol @@ -261,7 +262,6 @@ RegisterPciDevice ( // Process OpRom // if (!PciIoDevice->AllOpRomProcessed) { - PciIoDevice->AllOpRomProcessed = TRUE; // // Get the OpRom provided by platform @@ -279,7 +279,7 @@ RegisterPciDevice ( PciIoDevice->PciIo.RomImage = PlatformOpRomBuffer; // // For OpROM read from gPciPlatformProtocol: - // Add the Rom Image to internal database for later PCI light enumeration + // Add the Rom Image to internal database for later PCI light enumeration // PciRomAddImageMapping ( NULL, @@ -290,16 +290,46 @@ RegisterPciDevice ( (UINT64) (UINTN) PciIoDevice->PciIo.RomImage, PciIoDevice->PciIo.RomSize ); - } } + } + + // + // 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, + &PciIoDevice->LoadFile2, + NULL + ); + if (EFI_ERROR (Status)) { + gBS->UninstallMultipleProtocolInterfaces ( + &PciIoDevice->Handle, + &gEfiDevicePathProtocolGuid, + PciIoDevice->DevicePath, + &gEfiPciIoProtocolGuid, + &PciIoDevice->PciIo, + NULL + ); + return Status; + } + } + + + if (!PciIoDevice->AllOpRomProcessed) { + + PciIoDevice->AllOpRomProcessed = TRUE; // // Dispatch the EFI OpRom for the PCI device. // The OpRom is got from platform in the above code - // or loaded from device in previous bus enumeration + // or loaded from device in the previous round of bus enumeration // - if (PciIoDevice->RomSize > 0) { + if (HasEfiImage) { ProcessOpRomImage (PciIoDevice); } } @@ -323,6 +353,14 @@ RegisterPciDevice ( &PciIoDevice->PciIo, NULL ); + if (HasEfiImage) { + gBS->UninstallMultipleProtocolInterfaces ( + &PciIoDevice->Handle, + &gEfiLoadFile2ProtocolGuid, + &PciIoDevice->LoadFile2, + NULL + ); + } return Status; } @@ -340,12 +378,6 @@ RegisterPciDevice ( return Status; } - // - // Install Pccard Hotplug GUID for Pccard device so that - // to notify CardBus driver to stop the device when de-register happens - // - InstallPciHotplugGuid (PciIoDevice); - if (Handle != NULL) { *Handle = PciIoDevice->Handle; } @@ -456,7 +488,7 @@ DeRegisterPciDevice ( CurrentLink = PciIoDevice->ChildList.ForwardLink; - while (CurrentLink && CurrentLink != &PciIoDevice->ChildList) { + while (CurrentLink != NULL && CurrentLink != &PciIoDevice->ChildList) { Node = PCI_IO_DEVICE_FROM_LINK (CurrentLink); Status = DeRegisterPciDevice (Controller, Node->Handle); @@ -467,10 +499,6 @@ DeRegisterPciDevice ( CurrentLink = CurrentLink->ForwardLink; } } - // - // Uninstall Pccard Hotplug GUID for Pccard device - // - UninstallPciHotplugGuid (PciIoDevice); // // Close the child handle @@ -507,6 +535,33 @@ DeRegisterPciDevice ( ); } + if (!EFI_ERROR (Status)) { + // + // Try to uninstall LoadFile2 protocol if exists + // + Status = gBS->OpenProtocol ( + Handle, + &gEfiLoadFile2ProtocolGuid, + NULL, + gPciBusDriverBinding.DriverBindingHandle, + Controller, + EFI_OPEN_PROTOCOL_TEST_PROTOCOL + ); + if (!EFI_ERROR (Status)) { + Status = gBS->UninstallMultipleProtocolInterfaces ( + Handle, + &gEfiLoadFile2ProtocolGuid, + &PciIoDevice->LoadFile2, + NULL + ); + } + // + // Restore Status + // + Status = EFI_SUCCESS; + } + + if (EFI_ERROR (Status)) { gBS->OpenProtocol ( Controller, @@ -571,7 +626,7 @@ StartPciDevicesOnBridge ( CurrentLink = RootBridge->ChildList.ForwardLink; - while (CurrentLink && CurrentLink != &RootBridge->ChildList) { + while (CurrentLink != NULL && CurrentLink != &RootBridge->ChildList) { PciIoDevice = PCI_IO_DEVICE_FROM_LINK (CurrentLink); if (RemainingDevicePath != NULL) { @@ -728,7 +783,7 @@ StartPciDevices ( CurrentLink = gPciDevicePool.ForwardLink; - while (CurrentLink && CurrentLink != &gPciDevicePool) { + while (CurrentLink != NULL && CurrentLink != &gPciDevicePool) { RootBridge = PCI_IO_DEVICE_FROM_LINK (CurrentLink); // @@ -825,8 +880,9 @@ CreateRootBridge ( // // Initialize the PCI I/O instance structure // - Status = InitializePciIoInstance (Dev); - Status = InitializePciDriverOverrideInstance (Dev); + InitializePciIoInstance (Dev); + InitializePciDriverOverrideInstance (Dev); + InitializePciLoadFile2 (Dev); // // Initialize reserved resource list and @@ -839,11 +895,11 @@ CreateRootBridge ( } /** - Get root bridge device instance by specific handle + Get root bridge device instance by specific handle. - @param RootBridgeHandle Given root bridge handle + @param RootBridgeHandle Given root bridge handle. - @return root bridge device instance + @return root bridge device instance. **/ PCI_IO_DEVICE * GetRootBridgeByHandle ( @@ -855,7 +911,7 @@ GetRootBridgeByHandle ( CurrentLink = gPciDevicePool.ForwardLink; - while (CurrentLink && CurrentLink != &gPciDevicePool) { + while (CurrentLink != NULL && CurrentLink != &gPciDevicePool) { RootBridgeDev = PCI_IO_DEVICE_FROM_LINK (CurrentLink); if (RootBridgeDev->Handle == RootBridgeHandle) { @@ -869,12 +925,12 @@ GetRootBridgeByHandle ( } /** - Judege whether Pci device existed + Judege whether Pci device existed. - @param Bridge Parent bridege instance - @param PciIoDevice Device instance + @param Bridge Parent bridege instance. + @param PciIoDevice Device instance. - @return whether Pci device existed + @return whether Pci device existed. **/ BOOLEAN PciDeviceExisted ( @@ -888,7 +944,7 @@ PciDeviceExisted ( CurrentLink = Bridge->ChildList.ForwardLink; - while (CurrentLink && CurrentLink != &Bridge->ChildList) { + while (CurrentLink != NULL && CurrentLink != &Bridge->ChildList) { Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink); @@ -909,11 +965,11 @@ PciDeviceExisted ( } /** - Active VGA device + Active VGA device. - @param VgaDevice device instance for VGA + @param VgaDevice device instance for VGA. - @return device instance + @return device instance. **/ PCI_IO_DEVICE * ActiveVGADeviceOnTheSameSegment ( @@ -925,7 +981,7 @@ ActiveVGADeviceOnTheSameSegment ( CurrentLink = gPciDevicePool.ForwardLink; - while (CurrentLink && CurrentLink != &gPciDevicePool) { + while (CurrentLink != NULL && CurrentLink != &gPciDevicePool) { Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink); @@ -945,11 +1001,11 @@ ActiveVGADeviceOnTheSameSegment ( } /** - Active VGA device on root bridge + Active VGA device on root bridge. - @param RootBridge Root bridge device instance + @param RootBridge Root bridge device instance. - @return VGA device instance + @return VGA device instance. **/ PCI_IO_DEVICE * ActiveVGADeviceOnTheRootBridge ( @@ -961,7 +1017,7 @@ ActiveVGADeviceOnTheRootBridge ( CurrentLink = RootBridge->ChildList.ForwardLink; - while (CurrentLink && CurrentLink != &RootBridge->ChildList) { + while (CurrentLink != NULL && CurrentLink != &RootBridge->ChildList) { Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink); @@ -969,7 +1025,7 @@ ActiveVGADeviceOnTheRootBridge ( (Temp->Attributes & (EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO | - EFI_PCI_IO_ATTRIBUTE_VGA_IO_16))) { + EFI_PCI_IO_ATTRIBUTE_VGA_IO_16)) != 0) { return Temp; } @@ -989,13 +1045,13 @@ ActiveVGADeviceOnTheRootBridge ( } /** - Get HPC PCI address according to its device path - @param PciRootBridgeIo Root bridege Io instance - @param HpcDevicePath Given searching device path - @param PciAddress Buffer holding searched result + Get HPC PCI address according to its device path. + @param PciRootBridgeIo Root bridege Io instance. + @param HpcDevicePath Given searching device path. + @param PciAddress Buffer holding searched result. @retval EFI_NOT_FOUND Can not find the specific device path. - @retval EFI_SUCCESS Success to get the device path + @retval EFI_SUCCESS Success to get the device path. **/ EFI_STATUS GetHpcPciAddress ( @@ -1041,7 +1097,7 @@ GetHpcPciAddress ( CurrentLink = gPciDevicePool.ForwardLink; - while (CurrentLink && CurrentLink != &gPciDevicePool) { + while (CurrentLink != NULL && CurrentLink != &gPciDevicePool) { RootBridge = PCI_IO_DEVICE_FROM_LINK (CurrentLink); // @@ -1068,10 +1124,10 @@ GetHpcPciAddress ( } /** - 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 + 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_NOT_FOUND Can not find the specific device path. **/ @@ -1099,7 +1155,7 @@ GetHpcPciAddressFromRootBridge ( CurrentLink = RootBridge->ChildList.ForwardLink; Node.DevPath = CurrentDevicePath; - while (CurrentLink && CurrentLink != &RootBridge->ChildList) { + while (CurrentLink != NULL && CurrentLink != &RootBridge->ChildList) { Temp = PCI_IO_DEVICE_FROM_LINK (CurrentLink); if (Node.Pci->Device == Temp->DeviceNumber && @@ -1136,7 +1192,11 @@ GetHpcPciAddressFromRootBridge ( return EFI_NOT_FOUND; } - *PciAddress = EFI_PCI_ADDRESS (Temp->BusNumber, Temp->DeviceNumber, Temp->FunctionNumber, 0); + if (Temp != NULL) { + *PciAddress = EFI_PCI_ADDRESS (Temp->BusNumber, Temp->DeviceNumber, Temp->FunctionNumber, 0); + } else { + return EFI_NOT_FOUND; + } return EFI_SUCCESS;