Merge branch 'linux-next' of git://git.infradead.org/~dedekind/ubifs-2.6
[linux-2.6-block.git] / include / linux / tty_driver.h
CommitLineData
1da177e4
LT
1#ifndef _LINUX_TTY_DRIVER_H
2#define _LINUX_TTY_DRIVER_H
3
4/*
5 * This structure defines the interface between the low-level tty
6 * driver and the tty routines. The following routines can be
7 * defined; unless noted otherwise, they are optional, and can be
8 * filled in with a null pointer.
9 *
10 * int (*open)(struct tty_struct * tty, struct file * filp);
11 *
12 * This routine is called when a particular tty device is opened.
13 * This routine is mandatory; if this routine is not filled in,
14 * the attempted open will fail with ENODEV.
f34d7a5b
AC
15 *
16 * Required method.
1da177e4
LT
17 *
18 * void (*close)(struct tty_struct * tty, struct file * filp);
19 *
20 * This routine is called when a particular tty device is closed.
21 *
f34d7a5b
AC
22 * Required method.
23 *
1da177e4
LT
24 * int (*write)(struct tty_struct * tty,
25 * const unsigned char *buf, int count);
26 *
27 * This routine is called by the kernel to write a series of
28 * characters to the tty device. The characters may come from
29 * user space or kernel space. This routine will return the
36c7343b 30 * number of characters actually accepted for writing.
1da177e4 31 *
f34d7a5b
AC
32 * Optional: Required for writable devices.
33 *
34 * int (*put_char)(struct tty_struct *tty, unsigned char ch);
1da177e4
LT
35 *
36 * This routine is called by the kernel to write a single
37 * character to the tty device. If the kernel uses this routine,
38 * it must call the flush_chars() routine (if defined) when it is
39 * done stuffing characters into the driver. If there is no room
40 * in the queue, the character is ignored.
41 *
f34d7a5b
AC
42 * Optional: Kernel will use the write method if not provided.
43 *
44 * Note: Do not call this function directly, call tty_put_char
45 *
1da177e4
LT
46 * void (*flush_chars)(struct tty_struct *tty);
47 *
48 * This routine is called by the kernel after it has written a
49 * series of characters to the tty device using put_char().
f34d7a5b
AC
50 *
51 * Optional:
52 *
53 * Note: Do not call this function directly, call tty_driver_flush_chars
1da177e4
LT
54 *
55 * int (*write_room)(struct tty_struct *tty);
56 *
57 * This routine returns the numbers of characters the tty driver
58 * will accept for queuing to be written. This number is subject
59 * to change as output buffers get emptied, or if the output flow
60 * control is acted.
f34d7a5b
AC
61 *
62 * Required if write method is provided else not needed.
63 *
64 * Note: Do not call this function directly, call tty_write_room
1da177e4
LT
65 *
66 * int (*ioctl)(struct tty_struct *tty, struct file * file,
67 * unsigned int cmd, unsigned long arg);
68 *
69 * This routine allows the tty driver to implement
70 * device-specific ioctl's. If the ioctl number passed in cmd
71 * is not recognized by the driver, it should return ENOIOCTLCMD.
e10cc1df 72 *
f34d7a5b
AC
73 * Optional
74 *
e10cc1df
PF
75 * long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
76 * unsigned int cmd, unsigned long arg);
77 *
78 * implement ioctl processing for 32 bit process on 64 bit system
f34d7a5b
AC
79 *
80 * Optional
1da177e4 81 *
edc6afc5 82 * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
1da177e4
LT
83 *
84 * This routine allows the tty driver to be notified when
f34d7a5b
AC
85 * device's termios settings have changed.
86 *
87 * Optional: Called under the termios lock
88 *
1da177e4
LT
89 *
90 * void (*set_ldisc)(struct tty_struct *tty);
91 *
92 * This routine allows the tty driver to be notified when the
93 * device's termios settings have changed.
f34d7a5b
AC
94 *
95 * Optional: Called under BKL (currently)
1da177e4
LT
96 *
97 * void (*throttle)(struct tty_struct * tty);
98 *
99 * This routine notifies the tty driver that input buffers for
100 * the line discipline are close to full, and it should somehow
101 * signal that no more characters should be sent to the tty.
39c2e60f
AC
102 *
103 * Optional: Always invoke via tty_throttle();
1da177e4
LT
104 *
105 * void (*unthrottle)(struct tty_struct * tty);
106 *
107 * This routine notifies the tty drivers that it should signals
108 * that characters can now be sent to the tty without fear of
109 * overrunning the input buffers of the line disciplines.
110 *
39c2e60f
AC
111 * Optional: Always invoke via tty_unthrottle();
112 *
1da177e4
LT
113 * void (*stop)(struct tty_struct *tty);
114 *
115 * This routine notifies the tty driver that it should stop
116 * outputting characters to the tty device.
f34d7a5b
AC
117 *
118 * Optional:
119 *
120 * Note: Call stop_tty not this method.
1da177e4
LT
121 *
122 * void (*start)(struct tty_struct *tty);
123 *
124 * This routine notifies the tty driver that it resume sending
125 * characters to the tty device.
f34d7a5b
AC
126 *
127 * Optional:
128 *
129 * Note: Call start_tty not this method.
1da177e4
LT
130 *
131 * void (*hangup)(struct tty_struct *tty);
132 *
133 * This routine notifies the tty driver that it should hangup the
134 * tty device.
135 *
36c7343b 136 * Optional:
f34d7a5b 137 *
9e98966c 138 * int (*break_ctl)(struct tty_stuct *tty, int state);
1da177e4
LT
139 *
140 * This optional routine requests the tty driver to turn on or
141 * off BREAK status on the RS-232 port. If state is -1,
142 * then the BREAK status should be turned on; if state is 0, then
143 * BREAK should be turned off.
144 *
145 * If this routine is implemented, the high-level tty driver will
146 * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK,
f34d7a5b
AC
147 * TIOCCBRK.
148 *
9e98966c
AC
149 * If the driver sets TTY_DRIVER_HARDWARE_BREAK then the interface
150 * will also be called with actual times and the hardware is expected
151 * to do the delay work itself. 0 and -1 are still used for on/off.
152 *
f34d7a5b 153 * Optional: Required for TCSBRK/BRKP/etc handling.
1da177e4
LT
154 *
155 * void (*wait_until_sent)(struct tty_struct *tty, int timeout);
156 *
157 * This routine waits until the device has written out all of the
158 * characters in its transmitter FIFO.
159 *
f34d7a5b
AC
160 * Optional: If not provided the device is assumed to have no FIFO
161 *
162 * Note: Usually correct to call tty_wait_until_sent
163 *
1da177e4
LT
164 * void (*send_xchar)(struct tty_struct *tty, char ch);
165 *
166 * This routine is used to send a high-priority XON/XOFF
167 * character to the device.
f34d7a5b
AC
168 *
169 * Optional: If not provided then the write method is called under
170 * the atomic write lock to keep it serialized with the ldisc.
1da177e4
LT
171 */
172
173#include <linux/fs.h>
174#include <linux/list.h>
175#include <linux/cdev.h>
176
177struct tty_struct;
f2d937f3 178struct tty_driver;
1da177e4
LT
179
180struct tty_operations {
181 int (*open)(struct tty_struct * tty, struct file * filp);
182 void (*close)(struct tty_struct * tty, struct file * filp);
183 int (*write)(struct tty_struct * tty,
184 const unsigned char *buf, int count);
f34d7a5b 185 int (*put_char)(struct tty_struct *tty, unsigned char ch);
1da177e4
LT
186 void (*flush_chars)(struct tty_struct *tty);
187 int (*write_room)(struct tty_struct *tty);
188 int (*chars_in_buffer)(struct tty_struct *tty);
189 int (*ioctl)(struct tty_struct *tty, struct file * file,
190 unsigned int cmd, unsigned long arg);
e10cc1df
PF
191 long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
192 unsigned int cmd, unsigned long arg);
edc6afc5 193 void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
1da177e4
LT
194 void (*throttle)(struct tty_struct * tty);
195 void (*unthrottle)(struct tty_struct * tty);
196 void (*stop)(struct tty_struct *tty);
197 void (*start)(struct tty_struct *tty);
198 void (*hangup)(struct tty_struct *tty);
9e98966c 199 int (*break_ctl)(struct tty_struct *tty, int state);
1da177e4
LT
200 void (*flush_buffer)(struct tty_struct *tty);
201 void (*set_ldisc)(struct tty_struct *tty);
202 void (*wait_until_sent)(struct tty_struct *tty, int timeout);
203 void (*send_xchar)(struct tty_struct *tty, char ch);
204 int (*read_proc)(char *page, char **start, off_t off,
205 int count, int *eof, void *data);
1da177e4
LT
206 int (*tiocmget)(struct tty_struct *tty, struct file *file);
207 int (*tiocmset)(struct tty_struct *tty, struct file *file,
208 unsigned int set, unsigned int clear);
f2d937f3
JW
209#ifdef CONFIG_CONSOLE_POLL
210 int (*poll_init)(struct tty_driver *driver, int line, char *options);
211 int (*poll_get_char)(struct tty_driver *driver, int line);
212 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
213#endif
1da177e4
LT
214};
215
216struct tty_driver {
217 int magic; /* magic number for this structure */
218 struct cdev cdev;
219 struct module *owner;
220 const char *driver_name;
1da177e4
LT
221 const char *name;
222 int name_base; /* offset of printed name */
223 int major; /* major device number */
224 int minor_start; /* start of minor device number */
225 int minor_num; /* number of *possible* devices */
226 int num; /* number of devices allocated */
227 short type; /* type of tty driver */
228 short subtype; /* subtype of tty driver */
edc6afc5 229 struct ktermios init_termios; /* Initial termios */
1da177e4
LT
230 int flags; /* tty driver flags */
231 int refcount; /* for loadable tty drivers */
232 struct proc_dir_entry *proc_entry; /* /proc fs entry */
233 struct tty_driver *other; /* only used for the PTY driver */
234
235 /*
236 * Pointer to the tty data structures
237 */
238 struct tty_struct **ttys;
edc6afc5
AC
239 struct ktermios **termios;
240 struct ktermios **termios_locked;
f34d7a5b
AC
241 void *driver_state;
242
1da177e4 243 /*
f34d7a5b 244 * Driver methods
1da177e4 245 */
1da177e4 246
f34d7a5b 247 const struct tty_operations *ops;
1da177e4
LT
248 struct list_head tty_drivers;
249};
250
251extern struct list_head tty_drivers;
252
253struct tty_driver *alloc_tty_driver(int lines);
254void put_tty_driver(struct tty_driver *driver);
b68e31d0
JD
255void tty_set_operations(struct tty_driver *driver,
256 const struct tty_operations *op);
f2d937f3 257extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
1da177e4
LT
258
259/* tty driver magic number */
260#define TTY_DRIVER_MAGIC 0x5402
261
262/*
263 * tty driver flags
264 *
265 * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the
266 * termios setting when the last process has closed the device.
267 * Used for PTY's, in particular.
268 *
269 * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will
270 * guarantee never not to set any special character handling
271 * flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR ||
272 * !INPCK)). That is, if there is no reason for the driver to
273 * send notifications of parity and break characters up to the
274 * line driver, it won't do so. This allows the line driver to
275 * optimize for this case if this flag is set. (Note that there
276 * is also a promise, if the above case is true, not to signal
277 * overruns, either.)
278 *
331b8319
GKH
279 * TTY_DRIVER_DYNAMIC_DEV --- if set, the individual tty devices need
280 * to be registered with a call to tty_register_driver() when the
281 * device is found in the system and unregistered with a call to
282 * tty_unregister_device() so the devices will be show up
283 * properly in sysfs. If not set, driver->num entries will be
284 * created by the tty core in sysfs when tty_register_driver() is
285 * called. This is to be used by drivers that have tty devices
286 * that can appear and disappear while the main tty driver is
287 * registered with the tty core.
1da177e4
LT
288 *
289 * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead
290 * use dynamic memory keyed through the devpts filesystem. This
291 * is only applicable to the pty driver.
9e98966c
AC
292 *
293 * TTY_DRIVER_HARDWARE_BREAK -- hardware handles break signals. Pass
294 * the requested timeout to the caller instead of using a simple
295 * on/off interface.
296 *
1da177e4
LT
297 */
298#define TTY_DRIVER_INSTALLED 0x0001
299#define TTY_DRIVER_RESET_TERMIOS 0x0002
300#define TTY_DRIVER_REAL_RAW 0x0004
331b8319 301#define TTY_DRIVER_DYNAMIC_DEV 0x0008
1da177e4 302#define TTY_DRIVER_DEVPTS_MEM 0x0010
9e98966c 303#define TTY_DRIVER_HARDWARE_BREAK 0x0020
1da177e4
LT
304
305/* tty driver types */
306#define TTY_DRIVER_TYPE_SYSTEM 0x0001
307#define TTY_DRIVER_TYPE_CONSOLE 0x0002
308#define TTY_DRIVER_TYPE_SERIAL 0x0003
309#define TTY_DRIVER_TYPE_PTY 0x0004
310#define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */
311#define TTY_DRIVER_TYPE_SYSCONS 0x0006
312
313/* system subtypes (magic, used by tty_io.c) */
314#define SYSTEM_TYPE_TTY 0x0001
315#define SYSTEM_TYPE_CONSOLE 0x0002
316#define SYSTEM_TYPE_SYSCONS 0x0003
317#define SYSTEM_TYPE_SYSPTMX 0x0004
318
319/* pty subtypes (magic, used by tty_io.c) */
320#define PTY_TYPE_MASTER 0x0001
321#define PTY_TYPE_SLAVE 0x0002
322
323/* serial subtype definitions */
324#define SERIAL_TYPE_NORMAL 1
325
326#endif /* #ifdef _LINUX_TTY_DRIVER_H */