]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaBus.c
IntelFrameworkModulePkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaBusDxe / IsaBus.c
CommitLineData
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
9Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
180a5a35 10This program and the accompanying materials\r
f8cd287b 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
0a6f4824 37 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
6fcb2d91 38 @param[in] SystemTable A pointer to the EFI System Table.\r
0a6f4824 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
0a6f4824
LG
68/**\r
69 Tests to see if a controller can be managed by the ISA Bus Driver. If a child device is provided,\r
6fcb2d91 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
0a6f4824 75 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
6fcb2d91 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
0a6f4824 78\r
6fcb2d91 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
0a6f4824 81 @retval EFI_ACCESS_DENIED The device is already being managed by a different driver\r
6fcb2d91 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
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
0a6f4824 100 // path node in RemainingDevicePath is an ACPI Device path node which is a\r
6fcb2d91 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
0a6f4824
LG
195 Start this driver on ControllerHandle.\r
196\r
6fcb2d91 197 Note that the ISA Bus driver always creates all of its child handles on the first call to Start().\r
0a6f4824
LG
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
6fcb2d91 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
0a6f4824 206 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
6fcb2d91 207\r
208 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
0a6f4824
LG
209 @param[in] ControllerHandle The handle of the controller to start. This handle\r
210 must support a protocol interface that supplies\r
6fcb2d91 211 an I/O abstraction to the driver.\r
0a6f4824 212 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.\r
6fcb2d91 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 221EFI_STATUS\r
222EFIAPI\r
223IsaBusControllerDriverStart (\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
613382e9
ED
242 DevicePathData = NULL;\r
243\r
c3902377 244 //\r
6fcb2d91 245 // Get Pci IO Protocol\r
c3902377 246 //\r
247 Status = gBS->OpenProtocol (\r
248 Controller,\r
6fcb2d91 249 &gEfiPciIoProtocolGuid,\r
250 (VOID **) &PciIo,\r
c3902377 251 This->DriverBindingHandle,\r
252 Controller,\r
6fcb2d91 253 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
c3902377 254 );\r
6fcb2d91 255 if (EFI_ERROR (Status)) {\r
c3902377 256 return Status;\r
257 }\r
6fcb2d91 258\r
c3902377 259 //\r
6fcb2d91 260 // Open Device Path Protocol\r
c3902377 261 //\r
262 Status = gBS->OpenProtocol (\r
263 Controller,\r
6fcb2d91 264 &gEfiDevicePathProtocolGuid,\r
265 (VOID **) &ParentDevicePath,\r
c3902377 266 This->DriverBindingHandle,\r
267 Controller,\r
6fcb2d91 268 EFI_OPEN_PROTOCOL_BY_DRIVER\r
c3902377 269 );\r
9277fdf8 270 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
c3902377 271 return Status;\r
272 }\r
6fcb2d91 273\r
c3902377 274 //\r
275 // Open ISA Acpi Protocol\r
276 //\r
277 Status = gBS->OpenProtocol (\r
278 Controller,\r
279 &gEfiIsaAcpiProtocolGuid,\r
280 (VOID **) &IsaAcpi,\r
281 This->DriverBindingHandle,\r
282 Controller,\r
283 EFI_OPEN_PROTOCOL_BY_DRIVER\r
284 );\r
9277fdf8 285 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
c3902377 286 //\r
287 // Close opened protocol\r
288 //\r
289 gBS->CloseProtocol (\r
290 Controller,\r
291 &gEfiDevicePathProtocolGuid,\r
292 This->DriverBindingHandle,\r
293 Controller\r
294 );\r
c3902377 295 return Status;\r
296 }\r
297 //\r
298 // The IsaBus driver will use memory below 16M, which is not tested yet,\r
299 // so call CompatibleRangeTest to test them. Since memory below 1M should\r
300 // be reserved to CSM, and 15M~16M might be reserved for Isa hole, test 1M\r
301 // ~15M here\r
302 //\r
303 Status = gBS->LocateProtocol (\r
304 &gEfiGenericMemTestProtocolGuid,\r
305 NULL,\r
306 (VOID **) &GenMemoryTest\r
307 );\r
308\r
309 if (!EFI_ERROR (Status)) {\r
310 Status = GenMemoryTest->CompatibleRangeTest (\r
311 GenMemoryTest,\r
312 0x100000,\r
313 0xE00000\r
314 );\r
315 }\r
316 //\r
317 // Report Status Code here since we will initialize the host controller\r
318 //\r
319 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
320 EFI_PROGRESS_CODE,\r
321 (EFI_IO_BUS_LPC | EFI_IOB_PC_INIT),\r
322 ParentDevicePath\r
323 );\r
324\r
325 //\r
326 // first init ISA interface\r
327 //\r
328 IsaAcpi->InterfaceInit (IsaAcpi);\r
329\r
330 //\r
331 // Report Status Code here since we will enable the host controller\r
332 //\r
333 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
334 EFI_PROGRESS_CODE,\r
335 (EFI_IO_BUS_LPC | EFI_IOB_PC_ENABLE),\r
336 ParentDevicePath\r
337 );\r
338\r
339 //\r
340 // Create each ISA device handle in this ISA bus\r
341 //\r
342 IsaDevice = NULL;\r
343 do {\r
344 Status = IsaAcpi->DeviceEnumerate (IsaAcpi, &IsaDevice);\r
345 if (EFI_ERROR (Status)) {\r
346 break;\r
347 }\r
348 //\r
349 // Get current resource of this ISA device\r
350 //\r
351 ResourceList = NULL;\r
352 Status = IsaAcpi->GetCurResource (IsaAcpi, IsaDevice, &ResourceList);\r
353 if (EFI_ERROR (Status)) {\r
354 continue;\r
355 }\r
356\r
357 //\r
358 // Create handle for this ISA device\r
359 //\r
9277fdf8 360 // If any child device handle was created in previous call to Start() and not stopped\r
361 // in previous call to Stop(), it will not be created again because the\r
362 // InstallMultipleProtocolInterfaces() boot service will reject same device path.\r
363 //\r
c3902377 364 Status = IsaCreateDevice (\r
365 This,\r
366 Controller,\r
367 PciIo,\r
368 ParentDevicePath,\r
369 ResourceList,\r
370 &DevicePathData\r
c3902377 371 );\r
372\r
373 if (EFI_ERROR (Status)) {\r
374 continue;\r
375 }\r
376 //\r
377 // Initialize ISA device\r
378 //\r
379 IsaAcpi->InitDevice (IsaAcpi, IsaDevice);\r
380\r
381 //\r
382 // Set resources for this ISA device\r
383 //\r
384 Status = IsaAcpi->SetResource (IsaAcpi, IsaDevice, ResourceList);\r
385\r
386 //\r
387 // Report Status Code here when failed to resource conflicts\r
388 //\r
389 if (EFI_ERROR (Status) && (Status != EFI_UNSUPPORTED)) {\r
390 //\r
391 // It's hard to tell which resource conflicts\r
392 //\r
c3902377 393 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
394 EFI_ERROR_CODE,\r
395 (EFI_IO_BUS_LPC | EFI_IOB_EC_RESOURCE_CONFLICT),\r
396 DevicePathData\r
397 );\r
398\r
399 }\r
400 //\r
401 // Set power for this ISA device\r
402 //\r
403 IsaAcpi->SetPower (IsaAcpi, IsaDevice, TRUE);\r
404\r
405 //\r
406 // Enable this ISA device\r
407 //\r
408 IsaAcpi->EnableDevice (IsaAcpi, IsaDevice, TRUE);\r
409\r
410 } while (TRUE);\r
411\r
c3902377 412 return EFI_SUCCESS;\r
413}\r
414\r
6fcb2d91 415/**\r
0a6f4824
LG
416 Stop this driver on ControllerHandle.\r
417\r
418 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
419 As a result, much of the error checking on the parameters to Stop() has been moved\r
420 into this common boot service. It is legal to call Stop() from other locations,\r
6fcb2d91 421 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
422 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
423 same driver's Start() function.\r
424 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
425 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
426 Start() function, and the Start() function must have called OpenProtocol() on\r
427 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
0a6f4824 428\r
6fcb2d91 429 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
0a6f4824
LG
430 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
431 support a bus specific I/O protocol for the driver\r
6fcb2d91 432 to use to stop the device.\r
433 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
0a6f4824 434 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
6fcb2d91 435 if NumberOfChildren is 0.\r
436\r
437 @retval EFI_SUCCESS The device was stopped.\r
438 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
439**/\r
c3902377 440EFI_STATUS\r
441EFIAPI\r
442IsaBusControllerDriverStop (\r
443 IN EFI_DRIVER_BINDING_PROTOCOL * This,\r
444 IN EFI_HANDLE Controller,\r
445 IN UINTN NumberOfChildren,\r
446 IN EFI_HANDLE * ChildHandleBuffer OPTIONAL\r
447 )\r
c3902377 448{\r
449 EFI_STATUS Status;\r
450 UINTN Index;\r
451 BOOLEAN AllChildrenStopped;\r
452 ISA_IO_DEVICE *IsaIoDevice;\r
453 EFI_ISA_IO_PROTOCOL *IsaIo;\r
9277fdf8 454 EFI_PCI_IO_PROTOCOL *PciIo;\r
c3902377 455\r
456 if (NumberOfChildren == 0) {\r
457 //\r
458 // Close the bus driver\r
459 //\r
c3902377 460 Status = gBS->CloseProtocol (\r
461 Controller,\r
462 &gEfiDevicePathProtocolGuid,\r
463 This->DriverBindingHandle,\r
464 Controller\r
465 );\r
466 if (EFI_ERROR (Status)) {\r
467 return Status;\r
468 }\r
469\r
470 Status = gBS->CloseProtocol (\r
471 Controller,\r
472 &gEfiIsaAcpiProtocolGuid,\r
473 This->DriverBindingHandle,\r
474 Controller\r
475 );\r
476 if (EFI_ERROR (Status)) {\r
477 return Status;\r
478 }\r
479\r
480 return EFI_SUCCESS;\r
481 }\r
482 //\r
483 // Complete all outstanding transactions to Controller.\r
484 // Don't allow any new transaction to Controller to be started.\r
485 //\r
486 //\r
487 // Stop all the children\r
488 // Find all the ISA devices that were discovered on this PCI to ISA Bridge\r
489 // with the Start() function.\r
490 //\r
491 AllChildrenStopped = TRUE;\r
492\r
493 for (Index = 0; Index < NumberOfChildren; Index++) {\r
494\r
495 Status = gBS->OpenProtocol (\r
496 ChildHandleBuffer[Index],\r
497 &gEfiIsaIoProtocolGuid,\r
498 (VOID **) &IsaIo,\r
499 This->DriverBindingHandle,\r
500 Controller,\r
501 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
502 );\r
503 if (!EFI_ERROR (Status)) {\r
504\r
505 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo);\r
506\r
9277fdf8 507 //\r
508 // Close the child handle\r
509 //\r
510\r
511 Status = gBS->CloseProtocol (\r
512 Controller,\r
513 &gEfiPciIoProtocolGuid,\r
514 This->DriverBindingHandle,\r
515 ChildHandleBuffer[Index]\r
516 );\r
c3902377 517 Status = gBS->UninstallMultipleProtocolInterfaces (\r
518 ChildHandleBuffer[Index],\r
519 &gEfiDevicePathProtocolGuid,\r
520 IsaIoDevice->DevicePath,\r
521 &gEfiIsaIoProtocolGuid,\r
522 &IsaIoDevice->IsaIo,\r
523 NULL\r
524 );\r
525\r
526 if (!EFI_ERROR (Status)) {\r
f423cbf1 527 FreePool (IsaIoDevice->DevicePath);\r
528 FreePool (IsaIoDevice);\r
9277fdf8 529 } else {\r
530 //\r
531 // Re-open PCI IO Protocol on behalf of the child device\r
532 // because of failure of destroying the child device handle\r
533 //\r
534 gBS->OpenProtocol (\r
535 Controller,\r
536 &gEfiPciIoProtocolGuid,\r
537 (VOID **) &PciIo,\r
538 This->DriverBindingHandle,\r
539 ChildHandleBuffer[Index],\r
540 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
0a6f4824 541 );\r
c3902377 542 }\r
543 }\r
544\r
545 if (EFI_ERROR (Status)) {\r
546 AllChildrenStopped = FALSE;\r
547 }\r
548 }\r
549\r
550 if (!AllChildrenStopped) {\r
551 return EFI_DEVICE_ERROR;\r
552 }\r
553\r
554 return EFI_SUCCESS;\r
555}\r
6fcb2d91 556\r
c3902377 557//\r
558// Internal Function\r
559//\r
6fcb2d91 560\r
561/**\r
0a6f4824 562 Create EFI Handle for a ISA device found via ISA ACPI Protocol\r
6fcb2d91 563\r
564 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.\r
565 @param[in] Controller The handle of ISA bus controller(PCI to ISA bridge)\r
0a6f4824 566 @param[in] PciIo The Pointer to the PCI protocol\r
6fcb2d91 567 @param[in] ParentDevicePath Device path of the ISA bus controller\r
568 @param[in] IsaDeviceResourceList The resource list of the ISA device\r
0a2dfa19 569 @param[out] ChildDevicePath The pointer to the child device.\r
6fcb2d91 570\r
571 @retval EFI_SUCCESS The handle for the child device was created.\r
572 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
573 @retval EFI_DEVICE_ERROR The handle for the child device can not be created.\r
574**/\r
c3902377 575EFI_STATUS\r
576IsaCreateDevice (\r
577 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
578 IN EFI_HANDLE Controller,\r
579 IN EFI_PCI_IO_PROTOCOL *PciIo,\r
580 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,\r
581 IN EFI_ISA_ACPI_RESOURCE_LIST *IsaDeviceResourceList,\r
582 OUT EFI_DEVICE_PATH_PROTOCOL **ChildDevicePath\r
583 )\r
c3902377 584{\r
585 EFI_STATUS Status;\r
586 ISA_IO_DEVICE *IsaIoDevice;\r
587 EFI_DEV_PATH Node;\r
588\r
589 //\r
590 // Initialize the PCI_IO_DEVICE structure\r
591 //\r
592 IsaIoDevice = AllocateZeroPool (sizeof (ISA_IO_DEVICE));\r
593 if (IsaIoDevice == NULL) {\r
594 return EFI_OUT_OF_RESOURCES;\r
595 }\r
596\r
597 IsaIoDevice->Signature = ISA_IO_DEVICE_SIGNATURE;\r
598 IsaIoDevice->Handle = NULL;\r
599 IsaIoDevice->PciIo = PciIo;\r
600\r
601 //\r
602 // Initialize the ISA I/O instance structure\r
603 //\r
6fcb2d91 604 InitializeIsaIoInstance (IsaIoDevice, IsaDeviceResourceList);\r
605\r
c3902377 606 //\r
607 // Build the child device path\r
608 //\r
609 Node.DevPath.Type = ACPI_DEVICE_PATH;\r
610 Node.DevPath.SubType = ACPI_DP;\r
611 SetDevicePathNodeLength (&Node.DevPath, sizeof (ACPI_HID_DEVICE_PATH));\r
612 Node.Acpi.HID = IsaDeviceResourceList->Device.HID;\r
613 Node.Acpi.UID = IsaDeviceResourceList->Device.UID;\r
614\r
615 IsaIoDevice->DevicePath = AppendDevicePathNode (\r
616 ParentDevicePath,\r
617 &Node.DevPath\r
618 );\r
619\r
620 if (IsaIoDevice->DevicePath == NULL) {\r
6fcb2d91 621 Status = EFI_OUT_OF_RESOURCES;\r
c3902377 622 goto Done;\r
623 }\r
624\r
625 *ChildDevicePath = IsaIoDevice->DevicePath;\r
626\r
627 //\r
6fcb2d91 628 // Create a child handle and install Device Path and ISA I/O protocols\r
c3902377 629 //\r
630 Status = gBS->InstallMultipleProtocolInterfaces (\r
631 &IsaIoDevice->Handle,\r
632 &gEfiDevicePathProtocolGuid,\r
633 IsaIoDevice->DevicePath,\r
634 &gEfiIsaIoProtocolGuid,\r
635 &IsaIoDevice->IsaIo,\r
636 NULL\r
637 );\r
638 if (EFI_ERROR (Status)) {\r
639 goto Done;\r
640 }\r
641\r
642 Status = gBS->OpenProtocol (\r
643 Controller,\r
644 &gEfiPciIoProtocolGuid,\r
645 (VOID **) &PciIo,\r
646 This->DriverBindingHandle,\r
647 IsaIoDevice->Handle,\r
648 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
649 );\r
650 if (EFI_ERROR (Status)) {\r
651 gBS->UninstallMultipleProtocolInterfaces (\r
652 IsaIoDevice->Handle,\r
653 &gEfiDevicePathProtocolGuid,\r
654 IsaIoDevice->DevicePath,\r
655 &gEfiIsaIoProtocolGuid,\r
656 &IsaIoDevice->IsaIo,\r
657 NULL\r
658 );\r
659 }\r
660\r
661Done:\r
662\r
663 if (EFI_ERROR (Status)) {\r
664 if (IsaIoDevice->DevicePath != NULL) {\r
f423cbf1 665 FreePool (IsaIoDevice->DevicePath);\r
c3902377 666 }\r
667\r
f423cbf1 668 FreePool (IsaIoDevice);\r
c3902377 669 }\r
670\r
671 return Status;\r
672}\r
6fcb2d91 673\r