ReactOS  0.4.14-dev-49-gfb4591c
serial.h
Go to the documentation of this file.
1 /*
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
6  *
7  * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
8  */
9 
10 #ifndef _SERIAL_PCH_
11 #define _SERIAL_PCH_
12 
13 #include <ntddk.h>
14 #include <ntddser.h>
15 
16 /* See winbase.h */
17 #define PST_RS232 1
18 #define COMMPROP_INITIALIZED 0xE73CF52E
19 
20 typedef enum
21 {
28 
29 typedef enum
30 {
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 */
38 } UART_TYPE;
39 
40 typedef struct _CIRCULAR_BUFFER
41 {
47 
49 {
54 
56 
64 
69 
79 
81 
82  /* Current values */
83  UCHAR MCR; /* Base+4, Modem Control Register */
84  UCHAR MSR; /* Base+6, Modem Status Register */
86 
87 typedef struct _WORKITEM_DATA
88 {
91 
99 
100 #define SERIAL_TAG 'lreS'
101 
102 #define INFINITE MAXULONG
103 
104 /* Baud master clock */
105 #define BAUD_CLOCK 1843200
106 #define CLOCKS_PER_BIT 16
107 
108 /* UART registers and bits */
109 #define SER_RBR(x) ((PUCHAR)(x)+0) /* Receive Register */
110 #define SER_THR(x) ((PUCHAR)(x)+0) /* Transmit Register */
111 #define SER_DLL(x) ((PUCHAR)(x)+0) /* Baud Rate Divisor LSB */
112 #define SER_IER(x) ((PUCHAR)(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) ((PUCHAR)(x)+1) /* Baud Rate Divisor MSB */
120 #define SER_IIR(x) ((PUCHAR)(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) ((PUCHAR)(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) ((PUCHAR)(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) ((PUCHAR)(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) ((PUCHAR)(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) ((PUCHAR)(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) ((PUCHAR)(x)+7) /* Scratch Pad Register, Uart >= Uart16450 */
171 
172 /************************************ circularbuffer.c */
173 
174 /* FIXME: transform these functions into #define? */
175 NTSTATUS
179 
180 NTSTATUS
183 
184 BOOLEAN
187 
188 ULONG
191 
192 NTSTATUS
195  IN UCHAR Entry);
196 
197 NTSTATUS
200  OUT PUCHAR Entry);
201 
202 NTSTATUS
205  IN ULONG NewBufferSize);
206 
207 /************************************ cleanup.c */
208 
210 
211 /************************************ close.c */
212 
214 
215 /************************************ create.c */
216 
218 
219 /************************************ devctrl.c */
220 
222 
225  IN PSERIAL_DEVICE_EXTENSION DeviceExtension,
226  IN ULONG NewBaudRate);
227 
230  IN PSERIAL_DEVICE_EXTENSION DeviceExtension,
231  IN PSERIAL_LINE_CONTROL NewSettings);
232 
233 /************************************ info.c */
234 
236 
237 /************************************ legacy.c */
238 
239 UART_TYPE
241  IN PUCHAR ComPortBase);
242 
243 /************************************ misc.c */
244 
245 NTSTATUS
248  IN PIRP Irp);
249 
251 
252 VOID NTAPI
254  IN PKDPC Dpc,
255  IN PVOID pDeviceExtension, // real type PSERIAL_DEVICE_EXTENSION
256  IN PVOID Unused1,
257  IN PVOID Unused2);
258 
259 VOID NTAPI
261  IN PKDPC Dpc,
262  IN PVOID pDeviceExtension, // real type PSERIAL_DEVICE_EXTENSION
263  IN PVOID Unused1,
264  IN PVOID Unused2);
265 
266 VOID NTAPI
268  IN PKDPC Dpc,
269  IN PVOID pDeviceExtension, // real type PSERIAL_DEVICE_EXTENSION
270  IN PVOID pIrp, // real type PIRP
271  IN PVOID Unused);
272 
273 KSERVICE_ROUTINE SerialInterruptService;
274 
275 /************************************ pnp.c */
276 
281  IN UART_TYPE UartType,
282  IN PULONG pComPortNumber OPTIONAL,
283  OUT PDEVICE_OBJECT* pFdo OPTIONAL);
284 
285 DRIVER_ADD_DEVICE SerialAddDevice;
286 
291  IN PCM_RESOURCE_LIST ResourceListTranslated);
292 
294 
295 /************************************ power.c */
296 
298 
299 /************************************ rw.c */
300 
303 
304 #endif /* _SERIAL_PCH_ */
PIRP Irp
Definition: serial.h:89
struct _CIRCULAR_BUFFER CIRCULAR_BUFFER
SERIAL_DEVICE_STATE PnpState
Definition: serial.h:52
_Must_inspect_result_ typedef _In_ PVOID Unused
Definition: iotypes.h:1129
#define IN
Definition: typedefs.h:38
CIRCULAR_BUFFER OutputBuffer
Definition: serial.h:77
SERIAL_DEVICE_STATE
Definition: serial.h:20
struct _WORKITEM_DATA WORKITEM_DATA
PIO_WORKITEM IoWorkItem
Definition: serial.h:90
_In_ PDEVICE_OBJECT Pdo
Definition: classpnp.h:301
BOOLEAN UseTotalTimeout
Definition: serial.h:93
NTSTATUS ForwardIrpAndWait(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fdo.c:32
_In_ PIRP Irp
Definition: csq.h:116
BOOLEAN IsCircularBufferEmpty(IN PCIRCULAR_BUFFER pBuffer)
unsigned char * PUCHAR
Definition: retypes.h:3
SERIAL_LINE_CONTROL SerialLineControl
Definition: serial.h:65
LONG NTSTATUS
Definition: precomp.h:26
KSERVICE_ROUTINE SerialInterruptService
Definition: serial.h:273
struct _SERIAL_DEVICE_EXTENSION SERIAL_DEVICE_EXTENSION
ULONG WritePosition
Definition: serial.h:45
struct _WORKITEM_DATA * PWORKITEM_DATA
UNICODE_STRING SerialInterfaceName
Definition: serial.h:80
KSPIN_LOCK InputBufferLock
Definition: serial.h:76
DRIVER_ADD_DEVICE SerialAddDevice
Definition: serial.h:285
PDEVICE_OBJECT Pdo
Definition: serial.h:50
const MUI_LANGUAGE_RESOURCE ResourceList[]
Definition: muilanguages.h:414
DRIVER_DISPATCH SerialWrite
Definition: serial.h:302
SERIAL_TIMEOUTS SerialTimeOuts
Definition: serial.h:72
KEVENT InputBufferNotEmpty
Definition: serial.h:74
BOOLEAN DontWait
Definition: serial.h:96
KSPIN_LOCK OutputBufferLock
Definition: serial.h:78
LARGE_INTEGER IntervalTimeout
Definition: serial.h:94
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
DRIVER_DISPATCH SerialQueryInformation
Definition: serial.h:235
SERIALPERF_STATS SerialPerfStats
Definition: serial.h:71
NTSTATUS NTAPI SerialSetBaudRate(IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN ULONG NewBaudRate)
Definition: devctrl.c:50
DRIVER_DISPATCH SerialClose
Definition: serial.h:213
unsigned char BOOLEAN
PVOID pBuffer
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
UART_TYPE SerialDetectUartType(IN PUCHAR ComPortBase)
Definition: legacy.c:16
ULONG BreakInterruptErrorCount
Definition: serial.h:70
_In_ LARGE_INTEGER _In_opt_ PKDPC Dpc
Definition: kefuncs.h:524
LARGE_INTEGER TotalTimeoutTime
Definition: serial.h:95
BOOLEAN ReadAtLeastOneByte
Definition: serial.h:97
NTSTATUS NTAPI SerialAddDeviceInternal(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT Pdo, IN UART_TYPE UartType, IN PULONG pComPortNumber OPTIONAL, OUT PDEVICE_OBJECT *pFdo OPTIONAL)
Definition: pnp.c:18
#define BufferSize
Definition: classpnp.h:419
ULONG GetNumberOfElementsInCircularBuffer(IN PCIRCULAR_BUFFER pBuffer)
ULONG Length
Definition: serial.h:43
DRIVER_DISPATCH SerialDeviceControl
Definition: serial.h:221
unsigned char UCHAR
Definition: xmlstorage.h:181
NTSTATUS NTAPI SerialSetLineControl(IN PSERIAL_DEVICE_EXTENSION DeviceExtension, IN PSERIAL_LINE_CONTROL NewSettings)
Definition: devctrl.c:88
Definition: ketypes.h:687
NTSTATUS FreeCircularBuffer(IN PCIRCULAR_BUFFER pBuffer)
VOID NTAPI SerialSendByte(IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID Unused1, IN PVOID Unused2)
Definition: misc.c:107
DRIVER_DISPATCH(nfs41_FsdDispatch)
NTSTATUS IncreaseCircularBufferSize(IN PCIRCULAR_BUFFER pBuffer, IN ULONG NewBufferSize)
UART_TYPE
Definition: serial.h:29
DRIVER_DISPATCH SerialRead
Definition: serial.h:301
NTSTATUS PushCircularBufferEntry(IN PCIRCULAR_BUFFER pBuffer, IN UCHAR Entry)
IO_REMOVE_LOCK RemoveLock
Definition: serial.h:53
PKINTERRUPT Interrupt
Definition: serial.h:60
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
ULONG ReadPosition
Definition: serial.h:44
struct _SERIAL_DEVICE_EXTENSION * PSERIAL_DEVICE_EXTENSION
NTSTATUS PopCircularBufferEntry(IN PCIRCULAR_BUFFER pBuffer, OUT PUCHAR Entry)
VOID NTAPI SerialCompleteIrp(IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID pIrp, IN PVOID Unused)
Definition: misc.c:145
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
BOOLEAN UseIntervalTimeout
Definition: serial.h:92
NTSTATUS NTAPI SerialPnpStartDevice(IN PDEVICE_OBJECT DeviceObject, IN PCM_RESOURCE_LIST ResourceList, IN PCM_RESOURCE_LIST ResourceListTranslated)
Definition: pnp.c:136
unsigned int * PULONG
Definition: retypes.h:1
DRIVER_DISPATCH SerialPnp
Definition: serial.h:293
NTSTATUS InitializeCircularBuffer(IN PCIRCULAR_BUFFER pBuffer, IN ULONG BufferSize)
VOID NTAPI SerialReceiveByte(IN PKDPC Dpc, IN PVOID pDeviceExtension, IN PVOID Unused1, IN PVOID Unused2)
Definition: misc.c:70
CIRCULAR_BUFFER InputBuffer
Definition: serial.h:75
#define OUT
Definition: typedefs.h:39
struct _CIRCULAR_BUFFER * PCIRCULAR_BUFFER
unsigned int ULONG
Definition: retypes.h:1
PDEVICE_OBJECT LowerDevice
Definition: serial.h:51
DRIVER_DISPATCH ForwardIrpAndForget
Definition: serial.h:250
DRIVER_DISPATCH SerialCreate
Definition: serial.h:217
DRIVER_DISPATCH SerialPower
Definition: serial.h:297
UART_TYPE UartType
Definition: serial.h:66
base of all file and directory entries
Definition: entries.h:82
PUCHAR Buffer
Definition: serial.h:42
DRIVER_DISPATCH SerialCleanup
Definition: serial.h:209
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68