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
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 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
84 IN EFI_COMPONENT_NAME_PROTOCOL
* ComponentName
, OPTIONAL
86 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
* DriverConfiguration
, OPTIONAL
87 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
* DriverDiagnostics OPTIONAL
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.
101 ImageHandle - The image handle of the driver
103 SystemTable - The EFI System Table that was passed to the driver's entry point
105 DriverBinding - A Driver Binding Protocol instance that this driver is producing
107 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this
108 parameter is NULL, then a new handle is created.
110 ComponentName - A Component Name Protocol instance that this driver is producing
112 DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing
114 DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing
118 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle
120 Otherwise, then return status from gBS->InstallProtocolInterface()
126 Status
= EfiLibInstallDriverBinding (ImageHandle
, SystemTable
, DriverBinding
, DriverBindingHandle
);
127 if (EFI_ERROR (Status
)) {
131 if (ComponentName
!= NULL
) {
132 Status
= gBS
->InstallProtocolInterface (
133 &DriverBinding
->DriverBindingHandle
,
134 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
135 &gEfiComponentName2ProtocolGuid
,
137 &gEfiComponentNameProtocolGuid
,
139 EFI_NATIVE_INTERFACE
,
142 if (EFI_ERROR (Status
)) {
147 if (DriverConfiguration
!= NULL
) {
148 Status
= gBS
->InstallProtocolInterface (
149 &DriverBinding
->DriverBindingHandle
,
150 &gEfiDriverConfigurationProtocolGuid
,
151 EFI_NATIVE_INTERFACE
,
154 if (EFI_ERROR (Status
)) {
159 if (DriverDiagnostics
!= NULL
) {
160 Status
= gBS
->InstallProtocolInterface (
161 &DriverBinding
->DriverBindingHandle
,
162 &gEfiDriverDiagnosticsProtocolGuid
,
163 EFI_NATIVE_INTERFACE
,
166 if (EFI_ERROR (Status
)) {
175 EfiLibTestManagedDevice (
176 IN EFI_HANDLE ControllerHandle
,
177 IN EFI_HANDLE DriverBindingHandle
,
178 IN EFI_GUID
*ManagedProtocolGuid
184 Test to see if the controller is managed by a specific driver.
188 ControllerHandle - Handle for controller to test
190 DriverBindingHandle - Driver binding handle for controller
192 ManagedProtocolGuid - The protocol guid the driver opens on controller
196 EFI_SUCCESS - The controller is managed by the driver
198 EFI_UNSUPPORTED - The controller is not managed by the driver
203 VOID
*ManagedInterface
;
205 Status
= gBS
->OpenProtocol (
211 EFI_OPEN_PROTOCOL_BY_DRIVER
213 if (!EFI_ERROR (Status
)) {
220 return EFI_UNSUPPORTED
;
223 if (Status
!= EFI_ALREADY_STARTED
) {
224 return EFI_UNSUPPORTED
;
231 EfiLibTestChildHandle (
232 IN EFI_HANDLE ControllerHandle
,
233 IN EFI_HANDLE ChildHandle
,
234 IN EFI_GUID
*ConsumedGuid
240 Test to see if the child handle is the child of the controller
244 ControllerHandle - Handle for controller (parent)
246 ChildHandle - Child handle to test
248 ConsumsedGuid - Protocol guid consumed by child from controller
252 EFI_SUCCESS - The child handle is the child of the controller
254 EFI_UNSUPPORTED - The child handle is not the child of the controller
259 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfoBuffer
;
264 // Retrieve the list of agents that are consuming one of the protocols
265 // on ControllerHandle that the children consume
267 Status
= gBS
->OpenProtocolInformation (
273 if (EFI_ERROR (Status
)) {
274 return EFI_UNSUPPORTED
;
278 // See if one of the agents is ChildHandle
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
;
287 gBS
->FreePool (OpenInfoBuffer
);