3 Copyright (c) 2006, 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.
27 InitializePciDriverOverrideInstance (
28 PCI_IO_DEVICE
*PciIoDevice
34 Initializes a PCI Driver Override Instance
43 // TODO: PciIoDevice - add argument and description to function comment
44 // TODO: EFI_SUCCESS - add return value to function comment
46 PciIoDevice
->PciDriverOverride
.GetDriver
= GetDriver
;
53 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*This
,
54 IN OUT EFI_HANDLE
*DriverImageHandle
60 Get a overriding driver image
69 // TODO: This - add argument and description to function comment
70 // TODO: DriverImageHandle - add argument and description to function comment
71 // TODO: EFI_SUCCESS - add return value to function comment
72 // TODO: EFI_NOT_FOUND - add return value to function comment
73 // TODO: EFI_SUCCESS - add return value to function comment
74 // TODO: EFI_INVALID_PARAMETER - add return value to function comment
76 PCI_IO_DEVICE
*PciIoDevice
;
77 LIST_ENTRY
*CurrentLink
;
78 PCI_DRIVER_OVERRIDE_LIST
*Node
;
80 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This
);
82 CurrentLink
= PciIoDevice
->OptionRomDriverList
.ForwardLink
;
84 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->OptionRomDriverList
) {
86 Node
= DRIVER_OVERRIDE_FROM_LINK (CurrentLink
);
88 if (*DriverImageHandle
== NULL
) {
90 *DriverImageHandle
= Node
->DriverImageHandle
;
94 if (*DriverImageHandle
== Node
->DriverImageHandle
) {
96 if (CurrentLink
->ForwardLink
== &PciIoDevice
->OptionRomDriverList
||
97 CurrentLink
->ForwardLink
== NULL
) {
104 Node
= DRIVER_OVERRIDE_FROM_LINK (CurrentLink
->ForwardLink
);
105 *DriverImageHandle
= Node
->DriverImageHandle
;
109 CurrentLink
= CurrentLink
->ForwardLink
;
112 return EFI_INVALID_PARAMETER
;
117 IN PCI_IO_DEVICE
*PciIoDevice
,
118 IN EFI_HANDLE DriverImageHandle
124 Add a overriding driver image
133 // TODO: PciIoDevice - add argument and description to function comment
134 // TODO: DriverImageHandle - add argument and description to function comment
135 // TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
136 // TODO: EFI_SUCCESS - add return value to function comment
137 // TODO: EFI_SUCCESS - add return value to function comment
138 // TODO: EFI_SUCCESS - add return value to function comment
139 // TODO: EFI_SUCCESS - add return value to function comment
142 EFI_IMAGE_DOS_HEADER
*DosHdr
;
143 EFI_IMAGE_NT_HEADERS
*PeHdr
;
144 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
145 PCI_DRIVER_OVERRIDE_LIST
*Node
;
146 EFI_DRIVER_OS_HANDOFF_HEADER
*DriverOsHandoffHeader
;
147 EFI_DRIVER_OS_HANDOFF_HEADER
*NewDriverOsHandoffHeader
;
148 EFI_DRIVER_OS_HANDOFF
*DriverOsHandoff
;
149 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
150 EFI_HANDLE DeviceHandle
;
151 UINTN NumberOfEntries
;
155 Status
= gBS
->HandleProtocol (DriverImageHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**) &LoadedImage
);
156 if (EFI_ERROR (Status
)) {
160 Node
= AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST
));
162 return EFI_OUT_OF_RESOURCES
;
165 Node
->Signature
= DRIVER_OVERRIDE_SIGNATURE
;
166 Node
->DriverImageHandle
= DriverImageHandle
;
168 InsertTailList (&PciIoDevice
->OptionRomDriverList
, &(Node
->Link
));
170 PciIoDevice
->BusOverride
= TRUE
;
172 DosHdr
= (EFI_IMAGE_DOS_HEADER
*) LoadedImage
->ImageBase
;
173 if (DosHdr
->e_magic
!= EFI_IMAGE_DOS_SIGNATURE
) {
177 PeHdr
= (EFI_IMAGE_NT_HEADERS
*) ((UINTN
) LoadedImage
->ImageBase
+ DosHdr
->e_lfanew
);
179 if (PeHdr
->FileHeader
.Machine
!= EFI_IMAGE_MACHINE_EBC
) {
183 DriverOsHandoffHeader
= NULL
;
184 Status
= EfiGetSystemConfigurationTable (&gEfiUgaIoProtocolGuid
, (VOID
**) &DriverOsHandoffHeader
);
185 if (!EFI_ERROR (Status
) && DriverOsHandoffHeader
!= NULL
) {
186 for (Index
= 0; Index
< DriverOsHandoffHeader
->NumberOfEntries
; Index
++) {
187 DriverOsHandoff
= (EFI_DRIVER_OS_HANDOFF
*)((UINTN
)(DriverOsHandoffHeader
) +
188 DriverOsHandoffHeader
->HeaderSize
+
189 Index
* DriverOsHandoffHeader
->SizeOfEntries
);
190 DevicePath
= DriverOsHandoff
->DevicePath
;
191 Status
= gBS
->LocateDevicePath (&gEfiDevicePathProtocolGuid
, &DevicePath
, &DeviceHandle
);
192 if (!EFI_ERROR (Status
) && DeviceHandle
!= NULL
&& IsDevicePathEnd (DevicePath
)) {
193 if (DeviceHandle
== PciIoDevice
->Handle
) {
199 NumberOfEntries
= DriverOsHandoffHeader
->NumberOfEntries
+ 1;
204 Status
= gBS
->AllocatePool (
205 EfiRuntimeServicesData
,
206 sizeof (EFI_DRIVER_OS_HANDOFF_HEADER
) + NumberOfEntries
* sizeof (EFI_DRIVER_OS_HANDOFF
),
207 (VOID
**) &NewDriverOsHandoffHeader
209 if (EFI_ERROR (Status
)) {
213 if (DriverOsHandoffHeader
== NULL
) {
214 NewDriverOsHandoffHeader
->Version
= 0;
215 NewDriverOsHandoffHeader
->HeaderSize
= sizeof (EFI_DRIVER_OS_HANDOFF_HEADER
);
216 NewDriverOsHandoffHeader
->SizeOfEntries
= sizeof (EFI_DRIVER_OS_HANDOFF
);
217 NewDriverOsHandoffHeader
->NumberOfEntries
= (UINT32
) NumberOfEntries
;
220 NewDriverOsHandoffHeader
,
221 DriverOsHandoffHeader
,
222 DriverOsHandoffHeader
->HeaderSize
+ (NumberOfEntries
- 1) * DriverOsHandoffHeader
->SizeOfEntries
224 NewDriverOsHandoffHeader
->NumberOfEntries
= (UINT32
) NumberOfEntries
;
227 DriverOsHandoff
= (EFI_DRIVER_OS_HANDOFF
*)((UINTN
)NewDriverOsHandoffHeader
+
228 NewDriverOsHandoffHeader
->HeaderSize
+
229 (NumberOfEntries
- 1) * NewDriverOsHandoffHeader
->SizeOfEntries
);
232 // Fill in the EFI_DRIVER_OS_HANDOFF structure
234 DriverOsHandoff
->Type
= EfiUgaDriverFromPciRom
;
237 // Compute the size of the device path
239 Size
= GetDevicePathSize (PciIoDevice
->DevicePath
);
241 DriverOsHandoff
->DevicePath
= NULL
;
245 // Allocate space for duplicate device path
247 Status
= gBS
->AllocatePool (
248 EfiRuntimeServicesData
,
250 (VOID
**) &DriverOsHandoff
->DevicePath
252 if (EFI_ERROR (Status
)) {
253 gBS
->FreePool (NewDriverOsHandoffHeader
);
258 // Make copy of device path
260 CopyMem (DriverOsHandoff
->DevicePath
, PciIoDevice
->DevicePath
, Size
);
263 DriverOsHandoff
->PciRomSize
= (UINT64
) PciIoDevice
->PciIo
.RomSize
;
264 Status
= gBS
->AllocatePool (
265 EfiRuntimeServicesData
,
266 (UINTN
) DriverOsHandoff
->PciRomSize
,
267 (VOID
**) &DriverOsHandoff
->PciRomImage
269 if (EFI_ERROR (Status
)) {
270 gBS
->FreePool (NewDriverOsHandoffHeader
);
275 DriverOsHandoff
->PciRomImage
,
276 PciIoDevice
->PciIo
.RomImage
,
277 (UINTN
) DriverOsHandoff
->PciRomSize
280 Status
= gBS
->InstallConfigurationTable (&gEfiUgaIoProtocolGuid
, NewDriverOsHandoffHeader
);
281 if (EFI_ERROR (Status
)) {
285 if (DriverOsHandoffHeader
!= NULL
) {
286 gBS
->FreePool (DriverOsHandoffHeader
);