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>
18 #define COMMPROP_INITIALIZED 0xE73CF52E
21 /* Why is it only defined in ntifs.h file? */
23 IoAttachDeviceToDeviceStackSafe(
24 IN PDEVICE_OBJECT SourceDevice
,
25 IN PDEVICE_OBJECT TargetDevice
,
26 OUT PDEVICE_OBJECT
*AttachedToDeviceObject
);
36 } SERIAL_DEVICE_STATE
;
41 Uart8250
, /* initial version */
42 Uart16450
, /* + 38.4 Kbps */
43 Uart16550
, /* + 115 Kbps */
44 Uart16550A
,/* + FIFO 16 bytes */
45 Uart16650
, /* + FIFO 32 bytes, 230 Kbps, power management, auto-flow */
46 Uart16750
/* + FIFO 64 bytes, 460 Kbps */
49 typedef struct _CIRCULAR_BUFFER
55 } CIRCULAR_BUFFER
, *PCIRCULAR_BUFFER
;
57 typedef struct _SERIAL_DEVICE_EXTENSION
60 PDEVICE_OBJECT LowerDevice
;
61 SERIAL_DEVICE_STATE PnpState
;
62 IO_REMOVE_LOCK RemoveLock
;
64 ULONG SerialPortNumber
;
69 PKINTERRUPT Interrupt
;
74 SERIAL_LINE_CONTROL SerialLineControl
;
79 ULONG BreakInterruptErrorCount
;
80 SERIALPERF_STATS SerialPerfStats
;
81 SERIAL_TIMEOUTS SerialTimeOuts
;
83 KEVENT InputBufferNotEmpty
;
84 CIRCULAR_BUFFER InputBuffer
;
85 KSPIN_LOCK InputBufferLock
;
86 CIRCULAR_BUFFER OutputBuffer
;
87 KSPIN_LOCK OutputBufferLock
;
89 UNICODE_STRING SerialInterfaceName
;
92 UCHAR MCR
; /* Base+4, Modem Control Register */
93 UCHAR MSR
; /* Base+6, Modem Status Register */
94 } SERIAL_DEVICE_EXTENSION
, *PSERIAL_DEVICE_EXTENSION
;
96 typedef struct _WORKITEM_DATA
99 PIO_WORKITEM IoWorkItem
;
101 BOOLEAN UseIntervalTimeout
;
102 BOOLEAN UseTotalTimeout
;
103 LARGE_INTEGER IntervalTimeout
;
104 LARGE_INTEGER TotalTimeoutTime
;
106 BOOLEAN ReadAtLeastOneByte
;
107 } WORKITEM_DATA
, *PWORKITEM_DATA
;
109 #define SERIAL_TAG 'lreS'
111 #define INFINITE MAXULONG
113 /* Baud master clock */
114 #define BAUD_CLOCK 1843200
115 #define CLOCKS_PER_BIT 16
117 /* UART registers and bits */
118 #define SER_RBR(x) ((x)+0) /* Receive Register */
119 #define SER_THR(x) ((x)+0) /* Transmit Register */
120 #define SER_DLL(x) ((x)+0) /* Baud Rate Divisor LSB */
121 #define SER_IER(x) ((x)+1) /* Interrupt Enable Register */
122 #define SR_IER_DATA_RECEIVED 0x01
123 #define SR_IER_THR_EMPTY 0x02
124 #define SR_IER_LSR_CHANGE 0x04
125 #define SR_IER_MSR_CHANGE 0x08
126 #define SR_IER_SLEEP_MODE 0x10 /* Uart >= 16750 */
127 #define SR_IER_LOW_POWER 0x20 /* Uart >= 16750 */
128 #define SER_DLM(x) ((x)+1) /* Baud Rate Divisor MSB */
129 #define SER_IIR(x) ((x)+2) /* Interrupt Identification Register */
130 #define SR_IIR_SELF 0x00
131 #define SR_IIR_ID_MASK 0x07
132 #define SR_IIR_MSR_CHANGE SR_IIR_SELF
133 #define SR_IIR_THR_EMPTY (SR_IIR_SELF | 2)
134 #define SR_IIR_DATA_RECEIVED (SR_IIR_SELF | 4)
135 #define SR_IIR_ERROR (SR_IIR_SELF | 6)
136 #define SER_FCR(x) ((x)+2) /* FIFO Control Register (Uart >= 16550A) */
137 #define SR_FCR_ENABLE_FIFO 0x01
138 #define SR_FCR_CLEAR_RCVR (0x02 | SR_FCR_ENABLE_FIFO)
139 #define SR_FCR_CLEAR_XMIT (0x04 | SR_FCR_ENABLE_FIFO)
140 #define SR_FCR_1_BYTE (0x00 | SR_FCR_ENABLE_FIFO)
141 #define SR_FCR_4_BYTES (0x40 | SR_FCR_ENABLE_FIFO)
142 #define SR_FCR_8_BYTES (0x80 | SR_FCR_ENABLE_FIFO)
143 #define SR_FCR_14_BYTES (0xC0 | SR_FCR_ENABLE_FIFO)
144 #define SER_LCR(x) ((x)+3) /* Line Control Register */
145 #define SR_LCR_CS5 0x00
146 #define SR_LCR_CS6 0x01
147 #define SR_LCR_CS7 0x02
148 #define SR_LCR_CS8 0x03
149 #define SR_LCR_ST1 0x00
150 #define SR_LCR_ST2 0x04
151 #define SR_LCR_PNO 0x00
152 #define SR_LCR_POD 0x08
153 #define SR_LCR_PEV 0x18
154 #define SR_LCR_PMK 0x28
155 #define SR_LCR_PSP 0x38
156 #define SR_LCR_BRK 0x40
157 #define SR_LCR_DLAB 0x80
158 #define SER_MCR(x) ((x)+4) /* Modem Control Register */
159 #define SR_MCR_DTR SERIAL_DTR_STATE
160 #define SR_MCR_RTS SERIAL_RTS_STATE
161 #define SER_LSR(x) ((x)+5) /* Line Status Register */
162 #define SR_LSR_DATA_RECEIVED 0x01
163 #define SR_LSR_OVERRUN_ERROR 0x02
164 #define SR_LSR_PARITY_ERROR 0x04
165 #define SR_LSR_FRAMING_ERROR 0x08
166 #define SR_LSR_BREAK_INT 0x10
167 #define SR_LSR_THR_EMPTY 0x20
168 #define SR_LSR_TSR_EMPTY 0x40
169 #define SR_LSR_ERROR_IN_FIFO 0x80 /* Uart >= 16550A */
170 #define SER_MSR(x) ((x)+6) /* Modem Status Register */
171 #define SR_MSR_CTS_CHANGED 0x01
172 #define SR_MSR_DSR_CHANGED 0x02
173 #define SR_MSR_RI_CHANGED 0x04
174 #define SR_MSR_DCD_CHANGED 0x08
175 #define SR_MSR_CTS SERIAL_CTS_STATE /* Clear To Send */
176 #define SR_MSR_DSR SERIAL_DSR_STATE /* Data Set Ready */
177 #define SI_MSR_RI SERIAL_RI_STATE /* Ring Indicator */
178 #define SR_MSR_DCD SERIAL_DCD_STATE /* Data Carrier Detect */
179 #define SER_SCR(x) ((x)+7) /* Scratch Pad Register, Uart >= Uart16450 */
181 /************************************ circularbuffer.c */
183 /* FIXME: transform these functions into #define? */
185 InitializeCircularBuffer(
186 IN PCIRCULAR_BUFFER pBuffer
,
187 IN ULONG BufferSize
);
191 IN PCIRCULAR_BUFFER pBuffer
);
194 IsCircularBufferEmpty(
195 IN PCIRCULAR_BUFFER pBuffer
);
198 GetNumberOfElementsInCircularBuffer(
199 IN PCIRCULAR_BUFFER pBuffer
);
202 PushCircularBufferEntry(
203 IN PCIRCULAR_BUFFER pBuffer
,
207 PopCircularBufferEntry(
208 IN PCIRCULAR_BUFFER pBuffer
,
212 IncreaseCircularBufferSize(
213 IN PCIRCULAR_BUFFER pBuffer
,
214 IN ULONG NewBufferSize
);
216 /************************************ cleanup.c */
218 DRIVER_DISPATCH SerialCleanup
;
220 /************************************ close.c */
222 DRIVER_DISPATCH SerialClose
;
224 /************************************ create.c */
226 DRIVER_DISPATCH SerialCreate
;
228 /************************************ devctrl.c */
230 DRIVER_DISPATCH SerialDeviceControl
;
234 IN PSERIAL_DEVICE_EXTENSION DeviceExtension
,
235 IN ULONG NewBaudRate
);
238 SerialSetLineControl(
239 IN PSERIAL_DEVICE_EXTENSION DeviceExtension
,
240 IN PSERIAL_LINE_CONTROL NewSettings
);
242 /************************************ info.c */
244 DRIVER_DISPATCH SerialQueryInformation
;
246 /************************************ legacy.c */
249 SerialDetectUartType(
250 IN PUCHAR ComPortBase
);
252 /************************************ misc.c */
256 IN PDEVICE_OBJECT DeviceObject
,
259 DRIVER_DISPATCH ForwardIrpAndForget
;
264 IN PVOID pDeviceExtension
, // real type PSERIAL_DEVICE_EXTENSION
271 IN PVOID pDeviceExtension
, // real type PSERIAL_DEVICE_EXTENSION
278 IN PVOID pDeviceExtension
, // real type PSERIAL_DEVICE_EXTENSION
279 IN PVOID pIrp
, // real type PIRP
282 KSERVICE_ROUTINE SerialInterruptService
;
284 /************************************ pnp.c */
287 SerialAddDeviceInternal(
288 IN PDRIVER_OBJECT DriverObject
,
289 IN PDEVICE_OBJECT Pdo
,
290 IN UART_TYPE UartType
,
291 IN PULONG pComPortNumber OPTIONAL
,
292 OUT PDEVICE_OBJECT
* pFdo OPTIONAL
);
294 DRIVER_ADD_DEVICE SerialAddDevice
;
297 SerialPnpStartDevice(
298 IN PDEVICE_OBJECT DeviceObject
,
299 IN PCM_RESOURCE_LIST ResourceList
,
300 IN PCM_RESOURCE_LIST ResourceListTranslated
);
302 DRIVER_DISPATCH SerialPnp
;
304 /************************************ power.c */
306 DRIVER_DISPATCH SerialPower
;
308 /************************************ rw.c */
310 DRIVER_DISPATCH SerialRead
;
311 DRIVER_DISPATCH SerialWrite
;