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()
283 struct tty_struct *tty_port_tty_get(struct tty_port *port) in tty_port_tty_get() argument
288 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_get()
289 tty = tty_kref_get(port->tty); in tty_port_tty_get()
290 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_get()
304 void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) in tty_port_tty_set() argument
308 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_set()
309 tty_kref_put(port->tty); in tty_port_tty_set()
310 port->tty = tty_kref_get(tty); in tty_port_tty_set()
311 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_set()
315 static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty) in tty_port_shutdown() argument
317 mutex_lock(&port->mutex); in tty_port_shutdown()
318 if (port->console) in tty_port_shutdown()
321 if (tty_port_initialized(port)) { in tty_port_shutdown()
322 tty_port_set_initialized(port, 0); in tty_port_shutdown()
328 tty_port_lower_dtr_rts(port); in tty_port_shutdown()
330 if (port->ops->shutdown) in tty_port_shutdown()
331 port->ops->shutdown(port); in tty_port_shutdown()
334 mutex_unlock(&port->mutex); in tty_port_shutdown()
347 void tty_port_hangup(struct tty_port *port) in tty_port_hangup() argument
352 spin_lock_irqsave(&port->lock, flags); in tty_port_hangup()
353 port->count = 0; in tty_port_hangup()
354 tty = port->tty; in tty_port_hangup()
357 port->tty = NULL; in tty_port_hangup()
358 spin_unlock_irqrestore(&port->lock, flags); in tty_port_hangup()
359 tty_port_set_active(port, 0); in tty_port_hangup()
360 tty_port_shutdown(port, tty); in tty_port_hangup()
362 wake_up_interruptible(&port->open_wait); in tty_port_hangup()
363 wake_up_interruptible(&port->delta_msr_wait); in tty_port_hangup()
373 void tty_port_tty_hangup(struct tty_port *port, bool check_clocal) in tty_port_tty_hangup() argument
375 struct tty_struct *tty = tty_port_tty_get(port); in tty_port_tty_hangup()
388 void tty_port_tty_wakeup(struct tty_port *port) in tty_port_tty_wakeup() argument
390 port->client_ops->write_wakeup(port); in tty_port_tty_wakeup()
403 int tty_port_carrier_raised(struct tty_port *port) in tty_port_carrier_raised() argument
405 if (port->ops->carrier_raised == NULL) in tty_port_carrier_raised()
407 return port->ops->carrier_raised(port); in tty_port_carrier_raised()
420 void tty_port_raise_dtr_rts(struct tty_port *port) in tty_port_raise_dtr_rts() argument
422 if (port->ops->dtr_rts) in tty_port_raise_dtr_rts()
423 port->ops->dtr_rts(port, 1); in tty_port_raise_dtr_rts()
436 void tty_port_lower_dtr_rts(struct tty_port *port) in tty_port_lower_dtr_rts() argument
438 if (port->ops->dtr_rts) in tty_port_lower_dtr_rts()
439 port->ops->dtr_rts(port, 0); in tty_port_lower_dtr_rts()
468 int tty_port_block_til_ready(struct tty_port *port, in tty_port_block_til_ready() argument
478 tty_port_set_active(port, 1); in tty_port_block_til_ready()
484 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
485 tty_port_set_active(port, 1); in tty_port_block_til_ready()
499 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
500 port->count--; in tty_port_block_til_ready()
501 port->blocked_open++; in tty_port_block_til_ready()
502 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
506 if (C_BAUD(tty) && tty_port_initialized(port)) in tty_port_block_til_ready()
507 tty_port_raise_dtr_rts(port); in tty_port_block_til_ready()
509 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); in tty_port_block_til_ready()
512 if (tty_hung_up_p(filp) || !tty_port_initialized(port)) { in tty_port_block_til_ready()
513 if (port->flags & ASYNC_HUP_NOTIFY) in tty_port_block_til_ready()
525 if (do_clocal || tty_port_carrier_raised(port)) in tty_port_block_til_ready()
535 finish_wait(&port->open_wait, &wait); in tty_port_block_til_ready()
539 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
541 port->count++; in tty_port_block_til_ready()
542 port->blocked_open--; in tty_port_block_til_ready()
543 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
545 tty_port_set_active(port, 1); in tty_port_block_til_ready()
550 static void tty_port_drain_delay(struct tty_port *port, struct tty_struct *tty) in tty_port_drain_delay() argument
556 timeout = (HZ * 10 * port->drain_delay) / bps; in tty_port_drain_delay()
565 int tty_port_close_start(struct tty_port *port, in tty_port_close_start() argument
573 spin_lock_irqsave(&port->lock, flags); in tty_port_close_start()
574 if (tty->count == 1 && port->count != 1) { in tty_port_close_start()
576 port->count); in tty_port_close_start()
577 port->count = 1; in tty_port_close_start()
579 if (--port->count < 0) { in tty_port_close_start()
581 port->count); in tty_port_close_start()
582 port->count = 0; in tty_port_close_start()
585 if (port->count) { in tty_port_close_start()
586 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
589 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
593 if (tty_port_initialized(port)) { in tty_port_close_start()
597 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) in tty_port_close_start()
598 tty_wait_until_sent(tty, port->closing_wait); in tty_port_close_start()
599 if (port->drain_delay) in tty_port_close_start()
600 tty_port_drain_delay(port, tty); in tty_port_close_start()
611 void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) in tty_port_close_end() argument
618 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
620 if (port->blocked_open) { in tty_port_close_end()
621 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
622 if (port->close_delay) in tty_port_close_end()
623 msleep_interruptible(jiffies_to_msecs(port->close_delay)); in tty_port_close_end()
624 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
625 wake_up_interruptible(&port->open_wait); in tty_port_close_end()
627 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
628 tty_port_set_active(port, 0); in tty_port_close_end()
637 void tty_port_close(struct tty_port *port, struct tty_struct *tty, in tty_port_close() argument
640 if (tty_port_close_start(port, tty, filp) == 0) in tty_port_close()
642 tty_port_shutdown(port, tty); in tty_port_close()
644 tty_port_close_end(port, tty); in tty_port_close()
645 tty_port_tty_set(port, NULL); in tty_port_close()
659 int tty_port_install(struct tty_port *port, struct tty_driver *driver, in tty_port_install() argument
662 tty->port = port; in tty_port_install()
675 int tty_port_open(struct tty_port *port, struct tty_struct *tty, in tty_port_open() argument
678 spin_lock_irq(&port->lock); in tty_port_open()
679 ++port->count; in tty_port_open()
680 spin_unlock_irq(&port->lock); in tty_port_open()
681 tty_port_tty_set(port, tty); in tty_port_open()
689 mutex_lock(&port->mutex); in tty_port_open()
691 if (!tty_port_initialized(port)) { in tty_port_open()
693 if (port->ops->activate) { in tty_port_open()
694 int retval = port->ops->activate(port, tty); in tty_port_open()
696 mutex_unlock(&port->mutex); in tty_port_open()
700 tty_port_set_initialized(port, 1); in tty_port_open()
702 mutex_unlock(&port->mutex); in tty_port_open()
703 return tty_port_block_til_ready(port, tty, filp); in tty_port_open()