Lines Matching refs:tty

32 # define tty_debug_wait_until_sent(tty, f, args...)    tty_debug(tty, f, ##args)  argument
34 # define tty_debug_wait_until_sent(tty, f, args...) do {} while (0) argument
57 unsigned int tty_chars_in_buffer(struct tty_struct *tty) in tty_chars_in_buffer() argument
59 if (tty->ops->chars_in_buffer) in tty_chars_in_buffer()
60 return tty->ops->chars_in_buffer(tty); in tty_chars_in_buffer()
76 unsigned int tty_write_room(struct tty_struct *tty) in tty_write_room() argument
78 if (tty->ops->write_room) in tty_write_room()
79 return tty->ops->write_room(tty); in tty_write_room()
92 void tty_driver_flush_buffer(struct tty_struct *tty) in tty_driver_flush_buffer() argument
94 if (tty->ops->flush_buffer) in tty_driver_flush_buffer()
95 tty->ops->flush_buffer(tty); in tty_driver_flush_buffer()
112 void tty_unthrottle(struct tty_struct *tty) in tty_unthrottle() argument
114 down_write(&tty->termios_rwsem); in tty_unthrottle()
115 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && in tty_unthrottle()
116 tty->ops->unthrottle) in tty_unthrottle()
117 tty->ops->unthrottle(tty); in tty_unthrottle()
118 tty->flow_change = 0; in tty_unthrottle()
119 up_write(&tty->termios_rwsem); in tty_unthrottle()
136 int tty_throttle_safe(struct tty_struct *tty) in tty_throttle_safe() argument
140 mutex_lock(&tty->throttle_mutex); in tty_throttle_safe()
141 if (!tty_throttled(tty)) { in tty_throttle_safe()
142 if (tty->flow_change != TTY_THROTTLE_SAFE) in tty_throttle_safe()
145 set_bit(TTY_THROTTLED, &tty->flags); in tty_throttle_safe()
146 if (tty->ops->throttle) in tty_throttle_safe()
147 tty->ops->throttle(tty); in tty_throttle_safe()
150 mutex_unlock(&tty->throttle_mutex); in tty_throttle_safe()
167 int tty_unthrottle_safe(struct tty_struct *tty) in tty_unthrottle_safe() argument
171 mutex_lock(&tty->throttle_mutex); in tty_unthrottle_safe()
172 if (tty_throttled(tty)) { in tty_unthrottle_safe()
173 if (tty->flow_change != TTY_UNTHROTTLE_SAFE) in tty_unthrottle_safe()
176 clear_bit(TTY_THROTTLED, &tty->flags); in tty_unthrottle_safe()
177 if (tty->ops->unthrottle) in tty_unthrottle_safe()
178 tty->ops->unthrottle(tty); in tty_unthrottle_safe()
181 mutex_unlock(&tty->throttle_mutex); in tty_unthrottle_safe()
197 void tty_wait_until_sent(struct tty_struct *tty, long timeout) in tty_wait_until_sent() argument
199 tty_debug_wait_until_sent(tty, "wait until sent, timeout=%ld\n", timeout); in tty_wait_until_sent()
204 timeout = wait_event_interruptible_timeout(tty->write_wait, in tty_wait_until_sent()
205 !tty_chars_in_buffer(tty), timeout); in tty_wait_until_sent()
212 if (tty->ops->wait_until_sent) in tty_wait_until_sent()
213 tty->ops->wait_until_sent(tty, timeout); in tty_wait_until_sent()
222 static void unset_locked_termios(struct tty_struct *tty, struct ktermios *old) in unset_locked_termios() argument
224 struct ktermios *termios = &tty->termios; in unset_locked_termios()
225 struct ktermios *locked = &tty->termios_locked; in unset_locked_termios()
338 int tty_set_termios(struct tty_struct *tty, struct ktermios *new_termios) in tty_set_termios() argument
343 WARN_ON(tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_set_termios()
344 tty->driver->subtype == PTY_TYPE_MASTER); in tty_set_termios()
352 down_write(&tty->termios_rwsem); in tty_set_termios()
353 old_termios = tty->termios; in tty_set_termios()
354 tty->termios = *new_termios; in tty_set_termios()
355 unset_locked_termios(tty, &old_termios); in tty_set_termios()
357 if (tty->ops->set_termios) in tty_set_termios()
358 tty->ops->set_termios(tty, &old_termios); in tty_set_termios()
360 tty_termios_copy_hw(&tty->termios, &old_termios); in tty_set_termios()
362 ld = tty_ldisc_ref(tty); in tty_set_termios()
365 ld->ops->set_termios(tty, &old_termios); in tty_set_termios()
368 up_write(&tty->termios_rwsem); in tty_set_termios()
386 static int set_termios(struct tty_struct *tty, void __user *arg, int opt) in set_termios() argument
390 int retval = tty_check_change(tty); in set_termios()
395 down_read(&tty->termios_rwsem); in set_termios()
396 tmp_termios = tty->termios; in set_termios()
397 up_read(&tty->termios_rwsem); in set_termios()
424 ld = tty_ldisc_ref(tty);
428 ld->ops->flush_buffer(tty);
433 tty_wait_until_sent(tty, 0);
438 tty_set_termios(tty, &tmp_termios);
447 static void copy_termios(struct tty_struct *tty, struct ktermios *kterm) in copy_termios() argument
449 down_read(&tty->termios_rwsem); in copy_termios()
450 *kterm = tty->termios; in copy_termios()
451 up_read(&tty->termios_rwsem); in copy_termios()
454 static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm) in copy_termios_locked() argument
456 down_read(&tty->termios_rwsem); in copy_termios_locked()
457 *kterm = tty->termios_locked; in copy_termios_locked()
458 up_read(&tty->termios_rwsem); in copy_termios_locked()
461 static int get_termio(struct tty_struct *tty, struct termio __user *termio) in get_termio() argument
464 copy_termios(tty, &kterm); in get_termio()
476 static int get_sgflags(struct tty_struct *tty) in get_sgflags() argument
480 if (!L_ICANON(tty)) { in get_sgflags()
481 if (L_ISIG(tty)) in get_sgflags()
486 if (L_ECHO(tty)) in get_sgflags()
488 if (O_OPOST(tty)) in get_sgflags()
489 if (O_ONLCR(tty)) in get_sgflags()
494 static int get_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in get_sgttyb() argument
498 down_read(&tty->termios_rwsem); in get_sgttyb()
499 tmp.sg_ispeed = tty->termios.c_ispeed; in get_sgttyb()
500 tmp.sg_ospeed = tty->termios.c_ospeed; in get_sgttyb()
501 tmp.sg_erase = tty->termios.c_cc[VERASE]; in get_sgttyb()
502 tmp.sg_kill = tty->termios.c_cc[VKILL]; in get_sgttyb()
503 tmp.sg_flags = get_sgflags(tty); in get_sgttyb()
504 up_read(&tty->termios_rwsem); in get_sgttyb()
546 static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) in set_sgttyb() argument
552 retval = tty_check_change(tty); in set_sgttyb()
559 down_write(&tty->termios_rwsem); in set_sgttyb()
560 termios = tty->termios; in set_sgttyb()
569 up_write(&tty->termios_rwsem); in set_sgttyb()
570 tty_set_termios(tty, &termios); in set_sgttyb()
576 static int get_tchars(struct tty_struct *tty, struct tchars __user *tchars) in get_tchars() argument
580 down_read(&tty->termios_rwsem); in get_tchars()
581 tmp.t_intrc = tty->termios.c_cc[VINTR]; in get_tchars()
582 tmp.t_quitc = tty->termios.c_cc[VQUIT]; in get_tchars()
583 tmp.t_startc = tty->termios.c_cc[VSTART]; in get_tchars()
584 tmp.t_stopc = tty->termios.c_cc[VSTOP]; in get_tchars()
585 tmp.t_eofc = tty->termios.c_cc[VEOF]; in get_tchars()
586 tmp.t_brkc = tty->termios.c_cc[VEOL2]; /* what is brkc anyway? */ in get_tchars()
587 up_read(&tty->termios_rwsem); in get_tchars()
591 static int set_tchars(struct tty_struct *tty, struct tchars __user *tchars) in set_tchars() argument
597 down_write(&tty->termios_rwsem); in set_tchars()
598 tty->termios.c_cc[VINTR] = tmp.t_intrc; in set_tchars()
599 tty->termios.c_cc[VQUIT] = tmp.t_quitc; in set_tchars()
600 tty->termios.c_cc[VSTART] = tmp.t_startc; in set_tchars()
601 tty->termios.c_cc[VSTOP] = tmp.t_stopc; in set_tchars()
602 tty->termios.c_cc[VEOF] = tmp.t_eofc; in set_tchars()
603 tty->termios.c_cc[VEOL2] = tmp.t_brkc; /* what is brkc anyway? */ in set_tchars()
604 up_write(&tty->termios_rwsem); in set_tchars()
610 static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in get_ltchars() argument
614 down_read(&tty->termios_rwsem); in get_ltchars()
615 tmp.t_suspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
617 tmp.t_dsuspc = tty->termios.c_cc[VSUSP]; in get_ltchars()
618 tmp.t_rprntc = tty->termios.c_cc[VREPRINT]; in get_ltchars()
620 tmp.t_flushc = tty->termios.c_cc[VEOL2]; in get_ltchars()
621 tmp.t_werasc = tty->termios.c_cc[VWERASE]; in get_ltchars()
622 tmp.t_lnextc = tty->termios.c_cc[VLNEXT]; in get_ltchars()
623 up_read(&tty->termios_rwsem); in get_ltchars()
627 static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars) in set_ltchars() argument
634 down_write(&tty->termios_rwsem); in set_ltchars()
635 tty->termios.c_cc[VSUSP] = tmp.t_suspc; in set_ltchars()
637 tty->termios.c_cc[VEOL2] = tmp.t_dsuspc; in set_ltchars()
638 tty->termios.c_cc[VREPRINT] = tmp.t_rprntc; in set_ltchars()
640 tty->termios.c_cc[VEOL2] = tmp.t_flushc; in set_ltchars()
641 tty->termios.c_cc[VWERASE] = tmp.t_werasc; in set_ltchars()
642 tty->termios.c_cc[VLNEXT] = tmp.t_lnextc; in set_ltchars()
643 up_write(&tty->termios_rwsem); in set_ltchars()
657 static int tty_change_softcar(struct tty_struct *tty, int arg) in tty_change_softcar() argument
663 down_write(&tty->termios_rwsem); in tty_change_softcar()
664 old = tty->termios; in tty_change_softcar()
665 tty->termios.c_cflag &= ~CLOCAL; in tty_change_softcar()
666 tty->termios.c_cflag |= bit; in tty_change_softcar()
667 if (tty->ops->set_termios) in tty_change_softcar()
668 tty->ops->set_termios(tty, &old); in tty_change_softcar()
669 if (C_CLOCAL(tty) != bit) in tty_change_softcar()
671 up_write(&tty->termios_rwsem); in tty_change_softcar()
686 int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) in tty_mode_ioctl() argument
693 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && in tty_mode_ioctl()
694 tty->driver->subtype == PTY_TYPE_MASTER) in tty_mode_ioctl()
695 real_tty = tty->link; in tty_mode_ioctl()
697 real_tty = tty; in tty_mode_ioctl()
816 static int __tty_perform_flush(struct tty_struct *tty, unsigned long arg) in __tty_perform_flush() argument
818 struct tty_ldisc *ld = tty->ldisc; in __tty_perform_flush()
823 ld->ops->flush_buffer(tty); in __tty_perform_flush()
824 tty_unthrottle(tty); in __tty_perform_flush()
829 ld->ops->flush_buffer(tty); in __tty_perform_flush()
830 tty_unthrottle(tty); in __tty_perform_flush()
834 tty_driver_flush_buffer(tty); in __tty_perform_flush()
842 int tty_perform_flush(struct tty_struct *tty, unsigned long arg) in tty_perform_flush() argument
845 int retval = tty_check_change(tty); in tty_perform_flush()
849 ld = tty_ldisc_ref_wait(tty); in tty_perform_flush()
850 retval = __tty_perform_flush(tty, arg); in tty_perform_flush()
857 int n_tty_ioctl_helper(struct tty_struct *tty, unsigned int cmd, in n_tty_ioctl_helper() argument
864 retval = tty_check_change(tty); in n_tty_ioctl_helper()
869 spin_lock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
870 if (!tty->flow.tco_stopped) { in n_tty_ioctl_helper()
871 tty->flow.tco_stopped = true; in n_tty_ioctl_helper()
872 __stop_tty(tty); in n_tty_ioctl_helper()
874 spin_unlock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
877 spin_lock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
878 if (tty->flow.tco_stopped) { in n_tty_ioctl_helper()
879 tty->flow.tco_stopped = false; in n_tty_ioctl_helper()
880 __start_tty(tty); in n_tty_ioctl_helper()
882 spin_unlock_irq(&tty->flow.lock); in n_tty_ioctl_helper()
885 if (STOP_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
886 retval = tty_send_xchar(tty, STOP_CHAR(tty)); in n_tty_ioctl_helper()
889 if (START_CHAR(tty) != __DISABLED_CHAR) in n_tty_ioctl_helper()
890 retval = tty_send_xchar(tty, START_CHAR(tty)); in n_tty_ioctl_helper()
897 retval = tty_check_change(tty); in n_tty_ioctl_helper()
900 return __tty_perform_flush(tty, arg); in n_tty_ioctl_helper()
903 return tty_mode_ioctl(tty, cmd, arg); in n_tty_ioctl_helper()