Commit 695586ca20c56cf8cfa87160383307a288d32496
Committed by
Greg Kroah-Hartman
1 parent
4c2ef53d3b
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
TTY: provide drivers with tty_port_install
This will be used in tty_ops->install to set tty->port (and to call tty_standard_install). Signed-off-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Showing 2 changed files with 10 additions and 0 deletions Inline Diff
drivers/tty/tty_port.c
1 | /* | 1 | /* |
2 | * Tty port functions | 2 | * Tty port functions |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #include <linux/types.h> | 5 | #include <linux/types.h> |
6 | #include <linux/errno.h> | 6 | #include <linux/errno.h> |
7 | #include <linux/tty.h> | 7 | #include <linux/tty.h> |
8 | #include <linux/tty_driver.h> | 8 | #include <linux/tty_driver.h> |
9 | #include <linux/tty_flip.h> | 9 | #include <linux/tty_flip.h> |
10 | #include <linux/serial.h> | 10 | #include <linux/serial.h> |
11 | #include <linux/timer.h> | 11 | #include <linux/timer.h> |
12 | #include <linux/string.h> | 12 | #include <linux/string.h> |
13 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
14 | #include <linux/sched.h> | 14 | #include <linux/sched.h> |
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/wait.h> | 16 | #include <linux/wait.h> |
17 | #include <linux/bitops.h> | 17 | #include <linux/bitops.h> |
18 | #include <linux/delay.h> | 18 | #include <linux/delay.h> |
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | 20 | ||
21 | void tty_port_init(struct tty_port *port) | 21 | void tty_port_init(struct tty_port *port) |
22 | { | 22 | { |
23 | memset(port, 0, sizeof(*port)); | 23 | memset(port, 0, sizeof(*port)); |
24 | init_waitqueue_head(&port->open_wait); | 24 | init_waitqueue_head(&port->open_wait); |
25 | init_waitqueue_head(&port->close_wait); | 25 | init_waitqueue_head(&port->close_wait); |
26 | init_waitqueue_head(&port->delta_msr_wait); | 26 | init_waitqueue_head(&port->delta_msr_wait); |
27 | mutex_init(&port->mutex); | 27 | mutex_init(&port->mutex); |
28 | mutex_init(&port->buf_mutex); | 28 | mutex_init(&port->buf_mutex); |
29 | spin_lock_init(&port->lock); | 29 | spin_lock_init(&port->lock); |
30 | port->close_delay = (50 * HZ) / 100; | 30 | port->close_delay = (50 * HZ) / 100; |
31 | port->closing_wait = (3000 * HZ) / 100; | 31 | port->closing_wait = (3000 * HZ) / 100; |
32 | kref_init(&port->kref); | 32 | kref_init(&port->kref); |
33 | } | 33 | } |
34 | EXPORT_SYMBOL(tty_port_init); | 34 | EXPORT_SYMBOL(tty_port_init); |
35 | 35 | ||
36 | int tty_port_alloc_xmit_buf(struct tty_port *port) | 36 | int tty_port_alloc_xmit_buf(struct tty_port *port) |
37 | { | 37 | { |
38 | /* We may sleep in get_zeroed_page() */ | 38 | /* We may sleep in get_zeroed_page() */ |
39 | mutex_lock(&port->buf_mutex); | 39 | mutex_lock(&port->buf_mutex); |
40 | if (port->xmit_buf == NULL) | 40 | if (port->xmit_buf == NULL) |
41 | port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); | 41 | port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); |
42 | mutex_unlock(&port->buf_mutex); | 42 | mutex_unlock(&port->buf_mutex); |
43 | if (port->xmit_buf == NULL) | 43 | if (port->xmit_buf == NULL) |
44 | return -ENOMEM; | 44 | return -ENOMEM; |
45 | return 0; | 45 | return 0; |
46 | } | 46 | } |
47 | EXPORT_SYMBOL(tty_port_alloc_xmit_buf); | 47 | EXPORT_SYMBOL(tty_port_alloc_xmit_buf); |
48 | 48 | ||
49 | void tty_port_free_xmit_buf(struct tty_port *port) | 49 | void tty_port_free_xmit_buf(struct tty_port *port) |
50 | { | 50 | { |
51 | mutex_lock(&port->buf_mutex); | 51 | mutex_lock(&port->buf_mutex); |
52 | if (port->xmit_buf != NULL) { | 52 | if (port->xmit_buf != NULL) { |
53 | free_page((unsigned long)port->xmit_buf); | 53 | free_page((unsigned long)port->xmit_buf); |
54 | port->xmit_buf = NULL; | 54 | port->xmit_buf = NULL; |
55 | } | 55 | } |
56 | mutex_unlock(&port->buf_mutex); | 56 | mutex_unlock(&port->buf_mutex); |
57 | } | 57 | } |
58 | EXPORT_SYMBOL(tty_port_free_xmit_buf); | 58 | EXPORT_SYMBOL(tty_port_free_xmit_buf); |
59 | 59 | ||
60 | static void tty_port_destructor(struct kref *kref) | 60 | static void tty_port_destructor(struct kref *kref) |
61 | { | 61 | { |
62 | struct tty_port *port = container_of(kref, struct tty_port, kref); | 62 | struct tty_port *port = container_of(kref, struct tty_port, kref); |
63 | if (port->xmit_buf) | 63 | if (port->xmit_buf) |
64 | free_page((unsigned long)port->xmit_buf); | 64 | free_page((unsigned long)port->xmit_buf); |
65 | if (port->ops->destruct) | 65 | if (port->ops->destruct) |
66 | port->ops->destruct(port); | 66 | port->ops->destruct(port); |
67 | else | 67 | else |
68 | kfree(port); | 68 | kfree(port); |
69 | } | 69 | } |
70 | 70 | ||
71 | void tty_port_put(struct tty_port *port) | 71 | void tty_port_put(struct tty_port *port) |
72 | { | 72 | { |
73 | if (port) | 73 | if (port) |
74 | kref_put(&port->kref, tty_port_destructor); | 74 | kref_put(&port->kref, tty_port_destructor); |
75 | } | 75 | } |
76 | EXPORT_SYMBOL(tty_port_put); | 76 | EXPORT_SYMBOL(tty_port_put); |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * tty_port_tty_get - get a tty reference | 79 | * tty_port_tty_get - get a tty reference |
80 | * @port: tty port | 80 | * @port: tty port |
81 | * | 81 | * |
82 | * Return a refcount protected tty instance or NULL if the port is not | 82 | * Return a refcount protected tty instance or NULL if the port is not |
83 | * associated with a tty (eg due to close or hangup) | 83 | * associated with a tty (eg due to close or hangup) |
84 | */ | 84 | */ |
85 | 85 | ||
86 | struct tty_struct *tty_port_tty_get(struct tty_port *port) | 86 | struct tty_struct *tty_port_tty_get(struct tty_port *port) |
87 | { | 87 | { |
88 | unsigned long flags; | 88 | unsigned long flags; |
89 | struct tty_struct *tty; | 89 | struct tty_struct *tty; |
90 | 90 | ||
91 | spin_lock_irqsave(&port->lock, flags); | 91 | spin_lock_irqsave(&port->lock, flags); |
92 | tty = tty_kref_get(port->tty); | 92 | tty = tty_kref_get(port->tty); |
93 | spin_unlock_irqrestore(&port->lock, flags); | 93 | spin_unlock_irqrestore(&port->lock, flags); |
94 | return tty; | 94 | return tty; |
95 | } | 95 | } |
96 | EXPORT_SYMBOL(tty_port_tty_get); | 96 | EXPORT_SYMBOL(tty_port_tty_get); |
97 | 97 | ||
98 | /** | 98 | /** |
99 | * tty_port_tty_set - set the tty of a port | 99 | * tty_port_tty_set - set the tty of a port |
100 | * @port: tty port | 100 | * @port: tty port |
101 | * @tty: the tty | 101 | * @tty: the tty |
102 | * | 102 | * |
103 | * Associate the port and tty pair. Manages any internal refcounts. | 103 | * Associate the port and tty pair. Manages any internal refcounts. |
104 | * Pass NULL to deassociate a port | 104 | * Pass NULL to deassociate a port |
105 | */ | 105 | */ |
106 | 106 | ||
107 | void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) | 107 | void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) |
108 | { | 108 | { |
109 | unsigned long flags; | 109 | unsigned long flags; |
110 | 110 | ||
111 | spin_lock_irqsave(&port->lock, flags); | 111 | spin_lock_irqsave(&port->lock, flags); |
112 | if (port->tty) | 112 | if (port->tty) |
113 | tty_kref_put(port->tty); | 113 | tty_kref_put(port->tty); |
114 | port->tty = tty_kref_get(tty); | 114 | port->tty = tty_kref_get(tty); |
115 | spin_unlock_irqrestore(&port->lock, flags); | 115 | spin_unlock_irqrestore(&port->lock, flags); |
116 | } | 116 | } |
117 | EXPORT_SYMBOL(tty_port_tty_set); | 117 | EXPORT_SYMBOL(tty_port_tty_set); |
118 | 118 | ||
119 | static void tty_port_shutdown(struct tty_port *port) | 119 | static void tty_port_shutdown(struct tty_port *port) |
120 | { | 120 | { |
121 | mutex_lock(&port->mutex); | 121 | mutex_lock(&port->mutex); |
122 | if (port->ops->shutdown && !port->console && | 122 | if (port->ops->shutdown && !port->console && |
123 | test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) | 123 | test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) |
124 | port->ops->shutdown(port); | 124 | port->ops->shutdown(port); |
125 | mutex_unlock(&port->mutex); | 125 | mutex_unlock(&port->mutex); |
126 | } | 126 | } |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * tty_port_hangup - hangup helper | 129 | * tty_port_hangup - hangup helper |
130 | * @port: tty port | 130 | * @port: tty port |
131 | * | 131 | * |
132 | * Perform port level tty hangup flag and count changes. Drop the tty | 132 | * Perform port level tty hangup flag and count changes. Drop the tty |
133 | * reference. | 133 | * reference. |
134 | */ | 134 | */ |
135 | 135 | ||
136 | void tty_port_hangup(struct tty_port *port) | 136 | void tty_port_hangup(struct tty_port *port) |
137 | { | 137 | { |
138 | unsigned long flags; | 138 | unsigned long flags; |
139 | 139 | ||
140 | spin_lock_irqsave(&port->lock, flags); | 140 | spin_lock_irqsave(&port->lock, flags); |
141 | port->count = 0; | 141 | port->count = 0; |
142 | port->flags &= ~ASYNC_NORMAL_ACTIVE; | 142 | port->flags &= ~ASYNC_NORMAL_ACTIVE; |
143 | if (port->tty) { | 143 | if (port->tty) { |
144 | set_bit(TTY_IO_ERROR, &port->tty->flags); | 144 | set_bit(TTY_IO_ERROR, &port->tty->flags); |
145 | tty_kref_put(port->tty); | 145 | tty_kref_put(port->tty); |
146 | } | 146 | } |
147 | port->tty = NULL; | 147 | port->tty = NULL; |
148 | spin_unlock_irqrestore(&port->lock, flags); | 148 | spin_unlock_irqrestore(&port->lock, flags); |
149 | wake_up_interruptible(&port->open_wait); | 149 | wake_up_interruptible(&port->open_wait); |
150 | wake_up_interruptible(&port->delta_msr_wait); | 150 | wake_up_interruptible(&port->delta_msr_wait); |
151 | tty_port_shutdown(port); | 151 | tty_port_shutdown(port); |
152 | } | 152 | } |
153 | EXPORT_SYMBOL(tty_port_hangup); | 153 | EXPORT_SYMBOL(tty_port_hangup); |
154 | 154 | ||
155 | /** | 155 | /** |
156 | * tty_port_carrier_raised - carrier raised check | 156 | * tty_port_carrier_raised - carrier raised check |
157 | * @port: tty port | 157 | * @port: tty port |
158 | * | 158 | * |
159 | * Wrapper for the carrier detect logic. For the moment this is used | 159 | * Wrapper for the carrier detect logic. For the moment this is used |
160 | * to hide some internal details. This will eventually become entirely | 160 | * to hide some internal details. This will eventually become entirely |
161 | * internal to the tty port. | 161 | * internal to the tty port. |
162 | */ | 162 | */ |
163 | 163 | ||
164 | int tty_port_carrier_raised(struct tty_port *port) | 164 | int tty_port_carrier_raised(struct tty_port *port) |
165 | { | 165 | { |
166 | if (port->ops->carrier_raised == NULL) | 166 | if (port->ops->carrier_raised == NULL) |
167 | return 1; | 167 | return 1; |
168 | return port->ops->carrier_raised(port); | 168 | return port->ops->carrier_raised(port); |
169 | } | 169 | } |
170 | EXPORT_SYMBOL(tty_port_carrier_raised); | 170 | EXPORT_SYMBOL(tty_port_carrier_raised); |
171 | 171 | ||
172 | /** | 172 | /** |
173 | * tty_port_raise_dtr_rts - Raise DTR/RTS | 173 | * tty_port_raise_dtr_rts - Raise DTR/RTS |
174 | * @port: tty port | 174 | * @port: tty port |
175 | * | 175 | * |
176 | * Wrapper for the DTR/RTS raise logic. For the moment this is used | 176 | * Wrapper for the DTR/RTS raise logic. For the moment this is used |
177 | * to hide some internal details. This will eventually become entirely | 177 | * to hide some internal details. This will eventually become entirely |
178 | * internal to the tty port. | 178 | * internal to the tty port. |
179 | */ | 179 | */ |
180 | 180 | ||
181 | void tty_port_raise_dtr_rts(struct tty_port *port) | 181 | void tty_port_raise_dtr_rts(struct tty_port *port) |
182 | { | 182 | { |
183 | if (port->ops->dtr_rts) | 183 | if (port->ops->dtr_rts) |
184 | port->ops->dtr_rts(port, 1); | 184 | port->ops->dtr_rts(port, 1); |
185 | } | 185 | } |
186 | EXPORT_SYMBOL(tty_port_raise_dtr_rts); | 186 | EXPORT_SYMBOL(tty_port_raise_dtr_rts); |
187 | 187 | ||
188 | /** | 188 | /** |
189 | * tty_port_lower_dtr_rts - Lower DTR/RTS | 189 | * tty_port_lower_dtr_rts - Lower DTR/RTS |
190 | * @port: tty port | 190 | * @port: tty port |
191 | * | 191 | * |
192 | * Wrapper for the DTR/RTS raise logic. For the moment this is used | 192 | * Wrapper for the DTR/RTS raise logic. For the moment this is used |
193 | * to hide some internal details. This will eventually become entirely | 193 | * to hide some internal details. This will eventually become entirely |
194 | * internal to the tty port. | 194 | * internal to the tty port. |
195 | */ | 195 | */ |
196 | 196 | ||
197 | void tty_port_lower_dtr_rts(struct tty_port *port) | 197 | void tty_port_lower_dtr_rts(struct tty_port *port) |
198 | { | 198 | { |
199 | if (port->ops->dtr_rts) | 199 | if (port->ops->dtr_rts) |
200 | port->ops->dtr_rts(port, 0); | 200 | port->ops->dtr_rts(port, 0); |
201 | } | 201 | } |
202 | EXPORT_SYMBOL(tty_port_lower_dtr_rts); | 202 | EXPORT_SYMBOL(tty_port_lower_dtr_rts); |
203 | 203 | ||
204 | /** | 204 | /** |
205 | * tty_port_block_til_ready - Waiting logic for tty open | 205 | * tty_port_block_til_ready - Waiting logic for tty open |
206 | * @port: the tty port being opened | 206 | * @port: the tty port being opened |
207 | * @tty: the tty device being bound | 207 | * @tty: the tty device being bound |
208 | * @filp: the file pointer of the opener | 208 | * @filp: the file pointer of the opener |
209 | * | 209 | * |
210 | * Implement the core POSIX/SuS tty behaviour when opening a tty device. | 210 | * Implement the core POSIX/SuS tty behaviour when opening a tty device. |
211 | * Handles: | 211 | * Handles: |
212 | * - hangup (both before and during) | 212 | * - hangup (both before and during) |
213 | * - non blocking open | 213 | * - non blocking open |
214 | * - rts/dtr/dcd | 214 | * - rts/dtr/dcd |
215 | * - signals | 215 | * - signals |
216 | * - port flags and counts | 216 | * - port flags and counts |
217 | * | 217 | * |
218 | * The passed tty_port must implement the carrier_raised method if it can | 218 | * The passed tty_port must implement the carrier_raised method if it can |
219 | * do carrier detect and the dtr_rts method if it supports software | 219 | * do carrier detect and the dtr_rts method if it supports software |
220 | * management of these lines. Note that the dtr/rts raise is done each | 220 | * management of these lines. Note that the dtr/rts raise is done each |
221 | * iteration as a hangup may have previously dropped them while we wait. | 221 | * iteration as a hangup may have previously dropped them while we wait. |
222 | */ | 222 | */ |
223 | 223 | ||
224 | int tty_port_block_til_ready(struct tty_port *port, | 224 | int tty_port_block_til_ready(struct tty_port *port, |
225 | struct tty_struct *tty, struct file *filp) | 225 | struct tty_struct *tty, struct file *filp) |
226 | { | 226 | { |
227 | int do_clocal = 0, retval; | 227 | int do_clocal = 0, retval; |
228 | unsigned long flags; | 228 | unsigned long flags; |
229 | DEFINE_WAIT(wait); | 229 | DEFINE_WAIT(wait); |
230 | 230 | ||
231 | /* block if port is in the process of being closed */ | 231 | /* block if port is in the process of being closed */ |
232 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { | 232 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { |
233 | wait_event_interruptible_tty(port->close_wait, | 233 | wait_event_interruptible_tty(port->close_wait, |
234 | !(port->flags & ASYNC_CLOSING)); | 234 | !(port->flags & ASYNC_CLOSING)); |
235 | if (port->flags & ASYNC_HUP_NOTIFY) | 235 | if (port->flags & ASYNC_HUP_NOTIFY) |
236 | return -EAGAIN; | 236 | return -EAGAIN; |
237 | else | 237 | else |
238 | return -ERESTARTSYS; | 238 | return -ERESTARTSYS; |
239 | } | 239 | } |
240 | 240 | ||
241 | /* if non-blocking mode is set we can pass directly to open unless | 241 | /* if non-blocking mode is set we can pass directly to open unless |
242 | the port has just hung up or is in another error state */ | 242 | the port has just hung up or is in another error state */ |
243 | if (tty->flags & (1 << TTY_IO_ERROR)) { | 243 | if (tty->flags & (1 << TTY_IO_ERROR)) { |
244 | port->flags |= ASYNC_NORMAL_ACTIVE; | 244 | port->flags |= ASYNC_NORMAL_ACTIVE; |
245 | return 0; | 245 | return 0; |
246 | } | 246 | } |
247 | if (filp->f_flags & O_NONBLOCK) { | 247 | if (filp->f_flags & O_NONBLOCK) { |
248 | /* Indicate we are open */ | 248 | /* Indicate we are open */ |
249 | if (tty->termios->c_cflag & CBAUD) | 249 | if (tty->termios->c_cflag & CBAUD) |
250 | tty_port_raise_dtr_rts(port); | 250 | tty_port_raise_dtr_rts(port); |
251 | port->flags |= ASYNC_NORMAL_ACTIVE; | 251 | port->flags |= ASYNC_NORMAL_ACTIVE; |
252 | return 0; | 252 | return 0; |
253 | } | 253 | } |
254 | 254 | ||
255 | if (C_CLOCAL(tty)) | 255 | if (C_CLOCAL(tty)) |
256 | do_clocal = 1; | 256 | do_clocal = 1; |
257 | 257 | ||
258 | /* Block waiting until we can proceed. We may need to wait for the | 258 | /* Block waiting until we can proceed. We may need to wait for the |
259 | carrier, but we must also wait for any close that is in progress | 259 | carrier, but we must also wait for any close that is in progress |
260 | before the next open may complete */ | 260 | before the next open may complete */ |
261 | 261 | ||
262 | retval = 0; | 262 | retval = 0; |
263 | 263 | ||
264 | /* The port lock protects the port counts */ | 264 | /* The port lock protects the port counts */ |
265 | spin_lock_irqsave(&port->lock, flags); | 265 | spin_lock_irqsave(&port->lock, flags); |
266 | if (!tty_hung_up_p(filp)) | 266 | if (!tty_hung_up_p(filp)) |
267 | port->count--; | 267 | port->count--; |
268 | port->blocked_open++; | 268 | port->blocked_open++; |
269 | spin_unlock_irqrestore(&port->lock, flags); | 269 | spin_unlock_irqrestore(&port->lock, flags); |
270 | 270 | ||
271 | while (1) { | 271 | while (1) { |
272 | /* Indicate we are open */ | 272 | /* Indicate we are open */ |
273 | if (tty->termios->c_cflag & CBAUD) | 273 | if (tty->termios->c_cflag & CBAUD) |
274 | tty_port_raise_dtr_rts(port); | 274 | tty_port_raise_dtr_rts(port); |
275 | 275 | ||
276 | prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); | 276 | prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); |
277 | /* Check for a hangup or uninitialised port. | 277 | /* Check for a hangup or uninitialised port. |
278 | Return accordingly */ | 278 | Return accordingly */ |
279 | if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { | 279 | if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { |
280 | if (port->flags & ASYNC_HUP_NOTIFY) | 280 | if (port->flags & ASYNC_HUP_NOTIFY) |
281 | retval = -EAGAIN; | 281 | retval = -EAGAIN; |
282 | else | 282 | else |
283 | retval = -ERESTARTSYS; | 283 | retval = -ERESTARTSYS; |
284 | break; | 284 | break; |
285 | } | 285 | } |
286 | /* | 286 | /* |
287 | * Probe the carrier. For devices with no carrier detect | 287 | * Probe the carrier. For devices with no carrier detect |
288 | * tty_port_carrier_raised will always return true. | 288 | * tty_port_carrier_raised will always return true. |
289 | * Never ask drivers if CLOCAL is set, this causes troubles | 289 | * Never ask drivers if CLOCAL is set, this causes troubles |
290 | * on some hardware. | 290 | * on some hardware. |
291 | */ | 291 | */ |
292 | if (!(port->flags & ASYNC_CLOSING) && | 292 | if (!(port->flags & ASYNC_CLOSING) && |
293 | (do_clocal || tty_port_carrier_raised(port))) | 293 | (do_clocal || tty_port_carrier_raised(port))) |
294 | break; | 294 | break; |
295 | if (signal_pending(current)) { | 295 | if (signal_pending(current)) { |
296 | retval = -ERESTARTSYS; | 296 | retval = -ERESTARTSYS; |
297 | break; | 297 | break; |
298 | } | 298 | } |
299 | tty_unlock(); | 299 | tty_unlock(); |
300 | schedule(); | 300 | schedule(); |
301 | tty_lock(); | 301 | tty_lock(); |
302 | } | 302 | } |
303 | finish_wait(&port->open_wait, &wait); | 303 | finish_wait(&port->open_wait, &wait); |
304 | 304 | ||
305 | /* Update counts. A parallel hangup will have set count to zero and | 305 | /* Update counts. A parallel hangup will have set count to zero and |
306 | we must not mess that up further */ | 306 | we must not mess that up further */ |
307 | spin_lock_irqsave(&port->lock, flags); | 307 | spin_lock_irqsave(&port->lock, flags); |
308 | if (!tty_hung_up_p(filp)) | 308 | if (!tty_hung_up_p(filp)) |
309 | port->count++; | 309 | port->count++; |
310 | port->blocked_open--; | 310 | port->blocked_open--; |
311 | if (retval == 0) | 311 | if (retval == 0) |
312 | port->flags |= ASYNC_NORMAL_ACTIVE; | 312 | port->flags |= ASYNC_NORMAL_ACTIVE; |
313 | spin_unlock_irqrestore(&port->lock, flags); | 313 | spin_unlock_irqrestore(&port->lock, flags); |
314 | return retval; | 314 | return retval; |
315 | } | 315 | } |
316 | EXPORT_SYMBOL(tty_port_block_til_ready); | 316 | EXPORT_SYMBOL(tty_port_block_til_ready); |
317 | 317 | ||
318 | int tty_port_close_start(struct tty_port *port, | 318 | int tty_port_close_start(struct tty_port *port, |
319 | struct tty_struct *tty, struct file *filp) | 319 | struct tty_struct *tty, struct file *filp) |
320 | { | 320 | { |
321 | unsigned long flags; | 321 | unsigned long flags; |
322 | 322 | ||
323 | spin_lock_irqsave(&port->lock, flags); | 323 | spin_lock_irqsave(&port->lock, flags); |
324 | if (tty_hung_up_p(filp)) { | 324 | if (tty_hung_up_p(filp)) { |
325 | spin_unlock_irqrestore(&port->lock, flags); | 325 | spin_unlock_irqrestore(&port->lock, flags); |
326 | return 0; | 326 | return 0; |
327 | } | 327 | } |
328 | 328 | ||
329 | if (tty->count == 1 && port->count != 1) { | 329 | if (tty->count == 1 && port->count != 1) { |
330 | printk(KERN_WARNING | 330 | printk(KERN_WARNING |
331 | "tty_port_close_start: tty->count = 1 port count = %d.\n", | 331 | "tty_port_close_start: tty->count = 1 port count = %d.\n", |
332 | port->count); | 332 | port->count); |
333 | port->count = 1; | 333 | port->count = 1; |
334 | } | 334 | } |
335 | if (--port->count < 0) { | 335 | if (--port->count < 0) { |
336 | printk(KERN_WARNING "tty_port_close_start: count = %d\n", | 336 | printk(KERN_WARNING "tty_port_close_start: count = %d\n", |
337 | port->count); | 337 | port->count); |
338 | port->count = 0; | 338 | port->count = 0; |
339 | } | 339 | } |
340 | 340 | ||
341 | if (port->count) { | 341 | if (port->count) { |
342 | spin_unlock_irqrestore(&port->lock, flags); | 342 | spin_unlock_irqrestore(&port->lock, flags); |
343 | if (port->ops->drop) | 343 | if (port->ops->drop) |
344 | port->ops->drop(port); | 344 | port->ops->drop(port); |
345 | return 0; | 345 | return 0; |
346 | } | 346 | } |
347 | set_bit(ASYNCB_CLOSING, &port->flags); | 347 | set_bit(ASYNCB_CLOSING, &port->flags); |
348 | tty->closing = 1; | 348 | tty->closing = 1; |
349 | spin_unlock_irqrestore(&port->lock, flags); | 349 | spin_unlock_irqrestore(&port->lock, flags); |
350 | /* Don't block on a stalled port, just pull the chain */ | 350 | /* Don't block on a stalled port, just pull the chain */ |
351 | if (tty->flow_stopped) | 351 | if (tty->flow_stopped) |
352 | tty_driver_flush_buffer(tty); | 352 | tty_driver_flush_buffer(tty); |
353 | if (test_bit(ASYNCB_INITIALIZED, &port->flags) && | 353 | if (test_bit(ASYNCB_INITIALIZED, &port->flags) && |
354 | port->closing_wait != ASYNC_CLOSING_WAIT_NONE) | 354 | port->closing_wait != ASYNC_CLOSING_WAIT_NONE) |
355 | tty_wait_until_sent_from_close(tty, port->closing_wait); | 355 | tty_wait_until_sent_from_close(tty, port->closing_wait); |
356 | if (port->drain_delay) { | 356 | if (port->drain_delay) { |
357 | unsigned int bps = tty_get_baud_rate(tty); | 357 | unsigned int bps = tty_get_baud_rate(tty); |
358 | long timeout; | 358 | long timeout; |
359 | 359 | ||
360 | if (bps > 1200) | 360 | if (bps > 1200) |
361 | timeout = max_t(long, | 361 | timeout = max_t(long, |
362 | (HZ * 10 * port->drain_delay) / bps, HZ / 10); | 362 | (HZ * 10 * port->drain_delay) / bps, HZ / 10); |
363 | else | 363 | else |
364 | timeout = 2 * HZ; | 364 | timeout = 2 * HZ; |
365 | schedule_timeout_interruptible(timeout); | 365 | schedule_timeout_interruptible(timeout); |
366 | } | 366 | } |
367 | /* Flush the ldisc buffering */ | 367 | /* Flush the ldisc buffering */ |
368 | tty_ldisc_flush(tty); | 368 | tty_ldisc_flush(tty); |
369 | 369 | ||
370 | /* Drop DTR/RTS if HUPCL is set. This causes any attached modem to | 370 | /* Drop DTR/RTS if HUPCL is set. This causes any attached modem to |
371 | hang up the line */ | 371 | hang up the line */ |
372 | if (tty->termios->c_cflag & HUPCL) | 372 | if (tty->termios->c_cflag & HUPCL) |
373 | tty_port_lower_dtr_rts(port); | 373 | tty_port_lower_dtr_rts(port); |
374 | 374 | ||
375 | /* Don't call port->drop for the last reference. Callers will want | 375 | /* Don't call port->drop for the last reference. Callers will want |
376 | to drop the last active reference in ->shutdown() or the tty | 376 | to drop the last active reference in ->shutdown() or the tty |
377 | shutdown path */ | 377 | shutdown path */ |
378 | return 1; | 378 | return 1; |
379 | } | 379 | } |
380 | EXPORT_SYMBOL(tty_port_close_start); | 380 | EXPORT_SYMBOL(tty_port_close_start); |
381 | 381 | ||
382 | void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) | 382 | void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) |
383 | { | 383 | { |
384 | unsigned long flags; | 384 | unsigned long flags; |
385 | 385 | ||
386 | spin_lock_irqsave(&port->lock, flags); | 386 | spin_lock_irqsave(&port->lock, flags); |
387 | tty->closing = 0; | 387 | tty->closing = 0; |
388 | 388 | ||
389 | if (port->blocked_open) { | 389 | if (port->blocked_open) { |
390 | spin_unlock_irqrestore(&port->lock, flags); | 390 | spin_unlock_irqrestore(&port->lock, flags); |
391 | if (port->close_delay) { | 391 | if (port->close_delay) { |
392 | msleep_interruptible( | 392 | msleep_interruptible( |
393 | jiffies_to_msecs(port->close_delay)); | 393 | jiffies_to_msecs(port->close_delay)); |
394 | } | 394 | } |
395 | spin_lock_irqsave(&port->lock, flags); | 395 | spin_lock_irqsave(&port->lock, flags); |
396 | wake_up_interruptible(&port->open_wait); | 396 | wake_up_interruptible(&port->open_wait); |
397 | } | 397 | } |
398 | port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); | 398 | port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); |
399 | wake_up_interruptible(&port->close_wait); | 399 | wake_up_interruptible(&port->close_wait); |
400 | spin_unlock_irqrestore(&port->lock, flags); | 400 | spin_unlock_irqrestore(&port->lock, flags); |
401 | } | 401 | } |
402 | EXPORT_SYMBOL(tty_port_close_end); | 402 | EXPORT_SYMBOL(tty_port_close_end); |
403 | 403 | ||
404 | void tty_port_close(struct tty_port *port, struct tty_struct *tty, | 404 | void tty_port_close(struct tty_port *port, struct tty_struct *tty, |
405 | struct file *filp) | 405 | struct file *filp) |
406 | { | 406 | { |
407 | if (tty_port_close_start(port, tty, filp) == 0) | 407 | if (tty_port_close_start(port, tty, filp) == 0) |
408 | return; | 408 | return; |
409 | tty_port_shutdown(port); | 409 | tty_port_shutdown(port); |
410 | set_bit(TTY_IO_ERROR, &tty->flags); | 410 | set_bit(TTY_IO_ERROR, &tty->flags); |
411 | tty_port_close_end(port, tty); | 411 | tty_port_close_end(port, tty); |
412 | tty_port_tty_set(port, NULL); | 412 | tty_port_tty_set(port, NULL); |
413 | } | 413 | } |
414 | EXPORT_SYMBOL(tty_port_close); | 414 | EXPORT_SYMBOL(tty_port_close); |
415 | 415 | ||
416 | int tty_port_install(struct tty_port *port, struct tty_driver *driver, | ||
417 | struct tty_struct *tty) | ||
418 | { | ||
419 | tty->port = port; | ||
420 | return tty_standard_install(driver, tty); | ||
421 | } | ||
422 | EXPORT_SYMBOL_GPL(tty_port_install); | ||
423 | |||
416 | int tty_port_open(struct tty_port *port, struct tty_struct *tty, | 424 | int tty_port_open(struct tty_port *port, struct tty_struct *tty, |
417 | struct file *filp) | 425 | struct file *filp) |
418 | { | 426 | { |
419 | spin_lock_irq(&port->lock); | 427 | spin_lock_irq(&port->lock); |
420 | if (!tty_hung_up_p(filp)) | 428 | if (!tty_hung_up_p(filp)) |
421 | ++port->count; | 429 | ++port->count; |
422 | spin_unlock_irq(&port->lock); | 430 | spin_unlock_irq(&port->lock); |
423 | tty_port_tty_set(port, tty); | 431 | tty_port_tty_set(port, tty); |
424 | 432 | ||
425 | /* | 433 | /* |
426 | * Do the device-specific open only if the hardware isn't | 434 | * Do the device-specific open only if the hardware isn't |
427 | * already initialized. Serialize open and shutdown using the | 435 | * already initialized. Serialize open and shutdown using the |
428 | * port mutex. | 436 | * port mutex. |
429 | */ | 437 | */ |
430 | 438 | ||
431 | mutex_lock(&port->mutex); | 439 | mutex_lock(&port->mutex); |
432 | 440 | ||
433 | if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) { | 441 | if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) { |
434 | clear_bit(TTY_IO_ERROR, &tty->flags); | 442 | clear_bit(TTY_IO_ERROR, &tty->flags); |
435 | if (port->ops->activate) { | 443 | if (port->ops->activate) { |
436 | int retval = port->ops->activate(port, tty); | 444 | int retval = port->ops->activate(port, tty); |
437 | if (retval) { | 445 | if (retval) { |
438 | mutex_unlock(&port->mutex); | 446 | mutex_unlock(&port->mutex); |
439 | return retval; | 447 | return retval; |
440 | } | 448 | } |
441 | } | 449 | } |
442 | set_bit(ASYNCB_INITIALIZED, &port->flags); | 450 | set_bit(ASYNCB_INITIALIZED, &port->flags); |
443 | } | 451 | } |
444 | mutex_unlock(&port->mutex); | 452 | mutex_unlock(&port->mutex); |
445 | return tty_port_block_til_ready(port, tty, filp); | 453 | return tty_port_block_til_ready(port, tty, filp); |
446 | } | 454 | } |
447 | 455 | ||
448 | EXPORT_SYMBOL(tty_port_open); | 456 | EXPORT_SYMBOL(tty_port_open); |
449 | 457 |
include/linux/tty.h
1 | #ifndef _LINUX_TTY_H | 1 | #ifndef _LINUX_TTY_H |
2 | #define _LINUX_TTY_H | 2 | #define _LINUX_TTY_H |
3 | 3 | ||
4 | /* | 4 | /* |
5 | * 'tty.h' defines some structures used by tty_io.c and some defines. | 5 | * 'tty.h' defines some structures used by tty_io.c and some defines. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #define NR_LDISCS 30 | 8 | #define NR_LDISCS 30 |
9 | 9 | ||
10 | /* line disciplines */ | 10 | /* line disciplines */ |
11 | #define N_TTY 0 | 11 | #define N_TTY 0 |
12 | #define N_SLIP 1 | 12 | #define N_SLIP 1 |
13 | #define N_MOUSE 2 | 13 | #define N_MOUSE 2 |
14 | #define N_PPP 3 | 14 | #define N_PPP 3 |
15 | #define N_STRIP 4 | 15 | #define N_STRIP 4 |
16 | #define N_AX25 5 | 16 | #define N_AX25 5 |
17 | #define N_X25 6 /* X.25 async */ | 17 | #define N_X25 6 /* X.25 async */ |
18 | #define N_6PACK 7 | 18 | #define N_6PACK 7 |
19 | #define N_MASC 8 /* Reserved for Mobitex module <kaz@cafe.net> */ | 19 | #define N_MASC 8 /* Reserved for Mobitex module <kaz@cafe.net> */ |
20 | #define N_R3964 9 /* Reserved for Simatic R3964 module */ | 20 | #define N_R3964 9 /* Reserved for Simatic R3964 module */ |
21 | #define N_PROFIBUS_FDL 10 /* Reserved for Profibus */ | 21 | #define N_PROFIBUS_FDL 10 /* Reserved for Profibus */ |
22 | #define N_IRDA 11 /* Linux IrDa - http://irda.sourceforge.net/ */ | 22 | #define N_IRDA 11 /* Linux IrDa - http://irda.sourceforge.net/ */ |
23 | #define N_SMSBLOCK 12 /* SMS block mode - for talking to GSM data */ | 23 | #define N_SMSBLOCK 12 /* SMS block mode - for talking to GSM data */ |
24 | /* cards about SMS messages */ | 24 | /* cards about SMS messages */ |
25 | #define N_HDLC 13 /* synchronous HDLC */ | 25 | #define N_HDLC 13 /* synchronous HDLC */ |
26 | #define N_SYNC_PPP 14 /* synchronous PPP */ | 26 | #define N_SYNC_PPP 14 /* synchronous PPP */ |
27 | #define N_HCI 15 /* Bluetooth HCI UART */ | 27 | #define N_HCI 15 /* Bluetooth HCI UART */ |
28 | #define N_GIGASET_M101 16 /* Siemens Gigaset M101 serial DECT adapter */ | 28 | #define N_GIGASET_M101 16 /* Siemens Gigaset M101 serial DECT adapter */ |
29 | #define N_SLCAN 17 /* Serial / USB serial CAN Adaptors */ | 29 | #define N_SLCAN 17 /* Serial / USB serial CAN Adaptors */ |
30 | #define N_PPS 18 /* Pulse per Second */ | 30 | #define N_PPS 18 /* Pulse per Second */ |
31 | #define N_V253 19 /* Codec control over voice modem */ | 31 | #define N_V253 19 /* Codec control over voice modem */ |
32 | #define N_CAIF 20 /* CAIF protocol for talking to modems */ | 32 | #define N_CAIF 20 /* CAIF protocol for talking to modems */ |
33 | #define N_GSM0710 21 /* GSM 0710 Mux */ | 33 | #define N_GSM0710 21 /* GSM 0710 Mux */ |
34 | #define N_TI_WL 22 /* for TI's WL BT, FM, GPS combo chips */ | 34 | #define N_TI_WL 22 /* for TI's WL BT, FM, GPS combo chips */ |
35 | #define N_TRACESINK 23 /* Trace data routing for MIPI P1149.7 */ | 35 | #define N_TRACESINK 23 /* Trace data routing for MIPI P1149.7 */ |
36 | #define N_TRACEROUTER 24 /* Trace data routing for MIPI P1149.7 */ | 36 | #define N_TRACEROUTER 24 /* Trace data routing for MIPI P1149.7 */ |
37 | 37 | ||
38 | #ifdef __KERNEL__ | 38 | #ifdef __KERNEL__ |
39 | #include <linux/fs.h> | 39 | #include <linux/fs.h> |
40 | #include <linux/major.h> | 40 | #include <linux/major.h> |
41 | #include <linux/termios.h> | 41 | #include <linux/termios.h> |
42 | #include <linux/workqueue.h> | 42 | #include <linux/workqueue.h> |
43 | #include <linux/tty_driver.h> | 43 | #include <linux/tty_driver.h> |
44 | #include <linux/tty_ldisc.h> | 44 | #include <linux/tty_ldisc.h> |
45 | #include <linux/mutex.h> | 45 | #include <linux/mutex.h> |
46 | 46 | ||
47 | 47 | ||
48 | 48 | ||
49 | /* | 49 | /* |
50 | * (Note: the *_driver.minor_start values 1, 64, 128, 192 are | 50 | * (Note: the *_driver.minor_start values 1, 64, 128, 192 are |
51 | * hardcoded at present.) | 51 | * hardcoded at present.) |
52 | */ | 52 | */ |
53 | #define NR_UNIX98_PTY_DEFAULT 4096 /* Default maximum for Unix98 ptys */ | 53 | #define NR_UNIX98_PTY_DEFAULT 4096 /* Default maximum for Unix98 ptys */ |
54 | #define NR_UNIX98_PTY_RESERVE 1024 /* Default reserve for main devpts */ | 54 | #define NR_UNIX98_PTY_RESERVE 1024 /* Default reserve for main devpts */ |
55 | #define NR_UNIX98_PTY_MAX (1 << MINORBITS) /* Absolute limit */ | 55 | #define NR_UNIX98_PTY_MAX (1 << MINORBITS) /* Absolute limit */ |
56 | 56 | ||
57 | /* | 57 | /* |
58 | * This character is the same as _POSIX_VDISABLE: it cannot be used as | 58 | * This character is the same as _POSIX_VDISABLE: it cannot be used as |
59 | * a c_cc[] character, but indicates that a particular special character | 59 | * a c_cc[] character, but indicates that a particular special character |
60 | * isn't in use (eg VINTR has no character etc) | 60 | * isn't in use (eg VINTR has no character etc) |
61 | */ | 61 | */ |
62 | #define __DISABLED_CHAR '\0' | 62 | #define __DISABLED_CHAR '\0' |
63 | 63 | ||
64 | struct tty_buffer { | 64 | struct tty_buffer { |
65 | struct tty_buffer *next; | 65 | struct tty_buffer *next; |
66 | char *char_buf_ptr; | 66 | char *char_buf_ptr; |
67 | unsigned char *flag_buf_ptr; | 67 | unsigned char *flag_buf_ptr; |
68 | int used; | 68 | int used; |
69 | int size; | 69 | int size; |
70 | int commit; | 70 | int commit; |
71 | int read; | 71 | int read; |
72 | /* Data points here */ | 72 | /* Data points here */ |
73 | unsigned long data[0]; | 73 | unsigned long data[0]; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | /* | 76 | /* |
77 | * We default to dicing tty buffer allocations to this many characters | 77 | * We default to dicing tty buffer allocations to this many characters |
78 | * in order to avoid multiple page allocations. We know the size of | 78 | * in order to avoid multiple page allocations. We know the size of |
79 | * tty_buffer itself but it must also be taken into account that the | 79 | * tty_buffer itself but it must also be taken into account that the |
80 | * the buffer is 256 byte aligned. See tty_buffer_find for the allocation | 80 | * the buffer is 256 byte aligned. See tty_buffer_find for the allocation |
81 | * logic this must match | 81 | * logic this must match |
82 | */ | 82 | */ |
83 | 83 | ||
84 | #define TTY_BUFFER_PAGE (((PAGE_SIZE - sizeof(struct tty_buffer)) / 2) & ~0xFF) | 84 | #define TTY_BUFFER_PAGE (((PAGE_SIZE - sizeof(struct tty_buffer)) / 2) & ~0xFF) |
85 | 85 | ||
86 | 86 | ||
87 | struct tty_bufhead { | 87 | struct tty_bufhead { |
88 | struct work_struct work; | 88 | struct work_struct work; |
89 | spinlock_t lock; | 89 | spinlock_t lock; |
90 | struct tty_buffer *head; /* Queue head */ | 90 | struct tty_buffer *head; /* Queue head */ |
91 | struct tty_buffer *tail; /* Active buffer */ | 91 | struct tty_buffer *tail; /* Active buffer */ |
92 | struct tty_buffer *free; /* Free queue head */ | 92 | struct tty_buffer *free; /* Free queue head */ |
93 | int memory_used; /* Buffer space used excluding | 93 | int memory_used; /* Buffer space used excluding |
94 | free queue */ | 94 | free queue */ |
95 | }; | 95 | }; |
96 | /* | 96 | /* |
97 | * When a break, frame error, or parity error happens, these codes are | 97 | * When a break, frame error, or parity error happens, these codes are |
98 | * stuffed into the flags buffer. | 98 | * stuffed into the flags buffer. |
99 | */ | 99 | */ |
100 | #define TTY_NORMAL 0 | 100 | #define TTY_NORMAL 0 |
101 | #define TTY_BREAK 1 | 101 | #define TTY_BREAK 1 |
102 | #define TTY_FRAME 2 | 102 | #define TTY_FRAME 2 |
103 | #define TTY_PARITY 3 | 103 | #define TTY_PARITY 3 |
104 | #define TTY_OVERRUN 4 | 104 | #define TTY_OVERRUN 4 |
105 | 105 | ||
106 | #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR]) | 106 | #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR]) |
107 | #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT]) | 107 | #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT]) |
108 | #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE]) | 108 | #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE]) |
109 | #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL]) | 109 | #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL]) |
110 | #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF]) | 110 | #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF]) |
111 | #define TIME_CHAR(tty) ((tty)->termios->c_cc[VTIME]) | 111 | #define TIME_CHAR(tty) ((tty)->termios->c_cc[VTIME]) |
112 | #define MIN_CHAR(tty) ((tty)->termios->c_cc[VMIN]) | 112 | #define MIN_CHAR(tty) ((tty)->termios->c_cc[VMIN]) |
113 | #define SWTC_CHAR(tty) ((tty)->termios->c_cc[VSWTC]) | 113 | #define SWTC_CHAR(tty) ((tty)->termios->c_cc[VSWTC]) |
114 | #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART]) | 114 | #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART]) |
115 | #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP]) | 115 | #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP]) |
116 | #define SUSP_CHAR(tty) ((tty)->termios->c_cc[VSUSP]) | 116 | #define SUSP_CHAR(tty) ((tty)->termios->c_cc[VSUSP]) |
117 | #define EOL_CHAR(tty) ((tty)->termios->c_cc[VEOL]) | 117 | #define EOL_CHAR(tty) ((tty)->termios->c_cc[VEOL]) |
118 | #define REPRINT_CHAR(tty) ((tty)->termios->c_cc[VREPRINT]) | 118 | #define REPRINT_CHAR(tty) ((tty)->termios->c_cc[VREPRINT]) |
119 | #define DISCARD_CHAR(tty) ((tty)->termios->c_cc[VDISCARD]) | 119 | #define DISCARD_CHAR(tty) ((tty)->termios->c_cc[VDISCARD]) |
120 | #define WERASE_CHAR(tty) ((tty)->termios->c_cc[VWERASE]) | 120 | #define WERASE_CHAR(tty) ((tty)->termios->c_cc[VWERASE]) |
121 | #define LNEXT_CHAR(tty) ((tty)->termios->c_cc[VLNEXT]) | 121 | #define LNEXT_CHAR(tty) ((tty)->termios->c_cc[VLNEXT]) |
122 | #define EOL2_CHAR(tty) ((tty)->termios->c_cc[VEOL2]) | 122 | #define EOL2_CHAR(tty) ((tty)->termios->c_cc[VEOL2]) |
123 | 123 | ||
124 | #define _I_FLAG(tty, f) ((tty)->termios->c_iflag & (f)) | 124 | #define _I_FLAG(tty, f) ((tty)->termios->c_iflag & (f)) |
125 | #define _O_FLAG(tty, f) ((tty)->termios->c_oflag & (f)) | 125 | #define _O_FLAG(tty, f) ((tty)->termios->c_oflag & (f)) |
126 | #define _C_FLAG(tty, f) ((tty)->termios->c_cflag & (f)) | 126 | #define _C_FLAG(tty, f) ((tty)->termios->c_cflag & (f)) |
127 | #define _L_FLAG(tty, f) ((tty)->termios->c_lflag & (f)) | 127 | #define _L_FLAG(tty, f) ((tty)->termios->c_lflag & (f)) |
128 | 128 | ||
129 | #define I_IGNBRK(tty) _I_FLAG((tty), IGNBRK) | 129 | #define I_IGNBRK(tty) _I_FLAG((tty), IGNBRK) |
130 | #define I_BRKINT(tty) _I_FLAG((tty), BRKINT) | 130 | #define I_BRKINT(tty) _I_FLAG((tty), BRKINT) |
131 | #define I_IGNPAR(tty) _I_FLAG((tty), IGNPAR) | 131 | #define I_IGNPAR(tty) _I_FLAG((tty), IGNPAR) |
132 | #define I_PARMRK(tty) _I_FLAG((tty), PARMRK) | 132 | #define I_PARMRK(tty) _I_FLAG((tty), PARMRK) |
133 | #define I_INPCK(tty) _I_FLAG((tty), INPCK) | 133 | #define I_INPCK(tty) _I_FLAG((tty), INPCK) |
134 | #define I_ISTRIP(tty) _I_FLAG((tty), ISTRIP) | 134 | #define I_ISTRIP(tty) _I_FLAG((tty), ISTRIP) |
135 | #define I_INLCR(tty) _I_FLAG((tty), INLCR) | 135 | #define I_INLCR(tty) _I_FLAG((tty), INLCR) |
136 | #define I_IGNCR(tty) _I_FLAG((tty), IGNCR) | 136 | #define I_IGNCR(tty) _I_FLAG((tty), IGNCR) |
137 | #define I_ICRNL(tty) _I_FLAG((tty), ICRNL) | 137 | #define I_ICRNL(tty) _I_FLAG((tty), ICRNL) |
138 | #define I_IUCLC(tty) _I_FLAG((tty), IUCLC) | 138 | #define I_IUCLC(tty) _I_FLAG((tty), IUCLC) |
139 | #define I_IXON(tty) _I_FLAG((tty), IXON) | 139 | #define I_IXON(tty) _I_FLAG((tty), IXON) |
140 | #define I_IXANY(tty) _I_FLAG((tty), IXANY) | 140 | #define I_IXANY(tty) _I_FLAG((tty), IXANY) |
141 | #define I_IXOFF(tty) _I_FLAG((tty), IXOFF) | 141 | #define I_IXOFF(tty) _I_FLAG((tty), IXOFF) |
142 | #define I_IMAXBEL(tty) _I_FLAG((tty), IMAXBEL) | 142 | #define I_IMAXBEL(tty) _I_FLAG((tty), IMAXBEL) |
143 | #define I_IUTF8(tty) _I_FLAG((tty), IUTF8) | 143 | #define I_IUTF8(tty) _I_FLAG((tty), IUTF8) |
144 | 144 | ||
145 | #define O_OPOST(tty) _O_FLAG((tty), OPOST) | 145 | #define O_OPOST(tty) _O_FLAG((tty), OPOST) |
146 | #define O_OLCUC(tty) _O_FLAG((tty), OLCUC) | 146 | #define O_OLCUC(tty) _O_FLAG((tty), OLCUC) |
147 | #define O_ONLCR(tty) _O_FLAG((tty), ONLCR) | 147 | #define O_ONLCR(tty) _O_FLAG((tty), ONLCR) |
148 | #define O_OCRNL(tty) _O_FLAG((tty), OCRNL) | 148 | #define O_OCRNL(tty) _O_FLAG((tty), OCRNL) |
149 | #define O_ONOCR(tty) _O_FLAG((tty), ONOCR) | 149 | #define O_ONOCR(tty) _O_FLAG((tty), ONOCR) |
150 | #define O_ONLRET(tty) _O_FLAG((tty), ONLRET) | 150 | #define O_ONLRET(tty) _O_FLAG((tty), ONLRET) |
151 | #define O_OFILL(tty) _O_FLAG((tty), OFILL) | 151 | #define O_OFILL(tty) _O_FLAG((tty), OFILL) |
152 | #define O_OFDEL(tty) _O_FLAG((tty), OFDEL) | 152 | #define O_OFDEL(tty) _O_FLAG((tty), OFDEL) |
153 | #define O_NLDLY(tty) _O_FLAG((tty), NLDLY) | 153 | #define O_NLDLY(tty) _O_FLAG((tty), NLDLY) |
154 | #define O_CRDLY(tty) _O_FLAG((tty), CRDLY) | 154 | #define O_CRDLY(tty) _O_FLAG((tty), CRDLY) |
155 | #define O_TABDLY(tty) _O_FLAG((tty), TABDLY) | 155 | #define O_TABDLY(tty) _O_FLAG((tty), TABDLY) |
156 | #define O_BSDLY(tty) _O_FLAG((tty), BSDLY) | 156 | #define O_BSDLY(tty) _O_FLAG((tty), BSDLY) |
157 | #define O_VTDLY(tty) _O_FLAG((tty), VTDLY) | 157 | #define O_VTDLY(tty) _O_FLAG((tty), VTDLY) |
158 | #define O_FFDLY(tty) _O_FLAG((tty), FFDLY) | 158 | #define O_FFDLY(tty) _O_FLAG((tty), FFDLY) |
159 | 159 | ||
160 | #define C_BAUD(tty) _C_FLAG((tty), CBAUD) | 160 | #define C_BAUD(tty) _C_FLAG((tty), CBAUD) |
161 | #define C_CSIZE(tty) _C_FLAG((tty), CSIZE) | 161 | #define C_CSIZE(tty) _C_FLAG((tty), CSIZE) |
162 | #define C_CSTOPB(tty) _C_FLAG((tty), CSTOPB) | 162 | #define C_CSTOPB(tty) _C_FLAG((tty), CSTOPB) |
163 | #define C_CREAD(tty) _C_FLAG((tty), CREAD) | 163 | #define C_CREAD(tty) _C_FLAG((tty), CREAD) |
164 | #define C_PARENB(tty) _C_FLAG((tty), PARENB) | 164 | #define C_PARENB(tty) _C_FLAG((tty), PARENB) |
165 | #define C_PARODD(tty) _C_FLAG((tty), PARODD) | 165 | #define C_PARODD(tty) _C_FLAG((tty), PARODD) |
166 | #define C_HUPCL(tty) _C_FLAG((tty), HUPCL) | 166 | #define C_HUPCL(tty) _C_FLAG((tty), HUPCL) |
167 | #define C_CLOCAL(tty) _C_FLAG((tty), CLOCAL) | 167 | #define C_CLOCAL(tty) _C_FLAG((tty), CLOCAL) |
168 | #define C_CIBAUD(tty) _C_FLAG((tty), CIBAUD) | 168 | #define C_CIBAUD(tty) _C_FLAG((tty), CIBAUD) |
169 | #define C_CRTSCTS(tty) _C_FLAG((tty), CRTSCTS) | 169 | #define C_CRTSCTS(tty) _C_FLAG((tty), CRTSCTS) |
170 | 170 | ||
171 | #define L_ISIG(tty) _L_FLAG((tty), ISIG) | 171 | #define L_ISIG(tty) _L_FLAG((tty), ISIG) |
172 | #define L_ICANON(tty) _L_FLAG((tty), ICANON) | 172 | #define L_ICANON(tty) _L_FLAG((tty), ICANON) |
173 | #define L_XCASE(tty) _L_FLAG((tty), XCASE) | 173 | #define L_XCASE(tty) _L_FLAG((tty), XCASE) |
174 | #define L_ECHO(tty) _L_FLAG((tty), ECHO) | 174 | #define L_ECHO(tty) _L_FLAG((tty), ECHO) |
175 | #define L_ECHOE(tty) _L_FLAG((tty), ECHOE) | 175 | #define L_ECHOE(tty) _L_FLAG((tty), ECHOE) |
176 | #define L_ECHOK(tty) _L_FLAG((tty), ECHOK) | 176 | #define L_ECHOK(tty) _L_FLAG((tty), ECHOK) |
177 | #define L_ECHONL(tty) _L_FLAG((tty), ECHONL) | 177 | #define L_ECHONL(tty) _L_FLAG((tty), ECHONL) |
178 | #define L_NOFLSH(tty) _L_FLAG((tty), NOFLSH) | 178 | #define L_NOFLSH(tty) _L_FLAG((tty), NOFLSH) |
179 | #define L_TOSTOP(tty) _L_FLAG((tty), TOSTOP) | 179 | #define L_TOSTOP(tty) _L_FLAG((tty), TOSTOP) |
180 | #define L_ECHOCTL(tty) _L_FLAG((tty), ECHOCTL) | 180 | #define L_ECHOCTL(tty) _L_FLAG((tty), ECHOCTL) |
181 | #define L_ECHOPRT(tty) _L_FLAG((tty), ECHOPRT) | 181 | #define L_ECHOPRT(tty) _L_FLAG((tty), ECHOPRT) |
182 | #define L_ECHOKE(tty) _L_FLAG((tty), ECHOKE) | 182 | #define L_ECHOKE(tty) _L_FLAG((tty), ECHOKE) |
183 | #define L_FLUSHO(tty) _L_FLAG((tty), FLUSHO) | 183 | #define L_FLUSHO(tty) _L_FLAG((tty), FLUSHO) |
184 | #define L_PENDIN(tty) _L_FLAG((tty), PENDIN) | 184 | #define L_PENDIN(tty) _L_FLAG((tty), PENDIN) |
185 | #define L_IEXTEN(tty) _L_FLAG((tty), IEXTEN) | 185 | #define L_IEXTEN(tty) _L_FLAG((tty), IEXTEN) |
186 | #define L_EXTPROC(tty) _L_FLAG((tty), EXTPROC) | 186 | #define L_EXTPROC(tty) _L_FLAG((tty), EXTPROC) |
187 | 187 | ||
188 | struct device; | 188 | struct device; |
189 | struct signal_struct; | 189 | struct signal_struct; |
190 | 190 | ||
191 | /* | 191 | /* |
192 | * Port level information. Each device keeps its own port level information | 192 | * Port level information. Each device keeps its own port level information |
193 | * so provide a common structure for those ports wanting to use common support | 193 | * so provide a common structure for those ports wanting to use common support |
194 | * routines. | 194 | * routines. |
195 | * | 195 | * |
196 | * The tty port has a different lifetime to the tty so must be kept apart. | 196 | * The tty port has a different lifetime to the tty so must be kept apart. |
197 | * In addition be careful as tty -> port mappings are valid for the life | 197 | * In addition be careful as tty -> port mappings are valid for the life |
198 | * of the tty object but in many cases port -> tty mappings are valid only | 198 | * of the tty object but in many cases port -> tty mappings are valid only |
199 | * until a hangup so don't use the wrong path. | 199 | * until a hangup so don't use the wrong path. |
200 | */ | 200 | */ |
201 | 201 | ||
202 | struct tty_port; | 202 | struct tty_port; |
203 | 203 | ||
204 | struct tty_port_operations { | 204 | struct tty_port_operations { |
205 | /* Return 1 if the carrier is raised */ | 205 | /* Return 1 if the carrier is raised */ |
206 | int (*carrier_raised)(struct tty_port *port); | 206 | int (*carrier_raised)(struct tty_port *port); |
207 | /* Control the DTR line */ | 207 | /* Control the DTR line */ |
208 | void (*dtr_rts)(struct tty_port *port, int raise); | 208 | void (*dtr_rts)(struct tty_port *port, int raise); |
209 | /* Called when the last close completes or a hangup finishes | 209 | /* Called when the last close completes or a hangup finishes |
210 | IFF the port was initialized. Do not use to free resources. Called | 210 | IFF the port was initialized. Do not use to free resources. Called |
211 | under the port mutex to serialize against activate/shutdowns */ | 211 | under the port mutex to serialize against activate/shutdowns */ |
212 | void (*shutdown)(struct tty_port *port); | 212 | void (*shutdown)(struct tty_port *port); |
213 | void (*drop)(struct tty_port *port); | 213 | void (*drop)(struct tty_port *port); |
214 | /* Called under the port mutex from tty_port_open, serialized using | 214 | /* Called under the port mutex from tty_port_open, serialized using |
215 | the port mutex */ | 215 | the port mutex */ |
216 | /* FIXME: long term getting the tty argument *out* of this would be | 216 | /* FIXME: long term getting the tty argument *out* of this would be |
217 | good for consoles */ | 217 | good for consoles */ |
218 | int (*activate)(struct tty_port *port, struct tty_struct *tty); | 218 | int (*activate)(struct tty_port *port, struct tty_struct *tty); |
219 | /* Called on the final put of a port */ | 219 | /* Called on the final put of a port */ |
220 | void (*destruct)(struct tty_port *port); | 220 | void (*destruct)(struct tty_port *port); |
221 | }; | 221 | }; |
222 | 222 | ||
223 | struct tty_port { | 223 | struct tty_port { |
224 | struct tty_struct *tty; /* Back pointer */ | 224 | struct tty_struct *tty; /* Back pointer */ |
225 | const struct tty_port_operations *ops; /* Port operations */ | 225 | const struct tty_port_operations *ops; /* Port operations */ |
226 | spinlock_t lock; /* Lock protecting tty field */ | 226 | spinlock_t lock; /* Lock protecting tty field */ |
227 | int blocked_open; /* Waiting to open */ | 227 | int blocked_open; /* Waiting to open */ |
228 | int count; /* Usage count */ | 228 | int count; /* Usage count */ |
229 | wait_queue_head_t open_wait; /* Open waiters */ | 229 | wait_queue_head_t open_wait; /* Open waiters */ |
230 | wait_queue_head_t close_wait; /* Close waiters */ | 230 | wait_queue_head_t close_wait; /* Close waiters */ |
231 | wait_queue_head_t delta_msr_wait; /* Modem status change */ | 231 | wait_queue_head_t delta_msr_wait; /* Modem status change */ |
232 | unsigned long flags; /* TTY flags ASY_*/ | 232 | unsigned long flags; /* TTY flags ASY_*/ |
233 | unsigned char console:1; /* port is a console */ | 233 | unsigned char console:1; /* port is a console */ |
234 | struct mutex mutex; /* Locking */ | 234 | struct mutex mutex; /* Locking */ |
235 | struct mutex buf_mutex; /* Buffer alloc lock */ | 235 | struct mutex buf_mutex; /* Buffer alloc lock */ |
236 | unsigned char *xmit_buf; /* Optional buffer */ | 236 | unsigned char *xmit_buf; /* Optional buffer */ |
237 | unsigned int close_delay; /* Close port delay */ | 237 | unsigned int close_delay; /* Close port delay */ |
238 | unsigned int closing_wait; /* Delay for output */ | 238 | unsigned int closing_wait; /* Delay for output */ |
239 | int drain_delay; /* Set to zero if no pure time | 239 | int drain_delay; /* Set to zero if no pure time |
240 | based drain is needed else | 240 | based drain is needed else |
241 | set to size of fifo */ | 241 | set to size of fifo */ |
242 | struct kref kref; /* Ref counter */ | 242 | struct kref kref; /* Ref counter */ |
243 | }; | 243 | }; |
244 | 244 | ||
245 | /* | 245 | /* |
246 | * Where all of the state associated with a tty is kept while the tty | 246 | * Where all of the state associated with a tty is kept while the tty |
247 | * is open. Since the termios state should be kept even if the tty | 247 | * is open. Since the termios state should be kept even if the tty |
248 | * has been closed --- for things like the baud rate, etc --- it is | 248 | * has been closed --- for things like the baud rate, etc --- it is |
249 | * not stored here, but rather a pointer to the real state is stored | 249 | * not stored here, but rather a pointer to the real state is stored |
250 | * here. Possible the winsize structure should have the same | 250 | * here. Possible the winsize structure should have the same |
251 | * treatment, but (1) the default 80x24 is usually right and (2) it's | 251 | * treatment, but (1) the default 80x24 is usually right and (2) it's |
252 | * most often used by a windowing system, which will set the correct | 252 | * most often used by a windowing system, which will set the correct |
253 | * size each time the window is created or resized anyway. | 253 | * size each time the window is created or resized anyway. |
254 | * - TYT, 9/14/92 | 254 | * - TYT, 9/14/92 |
255 | */ | 255 | */ |
256 | 256 | ||
257 | struct tty_operations; | 257 | struct tty_operations; |
258 | 258 | ||
259 | struct tty_struct { | 259 | struct tty_struct { |
260 | int magic; | 260 | int magic; |
261 | struct kref kref; | 261 | struct kref kref; |
262 | struct device *dev; | 262 | struct device *dev; |
263 | struct tty_driver *driver; | 263 | struct tty_driver *driver; |
264 | const struct tty_operations *ops; | 264 | const struct tty_operations *ops; |
265 | int index; | 265 | int index; |
266 | 266 | ||
267 | /* Protects ldisc changes: Lock tty not pty */ | 267 | /* Protects ldisc changes: Lock tty not pty */ |
268 | struct mutex ldisc_mutex; | 268 | struct mutex ldisc_mutex; |
269 | struct tty_ldisc *ldisc; | 269 | struct tty_ldisc *ldisc; |
270 | 270 | ||
271 | struct mutex termios_mutex; | 271 | struct mutex termios_mutex; |
272 | spinlock_t ctrl_lock; | 272 | spinlock_t ctrl_lock; |
273 | /* Termios values are protected by the termios mutex */ | 273 | /* Termios values are protected by the termios mutex */ |
274 | struct ktermios *termios, *termios_locked; | 274 | struct ktermios *termios, *termios_locked; |
275 | struct termiox *termiox; /* May be NULL for unsupported */ | 275 | struct termiox *termiox; /* May be NULL for unsupported */ |
276 | char name[64]; | 276 | char name[64]; |
277 | struct pid *pgrp; /* Protected by ctrl lock */ | 277 | struct pid *pgrp; /* Protected by ctrl lock */ |
278 | struct pid *session; | 278 | struct pid *session; |
279 | unsigned long flags; | 279 | unsigned long flags; |
280 | int count; | 280 | int count; |
281 | struct winsize winsize; /* termios mutex */ | 281 | struct winsize winsize; /* termios mutex */ |
282 | unsigned char stopped:1, hw_stopped:1, flow_stopped:1, packet:1; | 282 | unsigned char stopped:1, hw_stopped:1, flow_stopped:1, packet:1; |
283 | unsigned char low_latency:1, warned:1; | 283 | unsigned char low_latency:1, warned:1; |
284 | unsigned char ctrl_status; /* ctrl_lock */ | 284 | unsigned char ctrl_status; /* ctrl_lock */ |
285 | unsigned int receive_room; /* Bytes free for queue */ | 285 | unsigned int receive_room; /* Bytes free for queue */ |
286 | 286 | ||
287 | struct tty_struct *link; | 287 | struct tty_struct *link; |
288 | struct fasync_struct *fasync; | 288 | struct fasync_struct *fasync; |
289 | struct tty_bufhead buf; /* Locked internally */ | 289 | struct tty_bufhead buf; /* Locked internally */ |
290 | int alt_speed; /* For magic substitution of 38400 bps */ | 290 | int alt_speed; /* For magic substitution of 38400 bps */ |
291 | wait_queue_head_t write_wait; | 291 | wait_queue_head_t write_wait; |
292 | wait_queue_head_t read_wait; | 292 | wait_queue_head_t read_wait; |
293 | struct work_struct hangup_work; | 293 | struct work_struct hangup_work; |
294 | void *disc_data; | 294 | void *disc_data; |
295 | void *driver_data; | 295 | void *driver_data; |
296 | struct list_head tty_files; | 296 | struct list_head tty_files; |
297 | 297 | ||
298 | #define N_TTY_BUF_SIZE 4096 | 298 | #define N_TTY_BUF_SIZE 4096 |
299 | 299 | ||
300 | /* | 300 | /* |
301 | * The following is data for the N_TTY line discipline. For | 301 | * The following is data for the N_TTY line discipline. For |
302 | * historical reasons, this is included in the tty structure. | 302 | * historical reasons, this is included in the tty structure. |
303 | * Mostly locked by the BKL. | 303 | * Mostly locked by the BKL. |
304 | */ | 304 | */ |
305 | unsigned int column; | 305 | unsigned int column; |
306 | unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1; | 306 | unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1; |
307 | unsigned char closing:1; | 307 | unsigned char closing:1; |
308 | unsigned char echo_overrun:1; | 308 | unsigned char echo_overrun:1; |
309 | unsigned short minimum_to_wake; | 309 | unsigned short minimum_to_wake; |
310 | unsigned long overrun_time; | 310 | unsigned long overrun_time; |
311 | int num_overrun; | 311 | int num_overrun; |
312 | unsigned long process_char_map[256/(8*sizeof(unsigned long))]; | 312 | unsigned long process_char_map[256/(8*sizeof(unsigned long))]; |
313 | char *read_buf; | 313 | char *read_buf; |
314 | int read_head; | 314 | int read_head; |
315 | int read_tail; | 315 | int read_tail; |
316 | int read_cnt; | 316 | int read_cnt; |
317 | unsigned long read_flags[N_TTY_BUF_SIZE/(8*sizeof(unsigned long))]; | 317 | unsigned long read_flags[N_TTY_BUF_SIZE/(8*sizeof(unsigned long))]; |
318 | unsigned char *echo_buf; | 318 | unsigned char *echo_buf; |
319 | unsigned int echo_pos; | 319 | unsigned int echo_pos; |
320 | unsigned int echo_cnt; | 320 | unsigned int echo_cnt; |
321 | int canon_data; | 321 | int canon_data; |
322 | unsigned long canon_head; | 322 | unsigned long canon_head; |
323 | unsigned int canon_column; | 323 | unsigned int canon_column; |
324 | struct mutex atomic_read_lock; | 324 | struct mutex atomic_read_lock; |
325 | struct mutex atomic_write_lock; | 325 | struct mutex atomic_write_lock; |
326 | struct mutex output_lock; | 326 | struct mutex output_lock; |
327 | struct mutex echo_lock; | 327 | struct mutex echo_lock; |
328 | unsigned char *write_buf; | 328 | unsigned char *write_buf; |
329 | int write_cnt; | 329 | int write_cnt; |
330 | spinlock_t read_lock; | 330 | spinlock_t read_lock; |
331 | /* If the tty has a pending do_SAK, queue it here - akpm */ | 331 | /* If the tty has a pending do_SAK, queue it here - akpm */ |
332 | struct work_struct SAK_work; | 332 | struct work_struct SAK_work; |
333 | struct tty_port *port; | 333 | struct tty_port *port; |
334 | }; | 334 | }; |
335 | 335 | ||
336 | /* Each of a tty's open files has private_data pointing to tty_file_private */ | 336 | /* Each of a tty's open files has private_data pointing to tty_file_private */ |
337 | struct tty_file_private { | 337 | struct tty_file_private { |
338 | struct tty_struct *tty; | 338 | struct tty_struct *tty; |
339 | struct file *file; | 339 | struct file *file; |
340 | struct list_head list; | 340 | struct list_head list; |
341 | }; | 341 | }; |
342 | 342 | ||
343 | /* tty magic number */ | 343 | /* tty magic number */ |
344 | #define TTY_MAGIC 0x5401 | 344 | #define TTY_MAGIC 0x5401 |
345 | 345 | ||
346 | /* | 346 | /* |
347 | * These bits are used in the flags field of the tty structure. | 347 | * These bits are used in the flags field of the tty structure. |
348 | * | 348 | * |
349 | * So that interrupts won't be able to mess up the queues, | 349 | * So that interrupts won't be able to mess up the queues, |
350 | * copy_to_cooked must be atomic with respect to itself, as must | 350 | * copy_to_cooked must be atomic with respect to itself, as must |
351 | * tty->write. Thus, you must use the inline functions set_bit() and | 351 | * tty->write. Thus, you must use the inline functions set_bit() and |
352 | * clear_bit() to make things atomic. | 352 | * clear_bit() to make things atomic. |
353 | */ | 353 | */ |
354 | #define TTY_THROTTLED 0 /* Call unthrottle() at threshold min */ | 354 | #define TTY_THROTTLED 0 /* Call unthrottle() at threshold min */ |
355 | #define TTY_IO_ERROR 1 /* Cause an I/O error (may be no ldisc too) */ | 355 | #define TTY_IO_ERROR 1 /* Cause an I/O error (may be no ldisc too) */ |
356 | #define TTY_OTHER_CLOSED 2 /* Other side (if any) has closed */ | 356 | #define TTY_OTHER_CLOSED 2 /* Other side (if any) has closed */ |
357 | #define TTY_EXCLUSIVE 3 /* Exclusive open mode */ | 357 | #define TTY_EXCLUSIVE 3 /* Exclusive open mode */ |
358 | #define TTY_DEBUG 4 /* Debugging */ | 358 | #define TTY_DEBUG 4 /* Debugging */ |
359 | #define TTY_DO_WRITE_WAKEUP 5 /* Call write_wakeup after queuing new */ | 359 | #define TTY_DO_WRITE_WAKEUP 5 /* Call write_wakeup after queuing new */ |
360 | #define TTY_PUSH 6 /* n_tty private */ | 360 | #define TTY_PUSH 6 /* n_tty private */ |
361 | #define TTY_CLOSING 7 /* ->close() in progress */ | 361 | #define TTY_CLOSING 7 /* ->close() in progress */ |
362 | #define TTY_LDISC 9 /* Line discipline attached */ | 362 | #define TTY_LDISC 9 /* Line discipline attached */ |
363 | #define TTY_LDISC_CHANGING 10 /* Line discipline changing */ | 363 | #define TTY_LDISC_CHANGING 10 /* Line discipline changing */ |
364 | #define TTY_LDISC_OPEN 11 /* Line discipline is open */ | 364 | #define TTY_LDISC_OPEN 11 /* Line discipline is open */ |
365 | #define TTY_HW_COOK_OUT 14 /* Hardware can do output cooking */ | 365 | #define TTY_HW_COOK_OUT 14 /* Hardware can do output cooking */ |
366 | #define TTY_HW_COOK_IN 15 /* Hardware can do input cooking */ | 366 | #define TTY_HW_COOK_IN 15 /* Hardware can do input cooking */ |
367 | #define TTY_PTY_LOCK 16 /* pty private */ | 367 | #define TTY_PTY_LOCK 16 /* pty private */ |
368 | #define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */ | 368 | #define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */ |
369 | #define TTY_HUPPED 18 /* Post driver->hangup() */ | 369 | #define TTY_HUPPED 18 /* Post driver->hangup() */ |
370 | #define TTY_FLUSHING 19 /* Flushing to ldisc in progress */ | 370 | #define TTY_FLUSHING 19 /* Flushing to ldisc in progress */ |
371 | #define TTY_FLUSHPENDING 20 /* Queued buffer flush pending */ | 371 | #define TTY_FLUSHPENDING 20 /* Queued buffer flush pending */ |
372 | #define TTY_HUPPING 21 /* ->hangup() in progress */ | 372 | #define TTY_HUPPING 21 /* ->hangup() in progress */ |
373 | 373 | ||
374 | #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty)) | 374 | #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty)) |
375 | 375 | ||
376 | extern void tty_write_flush(struct tty_struct *); | 376 | extern void tty_write_flush(struct tty_struct *); |
377 | 377 | ||
378 | extern struct ktermios tty_std_termios; | 378 | extern struct ktermios tty_std_termios; |
379 | 379 | ||
380 | extern void console_init(void); | 380 | extern void console_init(void); |
381 | extern int vcs_init(void); | 381 | extern int vcs_init(void); |
382 | 382 | ||
383 | extern struct class *tty_class; | 383 | extern struct class *tty_class; |
384 | 384 | ||
385 | /** | 385 | /** |
386 | * tty_kref_get - get a tty reference | 386 | * tty_kref_get - get a tty reference |
387 | * @tty: tty device | 387 | * @tty: tty device |
388 | * | 388 | * |
389 | * Return a new reference to a tty object. The caller must hold | 389 | * Return a new reference to a tty object. The caller must hold |
390 | * sufficient locks/counts to ensure that their existing reference cannot | 390 | * sufficient locks/counts to ensure that their existing reference cannot |
391 | * go away | 391 | * go away |
392 | */ | 392 | */ |
393 | 393 | ||
394 | static inline struct tty_struct *tty_kref_get(struct tty_struct *tty) | 394 | static inline struct tty_struct *tty_kref_get(struct tty_struct *tty) |
395 | { | 395 | { |
396 | if (tty) | 396 | if (tty) |
397 | kref_get(&tty->kref); | 397 | kref_get(&tty->kref); |
398 | return tty; | 398 | return tty; |
399 | } | 399 | } |
400 | extern void tty_kref_put(struct tty_struct *tty); | 400 | extern void tty_kref_put(struct tty_struct *tty); |
401 | 401 | ||
402 | extern int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, | 402 | extern int tty_paranoia_check(struct tty_struct *tty, struct inode *inode, |
403 | const char *routine); | 403 | const char *routine); |
404 | extern char *tty_name(struct tty_struct *tty, char *buf); | 404 | extern char *tty_name(struct tty_struct *tty, char *buf); |
405 | extern void tty_wait_until_sent(struct tty_struct *tty, long timeout); | 405 | extern void tty_wait_until_sent(struct tty_struct *tty, long timeout); |
406 | extern int tty_check_change(struct tty_struct *tty); | 406 | extern int tty_check_change(struct tty_struct *tty); |
407 | extern void stop_tty(struct tty_struct *tty); | 407 | extern void stop_tty(struct tty_struct *tty); |
408 | extern void start_tty(struct tty_struct *tty); | 408 | extern void start_tty(struct tty_struct *tty); |
409 | extern int tty_register_driver(struct tty_driver *driver); | 409 | extern int tty_register_driver(struct tty_driver *driver); |
410 | extern int tty_unregister_driver(struct tty_driver *driver); | 410 | extern int tty_unregister_driver(struct tty_driver *driver); |
411 | extern struct device *tty_register_device(struct tty_driver *driver, | 411 | extern struct device *tty_register_device(struct tty_driver *driver, |
412 | unsigned index, struct device *dev); | 412 | unsigned index, struct device *dev); |
413 | extern void tty_unregister_device(struct tty_driver *driver, unsigned index); | 413 | extern void tty_unregister_device(struct tty_driver *driver, unsigned index); |
414 | extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp, | 414 | extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp, |
415 | int buflen); | 415 | int buflen); |
416 | extern void tty_write_message(struct tty_struct *tty, char *msg); | 416 | extern void tty_write_message(struct tty_struct *tty, char *msg); |
417 | extern int tty_put_char(struct tty_struct *tty, unsigned char c); | 417 | extern int tty_put_char(struct tty_struct *tty, unsigned char c); |
418 | extern int tty_chars_in_buffer(struct tty_struct *tty); | 418 | extern int tty_chars_in_buffer(struct tty_struct *tty); |
419 | extern int tty_write_room(struct tty_struct *tty); | 419 | extern int tty_write_room(struct tty_struct *tty); |
420 | extern void tty_driver_flush_buffer(struct tty_struct *tty); | 420 | extern void tty_driver_flush_buffer(struct tty_struct *tty); |
421 | extern void tty_throttle(struct tty_struct *tty); | 421 | extern void tty_throttle(struct tty_struct *tty); |
422 | extern void tty_unthrottle(struct tty_struct *tty); | 422 | extern void tty_unthrottle(struct tty_struct *tty); |
423 | extern int tty_do_resize(struct tty_struct *tty, struct winsize *ws); | 423 | extern int tty_do_resize(struct tty_struct *tty, struct winsize *ws); |
424 | extern void tty_driver_remove_tty(struct tty_driver *driver, | 424 | extern void tty_driver_remove_tty(struct tty_driver *driver, |
425 | struct tty_struct *tty); | 425 | struct tty_struct *tty); |
426 | extern void tty_shutdown(struct tty_struct *tty); | 426 | extern void tty_shutdown(struct tty_struct *tty); |
427 | extern void tty_free_termios(struct tty_struct *tty); | 427 | extern void tty_free_termios(struct tty_struct *tty); |
428 | extern int is_current_pgrp_orphaned(void); | 428 | extern int is_current_pgrp_orphaned(void); |
429 | extern struct pid *tty_get_pgrp(struct tty_struct *tty); | 429 | extern struct pid *tty_get_pgrp(struct tty_struct *tty); |
430 | extern int is_ignored(int sig); | 430 | extern int is_ignored(int sig); |
431 | extern int tty_signal(int sig, struct tty_struct *tty); | 431 | extern int tty_signal(int sig, struct tty_struct *tty); |
432 | extern void tty_hangup(struct tty_struct *tty); | 432 | extern void tty_hangup(struct tty_struct *tty); |
433 | extern void tty_vhangup(struct tty_struct *tty); | 433 | extern void tty_vhangup(struct tty_struct *tty); |
434 | extern void tty_vhangup_locked(struct tty_struct *tty); | 434 | extern void tty_vhangup_locked(struct tty_struct *tty); |
435 | extern void tty_vhangup_self(void); | 435 | extern void tty_vhangup_self(void); |
436 | extern void tty_unhangup(struct file *filp); | 436 | extern void tty_unhangup(struct file *filp); |
437 | extern int tty_hung_up_p(struct file *filp); | 437 | extern int tty_hung_up_p(struct file *filp); |
438 | extern void do_SAK(struct tty_struct *tty); | 438 | extern void do_SAK(struct tty_struct *tty); |
439 | extern void __do_SAK(struct tty_struct *tty); | 439 | extern void __do_SAK(struct tty_struct *tty); |
440 | extern void disassociate_ctty(int priv); | 440 | extern void disassociate_ctty(int priv); |
441 | extern void no_tty(void); | 441 | extern void no_tty(void); |
442 | extern void tty_flip_buffer_push(struct tty_struct *tty); | 442 | extern void tty_flip_buffer_push(struct tty_struct *tty); |
443 | extern void tty_flush_to_ldisc(struct tty_struct *tty); | 443 | extern void tty_flush_to_ldisc(struct tty_struct *tty); |
444 | extern void tty_buffer_free_all(struct tty_struct *tty); | 444 | extern void tty_buffer_free_all(struct tty_struct *tty); |
445 | extern void tty_buffer_flush(struct tty_struct *tty); | 445 | extern void tty_buffer_flush(struct tty_struct *tty); |
446 | extern void tty_buffer_init(struct tty_struct *tty); | 446 | extern void tty_buffer_init(struct tty_struct *tty); |
447 | extern speed_t tty_get_baud_rate(struct tty_struct *tty); | 447 | extern speed_t tty_get_baud_rate(struct tty_struct *tty); |
448 | extern speed_t tty_termios_baud_rate(struct ktermios *termios); | 448 | extern speed_t tty_termios_baud_rate(struct ktermios *termios); |
449 | extern speed_t tty_termios_input_baud_rate(struct ktermios *termios); | 449 | extern speed_t tty_termios_input_baud_rate(struct ktermios *termios); |
450 | extern void tty_termios_encode_baud_rate(struct ktermios *termios, | 450 | extern void tty_termios_encode_baud_rate(struct ktermios *termios, |
451 | speed_t ibaud, speed_t obaud); | 451 | speed_t ibaud, speed_t obaud); |
452 | extern void tty_encode_baud_rate(struct tty_struct *tty, | 452 | extern void tty_encode_baud_rate(struct tty_struct *tty, |
453 | speed_t ibaud, speed_t obaud); | 453 | speed_t ibaud, speed_t obaud); |
454 | extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old); | 454 | extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old); |
455 | extern int tty_termios_hw_change(struct ktermios *a, struct ktermios *b); | 455 | extern int tty_termios_hw_change(struct ktermios *a, struct ktermios *b); |
456 | extern int tty_set_termios(struct tty_struct *tty, struct ktermios *kt); | 456 | extern int tty_set_termios(struct tty_struct *tty, struct ktermios *kt); |
457 | 457 | ||
458 | extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *); | 458 | extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *); |
459 | extern void tty_ldisc_deref(struct tty_ldisc *); | 459 | extern void tty_ldisc_deref(struct tty_ldisc *); |
460 | extern struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *); | 460 | extern struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *); |
461 | extern void tty_ldisc_hangup(struct tty_struct *tty); | 461 | extern void tty_ldisc_hangup(struct tty_struct *tty); |
462 | extern const struct file_operations tty_ldiscs_proc_fops; | 462 | extern const struct file_operations tty_ldiscs_proc_fops; |
463 | 463 | ||
464 | extern void tty_wakeup(struct tty_struct *tty); | 464 | extern void tty_wakeup(struct tty_struct *tty); |
465 | extern void tty_ldisc_flush(struct tty_struct *tty); | 465 | extern void tty_ldisc_flush(struct tty_struct *tty); |
466 | 466 | ||
467 | extern long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | 467 | extern long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
468 | extern int tty_mode_ioctl(struct tty_struct *tty, struct file *file, | 468 | extern int tty_mode_ioctl(struct tty_struct *tty, struct file *file, |
469 | unsigned int cmd, unsigned long arg); | 469 | unsigned int cmd, unsigned long arg); |
470 | extern int tty_perform_flush(struct tty_struct *tty, unsigned long arg); | 470 | extern int tty_perform_flush(struct tty_struct *tty, unsigned long arg); |
471 | extern dev_t tty_devnum(struct tty_struct *tty); | 471 | extern dev_t tty_devnum(struct tty_struct *tty); |
472 | extern void proc_clear_tty(struct task_struct *p); | 472 | extern void proc_clear_tty(struct task_struct *p); |
473 | extern struct tty_struct *get_current_tty(void); | 473 | extern struct tty_struct *get_current_tty(void); |
474 | extern void tty_default_fops(struct file_operations *fops); | 474 | extern void tty_default_fops(struct file_operations *fops); |
475 | extern struct tty_struct *alloc_tty_struct(void); | 475 | extern struct tty_struct *alloc_tty_struct(void); |
476 | extern int tty_alloc_file(struct file *file); | 476 | extern int tty_alloc_file(struct file *file); |
477 | extern void tty_add_file(struct tty_struct *tty, struct file *file); | 477 | extern void tty_add_file(struct tty_struct *tty, struct file *file); |
478 | extern void tty_free_file(struct file *file); | 478 | extern void tty_free_file(struct file *file); |
479 | extern void free_tty_struct(struct tty_struct *tty); | 479 | extern void free_tty_struct(struct tty_struct *tty); |
480 | extern void initialize_tty_struct(struct tty_struct *tty, | 480 | extern void initialize_tty_struct(struct tty_struct *tty, |
481 | struct tty_driver *driver, int idx); | 481 | struct tty_driver *driver, int idx); |
482 | extern void deinitialize_tty_struct(struct tty_struct *tty); | 482 | extern void deinitialize_tty_struct(struct tty_struct *tty); |
483 | extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx); | 483 | extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx); |
484 | extern int tty_release(struct inode *inode, struct file *filp); | 484 | extern int tty_release(struct inode *inode, struct file *filp); |
485 | extern int tty_init_termios(struct tty_struct *tty); | 485 | extern int tty_init_termios(struct tty_struct *tty); |
486 | extern int tty_standard_install(struct tty_driver *driver, | 486 | extern int tty_standard_install(struct tty_driver *driver, |
487 | struct tty_struct *tty); | 487 | struct tty_struct *tty); |
488 | 488 | ||
489 | extern struct tty_struct *tty_pair_get_tty(struct tty_struct *tty); | 489 | extern struct tty_struct *tty_pair_get_tty(struct tty_struct *tty); |
490 | extern struct tty_struct *tty_pair_get_pty(struct tty_struct *tty); | 490 | extern struct tty_struct *tty_pair_get_pty(struct tty_struct *tty); |
491 | 491 | ||
492 | extern struct mutex tty_mutex; | 492 | extern struct mutex tty_mutex; |
493 | extern spinlock_t tty_files_lock; | 493 | extern spinlock_t tty_files_lock; |
494 | 494 | ||
495 | extern void tty_write_unlock(struct tty_struct *tty); | 495 | extern void tty_write_unlock(struct tty_struct *tty); |
496 | extern int tty_write_lock(struct tty_struct *tty, int ndelay); | 496 | extern int tty_write_lock(struct tty_struct *tty, int ndelay); |
497 | #define tty_is_writelocked(tty) (mutex_is_locked(&tty->atomic_write_lock)) | 497 | #define tty_is_writelocked(tty) (mutex_is_locked(&tty->atomic_write_lock)) |
498 | 498 | ||
499 | extern void tty_port_init(struct tty_port *port); | 499 | extern void tty_port_init(struct tty_port *port); |
500 | extern int tty_port_alloc_xmit_buf(struct tty_port *port); | 500 | extern int tty_port_alloc_xmit_buf(struct tty_port *port); |
501 | extern void tty_port_free_xmit_buf(struct tty_port *port); | 501 | extern void tty_port_free_xmit_buf(struct tty_port *port); |
502 | extern void tty_port_put(struct tty_port *port); | 502 | extern void tty_port_put(struct tty_port *port); |
503 | 503 | ||
504 | static inline struct tty_port *tty_port_get(struct tty_port *port) | 504 | static inline struct tty_port *tty_port_get(struct tty_port *port) |
505 | { | 505 | { |
506 | if (port) | 506 | if (port) |
507 | kref_get(&port->kref); | 507 | kref_get(&port->kref); |
508 | return port; | 508 | return port; |
509 | } | 509 | } |
510 | 510 | ||
511 | extern struct tty_struct *tty_port_tty_get(struct tty_port *port); | 511 | extern struct tty_struct *tty_port_tty_get(struct tty_port *port); |
512 | extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty); | 512 | extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty); |
513 | extern int tty_port_carrier_raised(struct tty_port *port); | 513 | extern int tty_port_carrier_raised(struct tty_port *port); |
514 | extern void tty_port_raise_dtr_rts(struct tty_port *port); | 514 | extern void tty_port_raise_dtr_rts(struct tty_port *port); |
515 | extern void tty_port_lower_dtr_rts(struct tty_port *port); | 515 | extern void tty_port_lower_dtr_rts(struct tty_port *port); |
516 | extern void tty_port_hangup(struct tty_port *port); | 516 | extern void tty_port_hangup(struct tty_port *port); |
517 | extern int tty_port_block_til_ready(struct tty_port *port, | 517 | extern int tty_port_block_til_ready(struct tty_port *port, |
518 | struct tty_struct *tty, struct file *filp); | 518 | struct tty_struct *tty, struct file *filp); |
519 | extern int tty_port_close_start(struct tty_port *port, | 519 | extern int tty_port_close_start(struct tty_port *port, |
520 | struct tty_struct *tty, struct file *filp); | 520 | struct tty_struct *tty, struct file *filp); |
521 | extern void tty_port_close_end(struct tty_port *port, struct tty_struct *tty); | 521 | extern void tty_port_close_end(struct tty_port *port, struct tty_struct *tty); |
522 | extern void tty_port_close(struct tty_port *port, | 522 | extern void tty_port_close(struct tty_port *port, |
523 | struct tty_struct *tty, struct file *filp); | 523 | struct tty_struct *tty, struct file *filp); |
524 | extern int tty_port_install(struct tty_port *port, struct tty_driver *driver, | ||
525 | struct tty_struct *tty); | ||
524 | extern int tty_port_open(struct tty_port *port, | 526 | extern int tty_port_open(struct tty_port *port, |
525 | struct tty_struct *tty, struct file *filp); | 527 | struct tty_struct *tty, struct file *filp); |
526 | static inline int tty_port_users(struct tty_port *port) | 528 | static inline int tty_port_users(struct tty_port *port) |
527 | { | 529 | { |
528 | return port->count + port->blocked_open; | 530 | return port->count + port->blocked_open; |
529 | } | 531 | } |
530 | 532 | ||
531 | extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc); | 533 | extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc); |
532 | extern int tty_unregister_ldisc(int disc); | 534 | extern int tty_unregister_ldisc(int disc); |
533 | extern int tty_set_ldisc(struct tty_struct *tty, int ldisc); | 535 | extern int tty_set_ldisc(struct tty_struct *tty, int ldisc); |
534 | extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty); | 536 | extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty); |
535 | extern void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty); | 537 | extern void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty); |
536 | extern void tty_ldisc_init(struct tty_struct *tty); | 538 | extern void tty_ldisc_init(struct tty_struct *tty); |
537 | extern void tty_ldisc_deinit(struct tty_struct *tty); | 539 | extern void tty_ldisc_deinit(struct tty_struct *tty); |
538 | extern void tty_ldisc_begin(void); | 540 | extern void tty_ldisc_begin(void); |
539 | /* This last one is just for the tty layer internals and shouldn't be used elsewhere */ | 541 | /* This last one is just for the tty layer internals and shouldn't be used elsewhere */ |
540 | extern void tty_ldisc_enable(struct tty_struct *tty); | 542 | extern void tty_ldisc_enable(struct tty_struct *tty); |
541 | 543 | ||
542 | 544 | ||
543 | /* n_tty.c */ | 545 | /* n_tty.c */ |
544 | extern struct tty_ldisc_ops tty_ldisc_N_TTY; | 546 | extern struct tty_ldisc_ops tty_ldisc_N_TTY; |
545 | extern void n_tty_inherit_ops(struct tty_ldisc_ops *ops); | 547 | extern void n_tty_inherit_ops(struct tty_ldisc_ops *ops); |
546 | 548 | ||
547 | /* tty_audit.c */ | 549 | /* tty_audit.c */ |
548 | #ifdef CONFIG_AUDIT | 550 | #ifdef CONFIG_AUDIT |
549 | extern void tty_audit_add_data(struct tty_struct *tty, unsigned char *data, | 551 | extern void tty_audit_add_data(struct tty_struct *tty, unsigned char *data, |
550 | size_t size); | 552 | size_t size); |
551 | extern void tty_audit_exit(void); | 553 | extern void tty_audit_exit(void); |
552 | extern void tty_audit_fork(struct signal_struct *sig); | 554 | extern void tty_audit_fork(struct signal_struct *sig); |
553 | extern void tty_audit_tiocsti(struct tty_struct *tty, char ch); | 555 | extern void tty_audit_tiocsti(struct tty_struct *tty, char ch); |
554 | extern void tty_audit_push(struct tty_struct *tty); | 556 | extern void tty_audit_push(struct tty_struct *tty); |
555 | extern int tty_audit_push_task(struct task_struct *tsk, | 557 | extern int tty_audit_push_task(struct task_struct *tsk, |
556 | uid_t loginuid, u32 sessionid); | 558 | uid_t loginuid, u32 sessionid); |
557 | #else | 559 | #else |
558 | static inline void tty_audit_add_data(struct tty_struct *tty, | 560 | static inline void tty_audit_add_data(struct tty_struct *tty, |
559 | unsigned char *data, size_t size) | 561 | unsigned char *data, size_t size) |
560 | { | 562 | { |
561 | } | 563 | } |
562 | static inline void tty_audit_tiocsti(struct tty_struct *tty, char ch) | 564 | static inline void tty_audit_tiocsti(struct tty_struct *tty, char ch) |
563 | { | 565 | { |
564 | } | 566 | } |
565 | static inline void tty_audit_exit(void) | 567 | static inline void tty_audit_exit(void) |
566 | { | 568 | { |
567 | } | 569 | } |
568 | static inline void tty_audit_fork(struct signal_struct *sig) | 570 | static inline void tty_audit_fork(struct signal_struct *sig) |
569 | { | 571 | { |
570 | } | 572 | } |
571 | static inline void tty_audit_push(struct tty_struct *tty) | 573 | static inline void tty_audit_push(struct tty_struct *tty) |
572 | { | 574 | { |
573 | } | 575 | } |
574 | static inline int tty_audit_push_task(struct task_struct *tsk, | 576 | static inline int tty_audit_push_task(struct task_struct *tsk, |
575 | uid_t loginuid, u32 sessionid) | 577 | uid_t loginuid, u32 sessionid) |
576 | { | 578 | { |
577 | return 0; | 579 | return 0; |
578 | } | 580 | } |
579 | #endif | 581 | #endif |
580 | 582 | ||
581 | /* tty_io.c */ | 583 | /* tty_io.c */ |
582 | extern int __init tty_init(void); | 584 | extern int __init tty_init(void); |
583 | 585 | ||
584 | /* tty_ioctl.c */ | 586 | /* tty_ioctl.c */ |
585 | extern int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file, | 587 | extern int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file, |
586 | unsigned int cmd, unsigned long arg); | 588 | unsigned int cmd, unsigned long arg); |
587 | extern long n_tty_compat_ioctl_helper(struct tty_struct *tty, struct file *file, | 589 | extern long n_tty_compat_ioctl_helper(struct tty_struct *tty, struct file *file, |
588 | unsigned int cmd, unsigned long arg); | 590 | unsigned int cmd, unsigned long arg); |
589 | 591 | ||
590 | /* serial.c */ | 592 | /* serial.c */ |
591 | 593 | ||
592 | extern void serial_console_init(void); | 594 | extern void serial_console_init(void); |
593 | 595 | ||
594 | /* pcxx.c */ | 596 | /* pcxx.c */ |
595 | 597 | ||
596 | extern int pcxe_open(struct tty_struct *tty, struct file *filp); | 598 | extern int pcxe_open(struct tty_struct *tty, struct file *filp); |
597 | 599 | ||
598 | /* vt.c */ | 600 | /* vt.c */ |
599 | 601 | ||
600 | extern int vt_ioctl(struct tty_struct *tty, | 602 | extern int vt_ioctl(struct tty_struct *tty, |
601 | unsigned int cmd, unsigned long arg); | 603 | unsigned int cmd, unsigned long arg); |
602 | 604 | ||
603 | extern long vt_compat_ioctl(struct tty_struct *tty, | 605 | extern long vt_compat_ioctl(struct tty_struct *tty, |
604 | unsigned int cmd, unsigned long arg); | 606 | unsigned int cmd, unsigned long arg); |
605 | 607 | ||
606 | /* tty_mutex.c */ | 608 | /* tty_mutex.c */ |
607 | /* functions for preparation of BKL removal */ | 609 | /* functions for preparation of BKL removal */ |
608 | extern void __lockfunc tty_lock(void) __acquires(tty_lock); | 610 | extern void __lockfunc tty_lock(void) __acquires(tty_lock); |
609 | extern void __lockfunc tty_unlock(void) __releases(tty_lock); | 611 | extern void __lockfunc tty_unlock(void) __releases(tty_lock); |
610 | 612 | ||
611 | /* | 613 | /* |
612 | * this shall be called only from where BTM is held (like close) | 614 | * this shall be called only from where BTM is held (like close) |
613 | * | 615 | * |
614 | * We need this to ensure nobody waits for us to finish while we are waiting. | 616 | * We need this to ensure nobody waits for us to finish while we are waiting. |
615 | * Without this we were encountering system stalls. | 617 | * Without this we were encountering system stalls. |
616 | * | 618 | * |
617 | * This should be indeed removed with BTM removal later. | 619 | * This should be indeed removed with BTM removal later. |
618 | * | 620 | * |
619 | * Locking: BTM required. Nobody is allowed to hold port->mutex. | 621 | * Locking: BTM required. Nobody is allowed to hold port->mutex. |
620 | */ | 622 | */ |
621 | static inline void tty_wait_until_sent_from_close(struct tty_struct *tty, | 623 | static inline void tty_wait_until_sent_from_close(struct tty_struct *tty, |
622 | long timeout) | 624 | long timeout) |
623 | { | 625 | { |
624 | tty_unlock(); /* tty->ops->close holds the BTM, drop it while waiting */ | 626 | tty_unlock(); /* tty->ops->close holds the BTM, drop it while waiting */ |
625 | tty_wait_until_sent(tty, timeout); | 627 | tty_wait_until_sent(tty, timeout); |
626 | tty_lock(); | 628 | tty_lock(); |
627 | } | 629 | } |
628 | 630 | ||
629 | /* | 631 | /* |
630 | * wait_event_interruptible_tty -- wait for a condition with the tty lock held | 632 | * wait_event_interruptible_tty -- wait for a condition with the tty lock held |
631 | * | 633 | * |
632 | * The condition we are waiting for might take a long time to | 634 | * The condition we are waiting for might take a long time to |
633 | * become true, or might depend on another thread taking the | 635 | * become true, or might depend on another thread taking the |
634 | * BTM. In either case, we need to drop the BTM to guarantee | 636 | * BTM. In either case, we need to drop the BTM to guarantee |
635 | * forward progress. This is a leftover from the conversion | 637 | * forward progress. This is a leftover from the conversion |
636 | * from the BKL and should eventually get removed as the BTM | 638 | * from the BKL and should eventually get removed as the BTM |
637 | * falls out of use. | 639 | * falls out of use. |
638 | * | 640 | * |
639 | * Do not use in new code. | 641 | * Do not use in new code. |
640 | */ | 642 | */ |
641 | #define wait_event_interruptible_tty(wq, condition) \ | 643 | #define wait_event_interruptible_tty(wq, condition) \ |
642 | ({ \ | 644 | ({ \ |
643 | int __ret = 0; \ | 645 | int __ret = 0; \ |
644 | if (!(condition)) { \ | 646 | if (!(condition)) { \ |
645 | __wait_event_interruptible_tty(wq, condition, __ret); \ | 647 | __wait_event_interruptible_tty(wq, condition, __ret); \ |
646 | } \ | 648 | } \ |
647 | __ret; \ | 649 | __ret; \ |
648 | }) | 650 | }) |
649 | 651 | ||
650 | #define __wait_event_interruptible_tty(wq, condition, ret) \ | 652 | #define __wait_event_interruptible_tty(wq, condition, ret) \ |
651 | do { \ | 653 | do { \ |
652 | DEFINE_WAIT(__wait); \ | 654 | DEFINE_WAIT(__wait); \ |
653 | \ | 655 | \ |
654 | for (;;) { \ | 656 | for (;;) { \ |
655 | prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ | 657 | prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ |
656 | if (condition) \ | 658 | if (condition) \ |
657 | break; \ | 659 | break; \ |
658 | if (!signal_pending(current)) { \ | 660 | if (!signal_pending(current)) { \ |
659 | tty_unlock(); \ | 661 | tty_unlock(); \ |
660 | schedule(); \ | 662 | schedule(); \ |
661 | tty_lock(); \ | 663 | tty_lock(); \ |
662 | continue; \ | 664 | continue; \ |
663 | } \ | 665 | } \ |
664 | ret = -ERESTARTSYS; \ | 666 | ret = -ERESTARTSYS; \ |
665 | break; \ | 667 | break; \ |
666 | } \ | 668 | } \ |
667 | finish_wait(&wq, &__wait); \ | 669 | finish_wait(&wq, &__wait); \ |
668 | } while (0) | 670 | } while (0) |
669 | 671 | ||
670 | 672 | ||
671 | #endif /* __KERNEL__ */ | 673 | #endif /* __KERNEL__ */ |
672 | #endif | 674 | #endif |
673 | 675 |