2009-02-24 00:17:06 +01:00
|
|
|
/** @file
|
|
|
|
EFI PCAT ISA ACPI Driver for a Generic PC Platform
|
2008-04-17 07:48:13 +02:00
|
|
|
|
2010-04-24 14:07:51 +02:00
|
|
|
Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
2010-04-12 06:38:44 +02:00
|
|
|
This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
2008-04-17 07:48:13 +02:00
|
|
|
|
2010-04-12 06:38:44 +02:00
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2008-04-17 07:48:13 +02:00
|
|
|
|
2009-02-24 00:17:06 +01:00
|
|
|
**/
|
2008-04-17 07:48:13 +02:00
|
|
|
|
|
|
|
#include "PcatIsaAcpi.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// PcatIsaAcpi Driver Binding Protocol
|
|
|
|
//
|
|
|
|
EFI_DRIVER_BINDING_PROTOCOL gPcatIsaAcpiDriverBinding = {
|
|
|
|
PcatIsaAcpiDriverBindingSupported,
|
|
|
|
PcatIsaAcpiDriverBindingStart,
|
|
|
|
PcatIsaAcpiDriverBindingStop,
|
|
|
|
0xa,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2010-04-12 06:38:44 +02:00
|
|
|
/**
|
|
|
|
the entry point of the PcatIsaAcpi driver.
|
|
|
|
|
|
|
|
@param ImageHandle Handle for driver image
|
|
|
|
@param SystemTable Point to EFI_SYSTEM_TABLE
|
|
|
|
|
|
|
|
@return Sucess or not for installing driver binding protocol
|
|
|
|
**/
|
2008-04-17 07:48:13 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PcatIsaAcpiDriverEntryPoint (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return EfiLibInstallDriverBindingComponentName2 (
|
|
|
|
ImageHandle,
|
|
|
|
SystemTable,
|
|
|
|
&gPcatIsaAcpiDriverBinding,
|
|
|
|
ImageHandle,
|
|
|
|
&gPcatIsaAcpiComponentName,
|
|
|
|
&gPcatIsaAcpiComponentName2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-04-12 06:38:44 +02:00
|
|
|
/**
|
|
|
|
ControllerDriver Protocol Method
|
|
|
|
|
|
|
|
@param This Driver Binding protocol instance pointer.
|
|
|
|
@param Controller Handle of device to test.
|
|
|
|
@param RemainingDevicePath Optional parameter use to pick a specific child
|
|
|
|
device to start.
|
|
|
|
@retval EFI_SUCCESS This driver supports this device.
|
|
|
|
@retval other This driver does not support this device.
|
|
|
|
|
|
|
|
**/
|
2008-04-17 07:48:13 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PcatIsaAcpiDriverBindingSupported (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
|
|
|
PCI_TYPE00 Pci;
|
2010-07-03 01:20:11 +02:00
|
|
|
UINTN SegmentNumber;
|
|
|
|
UINTN BusNumber;
|
|
|
|
UINTN DeviceNumber;
|
|
|
|
UINTN FunctionNumber;
|
2008-04-17 07:48:13 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get PciIo protocol instance
|
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
2008-11-27 05:37:39 +01:00
|
|
|
(VOID**)&PciIo,
|
2008-04-17 07:48:13 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = PciIo->Pci.Read (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoWidthUint32,
|
|
|
|
0,
|
|
|
|
sizeof(Pci) / sizeof(UINT32),
|
|
|
|
&Pci);
|
2009-02-24 00:17:06 +01:00
|
|
|
|
2008-04-17 07:48:13 +02:00
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
if ((Pci.Hdr.Command & 0x03) == 0x03) {
|
|
|
|
if (Pci.Hdr.ClassCode[2] == PCI_CLASS_BRIDGE) {
|
|
|
|
//
|
|
|
|
// See if this is a standard PCI to ISA Bridge from the Base Code and Class Code
|
|
|
|
//
|
2008-10-27 02:52:32 +01:00
|
|
|
if (Pci.Hdr.ClassCode[1] == PCI_CLASS_BRIDGE_ISA) {
|
2008-04-17 07:48:13 +02:00
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// See if this is an Intel PCI to ISA bridge in Positive Decode Mode
|
|
|
|
//
|
2010-07-03 01:20:11 +02:00
|
|
|
if (Pci.Hdr.ClassCode[1] == PCI_CLASS_BRIDGE_ISA_PDECODE &&
|
|
|
|
Pci.Hdr.VendorId == 0x8086 ) {
|
|
|
|
//
|
|
|
|
// See if this is on Function #0 to avoid false positives on
|
|
|
|
// PCI_CLASS_BRIDGE_OTHER that has the same value as
|
|
|
|
// PCI_CLASS_BRIDGE_ISA_PDECODE
|
|
|
|
//
|
|
|
|
Status = PciIo->GetLocation (
|
|
|
|
PciIo,
|
|
|
|
&SegmentNumber,
|
|
|
|
&BusNumber,
|
|
|
|
&DeviceNumber,
|
|
|
|
&FunctionNumber
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status) && FunctionNumber == 0) {
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
} else {
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
}
|
2008-04-17 07:48:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2010-04-12 06:38:44 +02:00
|
|
|
/**
|
|
|
|
Install EFI_ISA_ACPI_PROTOCOL.
|
|
|
|
|
|
|
|
@param This Driver Binding protocol instance pointer.
|
|
|
|
@param ControllerHandle Handle of device to bind driver to.
|
|
|
|
@param RemainingDevicePath Optional parameter use to pick a specific child
|
|
|
|
device to start.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS This driver is added to ControllerHandle
|
|
|
|
@retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
|
|
|
|
@retval other This driver does not support this device
|
|
|
|
**/
|
2008-04-17 07:48:13 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PcatIsaAcpiDriverBindingStart (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_PCI_IO_PROTOCOL *PciIo;
|
|
|
|
PCAT_ISA_ACPI_DEV *PcatIsaAcpiDev;
|
2010-12-28 11:10:10 +01:00
|
|
|
UINT64 Supports;
|
|
|
|
BOOLEAN Enabled;
|
|
|
|
|
|
|
|
Enabled = FALSE;
|
|
|
|
Supports = 0;
|
2008-04-17 07:48:13 +02:00
|
|
|
PcatIsaAcpiDev = NULL;
|
|
|
|
//
|
|
|
|
// Open the PCI I/O Protocol Interface
|
|
|
|
//
|
|
|
|
PciIo = NULL;
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
2008-11-27 05:37:39 +01:00
|
|
|
(VOID**)&PciIo,
|
2008-04-17 07:48:13 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
2010-12-28 11:10:10 +01:00
|
|
|
//
|
|
|
|
// Get supported PCI attributes
|
|
|
|
//
|
|
|
|
Status = PciIo->Attributes (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoAttributeOperationSupported,
|
|
|
|
0,
|
|
|
|
&Supports
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
Supports &= (EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_IO_16);
|
|
|
|
if (Supports == 0 || Supports == (EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_IO_16)) {
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
Enabled = TRUE;
|
2008-04-17 07:48:13 +02:00
|
|
|
Status = PciIo->Attributes (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoAttributeOperationEnable,
|
2010-12-28 11:10:10 +01:00
|
|
|
EFI_PCI_DEVICE_ENABLE | Supports | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,
|
2008-04-17 07:48:13 +02:00
|
|
|
NULL
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate memory for the PCAT ISA ACPI Device structure
|
|
|
|
//
|
|
|
|
PcatIsaAcpiDev = NULL;
|
|
|
|
Status = gBS->AllocatePool (
|
|
|
|
EfiBootServicesData,
|
|
|
|
sizeof(PCAT_ISA_ACPI_DEV),
|
2008-11-27 05:37:39 +01:00
|
|
|
(VOID**)&PcatIsaAcpiDev
|
2008-04-17 07:48:13 +02:00
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initialize the PCAT ISA ACPI Device structure
|
|
|
|
//
|
|
|
|
PcatIsaAcpiDev->Signature = PCAT_ISA_ACPI_DEV_SIGNATURE;
|
|
|
|
PcatIsaAcpiDev->Handle = Controller;
|
|
|
|
PcatIsaAcpiDev->PciIo = PciIo;
|
|
|
|
|
|
|
|
//
|
|
|
|
// IsaAcpi interface
|
|
|
|
//
|
|
|
|
(PcatIsaAcpiDev->IsaAcpi).DeviceEnumerate = IsaDeviceEnumerate;
|
|
|
|
(PcatIsaAcpiDev->IsaAcpi).SetPower = IsaDeviceSetPower;
|
|
|
|
(PcatIsaAcpiDev->IsaAcpi).GetCurResource = IsaGetCurrentResource;
|
|
|
|
(PcatIsaAcpiDev->IsaAcpi).GetPosResource = IsaGetPossibleResource;
|
|
|
|
(PcatIsaAcpiDev->IsaAcpi).SetResource = IsaSetResource;
|
|
|
|
(PcatIsaAcpiDev->IsaAcpi).EnableDevice = IsaEnableDevice;
|
|
|
|
(PcatIsaAcpiDev->IsaAcpi).InitDevice = IsaInitDevice;
|
|
|
|
(PcatIsaAcpiDev->IsaAcpi).InterfaceInit = IsaInterfaceInit;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Install the ISA ACPI Protocol interface
|
|
|
|
//
|
|
|
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
|
|
|
&Controller,
|
|
|
|
&gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi,
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
Done:
|
|
|
|
if (EFI_ERROR (Status)) {
|
2010-12-28 11:10:10 +01:00
|
|
|
if (PciIo != NULL && Enabled) {
|
2008-04-17 07:48:13 +02:00
|
|
|
PciIo->Attributes (
|
|
|
|
PciIo,
|
|
|
|
EfiPciIoAttributeOperationDisable,
|
2010-12-28 11:10:10 +01:00
|
|
|
EFI_PCI_DEVICE_ENABLE | Supports | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,
|
2008-04-17 07:48:13 +02:00
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
if (PcatIsaAcpiDev != NULL) {
|
|
|
|
gBS->FreePool (PcatIsaAcpiDev);
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-04-12 06:38:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Stop this driver on ControllerHandle. Support stopping any child handles
|
|
|
|
created by this driver.
|
|
|
|
|
|
|
|
@param This Protocol instance pointer.
|
|
|
|
@param ControllerHandle Handle of device to stop driver on
|
|
|
|
@param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
|
|
|
|
children is zero stop the entire bus driver.
|
|
|
|
@param ChildHandleBuffer List of Child Handles to Stop.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS This driver is removed ControllerHandle
|
|
|
|
@retval other This driver was not removed from this device
|
|
|
|
|
|
|
|
**/
|
2008-04-17 07:48:13 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
PcatIsaAcpiDriverBindingStop (
|
|
|
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE Controller,
|
|
|
|
IN UINTN NumberOfChildren,
|
|
|
|
IN EFI_HANDLE *ChildHandleBuffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_ISA_ACPI_PROTOCOL *IsaAcpi;
|
|
|
|
PCAT_ISA_ACPI_DEV *PcatIsaAcpiDev;
|
2010-12-28 11:10:10 +01:00
|
|
|
UINT64 Supports;
|
2008-04-17 07:48:13 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Get the ISA ACPI Protocol Interface
|
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiIsaAcpiProtocolGuid,
|
2008-11-27 05:37:39 +01:00
|
|
|
(VOID**)&IsaAcpi,
|
2008-04-17 07:48:13 +02:00
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the PCAT ISA ACPI Device structure from the ISA ACPI Protocol
|
|
|
|
//
|
|
|
|
PcatIsaAcpiDev = PCAT_ISA_ACPI_DEV_FROM_THIS (IsaAcpi);
|
|
|
|
|
2010-12-28 11:10:10 +01:00
|
|
|
//
|
|
|
|
// Get supported PCI attributes
|
|
|
|
//
|
|
|
|
Status = PcatIsaAcpiDev->PciIo->Attributes (
|
|
|
|
PcatIsaAcpiDev->PciIo,
|
|
|
|
EfiPciIoAttributeOperationSupported,
|
|
|
|
0,
|
|
|
|
&Supports
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Supports &= (EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_IO_16);
|
|
|
|
|
2008-04-17 07:48:13 +02:00
|
|
|
PcatIsaAcpiDev->PciIo->Attributes (
|
|
|
|
PcatIsaAcpiDev->PciIo,
|
|
|
|
EfiPciIoAttributeOperationDisable,
|
2010-12-28 11:10:10 +01:00
|
|
|
EFI_PCI_DEVICE_ENABLE | Supports | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,
|
2008-04-17 07:48:13 +02:00
|
|
|
NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Uninstall protocol interface: EFI_ISA_ACPI_PROTOCOL
|
|
|
|
//
|
|
|
|
Status = gBS->UninstallProtocolInterface (
|
|
|
|
Controller,
|
|
|
|
&gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
Controller,
|
|
|
|
&gEfiPciIoProtocolGuid,
|
|
|
|
This->DriverBindingHandle,
|
|
|
|
Controller
|
|
|
|
);
|
|
|
|
|
|
|
|
gBS->FreePool (PcatIsaAcpiDev);
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|