Lines Matching refs:tty
30 # define tty_debug_wait_until_sent(tty, f, args...) tty_debug(tty, f, ##args) argument
32 # define tty_debug_wait_until_sent(tty, f, args...) do {} while (0) argument
55 int tty_chars_in_buffer(struct tty_struct *tty) in tty_chars_in_buffer() argument
57 if (tty->ops->chars_in_buffer) in tty_chars_in_buffer()
58 return tty->ops->chars_in_buffer(tty); in tty_chars_in_buffer()
75 int tty_write_room(struct tty_struct *tty) in tty_write_room() argument
77 if (tty->ops->write_room) in tty_write_room()
78 return tty->ops->write_room(tty); in tty_write_room()
91 void tty_driver_flush_buffer(struct tty_struct *tty) in tty_driver_flush_buffer() argument
93 if (tty->ops->flush_buffer) in tty_driver_flush_buffer()
94 tty->ops->flush_buffer(tty); in tty_driver_flush_buffer()
108 void tty_throttle(struct tty_struct *tty) in tty_throttle() argument
110 down_write(&tty->termios_rwsem); in tty_throttle()
112 if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && in tty_throttle()
113 tty->ops->throttle) in tty_throttle()
114 tty->ops->throttle(tty); in tty_throttle()
115 tty->flow_change = 0; in tty_throttle()
116 up_write(&tty->termios_rwsem); in tty_throttle()
133 void tty_unthrottle(struct tty_struct *tty) in tty_unthrottle() argument
135 down_write(&tty->termios_rwsem); in tty_unthrottle()
136 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && in tty_unthrottle()
137 tty->ops->unthrottle) in tty_unthrottle()
138 tty->ops->unthrottle(tty); in tty_unthrottle()
139 tty->flow_change = 0; in tty_unthrottle()
140 up_write(&tty->termios_rwsem); in tty_unthrottle()
156 int tty_throttle_safe(struct tty_struct *tty) in tty_throttle_safe() argument
160 mutex_lock(&tty->throttle_mutex); in tty_throttle_safe()
161 if (!tty_throttled(tty)) { in tty_throttle_safe()
162 if (tty->flow_change != TTY_THROTTLE_SAFE) in tty_throttle_safe()
165 set_bit(TTY_THROTTLED, &tty->flags); in tty_throttle_safe()
166 if (tty->ops->throttle) in tty_throttle_safe()
167 tty->ops->throttle(tty); in tty_throttle_safe()
170 mutex_unlock(&tty->throttle_mutex); in tty_throttle_safe()
187 int tty_unthrottle_safe(struct tty_struct *tty) in tty_unthrottle_safe() argument
191 mutex_lock(&tty->throttle_mutex); in tty_unthrottle_safe()
192 if (tty_throttled(tty)) { in tty_unthrottle_safe()
193 if (tty->flow_change != TTY_UNTHROTTLE_SAFE) in tty_unthrottle_safe()
196 clear_bit(TTY_THROTTLED, &tty->flags); in tty_unthrottle_safe()
197 if (tty->ops->unthrottle) in tty_unthrottle_safe()
198 tty->ops->unthrottle(tty); in tty_unthrottle_safe()
201 mutex_unlock(&tty->throttle_mutex); in tty_unthrottle_safe()
217 void tty_wait_until_sent(struct tty_struct *tty, long timeout) in tty_wait_until_sent() argument
219 tty_debug_wait_until_sent(tty, "wait until sent, timeout=%ld\n", timeout); in tty_wait_until_sent()
224 timeout = wait_event_interruptible_timeout(tty->write_wait, in tty_wait_until_sent()
225 !tty_chars_in_buffer(tty), timeout); in tty_wait_until_sent()
232 if (tty->ops->wait_until_sent) in tty_wait_until_sent()
233 tty->ops->wait_until_sent(tty, timeout); in tty_wait_until_sent()
242 static void unset_locked_termios(struct tty_struct *tty, struct ktermios *old) in unset_locked_termios() argument
244 struct ktermios *termios = &tty->termios; in unset_locked_termios()
245 struct ktermios *locked = &tty->termios_locked; in unset_locked_termios()
477 void tty_encode_baud_rate(struct tty_struct *tty, speed_t ibaud, speed_t obaud) in tty_encode_baud_rate() argument
479 tty_termios_encode_baud_rate(&tty->termios, ibaud, obaud); in tty_encode_baud_rate()
535 int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) in tty_set_termios() argument
540 WARN_ON(tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_set_termios()
541 tty->driver->subtype == PTY_TYPE_MASTER); in tty_set_termios()
549 down_write(&tty->termios_rwsem); in tty_set_termios()
550 old_termios = tty->termios; in tty_set_termios()
551 tty->termios = *new_termios; in tty_set_termios()
552 unset_locked_termios(tty, &old_termios); in tty_set_termios()
554 if (tty->ops->set_termios) in tty_set_termios()
555 tty->ops->set_termios(tty, &old_termios); in tty_set_termios()
557 tty_termios_copy_hw(&tty->termios, &old_termios); in tty_set_termios()
559 ld = tty_ldisc_ref(tty); in tty_set_termios()
562 ld->ops->set_termios(tty, &old_termios); in tty_set_termios()
565 up_write(&tty->termios_rwsem); in tty_set_termios()
583 static int set_termios(struct tty_struct *tty, void __user *arg, int opt) in set_termios() argument
587 int retval = tty_check_change(tty); in set_termios()
592 down_read(&tty->termios_rwsem); in set_termios()
593 tmp_termios = tty->termios; in set_termios()
594 up_read(&tty->termios_rwsem); in set_termios()
621 ld = tty_ldisc_ref(tty);
625 ld->ops->flush_buffer(tty);
630 tty_wait_until_sent(tty, 0);
635 tty_set_termios(tty, &tmp_termios);
644 static void copy_termios(struct tty_struct *tty, struct ktermios *kterm) in copy_termios() argument
646 down_read(&tty->termios_rwsem); in copy_termios()
647 *kterm = tty->termios; in copy_termios()
648 up_read(&tty->termios_rwsem); in copy_termios()
651 static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm) in copy_termios_locked() argument
653 down_read(&tty->termios_rwsem); in copy_termios_locked()
654 *kterm = tty->termios_locked; in copy_termios_locked()
655 up_read(&tty->termios_rwsem); in copy_termios_locked()
658 static int get_termio(struct tty_struct *tty, struct termio __user *termio) in get_termio() argument
661 copy_termios(tty, &kterm); in get_termio()
680 static int set_termiox(struct tty_struct *tty, void __user *arg, int opt) in set_termiox() argument
685 if (tty->termiox == NULL) in set_termiox()
690 ld = tty_ldisc_ref(tty); in set_termiox()
693 ld->ops->flush_buffer(tty); in set_termiox()
697 tty_wait_until_sent(tty, 0); in set_termiox()
702 down_write(&tty->termios_rwsem); in set_termiox()
703 if (tty->ops->set_termiox) in set_termiox()
704 tty->ops->set_termiox(tty, &tnew); in set_termiox()
705 up_write(&tty->termios_rwsem); in set_termiox()
718 static int get_sgflags(struct tty_struct *tty) in get_sgflags() argument
722 if (!L_ICANON(tty)) { in get_sgflags()
723 if (L_ISIG(tty)) in get_sgflags()
728 if (L_ECHO(tty)) in get_sgflags()
730 if (O_OPOST(tty)) in get_sgflags()
731 if (O_ONLCR(tty)) in get_sgflags()
736 static int get_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in get_sgttyb() argument
740 down_read(&tty->termios_rwsem); in get_sgttyb()
741 tmp.sg_ispeed = tty->termios.c_ispeed; in get_sgttyb()
742 tmp.sg_ospeed = tty->termios.c_ospeed; in get_sgttyb()
743 tmp.sg_erase = tty->termios.c_cc[VERASE]; in get_sgttyb()
744 tmp.sg_kill = tty->termios.c_cc[VKILL]; in get_sgttyb()
745 tmp.sg_flags = get_sgflags(tty); in get_sgttyb()
746 up_read(&tty->termios_rwsem); in get_sgttyb()
788 static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in set_sgttyb() argument
794 retval = tty_check_change(tty); in set_sgttyb()
801 down_write(&tty->termios_rwsem); in set_sgttyb()
802 termios = tty->termios; in set_sgttyb()
811 up_write(&tty->termios_rwsem); in set_sgttyb()
812 tty_set_termios(tty, &termios); in set_sgttyb()
818 static int get_tchars(struct tty_struct *tty, struct tchars __user *tchars) in get_tchars() argument
822 down_read(&tty->termios_rwsem); in get_tchars()
823 tmp.t_intrc = tty->termios.c_cc[VINTR]; in get_tchars()
824 tmp.t_quitc = tty->termios.c_cc[VQUIT]; in get_tchars()
825 tmp.t_startc = tty->termios.c_cc[VSTART]; in get_tchars()
826 tmp.t_stopc = tty->termios.c_cc[VSTOP]; in get_tchars()
827 tmp.t_eofc = tty->termios.c_cc[VEOF]; in get_tchars()
828 tmp.t_brkc = tty->termios.c_cc[VEOL2]; /* what is brkc anyway? */ in get_tchars()
829 up_read(&tty->termios_rwsem); in get_tchars()
833 static int set_tchars(struct tty_struct *tty, struct tchars __user *tchars) in set_tchars() argument
839 down_write(&tty->termios_rwsem); in set_tchars()
840 tty->termios.c_cc[VINTR] = tmp.t_intrc; in set_tchars()
841 tty->termios.c_cc[VQUIT] = tmp.t_quitc; in set_tchars()
842 tty->termios.c_cc[VSTART] = tmp.t_startc; in set_tchars()
843 tty->termios.c_cc[VSTOP] = tmp.t_stopc; in set_tchars()
844 tty->termios.c_cc[VEOF] = tmp.t_eofc; in set_tchars()
845 tty->termios.c_cc[VEOL2] = tmp.t_brkc; /* what is brkc anyway? */ in set_tchars()
846 up_write(&tty->termios_rwsem); in set_tchars()
852 static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in get_ltchars() argument
856 down_read(&tty->termios_rwsem); in get_ltchars()
857 tmp.t_suspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
859 tmp.t_dsuspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
860 tmp.t_rprntc = tty->termios.c_cc[VREPRINT]; in get_ltchars()
862 tmp.t_flushc = tty->termios.c_cc[VEOL2]; in get_ltchars()
863 tmp.t_werasc = tty->termios.c_cc[VWERASE]; in get_ltchars()
864 tmp.t_lnextc = tty->termios.c_cc[VLNEXT]; in get_ltchars()
865 up_read(&tty->termios_rwsem); in get_ltchars()
869 static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in set_ltchars() argument
876 down_write(&tty->termios_rwsem); in set_ltchars()
877 tty->termios.c_cc[VSUSP] = tmp.t_suspc; in set_ltchars()
879 tty->termios.c_cc[VEOL2] = tmp.t_dsuspc; in set_ltchars()
880 tty->termios.c_cc[VREPRINT] = tmp.t_rprntc; in set_ltchars()
882 tty->termios.c_cc[VEOL2] = tmp.t_flushc; in set_ltchars()
883 tty->termios.c_cc[VWERASE] = tmp.t_werasc; in set_ltchars()
884 tty->termios.c_cc[VLNEXT] = tmp.t_lnextc; in set_ltchars()
885 up_write(&tty->termios_rwsem); in set_ltchars()
899 static int tty_change_softcar(struct tty_struct *tty, int arg) in tty_change_softcar() argument
905 down_write(&tty->termios_rwsem); in tty_change_softcar()
906 old = tty->termios; in tty_change_softcar()
907 tty->termios.c_cflag &= ~CLOCAL; in tty_change_softcar()
908 tty->termios.c_cflag |= bit; in tty_change_softcar()
909 if (tty->ops->set_termios) in tty_change_softcar()
910 tty->ops->set_termios(tty, &old); in tty_change_softcar()
911 if (C_CLOCAL(tty) != bit) in tty_change_softcar()
913 up_write(&tty->termios_rwsem); in tty_change_softcar()
929 int tty_mode_ioctl(struct tty_struct *tty, struct file *file, in tty_mode_ioctl() argument
939 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_mode_ioctl()
940 tty->driver->subtype == PTY_TYPE_MASTER) in tty_mode_ioctl()
941 real_tty = tty->link; in tty_mode_ioctl()
943 real_tty = tty; in tty_mode_ioctl()
1074 static int __tty_perform_flush(struct tty_struct *tty, unsigned long arg) in __tty_perform_flush() argument
1076 struct tty_ldisc *ld = tty->ldisc; in __tty_perform_flush()
1081 ld->ops->flush_buffer(tty); in __tty_perform_flush()
1082 tty_unthrottle(tty); in __tty_perform_flush()
1087 ld->ops->flush_buffer(tty); in __tty_perform_flush()
1088 tty_unthrottle(tty); in __tty_perform_flush()
1092 tty_driver_flush_buffer(tty); in __tty_perform_flush()
1100 int tty_perform_flush(struct tty_struct *tty, unsigned long arg) in tty_perform_flush() argument
1103 int retval = tty_check_change(tty); in tty_perform_flush()
1107 ld = tty_ldisc_ref_wait(tty); in tty_perform_flush()
1108 retval = __tty_perform_flush(tty, arg); in tty_perform_flush()
1115 int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file, in n_tty_ioctl_helper() argument
1122 retval = tty_check_change(tty); in n_tty_ioctl_helper()
1127 spin_lock_irq(&tty->flow_lock); in n_tty_ioctl_helper()
1128 if (!tty->flow_stopped) { in n_tty_ioctl_helper()
1129 tty->flow_stopped = 1; in n_tty_ioctl_helper()
1130 __stop_tty(tty); in n_tty_ioctl_helper()
1132 spin_unlock_irq(&tty->flow_lock); in n_tty_ioctl_helper()
1135 spin_lock_irq(&tty->flow_lock); in n_tty_ioctl_helper()
1136 if (tty->flow_stopped) { in n_tty_ioctl_helper()
1137 tty->flow_stopped = 0; in n_tty_ioctl_helper()
1138 __start_tty(tty); in n_tty_ioctl_helper()
1140 spin_unlock_irq(&tty->flow_lock); in n_tty_ioctl_helper()
1143 if (STOP_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
1144 retval = tty_send_xchar(tty, STOP_CHAR(tty)); in n_tty_ioctl_helper()
1147 if (START_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
1148 retval = tty_send_xchar(tty, START_CHAR(tty)); in n_tty_ioctl_helper()
1155 retval = tty_check_change(tty); in n_tty_ioctl_helper()
1158 return __tty_perform_flush(tty, arg); in n_tty_ioctl_helper()
1161 return tty_mode_ioctl(tty, file, cmd, arg); in n_tty_ioctl_helper()
1167 long n_tty_compat_ioctl_helper(struct tty_struct *tty, struct file *file, in n_tty_compat_ioctl_helper() argument
1173 return tty_mode_ioctl(tty, file, cmd, (unsigned long) compat_ptr(arg)); in n_tty_compat_ioctl_helper()