Commit | Line | Data |
---|---|---|
9834b6c1 RN |
1 | /** @file\r |
2 | This file consumes the ISA Host Controller protocol produced by the ISA Host\r | |
3 | Controller and installs the ISA Host Controller Service Binding protocol\r | |
4 | on the ISA Host Controller's handle.\r | |
5 | \r | |
2048c585 | 6 | Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r |
9834b6c1 RN |
7 | This program and the accompanying materials\r |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | \r | |
16 | **/\r | |
17 | \r | |
18 | #include "IsaBusDxe.h"\r | |
19 | #include "ComponentName.h"\r | |
20 | \r | |
21 | /**\r | |
22 | Tests to see if this driver supports a given controller. If a child device is provided, \r | |
23 | it further tests to see if this driver supports creating a handle for the specified child device.\r | |
24 | \r | |
25 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
26 | @param[in] ControllerHandle The handle of the controller to test. This handle \r | |
27 | must support a protocol interface that supplies \r | |
28 | an I/O abstraction to the driver.\r | |
29 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r | |
30 | parameter is ignored by device drivers, and is optional for bus \r | |
31 | drivers. For bus drivers, if this parameter is not NULL, then \r | |
32 | the bus driver must determine if the bus controller specified \r | |
33 | by ControllerHandle and the child controller specified \r | |
34 | by RemainingDevicePath are both supported by this \r | |
35 | bus driver.\r | |
36 | \r | |
37 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r | |
38 | RemainingDevicePath is supported by the driver specified by This.\r | |
39 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
40 | RemainingDevicePath is already being managed by the driver\r | |
41 | specified by This.\r | |
42 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
43 | RemainingDevicePath is already being managed by a different\r | |
44 | driver or an application that requires exclusive access.\r | |
45 | Currently not implemented.\r | |
46 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
47 | RemainingDevicePath is not supported by the driver specified by This.\r | |
48 | **/\r | |
49 | EFI_STATUS\r | |
50 | EFIAPI\r | |
51 | IsaBusDriverBindingSupported (\r | |
52 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
53 | IN EFI_HANDLE Controller,\r | |
54 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
55 | )\r | |
56 | {\r | |
57 | EFI_STATUS Status;\r | |
58 | VOID *Instance;\r | |
59 | \r | |
60 | Status = gBS->OpenProtocol (\r | |
61 | Controller,\r | |
62 | &gEfiIsaHcProtocolGuid,\r | |
63 | &Instance,\r | |
64 | This->DriverBindingHandle,\r | |
65 | Controller,\r | |
66 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
67 | );\r | |
68 | if (!EFI_ERROR (Status)) {\r | |
69 | gBS->CloseProtocol (\r | |
70 | Controller,\r | |
71 | &gEfiIsaHcProtocolGuid,\r | |
72 | This->DriverBindingHandle,\r | |
73 | Controller\r | |
74 | );\r | |
75 | }\r | |
76 | \r | |
77 | if (EFI_ERROR (Status)) {\r | |
78 | return Status;\r | |
79 | }\r | |
80 | \r | |
81 | Status = gBS->OpenProtocol (\r | |
82 | Controller,\r | |
83 | &gEfiDevicePathProtocolGuid,\r | |
84 | &Instance,\r | |
85 | This->DriverBindingHandle,\r | |
86 | Controller,\r | |
87 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
88 | );\r | |
89 | if (!EFI_ERROR (Status)) {\r | |
90 | gBS->CloseProtocol (\r | |
91 | Controller,\r | |
92 | &gEfiDevicePathProtocolGuid,\r | |
93 | This->DriverBindingHandle,\r | |
94 | Controller\r | |
95 | );\r | |
96 | }\r | |
97 | \r | |
98 | return Status;\r | |
99 | }\r | |
100 | \r | |
101 | ISA_BUS_CHILD_PRIVATE_DATA mIsaBusChildPrivateTemplate = {\r | |
102 | ISA_BUS_CHILD_PRIVATE_DATA_SIGNATURE,\r | |
103 | FALSE\r | |
104 | };\r | |
105 | \r | |
106 | /**\r | |
107 | Creates a child handle and installs a protocol.\r | |
108 | \r | |
109 | The CreateChild() function installs a protocol on ChildHandle. \r | |
110 | If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle. \r | |
111 | If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.\r | |
112 | \r | |
113 | @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r | |
114 | @param ChildHandle Pointer to the handle of the child to create. If it is NULL,\r | |
115 | then a new handle is created. If it is a pointer to an existing UEFI handle, \r | |
116 | then the protocol is added to the existing UEFI handle.\r | |
117 | \r | |
118 | @retval EFI_SUCCES The protocol was added to ChildHandle.\r | |
119 | @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r | |
2048c585 | 120 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create\r |
9834b6c1 RN |
121 | the child\r |
122 | @retval other The child handle was not created\r | |
123 | \r | |
124 | **/\r | |
125 | EFI_STATUS\r | |
126 | EFIAPI\r | |
127 | IsaBusCreateChild (\r | |
128 | IN EFI_SERVICE_BINDING_PROTOCOL *This,\r | |
129 | IN OUT EFI_HANDLE *ChildHandle\r | |
130 | )\r | |
131 | {\r | |
132 | EFI_STATUS Status;\r | |
133 | ISA_BUS_PRIVATE_DATA *Private;\r | |
134 | EFI_ISA_HC_PROTOCOL *IsaHc;\r | |
135 | ISA_BUS_CHILD_PRIVATE_DATA *Child;\r | |
136 | \r | |
137 | Private = ISA_BUS_PRIVATE_DATA_FROM_THIS (This);\r | |
138 | \r | |
139 | Child = AllocateCopyPool (sizeof (mIsaBusChildPrivateTemplate), &mIsaBusChildPrivateTemplate);\r | |
140 | if (Child == NULL) {\r | |
141 | return EFI_OUT_OF_RESOURCES;\r | |
142 | }\r | |
143 | \r | |
144 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
145 | ChildHandle,\r | |
146 | &gEfiIsaHcProtocolGuid, Private->IsaHc,\r | |
147 | &gEfiCallerIdGuid, Child,\r | |
148 | NULL\r | |
149 | );\r | |
150 | if (EFI_ERROR (Status)) {\r | |
151 | FreePool (Child);\r | |
152 | return Status;\r | |
153 | }\r | |
154 | \r | |
155 | return gBS->OpenProtocol (\r | |
156 | Private->IsaHcHandle,\r | |
157 | &gEfiIsaHcProtocolGuid,\r | |
158 | (VOID **) &IsaHc,\r | |
159 | gIsaBusDriverBinding.DriverBindingHandle,\r | |
160 | *ChildHandle,\r | |
161 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
162 | );\r | |
163 | }\r | |
164 | \r | |
165 | /**\r | |
166 | Destroys a child handle with a protocol installed on it.\r | |
167 | \r | |
168 | The DestroyChild() function does the opposite of CreateChild(). It removes a protocol \r | |
169 | that was installed by CreateChild() from ChildHandle. If the removed protocol is the \r | |
170 | last protocol on ChildHandle, then ChildHandle is destroyed.\r | |
171 | \r | |
172 | @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r | |
173 | @param ChildHandle Handle of the child to destroy\r | |
174 | \r | |
175 | @retval EFI_SUCCES The protocol was removed from ChildHandle.\r | |
176 | @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r | |
177 | @retval EFI_INVALID_PARAMETER Child handle is NULL.\r | |
178 | @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle\r | |
179 | because its services are being used.\r | |
180 | @retval other The child handle was not destroyed\r | |
181 | \r | |
182 | **/\r | |
183 | EFI_STATUS\r | |
184 | EFIAPI\r | |
185 | IsaBusDestroyChild (\r | |
186 | IN EFI_SERVICE_BINDING_PROTOCOL *This,\r | |
187 | IN EFI_HANDLE ChildHandle\r | |
188 | )\r | |
189 | {\r | |
190 | EFI_STATUS Status;\r | |
191 | ISA_BUS_PRIVATE_DATA *Private;\r | |
192 | EFI_ISA_HC_PROTOCOL *IsaHc;\r | |
193 | ISA_BUS_CHILD_PRIVATE_DATA *Child;\r | |
194 | \r | |
195 | Private = ISA_BUS_PRIVATE_DATA_FROM_THIS (This);\r | |
196 | \r | |
197 | Status = gBS->OpenProtocol (\r | |
198 | ChildHandle,\r | |
199 | &gEfiCallerIdGuid,\r | |
200 | (VOID **) &Child,\r | |
201 | gIsaBusDriverBinding.DriverBindingHandle,\r | |
202 | ChildHandle,\r | |
203 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
204 | );\r | |
205 | if (EFI_ERROR (Status)) {\r | |
206 | return Status;\r | |
207 | }\r | |
208 | \r | |
209 | ASSERT (Child->Signature == ISA_BUS_CHILD_PRIVATE_DATA_SIGNATURE);\r | |
210 | \r | |
211 | if (Child->InDestroying) {\r | |
212 | return EFI_SUCCESS;\r | |
213 | }\r | |
214 | \r | |
215 | Child->InDestroying = TRUE;\r | |
216 | Status = gBS->CloseProtocol (\r | |
217 | Private->IsaHcHandle,\r | |
218 | &gEfiIsaHcProtocolGuid,\r | |
219 | gIsaBusDriverBinding.DriverBindingHandle,\r | |
220 | ChildHandle\r | |
221 | );\r | |
222 | ASSERT_EFI_ERROR (Status);\r | |
223 | if (!EFI_ERROR (Status)) {\r | |
224 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
225 | ChildHandle,\r | |
226 | &gEfiIsaHcProtocolGuid, Private->IsaHc,\r | |
227 | &gEfiCallerIdGuid, Child,\r | |
228 | NULL\r | |
229 | );\r | |
230 | if (EFI_ERROR (Status)) {\r | |
231 | gBS->OpenProtocol (\r | |
232 | Private->IsaHcHandle,\r | |
233 | &gEfiIsaHcProtocolGuid,\r | |
234 | (VOID **) &IsaHc,\r | |
235 | gIsaBusDriverBinding.DriverBindingHandle,\r | |
236 | ChildHandle,\r | |
237 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
238 | );\r | |
239 | }\r | |
240 | }\r | |
241 | \r | |
242 | if (EFI_ERROR (Status)) {\r | |
243 | Child->InDestroying = FALSE;\r | |
244 | } else {\r | |
245 | FreePool (Child);\r | |
246 | }\r | |
247 | \r | |
248 | return Status;\r | |
249 | }\r | |
250 | \r | |
251 | ISA_BUS_PRIVATE_DATA mIsaBusPrivateTemplate = {\r | |
252 | ISA_BUS_PRIVATE_DATA_SIGNATURE,\r | |
253 | {\r | |
254 | IsaBusCreateChild,\r | |
255 | IsaBusDestroyChild\r | |
256 | }\r | |
257 | };\r | |
258 | \r | |
259 | /**\r | |
260 | Starts a device controller or a bus controller.\r | |
261 | \r | |
262 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
263 | @param[in] ControllerHandle The handle of the controller to start. This handle \r | |
264 | must support a protocol interface that supplies \r | |
265 | an I/O abstraction to the driver.\r | |
266 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r | |
267 | parameter is ignored by device drivers, and is optional for bus \r | |
268 | drivers. For a bus driver, if this parameter is NULL, then handles \r | |
269 | for all the children of Controller are created by this driver. \r | |
270 | If this parameter is not NULL and the first Device Path Node is \r | |
271 | not the End of Device Path Node, then only the handle for the \r | |
272 | child device specified by the first Device Path Node of \r | |
273 | RemainingDevicePath is created by this driver.\r | |
274 | If the first Device Path Node of RemainingDevicePath is \r | |
275 | the End of Device Path Node, no child handle is created by this\r | |
276 | driver.\r | |
277 | \r | |
278 | @retval EFI_SUCCESS The device was started.\r | |
279 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
280 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
281 | @retval Others The driver failded to start the device.\r | |
282 | \r | |
283 | **/\r | |
284 | EFI_STATUS\r | |
285 | EFIAPI\r | |
286 | IsaBusDriverBindingStart (\r | |
287 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
288 | IN EFI_HANDLE Controller,\r | |
289 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
290 | )\r | |
291 | {\r | |
292 | EFI_STATUS Status;\r | |
293 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
294 | ISA_BUS_PRIVATE_DATA *Private;\r | |
295 | \r | |
296 | Status = gBS->OpenProtocol (\r | |
297 | Controller,\r | |
298 | &gEfiIsaHcProtocolGuid,\r | |
299 | (VOID **) &mIsaBusPrivateTemplate.IsaHc,\r | |
300 | This->DriverBindingHandle,\r | |
301 | Controller,\r | |
302 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
303 | );\r | |
304 | if (EFI_ERROR (Status)) {\r | |
305 | return Status;\r | |
306 | }\r | |
307 | \r | |
308 | Status = gBS->OpenProtocol (\r | |
309 | Controller,\r | |
310 | &gEfiDevicePathProtocolGuid,\r | |
311 | (VOID **) &DevicePath,\r | |
312 | This->DriverBindingHandle,\r | |
313 | Controller,\r | |
314 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
315 | );\r | |
316 | if (EFI_ERROR (Status)) {\r | |
317 | gBS->CloseProtocol (\r | |
318 | Controller,\r | |
319 | &gEfiIsaHcProtocolGuid,\r | |
320 | This->DriverBindingHandle,\r | |
321 | Controller\r | |
322 | );\r | |
323 | return Status;\r | |
324 | }\r | |
325 | \r | |
326 | Private = AllocateCopyPool (sizeof (mIsaBusPrivateTemplate), &mIsaBusPrivateTemplate);\r | |
327 | ASSERT (Private != NULL);\r | |
328 | \r | |
329 | Private->IsaHcHandle = Controller;\r | |
330 | \r | |
331 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
332 | &Controller,\r | |
333 | &gEfiIsaHcServiceBindingProtocolGuid, &Private->ServiceBinding,\r | |
334 | NULL\r | |
335 | );\r | |
336 | ASSERT_EFI_ERROR (Status);\r | |
337 | \r | |
338 | return Status;\r | |
339 | }\r | |
340 | \r | |
341 | /**\r | |
342 | Stops a device controller or a bus controller.\r | |
343 | \r | |
344 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
345 | @param[in] ControllerHandle A handle to the device being stopped. The handle must \r | |
346 | support a bus specific I/O protocol for the driver \r | |
347 | to use to stop the device.\r | |
348 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
349 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r | |
350 | if NumberOfChildren is 0.\r | |
351 | \r | |
352 | @retval EFI_SUCCESS The device was stopped.\r | |
353 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
354 | \r | |
355 | **/\r | |
356 | EFI_STATUS\r | |
357 | EFIAPI\r | |
358 | IsaBusDriverBindingStop (\r | |
359 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
360 | IN EFI_HANDLE Controller,\r | |
361 | IN UINTN NumberOfChildren,\r | |
362 | IN EFI_HANDLE *ChildHandleBuffer\r | |
363 | )\r | |
364 | {\r | |
365 | EFI_STATUS Status;\r | |
366 | EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r | |
367 | ISA_BUS_PRIVATE_DATA *Private;\r | |
368 | UINTN Index;\r | |
369 | BOOLEAN AllChildrenStopped;\r | |
370 | \r | |
371 | Status = gBS->OpenProtocol (\r | |
372 | Controller,\r | |
373 | &gEfiIsaHcServiceBindingProtocolGuid,\r | |
374 | (VOID **) &ServiceBinding,\r | |
375 | This->DriverBindingHandle,\r | |
376 | Controller,\r | |
377 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
378 | );\r | |
379 | if (EFI_ERROR (Status)) {\r | |
380 | return Status;\r | |
381 | }\r | |
382 | \r | |
383 | Private = ISA_BUS_PRIVATE_DATA_FROM_THIS (ServiceBinding);\r | |
384 | \r | |
385 | if (NumberOfChildren == 0) {\r | |
386 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
387 | Controller,\r | |
388 | &gEfiIsaHcServiceBindingProtocolGuid, &Private->ServiceBinding,\r | |
389 | NULL\r | |
390 | );\r | |
391 | if (!EFI_ERROR (Status)) {\r | |
392 | gBS->CloseProtocol (\r | |
393 | Controller,\r | |
394 | &gEfiDevicePathProtocolGuid,\r | |
395 | This->DriverBindingHandle,\r | |
396 | Controller\r | |
397 | );\r | |
398 | gBS->CloseProtocol (\r | |
399 | Controller,\r | |
400 | &gEfiIsaHcProtocolGuid,\r | |
401 | This->DriverBindingHandle,\r | |
402 | Controller\r | |
403 | );\r | |
404 | FreePool (Private);\r | |
405 | }\r | |
406 | \r | |
407 | return Status;\r | |
408 | }\r | |
409 | \r | |
410 | AllChildrenStopped = TRUE;\r | |
411 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
412 | Status = ServiceBinding->DestroyChild (ServiceBinding, ChildHandleBuffer[Index]);\r | |
413 | if (EFI_ERROR (Status)) {\r | |
414 | AllChildrenStopped = FALSE;\r | |
415 | }\r | |
416 | }\r | |
417 | \r | |
418 | return AllChildrenStopped ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r | |
419 | }\r | |
420 | \r | |
421 | //\r | |
422 | // ISA Bus Driver Binding Protocol Instance\r | |
423 | //\r | |
424 | EFI_DRIVER_BINDING_PROTOCOL gIsaBusDriverBinding = {\r | |
425 | IsaBusDriverBindingSupported,\r | |
426 | IsaBusDriverBindingStart,\r | |
427 | IsaBusDriverBindingStop,\r | |
428 | 0x10,\r | |
429 | NULL,\r | |
430 | NULL\r | |
431 | };\r | |
432 | \r | |
433 | /**\r | |
434 | Entry point of the IsaBusDxe driver.\r | |
435 | \r | |
436 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
437 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
438 | \r | |
439 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
440 | @retval other Some error occurs when executing this entry point.\r | |
441 | **/\r | |
442 | EFI_STATUS\r | |
443 | EFIAPI\r | |
444 | InitializeIsaBus (\r | |
445 | IN EFI_HANDLE ImageHandle,\r | |
446 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
447 | )\r | |
448 | {\r | |
449 | EFI_STATUS Status;\r | |
450 | \r | |
451 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
452 | ImageHandle,\r | |
453 | SystemTable,\r | |
454 | &gIsaBusDriverBinding,\r | |
455 | ImageHandle,\r | |
456 | &gIsaBusComponentName,\r | |
457 | &gIsaBusComponentName2\r | |
458 | );\r | |
459 | ASSERT_EFI_ERROR (Status);\r | |
460 | return Status;\r | |
461 | }\r |