Lines Matching refs:port
20 void tty_port_init(struct tty_port *port) in tty_port_init() argument
22 memset(port, 0, sizeof(*port)); in tty_port_init()
23 tty_buffer_init(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()
47 void tty_port_link_device(struct tty_port *port, in tty_port_link_device() argument
52 driver->ports[index] = port; in tty_port_link_device()
67 struct device *tty_port_register_device(struct tty_port *port, in tty_port_register_device() argument
71 tty_port_link_device(port, driver, index); in tty_port_register_device()
89 struct device *tty_port_register_device_attr(struct tty_port *port, in tty_port_register_device_attr() argument
94 tty_port_link_device(port, driver, index); in tty_port_register_device_attr()
100 int tty_port_alloc_xmit_buf(struct tty_port *port) in tty_port_alloc_xmit_buf() argument
103 mutex_lock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
104 if (port->xmit_buf == NULL) in tty_port_alloc_xmit_buf()
105 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); in tty_port_alloc_xmit_buf()
106 mutex_unlock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
107 if (port->xmit_buf == NULL) in tty_port_alloc_xmit_buf()
113 void tty_port_free_xmit_buf(struct tty_port *port) in tty_port_free_xmit_buf() argument
115 mutex_lock(&port->buf_mutex); in tty_port_free_xmit_buf()
116 if (port->xmit_buf != NULL) { in tty_port_free_xmit_buf()
117 free_page((unsigned long)port->xmit_buf); in tty_port_free_xmit_buf()
118 port->xmit_buf = NULL; in tty_port_free_xmit_buf()
120 mutex_unlock(&port->buf_mutex); in tty_port_free_xmit_buf()
132 void tty_port_destroy(struct tty_port *port) in tty_port_destroy() argument
134 cancel_work_sync(&port->buf.work); in tty_port_destroy()
135 tty_buffer_free_all(port); in tty_port_destroy()
141 struct tty_port *port = container_of(kref, struct tty_port, kref); in tty_port_destructor() local
144 if (WARN_ON(port->itty)) in tty_port_destructor()
146 if (port->xmit_buf) in tty_port_destructor()
147 free_page((unsigned long)port->xmit_buf); in tty_port_destructor()
148 tty_port_destroy(port); in tty_port_destructor()
149 if (port->ops && port->ops->destruct) in tty_port_destructor()
150 port->ops->destruct(port); in tty_port_destructor()
152 kfree(port); in tty_port_destructor()
155 void tty_port_put(struct tty_port *port) in tty_port_put() argument
157 if (port) in tty_port_put()
158 kref_put(&port->kref, tty_port_destructor); in tty_port_put()
170 struct tty_struct *tty_port_tty_get(struct tty_port *port) in tty_port_tty_get() argument
175 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_get()
176 tty = tty_kref_get(port->tty); in tty_port_tty_get()
177 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_get()
191 void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) in tty_port_tty_set() argument
195 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_set()
196 tty_kref_put(port->tty); in tty_port_tty_set()
197 port->tty = tty_kref_get(tty); in tty_port_tty_set()
198 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_set()
202 static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty) in tty_port_shutdown() argument
204 mutex_lock(&port->mutex); in tty_port_shutdown()
205 if (port->console) in tty_port_shutdown()
208 if (test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) { in tty_port_shutdown()
214 tty_port_lower_dtr_rts(port); in tty_port_shutdown()
216 if (port->ops->shutdown) in tty_port_shutdown()
217 port->ops->shutdown(port); in tty_port_shutdown()
220 mutex_unlock(&port->mutex); in tty_port_shutdown()
233 void tty_port_hangup(struct tty_port *port) in tty_port_hangup() argument
238 spin_lock_irqsave(&port->lock, flags); in tty_port_hangup()
239 port->count = 0; in tty_port_hangup()
240 port->flags &= ~ASYNC_NORMAL_ACTIVE; in tty_port_hangup()
241 tty = port->tty; in tty_port_hangup()
244 port->tty = NULL; in tty_port_hangup()
245 spin_unlock_irqrestore(&port->lock, flags); in tty_port_hangup()
246 tty_port_shutdown(port, tty); in tty_port_hangup()
248 wake_up_interruptible(&port->open_wait); in tty_port_hangup()
249 wake_up_interruptible(&port->delta_msr_wait); in tty_port_hangup()
259 void tty_port_tty_hangup(struct tty_port *port, bool check_clocal) in tty_port_tty_hangup() argument
261 struct tty_struct *tty = tty_port_tty_get(port); in tty_port_tty_hangup()
274 void tty_port_tty_wakeup(struct tty_port *port) in tty_port_tty_wakeup() argument
276 struct tty_struct *tty = tty_port_tty_get(port); in tty_port_tty_wakeup()
294 int tty_port_carrier_raised(struct tty_port *port) in tty_port_carrier_raised() argument
296 if (port->ops->carrier_raised == NULL) in tty_port_carrier_raised()
298 return port->ops->carrier_raised(port); in tty_port_carrier_raised()
311 void tty_port_raise_dtr_rts(struct tty_port *port) in tty_port_raise_dtr_rts() argument
313 if (port->ops->dtr_rts) in tty_port_raise_dtr_rts()
314 port->ops->dtr_rts(port, 1); in tty_port_raise_dtr_rts()
327 void tty_port_lower_dtr_rts(struct tty_port *port) in tty_port_lower_dtr_rts() argument
329 if (port->ops->dtr_rts) in tty_port_lower_dtr_rts()
330 port->ops->dtr_rts(port, 0); in tty_port_lower_dtr_rts()
359 int tty_port_block_til_ready(struct tty_port *port, in tty_port_block_til_ready() argument
367 if (port->flags & ASYNC_CLOSING) { in tty_port_block_til_ready()
368 wait_event_interruptible_tty(tty, port->close_wait, in tty_port_block_til_ready()
369 !(port->flags & ASYNC_CLOSING)); in tty_port_block_til_ready()
370 if (port->flags & ASYNC_HUP_NOTIFY) in tty_port_block_til_ready()
379 port->flags |= ASYNC_NORMAL_ACTIVE; in tty_port_block_til_ready()
385 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
386 port->flags |= ASYNC_NORMAL_ACTIVE; in tty_port_block_til_ready()
400 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
401 port->count--; in tty_port_block_til_ready()
402 port->blocked_open++; in tty_port_block_til_ready()
403 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
407 if (C_BAUD(tty) && test_bit(ASYNCB_INITIALIZED, &port->flags)) in tty_port_block_til_ready()
408 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
410 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); in tty_port_block_til_ready()
413 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { in tty_port_block_til_ready()
414 if (port->flags & ASYNC_HUP_NOTIFY) in tty_port_block_til_ready()
426 if (!(port->flags & ASYNC_CLOSING) && in tty_port_block_til_ready()
427 (do_clocal || tty_port_carrier_raised(port))) in tty_port_block_til_ready()
437 finish_wait(&port->open_wait, &wait); in tty_port_block_til_ready()
441 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
443 port->count++; in tty_port_block_til_ready()
444 port->blocked_open--; in tty_port_block_til_ready()
446 port->flags |= ASYNC_NORMAL_ACTIVE; in tty_port_block_til_ready()
447 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
452 static void tty_port_drain_delay(struct tty_port *port, struct tty_struct *tty) in tty_port_drain_delay() argument
458 timeout = (HZ * 10 * port->drain_delay) / bps; in tty_port_drain_delay()
470 int tty_port_close_start(struct tty_port *port, in tty_port_close_start() argument
478 spin_lock_irqsave(&port->lock, flags); in tty_port_close_start()
479 if (tty->count == 1 && port->count != 1) { in tty_port_close_start()
482 port->count); in tty_port_close_start()
483 port->count = 1; in tty_port_close_start()
485 if (--port->count < 0) { in tty_port_close_start()
487 port->count); in tty_port_close_start()
488 port->count = 0; in tty_port_close_start()
491 if (port->count) { in tty_port_close_start()
492 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
495 set_bit(ASYNCB_CLOSING, &port->flags); in tty_port_close_start()
496 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
500 if (test_bit(ASYNCB_INITIALIZED, &port->flags)) { in tty_port_close_start()
504 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) in tty_port_close_start()
505 tty_wait_until_sent_from_close(tty, port->closing_wait); in tty_port_close_start()
506 if (port->drain_delay) in tty_port_close_start()
507 tty_port_drain_delay(port, tty); in tty_port_close_start()
518 void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) in tty_port_close_end() argument
525 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
527 if (port->blocked_open) { in tty_port_close_end()
528 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
529 if (port->close_delay) { in tty_port_close_end()
531 jiffies_to_msecs(port->close_delay)); in tty_port_close_end()
533 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
534 wake_up_interruptible(&port->open_wait); in tty_port_close_end()
536 port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); in tty_port_close_end()
537 wake_up_interruptible(&port->close_wait); in tty_port_close_end()
538 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
551 void tty_port_close(struct tty_port *port, struct tty_struct *tty, in tty_port_close() argument
554 if (tty_port_close_start(port, tty, filp) == 0) in tty_port_close()
556 tty_port_shutdown(port, tty); in tty_port_close()
558 tty_port_close_end(port, tty); in tty_port_close()
559 tty_port_tty_set(port, NULL); in tty_port_close()
573 int tty_port_install(struct tty_port *port, struct tty_driver *driver, in tty_port_install() argument
576 tty->port = port; in tty_port_install()
589 int tty_port_open(struct tty_port *port, struct tty_struct *tty, in tty_port_open() argument
592 spin_lock_irq(&port->lock); in tty_port_open()
593 ++port->count; in tty_port_open()
594 spin_unlock_irq(&port->lock); in tty_port_open()
595 tty_port_tty_set(port, tty); in tty_port_open()
603 mutex_lock(&port->mutex); in tty_port_open()
605 if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) { in tty_port_open()
607 if (port->ops->activate) { in tty_port_open()
608 int retval = port->ops->activate(port, tty); in tty_port_open()
610 mutex_unlock(&port->mutex); in tty_port_open()
614 set_bit(ASYNCB_INITIALIZED, &port->flags); in tty_port_open()
616 mutex_unlock(&port->mutex); in tty_port_open()
617 return tty_port_block_til_ready(port, tty, filp); in tty_port_open()