]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/IsaAcpiDxe/PcatIsaAcpi.c
PcAtChipsetPkg/IsaAcpiDxe: Restore PCI attributes correctly
[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
cb68247d 4Copyright (c) 2006 - 2017, 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
619ad10f 35 @return Success or not for installing driver binding protocol\r
18c97f53 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
cb68247d 175 UINT64 OriginalAttributes;\r
e0ee9d93 176 BOOLEAN Enabled;\r
177\r
178 Enabled = FALSE;\r
179 Supports = 0;\r
c69dd9df 180 PcatIsaAcpiDev = NULL;\r
181 //\r
182 // Open the PCI I/O Protocol Interface\r
183 //\r
184 PciIo = NULL;\r
185 Status = gBS->OpenProtocol (\r
186 Controller, \r
187 &gEfiPciIoProtocolGuid, \r
9c83c97a 188 (VOID**)&PciIo,\r
c69dd9df 189 This->DriverBindingHandle, \r
190 Controller, \r
191 EFI_OPEN_PROTOCOL_BY_DRIVER \r
192 );\r
193 if (EFI_ERROR (Status)) {\r
194 goto Done;\r
195 }\r
196\r
e0ee9d93 197 //\r
198 // Get supported PCI attributes\r
199 //\r
200 Status = PciIo->Attributes (\r
201 PciIo,\r
202 EfiPciIoAttributeOperationSupported,\r
203 0,\r
204 &Supports\r
205 );\r
206 if (EFI_ERROR (Status)) {\r
207 goto Done;\r
208 }\r
209\r
df6bd1b6 210 Supports &= (UINT64) (EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_IO_16);\r
e0ee9d93 211 if (Supports == 0 || Supports == (EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_IO_16)) {\r
212 Status = EFI_UNSUPPORTED;\r
213 goto Done;\r
cb68247d
RN
214 }\r
215\r
216 Status = PciIo->Attributes (\r
217 PciIo,\r
218 EfiPciIoAttributeOperationGet,\r
219 0,\r
220 &OriginalAttributes\r
221 );\r
222 if (EFI_ERROR (Status)) {\r
223 goto Done;\r
224 }\r
e0ee9d93 225\r
c69dd9df 226 Status = PciIo->Attributes (\r
227 PciIo, \r
228 EfiPciIoAttributeOperationEnable, \r
e0ee9d93 229 EFI_PCI_DEVICE_ENABLE | Supports | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO, \r
c69dd9df 230 NULL \r
231 );\r
232 if (EFI_ERROR (Status)) {\r
233 goto Done;\r
234 }\r
cb68247d
RN
235\r
236 Enabled = TRUE;\r
c69dd9df 237 //\r
238 // Allocate memory for the PCAT ISA ACPI Device structure\r
239 //\r
240 PcatIsaAcpiDev = NULL;\r
241 Status = gBS->AllocatePool (\r
242 EfiBootServicesData,\r
243 sizeof(PCAT_ISA_ACPI_DEV),\r
9c83c97a 244 (VOID**)&PcatIsaAcpiDev\r
c69dd9df 245 );\r
246 if (EFI_ERROR (Status)) {\r
247 goto Done;\r
248 }\r
249\r
250 //\r
251 // Initialize the PCAT ISA ACPI Device structure\r
252 //\r
cb68247d
RN
253 PcatIsaAcpiDev->Signature = PCAT_ISA_ACPI_DEV_SIGNATURE;\r
254 PcatIsaAcpiDev->Handle = Controller;\r
255 PcatIsaAcpiDev->PciIo = PciIo;\r
256 PcatIsaAcpiDev->OriginalAttributes = OriginalAttributes;\r
e8bce4b4
RN
257\r
258 //\r
259 // Initialize PcatIsaAcpiDeviceList\r
260 //\r
261 InitializePcatIsaAcpiDeviceList ();\r
c69dd9df 262 \r
263 //\r
264 // IsaAcpi interface\r
265 //\r
266 (PcatIsaAcpiDev->IsaAcpi).DeviceEnumerate = IsaDeviceEnumerate;\r
267 (PcatIsaAcpiDev->IsaAcpi).SetPower = IsaDeviceSetPower;\r
268 (PcatIsaAcpiDev->IsaAcpi).GetCurResource = IsaGetCurrentResource;\r
269 (PcatIsaAcpiDev->IsaAcpi).GetPosResource = IsaGetPossibleResource;\r
270 (PcatIsaAcpiDev->IsaAcpi).SetResource = IsaSetResource;\r
271 (PcatIsaAcpiDev->IsaAcpi).EnableDevice = IsaEnableDevice;\r
272 (PcatIsaAcpiDev->IsaAcpi).InitDevice = IsaInitDevice;\r
273 (PcatIsaAcpiDev->IsaAcpi).InterfaceInit = IsaInterfaceInit;\r
274 \r
275 //\r
276 // Install the ISA ACPI Protocol interface\r
277 //\r
278 Status = gBS->InstallMultipleProtocolInterfaces (\r
279 &Controller,\r
280 &gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi,\r
281 NULL\r
282 );\r
283\r
284Done:\r
285 if (EFI_ERROR (Status)) {\r
e0ee9d93 286 if (PciIo != NULL && Enabled) {\r
c69dd9df 287 PciIo->Attributes (\r
288 PciIo, \r
cb68247d
RN
289 EfiPciIoAttributeOperationSet,\r
290 OriginalAttributes,\r
c69dd9df 291 NULL \r
292 );\r
293 }\r
294 gBS->CloseProtocol (\r
295 Controller, \r
296 &gEfiPciIoProtocolGuid, \r
297 This->DriverBindingHandle, \r
298 Controller\r
299 );\r
300 if (PcatIsaAcpiDev != NULL) {\r
301 gBS->FreePool (PcatIsaAcpiDev);\r
302 }\r
303 return Status;\r
304 }\r
305 \r
306 return EFI_SUCCESS;\r
307}\r
308\r
18c97f53 309\r
310/**\r
311 Stop this driver on ControllerHandle. Support stopping any child handles\r
312 created by this driver.\r
313\r
314 @param This Protocol instance pointer.\r
315 @param ControllerHandle Handle of device to stop driver on\r
316 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
317 children is zero stop the entire bus driver.\r
318 @param ChildHandleBuffer List of Child Handles to Stop.\r
319\r
320 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
321 @retval other This driver was not removed from this device\r
322\r
323**/\r
c69dd9df 324EFI_STATUS\r
325EFIAPI\r
326PcatIsaAcpiDriverBindingStop (\r
327 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
328 IN EFI_HANDLE Controller,\r
329 IN UINTN NumberOfChildren,\r
330 IN EFI_HANDLE *ChildHandleBuffer\r
331 )\r
c69dd9df 332{\r
333 EFI_STATUS Status;\r
334 EFI_ISA_ACPI_PROTOCOL *IsaAcpi;\r
335 PCAT_ISA_ACPI_DEV *PcatIsaAcpiDev;\r
336 \r
337 //\r
338 // Get the ISA ACPI Protocol Interface\r
339 // \r
340 Status = gBS->OpenProtocol (\r
341 Controller, \r
342 &gEfiIsaAcpiProtocolGuid, \r
9c83c97a 343 (VOID**)&IsaAcpi,\r
c69dd9df 344 This->DriverBindingHandle, \r
345 Controller, \r
346 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
347 );\r
348 if (EFI_ERROR (Status)) {\r
349 return Status;\r
350 }\r
351\r
352 //\r
353 // Get the PCAT ISA ACPI Device structure from the ISA ACPI Protocol\r
354 //\r
355 PcatIsaAcpiDev = PCAT_ISA_ACPI_DEV_FROM_THIS (IsaAcpi);\r
356\r
e0ee9d93 357 //\r
cb68247d 358 // Restore PCI attributes\r
e0ee9d93 359 //\r
360 Status = PcatIsaAcpiDev->PciIo->Attributes (\r
361 PcatIsaAcpiDev->PciIo,\r
cb68247d
RN
362 EfiPciIoAttributeOperationSet,\r
363 PcatIsaAcpiDev->OriginalAttributes,\r
364 NULL\r
e0ee9d93 365 );\r
366 if (EFI_ERROR (Status)) {\r
367 return Status;\r
368 }\r
369\r
c69dd9df 370 //\r
371 // Uninstall protocol interface: EFI_ISA_ACPI_PROTOCOL\r
372 //\r
373 Status = gBS->UninstallProtocolInterface (\r
374 Controller,\r
375 &gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi\r
376 );\r
377 if (EFI_ERROR (Status)) {\r
378 return Status;\r
379 }\r
380\r
381 gBS->CloseProtocol (\r
382 Controller, \r
383 &gEfiPciIoProtocolGuid, \r
384 This->DriverBindingHandle, \r
385 Controller\r
386 );\r
387 \r
388 gBS->FreePool (PcatIsaAcpiDev);\r
389 \r
390 return EFI_SUCCESS;\r
391}\r