4 Discovers all the ISA Controllers and their resources by using the ISA ACPI
5 Protocol, produces an instance of the ISA I/O Protocol for every ISA
6 Controller found. This driver is designed to manage a PCI-to-ISA bridge Device
9 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
10 This program and the accompanying materials
11 are licensed and made available under the terms and conditions of the BSD License
12 which accompanies this distribution. The full text of the license may be found at
13 http://opensource.org/licenses/bsd-license.php
15 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
16 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "InternalIsaBus.h"
23 // ISA Bus Driver Global Variables
25 EFI_DRIVER_BINDING_PROTOCOL gIsaBusControllerDriver
= {
26 IsaBusControllerDriverSupported
,
27 IsaBusControllerDriverStart
,
28 IsaBusControllerDriverStop
,
35 The main entry point for the ISA Bus driver.
37 @param[in] ImageHandle The firmware allocated handle for the EFI image.
38 @param[in] SystemTable A pointer to the EFI System Table.
40 @retval EFI_SUCCESS The entry point is executed successfully.
41 @retval EFI_OUT_OF_RESOURCES There was not enough memory in pool to install all the protocols.
46 IN EFI_HANDLE ImageHandle
,
47 IN EFI_SYSTEM_TABLE
*SystemTable
53 // Install driver model protocol(s).
55 Status
= EfiLibInstallDriverBindingComponentName2 (
58 &gIsaBusControllerDriver
,
60 &gIsaBusComponentName
,
61 &gIsaBusComponentName2
63 ASSERT_EFI_ERROR (Status
);
69 Tests to see if a controller can be managed by the ISA Bus Driver. If a child device is provided,
70 it further tests to see if this driver supports creating a handle for the specified child device.
72 Note that the ISA Bus driver always creates all of its child handles on the first call to Start().
73 How the Start() function of a driver is implemented can affect how the Supported() function is implemented.
75 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
76 @param[in] Controller The handle of the controller to test.
77 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
79 @retval EFI_SUCCESS The device is supported by this driver.
80 @retval EFI_ALREADY_STARTED The device is already being managed by this driver.
81 @retval EFI_ACCESS_DENIED The device is already being managed by a different driver
82 or an application that requires exclusive access.
83 @retval EFI_UNSUPPORTED The device is is not supported by this driver.
88 IsaBusControllerDriverSupported (
89 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
90 IN EFI_HANDLE Controller
,
91 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
95 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
96 EFI_ISA_ACPI_PROTOCOL
*IsaAcpi
;
99 // If RemainingDevicePath is not NULL, it should verify that the first device
100 // path node in RemainingDevicePath is an ACPI Device path node which is a
101 // legal Device Path Node for this bus driver's children.
103 if (RemainingDevicePath
!= NULL
) {
104 if (RemainingDevicePath
->Type
!= ACPI_DEVICE_PATH
) {
105 return EFI_UNSUPPORTED
;
106 } else if (RemainingDevicePath
->SubType
== ACPI_DP
) {
107 if (DevicePathNodeLength (RemainingDevicePath
) != sizeof (ACPI_HID_DEVICE_PATH
)) {
108 return EFI_UNSUPPORTED
;
110 } else if (RemainingDevicePath
->SubType
== ACPI_EXTENDED_DP
) {
111 if (DevicePathNodeLength (RemainingDevicePath
) != sizeof (ACPI_EXTENDED_HID_DEVICE_PATH
)) {
112 return EFI_UNSUPPORTED
;
115 return EFI_UNSUPPORTED
;
119 // Try to open EFI DEVICE PATH protocol on the controller
121 Status
= gBS
->OpenProtocol (
123 &gEfiDevicePathProtocolGuid
,
124 (VOID
**) &ParentDevicePath
,
125 This
->DriverBindingHandle
,
127 EFI_OPEN_PROTOCOL_BY_DRIVER
130 // Although this driver creates all child handles at one time,
131 // but because all child handles may be not stopped at one time in EFI Driver Binding.Stop(),
132 // So it is allowed to create child handles again in successive calls to EFI Driver Binding.Start().
134 if (Status
== EFI_ALREADY_STARTED
) {
138 if (EFI_ERROR (Status
)) {
144 &gEfiDevicePathProtocolGuid
,
145 This
->DriverBindingHandle
,
150 // Try to get Pci IO Protocol because it is assumed
151 // to have been opened by ISA ACPI driver
153 Status
= gBS
->OpenProtocol (
155 &gEfiPciIoProtocolGuid
,
157 This
->DriverBindingHandle
,
159 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
161 if (EFI_ERROR (Status
)) {
166 // Try to open the Isa Acpi protocol on the controller
168 Status
= gBS
->OpenProtocol (
170 &gEfiIsaAcpiProtocolGuid
,
172 This
->DriverBindingHandle
,
174 EFI_OPEN_PROTOCOL_BY_DRIVER
176 if (EFI_ERROR (Status
)) {
181 // Add more check to see if the child device is valid by calling IsaAcpi->DeviceEnumerate?
186 &gEfiIsaAcpiProtocolGuid
,
187 This
->DriverBindingHandle
,
195 Start this driver on ControllerHandle.
197 Note that the ISA Bus driver always creates all of its child handles on the first call to Start().
198 The Start() function is designed to be invoked from the EFI boot service ConnectController().
199 As a result, much of the error checking on the parameters to Start() has been moved into this
200 common boot service. It is legal to call Start() from other locations, but the following calling
201 restrictions must be followed or the system behavior will not be deterministic.
202 1. ControllerHandle must be a valid EFI_HANDLE.
203 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
204 EFI_DEVICE_PATH_PROTOCOL.
205 3. Prior to calling Start(), the Supported() function for the driver specified by This must
206 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
208 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
209 @param[in] ControllerHandle The handle of the controller to start. This handle
210 must support a protocol interface that supplies
211 an I/O abstraction to the driver.
212 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
213 This parameter is ignored by device drivers, and is optional for bus drivers.
215 @retval EFI_SUCCESS The device was started.
216 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.
217 Currently not implemented.
218 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
219 @retval Others The driver failded to start the device.
223 IsaBusControllerDriverStart (
224 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
225 IN EFI_HANDLE Controller
,
226 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
230 EFI_PCI_IO_PROTOCOL
*PciIo
;
231 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
232 EFI_ISA_ACPI_PROTOCOL
*IsaAcpi
;
233 EFI_ISA_ACPI_DEVICE_ID
*IsaDevice
;
234 EFI_ISA_ACPI_RESOURCE_LIST
*ResourceList
;
235 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenMemoryTest
;
238 // Local variables declaration for StatusCode reporting
240 EFI_DEVICE_PATH_PROTOCOL
*DevicePathData
;
242 DevicePathData
= NULL
;
245 // Get Pci IO Protocol
247 Status
= gBS
->OpenProtocol (
249 &gEfiPciIoProtocolGuid
,
251 This
->DriverBindingHandle
,
253 EFI_OPEN_PROTOCOL_GET_PROTOCOL
255 if (EFI_ERROR (Status
)) {
260 // Open Device Path Protocol
262 Status
= gBS
->OpenProtocol (
264 &gEfiDevicePathProtocolGuid
,
265 (VOID
**) &ParentDevicePath
,
266 This
->DriverBindingHandle
,
268 EFI_OPEN_PROTOCOL_BY_DRIVER
270 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
275 // Open ISA Acpi Protocol
277 Status
= gBS
->OpenProtocol (
279 &gEfiIsaAcpiProtocolGuid
,
281 This
->DriverBindingHandle
,
283 EFI_OPEN_PROTOCOL_BY_DRIVER
285 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
287 // Close opened protocol
291 &gEfiDevicePathProtocolGuid
,
292 This
->DriverBindingHandle
,
298 // The IsaBus driver will use memory below 16M, which is not tested yet,
299 // so call CompatibleRangeTest to test them. Since memory below 1M should
300 // be reserved to CSM, and 15M~16M might be reserved for Isa hole, test 1M
303 Status
= gBS
->LocateProtocol (
304 &gEfiGenericMemTestProtocolGuid
,
306 (VOID
**) &GenMemoryTest
309 if (!EFI_ERROR (Status
)) {
310 Status
= GenMemoryTest
->CompatibleRangeTest (
317 // Report Status Code here since we will initialize the host controller
319 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
321 (EFI_IO_BUS_LPC
| EFI_IOB_PC_INIT
),
326 // first init ISA interface
328 IsaAcpi
->InterfaceInit (IsaAcpi
);
331 // Report Status Code here since we will enable the host controller
333 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
335 (EFI_IO_BUS_LPC
| EFI_IOB_PC_ENABLE
),
340 // Create each ISA device handle in this ISA bus
344 Status
= IsaAcpi
->DeviceEnumerate (IsaAcpi
, &IsaDevice
);
345 if (EFI_ERROR (Status
)) {
349 // Get current resource of this ISA device
352 Status
= IsaAcpi
->GetCurResource (IsaAcpi
, IsaDevice
, &ResourceList
);
353 if (EFI_ERROR (Status
)) {
358 // Create handle for this ISA device
360 // If any child device handle was created in previous call to Start() and not stopped
361 // in previous call to Stop(), it will not be created again because the
362 // InstallMultipleProtocolInterfaces() boot service will reject same device path.
364 Status
= IsaCreateDevice (
373 if (EFI_ERROR (Status
)) {
377 // Initialize ISA device
379 IsaAcpi
->InitDevice (IsaAcpi
, IsaDevice
);
382 // Set resources for this ISA device
384 Status
= IsaAcpi
->SetResource (IsaAcpi
, IsaDevice
, ResourceList
);
387 // Report Status Code here when failed to resource conflicts
389 if (EFI_ERROR (Status
) && (Status
!= EFI_UNSUPPORTED
)) {
391 // It's hard to tell which resource conflicts
393 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
395 (EFI_IO_BUS_LPC
| EFI_IOB_EC_RESOURCE_CONFLICT
),
401 // Set power for this ISA device
403 IsaAcpi
->SetPower (IsaAcpi
, IsaDevice
, TRUE
);
406 // Enable this ISA device
408 IsaAcpi
->EnableDevice (IsaAcpi
, IsaDevice
, TRUE
);
416 Stop this driver on ControllerHandle.
418 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
419 As a result, much of the error checking on the parameters to Stop() has been moved
420 into this common boot service. It is legal to call Stop() from other locations,
421 but the following calling restrictions must be followed or the system behavior will not be deterministic.
422 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
423 same driver's Start() function.
424 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
425 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
426 Start() function, and the Start() function must have called OpenProtocol() on
427 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
429 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
430 @param[in] ControllerHandle A handle to the device being stopped. The handle must
431 support a bus specific I/O protocol for the driver
432 to use to stop the device.
433 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
434 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
435 if NumberOfChildren is 0.
437 @retval EFI_SUCCESS The device was stopped.
438 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
442 IsaBusControllerDriverStop (
443 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
444 IN EFI_HANDLE Controller
,
445 IN UINTN NumberOfChildren
,
446 IN EFI_HANDLE
* ChildHandleBuffer OPTIONAL
451 BOOLEAN AllChildrenStopped
;
452 ISA_IO_DEVICE
*IsaIoDevice
;
453 EFI_ISA_IO_PROTOCOL
*IsaIo
;
454 EFI_PCI_IO_PROTOCOL
*PciIo
;
456 if (NumberOfChildren
== 0) {
458 // Close the bus driver
460 Status
= gBS
->CloseProtocol (
462 &gEfiDevicePathProtocolGuid
,
463 This
->DriverBindingHandle
,
466 if (EFI_ERROR (Status
)) {
470 Status
= gBS
->CloseProtocol (
472 &gEfiIsaAcpiProtocolGuid
,
473 This
->DriverBindingHandle
,
476 if (EFI_ERROR (Status
)) {
483 // Complete all outstanding transactions to Controller.
484 // Don't allow any new transaction to Controller to be started.
487 // Stop all the children
488 // Find all the ISA devices that were discovered on this PCI to ISA Bridge
489 // with the Start() function.
491 AllChildrenStopped
= TRUE
;
493 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
495 Status
= gBS
->OpenProtocol (
496 ChildHandleBuffer
[Index
],
497 &gEfiIsaIoProtocolGuid
,
499 This
->DriverBindingHandle
,
501 EFI_OPEN_PROTOCOL_GET_PROTOCOL
503 if (!EFI_ERROR (Status
)) {
505 IsaIoDevice
= ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo
);
508 // Close the child handle
511 Status
= gBS
->CloseProtocol (
513 &gEfiPciIoProtocolGuid
,
514 This
->DriverBindingHandle
,
515 ChildHandleBuffer
[Index
]
517 Status
= gBS
->UninstallMultipleProtocolInterfaces (
518 ChildHandleBuffer
[Index
],
519 &gEfiDevicePathProtocolGuid
,
520 IsaIoDevice
->DevicePath
,
521 &gEfiIsaIoProtocolGuid
,
526 if (!EFI_ERROR (Status
)) {
527 FreePool (IsaIoDevice
->DevicePath
);
528 FreePool (IsaIoDevice
);
531 // Re-open PCI IO Protocol on behalf of the child device
532 // because of failure of destroying the child device handle
536 &gEfiPciIoProtocolGuid
,
538 This
->DriverBindingHandle
,
539 ChildHandleBuffer
[Index
],
540 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
545 if (EFI_ERROR (Status
)) {
546 AllChildrenStopped
= FALSE
;
550 if (!AllChildrenStopped
) {
551 return EFI_DEVICE_ERROR
;
562 Create EFI Handle for a ISA device found via ISA ACPI Protocol
564 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.
565 @param[in] Controller The handle of ISA bus controller(PCI to ISA bridge)
566 @param[in] PciIo The Pointer to the PCI protocol
567 @param[in] ParentDevicePath Device path of the ISA bus controller
568 @param[in] IsaDeviceResourceList The resource list of the ISA device
569 @param[out] ChildDevicePath The pointer to the child device.
571 @retval EFI_SUCCESS The handle for the child device was created.
572 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
573 @retval EFI_DEVICE_ERROR The handle for the child device can not be created.
577 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
578 IN EFI_HANDLE Controller
,
579 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
580 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
581 IN EFI_ISA_ACPI_RESOURCE_LIST
*IsaDeviceResourceList
,
582 OUT EFI_DEVICE_PATH_PROTOCOL
**ChildDevicePath
586 ISA_IO_DEVICE
*IsaIoDevice
;
590 // Initialize the PCI_IO_DEVICE structure
592 IsaIoDevice
= AllocateZeroPool (sizeof (ISA_IO_DEVICE
));
593 if (IsaIoDevice
== NULL
) {
594 return EFI_OUT_OF_RESOURCES
;
597 IsaIoDevice
->Signature
= ISA_IO_DEVICE_SIGNATURE
;
598 IsaIoDevice
->Handle
= NULL
;
599 IsaIoDevice
->PciIo
= PciIo
;
602 // Initialize the ISA I/O instance structure
604 InitializeIsaIoInstance (IsaIoDevice
, IsaDeviceResourceList
);
607 // Build the child device path
609 Node
.DevPath
.Type
= ACPI_DEVICE_PATH
;
610 Node
.DevPath
.SubType
= ACPI_DP
;
611 SetDevicePathNodeLength (&Node
.DevPath
, sizeof (ACPI_HID_DEVICE_PATH
));
612 Node
.Acpi
.HID
= IsaDeviceResourceList
->Device
.HID
;
613 Node
.Acpi
.UID
= IsaDeviceResourceList
->Device
.UID
;
615 IsaIoDevice
->DevicePath
= AppendDevicePathNode (
620 if (IsaIoDevice
->DevicePath
== NULL
) {
621 Status
= EFI_OUT_OF_RESOURCES
;
625 *ChildDevicePath
= IsaIoDevice
->DevicePath
;
628 // Create a child handle and install Device Path and ISA I/O protocols
630 Status
= gBS
->InstallMultipleProtocolInterfaces (
631 &IsaIoDevice
->Handle
,
632 &gEfiDevicePathProtocolGuid
,
633 IsaIoDevice
->DevicePath
,
634 &gEfiIsaIoProtocolGuid
,
638 if (EFI_ERROR (Status
)) {
642 Status
= gBS
->OpenProtocol (
644 &gEfiPciIoProtocolGuid
,
646 This
->DriverBindingHandle
,
648 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
650 if (EFI_ERROR (Status
)) {
651 gBS
->UninstallMultipleProtocolInterfaces (
653 &gEfiDevicePathProtocolGuid
,
654 IsaIoDevice
->DevicePath
,
655 &gEfiIsaIoProtocolGuid
,
663 if (EFI_ERROR (Status
)) {
664 if (IsaIoDevice
->DevicePath
!= NULL
) {
665 FreePool (IsaIoDevice
->DevicePath
);
668 FreePool (IsaIoDevice
);