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 (!test_bit(TTY_THROTTLED, &tty->flags)) { 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 (test_bit(TTY_THROTTLED, &tty->flags)) { 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, "\n"); 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()
484 void tty_encode_baud_rate(struct tty_struct *tty, speed_t ibaud, speed_t obaud) in tty_encode_baud_rate() argument
486 tty_termios_encode_baud_rate(&tty->termios, ibaud, obaud); in tty_encode_baud_rate()
542 int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) in tty_set_termios() argument
547 WARN_ON(tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_set_termios()
548 tty->driver->subtype == PTY_TYPE_MASTER); in tty_set_termios()
556 down_write(&tty->termios_rwsem); in tty_set_termios()
557 old_termios = tty->termios; in tty_set_termios()
558 tty->termios = *new_termios; in tty_set_termios()
559 unset_locked_termios(&tty->termios, &old_termios, &tty->termios_locked); in tty_set_termios()
561 if (tty->ops->set_termios) in tty_set_termios()
562 tty->ops->set_termios(tty, &old_termios); in tty_set_termios()
564 tty_termios_copy_hw(&tty->termios, &old_termios); in tty_set_termios()
566 ld = tty_ldisc_ref(tty); in tty_set_termios()
569 ld->ops->set_termios(tty, &old_termios); in tty_set_termios()
572 up_write(&tty->termios_rwsem); in tty_set_termios()
590 static int set_termios(struct tty_struct *tty, void __user *arg, int opt) in set_termios() argument
594 int retval = tty_check_change(tty); in set_termios()
599 down_read(&tty->termios_rwsem); in set_termios()
600 tmp_termios = tty->termios; in set_termios()
601 up_read(&tty->termios_rwsem); in set_termios()
628 ld = tty_ldisc_ref(tty);
632 ld->ops->flush_buffer(tty);
637 tty_wait_until_sent(tty, 0);
642 tty_set_termios(tty, &tmp_termios);
651 static void copy_termios(struct tty_struct *tty, struct ktermios *kterm) in copy_termios() argument
653 down_read(&tty->termios_rwsem); in copy_termios()
654 *kterm = tty->termios; in copy_termios()
655 up_read(&tty->termios_rwsem); in copy_termios()
658 static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm) in copy_termios_locked() argument
660 down_read(&tty->termios_rwsem); in copy_termios_locked()
661 *kterm = tty->termios_locked; in copy_termios_locked()
662 up_read(&tty->termios_rwsem); in copy_termios_locked()
665 static int get_termio(struct tty_struct *tty, struct termio __user *termio) in get_termio() argument
668 copy_termios(tty, &kterm); in get_termio()
687 static int set_termiox(struct tty_struct *tty, void __user *arg, int opt) in set_termiox() argument
692 if (tty->termiox == NULL) in set_termiox()
697 ld = tty_ldisc_ref(tty); in set_termiox()
700 ld->ops->flush_buffer(tty); in set_termiox()
704 tty_wait_until_sent(tty, 0); in set_termiox()
709 down_write(&tty->termios_rwsem); in set_termiox()
710 if (tty->ops->set_termiox) in set_termiox()
711 tty->ops->set_termiox(tty, &tnew); in set_termiox()
712 up_write(&tty->termios_rwsem); in set_termiox()
725 static int get_sgflags(struct tty_struct *tty) in get_sgflags() argument
729 if (!(tty->termios.c_lflag & ICANON)) { in get_sgflags()
730 if (tty->termios.c_lflag & ISIG) in get_sgflags()
735 if (tty->termios.c_lflag & ECHO) in get_sgflags()
737 if (tty->termios.c_oflag & OPOST) in get_sgflags()
738 if (tty->termios.c_oflag & ONLCR) in get_sgflags()
743 static int get_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in get_sgttyb() argument
747 down_read(&tty->termios_rwsem); in get_sgttyb()
748 tmp.sg_ispeed = tty->termios.c_ispeed; in get_sgttyb()
749 tmp.sg_ospeed = tty->termios.c_ospeed; in get_sgttyb()
750 tmp.sg_erase = tty->termios.c_cc[VERASE]; in get_sgttyb()
751 tmp.sg_kill = tty->termios.c_cc[VKILL]; in get_sgttyb()
752 tmp.sg_flags = get_sgflags(tty); in get_sgttyb()
753 up_read(&tty->termios_rwsem); in get_sgttyb()
795 static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in set_sgttyb() argument
801 retval = tty_check_change(tty); in set_sgttyb()
808 down_write(&tty->termios_rwsem); in set_sgttyb()
809 termios = tty->termios; in set_sgttyb()
818 up_write(&tty->termios_rwsem); in set_sgttyb()
819 tty_set_termios(tty, &termios); in set_sgttyb()
825 static int get_tchars(struct tty_struct *tty, struct tchars __user *tchars) in get_tchars() argument
829 down_read(&tty->termios_rwsem); in get_tchars()
830 tmp.t_intrc = tty->termios.c_cc[VINTR]; in get_tchars()
831 tmp.t_quitc = tty->termios.c_cc[VQUIT]; in get_tchars()
832 tmp.t_startc = tty->termios.c_cc[VSTART]; in get_tchars()
833 tmp.t_stopc = tty->termios.c_cc[VSTOP]; in get_tchars()
834 tmp.t_eofc = tty->termios.c_cc[VEOF]; in get_tchars()
835 tmp.t_brkc = tty->termios.c_cc[VEOL2]; /* what is brkc anyway? */ in get_tchars()
836 up_read(&tty->termios_rwsem); in get_tchars()
840 static int set_tchars(struct tty_struct *tty, struct tchars __user *tchars) in set_tchars() argument
846 down_write(&tty->termios_rwsem); in set_tchars()
847 tty->termios.c_cc[VINTR] = tmp.t_intrc; in set_tchars()
848 tty->termios.c_cc[VQUIT] = tmp.t_quitc; in set_tchars()
849 tty->termios.c_cc[VSTART] = tmp.t_startc; in set_tchars()
850 tty->termios.c_cc[VSTOP] = tmp.t_stopc; in set_tchars()
851 tty->termios.c_cc[VEOF] = tmp.t_eofc; in set_tchars()
852 tty->termios.c_cc[VEOL2] = tmp.t_brkc; /* what is brkc anyway? */ in set_tchars()
853 up_write(&tty->termios_rwsem); in set_tchars()
859 static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in get_ltchars() argument
863 down_read(&tty->termios_rwsem); in get_ltchars()
864 tmp.t_suspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
866 tmp.t_dsuspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
867 tmp.t_rprntc = tty->termios.c_cc[VREPRINT]; in get_ltchars()
869 tmp.t_flushc = tty->termios.c_cc[VEOL2]; in get_ltchars()
870 tmp.t_werasc = tty->termios.c_cc[VWERASE]; in get_ltchars()
871 tmp.t_lnextc = tty->termios.c_cc[VLNEXT]; in get_ltchars()
872 up_read(&tty->termios_rwsem); in get_ltchars()
876 static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in set_ltchars() argument
883 down_write(&tty->termios_rwsem); in set_ltchars()
884 tty->termios.c_cc[VSUSP] = tmp.t_suspc; in set_ltchars()
886 tty->termios.c_cc[VEOL2] = tmp.t_dsuspc; in set_ltchars()
887 tty->termios.c_cc[VREPRINT] = tmp.t_rprntc; in set_ltchars()
889 tty->termios.c_cc[VEOL2] = tmp.t_flushc; in set_ltchars()
890 tty->termios.c_cc[VWERASE] = tmp.t_werasc; in set_ltchars()
891 tty->termios.c_cc[VLNEXT] = tmp.t_lnextc; in set_ltchars()
892 up_write(&tty->termios_rwsem); in set_ltchars()
906 static int tty_change_softcar(struct tty_struct *tty, int arg) in tty_change_softcar() argument
912 down_write(&tty->termios_rwsem); in tty_change_softcar()
913 old = tty->termios; in tty_change_softcar()
914 tty->termios.c_cflag &= ~CLOCAL; in tty_change_softcar()
915 tty->termios.c_cflag |= bit; in tty_change_softcar()
916 if (tty->ops->set_termios) in tty_change_softcar()
917 tty->ops->set_termios(tty, &old); in tty_change_softcar()
918 if ((tty->termios.c_cflag & CLOCAL) != bit) in tty_change_softcar()
920 up_write(&tty->termios_rwsem); in tty_change_softcar()
936 int tty_mode_ioctl(struct tty_struct *tty, struct file *file, in tty_mode_ioctl() argument
946 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_mode_ioctl()
947 tty->driver->subtype == PTY_TYPE_MASTER) in tty_mode_ioctl()
948 real_tty = tty->link; in tty_mode_ioctl()
950 real_tty = tty; in tty_mode_ioctl()
1081 static int __tty_perform_flush(struct tty_struct *tty, unsigned long arg) in __tty_perform_flush() argument
1083 struct tty_ldisc *ld = tty->ldisc; in __tty_perform_flush()
1088 ld->ops->flush_buffer(tty); in __tty_perform_flush()
1089 tty_unthrottle(tty); in __tty_perform_flush()
1094 ld->ops->flush_buffer(tty); in __tty_perform_flush()
1095 tty_unthrottle(tty); in __tty_perform_flush()
1099 tty_driver_flush_buffer(tty); in __tty_perform_flush()
1107 int tty_perform_flush(struct tty_struct *tty, unsigned long arg) in tty_perform_flush() argument
1110 int retval = tty_check_change(tty); in tty_perform_flush()
1114 ld = tty_ldisc_ref_wait(tty); in tty_perform_flush()
1115 retval = __tty_perform_flush(tty, arg); in tty_perform_flush()
1122 int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file, in n_tty_ioctl_helper() argument
1129 retval = tty_check_change(tty); in n_tty_ioctl_helper()
1134 spin_lock_irq(&tty->flow_lock); in n_tty_ioctl_helper()
1135 if (!tty->flow_stopped) { in n_tty_ioctl_helper()
1136 tty->flow_stopped = 1; in n_tty_ioctl_helper()
1137 __stop_tty(tty); in n_tty_ioctl_helper()
1139 spin_unlock_irq(&tty->flow_lock); in n_tty_ioctl_helper()
1142 spin_lock_irq(&tty->flow_lock); in n_tty_ioctl_helper()
1143 if (tty->flow_stopped) { in n_tty_ioctl_helper()
1144 tty->flow_stopped = 0; in n_tty_ioctl_helper()
1145 __start_tty(tty); in n_tty_ioctl_helper()
1147 spin_unlock_irq(&tty->flow_lock); in n_tty_ioctl_helper()
1150 if (STOP_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
1151 retval = tty_send_xchar(tty, STOP_CHAR(tty)); in n_tty_ioctl_helper()
1154 if (START_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
1155 retval = tty_send_xchar(tty, START_CHAR(tty)); in n_tty_ioctl_helper()
1162 retval = tty_check_change(tty); in n_tty_ioctl_helper()
1165 return __tty_perform_flush(tty, arg); in n_tty_ioctl_helper()
1168 return tty_mode_ioctl(tty, file, cmd, arg); in n_tty_ioctl_helper()
1174 long n_tty_compat_ioctl_helper(struct tty_struct *tty, struct file *file, in n_tty_compat_ioctl_helper() argument
1180 return tty_mode_ioctl(tty, file, cmd, (unsigned long) compat_ptr(arg)); in n_tty_compat_ioctl_helper()