diff options
author | Alan Cox <alan@lxorguk.ukuu.org.uk> | 2008-04-30 03:54:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-30 11:29:47 -0400 |
commit | f34d7a5b7010b82fe97da95496b9971435530062 (patch) | |
tree | 87e2abec1e33ed4fe5e63ee2fd000bc2ad745e57 /include | |
parent | 251b8dd7eee30fda089a1dc088abf4fc9a0dee9c (diff) |
tty: The big operations rework
- Operations are now a shared const function block as with most other Linux
objects
- Introduce wrappers for some optional functions to get consistent behaviour
- Wrap put_char which used to be patched by the tty layer
- Document which functions are needed/optional
- Make put_char report success/fail
- Cache the driver->ops pointer in the tty as tty->ops
- Remove various surplus lock calls we no longer need
- Remove proc_write method as noted by Alexey Dobriyan
- Introduce some missing sanity checks where certain driver/ldisc
combinations would oops as they didn't check needed methods were present
[akpm@linux-foundation.org: fix fs/compat_ioctl.c build]
[akpm@linux-foundation.org: fix isicom]
[akpm@linux-foundation.org: fix arch/ia64/hp/sim/simserial.c build]
[akpm@linux-foundation.org: fix kgdb]
Signed-off-by: Alan Cox <alan@redhat.com>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/tty.h | 8 | ||||
-rw-r--r-- | include/linux/tty_driver.h | 102 |
2 files changed, 62 insertions, 48 deletions
diff --git a/include/linux/tty.h b/include/linux/tty.h index 2699298b00ef..c36a76da2ae2 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h | |||
@@ -177,9 +177,13 @@ struct signal_struct; | |||
177 | * size each time the window is created or resized anyway. | 177 | * size each time the window is created or resized anyway. |
178 | * - TYT, 9/14/92 | 178 | * - TYT, 9/14/92 |
179 | */ | 179 | */ |
180 | |||
181 | struct tty_operations; | ||
182 | |||
180 | struct tty_struct { | 183 | struct tty_struct { |
181 | int magic; | 184 | int magic; |
182 | struct tty_driver *driver; | 185 | struct tty_driver *driver; |
186 | const struct tty_operations *ops; | ||
183 | int index; | 187 | int index; |
184 | struct tty_ldisc ldisc; | 188 | struct tty_ldisc ldisc; |
185 | struct mutex termios_mutex; | 189 | struct mutex termios_mutex; |
@@ -295,6 +299,10 @@ extern void tty_unregister_device(struct tty_driver *driver, unsigned index); | |||
295 | extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp, | 299 | extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp, |
296 | int buflen); | 300 | int buflen); |
297 | extern void tty_write_message(struct tty_struct *tty, char *msg); | 301 | extern void tty_write_message(struct tty_struct *tty, char *msg); |
302 | extern int tty_put_char(struct tty_struct *tty, unsigned char c); | ||
303 | extern int tty_chars_in_buffer(struct tty_struct *tty); | ||
304 | extern int tty_write_room(struct tty_struct *tty); | ||
305 | extern void tty_driver_flush_buffer(struct tty_struct *tty); | ||
298 | 306 | ||
299 | extern int is_current_pgrp_orphaned(void); | 307 | extern int is_current_pgrp_orphaned(void); |
300 | extern struct pid *tty_get_pgrp(struct tty_struct *tty); | 308 | extern struct pid *tty_get_pgrp(struct tty_struct *tty); |
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h index 21f69aca4505..f80d73b690f6 100644 --- a/include/linux/tty_driver.h +++ b/include/linux/tty_driver.h | |||
@@ -12,11 +12,15 @@ | |||
12 | * This routine is called when a particular tty device is opened. | 12 | * This routine is called when a particular tty device is opened. |
13 | * This routine is mandatory; if this routine is not filled in, | 13 | * This routine is mandatory; if this routine is not filled in, |
14 | * the attempted open will fail with ENODEV. | 14 | * the attempted open will fail with ENODEV. |
15 | * | ||
16 | * Required method. | ||
15 | * | 17 | * |
16 | * void (*close)(struct tty_struct * tty, struct file * filp); | 18 | * void (*close)(struct tty_struct * tty, struct file * filp); |
17 | * | 19 | * |
18 | * This routine is called when a particular tty device is closed. | 20 | * This routine is called when a particular tty device is closed. |
19 | * | 21 | * |
22 | * Required method. | ||
23 | * | ||
20 | * int (*write)(struct tty_struct * tty, | 24 | * int (*write)(struct tty_struct * tty, |
21 | * const unsigned char *buf, int count); | 25 | * const unsigned char *buf, int count); |
22 | * | 26 | * |
@@ -26,7 +30,9 @@ | |||
26 | * number of characters actually accepted for writing. This | 30 | * number of characters actually accepted for writing. This |
27 | * routine is mandatory. | 31 | * routine is mandatory. |
28 | * | 32 | * |
29 | * void (*put_char)(struct tty_struct *tty, unsigned char ch); | 33 | * Optional: Required for writable devices. |
34 | * | ||
35 | * int (*put_char)(struct tty_struct *tty, unsigned char ch); | ||
30 | * | 36 | * |
31 | * This routine is called by the kernel to write a single | 37 | * This routine is called by the kernel to write a single |
32 | * character to the tty device. If the kernel uses this routine, | 38 | * character to the tty device. If the kernel uses this routine, |
@@ -34,10 +40,18 @@ | |||
34 | * done stuffing characters into the driver. If there is no room | 40 | * done stuffing characters into the driver. If there is no room |
35 | * in the queue, the character is ignored. | 41 | * in the queue, the character is ignored. |
36 | * | 42 | * |
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 | * | ||
37 | * void (*flush_chars)(struct tty_struct *tty); | 47 | * void (*flush_chars)(struct tty_struct *tty); |
38 | * | 48 | * |
39 | * This routine is called by the kernel after it has written a | 49 | * This routine is called by the kernel after it has written a |
40 | * series of characters to the tty device using put_char(). | 50 | * series of characters to the tty device using put_char(). |
51 | * | ||
52 | * Optional: | ||
53 | * | ||
54 | * Note: Do not call this function directly, call tty_driver_flush_chars | ||
41 | * | 55 | * |
42 | * int (*write_room)(struct tty_struct *tty); | 56 | * int (*write_room)(struct tty_struct *tty); |
43 | * | 57 | * |
@@ -45,6 +59,10 @@ | |||
45 | * will accept for queuing to be written. This number is subject | 59 | * will accept for queuing to be written. This number is subject |
46 | * to change as output buffers get emptied, or if the output flow | 60 | * to change as output buffers get emptied, or if the output flow |
47 | * control is acted. | 61 | * control is acted. |
62 | * | ||
63 | * Required if write method is provided else not needed. | ||
64 | * | ||
65 | * Note: Do not call this function directly, call tty_write_room | ||
48 | * | 66 | * |
49 | * int (*ioctl)(struct tty_struct *tty, struct file * file, | 67 | * int (*ioctl)(struct tty_struct *tty, struct file * file, |
50 | * unsigned int cmd, unsigned long arg); | 68 | * unsigned int cmd, unsigned long arg); |
@@ -53,22 +71,29 @@ | |||
53 | * device-specific ioctl's. If the ioctl number passed in cmd | 71 | * device-specific ioctl's. If the ioctl number passed in cmd |
54 | * is not recognized by the driver, it should return ENOIOCTLCMD. | 72 | * is not recognized by the driver, it should return ENOIOCTLCMD. |
55 | * | 73 | * |
74 | * Optional | ||
75 | * | ||
56 | * long (*compat_ioctl)(struct tty_struct *tty, struct file * file, | 76 | * long (*compat_ioctl)(struct tty_struct *tty, struct file * file, |
57 | * unsigned int cmd, unsigned long arg); | 77 | * unsigned int cmd, unsigned long arg); |
58 | * | 78 | * |
59 | * implement ioctl processing for 32 bit process on 64 bit system | 79 | * implement ioctl processing for 32 bit process on 64 bit system |
80 | * | ||
81 | * Optional | ||
60 | * | 82 | * |
61 | * void (*set_termios)(struct tty_struct *tty, struct ktermios * old); | 83 | * void (*set_termios)(struct tty_struct *tty, struct ktermios * old); |
62 | * | 84 | * |
63 | * This routine allows the tty driver to be notified when | 85 | * This routine allows the tty driver to be notified when |
64 | * device's termios settings have changed. Note that a | 86 | * device's termios settings have changed. |
65 | * well-designed tty driver should be prepared to accept the case | 87 | * |
66 | * where old == NULL, and try to do something rational. | 88 | * Optional: Called under the termios lock |
89 | * | ||
67 | * | 90 | * |
68 | * void (*set_ldisc)(struct tty_struct *tty); | 91 | * void (*set_ldisc)(struct tty_struct *tty); |
69 | * | 92 | * |
70 | * This routine allows the tty driver to be notified when the | 93 | * This routine allows the tty driver to be notified when the |
71 | * device's termios settings have changed. | 94 | * device's termios settings have changed. |
95 | * | ||
96 | * Optional: Called under BKL (currently) | ||
72 | * | 97 | * |
73 | * void (*throttle)(struct tty_struct * tty); | 98 | * void (*throttle)(struct tty_struct * tty); |
74 | * | 99 | * |
@@ -86,17 +111,27 @@ | |||
86 | * | 111 | * |
87 | * This routine notifies the tty driver that it should stop | 112 | * This routine notifies the tty driver that it should stop |
88 | * outputting characters to the tty device. | 113 | * outputting characters to the tty device. |
114 | * | ||
115 | * Optional: | ||
116 | * | ||
117 | * Note: Call stop_tty not this method. | ||
89 | * | 118 | * |
90 | * void (*start)(struct tty_struct *tty); | 119 | * void (*start)(struct tty_struct *tty); |
91 | * | 120 | * |
92 | * This routine notifies the tty driver that it resume sending | 121 | * This routine notifies the tty driver that it resume sending |
93 | * characters to the tty device. | 122 | * characters to the tty device. |
123 | * | ||
124 | * Optional: | ||
125 | * | ||
126 | * Note: Call start_tty not this method. | ||
94 | * | 127 | * |
95 | * void (*hangup)(struct tty_struct *tty); | 128 | * void (*hangup)(struct tty_struct *tty); |
96 | * | 129 | * |
97 | * This routine notifies the tty driver that it should hangup the | 130 | * This routine notifies the tty driver that it should hangup the |
98 | * tty device. | 131 | * tty device. |
99 | * | 132 | * |
133 | * Required: | ||
134 | * | ||
100 | * void (*break_ctl)(struct tty_stuct *tty, int state); | 135 | * void (*break_ctl)(struct tty_stuct *tty, int state); |
101 | * | 136 | * |
102 | * This optional routine requests the tty driver to turn on or | 137 | * This optional routine requests the tty driver to turn on or |
@@ -106,18 +141,26 @@ | |||
106 | * | 141 | * |
107 | * If this routine is implemented, the high-level tty driver will | 142 | * If this routine is implemented, the high-level tty driver will |
108 | * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK, | 143 | * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK, |
109 | * TIOCCBRK. Otherwise, these ioctls will be passed down to the | 144 | * TIOCCBRK. |
110 | * driver to handle. | 145 | * |
146 | * Optional: Required for TCSBRK/BRKP/etc handling. | ||
111 | * | 147 | * |
112 | * void (*wait_until_sent)(struct tty_struct *tty, int timeout); | 148 | * void (*wait_until_sent)(struct tty_struct *tty, int timeout); |
113 | * | 149 | * |
114 | * This routine waits until the device has written out all of the | 150 | * This routine waits until the device has written out all of the |
115 | * characters in its transmitter FIFO. | 151 | * characters in its transmitter FIFO. |
116 | * | 152 | * |
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 | * | ||
117 | * void (*send_xchar)(struct tty_struct *tty, char ch); | 157 | * void (*send_xchar)(struct tty_struct *tty, char ch); |
118 | * | 158 | * |
119 | * This routine is used to send a high-priority XON/XOFF | 159 | * This routine is used to send a high-priority XON/XOFF |
120 | * character to the device. | 160 | * character to the device. |
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. | ||
121 | */ | 164 | */ |
122 | 165 | ||
123 | #include <linux/fs.h> | 166 | #include <linux/fs.h> |
@@ -132,7 +175,7 @@ struct tty_operations { | |||
132 | void (*close)(struct tty_struct * tty, struct file * filp); | 175 | void (*close)(struct tty_struct * tty, struct file * filp); |
133 | int (*write)(struct tty_struct * tty, | 176 | int (*write)(struct tty_struct * tty, |
134 | const unsigned char *buf, int count); | 177 | const unsigned char *buf, int count); |
135 | void (*put_char)(struct tty_struct *tty, unsigned char ch); | 178 | int (*put_char)(struct tty_struct *tty, unsigned char ch); |
136 | void (*flush_chars)(struct tty_struct *tty); | 179 | void (*flush_chars)(struct tty_struct *tty); |
137 | int (*write_room)(struct tty_struct *tty); | 180 | int (*write_room)(struct tty_struct *tty); |
138 | int (*chars_in_buffer)(struct tty_struct *tty); | 181 | int (*chars_in_buffer)(struct tty_struct *tty); |
@@ -153,8 +196,6 @@ struct tty_operations { | |||
153 | void (*send_xchar)(struct tty_struct *tty, char ch); | 196 | void (*send_xchar)(struct tty_struct *tty, char ch); |
154 | int (*read_proc)(char *page, char **start, off_t off, | 197 | int (*read_proc)(char *page, char **start, off_t off, |
155 | int count, int *eof, void *data); | 198 | 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); | 199 | int (*tiocmget)(struct tty_struct *tty, struct file *file); |
159 | int (*tiocmset)(struct tty_struct *tty, struct file *file, | 200 | int (*tiocmset)(struct tty_struct *tty, struct file *file, |
160 | unsigned int set, unsigned int clear); | 201 | unsigned int set, unsigned int clear); |
@@ -190,48 +231,13 @@ struct tty_driver { | |||
190 | struct tty_struct **ttys; | 231 | struct tty_struct **ttys; |
191 | struct ktermios **termios; | 232 | struct ktermios **termios; |
192 | struct ktermios **termios_locked; | 233 | struct ktermios **termios_locked; |
193 | void *driver_state; /* only used for the PTY driver */ | 234 | void *driver_state; |
194 | 235 | ||
195 | /* | 236 | /* |
196 | * Interface routines from the upper tty layer to the tty | 237 | * Driver methods |
197 | * driver. Will be replaced with struct tty_operations. | ||
198 | */ | 238 | */ |
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); | ||
233 | #endif | ||
234 | 239 | ||
240 | const struct tty_operations *ops; | ||
235 | struct list_head tty_drivers; | 241 | struct list_head tty_drivers; |
236 | }; | 242 | }; |
237 | 243 | ||