2 EFI PCAT ISA ACPI Driver for a Generic PC Platform
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "PcatIsaAcpi.h"
18 // PcatIsaAcpi Driver Binding Protocol
20 EFI_DRIVER_BINDING_PROTOCOL gPcatIsaAcpiDriverBinding
= {
21 PcatIsaAcpiDriverBindingSupported
,
22 PcatIsaAcpiDriverBindingStart
,
23 PcatIsaAcpiDriverBindingStop
,
30 the entry point of the PcatIsaAcpi driver.
32 @param ImageHandle Handle for driver image
33 @param SystemTable Point to EFI_SYSTEM_TABLE
35 @return Sucess or not for installing driver binding protocol
39 PcatIsaAcpiDriverEntryPoint (
40 IN EFI_HANDLE ImageHandle
,
41 IN EFI_SYSTEM_TABLE
*SystemTable
44 return EfiLibInstallDriverBindingComponentName2 (
47 &gPcatIsaAcpiDriverBinding
,
49 &gPcatIsaAcpiComponentName
,
50 &gPcatIsaAcpiComponentName2
55 ControllerDriver Protocol Method
57 @param This Driver Binding protocol instance pointer.
58 @param Controller Handle of device to test.
59 @param RemainingDevicePath Optional parameter use to pick a specific child
61 @retval EFI_SUCCESS This driver supports this device.
62 @retval other This driver does not support this device.
67 PcatIsaAcpiDriverBindingSupported (
68 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
69 IN EFI_HANDLE Controller
,
70 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
74 EFI_PCI_IO_PROTOCOL
*PciIo
;
82 // Get PciIo protocol instance
84 Status
= gBS
->OpenProtocol (
86 &gEfiPciIoProtocolGuid
,
88 This
->DriverBindingHandle
,
90 EFI_OPEN_PROTOCOL_BY_DRIVER
92 if (EFI_ERROR(Status
)) {
96 Status
= PciIo
->Pci
.Read (
100 sizeof(Pci
) / sizeof(UINT32
),
103 if (!EFI_ERROR (Status
)) {
104 Status
= EFI_UNSUPPORTED
;
105 if ((Pci
.Hdr
.Command
& 0x03) == 0x03) {
106 if (Pci
.Hdr
.ClassCode
[2] == PCI_CLASS_BRIDGE
) {
108 // See if this is a standard PCI to ISA Bridge from the Base Code and Class Code
110 if (Pci
.Hdr
.ClassCode
[1] == PCI_CLASS_BRIDGE_ISA
) {
111 Status
= EFI_SUCCESS
;
115 // See if this is an Intel PCI to ISA bridge in Positive Decode Mode
117 if (Pci
.Hdr
.ClassCode
[1] == PCI_CLASS_BRIDGE_ISA_PDECODE
&&
118 Pci
.Hdr
.VendorId
== 0x8086 ) {
120 // See if this is on Function #0 to avoid false positives on
121 // PCI_CLASS_BRIDGE_OTHER that has the same value as
122 // PCI_CLASS_BRIDGE_ISA_PDECODE
124 Status
= PciIo
->GetLocation (
131 if (!EFI_ERROR (Status
) && FunctionNumber
== 0) {
132 Status
= EFI_SUCCESS
;
134 Status
= EFI_UNSUPPORTED
;
143 &gEfiPciIoProtocolGuid
,
144 This
->DriverBindingHandle
,
152 Install EFI_ISA_ACPI_PROTOCOL.
154 @param This Driver Binding protocol instance pointer.
155 @param ControllerHandle Handle of device to bind driver to.
156 @param RemainingDevicePath Optional parameter use to pick a specific child
159 @retval EFI_SUCCESS This driver is added to ControllerHandle
160 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
161 @retval other This driver does not support this device
165 PcatIsaAcpiDriverBindingStart (
166 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
167 IN EFI_HANDLE Controller
,
168 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
172 EFI_PCI_IO_PROTOCOL
*PciIo
;
173 PCAT_ISA_ACPI_DEV
*PcatIsaAcpiDev
;
179 PcatIsaAcpiDev
= NULL
;
181 // Open the PCI I/O Protocol Interface
184 Status
= gBS
->OpenProtocol (
186 &gEfiPciIoProtocolGuid
,
188 This
->DriverBindingHandle
,
190 EFI_OPEN_PROTOCOL_BY_DRIVER
192 if (EFI_ERROR (Status
)) {
197 // Get supported PCI attributes
199 Status
= PciIo
->Attributes (
201 EfiPciIoAttributeOperationSupported
,
205 if (EFI_ERROR (Status
)) {
209 Supports
&= (EFI_PCI_IO_ATTRIBUTE_ISA_IO
| EFI_PCI_IO_ATTRIBUTE_ISA_IO_16
);
210 if (Supports
== 0 || Supports
== (EFI_PCI_IO_ATTRIBUTE_ISA_IO
| EFI_PCI_IO_ATTRIBUTE_ISA_IO_16
)) {
211 Status
= EFI_UNSUPPORTED
;
216 Status
= PciIo
->Attributes (
218 EfiPciIoAttributeOperationEnable
,
219 EFI_PCI_DEVICE_ENABLE
| Supports
| EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO
,
222 if (EFI_ERROR (Status
)) {
227 // Allocate memory for the PCAT ISA ACPI Device structure
229 PcatIsaAcpiDev
= NULL
;
230 Status
= gBS
->AllocatePool (
232 sizeof(PCAT_ISA_ACPI_DEV
),
233 (VOID
**)&PcatIsaAcpiDev
235 if (EFI_ERROR (Status
)) {
240 // Initialize the PCAT ISA ACPI Device structure
242 PcatIsaAcpiDev
->Signature
= PCAT_ISA_ACPI_DEV_SIGNATURE
;
243 PcatIsaAcpiDev
->Handle
= Controller
;
244 PcatIsaAcpiDev
->PciIo
= PciIo
;
249 (PcatIsaAcpiDev
->IsaAcpi
).DeviceEnumerate
= IsaDeviceEnumerate
;
250 (PcatIsaAcpiDev
->IsaAcpi
).SetPower
= IsaDeviceSetPower
;
251 (PcatIsaAcpiDev
->IsaAcpi
).GetCurResource
= IsaGetCurrentResource
;
252 (PcatIsaAcpiDev
->IsaAcpi
).GetPosResource
= IsaGetPossibleResource
;
253 (PcatIsaAcpiDev
->IsaAcpi
).SetResource
= IsaSetResource
;
254 (PcatIsaAcpiDev
->IsaAcpi
).EnableDevice
= IsaEnableDevice
;
255 (PcatIsaAcpiDev
->IsaAcpi
).InitDevice
= IsaInitDevice
;
256 (PcatIsaAcpiDev
->IsaAcpi
).InterfaceInit
= IsaInterfaceInit
;
259 // Install the ISA ACPI Protocol interface
261 Status
= gBS
->InstallMultipleProtocolInterfaces (
263 &gEfiIsaAcpiProtocolGuid
, &PcatIsaAcpiDev
->IsaAcpi
,
268 if (EFI_ERROR (Status
)) {
269 if (PciIo
!= NULL
&& Enabled
) {
272 EfiPciIoAttributeOperationDisable
,
273 EFI_PCI_DEVICE_ENABLE
| Supports
| EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO
,
279 &gEfiPciIoProtocolGuid
,
280 This
->DriverBindingHandle
,
283 if (PcatIsaAcpiDev
!= NULL
) {
284 gBS
->FreePool (PcatIsaAcpiDev
);
294 Stop this driver on ControllerHandle. Support stopping any child handles
295 created by this driver.
297 @param This Protocol instance pointer.
298 @param ControllerHandle Handle of device to stop driver on
299 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
300 children is zero stop the entire bus driver.
301 @param ChildHandleBuffer List of Child Handles to Stop.
303 @retval EFI_SUCCESS This driver is removed ControllerHandle
304 @retval other This driver was not removed from this device
309 PcatIsaAcpiDriverBindingStop (
310 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
311 IN EFI_HANDLE Controller
,
312 IN UINTN NumberOfChildren
,
313 IN EFI_HANDLE
*ChildHandleBuffer
317 EFI_ISA_ACPI_PROTOCOL
*IsaAcpi
;
318 PCAT_ISA_ACPI_DEV
*PcatIsaAcpiDev
;
322 // Get the ISA ACPI Protocol Interface
324 Status
= gBS
->OpenProtocol (
326 &gEfiIsaAcpiProtocolGuid
,
328 This
->DriverBindingHandle
,
330 EFI_OPEN_PROTOCOL_GET_PROTOCOL
332 if (EFI_ERROR (Status
)) {
337 // Get the PCAT ISA ACPI Device structure from the ISA ACPI Protocol
339 PcatIsaAcpiDev
= PCAT_ISA_ACPI_DEV_FROM_THIS (IsaAcpi
);
342 // Get supported PCI attributes
344 Status
= PcatIsaAcpiDev
->PciIo
->Attributes (
345 PcatIsaAcpiDev
->PciIo
,
346 EfiPciIoAttributeOperationSupported
,
350 if (EFI_ERROR (Status
)) {
354 Supports
&= (EFI_PCI_IO_ATTRIBUTE_ISA_IO
| EFI_PCI_IO_ATTRIBUTE_ISA_IO_16
);
356 PcatIsaAcpiDev
->PciIo
->Attributes (
357 PcatIsaAcpiDev
->PciIo
,
358 EfiPciIoAttributeOperationDisable
,
359 EFI_PCI_DEVICE_ENABLE
| Supports
| EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO
,
364 // Uninstall protocol interface: EFI_ISA_ACPI_PROTOCOL
366 Status
= gBS
->UninstallProtocolInterface (
368 &gEfiIsaAcpiProtocolGuid
, &PcatIsaAcpiDev
->IsaAcpi
370 if (EFI_ERROR (Status
)) {
376 &gEfiPciIoProtocolGuid
,
377 This
->DriverBindingHandle
,
381 gBS
->FreePool (PcatIsaAcpiDev
);