Lines Matching full:tty
3 * Tty port functions
8 #include <linux/tty.h>
21 #include "tty.h"
26 struct tty_struct *tty; in tty_port_default_receive_buf() local
29 tty = READ_ONCE(port->itty); in tty_port_default_receive_buf()
30 if (!tty) in tty_port_default_receive_buf()
33 ld = tty_ldisc_ref(tty); in tty_port_default_receive_buf()
47 struct tty_struct *tty; in tty_port_default_lookahead_buf() local
50 tty = READ_ONCE(port->itty); in tty_port_default_lookahead_buf()
51 if (!tty) in tty_port_default_lookahead_buf()
54 ld = tty_ldisc_ref(tty); in tty_port_default_lookahead_buf()
59 ld->ops->lookahead_buf(ld->tty, p, f, count); in tty_port_default_lookahead_buf()
103 * tty_port_link_device - link tty and tty_port
106 * @index: index of the tty
108 * Provide the tty layer with a link from a tty (specified by @index) to a
123 * tty_port_register_device - register tty device
126 * @index: index of the tty
130 * to a concrete tty specified by @index. Use this or tty_port_install() (or
142 * tty_port_register_device_attr - register tty device
145 * @index: index of the tty
151 * linked to a concrete tty specified by @index. Use this or tty_port_install()
166 * tty_port_register_device_attr_serdev - register tty or serdev device
169 * @index: index of the tty
175 * Register a serdev or tty device depending on if the parent device has any
199 * tty_port_unregister_device - deregister a tty or serdev device
202 * @index: index of the tty
204 * If a tty or serdev device is registered with a call to
250 * @port: tty port to be destroyed
267 /* check if last port ref was dropped before tty release */ in tty_port_destructor()
293 * tty_port_tty_get - get a tty reference
294 * @port: tty port
296 * Return a refcount protected tty instance or %NULL if the port is not
297 * associated with a tty (eg due to close or hangup).
302 return tty_kref_get(port->tty); in tty_port_tty_get()
307 * tty_port_tty_set - set the tty of a port
308 * @port: tty port
309 * @tty: the tty
311 * Associate the port and tty pair. Manages any internal refcounts. Pass %NULL
314 void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty) in tty_port_tty_set() argument
317 tty_kref_put(port->tty); in tty_port_tty_set()
318 port->tty = tty_kref_get(tty); in tty_port_tty_set()
324 * @port: tty port to be shut down
325 * @tty: the associated tty
329 * functioning). It lowers DTR/RTS (if @tty has HUPCL set) and invokes
332 static void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty) in tty_port_shutdown() argument
347 if (tty && C_HUPCL(tty)) in tty_port_shutdown()
356 * @port: tty port
358 * Perform port level tty hangup flag and count changes. Drop the tty
361 * Caller holds tty lock.
365 struct tty_struct *tty; in tty_port_hangup() local
369 tty = port->tty; in tty_port_hangup()
370 if (tty) in tty_port_hangup()
371 set_bit(TTY_IO_ERROR, &tty->flags); in tty_port_hangup()
372 port->tty = NULL; in tty_port_hangup()
376 tty_port_shutdown(port, tty); in tty_port_hangup()
377 tty_kref_put(tty); in tty_port_hangup()
386 struct tty_struct *tty = scoped_tty(); in __tty_port_tty_hangup() local
388 if (!check_clocal || !C_CLOCAL(tty)) { in __tty_port_tty_hangup()
390 tty_hangup(tty); in __tty_port_tty_hangup()
392 tty_vhangup(tty); in __tty_port_tty_hangup()
399 * tty_port_tty_wakeup - helper to wake up a tty
400 * @port: tty port
410 * @port: tty port
414 * internal to the tty port.
426 * @port: tty port
430 * tty port.
441 * @port: tty port
445 * tty port.
455 * tty_port_block_til_ready - Waiting logic for tty open
456 * @port: the tty port being opened
457 * @tty: the tty device being bound
460 * Implement the core POSIX/SuS tty behaviour when opening a tty device.
474 * Caller holds tty lock.
476 * Note: May drop and reacquire tty lock when blocking, so @tty and @port may
480 struct tty_struct *tty, struct file *filp) in tty_port_block_til_ready() argument
488 if (tty_io_error(tty)) { in tty_port_block_til_ready()
494 if (C_BAUD(tty)) in tty_port_block_til_ready()
500 if (C_CLOCAL(tty)) in tty_port_block_til_ready()
518 if (C_BAUD(tty) && tty_port_initialized(port)) in tty_port_block_til_ready()
544 tty_unlock(tty); in tty_port_block_til_ready()
546 tty_lock(tty); in tty_port_block_til_ready()
564 static void tty_port_drain_delay(struct tty_port *port, struct tty_struct *tty) in tty_port_drain_delay() argument
566 unsigned int bps = tty_get_baud_rate(tty); in tty_port_drain_delay()
579 * tty_port_close_start - helper for tty->ops->close, part 1/2
581 * @tty: tty being closed
589 * Locking: Caller holds tty lock.
594 struct tty_struct *tty, struct file *filp) in tty_port_close_start() argument
600 if (tty->count == 1 && port->count != 1) { in tty_port_close_start()
601 tty_warn(tty, "%s: tty->count = 1 port count = %d\n", __func__, in tty_port_close_start()
606 tty_warn(tty, "%s: bad port count (%d)\n", __func__, in tty_port_close_start()
615 tty->closing = 1; in tty_port_close_start()
619 if (tty->flow.tco_stopped) in tty_port_close_start()
620 tty_driver_flush_buffer(tty); in tty_port_close_start()
622 tty_wait_until_sent(tty, port->closing_wait); in tty_port_close_start()
624 tty_port_drain_delay(port, tty); in tty_port_close_start()
627 tty_ldisc_flush(tty); in tty_port_close_start()
635 * tty_port_close_end - helper for tty->ops->close, part 2/2
637 * @tty: tty being closed
643 * Locking: Caller holds tty lock.
645 void tty_port_close_end(struct tty_port *port, struct tty_struct *tty) in tty_port_close_end() argument
649 tty_ldisc_flush(tty); in tty_port_close_end()
650 tty->closing = 0; in tty_port_close_end()
667 * tty_port_close - generic tty->ops->close handler
669 * @tty: tty being closed
672 * It is a generic helper to be used in driver's @tty->ops->close. It wraps a
677 * Locking: Caller holds tty lock
679 void tty_port_close(struct tty_port *port, struct tty_struct *tty, in tty_port_close() argument
682 if (tty_port_close_start(port, tty, filp) == 0) in tty_port_close()
684 tty_port_shutdown(port, tty); in tty_port_close()
686 set_bit(TTY_IO_ERROR, &tty->flags); in tty_port_close()
687 tty_port_close_end(port, tty); in tty_port_close()
693 * tty_port_install - generic tty->ops->install handler
696 * @tty: tty to be installed
699 * to a concrete tty specified by @tty. Use this or tty_port_register_device()
703 struct tty_struct *tty) in tty_port_install() argument
705 tty->port = port; in tty_port_install()
706 return tty_standard_install(driver, tty); in tty_port_install()
711 * tty_port_open - generic tty->ops->open handler
713 * @tty: tty to be opened
716 * It is a generic helper to be used in driver's @tty->ops->open. It activates
722 * returns an error (on the contrary, @tty->ops->close is).
724 * Locking: Caller holds tty lock.
726 * Note: may drop and reacquire tty lock (in tty_port_block_til_ready()) so
727 * @tty and @port may have changed state (eg., may be hung up now).
729 int tty_port_open(struct tty_port *port, struct tty_struct *tty, in tty_port_open() argument
734 tty_port_tty_set(port, tty); in tty_port_open()
745 clear_bit(TTY_IO_ERROR, &tty->flags); in tty_port_open()
747 int retval = port->ops->activate(port, tty); in tty_port_open()
753 return tty_port_block_til_ready(port, tty, filp); in tty_port_open()