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