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.

410 lines
10 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name :
  4. serscan.h
  5. Abstract:
  6. Type definitions and data for the serial imaging driver.
  7. Author:
  8. Revision History:
  9. --*/
  10. #include "wdm.h"
  11. //#include <ntddk.h>
  12. #include <ntddser.h>
  13. #if DBG
  14. #define SERALWAYS ((ULONG)0x00000000)
  15. #define SERCONFIG ((ULONG)0x00000001)
  16. #define SERUNLOAD ((ULONG)0x00000002)
  17. #define SERINITDEV ((ULONG)0x00000004)
  18. #define SERIRPPATH ((ULONG)0x00000008)
  19. #define SERSTARTER ((ULONG)0x00000010)
  20. #define SERPUSHER ((ULONG)0x00000020)
  21. #define SERERRORS ((ULONG)0x00000040)
  22. #define SERTHREAD ((ULONG)0x00000080)
  23. #define SERDEFERED ((ULONG)0x00000100)
  24. extern ULONG SerScanDebugLevel;
  25. #define DebugDump(LEVEL,STRING) \
  26. do { \
  27. ULONG _level = (LEVEL); \
  28. if ((_level == SERALWAYS)||(SerScanDebugLevel & _level)) { \
  29. DbgPrint ("SERSCAN.SYS:"); \
  30. DbgPrint STRING; \
  31. } \
  32. } while (0)
  33. //
  34. // macro for doing INT 3 (or non-x86 equivalent)
  35. //
  36. #if _X86_
  37. #define DEBUG_BREAKPOINT() _asm int 3;
  38. #else
  39. #define DEBUG_BREAKPOINT() DbgBreakPoint()
  40. #endif
  41. #else
  42. #define DEBUG_BREAKPOINT()
  43. #define DebugDump(LEVEL,STRING) do {NOTHING;} while (0)
  44. #endif
  45. #ifdef POOL_TAGGING
  46. #ifdef ExAllocatePool
  47. #undef ExAllocatePool
  48. #endif
  49. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'SerC')
  50. #endif
  51. //
  52. // For the above directory, the serial port will
  53. // use the following name as the suffix of the serial
  54. // ports for that directory. It will also append
  55. // a number onto the end of the name. That number
  56. // will start at 1.
  57. //
  58. #define SERSCAN_LINK_NAME L"SERSCAN"
  59. //
  60. // This is the class name.
  61. //
  62. #define SERSCAN_NT_SUFFIX L"serscan"
  63. #define SERIAL_DATA_OFFSET 0
  64. #define SERIAL_STATUS_OFFSET 1
  65. #define SERIAL_CONTROL_OFFSET 2
  66. #define SERIAL_REGISTER_SPAN 3
  67. typedef struct _DEVICE_EXTENSION {
  68. //
  69. // Points to the device object that contains
  70. // this device extension.
  71. //
  72. PDEVICE_OBJECT DeviceObject;
  73. //
  74. //
  75. //
  76. PDEVICE_OBJECT Pdo;
  77. //
  78. // Points to the lower in stack device object that this device is
  79. // connected to.
  80. //
  81. PDEVICE_OBJECT LowerDevice;
  82. //
  83. // To connect to lower object when opening
  84. //
  85. PDEVICE_OBJECT AttachedDeviceObject;
  86. PFILE_OBJECT AttachedFileObject;
  87. //
  88. //
  89. //
  90. PVOID SerclassContext;
  91. ULONG HardwareCapabilities;
  92. //
  93. // Records whether we actually created the symbolic link name
  94. // at driver load time. If we didn't create it, we won't try
  95. // to distroy it when we unload.
  96. //
  97. BOOLEAN CreatedSymbolicLink;
  98. //
  99. // This points to the symbolic link name that was
  100. // linked to the actual nt device name.
  101. //
  102. UNICODE_STRING SymbolicLinkName;
  103. //
  104. // This points to the class name used to create the
  105. // device and the symbolic link. We carry this
  106. // around for a short while...
  107. UNICODE_STRING ClassName;
  108. //
  109. //
  110. //
  111. UNICODE_STRING InterfaceNameString;
  112. //
  113. // This tells us whether we are in a passthrough
  114. // or filtering mode.
  115. BOOLEAN PassThrough;
  116. //
  117. // Number of opens on this device
  118. //
  119. ULONG OpenCount;
  120. //
  121. // Access control
  122. //
  123. // ERESOURCE Resource;
  124. FAST_MUTEX Mutex;
  125. KSPIN_LOCK SpinLock;
  126. //
  127. // Life span control
  128. //
  129. LONG ReferenceCount;
  130. BOOLEAN Removing;
  131. KEVENT RemoveEvent;
  132. KEVENT PdoStartEvent;
  133. //KEVENT PendingIoEvent;
  134. //ULONG PendingIoCount;
  135. DEVICE_POWER_STATE SystemPowerStateMap[PowerSystemMaximum];
  136. SYSTEM_POWER_STATE SystemWake;
  137. DEVICE_POWER_STATE DeviceWake;
  138. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  139. //
  140. // Bit Definitions in the status register.
  141. //
  142. #define SER_STATUS_NOT_ERROR 0x08 //not error on device
  143. #define SER_STATUS_SLCT 0x10 //device is selected (on-line)
  144. #define SER_STATUS_PE 0x20 //paper empty
  145. #define SER_STATUS_NOT_ACK 0x40 //not acknowledge (data transfer was not ok)
  146. #define SER_STATUS_NOT_BUSY 0x80 //operation in progress
  147. //
  148. // Bit Definitions in the control register.
  149. //
  150. #define SER_CONTROL_STROBE 0x01 //to read or write data
  151. #define SER_CONTROL_AUTOFD 0x02 //to autofeed continuous form paper
  152. #define SER_CONTROL_NOT_INIT 0x04 //begin an initialization routine
  153. #define SER_CONTROL_SLIN 0x08 //to select the device
  154. #define SER_CONTROL_IRQ_ENB 0x10 //to enable interrupts
  155. #define SER_CONTROL_DIR 0x20 //direction = read
  156. #define SER_CONTROL_WR_CONTROL 0xc0 //the 2 highest bits of the control
  157. // register must be 1
  158. #define StoreData(RegisterBase,DataByte) \
  159. { \
  160. PUCHAR _Address = RegisterBase; \
  161. UCHAR _Control; \
  162. _Control = GetControl(_Address); \
  163. ASSERT(!(_Control & SER_CONTROL_STROBE)); \
  164. StoreControl( \
  165. _Address, \
  166. (UCHAR)(_Control & ~(SER_CONTROL_STROBE | SER_CONTROL_DIR)) \
  167. ); \
  168. WRITE_PORT_UCHAR( \
  169. _Address+SERIAL_DATA_OFFSET, \
  170. (UCHAR)DataByte \
  171. ); \
  172. KeStallExecutionProcessor((ULONG)1); \
  173. StoreControl( \
  174. _Address, \
  175. (UCHAR)((_Control | SER_CONTROL_STROBE) & ~SER_CONTROL_DIR) \
  176. ); \
  177. KeStallExecutionProcessor((ULONG)1); \
  178. StoreControl( \
  179. _Address, \
  180. (UCHAR)(_Control & ~(SER_CONTROL_STROBE | SER_CONTROL_DIR)) \
  181. ); \
  182. KeStallExecutionProcessor((ULONG)1); \
  183. StoreControl( \
  184. _Address, \
  185. (UCHAR)_Control \
  186. ); \
  187. }
  188. #define GetControl(RegisterBase) \
  189. (READ_PORT_UCHAR((RegisterBase)+SERIAL_CONTROL_OFFSET))
  190. #define StoreControl(RegisterBase,ControlByte) \
  191. { \
  192. WRITE_PORT_UCHAR( \
  193. (RegisterBase)+SERIAL_CONTROL_OFFSET, \
  194. (UCHAR)ControlByte \
  195. ); \
  196. }
  197. #define GetStatus(RegisterBase) \
  198. (READ_PORT_UCHAR((RegisterBase)+SERIAL_STATUS_OFFSET))
  199. //
  200. // Macros
  201. //
  202. //
  203. // Prototypes
  204. //
  205. NTSTATUS
  206. SerScanCreateOpen(
  207. IN PDEVICE_OBJECT DeviceObject,
  208. IN PIRP Irp
  209. );
  210. NTSTATUS
  211. SerScanClose(
  212. IN PDEVICE_OBJECT DeviceObject,
  213. IN PIRP Irp
  214. );
  215. NTSTATUS
  216. SerScanCleanup(
  217. IN PDEVICE_OBJECT DeviceObject,
  218. IN PIRP Irp
  219. );
  220. NTSTATUS
  221. SerScanReadWrite(
  222. IN PDEVICE_OBJECT DeviceObject,
  223. IN PIRP Irp
  224. );
  225. NTSTATUS
  226. SerScanDeviceControl(
  227. IN PDEVICE_OBJECT DeviceObject,
  228. IN PIRP Irp
  229. );
  230. NTSTATUS
  231. SerScanQueryInformationFile(
  232. IN PDEVICE_OBJECT DeviceObject,
  233. IN PIRP Irp
  234. );
  235. NTSTATUS
  236. SerScanSetInformationFile(
  237. IN PDEVICE_OBJECT DeviceObject,
  238. IN PIRP Irp
  239. );
  240. NTSTATUS
  241. SerScanPower(
  242. IN PDEVICE_OBJECT pDeviceObject,
  243. IN PIRP pIrp
  244. );
  245. VOID
  246. SerScanUnload(
  247. IN PDRIVER_OBJECT DriverObject
  248. );
  249. NTSTATUS
  250. SerScanHandleSymbolicLink(
  251. PDEVICE_OBJECT DeviceObject,
  252. PUNICODE_STRING InterfaceName,
  253. BOOLEAN Create
  254. );
  255. NTSTATUS
  256. SerScanPassThrough(
  257. IN PDEVICE_OBJECT DeviceObject,
  258. IN PIRP Irp
  259. );
  260. NTSTATUS
  261. DriverEntry(
  262. IN PDRIVER_OBJECT DriverObject,
  263. IN PUNICODE_STRING RegistryPath
  264. );
  265. NTSTATUS
  266. SerScanAddDevice(
  267. IN PDRIVER_OBJECT pDriverObject,
  268. IN PDEVICE_OBJECT pPhysicalDeviceObject
  269. );
  270. NTSTATUS
  271. SerScanPnp (
  272. IN PDEVICE_OBJECT pDeviceObject,
  273. IN PIRP pIrp
  274. );
  275. BOOLEAN
  276. SerScanMakeNames(
  277. IN ULONG SerialPortNumber,
  278. OUT PUNICODE_STRING ClassName,
  279. OUT PUNICODE_STRING LinkName
  280. );
  281. VOID
  282. SerScanLogError(
  283. IN PDRIVER_OBJECT DriverObject,
  284. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  285. IN PHYSICAL_ADDRESS P1,
  286. IN PHYSICAL_ADDRESS P2,
  287. IN ULONG SequenceNumber,
  288. IN UCHAR MajorFunctionCode,
  289. IN UCHAR RetryCount,
  290. IN ULONG UniqueErrorValue,
  291. IN NTSTATUS FinalStatus,
  292. IN NTSTATUS SpecificIOStatus
  293. );
  294. NTSTATUS
  295. SerScanSynchCompletionRoutine(
  296. IN PDEVICE_OBJECT DeviceObject,
  297. IN PIRP Irp,
  298. IN PKEVENT Event
  299. );
  300. NTSTATUS
  301. SerScanCompleteIrp(
  302. IN PDEVICE_OBJECT DeviceObject,
  303. IN PIRP Irp,
  304. IN PVOID Context
  305. );
  306. #define WAIT 1
  307. #define NO_WAIT 0
  308. NTSTATUS
  309. SerScanCallParent(
  310. IN PDEVICE_EXTENSION Extension,
  311. IN PIRP Irp,
  312. IN BOOLEAN Wait,
  313. IN PIO_COMPLETION_ROUTINE CompletionRoutine
  314. );
  315. NTSTATUS
  316. SerScanQueueIORequest(
  317. IN PDEVICE_EXTENSION Extension,
  318. IN PIRP Irp
  319. );
  320. VOID
  321. SSIncrementIoCount(
  322. IN PDEVICE_OBJECT pDeviceObject
  323. );
  324. LONG
  325. SSDecrementIoCount(
  326. IN PDEVICE_OBJECT pDeviceObject
  327. );
  328. NTSTATUS
  329. WaitForLowerDriverToCompleteIrp(
  330. PDEVICE_OBJECT TargetDeviceObject,
  331. PIRP Irp,
  332. PKEVENT Event
  333. );