Lines Matching full:port

2  * Tty port functions
21 void tty_port_init(struct tty_port *port) in tty_port_init() argument
23 memset(port, 0, sizeof(*port)); in tty_port_init()
24 init_waitqueue_head(&port->open_wait); in tty_port_init()
25 init_waitqueue_head(&port->close_wait); in tty_port_init()
26 init_waitqueue_head(&port->delta_msr_wait); in tty_port_init()
27 mutex_init(&port->mutex); in tty_port_init()
28 mutex_init(&port->buf_mutex); in tty_port_init()
29 spin_lock_init(&port->lock); in tty_port_init()
30 port->close_delay = (50 * HZ) / 100; in tty_port_init()
31 port->closing_wait = (3000 * HZ) / 100; in tty_port_init()
32 kref_init(&port->kref); in tty_port_init()
36 int tty_port_alloc_xmit_buf(struct tty_port *port) in tty_port_alloc_xmit_buf() argument
39 mutex_lock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
40 if (port->xmit_buf == NULL) in tty_port_alloc_xmit_buf()
41 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); in tty_port_alloc_xmit_buf()
42 mutex_unlock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
43 if (port->xmit_buf == NULL) in tty_port_alloc_xmit_buf()
49 void tty_port_free_xmit_buf(struct tty_port *port) in tty_port_free_xmit_buf() argument
51 mutex_lock(&port->buf_mutex); in tty_port_free_xmit_buf()
52 if (port->xmit_buf != NULL) { in tty_port_free_xmit_buf()
53 free_page((unsigned long)port->xmit_buf); in tty_port_free_xmit_buf()
54 port->xmit_buf = NULL; in tty_port_free_xmit_buf()
56 mutex_unlock(&port->buf_mutex); in tty_port_free_xmit_buf()
62 struct tty_port *port = container_of(kref, struct tty_port, kref); in tty_port_destructor() local
63 if (port->xmit_buf) in tty_port_destructor()
64 free_page((unsigned long)port->xmit_buf); in tty_port_destructor()
65 if (port->ops->destruct) in tty_port_destructor()
66 port->ops->destruct(port); in tty_port_destructor()
68 kfree(port); in tty_port_destructor()
71 void tty_port_put(struct tty_port *port) in tty_port_put() argument
73 if (port) in tty_port_put()
74 kref_put(&port->kref, tty_port_destructor); in tty_port_put()
80 * @port: tty port
82 * Return a refcount protected tty instance or NULL if the port is not
86 struct tty_struct *tty_port_tty_get(struct tty_port *port) in tty_port_tty_get() argument
91 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_get()
92 tty = tty_kref_get(port->tty); in tty_port_tty_get()
93 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_get()
99 * tty_port_tty_set - set the tty of a port
100 * @port: tty port
103 * Associate the port and tty pair. Manages any internal refcounts.
104 * Pass NULL to deassociate a port
107 void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) in tty_port_tty_set() argument
111 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_set()
112 if (port->tty) in tty_port_tty_set()
113 tty_kref_put(port->tty); in tty_port_tty_set()
114 port->tty = tty_kref_get(tty); in tty_port_tty_set()
115 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_set()
119 static void tty_port_shutdown(struct tty_port *port) in tty_port_shutdown() argument
121 mutex_lock(&port->mutex); in tty_port_shutdown()
122 if (port->ops->shutdown && !port->console && in tty_port_shutdown()
123 test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) in tty_port_shutdown()
124 port->ops->shutdown(port); in tty_port_shutdown()
125 mutex_unlock(&port->mutex); in tty_port_shutdown()
130 * @port: tty port
132 * Perform port level tty hangup flag and count changes. Drop the tty
136 void tty_port_hangup(struct tty_port *port) in tty_port_hangup() argument
140 spin_lock_irqsave(&port->lock, flags); in tty_port_hangup()
141 port->count = 0; in tty_port_hangup()
142 port->flags &= ~ASYNC_NORMAL_ACTIVE; in tty_port_hangup()
143 if (port->tty) { in tty_port_hangup()
144 set_bit(TTY_IO_ERROR, &port->tty->flags); in tty_port_hangup()
145 tty_kref_put(port->tty); in tty_port_hangup()
147 port->tty = NULL; in tty_port_hangup()
148 spin_unlock_irqrestore(&port->lock, flags); in tty_port_hangup()
149 wake_up_interruptible(&port->open_wait); in tty_port_hangup()
150 wake_up_interruptible(&port->delta_msr_wait); in tty_port_hangup()
151 tty_port_shutdown(port); in tty_port_hangup()
157 * @port: tty port
161 * internal to the tty port.
164 int tty_port_carrier_raised(struct tty_port *port) in tty_port_carrier_raised() argument
166 if (port->ops->carrier_raised == NULL) in tty_port_carrier_raised()
168 return port->ops->carrier_raised(port); in tty_port_carrier_raised()
174 * @port: tty port
178 * internal to the tty port.
181 void tty_port_raise_dtr_rts(struct tty_port *port) in tty_port_raise_dtr_rts() argument
183 if (port->ops->dtr_rts) in tty_port_raise_dtr_rts()
184 port->ops->dtr_rts(port, 1); in tty_port_raise_dtr_rts()
190 * @port: tty port
194 * internal to the tty port.
197 void tty_port_lower_dtr_rts(struct tty_port *port) in tty_port_lower_dtr_rts() argument
199 if (port->ops->dtr_rts) in tty_port_lower_dtr_rts()
200 port->ops->dtr_rts(port, 0); in tty_port_lower_dtr_rts()
206 * @port: the tty port being opened
216 * - port flags and counts
224 int tty_port_block_til_ready(struct tty_port *port, in tty_port_block_til_ready() argument
231 /* block if port is in the process of being closed */ in tty_port_block_til_ready()
232 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { in tty_port_block_til_ready()
233 wait_event_interruptible_tty(port->close_wait, in tty_port_block_til_ready()
234 !(port->flags & ASYNC_CLOSING)); in tty_port_block_til_ready()
235 if (port->flags & ASYNC_HUP_NOTIFY) in tty_port_block_til_ready()
242 the port has just hung up or is in another error state */ in tty_port_block_til_ready()
244 port->flags |= ASYNC_NORMAL_ACTIVE; in tty_port_block_til_ready()
250 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
251 port->flags |= ASYNC_NORMAL_ACTIVE; in tty_port_block_til_ready()
264 /* The port lock protects the port counts */ in tty_port_block_til_ready()
265 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
267 port->count--; in tty_port_block_til_ready()
268 port->blocked_open++; in tty_port_block_til_ready()
269 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
274 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
276 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); in tty_port_block_til_ready()
277 /* Check for a hangup or uninitialised port. in tty_port_block_til_ready()
279 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { in tty_port_block_til_ready()
280 if (port->flags & ASYNC_HUP_NOTIFY) in tty_port_block_til_ready()
292 if (!(port->flags & ASYNC_CLOSING) && in tty_port_block_til_ready()
293 (do_clocal || tty_port_carrier_raised(port))) in tty_port_block_til_ready()
303 finish_wait(&port->open_wait, &wait); in tty_port_block_til_ready()
307 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
309 port->count++; in tty_port_block_til_ready()
310 port->blocked_open--; in tty_port_block_til_ready()
312 port->flags |= ASYNC_NORMAL_ACTIVE; in tty_port_block_til_ready()
313 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
318 int tty_port_close_start(struct tty_port *port, in tty_port_close_start() argument
323 spin_lock_irqsave(&port->lock, flags); in tty_port_close_start()
325 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
329 if (tty->count == 1 && port->count != 1) { in tty_port_close_start()
331 "tty_port_close_start: tty->count = 1 port count = %d.\n", in tty_port_close_start()
332 port->count); in tty_port_close_start()
333 port->count = 1; in tty_port_close_start()
335 if (--port->count < 0) { in tty_port_close_start()
337 port->count); in tty_port_close_start()
338 port->count = 0; in tty_port_close_start()
341 if (port->count) { in tty_port_close_start()
342 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
343 if (port->ops->drop) in tty_port_close_start()
344 port->ops->drop(port); in tty_port_close_start()
347 set_bit(ASYNCB_CLOSING, &port->flags); in tty_port_close_start()
349 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
350 /* Don't block on a stalled port, just pull the chain */ in tty_port_close_start()
353 if (test_bit(ASYNCB_INITIALIZED, &port->flags) && in tty_port_close_start()
354 port->closing_wait != ASYNC_CLOSING_WAIT_NONE) in tty_port_close_start()
355 tty_wait_until_sent_from_close(tty, port->closing_wait); in tty_port_close_start()
356 if (port->drain_delay) { in tty_port_close_start()
362 (HZ * 10 * port->drain_delay) / bps, HZ / 10); in tty_port_close_start()
373 tty_port_lower_dtr_rts(port); in tty_port_close_start()
375 /* Don't call port->drop for the last reference. Callers will want in tty_port_close_start()
382 void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) in tty_port_close_end() argument
386 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
389 if (port->blocked_open) { in tty_port_close_end()
390 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
391 if (port->close_delay) { in tty_port_close_end()
393 jiffies_to_msecs(port->close_delay)); in tty_port_close_end()
395 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
396 wake_up_interruptible(&port->open_wait); in tty_port_close_end()
398 port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); in tty_port_close_end()
399 wake_up_interruptible(&port->close_wait); in tty_port_close_end()
400 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
404 void tty_port_close(struct tty_port *port, struct tty_struct *tty, in tty_port_close() argument
407 if (tty_port_close_start(port, tty, filp) == 0) in tty_port_close()
409 tty_port_shutdown(port); in tty_port_close()
411 tty_port_close_end(port, tty); in tty_port_close()
412 tty_port_tty_set(port, NULL); in tty_port_close()
416 int tty_port_open(struct tty_port *port, struct tty_struct *tty, in tty_port_open() argument
419 spin_lock_irq(&port->lock); in tty_port_open()
421 ++port->count; in tty_port_open()
422 spin_unlock_irq(&port->lock); in tty_port_open()
423 tty_port_tty_set(port, tty); in tty_port_open()
428 * port mutex. in tty_port_open()
431 mutex_lock(&port->mutex); in tty_port_open()
433 if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) { in tty_port_open()
435 if (port->ops->activate) { in tty_port_open()
436 int retval = port->ops->activate(port, tty); in tty_port_open()
438 mutex_unlock(&port->mutex); in tty_port_open()
442 set_bit(ASYNCB_INITIALIZED, &port->flags); in tty_port_open()
444 mutex_unlock(&port->mutex); in tty_port_open()
445 return tty_port_block_til_ready(port, tty, filp); in tty_port_open()