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.

255 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. hidpen.c
  5. Abstract: Serial Pen Tablet HID Driver.
  6. Environment:
  7. Kernel mode
  8. Author:
  9. Michael Tsang (MikeTs) 13-Mar-2000
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. #ifdef ALLOC_PRAGMA
  14. #pragma alloc_text(INIT, DriverEntry)
  15. #pragma alloc_text(PAGE, HpenCreateClose)
  16. #pragma alloc_text(PAGE, HpenAddDevice)
  17. #pragma alloc_text(PAGE, HpenUnload)
  18. #endif //ifdef ALLOC_PRAGMA
  19. /*****************************************************************************
  20. *
  21. * @doc EXTERNAL
  22. *
  23. * @func NTSTATUS | DriverEntry |
  24. * Installable driver initialization entry point.
  25. * <nl>This entry point is called directly by the I/O system.
  26. *
  27. * @parm IN PDRIVER_OBJECT | DrvObj | Points to the driver object.
  28. * @parm IN PUNICODE_STRINT | RegPath | Points to the registry path.
  29. *
  30. * @rvalue SUCCESS | returns STATUS_SUCCESS
  31. * @rvalue FAILURE | returns NT status code
  32. *
  33. *****************************************************************************/
  34. NTSTATUS EXTERNAL
  35. DriverEntry(
  36. IN PDRIVER_OBJECT DrvObj,
  37. IN PUNICODE_STRING RegPath
  38. )
  39. {
  40. PROCNAME("DriverEntry")
  41. NTSTATUS status = STATUS_SUCCESS;
  42. HID_MINIDRIVER_REGISTRATION hidMinidriverRegistration;
  43. ENTER(1, ("(DrvObj=%p,RegPath=%p)\n", DrvObj, RegPath));
  44. DrvObj->MajorFunction[IRP_MJ_CREATE] =
  45. DrvObj->MajorFunction[IRP_MJ_CLOSE] = HpenCreateClose;
  46. DrvObj->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = HpenInternalIoctl;
  47. DrvObj->MajorFunction[IRP_MJ_PNP] = HpenPnp;
  48. DrvObj->MajorFunction[IRP_MJ_POWER] = HpenPower;
  49. DrvObj->DriverUnload = HpenUnload;
  50. DrvObj->DriverExtension->AddDevice = HpenAddDevice;
  51. //
  52. // Register with HIDCLASS.SYS module
  53. //
  54. RtlZeroMemory(&hidMinidriverRegistration,
  55. sizeof(hidMinidriverRegistration));
  56. hidMinidriverRegistration.Revision = HID_REVISION;
  57. hidMinidriverRegistration.DriverObject = DrvObj;
  58. hidMinidriverRegistration.RegistryPath = RegPath;
  59. hidMinidriverRegistration.DeviceExtensionSize = sizeof(DEVICE_EXTENSION);
  60. hidMinidriverRegistration.DevicesArePolled = FALSE;
  61. status = HidRegisterMinidriver(&hidMinidriverRegistration);
  62. if (NT_SUCCESS(status))
  63. {
  64. #ifdef DEBUG
  65. ExInitializeFastMutex(&gmutexDevExtList);
  66. InitializeListHead(&glistDevExtHead);
  67. #endif
  68. }
  69. else
  70. {
  71. ERRPRINT(("failed to register mini driver (status=%x)\n", status));
  72. }
  73. EXIT(1, ("=%x\n", status));
  74. return status;
  75. } //DriverEntry
  76. /*****************************************************************************
  77. *
  78. * @doc EXTERNAL
  79. *
  80. * @func NTSTATUS | HpenCreateClose |
  81. * Process the create and close IRPs sent to this device.
  82. *
  83. * @parm IN PDEVICE_OBJECT | DevObj | Points to the device object.
  84. * @parm IN PIRP | Irp | Points to an I/O Request Packet.
  85. *
  86. * @rvalue STATUS_SUCCESS | success
  87. * @rvalue STATUS_INVALID_PARAMETER | Irp not handled
  88. *
  89. *****************************************************************************/
  90. NTSTATUS EXTERNAL
  91. HpenCreateClose(
  92. IN PDEVICE_OBJECT DevObj,
  93. IN PIRP Irp
  94. )
  95. {
  96. PROCNAME("HpenCreateClose")
  97. NTSTATUS status = STATUS_SUCCESS;
  98. PIO_STACK_LOCATION irpsp;
  99. PAGED_CODE ();
  100. UNREFERENCED_PARAMETER(DevObj);
  101. irpsp = IoGetCurrentIrpStackLocation(Irp);
  102. ENTER(1, ("(DevObj=%p,Irp=%p,IrpStack=%p,Major=%s)\n",
  103. DevObj, Irp, irpsp,
  104. LookupName(irpsp->MajorFunction, MajorFnNames)));
  105. switch(irpsp->MajorFunction)
  106. {
  107. case IRP_MJ_CREATE:
  108. case IRP_MJ_CLOSE:
  109. Irp->IoStatus.Information = 0;
  110. break;
  111. default:
  112. ERRPRINT(("invalid major function %s\n",
  113. LookupName(irpsp->MajorFunction, MajorFnNames)));
  114. status = STATUS_INVALID_PARAMETER;
  115. break;
  116. }
  117. Irp->IoStatus.Status = status;
  118. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  119. EXIT(1, ("=%x\n", status));
  120. return status;
  121. } //HpenCreateClose
  122. /*****************************************************************************
  123. *
  124. * @doc EXTERNAL
  125. *
  126. * @func NTSTATUS | HpenAddDevice |
  127. * Called by hidclass, allows us to initialize our device extensions.
  128. *
  129. * @parm IN PDRIVER_OBJECT | DrvObj | Points to the driver object.
  130. * @parm IN PDEVICE_OBJECT | DevObj |
  131. * Points to a functional device object created by hidclass.
  132. *
  133. * @rvalue SUCCESS | Returns STATUS_SUCCESS.
  134. * @rvalue FAILURE | Returns NT status code.
  135. *
  136. *****************************************************************************/
  137. NTSTATUS EXTERNAL
  138. HpenAddDevice(
  139. IN PDRIVER_OBJECT DrvObj,
  140. IN PDEVICE_OBJECT DevObj
  141. )
  142. {
  143. PROCNAME("HpenAddDevice")
  144. NTSTATUS status;
  145. PDEVICE_EXTENSION devext;
  146. PAGED_CODE ();
  147. ENTER(1, ("(DrvObj=%p,DevObj=%p)\n", DrvObj, DevObj));
  148. ASSERT(DevObj != NULL);
  149. UNREFERENCED_PARAMETER(DrvObj);
  150. devext = GET_MINIDRIVER_DEVICE_EXTENSION(DevObj);
  151. RtlZeroMemory(devext, sizeof(*devext));
  152. devext->pdo = GET_PDO(DevObj);
  153. devext->SerialDevObj = GET_NEXT_DEVICE_OBJECT(DevObj);
  154. devext->ReadWorkItem[0].WorkItem = IoAllocateWorkItem(DevObj);
  155. if (devext->ReadWorkItem[0].WorkItem != NULL)
  156. {
  157. devext->ReadWorkItem[1].WorkItem = IoAllocateWorkItem(DevObj);
  158. if (devext->ReadWorkItem[1].WorkItem != NULL)
  159. {
  160. IoInitializeRemoveLock(&devext->RemoveLock, HPEN_POOL_TAG, 0, 10);
  161. KeInitializeSpinLock(&devext->SpinLock);
  162. devext->PowerState = PowerDeviceD0;
  163. #ifdef DEBUG
  164. ExAcquireFastMutex(&gmutexDevExtList);
  165. InsertTailList(&glistDevExtHead, &devext->List);
  166. ExReleaseFastMutex(&gmutexDevExtList);
  167. #endif
  168. OemAddDevice(devext);
  169. DevObj->Flags &= ~DO_DEVICE_INITIALIZING;
  170. DevObj->Flags |= DO_POWER_PAGABLE;
  171. status = STATUS_SUCCESS;
  172. }
  173. else
  174. {
  175. ERRPRINT(("failed to allocate second read work item\n"));
  176. IoFreeWorkItem(devext->ReadWorkItem[0].WorkItem);
  177. status = STATUS_INSUFFICIENT_RESOURCES;
  178. }
  179. }
  180. else
  181. {
  182. ERRPRINT(("failed to allocate first read work item\n"));
  183. status = STATUS_INSUFFICIENT_RESOURCES;
  184. }
  185. EXIT(1, ("=%x\n", status));
  186. return status;
  187. } //HpenAddDevice
  188. /*****************************************************************************
  189. *
  190. * @doc EXTERNAL
  191. *
  192. * @func void | HpenUnload | Free all the allocated resources, etc.
  193. *
  194. * @parm IN PDRIVER_OBJECT | DrvObj | Points to the driver object.
  195. *
  196. *****************************************************************************/
  197. VOID EXTERNAL
  198. HpenUnload(
  199. IN PDRIVER_OBJECT DrvObj
  200. )
  201. {
  202. PROCNAME("HpenUnload")
  203. PAGED_CODE();
  204. ENTER(1, ("(DrvObj=%p)\n", DrvObj));
  205. ASSERT(DrvObj->DeviceObject == NULL);
  206. UNREFERENCED_PARAMETER(DrvObj);
  207. EXIT(1, ("!\n"));
  208. return;
  209. } //HpenUnload