3 Discovers all the ISA Controllers and their resources by using the ISA PnP
4 Protocol, produces an instance of the ISA I/O Protocol for every ISA
5 Controller found, loads and initializes all ISA Device Drivers, matches ISA
6 Device Drivers with their respective ISA Controllers in a deterministic
7 manner, and informs a ISA Device Driver when it is to start managing an ISA
10 Copyright (c) 2006 - 2007, Intel Corporation.<BR>
11 All rights reserved. This program and the accompanying materials
12 are licensed and made available under the terms and conditions of the BSD License
13 which accompanies this distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include "InternalIsaBus.h"
25 // ISA Bus Driver Global Variables
27 EFI_DRIVER_BINDING_PROTOCOL gIsaBusControllerDriver
= {
28 IsaBusControllerDriverSupported
,
29 IsaBusControllerDriverStart
,
30 IsaBusControllerDriverStop
,
37 The user Entry Point for module IsaBus. The user code starts with this function.
39 @param[in] ImageHandle The firmware allocated handle for the EFI image.
40 @param[in] SystemTable A pointer to the EFI System Table.
42 @retval EFI_SUCCESS The entry point is executed successfully.
43 @retval other Some error occurs when executing this entry point.
49 IN EFI_HANDLE ImageHandle
,
50 IN EFI_SYSTEM_TABLE
*SystemTable
56 // Install driver model protocol(s).
58 Status
= EfiLibInstallDriverBindingComponentName2 (
61 &gIsaBusControllerDriver
,
63 &gIsaBusComponentName
,
64 &gIsaBusComponentName2
66 ASSERT_EFI_ERROR (Status
);
75 IsaBusControllerDriverSupported (
76 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
77 IN EFI_HANDLE Controller
,
78 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
84 This function checks to see if a controller can be managed by the ISA Bus
85 Driver. This is done by checking to see if the controller supports the
86 EFI_PCI_IO_PROTOCOL protocol, and then looking at the PCI Configuration
87 Header to see if the device is a PCI to ISA bridge. The class code of
88 PCI to ISA bridge: Base class 06h, Sub class 01h Interface 00h
92 This - The EFI_DRIVER_BINDING_PROTOCOL instance.
93 Controller - The handle of the device to check.
94 RemainingDevicePath - A pointer to the remaining portion of a device path.
98 EFI_SUCCESS - The device is supported by this driver.
99 EFI_UNSUPPORTED - The device is not supported by this driver.
104 EFI_ISA_ACPI_PROTOCOL
*IsaAcpi
;
107 // If RemainingDevicePath is not NULL, it should verify that the first device
108 // path node in RemainingDevicePath is an ACPI Device path node
110 if (RemainingDevicePath
!= NULL
) {
111 if (RemainingDevicePath
->Type
!= ACPI_DEVICE_PATH
) {
112 return EFI_UNSUPPORTED
;
113 } else if (RemainingDevicePath
->SubType
== ACPI_DP
) {
114 if (DevicePathNodeLength (RemainingDevicePath
) != sizeof (ACPI_HID_DEVICE_PATH
)) {
115 return EFI_UNSUPPORTED
;
117 } else if (RemainingDevicePath
->SubType
== ACPI_EXTENDED_DP
) {
118 if (DevicePathNodeLength (RemainingDevicePath
) != sizeof (ACPI_EXTENDED_HID_DEVICE_PATH
)) {
119 return EFI_UNSUPPORTED
;
122 return EFI_UNSUPPORTED
;
126 // Test the existence of DEVICE_PATH protocol
128 Status
= gBS
->OpenProtocol (
130 &gEfiDevicePathProtocolGuid
,
132 This
->DriverBindingHandle
,
134 EFI_OPEN_PROTOCOL_TEST_PROTOCOL
136 if (EFI_ERROR (Status
)) {
140 // Get the Isa Acpi protocol
142 Status
= gBS
->OpenProtocol (
144 &gEfiIsaAcpiProtocolGuid
,
146 This
->DriverBindingHandle
,
148 EFI_OPEN_PROTOCOL_BY_DRIVER
150 if (Status
== EFI_ALREADY_STARTED
) {
154 if (EFI_ERROR (Status
)) {
160 &gEfiIsaAcpiProtocolGuid
,
161 This
->DriverBindingHandle
,
170 IsaBusControllerDriverStart (
171 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
172 IN EFI_HANDLE Controller
,
173 IN EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath OPTIONAL
179 This function tells the ISA Bus Driver to start managing a PCI to ISA
184 This - The EFI_DRIVER_BINDING_PROTOCOL instance.
185 Controller - A handle to the device being started.
186 RemainingDevicePath - A pointer to the remaining portion of a device path.
190 EFI_SUCCESS - The device was started.
191 EFI_UNSUPPORTED - The device is not supported.
192 EFI_DEVICE_ERROR - The device could not be started due to a device error.
193 EFI_ALREADY_STARTED - The device has already been started.
194 EFI_INVALID_PARAMETER - One of the parameters has an invalid value.
195 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
201 EFI_PCI_IO_PROTOCOL
*PciIo
;
202 EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
;
203 EFI_ISA_ACPI_PROTOCOL
*IsaAcpi
;
204 EFI_ISA_ACPI_DEVICE_ID
*IsaDevice
;
205 EFI_ISA_ACPI_RESOURCE_LIST
*ResourceList
;
206 EFI_GENERIC_MEMORY_TEST_PROTOCOL
*GenMemoryTest
;
209 // Local variables declaration for StatusCode reporting
211 EFI_DEVICE_PATH_PROTOCOL
*DevicePathData
;
214 // Open Device Path Protocol
216 Status
= gBS
->OpenProtocol (
218 &gEfiDevicePathProtocolGuid
,
219 (VOID
**) &ParentDevicePath
,
220 This
->DriverBindingHandle
,
222 EFI_OPEN_PROTOCOL_BY_DRIVER
224 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
228 // Open Pci IO Protocol
230 Status
= gBS
->OpenProtocol (
232 &gEfiPciIoProtocolGuid
,
234 This
->DriverBindingHandle
,
236 EFI_OPEN_PROTOCOL_GET_PROTOCOL
238 if (EFI_ERROR (Status
)) {
240 // Close opened protocol
244 &gEfiDevicePathProtocolGuid
,
245 This
->DriverBindingHandle
,
251 // Open ISA Acpi Protocol
253 Status
= gBS
->OpenProtocol (
255 &gEfiIsaAcpiProtocolGuid
,
257 This
->DriverBindingHandle
,
259 EFI_OPEN_PROTOCOL_BY_DRIVER
261 if (EFI_ERROR (Status
) && Status
!= EFI_ALREADY_STARTED
) {
263 // Close opened protocol
267 &gEfiDevicePathProtocolGuid
,
268 This
->DriverBindingHandle
,
273 &gEfiPciIoProtocolGuid
,
274 This
->DriverBindingHandle
,
280 // The IsaBus driver will use memory below 16M, which is not tested yet,
281 // so call CompatibleRangeTest to test them. Since memory below 1M should
282 // be reserved to CSM, and 15M~16M might be reserved for Isa hole, test 1M
285 Status
= gBS
->LocateProtocol (
286 &gEfiGenericMemTestProtocolGuid
,
288 (VOID
**) &GenMemoryTest
291 if (!EFI_ERROR (Status
)) {
292 Status
= GenMemoryTest
->CompatibleRangeTest (
299 // Report Status Code here since we will initialize the host controller
301 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
303 (EFI_IO_BUS_LPC
| EFI_IOB_PC_INIT
),
308 // first init ISA interface
310 IsaAcpi
->InterfaceInit (IsaAcpi
);
313 // Report Status Code here since we will enable the host controller
315 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
317 (EFI_IO_BUS_LPC
| EFI_IOB_PC_ENABLE
),
322 // Create each ISA device handle in this ISA bus
326 Status
= IsaAcpi
->DeviceEnumerate (IsaAcpi
, &IsaDevice
);
327 if (EFI_ERROR (Status
)) {
331 // Get current resource of this ISA device
334 Status
= IsaAcpi
->GetCurResource (IsaAcpi
, IsaDevice
, &ResourceList
);
335 if (EFI_ERROR (Status
)) {
340 // Create handle for this ISA device
342 Status
= IsaCreateDevice (
351 if (EFI_ERROR (Status
)) {
355 // Initialize ISA device
357 IsaAcpi
->InitDevice (IsaAcpi
, IsaDevice
);
360 // Set resources for this ISA device
362 Status
= IsaAcpi
->SetResource (IsaAcpi
, IsaDevice
, ResourceList
);
365 // Report Status Code here when failed to resource conflicts
367 if (EFI_ERROR (Status
) && (Status
!= EFI_UNSUPPORTED
)) {
369 // It's hard to tell which resource conflicts
371 REPORT_STATUS_CODE_WITH_DEVICE_PATH (
373 (EFI_IO_BUS_LPC
| EFI_IOB_EC_RESOURCE_CONFLICT
),
379 // Set power for this ISA device
381 IsaAcpi
->SetPower (IsaAcpi
, IsaDevice
, TRUE
);
384 // Enable this ISA device
386 IsaAcpi
->EnableDevice (IsaAcpi
, IsaDevice
, TRUE
);
395 IsaBusControllerDriverStop (
396 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
397 IN EFI_HANDLE Controller
,
398 IN UINTN NumberOfChildren
,
399 IN EFI_HANDLE
* ChildHandleBuffer OPTIONAL
405 This function tells the ISA Bus Driver to stop managing a PCI to ISA
410 This - The EFI_DRIVER_BINDING_PROTOCOL instance.
411 Controller - A handle to the device being stopped.
412 NumberOfChindren - The number of child device handles in ChildHandleBuffer.
413 ChildHandleBuffer - An array of child handles to be freed.
418 EFI_SUCCESS - The device was stopped.
419 EFI_DEVICE_ERROR - The device could not be stopped due to a device error.
420 EFI_NOT_STARTED - The device has not been started.
421 EFI_INVALID_PARAMETER - One of the parameters has an invalid value.
422 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
429 BOOLEAN AllChildrenStopped
;
430 ISA_IO_DEVICE
*IsaIoDevice
;
431 EFI_ISA_IO_PROTOCOL
*IsaIo
;
433 if (NumberOfChildren
== 0) {
435 // Close the bus driver
437 Status
= gBS
->CloseProtocol (
439 &gEfiPciIoProtocolGuid
,
440 This
->DriverBindingHandle
,
443 if (EFI_ERROR (Status
)) {
447 Status
= gBS
->CloseProtocol (
449 &gEfiDevicePathProtocolGuid
,
450 This
->DriverBindingHandle
,
453 if (EFI_ERROR (Status
)) {
457 Status
= gBS
->CloseProtocol (
459 &gEfiIsaAcpiProtocolGuid
,
460 This
->DriverBindingHandle
,
463 if (EFI_ERROR (Status
)) {
470 // Complete all outstanding transactions to Controller.
471 // Don't allow any new transaction to Controller to be started.
474 // Stop all the children
475 // Find all the ISA devices that were discovered on this PCI to ISA Bridge
476 // with the Start() function.
478 AllChildrenStopped
= TRUE
;
480 for (Index
= 0; Index
< NumberOfChildren
; Index
++) {
482 Status
= gBS
->OpenProtocol (
483 ChildHandleBuffer
[Index
],
484 &gEfiIsaIoProtocolGuid
,
486 This
->DriverBindingHandle
,
488 EFI_OPEN_PROTOCOL_GET_PROTOCOL
490 if (!EFI_ERROR (Status
)) {
492 IsaIoDevice
= ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo
);
494 Status
= gBS
->UninstallMultipleProtocolInterfaces (
495 ChildHandleBuffer
[Index
],
496 &gEfiDevicePathProtocolGuid
,
497 IsaIoDevice
->DevicePath
,
498 &gEfiIsaIoProtocolGuid
,
503 if (!EFI_ERROR (Status
)) {
505 // Close the child handle
507 Status
= gBS
->CloseProtocol (
509 &gEfiPciIoProtocolGuid
,
510 This
->DriverBindingHandle
,
511 ChildHandleBuffer
[Index
]
514 gBS
->FreePool (IsaIoDevice
->DevicePath
);
515 gBS
->FreePool (IsaIoDevice
);
519 if (EFI_ERROR (Status
)) {
520 AllChildrenStopped
= FALSE
;
524 if (!AllChildrenStopped
) {
525 return EFI_DEVICE_ERROR
;
535 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
536 IN EFI_HANDLE Controller
,
537 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
538 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
539 IN EFI_ISA_ACPI_RESOURCE_LIST
*IsaDeviceResourceList
,
540 OUT EFI_DEVICE_PATH_PROTOCOL
**ChildDevicePath
546 Create ISA device found by IsaPnpProtocol
550 This - The EFI_DRIVER_BINDING_PROTOCOL instance.
551 Controller - The handle of ISA bus controller(PCI to ISA bridge)
552 PciIo - The Pointer to the PCI protocol
553 ParentDevicePath - Device path of the ISA bus controller
554 IsaDeviceResourceList - The resource list of the ISA device
555 ChildDevicePath - The pointer to the child device.
559 EFI_SUCCESS - Create the child device.
560 EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of
562 EFI_DEVICE_ERROR - Can not create child device.
567 ISA_IO_DEVICE
*IsaIoDevice
;
571 // Initialize the PCI_IO_DEVICE structure
573 IsaIoDevice
= AllocateZeroPool (sizeof (ISA_IO_DEVICE
));
574 if (IsaIoDevice
== NULL
) {
575 return EFI_OUT_OF_RESOURCES
;
578 IsaIoDevice
->Signature
= ISA_IO_DEVICE_SIGNATURE
;
579 IsaIoDevice
->Handle
= NULL
;
580 IsaIoDevice
->PciIo
= PciIo
;
583 // Initialize the ISA I/O instance structure
585 Status
= InitializeIsaIoInstance (IsaIoDevice
, IsaDeviceResourceList
);
586 if (EFI_ERROR (Status
)) {
587 gBS
->FreePool (IsaIoDevice
);
591 // Build the child device path
593 Node
.DevPath
.Type
= ACPI_DEVICE_PATH
;
594 Node
.DevPath
.SubType
= ACPI_DP
;
595 SetDevicePathNodeLength (&Node
.DevPath
, sizeof (ACPI_HID_DEVICE_PATH
));
596 Node
.Acpi
.HID
= IsaDeviceResourceList
->Device
.HID
;
597 Node
.Acpi
.UID
= IsaDeviceResourceList
->Device
.UID
;
599 IsaIoDevice
->DevicePath
= AppendDevicePathNode (
604 if (IsaIoDevice
->DevicePath
== NULL
) {
605 Status
= EFI_DEVICE_ERROR
;
609 *ChildDevicePath
= IsaIoDevice
->DevicePath
;
612 // Create a child handle and attach the DevicePath,
613 // PCI I/O, and Controller State
615 Status
= gBS
->InstallMultipleProtocolInterfaces (
616 &IsaIoDevice
->Handle
,
617 &gEfiDevicePathProtocolGuid
,
618 IsaIoDevice
->DevicePath
,
619 &gEfiIsaIoProtocolGuid
,
623 if (EFI_ERROR (Status
)) {
627 Status
= gBS
->OpenProtocol (
629 &gEfiPciIoProtocolGuid
,
631 This
->DriverBindingHandle
,
633 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
635 if (EFI_ERROR (Status
)) {
636 gBS
->UninstallMultipleProtocolInterfaces (
638 &gEfiDevicePathProtocolGuid
,
639 IsaIoDevice
->DevicePath
,
640 &gEfiIsaIoProtocolGuid
,
648 if (EFI_ERROR (Status
)) {
649 if (IsaIoDevice
->DevicePath
!= NULL
) {
650 gBS
->FreePool (IsaIoDevice
->DevicePath
);
653 gBS
->FreePool (IsaIoDevice
);