tty: Add termiox
[linux-2.6.git] / include / linux / tty_driver.h
blobac6e58e26b73f4f9d55ab5e32a188c783dd9d3c5
1 #ifndef _LINUX_TTY_DRIVER_H
2 #define _LINUX_TTY_DRIVER_H
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.
10 * int (*open)(struct tty_struct * tty, struct file * filp);
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.
16 * Required method.
18 * void (*close)(struct tty_struct * tty, struct file * filp);
20 * This routine is called when a particular tty device is closed.
22 * Required method.
24 * int (*write)(struct tty_struct * tty,
25 * const unsigned char *buf, int count);
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
30 * number of characters actually accepted for writing.
32 * Optional: Required for writable devices.
34 * int (*put_char)(struct tty_struct *tty, unsigned char ch);
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.
42 * Optional: Kernel will use the write method if not provided.
44 * Note: Do not call this function directly, call tty_put_char
46 * void (*flush_chars)(struct tty_struct *tty);
48 * This routine is called by the kernel after it has written a
49 * series of characters to the tty device using put_char().
51 * Optional:
53 * Note: Do not call this function directly, call tty_driver_flush_chars
55 * int (*write_room)(struct tty_struct *tty);
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.
62 * Required if write method is provided else not needed.
64 * Note: Do not call this function directly, call tty_write_room
66 * int (*ioctl)(struct tty_struct *tty, struct file * file,
67 * unsigned int cmd, unsigned long arg);
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.
73 * Optional
75 * long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
76 * unsigned int cmd, unsigned long arg);
78 * implement ioctl processing for 32 bit process on 64 bit system
80 * Optional
82 * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
84 * This routine allows the tty driver to be notified when
85 * device's termios settings have changed.
87 * Optional: Called under the termios lock
90 * void (*set_ldisc)(struct tty_struct *tty);
92 * This routine allows the tty driver to be notified when the
93 * device's termios settings have changed.
95 * Optional: Called under BKL (currently)
97 * void (*throttle)(struct tty_struct * tty);
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.
103 * Optional: Always invoke via tty_throttle();
105 * void (*unthrottle)(struct tty_struct * tty);
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.
111 * Optional: Always invoke via tty_unthrottle();
113 * void (*stop)(struct tty_struct *tty);
115 * This routine notifies the tty driver that it should stop
116 * outputting characters to the tty device.
118 * Optional:
120 * Note: Call stop_tty not this method.
122 * void (*start)(struct tty_struct *tty);
124 * This routine notifies the tty driver that it resume sending
125 * characters to the tty device.
127 * Optional:
129 * Note: Call start_tty not this method.
131 * void (*hangup)(struct tty_struct *tty);
133 * This routine notifies the tty driver that it should hangup the
134 * tty device.
136 * Optional:
138 * int (*break_ctl)(struct tty_stuct *tty, int state);
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.
145 * If this routine is implemented, the high-level tty driver will
146 * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK,
147 * TIOCCBRK.
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.
153 * Optional: Required for TCSBRK/BRKP/etc handling.
155 * void (*wait_until_sent)(struct tty_struct *tty, int timeout);
157 * This routine waits until the device has written out all of the
158 * characters in its transmitter FIFO.
160 * Optional: If not provided the device is assumed to have no FIFO
162 * Note: Usually correct to call tty_wait_until_sent
164 * void (*send_xchar)(struct tty_struct *tty, char ch);
166 * This routine is used to send a high-priority XON/XOFF
167 * character to the device.
169 * Optional: If not provided then the write method is called under
170 * the atomic write lock to keep it serialized with the ldisc.
172 * int (*resize)(struct tty_struct *tty, struct tty_struct *real_tty,
173 * unsigned int rows, unsigned int cols);
175 * Called when a termios request is issued which changes the
176 * requested terminal geometry.
178 * Optional: the default action is to update the termios structure
179 * without error. This is usually the correct behaviour. Drivers should
180 * not force errors here if they are not resizable objects (eg a serial
181 * line). See tty_do_resize() if you need to wrap the standard method
182 * in your own logic - the usual case.
184 * void (*set_termiox)(struct tty_struct *tty, struct termiox *new);
186 * Called when the device receives a termiox based ioctl. Passes down
187 * the requested data from user space. This method will not be invoked
188 * unless the tty also has a valid tty->termiox pointer.
190 * Optional: Called under the termios lock
193 #include <linux/fs.h>
194 #include <linux/list.h>
195 #include <linux/cdev.h>
197 struct tty_struct;
198 struct tty_driver;
200 struct tty_operations {
201 int (*open)(struct tty_struct * tty, struct file * filp);
202 void (*close)(struct tty_struct * tty, struct file * filp);
203 int (*write)(struct tty_struct * tty,
204 const unsigned char *buf, int count);
205 int (*put_char)(struct tty_struct *tty, unsigned char ch);
206 void (*flush_chars)(struct tty_struct *tty);
207 int (*write_room)(struct tty_struct *tty);
208 int (*chars_in_buffer)(struct tty_struct *tty);
209 int (*ioctl)(struct tty_struct *tty, struct file * file,
210 unsigned int cmd, unsigned long arg);
211 long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
212 unsigned int cmd, unsigned long arg);
213 void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
214 void (*throttle)(struct tty_struct * tty);
215 void (*unthrottle)(struct tty_struct * tty);
216 void (*stop)(struct tty_struct *tty);
217 void (*start)(struct tty_struct *tty);
218 void (*hangup)(struct tty_struct *tty);
219 int (*break_ctl)(struct tty_struct *tty, int state);
220 void (*flush_buffer)(struct tty_struct *tty);
221 void (*set_ldisc)(struct tty_struct *tty);
222 void (*wait_until_sent)(struct tty_struct *tty, int timeout);
223 void (*send_xchar)(struct tty_struct *tty, char ch);
224 int (*read_proc)(char *page, char **start, off_t off,
225 int count, int *eof, void *data);
226 int (*tiocmget)(struct tty_struct *tty, struct file *file);
227 int (*tiocmset)(struct tty_struct *tty, struct file *file,
228 unsigned int set, unsigned int clear);
229 int (*resize)(struct tty_struct *tty, struct tty_struct *real_tty,
230 struct winsize *ws);
231 int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
232 #ifdef CONFIG_CONSOLE_POLL
233 int (*poll_init)(struct tty_driver *driver, int line, char *options);
234 int (*poll_get_char)(struct tty_driver *driver, int line);
235 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
236 #endif
239 struct tty_driver {
240 int magic; /* magic number for this structure */
241 struct cdev cdev;
242 struct module *owner;
243 const char *driver_name;
244 const char *name;
245 int name_base; /* offset of printed name */
246 int major; /* major device number */
247 int minor_start; /* start of minor device number */
248 int minor_num; /* number of *possible* devices */
249 int num; /* number of devices allocated */
250 short type; /* type of tty driver */
251 short subtype; /* subtype of tty driver */
252 struct ktermios init_termios; /* Initial termios */
253 int flags; /* tty driver flags */
254 int refcount; /* for loadable tty drivers */
255 struct proc_dir_entry *proc_entry; /* /proc fs entry */
256 struct tty_driver *other; /* only used for the PTY driver */
259 * Pointer to the tty data structures
261 struct tty_struct **ttys;
262 struct ktermios **termios;
263 struct ktermios **termios_locked;
264 void *driver_state;
267 * Driver methods
270 const struct tty_operations *ops;
271 struct list_head tty_drivers;
274 extern struct list_head tty_drivers;
276 struct tty_driver *alloc_tty_driver(int lines);
277 void put_tty_driver(struct tty_driver *driver);
278 void tty_set_operations(struct tty_driver *driver,
279 const struct tty_operations *op);
280 extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
282 /* tty driver magic number */
283 #define TTY_DRIVER_MAGIC 0x5402
286 * tty driver flags
288 * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the
289 * termios setting when the last process has closed the device.
290 * Used for PTY's, in particular.
292 * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will
293 * guarantee never not to set any special character handling
294 * flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR ||
295 * !INPCK)). That is, if there is no reason for the driver to
296 * send notifications of parity and break characters up to the
297 * line driver, it won't do so. This allows the line driver to
298 * optimize for this case if this flag is set. (Note that there
299 * is also a promise, if the above case is true, not to signal
300 * overruns, either.)
302 * TTY_DRIVER_DYNAMIC_DEV --- if set, the individual tty devices need
303 * to be registered with a call to tty_register_driver() when the
304 * device is found in the system and unregistered with a call to
305 * tty_unregister_device() so the devices will be show up
306 * properly in sysfs. If not set, driver->num entries will be
307 * created by the tty core in sysfs when tty_register_driver() is
308 * called. This is to be used by drivers that have tty devices
309 * that can appear and disappear while the main tty driver is
310 * registered with the tty core.
312 * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead
313 * use dynamic memory keyed through the devpts filesystem. This
314 * is only applicable to the pty driver.
316 * TTY_DRIVER_HARDWARE_BREAK -- hardware handles break signals. Pass
317 * the requested timeout to the caller instead of using a simple
318 * on/off interface.
321 #define TTY_DRIVER_INSTALLED 0x0001
322 #define TTY_DRIVER_RESET_TERMIOS 0x0002
323 #define TTY_DRIVER_REAL_RAW 0x0004
324 #define TTY_DRIVER_DYNAMIC_DEV 0x0008
325 #define TTY_DRIVER_DEVPTS_MEM 0x0010
326 #define TTY_DRIVER_HARDWARE_BREAK 0x0020
328 /* tty driver types */
329 #define TTY_DRIVER_TYPE_SYSTEM 0x0001
330 #define TTY_DRIVER_TYPE_CONSOLE 0x0002
331 #define TTY_DRIVER_TYPE_SERIAL 0x0003
332 #define TTY_DRIVER_TYPE_PTY 0x0004
333 #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */
334 #define TTY_DRIVER_TYPE_SYSCONS 0x0006
336 /* system subtypes (magic, used by tty_io.c) */
337 #define SYSTEM_TYPE_TTY 0x0001
338 #define SYSTEM_TYPE_CONSOLE 0x0002
339 #define SYSTEM_TYPE_SYSCONS 0x0003
340 #define SYSTEM_TYPE_SYSPTMX 0x0004
342 /* pty subtypes (magic, used by tty_io.c) */
343 #define PTY_TYPE_MASTER 0x0001
344 #define PTY_TYPE_SLAVE 0x0002
346 /* serial subtype definitions */
347 #define SERIAL_TYPE_NORMAL 1
349 #endif /* #ifdef _LINUX_TTY_DRIVER_H */