Lines Matching full:port

3  * Tty port functions
23 static size_t tty_port_default_receive_buf(struct tty_port *port, const u8 *p, in tty_port_default_receive_buf() argument
29 tty = READ_ONCE(port->itty); in tty_port_default_receive_buf()
44 static void tty_port_default_lookahead_buf(struct tty_port *port, const u8 *p, in tty_port_default_lookahead_buf() argument
50 tty = READ_ONCE(port->itty); in tty_port_default_lookahead_buf()
64 static void tty_port_default_wakeup(struct tty_port *port) in tty_port_default_wakeup() argument
66 struct tty_struct *tty = tty_port_tty_get(port); in tty_port_default_wakeup()
83 * @port: tty_port to initialize
85 * Initializes the state of struct tty_port. When a port was initialized using
86 * this function, one has to destroy the port by tty_port_destroy(). Either
90 void tty_port_init(struct tty_port *port) in tty_port_init() argument
92 memset(port, 0, sizeof(*port)); in tty_port_init()
93 tty_buffer_init(port); in tty_port_init()
94 init_waitqueue_head(&port->open_wait); in tty_port_init()
95 init_waitqueue_head(&port->delta_msr_wait); in tty_port_init()
96 mutex_init(&port->mutex); in tty_port_init()
97 mutex_init(&port->buf_mutex); in tty_port_init()
98 spin_lock_init(&port->lock); in tty_port_init()
99 port->close_delay = (50 * HZ) / 100; in tty_port_init()
100 port->closing_wait = (3000 * HZ) / 100; in tty_port_init()
101 port->client_ops = &tty_port_default_client_ops; in tty_port_init()
102 kref_init(&port->kref); in tty_port_init()
108 * @port: tty_port of the device
113 * tty_port (@port). Use this only if neither tty_port_register_device() nor
117 void tty_port_link_device(struct tty_port *port, in tty_port_link_device() argument
122 driver->ports[index] = port; in tty_port_link_device()
128 * @port: tty_port of the device
133 * It is the same as tty_register_device() except the provided @port is linked
137 struct device *tty_port_register_device(struct tty_port *port, in tty_port_register_device() argument
141 return tty_port_register_device_attr(port, driver, index, device, NULL, NULL); in tty_port_register_device()
147 * @port: tty_port of the device
154 * It is the same as tty_register_device_attr() except the provided @port is
158 struct device *tty_port_register_device_attr(struct tty_port *port, in tty_port_register_device_attr() argument
163 tty_port_link_device(port, driver, index); in tty_port_register_device_attr()
171 * @port: tty_port of the device
174 * @host: serial port hardware device
182 struct device *tty_port_register_device_attr_serdev(struct tty_port *port, in tty_port_register_device_attr_serdev() argument
189 tty_port_link_device(port, driver, index); in tty_port_register_device_attr_serdev()
191 dev = serdev_tty_port_register(port, host, parent, driver, index); in tty_port_register_device_attr_serdev()
204 * @port: tty_port of the device
207 * @host: serial port hardware controller device
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()
224 * @port: tty_port of the device
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 = (u8 *)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()
272 * tty_port_destroy - destroy inited port
273 * @port: tty port to be destroyed
275 * When a port was initialized using tty_port_init(), one has to destroy the
276 * port by this function. Either indirectly by using &tty_port refcounting
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
290 /* check if last port ref was dropped before tty release */ in tty_port_destructor()
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()
303 * @port: port to drop a reference of (can be NULL)
305 * The final put will destroy and free up the @port using
306 * @port->ops->destruct() hook, or using kfree() if not provided.
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()
317 * @port: tty port
319 * Return a refcount protected tty instance or %NULL if the port is not
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()
335 * tty_port_tty_set - set the tty of a port
336 * @port: tty port
339 * Associate the port and tty pair. Manages any internal refcounts. Pass %NULL
340 * to deassociate a port.
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()
355 * @port: tty port to be shut down
361 * @port->ops->shutdown().
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, false); 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()
387 * @port: tty port
389 * Perform port level tty hangup flag and count changes. Drop the tty
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, false); 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()
416 * @port: tty port
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()
431 * @port: tty port
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()
441 * @port: tty port
445 * internal to the tty port.
447 bool 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()
457 * @port: tty port
461 * tty port.
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, true); in tty_port_raise_dtr_rts()
472 * @port: tty port
476 * tty port.
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, false); in tty_port_lower_dtr_rts()
487 * @port: the tty port being opened
498 * - port flags and counts
500 * The passed @port must implement the @port->ops->carrier_raised method if it
501 * can do carrier detect and the @port->ops->dtr_rts method if it supports
507 * Note: May drop and reacquire tty lock when blocking, so @tty and @port may
510 int tty_port_block_til_ready(struct tty_port *port, in tty_port_block_til_ready() argument
518 * the port has just hung up or is in another error state. in tty_port_block_til_ready()
521 tty_port_set_active(port, true); 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, true); in tty_port_block_til_ready()
542 /* The port lock protects the port counts */ 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()
554 /* Check for a hangup or uninitialised port. 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, true); 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()
612 * @port: tty_port of the device
616 * Decrements and checks open count. Flushes the port if this is the last
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()
635 tty_warn(tty, "%s: tty->count = 1 port count = %d\n", __func__, 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()
640 tty_warn(tty, "%s: bad port count (%d)\n", __func__, 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()
654 /* Don't block on a stalled port, just pull the chain */ 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()
665 /* Report to caller this is the last port reference */ in tty_port_close_start()
672 * @port: tty_port of the device
677 * line discipline and delays the close by @port->close_delay.
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, false); in tty_port_close_end()
704 * @port: tty_port of the device
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()
730 * @port: tty_port of the device
734 * It is the same as tty_standard_install() except the provided @port is linked
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()
748 * @port: tty_port of the device
753 * the devices using @port->ops->activate if not active already. And waits for
757 * Note that @port->ops->shutdown is not called when @port->ops->activate
763 * @tty and @port may have changed state (eg., may be hung up now).
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()
776 * port mutex. 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, true); 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()