X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FPciBusDxe%2FPciDriverOverride.c;h=e8fae17e8bfb6d4137031e75674d276b143bff75;hb=dc080d3b61e570e7a3163fc24afa6f8388d0c0bf;hp=97f45e42d0d08e37a22408a854d0754e58050390;hpb=cd5ebaa06dca3e6ef3c464081e6defe00d358c69;p=mirror_edk2.git diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDriverOverride.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciDriverOverride.c index 97f45e42d0..e8fae17e8b 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciDriverOverride.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciDriverOverride.c @@ -1,7 +1,7 @@ /** @file Functions implementation for Bus Specific Driver Override protoocl. -Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, 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 @@ -28,6 +28,56 @@ InitializePciDriverOverrideInstance ( PciIoDevice->PciDriverOverride.GetDriver = GetDriver; } +/** + Find the image handle whose path equals to ImagePath. + + @param ImagePath Image path. + + @return Image handle. +**/ +EFI_HANDLE +LocateImageHandle ( + IN EFI_DEVICE_PATH_PROTOCOL *ImagePath + ) +{ + EFI_STATUS Status; + EFI_HANDLE *Handles; + UINTN Index; + UINTN HandleNum; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + UINTN ImagePathSize; + EFI_HANDLE ImageHandle; + + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiLoadedImageDevicePathProtocolGuid, + NULL, + &HandleNum, + &Handles + ); + if (EFI_ERROR (Status)) { + return NULL; + } + + ImageHandle = NULL; + ImagePathSize = GetDevicePathSize (ImagePath); + + for (Index = 0; Index < HandleNum; Index++) { + Status = gBS->HandleProtocol (Handles[Index], &gEfiLoadedImageDevicePathProtocolGuid, (VOID **) &DevicePath); + if (EFI_ERROR (Status)) { + continue; + } + if ((ImagePathSize == GetDevicePathSize (DevicePath)) && + (CompareMem (ImagePath, DevicePath, ImagePathSize) == 0) + ) { + ImageHandle = Handles[Index]; + break; + } + } + + FreePool (Handles); + return ImageHandle; +} /** Uses a bus specific algorithm to retrieve a driver image handle for a controller. @@ -53,49 +103,60 @@ GetDriver ( ) { PCI_IO_DEVICE *PciIoDevice; - LIST_ENTRY *CurrentLink; - PCI_DRIVER_OVERRIDE_LIST *Node; + LIST_ENTRY *Link; + PCI_DRIVER_OVERRIDE_LIST *Override; + BOOLEAN ReturnNext; + Override = NULL; PciIoDevice = PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This); + ReturnNext = (BOOLEAN) (*DriverImageHandle == NULL); + for ( Link = GetFirstNode (&PciIoDevice->OptionRomDriverList) + ; !IsNull (&PciIoDevice->OptionRomDriverList, Link) + ; Link = GetNextNode (&PciIoDevice->OptionRomDriverList, Link) + ) { - CurrentLink = PciIoDevice->OptionRomDriverList.ForwardLink; - - while (CurrentLink != NULL && CurrentLink != &PciIoDevice->OptionRomDriverList) { - - Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink); - - if (*DriverImageHandle == NULL) { + Override = DRIVER_OVERRIDE_FROM_LINK (Link); - *DriverImageHandle = Node->DriverImageHandle; - return EFI_SUCCESS; - } - - if (*DriverImageHandle == Node->DriverImageHandle) { - - if (CurrentLink->ForwardLink == &PciIoDevice->OptionRomDriverList || - CurrentLink->ForwardLink == NULL) { - return EFI_NOT_FOUND; + if (ReturnNext) { + if (Override->DriverImageHandle == NULL) { + Override->DriverImageHandle = LocateImageHandle (Override->DriverImagePath); } - // - // Get next node - // - Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink->ForwardLink); - *DriverImageHandle = Node->DriverImageHandle; - return EFI_SUCCESS; + if (Override->DriverImageHandle == NULL) { + // + // The Option ROM identified by Override->DriverImagePath is not loaded. + // + continue; + } else { + *DriverImageHandle = Override->DriverImageHandle; + return EFI_SUCCESS; + } } - CurrentLink = CurrentLink->ForwardLink; + if (*DriverImageHandle == Override->DriverImageHandle) { + ReturnNext = TRUE; + } } - return EFI_INVALID_PARAMETER; + ASSERT (IsNull (&PciIoDevice->OptionRomDriverList, Link)); + // + // ReturnNext indicates a handle match happens. + // If all nodes are checked without handle match happening, + // the DriverImageHandle should be a invalid handle. + // + if (ReturnNext) { + return EFI_NOT_FOUND; + } else { + return EFI_INVALID_PARAMETER; + } } /** Add an overriding driver image. @param PciIoDevice Instance of PciIo device. - @param DriverImageHandle new added driver image. + @param DriverImageHandle Image handle of newly added driver image. + @param DriverImagePath Device path of newly added driver image. @retval EFI_SUCCESS Successfully added driver. @retval EFI_OUT_OF_RESOURCES No memory resource for new driver instance. @@ -104,40 +165,30 @@ GetDriver ( **/ EFI_STATUS AddDriver ( - IN PCI_IO_DEVICE *PciIoDevice, - IN EFI_HANDLE DriverImageHandle + IN PCI_IO_DEVICE *PciIoDevice, + IN EFI_HANDLE DriverImageHandle, + IN EFI_DEVICE_PATH_PROTOCOL *DriverImagePath ) { - EFI_STATUS Status; - EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; - PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; PCI_DRIVER_OVERRIDE_LIST *Node; - Status = gBS->HandleProtocol (DriverImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage); - if (EFI_ERROR (Status)) { - return Status; - } + // + // Caller should pass in either Image Handle or Image Path, but not both. + // + ASSERT ((DriverImageHandle == NULL) || (DriverImagePath == NULL)); - Node = AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST)); + Node = AllocateZeroPool (sizeof (PCI_DRIVER_OVERRIDE_LIST)); if (Node == NULL) { return EFI_OUT_OF_RESOURCES; } Node->Signature = DRIVER_OVERRIDE_SIGNATURE; Node->DriverImageHandle = DriverImageHandle; + Node->DriverImagePath = DuplicateDevicePath (DriverImagePath); - InsertTailList (&PciIoDevice->OptionRomDriverList, &(Node->Link)); + InsertTailList (&PciIoDevice->OptionRomDriverList, &Node->Link); PciIoDevice->BusOverride = TRUE; - - ImageContext.Handle = LoadedImage->ImageBase; - ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory; - - // - // Get information about the image - // - PeCoffLoaderGetImageInfo (&ImageContext); - return EFI_SUCCESS; }