]> git.proxmox.com Git - mirror_edk2.git/blame - EdkCompatibilityPkg/Foundation/Library/Dxe/EfiDriverLib/EfiDriverModelLib.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Dxe / EfiDriverLib / EfiDriverModelLib.c
CommitLineData
3eb9473e 1/*++\r
2\r
3Copyright (c) 2004 - 2007, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 EfiDriverModelLib.c\r
15\r
16Abstract:\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
25EFI_STATUS\r
26EfiLibInstallDriverBinding (\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
34Routine 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
42Arguments:\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
53Returns: \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
75EFI_STATUS\r
76EfiLibInstallAllDriverProtocols (\r
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
81#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
82 IN EFI_COMPONENT_NAME2_PROTOCOL * ComponentName, OPTIONAL\r
83#else\r
84 IN EFI_COMPONENT_NAME_PROTOCOL * ComponentName, OPTIONAL\r
85#endif\r
86 IN EFI_DRIVER_CONFIGURATION_PROTOCOL * DriverConfiguration, OPTIONAL\r
87 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL * DriverDiagnostics OPTIONAL\r
88 )\r
89/*++\r
90\r
91Routine Description:\r
92\r
93 Intialize a driver by installing the Driver Binding Protocol onto the \r
94 driver's DriverBindingHandle. This is typically the same as the driver's\r
95 ImageHandle, but it can be different if the driver produces multiple\r
96 DriverBinding Protocols. This function also initializes the EFI Driver\r
97 Library that initializes the global variables gST, gBS, gRT.\r
98\r
99Arguments:\r
100\r
101 ImageHandle - The image handle of the driver\r
102\r
103 SystemTable - The EFI System Table that was passed to the driver's entry point\r
104\r
105 DriverBinding - A Driver Binding Protocol instance that this driver is producing\r
106\r
107 DriverBindingHandle - The handle that DriverBinding is to be installe onto. If this\r
108 parameter is NULL, then a new handle is created.\r
109\r
110 ComponentName - A Component Name Protocol instance that this driver is producing\r
111\r
112 DriverConfiguration - A Driver Configuration Protocol instance that this driver is producing\r
113 \r
114 DriverDiagnostics - A Driver Diagnostics Protocol instance that this driver is producing\r
115\r
116Returns: \r
117\r
118 EFI_SUCCESS if all the protocols were installed onto DriverBindingHandle\r
119\r
120 Otherwise, then return status from gBS->InstallProtocolInterface()\r
121\r
122--*/\r
123{\r
124 EFI_STATUS Status;\r
125\r
126 Status = EfiLibInstallDriverBinding (ImageHandle, SystemTable, DriverBinding, DriverBindingHandle);\r
127 if (EFI_ERROR (Status)) {\r
128 return Status;\r
129 }\r
130\r
131 if (ComponentName != NULL) {\r
132 Status = gBS->InstallProtocolInterface (\r
133 &DriverBinding->DriverBindingHandle,\r
134#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
135 &gEfiComponentName2ProtocolGuid,\r
136#else\r
137 &gEfiComponentNameProtocolGuid,\r
138#endif\r
139 EFI_NATIVE_INTERFACE,\r
140 ComponentName\r
141 );\r
142 if (EFI_ERROR (Status)) {\r
143 return Status;\r
144 }\r
145 }\r
146\r
147 if (DriverConfiguration != NULL) {\r
148 Status = gBS->InstallProtocolInterface (\r
149 &DriverBinding->DriverBindingHandle,\r
150 &gEfiDriverConfigurationProtocolGuid,\r
151 EFI_NATIVE_INTERFACE,\r
152 DriverConfiguration\r
153 );\r
154 if (EFI_ERROR (Status)) {\r
155 return Status;\r
156 }\r
157 }\r
158\r
159 if (DriverDiagnostics != NULL) {\r
160 Status = gBS->InstallProtocolInterface (\r
161 &DriverBinding->DriverBindingHandle,\r
162 &gEfiDriverDiagnosticsProtocolGuid,\r
163 EFI_NATIVE_INTERFACE,\r
164 DriverDiagnostics\r
165 );\r
166 if (EFI_ERROR (Status)) {\r
167 return Status;\r
168 }\r
169 }\r
170\r
171 return EFI_SUCCESS;\r
172}\r
173\r
174EFI_STATUS\r
175EfiLibTestManagedDevice (\r
176 IN EFI_HANDLE ControllerHandle,\r
177 IN EFI_HANDLE DriverBindingHandle,\r
178 IN EFI_GUID *ManagedProtocolGuid\r
179 )\r
180/*++\r
181\r
182Routine Description:\r
183\r
184 Test to see if the controller is managed by a specific driver.\r
185\r
186Arguments:\r
187\r
188 ControllerHandle - Handle for controller to test\r
189\r
190 DriverBindingHandle - Driver binding handle for controller\r
191\r
192 ManagedProtocolGuid - The protocol guid the driver opens on controller\r
193\r
194Returns: \r
195\r
196 EFI_SUCCESS - The controller is managed by the driver\r
197\r
198 EFI_UNSUPPORTED - The controller is not managed by the driver\r
199\r
200--*/\r
201{\r
202 EFI_STATUS Status;\r
203 VOID *ManagedInterface;\r
204\r
205 Status = gBS->OpenProtocol (\r
206 ControllerHandle,\r
207 ManagedProtocolGuid,\r
208 &ManagedInterface,\r
209 DriverBindingHandle,\r
210 ControllerHandle,\r
211 EFI_OPEN_PROTOCOL_BY_DRIVER\r
212 );\r
213 if (!EFI_ERROR (Status)) {\r
214 gBS->CloseProtocol (\r
215 ControllerHandle,\r
216 ManagedProtocolGuid,\r
217 DriverBindingHandle,\r
218 ControllerHandle\r
219 );\r
220 return EFI_UNSUPPORTED;\r
221 }\r
222\r
223 if (Status != EFI_ALREADY_STARTED) {\r
224 return EFI_UNSUPPORTED;\r
225 }\r
226\r
227 return EFI_SUCCESS;\r
228}\r
229\r
230EFI_STATUS\r
231EfiLibTestChildHandle (\r
232 IN EFI_HANDLE ControllerHandle,\r
233 IN EFI_HANDLE ChildHandle,\r
234 IN EFI_GUID *ConsumedGuid\r
235 )\r
236/*++\r
237\r
238Routine Description:\r
239\r
240 Test to see if the child handle is the child of the controller\r
241\r
242Arguments:\r
243\r
244 ControllerHandle - Handle for controller (parent)\r
245\r
246 ChildHandle - Child handle to test\r
247\r
248 ConsumsedGuid - Protocol guid consumed by child from controller\r
249\r
250Returns: \r
251\r
252 EFI_SUCCESS - The child handle is the child of the controller\r
253\r
254 EFI_UNSUPPORTED - The child handle is not the child of the controller\r
255\r
256--*/\r
257{\r
258 EFI_STATUS Status;\r
259 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
260 UINTN EntryCount;\r
261 UINTN Index;\r
262\r
263 //\r
264 // Retrieve the list of agents that are consuming one of the protocols\r
265 // on ControllerHandle that the children consume\r
266 //\r
267 Status = gBS->OpenProtocolInformation (\r
268 ControllerHandle,\r
269 ConsumedGuid,\r
270 &OpenInfoBuffer,\r
271 &EntryCount\r
272 );\r
273 if (EFI_ERROR (Status)) {\r
274 return EFI_UNSUPPORTED;\r
275 }\r
276\r
277 //\r
278 // See if one of the agents is ChildHandle\r
279 //\r
280 Status = EFI_UNSUPPORTED;\r
281 for (Index = 0; Index < EntryCount; Index++) {\r
282 if (OpenInfoBuffer[Index].ControllerHandle == ChildHandle &&\r
283 OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {\r
284 Status = EFI_SUCCESS;\r
285 }\r
286 }\r
287 gBS->FreePool (OpenInfoBuffer);\r
288 return Status;\r
289}\r