]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/Wpce791/LpcIsaAcpi.c
Vlv2TbltDevicePkg:Signal EndOfDxe Event.
[mirror_edk2.git] / Vlv2TbltDevicePkg / Wpce791 / LpcIsaAcpi.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
14Module Name:\r
15\r
16 LpcIsaAcpi.c\r
17\r
18Abstract: IsaAcpi implementation\r
19\r
20\r
21\r
22--*/\r
23\r
24#include "LpcDriver.h"\r
25\r
26//\r
27// PS/2 Keyboard Controller\r
28//\r
29static EFI_ISA_ACPI_RESOURCE mLpcWpce791Ps2KeyboardDeviceResources[] = {\r
30 {EfiIsaAcpiResourceIo, 0, 0x60, 0x64},\r
31 {EfiIsaAcpiResourceInterrupt, 0, 1, 0},\r
32 {EfiIsaAcpiResourceEndOfList, 0, 0, 0}\r
33};\r
34\r
35//\r
36// PS/2 Mouse Controller\r
37//\r
38static EFI_ISA_ACPI_RESOURCE mLpcWpce791Ps2MouseDeviceResources[] = {\r
39 {EfiIsaAcpiResourceIo, 0, 0x60, 0x64},\r
40 {EfiIsaAcpiResourceInterrupt, 0, 12, 0},\r
41 {EfiIsaAcpiResourceEndOfList, 0, 0, 0}\r
42};\r
43\r
44//\r
45// COM\r
46//\r
47static EFI_ISA_ACPI_RESOURCE mLpcWpce791ComDeviceResources[] = {\r
48 {EfiIsaAcpiResourceIo, 0, 0x3f8, 0x3ff},\r
49 {EfiIsaAcpiResourceInterrupt, 0, 4, 0},\r
50 {EfiIsaAcpiResourceEndOfList, 0, 0, 0}\r
51};\r
52\r
53//\r
54// Table of ISA Controllers\r
55//\r
56EFI_ISA_ACPI_RESOURCE_LIST mLpcWpce791DeviceList[] = {\r
57 {{EISA_PNP_ID(0x303), 0}, mLpcWpce791Ps2KeyboardDeviceResources }, // PS/2 Keyboard Controller\r
58 {{EISA_PNP_ID(0xF03), 0}, mLpcWpce791Ps2MouseDeviceResources }, // PS/2 Mouse Controller\r
59 {{EISA_PNP_ID(0x501), 0}, mLpcWpce791ComDeviceResources }, // COM\r
60 {{0, 0}, NULL } // End\r
61};\r
62\r
63static ICH_DMA_INIT mIchDmaInitTable [] = {\r
64//\r
65//Register OFFSET, Value\r
66//\r
67\r
68 0x0D8, 0x000, // Reset DMA Controller 2\r
69 0x0D0, 0x000, // Enable DMA controller 2\r
70 0x00C, 0x000, // Reset DMA Controller 1\r
71 0x008, 0x000, // Enable DMA controller 1\r
72\r
73 //\r
74 // Channel 4\r
75 //\r
76 0x0D6, 0x0c0, // DMA contr. 2 Cascade mode, addr. increment, disable auto init.\r
77 0x0D2, 0x000, // Clear write request register\r
78 0x0d4, 0x000, // Enable DREQs for channel\r
79\r
80 //\r
81 // Channel 0\r
82 //\r
83 0x00B, 0x040, // DMA contr. 1 single mode, addr. increment, disable auto init.\r
84 0x009, 0x000, // Clear write request register\r
85 0x00A, 0x000, // Enable DREQs for channel\r
86\r
87 //\r
88 // Channel 1\r
89 //\r
90 0x00B, 0x041, // DMA contr. 1 single mode, addr. increment, disable auto init.\r
91 0x009, 0x001, // Clear write request register\r
92 0x00A, 0x001, // Enable DREQs for channel\r
93\r
94 //\r
95 // Channel 2\r
96 //\r
97 0x00B, 0x042, // DMA contr. 1 single mode, addr. increment, disable auto init.\r
98 0x009, 0x002, // Clear write request register\r
99 0x00A, 0x002, // Enable DREQs for channel\r
100\r
101 //\r
102 // Channel 3\r
103 //\r
104 0x00B, 0x043, // DMA contr. 1 single mode, addr. increment, disable auto init.\r
105 0x009, 0x003, // Clear write request register\r
106 0x00A, 0x003, // Enable DREQs for channel\r
107\r
108 //\r
109 // Channel 5\r
110 //\r
111 0x0D6, 0x041, // DMA contr. 2 single mode, addr. increment, disable auto init.\r
112 0x0D2, 0x001, // Clear write request register\r
113 0x0D4, 0x001, // Enable DREQs for channel\r
114\r
115 //\r
116 // Channel 6\r
117 //\r
118 0x0D6, 0x042, // DMA contr. 2 single mode, addr. increment, disable auto init.\r
119 0x0D2, 0x002, // Clear write request register\r
120 0x0D4, 0x002, // Enable DREQs for channel\r
121\r
122 //\r
123 // Channel 7\r
124 //\r
125 0x0D6, 0x043, // DMA contr. 2 single mode, addr. increment, disable auto init.\r
126 0x0D2, 0x003, // Clear write request register\r
127 0x0D4, 0x003 // Enable DREQs for channel\r
128\r
129};\r
130\r
131//\r
132// ISA ACPI Protocol Functions\r
133//\r
134/**\r
135\r
136 Enumerate the ISA devices on the ISA bus\r
137\r
138**/\r
139VOID\r
140IsaDeviceLookup (\r
141 IN EFI_ISA_ACPI_DEVICE_ID *Device,\r
142 OUT EFI_ISA_ACPI_RESOURCE_LIST **IsaAcpiDevice,\r
143 OUT EFI_ISA_ACPI_RESOURCE_LIST **NextIsaAcpiDevice\r
144 )\r
145{\r
146 UINTN Index;\r
147\r
148 *IsaAcpiDevice = NULL;\r
149 if (NextIsaAcpiDevice != NULL) {\r
150 *NextIsaAcpiDevice = NULL;\r
151 }\r
152 if (Device == NULL) {\r
153 Index = 0;\r
154 } else {\r
155 for(Index = 0; mLpcWpce791DeviceList[Index].Device.HID != 0; Index++) {\r
156 if (Device->HID == mLpcWpce791DeviceList[Index].Device.HID &&\r
157 Device->UID == mLpcWpce791DeviceList[Index].Device.UID ) {\r
158 break;\r
159 }\r
160 }\r
161 if (mLpcWpce791DeviceList[Index].Device.HID == 0) {\r
162 return;\r
163 }\r
164 *IsaAcpiDevice = &(mLpcWpce791DeviceList[Index]);\r
165 Index++;\r
166 }\r
167 if (NextIsaAcpiDevice != NULL && mLpcWpce791DeviceList[Index].Device.HID != 0){\r
168 *NextIsaAcpiDevice = &(mLpcWpce791DeviceList[Index]);\r
169 }\r
170}\r
171\r
172\r
173/**\r
174 Enumerate the ISA devices on the ISA bus\r
175 It is hard code now and future it will get from ACPI table\r
176\r
177**/\r
178EFI_STATUS\r
179EFIAPI\r
180IsaDeviceEnumerate (\r
181 IN EFI_ISA_ACPI_PROTOCOL *This,\r
182 OUT EFI_ISA_ACPI_DEVICE_ID **Device\r
183 )\r
184{\r
185 EFI_ISA_ACPI_RESOURCE_LIST *IsaAcpiDevice;\r
186 EFI_ISA_ACPI_RESOURCE_LIST *NextIsaAcpiDevice;\r
187\r
188 IsaDeviceLookup (*Device, &IsaAcpiDevice, &NextIsaAcpiDevice);\r
189 if (NextIsaAcpiDevice == NULL) {\r
190 return EFI_NOT_FOUND;\r
191 }\r
192 *Device = &(NextIsaAcpiDevice->Device);\r
193 return EFI_SUCCESS;\r
194}\r
195\r
196/**\r
197 Set ISA device power use sio\r
198\r
199**/\r
200EFI_STATUS\r
201EFIAPI\r
202IsaDeviceSetPower (\r
203 IN EFI_ISA_ACPI_PROTOCOL *This,\r
204 IN EFI_ISA_ACPI_DEVICE_ID *Device,\r
205 IN BOOLEAN OnOff\r
206 )\r
207{\r
208 return EFI_UNSUPPORTED;\r
209}\r
210\r
211\r
212/**\r
213 Get current Resource of the specific ISA device\r
214 It is hardcode now and future will get from ACPI table\r
215\r
216**/\r
217EFI_STATUS\r
218EFIAPI\r
219IsaGetCurrentResource (\r
220 IN EFI_ISA_ACPI_PROTOCOL *This,\r
221 IN EFI_ISA_ACPI_DEVICE_ID *Device,\r
222 OUT EFI_ISA_ACPI_RESOURCE_LIST **ResourceList\r
223 )\r
224{\r
225 IsaDeviceLookup (Device, ResourceList, NULL);\r
226 if (*ResourceList == NULL || (*ResourceList)->ResourceItem == NULL) {\r
227 return EFI_NOT_FOUND;\r
228 }\r
229 return EFI_SUCCESS;\r
230}\r
231\r
232EFI_STATUS\r
233EFIAPI\r
234IsaGetPossibleResource (\r
235 IN EFI_ISA_ACPI_PROTOCOL *This,\r
236 IN EFI_ISA_ACPI_DEVICE_ID *Device,\r
237 OUT EFI_ISA_ACPI_RESOURCE_LIST **ResourceList\r
238 )\r
239{\r
240 //\r
241 // Not supported yet\r
242 //\r
243 return EFI_UNSUPPORTED;\r
244}\r
245\r
246\r
247EFI_STATUS\r
248EFIAPI\r
249IsaSetResource (\r
250 IN EFI_ISA_ACPI_PROTOCOL *This,\r
251 IN EFI_ISA_ACPI_DEVICE_ID *Device,\r
252 IN EFI_ISA_ACPI_RESOURCE_LIST *ResourceList\r
253 )\r
254{\r
255 return EFI_UNSUPPORTED;\r
256}\r
257\r
258EFI_STATUS\r
259EFIAPI\r
260IsaEnableDevice (\r
261 IN EFI_ISA_ACPI_PROTOCOL *This,\r
262 IN EFI_ISA_ACPI_DEVICE_ID *Device,\r
263 IN BOOLEAN Enable\r
264 )\r
265{\r
266\r
267 return EFI_UNSUPPORTED;\r
268}\r
269\r
270/**\r
271\r
272 Clear out Resource List if device is set to disable by platform policy\r
273\r
274**/\r
275VOID\r
276EmptyResourceList (\r
277 IN UINT32 DeviceHid\r
278 )\r
279{\r
280 UINT8 Index;\r
281 for (Index = 0; mLpcWpce791DeviceList[Index].Device.HID != 0; Index++) {\r
282 if (DeviceHid == mLpcWpce791DeviceList[Index].Device.HID) {\r
283 mLpcWpce791DeviceList[Index].ResourceItem = NULL;\r
284 }\r
285 }\r
286 return;\r
287}\r
288\r
289/**\r
290\r
291 Clear out Resource List if device is set to disable by platform policy\r
292\r
293**/\r
294VOID\r
295EmptyResourceListHidUid (\r
296 IN UINT32 DeviceHid,\r
297 IN UINT32 DeviceUid\r
298 )\r
299{\r
300 UINT8 Index;\r
301 for (Index = 0; mLpcWpce791DeviceList[Index].Device.HID != 0; Index++) {\r
302 if ((DeviceHid == mLpcWpce791DeviceList[Index].Device.HID) &&\r
303 (DeviceUid == mLpcWpce791DeviceList[Index].Device.UID)) {\r
304 mLpcWpce791DeviceList[Index].ResourceItem = NULL;\r
305 }\r
306 }\r
307 return;\r
308}\r
309\r
310EFI_STATUS\r
311EFIAPI\r
312IsaInitDevice (\r
313 IN EFI_ISA_ACPI_PROTOCOL *This,\r
314 IN EFI_ISA_ACPI_DEVICE_ID *Device\r
315 )\r
316{\r
317 EFI_WPCE791_POLICY_PROTOCOL *LpcWpce791Policy;\r
318 EFI_STATUS Status;\r
319\r
320 //\r
321 // Disable configuration according to platform protocol\r
322 //\r
323 Status = gBS->LocateProtocol (\r
324 &gEfiLpcWpce791PolicyProtocolGuid,\r
325 NULL,\r
326 (VOID **) &LpcWpce791Policy\r
327 );\r
328 if (!EFI_ERROR(Status)) {\r
329 if (LpcWpce791Policy->DeviceEnables.Ps2Keyboard == EFI_WPCE791_PS2_KEYBOARD_DISABLE) {\r
330 EmptyResourceList(EISA_PNP_ID(0x303));\r
331 DisableLogicalDevice (SIO_KEYBOARD);\r
332 EmptyResourceList(EISA_PNP_ID(0xF03));\r
333 DisableLogicalDevice (SIO_KEYBOARD);\r
334 }\r
335 if (LpcWpce791Policy->DeviceEnables.Ps2Mouse == EFI_WPCE791_PS2_MOUSE_DISABLE) {\r
336 EmptyResourceList(EISA_PNP_ID(0xF03));\r
337 DisableLogicalDevice (SIO_MOUSE);\r
338 }\r
339 }\r
340\r
341 return EFI_SUCCESS;\r
342}\r
343\r
344EFI_STATUS\r
345EFIAPI\r
346LpcInterfaceInit (\r
347 IN EFI_ISA_ACPI_PROTOCOL *This\r
348 )\r
349{\r
350 EFI_PCI_IO_PROTOCOL *PciIo;\r
351 UINTN Index;\r
352\r
353 PciIo = (LPC_ISA_ACPI_FROM_THIS (This))->PciIo;\r
354\r
355 //\r
356 // DMA controller initialize\r
357 //\r
358 for (Index=0; Index < (sizeof(mIchDmaInitTable)/sizeof(ICH_DMA_INIT)); Index++) {\r
359 PciIo->Io.Write (\r
360 PciIo,\r
361 EfiPciIoWidthUint8,\r
362 EFI_PCI_IO_PASS_THROUGH_BAR,\r
363 mIchDmaInitTable[Index].Register,\r
364 1,\r
365 &mIchDmaInitTable[Index].Value\r
366 );\r
367 }\r
368\r
369 return EFI_SUCCESS;\r
370}\r
371\r