]> git.proxmox.com Git - mirror_edk2.git/blob - PcAtChipsetPkg/IsaAcpiDxe/PcatIsaAcpi.c
add correct [Depex] section.
[mirror_edk2.git] / PcAtChipsetPkg / IsaAcpiDxe / PcatIsaAcpi.c
1 /** @file
2 EFI PCAT ISA ACPI Driver for a Generic PC Platform
3
4 Copyright (c) 2006, 2009, Intel Corporation
5 All rights reserved. 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
9
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.
12
13 **/
14
15 #include "PcatIsaAcpi.h"
16
17 //
18 // PcatIsaAcpi Driver Binding Protocol
19 //
20 EFI_DRIVER_BINDING_PROTOCOL gPcatIsaAcpiDriverBinding = {
21 PcatIsaAcpiDriverBindingSupported,
22 PcatIsaAcpiDriverBindingStart,
23 PcatIsaAcpiDriverBindingStop,
24 0xa,
25 NULL,
26 NULL
27 };
28
29 EFI_STATUS
30 EFIAPI
31 PcatIsaAcpiDriverEntryPoint (
32 IN EFI_HANDLE ImageHandle,
33 IN EFI_SYSTEM_TABLE *SystemTable
34 )
35 /*++
36
37 Routine Description:
38 the entry point of the PcatIsaAcpi driver
39
40 Arguments:
41
42 Returns:
43
44 --*/
45 {
46 return EfiLibInstallDriverBindingComponentName2 (
47 ImageHandle,
48 SystemTable,
49 &gPcatIsaAcpiDriverBinding,
50 ImageHandle,
51 &gPcatIsaAcpiComponentName,
52 &gPcatIsaAcpiComponentName2
53 );
54 }
55
56 EFI_STATUS
57 EFIAPI
58 PcatIsaAcpiDriverBindingSupported (
59 IN EFI_DRIVER_BINDING_PROTOCOL *This,
60 IN EFI_HANDLE Controller,
61 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
62 )
63 /*++
64
65 Routine Description:
66
67 ControllerDriver Protocol Method
68
69 Arguments:
70
71 Returns:
72
73 --*/
74 {
75 EFI_STATUS Status;
76 EFI_PCI_IO_PROTOCOL *PciIo;
77 PCI_TYPE00 Pci;
78
79 //
80 // Get PciIo protocol instance
81 //
82 Status = gBS->OpenProtocol (
83 Controller,
84 &gEfiPciIoProtocolGuid,
85 (VOID**)&PciIo,
86 This->DriverBindingHandle,
87 Controller,
88 EFI_OPEN_PROTOCOL_BY_DRIVER
89 );
90 if (EFI_ERROR(Status)) {
91 return Status;
92 }
93
94 Status = PciIo->Pci.Read (
95 PciIo,
96 EfiPciIoWidthUint32,
97 0,
98 sizeof(Pci) / sizeof(UINT32),
99 &Pci);
100
101 if (!EFI_ERROR (Status)) {
102 Status = EFI_UNSUPPORTED;
103 if ((Pci.Hdr.Command & 0x03) == 0x03) {
104 if (Pci.Hdr.ClassCode[2] == PCI_CLASS_BRIDGE) {
105 //
106 // See if this is a standard PCI to ISA Bridge from the Base Code and Class Code
107 //
108 if (Pci.Hdr.ClassCode[1] == PCI_CLASS_BRIDGE_ISA) {
109 Status = EFI_SUCCESS;
110 }
111
112 //
113 // See if this is an Intel PCI to ISA bridge in Positive Decode Mode
114 //
115 if (Pci.Hdr.ClassCode[1] == PCI_CLASS_BRIDGE_ISA_PDECODE &&
116 Pci.Hdr.VendorId == 0x8086 &&
117 (Pci.Hdr.DeviceId & 0xF000) == 0x7000) {
118 Status = EFI_SUCCESS;
119 }
120 }
121 }
122 }
123
124 gBS->CloseProtocol (
125 Controller,
126 &gEfiPciIoProtocolGuid,
127 This->DriverBindingHandle,
128 Controller
129 );
130
131 return Status;
132 }
133
134 EFI_STATUS
135 EFIAPI
136 PcatIsaAcpiDriverBindingStart (
137 IN EFI_DRIVER_BINDING_PROTOCOL *This,
138 IN EFI_HANDLE Controller,
139 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
140 )
141 /*++
142
143 Routine Description:
144 Install EFI_ISA_ACPI_PROTOCOL
145
146 Arguments:
147
148 Returns:
149
150 --*/
151 {
152 EFI_STATUS Status;
153 EFI_PCI_IO_PROTOCOL *PciIo;
154 PCAT_ISA_ACPI_DEV *PcatIsaAcpiDev;
155
156 PcatIsaAcpiDev = NULL;
157 //
158 // Open the PCI I/O Protocol Interface
159 //
160 PciIo = NULL;
161 Status = gBS->OpenProtocol (
162 Controller,
163 &gEfiPciIoProtocolGuid,
164 (VOID**)&PciIo,
165 This->DriverBindingHandle,
166 Controller,
167 EFI_OPEN_PROTOCOL_BY_DRIVER
168 );
169 if (EFI_ERROR (Status)) {
170 goto Done;
171 }
172
173 Status = PciIo->Attributes (
174 PciIo,
175 EfiPciIoAttributeOperationEnable,
176 EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,
177 NULL
178 );
179 if (EFI_ERROR (Status)) {
180 goto Done;
181 }
182
183 //
184 // Allocate memory for the PCAT ISA ACPI Device structure
185 //
186 PcatIsaAcpiDev = NULL;
187 Status = gBS->AllocatePool (
188 EfiBootServicesData,
189 sizeof(PCAT_ISA_ACPI_DEV),
190 (VOID**)&PcatIsaAcpiDev
191 );
192 if (EFI_ERROR (Status)) {
193 goto Done;
194 }
195
196 //
197 // Initialize the PCAT ISA ACPI Device structure
198 //
199 PcatIsaAcpiDev->Signature = PCAT_ISA_ACPI_DEV_SIGNATURE;
200 PcatIsaAcpiDev->Handle = Controller;
201 PcatIsaAcpiDev->PciIo = PciIo;
202
203 //
204 // IsaAcpi interface
205 //
206 (PcatIsaAcpiDev->IsaAcpi).DeviceEnumerate = IsaDeviceEnumerate;
207 (PcatIsaAcpiDev->IsaAcpi).SetPower = IsaDeviceSetPower;
208 (PcatIsaAcpiDev->IsaAcpi).GetCurResource = IsaGetCurrentResource;
209 (PcatIsaAcpiDev->IsaAcpi).GetPosResource = IsaGetPossibleResource;
210 (PcatIsaAcpiDev->IsaAcpi).SetResource = IsaSetResource;
211 (PcatIsaAcpiDev->IsaAcpi).EnableDevice = IsaEnableDevice;
212 (PcatIsaAcpiDev->IsaAcpi).InitDevice = IsaInitDevice;
213 (PcatIsaAcpiDev->IsaAcpi).InterfaceInit = IsaInterfaceInit;
214
215 //
216 // Install the ISA ACPI Protocol interface
217 //
218 Status = gBS->InstallMultipleProtocolInterfaces (
219 &Controller,
220 &gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi,
221 NULL
222 );
223
224 Done:
225 if (EFI_ERROR (Status)) {
226 if (PciIo) {
227 PciIo->Attributes (
228 PciIo,
229 EfiPciIoAttributeOperationDisable,
230 EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,
231 NULL
232 );
233 }
234 gBS->CloseProtocol (
235 Controller,
236 &gEfiPciIoProtocolGuid,
237 This->DriverBindingHandle,
238 Controller
239 );
240 if (PcatIsaAcpiDev != NULL) {
241 gBS->FreePool (PcatIsaAcpiDev);
242 }
243 return Status;
244 }
245
246 return EFI_SUCCESS;
247 }
248
249 EFI_STATUS
250 EFIAPI
251 PcatIsaAcpiDriverBindingStop (
252 IN EFI_DRIVER_BINDING_PROTOCOL *This,
253 IN EFI_HANDLE Controller,
254 IN UINTN NumberOfChildren,
255 IN EFI_HANDLE *ChildHandleBuffer
256 )
257 /*++
258
259 Routine Description:
260
261 Arguments:
262
263 Returns:
264
265 --*/
266 {
267 EFI_STATUS Status;
268 EFI_ISA_ACPI_PROTOCOL *IsaAcpi;
269 PCAT_ISA_ACPI_DEV *PcatIsaAcpiDev;
270
271 //
272 // Get the ISA ACPI Protocol Interface
273 //
274 Status = gBS->OpenProtocol (
275 Controller,
276 &gEfiIsaAcpiProtocolGuid,
277 (VOID**)&IsaAcpi,
278 This->DriverBindingHandle,
279 Controller,
280 EFI_OPEN_PROTOCOL_GET_PROTOCOL
281 );
282 if (EFI_ERROR (Status)) {
283 return Status;
284 }
285
286 //
287 // Get the PCAT ISA ACPI Device structure from the ISA ACPI Protocol
288 //
289 PcatIsaAcpiDev = PCAT_ISA_ACPI_DEV_FROM_THIS (IsaAcpi);
290
291 PcatIsaAcpiDev->PciIo->Attributes (
292 PcatIsaAcpiDev->PciIo,
293 EfiPciIoAttributeOperationDisable,
294 EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,
295 NULL
296 );
297
298 //
299 // Uninstall protocol interface: EFI_ISA_ACPI_PROTOCOL
300 //
301 Status = gBS->UninstallProtocolInterface (
302 Controller,
303 &gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi
304 );
305 if (EFI_ERROR (Status)) {
306 return Status;
307 }
308
309 gBS->CloseProtocol (
310 Controller,
311 &gEfiPciIoProtocolGuid,
312 This->DriverBindingHandle,
313 Controller
314 );
315
316 gBS->FreePool (PcatIsaAcpiDev);
317
318 return EFI_SUCCESS;
319 }