]>
Commit | Line | Data |
---|---|---|
c860b463 | 1 | /** @file\r |
2 | EFI PCAT ISA ACPI Driver for a Generic PC Platform\r | |
c69dd9df | 3 | \r |
df6bd1b6 | 4 | Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r |
18c97f53 | 5 | This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
c69dd9df | 9 | \r |
18c97f53 | 10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
11 | WITHOUT 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 | |
20 | EFI_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 | 37 | EFI_STATUS\r |
38 | EFIAPI\r | |
39 | PcatIsaAcpiDriverEntryPoint (\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 | 65 | EFI_STATUS\r |
66 | EFIAPI\r | |
67 | PcatIsaAcpiDriverBindingSupported (\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 | 163 | EFI_STATUS\r |
164 | EFIAPI\r | |
165 | PcatIsaAcpiDriverBindingStart (\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 | |
df6bd1b6 | 209 | Supports &= (UINT64) (EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_IO_16);\r |
e0ee9d93 | 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 | |
e8bce4b4 RN |
245 | \r |
246 | //\r | |
247 | // Initialize PcatIsaAcpiDeviceList\r | |
248 | //\r | |
249 | InitializePcatIsaAcpiDeviceList ();\r | |
c69dd9df | 250 | \r |
251 | //\r | |
252 | // IsaAcpi interface\r | |
253 | //\r | |
254 | (PcatIsaAcpiDev->IsaAcpi).DeviceEnumerate = IsaDeviceEnumerate;\r | |
255 | (PcatIsaAcpiDev->IsaAcpi).SetPower = IsaDeviceSetPower;\r | |
256 | (PcatIsaAcpiDev->IsaAcpi).GetCurResource = IsaGetCurrentResource;\r | |
257 | (PcatIsaAcpiDev->IsaAcpi).GetPosResource = IsaGetPossibleResource;\r | |
258 | (PcatIsaAcpiDev->IsaAcpi).SetResource = IsaSetResource;\r | |
259 | (PcatIsaAcpiDev->IsaAcpi).EnableDevice = IsaEnableDevice;\r | |
260 | (PcatIsaAcpiDev->IsaAcpi).InitDevice = IsaInitDevice;\r | |
261 | (PcatIsaAcpiDev->IsaAcpi).InterfaceInit = IsaInterfaceInit;\r | |
262 | \r | |
263 | //\r | |
264 | // Install the ISA ACPI Protocol interface\r | |
265 | //\r | |
266 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
267 | &Controller,\r | |
268 | &gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi,\r | |
269 | NULL\r | |
270 | );\r | |
271 | \r | |
272 | Done:\r | |
273 | if (EFI_ERROR (Status)) {\r | |
e0ee9d93 | 274 | if (PciIo != NULL && Enabled) {\r |
c69dd9df | 275 | PciIo->Attributes (\r |
276 | PciIo, \r | |
277 | EfiPciIoAttributeOperationDisable, \r | |
e0ee9d93 | 278 | EFI_PCI_DEVICE_ENABLE | Supports | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,\r |
c69dd9df | 279 | NULL \r |
280 | );\r | |
281 | }\r | |
282 | gBS->CloseProtocol (\r | |
283 | Controller, \r | |
284 | &gEfiPciIoProtocolGuid, \r | |
285 | This->DriverBindingHandle, \r | |
286 | Controller\r | |
287 | );\r | |
288 | if (PcatIsaAcpiDev != NULL) {\r | |
289 | gBS->FreePool (PcatIsaAcpiDev);\r | |
290 | }\r | |
291 | return Status;\r | |
292 | }\r | |
293 | \r | |
294 | return EFI_SUCCESS;\r | |
295 | }\r | |
296 | \r | |
18c97f53 | 297 | \r |
298 | /**\r | |
299 | Stop this driver on ControllerHandle. Support stopping any child handles\r | |
300 | created by this driver.\r | |
301 | \r | |
302 | @param This Protocol instance pointer.\r | |
303 | @param ControllerHandle Handle of device to stop driver on\r | |
304 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
305 | children is zero stop the entire bus driver.\r | |
306 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
307 | \r | |
308 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r | |
309 | @retval other This driver was not removed from this device\r | |
310 | \r | |
311 | **/\r | |
c69dd9df | 312 | EFI_STATUS\r |
313 | EFIAPI\r | |
314 | PcatIsaAcpiDriverBindingStop (\r | |
315 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
316 | IN EFI_HANDLE Controller,\r | |
317 | IN UINTN NumberOfChildren,\r | |
318 | IN EFI_HANDLE *ChildHandleBuffer\r | |
319 | )\r | |
c69dd9df | 320 | {\r |
321 | EFI_STATUS Status;\r | |
322 | EFI_ISA_ACPI_PROTOCOL *IsaAcpi;\r | |
323 | PCAT_ISA_ACPI_DEV *PcatIsaAcpiDev;\r | |
e0ee9d93 | 324 | UINT64 Supports;\r |
c69dd9df | 325 | \r |
326 | //\r | |
327 | // Get the ISA ACPI Protocol Interface\r | |
328 | // \r | |
329 | Status = gBS->OpenProtocol (\r | |
330 | Controller, \r | |
331 | &gEfiIsaAcpiProtocolGuid, \r | |
9c83c97a | 332 | (VOID**)&IsaAcpi,\r |
c69dd9df | 333 | This->DriverBindingHandle, \r |
334 | Controller, \r | |
335 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
336 | );\r | |
337 | if (EFI_ERROR (Status)) {\r | |
338 | return Status;\r | |
339 | }\r | |
340 | \r | |
341 | //\r | |
342 | // Get the PCAT ISA ACPI Device structure from the ISA ACPI Protocol\r | |
343 | //\r | |
344 | PcatIsaAcpiDev = PCAT_ISA_ACPI_DEV_FROM_THIS (IsaAcpi);\r | |
345 | \r | |
e0ee9d93 | 346 | //\r |
347 | // Get supported PCI attributes\r | |
348 | //\r | |
349 | Status = PcatIsaAcpiDev->PciIo->Attributes (\r | |
350 | PcatIsaAcpiDev->PciIo,\r | |
351 | EfiPciIoAttributeOperationSupported,\r | |
352 | 0,\r | |
353 | &Supports\r | |
354 | );\r | |
355 | if (EFI_ERROR (Status)) {\r | |
356 | return Status;\r | |
357 | }\r | |
358 | \r | |
df6bd1b6 | 359 | Supports &= (UINT64) (EFI_PCI_IO_ATTRIBUTE_ISA_IO | EFI_PCI_IO_ATTRIBUTE_ISA_IO_16);\r |
e0ee9d93 | 360 | \r |
c69dd9df | 361 | PcatIsaAcpiDev->PciIo->Attributes (\r |
362 | PcatIsaAcpiDev->PciIo, \r | |
363 | EfiPciIoAttributeOperationDisable, \r | |
e0ee9d93 | 364 | EFI_PCI_DEVICE_ENABLE | Supports | EFI_PCI_IO_ATTRIBUTE_ISA_MOTHERBOARD_IO,\r |
c69dd9df | 365 | NULL \r |
366 | );\r | |
367 | \r | |
368 | //\r | |
369 | // Uninstall protocol interface: EFI_ISA_ACPI_PROTOCOL\r | |
370 | //\r | |
371 | Status = gBS->UninstallProtocolInterface (\r | |
372 | Controller,\r | |
373 | &gEfiIsaAcpiProtocolGuid, &PcatIsaAcpiDev->IsaAcpi\r | |
374 | );\r | |
375 | if (EFI_ERROR (Status)) {\r | |
376 | return Status;\r | |
377 | }\r | |
378 | \r | |
379 | gBS->CloseProtocol (\r | |
380 | Controller, \r | |
381 | &gEfiPciIoProtocolGuid, \r | |
382 | This->DriverBindingHandle, \r | |
383 | Controller\r | |
384 | );\r | |
385 | \r | |
386 | gBS->FreePool (PcatIsaAcpiDev);\r | |
387 | \r | |
388 | return EFI_SUCCESS;\r | |
389 | }\r |