6d155e200e9c990605332c3796f2733b0c21dc4a
[reactos.git] / reactos / drivers / input / i8042prt / i8042prt.h
1 #ifndef _I8042DRV_H
2 #define _I8042DRV_H
3 #include <ddk/ntddk.h>
4 #include <ddk/ntddkbd.h>
5 #include <ddk/ntdd8042.h>
6
7 #define KEYBOARD_IRQ 1
8 #define MOUSE_IRQ 12
9 #define KBD_BUFFER_SIZE 32
10
11 // should be in ntdd8042.h
12
13 typedef VOID DDKAPI
14 (*KEYBOARD_CLASS_SERVICE_CALLBACK) (
15 IN PDEVICE_OBJECT DeviceObject,
16 IN PKEYBOARD_INPUT_DATA InputDataStart,
17 IN PKEYBOARD_INPUT_DATA InputDataEnd,
18 IN OUT PULONG InputDataConsumed
19 );
20
21 /* I'm not actually sure if this is in the ddk, would seem logical */
22 typedef VOID DDKAPI
23 (*MOUSE_CLASS_SERVICE_CALLBACK) (
24 IN PDEVICE_OBJECT DeviceObject,
25 IN PMOUSE_INPUT_DATA InputDataStart,
26 IN PMOUSE_INPUT_DATA InputDataEnd,
27 IN OUT PULONG InputDataConsumed
28 );
29
30 typedef struct _CONNECT_DATA {
31 PDEVICE_OBJECT ClassDeviceObject;
32 PVOID ClassService;
33 } CONNECT_DATA, *PCONNECT_DATA;
34
35 #define IOCTL_INTERNAL_KEYBOARD_CONNECT \
36 CTL_CODE(FILE_DEVICE_KEYBOARD, 0x0080, METHOD_NEITHER, FILE_ANY_ACCESS)
37
38 #define IOCTL_INTERNAL_MOUSE_CONNECT \
39 CTL_CODE(FILE_DEVICE_MOUSE, 0x0080, METHOD_NEITHER, FILE_ANY_ACCESS)
40
41 /* For some bizarre reason, these are different from the defines in
42 * w32api. I'm quite sure these are correct though, needs to be checked
43 * against the ddk
44 */
45 #define KEYBOARD_SCROLL_LOCK_ON 0x01
46 #define KEYBOARD_NUM_LOCK_ON 0x02
47 #define KEYBOARD_CAPS_LOCK_ON 0x04
48
49 /*-----------------------------------------------------
50 * DeviceExtension
51 * --------------------------------------------------*/
52 typedef struct _COMMAND_CONTEXT
53 {
54 int NumInput;
55 int CurInput;
56 UCHAR * Input;
57 int NumOutput;
58 int CurOutput;
59 UCHAR * Output;
60 NTSTATUS Status;
61
62 BOOLEAN GotAck;
63 KEVENT Event;
64
65 PVOID DevExt;
66 } COMMAND_CONTEXT, *PCOMMAND_CONTEXT;
67
68 typedef enum _MOUSE_TIMEOUT_STATE
69 {
70 NoChange,
71 TimeoutStart,
72 TimeoutCancel
73 } MOUSE_TIMEOUT_STATE, *PMOUSE_TIMEOUT_STATE;
74
75 /* TODO: part of this should be in the _ATTRIBUTES structs instead */
76 typedef struct _I8042_SETTINGS
77 {
78 DWORD Headless; /* done */
79 DWORD CrashScroll;
80 DWORD CrashSysRq; /* done */
81 DWORD ReportResetErrors;
82 DWORD PollStatusIterations; /* done */
83 DWORD ResendIterations; /* done */
84 DWORD PollingIterations;
85 DWORD PollingIterationsMaximum;
86 DWORD OverrideKeyboardType;
87 DWORD OverrideKeyboardSubtype;
88 DWORD MouseResendStallTime;
89 DWORD MouseSynchIn100ns;
90 DWORD MouseResolution;
91 DWORD NumberOfButtons;
92 DWORD EnableWheelDetection;
93 } I8042_SETTINGS, *PI8042_SETTINGS;
94
95 typedef enum _I8042_MOUSE_TYPE
96 {
97 GenericPS2,
98 Intellimouse,
99 IntellimouseExplorer,
100 Ps2pp
101 } I8042_MOUSE_TYPE, *PI8042_MOUSE_TYPE;
102
103 typedef enum _I8042_DEVICE_TYPE
104 {
105 Keyboard,
106 Mouse
107 } I8042_DEVICE_TYPE, *PI8042_DEVICE_TYPE;
108
109 typedef struct _I8042_DEVICE
110 {
111 LIST_ENTRY ListEntry;
112 PDEVICE_OBJECT Pdo;
113 } I8042_DEVICE, *PI8042_DEVICE;
114
115 typedef struct _DEVICE_EXTENSION
116 {
117 PDEVICE_OBJECT KeyboardObject;
118 PDEVICE_OBJECT MouseObject;
119
120 CONNECT_DATA KeyboardData;
121 CONNECT_DATA MouseData;
122
123 BOOLEAN KeyboardExists;
124 BOOLEAN KeyboardIsAT;
125 BOOLEAN MouseExists;
126
127 BOOLEAN KeyboardClaimed;
128 BOOLEAN MouseClaimed;
129
130 ULONG BusNumber;
131 LIST_ENTRY BusDevices;
132
133 INTERNAL_I8042_START_INFORMATION KeyboardStartInformation;
134 INTERNAL_I8042_START_INFORMATION MouseStartInformation;
135
136 INTERNAL_I8042_HOOK_KEYBOARD KeyboardHook;
137 INTERNAL_I8042_HOOK_MOUSE MouseHook;
138
139 PKINTERRUPT KeyboardInterruptObject;
140 PKINTERRUPT MouseInterruptObject;
141 PKINTERRUPT HighestDIRQLInterrupt;
142 KSPIN_LOCK SpinLock;
143 KDPC DpcKbd;
144 KDPC DpcMouse;
145
146 KTIMER TimerMouseTimeout;
147 KDPC DpcMouseTimeout;
148 MOUSE_TIMEOUT_STATE MouseTimeoutState;
149 BOOLEAN MouseTimeoutActive;
150
151 KEYBOARD_ATTRIBUTES KeyboardAttributes;
152 KEYBOARD_INDICATOR_PARAMETERS KeyboardIndicators;
153 KEYBOARD_TYPEMATIC_PARAMETERS KeyboardTypematic;
154
155 BOOLEAN WantAck;
156 BOOLEAN WantOutput;
157 BOOLEAN SignalEvent;
158
159 KEYBOARD_SCAN_STATE KeyboardScanState;
160 BOOLEAN KeyComplete;
161 KEYBOARD_INPUT_DATA *KeyboardBuffer;
162 ULONG KeysInBuffer;
163
164 MOUSE_ATTRIBUTES MouseAttributes;
165
166 MOUSE_STATE MouseState;
167 BOOLEAN MouseComplete;
168 MOUSE_RESET_SUBSTATE MouseResetState;
169 MOUSE_INPUT_DATA *MouseBuffer;
170 ULONG MouseInBuffer;
171 USHORT MouseButtonState;
172
173 UCHAR MouseLogiBuffer[3];
174 UCHAR MouseLogitechID;
175 I8042_MOUSE_TYPE MouseType;
176
177 OUTPUT_PACKET Packet;
178 UINT PacketResends;
179 BOOLEAN PacketComplete;
180 NTSTATUS PacketResult;
181 UCHAR PacketBuffer[16];
182 UCHAR PacketPort;
183
184 PIRP CurrentIrp;
185 PDEVICE_OBJECT CurrentIrpDevice;
186
187 /* registry config values */
188 I8042_SETTINGS Settings;
189
190 /* Debugger stuff */
191 BOOLEAN TabPressed;
192 ULONG DebugKey;
193 PIO_WORKITEM DebugWorkItem;
194 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
195
196 typedef struct _FDO_DEVICE_EXTENSION
197 {
198 PDEVICE_EXTENSION PortDevExt;
199 I8042_DEVICE_TYPE Type;
200 PDEVICE_OBJECT DeviceObject;
201
202 LIST_ENTRY BusDevices;
203 } FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
204
205 typedef struct _I8042_HOOK_WORKITEM
206 {
207 PIO_WORKITEM WorkItem;
208 PDEVICE_OBJECT Target;
209 PIRP Irp;
210 } I8042_HOOK_WORKITEM, *PI8042_HOOK_WORKITEM;
211
212 /*
213 * Some defines
214 */
215 #define TAG_I8042 TAG('8', '0', '4', '2')
216
217 #define KBD_WRAP_MASK 0x1F
218
219 #define disable() __asm__("cli\n\t")
220 #define enable() __asm__("sti\n\t")
221
222 #define ALT_PRESSED (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)
223 #define CTRL_PRESSED (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)
224
225
226 /*
227 * Keyboard controller ports
228 */
229
230 #define I8042_DATA_PORT 0x60
231 #define I8042_CTRL_PORT 0x64
232
233
234 /*
235 * Controller commands
236 */
237
238 #define KBD_READ_MODE 0x20
239 #define KBD_WRITE_MODE 0x60
240 #define KBD_SELF_TEST 0xAA
241 #define KBD_LINE_TEST 0xAB
242 #define KBD_CTRL_ENABLE 0xAE
243
244 #define MOUSE_LINE_TEST 0xA9
245 #define MOUSE_CTRL_ENABLE 0xA8
246
247 #define KBD_READ_OUTPUT_PORT 0xD0
248 #define KBD_WRITE_OUTPUT_PORT 0xD1
249
250 /*
251 * Keyboard commands
252 */
253
254 #define KBD_SET_LEDS 0xED
255 #define KBD_GET_ID 0xF2
256 #define KBD_ENABLE 0xF4
257 #define KBD_DISABLE 0xF5
258 #define KBD_RESET 0xFF
259
260
261 /*
262 * Keyboard responces
263 */
264
265 #define KBD_BATCC 0xAA
266 #define KBD_ACK 0xFA
267 #define KBD_NACK 0xFC
268 #define KBD_RESEND 0xFE
269
270 /*
271 * Controller status register bits
272 */
273
274 #define KBD_OBF 0x01
275 #define KBD_IBF 0x02
276 #define KBD_AUX 0x10
277 #define KBD_GTO 0x40
278 #define KBD_PERR 0x80
279
280
281 /*
282 * LED bits
283 */
284
285 #define KBD_LED_SCROLL 0x01
286 #define KBD_LED_NUM 0x02
287 #define KBD_LED_CAPS 0x04
288
289 /*
290 * Mouse responses
291 */
292 #define MOUSE_ACK 0xFA
293 #define MOUSE_ERROR 0xFC
294 #define MOUSE_NACK 0xFE
295
296 /* i8042prt.c */
297 NTSTATUS I8042ReadData(BYTE *Data);
298
299 NTSTATUS I8042ReadStatus(BYTE *Status);
300
301 NTSTATUS I8042ReadDataWait(PDEVICE_EXTENSION DevExt, BYTE *Data);
302
303 VOID I8042Flush();
304
305 VOID STDCALL I8042IsrWritePort(PDEVICE_EXTENSION DevExt,
306 UCHAR Value,
307 UCHAR SelectCmd);
308
309 NTSTATUS STDCALL I8042SynchWritePort(PDEVICE_EXTENSION DevExt,
310 UCHAR Port,
311 UCHAR Value,
312 BOOLEAN WaitForAck);
313
314 NTSTATUS STDCALL I8042StartPacket(PDEVICE_EXTENSION DevExt,
315 PDEVICE_OBJECT Device,
316 PUCHAR Bytes,
317 ULONG ByteCount,
318 PIRP Irp);
319
320 BOOLEAN STDCALL I8042PacketIsr(PDEVICE_EXTENSION DevExt,
321 UCHAR Output);
322
323 VOID I8042PacketDpc(PDEVICE_EXTENSION DevExt);
324
325 VOID STDCALL I8042SendHookWorkItem(PDEVICE_OBJECT DeviceObject,
326 PVOID Context);
327
328 BOOLEAN I8042Write(PDEVICE_EXTENSION DevExt, int addr, BYTE data);
329
330 /* keyboard.c */
331 VOID STDCALL I8042IsrWritePortKbd(PVOID Context,
332 UCHAR Value);
333
334 NTSTATUS STDCALL I8042SynchWritePortKbd(PVOID Context,
335 UCHAR Value,
336 BOOLEAN WaitForAck);
337
338 BOOLEAN STDCALL I8042InterruptServiceKbd(struct _KINTERRUPT *Interrupt,
339 VOID * Context);
340
341 VOID STDCALL I8042DpcRoutineKbd(PKDPC Dpc,
342 PVOID DeferredContext,
343 PVOID SystemArgument1,
344 PVOID SystemArgument2);
345
346 BOOLEAN STDCALL I8042StartIoKbd(PDEVICE_OBJECT DeviceObject, PIRP Irp);
347
348 NTSTATUS STDCALL I8042InternalDeviceControlKbd(PDEVICE_OBJECT DeviceObject,
349 PIRP Irp);
350
351 BOOLEAN STDCALL I8042KeyboardEnable(PDEVICE_EXTENSION DevExt);
352
353 BOOLEAN STDCALL I8042KeyboardEnableInterrupt(PDEVICE_EXTENSION DevExt);
354
355 BOOLEAN STDCALL I8042DetectKeyboard(PDEVICE_EXTENSION DevExt);
356
357 /* registry.c */
358 VOID STDCALL I8042ReadRegistry(PDRIVER_OBJECT DriverObject,
359 PDEVICE_EXTENSION DevExt);
360
361 /* mouse.c */
362 VOID STDCALL I8042DpcRoutineMouse(PKDPC Dpc,
363 PVOID DeferredContext,
364 PVOID SystemArgument1,
365 PVOID SystemArgument2);
366
367 VOID STDCALL I8042DpcRoutineMouseTimeout(PKDPC Dpc,
368 PVOID DeferredContext,
369 PVOID SystemArgument1,
370 PVOID SystemArgument2);
371
372 BOOLEAN STDCALL I8042InterruptServiceMouse(struct _KINTERRUPT *Interrupt,
373 VOID *Context);
374
375 NTSTATUS STDCALL I8042InternalDeviceControlMouse(PDEVICE_OBJECT DeviceObject,
376 PIRP Irp);
377
378 VOID STDCALL I8042QueueMousePacket(PVOID Context);
379
380 VOID STDCALL I8042MouseHandleButtons(PDEVICE_EXTENSION DevExt,
381 USHORT Mask);
382
383 VOID STDCALL I8042MouseHandle(PDEVICE_EXTENSION DevExt,
384 BYTE Output);
385
386 BOOLEAN STDCALL I8042MouseEnable(PDEVICE_EXTENSION DevExt);
387 BOOLEAN STDCALL I8042MouseDisable(PDEVICE_EXTENSION DevExt);
388
389 /* ps2pp.c */
390 VOID I8042MouseHandlePs2pp(PDEVICE_EXTENSION DevExt, BYTE Input);
391
392 #endif // _KEYBOARD_H_