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