Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 15 | * |
| 16 | * Required method. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 22 | * Required method. |
| 23 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Alan Cox | 36c7343 | 2008-06-23 12:06:52 +0100 | [diff] [blame] | 30 | * number of characters actually accepted for writing. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | * |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 32 | * Optional: Required for writable devices. |
| 33 | * |
| 34 | * int (*put_char)(struct tty_struct *tty, unsigned char ch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 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 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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(). |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 50 | * |
| 51 | * Optional: |
| 52 | * |
| 53 | * Note: Do not call this function directly, call tty_driver_flush_chars |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 61 | * |
| 62 | * Required if write method is provided else not needed. |
| 63 | * |
| 64 | * Note: Do not call this function directly, call tty_write_room |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Paul Fulghum | e10cc1d | 2007-05-10 22:22:50 -0700 | [diff] [blame] | 72 | * |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 73 | * Optional |
| 74 | * |
Paul Fulghum | e10cc1d | 2007-05-10 22:22:50 -0700 | [diff] [blame] | 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 |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 79 | * |
| 80 | * Optional |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | * |
Alan Cox | edc6afc | 2006-12-08 02:38:44 -0800 | [diff] [blame] | 82 | * void (*set_termios)(struct tty_struct *tty, struct ktermios * old); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | * |
| 84 | * This routine allows the tty driver to be notified when |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 85 | * device's termios settings have changed. |
| 86 | * |
| 87 | * Optional: Called under the termios lock |
| 88 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 94 | * |
| 95 | * Optional: Called under BKL (currently) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Alan Cox | 39c2e60 | 2008-04-30 00:54:18 -0700 | [diff] [blame] | 102 | * |
| 103 | * Optional: Always invoke via tty_throttle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Alan Cox | 39c2e60 | 2008-04-30 00:54:18 -0700 | [diff] [blame] | 111 | * Optional: Always invoke via tty_unthrottle(); |
| 112 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 117 | * |
| 118 | * Optional: |
| 119 | * |
| 120 | * Note: Call stop_tty not this method. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 126 | * |
| 127 | * Optional: |
| 128 | * |
| 129 | * Note: Call start_tty not this method. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Alan Cox | 36c7343 | 2008-06-23 12:06:52 +0100 | [diff] [blame] | 136 | * Optional: |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 137 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | * void (*break_ctl)(struct tty_stuct *tty, int state); |
| 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, |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 147 | * TIOCCBRK. |
| 148 | * |
| 149 | * Optional: Required for TCSBRK/BRKP/etc handling. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | * |
| 151 | * void (*wait_until_sent)(struct tty_struct *tty, int timeout); |
| 152 | * |
| 153 | * This routine waits until the device has written out all of the |
| 154 | * characters in its transmitter FIFO. |
| 155 | * |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 156 | * Optional: If not provided the device is assumed to have no FIFO |
| 157 | * |
| 158 | * Note: Usually correct to call tty_wait_until_sent |
| 159 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | * void (*send_xchar)(struct tty_struct *tty, char ch); |
| 161 | * |
| 162 | * This routine is used to send a high-priority XON/XOFF |
| 163 | * character to the device. |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 164 | * |
| 165 | * Optional: If not provided then the write method is called under |
| 166 | * the atomic write lock to keep it serialized with the ldisc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | */ |
| 168 | |
| 169 | #include <linux/fs.h> |
| 170 | #include <linux/list.h> |
| 171 | #include <linux/cdev.h> |
| 172 | |
| 173 | struct tty_struct; |
Jason Wessel | f2d937f | 2008-04-17 20:05:37 +0200 | [diff] [blame] | 174 | struct tty_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | struct tty_operations { |
| 177 | int (*open)(struct tty_struct * tty, struct file * filp); |
| 178 | void (*close)(struct tty_struct * tty, struct file * filp); |
| 179 | int (*write)(struct tty_struct * tty, |
| 180 | const unsigned char *buf, int count); |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 181 | int (*put_char)(struct tty_struct *tty, unsigned char ch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | void (*flush_chars)(struct tty_struct *tty); |
| 183 | int (*write_room)(struct tty_struct *tty); |
| 184 | int (*chars_in_buffer)(struct tty_struct *tty); |
| 185 | int (*ioctl)(struct tty_struct *tty, struct file * file, |
| 186 | unsigned int cmd, unsigned long arg); |
Paul Fulghum | e10cc1d | 2007-05-10 22:22:50 -0700 | [diff] [blame] | 187 | long (*compat_ioctl)(struct tty_struct *tty, struct file * file, |
| 188 | unsigned int cmd, unsigned long arg); |
Alan Cox | edc6afc | 2006-12-08 02:38:44 -0800 | [diff] [blame] | 189 | void (*set_termios)(struct tty_struct *tty, struct ktermios * old); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | void (*throttle)(struct tty_struct * tty); |
| 191 | void (*unthrottle)(struct tty_struct * tty); |
| 192 | void (*stop)(struct tty_struct *tty); |
| 193 | void (*start)(struct tty_struct *tty); |
| 194 | void (*hangup)(struct tty_struct *tty); |
| 195 | void (*break_ctl)(struct tty_struct *tty, int state); |
| 196 | void (*flush_buffer)(struct tty_struct *tty); |
| 197 | void (*set_ldisc)(struct tty_struct *tty); |
| 198 | void (*wait_until_sent)(struct tty_struct *tty, int timeout); |
| 199 | void (*send_xchar)(struct tty_struct *tty, char ch); |
| 200 | int (*read_proc)(char *page, char **start, off_t off, |
| 201 | int count, int *eof, void *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | int (*tiocmget)(struct tty_struct *tty, struct file *file); |
| 203 | int (*tiocmset)(struct tty_struct *tty, struct file *file, |
| 204 | unsigned int set, unsigned int clear); |
Jason Wessel | f2d937f | 2008-04-17 20:05:37 +0200 | [diff] [blame] | 205 | #ifdef CONFIG_CONSOLE_POLL |
| 206 | int (*poll_init)(struct tty_driver *driver, int line, char *options); |
| 207 | int (*poll_get_char)(struct tty_driver *driver, int line); |
| 208 | void (*poll_put_char)(struct tty_driver *driver, int line, char ch); |
| 209 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | struct tty_driver { |
| 213 | int magic; /* magic number for this structure */ |
| 214 | struct cdev cdev; |
| 215 | struct module *owner; |
| 216 | const char *driver_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | const char *name; |
| 218 | int name_base; /* offset of printed name */ |
| 219 | int major; /* major device number */ |
| 220 | int minor_start; /* start of minor device number */ |
| 221 | int minor_num; /* number of *possible* devices */ |
| 222 | int num; /* number of devices allocated */ |
| 223 | short type; /* type of tty driver */ |
| 224 | short subtype; /* subtype of tty driver */ |
Alan Cox | edc6afc | 2006-12-08 02:38:44 -0800 | [diff] [blame] | 225 | struct ktermios init_termios; /* Initial termios */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | int flags; /* tty driver flags */ |
| 227 | int refcount; /* for loadable tty drivers */ |
| 228 | struct proc_dir_entry *proc_entry; /* /proc fs entry */ |
| 229 | struct tty_driver *other; /* only used for the PTY driver */ |
| 230 | |
| 231 | /* |
| 232 | * Pointer to the tty data structures |
| 233 | */ |
| 234 | struct tty_struct **ttys; |
Alan Cox | edc6afc | 2006-12-08 02:38:44 -0800 | [diff] [blame] | 235 | struct ktermios **termios; |
| 236 | struct ktermios **termios_locked; |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 237 | void *driver_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Alan Cox | f34d7a5 | 2008-04-30 00:54:13 -0700 | [diff] [blame] | 239 | /* |
| 240 | * Driver methods |
| 241 | */ |
| 242 | |
| 243 | const struct tty_operations *ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | struct list_head tty_drivers; |
| 245 | }; |
| 246 | |
| 247 | extern struct list_head tty_drivers; |
| 248 | |
| 249 | struct tty_driver *alloc_tty_driver(int lines); |
| 250 | void put_tty_driver(struct tty_driver *driver); |
Jeff Dike | b68e31d | 2006-10-02 02:17:18 -0700 | [diff] [blame] | 251 | void tty_set_operations(struct tty_driver *driver, |
| 252 | const struct tty_operations *op); |
Jason Wessel | f2d937f | 2008-04-17 20:05:37 +0200 | [diff] [blame] | 253 | extern struct tty_driver *tty_find_polling_driver(char *name, int *line); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | /* tty driver magic number */ |
| 256 | #define TTY_DRIVER_MAGIC 0x5402 |
| 257 | |
| 258 | /* |
| 259 | * tty driver flags |
| 260 | * |
| 261 | * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the |
| 262 | * termios setting when the last process has closed the device. |
| 263 | * Used for PTY's, in particular. |
| 264 | * |
| 265 | * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will |
| 266 | * guarantee never not to set any special character handling |
| 267 | * flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR || |
| 268 | * !INPCK)). That is, if there is no reason for the driver to |
| 269 | * send notifications of parity and break characters up to the |
| 270 | * line driver, it won't do so. This allows the line driver to |
| 271 | * optimize for this case if this flag is set. (Note that there |
| 272 | * is also a promise, if the above case is true, not to signal |
| 273 | * overruns, either.) |
| 274 | * |
Greg Kroah-Hartman | 331b831 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 275 | * TTY_DRIVER_DYNAMIC_DEV --- if set, the individual tty devices need |
| 276 | * to be registered with a call to tty_register_driver() when the |
| 277 | * device is found in the system and unregistered with a call to |
| 278 | * tty_unregister_device() so the devices will be show up |
| 279 | * properly in sysfs. If not set, driver->num entries will be |
| 280 | * created by the tty core in sysfs when tty_register_driver() is |
| 281 | * called. This is to be used by drivers that have tty devices |
| 282 | * that can appear and disappear while the main tty driver is |
| 283 | * registered with the tty core. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | * |
| 285 | * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead |
| 286 | * use dynamic memory keyed through the devpts filesystem. This |
| 287 | * is only applicable to the pty driver. |
| 288 | */ |
| 289 | #define TTY_DRIVER_INSTALLED 0x0001 |
| 290 | #define TTY_DRIVER_RESET_TERMIOS 0x0002 |
| 291 | #define TTY_DRIVER_REAL_RAW 0x0004 |
Greg Kroah-Hartman | 331b831 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 292 | #define TTY_DRIVER_DYNAMIC_DEV 0x0008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | #define TTY_DRIVER_DEVPTS_MEM 0x0010 |
| 294 | |
| 295 | /* tty driver types */ |
| 296 | #define TTY_DRIVER_TYPE_SYSTEM 0x0001 |
| 297 | #define TTY_DRIVER_TYPE_CONSOLE 0x0002 |
| 298 | #define TTY_DRIVER_TYPE_SERIAL 0x0003 |
| 299 | #define TTY_DRIVER_TYPE_PTY 0x0004 |
| 300 | #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */ |
| 301 | #define TTY_DRIVER_TYPE_SYSCONS 0x0006 |
| 302 | |
| 303 | /* system subtypes (magic, used by tty_io.c) */ |
| 304 | #define SYSTEM_TYPE_TTY 0x0001 |
| 305 | #define SYSTEM_TYPE_CONSOLE 0x0002 |
| 306 | #define SYSTEM_TYPE_SYSCONS 0x0003 |
| 307 | #define SYSTEM_TYPE_SYSPTMX 0x0004 |
| 308 | |
| 309 | /* pty subtypes (magic, used by tty_io.c) */ |
| 310 | #define PTY_TYPE_MASTER 0x0001 |
| 311 | #define PTY_TYPE_SLAVE 0x0002 |
| 312 | |
| 313 | /* serial subtype definitions */ |
| 314 | #define SERIAL_TYPE_NORMAL 1 |
| 315 | |
| 316 | #endif /* #ifdef _LINUX_TTY_DRIVER_H */ |