2 Functions implementation for Bus Specific Driver Override protoocl.
4 Copyright (c) 2006 - 2017, 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
;
32 Find the image handle whose path equals to ImagePath.
34 @param ImagePath Image path.
40 IN EFI_DEVICE_PATH_PROTOCOL
*ImagePath
47 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
49 EFI_HANDLE ImageHandle
;
51 Status
= gBS
->LocateHandleBuffer (
53 &gEfiLoadedImageDevicePathProtocolGuid
,
58 if (EFI_ERROR (Status
)) {
63 ImagePathSize
= GetDevicePathSize (ImagePath
);
65 for (Index
= 0; Index
< HandleNum
; Index
++) {
66 Status
= gBS
->HandleProtocol (Handles
[Index
], &gEfiLoadedImageDevicePathProtocolGuid
, (VOID
**) &DevicePath
);
67 if (EFI_ERROR (Status
)) {
70 if ((ImagePathSize
== GetDevicePathSize (DevicePath
)) &&
71 (CompareMem (ImagePath
, DevicePath
, ImagePathSize
) == 0)
73 ImageHandle
= Handles
[Index
];
83 Uses a bus specific algorithm to retrieve a driver image handle for a controller.
85 @param This A pointer to the EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL instance.
86 @param DriverImageHandle On input, a pointer to the previous driver image handle returned
87 by GetDriver(). On output, a pointer to the next driver
88 image handle. Passing in a NULL, will return the first driver
91 @retval EFI_SUCCESS A bus specific override driver is returned in DriverImageHandle.
92 @retval EFI_NOT_FOUND The end of the list of override drivers was reached.
93 A bus specific override driver is not returned in DriverImageHandle.
94 @retval EFI_INVALID_PARAMETER DriverImageHandle is not a handle that was returned on a
95 previous call to GetDriver().
101 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*This
,
102 IN OUT EFI_HANDLE
*DriverImageHandle
105 PCI_IO_DEVICE
*PciIoDevice
;
107 PCI_DRIVER_OVERRIDE_LIST
*Override
;
111 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This
);
112 ReturnNext
= (BOOLEAN
) (*DriverImageHandle
== NULL
);
113 for ( Link
= GetFirstNode (&PciIoDevice
->OptionRomDriverList
)
114 ; !IsNull (&PciIoDevice
->OptionRomDriverList
, Link
)
115 ; Link
= GetNextNode (&PciIoDevice
->OptionRomDriverList
, Link
)
118 Override
= DRIVER_OVERRIDE_FROM_LINK (Link
);
121 if (Override
->DriverImageHandle
== NULL
) {
122 Override
->DriverImageHandle
= LocateImageHandle (Override
->DriverImagePath
);
125 if (Override
->DriverImageHandle
== NULL
) {
127 // The Option ROM identified by Override->DriverImagePath is not loaded.
131 *DriverImageHandle
= Override
->DriverImageHandle
;
136 if (*DriverImageHandle
== Override
->DriverImageHandle
) {
141 ASSERT (IsNull (&PciIoDevice
->OptionRomDriverList
, Link
));
143 // ReturnNext indicates a handle match happens.
144 // If all nodes are checked without handle match happening,
145 // the DriverImageHandle should be a invalid handle.
148 return EFI_NOT_FOUND
;
150 return EFI_INVALID_PARAMETER
;
155 Add an overriding driver image.
157 @param PciIoDevice Instance of PciIo device.
158 @param DriverImageHandle Image handle of newly added driver image.
159 @param DriverImagePath Device path of newly added driver image.
161 @retval EFI_SUCCESS Successfully added driver.
162 @retval EFI_OUT_OF_RESOURCES No memory resource for new driver instance.
163 @retval other Some error occurred when locating gEfiLoadedImageProtocolGuid.
168 IN PCI_IO_DEVICE
*PciIoDevice
,
169 IN EFI_HANDLE DriverImageHandle
,
170 IN EFI_DEVICE_PATH_PROTOCOL
*DriverImagePath
173 PCI_DRIVER_OVERRIDE_LIST
*Node
;
176 // Caller should pass in either Image Handle or Image Path, but not both.
178 ASSERT ((DriverImageHandle
== NULL
) || (DriverImagePath
== NULL
));
180 Node
= AllocateZeroPool (sizeof (PCI_DRIVER_OVERRIDE_LIST
));
182 return EFI_OUT_OF_RESOURCES
;
185 Node
->Signature
= DRIVER_OVERRIDE_SIGNATURE
;
186 Node
->DriverImageHandle
= DriverImageHandle
;
187 Node
->DriverImagePath
= DuplicateDevicePath (DriverImagePath
);
189 InsertTailList (&PciIoDevice
->OptionRomDriverList
, &Node
->Link
);
191 PciIoDevice
->BusOverride
= TRUE
;