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.

1153 lines
30 KiB

  1. /*++
  2. Module Name:
  3. moxa.h
  4. Environment:
  5. Kernel mode
  6. Revision History :
  7. --*/
  8. #define CONTROL_DEVICE_NAME L"\\Device\\MxCtl"
  9. #define CONTROL_DEVICE_LINK L"\\DosDevices\\MXCTL"
  10. //#define MOXA_DEVICE_NAME L"\\Device\\Mx000"
  11. //#define MOXA_DEVICE_LINK L"\\DosDevices\\COMxxx"
  12. //
  13. // This define gives the default Object directory
  14. // that we should use to insert the symbolic links
  15. // between the NT device name and namespace used by
  16. // that object directory.
  17. #define DEFAULT_DIRECTORY L"DosDevices"
  18. #ifdef DEFINE_GUID
  19. // {12FC95C1-CD81-11d3-84D5-0000E8CBD321}
  20. #define MOXA_WMI_PORT_STATUS_GUID \
  21. { 0x12fc95c1, 0xcd81, 0x11d3, 0x84, 0xd5, 0x0, 0x0, 0xe8, 0xcb, 0xd3, 0x21}
  22. DEFINE_GUID(MoxaWmiPortStatusGuid,
  23. 0x12fc95c1, 0xcd81, 0x11d3, 0x84, 0xd5, 0x0, 0x0, 0xe8, 0xcb, 0xd3, 0x21);
  24. #endif
  25. typedef struct _MOXA_WMI_PORT_STATUS
  26. {
  27. // The BaudRate property indicates the baud rate for this serial port
  28. USHORT LineStatus;
  29. USHORT FlowControl;
  30. } MOXA_WMI_PORT_STATUS, *PMOXA_WMI_PORT_STATUS;
  31. //
  32. // Extension IoControlCode values for MOXA device.
  33. //
  34. #define MOXA_IOCTL 0x800
  35. #define IOCTL_MOXA_Driver CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+0,METHOD_BUFFERED,FILE_ANY_ACCESS)
  36. #define IOCTL_MOXA_LineInput CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+6,METHOD_BUFFERED,FILE_ANY_ACCESS)
  37. #define IOCTL_MOXA_OQueue CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+11,METHOD_BUFFERED,FILE_ANY_ACCESS)
  38. #define IOCTL_MOXA_IQueue CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+13,METHOD_BUFFERED,FILE_ANY_ACCESS)
  39. #define IOCTL_MOXA_View CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+14,METHOD_BUFFERED,FILE_ANY_ACCESS)
  40. #define IOCTL_MOXA_TxLowWater CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+15,METHOD_BUFFERED,FILE_ANY_ACCESS)
  41. #define IOCTL_MOXA_Statistic CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+16,METHOD_BUFFERED,FILE_ANY_ACCESS)
  42. #define IOCTL_MOXA_LoopBack CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+17,METHOD_BUFFERED,FILE_ANY_ACCESS)
  43. #define IOCTL_MOXA_UARTTest CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+18,METHOD_BUFFERED,FILE_ANY_ACCESS)
  44. #define IOCTL_MOXA_IRQTest CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+19,METHOD_BUFFERED,FILE_ANY_ACCESS)
  45. #define IOCTL_MOXA_LineStatus CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+20,METHOD_BUFFERED,FILE_ANY_ACCESS)
  46. #define IOCTL_MOXA_PortStatus CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+21,METHOD_BUFFERED,FILE_ANY_ACCESS)
  47. #define IOCTL_MOXA_Linked CTL_CODE(FILE_DEVICE_SERIAL_PORT, MOXA_IOCTL+27,METHOD_BUFFERED,FILE_ANY_ACCESS)
  48. #define IOCTL_MOXA_INTERNAL_BASIC_SETTINGS CTL_CODE(FILE_DEVICE_SERIAL_PORT,MOXA_IOCTL+30, METHOD_BUFFERED, FILE_ANY_ACCESS)
  49. #define IOCTL_MOXA_INTERNAL_BOARD_READY CTL_CODE(FILE_DEVICE_SERIAL_PORT,MOXA_IOCTL+31, METHOD_BUFFERED, FILE_ANY_ACCESS)
  50. //
  51. #define MAX_COM 256
  52. //
  53. // status code for MOXA_IOCTL_Driver
  54. //
  55. #define MX_DRIVER 0x405
  56. //
  57. // Definitions for MOXA cards
  58. //
  59. #define MAX_CARD 4
  60. #define MAX_TYPE 6
  61. #define MAXPORT_PER_CARD 32
  62. #define MAX_PORT 128
  63. #define C218ISA 1
  64. #define C218PCI 2
  65. #define C320ISA 3
  66. #define C320PCI 4
  67. #define CP204J 5
  68. //
  69. // for C218/CP204J BIOS initialization
  70. //
  71. #define C218_ConfBase 0x800
  72. #define C218_status (C218_ConfBase + 0) /* BIOS running status */
  73. #define C218_diag (C218_ConfBase + 2) /* diagnostic status */
  74. #define C218_key (C218_ConfBase + 4) /* WORD (0x218 for C218)*/
  75. #define C218DLoad_len (C218_ConfBase + 6) /* WORD */
  76. #define C218check_sum (C218_ConfBase + 8) /* BYTE */
  77. #define C218chksum_ok (C218_ConfBase + 0x0a) /* BYTE (1:ok) */
  78. #define C218_TestRx (C218_ConfBase + 0x10) /* 8 bytes for 8 ports */
  79. #define C218_TestTx (C218_ConfBase + 0x18) /* 8 bytes for 8 ports */
  80. #define C218_RXerr (C218_ConfBase + 0x20) /* 8 bytes for 8 ports */
  81. #define C218_ErrFlag (C218_ConfBase + 0x28) /* 8 bytes for 8 ports */
  82. #define C218_TestCnt C218_ConfBase + 0x30 /* 8 words for 8 ports */
  83. #define C218_LoadBuf 0x0f00
  84. #define C218_KeyCode 0x218
  85. /*
  86. * for C320 BIOS initialization
  87. */
  88. #define C320_ConfBase 0x800
  89. #define C320_status C320_ConfBase + 0 /* BIOS running status */
  90. #define C320_diag C320_ConfBase + 2 /* diagnostic status */
  91. #define C320_key C320_ConfBase + 4 /* WORD (0320H for C320)*/
  92. #define C320DLoad_len C320_ConfBase + 6 /* WORD */
  93. #define C320check_sum C320_ConfBase + 8 /* WORD */
  94. #define C320chksum_ok C320_ConfBase + 0x0a /* WORD (1:ok) */
  95. #define C320bapi_len C320_ConfBase + 0x0c /* WORD */
  96. #define C320UART_no C320_ConfBase + 0x0e /* WORD */
  97. #define C320B_unlinked (Config_base + 16)
  98. #define C320_runOK (Config_base + 18)
  99. #define Disable_Irq (Config_base + 20)
  100. #define TMS320Port1 (Config_base + 22)
  101. #define TMS320Port2 (Config_base + 24)
  102. #define TMS320Clock (Config_base + 26)
  103. #define STS_init 0x05 /* for C320_status */
  104. #define C320_LoadBuf 0x0f00
  105. #define C320_KeyCode 0x320
  106. #define FixPage_addr 0x0000 /* starting addr of static page */
  107. #define DynPage_addr 0x2000 /* starting addr of dynamic page */
  108. #define Control_reg 0x1ff0 /* select page and reset control */
  109. #define HW_reset 0x80
  110. //
  111. // Function Codes
  112. //
  113. #define FC_CardReset 0x80
  114. #define FC_ChannelReset 1
  115. #define FC_EnableCH 2
  116. #define FC_DisableCH 3
  117. #define FC_SetParam 4
  118. #define FC_SetMode 5
  119. #define FC_SetRate 6
  120. #define FC_LineControl 7
  121. #define FC_LineStatus 8
  122. #define FC_XmitControl 9
  123. #define FC_FlushQueue 10
  124. #define FC_SendBreak 11
  125. #define FC_StopBreak 12
  126. #define FC_LoopbackON 13
  127. #define FC_LoopbackOFF 14
  128. #define FC_ClrIrqTable 15
  129. #define FC_SendXon 16
  130. #define FC_SetTermIrq 17
  131. #define FC_SetCntIrq 18
  132. //#define FC_SetBreakIrq 19 // canceled
  133. #define FC_SetLineIrq 20
  134. #define FC_SetFlowCtl 21
  135. #define FC_GenIrq 22
  136. //#define FC_InCD180 23
  137. //#define FC_OutCD180 24
  138. #define FC_InUARTreg 23
  139. #define FC_OutUARTreg 24
  140. #define FC_SetXonXoff 25
  141. //#define FC_OutCD180CCR 26 // canceled
  142. #define FC_ExtIQueue 27
  143. #define FC_ExtOQueue 28
  144. #define FC_ClrLineIrq 29
  145. #define FC_HWFlowCtl 30
  146. #define FC_SetBINmode 31
  147. #define FC_SetEventCh 32
  148. #define FC_SetTxtrigger 33
  149. #define FC_SetRxtrigger 34
  150. #define FC_GetClockRate 35
  151. #define FC_SetBaud 36
  152. #define FC_DTRcontrol 37
  153. #define FC_RTScontrol 38
  154. #define FC_SetXoffLimit 39
  155. #define FC_SetFlowRepl 40
  156. #define FC_SetDataMode 41
  157. #define FC_GetDTRRTS 42
  158. //#define FC_GetCCSR 43
  159. #define FC_GetTXstat 43 /* for Windows NT */
  160. #define FC_SetChars 44
  161. #define FC_GetDataError 45
  162. #define FC_ClearPort 46
  163. #define FC_GetAll 47 // (oqueue+linestatus+ccsr+dataerror)
  164. #define FC_ImmSend 51
  165. #define FC_SetXonState 52
  166. #define FC_SetXoffState 53
  167. #define FC_SetRxFIFOTrig 54
  168. #define FC_SetTxFIFOCnt 55
  169. #define Max_func 55 * 2
  170. //
  171. // Dual-Ported RAM
  172. //
  173. #define DRAM_global 0
  174. #define INT_data (DRAM_global + 0)
  175. #define Config_base (DRAM_global + 0x108)
  176. #define IRQindex (INT_data + 0)
  177. #define IRQpending (INT_data + 4)
  178. #define IRQtable (INT_data + 8)
  179. //
  180. // Interrupt Status
  181. //
  182. #define IntrRx 0x01 /* received data available */
  183. #define IntrTx 0x02 /* transmit buffer empty */
  184. #define IntrError 0x04 /* data error */
  185. #define IntrBreak 0x08 /* received break */
  186. #define IntrLine 0x10 /* line status change */
  187. #define IntrEvent 0x20 /* event character */
  188. #define IntrRx80Full 0x40 /* Rx data over 80% full */
  189. #define IntrEof 0x80 /* received EOF char */
  190. #define IntrRxTrigger 0x100 /* rx data count reach trigger value */
  191. #define IntrTxTrigger 0x200 /* tx data count below trigger value*/
  192. //
  193. //
  194. #define Magic_code 0x404
  195. #define Magic_no (Config_base + 0)
  196. #define Card_model_no (Config_base + 2)
  197. #define Total_ports (Config_base + 4)
  198. #define C320B_len (Config_base + 6)
  199. #define Module_cnt (Config_base + 8)
  200. #define Module_no (Config_base + 10)
  201. #define C320B_restart (Config_base + 12)
  202. //#define Timer_10ms (Config_base + 14)
  203. #define Card_Exist (Config_base + 14)
  204. #define Disable_Irq (Config_base + 20)
  205. //
  206. // DATA BUFFER in DRAM
  207. //
  208. #define Extern_table 0x400 /* Base address of the external table
  209. (24 words * 64) total 3K bytes
  210. (24 words * 128) total 6K bytes */
  211. #define Extern_size 0x60 /* 96 bytes */
  212. #define RXrptr 0 /* read pointer for RX buffer */
  213. #define RXwptr 2 /* write pointer for RX buffer */
  214. #define TXrptr 4 /* read pointer for TX buffer */
  215. #define TXwptr 6 /* write pointer for TX buffer */
  216. #define HostStat 8 /* IRQ flag and general flag */
  217. #define FlagStat 10
  218. #define Flow_control 0x0C /* B7 B6 B5 B4 B3 B2 B1 B0 */
  219. /* x x x x | | | | */
  220. /* | | | + CTS flow */
  221. /* | | +--- RTS flow */
  222. /* | +------ TX Xon/Xoff*/
  223. /* +--------- RX Xon/Xoff*/
  224. #define Break_cnt 0x0e /* received break count */
  225. #define CD180TXirq 0x10 /* if non-0: enable TX irq */
  226. #define RX_mask 0x12
  227. #define TX_mask 0x14
  228. #define Ofs_rxb 0x16
  229. #define Ofs_txb 0x18
  230. #define Page_rxb 0x1A
  231. #define Page_txb 0x1C
  232. #define EndPage_rxb 0x1E
  233. #define EndPage_txb 0x20
  234. //#define DataCnt_IntrRx 0x22 /* available when WakeupRx on */
  235. #define Data_error 0x0022
  236. /* Updated by firmware and driver
  237. have to clear it after reference,
  238. Firmware will clear it only when
  239. FC_GetDataError called.
  240. B7 B6 B5 B4 B3 B2 B1 B0
  241. X X X | | | | |
  242. | | | | +--Break
  243. | | | +-----Framing
  244. | | +--------Overrun
  245. | +-----------OqueueOverrun
  246. +--------------Parity
  247. */
  248. #define ErrorIntr_Cnt 0x24
  249. #define LineIntr_Cnt 0x26
  250. #define Rx_trigger 0x28
  251. #define Tx_trigger 0x2a
  252. #define FuncCode 0x40
  253. #define FuncArg 0x42
  254. #define FuncArg1 0x44
  255. #define C218rx_size 0x2000 /* 8K bytes */
  256. #define C218tx_size 0x8000 /* 32K bytes */
  257. #define C218rx_mask (C218rx_size - 1)
  258. #define C218tx_mask (C218tx_size - 1)
  259. #define C320p8rx_size 0x2000
  260. #define C320p8tx_size 0x8000
  261. #define C320p8rx_mask (C320p8rx_size - 1)
  262. #define C320p8tx_mask (C320p8tx_size - 1)
  263. #define C320p16rx_size 0x2000
  264. #define C320p16tx_size 0x4000
  265. #define C320p16rx_mask (C320p16rx_size - 1)
  266. #define C320p16tx_mask (C320p16tx_size - 1)
  267. #define C320p24rx_size 0x2000
  268. #define C320p24tx_size 0x2000
  269. #define C320p24rx_mask (C320p24rx_size - 1)
  270. #define C320p24tx_mask (C320p24tx_size - 1)
  271. #define C320p32rx_size 0x1000
  272. #define C320p32tx_size 0x1000
  273. #define C320p32rx_mask (C320p32rx_size - 1)
  274. #define C320p32tx_mask (C320p32tx_size - 1)
  275. /* 8-14-01 by William */
  276. #define RX_offset 256
  277. #define Page_size 0x2000
  278. #define Page_mask (Page_size - 1)
  279. #define C218rx_spage 3
  280. #define C218tx_spage 4
  281. #define C218rx_pageno 1
  282. #define C218tx_pageno 4
  283. #define C218buf_pageno 5
  284. #define C320p8rx_spage 3
  285. #define C320p8tx_spage 4
  286. #define C320p8rx_pgno 1
  287. #define C320p8tx_pgno 4
  288. #define C320p8buf_pgno 5
  289. #define C320p16rx_spage 3
  290. #define C320p16tx_spage 4
  291. #define C320p16rx_pgno 1
  292. #define C320p16tx_pgno 2
  293. #define C320p16buf_pgno 3
  294. #define C320p24rx_spage 3
  295. #define C320p24tx_spage 4
  296. #define C320p24rx_pgno 1
  297. #define C320p24tx_pgno 1
  298. #define C320p24buf_pgno 2
  299. #define C320p32rx_spage 3
  300. #define C320p32tx_ofs C320p32rx_size
  301. #define C320p32tx_spage 3
  302. #define C320p32buf_pgno 1
  303. //
  304. // Host Status
  305. //
  306. #define WakeupRx 0x01
  307. #define WakeupTx 0x02
  308. #define WakeupError 0x04
  309. #define WakeupBreak 0x08
  310. #define WakeupLine 0x10
  311. #define WakeupEvent 0x20
  312. #define WakeupRx80Full 0x40
  313. #define WakeupEof 0x80
  314. #define WakeupRxTrigger 0x100
  315. #define WakeupTxTrigger 0x200
  316. //
  317. // Flow_control
  318. //
  319. #define CTS_FlowCtl 1
  320. #define RTS_FlowCtl 2
  321. #define Tx_FlowCtl 4
  322. #define Rx_FlowCtl 8
  323. //
  324. // Flag status
  325. //
  326. #define Rx_over 0x01 /* received data overflow */
  327. #define Rx_xoff 0x02 /* Rx flow off by XOFF or CTS */
  328. #define Tx_flowOff 0x04 /* Tx held by XOFF */
  329. #define Tx_enable 0x08 /* 1-Tx enable */
  330. #define CTS_state 0x10 /* line status (CTS) 1-ON,0-OFF */
  331. #define DSR_state 0x20 /* line status (DSR) 1-ON,0-OFF */
  332. #define DCD_state 0x80 /* line status (DCD) 1-ON,0-OFF */
  333. //
  334. // LineStatus
  335. //
  336. #define LSTATUS_CTS 1
  337. #define LSTATUS_DSR 2
  338. #define LSTATUS_DCD 8
  339. // Rx FIFO Trigger
  340. #define RxFIOFOTrig1 0 // trigger level = 1
  341. #define RxFIOFOTrig4 1 // trigger level = 4
  342. #define RxFIOFOTrig8 2 // trigger level = 8
  343. #define RxFIOFOTrig14 3 // trigger level = 14
  344. //
  345. // DataMode
  346. //
  347. #define MOXA_5_DATA ((UCHAR)0x00)
  348. #define MOXA_6_DATA ((UCHAR)0x01)
  349. #define MOXA_7_DATA ((UCHAR)0x02)
  350. #define MOXA_8_DATA ((UCHAR)0x03)
  351. #define MOXA_DATA_MASK ((UCHAR)0x03)
  352. #define MOXA_1_STOP ((UCHAR)0x00)
  353. #define MOXA_1_5_STOP ((UCHAR)0x04) // Only valid for 5 data bits
  354. #define MOXA_2_STOP ((UCHAR)0x08) // Not valid for 5 data bits
  355. #define MOXA_STOP_MASK ((UCHAR)0x0c)
  356. #define MOXA_NONE_PARITY ((UCHAR)0x00)
  357. #define MOXA_ODD_PARITY ((UCHAR)0xc0)
  358. #define MOXA_EVEN_PARITY ((UCHAR)0x40)
  359. #define MOXA_MARK_PARITY ((UCHAR)0xa0)
  360. #define MOXA_SPACE_PARITY ((UCHAR)0x20)
  361. #define MOXA_PARITY_MASK ((UCHAR)0xe0)
  362. #define MOXA_INT_MAPPED ((UCHAR)0x01)
  363. #define MOXA_INT_IS_ROOT ((UCHAR)0x02)
  364. //
  365. //
  366. #define SERIAL_PNPACCEPT_OK 0x0L
  367. #define SERIAL_PNPACCEPT_REMOVING 0x1L
  368. #define SERIAL_PNPACCEPT_STOPPING 0x2L
  369. #define SERIAL_PNPACCEPT_STOPPED 0x4L
  370. #define SERIAL_PNPACCEPT_SURPRISE_REMOVING 0x8L
  371. #define SERIAL_PNP_ADDED 0x0L
  372. #define SERIAL_PNP_STARTED 0x1L
  373. #define SERIAL_PNP_QSTOP 0x2L
  374. #define SERIAL_PNP_STOPPING 0x3L
  375. #define SERIAL_PNP_QREMOVE 0x4L
  376. #define SERIAL_PNP_REMOVING 0x5L
  377. #define SERIAL_PNP_RESTARTING 0x6L
  378. #define SERIAL_FLAGS_CLEAR 0x0L
  379. #define SERIAL_FLAGS_STARTED 0x1L
  380. #define SERIAL_FLAGS_STOPPED 0x2L
  381. #define SERIAL_FLAGS_BROKENHW 0x4L
  382. #define REGISTRY_MULTIPORT_CLASS L"\\REGISTRY\\Machine\\System\\CurrentControlSet\\Control\\Class\\{50906CB8-BA12-11D1-BF5D-0000F805F530}"
  383. //
  384. //
  385. //
  386. #define MOXA_WMI_GUID_LIST_SIZE 6
  387. //
  388. //
  389. // Debugging Output Levels
  390. //
  391. #define MX_DBG_MASK 0x000000FF
  392. #define MX_DBG_NOISE 0x00000001
  393. #define MX_DBG_TRACE 0x00000002
  394. #define MX_DBG_INFO 0x00000004
  395. #define MX_DBG_ERROR 0x00000008
  396. #define MX_DBG_TRACE_ISR 0x00000010
  397. #define MX_DEFAULT_DEBUG_OUTPUT_LEVEL (MX_DBG_MASK & ~MX_DBG_TRACE_ISR)
  398. //#define MX_DEFAULT_DEBUG_OUTPUT_LEVEL MX_DBG_MASK
  399. #if DBG
  400. #define MoxaKdPrint(_l_, _x_) \
  401. if (MX_DEFAULT_DEBUG_OUTPUT_LEVEL & (_l_)) { \
  402. DbgPrint ("Mxport.SYS: "); \
  403. DbgPrint _x_; \
  404. }
  405. #define TRAP() DbgBreakPoint()
  406. #define DbgRaiseIrql(_x_,_y_) KeRaiseIrql(_x_,_y_)
  407. #define DbgLowerIrql(_x_) KeLowerIrql(_x_)
  408. #else
  409. #define MoxaKdPrint(_l_, _x_)
  410. #define TRAP()
  411. #define DbgRaiseIrql(_x_,_y_)
  412. #define DbgLowerIrql(_x_)
  413. #endif
  414. #undef ExAllocatePool
  415. #undef ExAllocatePoolWithQuota
  416. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'pixM')
  417. #define ExAllocatePoolWithQuota(a,b) ExAllocatePoolWithQuotaTag(a,b,'pixM')
  418. //
  419. //
  420. #define MoxaCompleteRequest(PDevExt, PIrp, PriBoost) \
  421. { \
  422. IoCompleteRequest((PIrp), (PriBoost)); \
  423. MoxaIRPEpilogue((PDevExt)); \
  424. }
  425. typedef enum _MOXA_MEM_COMPARES {
  426. AddressesAreEqual,
  427. AddressesOverlap,
  428. AddressesAreDisjoint
  429. } MOXA_MEM_COMPARES,*PSERIAL_MEM_COMPARES;
  430. #define DEVICE_OBJECT_NAME_LENGTH 128
  431. #define SYMBOLIC_NAME_LENGTH 128
  432. #define SERIAL_DEVICE_MAP L"SERIALCOMM"
  433. typedef struct _MOXA_DEVICE_STATE {
  434. //
  435. // TRUE if we need to set the state to open
  436. // on a powerup
  437. //
  438. BOOLEAN Reopen;
  439. //
  440. // Hardware registers
  441. //
  442. USHORT HostState;
  443. } MOXA_DEVICE_STATE, *PMOXA_DEVICE_STATE;
  444. #if DBG
  445. #define MoxaLockPagableSectionByHandle(_secHandle) \
  446. { \
  447. MmLockPagableSectionByHandle((_secHandle)); \
  448. InterlockedIncrement(&MoxaGlobalData->PAGESER_Count); \
  449. }
  450. #define MoxaUnlockPagableImageSection(_secHandle) \
  451. { \
  452. InterlockedDecrement(&MoxaGlobalData->PAGESER_Count); \
  453. MmUnlockPagableImageSection(_secHandle); \
  454. }
  455. #else
  456. #define MoxaLockPagableSectionByHandle(_secHandle) \
  457. { \
  458. MmLockPagableSectionByHandle((_secHandle)); \
  459. }
  460. #define MoxaUnlockPagableImageSection(_secHandle) \
  461. { \
  462. MmUnlockPagableImageSection(_secHandle); \
  463. }
  464. #endif // DBG
  465. #define MoxaRemoveQueueDpc(_dpc, _pExt) \
  466. { \
  467. if (KeRemoveQueueDpc((_dpc))) { \
  468. InterlockedDecrement(&(_pExt)->DpcCount); \
  469. } \
  470. }
  471. #if DBG
  472. typedef struct _DPC_QUEUE_DEBUG {
  473. PVOID Dpc;
  474. ULONG QueuedCount;
  475. ULONG FlushCount;
  476. } DPC_QUEUE_DEBUG, *PDPC_QUEUE_DEBUG;
  477. #define MAX_DPC_QUEUE 14
  478. #endif
  479. //
  480. // ISR switch structure
  481. //
  482. typedef struct _SERIAL_MULTIPORT_DISPATCH {
  483. ULONG BoardNo;
  484. PVOID GlobalData;
  485. /*
  486. ULONG NumPorts;
  487. PUCHAR CardBase;
  488. PUCHAR PciIntAckBase;
  489. PUSHORT IntNdx;
  490. PUCHAR IntPend;
  491. PUCHAR IntTable;
  492. struct _MOXA_DEVICE_EXTENSION *ExtensionOfFisrtPort;
  493. */
  494. } MOXA_MULTIPORT_DISPATCH,*PMOXA_MULTIPORT_DISPATCH;
  495. typedef struct _MOXA_CISR_SW {
  496. MOXA_MULTIPORT_DISPATCH Dispatch;
  497. LIST_ENTRY SharerList;
  498. } MOXA_CISR_SW, *PMOXA_CISR_SW;
  499. struct _MOXA_DEVICE_EXTENSION;
  500. typedef struct _MOXA_GLOBAL_DATA {
  501. PDRIVER_OBJECT DriverObject;
  502. UNICODE_STRING RegistryPath;
  503. PLIST_ENTRY InterruptShareList[MAX_CARD];
  504. USHORT PciBusNum[MAX_CARD];
  505. USHORT PciDevNum[MAX_CARD];
  506. INTERFACE_TYPE InterfaceType[MAX_CARD];
  507. ULONG IntVector[MAX_CARD];
  508. PHYSICAL_ADDRESS PciIntAckPort[MAX_CARD];
  509. PUCHAR PciIntAckBase[MAX_CARD];
  510. PHYSICAL_ADDRESS BankAddr[MAX_CARD];
  511. PKINTERRUPT Interrupt[MAX_CARD];
  512. KIRQL Irql[MAX_CARD];
  513. KAFFINITY ProcessorAffinity[MAX_CARD];
  514. ULONG CardType[MAX_CARD];
  515. ULONG NumPorts[MAX_CARD];
  516. ULONG BoardIndex[MAX_CARD];
  517. PUCHAR CardBase[MAX_CARD];
  518. PUSHORT IntNdx[MAX_CARD];
  519. PUCHAR IntPend[MAX_CARD];
  520. PUCHAR IntTable[MAX_CARD];
  521. struct _MOXA_DEVICE_EXTENSION *Extension[MAX_PORT];
  522. USHORT ComNo[MAX_CARD][MAXPORT_PER_CARD];
  523. UCHAR PortFlag[MAX_CARD][MAXPORT_PER_CARD];
  524. PVOID PAGESER_Handle;
  525. BOOLEAN BoardReady[MAX_CARD];
  526. #if DBG
  527. ULONG PAGESER_Count;
  528. #endif // DBG
  529. } MOXA_GLOBAL_DATA,*PMOXA_GLOBAL_DATA;
  530. typedef struct _CONFIG_DATA {
  531. LIST_ENTRY ConfigList;
  532. PHYSICAL_ADDRESS BankAddr;
  533. ULONG CardType;
  534. } CONFIG_DATA,*PCONFIG_DATA;
  535. typedef struct _MOXA_DEVICE_EXTENSION {
  536. PDRIVER_OBJECT DriverObject;
  537. PDEVICE_OBJECT DeviceObject;
  538. PDEVICE_OBJECT LowerDeviceObject;
  539. PDEVICE_OBJECT Pdo;
  540. PMOXA_GLOBAL_DATA GlobalData;
  541. BOOLEAN ControlDevice;
  542. BOOLEAN PortExist;
  543. PUCHAR PortBase;
  544. PUCHAR PortOfs;
  545. ULONG PortIndex; // The port index per board from 0 to MAXPORT_PER_CARD
  546. ULONG PortNo; // The port index per system form 0 to MAX_PORT
  547. BOOLEAN DeviceIsOpened;
  548. PKINTERRUPT Interrupt;
  549. ULONG ClockType;
  550. ULONG CurrentBaud;
  551. UCHAR DataMode;
  552. UCHAR ValidDataMask;
  553. SERIAL_TIMEOUTS Timeouts;
  554. SERIAL_CHARS SpecialChars;
  555. UCHAR EscapeChar;
  556. SERIAL_HANDFLOW HandFlow;
  557. //
  558. // Holds performance statistics that applications can query.
  559. // Reset on each open. Only set at device level.
  560. //
  561. SERIALPERF_STATS PerfStats;
  562. USHORT ModemStatus;
  563. ULONG IsrWaitMask;
  564. ULONG HistoryMask;
  565. ULONG *IrpMaskLocation;
  566. ULONG RxBufferSize;
  567. ULONG TxBufferSize;
  568. ULONG BufferSizePt8;
  569. ULONG ErrorWord;
  570. ULONG TXHolding;
  571. ULONG WriteLength;
  572. PUCHAR WriteCurrentChar;
  573. BOOLEAN AlreadyComplete;
  574. ULONG ReadLength;
  575. PUCHAR ReadCurrentChar;
  576. ULONG NumberNeededForRead;
  577. LONG CountOnLastRead;
  578. ULONG ReadByIsr;
  579. ULONG TotalCharsQueued;
  580. ULONG SupportedBauds;
  581. ULONG MaxBaud;
  582. BOOLEAN SendBreak;
  583. KSPIN_LOCK ControlLock;
  584. PLIST_ENTRY InterruptShareList;
  585. LIST_ENTRY ReadQueue;
  586. LIST_ENTRY WriteQueue;
  587. LIST_ENTRY MaskQueue;
  588. LIST_ENTRY PurgeQueue;
  589. PIRP CurrentReadIrp;
  590. PIRP CurrentWriteIrp;
  591. PIRP CurrentMaskIrp;
  592. PIRP CurrentPurgeIrp;
  593. PIRP CurrentWaitIrp;
  594. KTIMER ReadRequestTotalTimer;
  595. KTIMER ReadRequestIntervalTimer;
  596. KTIMER WriteRequestTotalTimer;
  597. KDPC CompleteWriteDpc;
  598. KDPC CompleteReadDpc;
  599. KDPC TotalReadTimeoutDpc;
  600. KDPC IntervalReadTimeoutDpc;
  601. KDPC TotalWriteTimeoutDpc;
  602. KDPC CommErrorDpc;
  603. KDPC CommWaitDpc;
  604. KDPC IsrInDpc;
  605. KDPC IsrOutDpc;
  606. //
  607. // 9-24-01 by William
  608. //
  609. // KDPC IntrLineDpc;
  610. // KDPC IntrErrorDpc;
  611. // end
  612. //
  613. // This DPC is fired to set an event stating that all other
  614. // DPC's have been finish for this device extension so that
  615. // paged code may be unlocked.
  616. //
  617. KDPC IsrUnlockPagesDpc;
  618. LARGE_INTEGER IntervalTime;
  619. PLARGE_INTEGER IntervalTimeToUse;
  620. LARGE_INTEGER ShortIntervalAmount;
  621. LARGE_INTEGER LongIntervalAmount;
  622. LARGE_INTEGER CutOverAmount;
  623. LARGE_INTEGER LastReadTime;
  624. UCHAR IsrInFlag;
  625. UCHAR IsrOutFlag;
  626. USHORT ErrorCnt;
  627. USHORT LineIntrCnt;
  628. UCHAR PortFlag;
  629. ULONG BoardNo;
  630. // This is the water mark that the rxfifo should be
  631. // set to when the fifo is turned on. This is not the actual
  632. // value, but the encoded value that goes into the register.
  633. //
  634. USHORT RxFifoTrigger;
  635. //
  636. // The number of characters to push out if a fifo is present.
  637. //
  638. USHORT TxFifoAmount;
  639. // This lock will be used to protect the accept / reject state
  640. // transitions and flags of the driver It must be acquired
  641. // before a cancel lock
  642. //
  643. KSPIN_LOCK FlagsLock;
  644. // This is where keep track of the power state the device is in.
  645. //
  646. DEVICE_POWER_STATE PowerState;
  647. //
  648. // This links together all devobjs that this driver owns.
  649. // It is needed to search when starting a new device.
  650. //
  651. LIST_ENTRY AllDevObjs;
  652. //
  653. // We keep a pointer around to our device name for dumps
  654. // and for creating "external" symbolic links to this
  655. // device.
  656. //
  657. UNICODE_STRING DeviceName;
  658. //
  659. // This points to the object directory that we will place
  660. // a symbolic link to our device name.
  661. //
  662. UNICODE_STRING ObjectDirectory;
  663. // Records whether we actually created the symbolic link name
  664. // at driver load time. If we didn't create it, we won't try
  665. // to destroy it when we unload.
  666. //
  667. BOOLEAN CreatedSymbolicLink;
  668. //
  669. // Records whether we actually created an entry in SERIALCOMM
  670. // at driver load time. If we didn't create it, we won't try
  671. // to destroy it when the device is removed.
  672. //
  673. BOOLEAN CreatedSerialCommEntry;
  674. //
  675. // This points to the symbolic link name that will be
  676. // linked to the actual nt device name.
  677. //
  678. UNICODE_STRING SymbolicLinkName;
  679. //
  680. // This points to the pure "COMx" name
  681. //
  682. WCHAR DosName[32];
  683. //
  684. // String where we keep the symbolic link that is returned to us when we
  685. // register our device under the COMM class with the Plug and Play manager.
  686. //
  687. UNICODE_STRING DeviceClassSymbolicName;
  688. //
  689. // Count of pending IRP's
  690. //
  691. ULONG PendingIRPCnt;
  692. //
  693. // Accepting requests?
  694. //
  695. ULONG DevicePNPAccept;
  696. //
  697. // No IRP's pending event
  698. //
  699. KEVENT PendingIRPEvent;
  700. //
  701. // PNP State
  702. //
  703. ULONG PNPState;
  704. //
  705. // Misc Flags
  706. //
  707. ULONG Flags;
  708. //
  709. // Open count
  710. //
  711. LONG OpenCount;
  712. //
  713. // Start sync event
  714. //
  715. KEVENT SerialStartEvent;
  716. //
  717. // Current state during powerdown
  718. //
  719. MOXA_DEVICE_STATE DeviceState;
  720. //
  721. // Device stack capabilites
  722. //
  723. DEVICE_POWER_STATE DeviceStateMap[PowerSystemMaximum];
  724. //
  725. // Event to signal transition to D0 completion
  726. //
  727. KEVENT PowerD0Event;
  728. //
  729. // List of stalled IRP's
  730. //
  731. LIST_ENTRY StalledIrpQueue;
  732. //
  733. // Mutex on open status
  734. //
  735. FAST_MUTEX OpenMutex;
  736. //
  737. // Mutex on close
  738. //
  739. FAST_MUTEX CloseMutex;
  740. //
  741. // TRUE if we own power policy
  742. //
  743. BOOLEAN OwnsPowerPolicy;
  744. //
  745. // SystemWake from devcaps
  746. //
  747. SYSTEM_POWER_STATE SystemWake;
  748. //
  749. // DeviceWake from devcaps
  750. //
  751. DEVICE_POWER_STATE DeviceWake;
  752. //
  753. // Should we enable wakeup
  754. //
  755. BOOLEAN SendWaitWake;
  756. //
  757. // Pending wait wake IRP
  758. //
  759. PIRP PendingWakeIrp;
  760. //
  761. // WMI Information
  762. //
  763. WMILIB_CONTEXT WmiLibInfo;
  764. //
  765. // Name to use as WMI identifier
  766. //
  767. UNICODE_STRING WmiIdentifier;
  768. //
  769. // WMI Comm Data
  770. //
  771. SERIAL_WMI_COMM_DATA WmiCommData;
  772. //
  773. // WMI HW Data
  774. //
  775. SERIAL_WMI_HW_DATA WmiHwData;
  776. //
  777. // Pending DPC count
  778. //
  779. ULONG DpcCount;
  780. //
  781. // Pending DPC event
  782. //
  783. KEVENT PendingDpcEvent;
  784. ULONG PollingPeriod;
  785. //
  786. //
  787. } MOXA_DEVICE_EXTENSION,*PMOXA_DEVICE_EXTENSION;
  788. typedef struct _MOXA_IOCTL_FUNC {
  789. PUCHAR PortOfs;
  790. UCHAR Command;
  791. USHORT Argument;
  792. } MOXA_IOCTL_FUNC,*PMOXA_IOCTL_FUNC;
  793. typedef struct _MOXA_IOCTL_GEN_FUNC {
  794. PUCHAR PortOfs;
  795. UCHAR Command;
  796. PUSHORT Argument;
  797. USHORT ArguSize;
  798. } MOXA_IOCTL_GEN_FUNC,*PMOXA_IOCTL_GEN_FUNC;
  799. typedef struct _MOXA_IOCTL_FUNC_ARGU {
  800. PUCHAR PortOfs;
  801. UCHAR Command;
  802. PUSHORT Argument;
  803. } MOXA_IOCTL_FUNC_ARGU,*PMOXA_IOCTL_FUNC_ARGU;
  804. typedef struct _MOXA_IOCTL_SYNC {
  805. PMOXA_DEVICE_EXTENSION Extension;
  806. PVOID Data;
  807. } MOXA_IOCTL_SYNC,*PMOXA_IOCTL_SYNC;
  808. typedef union _MOXA_IOCTL_DownLoad {
  809. struct {
  810. ULONG CardNo;
  811. ULONG Len;
  812. PUCHAR Buf;
  813. } i;
  814. struct {
  815. ULONG CardNo;
  816. ULONG Status;
  817. PUCHAR Buf;
  818. } o;
  819. } MOXA_IOCTL_DownLoad,*PMOXA_IOCTL_DownLoad;
  820. typedef struct _MOXA_IOCTL_LINPUT_IN {
  821. UCHAR Terminater;
  822. ULONG BufferSize;
  823. } MOXA_IOCTL_LINPUT_IN,*PMOXA_IOCTL_LINPUT_IN;
  824. typedef struct _MOXA_IOCTL_LINPUT_OUT {
  825. ULONG DataLen;
  826. UCHAR DataBuffer[1];
  827. } MOXA_IOCTL_LINPUT_OUT,*PMOXA_IOCTL_LINPUT_OUT;
  828. typedef struct _MOXA_IOCTL_PUTB {
  829. ULONG DataLen;
  830. PUCHAR DataBuffer;
  831. } MOXA_IOCTL_PUTB,*PMOXA_IOCTL_PUTB;
  832. //
  833. // The following three macros are used to initialize, increment
  834. // and decrement reference counts in IRPs that are used by
  835. // this driver. The reference count is stored in the fourth
  836. // argument of the irp, which is never used by any operation
  837. // accepted by this driver.
  838. //
  839. #define MOXA_INIT_REFERENCE(Irp) \
  840. IoGetCurrentIrpStackLocation((Irp))->Parameters.Others.Argument4 = NULL;
  841. #define MOXA_INC_REFERENCE(Irp) \
  842. ((*((LONG *)(&(IoGetCurrentIrpStackLocation((Irp)))->Parameters.Others.Argument4)))++)
  843. #define MOXA_DEC_REFERENCE(Irp) \
  844. ((*((LONG *)(&(IoGetCurrentIrpStackLocation((Irp)))->Parameters.Others.Argument4)))--)
  845. #define MOXA_REFERENCE_COUNT(Irp) \
  846. ((LONG)((IoGetCurrentIrpStackLocation((Irp))->Parameters.Others.Argument4)))
  847. //
  848. // These values are used by the routines that can be used
  849. // to complete a read (other than interval timeout) to indicate
  850. // to the interval timeout that it should complete.
  851. //
  852. #define MOXA_COMPLETE_READ_CANCEL ((LONG)-1)
  853. #define MOXA_COMPLETE_READ_TOTAL ((LONG)-2)
  854. #define MOXA_COMPLETE_READ_COMPLETE ((LONG)-3)
  855. #define WRITE_LOW_WATER 128
  856. //
  857. // Moxa Utilities using data structure:
  858. //
  859. typedef struct _MOXA_IOCTL_Statistic {
  860. ULONG TxCount; // total transmitted count
  861. ULONG RxCount; // total received count
  862. ULONG LStatus; // current line status
  863. ULONG FlowCtl; // current flow control setting
  864. } MOXA_IOCTL_Statistic,*PMOXA_IOCTL_Statistic;
  865. typedef struct _MOXA_IOCTL_PortStatus {
  866. USHORT Open; // open/close state
  867. USHORT TxHold; // Transmit holding reason
  868. ULONG DataMode; // current data bits/parity/stop bits
  869. ULONG BaudRate; // Current baud rate
  870. ULONG MaxBaudRate; // Max. baud rate
  871. ULONG TxBuffer; // Tx buffer size
  872. ULONG RxBuffer; // Rx buffer size
  873. ULONG TxXonThreshold; // Xon limit
  874. ULONG TxXoffThreshold; // Xoff limit
  875. ULONG FlowControl; // Current flow control setting.
  876. } MOXA_IOCTL_PortStatus,*PMOXA_IOCTL_PortStatus;
  877. #define MX_PCI_VENID 0x1393
  878. #define MX_C218PCI_DEVID 0x2180
  879. #define MX_C320PCI_DEVID 0x3200
  880. struct MoxaPciInfo {
  881. USHORT BusNum;
  882. USHORT DevNum;
  883. };
  884. typedef struct _MxConfig {
  885. int NoBoards;
  886. int BusType[MAX_CARD];
  887. struct MoxaPciInfo Pci[MAX_CARD];
  888. int BoardType[MAX_CARD];
  889. ULONG BaseAddr[MAX_CARD];
  890. ULONG PciIrqAckPort[MAX_CARD];
  891. int Irq[MAX_CARD];
  892. // INT NoPorts[MAX_CARD];
  893. USHORT ComNo[MAX_CARD][MAXPORT_PER_CARD];
  894. #define DISABLE_FIFO 0x01
  895. #define NORMAL_TX_MODE 0x02
  896. UCHAR PortFlag[MAX_CARD][MAXPORT_PER_CARD];
  897. } MOXA_Config,*PMOXA_Config;
  898. #define MAX_PCI_BOARDS 8
  899. typedef struct _MxPciConfig {
  900. int NoBoards;
  901. USHORT DevId[MAX_PCI_BOARDS];
  902. USHORT BusNum[MAX_PCI_BOARDS];
  903. USHORT DevNum[MAX_PCI_BOARDS];
  904. ULONG BaseAddr[MAX_PCI_BOARDS];
  905. ULONG PciIrqAckPort[MAX_PCI_BOARDS];
  906. int Irq[MAX_PCI_BOARDS];
  907. } MOXA_PCIConfig,*PMOXA_PCIConfig;
  908. typedef struct _DEVICE_SETTINGS {
  909. ULONG BoardIndex;
  910. ULONG PortIndex;
  911. ULONG BoardType;
  912. ULONG NumPorts;
  913. INTERFACE_TYPE InterfaceType;
  914. ULONG BusNumber;
  915. PHYSICAL_ADDRESS OriginalBaseAddress;
  916. PHYSICAL_ADDRESS OriginalAckPort;
  917. PUCHAR BaseAddress;
  918. PUCHAR AckPort;
  919. struct {
  920. ULONG Level;
  921. ULONG Vector;
  922. ULONG Affinity;
  923. } Interrupt;
  924. } DEVICE_SETTINGS, *PDEVICE_SETTINGS;