Lines Matching refs:tty
51 unsigned int tty_chars_in_buffer(struct tty_struct *tty) in tty_chars_in_buffer() argument
53 if (tty->ops->chars_in_buffer) in tty_chars_in_buffer()
54 return tty->ops->chars_in_buffer(tty); in tty_chars_in_buffer()
70 unsigned int tty_write_room(struct tty_struct *tty) in tty_write_room() argument
72 if (tty->ops->write_room) in tty_write_room()
73 return tty->ops->write_room(tty); in tty_write_room()
86 void tty_driver_flush_buffer(struct tty_struct *tty) in tty_driver_flush_buffer() argument
88 if (tty->ops->flush_buffer) in tty_driver_flush_buffer()
89 tty->ops->flush_buffer(tty); in tty_driver_flush_buffer()
106 void tty_unthrottle(struct tty_struct *tty) in tty_unthrottle() argument
108 down_write(&tty->termios_rwsem); in tty_unthrottle()
109 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && in tty_unthrottle()
110 tty->ops->unthrottle) in tty_unthrottle()
111 tty->ops->unthrottle(tty); in tty_unthrottle()
112 tty->flow_change = 0; in tty_unthrottle()
113 up_write(&tty->termios_rwsem); in tty_unthrottle()
130 int tty_throttle_safe(struct tty_struct *tty) in tty_throttle_safe() argument
134 mutex_lock(&tty->throttle_mutex); in tty_throttle_safe()
135 if (!tty_throttled(tty)) { in tty_throttle_safe()
136 if (tty->flow_change != TTY_THROTTLE_SAFE) in tty_throttle_safe()
139 set_bit(TTY_THROTTLED, &tty->flags); in tty_throttle_safe()
140 if (tty->ops->throttle) in tty_throttle_safe()
141 tty->ops->throttle(tty); in tty_throttle_safe()
144 mutex_unlock(&tty->throttle_mutex); in tty_throttle_safe()
161 int tty_unthrottle_safe(struct tty_struct *tty) in tty_unthrottle_safe() argument
165 mutex_lock(&tty->throttle_mutex); in tty_unthrottle_safe()
166 if (tty_throttled(tty)) { in tty_unthrottle_safe()
167 if (tty->flow_change != TTY_UNTHROTTLE_SAFE) in tty_unthrottle_safe()
170 clear_bit(TTY_THROTTLED, &tty->flags); in tty_unthrottle_safe()
171 if (tty->ops->unthrottle) in tty_unthrottle_safe()
172 tty->ops->unthrottle(tty); in tty_unthrottle_safe()
175 mutex_unlock(&tty->throttle_mutex); in tty_unthrottle_safe()
191 void tty_wait_until_sent(struct tty_struct *tty, long timeout) in tty_wait_until_sent() argument
196 timeout = wait_event_interruptible_timeout(tty->write_wait, in tty_wait_until_sent()
197 !tty_chars_in_buffer(tty), timeout); in tty_wait_until_sent()
204 if (tty->ops->wait_until_sent) in tty_wait_until_sent()
205 tty->ops->wait_until_sent(tty, timeout); in tty_wait_until_sent()
214 static void unset_locked_termios(struct tty_struct *tty, const struct ktermios *old) in unset_locked_termios() argument
216 struct ktermios *termios = &tty->termios; in unset_locked_termios()
217 struct ktermios *locked = &tty->termios_locked; in unset_locked_termios()
332 int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) in tty_set_termios() argument
337 WARN_ON(tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_set_termios()
338 tty->driver->subtype == PTY_TYPE_MASTER); in tty_set_termios()
346 down_write(&tty->termios_rwsem); in tty_set_termios()
347 old_termios = tty->termios; in tty_set_termios()
348 tty->termios = *new_termios; in tty_set_termios()
349 unset_locked_termios(tty, &old_termios); in tty_set_termios()
351 tty->termios.c_cflag ^= (tty->termios.c_cflag ^ old_termios.c_cflag) & ADDRB; in tty_set_termios()
353 if (tty->ops->set_termios) in tty_set_termios()
354 tty->ops->set_termios(tty, &old_termios); in tty_set_termios()
356 tty_termios_copy_hw(&tty->termios, &old_termios); in tty_set_termios()
358 ld = tty_ldisc_ref(tty); in tty_set_termios()
361 ld->ops->set_termios(tty, &old_termios); in tty_set_termios()
364 up_write(&tty->termios_rwsem); in tty_set_termios()
456 static int set_termios(struct tty_struct *tty, void __user *arg, int opt) in set_termios() argument
460 int retval = tty_check_change(tty); in set_termios()
465 down_read(&tty->termios_rwsem); in set_termios()
466 tmp_termios = tty->termios; in set_termios()
467 up_read(&tty->termios_rwsem); in set_termios()
496 retval = wait_event_interruptible(tty->write_wait, !tty_chars_in_buffer(tty));
500 if (tty_write_lock(tty, false) < 0)
504 if (tty_chars_in_buffer(tty)) {
505 tty_write_unlock(tty);
509 ld = tty_ldisc_ref(tty);
512 ld->ops->flush_buffer(tty);
516 if ((opt & TERMIOS_WAIT) && tty->ops->wait_until_sent) {
517 tty->ops->wait_until_sent(tty, 0);
519 tty_write_unlock(tty);
524 tty_set_termios(tty, &tmp_termios);
526 tty_write_unlock(tty);
528 tty_set_termios(tty, &tmp_termios);
538 static void copy_termios(struct tty_struct *tty, struct ktermios *kterm) in copy_termios() argument
540 down_read(&tty->termios_rwsem); in copy_termios()
541 *kterm = tty->termios; in copy_termios()
542 up_read(&tty->termios_rwsem); in copy_termios()
545 static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm) in copy_termios_locked() argument
547 down_read(&tty->termios_rwsem); in copy_termios_locked()
548 *kterm = tty->termios_locked; in copy_termios_locked()
549 up_read(&tty->termios_rwsem); in copy_termios_locked()
552 static int get_termio(struct tty_struct *tty, struct termio __user *termio) in get_termio() argument
555 copy_termios(tty, &kterm); in get_termio()
567 static int get_sgflags(struct tty_struct *tty) in get_sgflags() argument
571 if (!L_ICANON(tty)) { in get_sgflags()
572 if (L_ISIG(tty)) in get_sgflags()
577 if (L_ECHO(tty)) in get_sgflags()
579 if (O_OPOST(tty)) in get_sgflags()
580 if (O_ONLCR(tty)) in get_sgflags()
585 static int get_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in get_sgttyb() argument
589 down_read(&tty->termios_rwsem); in get_sgttyb()
590 tmp.sg_ispeed = tty->termios.c_ispeed; in get_sgttyb()
591 tmp.sg_ospeed = tty->termios.c_ospeed; in get_sgttyb()
592 tmp.sg_erase = tty->termios.c_cc[VERASE]; in get_sgttyb()
593 tmp.sg_kill = tty->termios.c_cc[VKILL]; in get_sgttyb()
594 tmp.sg_flags = get_sgflags(tty); in get_sgttyb()
595 up_read(&tty->termios_rwsem); in get_sgttyb()
637 static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in set_sgttyb() argument
643 retval = tty_check_change(tty); in set_sgttyb()
650 down_write(&tty->termios_rwsem); in set_sgttyb()
651 termios = tty->termios; in set_sgttyb()
658 up_write(&tty->termios_rwsem); in set_sgttyb()
659 tty_set_termios(tty, &termios); in set_sgttyb()
665 static int get_tchars(struct tty_struct *tty, struct tchars __user *tchars) in get_tchars() argument
669 down_read(&tty->termios_rwsem); in get_tchars()
670 tmp.t_intrc = tty->termios.c_cc[VINTR]; in get_tchars()
671 tmp.t_quitc = tty->termios.c_cc[VQUIT]; in get_tchars()
672 tmp.t_startc = tty->termios.c_cc[VSTART]; in get_tchars()
673 tmp.t_stopc = tty->termios.c_cc[VSTOP]; in get_tchars()
674 tmp.t_eofc = tty->termios.c_cc[VEOF]; in get_tchars()
675 tmp.t_brkc = tty->termios.c_cc[VEOL2]; /* what is brkc anyway? */ in get_tchars()
676 up_read(&tty->termios_rwsem); in get_tchars()
680 static int set_tchars(struct tty_struct *tty, struct tchars __user *tchars) in set_tchars() argument
686 down_write(&tty->termios_rwsem); in set_tchars()
687 tty->termios.c_cc[VINTR] = tmp.t_intrc; in set_tchars()
688 tty->termios.c_cc[VQUIT] = tmp.t_quitc; in set_tchars()
689 tty->termios.c_cc[VSTART] = tmp.t_startc; in set_tchars()
690 tty->termios.c_cc[VSTOP] = tmp.t_stopc; in set_tchars()
691 tty->termios.c_cc[VEOF] = tmp.t_eofc; in set_tchars()
692 tty->termios.c_cc[VEOL2] = tmp.t_brkc; /* what is brkc anyway? */ in set_tchars()
693 up_write(&tty->termios_rwsem); in set_tchars()
699 static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in get_ltchars() argument
703 down_read(&tty->termios_rwsem); in get_ltchars()
704 tmp.t_suspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
706 tmp.t_dsuspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
707 tmp.t_rprntc = tty->termios.c_cc[VREPRINT]; in get_ltchars()
709 tmp.t_flushc = tty->termios.c_cc[VEOL2]; in get_ltchars()
710 tmp.t_werasc = tty->termios.c_cc[VWERASE]; in get_ltchars()
711 tmp.t_lnextc = tty->termios.c_cc[VLNEXT]; in get_ltchars()
712 up_read(&tty->termios_rwsem); in get_ltchars()
716 static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in set_ltchars() argument
723 down_write(&tty->termios_rwsem); in set_ltchars()
724 tty->termios.c_cc[VSUSP] = tmp.t_suspc; in set_ltchars()
726 tty->termios.c_cc[VEOL2] = tmp.t_dsuspc; in set_ltchars()
727 tty->termios.c_cc[VREPRINT] = tmp.t_rprntc; in set_ltchars()
729 tty->termios.c_cc[VEOL2] = tmp.t_flushc; in set_ltchars()
730 tty->termios.c_cc[VWERASE] = tmp.t_werasc; in set_ltchars()
731 tty->termios.c_cc[VLNEXT] = tmp.t_lnextc; in set_ltchars()
732 up_write(&tty->termios_rwsem); in set_ltchars()
746 static int tty_change_softcar(struct tty_struct *tty, bool enable) in tty_change_softcar() argument
752 down_write(&tty->termios_rwsem); in tty_change_softcar()
753 old = tty->termios; in tty_change_softcar()
754 tty->termios.c_cflag &= ~CLOCAL; in tty_change_softcar()
755 tty->termios.c_cflag |= bit; in tty_change_softcar()
756 if (tty->ops->set_termios) in tty_change_softcar()
757 tty->ops->set_termios(tty, &old); in tty_change_softcar()
758 if (C_CLOCAL(tty) != bit) in tty_change_softcar()
760 up_write(&tty->termios_rwsem); in tty_change_softcar()
775 int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) in tty_mode_ioctl() argument
782 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_mode_ioctl()
783 tty->driver->subtype == PTY_TYPE_MASTER) in tty_mode_ioctl()
784 real_tty = tty->link; in tty_mode_ioctl()
786 real_tty = tty; in tty_mode_ioctl()
905 static int __tty_perform_flush(struct tty_struct *tty, unsigned long arg) in __tty_perform_flush() argument
907 struct tty_ldisc *ld = tty->ldisc; in __tty_perform_flush()
912 ld->ops->flush_buffer(tty); in __tty_perform_flush()
913 tty_unthrottle(tty); in __tty_perform_flush()
918 ld->ops->flush_buffer(tty); in __tty_perform_flush()
919 tty_unthrottle(tty); in __tty_perform_flush()
923 tty_driver_flush_buffer(tty); in __tty_perform_flush()
931 int tty_perform_flush(struct tty_struct *tty, unsigned long arg) in tty_perform_flush() argument
934 int retval = tty_check_change(tty); in tty_perform_flush()
938 ld = tty_ldisc_ref_wait(tty); in tty_perform_flush()
939 retval = __tty_perform_flush(tty, arg); in tty_perform_flush()
946 int n_tty_ioctl_helper(struct tty_struct *tty, unsigned int cmd, in n_tty_ioctl_helper() argument
953 retval = tty_check_change(tty); in n_tty_ioctl_helper()
958 spin_lock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
959 if (!tty->flow.tco_stopped) { in n_tty_ioctl_helper()
960 tty->flow.tco_stopped = true; in n_tty_ioctl_helper()
961 __stop_tty(tty); in n_tty_ioctl_helper()
963 spin_unlock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
966 spin_lock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
967 if (tty->flow.tco_stopped) { in n_tty_ioctl_helper()
968 tty->flow.tco_stopped = false; in n_tty_ioctl_helper()
969 __start_tty(tty); in n_tty_ioctl_helper()
971 spin_unlock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
974 if (STOP_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
975 retval = tty_send_xchar(tty, STOP_CHAR(tty)); in n_tty_ioctl_helper()
978 if (START_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
979 retval = tty_send_xchar(tty, START_CHAR(tty)); in n_tty_ioctl_helper()
986 retval = tty_check_change(tty); in n_tty_ioctl_helper()
989 return __tty_perform_flush(tty, arg); in n_tty_ioctl_helper()
992 return tty_mode_ioctl(tty, cmd, arg); in n_tty_ioctl_helper()