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.

267 lines
6.8 KiB

  1. /***************************************************************************
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. UTILS.H
  5. Abstract:
  6. Header file for routines that don't fit anywhere else.
  7. Environment:
  8. kernel mode only
  9. Notes:
  10. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  11. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  12. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  13. PURPOSE.
  14. Copyright (c) 1998 Microsoft Corporation. All Rights Reserved.
  15. Revision History:
  16. 12/23/97 : created
  17. Authors:
  18. Tom Green
  19. ****************************************************************************/
  20. #ifndef __UTILS_H__
  21. #define __UTILS_H__
  22. // state machine defines for restarting reads from completion routines
  23. #define START_READ 0x0001
  24. #define IMMEDIATE_READ 0x0002
  25. #define END_READ 0x0003
  26. //
  27. // State machine defines for LSRMST insertion
  28. //
  29. #define USBSER_ESCSTATE_DATA 1
  30. #define USBSER_ESCSTATE_NODATA 2
  31. #define USBSER_ESCSTATE_LINESTATUS 3
  32. NTSTATUS
  33. UsbSerGetRegistryKeyValue(IN HANDLE Handle, IN PWCHAR PKeyNameString,
  34. IN ULONG KeyNameStringLength, IN PVOID PData,
  35. IN ULONG DataLength);
  36. VOID
  37. UsbSerUndoExternalNaming(IN PDEVICE_EXTENSION PDevExt);
  38. NTSTATUS
  39. UsbSerDoExternalNaming(IN PDEVICE_EXTENSION PDevExt);
  40. NTSTATUS
  41. StartDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  42. NTSTATUS
  43. StopDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  44. NTSTATUS
  45. RemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  46. NTSTATUS
  47. CreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
  48. IN PDEVICE_OBJECT *DeviceObject,
  49. IN PCHAR DeviceName);
  50. VOID
  51. CompleteIO(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
  52. IN ULONG MajorFunction, IN PVOID IoBuffer,
  53. IN ULONG_PTR BufferLen);
  54. NTSTATUS
  55. DeleteObjectAndLink(IN PDEVICE_OBJECT DeviceObject);
  56. VOID
  57. StartPerfTimer(IN OUT PDEVICE_EXTENSION DeviceExtension);
  58. VOID
  59. StopPerfTimer(IN OUT PDEVICE_EXTENSION DeviceExtension,
  60. IN ULONG BytesXfered);
  61. ULONG
  62. BytesPerSecond(IN OUT PDEVICE_EXTENSION DeviceExtension);
  63. NTSTATUS
  64. CallUSBD(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb);
  65. NTSTATUS
  66. CallUSBD_SyncCompletionRoutine(IN PDEVICE_OBJECT DeviceObject,
  67. IN PIRP Irp,
  68. IN PVOID Context);
  69. NTSTATUS
  70. GetDeviceDescriptor(IN PDEVICE_OBJECT DeviceObject);
  71. NTSTATUS
  72. ConfigureDevice(IN PDEVICE_OBJECT DeviceObject);
  73. NTSTATUS
  74. SelectInterface(IN PDEVICE_OBJECT DeviceObject,
  75. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor);
  76. PURB
  77. BuildRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
  78. IN USBD_PIPE_HANDLE PipeHandle, IN BOOLEAN Read);
  79. VOID
  80. BuildReadRequest(PURB Urb, PUCHAR Buffer, ULONG Length,
  81. IN USBD_PIPE_HANDLE PipeHandle, IN BOOLEAN Read);
  82. NTSTATUS
  83. ClassVendorCommand(IN PDEVICE_OBJECT DeviceObject, IN UCHAR Request,
  84. IN USHORT Value, IN USHORT Index, IN PVOID Buffer,
  85. IN OUT PULONG BufferLen, IN BOOLEAN Read, IN ULONG ComType);
  86. VOID
  87. CancelPendingWaitMasks(IN PDEVICE_EXTENSION DeviceExtension);
  88. VOID
  89. CancelPendingNotifyOrRead(IN PDEVICE_EXTENSION DeviceExtension,
  90. IN BOOLEAN Notify);
  91. VOID
  92. StartRead(IN PDEVICE_EXTENSION DeviceExtension);
  93. VOID
  94. RestartRead(IN PDEVICE_EXTENSION DeviceExtension);
  95. VOID
  96. StartNotifyRead(IN PDEVICE_EXTENSION DeviceExtension);
  97. VOID
  98. RestartNotifyRead(IN PDEVICE_EXTENSION DeviceExtension);
  99. NTSTATUS
  100. ReadCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context);
  101. ULONG
  102. GetData(IN PDEVICE_EXTENSION DeviceExtension, IN PCHAR Buffer,
  103. IN ULONG BufferLen, IN OUT PULONG_PTR NewCount);
  104. VOID
  105. PutData(IN PDEVICE_EXTENSION DeviceExtension, IN ULONG BufferLen);
  106. VOID
  107. CheckForQueuedReads(IN PDEVICE_EXTENSION DeviceExtension);
  108. NTSTATUS
  109. UsbSerSyncCompletion(IN PDEVICE_OBJECT PDevObj, IN PIRP PIrp,
  110. IN PKEVENT PUsbSerSyncEvent);
  111. VOID
  112. UsbSerFetchBooleanLocked(PBOOLEAN PDest, BOOLEAN Src,
  113. PKSPIN_LOCK PSpinLock);
  114. VOID
  115. UsbSerFetchPVoidLocked(PVOID *PDest, PVOID Src, PKSPIN_LOCK PSpinLock);
  116. VOID
  117. UsbSerRundownIrpRefs(IN PIRP *PpCurrentOpIrp, IN PKTIMER IntervalTimer OPTIONAL,
  118. IN PKTIMER TotalTimer OPTIONAL,
  119. IN PDEVICE_EXTENSION PDevExt);
  120. VOID
  121. UsbSerGetNextIrp(IN PIRP *PpCurrentOpIrp, IN PLIST_ENTRY PQueueToProcess,
  122. OUT PIRP *PpNextIrp, IN BOOLEAN CompleteCurrent,
  123. IN PDEVICE_EXTENSION PDevExt);
  124. NTSTATUS
  125. UsbSerAbortPipes(IN PDEVICE_OBJECT PDevObj);
  126. VOID
  127. USBSER_RestartNotifyReadWorkItem(IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_EXTENSION DeviceExtension);
  128. #if DBG
  129. PVOID
  130. UsbSerLockPagableCodeSection(PVOID SecFunc);
  131. #define UsbSerLockPagableSectionByHandle(_secHandle) \
  132. { \
  133. MmLockPagableSectionByHandle((_secHandle)); \
  134. InterlockedIncrement(&PAGEUSBSER_Count); \
  135. }
  136. #define UsbSerUnlockPagableImageSection(_secHandle) \
  137. { \
  138. InterlockedDecrement(&PAGEUSBSER_Count); \
  139. MmUnlockPagableImageSection(_secHandle); \
  140. }
  141. //
  142. // Use if code can be called non-locked at lower irql
  143. //
  144. #define USBSER_LOCKED_PAGED_CODE() \
  145. if ((KeGetCurrentIrql() > APC_LEVEL) \
  146. && (PAGEUSBSER_Count == 0)) { \
  147. KdPrint(("USBSER: Pageable code called at IRQL %d without lock \n", \
  148. KeGetCurrentIrql())); \
  149. ASSERT(FALSE); \
  150. }
  151. //
  152. // Use if code must always be locked; e.g., the function grabs a spinlock
  153. //
  154. #define USBSER_ALWAYS_LOCKED_CODE() \
  155. if (PAGEUSBSER_Count == 0) { \
  156. KdPrint(("USBSER: Pagable code raises IRQL called without lock\n")); \
  157. ASSERT(FALSE); \
  158. }
  159. #define UsbSerAcquireSpinLock(_pLock, _pIrql) \
  160. { \
  161. ASSERTMSG(PAGEUSBSER_Count, "USBSER: Acquire spinlock without paging lock\n")); \
  162. KeAcquireSpinLock((_pLock), (_pIrql)); \
  163. }
  164. #define UsbSerReleaseSpinLock(_pLock, Irql) \
  165. { \
  166. ASSERTMSG(PAGEUSBSER_Count, "USBSER: Release spinlock and paging unlocked\n")); \
  167. KeReleaseSpinLock((_pLock), (_pIrql)); \
  168. }
  169. #else
  170. #define UsbSerLockPagableCodeSection(_secFunc) \
  171. MmLockPagableCodeSection((_secFunc))
  172. #define UsbSerLockPagableSectionByHandle(_secHandle) \
  173. { \
  174. MmLockPagableSectionByHandle((_secHandle)); \
  175. }
  176. #define UsbSerUnlockPagableImageSection(_secHandle) \
  177. { \
  178. MmUnlockPagableImageSection(_secHandle); \
  179. }
  180. #define USBSER_LOCKED_PAGED_CODE()
  181. #define USBSER_ALWAYS_LOCKED_CODE()
  182. #define UsbSerAcquireSpinLock(_pLock, _pIrql) \
  183. KeAcquireSpinLock((_pLock), (_pIrql))
  184. #define UsbSerReleaseSpinLock(_pLock, Irql) \
  185. KeReleaseSpinLock((_pLock), (_pIrql))
  186. #endif // DBG
  187. #endif // __UTILS_H__