2 Functions implementation for Bus Specific Driver Override protocol.
4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 Initializes a PCI Driver Override Instance.
14 @param PciIoDevice PCI Device instance.
18 InitializePciDriverOverrideInstance (
19 IN OUT PCI_IO_DEVICE
*PciIoDevice
22 PciIoDevice
->PciDriverOverride
.GetDriver
= GetDriver
;
26 Find the image handle whose path equals to ImagePath.
28 @param ImagePath Image path.
34 IN EFI_DEVICE_PATH_PROTOCOL
*ImagePath
41 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
43 EFI_HANDLE ImageHandle
;
45 Status
= gBS
->LocateHandleBuffer (
47 &gEfiLoadedImageDevicePathProtocolGuid
,
52 if (EFI_ERROR (Status
)) {
57 ImagePathSize
= GetDevicePathSize (ImagePath
);
59 for (Index
= 0; Index
< HandleNum
; Index
++) {
60 Status
= gBS
->HandleProtocol (Handles
[Index
], &gEfiLoadedImageDevicePathProtocolGuid
, (VOID
**) &DevicePath
);
61 if (EFI_ERROR (Status
)) {
64 if ((ImagePathSize
== GetDevicePathSize (DevicePath
)) &&
65 (CompareMem (ImagePath
, DevicePath
, ImagePathSize
) == 0)
67 ImageHandle
= Handles
[Index
];
77 Uses a bus specific algorithm to retrieve a driver image handle for a controller.
79 @param This A pointer to the EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL instance.
80 @param DriverImageHandle On input, a pointer to the previous driver image handle returned
81 by GetDriver(). On output, a pointer to the next driver
82 image handle. Passing in a NULL, will return the first driver
85 @retval EFI_SUCCESS A bus specific override driver is returned in DriverImageHandle.
86 @retval EFI_NOT_FOUND The end of the list of override drivers was reached.
87 A bus specific override driver is not returned in DriverImageHandle.
88 @retval EFI_INVALID_PARAMETER DriverImageHandle is not a handle that was returned on a
89 previous call to GetDriver().
95 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*This
,
96 IN OUT EFI_HANDLE
*DriverImageHandle
99 PCI_IO_DEVICE
*PciIoDevice
;
101 PCI_DRIVER_OVERRIDE_LIST
*Override
;
105 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This
);
106 ReturnNext
= (BOOLEAN
) (*DriverImageHandle
== NULL
);
107 for ( Link
= GetFirstNode (&PciIoDevice
->OptionRomDriverList
)
108 ; !IsNull (&PciIoDevice
->OptionRomDriverList
, Link
)
109 ; Link
= GetNextNode (&PciIoDevice
->OptionRomDriverList
, Link
)
112 Override
= DRIVER_OVERRIDE_FROM_LINK (Link
);
115 if (Override
->DriverImageHandle
== NULL
) {
116 Override
->DriverImageHandle
= LocateImageHandle (Override
->DriverImagePath
);
119 if (Override
->DriverImageHandle
== NULL
) {
121 // The Option ROM identified by Override->DriverImagePath is not loaded.
125 *DriverImageHandle
= Override
->DriverImageHandle
;
130 if (*DriverImageHandle
== Override
->DriverImageHandle
) {
135 ASSERT (IsNull (&PciIoDevice
->OptionRomDriverList
, Link
));
137 // ReturnNext indicates a handle match happens.
138 // If all nodes are checked without handle match happening,
139 // the DriverImageHandle should be a invalid handle.
142 return EFI_NOT_FOUND
;
144 return EFI_INVALID_PARAMETER
;
149 Add an overriding driver image.
151 @param PciIoDevice Instance of PciIo device.
152 @param DriverImageHandle Image handle of newly added driver image.
153 @param DriverImagePath Device path of newly added driver image.
155 @retval EFI_SUCCESS Successfully added driver.
156 @retval EFI_OUT_OF_RESOURCES No memory resource for new driver instance.
157 @retval other Some error occurred when locating gEfiLoadedImageProtocolGuid.
162 IN PCI_IO_DEVICE
*PciIoDevice
,
163 IN EFI_HANDLE DriverImageHandle
,
164 IN EFI_DEVICE_PATH_PROTOCOL
*DriverImagePath
167 PCI_DRIVER_OVERRIDE_LIST
*Node
;
170 // Caller should pass in either Image Handle or Image Path, but not both.
172 ASSERT ((DriverImageHandle
== NULL
) || (DriverImagePath
== NULL
));
174 Node
= AllocateZeroPool (sizeof (PCI_DRIVER_OVERRIDE_LIST
));
176 return EFI_OUT_OF_RESOURCES
;
179 Node
->Signature
= DRIVER_OVERRIDE_SIGNATURE
;
180 Node
->DriverImageHandle
= DriverImageHandle
;
181 Node
->DriverImagePath
= DuplicateDevicePath (DriverImagePath
);
183 InsertTailList (&PciIoDevice
->OptionRomDriverList
, &Node
->Link
);
185 PciIoDevice
->BusOverride
= TRUE
;