]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/IsaAcpiDxe/PcatIsaAcpi.c
Update logic in Suuported() for PCI-ISA Bridges with Positive Decode to avoid false...
[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
174 \r
175 PcatIsaAcpiDev = NULL;\r
176 //\r
177 // Open the PCI I/O Protocol Interface\r
178 //\r
179 PciIo = NULL;\r
180 Status = gBS->OpenProtocol (\r
181 Controller, \r
182 &gEfiPciIoProtocolGuid, \r
9c83c97a 183 (VOID**)&PciIo,\r
c69dd9df 184 This->DriverBindingHandle, \r
185 Controller, \r
186 EFI_OPEN_PROTOCOL_BY_DRIVER \r
187 );\r
188 if (EFI_ERROR (Status)) {\r
189 goto Done;\r
190 }\r
191\r
192 Status = PciIo->Attributes (\r
193 PciIo, \r
194 EfiPciIoAttributeOperationEnable, \r
195 EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO, \r
196 NULL \r
197 );\r
198 if (EFI_ERROR (Status)) {\r
199 goto Done;\r
200 }\r
201 \r
202 //\r
203 // Allocate memory for the PCAT ISA ACPI Device structure\r
204 //\r
205 PcatIsaAcpiDev = NULL;\r
206 Status = gBS->AllocatePool (\r
207 EfiBootServicesData,\r
208 sizeof(PCAT_ISA_ACPI_DEV),\r
9c83c97a 209 (VOID**)&PcatIsaAcpiDev\r
c69dd9df 210 );\r
211 if (EFI_ERROR (Status)) {\r
212 goto Done;\r
213 }\r
214\r
215 //\r
216 // Initialize the PCAT ISA ACPI Device structure\r
217 //\r
218 PcatIsaAcpiDev->Signature = PCAT_ISA_ACPI_DEV_SIGNATURE;\r
219 PcatIsaAcpiDev->Handle = Controller;\r
220 PcatIsaAcpiDev->PciIo = PciIo;\r
221 \r
222 //\r
223 // IsaAcpi interface\r
224 //\r
225 (PcatIsaAcpiDev->IsaAcpi).DeviceEnumerate = IsaDeviceEnumerate;\r
226 (PcatIsaAcpiDev->IsaAcpi).SetPower = IsaDeviceSetPower;\r
227 (PcatIsaAcpiDev->IsaAcpi).GetCurResource = IsaGetCurrentResource;\r
228 (PcatIsaAcpiDev->IsaAcpi).GetPosResource = IsaGetPossibleResource;\r
229 (PcatIsaAcpiDev->IsaAcpi).SetResource = IsaSetResource;\r
230 (PcatIsaAcpiDev->IsaAcpi).EnableDevice = IsaEnableDevice;\r
231 (PcatIsaAcpiDev->IsaAcpi).InitDevice = IsaInitDevice;\r
232 (PcatIsaAcpiDev->IsaAcpi).InterfaceInit = IsaInterfaceInit;\r
233 \r
234 //\r
235 // Install the ISA ACPI Protocol interface\r
236 //\r
237 Status = gBS->InstallMultipleProtocolInterfaces (\r
238 &Controller,\r
239 &gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi,\r
240 NULL\r
241 );\r
242\r
243Done:\r
244 if (EFI_ERROR (Status)) {\r
245 if (PciIo) {\r
246 PciIo->Attributes (\r
247 PciIo, \r
248 EfiPciIoAttributeOperationDisable, \r
249 EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,\r
250 NULL \r
251 );\r
252 }\r
253 gBS->CloseProtocol (\r
254 Controller, \r
255 &gEfiPciIoProtocolGuid, \r
256 This->DriverBindingHandle, \r
257 Controller\r
258 );\r
259 if (PcatIsaAcpiDev != NULL) {\r
260 gBS->FreePool (PcatIsaAcpiDev);\r
261 }\r
262 return Status;\r
263 }\r
264 \r
265 return EFI_SUCCESS;\r
266}\r
267\r
18c97f53 268\r
269/**\r
270 Stop this driver on ControllerHandle. Support stopping any child handles\r
271 created by this driver.\r
272\r
273 @param This Protocol instance pointer.\r
274 @param ControllerHandle Handle of device to stop driver on\r
275 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
276 children is zero stop the entire bus driver.\r
277 @param ChildHandleBuffer List of Child Handles to Stop.\r
278\r
279 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
280 @retval other This driver was not removed from this device\r
281\r
282**/\r
c69dd9df 283EFI_STATUS\r
284EFIAPI\r
285PcatIsaAcpiDriverBindingStop (\r
286 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
287 IN EFI_HANDLE Controller,\r
288 IN UINTN NumberOfChildren,\r
289 IN EFI_HANDLE *ChildHandleBuffer\r
290 )\r
c69dd9df 291{\r
292 EFI_STATUS Status;\r
293 EFI_ISA_ACPI_PROTOCOL *IsaAcpi;\r
294 PCAT_ISA_ACPI_DEV *PcatIsaAcpiDev;\r
295 \r
296 //\r
297 // Get the ISA ACPI Protocol Interface\r
298 // \r
299 Status = gBS->OpenProtocol (\r
300 Controller, \r
301 &gEfiIsaAcpiProtocolGuid, \r
9c83c97a 302 (VOID**)&IsaAcpi,\r
c69dd9df 303 This->DriverBindingHandle, \r
304 Controller, \r
305 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
306 );\r
307 if (EFI_ERROR (Status)) {\r
308 return Status;\r
309 }\r
310\r
311 //\r
312 // Get the PCAT ISA ACPI Device structure from the ISA ACPI Protocol\r
313 //\r
314 PcatIsaAcpiDev = PCAT_ISA_ACPI_DEV_FROM_THIS (IsaAcpi);\r
315\r
316 PcatIsaAcpiDev->PciIo->Attributes (\r
317 PcatIsaAcpiDev->PciIo, \r
318 EfiPciIoAttributeOperationDisable, \r
319 EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,\r
320 NULL \r
321 );\r
322 \r
323 //\r
324 // Uninstall protocol interface: EFI_ISA_ACPI_PROTOCOL\r
325 //\r
326 Status = gBS->UninstallProtocolInterface (\r
327 Controller,\r
328 &gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi\r
329 );\r
330 if (EFI_ERROR (Status)) {\r
331 return Status;\r
332 }\r
333\r
334 gBS->CloseProtocol (\r
335 Controller, \r
336 &gEfiPciIoProtocolGuid, \r
337 This->DriverBindingHandle, \r
338 Controller\r
339 );\r
340 \r
341 gBS->FreePool (PcatIsaAcpiDev);\r
342 \r
343 return EFI_SUCCESS;\r
344}\r