]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/PciBusNoEnumerationDxe/PciDriverOverride.c
SourceLevelDebugPkg: Fix PEI timer interrupt regression
[mirror_edk2.git] / DuetPkg / PciBusNoEnumerationDxe / PciDriverOverride.c
1 /*++
2
3 Copyright (c) 2005 - 2007, Intel Corporation. All rights reserved.<BR>
4 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
8
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.
11
12 Module Name:
13
14 PciDriverOverride.c
15
16 Abstract:
17
18 PCI Bus Driver
19
20 Revision History
21
22 --*/
23
24 #include "PciBus.h"
25
26 EFI_STATUS
27 EFIAPI
28 GetDriver(
29 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,
30 IN OUT EFI_HANDLE *DriverImageHandle
31 );
32
33
34
35 EFI_STATUS
36 InitializePciDriverOverrideInstance (
37 PCI_IO_DEVICE *PciIoDevice
38 )
39 /*++
40
41 Routine Description:
42
43 Initializes a PCI Driver Override Instance
44
45 Arguments:
46
47 Returns:
48
49 None
50
51 --*/
52
53 {
54 PciIoDevice->PciDriverOverride.GetDriver = GetDriver;
55 return EFI_SUCCESS;
56 }
57
58 EFI_STATUS
59 EFIAPI
60 GetDriver (
61 IN EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL *This,
62 IN OUT EFI_HANDLE *DriverImageHandle
63 )
64 /*++
65
66 Routine Description:
67
68 Get a overriding driver image
69
70 Arguments:
71
72 Returns:
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
117 EFI_STATUS
118 AddDriver (
119 IN PCI_IO_DEVICE *PciIoDevice,
120 IN EFI_HANDLE DriverImageHandle
121 )
122 /*++
123
124 Routine Description:
125
126 Add a overriding driver image
127
128 Arguments:
129
130 Returns:
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 }