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