Lines Matching refs:port

22 static int tty_port_default_receive_buf(struct tty_port *port,  in tty_port_default_receive_buf()  argument
30 tty = READ_ONCE(port->itty); in tty_port_default_receive_buf()
45 static void tty_port_default_wakeup(struct tty_port *port) in tty_port_default_wakeup() argument
47 struct tty_struct *tty = tty_port_tty_get(port); in tty_port_default_wakeup()
60 void tty_port_init(struct tty_port *port) in tty_port_init() argument
62 memset(port, 0, sizeof(*port)); in tty_port_init()
63 tty_buffer_init(port); in tty_port_init()
64 init_waitqueue_head(&port->open_wait); in tty_port_init()
65 init_waitqueue_head(&port->delta_msr_wait); in tty_port_init()
66 mutex_init(&port->mutex); in tty_port_init()
67 mutex_init(&port->buf_mutex); in tty_port_init()
68 spin_lock_init(&port->lock); in tty_port_init()
69 port->close_delay = (50 * HZ) / 100; in tty_port_init()
70 port->closing_wait = (3000 * HZ) / 100; in tty_port_init()
71 port->client_ops = &default_client_ops; in tty_port_init()
72 kref_init(&port->kref); in tty_port_init()
87 void tty_port_link_device(struct tty_port *port, in tty_port_link_device() argument
92 driver->ports[index] = port; in tty_port_link_device()
107 struct device *tty_port_register_device(struct tty_port *port, in tty_port_register_device() argument
111 return tty_port_register_device_attr(port, driver, index, device, NULL, NULL); in tty_port_register_device()
128 struct device *tty_port_register_device_attr(struct tty_port *port, in tty_port_register_device_attr() argument
133 tty_port_link_device(port, driver, index); in tty_port_register_device_attr()
151 struct device *tty_port_register_device_attr_serdev(struct tty_port *port, in tty_port_register_device_attr_serdev() argument
158 tty_port_link_device(port, driver, index); in tty_port_register_device_attr_serdev()
160 dev = serdev_tty_port_register(port, device, driver, index); in tty_port_register_device_attr_serdev()
181 struct device *tty_port_register_device_serdev(struct tty_port *port, in tty_port_register_device_serdev() argument
185 return tty_port_register_device_attr_serdev(port, driver, index, in tty_port_register_device_serdev()
200 void tty_port_unregister_device(struct tty_port *port, in tty_port_unregister_device() argument
205 ret = serdev_tty_port_unregister(port); in tty_port_unregister_device()
213 int tty_port_alloc_xmit_buf(struct tty_port *port) in tty_port_alloc_xmit_buf() argument
216 mutex_lock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
217 if (port->xmit_buf == NULL) in tty_port_alloc_xmit_buf()
218 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL); in tty_port_alloc_xmit_buf()
219 mutex_unlock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
220 if (port->xmit_buf == NULL) in tty_port_alloc_xmit_buf()
226 void tty_port_free_xmit_buf(struct tty_port *port) in tty_port_free_xmit_buf() argument
228 mutex_lock(&port->buf_mutex); in tty_port_free_xmit_buf()
229 if (port->xmit_buf != NULL) { in tty_port_free_xmit_buf()
230 free_page((unsigned long)port->xmit_buf); in tty_port_free_xmit_buf()
231 port->xmit_buf = NULL; in tty_port_free_xmit_buf()
233 mutex_unlock(&port->buf_mutex); in tty_port_free_xmit_buf()
245 void tty_port_destroy(struct tty_port *port) in tty_port_destroy() argument
247 tty_buffer_cancel_work(port); in tty_port_destroy()
248 tty_buffer_free_all(port); in tty_port_destroy()
254 struct tty_port *port = container_of(kref, struct tty_port, kref); in tty_port_destructor() local
257 if (WARN_ON(port->itty)) in tty_port_destructor()
259 if (port->xmit_buf) in tty_port_destructor()
260 free_page((unsigned long)port->xmit_buf); in tty_port_destructor()
261 tty_port_destroy(port); in tty_port_destructor()
262 if (port->ops && port->ops->destruct) in tty_port_destructor()
263 port->ops->destruct(port); in tty_port_destructor()
265 kfree(port); in tty_port_destructor()
268 void tty_port_put(struct tty_port *port) in tty_port_put() argument
270 if (port) in tty_port_put()
271 kref_put(&port->kref, tty_port_destructor); in tty_port_put()
282 struct tty_struct *tty_port_tty_get(struct tty_port *port) in tty_port_tty_get() argument
287 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_get()
288 tty = tty_kref_get(port->tty); in tty_port_tty_get()
289 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_get()
302 void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) in tty_port_tty_set() argument
306 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_set()
307 tty_kref_put(port->tty); in tty_port_tty_set()
308 port->tty = tty_kref_get(tty); in tty_port_tty_set()
309 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_set()
313 static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty) in tty_port_shutdown() argument
315 mutex_lock(&port->mutex); in tty_port_shutdown()
316 if (port->console) in tty_port_shutdown()
319 if (tty_port_initialized(port)) { in tty_port_shutdown()
320 tty_port_set_initialized(port, 0); in tty_port_shutdown()
326 tty_port_lower_dtr_rts(port); in tty_port_shutdown()
328 if (port->ops->shutdown) in tty_port_shutdown()
329 port->ops->shutdown(port); in tty_port_shutdown()
332 mutex_unlock(&port->mutex); in tty_port_shutdown()
344 void tty_port_hangup(struct tty_port *port) in tty_port_hangup() argument
349 spin_lock_irqsave(&port->lock, flags); in tty_port_hangup()
350 port->count = 0; in tty_port_hangup()
351 tty = port->tty; in tty_port_hangup()
354 port->tty = NULL; in tty_port_hangup()
355 spin_unlock_irqrestore(&port->lock, flags); in tty_port_hangup()
356 tty_port_set_active(port, 0); in tty_port_hangup()
357 tty_port_shutdown(port, tty); in tty_port_hangup()
359 wake_up_interruptible(&port->open_wait); in tty_port_hangup()
360 wake_up_interruptible(&port->delta_msr_wait); in tty_port_hangup()
370 void tty_port_tty_hangup(struct tty_port *port, bool check_clocal) in tty_port_tty_hangup() argument
372 struct tty_struct *tty = tty_port_tty_get(port); in tty_port_tty_hangup()
385 void tty_port_tty_wakeup(struct tty_port *port) in tty_port_tty_wakeup() argument
387 port->client_ops->write_wakeup(port); in tty_port_tty_wakeup()
399 int tty_port_carrier_raised(struct tty_port *port) in tty_port_carrier_raised() argument
401 if (port->ops->carrier_raised == NULL) in tty_port_carrier_raised()
403 return port->ops->carrier_raised(port); in tty_port_carrier_raised()
415 void tty_port_raise_dtr_rts(struct tty_port *port) in tty_port_raise_dtr_rts() argument
417 if (port->ops->dtr_rts) in tty_port_raise_dtr_rts()
418 port->ops->dtr_rts(port, 1); in tty_port_raise_dtr_rts()
430 void tty_port_lower_dtr_rts(struct tty_port *port) in tty_port_lower_dtr_rts() argument
432 if (port->ops->dtr_rts) in tty_port_lower_dtr_rts()
433 port->ops->dtr_rts(port, 0); in tty_port_lower_dtr_rts()
461 int tty_port_block_til_ready(struct tty_port *port, in tty_port_block_til_ready() argument
471 tty_port_set_active(port, 1); in tty_port_block_til_ready()
477 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
478 tty_port_set_active(port, 1); in tty_port_block_til_ready()
492 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
493 port->count--; in tty_port_block_til_ready()
494 port->blocked_open++; in tty_port_block_til_ready()
495 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
499 if (C_BAUD(tty) && tty_port_initialized(port)) in tty_port_block_til_ready()
500 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
502 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); in tty_port_block_til_ready()
505 if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { in tty_port_block_til_ready()
506 if (port->flags & ASYNC_HUP_NOTIFY) in tty_port_block_til_ready()
518 if (do_clocal || tty_port_carrier_raised(port)) in tty_port_block_til_ready()
528 finish_wait(&port->open_wait, &wait); in tty_port_block_til_ready()
532 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
534 port->count++; in tty_port_block_til_ready()
535 port->blocked_open--; in tty_port_block_til_ready()
536 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
538 tty_port_set_active(port, 1); in tty_port_block_til_ready()
543 static void tty_port_drain_delay(struct tty_port *port, struct tty_struct *tty) in tty_port_drain_delay() argument
549 timeout = (HZ * 10 * port->drain_delay) / bps; in tty_port_drain_delay()
558 int tty_port_close_start(struct tty_port *port, in tty_port_close_start() argument
566 spin_lock_irqsave(&port->lock, flags); in tty_port_close_start()
567 if (tty->count == 1 && port->count != 1) { in tty_port_close_start()
569 port->count); in tty_port_close_start()
570 port->count = 1; in tty_port_close_start()
572 if (--port->count < 0) { in tty_port_close_start()
574 port->count); in tty_port_close_start()
575 port->count = 0; in tty_port_close_start()
578 if (port->count) { in tty_port_close_start()
579 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
582 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
586 if (tty_port_initialized(port)) { in tty_port_close_start()
590 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) in tty_port_close_start()
591 tty_wait_until_sent(tty, port->closing_wait); in tty_port_close_start()
592 if (port->drain_delay) in tty_port_close_start()
593 tty_port_drain_delay(port, tty); in tty_port_close_start()
604 void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) in tty_port_close_end() argument
611 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
613 if (port->blocked_open) { in tty_port_close_end()
614 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
615 if (port->close_delay) in tty_port_close_end()
616 msleep_interruptible(jiffies_to_msecs(port->close_delay)); in tty_port_close_end()
617 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
618 wake_up_interruptible(&port->open_wait); in tty_port_close_end()
620 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
621 tty_port_set_active(port, 0); in tty_port_close_end()
630 void tty_port_close(struct tty_port *port, struct tty_struct *tty, in tty_port_close() argument
633 if (tty_port_close_start(port, tty, filp) == 0) in tty_port_close()
635 tty_port_shutdown(port, tty); in tty_port_close()
636 if (!port->console) in tty_port_close()
638 tty_port_close_end(port, tty); in tty_port_close()
639 tty_port_tty_set(port, NULL); in tty_port_close()
653 int tty_port_install(struct tty_port *port, struct tty_driver *driver, in tty_port_install() argument
656 tty->port = port; in tty_port_install()
669 int tty_port_open(struct tty_port *port, struct tty_struct *tty, in tty_port_open() argument
672 spin_lock_irq(&port->lock); in tty_port_open()
673 ++port->count; in tty_port_open()
674 spin_unlock_irq(&port->lock); in tty_port_open()
675 tty_port_tty_set(port, tty); in tty_port_open()
683 mutex_lock(&port->mutex); in tty_port_open()
685 if (!tty_port_initialized(port)) { in tty_port_open()
687 if (port->ops->activate) { in tty_port_open()
688 int retval = port->ops->activate(port, tty); in tty_port_open()
690 mutex_unlock(&port->mutex); in tty_port_open()
694 tty_port_set_initialized(port, 1); in tty_port_open()
696 mutex_unlock(&port->mutex); in tty_port_open()
697 return tty_port_block_til_ready(port, tty, filp); in tty_port_open()