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