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
127 mutex_lock(&tty->throttle_mutex); in tty_throttle_safe()
128 if (!tty_throttled(tty)) { in tty_throttle_safe()
129 if (tty->flow_change != TTY_THROTTLE_SAFE) in tty_throttle_safe()
132 set_bit(TTY_THROTTLED, &tty->flags); in tty_throttle_safe()
133 if (tty->ops->throttle) in tty_throttle_safe()
134 tty->ops->throttle(tty); in tty_throttle_safe()
137 mutex_unlock(&tty->throttle_mutex); in tty_throttle_safe()
153 bool tty_unthrottle_safe(struct tty_struct *tty) in tty_unthrottle_safe() argument
157 mutex_lock(&tty->throttle_mutex); in tty_unthrottle_safe()
158 if (tty_throttled(tty)) { in tty_unthrottle_safe()
159 if (tty->flow_change != TTY_UNTHROTTLE_SAFE) in tty_unthrottle_safe()
162 clear_bit(TTY_THROTTLED, &tty->flags); in tty_unthrottle_safe()
163 if (tty->ops->unthrottle) in tty_unthrottle_safe()
164 tty->ops->unthrottle(tty); in tty_unthrottle_safe()
167 mutex_unlock(&tty->throttle_mutex); in tty_unthrottle_safe()
183 void tty_wait_until_sent(struct tty_struct *tty, long timeout) in tty_wait_until_sent() argument
188 timeout = wait_event_interruptible_timeout(tty->write_wait, in tty_wait_until_sent()
189 !tty_chars_in_buffer(tty), timeout); in tty_wait_until_sent()
196 if (tty->ops->wait_until_sent) in tty_wait_until_sent()
197 tty->ops->wait_until_sent(tty, timeout); in tty_wait_until_sent()
206 static void unset_locked_termios(struct tty_struct *tty, const struct ktermios *old) in unset_locked_termios() argument
208 struct ktermios *termios = &tty->termios; in unset_locked_termios()
209 struct ktermios *locked = &tty->termios_locked; in unset_locked_termios()
323 int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) in tty_set_termios() argument
328 WARN_ON(tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_set_termios()
329 tty->driver->subtype == PTY_TYPE_MASTER); in tty_set_termios()
337 down_write(&tty->termios_rwsem); in tty_set_termios()
338 old_termios = tty->termios; in tty_set_termios()
339 tty->termios = *new_termios; in tty_set_termios()
340 unset_locked_termios(tty, &old_termios); in tty_set_termios()
342 tty->termios.c_cflag ^= (tty->termios.c_cflag ^ old_termios.c_cflag) & ADDRB; in tty_set_termios()
344 if (tty->ops->set_termios) in tty_set_termios()
345 tty->ops->set_termios(tty, &old_termios); in tty_set_termios()
347 tty_termios_copy_hw(&tty->termios, &old_termios); in tty_set_termios()
349 ld = tty_ldisc_ref(tty); in tty_set_termios()
352 ld->ops->set_termios(tty, &old_termios); in tty_set_termios()
355 up_write(&tty->termios_rwsem); in tty_set_termios()
448 static int set_termios(struct tty_struct *tty, void __user *arg, int opt) in set_termios() argument
452 int retval = tty_check_change(tty); in set_termios()
457 down_read(&tty->termios_rwsem); in set_termios()
458 tmp_termios = tty->termios; in set_termios()
459 up_read(&tty->termios_rwsem); in set_termios()
488 retval = wait_event_interruptible(tty->write_wait, !tty_chars_in_buffer(tty));
492 if (tty_write_lock(tty, false) < 0)
496 if (tty_chars_in_buffer(tty)) {
497 tty_write_unlock(tty);
501 ld = tty_ldisc_ref(tty);
504 ld->ops->flush_buffer(tty);
508 if ((opt & TERMIOS_WAIT) && tty->ops->wait_until_sent) {
509 tty->ops->wait_until_sent(tty, 0);
511 tty_write_unlock(tty);
516 tty_set_termios(tty, &tmp_termios);
518 tty_write_unlock(tty);
520 tty_set_termios(tty, &tmp_termios);
530 static void copy_termios(struct tty_struct *tty, struct ktermios *kterm) in copy_termios() argument
532 down_read(&tty->termios_rwsem); in copy_termios()
533 *kterm = tty->termios; in copy_termios()
534 up_read(&tty->termios_rwsem); in copy_termios()
537 static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm) in copy_termios_locked() argument
539 down_read(&tty->termios_rwsem); in copy_termios_locked()
540 *kterm = tty->termios_locked; in copy_termios_locked()
541 up_read(&tty->termios_rwsem); in copy_termios_locked()
544 static int get_termio(struct tty_struct *tty, struct termio __user *termio) in get_termio() argument
547 copy_termios(tty, &kterm); in get_termio()
559 static int get_sgflags(struct tty_struct *tty) in get_sgflags() argument
563 if (!L_ICANON(tty)) { in get_sgflags()
564 if (L_ISIG(tty)) in get_sgflags()
569 if (L_ECHO(tty)) in get_sgflags()
571 if (O_OPOST(tty)) in get_sgflags()
572 if (O_ONLCR(tty)) in get_sgflags()
577 static int get_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in get_sgttyb() argument
581 down_read(&tty->termios_rwsem); in get_sgttyb()
582 tmp.sg_ispeed = tty->termios.c_ispeed; in get_sgttyb()
583 tmp.sg_ospeed = tty->termios.c_ospeed; in get_sgttyb()
584 tmp.sg_erase = tty->termios.c_cc[VERASE]; in get_sgttyb()
585 tmp.sg_kill = tty->termios.c_cc[VKILL]; in get_sgttyb()
586 tmp.sg_flags = get_sgflags(tty); in get_sgttyb()
587 up_read(&tty->termios_rwsem); in get_sgttyb()
629 static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in set_sgttyb() argument
635 retval = tty_check_change(tty); in set_sgttyb()
642 down_write(&tty->termios_rwsem); in set_sgttyb()
643 termios = tty->termios; in set_sgttyb()
650 up_write(&tty->termios_rwsem); in set_sgttyb()
651 tty_set_termios(tty, &termios); in set_sgttyb()
657 static int get_tchars(struct tty_struct *tty, struct tchars __user *tchars) in get_tchars() argument
661 down_read(&tty->termios_rwsem); in get_tchars()
662 tmp.t_intrc = tty->termios.c_cc[VINTR]; in get_tchars()
663 tmp.t_quitc = tty->termios.c_cc[VQUIT]; in get_tchars()
664 tmp.t_startc = tty->termios.c_cc[VSTART]; in get_tchars()
665 tmp.t_stopc = tty->termios.c_cc[VSTOP]; in get_tchars()
666 tmp.t_eofc = tty->termios.c_cc[VEOF]; in get_tchars()
667 tmp.t_brkc = tty->termios.c_cc[VEOL2]; /* what is brkc anyway? */ in get_tchars()
668 up_read(&tty->termios_rwsem); in get_tchars()
672 static int set_tchars(struct tty_struct *tty, struct tchars __user *tchars) in set_tchars() argument
678 down_write(&tty->termios_rwsem); in set_tchars()
679 tty->termios.c_cc[VINTR] = tmp.t_intrc; in set_tchars()
680 tty->termios.c_cc[VQUIT] = tmp.t_quitc; in set_tchars()
681 tty->termios.c_cc[VSTART] = tmp.t_startc; in set_tchars()
682 tty->termios.c_cc[VSTOP] = tmp.t_stopc; in set_tchars()
683 tty->termios.c_cc[VEOF] = tmp.t_eofc; in set_tchars()
684 tty->termios.c_cc[VEOL2] = tmp.t_brkc; /* what is brkc anyway? */ in set_tchars()
685 up_write(&tty->termios_rwsem); in set_tchars()
691 static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in get_ltchars() argument
695 down_read(&tty->termios_rwsem); in get_ltchars()
696 tmp.t_suspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
698 tmp.t_dsuspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
699 tmp.t_rprntc = tty->termios.c_cc[VREPRINT]; in get_ltchars()
701 tmp.t_flushc = tty->termios.c_cc[VEOL2]; in get_ltchars()
702 tmp.t_werasc = tty->termios.c_cc[VWERASE]; in get_ltchars()
703 tmp.t_lnextc = tty->termios.c_cc[VLNEXT]; in get_ltchars()
704 up_read(&tty->termios_rwsem); in get_ltchars()
708 static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in set_ltchars() argument
715 down_write(&tty->termios_rwsem); in set_ltchars()
716 tty->termios.c_cc[VSUSP] = tmp.t_suspc; in set_ltchars()
718 tty->termios.c_cc[VEOL2] = tmp.t_dsuspc; in set_ltchars()
719 tty->termios.c_cc[VREPRINT] = tmp.t_rprntc; in set_ltchars()
721 tty->termios.c_cc[VEOL2] = tmp.t_flushc; in set_ltchars()
722 tty->termios.c_cc[VWERASE] = tmp.t_werasc; in set_ltchars()
723 tty->termios.c_cc[VLNEXT] = tmp.t_lnextc; in set_ltchars()
724 up_write(&tty->termios_rwsem); in set_ltchars()
741 static int tty_change_softcar(struct tty_struct *tty, bool enable) in tty_change_softcar() argument
747 down_write(&tty->termios_rwsem); in tty_change_softcar()
748 old = tty->termios; in tty_change_softcar()
749 tty->termios.c_cflag &= ~CLOCAL; in tty_change_softcar()
750 tty->termios.c_cflag |= bit; in tty_change_softcar()
751 if (tty->ops->set_termios) in tty_change_softcar()
752 tty->ops->set_termios(tty, &old); in tty_change_softcar()
753 if (C_CLOCAL(tty) != bit) in tty_change_softcar()
755 up_write(&tty->termios_rwsem); in tty_change_softcar()
769 int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) in tty_mode_ioctl() argument
776 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_mode_ioctl()
777 tty->driver->subtype == PTY_TYPE_MASTER) in tty_mode_ioctl()
778 real_tty = tty->link; in tty_mode_ioctl()
780 real_tty = tty; in tty_mode_ioctl()
899 static int __tty_perform_flush(struct tty_struct *tty, unsigned long arg) in __tty_perform_flush() argument
901 struct tty_ldisc *ld = tty->ldisc; in __tty_perform_flush()
906 ld->ops->flush_buffer(tty); in __tty_perform_flush()
907 tty_unthrottle(tty); in __tty_perform_flush()
912 ld->ops->flush_buffer(tty); in __tty_perform_flush()
913 tty_unthrottle(tty); in __tty_perform_flush()
917 tty_driver_flush_buffer(tty); in __tty_perform_flush()
925 int tty_perform_flush(struct tty_struct *tty, unsigned long arg) in tty_perform_flush() argument
928 int retval = tty_check_change(tty); in tty_perform_flush()
932 ld = tty_ldisc_ref_wait(tty); in tty_perform_flush()
933 retval = __tty_perform_flush(tty, arg); in tty_perform_flush()
940 int n_tty_ioctl_helper(struct tty_struct *tty, unsigned int cmd, in n_tty_ioctl_helper() argument
947 retval = tty_check_change(tty); in n_tty_ioctl_helper()
952 spin_lock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
953 if (!tty->flow.tco_stopped) { in n_tty_ioctl_helper()
954 tty->flow.tco_stopped = true; in n_tty_ioctl_helper()
955 __stop_tty(tty); in n_tty_ioctl_helper()
957 spin_unlock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
960 spin_lock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
961 if (tty->flow.tco_stopped) { in n_tty_ioctl_helper()
962 tty->flow.tco_stopped = false; in n_tty_ioctl_helper()
963 __start_tty(tty); in n_tty_ioctl_helper()
965 spin_unlock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
968 if (STOP_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
969 retval = tty_send_xchar(tty, STOP_CHAR(tty)); in n_tty_ioctl_helper()
972 if (START_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
973 retval = tty_send_xchar(tty, START_CHAR(tty)); in n_tty_ioctl_helper()
980 retval = tty_check_change(tty); in n_tty_ioctl_helper()
983 return __tty_perform_flush(tty, arg); in n_tty_ioctl_helper()
986 return tty_mode_ioctl(tty, cmd, arg); in n_tty_ioctl_helper()