Lines Matching refs:port
23 static int tty_port_default_receive_buf(struct tty_port *port, in tty_port_default_receive_buf() argument
31 tty = READ_ONCE(port->itty); in tty_port_default_receive_buf()
46 static void tty_port_default_lookahead_buf(struct tty_port *port, const unsigned char *p, in tty_port_default_lookahead_buf() argument
52 tty = READ_ONCE(port->itty); in tty_port_default_lookahead_buf()
66 static void tty_port_default_wakeup(struct tty_port *port) in tty_port_default_wakeup() argument
68 struct tty_struct *tty = tty_port_tty_get(port); in tty_port_default_wakeup()
92 void tty_port_init(struct tty_port *port) in tty_port_init() argument
94 memset(port, 0, sizeof(*port)); in tty_port_init()
95 tty_buffer_init(port); in tty_port_init()
96 init_waitqueue_head(&port->open_wait); in tty_port_init()
97 init_waitqueue_head(&port->delta_msr_wait); in tty_port_init()
98 mutex_init(&port->mutex); in tty_port_init()
99 mutex_init(&port->buf_mutex); in tty_port_init()
100 spin_lock_init(&port->lock); in tty_port_init()
101 port->close_delay = (50 * HZ) / 100; in tty_port_init()
102 port->closing_wait = (3000 * HZ) / 100; in tty_port_init()
103 port->client_ops = &tty_port_default_client_ops; in tty_port_init()
104 kref_init(&port->kref); in tty_port_init()
119 void tty_port_link_device(struct tty_port *port, in tty_port_link_device() argument
124 driver->ports[index] = port; in tty_port_link_device()
139 struct device *tty_port_register_device(struct tty_port *port, in tty_port_register_device() argument
143 return tty_port_register_device_attr(port, driver, index, device, NULL, NULL); in tty_port_register_device()
160 struct device *tty_port_register_device_attr(struct tty_port *port, in tty_port_register_device_attr() argument
165 tty_port_link_device(port, driver, index); in tty_port_register_device_attr()
183 struct device *tty_port_register_device_attr_serdev(struct tty_port *port, in tty_port_register_device_attr_serdev() argument
190 tty_port_link_device(port, driver, index); in tty_port_register_device_attr_serdev()
192 dev = serdev_tty_port_register(port, device, driver, index); in tty_port_register_device_attr_serdev()
213 struct device *tty_port_register_device_serdev(struct tty_port *port, in tty_port_register_device_serdev() argument
217 return tty_port_register_device_attr_serdev(port, driver, index, in tty_port_register_device_serdev()
232 void tty_port_unregister_device(struct tty_port *port, in tty_port_unregister_device() argument
237 ret = serdev_tty_port_unregister(port); in tty_port_unregister_device()
245 int tty_port_alloc_xmit_buf(struct tty_port *port) in tty_port_alloc_xmit_buf() argument
248 mutex_lock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
249 if (port->xmit_buf == NULL) { in tty_port_alloc_xmit_buf()
250 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); in tty_port_alloc_xmit_buf()
251 if (port->xmit_buf) in tty_port_alloc_xmit_buf()
252 kfifo_init(&port->xmit_fifo, port->xmit_buf, PAGE_SIZE); in tty_port_alloc_xmit_buf()
254 mutex_unlock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
255 if (port->xmit_buf == NULL) in tty_port_alloc_xmit_buf()
261 void tty_port_free_xmit_buf(struct tty_port *port) in tty_port_free_xmit_buf() argument
263 mutex_lock(&port->buf_mutex); in tty_port_free_xmit_buf()
264 free_page((unsigned long)port->xmit_buf); in tty_port_free_xmit_buf()
265 port->xmit_buf = NULL; in tty_port_free_xmit_buf()
266 INIT_KFIFO(port->xmit_fifo); in tty_port_free_xmit_buf()
267 mutex_unlock(&port->buf_mutex); in tty_port_free_xmit_buf()
279 void tty_port_destroy(struct tty_port *port) in tty_port_destroy() argument
281 tty_buffer_cancel_work(port); in tty_port_destroy()
282 tty_buffer_free_all(port); in tty_port_destroy()
288 struct tty_port *port = container_of(kref, struct tty_port, kref); in tty_port_destructor() local
291 if (WARN_ON(port->itty)) in tty_port_destructor()
293 free_page((unsigned long)port->xmit_buf); in tty_port_destructor()
294 tty_port_destroy(port); in tty_port_destructor()
295 if (port->ops && port->ops->destruct) in tty_port_destructor()
296 port->ops->destruct(port); in tty_port_destructor()
298 kfree(port); in tty_port_destructor()
308 void tty_port_put(struct tty_port *port) in tty_port_put() argument
310 if (port) in tty_port_put()
311 kref_put(&port->kref, tty_port_destructor); in tty_port_put()
322 struct tty_struct *tty_port_tty_get(struct tty_port *port) in tty_port_tty_get() argument
327 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_get()
328 tty = tty_kref_get(port->tty); in tty_port_tty_get()
329 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_get()
342 void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) in tty_port_tty_set() argument
346 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_set()
347 tty_kref_put(port->tty); in tty_port_tty_set()
348 port->tty = tty_kref_get(tty); in tty_port_tty_set()
349 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_set()
363 static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty) in tty_port_shutdown() argument
365 mutex_lock(&port->mutex); in tty_port_shutdown()
366 if (port->console) in tty_port_shutdown()
369 if (tty_port_initialized(port)) { in tty_port_shutdown()
370 tty_port_set_initialized(port, 0); in tty_port_shutdown()
376 tty_port_lower_dtr_rts(port); in tty_port_shutdown()
378 if (port->ops->shutdown) in tty_port_shutdown()
379 port->ops->shutdown(port); in tty_port_shutdown()
382 mutex_unlock(&port->mutex); in tty_port_shutdown()
394 void tty_port_hangup(struct tty_port *port) in tty_port_hangup() argument
399 spin_lock_irqsave(&port->lock, flags); in tty_port_hangup()
400 port->count = 0; in tty_port_hangup()
401 tty = port->tty; in tty_port_hangup()
404 port->tty = NULL; in tty_port_hangup()
405 spin_unlock_irqrestore(&port->lock, flags); in tty_port_hangup()
406 tty_port_set_active(port, 0); in tty_port_hangup()
407 tty_port_shutdown(port, tty); in tty_port_hangup()
409 wake_up_interruptible(&port->open_wait); in tty_port_hangup()
410 wake_up_interruptible(&port->delta_msr_wait); in tty_port_hangup()
419 void tty_port_tty_hangup(struct tty_port *port, bool check_clocal) in tty_port_tty_hangup() argument
421 struct tty_struct *tty = tty_port_tty_get(port); in tty_port_tty_hangup()
433 void tty_port_tty_wakeup(struct tty_port *port) in tty_port_tty_wakeup() argument
435 port->client_ops->write_wakeup(port); in tty_port_tty_wakeup()
447 int tty_port_carrier_raised(struct tty_port *port) in tty_port_carrier_raised() argument
449 if (port->ops->carrier_raised == NULL) in tty_port_carrier_raised()
451 return port->ops->carrier_raised(port); in tty_port_carrier_raised()
463 void tty_port_raise_dtr_rts(struct tty_port *port) in tty_port_raise_dtr_rts() argument
465 if (port->ops->dtr_rts) in tty_port_raise_dtr_rts()
466 port->ops->dtr_rts(port, 1); in tty_port_raise_dtr_rts()
478 void tty_port_lower_dtr_rts(struct tty_port *port) in tty_port_lower_dtr_rts() argument
480 if (port->ops->dtr_rts) in tty_port_lower_dtr_rts()
481 port->ops->dtr_rts(port, 0); in tty_port_lower_dtr_rts()
510 int tty_port_block_til_ready(struct tty_port *port, in tty_port_block_til_ready() argument
521 tty_port_set_active(port, 1); in tty_port_block_til_ready()
527 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
528 tty_port_set_active(port, 1); in tty_port_block_til_ready()
543 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
544 port->count--; in tty_port_block_til_ready()
545 port->blocked_open++; in tty_port_block_til_ready()
546 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
550 if (C_BAUD(tty) && tty_port_initialized(port)) in tty_port_block_til_ready()
551 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
553 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); in tty_port_block_til_ready()
557 if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { in tty_port_block_til_ready()
558 if (port->flags & ASYNC_HUP_NOTIFY) in tty_port_block_til_ready()
570 if (do_clocal || tty_port_carrier_raised(port)) in tty_port_block_til_ready()
580 finish_wait(&port->open_wait, &wait); in tty_port_block_til_ready()
585 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
587 port->count++; in tty_port_block_til_ready()
588 port->blocked_open--; in tty_port_block_til_ready()
589 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
591 tty_port_set_active(port, 1); in tty_port_block_til_ready()
596 static void tty_port_drain_delay(struct tty_port *port, struct tty_struct *tty) in tty_port_drain_delay() argument
602 timeout = (HZ * 10 * port->drain_delay) / bps; in tty_port_drain_delay()
625 int tty_port_close_start(struct tty_port *port, in tty_port_close_start() argument
633 spin_lock_irqsave(&port->lock, flags); in tty_port_close_start()
634 if (tty->count == 1 && port->count != 1) { in tty_port_close_start()
636 port->count); in tty_port_close_start()
637 port->count = 1; in tty_port_close_start()
639 if (--port->count < 0) { in tty_port_close_start()
641 port->count); in tty_port_close_start()
642 port->count = 0; in tty_port_close_start()
645 if (port->count) { in tty_port_close_start()
646 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
649 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
653 if (tty_port_initialized(port)) { in tty_port_close_start()
657 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) in tty_port_close_start()
658 tty_wait_until_sent(tty, port->closing_wait); in tty_port_close_start()
659 if (port->drain_delay) in tty_port_close_start()
660 tty_port_drain_delay(port, tty); in tty_port_close_start()
681 void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) in tty_port_close_end() argument
688 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
690 if (port->blocked_open) { in tty_port_close_end()
691 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
692 if (port->close_delay) in tty_port_close_end()
693 msleep_interruptible(jiffies_to_msecs(port->close_delay)); in tty_port_close_end()
694 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
695 wake_up_interruptible(&port->open_wait); in tty_port_close_end()
697 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
698 tty_port_set_active(port, 0); in tty_port_close_end()
715 void tty_port_close(struct tty_port *port, struct tty_struct *tty, in tty_port_close() argument
718 if (tty_port_close_start(port, tty, filp) == 0) in tty_port_close()
720 tty_port_shutdown(port, tty); in tty_port_close()
721 if (!port->console) in tty_port_close()
723 tty_port_close_end(port, tty); in tty_port_close()
724 tty_port_tty_set(port, NULL); in tty_port_close()
738 int tty_port_install(struct tty_port *port, struct tty_driver *driver, in tty_port_install() argument
741 tty->port = port; in tty_port_install()
765 int tty_port_open(struct tty_port *port, struct tty_struct *tty, in tty_port_open() argument
768 spin_lock_irq(&port->lock); in tty_port_open()
769 ++port->count; in tty_port_open()
770 spin_unlock_irq(&port->lock); in tty_port_open()
771 tty_port_tty_set(port, tty); in tty_port_open()
779 mutex_lock(&port->mutex); in tty_port_open()
781 if (!tty_port_initialized(port)) { in tty_port_open()
783 if (port->ops->activate) { in tty_port_open()
784 int retval = port->ops->activate(port, tty); in tty_port_open()
787 mutex_unlock(&port->mutex); in tty_port_open()
791 tty_port_set_initialized(port, 1); in tty_port_open()
793 mutex_unlock(&port->mutex); in tty_port_open()
794 return tty_port_block_til_ready(port, tty, filp); in tty_port_open()