]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
4ea9375a HT |
3 | Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials \r | |
3eb9473e | 5 | are licensed and made available under the terms and conditions of the BSD License \r |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | EfiDriverModelLib.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Light weight lib to support EFI drivers.\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | #include "Tiano.h"\r | |
23 | #include "EfiDriverLib.h"\r | |
24 | \r | |
25 | EFI_STATUS\r | |
26 | EfiLibInstallDriverBinding (\r | |
27 | IN EFI_HANDLE ImageHandle,\r | |
28 | IN EFI_SYSTEM_TABLE *SystemTable,\r | |
29 | IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding,\r | |
30 | IN EFI_HANDLE DriverBindingHandle\r | |
31 | )\r | |
32 | /*++\r | |
33 | \r | |
34 | Routine Description:\r | |
35 | \r | |
36 | Intialize a driver by installing the Driver Binding Protocol onto the \r | |
37 | driver's DriverBindingHandle. This is typically the same as the driver's\r | |
38 | ImageHandle, but it can be different if the driver produces multiple\r | |
39 | DriverBinding Protocols. This function also initializes the EFI Driver\r | |
40 | Library that initializes the global variables gST, gBS, gRT.\r | |
41 | \r | |
42 | Arguments:\r | |
43 | \r | |
44 | ImageHandle - The image handle of the driver\r | |
45 | \r | |
46 | SystemTable - The EFI System Table that was passed to the driver's entry point\r | |
47 | \r | |
48 | DriverBinding - A Driver Binding Protocol instance that this driver is producing\r | |
49 | \r | |
50 | DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this\r | |
51 | parameter is NULL, then a new handle is created.\r | |
52 | \r | |
53 | Returns: \r | |
54 | \r | |
55 | EFI_SUCCESS is DriverBinding is installed onto DriverBindingHandle\r | |
56 | \r | |
57 | Otherwise, then return status from gBS->InstallProtocolInterface()\r | |
58 | \r | |
59 | --*/\r | |
60 | {\r | |
61 | EfiInitializeDriverLib (ImageHandle, SystemTable);\r | |
62 | \r | |
63 | DriverBinding->ImageHandle = ImageHandle;\r | |
64 | \r | |
65 | DriverBinding->DriverBindingHandle = DriverBindingHandle;\r | |
66 | \r | |
67 | return gBS->InstallProtocolInterface (\r | |
68 | &DriverBinding->DriverBindingHandle,\r | |
69 | &gEfiDriverBindingProtocolGuid,\r | |
70 | EFI_NATIVE_INTERFACE,\r | |
71 | DriverBinding\r | |
72 | );\r | |
73 | }\r | |
74 | \r | |
75 | EFI_STATUS\r | |
d850121e | 76 | InstallAllDriverProtocolsWorker (\r |
3eb9473e | 77 | IN EFI_HANDLE ImageHandle,\r |
78 | IN EFI_SYSTEM_TABLE * SystemTable,\r | |
79 | IN EFI_DRIVER_BINDING_PROTOCOL * DriverBinding,\r | |
80 | IN EFI_HANDLE DriverBindingHandle,\r | |
3eb9473e | 81 | IN EFI_COMPONENT_NAME_PROTOCOL * ComponentName, OPTIONAL\r |
d850121e | 82 | IN EFI_COMPONENT_NAME2_PROTOCOL * ComponentName2, OPTIONAL\r |
3eb9473e | 83 | IN EFI_DRIVER_CONFIGURATION_PROTOCOL * DriverConfiguration, OPTIONAL\r |
d850121e | 84 | IN EFI_DRIVER_CONFIGURATION2_PROTOCOL * DriverConfiguration2, OPTIONAL\r |
85 | IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL * DriverDiagnostics, OPTIONAL\r | |
86 | IN EFI_DRIVER_DIAGNOSTICS2_PROTOCOL * DriverDiagnostics2 OPTIONAL\r | |
3eb9473e | 87 | )\r |
88 | /*++\r | |
89 | \r | |
90 | Routine Description:\r | |
91 | \r | |
92 | Intialize a driver by installing the Driver Binding Protocol onto the \r | |
93 | driver's DriverBindingHandle. This is typically the same as the driver's\r | |
94 | ImageHandle, but it can be different if the driver produces multiple\r | |
95 | DriverBinding Protocols. This function also initializes the EFI Driver\r | |
96 | Library that initializes the global variables gST, gBS, gRT.\r | |
97 | \r | |
98 | Arguments:\r | |
99 | \r | |
100 | ImageHandle - The image handle of the driver\r | |
101 | \r | |
102 | SystemTable - The EFI System Table that was passed to the driver's entry point\r | |
103 | \r | |
104 | DriverBinding - A Driver Binding Protocol instance that this driver is producing\r | |
105 | \r | |
106 | DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this\r | |
107 | parameter is NULL, then a new handle is created.\r | |
108 | \r | |
109 | ComponentName - A Component Name Protocol instance that this driver is producing\r | |
110 | \r | |
d850121e | 111 | ComponentName2 - A Component Name2 Protocol instance that this driver is producing\r |
112 | \r | |
3eb9473e | 113 | DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing\r |
d850121e | 114 | \r |
115 | DriverConfiguration2- A Driver Configuration2 Protocol instance that this driver is producing\r | |
3eb9473e | 116 | \r |
117 | DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing\r | |
118 | \r | |
d850121e | 119 | DriverDiagnostics2 - A Driver Diagnostics2 Protocol instance that this driver is producing\r |
120 | \r | |
3eb9473e | 121 | Returns: \r |
122 | \r | |
123 | EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle\r | |
124 | \r | |
125 | Otherwise, then return status from gBS->InstallProtocolInterface()\r | |
126 | \r | |
127 | --*/\r | |
128 | {\r | |
129 | EFI_STATUS Status;\r | |
130 | \r | |
131 | Status = EfiLibInstallDriverBinding (ImageHandle, SystemTable, DriverBinding, DriverBindingHandle);\r | |
132 | if (EFI_ERROR (Status)) {\r | |
133 | return Status;\r | |
134 | }\r | |
135 | \r | |
136 | if (ComponentName != NULL) {\r | |
137 | Status = gBS->InstallProtocolInterface (\r | |
138 | &DriverBinding->DriverBindingHandle,\r | |
3eb9473e | 139 | &gEfiComponentNameProtocolGuid,\r |
3eb9473e | 140 | EFI_NATIVE_INTERFACE,\r |
141 | ComponentName\r | |
142 | );\r | |
143 | if (EFI_ERROR (Status)) {\r | |
144 | return Status;\r | |
145 | }\r | |
146 | }\r | |
147 | \r | |
d850121e | 148 | if (ComponentName2 != NULL) {\r |
149 | Status = gBS->InstallProtocolInterface (\r | |
150 | &DriverBinding->DriverBindingHandle,\r | |
151 | &gEfiComponentName2ProtocolGuid,\r | |
152 | EFI_NATIVE_INTERFACE,\r | |
153 | ComponentName2\r | |
154 | );\r | |
155 | if (EFI_ERROR (Status)) {\r | |
156 | return Status;\r | |
157 | }\r | |
158 | }\r | |
159 | \r | |
3eb9473e | 160 | if (DriverConfiguration != NULL) {\r |
161 | Status = gBS->InstallProtocolInterface (\r | |
162 | &DriverBinding->DriverBindingHandle,\r | |
163 | &gEfiDriverConfigurationProtocolGuid,\r | |
164 | EFI_NATIVE_INTERFACE,\r | |
165 | DriverConfiguration\r | |
166 | );\r | |
167 | if (EFI_ERROR (Status)) {\r | |
168 | return Status;\r | |
169 | }\r | |
170 | }\r | |
171 | \r | |
d850121e | 172 | if (DriverConfiguration2 != NULL) {\r |
173 | Status = gBS->InstallProtocolInterface (\r | |
174 | &DriverBinding->DriverBindingHandle,\r | |
175 | &gEfiDriverConfiguration2ProtocolGuid,\r | |
176 | EFI_NATIVE_INTERFACE,\r | |
177 | DriverConfiguration2\r | |
178 | );\r | |
179 | if (EFI_ERROR (Status)) {\r | |
180 | return Status;\r | |
181 | }\r | |
182 | }\r | |
183 | \r | |
3eb9473e | 184 | if (DriverDiagnostics != NULL) {\r |
185 | Status = gBS->InstallProtocolInterface (\r | |
186 | &DriverBinding->DriverBindingHandle,\r | |
187 | &gEfiDriverDiagnosticsProtocolGuid,\r | |
188 | EFI_NATIVE_INTERFACE,\r | |
189 | DriverDiagnostics\r | |
190 | );\r | |
191 | if (EFI_ERROR (Status)) {\r | |
192 | return Status;\r | |
193 | }\r | |
194 | }\r | |
195 | \r | |
d850121e | 196 | if (DriverDiagnostics2 != NULL) {\r |
197 | Status = gBS->InstallProtocolInterface (\r | |
198 | &DriverBinding->DriverBindingHandle,\r | |
199 | &gEfiDriverDiagnostics2ProtocolGuid,\r | |
200 | EFI_NATIVE_INTERFACE,\r | |
201 | DriverDiagnostics2\r | |
202 | );\r | |
203 | if (EFI_ERROR (Status)) {\r | |
204 | return Status;\r | |
205 | }\r | |
206 | }\r | |
207 | \r | |
3eb9473e | 208 | return EFI_SUCCESS;\r |
209 | }\r | |
210 | \r | |
d850121e | 211 | EFI_STATUS\r |
212 | EfiLibInstallAllDriverProtocols (\r | |
213 | IN EFI_HANDLE ImageHandle,\r | |
214 | IN EFI_SYSTEM_TABLE * SystemTable,\r | |
215 | IN EFI_DRIVER_BINDING_PROTOCOL * DriverBinding,\r | |
216 | IN EFI_HANDLE DriverBindingHandle,\r | |
217 | IN EFI_COMPONENT_NAME_PROTOCOL * ComponentName, OPTIONAL\r | |
218 | IN EFI_DRIVER_CONFIGURATION_PROTOCOL * DriverConfiguration, OPTIONAL\r | |
219 | IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL * DriverDiagnostics OPTIONAL\r | |
220 | )\r | |
221 | /*++\r | |
222 | \r | |
223 | Routine Description:\r | |
224 | \r | |
225 | Intialize a driver by installing the Driver Binding Protocol onto the \r | |
226 | driver's DriverBindingHandle. This is typically the same as the driver's\r | |
227 | ImageHandle, but it can be different if the driver produces multiple\r | |
228 | DriverBinding Protocols. This function also initializes the EFI Driver\r | |
229 | Library that initializes the global variables gST, gBS, gRT.\r | |
230 | \r | |
231 | Arguments:\r | |
232 | \r | |
233 | ImageHandle - The image handle of the driver\r | |
234 | \r | |
235 | SystemTable - The EFI System Table that was passed to the driver's entry point\r | |
236 | \r | |
237 | DriverBinding - A Driver Binding Protocol instance that this driver is producing\r | |
238 | \r | |
239 | DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this\r | |
240 | parameter is NULL, then a new handle is created.\r | |
241 | \r | |
242 | ComponentName - A Component Name Protocol instance that this driver is producing\r | |
243 | \r | |
244 | DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing\r | |
245 | \r | |
246 | DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing\r | |
247 | \r | |
248 | Returns: \r | |
249 | \r | |
250 | EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle\r | |
251 | \r | |
252 | Otherwise, then return status from gBS->InstallProtocolInterface()\r | |
253 | \r | |
254 | --*/\r | |
255 | {\r | |
256 | return InstallAllDriverProtocolsWorker (\r | |
257 | ImageHandle,\r | |
258 | SystemTable,\r | |
259 | DriverBinding,\r | |
260 | DriverBindingHandle,\r | |
261 | ComponentName,\r | |
262 | NULL,\r | |
263 | DriverConfiguration,\r | |
264 | NULL,\r | |
265 | DriverDiagnostics,\r | |
266 | NULL\r | |
267 | );\r | |
268 | }\r | |
269 | \r | |
270 | EFI_STATUS\r | |
271 | EfiLibInstallAllDriverProtocols2 (\r | |
272 | IN EFI_HANDLE ImageHandle,\r | |
273 | IN EFI_SYSTEM_TABLE * SystemTable,\r | |
274 | IN EFI_DRIVER_BINDING_PROTOCOL * DriverBinding,\r | |
275 | IN EFI_HANDLE DriverBindingHandle,\r | |
276 | IN EFI_COMPONENT_NAME2_PROTOCOL * ComponentName2, OPTIONAL\r | |
277 | IN EFI_DRIVER_CONFIGURATION2_PROTOCOL * DriverConfiguration2, OPTIONAL\r | |
278 | IN EFI_DRIVER_DIAGNOSTICS2_PROTOCOL * DriverDiagnostics2 OPTIONAL\r | |
279 | )\r | |
280 | /*++\r | |
281 | \r | |
282 | Routine Description:\r | |
283 | \r | |
284 | Intialize a driver by installing the Driver Binding Protocol onto the \r | |
285 | driver's DriverBindingHandle. This is typically the same as the driver's\r | |
286 | ImageHandle, but it can be different if the driver produces multiple\r | |
287 | DriverBinding Protocols. This function also initializes the EFI Driver\r | |
288 | Library that initializes the global variables gST, gBS, gRT.\r | |
289 | \r | |
290 | Arguments:\r | |
291 | \r | |
292 | ImageHandle - The image handle of the driver\r | |
293 | \r | |
294 | SystemTable - The EFI System Table that was passed to the driver's entry point\r | |
295 | \r | |
296 | DriverBinding - A Driver Binding Protocol instance that this driver is producing\r | |
297 | \r | |
298 | DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this\r | |
299 | parameter is NULL, then a new handle is created.\r | |
300 | \r | |
301 | ComponentName2 - A Component Name2 Protocol instance that this driver is producing\r | |
302 | \r | |
303 | DriverConfiguration2- A Driver Configuration2 Protocol instance that this driver is producing\r | |
304 | \r | |
305 | DriverDiagnostics2 - A Driver Diagnostics2 Protocol instance that this driver is producing\r | |
306 | \r | |
307 | Returns: \r | |
308 | \r | |
309 | EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle\r | |
310 | \r | |
311 | Otherwise, then return status from gBS->InstallProtocolInterface()\r | |
312 | \r | |
313 | --*/\r | |
314 | {\r | |
315 | return InstallAllDriverProtocolsWorker (\r | |
316 | ImageHandle,\r | |
317 | SystemTable,\r | |
318 | DriverBinding,\r | |
319 | DriverBindingHandle,\r | |
320 | NULL,\r | |
321 | ComponentName2,\r | |
322 | NULL,\r | |
323 | DriverConfiguration2,\r | |
324 | NULL,\r | |
325 | DriverDiagnostics2\r | |
326 | );\r | |
327 | }\r | |
328 | \r | |
3eb9473e | 329 | EFI_STATUS\r |
330 | EfiLibTestManagedDevice (\r | |
331 | IN EFI_HANDLE ControllerHandle,\r | |
332 | IN EFI_HANDLE DriverBindingHandle,\r | |
333 | IN EFI_GUID *ManagedProtocolGuid\r | |
334 | )\r | |
335 | /*++\r | |
336 | \r | |
337 | Routine Description:\r | |
338 | \r | |
339 | Test to see if the controller is managed by a specific driver.\r | |
340 | \r | |
341 | Arguments:\r | |
342 | \r | |
343 | ControllerHandle - Handle for controller to test\r | |
344 | \r | |
345 | DriverBindingHandle - Driver binding handle for controller\r | |
346 | \r | |
347 | ManagedProtocolGuid - The protocol guid the driver opens on controller\r | |
348 | \r | |
349 | Returns: \r | |
350 | \r | |
351 | EFI_SUCCESS - The controller is managed by the driver\r | |
352 | \r | |
353 | EFI_UNSUPPORTED - The controller is not managed by the driver\r | |
354 | \r | |
355 | --*/\r | |
356 | {\r | |
357 | EFI_STATUS Status;\r | |
358 | VOID *ManagedInterface;\r | |
359 | \r | |
360 | Status = gBS->OpenProtocol (\r | |
361 | ControllerHandle,\r | |
362 | ManagedProtocolGuid,\r | |
363 | &ManagedInterface,\r | |
364 | DriverBindingHandle,\r | |
365 | ControllerHandle,\r | |
366 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
367 | );\r | |
368 | if (!EFI_ERROR (Status)) {\r | |
369 | gBS->CloseProtocol (\r | |
370 | ControllerHandle,\r | |
371 | ManagedProtocolGuid,\r | |
372 | DriverBindingHandle,\r | |
373 | ControllerHandle\r | |
374 | );\r | |
375 | return EFI_UNSUPPORTED;\r | |
376 | }\r | |
377 | \r | |
378 | if (Status != EFI_ALREADY_STARTED) {\r | |
379 | return EFI_UNSUPPORTED;\r | |
380 | }\r | |
381 | \r | |
382 | return EFI_SUCCESS;\r | |
383 | }\r | |
384 | \r | |
385 | EFI_STATUS\r | |
386 | EfiLibTestChildHandle (\r | |
387 | IN EFI_HANDLE ControllerHandle,\r | |
388 | IN EFI_HANDLE ChildHandle,\r | |
389 | IN EFI_GUID *ConsumedGuid\r | |
390 | )\r | |
391 | /*++\r | |
392 | \r | |
393 | Routine Description:\r | |
394 | \r | |
395 | Test to see if the child handle is the child of the controller\r | |
396 | \r | |
397 | Arguments:\r | |
398 | \r | |
399 | ControllerHandle - Handle for controller (parent)\r | |
400 | \r | |
401 | ChildHandle - Child handle to test\r | |
402 | \r | |
403 | ConsumsedGuid - Protocol guid consumed by child from controller\r | |
404 | \r | |
405 | Returns: \r | |
406 | \r | |
407 | EFI_SUCCESS - The child handle is the child of the controller\r | |
408 | \r | |
409 | EFI_UNSUPPORTED - The child handle is not the child of the controller\r | |
410 | \r | |
411 | --*/\r | |
412 | {\r | |
413 | EFI_STATUS Status;\r | |
414 | EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r | |
415 | UINTN EntryCount;\r | |
416 | UINTN Index;\r | |
417 | \r | |
418 | //\r | |
419 | // Retrieve the list of agents that are consuming one of the protocols\r | |
420 | // on ControllerHandle that the children consume\r | |
421 | //\r | |
422 | Status = gBS->OpenProtocolInformation (\r | |
423 | ControllerHandle,\r | |
424 | ConsumedGuid,\r | |
425 | &OpenInfoBuffer,\r | |
426 | &EntryCount\r | |
427 | );\r | |
428 | if (EFI_ERROR (Status)) {\r | |
429 | return EFI_UNSUPPORTED;\r | |
430 | }\r | |
431 | \r | |
432 | //\r | |
433 | // See if one of the agents is ChildHandle\r | |
434 | //\r | |
435 | Status = EFI_UNSUPPORTED;\r | |
436 | for (Index = 0; Index < EntryCount; Index++) {\r | |
437 | if (OpenInfoBuffer[Index].ControllerHandle == ChildHandle &&\r | |
438 | OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {\r | |
439 | Status = EFI_SUCCESS;\r | |
440 | }\r | |
441 | }\r | |
442 | gBS->FreePool (OpenInfoBuffer);\r | |
443 | return Status;\r | |
444 | }\r |