]> git.proxmox.com Git - mirror_edk2.git/blame - CorebootModulePkg/PciBusNoEnumerationDxe/PciDriverOverride.c
CorebootModulePkg: Remove DuetPkg references
[mirror_edk2.git] / CorebootModulePkg / PciBusNoEnumerationDxe / PciDriverOverride.c
CommitLineData
81a23a0f
LL
1/*++
2
3Copyright (c) 2005 - 2007, Intel Corporation. All rights reserved.<BR>
4This program and the accompanying materials
5are licensed and made available under the terms and conditions of the BSD License
6which accompanies this distribution. The full text of the license may be found at
7http://opensource.org/licenses/bsd-license.php
8
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12Module Name:
13
14 PciDriverOverride.c
15
16Abstract:
17
18 PCI Bus Driver
19
20Revision History
21
22--*/
23
24#include "PciBus.h"
25
26EFI_STATUS
27EFIAPI
28GetDriver(
29 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,
30 IN OUT EFI_HANDLE *DriverImageHandle
31 );
32
33
34
35EFI_STATUS
36InitializePciDriverOverrideInstance (
37 PCI_IO_DEVICE *PciIoDevice
38 )
39/*++
40
41Routine Description:
42
43 Initializes a PCI Driver Override Instance
44
45Arguments:
46
47Returns:
48
49 None
50
51--*/
52
53{
54 PciIoDevice->PciDriverOverride.GetDriver = GetDriver;
55 return EFI_SUCCESS;
56}
57
58EFI_STATUS
59EFIAPI
60GetDriver (
61 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,
62 IN OUT EFI_HANDLE *DriverImageHandle
63 )
64/*++
65
66Routine Description:
67
68 Get a overriding driver image
69
70Arguments:
71
72Returns:
73
74 None
75
76--*/
77{
78 PCI_IO_DEVICE *PciIoDevice;
79 LIST_ENTRY *CurrentLink;
80 PCI_DRIVER_OVERRIDE_LIST *Node;
81
82 PciIoDevice = PCI_IO_DEVICE_FROM_PCI_DRIVER_OVERRIDE_THIS (This);
83
84 CurrentLink = PciIoDevice->OptionRomDriverList.ForwardLink;
85
86 while (CurrentLink && CurrentLink != &PciIoDevice->OptionRomDriverList) {
87
88 Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink);
89
90 if (*DriverImageHandle == NULL) {
91
92 *DriverImageHandle = Node->DriverImageHandle;
93 return EFI_SUCCESS;
94 }
95
96 if (*DriverImageHandle == Node->DriverImageHandle) {
97
98 if (CurrentLink->ForwardLink == &PciIoDevice->OptionRomDriverList ||
99 CurrentLink->ForwardLink == NULL) {
100 return EFI_NOT_FOUND;
101 }
102
103 //
104 // Get next node
105 //
106 Node = DRIVER_OVERRIDE_FROM_LINK (CurrentLink->ForwardLink);
107 *DriverImageHandle = Node->DriverImageHandle;
108 return EFI_SUCCESS;
109 }
110
111 CurrentLink = CurrentLink->ForwardLink;
112 }
113
114 return EFI_INVALID_PARAMETER;
115}
116
117EFI_STATUS
118AddDriver (
119 IN PCI_IO_DEVICE *PciIoDevice,
120 IN EFI_HANDLE DriverImageHandle
121 )
122/*++
123
124Routine Description:
125
126 Add a overriding driver image
127
128Arguments:
129
130Returns:
131
132 None
133
134--*/
135
136{
137 EFI_STATUS Status;
138 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
139 PE_COFF_LOADER_IMAGE_CONTEXT ImageContext;
140 PCI_DRIVER_OVERRIDE_LIST *Node;
141
142 Status = gBS->HandleProtocol (DriverImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &LoadedImage);
143 if (EFI_ERROR (Status)) {
144 return Status;
145 }
146
147 Node = AllocatePool (sizeof (PCI_DRIVER_OVERRIDE_LIST));
148 if (Node == NULL) {
149 return EFI_OUT_OF_RESOURCES;
150 }
151
152 Node->Signature = DRIVER_OVERRIDE_SIGNATURE;
153 Node->DriverImageHandle = DriverImageHandle;
154
155 InsertTailList (&PciIoDevice->OptionRomDriverList, &(Node->Link));
156
157 PciIoDevice->BusOverride = TRUE;
158
159
160 ImageContext.Handle = LoadedImage->ImageBase;
161 ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
162
163 //
164 // Get information about the image
165 //
166 Status = PeCoffLoaderGetImageInfo (&ImageContext);
167 if (EFI_ERROR (Status)) {
168 return EFI_SUCCESS;
169 }
170
171 if (ImageContext.Machine != EFI_IMAGE_MACHINE_EBC) {
172 return EFI_SUCCESS;
173 }
174
175 return EFI_SUCCESS;
176}