3 Copyright (c) 2005 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
29 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*This
,
30 IN OUT EFI_HANDLE
*DriverImageHandle
36 InitializePciDriverOverrideInstance (
37 PCI_IO_DEVICE
*PciIoDevice
43 Initializes a PCI Driver Override Instance
54 PciIoDevice
->PciDriverOverride
.GetDriver
= GetDriver
;
61 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*This
,
62 IN OUT EFI_HANDLE
*DriverImageHandle
68 Get a overriding driver image
78 PCI_IO_DEVICE
*PciIoDevice
;
79 LIST_ENTRY
*CurrentLink
;
80 PCI_DRIVER_OVERRIDE_LIST
*Node
;
82 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This
);
84 CurrentLink
= PciIoDevice
->OptionRomDriverList
.ForwardLink
;
86 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->OptionRomDriverList
) {
88 Node
= DRIVER_OVERRIDE_FROM_LINK (CurrentLink
);
90 if (*DriverImageHandle
== NULL
) {
92 *DriverImageHandle
= Node
->DriverImageHandle
;
96 if (*DriverImageHandle
== Node
->DriverImageHandle
) {
98 if (CurrentLink
->ForwardLink
== &PciIoDevice
->OptionRomDriverList
||
99 CurrentLink
->ForwardLink
== NULL
) {
100 return EFI_NOT_FOUND
;
106 Node
= DRIVER_OVERRIDE_FROM_LINK (CurrentLink
->ForwardLink
);
107 *DriverImageHandle
= Node
->DriverImageHandle
;
111 CurrentLink
= CurrentLink
->ForwardLink
;
114 return EFI_INVALID_PARAMETER
;
119 IN PCI_IO_DEVICE
*PciIoDevice
,
120 IN EFI_HANDLE DriverImageHandle
126 Add a overriding driver image
138 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
139 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
140 PCI_DRIVER_OVERRIDE_LIST
*Node
;
141 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
142 EFI_DRIVER_OS_HANDOFF_HEADER
*DriverOsHandoffHeader
;
143 EFI_DRIVER_OS_HANDOFF_HEADER
*NewDriverOsHandoffHeader
;
144 EFI_DRIVER_OS_HANDOFF
*DriverOsHandoff
;
145 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
146 EFI_HANDLE DeviceHandle
;
147 UINTN NumberOfEntries
;
152 Status
= gBS
->HandleProtocol (DriverImageHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**) &LoadedImage
);
153 if (EFI_ERROR (Status
)) {
157 Node
= AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST
));
159 return EFI_OUT_OF_RESOURCES
;
162 Node
->Signature
= DRIVER_OVERRIDE_SIGNATURE
;
163 Node
->DriverImageHandle
= DriverImageHandle
;
165 InsertTailList (&PciIoDevice
->OptionRomDriverList
, &(Node
->Link
));
167 PciIoDevice
->BusOverride
= TRUE
;
170 ImageContext
.Handle
= LoadedImage
->ImageBase
;
171 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
174 // Get information about the image
176 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
177 if (EFI_ERROR (Status
)) {
181 if (ImageContext
.Machine
!= EFI_IMAGE_MACHINE_EBC
) {
185 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
186 DriverOsHandoffHeader
= NULL
;
187 Status
= EfiLibGetSystemConfigurationTable (&gEfiUgaIoProtocolGuid
, (VOID
**) &DriverOsHandoffHeader
);
188 if (!EFI_ERROR (Status
) && DriverOsHandoffHeader
!= NULL
) {
189 for (Index
= 0; Index
< DriverOsHandoffHeader
->NumberOfEntries
; Index
++) {
190 DriverOsHandoff
= (EFI_DRIVER_OS_HANDOFF
*)((UINTN
)(DriverOsHandoffHeader
) +
191 DriverOsHandoffHeader
->HeaderSize
+
192 Index
* DriverOsHandoffHeader
->SizeOfEntries
);
193 DevicePath
= DriverOsHandoff
->DevicePath
;
194 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &DevicePath
, &DeviceHandle
);
195 if (!EFI_ERROR (Status
) && DeviceHandle
!= NULL
&& IsDevicePathEnd (DevicePath
)) {
196 if (DeviceHandle
== PciIoDevice
->Handle
) {
202 NumberOfEntries
= DriverOsHandoffHeader
->NumberOfEntries
+ 1;
207 Status
= gBS
->AllocatePool (
208 EfiRuntimeServicesData
,
209 sizeof (EFI_DRIVER_OS_HANDOFF_HEADER
) + NumberOfEntries
* sizeof (EFI_DRIVER_OS_HANDOFF
),
210 (VOID
**) &NewDriverOsHandoffHeader
212 if (EFI_ERROR (Status
)) {
216 if (DriverOsHandoffHeader
== NULL
) {
217 NewDriverOsHandoffHeader
->Version
= 0;
218 NewDriverOsHandoffHeader
->HeaderSize
= sizeof (EFI_DRIVER_OS_HANDOFF_HEADER
);
219 NewDriverOsHandoffHeader
->SizeOfEntries
= sizeof (EFI_DRIVER_OS_HANDOFF
);
220 NewDriverOsHandoffHeader
->NumberOfEntries
= (UINT32
) NumberOfEntries
;
223 NewDriverOsHandoffHeader
,
224 DriverOsHandoffHeader
,
225 DriverOsHandoffHeader
->HeaderSize
+ (NumberOfEntries
- 1) * DriverOsHandoffHeader
->SizeOfEntries
227 NewDriverOsHandoffHeader
->NumberOfEntries
= (UINT32
) NumberOfEntries
;
230 DriverOsHandoff
= (EFI_DRIVER_OS_HANDOFF
*)((UINTN
)NewDriverOsHandoffHeader
+
231 NewDriverOsHandoffHeader
->HeaderSize
+
232 (NumberOfEntries
- 1) * NewDriverOsHandoffHeader
->SizeOfEntries
);
235 // Fill in the EFI_DRIVER_OS_HANDOFF structure
237 DriverOsHandoff
->Type
= EfiUgaDriverFromPciRom
;
240 // Compute the size of the device path
242 Size
= EfiDevicePathSize (PciIoDevice
->DevicePath
);
244 DriverOsHandoff
->DevicePath
= NULL
;
248 // Allocate space for duplicate device path
250 Status
= gBS
->AllocatePool (
251 EfiRuntimeServicesData
,
253 (VOID
**) &DriverOsHandoff
->DevicePath
255 if (EFI_ERROR (Status
)) {
256 gBS
->FreePool (NewDriverOsHandoffHeader
);
261 // Make copy of device path
263 CopyMem (DriverOsHandoff
->DevicePath
, PciIoDevice
->DevicePath
, Size
);
266 DriverOsHandoff
->PciRomSize
= (UINT64
) PciIoDevice
->PciIo
.RomSize
;
267 Status
= gBS
->AllocatePool (
268 EfiRuntimeServicesData
,
269 (UINTN
) DriverOsHandoff
->PciRomSize
,
270 (VOID
**) &DriverOsHandoff
->PciRomImage
272 if (EFI_ERROR (Status
)) {
273 gBS
->FreePool (NewDriverOsHandoffHeader
);
278 DriverOsHandoff
->PciRomImage
,
279 PciIoDevice
->PciIo
.RomImage
,
280 (UINTN
) DriverOsHandoff
->PciRomSize
283 Status
= gBS
->InstallConfigurationTable (&gEfiUgaIoProtocolGuid
, NewDriverOsHandoffHeader
);
284 if (EFI_ERROR (Status
)) {
288 if (DriverOsHandoffHeader
!= NULL
) {
289 gBS
->FreePool (DriverOsHandoffHeader
);