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