2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: Serial driver
4 * FILE: drivers/dd/serial/serial.h
5 * PURPOSE: Serial driver header
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
11 #include <ndk/haltypes.h>
16 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
20 #define COMMPROP_INITIALIZED 0xE73CF52E
23 /* Why is it only defined in ntifs.h file? */
25 IoAttachDeviceToDeviceStackSafe(
26 IN PDEVICE_OBJECT SourceDevice
,
27 IN PDEVICE_OBJECT TargetDevice
,
28 OUT PDEVICE_OBJECT
*AttachedToDeviceObject
);
38 } SERIAL_DEVICE_STATE
;
43 Uart8250
, /* initial version */
44 Uart16450
, /* + 38.4 Kbps */
45 Uart16550
, /* + 115 Kbps */
46 Uart16550A
,/* + FIFO 16 bytes */
47 Uart16650
, /* + FIFO 32 bytes, 230 Kbps, power management, auto-flow */
48 Uart16750
/* + FIFO 64 bytes, 460 Kbps */
51 typedef struct _CIRCULAR_BUFFER
57 } CIRCULAR_BUFFER
, *PCIRCULAR_BUFFER
;
59 typedef struct _SERIAL_DEVICE_EXTENSION
62 PDEVICE_OBJECT LowerDevice
;
63 SERIAL_DEVICE_STATE PnpState
;
64 IO_REMOVE_LOCK RemoveLock
;
66 ULONG SerialPortNumber
;
71 PKINTERRUPT Interrupt
;
76 SERIAL_LINE_CONTROL SerialLineControl
;
81 ULONG BreakInterruptErrorCount
;
82 SERIALPERF_STATS SerialPerfStats
;
83 SERIAL_TIMEOUTS SerialTimeOuts
;
85 KEVENT InputBufferNotEmpty
;
86 CIRCULAR_BUFFER InputBuffer
;
87 KSPIN_LOCK InputBufferLock
;
88 CIRCULAR_BUFFER OutputBuffer
;
89 KSPIN_LOCK OutputBufferLock
;
91 UNICODE_STRING SerialInterfaceName
;
94 UCHAR MCR
; /* Base+4, Modem Control Register */
95 UCHAR MSR
; /* Base+6, Modem Status Register */
96 } SERIAL_DEVICE_EXTENSION
, *PSERIAL_DEVICE_EXTENSION
;
98 typedef struct _WORKITEM_DATA
101 PIO_WORKITEM IoWorkItem
;
103 BOOLEAN UseIntervalTimeout
;
104 BOOLEAN UseTotalTimeout
;
105 LARGE_INTEGER IntervalTimeout
;
106 LARGE_INTEGER TotalTimeoutTime
;
108 BOOLEAN ReadAtLeastOneByte
;
109 } WORKITEM_DATA
, *PWORKITEM_DATA
;
111 #define SERIAL_TAG TAG('S', 'e', 'r', 'l')
113 #define INFINITE ((ULONG)-1)
115 /* Baud master clock */
116 #define BAUD_CLOCK 1843200
117 #define CLOCKS_PER_BIT 16
119 /* UART registers and bits */
120 #define SER_RBR(x) ((x)+0) /* Receive Register */
121 #define SER_THR(x) ((x)+0) /* Transmit Register */
122 #define SER_DLL(x) ((x)+0) /* Baud Rate Divisor LSB */
123 #define SER_IER(x) ((x)+1) /* Interrupt Enable Register */
124 #define SR_IER_DATA_RECEIVED 0x01
125 #define SR_IER_THR_EMPTY 0x02
126 #define SR_IER_LSR_CHANGE 0x04
127 #define SR_IER_MSR_CHANGE 0x08
128 #define SR_IER_SLEEP_MODE 0x10 /* Uart >= 16750 */
129 #define SR_IER_LOW_POWER 0x20 /* Uart >= 16750 */
130 #define SER_DLM(x) ((x)+1) /* Baud Rate Divisor MSB */
131 #define SER_IIR(x) ((x)+2) /* Interrupt Identification Register */
132 #define SR_IIR_SELF 0x00
133 #define SR_IIR_ID_MASK 0x07
134 #define SR_IIR_MSR_CHANGE SR_IIR_SELF
135 #define SR_IIR_THR_EMPTY (SR_IIR_SELF | 2)
136 #define SR_IIR_DATA_RECEIVED (SR_IIR_SELF | 4)
137 #define SR_IIR_ERROR (SR_IIR_SELF | 6)
138 #define SER_FCR(x) ((x)+2) /* FIFO Control Register (Uart >= 16550A) */
139 #define SR_FCR_ENABLE_FIFO 0x01
140 #define SR_FCR_CLEAR_RCVR (0x02 | SR_FCR_ENABLE_FIFO)
141 #define SR_FCR_CLEAR_XMIT (0x04 | SR_FCR_ENABLE_FIFO)
142 #define SR_FCR_1_BYTE (0x00 | SR_FCR_ENABLE_FIFO)
143 #define SR_FCR_4_BYTES (0x40 | SR_FCR_ENABLE_FIFO)
144 #define SR_FCR_8_BYTES (0x80 | SR_FCR_ENABLE_FIFO)
145 #define SR_FCR_14_BYTES (0xC0 | SR_FCR_ENABLE_FIFO)
146 #define SER_LCR(x) ((x)+3) /* Line Control Register */
147 #define SR_LCR_CS5 0x00
148 #define SR_LCR_CS6 0x01
149 #define SR_LCR_CS7 0x02
150 #define SR_LCR_CS8 0x03
151 #define SR_LCR_ST1 0x00
152 #define SR_LCR_ST2 0x04
153 #define SR_LCR_PNO 0x00
154 #define SR_LCR_POD 0x08
155 #define SR_LCR_PEV 0x18
156 #define SR_LCR_PMK 0x28
157 #define SR_LCR_PSP 0x38
158 #define SR_LCR_BRK 0x40
159 #define SR_LCR_DLAB 0x80
160 #define SER_MCR(x) ((x)+4) /* Modem Control Register */
161 #define SR_MCR_DTR SERIAL_DTR_STATE
162 #define SR_MCR_RTS SERIAL_RTS_STATE
163 #define SER_LSR(x) ((x)+5) /* Line Status Register */
164 #define SR_LSR_DATA_RECEIVED 0x01
165 #define SR_LSR_OVERRUN_ERROR 0x02
166 #define SR_LSR_PARITY_ERROR 0x04
167 #define SR_LSR_FRAMING_ERROR 0x08
168 #define SR_LSR_BREAK_INT 0x10
169 #define SR_LSR_THR_EMPTY 0x20
170 #define SR_LSR_TSR_EMPTY 0x40
171 #define SR_LSR_ERROR_IN_FIFO 0x80 /* Uart >= 16550A */
172 #define SER_MSR(x) ((x)+6) /* Modem Status Register */
173 #define SR_MSR_CTS_CHANGED 0x01
174 #define SR_MSR_DSR_CHANGED 0x02
175 #define SR_MSR_RI_CHANGED 0x04
176 #define SR_MSR_DCD_CHANGED 0x08
177 #define SR_MSR_CTS SERIAL_CTS_STATE /* Clear To Send */
178 #define SR_MSR_DSR SERIAL_DSR_STATE /* Data Set Ready */
179 #define SI_MSR_RI SERIAL_RI_STATE /* Ring Indicator */
180 #define SR_MSR_DCD SERIAL_DCD_STATE /* Data Carrier Detect */
181 #define SER_SCR(x) ((x)+7) /* Scratch Pad Register, Uart >= Uart16450 */
183 /************************************ circularbuffer.c */
185 /* FIXME: transform these functions into #define? */
187 InitializeCircularBuffer(
188 IN PCIRCULAR_BUFFER pBuffer
,
189 IN ULONG BufferSize
);
193 IN PCIRCULAR_BUFFER pBuffer
);
196 IsCircularBufferEmpty(
197 IN PCIRCULAR_BUFFER pBuffer
);
200 GetNumberOfElementsInCircularBuffer(
201 IN PCIRCULAR_BUFFER pBuffer
);
204 PushCircularBufferEntry(
205 IN PCIRCULAR_BUFFER pBuffer
,
209 PopCircularBufferEntry(
210 IN PCIRCULAR_BUFFER pBuffer
,
214 IncreaseCircularBufferSize(
215 IN PCIRCULAR_BUFFER pBuffer
,
216 IN ULONG NewBufferSize
);
218 /************************************ cleanup.c */
220 DRIVER_DISPATCH SerialCleanup
;
222 /************************************ close.c */
224 DRIVER_DISPATCH SerialClose
;
226 /************************************ create.c */
228 DRIVER_DISPATCH SerialCreate
;
230 /************************************ devctrl.c */
232 DRIVER_DISPATCH SerialDeviceControl
;
236 IN PSERIAL_DEVICE_EXTENSION DeviceExtension
,
237 IN ULONG NewBaudRate
);
240 SerialSetLineControl(
241 IN PSERIAL_DEVICE_EXTENSION DeviceExtension
,
242 IN PSERIAL_LINE_CONTROL NewSettings
);
244 /************************************ info.c */
246 DRIVER_DISPATCH SerialQueryInformation
;
248 /************************************ legacy.c */
251 SerialDetectUartType(
252 IN PUCHAR ComPortBase
);
254 /************************************ misc.c */
258 IN PDEVICE_OBJECT DeviceObject
,
261 DRIVER_DISPATCH ForwardIrpAndForget
;
266 IN PVOID pDeviceExtension
, // real type PSERIAL_DEVICE_EXTENSION
273 IN PVOID pDeviceExtension
, // real type PSERIAL_DEVICE_EXTENSION
280 IN PVOID pDeviceExtension
, // real type PSERIAL_DEVICE_EXTENSION
281 IN PVOID pIrp
, // real type PIRP
284 KSERVICE_ROUTINE SerialInterruptService
;
286 /************************************ pnp.c */
289 SerialAddDeviceInternal(
290 IN PDRIVER_OBJECT DriverObject
,
291 IN PDEVICE_OBJECT Pdo
,
292 IN UART_TYPE UartType
,
293 IN PULONG pComPortNumber OPTIONAL
,
294 OUT PDEVICE_OBJECT
* pFdo OPTIONAL
);
296 DRIVER_ADD_DEVICE SerialAddDevice
;
299 SerialPnpStartDevice(
300 IN PDEVICE_OBJECT DeviceObject
,
301 IN PCM_RESOURCE_LIST ResourceList
,
302 IN PCM_RESOURCE_LIST ResourceListTranslated
);
304 DRIVER_DISPATCH SerialPnp
;
306 /************************************ power.c */
308 DRIVER_DISPATCH SerialPower
;
310 /************************************ rw.c */
312 DRIVER_DISPATCH SerialRead
;
313 DRIVER_DISPATCH SerialWrite
;