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