]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/Dxe/EfiDriverLib/EfiDriverModelLib.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Dxe / EfiDriverLib / EfiDriverModelLib.c
1 /*++
2
3 Copyright (c) 2004 - 2007, 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
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 EfiDriverModelLib.c
15
16 Abstract:
17
18 Light weight lib to support EFI drivers.
19
20 --*/
21
22 #include "Tiano.h"
23 #include "EfiDriverLib.h"
24
25 EFI_STATUS
26 EfiLibInstallDriverBinding (
27 IN EFI_HANDLE ImageHandle,
28 IN EFI_SYSTEM_TABLE *SystemTable,
29 IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,
30 IN EFI_HANDLE DriverBindingHandle
31 )
32 /*++
33
34 Routine Description:
35
36 Intialize a driver by installing the Driver Binding Protocol onto the
37 driver's DriverBindingHandle. This is typically the same as the driver's
38 ImageHandle, but it can be different if the driver produces multiple
39 DriverBinding Protocols. This function also initializes the EFI Driver
40 Library that initializes the global variables gST, gBS, gRT.
41
42 Arguments:
43
44 ImageHandle - The image handle of the driver
45
46 SystemTable - The EFI System Table that was passed to the driver's entry point
47
48 DriverBinding - A Driver Binding Protocol instance that this driver is producing
49
50 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
51 parameter is NULL, then a new handle is created.
52
53 Returns:
54
55 EFI_SUCCESS is DriverBinding is installed onto DriverBindingHandle
56
57 Otherwise, then return status from gBS->InstallProtocolInterface()
58
59 --*/
60 {
61 EfiInitializeDriverLib (ImageHandle, SystemTable);
62
63 DriverBinding->ImageHandle = ImageHandle;
64
65 DriverBinding->DriverBindingHandle = DriverBindingHandle;
66
67 return gBS->InstallProtocolInterface (
68 &DriverBinding->DriverBindingHandle,
69 &gEfiDriverBindingProtocolGuid,
70 EFI_NATIVE_INTERFACE,
71 DriverBinding
72 );
73 }
74
75 EFI_STATUS
76 EfiLibInstallAllDriverProtocols (
77 IN EFI_HANDLE ImageHandle,
78 IN EFI_SYSTEM_TABLE * SystemTable,
79 IN EFI_DRIVER_BINDING_PROTOCOL * DriverBinding,
80 IN EFI_HANDLE DriverBindingHandle,
81 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
82 IN EFI_COMPONENT_NAME2_PROTOCOL * ComponentName, OPTIONAL
83 #else
84 IN EFI_COMPONENT_NAME_PROTOCOL * ComponentName, OPTIONAL
85 #endif
86 IN EFI_DRIVER_CONFIGURATION_PROTOCOL * DriverConfiguration, OPTIONAL
87 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL * DriverDiagnostics OPTIONAL
88 )
89 /*++
90
91 Routine Description:
92
93 Intialize a driver by installing the Driver Binding Protocol onto the
94 driver's DriverBindingHandle. This is typically the same as the driver's
95 ImageHandle, but it can be different if the driver produces multiple
96 DriverBinding Protocols. This function also initializes the EFI Driver
97 Library that initializes the global variables gST, gBS, gRT.
98
99 Arguments:
100
101 ImageHandle - The image handle of the driver
102
103 SystemTable - The EFI System Table that was passed to the driver's entry point
104
105 DriverBinding - A Driver Binding Protocol instance that this driver is producing
106
107 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
108 parameter is NULL, then a new handle is created.
109
110 ComponentName - A Component Name Protocol instance that this driver is producing
111
112 DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing
113
114 DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing
115
116 Returns:
117
118 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
119
120 Otherwise, then return status from gBS->InstallProtocolInterface()
121
122 --*/
123 {
124 EFI_STATUS Status;
125
126 Status = EfiLibInstallDriverBinding (ImageHandle, SystemTable, DriverBinding, DriverBindingHandle);
127 if (EFI_ERROR (Status)) {
128 return Status;
129 }
130
131 if (ComponentName != NULL) {
132 Status = gBS->InstallProtocolInterface (
133 &DriverBinding->DriverBindingHandle,
134 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
135 &gEfiComponentName2ProtocolGuid,
136 #else
137 &gEfiComponentNameProtocolGuid,
138 #endif
139 EFI_NATIVE_INTERFACE,
140 ComponentName
141 );
142 if (EFI_ERROR (Status)) {
143 return Status;
144 }
145 }
146
147 if (DriverConfiguration != NULL) {
148 Status = gBS->InstallProtocolInterface (
149 &DriverBinding->DriverBindingHandle,
150 &gEfiDriverConfigurationProtocolGuid,
151 EFI_NATIVE_INTERFACE,
152 DriverConfiguration
153 );
154 if (EFI_ERROR (Status)) {
155 return Status;
156 }
157 }
158
159 if (DriverDiagnostics != NULL) {
160 Status = gBS->InstallProtocolInterface (
161 &DriverBinding->DriverBindingHandle,
162 &gEfiDriverDiagnosticsProtocolGuid,
163 EFI_NATIVE_INTERFACE,
164 DriverDiagnostics
165 );
166 if (EFI_ERROR (Status)) {
167 return Status;
168 }
169 }
170
171 return EFI_SUCCESS;
172 }
173
174 EFI_STATUS
175 EfiLibTestManagedDevice (
176 IN EFI_HANDLE ControllerHandle,
177 IN EFI_HANDLE DriverBindingHandle,
178 IN EFI_GUID *ManagedProtocolGuid
179 )
180 /*++
181
182 Routine Description:
183
184 Test to see if the controller is managed by a specific driver.
185
186 Arguments:
187
188 ControllerHandle - Handle for controller to test
189
190 DriverBindingHandle - Driver binding handle for controller
191
192 ManagedProtocolGuid - The protocol guid the driver opens on controller
193
194 Returns:
195
196 EFI_SUCCESS - The controller is managed by the driver
197
198 EFI_UNSUPPORTED - The controller is not managed by the driver
199
200 --*/
201 {
202 EFI_STATUS Status;
203 VOID *ManagedInterface;
204
205 Status = gBS->OpenProtocol (
206 ControllerHandle,
207 ManagedProtocolGuid,
208 &ManagedInterface,
209 DriverBindingHandle,
210 ControllerHandle,
211 EFI_OPEN_PROTOCOL_BY_DRIVER
212 );
213 if (!EFI_ERROR (Status)) {
214 gBS->CloseProtocol (
215 ControllerHandle,
216 ManagedProtocolGuid,
217 DriverBindingHandle,
218 ControllerHandle
219 );
220 return EFI_UNSUPPORTED;
221 }
222
223 if (Status != EFI_ALREADY_STARTED) {
224 return EFI_UNSUPPORTED;
225 }
226
227 return EFI_SUCCESS;
228 }
229
230 EFI_STATUS
231 EfiLibTestChildHandle (
232 IN EFI_HANDLE ControllerHandle,
233 IN EFI_HANDLE ChildHandle,
234 IN EFI_GUID *ConsumedGuid
235 )
236 /*++
237
238 Routine Description:
239
240 Test to see if the child handle is the child of the controller
241
242 Arguments:
243
244 ControllerHandle - Handle for controller (parent)
245
246 ChildHandle - Child handle to test
247
248 ConsumsedGuid - Protocol guid consumed by child from controller
249
250 Returns:
251
252 EFI_SUCCESS - The child handle is the child of the controller
253
254 EFI_UNSUPPORTED - The child handle is not the child of the controller
255
256 --*/
257 {
258 EFI_STATUS Status;
259 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
260 UINTN EntryCount;
261 UINTN Index;
262
263 //
264 // Retrieve the list of agents that are consuming one of the protocols
265 // on ControllerHandle that the children consume
266 //
267 Status = gBS->OpenProtocolInformation (
268 ControllerHandle,
269 ConsumedGuid,
270 &OpenInfoBuffer,
271 &EntryCount
272 );
273 if (EFI_ERROR (Status)) {
274 return EFI_UNSUPPORTED;
275 }
276
277 //
278 // See if one of the agents is ChildHandle
279 //
280 Status = EFI_UNSUPPORTED;
281 for (Index = 0; Index < EntryCount; Index++) {
282 if (OpenInfoBuffer[Index].ControllerHandle == ChildHandle &&
283 OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
284 Status = EFI_SUCCESS;
285 }
286 }
287 gBS->FreePool (OpenInfoBuffer);
288 return Status;
289 }