Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2489 lines
63 KiB

  1. /*
  2. Copyright (c) 1990-1998 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. i8042prt.h
  5. Abstract:
  6. These are the structures and defines that are used in the
  7. Intel i8042 port driver.
  8. Revision History:
  9. --*/
  10. #ifndef _I8042PRT_
  11. #define _I8042PRT_
  12. #include "ntddk.h"
  13. #include <ntddkbd.h>
  14. #include <ntddmou.h>
  15. #include <ntdd8042.h>
  16. #include "kbdmou.h"
  17. #include "wmilib.h"
  18. #include "i8042cfg.h"
  19. #include "i8042str.h"
  20. #define I8042_POOL_TAG (ULONG) '2408'
  21. #undef ExAllocatePool
  22. #define ExAllocatePool(type, size) \
  23. ExAllocatePoolWithTag (type, size, I8042_POOL_TAG)
  24. #if DBG
  25. #ifdef PAGED_CODE
  26. #undef PAGED_CODE
  27. #endif
  28. #define PAGED_CODE() \
  29. if (KeGetCurrentIrql() > APC_LEVEL) { \
  30. KdPrint(( "8042: Pageable code called at IRQL %d\n", KeGetCurrentIrql() )); \
  31. DbgBreakPoint(); \
  32. }
  33. #endif
  34. #define MOUSE_RECORD_ISR DBG
  35. #define I8042_VERBOSE DBG
  36. #define KEYBOARD_RECORD_INIT DBG
  37. #define DELAY_SYSBUTTON_COMPLETION 1
  38. //
  39. // Define the timer values.
  40. //
  41. #define I8042_ASYNC_NO_TIMEOUT -1
  42. #define I8042_ASYNC_TIMEOUT 3
  43. //
  44. // Define the default number of entries in the input data queue.
  45. //
  46. #define DATA_QUEUE_SIZE 100
  47. //
  48. // Define the default stall value.
  49. //
  50. #define I8042_STALL_DEFAULT 50
  51. //
  52. // Custom resource type used when pruning the fdo's resource lists
  53. //
  54. #define I8X_REMOVE_RESOURCE 0xef
  55. //
  56. // Length (including NULL) of the PnP string identifying the mouse
  57. //
  58. // New style mice will respond with MSHxxxx
  59. // Old style mice will respond with pnpxxxx
  60. //
  61. #define MOUSE_PNPID_LENGTH 8
  62. //
  63. // Number of times to poll the hardware (determined empiracally)
  64. //
  65. #define I8X_POLL_ITERATIONS_MAX (11200)
  66. //
  67. // Define the default "sync time" used to determine when the start
  68. // of a new mouse data packet is expected. The value is in units
  69. // of 100 nanoseconds.
  70. //
  71. #define MOUSE_SYNCH_PACKET_100NS 10000000UL // 1 second, in 100 ns units
  72. //
  73. // Time, in ms, for the mouse to respond to the query ID sequence
  74. //
  75. #define WHEEL_DETECTION_TIMEOUT 1500
  76. //
  77. // Default for how to initialize the mouse
  78. //
  79. #define I8X_INIT_POLLED_DEFAULT 0
  80. #define IOCTL_INTERNAL_MOUSE_RESET \
  81. CTL_CODE(FILE_DEVICE_MOUSE, 0x0FFF, METHOD_NEITHER, FILE_ANY_ACCESS)
  82. #define FAILED_RESET_STOP (0)
  83. #define FAILED_RESET_PROCEED (1)
  84. #define FAILED_RESET_PROCEED_ALWAYS (2)
  85. #define FAILED_RESET_DEFAULT FAILED_RESET_PROCEED
  86. #define STR_FAILED_RESET L"KeyboardFailedReset"
  87. //
  88. // Define booleans.
  89. //
  90. #define WAIT_FOR_ACKNOWLEDGE TRUE
  91. #define NO_WAIT_FOR_ACKNOWLEDGE FALSE
  92. #define AND_OPERATION TRUE
  93. #define OR_OPERATION FALSE
  94. #define ENABLE_OPERATION TRUE
  95. #define DISABLE_OPERATION FALSE
  96. //
  97. // Default keyboard scan code mode.
  98. //
  99. #define KEYBOARD_SCAN_CODE_SET 0x01
  100. //
  101. // Default number of function keys, number of LED indicators, and total
  102. // number of keys located on the known types of keyboard.
  103. //
  104. #define NUM_KNOWN_KEYBOARD_TYPES 8
  105. #define KEYBOARD_TYPE_DEFAULT 4
  106. #define KEYBOARD_INDICATORS_DEFAULT 0
  107. typedef struct _KEYBOARD_TYPE_INFORMATION {
  108. USHORT NumberOfFunctionKeys;
  109. USHORT NumberOfIndicators;
  110. USHORT NumberOfKeysTotal;
  111. } KEYBOARD_TYPE_INFORMATION, *PKEYBOARD_TYPE_INFORMATION;
  112. static const
  113. KEYBOARD_TYPE_INFORMATION KeyboardTypeInformation[NUM_KNOWN_KEYBOARD_TYPES] = {
  114. {10, 3, 84}, // PC/XT 83- 84-key keyboard (and compatibles)
  115. {12, 3, 102}, // Olivetti M24 102-key keyboard (and compatibles)
  116. {10, 3, 84}, // All AT type keyboards (84-86 keys)
  117. {12, 3, 101}, // Enhanced 101- or 102-key keyboards (and compatibles)
  118. {12, 3, 101}, // 5:
  119. {12, 3, 101}, // 6:
  120. { 0, 0, 0}, // 7: Japanese Keyboard
  121. { 0, 0, 0} // 8: Korean keyboard
  122. };
  123. typedef struct _KEYBOARD_OEM_INFORMATION {
  124. KEYBOARD_ID KeyboardId;
  125. KEYBOARD_TYPE_INFORMATION KeyboardTypeInformation;
  126. } KEYBOARD_OEM_INFORMATION, *PKEYBOARD_OEM_INFORMATION;
  127. //
  128. // Keyboard hardware OEM id. by MSKK
  129. //
  130. #define MSFT 0x0 // Microsoft
  131. #define AX 0x1 // AX consortium
  132. #define TOSHIBA 0x2 // TOSHIBA
  133. #define EPSON 0x4 // EPSON
  134. #define FJ 0x5 // Fujitsu
  135. #define IBMJ 0x7 // IBM Japan
  136. #define DECJ 0x8 // DEC Japan
  137. #define PANA 0xA // Panasonic
  138. #define NEC 0xD // NEC
  139. #define FE_SUBTYPE(SubType,OemId) ((SubType)|((OemId<<4)))
  140. #define IBM02_KEYBOARD(Id) (((Id).Type == 0x7) && ((Id).Subtype == FE_SUBTYPE(3,MSFT)))
  141. #define AX_KEYBOARD(Id) (((Id).Type == 0x7) && ((Id).Subtype == FE_SUBTYPE(1,MSFT)))
  142. #define OYAYUBI_KEYBOARD(Id) (((Id).Type == 0x7) && ((Id).Subtype == FE_SUBTYPE(2,FJ)))
  143. #define DEC_KANJI_KEYBOARD(Id) (((Id).Type == 0x7) && (((Id).Subtype == FE_SUBTYPE(1,DECJ)) || \
  144. ((Id).Subtype == FE_SUBTYPE(2,DECJ))))
  145. static const
  146. KEYBOARD_OEM_INFORMATION KeyboardFarEastOemInformation[] = {
  147. {{7, FE_SUBTYPE(1,MSFT)}, {12,3,101}}, // PC/AT 101 Enhanced Japanese Keyboard
  148. {{7, FE_SUBTYPE(1,MSFT)}, {12,4,105}}, // AX standard Japanese keyboard
  149. {{7, FE_SUBTYPE(2,MSFT)}, {12,3,106}}, // PC/AT 106 Japanese Keyboard
  150. {{7, FE_SUBTYPE(3,MSFT)}, {12,3,106}}, // IBM 5576-002 keyboard
  151. {{7, FE_SUBTYPE(1,MSFT)}, {12,4,105}}, // AX consortium compatible keyboard
  152. {{7, FE_SUBTYPE(2,FJ )}, {12,3,108}}, // Fujitsu OYAYUBI shift keyboard
  153. {{7, FE_SUBTYPE(1,DECJ)}, {17,3,111}}, // DEC LK411 (Ansi layout) keyboard
  154. {{7, FE_SUBTYPE(2,DECJ)}, {17,3,112}}, // DEC LK411 (JIS layout) keyboard
  155. {{8, FE_SUBTYPE(3,MSFT)}, {12,3,101}}, // PC/AT 101 Enhanced Korean Keyboard (A)
  156. {{8, FE_SUBTYPE(4,MSFT)}, {12,3,101}}, // PC/AT 101 Enhanced Korean Keyboard (B)
  157. {{8, FE_SUBTYPE(5,MSFT)}, {12,3,101}}, // PC/AT 101 Enhanced Korean Keyboard (C)
  158. {{8, FE_SUBTYPE(6,MSFT)}, {12,3,103}}, // PC/AT 103 Enhanced Korean Keyboard
  159. {{0, FE_SUBTYPE(0,MSFT)}, { 0,0, 0}} // Array terminator
  160. };
  161. //
  162. // Minimum, maximum, and default values for keyboard typematic rate and delay.
  163. //
  164. #define KEYBOARD_TYPEMATIC_RATE_MINIMUM 2
  165. #define KEYBOARD_TYPEMATIC_RATE_MAXIMUM 30
  166. #define KEYBOARD_TYPEMATIC_RATE_DEFAULT 30
  167. #define KEYBOARD_TYPEMATIC_DELAY_MINIMUM 250
  168. #define KEYBOARD_TYPEMATIC_DELAY_MAXIMUM 1000
  169. #define KEYBOARD_TYPEMATIC_DELAY_DEFAULT 250
  170. //
  171. // Define the 8042 mouse status bits.
  172. //
  173. #define LEFT_BUTTON 0x01
  174. #define RIGHT_BUTTON 0x02
  175. #define MIDDLE_BUTTON 0x04
  176. #define BUTTON_4 0x10
  177. #define BUTTON_5 0x20
  178. #define X_DATA_SIGN 0x10
  179. #define Y_DATA_SIGN 0x20
  180. #define X_OVERFLOW 0x40
  181. #define Y_OVERFLOW 0x80
  182. #define MOUSE_SIGN_OVERFLOW_MASK (X_DATA_SIGN | Y_DATA_SIGN | X_OVERFLOW | Y_OVERFLOW)
  183. //
  184. // Define the maximum positive and negative values for mouse motion.
  185. //
  186. #define MOUSE_MAXIMUM_POSITIVE_DELTA 0x000000FF
  187. #define MOUSE_MAXIMUM_NEGATIVE_DELTA 0xFFFFFF00
  188. //
  189. // Default number of buttons and sample rate for the i8042 mouse.
  190. //
  191. #define MOUSE_NUMBER_OF_BUTTONS 2
  192. #define MOUSE_SAMPLE_RATE 60
  193. //
  194. // Define the mouse resolution specifier. Note that (2**MOUSE_RESOLUTION)
  195. // specifies counts-per-millimeter. Counts-per-centimeter is
  196. // (counts-per-millimeter * 10).
  197. //
  198. #define MOUSE_RESOLUTION 3
  199. //
  200. // Define the maximum number of resets we allow without success before we
  201. // give up and consider the mouse dead
  202. //
  203. #define MOUSE_RESET_TIMEOUT (1500 * 1000 * 10)
  204. #define MOUSE_RESETS_MAX 3
  205. #define MOUSE_RESENDS_MAX 4
  206. #define MOUSE_RESET_RESENDS_MAX 10
  207. //
  208. // Defines and macros for Globals.ControllerData->HardwarePresent.
  209. //
  210. #define KEYBOARD_HARDWARE_PRESENT 0x001
  211. #define MOUSE_HARDWARE_PRESENT 0x002
  212. #define BALLPOINT_HARDWARE_PRESENT 0x004
  213. #define WHEELMOUSE_HARDWARE_PRESENT 0x008
  214. #define DUP_KEYBOARD_HARDWARE_PRESENT 0x010
  215. #define DUP_MOUSE_HARDWARE_PRESENT 0x020
  216. #define KEYBOARD_HARDWARE_INITIALIZED 0x100
  217. #define MOUSE_HARDWARE_INITIALIZED 0x200
  218. #define FIVE_BUTTON_HARDWARE_PRESENT 0x1000
  219. #define PHANTOM_KEYBOARD_HARDWARE_REPORTED 0x4000
  220. #define PHANTOM_MOUSE_HARDWARE_REPORTED 0x8000
  221. #define TEST_HARDWARE_PRESENT(bits) \
  222. ((Globals.ControllerData->HardwarePresent & (bits)) == (bits))
  223. #define CLEAR_HW_FLAGS(bits) (Globals.ControllerData->HardwarePresent &= ~(bits))
  224. #define SET_HW_FLAGS(bits) (Globals.ControllerData->HardwarePresent |= (bits))
  225. #define KEYBOARD_PRESENT() TEST_HARDWARE_PRESENT(KEYBOARD_HARDWARE_PRESENT)
  226. #define MOUSE_PRESENT() TEST_HARDWARE_PRESENT(MOUSE_HARDWARE_PRESENT)
  227. #define WHEEL_PRESENT() TEST_HARDWARE_PRESENT(WHEELMOUSE_HARDWARE_PRESENT)
  228. #define FIVE_PRESENT() TEST_HARDWARE_PRESENT(FIVE_BUTTON_HARDWARE_PRESENT)
  229. #define KEYBOARD_INITIALIZED() \
  230. TEST_HARDWARE_PRESENT(KEYBOARD_HARDWARE_INITIALIZED)
  231. #define MOUSE_INITIALIZED() \
  232. TEST_HARDWARE_PRESENT(MOUSE_HARDWARE_INITIALIZED)
  233. #define KEYBOARD_STARTED() (Globals.KeyboardExtension ? \
  234. Globals.KeyboardExtension->Started : \
  235. FALSE)
  236. #define MOUSE_STARTED() (Globals.MouseExtension ? \
  237. Globals.MouseExtension->Started : \
  238. FALSE)
  239. #define CLEAR_MOUSE_PRESENT() CLEAR_HW_FLAGS(MOUSE_HARDWARE_INITIALIZED | MOUSE_HARDWARE_PRESENT | WHEELMOUSE_HARDWARE_PRESENT)
  240. #define CLEAR_KEYBOARD_PRESENT() CLEAR_HW_FLAGS(KEYBOARD_HARDWARE_INITIALIZED | KEYBOARD_HARDWARE_PRESENT)
  241. #define KBD_POWERED_UP_STARTED 0x00000001
  242. #define KBD_POWERED_DOWN 0x00000002
  243. #define MOU_POWERED_UP_STARTED 0x00000010
  244. #define MOU_POWERED_DOWN 0x00000020
  245. #define KBD_POWERED_UP_SUCCESS 0x00000100
  246. #define KBD_POWERED_UP_FAILURE 0x00000200
  247. #define MOU_POWERED_UP_SUCCESS 0x00001000
  248. #define MOU_POWERED_UP_FAILURE 0x00002000
  249. #define WORK_ITEM_QUEUED 0x10000000
  250. #define MOU_POWER_FLAGS (MOU_POWERED_DOWN | \
  251. MOU_POWERED_UP_STARTED | \
  252. MOU_POWERED_UP_SUCCESS)
  253. #define KBD_POWER_FLAGS (KBD_POWERED_DOWN | \
  254. KBD_POWERED_UP_STARTED | \
  255. KBD_POWERED_UP_SUCCESS)
  256. #define SET_PWR_FLAGS(bits) (Globals.PowerFlags |= (bits))
  257. #define CMP_PWR_FLAGS(bits) ((Globals.PowerFlags & (bits)) == (bits))
  258. #define TEST_PWR_FLAGS(bits) (Globals.PowerFlags & (bits))
  259. #define KEYBOARD_POWERED_DOWN_SUCCESS() CMP_PWR_FLAGS(KBD_POWERED_DOWN)
  260. #define MOUSE_POWERED_DOWN_SUCCESS() CMP_PWR_FLAGS(MOU_POWERED_DOWN)
  261. #define KEYBOARD_POWERED_UP_SUCCESSFULLY() SET_PWR_FLAGS(KBD_POWERED_UP_SUCCESS)
  262. #define MOUSE_POWERED_UP_SUCCESSFULLY() SET_PWR_FLAGS(MOU_POWERED_UP_SUCCESS)
  263. #define KEYBOARD_POWERED_UP_FAILURE() SET_PWR_FLAGS(KBD_POWERED_UP_FAILURE)
  264. #define MOUSE_POWERED_UP_FAILURE() SET_PWR_FLAGS(MOU_POWERED_UP_FAILURE)
  265. #define KEYBOARD_POWERED_UP_FAILED() CMP_PWR_FLAGS(KBD_POWERED_UP_FAILURE)
  266. #define MOUSE_POWERED_UP_FAILED() CMP_PWR_FLAGS(MOU_POWERED_UP_FAILURE)
  267. #define KEYBOARD_POWERED_UP_SUCCESS() CMP_PWR_FLAGS(KBD_POWERED_UP_SUCCESS)
  268. #define MOUSE_POWERED_UP_SUCCESS() CMP_PWR_FLAGS(MOU_POWERED_UP_SUCCESS)
  269. #define A_POWERED_UP_SUCCEEDED() \
  270. TEST_PWR_FLAGS(KBD_POWERED_UP_SUCCESS | MOU_POWERED_UP_SUCCESS)
  271. #define IS_KEYBOARD(_devExt_) ((_devExt_)->IsKeyboard)
  272. #define IS_MOUSE(_devExt_) ((_devExt_)->IsKeyboard == FALSE)
  273. #define IS_LEVEL_TRIGGERED(_devExt_) ((_devExt_)->InterruptDescriptor.Flags == CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE)
  274. #define IS_EDGE_TRIGGERED(_devExt_) ((_devExt_)->InterruptDescriptor.Flags == CM_RESOURCE_INTERRUPT_LATCHED)
  275. #define DEVICE_START_SUCCESS(status) (NT_SUCCESS((status)) || ((status) == STATUS_DEVICE_NOT_CONNECTED))
  276. #define INIT_FIRST_TIME 0x00000001
  277. #define INIT_KEYBOARD 0x00010000
  278. #define INIT_MOUSE 0x00020000
  279. #if _X86_
  280. #define WRAP_IO_FUNCTIONS 0
  281. #else
  282. #define WRAP_IO_FUNCTIONS 1
  283. #endif
  284. typedef
  285. UCHAR
  286. (*PI8X_READ_UCHAR) (
  287. PUCHAR Address
  288. );
  289. typedef
  290. VOID
  291. (*PI8X_WRITE_UCHAR) (
  292. PUCHAR Address,
  293. UCHAR Byte
  294. );
  295. //
  296. // Define macros for performing I/O on the 8042 command/status and data
  297. // registers.
  298. //
  299. #define I8X_PUT_COMMAND_BYTE(Address, Byte) \
  300. Globals.I8xWriteXxxUchar(Address, (UCHAR) Byte)
  301. #define I8X_PUT_DATA_BYTE(Address, Byte) \
  302. Globals.I8xWriteXxxUchar(Address, (UCHAR) Byte)
  303. #define I8X_GET_STATUS_BYTE(Address) \
  304. Globals.I8xReadXxxUchar(Address)
  305. #define I8X_GET_DATA_BYTE(Address) \
  306. Globals.I8xReadXxxUchar(Address)
  307. #define I8X_WRITE_CMD_TO_MOUSE( ) \
  308. I8xPutByteAsynchronous( \
  309. (CCHAR) CommandPort, \
  310. (UCHAR) I8042_WRITE_TO_AUXILIARY_DEVICE \
  311. )
  312. #define I8X_MOUSE_COMMAND( Byte ) \
  313. I8xPutByteAsynchronous( \
  314. (CCHAR) DataPort, \
  315. (UCHAR) Byte \
  316. )
  317. //
  318. // Define commands to the 8042 controller.
  319. //
  320. #define I8042_READ_CONTROLLER_COMMAND_BYTE 0x20
  321. #define I8042_WRITE_CONTROLLER_COMMAND_BYTE 0x60
  322. #define I8042_DISABLE_MOUSE_DEVICE 0xA7
  323. #define I8042_ENABLE_MOUSE_DEVICE 0xA8
  324. #define I8042_AUXILIARY_DEVICE_TEST 0xA9
  325. #define I8042_KEYBOARD_DEVICE_TEST 0xAB
  326. #define I8042_DISABLE_KEYBOARD_DEVICE 0xAD
  327. #define I8042_ENABLE_KEYBOARD_DEVICE 0xAE
  328. #define I8042_WRITE_TO_AUXILIARY_DEVICE 0xD4
  329. //
  330. // Define the 8042 Controller Command Byte.
  331. //
  332. #define CCB_ENABLE_KEYBOARD_INTERRUPT 0x01
  333. #define CCB_ENABLE_MOUSE_INTERRUPT 0x02
  334. #define CCB_DISABLE_KEYBOARD_DEVICE 0x10
  335. #define CCB_DISABLE_MOUSE_DEVICE 0x20
  336. #define CCB_KEYBOARD_TRANSLATE_MODE 0x40
  337. //
  338. // Define the 8042 Controller Status Register bits.
  339. //
  340. #define OUTPUT_BUFFER_FULL 0x01
  341. #define INPUT_BUFFER_FULL 0x02
  342. #define MOUSE_OUTPUT_BUFFER_FULL 0x20
  343. //
  344. // Define the 8042 responses.
  345. //
  346. #define ACKNOWLEDGE 0xFA
  347. #define RESEND 0xFE
  348. #define FAILURE 0xFC
  349. //
  350. // Define commands to the keyboard (through the 8042 data port).
  351. //
  352. #define SET_KEYBOARD_INDICATORS 0xED
  353. #define SELECT_SCAN_CODE_SET 0xF0
  354. #define READ_KEYBOARD_ID 0xF2
  355. #define SET_KEYBOARD_TYPEMATIC 0xF3
  356. #define SET_ALL_TYPEMATIC_MAKE_BREAK 0xFA
  357. #define KEYBOARD_RESET 0xFF
  358. //
  359. // Define the keyboard responses.
  360. //
  361. #define KEYBOARD_COMPLETE_SUCCESS 0xAA
  362. #define KEYBOARD_COMPLETE_FAILURE 0xFC
  363. #define KEYBOARD_BREAK_CODE 0xF0
  364. #define KEYBOARD_DEBUG_HOTKEY_ENH 0x37 // SysReq scan code for Enhanced Keyboard
  365. #define KEYBOARD_DEBUG_HOTKEY_AT 0x54 // SysReq scan code for 84-key Keyboard
  366. //
  367. // Define keyboard power scan codes
  368. //
  369. #define KEYBOARD_POWER_CODE 0x5E
  370. #define KEYBOARD_SLEEP_CODE 0x5F
  371. #define KEYBOARD_WAKE_CODE 0x63
  372. /*
  373. Power event
  374. Set1: Make = E0, 5E Break = E0, DE
  375. Set2: Make = E0, 37 Break = E0, F0, 37
  376. Sleep event
  377. Set1: Make = E0, 5F Break = E0, DF
  378. Set2: Make = E0, 3F Break = E0, F0, 3F
  379. Wake event
  380. Set1: Make = E0, 63 Break = E0, E3
  381. Set2: Make = E0, 5E Break = E0, F0, 5E
  382. */
  383. //
  384. // Define commands to the mouse (through the 8042 data port).
  385. //
  386. #define SET_MOUSE_RESOLUTION 0xE8
  387. #define SET_MOUSE_SAMPLING_RATE 0xF3
  388. #define MOUSE_RESET 0xFF
  389. #define ENABLE_MOUSE_TRANSMISSION 0xF4
  390. #define SET_MOUSE_SCALING_1TO1 0xE6
  391. #define READ_MOUSE_STATUS 0xE9
  392. #define GET_DEVICE_ID 0xF2
  393. //
  394. // Define the mouse responses.
  395. //
  396. #define MOUSE_COMPLETE 0xAA
  397. #define MOUSE_ID_BYTE 0x00
  398. #define WHEELMOUSE_ID_BYTE 0x03
  399. #define FIVEBUTTON_ID_BYTE 0x04
  400. //
  401. // Define the i8042 controller input/output ports.
  402. //
  403. typedef enum _I8042_IO_PORT_TYPE {
  404. DataPort = 0,
  405. CommandPort,
  406. MaximumPortCount
  407. } I8042_IO_PORT_TYPE;
  408. //
  409. // Define the device types attached to the i8042 controller.
  410. //
  411. typedef enum _I8042_DEVICE_TYPE {
  412. ControllerDeviceType,
  413. KeyboardDeviceType,
  414. MouseDeviceType,
  415. UndefinedDeviceType
  416. } I8042_DEVICE_TYPE;
  417. //
  418. // Intel i8042 configuration information.
  419. //
  420. #ifdef FE_SB
  421. #define KBD_IDENTIFIER 0x10
  422. #endif
  423. typedef struct _I8042_CONFIGURATION_INFORMATION {
  424. //
  425. // Bus interface type.
  426. //
  427. INTERFACE_TYPE InterfaceType;
  428. //
  429. // Bus Number.
  430. //
  431. ULONG BusNumber;
  432. //
  433. // The port/register resources used by this device.
  434. //
  435. CM_PARTIAL_RESOURCE_DESCRIPTOR PortList[MaximumPortCount];
  436. ULONG PortListCount;
  437. //
  438. // The highest IRQL between the two potential interrupts
  439. //
  440. KIRQL InterruptSynchIrql;
  441. //
  442. // Number of retries allowed.
  443. //
  444. USHORT ResendIterations;
  445. //
  446. // Number of polling iterations allowed.
  447. //
  448. USHORT PollingIterations;
  449. //
  450. // Maximum number of polling iterations allowed.
  451. //
  452. USHORT PollingIterationsMaximum;
  453. //
  454. // Maximum number of times to check the Status register in
  455. // the ISR before deciding the interrupt is spurious.
  456. //
  457. USHORT PollStatusIterations;
  458. //
  459. // Microseconds to stall in KeStallExecutionProcessor calls.
  460. //
  461. USHORT StallMicroseconds;
  462. //
  463. // Tracking resolution on the mouse
  464. //
  465. // USHORT MouseResolution;
  466. //
  467. // Flag that indicates whether floating point context should be saved.
  468. //
  469. BOOLEAN FloatingSave;
  470. //
  471. // Flag indicating if the interrupts should be shared
  472. //
  473. BOOLEAN SharedInterrupts;
  474. #ifdef FE_SB
  475. //
  476. // Detected Device Identifier
  477. //
  478. WCHAR OverrideKeyboardIdentifier[KBD_IDENTIFIER];
  479. #endif
  480. } I8042_CONFIGURATION_INFORMATION, *PI8042_CONFIGURATION_INFORMATION;
  481. //
  482. // Define the common portion of the keyboard/mouse device extension.
  483. //
  484. typedef struct COMMON_DATA {
  485. //
  486. // Pointer back to the this extension's device object.
  487. //
  488. PDEVICE_OBJECT Self;
  489. PKINTERRUPT InterruptObject;
  490. //
  491. // The spin lock guarding the object's ISR
  492. //
  493. KSPIN_LOCK InterruptSpinLock;
  494. //
  495. // The top of the stack before this filter was added. AKA the location
  496. // to which all IRPS should be directed.
  497. //
  498. PDEVICE_OBJECT TopOfStack;
  499. //
  500. // "THE PDO" (ejected by root)
  501. //
  502. PDEVICE_OBJECT PDO;
  503. //
  504. // Remove tracking
  505. //
  506. IO_REMOVE_LOCK RemoveLock;
  507. //
  508. // The IRP sent to the device to power it to D0
  509. //
  510. PIRP OutstandingPowerIrp;
  511. //
  512. // Current power state that the device is in
  513. //
  514. DEVICE_POWER_STATE PowerState;
  515. //
  516. // Current power state that the system in in
  517. //
  518. SYSTEM_POWER_STATE SystemState;
  519. POWER_ACTION ShutdownType;
  520. //
  521. // Number of input data items currently in the InputData queue
  522. //
  523. ULONG InputCount;
  524. //
  525. // Reference count for number of keyboard enables.
  526. //
  527. LONG EnableCount;
  528. //
  529. // Timer used to retry the ISR DPC routine when the class
  530. // driver is unable to consume all the port driver's data.
  531. //
  532. KTIMER DataConsumptionTimer;
  533. //
  534. // DPC queue for completion of requests that fail by exceeding
  535. // the maximum number of retries.
  536. //
  537. KDPC RetriesExceededDpc;
  538. //
  539. // DPC queue for logging overrun and internal driver errors.
  540. //
  541. KDPC ErrorLogDpc;
  542. //
  543. // DPC queue for command timeouts.
  544. //
  545. KDPC TimeOutDpc;
  546. //
  547. // DPC queue for resetting the device
  548. //
  549. KDPC ResetDpc;
  550. //
  551. // Request sequence number (used for error logging).
  552. //
  553. ULONG SequenceNumber;
  554. //
  555. // Class connection data.
  556. //
  557. CONNECT_DATA ConnectData;
  558. //
  559. // WMI Information
  560. //
  561. WMILIB_CONTEXT WmiLibInfo;
  562. //
  563. // Current output buffer being written to the device
  564. //
  565. OUTPUT_PACKET CurrentOutput;
  566. //
  567. // Translated resource descriptor for the interrupt
  568. //
  569. CM_PARTIAL_RESOURCE_DESCRIPTOR InterruptDescriptor;
  570. PNP_DEVICE_STATE PnpDeviceState;
  571. //
  572. // Current resend count.
  573. //
  574. SHORT ResendCount;
  575. //
  576. // Indicates whether it is okay to log overflow errors.
  577. //
  578. BOOLEAN OkayToLogOverflow;
  579. BOOLEAN Initialized;
  580. BOOLEAN IsIsrActivated;
  581. BOOLEAN IsKeyboard;
  582. //
  583. // Has it been started?
  584. // Has the device been manually removed?
  585. //
  586. BOOLEAN Started;
  587. } *PCOMMON_DATA;
  588. #define GET_COMMON_DATA(ext) ((PCOMMON_DATA) ext)
  589. #define MANUALLY_REMOVED(ext) ((ext)->PnpDeviceState & PNP_DEVICE_REMOVED)
  590. //
  591. // Define the keyboard portion of the port device extension.
  592. //
  593. typedef struct _PORT_KEYBOARD_EXTENSION {
  594. //
  595. // Data in common with the mouse extension;
  596. //
  597. struct COMMON_DATA;
  598. //
  599. // bitfield which represents the power capabilities of the kb
  600. //
  601. UCHAR PowerCaps;
  602. //
  603. // A newly found power event which we need to inform the PO system of
  604. //
  605. UCHAR PowerEvent;
  606. UCHAR CurrentScanCode, LastScanCode;
  607. //
  608. // Irp to be completed when one the power buttons is pressed
  609. //
  610. PIRP SysButtonEventIrp;
  611. //
  612. // DPC to handle power button events (updating our caps and completing
  613. // previous IOCTL requests)
  614. //
  615. KDPC SysButtonEventDpc;
  616. //
  617. // Spin lock to guard the cancel routine and the IOCTL handler
  618. //
  619. KSPIN_LOCK SysButtonSpinLock;
  620. //
  621. // Symbolic name for the interface
  622. //
  623. UNICODE_STRING SysButtonInterfaceName;
  624. //
  625. // Keyboard attributes.
  626. //
  627. KEYBOARD_ATTRIBUTES KeyboardAttributes;
  628. //
  629. // Extended keyboard ID
  630. //
  631. KEYBOARD_ID_EX KeyboardIdentifierEx;
  632. //
  633. // Initial values of keyboard typematic rate and delay.
  634. //
  635. KEYBOARD_TYPEMATIC_PARAMETERS KeyRepeatCurrent;
  636. //
  637. // Current indicator (LED) setting.
  638. //
  639. KEYBOARD_INDICATOR_PARAMETERS KeyboardIndicators;
  640. //
  641. // Keyboard ISR DPC queue.
  642. //
  643. KDPC KeyboardIsrDpc;
  644. //
  645. // Keyboard ISR DPC recall queue.
  646. //
  647. KDPC KeyboardIsrDpcRetry;
  648. //
  649. // Used by the ISR and the ISR DPC (in I8xDpcVariableOperation calls)
  650. // to control processing by the ISR DPC.
  651. //
  652. LONG DpcInterlockKeyboard;
  653. //
  654. // Start of the port keyboard input data queue (really a circular buffer).
  655. //
  656. PKEYBOARD_INPUT_DATA InputData;
  657. //
  658. // Insertion pointer for keyboard InputData.
  659. //
  660. PKEYBOARD_INPUT_DATA DataIn;
  661. //
  662. // Removal pointer for keyboard InputData.
  663. //
  664. PKEYBOARD_INPUT_DATA DataOut;
  665. //
  666. // Points one input packet past the end of the InputData buffer.
  667. //
  668. PKEYBOARD_INPUT_DATA DataEnd;
  669. //
  670. // Current keyboard input packet.
  671. //
  672. KEYBOARD_INPUT_DATA CurrentInput;
  673. //
  674. // Current keyboard scan input state.
  675. //
  676. KEYBOARD_SCAN_STATE CurrentScanState;
  677. //
  678. // Routine to call after the mouse is reset
  679. //
  680. PI8042_KEYBOARD_INITIALIZATION_ROUTINE InitializationHookCallback;
  681. //
  682. // Routine to call when a byte is received via the interrupt
  683. //
  684. PI8042_KEYBOARD_ISR IsrHookCallback;
  685. //
  686. // Context variable for InitializationRoutine
  687. //
  688. PVOID HookContext;
  689. //
  690. // Crash by key combination.
  691. //
  692. // CrashFlags used to be Dump1Keys
  693. //
  694. LONG CrashFlags; // CrashDump call first press keys flag
  695. // 7 6 5 4 3 2 1 0 bit
  696. // | | | | | +--- Right Shift Key
  697. // | | | | +----- Right Ctrl Key
  698. // | | | +------- Right Alt Key
  699. // | | +----------- Left Shift Key
  700. // | +------------- Left Ctrl Key
  701. // +--------------- Left Alt Key
  702. //
  703. // CurrentCrashFlags used to be Dump2Key
  704. //
  705. LONG CurrentCrashFlags;
  706. //
  707. // Key to be pressed 2 times to cause the crash dump
  708. //
  709. UCHAR CrashScanCode;
  710. //
  711. // Alternate to CrashScanCode, used only for the print screen scan codes(s)
  712. //
  713. UCHAR CrashScanCode2;
  714. //
  715. // If FAILED_RESET_PROCEED, ignore the fact that the keyboard did not send
  716. // an ACK in response to the reset command and still look for the
  717. // success/failure code in the i8042 controller.
  718. //
  719. UCHAR FailedReset;
  720. } PORT_KEYBOARD_EXTENSION, *PPORT_KEYBOARD_EXTENSION;
  721. //
  722. // Define the structure used to enable the mouse
  723. //
  724. typedef struct _ENABLE_MOUSE {
  725. KDPC Dpc;
  726. KTIMER Timer;
  727. USHORT Count;
  728. BOOLEAN FirstTime;
  729. BOOLEAN Enabled;
  730. } ENABLE_MOUSE;
  731. typedef enum _INTERNAL_RESET_STATE {
  732. InternalContinueTimer = 0x0,
  733. InternalMouseReset,
  734. InternalPauseOneSec
  735. } INTERNAL_RESET_STATE;
  736. typedef enum _ISR_RESET_STATE {
  737. IsrResetNormal = 0x0,
  738. IsrResetStopResetting,
  739. IsrResetQueueReset,
  740. IsrResetPause
  741. } ISR_RESET_STATE;
  742. typedef enum _ISR_DPC_CAUSE {
  743. IsrDpcCauseKeyboardWriteComplete = 1,
  744. IsrDpcCauseMouseWriteComplete,
  745. IsrDpcCauseMouseResetComplete
  746. } ISR_DPC_CAUSE;
  747. typedef struct _RESET_MOUSE {
  748. KDPC Dpc;
  749. KTIMER Timer;
  750. ISR_RESET_STATE IsrResetState;
  751. } RESET_MOUSE;
  752. #define I8X_MOUSE_INIT_COUNTERS(mouExt) \
  753. { \
  754. (mouExt)->ResetCount = (mouExt)->FailedCompleteResetCount = -1; \
  755. (mouExt)->ResendCount = 0; \
  756. }
  757. //
  758. // Define the mouse portion of the port device extension.
  759. //
  760. typedef struct _PORT_MOUSE_EXTENSION {
  761. struct COMMON_DATA;
  762. //
  763. // Mouse attributes.
  764. //
  765. MOUSE_ATTRIBUTES MouseAttributes;
  766. //
  767. // Reset IRP used in StartIO
  768. //
  769. PIRP ResetIrp;
  770. //
  771. // Mouse ISR DPC queue.
  772. //
  773. KDPC MouseIsrDpc;
  774. //
  775. // Mouse ISR DPC recall queue.
  776. //
  777. KDPC MouseIsrDpcRetry;
  778. //
  779. // Mouse ISR reset queue.
  780. //
  781. KDPC MouseIsrResetDpc;
  782. //
  783. // These two structs represent different methods of initialization.
  784. //
  785. union {
  786. RESET_MOUSE ResetMouse;
  787. ENABLE_MOUSE EnableMouse;
  788. };
  789. //
  790. // Used by the ISR and the ISR DPC (in I8xDpcVariableOperation calls)
  791. // to control processing by the ISR DPC.
  792. //
  793. LONG DpcInterlockMouse;
  794. //
  795. // Start of the port mouse input data queue (really a circular buffer).
  796. //
  797. PMOUSE_INPUT_DATA InputData;
  798. //
  799. // Insertion pointer for mouse InputData.
  800. //
  801. PMOUSE_INPUT_DATA DataIn;
  802. //
  803. // Removal pointer for mouse InputData.
  804. //
  805. PMOUSE_INPUT_DATA DataOut;
  806. //
  807. // Points one input packet past the end of the InputData buffer.
  808. //
  809. PMOUSE_INPUT_DATA DataEnd;
  810. //
  811. // Current mouse input packet. (24 bytes)
  812. //
  813. MOUSE_INPUT_DATA CurrentInput;
  814. //
  815. // Current mouse input state.
  816. //
  817. MOUSE_STATE InputState;
  818. MOUSE_RESET_SUBSTATE InputResetSubState;
  819. MOUSE_RESET_SUBSTATE WorkerResetSubState;
  820. //
  821. // Count the number of times we have reset and failed
  822. //
  823. UCHAR ResetCount;
  824. //
  825. // Count the number of times we have reset and not gone through the entire
  826. // reset process
  827. //
  828. UCHAR FailedCompleteResetCount;
  829. //
  830. // Current mouse sign and overflow data.
  831. //
  832. UCHAR CurrentSignAndOverflow;
  833. //
  834. // Previous mouse sign and overflow data.
  835. //
  836. UCHAR PreviousSignAndOverflow;
  837. //
  838. // The tick count (since system boot) at which the mouse last interrupted.
  839. // Retrieved via KeQueryTickCount. Used to determine whether a byte of
  840. // the mouse data packet has been lost. Allows the driver to synch
  841. // up with the true mouse input state.
  842. //
  843. LARGE_INTEGER PreviousTick;
  844. //
  845. // Number of interval timer ticks to wait before deciding that the
  846. // next mouse interrupt is for the start of a new packet. Used to
  847. // synch up again if a byte of the mouse packet gets lost.
  848. //
  849. ULONG SynchTickCount;
  850. //
  851. // The amount of time that is valid between sending a set sampling sequence
  852. // (of 20, 40, and 60) and receiving the first pnp id packet from the mouse
  853. //
  854. // Expressed in terms of system ticks
  855. //
  856. ULONG WheelDetectionTimeout;
  857. //
  858. // Contains a multi sz list of pnp mouse IDs to check for a wheel mouse
  859. //
  860. UNICODE_STRING WheelDetectionIDs;
  861. //
  862. // Plug n Play ID received from the mouse during reset
  863. //
  864. WCHAR PnPID[MOUSE_PNPID_LENGTH];
  865. //
  866. // An upper filter callback hook to call when processing mouse bytes
  867. //
  868. PI8042_MOUSE_ISR IsrHookCallback;
  869. //
  870. // Context variable for IsrHookCallback
  871. //
  872. PVOID HookContext;
  873. PVOID NotificationEntry;
  874. //
  875. // List of sample rates to send to the mouse during a reset
  876. //
  877. PUCHAR SampleRates;
  878. ULONG MouseResetStallTime;
  879. //
  880. // Index into the SampleRates array
  881. //
  882. UCHAR SampleRatesIndex;
  883. //
  884. // Previous mouse button data.
  885. //
  886. UCHAR PreviousButtons;
  887. //
  888. // Statue to transition to after the last sample rate from SampleRates has
  889. // been sent to the mouse
  890. //
  891. USHORT PostSamplesState;
  892. //
  893. // Keep track of last byte of data received from mouse so we can detect
  894. // the two-byte string which indicates a potential reset
  895. //
  896. UCHAR LastByteReceived;
  897. //
  898. // Tracking resolution on the mouse
  899. //
  900. UCHAR Resolution;
  901. //
  902. // One of 3 states that determines whether we should try and detect the wheel
  903. // on the mouse or not
  904. //
  905. UCHAR EnableWheelDetection;
  906. //
  907. // Skip button detection if it overridden in the registry.
  908. //
  909. UCHAR NumberOfButtonsOverride;
  910. //
  911. // If 0, then initalize the mouse via the interrupt, if non zero, initialize
  912. // the mouse via polling
  913. //
  914. UCHAR InitializePolled;
  915. #if MOUSE_RECORD_ISR
  916. ULONG RecordHistoryFlags;
  917. ULONG RecordHistoryCount;
  918. ULONG RecordHistoryState;
  919. #endif
  920. } PORT_MOUSE_EXTENSION, *PPORT_MOUSE_EXTENSION;
  921. //
  922. // controller specific data used by both devices
  923. //
  924. typedef struct _CONTROLLER_DATA {
  925. //
  926. // Indicate which hardware is actually present (keyboard and/or mouse).
  927. //
  928. ULONG HardwarePresent;
  929. //
  930. // IOCTL synchronization object
  931. //
  932. PCONTROLLER_OBJECT ControllerObject;
  933. //
  934. // Port configuration information.
  935. //
  936. I8042_CONFIGURATION_INFORMATION Configuration;
  937. //
  938. // Timer used to timeout i8042 commands.
  939. //
  940. KTIMER CommandTimer;
  941. //
  942. // Spin lock to guard freeing of bytes written to device
  943. //
  944. KSPIN_LOCK BytesSpinLock;
  945. //
  946. // Spin lock to guard powering the devices back up
  947. //
  948. KSPIN_LOCK PowerSpinLock;
  949. //
  950. // Default buffer to use for a write to a device if the request <=4 bytes
  951. // (avoid lots of tiny sized allocs)
  952. //
  953. UCHAR DefaultBuffer[4];
  954. //
  955. // Timer count used by the command time out routine.
  956. //
  957. LONG TimerCount;
  958. //
  959. // Interrupt to synchronize against
  960. //
  961. // IN PKINTERRUPT HigherInterrupt;
  962. //
  963. // The mapped addresses for this device's registers.
  964. //
  965. PUCHAR DeviceRegisters[MaximumPortCount];
  966. //
  967. // List of ports in IRP_MN_FILTER_RESOURCE_REQUIREMENTS
  968. //
  969. PHYSICAL_ADDRESS KnownPorts[MaximumPortCount];
  970. ULONG KnownPortsCount;
  971. #if DBG
  972. ULONG CurrentIoControlCode;
  973. #endif
  974. } CONTROLLER_DATA, *PCONTROLLER_DATA;
  975. #define POST_BUTTONDETECT_COMMAND (SET_MOUSE_RESOLUTION)
  976. #define POST_BUTTONDETECT_COMMAND_SUBSTATE (ExpectingSetResolutionDefaultACK)
  977. #define POST_WHEEL_DETECT_COMMAND (GET_DEVICE_ID)
  978. #define POST_WHEEL_DETECT_COMMAND_SUBSTATE (ExpectingGetDeviceId2ACK)
  979. #define ExpectingPnpId (I8042ReservedMinimum+ 2)
  980. #define PostWheelDetectState (I8042ReservedMinimum+ 3)
  981. #define PostEnableWheelState (I8042ReservedMinimum+ 4)
  982. #define QueueingMouseReset (I8042ReservedMinimum+100)
  983. #define MouseResetFailed (I8042ReservedMinimum+101)
  984. #define ExpectingLegacyPnpIdByte2_Make (I8042ReservedMinimum+200)
  985. #define ExpectingLegacyPnpIdByte2_Break (I8042ReservedMinimum+201)
  986. #define ExpectingLegacyPnpIdByte3_Make (I8042ReservedMinimum+202)
  987. #define ExpectingLegacyPnpIdByte3_Break (I8042ReservedMinimum+203)
  988. #define ExpectingLegacyPnpIdByte4_Make (I8042ReservedMinimum+204)
  989. #define ExpectingLegacyPnpIdByte4_Break (I8042ReservedMinimum+205)
  990. #define ExpectingLegacyPnpIdByte5_Make (I8042ReservedMinimum+206)
  991. #define ExpectingLegacyPnpIdByte5_Break (I8042ReservedMinimum+207)
  992. #define ExpectingLegacyPnpIdByte6_Make (I8042ReservedMinimum+208)
  993. #define ExpectingLegacyPnpIdByte6_Break (I8042ReservedMinimum+209)
  994. #define ExpectingLegacyPnpIdByte7_Make (I8042ReservedMinimum+210)
  995. #define ExpectingLegacyPnpIdByte7_Break (I8042ReservedMinimum+211)
  996. #define QueueingMousePolledReset (I8042ReservedMinimum+300)
  997. #define KeepOldSubState (I8042ReservedMinimum+400)
  998. typedef struct _GLOBALS {
  999. #if I8042_VERBOSE
  1000. //
  1001. // Flags: Bit field for enabling debugging print statements
  1002. // Level: Legacy way of controllign debugging statements
  1003. //
  1004. ULONG DebugFlags;
  1005. ULONG IsrDebugFlags;
  1006. #endif
  1007. //
  1008. // Pointer to controller specific data that both extensions may access it
  1009. //
  1010. PCONTROLLER_DATA ControllerData;
  1011. //
  1012. // The two possible extensions that can be created
  1013. //
  1014. PPORT_MOUSE_EXTENSION MouseExtension;
  1015. PPORT_KEYBOARD_EXTENSION KeyboardExtension;
  1016. //
  1017. // Generic read and write functions. Since we can use both memory and port
  1018. // type resources, we must use a function pointer to abstract access to them.
  1019. //
  1020. PI8X_READ_UCHAR I8xReadXxxUchar;
  1021. PI8X_WRITE_UCHAR I8xWriteXxxUchar;
  1022. //
  1023. // Path to the driver's entry in the registry
  1024. //
  1025. UNICODE_STRING RegistryPath;
  1026. //
  1027. // Keep track of the number of AddDevice and StartDevice calls. Want to
  1028. // postpone h/w initialization until the last StartDevice is received
  1029. // (due to some h/w which freezes if initialized more than once)
  1030. //
  1031. LONG AddedKeyboards;
  1032. LONG AddedMice;
  1033. LONG StartedDevices;
  1034. ULONG PowerFlags;
  1035. //
  1036. // Provide mutual exclusion during dispatch functions
  1037. //
  1038. FAST_MUTEX DispatchMutex;
  1039. //
  1040. // Set during the first H/W intialization to indicate that the register
  1041. // addresses must be unmapped when the driver is unloaded. It is also used
  1042. // when calling I8X_PUT_COMMAND_BYTE, I8X_PUT_DATA_BYTE, I8X_GET_STATUS_BYTE,
  1043. // I8X_GET_DATA_BYTE.
  1044. //
  1045. BOOLEAN RegistersMapped;
  1046. BOOLEAN BreakOnSysRq;
  1047. BOOLEAN Headless;
  1048. BOOLEAN ReportResetErrors;
  1049. } GLOBALS;
  1050. extern GLOBALS Globals;
  1051. #define RECORD_INIT 0x00000001
  1052. #define RECORD_RESUME_FROM_POWER 0x00000002
  1053. #define RECORD_DPC_RESET 0x00000004
  1054. #define RECORD_DPC_RESET_POLLED 0x00000008
  1055. #define RECORD_HW_PROFILE_CHANGE 0x00000010
  1056. #if MOUSE_RECORD_ISR
  1057. typedef struct _MOUSE_STATE_RECORD {
  1058. USHORT InputResetSubState;
  1059. USHORT InputState;
  1060. UCHAR LastByte;
  1061. UCHAR Reserved;
  1062. UCHAR Byte;
  1063. UCHAR Command;
  1064. LARGE_INTEGER Time;
  1065. } MOUSE_STATE_RECORD, *PMOUSE_STATE_RECORD;
  1066. extern PMOUSE_STATE_RECORD IsrStateHistory;
  1067. extern PMOUSE_STATE_RECORD CurrentIsrState;
  1068. extern PMOUSE_STATE_RECORD IsrStateHistoryEnd;
  1069. extern ULONG IsrStateCount;
  1070. #define RECORD_ISR_STATE(devExt, byte, lastbyte, time) \
  1071. if ((devExt->RecordHistoryFlags & devExt->RecordHistoryState)) { \
  1072. if (CurrentIsrState >= IsrStateHistoryEnd) { \
  1073. CurrentIsrState = IsrStateHistory; \
  1074. RtlFillMemory(CurrentIsrState, sizeof(MOUSE_STATE_RECORD), 0x88); \
  1075. CurrentIsrState++; \
  1076. } \
  1077. CurrentIsrState->InputState = (USHORT) devExt->InputState; \
  1078. CurrentIsrState->InputResetSubState = (USHORT) devExt->InputResetSubState; \
  1079. CurrentIsrState->Byte = byte; \
  1080. CurrentIsrState->LastByte = lastbyte; \
  1081. CurrentIsrState->Time = time; \
  1082. CurrentIsrState++; \
  1083. }
  1084. #define RECORD_ISR_STATE_COMMAND(devExt, command) \
  1085. if ((devExt->RecordHistoryFlags & devExt->RecordHistoryState)) \
  1086. CurrentIsrState->Command = command;
  1087. #define RECORD_ISR_STATE_TRANSITION(devExt, state) \
  1088. if ((devExt->RecordHistoryFlags & devExt->RecordHistoryState)) { \
  1089. if (CurrentIsrState >= IsrStateHistoryEnd) CurrentIsrState = IsrStateHistory; \
  1090. RtlFillMemory(CurrentIsrState, sizeof(MOUSE_STATE_RECORD), 0xFF); \
  1091. CurrentIsrState->Time.LowPart = state; \
  1092. CurrentIsrState++; \
  1093. }
  1094. #define SET_RECORD_STATE(devExt, state) \
  1095. { \
  1096. if (IsrStateHistory) devExt->RecordHistoryState |= (state); \
  1097. RECORD_ISR_STATE_TRANSITION(devExt, state); \
  1098. }
  1099. #define CLEAR_RECORD_STATE(devExt) devExt->RecordHistoryState = 0x0;
  1100. #define SET_RECORD_FLAGS(devExt, flags) if (IsrStateHistory) devExt->RecordHistoryFlags |= (flags)
  1101. #define CLEAR_RECORD_FLAGS(devExt, flags) devExt->RecordHistoryFlags &= ~(flags)
  1102. #else
  1103. #define RECORD_ISR_STATE(devExt, byte, lastbyte, time)
  1104. #define RECORD_ISR_STATE_COMMAND(devExt, command)
  1105. #define SET_RECORD_STATE(devExt, state)
  1106. #define CLEAR_RECORD_STATE(devExt)
  1107. #define SET_RECORD_FLAGS(devExt, flags)
  1108. #define CLEAN_RECORD_FLAGS(devExt, flags)
  1109. #endif // MOUSE_RECORD_ISR
  1110. typedef struct _I8X_KEYBOARD_WORK_ITEM {
  1111. PIO_WORKITEM Item;
  1112. ULONG MakeCode;
  1113. PIRP Irp;
  1114. } I8X_KEYBOARD_WORK_ITEM, *PI8X_KEYBOARD_WORK_ITEM;
  1115. typedef struct _I8X_MOUSE_RESET_INFO {
  1116. PPORT_MOUSE_EXTENSION MouseExtension;
  1117. INTERNAL_RESET_STATE InternalResetState;
  1118. } I8X_MOUSE_RESET_INFO, * PI8X_MOUSE_RESET_INFO;
  1119. //
  1120. // Define the port TransmitControllerCommandByte context structure.
  1121. //
  1122. typedef struct _I8042_TRANSMIT_CCB_CONTEXT {
  1123. IN ULONG HardwareDisableEnableMask;
  1124. IN BOOLEAN AndOperation;
  1125. IN UCHAR ByteMask;
  1126. OUT NTSTATUS Status;
  1127. } I8042_TRANSMIT_CCB_CONTEXT, *PI8042_TRANSMIT_CCB_CONTEXT;
  1128. //
  1129. // Define the port InitializeDataQueue context structure.
  1130. //
  1131. typedef struct _I8042_INITIALIZE_DATA_CONTEXT {
  1132. IN PVOID DeviceExtension;
  1133. IN CCHAR DeviceType;
  1134. } I8042_INITIALIZE_DATA_CONTEXT, *PI8042_INITIALIZE_DATA_CONTEXT;
  1135. //
  1136. // Define the port Get/SetDataQueuePointer context structures.
  1137. //
  1138. typedef struct _GET_DATA_POINTER_CONTEXT {
  1139. IN PVOID DeviceExtension;
  1140. IN CCHAR DeviceType;
  1141. OUT PVOID DataIn;
  1142. OUT PVOID DataOut;
  1143. OUT ULONG InputCount;
  1144. } GET_DATA_POINTER_CONTEXT, *PGET_DATA_POINTER_CONTEXT;
  1145. typedef struct _SET_DATA_POINTER_CONTEXT {
  1146. IN PVOID DeviceExtension;
  1147. IN CCHAR DeviceType;
  1148. IN ULONG InputCount;
  1149. IN PVOID DataOut;
  1150. } SET_DATA_POINTER_CONTEXT, *PSET_DATA_POINTER_CONTEXT;
  1151. typedef struct _POWER_UP_WORK_ITEM {
  1152. WORK_QUEUE_ITEM Item;
  1153. PIRP MousePowerIrp;
  1154. PIRP KeyboardPowerIrp;
  1155. } POWER_UP_WORK_ITEM, *PPOWER_UP_WORK_ITEM;
  1156. //
  1157. // Define the port timer context structure.
  1158. //
  1159. typedef struct _TIMER_CONTEXT {
  1160. IN PDEVICE_OBJECT DeviceObject;
  1161. IN PLONG TimerCounter;
  1162. OUT LONG NewTimerCount;
  1163. } TIMER_CONTEXT, *PTIMER_CONTEXT;
  1164. //
  1165. // Define the device InitiateOutput context structure.
  1166. //
  1167. typedef struct INITIATE_OUTPUT_CONTEXT {
  1168. IN PDEVICE_OBJECT DeviceObject;
  1169. IN PUCHAR Bytes;
  1170. IN ULONG ByteCount;
  1171. } INITIATE_OUTPUT_CONTEXT, *PINITIATE_OUTPUT_CONTEXT;
  1172. //
  1173. // Statically allocate the (known) scancode-to-indicator-light mapping.
  1174. // This information is returned by the
  1175. // IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION device control request.
  1176. //
  1177. #define KEYBOARD_NUMBER_OF_INDICATORS 3
  1178. static const INDICATOR_LIST IndicatorList[KEYBOARD_NUMBER_OF_INDICATORS] = {
  1179. {0x3A, KEYBOARD_CAPS_LOCK_ON},
  1180. {0x45, KEYBOARD_NUM_LOCK_ON},
  1181. {0x46, KEYBOARD_SCROLL_LOCK_ON}};
  1182. //
  1183. // Define the context structure and operations for I8xDpcVariableOperation.
  1184. //
  1185. typedef enum _OPERATION_TYPE {
  1186. IncrementOperation,
  1187. DecrementOperation,
  1188. WriteOperation,
  1189. ReadOperation
  1190. } OPERATION_TYPE;
  1191. typedef struct _VARIABLE_OPERATION_CONTEXT {
  1192. IN PLONG VariableAddress;
  1193. IN OPERATION_TYPE Operation;
  1194. IN OUT PLONG NewValue;
  1195. } VARIABLE_OPERATION_CONTEXT, *PVARIABLE_OPERATION_CONTEXT;
  1196. //
  1197. // Define the actions to be taked on processing a system button
  1198. //
  1199. typedef enum _SYS_BUTTON_ACTION {
  1200. NoAction =0,
  1201. SendAction,
  1202. UpdateAction
  1203. } SYS_BUTTON_ACTION;
  1204. //
  1205. // Function prototypes.
  1206. //
  1207. // begin_i8042dep
  1208. NTSTATUS
  1209. DriverEntry(
  1210. IN PDRIVER_OBJECT DriverObject,
  1211. IN PUNICODE_STRING RegistryPath
  1212. );
  1213. BOOLEAN
  1214. I8xDetermineSharedInterrupts(
  1215. VOID
  1216. );
  1217. VOID
  1218. I8xDrainOutputBuffer(
  1219. IN PUCHAR DataAddress,
  1220. IN PUCHAR CommandAddress
  1221. );
  1222. VOID
  1223. I8xGetByteAsynchronous(
  1224. IN CCHAR DeviceType,
  1225. OUT PUCHAR Byte
  1226. );
  1227. NTSTATUS
  1228. I8xGetBytePolled(
  1229. IN CCHAR DeviceType,
  1230. OUT PUCHAR Byte
  1231. );
  1232. VOID
  1233. I8xGetDataQueuePointer(
  1234. IN PGET_DATA_POINTER_CONTEXT Context
  1235. );
  1236. VOID
  1237. I8xInitializeHardware(
  1238. NTSTATUS *KeyboardStatus,
  1239. NTSTATUS *MouseStatus,
  1240. ULONG InitFlags
  1241. );
  1242. NTSTATUS
  1243. I8xInitializeHardwareAtBoot(
  1244. NTSTATUS *KeyboardStatus,
  1245. NTSTATUS *MouseStatus
  1246. );
  1247. VOID
  1248. I8xLogError(
  1249. IN PDEVICE_OBJECT DeviceObject,
  1250. IN NTSTATUS ErrorCode,
  1251. IN ULONG UniqueErrorValue,
  1252. IN NTSTATUS FinalStatus,
  1253. IN PULONG DumpData,
  1254. IN ULONG DumpCount
  1255. );
  1256. VOID
  1257. I8xPutByteAsynchronous(
  1258. IN CCHAR PortType,
  1259. IN UCHAR Byte
  1260. );
  1261. NTSTATUS
  1262. I8xPutBytePolled(
  1263. IN CCHAR PortType,
  1264. IN BOOLEAN WaitForAcknowledge,
  1265. IN CCHAR AckDeviceType,
  1266. IN UCHAR Byte
  1267. );
  1268. VOID
  1269. I8xReinitializeHardware (
  1270. PPOWER_UP_WORK_ITEM Item
  1271. );
  1272. VOID
  1273. I8xServiceParameters(
  1274. IN PUNICODE_STRING RegistryPath
  1275. );
  1276. NTSTATUS
  1277. I8xGetControllerCommand(
  1278. IN ULONG HardwareDisableEnableMask,
  1279. OUT PUCHAR Byte
  1280. );
  1281. NTSTATUS
  1282. I8xPutControllerCommand(
  1283. IN UCHAR Byte
  1284. );
  1285. NTSTATUS
  1286. I8xToggleInterrupts(
  1287. BOOLEAN State
  1288. );
  1289. NTSTATUS
  1290. I8xPutControllerCommand(
  1291. IN UCHAR Byte
  1292. );
  1293. VOID
  1294. I8xTransmitControllerCommand(
  1295. IN PI8042_TRANSMIT_CCB_CONTEXT TransmitCCBContext
  1296. );
  1297. // end_i8042dep
  1298. // begin_i8042cmn
  1299. NTSTATUS
  1300. I8xClose (
  1301. IN PDEVICE_OBJECT DeviceObject,
  1302. IN PIRP Irp
  1303. );
  1304. VOID
  1305. I8042CompletionDpc(
  1306. IN PKDPC Dpc,
  1307. IN PDEVICE_OBJECT DeviceObject,
  1308. IN PIRP Irp,
  1309. IN ISR_DPC_CAUSE IsrDpcCause
  1310. );
  1311. IO_ALLOCATION_ACTION
  1312. I8xControllerRoutine (
  1313. IN PDEVICE_OBJECT DeviceObject,
  1314. IN PIRP Irp,
  1315. IN PVOID MapRegisterBase,
  1316. IN PVOID Context
  1317. );
  1318. NTSTATUS
  1319. I8xCreate (
  1320. IN PDEVICE_OBJECT DeviceObject,
  1321. IN PIRP Irp
  1322. );
  1323. VOID
  1324. I8xDecrementTimer(
  1325. IN PTIMER_CONTEXT Context
  1326. );
  1327. VOID
  1328. I8xDpcVariableOperation(
  1329. IN PVOID Context
  1330. );
  1331. VOID
  1332. I8042ErrorLogDpc(
  1333. IN PKDPC Dpc,
  1334. IN PDEVICE_OBJECT DeviceObject,
  1335. IN PIRP Irp,
  1336. IN PVOID Context
  1337. );
  1338. NTSTATUS
  1339. I8xFlush(
  1340. IN PDEVICE_OBJECT DeviceObject,
  1341. IN PIRP Irp
  1342. );
  1343. VOID
  1344. I8xInitializeDataQueue(
  1345. IN PI8042_INITIALIZE_DATA_CONTEXT InitializeDataContext
  1346. );
  1347. VOID
  1348. I8xInitiateOutputWrapper(
  1349. IN PINITIATE_OUTPUT_CONTEXT InitiateContext
  1350. );
  1351. VOID
  1352. I8xInitiateIo(
  1353. IN PDEVICE_OBJECT DeviceObject
  1354. );
  1355. NTSTATUS
  1356. I8xDeviceControl(
  1357. IN PDEVICE_OBJECT DeviceObject,
  1358. IN PIRP Irp
  1359. );
  1360. NTSTATUS
  1361. I8xInternalDeviceControl(
  1362. IN PDEVICE_OBJECT DeviceObject,
  1363. IN PIRP Irp
  1364. );
  1365. VOID
  1366. I8042RetriesExceededDpc(
  1367. IN PKDPC Dpc,
  1368. IN PDEVICE_OBJECT DeviceObject,
  1369. IN PIRP Irp,
  1370. IN PVOID Context
  1371. );
  1372. BOOLEAN
  1373. I8xSanityCheckResources(
  1374. VOID
  1375. );
  1376. NTSTATUS
  1377. I8xSendIoctl(
  1378. PDEVICE_OBJECT Target,
  1379. ULONG Ioctl,
  1380. PVOID InputBuffer,
  1381. ULONG InputBufferLength
  1382. );
  1383. VOID
  1384. I8xSetDataQueuePointer(
  1385. IN PSET_DATA_POINTER_CONTEXT Context
  1386. );
  1387. VOID
  1388. I8xStartIo(
  1389. IN PDEVICE_OBJECT DeviceObject,
  1390. IN PIRP Irp
  1391. );
  1392. VOID
  1393. I8xCompletePendedRequest(
  1394. PDEVICE_OBJECT DeviceObject,
  1395. PIRP Irp,
  1396. ULONG_PTR Information,
  1397. NTSTATUS Status
  1398. );
  1399. VOID
  1400. I8xFinishResetRequest(
  1401. PPORT_MOUSE_EXTENSION MouseExtension,
  1402. BOOLEAN Failed,
  1403. BOOLEAN RaiseIrql,
  1404. BOOLEAN CancelTimer
  1405. );
  1406. VOID
  1407. I8042TimeOutDpc(
  1408. IN PKDPC Dpc,
  1409. IN PDEVICE_OBJECT DeviceObject,
  1410. IN PVOID SystemContext1,
  1411. IN PVOID SystemContext2
  1412. );
  1413. // end_i8042cmn
  1414. // begin_kbddep
  1415. UCHAR
  1416. I8xConvertTypematicParameters(
  1417. IN USHORT Rate,
  1418. IN USHORT Delay
  1419. );
  1420. NTSTATUS
  1421. I8xInitializeKeyboard(
  1422. IN PPORT_KEYBOARD_EXTENSION KeyboardExtension
  1423. );
  1424. NTSTATUS
  1425. I8xKeyboardConfiguration(
  1426. IN PPORT_KEYBOARD_EXTENSION KeyboardExtension,
  1427. IN PCM_RESOURCE_LIST ResourceList
  1428. );
  1429. BOOLEAN
  1430. I8042KeyboardInterruptService(
  1431. IN PKINTERRUPT Interrupt,
  1432. IN PDEVICE_OBJECT DeviceObject
  1433. );
  1434. VOID
  1435. I8xKeyboardServiceParameters(
  1436. IN PUNICODE_STRING RegistryPath,
  1437. IN PPORT_KEYBOARD_EXTENSION KeyboardExtension
  1438. );
  1439. VOID
  1440. I8xQueueCurrentKeyboardInput(
  1441. IN PDEVICE_OBJECT DeviceObject
  1442. );
  1443. // end_kbddep
  1444. // begin_kbdcmn
  1445. VOID
  1446. I8042KeyboardIsrDpc(
  1447. IN PKDPC Dpc,
  1448. IN PDEVICE_OBJECT DeviceObject,
  1449. IN PIRP Irp,
  1450. IN PVOID Context
  1451. );
  1452. BOOLEAN
  1453. I8xWriteDataToKeyboardQueue(
  1454. IN PPORT_KEYBOARD_EXTENSION KeyboardExtension,
  1455. IN PKEYBOARD_INPUT_DATA InputData
  1456. );
  1457. // end_kbdcmn
  1458. // begin_kbdpnp
  1459. NTSTATUS
  1460. I8xKeyboardConnectInterrupt(
  1461. PPORT_KEYBOARD_EXTENSION KeyboardExtension
  1462. );
  1463. NTSTATUS
  1464. I8xKeyboardInitializeHardware(
  1465. PPORT_KEYBOARD_EXTENSION KeyboardExtension,
  1466. PPORT_MOUSE_EXTENSION MouseExtension
  1467. );
  1468. VOID
  1469. I8xKeyboardRemoveDevice(
  1470. PDEVICE_OBJECT DeviceObject
  1471. );
  1472. NTSTATUS
  1473. I8xKeyboardStartDevice(
  1474. IN OUT PPORT_KEYBOARD_EXTENSION KeyboardExtension,
  1475. IN PCM_RESOURCE_LIST ResourceList
  1476. );
  1477. // end_kbdpnp
  1478. // begin_moucmn
  1479. VOID
  1480. I8042MouseIsrDpc(
  1481. IN PKDPC Dpc,
  1482. IN PDEVICE_OBJECT DeviceObject,
  1483. IN PIRP Irp,
  1484. IN PVOID Context
  1485. );
  1486. BOOLEAN
  1487. I8xWriteDataToMouseQueue(
  1488. IN PPORT_MOUSE_EXTENSION MouseExtension,
  1489. IN PMOUSE_INPUT_DATA InputData
  1490. );
  1491. // end_moucmn
  1492. // begin_moudep
  1493. NTSTATUS
  1494. I8xMouseConfiguration(
  1495. IN PPORT_MOUSE_EXTENSION MouseExtension,
  1496. IN PCM_RESOURCE_LIST ResourceList
  1497. );
  1498. VOID
  1499. MouseCopyWheelIDs(
  1500. PUNICODE_STRING Destination,
  1501. PUNICODE_STRING Source
  1502. );
  1503. NTSTATUS
  1504. I8xMouseEnableTransmission(
  1505. IN PPORT_MOUSE_EXTENSION MouseExtension
  1506. );
  1507. NTSTATUS
  1508. I8xTransmitByteSequence(
  1509. PUCHAR Bytes,
  1510. ULONG* UniqueErrorValue,
  1511. ULONG* ErrorCode,
  1512. ULONG* DumpData,
  1513. ULONG* DumpCount
  1514. );
  1515. NTSTATUS
  1516. I8xGetBytePolledIterated(
  1517. IN CCHAR DeviceType,
  1518. OUT PUCHAR Byte,
  1519. ULONG Attempts
  1520. );
  1521. NTSTATUS
  1522. I8xFindWheelMouse(
  1523. IN PPORT_MOUSE_EXTENSION MouseExtension
  1524. );
  1525. NTSTATUS
  1526. I8xInitializeMouse(
  1527. IN PPORT_MOUSE_EXTENSION MouseExension
  1528. );
  1529. BOOLEAN
  1530. I8042MouseInterruptService(
  1531. IN PKINTERRUPT Interrupt,
  1532. IN PVOID Context
  1533. );
  1534. NTSTATUS
  1535. I8xQueryNumberOfMouseButtons(
  1536. OUT PUCHAR NumberOfMouseButtons
  1537. );
  1538. NTSTATUS
  1539. I8xResetMouse(
  1540. PPORT_MOUSE_EXTENSION MouseExtension
  1541. );
  1542. VOID
  1543. I8xResetMouseFailed(
  1544. PPORT_MOUSE_EXTENSION MouseExtension
  1545. );
  1546. VOID
  1547. I8xSendResetCommand (
  1548. PPORT_MOUSE_EXTENSION MouseExtension
  1549. );
  1550. VOID
  1551. I8xMouseServiceParameters(
  1552. IN PUNICODE_STRING RegistryPath,
  1553. IN PPORT_MOUSE_EXTENSION MouseExtension
  1554. );
  1555. VOID
  1556. I8xQueueCurrentMouseInput(
  1557. IN PDEVICE_OBJECT DeviceObject
  1558. );
  1559. BOOLEAN
  1560. I8xVerifyMousePnPID(
  1561. PPORT_MOUSE_EXTENSION MouseExtension,
  1562. PWSTR MouseID
  1563. );
  1564. // end_moudep
  1565. // begin_moupnp
  1566. NTSTATUS
  1567. I8xMouseConnectInterruptAndEnable(
  1568. PPORT_MOUSE_EXTENSION MouseExtension,
  1569. BOOLEAN Reset
  1570. );
  1571. NTSTATUS
  1572. I8xMouseInitializeHardware(
  1573. PPORT_KEYBOARD_EXTENSION KeyboardExtension,
  1574. PPORT_MOUSE_EXTENSION MouseExtension
  1575. );
  1576. NTSTATUS
  1577. I8xProfileNotificationCallback(
  1578. IN PHWPROFILE_CHANGE_NOTIFICATION NotificationStructure,
  1579. PPORT_MOUSE_EXTENSION MouseExtension
  1580. );
  1581. VOID
  1582. I8xMouseRemoveDevice(
  1583. PDEVICE_OBJECT DeviceObject
  1584. );
  1585. NTSTATUS
  1586. I8xMouseStartDevice(
  1587. PPORT_MOUSE_EXTENSION MouseExtension,
  1588. IN PCM_RESOURCE_LIST ResourceList
  1589. );
  1590. BOOLEAN
  1591. I8xMouseEnableSynchRoutine(
  1592. IN PPORT_MOUSE_EXTENSION MouseExtension
  1593. );
  1594. VOID
  1595. I8xMouseEnableDpc(
  1596. IN PKDPC Dpc,
  1597. IN PPORT_MOUSE_EXTENSION MouseExtension,
  1598. IN PVOID SystemArg1,
  1599. IN PVOID SystemArg2
  1600. );
  1601. VOID
  1602. I8xIsrResetDpc(
  1603. IN PKDPC Dpc,
  1604. IN PPORT_MOUSE_EXTENSION MouseExtension,
  1605. IN ULONG ResetPolled,
  1606. IN PVOID SystemArg2
  1607. );
  1608. VOID
  1609. I8xMouseResetTimeoutProc(
  1610. IN PKDPC Dpc,
  1611. IN PPORT_MOUSE_EXTENSION MouseExtension,
  1612. IN PVOID SystemArg1,
  1613. IN PVOID SystemArg2
  1614. );
  1615. BOOLEAN
  1616. I8xMouseResetSynchRoutine(
  1617. PI8X_MOUSE_RESET_INFO ResetInfo
  1618. );
  1619. VOID
  1620. I8xMouseInitializeInterruptWorker(
  1621. IN PDEVICE_OBJECT DeviceObject,
  1622. IN PIO_WORKITEM Item
  1623. );
  1624. VOID
  1625. I8xMouseInitializePolledWorker(
  1626. IN PDEVICE_OBJECT DeviceObject,
  1627. IN PIO_WORKITEM Item
  1628. );
  1629. // end_moupnp
  1630. // begin_pnp
  1631. NTSTATUS
  1632. I8xAddDevice (
  1633. IN PDRIVER_OBJECT Driver,
  1634. IN PDEVICE_OBJECT PDO
  1635. );
  1636. NTSTATUS
  1637. I8xFilterResourceRequirements(
  1638. IN PDEVICE_OBJECT DeviceObject,
  1639. IN PIRP Irp
  1640. );
  1641. NTSTATUS
  1642. I8xFindPortCallout(
  1643. IN PVOID Context,
  1644. IN PUNICODE_STRING PathName,
  1645. IN INTERFACE_TYPE BusType,
  1646. IN ULONG BusNumber,
  1647. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  1648. IN CONFIGURATION_TYPE ControllerType,
  1649. IN ULONG ControllerNumber,
  1650. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  1651. IN CONFIGURATION_TYPE PeripheralType,
  1652. IN ULONG PeripheralNumber,
  1653. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  1654. );
  1655. LONG
  1656. I8xManuallyRemoveDevice(
  1657. PCOMMON_DATA CommonData
  1658. );
  1659. NTSTATUS
  1660. I8xPnP (
  1661. IN PDEVICE_OBJECT DeviceObject,
  1662. IN PIRP Irp
  1663. );
  1664. NTSTATUS
  1665. I8xPnPComplete (
  1666. IN PDEVICE_OBJECT DeviceObject,
  1667. IN PIRP Irp,
  1668. IN PKEVENT Event
  1669. );
  1670. NTSTATUS
  1671. I8xPower (
  1672. IN PDEVICE_OBJECT DeviceObject,
  1673. IN PIRP Irp
  1674. );
  1675. NTSTATUS
  1676. I8xPowerUpToD0Complete(
  1677. IN PDEVICE_OBJECT DeviceObject,
  1678. IN PIRP Irp,
  1679. IN PVOID Context
  1680. );
  1681. void
  1682. I8xSetPowerFlag(
  1683. IN ULONG Flag,
  1684. IN BOOLEAN Set
  1685. );
  1686. NTSTATUS
  1687. I8xRegisterDeviceInterface(
  1688. PDEVICE_OBJECT PDO,
  1689. CONST GUID *Guid,
  1690. PUNICODE_STRING SymbolicName
  1691. );
  1692. BOOLEAN
  1693. I8xRemovePort(
  1694. IN PIO_RESOURCE_DESCRIPTOR ResDesc
  1695. );
  1696. NTSTATUS
  1697. I8xSendIrpSynchronously (
  1698. IN PDEVICE_OBJECT DeviceObject,
  1699. IN PIRP Irp,
  1700. IN BOOLEAN Strict
  1701. );
  1702. VOID
  1703. I8xUnload(
  1704. IN PDRIVER_OBJECT DriverObject
  1705. );
  1706. // end_pnp
  1707. // begin_sysbtn
  1708. VOID
  1709. I8xCompleteSysButtonIrp(
  1710. PIRP Irp,
  1711. ULONG Event,
  1712. NTSTATUS Status
  1713. );
  1714. #if DELAY_SYSBUTTON_COMPLETION
  1715. VOID
  1716. I8xCompleteSysButtonEventWorker(
  1717. IN PDEVICE_OBJECT DeviceObject,
  1718. IN PI8X_KEYBOARD_WORK_ITEM Item
  1719. );
  1720. #endif
  1721. NTSTATUS
  1722. I8xKeyboardGetSysButtonCaps(
  1723. PPORT_KEYBOARD_EXTENSION KeyboardExtension,
  1724. PIRP Irp
  1725. );
  1726. NTSTATUS
  1727. I8xKeyboardGetSysButtonEvent(
  1728. PPORT_KEYBOARD_EXTENSION KeyboardExtension,
  1729. PIRP Irp
  1730. );
  1731. VOID
  1732. I8xKeyboardSysButtonEventDpc(
  1733. IN PKDPC Dpc,
  1734. IN PDEVICE_OBJECT DeviceObject,
  1735. IN SYS_BUTTON_ACTION Action,
  1736. IN ULONG ButtonEvent
  1737. );
  1738. VOID
  1739. I8xSysButtonCancelRoutine(
  1740. IN PDEVICE_OBJECT DeviceObject,
  1741. IN PIRP Irp
  1742. );
  1743. // end_sysbtn
  1744. // begin_hook
  1745. VOID
  1746. I8xMouseIsrWritePort(
  1747. IN PDEVICE_OBJECT DeviceObject,
  1748. IN UCHAR Value
  1749. );
  1750. VOID
  1751. I8xKeyboardIsrWritePort(
  1752. IN PDEVICE_OBJECT DeviceObject,
  1753. IN UCHAR Value
  1754. );
  1755. NTSTATUS
  1756. I8xKeyboardSynchReadPort (
  1757. IN PDEVICE_OBJECT DeviceObject,
  1758. IN PUCHAR Value,
  1759. IN BOOLEAN Dummy
  1760. );
  1761. NTSTATUS
  1762. I8xKeyboardSynchWritePort (
  1763. IN PDEVICE_OBJECT DeviceObject,
  1764. IN UCHAR Value,
  1765. IN BOOLEAN WaitForACK
  1766. );
  1767. // end_hook
  1768. // begin_wmi
  1769. NTSTATUS
  1770. I8xSystemControl (
  1771. IN PDEVICE_OBJECT DeviceObject,
  1772. IN PIRP Irp
  1773. );
  1774. NTSTATUS
  1775. I8xInitWmi(
  1776. PCOMMON_DATA CommonData
  1777. );
  1778. NTSTATUS
  1779. I8xSetWmiDataBlock(
  1780. IN PDEVICE_OBJECT DeviceObject,
  1781. IN PIRP Irp,
  1782. IN ULONG GuidIndex,
  1783. IN ULONG InstanceIndex,
  1784. IN ULONG BufferSize,
  1785. IN PUCHAR Buffer
  1786. );
  1787. NTSTATUS
  1788. I8xSetWmiDataItem(
  1789. IN PDEVICE_OBJECT DeviceObject,
  1790. IN PIRP Irp,
  1791. IN ULONG GuidIndex,
  1792. IN ULONG InstanceIndex,
  1793. IN ULONG DataItemId,
  1794. IN ULONG BufferSize,
  1795. IN PUCHAR Buffer
  1796. );
  1797. NTSTATUS
  1798. I8xKeyboardQueryWmiDataBlock(
  1799. IN PDEVICE_OBJECT DeviceObject,
  1800. IN PIRP Irp,
  1801. IN ULONG GuidIndex,
  1802. IN ULONG InstanceIndex,
  1803. IN ULONG InstanceCount,
  1804. IN OUT PULONG InstanceLengthArray,
  1805. IN ULONG BufferAvail,
  1806. OUT PUCHAR Buffer
  1807. );
  1808. NTSTATUS
  1809. I8xMouseQueryWmiDataBlock(
  1810. IN PDEVICE_OBJECT DeviceObject,
  1811. IN PIRP Irp,
  1812. IN ULONG GuidIndex,
  1813. IN ULONG InstanceIndex,
  1814. IN ULONG InstanceCount,
  1815. IN OUT PULONG InstanceLengthArray,
  1816. IN ULONG BufferAvail,
  1817. OUT PUCHAR Buffer
  1818. );
  1819. NTSTATUS
  1820. I8xQueryWmiRegInfo(
  1821. IN PDEVICE_OBJECT DeviceObject,
  1822. OUT PULONG RegFlags,
  1823. OUT PUNICODE_STRING InstanceName,
  1824. OUT PUNICODE_STRING *RegistryPath,
  1825. OUT PUNICODE_STRING MofResourceName,
  1826. OUT PDEVICE_OBJECT *Pdo
  1827. );
  1828. // end_wmi
  1829. //
  1830. // Flags to represent modifier key states
  1831. //
  1832. #define CRASH_R_SHIFT 0x01
  1833. #define CRASH_R_CTRL 0x02
  1834. #define CRASH_R_ALT 0x04
  1835. #define CRASH_L_SHIFT 0x10
  1836. #define CRASH_L_CTRL 0x20
  1837. #define CRASH_L_ALT 0x40
  1838. #define CRASH_FIRST_TIME 0x100
  1839. #define CRASH_SECOND_TIME 0x200
  1840. #define CRASH_BOTH_TIMES (CRASH_FIRST_TIME | CRASH_SECOND_TIME)
  1841. VOID
  1842. I8xProcessCrashDump(
  1843. PPORT_KEYBOARD_EXTENSION DeviceExtension,
  1844. UCHAR ScanCode,
  1845. KEYBOARD_SCAN_STATE ScanState
  1846. );
  1847. VOID
  1848. I8xServiceCrashDump(
  1849. IN PPORT_KEYBOARD_EXTENSION DeviceExtension,
  1850. IN PUNICODE_STRING RegistryPath
  1851. );
  1852. #if defined(_X86_)
  1853. #ifndef _FJKBD_H_
  1854. #define _FJKBD_H_
  1855. //
  1856. // oyayubi-shift keyboard internal input mode value.
  1857. //
  1858. #define THUMB_NOROMAN_ALPHA_CAPSON 0x01
  1859. #define THUMB_NOROMAN_ALPHA_CAPSOFF 0x02
  1860. #define THUMB_NOROMAN_HIRAGANA 0x03
  1861. #define THUMB_NOROMAN_KATAKANA 0x04
  1862. #define THUMB_ROMAN_ALPHA_CAPSON 0x05
  1863. #define THUMB_ROMAN_ALPHA_CAPSOFF 0x06
  1864. #define THUMB_ROMAN_HIRAGANA 0x07
  1865. #define THUMB_ROMAN_KATAKANA 0x08
  1866. //
  1867. // Following functions are oyayubi-shift keyboard use only.
  1868. //
  1869. NTSTATUS
  1870. I8042SetIMEStatusForOasys(
  1871. IN PDEVICE_OBJECT DeviceObject,
  1872. IN PIRP Irp,
  1873. IN OUT PINITIATE_OUTPUT_CONTEXT InitiateContext
  1874. );
  1875. ULONG
  1876. I8042QueryIMEStatusForOasys(
  1877. IN PKEYBOARD_IME_STATUS KeyboardIMEStatus
  1878. );
  1879. VOID
  1880. I8xKeyboardInitiateIoForOasys(
  1881. IN PDEVICE_OBJECT DeviceObject
  1882. );
  1883. #endif // _FJKBD_H_
  1884. #endif // _X86_
  1885. #if DBG
  1886. #define DEFAULT_DEBUG_FLAGS 0x88888808 // 0x8cc8888f
  1887. #else
  1888. #define DEFAULT_DEBUG_FLAGS 0x0
  1889. #endif
  1890. #if I8042_VERBOSE
  1891. //
  1892. //Debug messaging and breakpoint macros
  1893. //
  1894. #define DBG_ALWAYS 0x00000000
  1895. #define DBG_STARTUP_SHUTDOWN_MASK 0x0000000F
  1896. #define DBG_SS_NOISE 0x00000001
  1897. #define DBG_SS_TRACE 0x00000002
  1898. #define DBG_SS_INFO 0x00000004
  1899. #define DBG_SS_ERROR 0x00000008
  1900. #define DBG_CALL_MASK 0x000000F0
  1901. #define DBG_CALL_NOISE 0x00000010
  1902. #define DBG_CALL_TRACE 0x00000020
  1903. #define DBG_CALL_INFO 0x00000040
  1904. #define DBG_CALL_ERROR 0x00000080
  1905. #define DBG_IOCTL_MASK 0x00000F00
  1906. #define DBG_IOCTL_NOISE 0x00000100
  1907. #define DBG_IOCTL_TRACE 0x00000200
  1908. #define DBG_IOCTL_INFO 0x00000400
  1909. #define DBG_IOCTL_ERROR 0x00000800
  1910. #define DBG_DPC_MASK 0x0000F000
  1911. #define DBG_DPC_NOISE 0x00001000
  1912. #define DBG_DPC_TRACE 0x00002000
  1913. #define DBG_DPC_INFO 0x00004000
  1914. #define DBG_DPC_ERROR 0x00008000
  1915. #define DBG_CREATE_CLOSE_MASK 0x000F0000
  1916. #define DBG_CC_NOISE 0x00010000
  1917. #define DBG_CC_TRACE 0x00020000
  1918. #define DBG_CC_INFO 0x00040000
  1919. #define DBG_CC_ERROR 0x00080000
  1920. #define DBG_POWER_MASK 0x00F00000
  1921. #define DBG_POWER_NOISE 0x00100000
  1922. #define DBG_POWER_TRACE 0x00200000
  1923. #define DBG_POWER_INFO 0x00400000
  1924. #define DBG_POWER_ERROR 0x00800000
  1925. #define DBG_PNP_MASK 0x0F000000
  1926. #define DBG_PNP_NOISE 0x01000000
  1927. #define DBG_PNP_TRACE 0x02000000
  1928. #define DBG_PNP_INFO 0x04000000
  1929. #define DBG_PNP_ERROR 0x08000000
  1930. #define DBG_BUFIO_MASK 0xF0000000
  1931. #define DBG_BUFIO_NOISE 0x10000000
  1932. #define DBG_BUFIO_TRACE 0x20000000
  1933. #define DBG_BUFIO_INFO 0x40000000
  1934. #define DBG_BUFIO_ERROR 0x80000000
  1935. #define DBG_KBISR_NOISE 0x00000001
  1936. #define DBG_KBISR_TRACE 0x00000002
  1937. #define DBG_KBISR_INFO 0x00000004
  1938. #define DBG_KBISR_ERROR 0x00000008
  1939. #define DBG_KBISR_STATE 0x00000010
  1940. #define DBG_KBISR_SCODE 0x00000020
  1941. #define DBG_KBISR_BREAK 0x00000040
  1942. #define DBG_KBISR_EMUL 0x00000080
  1943. #define DBG_KBISR_POWER 0x00000100
  1944. #define DBG_MOUISR_MASK 0x000F0000
  1945. #define DBG_MOUISR_NOISE 0x00010000
  1946. #define DBG_MOUISR_TRACE 0x00020000
  1947. #define DBG_MOUISR_INFO 0x00040000
  1948. #define DBG_MOUISR_ERROR 0x00080000
  1949. #define DBG_MOUISR_STATE 0x00100000
  1950. #define DBG_MOUISR_BYTE 0x00200000
  1951. #define DBG_MOUISR_RESETTING 0x00400000
  1952. #define DBG_MOUISR_ACK 0x00800000
  1953. #define DBG_MOUISR_PNPID 0x01000000
  1954. #define DBG_MOUISR_BREAK 0x02000000
  1955. // #define DBG_MOUISR_BREAK 0x04000000
  1956. #define Print(_flags_, _x_) \
  1957. if (Globals.DebugFlags & (_flags_) || !(_flags_)) { \
  1958. DbgPrint (pDriverName); \
  1959. DbgPrint _x_; \
  1960. }
  1961. #define IsrPrint(_flags_, _x_) \
  1962. if (Globals.IsrDebugFlags & (_flags_) || !(_flags_)) { \
  1963. DbgPrint (((ULONG)(_flags_)) >= 0x0001000 ? pIsrMou : pIsrKb); \
  1964. DbgPrint _x_; \
  1965. }
  1966. #define TRAP() DbgBreakPoint()
  1967. #else
  1968. #define Print(_l_,_x_)
  1969. #define IsrPrint(_l_,_x_)
  1970. #define TRAP()
  1971. #endif // I8042_VERBOSE
  1972. static UCHAR ScanCodeToUChar[] = {
  1973. 0x00, // Nothing
  1974. 0x00, // Esc
  1975. '1',
  1976. '2',
  1977. '3',
  1978. '4',
  1979. '5',
  1980. '6',
  1981. '7',
  1982. '8',
  1983. '9',
  1984. '0',
  1985. '-',
  1986. '=',
  1987. 0x00, // Backspace
  1988. 0x00, // Tab
  1989. 'Q',
  1990. 'W',
  1991. 'E',
  1992. 'R',
  1993. 'T',
  1994. 'Y',
  1995. 'U',
  1996. 'I',
  1997. 'O',
  1998. 'P',
  1999. '[',
  2000. ']',
  2001. '\\',
  2002. 0x00, // Caps lock
  2003. 'A',
  2004. 'S',
  2005. 'D',
  2006. 'F',
  2007. 'G',
  2008. 'H',
  2009. 'I',
  2010. 'J',
  2011. 'K',
  2012. 'L',
  2013. ';',
  2014. '\'',
  2015. 0x00, // Return
  2016. 0x00, // Shift left
  2017. 'Z',
  2018. 'X',
  2019. 'C',
  2020. 'V',
  2021. 'B',
  2022. 'N',
  2023. 'M',
  2024. ',',
  2025. '.',
  2026. '/'
  2027. };
  2028. static const int ScanCodeToUCharCount = sizeof(ScanCodeToUChar)/sizeof(UCHAR);
  2029. /*
  2030. 0x00, // Shift right
  2031. 0x00, // Ctrl left
  2032. 0x00, // Alt left
  2033. ' ',
  2034. 0x00, // Alt right
  2035. 0x00, // Ctrl right
  2036. 0x00, // num lock
  2037. */
  2038. #define CTRL_SCANCODE 0x1d
  2039. #define LEFT_SHIFT_SCANCODE 0x2A
  2040. #define RIGHT_SHIFT_SCANCODE 0x36
  2041. #define ALT_SCANCODE 0x38
  2042. #define SCROLL_LOCK_SCANCODE 0x46
  2043. #endif // _I8042PRT_