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