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