]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/IsaAcpiDxe/PcatIsaAcpi.c
Fixed typos per the PI Spec 1.2 Errata B.
[mirror_edk2.git] / PcAtChipsetPkg / IsaAcpiDxe / PcatIsaAcpi.c
CommitLineData
c860b463 1/** @file\r
2 EFI PCAT ISA ACPI Driver for a Generic PC Platform\r
c69dd9df 3\r
95d48e82 4Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
18c97f53 5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
c69dd9df 9\r
18c97f53 10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
c69dd9df 12\r
c860b463 13**/\r
c69dd9df 14\r
15#include "PcatIsaAcpi.h"\r
16\r
17//\r
18// PcatIsaAcpi Driver Binding Protocol\r
19//\r
20EFI_DRIVER_BINDING_PROTOCOL gPcatIsaAcpiDriverBinding = {\r
21 PcatIsaAcpiDriverBindingSupported,\r
22 PcatIsaAcpiDriverBindingStart,\r
23 PcatIsaAcpiDriverBindingStop,\r
24 0xa,\r
25 NULL,\r
26 NULL\r
27};\r
28\r
18c97f53 29/**\r
30 the entry point of the PcatIsaAcpi driver.\r
31\r
32 @param ImageHandle Handle for driver image\r
33 @param SystemTable Point to EFI_SYSTEM_TABLE\r
34\r
35 @return Sucess or not for installing driver binding protocol\r
36**/\r
c69dd9df 37EFI_STATUS\r
38EFIAPI\r
39PcatIsaAcpiDriverEntryPoint (\r
40 IN EFI_HANDLE ImageHandle,\r
41 IN EFI_SYSTEM_TABLE *SystemTable\r
42 )\r
c69dd9df 43{\r
44 return EfiLibInstallDriverBindingComponentName2 (\r
45 ImageHandle, \r
46 SystemTable, \r
47 &gPcatIsaAcpiDriverBinding,\r
48 ImageHandle,\r
49 &gPcatIsaAcpiComponentName,\r
50 &gPcatIsaAcpiComponentName2\r
51 );\r
52}\r
53\r
18c97f53 54/**\r
55 ControllerDriver Protocol Method\r
56\r
57 @param This Driver Binding protocol instance pointer. \r
58 @param Controller Handle of device to test.\r
59 @param RemainingDevicePath Optional parameter use to pick a specific child\r
60 device to start.\r
61 @retval EFI_SUCCESS This driver supports this device.\r
62 @retval other This driver does not support this device.\r
63\r
64**/\r
c69dd9df 65EFI_STATUS\r
66EFIAPI\r
67PcatIsaAcpiDriverBindingSupported (\r
68 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
69 IN EFI_HANDLE Controller,\r
70 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
71 )\r
c69dd9df 72{\r
73 EFI_STATUS Status;\r
74 EFI_PCI_IO_PROTOCOL *PciIo;\r
75 PCI_TYPE00 Pci;\r
755e4d11 76 UINTN SegmentNumber;\r
77 UINTN BusNumber;\r
78 UINTN DeviceNumber;\r
79 UINTN FunctionNumber;\r
c69dd9df 80\r
81 //\r
82 // Get PciIo protocol instance\r
83 // \r
84 Status = gBS->OpenProtocol (\r
85 Controller, \r
86 &gEfiPciIoProtocolGuid, \r
9c83c97a 87 (VOID**)&PciIo,\r
c69dd9df 88 This->DriverBindingHandle,\r
89 Controller,\r
90 EFI_OPEN_PROTOCOL_BY_DRIVER\r
91 );\r
92 if (EFI_ERROR(Status)) {\r
93 return Status;\r
94 }\r
95\r
96 Status = PciIo->Pci.Read (\r
97 PciIo,\r
98 EfiPciIoWidthUint32,\r
99 0,\r
100 sizeof(Pci) / sizeof(UINT32), \r
101 &Pci);\r
c860b463 102\r
c69dd9df 103 if (!EFI_ERROR (Status)) {\r
104 Status = EFI_UNSUPPORTED;\r
105 if ((Pci.Hdr.Command & 0x03) == 0x03) {\r
106 if (Pci.Hdr.ClassCode[2] == PCI_CLASS_BRIDGE) {\r
107 //\r
108 // See if this is a standard PCI to ISA Bridge from the Base Code and Class Code\r
109 //\r
bc14bdb3 110 if (Pci.Hdr.ClassCode[1] == PCI_CLASS_BRIDGE_ISA) {\r
c69dd9df 111 Status = EFI_SUCCESS;\r
112 } \r
113\r
114 //\r
115 // See if this is an Intel PCI to ISA bridge in Positive Decode Mode\r
116 //\r
755e4d11 117 if (Pci.Hdr.ClassCode[1] == PCI_CLASS_BRIDGE_ISA_PDECODE && \r
118 Pci.Hdr.VendorId == 0x8086 ) {\r
119 //\r
120 // See if this is on Function #0 to avoid false positives on \r
121 // PCI_CLASS_BRIDGE_OTHER that has the same value as \r
122 // PCI_CLASS_BRIDGE_ISA_PDECODE\r
123 //\r
124 Status = PciIo->GetLocation (\r
125 PciIo, \r
126 &SegmentNumber, \r
127 &BusNumber, \r
128 &DeviceNumber, \r
129 &FunctionNumber\r
130 );\r
131 if (!EFI_ERROR (Status) && FunctionNumber == 0) {\r
132 Status = EFI_SUCCESS;\r
133 } else {\r
134 Status = EFI_UNSUPPORTED;\r
135 }\r
c69dd9df 136 }\r
137 } \r
138 }\r
139 }\r
140\r
141 gBS->CloseProtocol (\r
142 Controller, \r
143 &gEfiPciIoProtocolGuid, \r
144 This->DriverBindingHandle, \r
145 Controller \r
146 );\r
147 \r
148 return Status;\r
149}\r
150\r
18c97f53 151/**\r
152 Install EFI_ISA_ACPI_PROTOCOL.\r
153\r
154 @param This Driver Binding protocol instance pointer.\r
155 @param ControllerHandle Handle of device to bind driver to.\r
156 @param RemainingDevicePath Optional parameter use to pick a specific child\r
157 device to start.\r
158\r
159 @retval EFI_SUCCESS This driver is added to ControllerHandle\r
160 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
161 @retval other This driver does not support this device\r
162**/\r
c69dd9df 163EFI_STATUS\r
164EFIAPI\r
165PcatIsaAcpiDriverBindingStart (\r
166 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
167 IN EFI_HANDLE Controller,\r
168 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
169 )\r
c69dd9df 170{\r
171 EFI_STATUS Status;\r
172 EFI_PCI_IO_PROTOCOL *PciIo;\r
173 PCAT_ISA_ACPI_DEV *PcatIsaAcpiDev;\r
e0ee9d93 174 UINT64 Supports;\r
175 BOOLEAN Enabled;\r
176\r
177 Enabled = FALSE;\r
178 Supports = 0;\r
c69dd9df 179 PcatIsaAcpiDev = NULL;\r
180 //\r
181 // Open the PCI I/O Protocol Interface\r
182 //\r
183 PciIo = NULL;\r
184 Status = gBS->OpenProtocol (\r
185 Controller, \r
186 &gEfiPciIoProtocolGuid, \r
9c83c97a 187 (VOID**)&PciIo,\r
c69dd9df 188 This->DriverBindingHandle, \r
189 Controller, \r
190 EFI_OPEN_PROTOCOL_BY_DRIVER \r
191 );\r
192 if (EFI_ERROR (Status)) {\r
193 goto Done;\r
194 }\r
195\r
e0ee9d93 196 //\r
197 // Get supported PCI attributes\r
198 //\r
199 Status = PciIo->Attributes (\r
200 PciIo,\r
201 EfiPciIoAttributeOperationSupported,\r
202 0,\r
203 &Supports\r
204 );\r
205 if (EFI_ERROR (Status)) {\r
206 goto Done;\r
207 }\r
208\r
209 Supports &= (EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_IO_16);\r
210 if (Supports == 0 || Supports == (EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_IO_16)) {\r
211 Status = EFI_UNSUPPORTED;\r
212 goto Done;\r
213 } \r
214\r
215 Enabled = TRUE;\r
c69dd9df 216 Status = PciIo->Attributes (\r
217 PciIo, \r
218 EfiPciIoAttributeOperationEnable, \r
e0ee9d93 219 EFI_PCI_DEVICE_ENABLE | Supports | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO, \r
c69dd9df 220 NULL \r
221 );\r
222 if (EFI_ERROR (Status)) {\r
223 goto Done;\r
224 }\r
225 \r
226 //\r
227 // Allocate memory for the PCAT ISA ACPI Device structure\r
228 //\r
229 PcatIsaAcpiDev = NULL;\r
230 Status = gBS->AllocatePool (\r
231 EfiBootServicesData,\r
232 sizeof(PCAT_ISA_ACPI_DEV),\r
9c83c97a 233 (VOID**)&PcatIsaAcpiDev\r
c69dd9df 234 );\r
235 if (EFI_ERROR (Status)) {\r
236 goto Done;\r
237 }\r
238\r
239 //\r
240 // Initialize the PCAT ISA ACPI Device structure\r
241 //\r
242 PcatIsaAcpiDev->Signature = PCAT_ISA_ACPI_DEV_SIGNATURE;\r
243 PcatIsaAcpiDev->Handle = Controller;\r
244 PcatIsaAcpiDev->PciIo = PciIo;\r
245 \r
246 //\r
247 // IsaAcpi interface\r
248 //\r
249 (PcatIsaAcpiDev->IsaAcpi).DeviceEnumerate = IsaDeviceEnumerate;\r
250 (PcatIsaAcpiDev->IsaAcpi).SetPower = IsaDeviceSetPower;\r
251 (PcatIsaAcpiDev->IsaAcpi).GetCurResource = IsaGetCurrentResource;\r
252 (PcatIsaAcpiDev->IsaAcpi).GetPosResource = IsaGetPossibleResource;\r
253 (PcatIsaAcpiDev->IsaAcpi).SetResource = IsaSetResource;\r
254 (PcatIsaAcpiDev->IsaAcpi).EnableDevice = IsaEnableDevice;\r
255 (PcatIsaAcpiDev->IsaAcpi).InitDevice = IsaInitDevice;\r
256 (PcatIsaAcpiDev->IsaAcpi).InterfaceInit = IsaInterfaceInit;\r
257 \r
258 //\r
259 // Install the ISA ACPI Protocol interface\r
260 //\r
261 Status = gBS->InstallMultipleProtocolInterfaces (\r
262 &Controller,\r
263 &gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi,\r
264 NULL\r
265 );\r
266\r
267Done:\r
268 if (EFI_ERROR (Status)) {\r
e0ee9d93 269 if (PciIo != NULL && Enabled) {\r
c69dd9df 270 PciIo->Attributes (\r
271 PciIo, \r
272 EfiPciIoAttributeOperationDisable, \r
e0ee9d93 273 EFI_PCI_DEVICE_ENABLE | Supports | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,\r
c69dd9df 274 NULL \r
275 );\r
276 }\r
277 gBS->CloseProtocol (\r
278 Controller, \r
279 &gEfiPciIoProtocolGuid, \r
280 This->DriverBindingHandle, \r
281 Controller\r
282 );\r
283 if (PcatIsaAcpiDev != NULL) {\r
284 gBS->FreePool (PcatIsaAcpiDev);\r
285 }\r
286 return Status;\r
287 }\r
288 \r
289 return EFI_SUCCESS;\r
290}\r
291\r
18c97f53 292\r
293/**\r
294 Stop this driver on ControllerHandle. Support stopping any child handles\r
295 created by this driver.\r
296\r
297 @param This Protocol instance pointer.\r
298 @param ControllerHandle Handle of device to stop driver on\r
299 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
300 children is zero stop the entire bus driver.\r
301 @param ChildHandleBuffer List of Child Handles to Stop.\r
302\r
303 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
304 @retval other This driver was not removed from this device\r
305\r
306**/\r
c69dd9df 307EFI_STATUS\r
308EFIAPI\r
309PcatIsaAcpiDriverBindingStop (\r
310 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
311 IN EFI_HANDLE Controller,\r
312 IN UINTN NumberOfChildren,\r
313 IN EFI_HANDLE *ChildHandleBuffer\r
314 )\r
c69dd9df 315{\r
316 EFI_STATUS Status;\r
317 EFI_ISA_ACPI_PROTOCOL *IsaAcpi;\r
318 PCAT_ISA_ACPI_DEV *PcatIsaAcpiDev;\r
e0ee9d93 319 UINT64 Supports;\r
c69dd9df 320 \r
321 //\r
322 // Get the ISA ACPI Protocol Interface\r
323 // \r
324 Status = gBS->OpenProtocol (\r
325 Controller, \r
326 &gEfiIsaAcpiProtocolGuid, \r
9c83c97a 327 (VOID**)&IsaAcpi,\r
c69dd9df 328 This->DriverBindingHandle, \r
329 Controller, \r
330 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
331 );\r
332 if (EFI_ERROR (Status)) {\r
333 return Status;\r
334 }\r
335\r
336 //\r
337 // Get the PCAT ISA ACPI Device structure from the ISA ACPI Protocol\r
338 //\r
339 PcatIsaAcpiDev = PCAT_ISA_ACPI_DEV_FROM_THIS (IsaAcpi);\r
340\r
e0ee9d93 341 //\r
342 // Get supported PCI attributes\r
343 //\r
344 Status = PcatIsaAcpiDev->PciIo->Attributes (\r
345 PcatIsaAcpiDev->PciIo,\r
346 EfiPciIoAttributeOperationSupported,\r
347 0,\r
348 &Supports\r
349 );\r
350 if (EFI_ERROR (Status)) {\r
351 return Status;\r
352 }\r
353\r
354 Supports &= (EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_IO_16);\r
355\r
c69dd9df 356 PcatIsaAcpiDev->PciIo->Attributes (\r
357 PcatIsaAcpiDev->PciIo, \r
358 EfiPciIoAttributeOperationDisable, \r
e0ee9d93 359 EFI_PCI_DEVICE_ENABLE | Supports | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,\r
c69dd9df 360 NULL \r
361 );\r
362 \r
363 //\r
364 // Uninstall protocol interface: EFI_ISA_ACPI_PROTOCOL\r
365 //\r
366 Status = gBS->UninstallProtocolInterface (\r
367 Controller,\r
368 &gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi\r
369 );\r
370 if (EFI_ERROR (Status)) {\r
371 return Status;\r
372 }\r
373\r
374 gBS->CloseProtocol (\r
375 Controller, \r
376 &gEfiPciIoProtocolGuid, \r
377 This->DriverBindingHandle, \r
378 Controller\r
379 );\r
380 \r
381 gBS->FreePool (PcatIsaAcpiDev);\r
382 \r
383 return EFI_SUCCESS;\r
384}\r