]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/Wpce791/LpcDriver.c
MdeModulePkg: Fix use-after-free error in InstallConfigurationTable()
[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
3cbfba02
DW
230\r
231 //\r
232 // Get Pci IO\r
233 //\r
234 Status = gBS->OpenProtocol (\r
235 Controller,\r
236 &gEfiPciIoProtocolGuid,\r
237 (VOID **)&PciIo,\r
238 This->DriverBindingHandle,\r
239 Controller,\r
240 EFI_OPEN_PROTOCOL_BY_DRIVER\r
241 );\r
242\r
243 if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
244 return Status;\r
245 }\r
246\r
247 mLpc.PciIo = PciIo;\r
248\r
249 //\r
250 // Install IsaAcpi interface, the Sio interface is not installed!\r
251 //\r
252 Status = gBS->InstallMultipleProtocolInterfaces (\r
253 &Controller,\r
254 &gEfiIsaAcpiProtocolGuid,\r
255 &mLpc.IsaAcpi,\r
256 NULL\r
257 );\r
258 return Status;\r
259}\r
260\r
261\r
262EFI_STATUS\r
263EFIAPI\r
264LpcDriverStop (\r
265 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
266 IN EFI_HANDLE Controller,\r
267 IN UINTN NumberOfChildren,\r
268 IN EFI_HANDLE *ChildHandleBuffer\r
269 )\r
270{\r
271 EFI_STATUS Status;\r
272 EFI_ISA_ACPI_PROTOCOL *IsaAcpi;\r
273 LPC_DEV *LpcDev;\r
274\r
275 //\r
276 // Get EFI_ISA_ACPI_PROTOCOL interface\r
277 //\r
278 Status = gBS->OpenProtocol (\r
279 Controller,\r
280 &gEfiIsaAcpiProtocolGuid,\r
281 (VOID **)&IsaAcpi,\r
282 This->DriverBindingHandle,\r
283 Controller,\r
284 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
285 );\r
286 if (EFI_ERROR (Status)) {\r
287 return Status;\r
288 }\r
289\r
290 LpcDev = LPC_ISA_ACPI_FROM_THIS (IsaAcpi);\r
291\r
292 //\r
293 // Uninstall protocol interface: EFI_ISA_ACPI_PROTOCOL\r
294 //\r
295 Status = gBS->UninstallProtocolInterface (\r
296 Controller,\r
297 &gEfiIsaAcpiProtocolGuid,\r
298 &LpcDev->IsaAcpi\r
299 );\r
300 if (EFI_ERROR (Status)) {\r
301 return Status;\r
302 }\r
303\r
304 gBS->CloseProtocol (\r
305 Controller,\r
306 &gEfiPciIoProtocolGuid,\r
307 This->DriverBindingHandle,\r
308 Controller\r
309 );\r
310\r
311 return EFI_SUCCESS;\r
312}\r
313\r
314VOID\r
315LpcIoRead8 (\r
316 IN UINT16 Port,\r
317 OUT UINT8 *Data\r
318 )\r
319{\r
320 mLpc.PciIo->Io.Read(\r
321 mLpc.PciIo,\r
322 EfiPciWidthUint8,\r
323 EFI_PCI_IO_PASS_THROUGH_BAR,\r
324 Port,\r
325 1,\r
326 Data\r
327 );\r
328}\r
329\r
330VOID\r
331LpcIoWrite8 (\r
332 IN UINT16 Port,\r
333 IN UINT8 Data\r
334 )\r
335{\r
336 mLpc.PciIo->Io.Write(\r
337 mLpc.PciIo,\r
338 EfiPciWidthUint8,\r
339 EFI_PCI_IO_PASS_THROUGH_BAR,\r
340 Port,\r
341 1,\r
342 &Data\r
343 );\r
344}\r
345\r