]>
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 | |
1436aea4 MK |
46 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
47 | IN EFI_HANDLE Controller,\r | |
48 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
9834b6c1 RN |
49 | )\r |
50 | {\r | |
1436aea4 MK |
51 | EFI_STATUS Status;\r |
52 | VOID *Instance;\r | |
9834b6c1 RN |
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 | |
1436aea4 MK |
64 | Controller,\r |
65 | &gEfiIsaHcProtocolGuid,\r | |
66 | This->DriverBindingHandle,\r | |
67 | Controller\r | |
68 | );\r | |
9834b6c1 RN |
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 | |
1436aea4 MK |
85 | Controller,\r |
86 | &gEfiDevicePathProtocolGuid,\r | |
87 | This->DriverBindingHandle,\r | |
88 | Controller\r | |
89 | );\r | |
9834b6c1 RN |
90 | }\r |
91 | \r | |
92 | return Status;\r | |
93 | }\r | |
94 | \r | |
1436aea4 | 95 | ISA_BUS_CHILD_PRIVATE_DATA mIsaBusChildPrivateTemplate = {\r |
9834b6c1 RN |
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 | |
1d031e75 | 112 | @retval EFI_SUCCESS The protocol was added to ChildHandle.\r |
9834b6c1 | 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 | |
1436aea4 MK |
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 | |
9834b6c1 RN |
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 | |
1436aea4 MK |
140 | &gEfiIsaHcProtocolGuid,\r |
141 | Private->IsaHc,\r | |
142 | &gEfiCallerIdGuid,\r | |
143 | Child,\r | |
9834b6c1 RN |
144 | NULL\r |
145 | );\r | |
146 | if (EFI_ERROR (Status)) {\r | |
147 | FreePool (Child);\r | |
148 | return Status;\r | |
149 | }\r | |
150 | \r | |
151 | return gBS->OpenProtocol (\r | |
152 | Private->IsaHcHandle,\r | |
153 | &gEfiIsaHcProtocolGuid,\r | |
1436aea4 | 154 | (VOID **)&IsaHc,\r |
9834b6c1 RN |
155 | gIsaBusDriverBinding.DriverBindingHandle,\r |
156 | *ChildHandle,\r | |
157 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
158 | );\r | |
159 | }\r | |
160 | \r | |
161 | /**\r | |
162 | Destroys a child handle with a protocol installed on it.\r | |
d1102dba LG |
163 | \r |
164 | The DestroyChild() function does the opposite of CreateChild(). It removes a protocol\r | |
165 | that was installed by CreateChild() from ChildHandle. If the removed protocol is the\r | |
9834b6c1 RN |
166 | last protocol on ChildHandle, then ChildHandle is destroyed.\r |
167 | \r | |
168 | @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.\r | |
169 | @param ChildHandle Handle of the child to destroy\r | |
170 | \r | |
1d031e75 | 171 | @retval EFI_SUCCESS The protocol was removed from ChildHandle.\r |
9834b6c1 RN |
172 | @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.\r |
173 | @retval EFI_INVALID_PARAMETER Child handle is NULL.\r | |
174 | @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle\r | |
175 | because its services are being used.\r | |
176 | @retval other The child handle was not destroyed\r | |
177 | \r | |
178 | **/\r | |
179 | EFI_STATUS\r | |
180 | EFIAPI\r | |
181 | IsaBusDestroyChild (\r | |
1436aea4 MK |
182 | IN EFI_SERVICE_BINDING_PROTOCOL *This,\r |
183 | IN EFI_HANDLE ChildHandle\r | |
9834b6c1 RN |
184 | )\r |
185 | {\r | |
1436aea4 MK |
186 | EFI_STATUS Status;\r |
187 | ISA_BUS_PRIVATE_DATA *Private;\r | |
188 | EFI_ISA_HC_PROTOCOL *IsaHc;\r | |
189 | ISA_BUS_CHILD_PRIVATE_DATA *Child;\r | |
9834b6c1 RN |
190 | \r |
191 | Private = ISA_BUS_PRIVATE_DATA_FROM_THIS (This);\r | |
192 | \r | |
193 | Status = gBS->OpenProtocol (\r | |
194 | ChildHandle,\r | |
195 | &gEfiCallerIdGuid,\r | |
1436aea4 | 196 | (VOID **)&Child,\r |
9834b6c1 RN |
197 | gIsaBusDriverBinding.DriverBindingHandle,\r |
198 | ChildHandle,\r | |
199 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
200 | );\r | |
201 | if (EFI_ERROR (Status)) {\r | |
202 | return Status;\r | |
203 | }\r | |
204 | \r | |
205 | ASSERT (Child->Signature == ISA_BUS_CHILD_PRIVATE_DATA_SIGNATURE);\r | |
206 | \r | |
207 | if (Child->InDestroying) {\r | |
208 | return EFI_SUCCESS;\r | |
209 | }\r | |
210 | \r | |
211 | Child->InDestroying = TRUE;\r | |
1436aea4 MK |
212 | Status = gBS->CloseProtocol (\r |
213 | Private->IsaHcHandle,\r | |
214 | &gEfiIsaHcProtocolGuid,\r | |
215 | gIsaBusDriverBinding.DriverBindingHandle,\r | |
216 | ChildHandle\r | |
217 | );\r | |
9834b6c1 RN |
218 | ASSERT_EFI_ERROR (Status);\r |
219 | if (!EFI_ERROR (Status)) {\r | |
220 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
221 | ChildHandle,\r | |
1436aea4 MK |
222 | &gEfiIsaHcProtocolGuid,\r |
223 | Private->IsaHc,\r | |
224 | &gEfiCallerIdGuid,\r | |
225 | Child,\r | |
9834b6c1 RN |
226 | NULL\r |
227 | );\r | |
228 | if (EFI_ERROR (Status)) {\r | |
229 | gBS->OpenProtocol (\r | |
230 | Private->IsaHcHandle,\r | |
231 | &gEfiIsaHcProtocolGuid,\r | |
1436aea4 | 232 | (VOID **)&IsaHc,\r |
9834b6c1 RN |
233 | gIsaBusDriverBinding.DriverBindingHandle,\r |
234 | ChildHandle,\r | |
235 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
236 | );\r | |
237 | }\r | |
238 | }\r | |
239 | \r | |
240 | if (EFI_ERROR (Status)) {\r | |
241 | Child->InDestroying = FALSE;\r | |
242 | } else {\r | |
243 | FreePool (Child);\r | |
244 | }\r | |
245 | \r | |
246 | return Status;\r | |
247 | }\r | |
248 | \r | |
1436aea4 | 249 | ISA_BUS_PRIVATE_DATA mIsaBusPrivateTemplate = {\r |
9834b6c1 RN |
250 | ISA_BUS_PRIVATE_DATA_SIGNATURE,\r |
251 | {\r | |
252 | IsaBusCreateChild,\r | |
253 | IsaBusDestroyChild\r | |
254 | }\r | |
255 | };\r | |
256 | \r | |
257 | /**\r | |
258 | Starts a device controller or a bus controller.\r | |
259 | \r | |
260 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
d1102dba LG |
261 | @param[in] ControllerHandle The handle of the controller to start. This handle\r |
262 | must support a protocol interface that supplies\r | |
9834b6c1 | 263 | an I/O abstraction to the driver.\r |
d1102dba LG |
264 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r |
265 | parameter is ignored by device drivers, and is optional for bus\r | |
266 | drivers. For a bus driver, if this parameter is NULL, then handles\r | |
267 | for all the children of Controller are created by this driver.\r | |
268 | If this parameter is not NULL and the first Device Path Node is\r | |
269 | not the End of Device Path Node, then only the handle for the\r | |
270 | child device specified by the first Device Path Node of\r | |
9834b6c1 | 271 | RemainingDevicePath is created by this driver.\r |
d1102dba | 272 | If the first Device Path Node of RemainingDevicePath is\r |
9834b6c1 RN |
273 | the End of Device Path Node, no child handle is created by this\r |
274 | driver.\r | |
275 | \r | |
276 | @retval EFI_SUCCESS The device was started.\r | |
277 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
278 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
1d031e75 | 279 | @retval Others The driver failed to start the device.\r |
9834b6c1 RN |
280 | \r |
281 | **/\r | |
282 | EFI_STATUS\r | |
283 | EFIAPI\r | |
284 | IsaBusDriverBindingStart (\r | |
1436aea4 MK |
285 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
286 | IN EFI_HANDLE Controller,\r | |
287 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
9834b6c1 RN |
288 | )\r |
289 | {\r | |
1436aea4 MK |
290 | EFI_STATUS Status;\r |
291 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
292 | ISA_BUS_PRIVATE_DATA *Private;\r | |
9834b6c1 RN |
293 | \r |
294 | Status = gBS->OpenProtocol (\r | |
295 | Controller,\r | |
296 | &gEfiIsaHcProtocolGuid,\r | |
1436aea4 | 297 | (VOID **)&mIsaBusPrivateTemplate.IsaHc,\r |
9834b6c1 RN |
298 | This->DriverBindingHandle,\r |
299 | Controller,\r | |
300 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
301 | );\r | |
302 | if (EFI_ERROR (Status)) {\r | |
303 | return Status;\r | |
304 | }\r | |
305 | \r | |
306 | Status = gBS->OpenProtocol (\r | |
307 | Controller,\r | |
308 | &gEfiDevicePathProtocolGuid,\r | |
1436aea4 | 309 | (VOID **)&DevicePath,\r |
9834b6c1 RN |
310 | This->DriverBindingHandle,\r |
311 | Controller,\r | |
312 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
313 | );\r | |
314 | if (EFI_ERROR (Status)) {\r | |
315 | gBS->CloseProtocol (\r | |
316 | Controller,\r | |
317 | &gEfiIsaHcProtocolGuid,\r | |
318 | This->DriverBindingHandle,\r | |
319 | Controller\r | |
320 | );\r | |
321 | return Status;\r | |
322 | }\r | |
323 | \r | |
324 | Private = AllocateCopyPool (sizeof (mIsaBusPrivateTemplate), &mIsaBusPrivateTemplate);\r | |
325 | ASSERT (Private != NULL);\r | |
326 | \r | |
327 | Private->IsaHcHandle = Controller;\r | |
328 | \r | |
329 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
330 | &Controller,\r | |
1436aea4 MK |
331 | &gEfiIsaHcServiceBindingProtocolGuid,\r |
332 | &Private->ServiceBinding,\r | |
9834b6c1 RN |
333 | NULL\r |
334 | );\r | |
335 | ASSERT_EFI_ERROR (Status);\r | |
336 | \r | |
337 | return Status;\r | |
338 | }\r | |
339 | \r | |
340 | /**\r | |
341 | Stops a device controller or a bus controller.\r | |
d1102dba | 342 | \r |
9834b6c1 | 343 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
d1102dba LG |
344 | @param[in] ControllerHandle A handle to the device being stopped. The handle must\r |
345 | support a bus specific I/O protocol for the driver\r | |
9834b6c1 RN |
346 | to use to stop the device.\r |
347 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
d1102dba | 348 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r |
9834b6c1 RN |
349 | if NumberOfChildren is 0.\r |
350 | \r | |
351 | @retval EFI_SUCCESS The device was stopped.\r | |
352 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
353 | \r | |
354 | **/\r | |
355 | EFI_STATUS\r | |
356 | EFIAPI\r | |
357 | IsaBusDriverBindingStop (\r | |
1436aea4 MK |
358 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
359 | IN EFI_HANDLE Controller,\r | |
360 | IN UINTN NumberOfChildren,\r | |
361 | IN EFI_HANDLE *ChildHandleBuffer\r | |
9834b6c1 RN |
362 | )\r |
363 | {\r | |
1436aea4 MK |
364 | EFI_STATUS Status;\r |
365 | EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;\r | |
366 | ISA_BUS_PRIVATE_DATA *Private;\r | |
367 | UINTN Index;\r | |
368 | BOOLEAN AllChildrenStopped;\r | |
9834b6c1 RN |
369 | \r |
370 | Status = gBS->OpenProtocol (\r | |
371 | Controller,\r | |
372 | &gEfiIsaHcServiceBindingProtocolGuid,\r | |
1436aea4 | 373 | (VOID **)&ServiceBinding,\r |
9834b6c1 RN |
374 | This->DriverBindingHandle,\r |
375 | Controller,\r | |
376 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
377 | );\r | |
378 | if (EFI_ERROR (Status)) {\r | |
379 | return Status;\r | |
380 | }\r | |
381 | \r | |
382 | Private = ISA_BUS_PRIVATE_DATA_FROM_THIS (ServiceBinding);\r | |
383 | \r | |
384 | if (NumberOfChildren == 0) {\r | |
385 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
386 | Controller,\r | |
1436aea4 MK |
387 | &gEfiIsaHcServiceBindingProtocolGuid,\r |
388 | &Private->ServiceBinding,\r | |
9834b6c1 RN |
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 | |
1436aea4 | 424 | EFI_DRIVER_BINDING_PROTOCOL gIsaBusDriverBinding = {\r |
9834b6c1 RN |
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 | |
d1102dba LG |
435 | \r |
436 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
9834b6c1 | 437 | @param[in] SystemTable A pointer to the EFI System Table.\r |
d1102dba | 438 | \r |
9834b6c1 RN |
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 | |
1436aea4 | 449 | EFI_STATUS Status;\r |
d1102dba | 450 | \r |
9834b6c1 RN |
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 |