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