Lines Matching refs:tty
265 static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) in tty_ldisc_assign() argument
268 tty->ldisc = *ld; in tty_ldisc_assign()
283 static int tty_ldisc_try(struct tty_struct *tty) in tty_ldisc_try() argument
290 ld = &tty->ldisc; in tty_ldisc_try()
291 if (test_bit(TTY_LDISC, &tty->flags)) { in tty_ldisc_try()
315 struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) in tty_ldisc_ref_wait() argument
318 wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); in tty_ldisc_ref_wait()
319 WARN_ON(tty->ldisc.refcount == 0); in tty_ldisc_ref_wait()
320 return &tty->ldisc; in tty_ldisc_ref_wait()
336 struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) in tty_ldisc_ref() argument
338 if (tty_ldisc_try(tty)) in tty_ldisc_ref()
339 return &tty->ldisc; in tty_ldisc_ref()
385 void tty_ldisc_enable(struct tty_struct *tty) in tty_ldisc_enable() argument
387 set_bit(TTY_LDISC, &tty->flags); in tty_ldisc_enable()
388 clear_bit(TTY_LDISC_CHANGING, &tty->flags); in tty_ldisc_enable()
404 static void tty_set_termios_ldisc(struct tty_struct *tty, int num) in tty_set_termios_ldisc() argument
406 mutex_lock(&tty->termios_mutex); in tty_set_termios_ldisc()
407 tty->termios->c_line = num; in tty_set_termios_ldisc()
408 mutex_unlock(&tty->termios_mutex); in tty_set_termios_ldisc()
421 static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old) in tty_ldisc_restore() argument
428 tty_ldisc_assign(tty, old); in tty_ldisc_restore()
429 tty_set_termios_ldisc(tty, old->ops->num); in tty_ldisc_restore()
430 if (old->ops->open && (old->ops->open(tty) < 0)) { in tty_ldisc_restore()
435 tty_ldisc_assign(tty, &new_ldisc); in tty_ldisc_restore()
436 tty_set_termios_ldisc(tty, N_TTY); in tty_ldisc_restore()
438 int r = new_ldisc.ops->open(tty); in tty_ldisc_restore()
442 tty_name(tty, buf), r); in tty_ldisc_restore()
459 int tty_set_ldisc(struct tty_struct *tty, int ldisc) in tty_set_ldisc() argument
478 tty_wait_until_sent(tty, 0); in tty_set_ldisc()
480 if (tty->ldisc.ops->num == ldisc) { in tty_set_ldisc()
490 tty->receive_room = 0; in tty_set_ldisc()
492 o_ldisc = tty->ldisc; in tty_set_ldisc()
493 o_tty = tty->link; in tty_set_ldisc()
505 clear_bit(TTY_LDISC, &tty->flags); in tty_set_ldisc()
510 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) { in tty_set_ldisc()
511 if (tty->ldisc.refcount) { in tty_set_ldisc()
523 if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0) in tty_set_ldisc()
539 if (test_bit(TTY_LDISC_CHANGING, &tty->flags)) { in tty_set_ldisc()
543 ld = tty_ldisc_ref_wait(tty); in tty_set_ldisc()
552 set_bit(TTY_LDISC_CHANGING, &tty->flags); in tty_set_ldisc()
563 work = cancel_delayed_work(&tty->buf.work); in tty_set_ldisc()
571 (o_ldisc.ops->close)(tty); in tty_set_ldisc()
574 tty_ldisc_assign(tty, &new_ldisc); in tty_set_ldisc()
575 tty_set_termios_ldisc(tty, ldisc); in tty_set_ldisc()
577 retval = (new_ldisc.ops->open)(tty); in tty_set_ldisc()
580 tty_ldisc_restore(tty, &o_ldisc); in tty_set_ldisc()
586 if (tty->ldisc.ops->num != o_ldisc.ops->num && tty->ops->set_ldisc) in tty_set_ldisc()
587 tty->ops->set_ldisc(tty); in tty_set_ldisc()
596 tty_ldisc_enable(tty); in tty_set_ldisc()
603 schedule_delayed_work(&tty->buf.work, 1); in tty_set_ldisc()
617 int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) in tty_ldisc_setup() argument
619 struct tty_ldisc *ld = &tty->ldisc; in tty_ldisc_setup()
623 retval = (ld->ops->open)(tty); in tty_ldisc_setup()
631 (ld->ops->close)(tty); in tty_ldisc_setup()
636 tty_ldisc_enable(tty); in tty_ldisc_setup()
649 void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) in tty_ldisc_release() argument
658 clear_bit(TTY_LDISC, &tty->flags); in tty_ldisc_release()
659 cancel_delayed_work(&tty->buf.work); in tty_ldisc_release()
673 while (tty->ldisc.refcount) { in tty_ldisc_release()
675 wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0); in tty_ldisc_release()
684 if (tty->ldisc.ops->close) in tty_ldisc_release()
685 (tty->ldisc.ops->close)(tty); in tty_ldisc_release()
686 tty_ldisc_put(tty->ldisc.ops); in tty_ldisc_release()
692 tty_ldisc_assign(tty, &ld); in tty_ldisc_release()
693 tty_set_termios_ldisc(tty, N_TTY); in tty_ldisc_release()
714 void tty_ldisc_init(struct tty_struct *tty) in tty_ldisc_init() argument
719 tty_ldisc_assign(tty, &ld); in tty_ldisc_init()