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
27 } SERIAL_DEVICE_STATE
;
32 Uart8250
, /* initial version */
33 Uart16450
, /* + 38.4 Kbps */
34 Uart16550
, /* + 115 Kbps */
35 Uart16550A
,/* + FIFO 16 bytes */
36 Uart16650
, /* + FIFO 32 bytes, 230 Kbps, power management, auto-flow */
37 Uart16750
/* + FIFO 64 bytes, 460 Kbps */
40 typedef struct _CIRCULAR_BUFFER
46 } CIRCULAR_BUFFER
, *PCIRCULAR_BUFFER
;
48 typedef struct _SERIAL_DEVICE_EXTENSION
51 PDEVICE_OBJECT LowerDevice
;
52 SERIAL_DEVICE_STATE PnpState
;
53 IO_REMOVE_LOCK RemoveLock
;
55 ULONG SerialPortNumber
;
60 PKINTERRUPT Interrupt
;
65 SERIAL_LINE_CONTROL SerialLineControl
;
70 ULONG BreakInterruptErrorCount
;
71 SERIALPERF_STATS SerialPerfStats
;
72 SERIAL_TIMEOUTS SerialTimeOuts
;
74 KEVENT InputBufferNotEmpty
;
75 CIRCULAR_BUFFER InputBuffer
;
76 KSPIN_LOCK InputBufferLock
;
77 CIRCULAR_BUFFER OutputBuffer
;
78 KSPIN_LOCK OutputBufferLock
;
80 UNICODE_STRING SerialInterfaceName
;
83 UCHAR MCR
; /* Base+4, Modem Control Register */
84 UCHAR MSR
; /* Base+6, Modem Status Register */
85 } SERIAL_DEVICE_EXTENSION
, *PSERIAL_DEVICE_EXTENSION
;
87 typedef struct _WORKITEM_DATA
90 PIO_WORKITEM IoWorkItem
;
92 BOOLEAN UseIntervalTimeout
;
93 BOOLEAN UseTotalTimeout
;
94 LARGE_INTEGER IntervalTimeout
;
95 LARGE_INTEGER TotalTimeoutTime
;
97 BOOLEAN ReadAtLeastOneByte
;
98 } WORKITEM_DATA
, *PWORKITEM_DATA
;
100 #define SERIAL_TAG 'lreS'
102 #define INFINITE MAXULONG
104 /* Baud master clock */
105 #define BAUD_CLOCK 1843200
106 #define CLOCKS_PER_BIT 16
108 /* UART registers and bits */
109 #define SER_RBR(x) ((x)+0) /* Receive Register */
110 #define SER_THR(x) ((x)+0) /* Transmit Register */
111 #define SER_DLL(x) ((x)+0) /* Baud Rate Divisor LSB */
112 #define SER_IER(x) ((x)+1) /* Interrupt Enable Register */
113 #define SR_IER_DATA_RECEIVED 0x01
114 #define SR_IER_THR_EMPTY 0x02
115 #define SR_IER_LSR_CHANGE 0x04
116 #define SR_IER_MSR_CHANGE 0x08
117 #define SR_IER_SLEEP_MODE 0x10 /* Uart >= 16750 */
118 #define SR_IER_LOW_POWER 0x20 /* Uart >= 16750 */
119 #define SER_DLM(x) ((x)+1) /* Baud Rate Divisor MSB */
120 #define SER_IIR(x) ((x)+2) /* Interrupt Identification Register */
121 #define SR_IIR_SELF 0x00
122 #define SR_IIR_ID_MASK 0x07
123 #define SR_IIR_MSR_CHANGE SR_IIR_SELF
124 #define SR_IIR_THR_EMPTY (SR_IIR_SELF | 2)
125 #define SR_IIR_DATA_RECEIVED (SR_IIR_SELF | 4)
126 #define SR_IIR_ERROR (SR_IIR_SELF | 6)
127 #define SER_FCR(x) ((x)+2) /* FIFO Control Register (Uart >= 16550A) */
128 #define SR_FCR_ENABLE_FIFO 0x01
129 #define SR_FCR_CLEAR_RCVR (0x02 | SR_FCR_ENABLE_FIFO)
130 #define SR_FCR_CLEAR_XMIT (0x04 | SR_FCR_ENABLE_FIFO)
131 #define SR_FCR_1_BYTE (0x00 | SR_FCR_ENABLE_FIFO)
132 #define SR_FCR_4_BYTES (0x40 | SR_FCR_ENABLE_FIFO)
133 #define SR_FCR_8_BYTES (0x80 | SR_FCR_ENABLE_FIFO)
134 #define SR_FCR_14_BYTES (0xC0 | SR_FCR_ENABLE_FIFO)
135 #define SER_LCR(x) ((x)+3) /* Line Control Register */
136 #define SR_LCR_CS5 0x00
137 #define SR_LCR_CS6 0x01
138 #define SR_LCR_CS7 0x02
139 #define SR_LCR_CS8 0x03
140 #define SR_LCR_ST1 0x00
141 #define SR_LCR_ST2 0x04
142 #define SR_LCR_PNO 0x00
143 #define SR_LCR_POD 0x08
144 #define SR_LCR_PEV 0x18
145 #define SR_LCR_PMK 0x28
146 #define SR_LCR_PSP 0x38
147 #define SR_LCR_BRK 0x40
148 #define SR_LCR_DLAB 0x80
149 #define SER_MCR(x) ((x)+4) /* Modem Control Register */
150 #define SR_MCR_DTR SERIAL_DTR_STATE
151 #define SR_MCR_RTS SERIAL_RTS_STATE
152 #define SER_LSR(x) ((x)+5) /* Line Status Register */
153 #define SR_LSR_DATA_RECEIVED 0x01
154 #define SR_LSR_OVERRUN_ERROR 0x02
155 #define SR_LSR_PARITY_ERROR 0x04
156 #define SR_LSR_FRAMING_ERROR 0x08
157 #define SR_LSR_BREAK_INT 0x10
158 #define SR_LSR_THR_EMPTY 0x20
159 #define SR_LSR_TSR_EMPTY 0x40
160 #define SR_LSR_ERROR_IN_FIFO 0x80 /* Uart >= 16550A */
161 #define SER_MSR(x) ((x)+6) /* Modem Status Register */
162 #define SR_MSR_CTS_CHANGED 0x01
163 #define SR_MSR_DSR_CHANGED 0x02
164 #define SR_MSR_RI_CHANGED 0x04
165 #define SR_MSR_DCD_CHANGED 0x08
166 #define SR_MSR_CTS SERIAL_CTS_STATE /* Clear To Send */
167 #define SR_MSR_DSR SERIAL_DSR_STATE /* Data Set Ready */
168 #define SI_MSR_RI SERIAL_RI_STATE /* Ring Indicator */
169 #define SR_MSR_DCD SERIAL_DCD_STATE /* Data Carrier Detect */
170 #define SER_SCR(x) ((x)+7) /* Scratch Pad Register, Uart >= Uart16450 */
172 /************************************ circularbuffer.c */
174 /* FIXME: transform these functions into #define? */
176 InitializeCircularBuffer(
177 IN PCIRCULAR_BUFFER pBuffer
,
178 IN ULONG BufferSize
);
182 IN PCIRCULAR_BUFFER pBuffer
);
185 IsCircularBufferEmpty(
186 IN PCIRCULAR_BUFFER pBuffer
);
189 GetNumberOfElementsInCircularBuffer(
190 IN PCIRCULAR_BUFFER pBuffer
);
193 PushCircularBufferEntry(
194 IN PCIRCULAR_BUFFER pBuffer
,
198 PopCircularBufferEntry(
199 IN PCIRCULAR_BUFFER pBuffer
,
203 IncreaseCircularBufferSize(
204 IN PCIRCULAR_BUFFER pBuffer
,
205 IN ULONG NewBufferSize
);
207 /************************************ cleanup.c */
209 DRIVER_DISPATCH SerialCleanup
;
211 /************************************ close.c */
213 DRIVER_DISPATCH SerialClose
;
215 /************************************ create.c */
217 DRIVER_DISPATCH SerialCreate
;
219 /************************************ devctrl.c */
221 DRIVER_DISPATCH SerialDeviceControl
;
225 IN PSERIAL_DEVICE_EXTENSION DeviceExtension
,
226 IN ULONG NewBaudRate
);
229 SerialSetLineControl(
230 IN PSERIAL_DEVICE_EXTENSION DeviceExtension
,
231 IN PSERIAL_LINE_CONTROL NewSettings
);
233 /************************************ info.c */
235 DRIVER_DISPATCH SerialQueryInformation
;
237 /************************************ legacy.c */
240 SerialDetectUartType(
241 IN PUCHAR ComPortBase
);
243 /************************************ misc.c */
247 IN PDEVICE_OBJECT DeviceObject
,
250 DRIVER_DISPATCH ForwardIrpAndForget
;
255 IN PVOID pDeviceExtension
, // real type PSERIAL_DEVICE_EXTENSION
262 IN PVOID pDeviceExtension
, // real type PSERIAL_DEVICE_EXTENSION
269 IN PVOID pDeviceExtension
, // real type PSERIAL_DEVICE_EXTENSION
270 IN PVOID pIrp
, // real type PIRP
273 KSERVICE_ROUTINE SerialInterruptService
;
275 /************************************ pnp.c */
278 SerialAddDeviceInternal(
279 IN PDRIVER_OBJECT DriverObject
,
280 IN PDEVICE_OBJECT Pdo
,
281 IN UART_TYPE UartType
,
282 IN PULONG pComPortNumber OPTIONAL
,
283 OUT PDEVICE_OBJECT
* pFdo OPTIONAL
);
285 DRIVER_ADD_DEVICE SerialAddDevice
;
288 SerialPnpStartDevice(
289 IN PDEVICE_OBJECT DeviceObject
,
290 IN PCM_RESOURCE_LIST ResourceList
,
291 IN PCM_RESOURCE_LIST ResourceListTranslated
);
293 DRIVER_DISPATCH SerialPnp
;
295 /************************************ power.c */
297 DRIVER_DISPATCH SerialPower
;
299 /************************************ rw.c */
301 DRIVER_DISPATCH SerialRead
;
302 DRIVER_DISPATCH SerialWrite
;