Lines Matching refs:tty

33 # define tty_debug_wait_until_sent(tty, f, args...)    tty_debug(tty, f, ##args)  argument
35 # define tty_debug_wait_until_sent(tty, f, args...) do {} while (0) argument
58 unsigned int tty_chars_in_buffer(struct tty_struct *tty) in tty_chars_in_buffer() argument
60 if (tty->ops->chars_in_buffer) in tty_chars_in_buffer()
61 return tty->ops->chars_in_buffer(tty); in tty_chars_in_buffer()
77 unsigned int tty_write_room(struct tty_struct *tty) in tty_write_room() argument
79 if (tty->ops->write_room) in tty_write_room()
80 return tty->ops->write_room(tty); in tty_write_room()
93 void tty_driver_flush_buffer(struct tty_struct *tty) in tty_driver_flush_buffer() argument
95 if (tty->ops->flush_buffer) in tty_driver_flush_buffer()
96 tty->ops->flush_buffer(tty); in tty_driver_flush_buffer()
113 void tty_unthrottle(struct tty_struct *tty) in tty_unthrottle() argument
115 down_write(&tty->termios_rwsem); in tty_unthrottle()
116 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && in tty_unthrottle()
117 tty->ops->unthrottle) in tty_unthrottle()
118 tty->ops->unthrottle(tty); in tty_unthrottle()
119 tty->flow_change = 0; in tty_unthrottle()
120 up_write(&tty->termios_rwsem); in tty_unthrottle()
137 int tty_throttle_safe(struct tty_struct *tty) in tty_throttle_safe() argument
141 mutex_lock(&tty->throttle_mutex); in tty_throttle_safe()
142 if (!tty_throttled(tty)) { in tty_throttle_safe()
143 if (tty->flow_change != TTY_THROTTLE_SAFE) in tty_throttle_safe()
146 set_bit(TTY_THROTTLED, &tty->flags); in tty_throttle_safe()
147 if (tty->ops->throttle) in tty_throttle_safe()
148 tty->ops->throttle(tty); in tty_throttle_safe()
151 mutex_unlock(&tty->throttle_mutex); in tty_throttle_safe()
168 int tty_unthrottle_safe(struct tty_struct *tty) in tty_unthrottle_safe() argument
172 mutex_lock(&tty->throttle_mutex); in tty_unthrottle_safe()
173 if (tty_throttled(tty)) { in tty_unthrottle_safe()
174 if (tty->flow_change != TTY_UNTHROTTLE_SAFE) in tty_unthrottle_safe()
177 clear_bit(TTY_THROTTLED, &tty->flags); in tty_unthrottle_safe()
178 if (tty->ops->unthrottle) in tty_unthrottle_safe()
179 tty->ops->unthrottle(tty); in tty_unthrottle_safe()
182 mutex_unlock(&tty->throttle_mutex); in tty_unthrottle_safe()
198 void tty_wait_until_sent(struct tty_struct *tty, long timeout) in tty_wait_until_sent() argument
200 tty_debug_wait_until_sent(tty, "wait until sent, timeout=%ld\n", timeout); in tty_wait_until_sent()
205 timeout = wait_event_interruptible_timeout(tty->write_wait, in tty_wait_until_sent()
206 !tty_chars_in_buffer(tty), timeout); in tty_wait_until_sent()
213 if (tty->ops->wait_until_sent) in tty_wait_until_sent()
214 tty->ops->wait_until_sent(tty, timeout); in tty_wait_until_sent()
223 static void unset_locked_termios(struct tty_struct *tty, const struct ktermios *old) in unset_locked_termios() argument
225 struct ktermios *termios = &tty->termios; in unset_locked_termios()
226 struct ktermios *locked = &tty->termios_locked; in unset_locked_termios()
341 int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) in tty_set_termios() argument
346 WARN_ON(tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_set_termios()
347 tty->driver->subtype == PTY_TYPE_MASTER); in tty_set_termios()
355 down_write(&tty->termios_rwsem); in tty_set_termios()
356 old_termios = tty->termios; in tty_set_termios()
357 tty->termios = *new_termios; in tty_set_termios()
358 unset_locked_termios(tty, &old_termios); in tty_set_termios()
360 tty->termios.c_cflag ^= (tty->termios.c_cflag ^ old_termios.c_cflag) & ADDRB; in tty_set_termios()
362 if (tty->ops->set_termios) in tty_set_termios()
363 tty->ops->set_termios(tty, &old_termios); in tty_set_termios()
365 tty_termios_copy_hw(&tty->termios, &old_termios); in tty_set_termios()
367 ld = tty_ldisc_ref(tty); in tty_set_termios()
370 ld->ops->set_termios(tty, &old_termios); in tty_set_termios()
373 up_write(&tty->termios_rwsem); in tty_set_termios()
465 static int set_termios(struct tty_struct *tty, void __user *arg, int opt) in set_termios() argument
469 int retval = tty_check_change(tty); in set_termios()
474 down_read(&tty->termios_rwsem); in set_termios()
475 tmp_termios = tty->termios; in set_termios()
476 up_read(&tty->termios_rwsem); in set_termios()
503 ld = tty_ldisc_ref(tty);
507 ld->ops->flush_buffer(tty);
512 tty_wait_until_sent(tty, 0);
517 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()
734 static int tty_change_softcar(struct tty_struct *tty, int arg) in tty_change_softcar() argument
740 down_write(&tty->termios_rwsem); in tty_change_softcar()
741 old = tty->termios; in tty_change_softcar()
742 tty->termios.c_cflag &= ~CLOCAL; in tty_change_softcar()
743 tty->termios.c_cflag |= bit; in tty_change_softcar()
744 if (tty->ops->set_termios) in tty_change_softcar()
745 tty->ops->set_termios(tty, &old); in tty_change_softcar()
746 if (C_CLOCAL(tty) != bit) in tty_change_softcar()
748 up_write(&tty->termios_rwsem); in tty_change_softcar()
763 int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) in tty_mode_ioctl() argument
770 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_mode_ioctl()
771 tty->driver->subtype == PTY_TYPE_MASTER) in tty_mode_ioctl()
772 real_tty = tty->link; in tty_mode_ioctl()
774 real_tty = tty; in tty_mode_ioctl()
893 static int __tty_perform_flush(struct tty_struct *tty, unsigned long arg) in __tty_perform_flush() argument
895 struct tty_ldisc *ld = tty->ldisc; in __tty_perform_flush()
900 ld->ops->flush_buffer(tty); in __tty_perform_flush()
901 tty_unthrottle(tty); in __tty_perform_flush()
906 ld->ops->flush_buffer(tty); in __tty_perform_flush()
907 tty_unthrottle(tty); in __tty_perform_flush()
911 tty_driver_flush_buffer(tty); in __tty_perform_flush()
919 int tty_perform_flush(struct tty_struct *tty, unsigned long arg) in tty_perform_flush() argument
922 int retval = tty_check_change(tty); in tty_perform_flush()
926 ld = tty_ldisc_ref_wait(tty); in tty_perform_flush()
927 retval = __tty_perform_flush(tty, arg); in tty_perform_flush()
934 int n_tty_ioctl_helper(struct tty_struct *tty, unsigned int cmd, in n_tty_ioctl_helper() argument
941 retval = tty_check_change(tty); in n_tty_ioctl_helper()
946 spin_lock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
947 if (!tty->flow.tco_stopped) { in n_tty_ioctl_helper()
948 tty->flow.tco_stopped = true; in n_tty_ioctl_helper()
949 __stop_tty(tty); in n_tty_ioctl_helper()
951 spin_unlock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
954 spin_lock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
955 if (tty->flow.tco_stopped) { in n_tty_ioctl_helper()
956 tty->flow.tco_stopped = false; in n_tty_ioctl_helper()
957 __start_tty(tty); in n_tty_ioctl_helper()
959 spin_unlock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
962 if (STOP_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
963 retval = tty_send_xchar(tty, STOP_CHAR(tty)); in n_tty_ioctl_helper()
966 if (START_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
967 retval = tty_send_xchar(tty, START_CHAR(tty)); in n_tty_ioctl_helper()
974 retval = tty_check_change(tty); in n_tty_ioctl_helper()
977 return __tty_perform_flush(tty, arg); in n_tty_ioctl_helper()
980 return tty_mode_ioctl(tty, cmd, arg); in n_tty_ioctl_helper()