Source code of Windows XP (NT5)
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.

528 lines
9.9 KiB

  1. /*++
  2. Copyright (c) 1989, 1990, 1991, 1992, 1993 Microsoft Corporation
  3. Copyright (c) 1993 Logitech Inc.
  4. Module Name:
  5. sermouse.h
  6. Abstract:
  7. These are the structures and defines that are used in the
  8. i8250 serial mouse port driver.
  9. Revision History:
  10. --*/
  11. #ifndef _SERMOUSE_
  12. #define _SERMOUSE_
  13. #include <ntddmou.h>
  14. #include "kbdmou.h"
  15. #include "sermcfg.h"
  16. #include "uart.h"
  17. //
  18. // Default number of buttons and sample rate for the serial mouse.
  19. //
  20. #define MOUSE_NUMBER_OF_BUTTONS 2
  21. #define MOUSE_SAMPLE_RATE 40 // 1200 baud
  22. //
  23. // Protocol handler state constants.
  24. //
  25. #define STATE0 0 // Sync bit, buttons and high x & y bits
  26. #define STATE1 1 // lower x bits
  27. #define STATE2 2 // lower y bits
  28. #define STATE3 3 // Switch 2, extended packet bit & low z data
  29. #define STATE4 4 // high z data
  30. #define STATE_MAX 5
  31. //
  32. // Useful constants.
  33. //
  34. #define MOUSE_BUTTON_1 0x01
  35. #define MOUSE_BUTTON_2 0x02
  36. #define MOUSE_BUTTON_3 0x04
  37. #define MOUSE_BUTTON_LEFT 0x01
  38. #define MOUSE_BUTTON_RIGHT 0x02
  39. #define MOUSE_BUTTON_MIDDLE 0x04
  40. //
  41. // Conversion factor for milliseconds to microseconds.
  42. //
  43. #define MS_TO_MICROSECONDS 1000
  44. //
  45. // Protocol handler static data.
  46. //
  47. typedef struct _HANDLER_DATA {
  48. ULONG Error; // Error count
  49. ULONG State; // Keep the current state
  50. ULONG PreviousButtons; // The previous button state
  51. UCHAR Raw[STATE_MAX]; // Accumulate raw data
  52. } HANDLER_DATA, *PHANDLER_DATA;
  53. //
  54. // Define the protocol handler type.
  55. //
  56. typedef BOOLEAN
  57. (*PPROTOCOL_HANDLER)(
  58. IN PMOUSE_INPUT_DATA CurrentInput,
  59. IN PHANDLER_DATA HandlerData,
  60. IN UCHAR Value,
  61. IN UCHAR LineState);
  62. //
  63. // Defines for DeviceExtension->HardwarePresent.
  64. // These should match the values in i8042prt
  65. //
  66. #define MOUSE_HARDWARE_PRESENT 0x02
  67. #define BALLPOINT_HARDWARE_PRESENT 0x04
  68. #define WHEELMOUSE_HARDWARE_PRESENT 0x08
  69. //
  70. // Serial mouse configuration information.
  71. //
  72. typedef struct _SERIAL_MOUSE_CONFIGURATION_INFORMATION {
  73. //
  74. // Bus interface type.
  75. //
  76. INTERFACE_TYPE InterfaceType;
  77. //
  78. // Bus Number.
  79. //
  80. ULONG BusNumber;
  81. //
  82. // The port/register resources used by this device.
  83. //
  84. CM_PARTIAL_RESOURCE_DESCRIPTOR PortList[1];
  85. ULONG PortListCount;
  86. //
  87. // Interrupt resources.
  88. //
  89. CM_PARTIAL_RESOURCE_DESCRIPTOR MouseInterrupt;
  90. //
  91. // The mapped address for the set of this device's registers.
  92. //
  93. PUCHAR DeviceRegisters[1];
  94. //
  95. // The external frequency at which the UART is being driven.
  96. //
  97. ULONG BaudClock;
  98. //
  99. // The saved initial UART state.
  100. //
  101. UART UartSaved;
  102. //
  103. // Set at intialization to indicate that the base register
  104. // address must be unmapped when the driver is unloaded.
  105. //
  106. BOOLEAN UnmapRegistersRequired;
  107. //
  108. // Flag set through the registry to force the type of hardware
  109. // (bypassing NtDetect).
  110. //
  111. LONG OverrideHardwarePresent;
  112. //
  113. // Flag that indicates whether floating point context should be saved.
  114. //
  115. BOOLEAN FloatingSave;
  116. //
  117. // Mouse attributes.
  118. //
  119. MOUSE_ATTRIBUTES MouseAttributes;
  120. } SERIAL_MOUSE_CONFIGURATION_INFORMATION,
  121. *PSERIAL_MOUSE_CONFIGURATION_INFORMATION;
  122. //
  123. // Port device extension.
  124. //
  125. typedef struct _DEVICE_EXTENSION {
  126. //
  127. // If HardwarePresent is non-zero, there is some sort of serial
  128. // pointing device present in the system, either a serial mouse
  129. // (MOUSE_HARDWARE_PRESENT) or a serial ballpoint
  130. // (BALLPOINT_HARDWARE_PRESENT).
  131. //
  132. ULONG HardwarePresent;
  133. //
  134. // Port configuration information.
  135. //
  136. SERIAL_MOUSE_CONFIGURATION_INFORMATION Configuration;
  137. //
  138. // Reference count for number of mouse enables.
  139. //
  140. LONG MouseEnableCount;
  141. //
  142. // Pointer to the device object.
  143. //
  144. PDEVICE_OBJECT DeviceObject;
  145. //
  146. // Mouse class connection data.
  147. //
  148. CONNECT_DATA ConnectData;
  149. //
  150. // Number of input data items currently in the mouse InputData queue.
  151. //
  152. ULONG InputCount;
  153. //
  154. // Start of the port mouse input data queue (really a circular buffer).
  155. //
  156. PMOUSE_INPUT_DATA InputData;
  157. //
  158. // Insertion pointer for mouse InputData.
  159. //
  160. PMOUSE_INPUT_DATA DataIn;
  161. //
  162. // Removal pointer for mouse InputData.
  163. //
  164. PMOUSE_INPUT_DATA DataOut;
  165. //
  166. // Points one input packet past the end of the InputData buffer.
  167. //
  168. PMOUSE_INPUT_DATA DataEnd;
  169. //
  170. // Current mouse input packet.
  171. //
  172. MOUSE_INPUT_DATA CurrentInput;
  173. //
  174. // Pointer to interrupt object.
  175. //
  176. PKINTERRUPT InterruptObject;
  177. //
  178. // Mouse ISR DPC queue.
  179. //
  180. KDPC IsrDpc;
  181. //
  182. // Mouse ISR DPC recall queue.
  183. //
  184. KDPC IsrDpcRetry;
  185. //
  186. // Used by the ISR and the ISR DPC (in SerMouDpcVariableOperation calls)
  187. // to control processing by the ISR DPC.
  188. //
  189. LONG DpcInterlockVariable;
  190. //
  191. // Spinlock used to protect the DPC interlock variable.
  192. //
  193. KSPIN_LOCK SpinLock;
  194. //
  195. // Timer used to retry the ISR DPC routine when the class
  196. // driver is unable to consume all the port driver's data.
  197. //
  198. KTIMER DataConsumptionTimer;
  199. //
  200. // DPC queue for logging overrun and internal driver errors.
  201. //
  202. KDPC ErrorLogDpc;
  203. //
  204. // Request sequence number (used for error logging).
  205. //
  206. ULONG SequenceNumber;
  207. //
  208. // Pointer to the interrupt protocol handler routine.
  209. //
  210. PPROTOCOL_HANDLER ProtocolHandler;
  211. //
  212. // Static state machine handler data.
  213. //
  214. HANDLER_DATA HandlerData;
  215. //
  216. // Indicates which pointer port device this driver created (UnitId
  217. // is the suffix appended to the pointer port basename for the
  218. // call to IoCreateDevice).
  219. //
  220. USHORT UnitId;
  221. //
  222. // Indicates whether it is okay to log overflow errors.
  223. //
  224. BOOLEAN OkayToLogOverflow;
  225. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  226. //
  227. // Define the port Get/SetDataQueuePointer context structures.
  228. //
  229. typedef struct _GET_DATA_POINTER_CONTEXT {
  230. IN PDEVICE_EXTENSION DeviceExtension;
  231. OUT PVOID DataIn;
  232. OUT PVOID DataOut;
  233. OUT ULONG InputCount;
  234. } GET_DATA_POINTER_CONTEXT, *PGET_DATA_POINTER_CONTEXT;
  235. typedef struct _SET_DATA_POINTER_CONTEXT {
  236. IN PDEVICE_EXTENSION DeviceExtension;
  237. IN ULONG InputCount;
  238. IN PVOID DataOut;
  239. } SET_DATA_POINTER_CONTEXT, *PSET_DATA_POINTER_CONTEXT;
  240. //
  241. // Define the context structure and operations for SerMouDpcVariableOperation.
  242. //
  243. typedef enum _OPERATION_TYPE {
  244. IncrementOperation,
  245. DecrementOperation,
  246. WriteOperation,
  247. ReadOperation
  248. } OPERATION_TYPE;
  249. typedef struct _VARIABLE_OPERATION_CONTEXT {
  250. IN PLONG VariableAddress;
  251. IN OPERATION_TYPE Operation;
  252. IN OUT PLONG NewValue;
  253. } VARIABLE_OPERATION_CONTEXT, *PVARIABLE_OPERATION_CONTEXT;
  254. //
  255. // Function prototypes.
  256. //
  257. NTSTATUS
  258. DriverEntry(
  259. IN PDRIVER_OBJECT DriverObject,
  260. IN PUNICODE_STRING RegistryPath
  261. );
  262. VOID
  263. SerMouInitializeDevice(
  264. IN PDRIVER_OBJECT DriverObject,
  265. IN PDEVICE_EXTENSION TmpDeviceExtension,
  266. IN PUNICODE_STRING RegistryPath,
  267. IN PUNICODE_STRING BaseDeviceName
  268. );
  269. VOID
  270. SerialMouseErrorLogDpc(
  271. IN PKDPC Dpc,
  272. IN PDEVICE_OBJECT DeviceObject,
  273. IN PIRP Irp,
  274. IN PVOID Context
  275. );
  276. NTSTATUS
  277. SerialMouseFlush(
  278. IN PDEVICE_OBJECT DeviceObject,
  279. IN PIRP Irp
  280. );
  281. NTSTATUS
  282. SerialMouseInternalDeviceControl(
  283. IN PDEVICE_OBJECT DeviceObject,
  284. IN PIRP Irp
  285. );
  286. BOOLEAN
  287. SerialMouseInterruptService(
  288. IN PKINTERRUPT Interrupt,
  289. IN PVOID Context
  290. );
  291. VOID
  292. SerialMouseIsrDpc(
  293. IN PKDPC Dpc,
  294. IN PDEVICE_OBJECT DeviceObject,
  295. IN PIRP Irp,
  296. IN PVOID Context
  297. );
  298. NTSTATUS
  299. SerialMouseOpenClose(
  300. IN PDEVICE_OBJECT DeviceObject,
  301. IN PIRP Irp
  302. );
  303. VOID
  304. SerialMouseStartIo(
  305. IN PDEVICE_OBJECT DeviceObject,
  306. IN PIRP Irp
  307. );
  308. VOID
  309. SerialMouseUnload(
  310. IN PDRIVER_OBJECT DriverObject
  311. );
  312. VOID
  313. SerMouBuildResourceList(
  314. IN PDEVICE_EXTENSION DeviceExtension,
  315. OUT PCM_RESOURCE_LIST *ResourceList,
  316. OUT PULONG ResourceListSize
  317. );
  318. VOID
  319. SerMouConfiguration(
  320. IN OUT PLIST_ENTRY DeviceExtensionList,
  321. IN PUNICODE_STRING RegistryPath,
  322. IN PUNICODE_STRING DeviceName
  323. );
  324. VOID
  325. SerMouDisableInterrupts(
  326. IN PVOID Context
  327. );
  328. VOID
  329. SerMouDpcVariableOperation(
  330. IN PVOID Context
  331. );
  332. VOID
  333. SerMouEnableInterrupts(
  334. IN PVOID Context
  335. );
  336. VOID
  337. SerMouGetDataQueuePointer(
  338. IN PVOID Context
  339. );
  340. VOID
  341. SerMouInitializeDataQueue(
  342. IN PVOID Context
  343. );
  344. NTSTATUS
  345. SerMouInitializeHardware(
  346. IN PDEVICE_OBJECT DeviceObject
  347. );
  348. NTSTATUS
  349. SerMouPeripheralCallout(
  350. IN PVOID Context,
  351. IN PUNICODE_STRING PathName,
  352. IN INTERFACE_TYPE BusType,
  353. IN ULONG BusNumber,
  354. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  355. IN CONFIGURATION_TYPE ControllerType,
  356. IN ULONG ControllerNumber,
  357. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  358. IN CONFIGURATION_TYPE PeripheralType,
  359. IN ULONG PeripheralNumber,
  360. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  361. );
  362. NTSTATUS
  363. SerMouPeripheralListCallout(
  364. IN PVOID Context,
  365. IN PUNICODE_STRING PathName,
  366. IN INTERFACE_TYPE BusType,
  367. IN ULONG BusNumber,
  368. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  369. IN CONFIGURATION_TYPE ControllerType,
  370. IN ULONG ControllerNumber,
  371. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  372. IN CONFIGURATION_TYPE PeripheralType,
  373. IN ULONG PeripheralNumber,
  374. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  375. );
  376. VOID
  377. SerMouSendReport(
  378. IN PDEVICE_OBJECT DeviceObject
  379. );
  380. VOID
  381. SerMouServiceParameters(
  382. IN PDEVICE_EXTENSION DeviceExtension,
  383. IN PUNICODE_STRING RegistryPath,
  384. IN PUNICODE_STRING DeviceName
  385. );
  386. VOID
  387. SerMouSetDataQueuePointer(
  388. IN PVOID Context
  389. );
  390. BOOLEAN
  391. SerMouWriteDataToQueue(
  392. IN PDEVICE_EXTENSION DeviceExtension,
  393. IN PMOUSE_INPUT_DATA InputData
  394. );
  395. #endif // _SERMOUSE_