Lines Matching refs:tty

48 unsigned int tty_chars_in_buffer(struct tty_struct *tty)  in tty_chars_in_buffer()  argument
50 if (tty->ops->chars_in_buffer) in tty_chars_in_buffer()
51 return tty->ops->chars_in_buffer(tty); in tty_chars_in_buffer()
66 unsigned int tty_write_room(struct tty_struct *tty) in tty_write_room() argument
68 if (tty->ops->write_room) in tty_write_room()
69 return tty->ops->write_room(tty); in tty_write_room()
82 void tty_driver_flush_buffer(struct tty_struct *tty) in tty_driver_flush_buffer() argument
84 if (tty->ops->flush_buffer) in tty_driver_flush_buffer()
85 tty->ops->flush_buffer(tty); in tty_driver_flush_buffer()
101 void tty_unthrottle(struct tty_struct *tty) in tty_unthrottle() argument
103 down_write(&tty->termios_rwsem); in tty_unthrottle()
104 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && in tty_unthrottle()
105 tty->ops->unthrottle) in tty_unthrottle()
106 tty->ops->unthrottle(tty); in tty_unthrottle()
107 tty->flow_change = TTY_FLOW_NO_CHANGE; in tty_unthrottle()
108 up_write(&tty->termios_rwsem); in tty_unthrottle()
123 bool tty_throttle_safe(struct tty_struct *tty) in tty_throttle_safe() argument
125 guard(mutex)(&tty->throttle_mutex); in tty_throttle_safe()
127 if (tty_throttled(tty)) in tty_throttle_safe()
130 if (tty->flow_change != TTY_THROTTLE_SAFE) in tty_throttle_safe()
133 set_bit(TTY_THROTTLED, &tty->flags); in tty_throttle_safe()
134 if (tty->ops->throttle) in tty_throttle_safe()
135 tty->ops->throttle(tty); in tty_throttle_safe()
151 bool tty_unthrottle_safe(struct tty_struct *tty) in tty_unthrottle_safe() argument
153 guard(mutex)(&tty->throttle_mutex); in tty_unthrottle_safe()
155 if (!tty_throttled(tty)) in tty_unthrottle_safe()
158 if (tty->flow_change != TTY_UNTHROTTLE_SAFE) in tty_unthrottle_safe()
161 clear_bit(TTY_THROTTLED, &tty->flags); in tty_unthrottle_safe()
162 if (tty->ops->unthrottle) in tty_unthrottle_safe()
163 tty->ops->unthrottle(tty); in tty_unthrottle_safe()
179 void tty_wait_until_sent(struct tty_struct *tty, long timeout) in tty_wait_until_sent() argument
184 timeout = wait_event_interruptible_timeout(tty->write_wait, in tty_wait_until_sent()
185 !tty_chars_in_buffer(tty), timeout); in tty_wait_until_sent()
192 if (tty->ops->wait_until_sent) in tty_wait_until_sent()
193 tty->ops->wait_until_sent(tty, timeout); in tty_wait_until_sent()
202 static void unset_locked_termios(struct tty_struct *tty, const struct ktermios *old) in unset_locked_termios() argument
204 struct ktermios *termios = &tty->termios; in unset_locked_termios()
205 struct ktermios *locked = &tty->termios_locked; in unset_locked_termios()
319 int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) in tty_set_termios() argument
324 WARN_ON(tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_set_termios()
325 tty->driver->subtype == PTY_TYPE_MASTER); in tty_set_termios()
333 down_write(&tty->termios_rwsem); in tty_set_termios()
334 old_termios = tty->termios; in tty_set_termios()
335 tty->termios = *new_termios; in tty_set_termios()
336 unset_locked_termios(tty, &old_termios); in tty_set_termios()
338 tty->termios.c_cflag ^= (tty->termios.c_cflag ^ old_termios.c_cflag) & ADDRB; in tty_set_termios()
340 if (tty->ops->set_termios) in tty_set_termios()
341 tty->ops->set_termios(tty, &old_termios); in tty_set_termios()
343 tty_termios_copy_hw(&tty->termios, &old_termios); in tty_set_termios()
345 ld = tty_ldisc_ref(tty); in tty_set_termios()
348 ld->ops->set_termios(tty, &old_termios); in tty_set_termios()
351 up_write(&tty->termios_rwsem); in tty_set_termios()
444 static int set_termios(struct tty_struct *tty, void __user *arg, int opt) in set_termios() argument
448 int retval = tty_check_change(tty); in set_termios()
453 down_read(&tty->termios_rwsem); in set_termios()
454 tmp_termios = tty->termios; in set_termios()
455 up_read(&tty->termios_rwsem); in set_termios()
484 retval = wait_event_interruptible(tty->write_wait, !tty_chars_in_buffer(tty));
488 if (tty_write_lock(tty, false) < 0)
492 if (tty_chars_in_buffer(tty)) {
493 tty_write_unlock(tty);
497 ld = tty_ldisc_ref(tty);
500 ld->ops->flush_buffer(tty);
504 if ((opt & TERMIOS_WAIT) && tty->ops->wait_until_sent) {
505 tty->ops->wait_until_sent(tty, 0);
507 tty_write_unlock(tty);
512 tty_set_termios(tty, &tmp_termios);
514 tty_write_unlock(tty);
516 tty_set_termios(tty, &tmp_termios);
526 static void copy_termios(struct tty_struct *tty, struct ktermios *kterm) in copy_termios() argument
528 down_read(&tty->termios_rwsem); in copy_termios()
529 *kterm = tty->termios; in copy_termios()
530 up_read(&tty->termios_rwsem); in copy_termios()
533 static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm) in copy_termios_locked() argument
535 down_read(&tty->termios_rwsem); in copy_termios_locked()
536 *kterm = tty->termios_locked; in copy_termios_locked()
537 up_read(&tty->termios_rwsem); in copy_termios_locked()
540 static int get_termio(struct tty_struct *tty, struct termio __user *termio) in get_termio() argument
543 copy_termios(tty, &kterm); in get_termio()
555 static int get_sgflags(struct tty_struct *tty) in get_sgflags() argument
559 if (!L_ICANON(tty)) { in get_sgflags()
560 if (L_ISIG(tty)) in get_sgflags()
565 if (L_ECHO(tty)) in get_sgflags()
567 if (O_OPOST(tty)) in get_sgflags()
568 if (O_ONLCR(tty)) in get_sgflags()
573 static int get_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in get_sgttyb() argument
577 down_read(&tty->termios_rwsem); in get_sgttyb()
578 tmp.sg_ispeed = tty->termios.c_ispeed; in get_sgttyb()
579 tmp.sg_ospeed = tty->termios.c_ospeed; in get_sgttyb()
580 tmp.sg_erase = tty->termios.c_cc[VERASE]; in get_sgttyb()
581 tmp.sg_kill = tty->termios.c_cc[VKILL]; in get_sgttyb()
582 tmp.sg_flags = get_sgflags(tty); in get_sgttyb()
583 up_read(&tty->termios_rwsem); in get_sgttyb()
625 static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in set_sgttyb() argument
631 retval = tty_check_change(tty); in set_sgttyb()
638 down_write(&tty->termios_rwsem); in set_sgttyb()
639 termios = tty->termios; in set_sgttyb()
646 up_write(&tty->termios_rwsem); in set_sgttyb()
647 tty_set_termios(tty, &termios); in set_sgttyb()
653 static int get_tchars(struct tty_struct *tty, struct tchars __user *tchars) in get_tchars() argument
657 down_read(&tty->termios_rwsem); in get_tchars()
658 tmp.t_intrc = tty->termios.c_cc[VINTR]; in get_tchars()
659 tmp.t_quitc = tty->termios.c_cc[VQUIT]; in get_tchars()
660 tmp.t_startc = tty->termios.c_cc[VSTART]; in get_tchars()
661 tmp.t_stopc = tty->termios.c_cc[VSTOP]; in get_tchars()
662 tmp.t_eofc = tty->termios.c_cc[VEOF]; in get_tchars()
663 tmp.t_brkc = tty->termios.c_cc[VEOL2]; /* what is brkc anyway? */ in get_tchars()
664 up_read(&tty->termios_rwsem); in get_tchars()
668 static int set_tchars(struct tty_struct *tty, struct tchars __user *tchars) in set_tchars() argument
674 down_write(&tty->termios_rwsem); in set_tchars()
675 tty->termios.c_cc[VINTR] = tmp.t_intrc; in set_tchars()
676 tty->termios.c_cc[VQUIT] = tmp.t_quitc; in set_tchars()
677 tty->termios.c_cc[VSTART] = tmp.t_startc; in set_tchars()
678 tty->termios.c_cc[VSTOP] = tmp.t_stopc; in set_tchars()
679 tty->termios.c_cc[VEOF] = tmp.t_eofc; in set_tchars()
680 tty->termios.c_cc[VEOL2] = tmp.t_brkc; /* what is brkc anyway? */ in set_tchars()
681 up_write(&tty->termios_rwsem); in set_tchars()
687 static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in get_ltchars() argument
691 down_read(&tty->termios_rwsem); in get_ltchars()
692 tmp.t_suspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
694 tmp.t_dsuspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
695 tmp.t_rprntc = tty->termios.c_cc[VREPRINT]; in get_ltchars()
697 tmp.t_flushc = tty->termios.c_cc[VEOL2]; in get_ltchars()
698 tmp.t_werasc = tty->termios.c_cc[VWERASE]; in get_ltchars()
699 tmp.t_lnextc = tty->termios.c_cc[VLNEXT]; in get_ltchars()
700 up_read(&tty->termios_rwsem); in get_ltchars()
704 static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in set_ltchars() argument
711 down_write(&tty->termios_rwsem); in set_ltchars()
712 tty->termios.c_cc[VSUSP] = tmp.t_suspc; in set_ltchars()
714 tty->termios.c_cc[VEOL2] = tmp.t_dsuspc; in set_ltchars()
715 tty->termios.c_cc[VREPRINT] = tmp.t_rprntc; in set_ltchars()
717 tty->termios.c_cc[VEOL2] = tmp.t_flushc; in set_ltchars()
718 tty->termios.c_cc[VWERASE] = tmp.t_werasc; in set_ltchars()
719 tty->termios.c_cc[VLNEXT] = tmp.t_lnextc; in set_ltchars()
720 up_write(&tty->termios_rwsem); in set_ltchars()
737 static int tty_change_softcar(struct tty_struct *tty, bool enable) in tty_change_softcar() argument
743 down_write(&tty->termios_rwsem); in tty_change_softcar()
744 old = tty->termios; in tty_change_softcar()
745 tty->termios.c_cflag &= ~CLOCAL; in tty_change_softcar()
746 tty->termios.c_cflag |= bit; in tty_change_softcar()
747 if (tty->ops->set_termios) in tty_change_softcar()
748 tty->ops->set_termios(tty, &old); in tty_change_softcar()
749 if (C_CLOCAL(tty) != bit) in tty_change_softcar()
751 up_write(&tty->termios_rwsem); in tty_change_softcar()
765 int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) in tty_mode_ioctl() argument
772 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_mode_ioctl()
773 tty->driver->subtype == PTY_TYPE_MASTER) in tty_mode_ioctl()
774 real_tty = tty->link; in tty_mode_ioctl()
776 real_tty = tty; in tty_mode_ioctl()
895 static int __tty_perform_flush(struct tty_struct *tty, unsigned long arg) in __tty_perform_flush() argument
897 struct tty_ldisc *ld = tty->ldisc; in __tty_perform_flush()
902 ld->ops->flush_buffer(tty); in __tty_perform_flush()
903 tty_unthrottle(tty); in __tty_perform_flush()
908 ld->ops->flush_buffer(tty); in __tty_perform_flush()
909 tty_unthrottle(tty); in __tty_perform_flush()
913 tty_driver_flush_buffer(tty); in __tty_perform_flush()
921 int tty_perform_flush(struct tty_struct *tty, unsigned long arg) in tty_perform_flush() argument
924 int retval = tty_check_change(tty); in tty_perform_flush()
928 ld = tty_ldisc_ref_wait(tty); in tty_perform_flush()
929 retval = __tty_perform_flush(tty, arg); in tty_perform_flush()
936 int n_tty_ioctl_helper(struct tty_struct *tty, unsigned int cmd, in n_tty_ioctl_helper() argument
943 retval = tty_check_change(tty); in n_tty_ioctl_helper()
948 spin_lock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
949 if (!tty->flow.tco_stopped) { in n_tty_ioctl_helper()
950 tty->flow.tco_stopped = true; in n_tty_ioctl_helper()
951 __stop_tty(tty); in n_tty_ioctl_helper()
953 spin_unlock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
956 spin_lock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
957 if (tty->flow.tco_stopped) { in n_tty_ioctl_helper()
958 tty->flow.tco_stopped = false; in n_tty_ioctl_helper()
959 __start_tty(tty); in n_tty_ioctl_helper()
961 spin_unlock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
964 if (STOP_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
965 retval = tty_send_xchar(tty, STOP_CHAR(tty)); in n_tty_ioctl_helper()
968 if (START_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
969 retval = tty_send_xchar(tty, START_CHAR(tty)); in n_tty_ioctl_helper()
976 retval = tty_check_change(tty); in n_tty_ioctl_helper()
979 return __tty_perform_flush(tty, arg); in n_tty_ioctl_helper()
982 return tty_mode_ioctl(tty, cmd, arg); in n_tty_ioctl_helper()