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
22 @retval EFI_SUCCESS Operation success
25 InitializePciDriverOverrideInstance (
26 PCI_IO_DEVICE
*PciIoDevice
29 PciIoDevice
->PciDriverOverride
.GetDriver
= GetDriver
;
34 Get a overriding driver image
35 @param This Pointer to instance of EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
36 @param DriverImageHandle Override driver image,
38 @retval EFI_SUCCESS Success to get driver image handle
39 @retval EFI_NOT_FOUND can not find override driver image
40 @retval EFI_INVALID_PARAMETER Invalid parameter
45 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL
*This
,
46 IN OUT EFI_HANDLE
*DriverImageHandle
49 PCI_IO_DEVICE
*PciIoDevice
;
50 LIST_ENTRY
*CurrentLink
;
51 PCI_DRIVER_OVERRIDE_LIST
*Node
;
53 PciIoDevice
= PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This
);
55 CurrentLink
= PciIoDevice
->OptionRomDriverList
.ForwardLink
;
57 while (CurrentLink
&& CurrentLink
!= &PciIoDevice
->OptionRomDriverList
) {
59 Node
= DRIVER_OVERRIDE_FROM_LINK (CurrentLink
);
61 if (*DriverImageHandle
== NULL
) {
63 *DriverImageHandle
= Node
->DriverImageHandle
;
67 if (*DriverImageHandle
== Node
->DriverImageHandle
) {
69 if (CurrentLink
->ForwardLink
== &PciIoDevice
->OptionRomDriverList
||
70 CurrentLink
->ForwardLink
== NULL
) {
77 Node
= DRIVER_OVERRIDE_FROM_LINK (CurrentLink
->ForwardLink
);
78 *DriverImageHandle
= Node
->DriverImageHandle
;
82 CurrentLink
= CurrentLink
->ForwardLink
;
85 return EFI_INVALID_PARAMETER
;
89 Add an overriding driver image
91 @param PciIoDevice Instance of PciIo device
92 @param DriverImageHandle new added driver image
94 @retval EFI_OUT_OF_RESOURCES no memory resource for new driver instance
95 @retval EFI_SUCCESS Success add driver
99 IN PCI_IO_DEVICE
*PciIoDevice
,
100 IN EFI_HANDLE DriverImageHandle
104 EFI_IMAGE_DOS_HEADER
*DosHdr
;
105 EFI_IMAGE_NT_HEADERS
*PeHdr
;
106 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
107 PCI_DRIVER_OVERRIDE_LIST
*Node
;
109 Status
= gBS
->HandleProtocol (DriverImageHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**) &LoadedImage
);
110 if (EFI_ERROR (Status
)) {
114 Node
= AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST
));
116 return EFI_OUT_OF_RESOURCES
;
119 Node
->Signature
= DRIVER_OVERRIDE_SIGNATURE
;
120 Node
->DriverImageHandle
= DriverImageHandle
;
122 InsertTailList (&PciIoDevice
->OptionRomDriverList
, &(Node
->Link
));
124 PciIoDevice
->BusOverride
= TRUE
;
126 DosHdr
= (EFI_IMAGE_DOS_HEADER
*) LoadedImage
->ImageBase
;
127 if (DosHdr
->e_magic
!= EFI_IMAGE_DOS_SIGNATURE
) {
131 PeHdr
= (EFI_IMAGE_NT_HEADERS
*) ((UINTN
) LoadedImage
->ImageBase
+ DosHdr
->e_lfanew
);
133 if (PeHdr
->FileHeader
.Machine
!= EFI_IMAGE_MACHINE_EBC
) {