2 Using PS2 Mouse to simulation Absolution Pointer Device.
4 Copyright (c) 2006 - 2009, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
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.
18 #define PS2_PACKET_LENGTH 3
19 #define PS2_SYNC_MASK 0xc
20 #define PS2_SYNC_BYTE 0x8
22 #define IS_PS2_SYNC_BYTE(byte) ((byte & PS2_SYNC_MASK) == PS2_SYNC_BYTE)
24 #define PS2_READ_BYTE_ONE 0
25 #define PS2_READ_DATA_BYTE 1
26 #define PS2_PROCESS_PACKET 2
29 #define BAT_TIMEOUT 500000
34 #define KBC_DATA_PORT 0x60
35 #define KBC_CMD_STS_PORT 0x64
40 #define READ_CMD_BYTE 0x20
41 #define WRITE_CMD_BYTE 0x60
42 #define DISABLE_AUX 0xa7
43 #define ENABLE_AUX 0xa8
44 #define SELF_TEST 0xaa
45 #define DISABLE_KB 0xad
46 #define ENABLE_KB 0xae
47 #define WRITE_AUX_DEV 0xd4
49 #define CMD_SYS_FLAG 0x04
50 #define CMD_KB_STS 0x10
51 #define CMD_KB_DIS 0x10
55 // 8042 Auxiliary Device Command
57 #define SETSF1_CMD 0xe6
58 #define SETSF2_CMD 0xe7
59 #define SETRE_CMD 0xe8
61 #define SETRM_CMD 0xf0
62 #define SETSR_CMD 0xf3
63 #define ENABLE_CMD 0xf4
64 #define DISABLE_CMD 0xf5
65 #define RESET_CMD 0xff
71 #define PS2_RESEND 0xfe
72 #define PS2MOUSE_BAT1 0xaa
73 #define PS2MOUSE_BAT2 0x0
76 // Keyboard Controller Status
87 /// Output buffer for auxiliary device (PS/2):
88 /// 0 - Holds keyboard data
89 /// 1 - Holds data for auxiliary device
93 /// Keyboard lock status:
94 /// 0 - keyboard locked
100 /// 0 - data byte written via port 60h
101 /// 1 - command byte written via port 64h
106 /// 0 - power-on reset
107 /// 1 - self-test successful
109 #define KBC_SYSF 0x04
111 /// Input Buffer Status :
112 /// 0 - input buffer empty
113 /// 1 - CPU data in input buffer
115 #define KBC_INPB 0x02
117 /// Output Buffer Status :
118 /// 0 - output buffer empty
119 /// 1 - keyboard controller data in output buffer
121 #define KBC_OUTB 0x01
124 Issue self test command via IsaIo interface.
126 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
128 @return EFI_SUCCESS Success to do keyboard self testing.
129 @return others Fail to do keyboard self testing.
133 IN EFI_ISA_IO_PROTOCOL
*IsaIo
137 Issue command to enable keyboard AUX functionality.
139 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
141 @return Status of command issuing.
145 IN EFI_ISA_IO_PROTOCOL
*IsaIo
149 Issue command to disable keyboard AUX functionality.
151 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
153 @return Status of command issuing.
157 IN EFI_ISA_IO_PROTOCOL
*IsaIo
161 Issue command to enable keyboard.
163 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
165 @return Status of command issuing.
169 IN EFI_ISA_IO_PROTOCOL
*IsaIo
173 Issue command to disable keyboard.
175 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
177 @return Status of command issuing.
181 IN EFI_ISA_IO_PROTOCOL
*IsaIo
185 Issue command to check keyboard status.
187 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
188 @param KeyboardEnable return whether keyboard is enable.
190 @return Status of command issuing.
194 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
195 OUT BOOLEAN
*KeyboardEnable
199 Issue command to reset keyboard.
201 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
203 @return Status of command issuing.
207 IN EFI_ISA_IO_PROTOCOL
*IsaIo
211 Issue command to set mouse's sample rate
213 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
214 @param SampleRate value of sample rate
216 @return Status of command issuing.
219 PS2MouseSetSampleRate (
220 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
221 IN MOUSE_SR SampleRate
225 Issue command to set mouse's resolution.
227 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
228 @param Resolution value of resolution
230 @return Status of command issuing.
233 PS2MouseSetResolution (
234 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
235 IN MOUSE_RE Resolution
239 Issue command to set mouse's scaling.
241 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
242 @param Scaling value of scaling
244 @return Status of command issuing.
248 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
253 Issue command to enable Ps2 mouse.
255 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
257 @return Status of command issuing.
261 IN EFI_ISA_IO_PROTOCOL
*IsaIo
265 Get mouse packet . Only care first 3 bytes
267 @param MouseAbsolutePointerDev Pointer to PS2 Absolute Pointer Simulation Device Private Data Structure
269 @retval EFI_NOT_READY Mouse Device not ready to input data packet, or some error happened during getting the packet
270 @retval EFI_SUCCESS The data packet is gotten successfully.
275 PS2_MOUSE_ABSOLUTE_POINTER_DEV
*MouseAbsolutePointerDev
279 Read data via IsaIo protocol with given number.
281 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
282 @param Buffer Buffer receive data of mouse
283 @param BufSize The size of buffer
284 @param State Check input or read data
286 @return status of reading mouse data.
290 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
292 IN OUT UINTN
*BufSize
,
300 I/O work flow of outing 8042 command.
302 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
303 @param Command I/O command.
305 @retval EFI_SUCCESS Success to excute I/O work flow
306 @retval EFI_TIMEOUT Keyboard controller time out.
310 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
315 I/O work flow of in 8042 data.
317 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
318 @param Data Data value
320 @retval EFI_SUCCESS Success to excute I/O work flow
321 @retval EFI_TIMEOUT Keyboard controller time out.
325 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
330 I/O work flow of outing 8042 data.
332 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
333 @param Data Data value
335 @retval EFI_SUCCESS Success to excute I/O work flow
336 @retval EFI_TIMEOUT Keyboard controller time out.
340 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
345 I/O work flow of outing 8042 Aux command.
347 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
348 @param Command Aux I/O command
349 @param Resend Whether need resend the Aux command.
351 @retval EFI_SUCCESS Success to excute I/O work flow
352 @retval EFI_TIMEOUT Keyboard controller time out.
356 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
362 I/O work flow of in 8042 Aux data.
364 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
365 @param Data Buffer holding return value.
367 @retval EFI_SUCCESS Success to excute I/O work flow
368 @retval EFI_TIMEOUT Keyboard controller time out.
372 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
377 I/O work flow of outing 8042 Aux data.
379 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
380 @param Data Buffer holding return value.
382 @retval EFI_SUCCESS Success to excute I/O work flow
383 @retval EFI_TIMEOUT Keyboard controller time out.
387 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
392 Check keyboard controller status, if it is output buffer full and for auxiliary device.
394 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
396 @retval EFI_SUCCESS Keyboard controller is ready
397 @retval EFI_NOT_READY Keyboard controller is not ready
401 IN EFI_ISA_IO_PROTOCOL
*IsaIo
405 I/O work flow to wait input buffer empty in given time.
407 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
408 @param Timeout Wating time.
410 @retval EFI_TIMEOUT if input is still not empty in given time.
411 @retval EFI_SUCCESS input is empty.
415 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,
420 I/O work flow to wait output buffer full in given time.
422 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL
423 @param Timeout given time
425 @retval EFI_TIMEOUT output is not full in given time
426 @retval EFI_SUCCESS output is full in given time.
430 IN EFI_ISA_IO_PROTOCOL
*IsaIo
,