]>
Commit | Line | Data |
---|---|---|
f8cd287b | 1 | /**@file\r |
6fcb2d91 | 2 | ISA Bus UEFI driver.\r |
c3902377 | 3 | \r |
6fcb2d91 | 4 | Discovers all the ISA Controllers and their resources by using the ISA ACPI \r |
c3902377 | 5 | Protocol, produces an instance of the ISA I/O Protocol for every ISA \r |
6fcb2d91 | 6 | Controller found. This driver is designed to manage a PCI-to-ISA bridge Device\r |
7 | such as LPC bridge.\r | |
f8cd287b | 8 | \r |
6fcb2d91 | 9 | Copyright (c) 2006 - 2009, Intel Corporation.<BR>\r |
f8cd287b | 10 | All rights reserved. This program and the accompanying materials\r |
11 | are licensed and made available under the terms and conditions of the BSD License\r | |
12 | which accompanies this distribution. The full text of the license may be found at\r | |
13 | http://opensource.org/licenses/bsd-license.php\r | |
14 | \r | |
15 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
16 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
c3902377 | 17 | \r |
f8cd287b | 18 | **/\r |
c3902377 | 19 | \r |
c3902377 | 20 | #include "InternalIsaBus.h"\r |
21 | \r | |
22 | //\r | |
23 | // ISA Bus Driver Global Variables\r | |
24 | //\r | |
25 | EFI_DRIVER_BINDING_PROTOCOL gIsaBusControllerDriver = {\r | |
26 | IsaBusControllerDriverSupported,\r | |
27 | IsaBusControllerDriverStart,\r | |
28 | IsaBusControllerDriverStop,\r | |
29 | 0xa,\r | |
30 | NULL,\r | |
31 | NULL\r | |
32 | };\r | |
33 | \r | |
c55fa8cc | 34 | /**\r |
6fcb2d91 | 35 | The main entry point for the ISA Bus driver.\r |
c55fa8cc | 36 | \r |
6fcb2d91 | 37 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r |
38 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
c55fa8cc | 39 | \r |
6fcb2d91 | 40 | @retval EFI_SUCCESS The entry point is executed successfully.\r |
41 | @retval EFI_OUT_OF_RESOURCES There was not enough memory in pool to install all the protocols.\r | |
c55fa8cc | 42 | **/\r |
43 | EFI_STATUS\r | |
44 | EFIAPI\r | |
45 | InitializeIsaBus(\r | |
46 | IN EFI_HANDLE ImageHandle,\r | |
47 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
48 | )\r | |
49 | {\r | |
50 | EFI_STATUS Status;\r | |
51 | \r | |
52 | //\r | |
53 | // Install driver model protocol(s).\r | |
54 | //\r | |
f3d08ccf | 55 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
c55fa8cc | 56 | ImageHandle,\r |
57 | SystemTable,\r | |
58 | &gIsaBusControllerDriver,\r | |
59 | ImageHandle,\r | |
60 | &gIsaBusComponentName,\r | |
f3d08ccf | 61 | &gIsaBusComponentName2\r |
c55fa8cc | 62 | );\r |
63 | ASSERT_EFI_ERROR (Status);\r | |
64 | \r | |
c55fa8cc | 65 | return Status;\r |
66 | }\r | |
67 | \r | |
6fcb2d91 | 68 | /** \r |
69 | Tests to see if a controller can be managed by the ISA Bus Driver. If a child device is provided, \r | |
70 | it further tests to see if this driver supports creating a handle for the specified child device.\r | |
c55fa8cc | 71 | \r |
6fcb2d91 | 72 | Note that the ISA Bus driver always creates all of its child handles on the first call to Start().\r |
73 | How the Start() function of a driver is implemented can affect how the Supported() function is implemented.\r | |
74 | \r | |
75 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. \r | |
76 | @param[in] Controller The handle of the controller to test.\r | |
77 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.\r | |
78 | \r | |
79 | @retval EFI_SUCCESS The device is supported by this driver.\r | |
80 | @retval EFI_ALREADY_STARTED The device is already being managed by this driver.\r | |
81 | @retval EFI_ACCESS_DENIED The device is already being managed by a different driver \r | |
82 | or an application that requires exclusive access.\r | |
83 | @retval EFI_UNSUPPORTED The device is is not supported by this driver.\r | |
84 | \r | |
85 | **/\r | |
c3902377 | 86 | EFI_STATUS\r |
87 | EFIAPI\r | |
88 | IsaBusControllerDriverSupported (\r | |
6fcb2d91 | 89 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
c3902377 | 90 | IN EFI_HANDLE Controller,\r |
6fcb2d91 | 91 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r |
c3902377 | 92 | )\r |
c3902377 | 93 | {\r |
6fcb2d91 | 94 | EFI_STATUS Status;\r |
95 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
6fcb2d91 | 96 | EFI_ISA_ACPI_PROTOCOL *IsaAcpi;\r |
c3902377 | 97 | \r |
98 | //\r | |
99 | // If RemainingDevicePath is not NULL, it should verify that the first device\r | |
6fcb2d91 | 100 | // path node in RemainingDevicePath is an ACPI Device path node which is a \r |
101 | // legal Device Path Node for this bus driver's children.\r | |
c3902377 | 102 | //\r |
103 | if (RemainingDevicePath != NULL) {\r | |
104 | if (RemainingDevicePath->Type != ACPI_DEVICE_PATH) {\r | |
105 | return EFI_UNSUPPORTED;\r | |
106 | } else if (RemainingDevicePath->SubType == ACPI_DP) {\r | |
107 | if (DevicePathNodeLength (RemainingDevicePath) != sizeof (ACPI_HID_DEVICE_PATH)) {\r | |
108 | return EFI_UNSUPPORTED;\r | |
109 | }\r | |
110 | } else if (RemainingDevicePath->SubType == ACPI_EXTENDED_DP) {\r | |
111 | if (DevicePathNodeLength (RemainingDevicePath) != sizeof (ACPI_EXTENDED_HID_DEVICE_PATH)) {\r | |
112 | return EFI_UNSUPPORTED;\r | |
113 | }\r | |
114 | } else {\r | |
115 | return EFI_UNSUPPORTED;\r | |
116 | }\r | |
117 | }\r | |
118 | //\r | |
6fcb2d91 | 119 | // Try to open EFI DEVICE PATH protocol on the controller\r |
c3902377 | 120 | //\r |
121 | Status = gBS->OpenProtocol (\r | |
122 | Controller,\r | |
123 | &gEfiDevicePathProtocolGuid,\r | |
6fcb2d91 | 124 | (VOID **) &ParentDevicePath,\r |
125 | This->DriverBindingHandle,\r | |
126 | Controller,\r | |
127 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
128 | );\r | |
9277fdf8 | 129 | //\r |
130 | // Although this driver creates all child handles at one time,\r | |
131 | // but because all child handles may be not stopped at one time in EFI Driver Binding.Stop(),\r | |
132 | // So it is allowed to create child handles again in successive calls to EFI Driver Binding.Start().\r | |
133 | //\r | |
134 | if (Status == EFI_ALREADY_STARTED) {\r | |
135 | return EFI_SUCCESS;\r | |
136 | }\r | |
137 | \r | |
6fcb2d91 | 138 | if (EFI_ERROR (Status)) {\r |
139 | return Status;\r | |
140 | }\r | |
141 | \r | |
142 | gBS->CloseProtocol (\r | |
143 | Controller,\r | |
144 | &gEfiDevicePathProtocolGuid,\r | |
145 | This->DriverBindingHandle,\r | |
146 | Controller\r | |
147 | );\r | |
148 | \r | |
149 | //\r | |
150 | // Try to get Pci IO Protocol because it is assumed\r | |
151 | // to have been opened by ISA ACPI driver\r | |
152 | //\r | |
153 | Status = gBS->OpenProtocol (\r | |
154 | Controller,\r | |
155 | &gEfiPciIoProtocolGuid,\r | |
9277fdf8 | 156 | NULL,\r |
c3902377 | 157 | This->DriverBindingHandle,\r |
158 | Controller,\r | |
9277fdf8 | 159 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r |
c3902377 | 160 | );\r |
161 | if (EFI_ERROR (Status)) {\r | |
162 | return Status;\r | |
163 | }\r | |
6fcb2d91 | 164 | \r |
c3902377 | 165 | //\r |
6fcb2d91 | 166 | // Try to open the Isa Acpi protocol on the controller\r |
c3902377 | 167 | //\r |
168 | Status = gBS->OpenProtocol (\r | |
169 | Controller,\r | |
170 | &gEfiIsaAcpiProtocolGuid,\r | |
171 | (VOID **) &IsaAcpi,\r | |
172 | This->DriverBindingHandle,\r | |
173 | Controller,\r | |
174 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
175 | );\r | |
c3902377 | 176 | if (EFI_ERROR (Status)) {\r |
177 | return Status;\r | |
178 | }\r | |
179 | \r | |
6fcb2d91 | 180 | //\r |
181 | // Add more check to see if the child device is valid by calling IsaAcpi->DeviceEnumerate?\r | |
182 | //\r | |
183 | \r | |
c3902377 | 184 | gBS->CloseProtocol (\r |
185 | Controller,\r | |
186 | &gEfiIsaAcpiProtocolGuid,\r | |
187 | This->DriverBindingHandle,\r | |
188 | Controller\r | |
189 | );\r | |
190 | \r | |
191 | return Status;\r | |
192 | }\r | |
193 | \r | |
6fcb2d91 | 194 | /**\r |
195 | Start this driver on ControllerHandle. \r | |
196 | \r | |
197 | Note that the ISA Bus driver always creates all of its child handles on the first call to Start().\r | |
198 | The Start() function is designed to be invoked from the EFI boot service ConnectController(). \r | |
199 | As a result, much of the error checking on the parameters to Start() has been moved into this \r | |
200 | common boot service. It is legal to call Start() from other locations, but the following calling \r | |
201 | restrictions must be followed or the system behavior will not be deterministic.\r | |
202 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
203 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
204 | EFI_DEVICE_PATH_PROTOCOL.\r | |
205 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
206 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. \r | |
207 | \r | |
208 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
209 | @param[in] ControllerHandle The handle of the controller to start. This handle \r | |
210 | must support a protocol interface that supplies \r | |
211 | an I/O abstraction to the driver.\r | |
212 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. \r | |
213 | This parameter is ignored by device drivers, and is optional for bus drivers.\r | |
214 | \r | |
215 | @retval EFI_SUCCESS The device was started.\r | |
216 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.\r | |
217 | Currently not implemented.\r | |
218 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
219 | @retval Others The driver failded to start the device.\r | |
220 | **/\r | |
c3902377 | 221 | EFI_STATUS\r |
222 | EFIAPI\r | |
223 | IsaBusControllerDriverStart (\r | |
6fcb2d91 | 224 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r |
c3902377 | 225 | IN EFI_HANDLE Controller,\r |
6fcb2d91 | 226 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r |
c3902377 | 227 | )\r |
c3902377 | 228 | {\r |
229 | EFI_STATUS Status;\r | |
230 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
231 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
232 | EFI_ISA_ACPI_PROTOCOL *IsaAcpi;\r | |
233 | EFI_ISA_ACPI_DEVICE_ID *IsaDevice;\r | |
234 | EFI_ISA_ACPI_RESOURCE_LIST *ResourceList;\r | |
235 | EFI_GENERIC_MEMORY_TEST_PROTOCOL *GenMemoryTest;\r | |
236 | \r | |
237 | //\r | |
238 | // Local variables declaration for StatusCode reporting\r | |
239 | //\r | |
c3902377 | 240 | EFI_DEVICE_PATH_PROTOCOL *DevicePathData;\r |
241 | \r | |
c3902377 | 242 | //\r |
6fcb2d91 | 243 | // Get Pci IO Protocol\r |
c3902377 | 244 | //\r |
245 | Status = gBS->OpenProtocol (\r | |
246 | Controller,\r | |
6fcb2d91 | 247 | &gEfiPciIoProtocolGuid,\r |
248 | (VOID **) &PciIo,\r | |
c3902377 | 249 | This->DriverBindingHandle,\r |
250 | Controller,\r | |
6fcb2d91 | 251 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r |
c3902377 | 252 | );\r |
6fcb2d91 | 253 | if (EFI_ERROR (Status)) {\r |
c3902377 | 254 | return Status;\r |
255 | }\r | |
6fcb2d91 | 256 | \r |
c3902377 | 257 | //\r |
6fcb2d91 | 258 | // Open Device Path Protocol\r |
c3902377 | 259 | //\r |
260 | Status = gBS->OpenProtocol (\r | |
261 | Controller,\r | |
6fcb2d91 | 262 | &gEfiDevicePathProtocolGuid,\r |
263 | (VOID **) &ParentDevicePath,\r | |
c3902377 | 264 | This->DriverBindingHandle,\r |
265 | Controller,\r | |
6fcb2d91 | 266 | EFI_OPEN_PROTOCOL_BY_DRIVER\r |
c3902377 | 267 | );\r |
9277fdf8 | 268 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r |
c3902377 | 269 | return Status;\r |
270 | }\r | |
6fcb2d91 | 271 | \r |
c3902377 | 272 | //\r |
273 | // Open ISA Acpi Protocol\r | |
274 | //\r | |
275 | Status = gBS->OpenProtocol (\r | |
276 | Controller,\r | |
277 | &gEfiIsaAcpiProtocolGuid,\r | |
278 | (VOID **) &IsaAcpi,\r | |
279 | This->DriverBindingHandle,\r | |
280 | Controller,\r | |
281 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
282 | );\r | |
9277fdf8 | 283 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r |
c3902377 | 284 | //\r |
285 | // Close opened protocol\r | |
286 | //\r | |
287 | gBS->CloseProtocol (\r | |
288 | Controller,\r | |
289 | &gEfiDevicePathProtocolGuid,\r | |
290 | This->DriverBindingHandle,\r | |
291 | Controller\r | |
292 | );\r | |
c3902377 | 293 | return Status;\r |
294 | }\r | |
295 | //\r | |
296 | // The IsaBus driver will use memory below 16M, which is not tested yet,\r | |
297 | // so call CompatibleRangeTest to test them. Since memory below 1M should\r | |
298 | // be reserved to CSM, and 15M~16M might be reserved for Isa hole, test 1M\r | |
299 | // ~15M here\r | |
300 | //\r | |
301 | Status = gBS->LocateProtocol (\r | |
302 | &gEfiGenericMemTestProtocolGuid,\r | |
303 | NULL,\r | |
304 | (VOID **) &GenMemoryTest\r | |
305 | );\r | |
306 | \r | |
307 | if (!EFI_ERROR (Status)) {\r | |
308 | Status = GenMemoryTest->CompatibleRangeTest (\r | |
309 | GenMemoryTest,\r | |
310 | 0x100000,\r | |
311 | 0xE00000\r | |
312 | );\r | |
313 | }\r | |
314 | //\r | |
315 | // Report Status Code here since we will initialize the host controller\r | |
316 | //\r | |
317 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
318 | EFI_PROGRESS_CODE,\r | |
319 | (EFI_IO_BUS_LPC | EFI_IOB_PC_INIT),\r | |
320 | ParentDevicePath\r | |
321 | );\r | |
322 | \r | |
323 | //\r | |
324 | // first init ISA interface\r | |
325 | //\r | |
326 | IsaAcpi->InterfaceInit (IsaAcpi);\r | |
327 | \r | |
328 | //\r | |
329 | // Report Status Code here since we will enable the host controller\r | |
330 | //\r | |
331 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
332 | EFI_PROGRESS_CODE,\r | |
333 | (EFI_IO_BUS_LPC | EFI_IOB_PC_ENABLE),\r | |
334 | ParentDevicePath\r | |
335 | );\r | |
336 | \r | |
337 | //\r | |
338 | // Create each ISA device handle in this ISA bus\r | |
339 | //\r | |
340 | IsaDevice = NULL;\r | |
341 | do {\r | |
342 | Status = IsaAcpi->DeviceEnumerate (IsaAcpi, &IsaDevice);\r | |
343 | if (EFI_ERROR (Status)) {\r | |
344 | break;\r | |
345 | }\r | |
346 | //\r | |
347 | // Get current resource of this ISA device\r | |
348 | //\r | |
349 | ResourceList = NULL;\r | |
350 | Status = IsaAcpi->GetCurResource (IsaAcpi, IsaDevice, &ResourceList);\r | |
351 | if (EFI_ERROR (Status)) {\r | |
352 | continue;\r | |
353 | }\r | |
354 | \r | |
355 | //\r | |
356 | // Create handle for this ISA device\r | |
357 | //\r | |
9277fdf8 | 358 | // If any child device handle was created in previous call to Start() and not stopped\r |
359 | // in previous call to Stop(), it will not be created again because the\r | |
360 | // InstallMultipleProtocolInterfaces() boot service will reject same device path.\r | |
361 | //\r | |
c3902377 | 362 | Status = IsaCreateDevice (\r |
363 | This,\r | |
364 | Controller,\r | |
365 | PciIo,\r | |
366 | ParentDevicePath,\r | |
367 | ResourceList,\r | |
368 | &DevicePathData\r | |
c3902377 | 369 | );\r |
370 | \r | |
371 | if (EFI_ERROR (Status)) {\r | |
372 | continue;\r | |
373 | }\r | |
374 | //\r | |
375 | // Initialize ISA device\r | |
376 | //\r | |
377 | IsaAcpi->InitDevice (IsaAcpi, IsaDevice);\r | |
378 | \r | |
379 | //\r | |
380 | // Set resources for this ISA device\r | |
381 | //\r | |
382 | Status = IsaAcpi->SetResource (IsaAcpi, IsaDevice, ResourceList);\r | |
383 | \r | |
384 | //\r | |
385 | // Report Status Code here when failed to resource conflicts\r | |
386 | //\r | |
387 | if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {\r | |
388 | //\r | |
389 | // It's hard to tell which resource conflicts\r | |
390 | //\r | |
c3902377 | 391 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r |
392 | EFI_ERROR_CODE,\r | |
393 | (EFI_IO_BUS_LPC | EFI_IOB_EC_RESOURCE_CONFLICT),\r | |
394 | DevicePathData\r | |
395 | );\r | |
396 | \r | |
397 | }\r | |
398 | //\r | |
399 | // Set power for this ISA device\r | |
400 | //\r | |
401 | IsaAcpi->SetPower (IsaAcpi, IsaDevice, TRUE);\r | |
402 | \r | |
403 | //\r | |
404 | // Enable this ISA device\r | |
405 | //\r | |
406 | IsaAcpi->EnableDevice (IsaAcpi, IsaDevice, TRUE);\r | |
407 | \r | |
408 | } while (TRUE);\r | |
409 | \r | |
c3902377 | 410 | return EFI_SUCCESS;\r |
411 | }\r | |
412 | \r | |
6fcb2d91 | 413 | /**\r |
414 | Stop this driver on ControllerHandle. \r | |
415 | \r | |
416 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r | |
417 | As a result, much of the error checking on the parameters to Stop() has been moved \r | |
418 | into this common boot service. It is legal to call Stop() from other locations, \r | |
419 | but the following calling restrictions must be followed or the system behavior will not be deterministic.\r | |
420 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
421 | same driver's Start() function.\r | |
422 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
423 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
424 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
425 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
426 | \r | |
427 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
428 | @param[in] ControllerHandle A handle to the device being stopped. The handle must \r | |
429 | support a bus specific I/O protocol for the driver \r | |
430 | to use to stop the device.\r | |
431 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
432 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r | |
433 | if NumberOfChildren is 0.\r | |
434 | \r | |
435 | @retval EFI_SUCCESS The device was stopped.\r | |
436 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
437 | **/\r | |
c3902377 | 438 | EFI_STATUS\r |
439 | EFIAPI\r | |
440 | IsaBusControllerDriverStop (\r | |
441 | IN EFI_DRIVER_BINDING_PROTOCOL * This,\r | |
442 | IN EFI_HANDLE Controller,\r | |
443 | IN UINTN NumberOfChildren,\r | |
444 | IN EFI_HANDLE * ChildHandleBuffer OPTIONAL\r | |
445 | )\r | |
c3902377 | 446 | {\r |
447 | EFI_STATUS Status;\r | |
448 | UINTN Index;\r | |
449 | BOOLEAN AllChildrenStopped;\r | |
450 | ISA_IO_DEVICE *IsaIoDevice;\r | |
451 | EFI_ISA_IO_PROTOCOL *IsaIo;\r | |
9277fdf8 | 452 | EFI_PCI_IO_PROTOCOL *PciIo;\r |
c3902377 | 453 | \r |
454 | if (NumberOfChildren == 0) {\r | |
455 | //\r | |
456 | // Close the bus driver\r | |
457 | //\r | |
c3902377 | 458 | Status = gBS->CloseProtocol (\r |
459 | Controller,\r | |
460 | &gEfiDevicePathProtocolGuid,\r | |
461 | This->DriverBindingHandle,\r | |
462 | Controller\r | |
463 | );\r | |
464 | if (EFI_ERROR (Status)) {\r | |
465 | return Status;\r | |
466 | }\r | |
467 | \r | |
468 | Status = gBS->CloseProtocol (\r | |
469 | Controller,\r | |
470 | &gEfiIsaAcpiProtocolGuid,\r | |
471 | This->DriverBindingHandle,\r | |
472 | Controller\r | |
473 | );\r | |
474 | if (EFI_ERROR (Status)) {\r | |
475 | return Status;\r | |
476 | }\r | |
477 | \r | |
478 | return EFI_SUCCESS;\r | |
479 | }\r | |
480 | //\r | |
481 | // Complete all outstanding transactions to Controller.\r | |
482 | // Don't allow any new transaction to Controller to be started.\r | |
483 | //\r | |
484 | //\r | |
485 | // Stop all the children\r | |
486 | // Find all the ISA devices that were discovered on this PCI to ISA Bridge\r | |
487 | // with the Start() function.\r | |
488 | //\r | |
489 | AllChildrenStopped = TRUE;\r | |
490 | \r | |
491 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
492 | \r | |
493 | Status = gBS->OpenProtocol (\r | |
494 | ChildHandleBuffer[Index],\r | |
495 | &gEfiIsaIoProtocolGuid,\r | |
496 | (VOID **) &IsaIo,\r | |
497 | This->DriverBindingHandle,\r | |
498 | Controller,\r | |
499 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
500 | );\r | |
501 | if (!EFI_ERROR (Status)) {\r | |
502 | \r | |
503 | IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo);\r | |
504 | \r | |
9277fdf8 | 505 | //\r |
506 | // Close the child handle\r | |
507 | //\r | |
508 | \r | |
509 | Status = gBS->CloseProtocol (\r | |
510 | Controller,\r | |
511 | &gEfiPciIoProtocolGuid,\r | |
512 | This->DriverBindingHandle,\r | |
513 | ChildHandleBuffer[Index]\r | |
514 | );\r | |
c3902377 | 515 | Status = gBS->UninstallMultipleProtocolInterfaces (\r |
516 | ChildHandleBuffer[Index],\r | |
517 | &gEfiDevicePathProtocolGuid,\r | |
518 | IsaIoDevice->DevicePath,\r | |
519 | &gEfiIsaIoProtocolGuid,\r | |
520 | &IsaIoDevice->IsaIo,\r | |
521 | NULL\r | |
522 | );\r | |
523 | \r | |
524 | if (!EFI_ERROR (Status)) {\r | |
f423cbf1 | 525 | FreePool (IsaIoDevice->DevicePath);\r |
526 | FreePool (IsaIoDevice);\r | |
9277fdf8 | 527 | } else {\r |
528 | //\r | |
529 | // Re-open PCI IO Protocol on behalf of the child device\r | |
530 | // because of failure of destroying the child device handle\r | |
531 | //\r | |
532 | gBS->OpenProtocol (\r | |
533 | Controller,\r | |
534 | &gEfiPciIoProtocolGuid,\r | |
535 | (VOID **) &PciIo,\r | |
536 | This->DriverBindingHandle,\r | |
537 | ChildHandleBuffer[Index],\r | |
538 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
539 | ); \r | |
c3902377 | 540 | }\r |
541 | }\r | |
542 | \r | |
543 | if (EFI_ERROR (Status)) {\r | |
544 | AllChildrenStopped = FALSE;\r | |
545 | }\r | |
546 | }\r | |
547 | \r | |
548 | if (!AllChildrenStopped) {\r | |
549 | return EFI_DEVICE_ERROR;\r | |
550 | }\r | |
551 | \r | |
552 | return EFI_SUCCESS;\r | |
553 | }\r | |
6fcb2d91 | 554 | \r |
c3902377 | 555 | //\r |
556 | // Internal Function\r | |
557 | //\r | |
6fcb2d91 | 558 | \r |
559 | /**\r | |
560 | Create EFI Handle for a ISA device found via ISA ACPI Protocol \r | |
561 | \r | |
562 | @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
563 | @param[in] Controller The handle of ISA bus controller(PCI to ISA bridge)\r | |
564 | @param[in] PciIo The Pointer to the PCI protocol \r | |
565 | @param[in] ParentDevicePath Device path of the ISA bus controller\r | |
566 | @param[in] IsaDeviceResourceList The resource list of the ISA device\r | |
567 | @param[in] ChildDevicePath The pointer to the child device.\r | |
568 | \r | |
569 | @retval EFI_SUCCESS The handle for the child device was created.\r | |
570 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
571 | @retval EFI_DEVICE_ERROR The handle for the child device can not be created.\r | |
572 | **/\r | |
c3902377 | 573 | EFI_STATUS\r |
574 | IsaCreateDevice (\r | |
575 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
576 | IN EFI_HANDLE Controller,\r | |
577 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
578 | IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,\r | |
579 | IN EFI_ISA_ACPI_RESOURCE_LIST *IsaDeviceResourceList,\r | |
580 | OUT EFI_DEVICE_PATH_PROTOCOL **ChildDevicePath\r | |
581 | )\r | |
c3902377 | 582 | {\r |
583 | EFI_STATUS Status;\r | |
584 | ISA_IO_DEVICE *IsaIoDevice;\r | |
585 | EFI_DEV_PATH Node;\r | |
586 | \r | |
587 | //\r | |
588 | // Initialize the PCI_IO_DEVICE structure\r | |
589 | //\r | |
590 | IsaIoDevice = AllocateZeroPool (sizeof (ISA_IO_DEVICE));\r | |
591 | if (IsaIoDevice == NULL) {\r | |
592 | return EFI_OUT_OF_RESOURCES;\r | |
593 | }\r | |
594 | \r | |
595 | IsaIoDevice->Signature = ISA_IO_DEVICE_SIGNATURE;\r | |
596 | IsaIoDevice->Handle = NULL;\r | |
597 | IsaIoDevice->PciIo = PciIo;\r | |
598 | \r | |
599 | //\r | |
600 | // Initialize the ISA I/O instance structure\r | |
601 | //\r | |
6fcb2d91 | 602 | InitializeIsaIoInstance (IsaIoDevice, IsaDeviceResourceList);\r |
603 | \r | |
c3902377 | 604 | //\r |
605 | // Build the child device path\r | |
606 | //\r | |
607 | Node.DevPath.Type = ACPI_DEVICE_PATH;\r | |
608 | Node.DevPath.SubType = ACPI_DP;\r | |
609 | SetDevicePathNodeLength (&Node.DevPath, sizeof (ACPI_HID_DEVICE_PATH));\r | |
610 | Node.Acpi.HID = IsaDeviceResourceList->Device.HID;\r | |
611 | Node.Acpi.UID = IsaDeviceResourceList->Device.UID;\r | |
612 | \r | |
613 | IsaIoDevice->DevicePath = AppendDevicePathNode (\r | |
614 | ParentDevicePath,\r | |
615 | &Node.DevPath\r | |
616 | );\r | |
617 | \r | |
618 | if (IsaIoDevice->DevicePath == NULL) {\r | |
6fcb2d91 | 619 | Status = EFI_OUT_OF_RESOURCES;\r |
c3902377 | 620 | goto Done;\r |
621 | }\r | |
622 | \r | |
623 | *ChildDevicePath = IsaIoDevice->DevicePath;\r | |
624 | \r | |
625 | //\r | |
6fcb2d91 | 626 | // Create a child handle and install Device Path and ISA I/O protocols\r |
c3902377 | 627 | //\r |
628 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
629 | &IsaIoDevice->Handle,\r | |
630 | &gEfiDevicePathProtocolGuid,\r | |
631 | IsaIoDevice->DevicePath,\r | |
632 | &gEfiIsaIoProtocolGuid,\r | |
633 | &IsaIoDevice->IsaIo,\r | |
634 | NULL\r | |
635 | );\r | |
636 | if (EFI_ERROR (Status)) {\r | |
637 | goto Done;\r | |
638 | }\r | |
639 | \r | |
640 | Status = gBS->OpenProtocol (\r | |
641 | Controller,\r | |
642 | &gEfiPciIoProtocolGuid,\r | |
643 | (VOID **) &PciIo,\r | |
644 | This->DriverBindingHandle,\r | |
645 | IsaIoDevice->Handle,\r | |
646 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
647 | );\r | |
648 | if (EFI_ERROR (Status)) {\r | |
649 | gBS->UninstallMultipleProtocolInterfaces (\r | |
650 | IsaIoDevice->Handle,\r | |
651 | &gEfiDevicePathProtocolGuid,\r | |
652 | IsaIoDevice->DevicePath,\r | |
653 | &gEfiIsaIoProtocolGuid,\r | |
654 | &IsaIoDevice->IsaIo,\r | |
655 | NULL\r | |
656 | );\r | |
657 | }\r | |
658 | \r | |
659 | Done:\r | |
660 | \r | |
661 | if (EFI_ERROR (Status)) {\r | |
662 | if (IsaIoDevice->DevicePath != NULL) {\r | |
f423cbf1 | 663 | FreePool (IsaIoDevice->DevicePath);\r |
c3902377 | 664 | }\r |
665 | \r | |
f423cbf1 | 666 | FreePool (IsaIoDevice);\r |
c3902377 | 667 | }\r |
668 | \r | |
669 | return Status;\r | |
670 | }\r | |
6fcb2d91 | 671 | \r |