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