3 Copyright (c) 2004 - 2008, 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 Light weight lib to support EFI drivers.
23 #include "EfiDriverLib.h"
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
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.
44 ImageHandle - The image handle of the driver
46 SystemTable - The EFI System Table that was passed to the driver's entry point
48 DriverBinding - A Driver Binding Protocol instance that this driver is producing
50 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
51 parameter is NULL, then a new handle is created.
55 EFI_SUCCESS is DriverBinding is installed onto DriverBindingHandle
57 Otherwise, then return status from gBS->InstallProtocolInterface()
61 EfiInitializeDriverLib (ImageHandle
, SystemTable
);
63 DriverBinding
->ImageHandle
= ImageHandle
;
65 DriverBinding
->DriverBindingHandle
= DriverBindingHandle
;
67 return gBS
->InstallProtocolInterface (
68 &DriverBinding
->DriverBindingHandle
,
69 &gEfiDriverBindingProtocolGuid
,
76 InstallAllDriverProtocolsWorker (
77 IN EFI_HANDLE ImageHandle
,
78 IN EFI_SYSTEM_TABLE
* SystemTable
,
79 IN EFI_DRIVER_BINDING_PROTOCOL
* DriverBinding
,
80 IN EFI_HANDLE DriverBindingHandle
,
81 IN EFI_COMPONENT_NAME_PROTOCOL
* ComponentName
, OPTIONAL
82 IN EFI_COMPONENT_NAME2_PROTOCOL
* ComponentName2
, OPTIONAL
83 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
* DriverConfiguration
, OPTIONAL
84 IN EFI_DRIVER_CONFIGURATION2_PROTOCOL
* DriverConfiguration2
, OPTIONAL
85 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
* DriverDiagnostics
, OPTIONAL
86 IN EFI_DRIVER_DIAGNOSTICS2_PROTOCOL
* DriverDiagnostics2 OPTIONAL
92 Intialize a driver by installing the Driver Binding Protocol onto the
93 driver's DriverBindingHandle. This is typically the same as the driver's
94 ImageHandle, but it can be different if the driver produces multiple
95 DriverBinding Protocols. This function also initializes the EFI Driver
96 Library that initializes the global variables gST, gBS, gRT.
100 ImageHandle - The image handle of the driver
102 SystemTable - The EFI System Table that was passed to the driver's entry point
104 DriverBinding - A Driver Binding Protocol instance that this driver is producing
106 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
107 parameter is NULL, then a new handle is created.
109 ComponentName - A Component Name Protocol instance that this driver is producing
111 ComponentName2 - A Component Name2 Protocol instance that this driver is producing
113 DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing
115 DriverConfiguration2- A Driver Configuration2 Protocol instance that this driver is producing
117 DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing
119 DriverDiagnostics2 - A Driver Diagnostics2 Protocol instance that this driver is producing
123 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
125 Otherwise, then return status from gBS->InstallProtocolInterface()
131 Status
= EfiLibInstallDriverBinding (ImageHandle
, SystemTable
, DriverBinding
, DriverBindingHandle
);
132 if (EFI_ERROR (Status
)) {
136 if (ComponentName
!= NULL
) {
137 Status
= gBS
->InstallProtocolInterface (
138 &DriverBinding
->DriverBindingHandle
,
139 &gEfiComponentNameProtocolGuid
,
140 EFI_NATIVE_INTERFACE
,
143 if (EFI_ERROR (Status
)) {
148 if (ComponentName2
!= NULL
) {
149 Status
= gBS
->InstallProtocolInterface (
150 &DriverBinding
->DriverBindingHandle
,
151 &gEfiComponentName2ProtocolGuid
,
152 EFI_NATIVE_INTERFACE
,
155 if (EFI_ERROR (Status
)) {
160 if (DriverConfiguration
!= NULL
) {
161 Status
= gBS
->InstallProtocolInterface (
162 &DriverBinding
->DriverBindingHandle
,
163 &gEfiDriverConfigurationProtocolGuid
,
164 EFI_NATIVE_INTERFACE
,
167 if (EFI_ERROR (Status
)) {
172 if (DriverConfiguration2
!= NULL
) {
173 Status
= gBS
->InstallProtocolInterface (
174 &DriverBinding
->DriverBindingHandle
,
175 &gEfiDriverConfiguration2ProtocolGuid
,
176 EFI_NATIVE_INTERFACE
,
179 if (EFI_ERROR (Status
)) {
184 if (DriverDiagnostics
!= NULL
) {
185 Status
= gBS
->InstallProtocolInterface (
186 &DriverBinding
->DriverBindingHandle
,
187 &gEfiDriverDiagnosticsProtocolGuid
,
188 EFI_NATIVE_INTERFACE
,
191 if (EFI_ERROR (Status
)) {
196 if (DriverDiagnostics2
!= NULL
) {
197 Status
= gBS
->InstallProtocolInterface (
198 &DriverBinding
->DriverBindingHandle
,
199 &gEfiDriverDiagnostics2ProtocolGuid
,
200 EFI_NATIVE_INTERFACE
,
203 if (EFI_ERROR (Status
)) {
212 EfiLibInstallAllDriverProtocols (
213 IN EFI_HANDLE ImageHandle
,
214 IN EFI_SYSTEM_TABLE
* SystemTable
,
215 IN EFI_DRIVER_BINDING_PROTOCOL
* DriverBinding
,
216 IN EFI_HANDLE DriverBindingHandle
,
217 IN EFI_COMPONENT_NAME_PROTOCOL
* ComponentName
, OPTIONAL
218 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
* DriverConfiguration
, OPTIONAL
219 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
* DriverDiagnostics OPTIONAL
225 Intialize a driver by installing the Driver Binding Protocol onto the
226 driver's DriverBindingHandle. This is typically the same as the driver's
227 ImageHandle, but it can be different if the driver produces multiple
228 DriverBinding Protocols. This function also initializes the EFI Driver
229 Library that initializes the global variables gST, gBS, gRT.
233 ImageHandle - The image handle of the driver
235 SystemTable - The EFI System Table that was passed to the driver's entry point
237 DriverBinding - A Driver Binding Protocol instance that this driver is producing
239 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
240 parameter is NULL, then a new handle is created.
242 ComponentName - A Component Name Protocol instance that this driver is producing
244 DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing
246 DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing
250 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
252 Otherwise, then return status from gBS->InstallProtocolInterface()
256 return InstallAllDriverProtocolsWorker (
271 EfiLibInstallAllDriverProtocols2 (
272 IN EFI_HANDLE ImageHandle
,
273 IN EFI_SYSTEM_TABLE
* SystemTable
,
274 IN EFI_DRIVER_BINDING_PROTOCOL
* DriverBinding
,
275 IN EFI_HANDLE DriverBindingHandle
,
276 IN EFI_COMPONENT_NAME2_PROTOCOL
* ComponentName2
, OPTIONAL
277 IN EFI_DRIVER_CONFIGURATION2_PROTOCOL
* DriverConfiguration2
, OPTIONAL
278 IN EFI_DRIVER_DIAGNOSTICS2_PROTOCOL
* DriverDiagnostics2 OPTIONAL
284 Intialize a driver by installing the Driver Binding Protocol onto the
285 driver's DriverBindingHandle. This is typically the same as the driver's
286 ImageHandle, but it can be different if the driver produces multiple
287 DriverBinding Protocols. This function also initializes the EFI Driver
288 Library that initializes the global variables gST, gBS, gRT.
292 ImageHandle - The image handle of the driver
294 SystemTable - The EFI System Table that was passed to the driver's entry point
296 DriverBinding - A Driver Binding Protocol instance that this driver is producing
298 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
299 parameter is NULL, then a new handle is created.
301 ComponentName2 - A Component Name2 Protocol instance that this driver is producing
303 DriverConfiguration2- A Driver Configuration2 Protocol instance that this driver is producing
305 DriverDiagnostics2 - A Driver Diagnostics2 Protocol instance that this driver is producing
309 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
311 Otherwise, then return status from gBS->InstallProtocolInterface()
315 return InstallAllDriverProtocolsWorker (
323 DriverConfiguration2
,
330 EfiLibTestManagedDevice (
331 IN EFI_HANDLE ControllerHandle
,
332 IN EFI_HANDLE DriverBindingHandle
,
333 IN EFI_GUID
*ManagedProtocolGuid
339 Test to see if the controller is managed by a specific driver.
343 ControllerHandle - Handle for controller to test
345 DriverBindingHandle - Driver binding handle for controller
347 ManagedProtocolGuid - The protocol guid the driver opens on controller
351 EFI_SUCCESS - The controller is managed by the driver
353 EFI_UNSUPPORTED - The controller is not managed by the driver
358 VOID
*ManagedInterface
;
360 Status
= gBS
->OpenProtocol (
366 EFI_OPEN_PROTOCOL_BY_DRIVER
368 if (!EFI_ERROR (Status
)) {
375 return EFI_UNSUPPORTED
;
378 if (Status
!= EFI_ALREADY_STARTED
) {
379 return EFI_UNSUPPORTED
;
386 EfiLibTestChildHandle (
387 IN EFI_HANDLE ControllerHandle
,
388 IN EFI_HANDLE ChildHandle
,
389 IN EFI_GUID
*ConsumedGuid
395 Test to see if the child handle is the child of the controller
399 ControllerHandle - Handle for controller (parent)
401 ChildHandle - Child handle to test
403 ConsumsedGuid - Protocol guid consumed by child from controller
407 EFI_SUCCESS - The child handle is the child of the controller
409 EFI_UNSUPPORTED - The child handle is not the child of the controller
414 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfoBuffer
;
419 // Retrieve the list of agents that are consuming one of the protocols
420 // on ControllerHandle that the children consume
422 Status
= gBS
->OpenProtocolInformation (
428 if (EFI_ERROR (Status
)) {
429 return EFI_UNSUPPORTED
;
433 // See if one of the agents is ChildHandle
435 Status
= EFI_UNSUPPORTED
;
436 for (Index
= 0; Index
< EntryCount
; Index
++) {
437 if (OpenInfoBuffer
[Index
].ControllerHandle
== ChildHandle
&&
438 OpenInfoBuffer
[Index
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) {
439 Status
= EFI_SUCCESS
;
442 gBS
->FreePool (OpenInfoBuffer
);