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