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.
18 Initializes a PCI Driver Override Instance.
20 @param PciIoDevice Device instance.
24 InitializePciDriverOverrideInstance (
25 PCI_IO_DEVICE
*PciIoDevice
28 PciIoDevice
->PciDriverOverride
.GetDriver
= GetDriver
;
32 Get a overriding driver image.
33 @param This Pointer to instance of EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL.
34 @param DriverImageHandle Override driver image.
36 @retval EFI_SUCCESS Success to get driver image handle.
37 @retval EFI_NOT_FOUND can not find override driver image.
38 @retval EFI_INVALID_PARAMETER Invalid parameter.
43 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*This
,
44 IN OUT EFI_HANDLE
*DriverImageHandle
47 PCI_IO_DEVICE
*PciIoDevice
;
48 LIST_ENTRY
*CurrentLink
;
49 PCI_DRIVER_OVERRIDE_LIST
*Node
;
51 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This
);
53 CurrentLink
= PciIoDevice
->OptionRomDriverList
.ForwardLink
;
55 while (CurrentLink
!= NULL
&& CurrentLink
!= &PciIoDevice
->OptionRomDriverList
) {
57 Node
= DRIVER_OVERRIDE_FROM_LINK (CurrentLink
);
59 if (*DriverImageHandle
== NULL
) {
61 *DriverImageHandle
= Node
->DriverImageHandle
;
65 if (*DriverImageHandle
== Node
->DriverImageHandle
) {
67 if (CurrentLink
->ForwardLink
== &PciIoDevice
->OptionRomDriverList
||
68 CurrentLink
->ForwardLink
== NULL
) {
75 Node
= DRIVER_OVERRIDE_FROM_LINK (CurrentLink
->ForwardLink
);
76 *DriverImageHandle
= Node
->DriverImageHandle
;
80 CurrentLink
= CurrentLink
->ForwardLink
;
83 return EFI_INVALID_PARAMETER
;
87 Add an overriding driver image
89 @param PciIoDevice Instance of PciIo device.
90 @param DriverImageHandle new added driver image.
92 @retval EFI_OUT_OF_RESOURCES no memory resource for new driver instance.
93 @retval EFI_SUCCESS Success add driver.
97 IN PCI_IO_DEVICE
*PciIoDevice
,
98 IN EFI_HANDLE DriverImageHandle
102 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
103 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext
;
104 PCI_DRIVER_OVERRIDE_LIST
*Node
;
106 Status
= gBS
->HandleProtocol (DriverImageHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**) &LoadedImage
);
107 if (EFI_ERROR (Status
)) {
111 Node
= AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST
));
113 return EFI_OUT_OF_RESOURCES
;
116 Node
->Signature
= DRIVER_OVERRIDE_SIGNATURE
;
117 Node
->DriverImageHandle
= DriverImageHandle
;
119 InsertTailList (&PciIoDevice
->OptionRomDriverList
, &(Node
->Link
));
121 PciIoDevice
->BusOverride
= TRUE
;
123 ImageContext
.Handle
= LoadedImage
->ImageBase
;
124 ImageContext
.ImageRead
= PeCoffLoaderImageReadFromMemory
;
127 // Get information about the image
129 Status
= PeCoffLoaderGetImageInfo (&ImageContext
);
130 if (EFI_ERROR (Status
)) {
134 if (ImageContext
.Machine
!= EFI_IMAGE_MACHINE_EBC
) {