]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/Wpce791/LpcDriver.c
NetworkPkg: Use Http11 definitions in HttpDxe and HttpBootDxe
[mirror_edk2.git] / Vlv2TbltDevicePkg / Wpce791 / LpcDriver.c
CommitLineData
3cbfba02
DW
1/** @file\r
2\r
3 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
4 \r\r
5 This program and the accompanying materials are licensed and made available under\r\r
6 the terms and conditions of the BSD License that accompanies this distribution. \r\r
7 The full text of the license may be found at \r\r
8 http://opensource.org/licenses/bsd-license.php. \r\r
9 \r\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r\r
12 \r\r
13\r
14\r
15Module Name:\r
16\r
17 LpcDriver.c\r
18\r
19Abstract:\r
20\r
21 EFI Lpc Driver for a Generic PC Platform\r
22\r
23\r
24\r
25--*/\r
26\r
27#include "LpcDriver.h"\r
28#include "IndustryStandard/Pci22.h"\r
29\r
30//\r
31// This driver is for ACPI(PNP0A03,0)/PCI(0x1f,0)\r
32//\r
33\r
34//\r
35// Lpc Driver Global Variables\r
36//\r
37\r
38EFI_DRIVER_BINDING_PROTOCOL gLpcDriver = {\r
39 LpcDriverSupported,\r
40 LpcDriverStart,\r
41 LpcDriverStop,\r
42 0x10,\r
43 NULL,\r
44 NULL\r
45};\r
46\r
47LPC_DEV mLpc = {\r
48 LPC_DEV_SIGNATURE,\r
49 NULL,\r
50 {\r
51 IsaDeviceEnumerate,\r
52 IsaDeviceSetPower,\r
53 IsaGetCurrentResource,\r
54 IsaGetPossibleResource,\r
55 IsaSetResource,\r
56 IsaEnableDevice,\r
57 IsaInitDevice,\r
58 LpcInterfaceInit\r
59 },\r
60 NULL\r
61};\r
62\r
63BOOLEAN InitExecuted = FALSE;\r
64\r
65/**\r
66 the entry point of the Lpc driver\r
67\r
68**/\r
69EFI_STATUS\r
70EFIAPI\r
71LpcDriverEntryPoint(\r
72 IN EFI_HANDLE ImageHandle,\r
73 IN EFI_SYSTEM_TABLE *SystemTable\r
74 )\r
75{\r
76\r
77\r
78 return EfiLibInstallDriverBinding (ImageHandle, SystemTable, &gLpcDriver, ImageHandle);\r
79}\r
80\r
81/**\r
82\r
83 ControllerDriver Protocol Method\r
84\r
85**/\r
86EFI_STATUS\r
87EFIAPI\r
88LpcDriverSupported (\r
89 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
90 IN EFI_HANDLE Controller,\r
91 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
92 )\r
93{\r
94 EFI_STATUS Status;\r
95 EFI_PCI_IO_PROTOCOL *PciIo;\r
96 EFI_DEVICE_PATH_PROTOCOL *IsaBridgeDevicePath;\r
97\r
98 ACPI_HID_DEVICE_PATH *AcpiNode;\r
99 PCI_DEVICE_PATH *PciNode;\r
100 PCI_TYPE00 Pci;\r
101\r
102 //\r
103 // Get the ISA bridge's Device Path and test it\r
104 // the following code is specific\r
105 //\r
106 Status = gBS->OpenProtocol (\r
107 Controller,\r
108 &gEfiDevicePathProtocolGuid,\r
109 (VOID **)&IsaBridgeDevicePath,\r
110 This->DriverBindingHandle,\r
111 Controller,\r
112 EFI_OPEN_PROTOCOL_BY_DRIVER\r
113 );\r
114\r
115 if (EFI_ERROR (Status)) {\r
116 return Status;\r
117 }\r
118\r
119 Status = EFI_SUCCESS;\r
120 AcpiNode = (ACPI_HID_DEVICE_PATH *)IsaBridgeDevicePath;\r
121 if (AcpiNode->Header.Type != ACPI_DEVICE_PATH ||\r
122 AcpiNode->Header.SubType != ACPI_DP ||\r
123 DevicePathNodeLength (&AcpiNode->Header) != sizeof(ACPI_HID_DEVICE_PATH) ||\r
124 AcpiNode -> HID != EISA_PNP_ID(0x0A03) ||\r
125 AcpiNode -> UID != 0 ) {\r
126 Status = EFI_UNSUPPORTED;\r
127 } else {\r
128 //\r
129 // Get the next node\r
130 //\r
131 IsaBridgeDevicePath = NextDevicePathNode (IsaBridgeDevicePath);\r
132 PciNode = (PCI_DEVICE_PATH *)IsaBridgeDevicePath;\r
133 if (PciNode->Header.Type != HARDWARE_DEVICE_PATH ||\r
134 PciNode->Header.SubType != HW_PCI_DP ||\r
135 DevicePathNodeLength (&PciNode->Header) != sizeof (PCI_DEVICE_PATH) ||\r
136 PciNode -> Function != 0x00 ||\r
137 PciNode -> Device != 0x1f ) {\r
138 Status = EFI_UNSUPPORTED;\r
139 }\r
140 }\r
141\r
142 gBS->CloseProtocol (\r
143 Controller,\r
144 &gEfiDevicePathProtocolGuid,\r
145 This->DriverBindingHandle,\r
146 Controller\r
147 );\r
148\r
149 if (EFI_ERROR (Status)) {\r
150 return EFI_UNSUPPORTED;\r
151 }\r
152\r
153 //\r
154 // Get PciIo protocol instance\r
155 //\r
156 Status = gBS->OpenProtocol (\r
157 Controller,\r
158 &gEfiPciIoProtocolGuid,\r
159 (VOID **)&PciIo,\r
160 This->DriverBindingHandle,\r
161 Controller,\r
162 EFI_OPEN_PROTOCOL_BY_DRIVER\r
163 );\r
164\r
165 if (EFI_ERROR(Status)) {\r
166 return Status;\r
167 }\r
168\r
169 Status = PciIo->Pci.Read (\r
170 PciIo,\r
171 EfiPciIoWidthUint32,\r
172 0,\r
173 sizeof(Pci) / sizeof(UINT32),\r
174 &Pci\r
175 );\r
176\r
177 if (!EFI_ERROR (Status)) {\r
178 Status = EFI_SUCCESS; //TODO: force return success as temp solution EFI_UNSUPPORTED;\r
179 if ((Pci.Hdr.Command & 0x03) == 0x03) {\r
180 if (Pci.Hdr.ClassCode[2] == PCI_CLASS_BRIDGE) {\r
181 //\r
182 // See if this is a standard PCI to ISA Bridge from the Base Code\r
183 // and Class Code\r
184 //\r
185 if (Pci.Hdr.ClassCode[1] == PCI_CLASS_BRIDGE_ISA) {\r
186 Status = EFI_SUCCESS;\r
187 } else {\r
188 }\r
189\r
190 //\r
191 // See if this is an Intel PCI to ISA bridge in Positive Decode Mode\r
192 //\r
193 if (Pci.Hdr.ClassCode[1] == PCI_CLASS_BRIDGE_ISA_PDECODE &&\r
194 Pci.Hdr.VendorId == 0x8086 &&\r
195 Pci.Hdr.DeviceId == 0x7110) {\r
196 Status = EFI_SUCCESS;\r
197 } else {\r
198 }\r
199 } else {\r
200 }\r
201 }\r
202 else {\r
203 }\r
204 }\r
205\r
206 gBS->CloseProtocol (\r
207 Controller,\r
208 &gEfiPciIoProtocolGuid,\r
209 This->DriverBindingHandle,\r
210 Controller\r
211 );\r
212 return Status;\r
213}\r
214\r
215\r
216/**\r
217 Install EFI_ISA_ACPI_PROTOCOL\r
218\r
219**/\r
220EFI_STATUS\r
221EFIAPI\r
222LpcDriverStart (\r
223 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
224 IN EFI_HANDLE Controller,\r
225 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
226 )\r
227{\r
228 EFI_STATUS Status;\r
229 EFI_PCI_IO_PROTOCOL *PciIo;\r
230 LPC_DEV *LpcDev;\r
231\r
232\r
233 LpcDev = NULL;\r
234\r
235 //\r
236 // Get Pci IO\r
237 //\r
238 Status = gBS->OpenProtocol (\r
239 Controller,\r
240 &gEfiPciIoProtocolGuid,\r
241 (VOID **)&PciIo,\r
242 This->DriverBindingHandle,\r
243 Controller,\r
244 EFI_OPEN_PROTOCOL_BY_DRIVER\r
245 );\r
246\r
247 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
248 return Status;\r
249 }\r
250\r
251 mLpc.PciIo = PciIo;\r
252\r
253 //\r
254 // Install IsaAcpi interface, the Sio interface is not installed!\r
255 //\r
256 Status = gBS->InstallMultipleProtocolInterfaces (\r
257 &Controller,\r
258 &gEfiIsaAcpiProtocolGuid,\r
259 &mLpc.IsaAcpi,\r
260 NULL\r
261 );\r
262 return Status;\r
263}\r
264\r
265\r
266EFI_STATUS\r
267EFIAPI\r
268LpcDriverStop (\r
269 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
270 IN EFI_HANDLE Controller,\r
271 IN UINTN NumberOfChildren,\r
272 IN EFI_HANDLE *ChildHandleBuffer\r
273 )\r
274{\r
275 EFI_STATUS Status;\r
276 EFI_ISA_ACPI_PROTOCOL *IsaAcpi;\r
277 LPC_DEV *LpcDev;\r
278\r
279 //\r
280 // Get EFI_ISA_ACPI_PROTOCOL interface\r
281 //\r
282 Status = gBS->OpenProtocol (\r
283 Controller,\r
284 &gEfiIsaAcpiProtocolGuid,\r
285 (VOID **)&IsaAcpi,\r
286 This->DriverBindingHandle,\r
287 Controller,\r
288 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
289 );\r
290 if (EFI_ERROR (Status)) {\r
291 return Status;\r
292 }\r
293\r
294 LpcDev = LPC_ISA_ACPI_FROM_THIS (IsaAcpi);\r
295\r
296 //\r
297 // Uninstall protocol interface: EFI_ISA_ACPI_PROTOCOL\r
298 //\r
299 Status = gBS->UninstallProtocolInterface (\r
300 Controller,\r
301 &gEfiIsaAcpiProtocolGuid,\r
302 &LpcDev->IsaAcpi\r
303 );\r
304 if (EFI_ERROR (Status)) {\r
305 return Status;\r
306 }\r
307\r
308 gBS->CloseProtocol (\r
309 Controller,\r
310 &gEfiPciIoProtocolGuid,\r
311 This->DriverBindingHandle,\r
312 Controller\r
313 );\r
314\r
315 return EFI_SUCCESS;\r
316}\r
317\r
318VOID\r
319LpcIoRead8 (\r
320 IN UINT16 Port,\r
321 OUT UINT8 *Data\r
322 )\r
323{\r
324 mLpc.PciIo->Io.Read(\r
325 mLpc.PciIo,\r
326 EfiPciWidthUint8,\r
327 EFI_PCI_IO_PASS_THROUGH_BAR,\r
328 Port,\r
329 1,\r
330 Data\r
331 );\r
332}\r
333\r
334VOID\r
335LpcIoWrite8 (\r
336 IN UINT16 Port,\r
337 IN UINT8 Data\r
338 )\r
339{\r
340 mLpc.PciIo->Io.Write(\r
341 mLpc.PciIo,\r
342 EfiPciWidthUint8,\r
343 EFI_PCI_IO_PASS_THROUGH_BAR,\r
344 Port,\r
345 1,\r
346 &Data\r
347 );\r
348}\r
349\r