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