2 Functions implementation for Bus Specific Driver Override protoocl.
4 Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Initializes a PCI Driver Override Instance.
20 @param PciIoDevice PCI Device instance.
24 InitializePciDriverOverrideInstance (
25 IN OUT PCI_IO_DEVICE
*PciIoDevice
28 PciIoDevice
->PciDriverOverride
.GetDriver
= GetDriver
;
33 Uses a bus specific algorithm to retrieve a driver image handle for a controller.
35 @param This A pointer to the EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL instance.
36 @param DriverImageHandle On input, a pointer to the previous driver image handle returned
37 by GetDriver(). On output, a pointer to the next driver
38 image handle. Passing in a NULL, will return the first driver
41 @retval EFI_SUCCESS A bus specific override driver is returned in DriverImageHandle.
42 @retval EFI_NOT_FOUND The end of the list of override drivers was reached.
43 A bus specific override driver is not returned in DriverImageHandle.
44 @retval EFI_INVALID_PARAMETER DriverImageHandle is not a handle that was returned on a
45 previous call to GetDriver().
51 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*This
,
52 IN OUT EFI_HANDLE
*DriverImageHandle
55 PCI_IO_DEVICE
*PciIoDevice
;
56 LIST_ENTRY
*CurrentLink
;
57 PCI_DRIVER_OVERRIDE_LIST
*Node
;
59 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This
);
61 CurrentLink
= PciIoDevice
->OptionRomDriverList
.ForwardLink
;
63 while (CurrentLink
!= NULL
&& CurrentLink
!= &PciIoDevice
->OptionRomDriverList
) {
65 Node
= DRIVER_OVERRIDE_FROM_LINK (CurrentLink
);
67 if (*DriverImageHandle
== NULL
) {
69 *DriverImageHandle
= Node
->DriverImageHandle
;
73 if (*DriverImageHandle
== Node
->DriverImageHandle
) {
75 if (CurrentLink
->ForwardLink
== &PciIoDevice
->OptionRomDriverList
||
76 CurrentLink
->ForwardLink
== NULL
) {
83 Node
= DRIVER_OVERRIDE_FROM_LINK (CurrentLink
->ForwardLink
);
84 *DriverImageHandle
= Node
->DriverImageHandle
;
88 CurrentLink
= CurrentLink
->ForwardLink
;
91 return EFI_INVALID_PARAMETER
;
95 Add an overriding driver image.
97 @param PciIoDevice Instance of PciIo device.
98 @param DriverImageHandle new added driver image.
100 @retval EFI_SUCCESS Successfully added driver.
101 @retval EFI_OUT_OF_RESOURCES No memory resource for new driver instance.
102 @retval other Some error occurred when locating gEfiLoadedImageProtocolGuid.
107 IN PCI_IO_DEVICE
*PciIoDevice
,
108 IN EFI_HANDLE DriverImageHandle
112 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
113 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
114 PCI_DRIVER_OVERRIDE_LIST
*Node
;
116 Status
= gBS
->HandleProtocol (DriverImageHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**) &LoadedImage
);
117 if (EFI_ERROR (Status
)) {
121 Node
= AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST
));
123 return EFI_OUT_OF_RESOURCES
;
126 Node
->Signature
= DRIVER_OVERRIDE_SIGNATURE
;
127 Node
->DriverImageHandle
= DriverImageHandle
;
129 InsertTailList (&PciIoDevice
->OptionRomDriverList
, &(Node
->Link
));
131 PciIoDevice
->BusOverride
= TRUE
;
133 ImageContext
.Handle
= LoadedImage
->ImageBase
;
134 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
137 // Get information about the image
139 PeCoffLoaderGetImageInfo (&ImageContext
);