]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/Ps2MouseAbsolutePointerDxe/CommPs2.h
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / Ps2MouseAbsolutePointerDxe / CommPs2.h
CommitLineData
18a73eb7 1/** @file\r
2 Using PS2 Mouse to simulation Absolution Pointer Device.\r
0a6f4824
LG
3\r
4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
c0a00b14 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
afd0fe22 6\r
7**/\r
8\r
18a73eb7 9#ifndef __COMMPS2_H__\r
10#define __COMMPS2_H__\r
afd0fe22 11\r
12#define PS2_PACKET_LENGTH 3\r
13#define PS2_SYNC_MASK 0xc\r
14#define PS2_SYNC_BYTE 0x8\r
15\r
16#define IS_PS2_SYNC_BYTE(byte) ((byte & PS2_SYNC_MASK) == PS2_SYNC_BYTE)\r
17\r
18#define PS2_READ_BYTE_ONE 0\r
19#define PS2_READ_DATA_BYTE 1\r
20#define PS2_PROCESS_PACKET 2\r
21\r
22#define TIMEOUT 50000\r
23#define BAT_TIMEOUT 500000\r
24\r
25//\r
26// 8042 I/O Port\r
27//\r
28#define KBC_DATA_PORT 0x60\r
29#define KBC_CMD_STS_PORT 0x64\r
30\r
31//\r
32// 8042 Command\r
33//\r
34#define READ_CMD_BYTE 0x20\r
35#define WRITE_CMD_BYTE 0x60\r
36#define DISABLE_AUX 0xa7\r
37#define ENABLE_AUX 0xa8\r
38#define SELF_TEST 0xaa\r
39#define DISABLE_KB 0xad\r
40#define ENABLE_KB 0xae\r
41#define WRITE_AUX_DEV 0xd4\r
42\r
43#define CMD_SYS_FLAG 0x04\r
44#define CMD_KB_STS 0x10\r
45#define CMD_KB_DIS 0x10\r
46#define CMD_KB_EN 0x0\r
47\r
48//\r
49// 8042 Auxiliary Device Command\r
50//\r
51#define SETSF1_CMD 0xe6\r
52#define SETSF2_CMD 0xe7\r
53#define SETRE_CMD 0xe8\r
54#define READ_CMD 0xeb\r
55#define SETRM_CMD 0xf0\r
56#define SETSR_CMD 0xf3\r
57#define ENABLE_CMD 0xf4\r
58#define DISABLE_CMD 0xf5\r
59#define RESET_CMD 0xff\r
60\r
61//\r
62// return code\r
63//\r
64#define PS2_ACK 0xfa\r
65#define PS2_RESEND 0xfe\r
66#define PS2MOUSE_BAT1 0xaa\r
67#define PS2MOUSE_BAT2 0x0\r
68\r
69//\r
70// Keyboard Controller Status\r
71//\r
cab302fd 72///\r
73/// Parity Error\r
74///\r
0a6f4824 75#define KBC_PARE 0x80\r
cab302fd 76///\r
77/// General Time Out\r
78///\r
0a6f4824 79#define KBC_TIM 0x40\r
cab302fd 80///\r
81/// Output buffer for auxiliary device (PS/2):\r
82/// 0 - Holds keyboard data\r
83/// 1 - Holds data for auxiliary device\r
84///\r
0a6f4824 85#define KBC_AUXB 0x20\r
cab302fd 86///\r
87/// Keyboard lock status:\r
88/// 0 - keyboard locked\r
89/// 1 - keyboard free\r
90///\r
0a6f4824 91#define KBC_KEYL 0x10\r
cab302fd 92///\r
93/// Command/Data:\r
94/// 0 - data byte written via port 60h\r
95/// 1 - command byte written via port 64h\r
96///\r
97#define KBC_CD 0x08\r
98///\r
99/// System Flag:\r
100/// 0 - power-on reset\r
101/// 1 - self-test successful\r
102///\r
0a6f4824 103#define KBC_SYSF 0x04\r
cab302fd 104///\r
105/// Input Buffer Status :\r
106/// 0 - input buffer empty\r
107/// 1 - CPU data in input buffer\r
108///\r
0a6f4824 109#define KBC_INPB 0x02\r
cab302fd 110///\r
111/// Output Buffer Status :\r
112/// 0 - output buffer empty\r
113/// 1 - keyboard controller data in output buffer\r
114///\r
0a6f4824 115#define KBC_OUTB 0x01\r
bcd70414 116\r
117/**\r
118 Issue self test command via IsaIo interface.\r
0a6f4824 119\r
bcd70414 120 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
0a6f4824 121\r
bcd70414 122 @return EFI_SUCCESS Success to do keyboard self testing.\r
123 @return others Fail to do keyboard self testing.\r
124**/\r
afd0fe22 125EFI_STATUS\r
126KbcSelfTest (\r
127 IN EFI_ISA_IO_PROTOCOL *IsaIo\r
ed66e1bc 128 );\r
afd0fe22 129\r
bcd70414 130/**\r
131 Issue command to enable keyboard AUX functionality.\r
0a6f4824 132\r
bcd70414 133 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
0a6f4824 134\r
bcd70414 135 @return Status of command issuing.\r
136**/\r
afd0fe22 137EFI_STATUS\r
138KbcEnableAux (\r
139 IN EFI_ISA_IO_PROTOCOL *IsaIo\r
ed66e1bc 140 );\r
afd0fe22 141\r
bcd70414 142/**\r
143 Issue command to disable keyboard AUX functionality.\r
0a6f4824 144\r
bcd70414 145 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
0a6f4824 146\r
bcd70414 147 @return Status of command issuing.\r
148**/\r
afd0fe22 149EFI_STATUS\r
150KbcDisableAux (\r
151 IN EFI_ISA_IO_PROTOCOL *IsaIo\r
ed66e1bc 152 );\r
afd0fe22 153\r
bcd70414 154/**\r
155 Issue command to enable keyboard.\r
0a6f4824 156\r
bcd70414 157 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
0a6f4824 158\r
bcd70414 159 @return Status of command issuing.\r
160**/\r
afd0fe22 161EFI_STATUS\r
162KbcEnableKb (\r
163 IN EFI_ISA_IO_PROTOCOL *IsaIo\r
ed66e1bc 164 );\r
afd0fe22 165\r
bcd70414 166/**\r
167 Issue command to disable keyboard.\r
0a6f4824 168\r
bcd70414 169 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
0a6f4824 170\r
bcd70414 171 @return Status of command issuing.\r
172**/\r
afd0fe22 173EFI_STATUS\r
174KbcDisableKb (\r
175 IN EFI_ISA_IO_PROTOCOL *IsaIo\r
ed66e1bc 176 );\r
afd0fe22 177\r
bcd70414 178/**\r
179 Issue command to check keyboard status.\r
0a6f4824 180\r
bcd70414 181 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
182 @param KeyboardEnable return whether keyboard is enable.\r
0a6f4824 183\r
bcd70414 184 @return Status of command issuing.\r
185**/\r
afd0fe22 186EFI_STATUS\r
187CheckKbStatus (\r
188 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
189 OUT BOOLEAN *KeyboardEnable\r
ed66e1bc 190 );\r
afd0fe22 191\r
bcd70414 192/**\r
193 Issue command to reset keyboard.\r
0a6f4824 194\r
bcd70414 195 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
0a6f4824 196\r
bcd70414 197 @return Status of command issuing.\r
198**/\r
afd0fe22 199EFI_STATUS\r
200PS2MouseReset (\r
201 IN EFI_ISA_IO_PROTOCOL *IsaIo\r
ed66e1bc 202 );\r
afd0fe22 203\r
bcd70414 204/**\r
205 Issue command to set mouse's sample rate\r
0a6f4824 206\r
bcd70414 207 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
0a6f4824
LG
208 @param SampleRate value of sample rate\r
209\r
bcd70414 210 @return Status of command issuing.\r
211**/\r
afd0fe22 212EFI_STATUS\r
213PS2MouseSetSampleRate (\r
214 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
215 IN MOUSE_SR SampleRate\r
ed66e1bc 216 );\r
afd0fe22 217\r
bcd70414 218/**\r
219 Issue command to set mouse's resolution.\r
0a6f4824 220\r
bcd70414 221 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
222 @param Resolution value of resolution\r
0a6f4824 223\r
bcd70414 224 @return Status of command issuing.\r
225**/\r
afd0fe22 226EFI_STATUS\r
227PS2MouseSetResolution (\r
228 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
229 IN MOUSE_RE Resolution\r
ed66e1bc 230 );\r
afd0fe22 231\r
bcd70414 232/**\r
233 Issue command to set mouse's scaling.\r
0a6f4824 234\r
bcd70414 235 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
236 @param Scaling value of scaling\r
0a6f4824 237\r
bcd70414 238 @return Status of command issuing.\r
239**/\r
afd0fe22 240EFI_STATUS\r
241PS2MouseSetScaling (\r
242 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
243 IN MOUSE_SF Scaling\r
ed66e1bc 244 );\r
afd0fe22 245\r
bcd70414 246/**\r
247 Issue command to enable Ps2 mouse.\r
0a6f4824 248\r
bcd70414 249 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
0a6f4824 250\r
bcd70414 251 @return Status of command issuing.\r
252**/\r
afd0fe22 253EFI_STATUS\r
254PS2MouseEnable (\r
255 IN EFI_ISA_IO_PROTOCOL *IsaIo\r
ed66e1bc 256 );\r
afd0fe22 257\r
bcd70414 258/**\r
259 Get mouse packet . Only care first 3 bytes\r
afd0fe22 260\r
18a73eb7 261 @param MouseAbsolutePointerDev Pointer to PS2 Absolute Pointer Simulation Device Private Data Structure\r
afd0fe22 262\r
bcd70414 263 @retval EFI_NOT_READY Mouse Device not ready to input data packet, or some error happened during getting the packet\r
264 @retval EFI_SUCCESS The data packet is gotten successfully.\r
afd0fe22 265\r
bcd70414 266**/\r
afd0fe22 267EFI_STATUS\r
268PS2MouseGetPacket (\r
269 PS2_MOUSE_ABSOLUTE_POINTER_DEV *MouseAbsolutePointerDev\r
ed66e1bc 270 );\r
afd0fe22 271\r
bcd70414 272/**\r
273 Read data via IsaIo protocol with given number.\r
0a6f4824 274\r
bcd70414 275 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
276 @param Buffer Buffer receive data of mouse\r
277 @param BufSize The size of buffer\r
278 @param State Check input or read data\r
0a6f4824 279\r
bcd70414 280 @return status of reading mouse data.\r
281**/\r
afd0fe22 282EFI_STATUS\r
283PS2MouseRead (\r
284 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
285 OUT VOID *Buffer,\r
286 IN OUT UINTN *BufSize,\r
287 IN UINTN State\r
288 );\r
289\r
290//\r
291// 8042 I/O function\r
292//\r
bcd70414 293/**\r
294 I/O work flow of outing 8042 command.\r
0a6f4824 295\r
bcd70414 296 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
297 @param Command I/O command.\r
0a6f4824 298\r
70d3fe9d 299 @retval EFI_SUCCESS Success to execute I/O work flow\r
bcd70414 300 @retval EFI_TIMEOUT Keyboard controller time out.\r
301**/\r
afd0fe22 302EFI_STATUS\r
303Out8042Command (\r
304 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
305 IN UINT8 Command\r
306 );\r
307\r
bcd70414 308/**\r
309 I/O work flow of in 8042 data.\r
0a6f4824 310\r
bcd70414 311 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
312 @param Data Data value\r
0a6f4824 313\r
70d3fe9d 314 @retval EFI_SUCCESS Success to execute I/O work flow\r
bcd70414 315 @retval EFI_TIMEOUT Keyboard controller time out.\r
316**/\r
afd0fe22 317EFI_STATUS\r
318In8042Data (\r
319 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
320 IN OUT UINT8 *Data\r
321 );\r
322\r
bcd70414 323/**\r
324 I/O work flow of outing 8042 data.\r
0a6f4824 325\r
bcd70414 326 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
327 @param Data Data value\r
0a6f4824 328\r
70d3fe9d 329 @retval EFI_SUCCESS Success to execute I/O work flow\r
bcd70414 330 @retval EFI_TIMEOUT Keyboard controller time out.\r
331**/\r
afd0fe22 332EFI_STATUS\r
333Out8042Data (\r
334 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
335 IN UINT8 Data\r
336 );\r
337\r
bcd70414 338/**\r
339 I/O work flow of outing 8042 Aux command.\r
0a6f4824 340\r
bcd70414 341 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
342 @param Command Aux I/O command\r
343 @param Resend Whether need resend the Aux command.\r
0a6f4824 344\r
70d3fe9d 345 @retval EFI_SUCCESS Success to execute I/O work flow\r
bcd70414 346 @retval EFI_TIMEOUT Keyboard controller time out.\r
347**/\r
afd0fe22 348EFI_STATUS\r
349Out8042AuxCommand (\r
350 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
351 IN UINT8 Command,\r
352 IN BOOLEAN Resend\r
353 );\r
354\r
bcd70414 355/**\r
356 I/O work flow of in 8042 Aux data.\r
0a6f4824 357\r
bcd70414 358 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
359 @param Data Buffer holding return value.\r
0a6f4824 360\r
70d3fe9d 361 @retval EFI_SUCCESS Success to execute I/O work flow\r
bcd70414 362 @retval EFI_TIMEOUT Keyboard controller time out.\r
363**/\r
afd0fe22 364EFI_STATUS\r
365In8042AuxData (\r
366 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
367 IN OUT UINT8 *Data\r
368 );\r
369\r
bcd70414 370/**\r
371 I/O work flow of outing 8042 Aux data.\r
0a6f4824 372\r
bcd70414 373 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
18a73eb7 374 @param Data Buffer holding return value.\r
0a6f4824 375\r
70d3fe9d 376 @retval EFI_SUCCESS Success to execute I/O work flow\r
bcd70414 377 @retval EFI_TIMEOUT Keyboard controller time out.\r
378**/\r
afd0fe22 379EFI_STATUS\r
380Out8042AuxData (\r
381 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
382 IN UINT8 Data\r
383 );\r
384\r
bcd70414 385/**\r
18a73eb7 386 Check keyboard controller status, if it is output buffer full and for auxiliary device.\r
0a6f4824 387\r
bcd70414 388 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
0a6f4824 389\r
bcd70414 390 @retval EFI_SUCCESS Keyboard controller is ready\r
391 @retval EFI_NOT_READY Keyboard controller is not ready\r
392**/\r
afd0fe22 393EFI_STATUS\r
394CheckForInput (\r
395 IN EFI_ISA_IO_PROTOCOL *IsaIo\r
396 );\r
397\r
bcd70414 398/**\r
399 I/O work flow to wait input buffer empty in given time.\r
0a6f4824 400\r
bcd70414 401 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
402 @param Timeout Wating time.\r
0a6f4824 403\r
bcd70414 404 @retval EFI_TIMEOUT if input is still not empty in given time.\r
405 @retval EFI_SUCCESS input is empty.\r
406**/\r
afd0fe22 407EFI_STATUS\r
408WaitInputEmpty (\r
409 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
410 IN UINTN Timeout\r
411 );\r
412\r
bcd70414 413/**\r
414 I/O work flow to wait output buffer full in given time.\r
0a6f4824 415\r
bcd70414 416 @param IsaIo Pointer to instance of EFI_ISA_IO_PROTOCOL\r
417 @param Timeout given time\r
0a6f4824 418\r
bcd70414 419 @retval EFI_TIMEOUT output is not full in given time\r
420 @retval EFI_SUCCESS output is full in given time.\r
421**/\r
afd0fe22 422EFI_STATUS\r
423WaitOutputFull (\r
424 IN EFI_ISA_IO_PROTOCOL *IsaIo,\r
425 IN UINTN Timeout\r
426 );\r
427\r
cab302fd 428#endif\r
429\r