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.

485 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 1990, 1991, 1992, 1993 Microsoft Corporation
  3. Copyright (c) 1992 Logitech Inc.
  4. Module Name:
  5. busmouse.h
  6. Abstract:
  7. These are the structures and defines that are used in the
  8. Microsoft/Logitech Bus mouse port driver.
  9. Revision History:
  10. --*/
  11. #ifndef _BUSMOUSE_
  12. #define _BUSMOUSE_
  13. #include <ntddmou.h>
  14. #include "kbdmou.h"
  15. #include "buscfg.h"
  16. //
  17. // Default number of buttons and sample rate for the Inport mouse.
  18. //
  19. #define MOUSE_NUMBER_OF_BUTTONS 3
  20. #define MOUSE_SAMPLE_RATE_50HZ 50
  21. //
  22. // NOTE: This should be defined in the DDK instead...
  23. //
  24. #define MOUSE_BUS_HARDWARE MOUSE_INPORT_HARDWARE
  25. #define FILE_DEVICE_BUS_PORT FILE_DEVICE_INPORT_PORT
  26. #define BUSMOUSE_ERROR_VALUE_BASE INPORT_ERROR_VALUE_BASE
  27. //
  28. // Define the control port bits.
  29. //
  30. #define BUS_CONTROL_INTERRUPT_DISABLE 0x10
  31. #define BUS_CONTROL_COUNTER_CAPTURE 0x80
  32. #define BUS_CONTROL_X_LOW 0x00
  33. #define BUS_CONTROL_X_HIGH 0x20
  34. #define BUS_CONTROL_Y_LOW 0x40
  35. #define BUS_CONTROL_Y_HIGH 0x60
  36. //
  37. // Define the Bus data bits
  38. //
  39. #define BUS_DATA_BUTTON_1 0x80
  40. #define BUS_DATA_BUTTON_1_SHIFT 0x06
  41. #define BUS_DATA_BUTTON_2 0x40
  42. #define BUS_DATA_BUTTON_2_SHIFT 0x04
  43. #define BUS_DATA_BUTTON_3 0x20
  44. #define BUS_DATA_BUTTON_3_SHIFT 0x05
  45. //
  46. // Define the Configuration byte
  47. //
  48. #define BUS_CONFIGURATION_VALUE 0x91
  49. //
  50. // Define the registers.
  51. //
  52. #define BUS_DATA_PORT_READ 0x00
  53. #define BUS_SIGNATURE_PORT_READ_WRITE 0x01
  54. #define BUS_INTERRUPT_PORT_READ 0x02
  55. #define BUS_CONTROL_PORT_WRITE 0x02
  56. #define BUS_CONFIGURATION_PORT_READ_WRITE 0x03
  57. //
  58. // Inport mouse configuration information.
  59. //
  60. typedef struct _BUS_CONFIGURATION_INFORMATION {
  61. //
  62. // Bus interface type.
  63. //
  64. INTERFACE_TYPE InterfaceType;
  65. //
  66. // Bus Number.
  67. //
  68. ULONG BusNumber;
  69. #ifdef PNP_IDENTIFY
  70. //
  71. // Controller type & number
  72. //
  73. CONFIGURATION_TYPE ControllerType;
  74. ULONG ControllerNumber;
  75. //
  76. // Peripheral type & number
  77. CONFIGURATION_TYPE PeripheralType;
  78. ULONG PeripheralNumber;
  79. #endif
  80. //
  81. // The port/register resources used by this device.
  82. //
  83. CM_PARTIAL_RESOURCE_DESCRIPTOR PortList[1];
  84. ULONG PortListCount;
  85. //
  86. // Interrupt resources.
  87. //
  88. CM_PARTIAL_RESOURCE_DESCRIPTOR MouseInterrupt;
  89. //
  90. // The mapped address for the set of this device's registers.
  91. //
  92. PUCHAR DeviceRegisters[1];
  93. //
  94. // Set at intialization to indicate that the base register
  95. // address must be unmapped when the driver is unloaded.
  96. //
  97. BOOLEAN UnmapRegistersRequired;
  98. //
  99. // Flag that indicates whether floating point context should be saved.
  100. //
  101. BOOLEAN FloatingSave;
  102. //
  103. // Mouse attributes.
  104. //
  105. MOUSE_ATTRIBUTES MouseAttributes;
  106. } BUS_CONFIGURATION_INFORMATION, *PBUS_CONFIGURATION_INFORMATION;
  107. //
  108. // Port device extension.
  109. //
  110. typedef struct _DEVICE_EXTENSION {
  111. //
  112. // If HardwarePresent is TRUE, there is an Inport mouse present in
  113. // the system.
  114. //
  115. BOOLEAN HardwarePresent;
  116. //
  117. // Port configuration information.
  118. //
  119. BUS_CONFIGURATION_INFORMATION Configuration;
  120. //
  121. // Reference count for number of mouse enables.
  122. //
  123. LONG MouseEnableCount;
  124. //
  125. // Pointer to the device object.
  126. //
  127. PDEVICE_OBJECT DeviceObject;
  128. //
  129. // Mouse class connection data.
  130. //
  131. CONNECT_DATA ConnectData;
  132. //
  133. // Number of input data items currently in the mouse InputData queue.
  134. //
  135. ULONG InputCount;
  136. //
  137. // Start of the port mouse input data queue (really a circular buffer).
  138. //
  139. PMOUSE_INPUT_DATA InputData;
  140. //
  141. // Insertion pointer for mouse InputData.
  142. //
  143. PMOUSE_INPUT_DATA DataIn;
  144. //
  145. // Removal pointer for mouse InputData.
  146. //
  147. PMOUSE_INPUT_DATA DataOut;
  148. //
  149. // Points one input packet past the end of the InputData buffer.
  150. //
  151. PMOUSE_INPUT_DATA DataEnd;
  152. //
  153. // Current mouse input packet.
  154. //
  155. MOUSE_INPUT_DATA CurrentInput;
  156. //
  157. // Keep track of the previous button state.
  158. //
  159. UCHAR PreviousButtons;
  160. //
  161. // Pointer to interrupt object.
  162. //
  163. PKINTERRUPT InterruptObject;
  164. //
  165. // Mouse ISR DPC queue.
  166. //
  167. KDPC IsrDpc;
  168. //
  169. // Mouse ISR DPC recall queue.
  170. //
  171. KDPC IsrDpcRetry;
  172. //
  173. // Used by the ISR and the ISR DPC (in BusDpcVariableOperation calls)
  174. // to control processing by the ISR DPC.
  175. //
  176. LONG DpcInterlockVariable;
  177. //
  178. // Spinlock used to protect the DPC interlock variable.
  179. //
  180. KSPIN_LOCK SpinLock;
  181. //
  182. // Timer used to retry the ISR DPC routine when the class
  183. // driver is unable to consume all the port driver's data.
  184. //
  185. KTIMER DataConsumptionTimer;
  186. //
  187. // DPC queue for logging overrun and internal driver errors.
  188. //
  189. KDPC ErrorLogDpc;
  190. //
  191. // Request sequence number (used for error logging).
  192. //
  193. ULONG SequenceNumber;
  194. //
  195. // Indicates which pointer port device this driver created (UnitId
  196. // is the suffix appended to the pointer port basename for the
  197. // call to IoCreateDevice).
  198. //
  199. USHORT UnitId;
  200. //
  201. // Indicates whether it is okay to log overflow errors.
  202. //
  203. BOOLEAN OkayToLogOverflow;
  204. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  205. //
  206. // Define the port Get/SetDataQueuePointer context structures.
  207. //
  208. typedef struct _GET_DATA_POINTER_CONTEXT {
  209. IN PDEVICE_EXTENSION DeviceExtension;
  210. OUT PVOID DataIn;
  211. OUT PVOID DataOut;
  212. OUT ULONG InputCount;
  213. } GET_DATA_POINTER_CONTEXT, *PGET_DATA_POINTER_CONTEXT;
  214. typedef struct _SET_DATA_POINTER_CONTEXT {
  215. IN PDEVICE_EXTENSION DeviceExtension;
  216. IN ULONG InputCount;
  217. IN PVOID DataOut;
  218. } SET_DATA_POINTER_CONTEXT, *PSET_DATA_POINTER_CONTEXT;
  219. //
  220. // Define the context structure and operations for BusDpcVariableOperation.
  221. //
  222. typedef enum _OPERATION_TYPE {
  223. IncrementOperation,
  224. DecrementOperation,
  225. WriteOperation,
  226. ReadOperation
  227. } OPERATION_TYPE;
  228. typedef struct _VARIABLE_OPERATION_CONTEXT {
  229. IN PLONG VariableAddress;
  230. IN OPERATION_TYPE Operation;
  231. IN OUT PLONG NewValue;
  232. } VARIABLE_OPERATION_CONTEXT, *PVARIABLE_OPERATION_CONTEXT;
  233. //
  234. // Function prototypes.
  235. //
  236. NTSTATUS
  237. DriverEntry(
  238. IN PDRIVER_OBJECT DriverObject,
  239. IN PUNICODE_STRING RegistryPath
  240. );
  241. NTSTATUS
  242. DBusFlush(
  243. IN PDEVICE_OBJECT DeviceObject,
  244. IN PIRP Irp
  245. );
  246. NTSTATUS
  247. DBusInternalDeviceControl(
  248. IN PDEVICE_OBJECT DeviceObject,
  249. IN PIRP Irp
  250. );
  251. BOOLEAN
  252. DBusInterruptService(
  253. IN PKINTERRUPT Interrupt,
  254. IN PVOID Context
  255. );
  256. VOID
  257. DBusIsrDpc(
  258. IN PKDPC Dpc,
  259. IN PDEVICE_OBJECT DeviceObject,
  260. IN PIRP Irp,
  261. IN PVOID Context
  262. );
  263. NTSTATUS
  264. DBusOpenClose(
  265. IN PDEVICE_OBJECT DeviceObject,
  266. IN PIRP Irp
  267. );
  268. VOID
  269. DBusStartIo(
  270. IN PDEVICE_OBJECT DeviceObject,
  271. IN PIRP Irp
  272. );
  273. VOID
  274. DBusUnload(
  275. IN PDRIVER_OBJECT DriverObject
  276. );
  277. VOID
  278. BusBuildResourceList(
  279. IN PDEVICE_EXTENSION DeviceExtension,
  280. OUT PCM_RESOURCE_LIST *ResourceList,
  281. OUT PULONG ResourceListSize
  282. );
  283. VOID
  284. BusConfiguration(
  285. IN PDEVICE_EXTENSION DeviceExtension,
  286. IN PUNICODE_STRING RegistryPath,
  287. IN PUNICODE_STRING DeviceName
  288. );
  289. VOID
  290. BusDisableInterrupts(
  291. IN PVOID Context
  292. );
  293. VOID
  294. BusDpcVariableOperation(
  295. IN PVOID Context
  296. );
  297. VOID
  298. BusEnableInterrupts(
  299. IN PVOID Context
  300. );
  301. VOID
  302. BusErrorLogDpc(
  303. IN PKDPC Dpc,
  304. IN PDEVICE_OBJECT DeviceObject,
  305. IN PIRP Irp,
  306. IN PVOID Context
  307. );
  308. VOID
  309. BusGetDataQueuePointer(
  310. IN PVOID Context
  311. );
  312. VOID
  313. BusInitializeDataQueue(
  314. IN PVOID Context
  315. );
  316. NTSTATUS
  317. BusInitializeHardware(
  318. IN PDEVICE_OBJECT DeviceObject
  319. );
  320. NTSTATUS
  321. BusPeripheralCallout(
  322. IN PVOID Context,
  323. IN PUNICODE_STRING PathName,
  324. IN INTERFACE_TYPE BusType,
  325. IN ULONG BusNumber,
  326. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  327. IN CONFIGURATION_TYPE ControllerType,
  328. IN ULONG ControllerNumber,
  329. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  330. IN CONFIGURATION_TYPE PeripheralType,
  331. IN ULONG PeripheralNumber,
  332. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  333. );
  334. VOID
  335. BusServiceParameters(
  336. IN PDEVICE_EXTENSION DeviceExtension,
  337. IN PUNICODE_STRING RegistryPath,
  338. IN PUNICODE_STRING DeviceName
  339. );
  340. VOID
  341. BusSetDataQueuePointer(
  342. IN PVOID Context
  343. );
  344. BOOLEAN
  345. BusWriteDataToQueue(
  346. IN PDEVICE_EXTENSION DeviceExtension,
  347. IN PMOUSE_INPUT_DATA InputData
  348. );
  349. #if DBG
  350. VOID
  351. BusDebugPrint(
  352. IN ULONG DebugPrintLevel,
  353. IN PCCHAR DebugMessage,
  354. ...
  355. );
  356. #define BusPrint(x) BusDebugPrint x
  357. #else
  358. #define BusPrint(x)
  359. #endif
  360. #endif // _BUSMOUSE_