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.

702 lines
15 KiB

  1. /*++
  2. Copyright (c) 1989, 1990, 1991, 1992, 1993 Microsoft Corporation
  3. Module Name:
  4. inport.h
  5. Abstract:
  6. These are the structures and defines that are used in the
  7. Microsoft Inport mouse port driver.
  8. Revision History:
  9. --*/
  10. #ifndef _INPORT_
  11. #define _INPORT_
  12. #include "ntddk.h"
  13. #include <ntddmou.h>
  14. #include "kbdmou.h"
  15. #include "inpcfg.h"
  16. #include "wmilib.h"
  17. #define INP_POOL_TAG (ULONG) 'tpnI' // will get reversed
  18. #undef ExAllocatePool
  19. #define ExAllocatePool(type, size) \
  20. ExAllocatePoolWithTag (type, size, INP_POOL_TAG)
  21. //
  22. // Default number of buttons and sample rate for the Inport mouse.
  23. //
  24. #if defined(NEC_98)
  25. #define MOUSE_NUMBER_OF_BUTTONS 2
  26. #define PC98_MOUSE_SAMPLE_RATE_120HZ 120
  27. #else // defined(NEC_98)
  28. #define MOUSE_NUMBER_OF_BUTTONS 2
  29. #define MOUSE_SAMPLE_RATE_50HZ 50
  30. #endif // defined(NEC_98)
  31. //
  32. // Define the Inport chip reset value.
  33. //
  34. #define INPORT_RESET 0x80
  35. //
  36. // Define the data registers (pointed to by the Inport address register).
  37. //
  38. #define INPORT_DATA_REGISTER_1 1
  39. #define INPORT_DATA_REGISTER_2 2
  40. //
  41. // Define the Inport identification register and the chip code.
  42. //
  43. #define INPORT_ID_REGISTER 2
  44. #define INPORT_ID_CODE 0xDE
  45. //
  46. // Define the Inport mouse status register and the status bits.
  47. //
  48. #if defined(NEC_98)
  49. #define INPORT_STATUS_BUTTON3 0x20 // Right Button
  50. #define INPORT_STATUS_BUTTON1 0x80 // Left Button
  51. #else // defined(NEC_98)
  52. #define INPORT_STATUS_REGISTER 0
  53. #define INPORT_STATUS_BUTTON3 0x01
  54. #define INPORT_STATUS_BUTTON2 0x02
  55. #define INPORT_STATUS_BUTTON1 0x04
  56. #define INPORT_STATUS_MOVEMENT 0x40
  57. #endif // defined(NEC_98)
  58. //
  59. // Define the Inport mouse mode register and mode bits.
  60. //
  61. #define INPORT_MODE_REGISTER 7
  62. #define INPORT_MODE_0 0x00 // 0 HZ - INTR = 0
  63. #if defined(NEC_98)
  64. #define PC98_MODE_15HZ 0x03
  65. #define PC98_MODE_30HZ 0x02
  66. #define PC98_MODE_60HZ 0x01
  67. #define PC98_MODE_120HZ 0x00
  68. #define PC98_EVENT_MODE_60HZ 0x03
  69. #define PC98_EVENT_MODE_120HZ 0x02
  70. #define PC98_EVENT_MODE_240HZ 0x01
  71. #define PC98_EVENT_MODE_400HZ 0x00
  72. #define INPORT_MODE_1 0x06 // 0 HZ - INTR = 1
  73. #define INPORT_DATA_INTERRUPT_ENABLE 0x08
  74. #define INPORT_TIMER_INTERRUPT_ENABLE 0x10
  75. #define INPORT_MODE_HOLD 0x20
  76. #define INPORT_MODE_QUADRATURE 0x00
  77. #else // defined(NEC_98)
  78. #define INPORT_MODE_30HZ 0x01
  79. #define INPORT_MODE_50HZ 0x02
  80. #define INPORT_MODE_100HZ 0x03
  81. #define INPORT_MODE_200HZ 0x04
  82. #define INPORT_MODE_1 0x06 // 0 HZ - INTR = 1
  83. #define INPORT_DATA_INTERRUPT_ENABLE 0x08
  84. #define INPORT_TIMER_INTERRUPT_ENABLE 0x10
  85. #define INPORT_MODE_HOLD 0x20
  86. #define INPORT_MODE_QUADRATURE 0x00
  87. #endif // defined(NEC_98)
  88. #if defined(NEC_98)
  89. #define PC98_EOI 0x20
  90. #define PC98_WriteModePort 0x06
  91. #define PC98_WritePortC1 0x06
  92. #define PC98_WritePortC2 0x04
  93. #define PC98_ReadPortB 0x02
  94. #define PC98_ReadPortA 0x00
  95. #define PC98_WriteTimerPort 0xBFDB
  96. #define PC98_PicMasterPort 0x02
  97. #define PC98_PicSlavePort 0x0A
  98. #define PC98_AckMasterPort 0x00
  99. #define PC98_AckSlavePort 0x08
  100. #define PC98_PicMask_INT2 0x40 //0100 0000B
  101. #define PC98_PicMask_INT6 0x20 //0010 0000B
  102. #define PC98_VectorINT2 0x06
  103. #define PC98_VectorINT6 0x13
  104. #define PC98_X_ReadCommandLow 0x90
  105. #define PC98_X_ReadCommandHi 0xB0
  106. #define PC98_Y_ReadCommandLow 0xD0
  107. #define PC98_Y_ReadCommandHi 0xF0
  108. #define PC98_TimerIntDisable 0x10
  109. #define PC98_TimerIntEnable 0x80
  110. #define PC98_MouseEnable 0x08
  111. #define PC98_MouseDisable 0x09
  112. #define PC98_InitializeCommand 0x93
  113. #define PC98_MOUSE_RIGHT_BUTTON 0x20
  114. #define PC98_MOUSE_LEFT_BUTTON 0x80
  115. #define PC98_MOUSE_INT_SHARE_CHECK_PORT 0x869
  116. #define PC98_MOUSE_INT_SERVICE 0x80
  117. #define PC98_ConfigurationPort 0x0411
  118. #define PC98_ConfigurationDataPort 0x0413
  119. #define PC98_EventIntPort 0x63
  120. #define PC98_EventIntMode 0x01
  121. typedef struct _CONFIG_ROM_FLAG5{
  122. UCHAR Reserved : 5;
  123. UCHAR EventMouse : 1;
  124. UCHAR Reserved1 : 2;
  125. } ROM_FLAG5, *PROM_FLAG5;
  126. typedef struct _CONFIGURATION_DATA{
  127. UCHAR Reserved[40];
  128. UCHAR SystemInfo[512];
  129. UCHAR COM_ID[2];
  130. UCHAR Reserved1[15];
  131. ROM_FLAG5 EventMouseID;
  132. UCHAR Reserved2[110];
  133. } CONFIGURATION_DATA, *PCONFIGURATION_DATA;
  134. #endif // defined(NEC_98)
  135. //
  136. // Inport mouse configuration information.
  137. //
  138. typedef struct _INPORT_CONFIGURATION_INFORMATION {
  139. //
  140. // Bus interface type.
  141. //
  142. INTERFACE_TYPE InterfaceType;
  143. //
  144. // Bus Number.
  145. //
  146. ULONG BusNumber;
  147. //
  148. // The port/register resources used by this device.
  149. //
  150. #if defined(NEC_98)
  151. CM_PARTIAL_RESOURCE_DESCRIPTOR PortList[8];
  152. #else // defined(NEC_98)
  153. CM_PARTIAL_RESOURCE_DESCRIPTOR PortList[1];
  154. #endif // defined(NEC_98)
  155. ULONG PortListCount;
  156. //
  157. // Interrupt resources.
  158. //
  159. CM_PARTIAL_RESOURCE_DESCRIPTOR MouseInterrupt;
  160. //
  161. // The mapped address for the set of this device's registers.
  162. //
  163. PUCHAR DeviceRegisters[1];
  164. //
  165. // Set at intialization to indicate that the base register
  166. // address must be unmapped when the driver is unloaded.
  167. //
  168. BOOLEAN UnmapRegistersRequired;
  169. //
  170. // Flag that indicates whether floating point context should be saved.
  171. //
  172. BOOLEAN FloatingSave;
  173. //
  174. // Mouse attributes.
  175. //
  176. MOUSE_ATTRIBUTES MouseAttributes;
  177. //
  178. // Inport mode register Hz specifier for mouse interrupts.
  179. //
  180. UCHAR HzMode;
  181. } INPORT_CONFIGURATION_INFORMATION, *PINPORT_CONFIGURATION_INFORMATION;
  182. //
  183. // Port device extension.
  184. //
  185. typedef struct _DEVICE_EXTENSION {
  186. //
  187. // Port configuration information.
  188. //
  189. INPORT_CONFIGURATION_INFORMATION Configuration;
  190. //
  191. // Remove Lock object to protect IRP_MN_REMOVE_DEVICE
  192. //
  193. IO_REMOVE_LOCK RemoveLock;
  194. //
  195. // Reference count for number of mouse enables.
  196. //
  197. LONG MouseEnableCount;
  198. //
  199. // Pointer to the device object.
  200. //
  201. PDEVICE_OBJECT Self;
  202. //
  203. // Pointer the PDO of this stack
  204. //
  205. PDEVICE_OBJECT PDO;
  206. //
  207. // Pointer to the device object directly below inport
  208. //
  209. PDEVICE_OBJECT TopOfStack;
  210. //
  211. // WMI lib info
  212. //
  213. WMILIB_CONTEXT WmiLibInfo;
  214. //
  215. // Mouse class connection data.
  216. //
  217. CONNECT_DATA ConnectData;
  218. //
  219. // Number of input data items currently in the mouse InputData queue.
  220. //
  221. ULONG InputCount;
  222. //
  223. // Start of the port mouse input data queue (really a circular buffer).
  224. //
  225. PMOUSE_INPUT_DATA InputData;
  226. //
  227. // Insertion pointer for mouse InputData.
  228. //
  229. PMOUSE_INPUT_DATA DataIn;
  230. //
  231. // Removal pointer for mouse InputData.
  232. //
  233. PMOUSE_INPUT_DATA DataOut;
  234. //
  235. // Points one input packet past the end of the InputData buffer.
  236. //
  237. PMOUSE_INPUT_DATA DataEnd;
  238. //
  239. // Current mouse input packet.
  240. //
  241. MOUSE_INPUT_DATA CurrentInput;
  242. //
  243. // Previous mouse button state.
  244. //
  245. UCHAR PreviousButtons;
  246. //
  247. // Pointer to interrupt object.
  248. //
  249. PKINTERRUPT InterruptObject;
  250. //
  251. // Mouse ISR DPC queue.
  252. //
  253. KDPC IsrDpc;
  254. //
  255. // Mouse ISR DPC recall queue.
  256. //
  257. KDPC IsrDpcRetry;
  258. //
  259. // Used by the ISR and the ISR DPC (in InpDpcVariableOperation calls)
  260. // to control processing by the ISR DPC.
  261. //
  262. LONG DpcInterlockVariable;
  263. //
  264. // Spinlock used to protect the DPC interlock variable.
  265. //
  266. KSPIN_LOCK SpinLock;
  267. //
  268. // Timer used to retry the ISR DPC routine when the class
  269. // driver is unable to consume all the port driver's data.
  270. //
  271. KTIMER DataConsumptionTimer;
  272. //
  273. // DPC queue for logging overrun and internal driver errors.
  274. //
  275. KDPC ErrorLogDpc;
  276. //
  277. // Request sequence number (used for error logging).
  278. //
  279. ULONG SequenceNumber;
  280. //
  281. // Indicates which pointer port device this driver created (UnitId
  282. // is the suffix appended to the pointer port basename for the
  283. // call to IoCreateDevice).
  284. //
  285. USHORT UnitId;
  286. //
  287. // Indicates whether it is okay to log overflow errors.
  288. //
  289. BOOLEAN OkayToLogOverflow;
  290. //
  291. // PnP State of the device
  292. //
  293. BOOLEAN Started, Removed, Stopped;
  294. #if defined(NEC_98)
  295. //
  296. // Currect power state that the device is in
  297. //
  298. DEVICE_POWER_STATE PowerState;
  299. #endif // defined(NEC_98)
  300. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  301. typedef struct _GLOBALS {
  302. UNICODE_STRING RegistryPath;
  303. #if defined(NEC_98)
  304. PDEVICE_OBJECT DeviceObject;
  305. #endif // defined(NEC_98)
  306. } GLOBALS;
  307. extern GLOBALS Globals;
  308. //
  309. // Define the port Get/SetDataQueuePointer context structures.
  310. //
  311. typedef struct _GET_DATA_POINTER_CONTEXT {
  312. IN PDEVICE_EXTENSION DeviceExtension;
  313. OUT PVOID DataIn;
  314. OUT PVOID DataOut;
  315. OUT ULONG InputCount;
  316. } GET_DATA_POINTER_CONTEXT, *PGET_DATA_POINTER_CONTEXT;
  317. typedef struct _SET_DATA_POINTER_CONTEXT {
  318. IN PDEVICE_EXTENSION DeviceExtension;
  319. IN ULONG InputCount;
  320. IN PVOID DataOut;
  321. } SET_DATA_POINTER_CONTEXT, *PSET_DATA_POINTER_CONTEXT;
  322. //
  323. // Define the context structure and operations for InpDpcVariableOperation.
  324. //
  325. typedef enum _OPERATION_TYPE {
  326. IncrementOperation,
  327. DecrementOperation,
  328. WriteOperation,
  329. ReadOperation
  330. } OPERATION_TYPE;
  331. typedef struct _VARIABLE_OPERATION_CONTEXT {
  332. IN PLONG VariableAddress;
  333. IN OPERATION_TYPE Operation;
  334. IN OUT PLONG NewValue;
  335. } VARIABLE_OPERATION_CONTEXT, *PVARIABLE_OPERATION_CONTEXT;
  336. //
  337. // Function prototypes.
  338. //
  339. NTSTATUS
  340. DriverEntry(
  341. IN PDRIVER_OBJECT DriverObject,
  342. IN PUNICODE_STRING RegistryPath
  343. );
  344. NTSTATUS
  345. InportAddDevice (
  346. IN PDRIVER_OBJECT Driver,
  347. IN PDEVICE_OBJECT PDO
  348. );
  349. VOID
  350. InportErrorLogDpc(
  351. IN PKDPC Dpc,
  352. IN PDEVICE_OBJECT DeviceObject,
  353. IN PIRP Irp,
  354. IN PVOID Context
  355. );
  356. NTSTATUS
  357. InportFlush(
  358. IN PDEVICE_OBJECT DeviceObject,
  359. IN PIRP Irp
  360. );
  361. NTSTATUS
  362. InportInternalDeviceControl(
  363. IN PDEVICE_OBJECT DeviceObject,
  364. IN PIRP Irp
  365. );
  366. BOOLEAN
  367. InportInterruptService(
  368. IN PKINTERRUPT Interrupt,
  369. IN PVOID Context
  370. );
  371. VOID
  372. InportIsrDpc(
  373. IN PKDPC Dpc,
  374. IN PDEVICE_OBJECT DeviceObject,
  375. IN PIRP Irp,
  376. IN PVOID Context
  377. );
  378. NTSTATUS
  379. InpStartDevice(
  380. IN OUT PDEVICE_EXTENSION DeviceExtension,
  381. IN PCM_RESOURCE_LIST ResourceList
  382. );
  383. NTSTATUS
  384. InportPnP(
  385. IN PDEVICE_OBJECT DeviceObject,
  386. IN PIRP Irp
  387. );
  388. NTSTATUS
  389. InportPower(
  390. IN PDEVICE_OBJECT DeviceObject,
  391. IN PIRP Irp
  392. );
  393. NTSTATUS
  394. InportCreate(
  395. IN PDEVICE_OBJECT DeviceObject,
  396. IN PIRP Irp
  397. );
  398. NTSTATUS
  399. InportClose(
  400. IN PDEVICE_OBJECT DeviceObject,
  401. IN PIRP Irp
  402. );
  403. VOID
  404. InportStartIo(
  405. IN PDEVICE_OBJECT DeviceObject,
  406. IN PIRP Irp
  407. );
  408. NTSTATUS
  409. InportSystemControl(
  410. IN PDEVICE_OBJECT DeviceObject,
  411. IN PIRP Irp
  412. );
  413. NTSTATUS
  414. InportSetWmiDataItem(
  415. IN PDEVICE_OBJECT DeviceObject,
  416. IN PIRP Irp,
  417. IN ULONG GuidIndex,
  418. IN ULONG InstanceIndex,
  419. IN ULONG DataItemId,
  420. IN ULONG BufferSize,
  421. IN PUCHAR Buffer
  422. );
  423. NTSTATUS
  424. InportSetWmiDataBlock(
  425. IN PDEVICE_OBJECT DeviceObject,
  426. IN PIRP Irp,
  427. IN ULONG GuidIndex,
  428. IN ULONG InstanceIndex,
  429. IN ULONG BufferSize,
  430. IN PUCHAR Buffer
  431. );
  432. NTSTATUS
  433. InportQueryWmiDataBlock(
  434. IN PDEVICE_OBJECT DeviceObject,
  435. IN PIRP Irp,
  436. IN ULONG GuidIndex,
  437. IN ULONG InstanceIndex,
  438. IN ULONG InstanceCount,
  439. IN OUT PULONG InstanceLengthArray,
  440. IN ULONG BufferAvail,
  441. OUT PUCHAR Buffer
  442. );
  443. NTSTATUS
  444. InportQueryWmiRegInfo(
  445. IN PDEVICE_OBJECT DeviceObject,
  446. OUT PULONG RegFlags,
  447. OUT PUNICODE_STRING InstanceName,
  448. OUT PUNICODE_STRING *RegistryPath,
  449. OUT PUNICODE_STRING MofResourceName,
  450. OUT PDEVICE_OBJECT *Pdo
  451. );
  452. extern WMIGUIDREGINFO WmiGuidList[1];
  453. VOID
  454. InportUnload(
  455. IN PDRIVER_OBJECT DriverObject
  456. );
  457. #if DBG
  458. VOID
  459. InpDebugPrint(
  460. ULONG DebugPrintLevel,
  461. PCCHAR DebugMessage,
  462. ...
  463. );
  464. #define InpPrint(x) InpDebugPrint x
  465. extern ULONG InportDebug;
  466. #else
  467. #define InpPrint(x)
  468. #endif
  469. VOID
  470. InpDisableInterrupts(
  471. IN PVOID Context
  472. );
  473. VOID
  474. InpDpcVariableOperation(
  475. IN PVOID Context
  476. );
  477. VOID
  478. InpEnableInterrupts(
  479. IN PVOID Context
  480. );
  481. VOID
  482. InpGetDataQueuePointer(
  483. IN PVOID Context
  484. );
  485. VOID
  486. InpInitializeDataQueue(
  487. IN PVOID Context
  488. );
  489. NTSTATUS
  490. InpInitializeHardware(
  491. IN PDEVICE_OBJECT DeviceObject
  492. );
  493. VOID
  494. InpServiceParameters(
  495. IN PDEVICE_EXTENSION DeviceExtension,
  496. IN PUNICODE_STRING RegistryPath
  497. );
  498. VOID
  499. InpSetDataQueuePointer(
  500. IN PVOID Context
  501. );
  502. BOOLEAN
  503. InpWriteDataToQueue(
  504. IN PDEVICE_EXTENSION DeviceExtension,
  505. IN PMOUSE_INPUT_DATA InputData
  506. );
  507. VOID
  508. InpLogError(
  509. IN PDEVICE_OBJECT DeviceObject,
  510. IN NTSTATUS ErrorCode,
  511. IN ULONG UniqueErrorValue,
  512. IN NTSTATUS FinalStatus,
  513. IN PULONG DumpData,
  514. IN ULONG DumpCount
  515. );
  516. NTSTATUS
  517. InpSendIrpSynchronously (
  518. IN PDEVICE_OBJECT DeviceObject,
  519. IN PIRP Irp
  520. );
  521. #if defined(NEC_98)
  522. BOOLEAN
  523. InportInterruptServiceDummy(
  524. IN PKINTERRUPT Interrupt,
  525. IN PDEVICE_OBJECT DeviceObject
  526. );
  527. ULONG
  528. QueryEventMode(
  529. IN OUT VOID
  530. );
  531. // Hibenation
  532. NTSTATUS
  533. InportPowerUpToD0Complete(
  534. IN PDEVICE_OBJECT DeviceObject,
  535. IN PIRP Irp,
  536. IN PVOID Context
  537. );
  538. VOID
  539. InportReinitializeHardware(
  540. PWORK_QUEUE_ITEM Item
  541. );
  542. #else
  543. //
  544. // Default values for hardware
  545. //
  546. #define INP_DEF_PORT 0x023c //0x0378
  547. #define INP_DEF_PORT_SPAN 4
  548. #define INP_DEF_IRQ 5 // Jumper dependent!!!!
  549. #define INP_DEF_VECTOR 5 // Jumper dependent!!!!
  550. VOID
  551. InpFilterResourceRequirements(
  552. IN PDEVICE_OBJECT DeviceObject,
  553. IN PIRP Irp
  554. );
  555. NTSTATUS
  556. InpFindResourcesCallout(
  557. IN PVOID Context,
  558. IN PUNICODE_STRING PathName,
  559. IN INTERFACE_TYPE BusType,
  560. IN ULONG BusNumber,
  561. IN PKEY_VALUE_FULL_INFORMATION *BusInformation,
  562. IN CONFIGURATION_TYPE ControllerType,
  563. IN ULONG ControllerNumber,
  564. IN PKEY_VALUE_FULL_INFORMATION *ControllerInformation,
  565. IN CONFIGURATION_TYPE PeripheralType,
  566. IN ULONG PeripheralNumber,
  567. IN PKEY_VALUE_FULL_INFORMATION *PeripheralInformation
  568. );
  569. #endif // defined(NEC_98)
  570. #endif // _INPORT_