1 #ifndef _LINUX_TTY_DRIVER_H
2 #define _LINUX_TTY_DRIVER_H
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 * void (*close)(struct tty_struct * tty, struct file * filp);
18 * This routine is called when a particular tty device is closed.
20 * int (*write)(struct tty_struct * tty,
21 * const unsigned char *buf, int count);
23 * This routine is called by the kernel to write a series of
24 * characters to the tty device. The characters may come from
25 * user space or kernel space. This routine will return the
26 * number of characters actually accepted for writing. This
27 * routine is mandatory.
29 * void (*put_char)(struct tty_struct *tty, unsigned char ch);
31 * This routine is called by the kernel to write a single
32 * character to the tty device. If the kernel uses this routine,
33 * it must call the flush_chars() routine (if defined) when it is
34 * done stuffing characters into the driver. If there is no room
35 * in the queue, the character is ignored.
37 * void (*flush_chars)(struct tty_struct *tty);
39 * This routine is called by the kernel after it has written a
40 * series of characters to the tty device using put_char().
42 * int (*write_room)(struct tty_struct *tty);
44 * This routine returns the numbers of characters the tty driver
45 * will accept for queuing to be written. This number is subject
46 * to change as output buffers get emptied, or if the output flow
49 * int (*ioctl)(struct tty_struct *tty, struct file * file,
50 * unsigned int cmd, unsigned long arg);
52 * This routine allows the tty driver to implement
53 * device-specific ioctl's. If the ioctl number passed in cmd
54 * is not recognized by the driver, it should return ENOIOCTLCMD.
56 * long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
57 * unsigned int cmd, unsigned long arg);
59 * implement ioctl processing for 32 bit process on 64 bit system
61 * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
63 * This routine allows the tty driver to be notified when
64 * device's termios settings have changed. Note that a
65 * well-designed tty driver should be prepared to accept the case
66 * where old == NULL, and try to do something rational.
68 * void (*set_ldisc)(struct tty_struct *tty);
70 * This routine allows the tty driver to be notified when the
71 * device's termios settings have changed.
73 * void (*throttle)(struct tty_struct * tty);
75 * This routine notifies the tty driver that input buffers for
76 * the line discipline are close to full, and it should somehow
77 * signal that no more characters should be sent to the tty.
79 * void (*unthrottle)(struct tty_struct * tty);
81 * This routine notifies the tty drivers that it should signals
82 * that characters can now be sent to the tty without fear of
83 * overrunning the input buffers of the line disciplines.
85 * void (*stop)(struct tty_struct *tty);
87 * This routine notifies the tty driver that it should stop
88 * outputting characters to the tty device.
90 * void (*start)(struct tty_struct *tty);
92 * This routine notifies the tty driver that it resume sending
93 * characters to the tty device.
95 * void (*hangup)(struct tty_struct *tty);
97 * This routine notifies the tty driver that it should hangup the
100 * void (*break_ctl)(struct tty_stuct *tty, int state);
102 * This optional routine requests the tty driver to turn on or
103 * off BREAK status on the RS-232 port. If state is -1,
104 * then the BREAK status should be turned on; if state is 0, then
105 * BREAK should be turned off.
107 * If this routine is implemented, the high-level tty driver will
108 * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK,
109 * TIOCCBRK. Otherwise, these ioctls will be passed down to the
112 * void (*wait_until_sent)(struct tty_struct *tty, int timeout);
114 * This routine waits until the device has written out all of the
115 * characters in its transmitter FIFO.
117 * void (*send_xchar)(struct tty_struct *tty, char ch);
119 * This routine is used to send a high-priority XON/XOFF
120 * character to the device.
123 #include <linux/fs.h>
124 #include <linux/list.h>
125 #include <linux/cdev.h>
130 struct tty_operations {
131 int (*open)(struct tty_struct * tty, struct file * filp);
132 void (*close)(struct tty_struct * tty, struct file * filp);
133 int (*write)(struct tty_struct * tty,
134 const unsigned char *buf, int count);
135 void (*put_char)(struct tty_struct *tty, unsigned char ch);
136 void (*flush_chars)(struct tty_struct *tty);
137 int (*write_room)(struct tty_struct *tty);
138 int (*chars_in_buffer)(struct tty_struct *tty);
139 int (*ioctl)(struct tty_struct *tty, struct file * file,
140 unsigned int cmd, unsigned long arg);
141 long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
142 unsigned int cmd, unsigned long arg);
143 void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
144 void (*throttle)(struct tty_struct * tty);
145 void (*unthrottle)(struct tty_struct * tty);
146 void (*stop)(struct tty_struct *tty);
147 void (*start)(struct tty_struct *tty);
148 void (*hangup)(struct tty_struct *tty);
149 void (*break_ctl)(struct tty_struct *tty, int state);
150 void (*flush_buffer)(struct tty_struct *tty);
151 void (*set_ldisc)(struct tty_struct *tty);
152 void (*wait_until_sent)(struct tty_struct *tty, int timeout);
153 void (*send_xchar)(struct tty_struct *tty, char ch);
154 int (*read_proc)(char *page, char **start, off_t off,
155 int count, int *eof, void *data);
156 int (*write_proc)(struct file *file, const char __user *buffer,
157 unsigned long count, void *data);
158 int (*tiocmget)(struct tty_struct *tty, struct file *file);
159 int (*tiocmset)(struct tty_struct *tty, struct file *file,
160 unsigned int set, unsigned int clear);
161 #ifdef CONFIG_CONSOLE_POLL
162 int (*poll_init)(struct tty_driver *driver, int line, char *options);
163 int (*poll_get_char)(struct tty_driver *driver, int line);
164 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
169 int magic; /* magic number for this structure */
171 struct module *owner;
172 const char *driver_name;
174 int name_base; /* offset of printed name */
175 int major; /* major device number */
176 int minor_start; /* start of minor device number */
177 int minor_num; /* number of *possible* devices */
178 int num; /* number of devices allocated */
179 short type; /* type of tty driver */
180 short subtype; /* subtype of tty driver */
181 struct ktermios init_termios; /* Initial termios */
182 int flags; /* tty driver flags */
183 int refcount; /* for loadable tty drivers */
184 struct proc_dir_entry *proc_entry; /* /proc fs entry */
185 struct tty_driver *other; /* only used for the PTY driver */
188 * Pointer to the tty data structures
190 struct tty_struct **ttys;
191 struct ktermios **termios;
192 struct ktermios **termios_locked;
193 void *driver_state; /* only used for the PTY driver */
196 * Interface routines from the upper tty layer to the tty
197 * driver. Will be replaced with struct tty_operations.
199 int (*open)(struct tty_struct * tty, struct file * filp);
200 void (*close)(struct tty_struct * tty, struct file * filp);
201 int (*write)(struct tty_struct * tty,
202 const unsigned char *buf, int count);
203 void (*put_char)(struct tty_struct *tty, unsigned char ch);
204 void (*flush_chars)(struct tty_struct *tty);
205 int (*write_room)(struct tty_struct *tty);
206 int (*chars_in_buffer)(struct tty_struct *tty);
207 int (*ioctl)(struct tty_struct *tty, struct file * file,
208 unsigned int cmd, unsigned long arg);
209 long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
210 unsigned int cmd, unsigned long arg);
211 void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
212 void (*throttle)(struct tty_struct * tty);
213 void (*unthrottle)(struct tty_struct * tty);
214 void (*stop)(struct tty_struct *tty);
215 void (*start)(struct tty_struct *tty);
216 void (*hangup)(struct tty_struct *tty);
217 void (*break_ctl)(struct tty_struct *tty, int state);
218 void (*flush_buffer)(struct tty_struct *tty);
219 void (*set_ldisc)(struct tty_struct *tty);
220 void (*wait_until_sent)(struct tty_struct *tty, int timeout);
221 void (*send_xchar)(struct tty_struct *tty, char ch);
222 int (*read_proc)(char *page, char **start, off_t off,
223 int count, int *eof, void *data);
224 int (*write_proc)(struct file *file, const char __user *buffer,
225 unsigned long count, 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 #ifdef CONFIG_CONSOLE_POLL
230 int (*poll_init)(struct tty_driver *driver, int line, char *options);
231 int (*poll_get_char)(struct tty_driver *driver, int line);
232 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
235 struct list_head tty_drivers;
238 extern struct list_head tty_drivers;
240 struct tty_driver *alloc_tty_driver(int lines);
241 void put_tty_driver(struct tty_driver *driver);
242 void tty_set_operations(struct tty_driver *driver,
243 const struct tty_operations *op);
244 extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
246 /* tty driver magic number */
247 #define TTY_DRIVER_MAGIC 0x5402
252 * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the
253 * termios setting when the last process has closed the device.
254 * Used for PTY's, in particular.
256 * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will
257 * guarantee never not to set any special character handling
258 * flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR ||
259 * !INPCK)). That is, if there is no reason for the driver to
260 * send notifications of parity and break characters up to the
261 * line driver, it won't do so. This allows the line driver to
262 * optimize for this case if this flag is set. (Note that there
263 * is also a promise, if the above case is true, not to signal
266 * TTY_DRIVER_DYNAMIC_DEV --- if set, the individual tty devices need
267 * to be registered with a call to tty_register_driver() when the
268 * device is found in the system and unregistered with a call to
269 * tty_unregister_device() so the devices will be show up
270 * properly in sysfs. If not set, driver->num entries will be
271 * created by the tty core in sysfs when tty_register_driver() is
272 * called. This is to be used by drivers that have tty devices
273 * that can appear and disappear while the main tty driver is
274 * registered with the tty core.
276 * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead
277 * use dynamic memory keyed through the devpts filesystem. This
278 * is only applicable to the pty driver.
280 #define TTY_DRIVER_INSTALLED 0x0001
281 #define TTY_DRIVER_RESET_TERMIOS 0x0002
282 #define TTY_DRIVER_REAL_RAW 0x0004
283 #define TTY_DRIVER_DYNAMIC_DEV 0x0008
284 #define TTY_DRIVER_DEVPTS_MEM 0x0010
286 /* tty driver types */
287 #define TTY_DRIVER_TYPE_SYSTEM 0x0001
288 #define TTY_DRIVER_TYPE_CONSOLE 0x0002
289 #define TTY_DRIVER_TYPE_SERIAL 0x0003
290 #define TTY_DRIVER_TYPE_PTY 0x0004
291 #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */
292 #define TTY_DRIVER_TYPE_SYSCONS 0x0006
294 /* system subtypes (magic, used by tty_io.c) */
295 #define SYSTEM_TYPE_TTY 0x0001
296 #define SYSTEM_TYPE_CONSOLE 0x0002
297 #define SYSTEM_TYPE_SYSCONS 0x0003
298 #define SYSTEM_TYPE_SYSPTMX 0x0004
300 /* pty subtypes (magic, used by tty_io.c) */
301 #define PTY_TYPE_MASTER 0x0001
302 #define PTY_TYPE_SLAVE 0x0002
304 /* serial subtype definitions */
305 #define SERIAL_TYPE_NORMAL 1
307 #endif /* #ifdef _LINUX_TTY_DRIVER_H */