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.

297 lines
8.0 KiB

  1. /*++
  2. Copyright (c) 1991 - 2002 Microsoft Corporation
  3. Module Name:
  4. ## ## ### ## ## ##### ## ## ##### ### ##### #### ##### #####
  5. ### ### ## # ## ## ## ## ## ## ## ### ## ## ## # ## ## ## ##
  6. ######## ### #### ## #### ## ## ## ## ## ## ## ## ## ## ##
  7. # ### ## ### ### ##### #### ## ## ## ## ## ## ## ## ## ## ##
  8. # # ## ### #### ## ## ##### ####### ## ## ## ##### #####
  9. # ## # ## ## ## ## ## ## ## ## ## ## ## ## # ## ##
  10. # ## ### ## ## ##### ## ## ## ## ##### ## #### ## ##
  11. Abstract:
  12. This module contains the entire implementation of
  13. the virtual keypad miniport driver.
  14. @@BEGIN_DDKSPLIT
  15. Author:
  16. Wesley Witt (wesw) 1-Oct-2001
  17. @@END_DDKSPLIT
  18. Environment:
  19. Kernel mode only.
  20. Notes:
  21. --*/
  22. #include "mskeypad.h"
  23. #ifdef ALLOC_PRAGMA
  24. #pragma alloc_text(INIT,DriverEntry)
  25. #endif
  26. VOID
  27. MsKeypadCancelRoutine(
  28. IN PVOID DeviceExtensionIn,
  29. IN PIRP Irp,
  30. IN BOOLEAN CurrentIo
  31. )
  32. /*++
  33. Routine Description:
  34. This function is the miniport's IRP cancel routine.
  35. Arguments:
  36. DeviceExtension - Pointer to the mini-port's device extension.
  37. CurrentIo - TRUE if this is called for the current I/O
  38. Return Value:
  39. None.
  40. --*/
  41. {
  42. PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceExtensionIn;
  43. KIRQL OldIrql;
  44. if (CurrentIo) {
  45. KeAcquireSpinLock( &DeviceExtension->DeviceLock, &OldIrql );
  46. DeviceExtension->Keypress = 0;
  47. DeviceExtension->DataBuffer = NULL;
  48. KeReleaseSpinLock( &DeviceExtension->DeviceLock, OldIrql );
  49. }
  50. }
  51. NTSTATUS
  52. MsKeypadRead(
  53. IN PVOID DeviceExtensionIn,
  54. IN PIRP Irp,
  55. IN PVOID FsContext,
  56. IN LONGLONG StartingOffset,
  57. IN PVOID DataBuffer,
  58. IN ULONG DataBufferLength
  59. )
  60. /*++
  61. Routine Description:
  62. This routine processes the read requests for the local display miniport.
  63. Arguments:
  64. DeviceExtensionIn - Miniport's device extension
  65. StartingOffset - Starting offset for the I/O
  66. DataBuffer - Pointer to the data buffer
  67. DataBufferLength - Length of the data buffer in bytes
  68. Return Value:
  69. NT status code.
  70. --*/
  71. {
  72. PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceExtensionIn;
  73. KIRQL OldIrql;
  74. KeAcquireSpinLock( &DeviceExtension->DeviceLock, &OldIrql );
  75. if (DeviceExtension->Keypress) {
  76. *((PUCHAR)DataBuffer) = DeviceExtension->Keypress;
  77. KeReleaseSpinLock( &DeviceExtension->DeviceLock, OldIrql );
  78. return STATUS_SUCCESS;
  79. }
  80. DeviceExtension->DataBuffer = (PUCHAR) DataBuffer;
  81. KeReleaseSpinLock( &DeviceExtension->DeviceLock, OldIrql );
  82. return STATUS_PENDING;
  83. }
  84. NTSTATUS
  85. MsKeypadDeviceIoctl(
  86. IN PVOID DeviceExtensionIn,
  87. IN PIRP Irp,
  88. IN PVOID FsContext,
  89. IN ULONG FunctionCode,
  90. IN PVOID InputBuffer,
  91. IN ULONG InputBufferLength,
  92. IN PVOID OutputBuffer,
  93. IN ULONG OutputBufferLength
  94. )
  95. /*++
  96. Routine Description:
  97. This function is called by the SAPORT driver so that
  98. the mini-port driver can service an IOCTL call.
  99. Arguments:
  100. DeviceExtension - A pointer to the mini-port's device extension
  101. FunctionCode - The IOCTL function code
  102. InputBuffer - Pointer to the input buffer, contains the data sent down by the I/O
  103. InputBufferLength - Length in bytes of the InputBuffer
  104. OutputBuffer - Pointer to the output buffer, contains the data generated by this call
  105. OutputBufferLength - Length in bytes of the OutputBuffer
  106. Context:
  107. IRQL: IRQL PASSIVE_LEVEL, arbitrary thread context
  108. Return Value:
  109. If the function succeeds, it must return STATUS_SUCCESS.
  110. Otherwise, it must return one of the error status values defined in ntstatus.h.
  111. --*/
  112. {
  113. NTSTATUS Status = STATUS_SUCCESS;
  114. PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceExtensionIn;
  115. KIRQL OldIrql;
  116. switch (FunctionCode) {
  117. case FUNC_SA_GET_VERSION:
  118. *((PULONG)OutputBuffer) = SA_INTERFACE_VERSION;
  119. break;
  120. case FUNC_VDRIVER_INIT:
  121. if (InputBufferLength != sizeof(UCHAR) || InputBuffer == NULL) {
  122. return STATUS_BUFFER_TOO_SMALL;
  123. }
  124. KeAcquireSpinLock( &DeviceExtension->DeviceLock, &OldIrql );
  125. if (DeviceExtension->DataBuffer) {
  126. DeviceExtension->Keypress = *((PUCHAR)InputBuffer);
  127. DeviceExtension->DataBuffer[0] = DeviceExtension->Keypress;
  128. DeviceExtension->DataBuffer = NULL;
  129. KeReleaseSpinLock( &DeviceExtension->DeviceLock, OldIrql );
  130. SaPortCompleteRequest( DeviceExtension, NULL, sizeof(UCHAR), STATUS_SUCCESS, TRUE );
  131. KeAcquireSpinLock( &DeviceExtension->DeviceLock, &OldIrql );
  132. DeviceExtension->Keypress = 0;
  133. }
  134. KeReleaseSpinLock( &DeviceExtension->DeviceLock, OldIrql );
  135. break;
  136. default:
  137. Status = STATUS_NOT_SUPPORTED;
  138. REPORT_ERROR( SA_DEVICE_KEYPAD, "Unsupported device control", Status );
  139. break;
  140. }
  141. return Status;
  142. }
  143. NTSTATUS
  144. MsKeypadHwInitialize(
  145. IN PDEVICE_OBJECT DeviceObject,
  146. IN PIRP Irp,
  147. IN PVOID DeviceExtensionIn,
  148. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialResources,
  149. IN ULONG PartialResourceCount
  150. )
  151. /*++
  152. Routine Description:
  153. This function is called by the SAPORT driver so that
  154. the mini-port driver can initialize it's hardware
  155. resources.
  156. Arguments:
  157. DeviceObject - Pointer to the target device object.
  158. Irp - Pointer to an IRP structure that describes the requested I/O operation.
  159. DeviceExtension - A pointer to the mini-port's device extension.
  160. PartialResources - Pointer to the translated resources alloacted by the system.
  161. PartialResourceCount - The number of resources in the PartialResources array.
  162. Context:
  163. IRQL: IRQL PASSIVE_LEVEL, system thread context
  164. Return Value:
  165. If the function succeeds, it must return STATUS_SUCCESS.
  166. Otherwise, it must return one of the error status values defined in ntstatus.h.
  167. --*/
  168. {
  169. PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION) DeviceExtensionIn;
  170. KeInitializeSpinLock( &DeviceExtension->DeviceLock );
  171. return STATUS_SUCCESS;
  172. }
  173. NTSTATUS
  174. DriverEntry(
  175. IN PDRIVER_OBJECT DriverObject,
  176. IN PUNICODE_STRING RegistryPath
  177. )
  178. /*++
  179. Routine Description:
  180. This routine is the driver's entry point, called by the I/O system
  181. to load the driver. The driver's entry points are initialized and
  182. a spin lock to control paging is initialized.
  183. In DBG mode, this routine also examines the registry for special
  184. debug parameters.
  185. Arguments:
  186. DriverObject - a pointer to the object that represents this device driver.
  187. RegistryPath - a pointer to this driver's key in the Services tree.
  188. Return Value:
  189. STATUS_SUCCESS
  190. --*/
  191. {
  192. NTSTATUS Status;
  193. SAPORT_INITIALIZATION_DATA SaPortInitData;
  194. RtlZeroMemory( &SaPortInitData, sizeof(SAPORT_INITIALIZATION_DATA) );
  195. SaPortInitData.StructSize = sizeof(SAPORT_INITIALIZATION_DATA);
  196. SaPortInitData.DeviceType = SA_DEVICE_KEYPAD;
  197. SaPortInitData.HwInitialize = MsKeypadHwInitialize;
  198. SaPortInitData.DeviceIoctl = MsKeypadDeviceIoctl;
  199. SaPortInitData.Read = MsKeypadRead;
  200. SaPortInitData.CancelRoutine = MsKeypadCancelRoutine;
  201. SaPortInitData.DeviceExtensionSize = sizeof(DEVICE_EXTENSION);
  202. Status = SaPortInitialize( DriverObject, RegistryPath, &SaPortInitData );
  203. if (!NT_SUCCESS(Status)) {
  204. REPORT_ERROR( SA_DEVICE_KEYPAD, "SaPortInitialize failed\n", Status );
  205. return Status;
  206. }
  207. return STATUS_SUCCESS;
  208. }