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
)) {
65 if ((ImagePathSize
== GetDevicePathSize (DevicePath
)) &&
66 (CompareMem (ImagePath
, DevicePath
, ImagePathSize
) == 0)
69 ImageHandle
= Handles
[Index
];
79 Uses a bus specific algorithm to retrieve a driver image handle for a controller.
81 @param This A pointer to the EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL instance.
82 @param DriverImageHandle On input, a pointer to the previous driver image handle returned
83 by GetDriver(). On output, a pointer to the next driver
84 image handle. Passing in a NULL, will return the first driver
87 @retval EFI_SUCCESS A bus specific override driver is returned in DriverImageHandle.
88 @retval EFI_NOT_FOUND The end of the list of override drivers was reached.
89 A bus specific override driver is not returned in DriverImageHandle.
90 @retval EFI_INVALID_PARAMETER DriverImageHandle is not a handle that was returned on a
91 previous call to GetDriver().
97 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*This
,
98 IN OUT EFI_HANDLE
*DriverImageHandle
101 PCI_IO_DEVICE
*PciIoDevice
;
103 PCI_DRIVER_OVERRIDE_LIST
*Override
;
107 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This
);
108 ReturnNext
= (BOOLEAN
)(*DriverImageHandle
== NULL
);
109 for ( Link
= GetFirstNode (&PciIoDevice
->OptionRomDriverList
)
110 ; !IsNull (&PciIoDevice
->OptionRomDriverList
, Link
)
111 ; Link
= GetNextNode (&PciIoDevice
->OptionRomDriverList
, Link
)
114 Override
= DRIVER_OVERRIDE_FROM_LINK (Link
);
117 if (Override
->DriverImageHandle
== NULL
) {
118 Override
->DriverImageHandle
= LocateImageHandle (Override
->DriverImagePath
);
121 if (Override
->DriverImageHandle
== NULL
) {
123 // The Option ROM identified by Override->DriverImagePath is not loaded.
127 *DriverImageHandle
= Override
->DriverImageHandle
;
132 if (*DriverImageHandle
== Override
->DriverImageHandle
) {
137 ASSERT (IsNull (&PciIoDevice
->OptionRomDriverList
, Link
));
139 // ReturnNext indicates a handle match happens.
140 // If all nodes are checked without handle match happening,
141 // the DriverImageHandle should be a invalid handle.
144 return EFI_NOT_FOUND
;
146 return EFI_INVALID_PARAMETER
;
151 Add an overriding driver image.
153 @param PciIoDevice Instance of PciIo device.
154 @param DriverImageHandle Image handle of newly added driver image.
155 @param DriverImagePath Device path of newly added driver image.
157 @retval EFI_SUCCESS Successfully added driver.
158 @retval EFI_OUT_OF_RESOURCES No memory resource for new driver instance.
159 @retval other Some error occurred when locating gEfiLoadedImageProtocolGuid.
164 IN PCI_IO_DEVICE
*PciIoDevice
,
165 IN EFI_HANDLE DriverImageHandle
,
166 IN EFI_DEVICE_PATH_PROTOCOL
*DriverImagePath
169 PCI_DRIVER_OVERRIDE_LIST
*Node
;
172 // Caller should pass in either Image Handle or Image Path, but not both.
174 ASSERT ((DriverImageHandle
== NULL
) || (DriverImagePath
== NULL
));
176 Node
= AllocateZeroPool (sizeof (PCI_DRIVER_OVERRIDE_LIST
));
178 return EFI_OUT_OF_RESOURCES
;
181 Node
->Signature
= DRIVER_OVERRIDE_SIGNATURE
;
182 Node
->DriverImageHandle
= DriverImageHandle
;
183 Node
->DriverImagePath
= DuplicateDevicePath (DriverImagePath
);
185 InsertTailList (&PciIoDevice
->OptionRomDriverList
, &Node
->Link
);
187 PciIoDevice
->BusOverride
= TRUE
;