• Home
  • Raw
  • Download

Lines Matching refs:tty

26 #define tty_ldisc_debug(tty, f, args...)	tty_debug(tty, f, ##args)  argument
28 #define tty_ldisc_debug(tty, f, args...) argument
160 static struct tty_ldisc *tty_ldisc_get(struct tty_struct *tty, int disc) in tty_ldisc_get() argument
188 ld->tty = tty; in tty_ldisc_get()
262 struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) in tty_ldisc_ref_wait() argument
266 ldsem_down_read(&tty->ldisc_sem, MAX_SCHEDULE_TIMEOUT); in tty_ldisc_ref_wait()
267 ld = tty->ldisc; in tty_ldisc_ref_wait()
269 ldsem_up_read(&tty->ldisc_sem); in tty_ldisc_ref_wait()
283 struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) in tty_ldisc_ref() argument
287 if (ldsem_down_read_trylock(&tty->ldisc_sem)) { in tty_ldisc_ref()
288 ld = tty->ldisc; in tty_ldisc_ref()
290 ldsem_up_read(&tty->ldisc_sem); in tty_ldisc_ref()
306 ldsem_up_read(&ld->tty->ldisc_sem); in tty_ldisc_deref()
312 __tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout) in __tty_ldisc_lock() argument
314 return ldsem_down_write(&tty->ldisc_sem, timeout); in __tty_ldisc_lock()
318 __tty_ldisc_lock_nested(struct tty_struct *tty, unsigned long timeout) in __tty_ldisc_lock_nested() argument
320 return ldsem_down_write_nested(&tty->ldisc_sem, in __tty_ldisc_lock_nested()
324 static inline void __tty_ldisc_unlock(struct tty_struct *tty) in __tty_ldisc_unlock() argument
326 ldsem_up_write(&tty->ldisc_sem); in __tty_ldisc_unlock()
329 int tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout) in tty_ldisc_lock() argument
334 set_bit(TTY_LDISC_CHANGING, &tty->flags); in tty_ldisc_lock()
335 wake_up_interruptible_all(&tty->read_wait); in tty_ldisc_lock()
336 wake_up_interruptible_all(&tty->write_wait); in tty_ldisc_lock()
338 ret = __tty_ldisc_lock(tty, timeout); in tty_ldisc_lock()
341 set_bit(TTY_LDISC_HALTED, &tty->flags); in tty_ldisc_lock()
345 void tty_ldisc_unlock(struct tty_struct *tty) in tty_ldisc_unlock() argument
347 clear_bit(TTY_LDISC_HALTED, &tty->flags); in tty_ldisc_unlock()
349 clear_bit(TTY_LDISC_CHANGING, &tty->flags); in tty_ldisc_unlock()
350 __tty_ldisc_unlock(tty); in tty_ldisc_unlock()
354 tty_ldisc_lock_pair_timeout(struct tty_struct *tty, struct tty_struct *tty2, in tty_ldisc_lock_pair_timeout() argument
359 if (tty < tty2) { in tty_ldisc_lock_pair_timeout()
360 ret = __tty_ldisc_lock(tty, timeout); in tty_ldisc_lock_pair_timeout()
364 __tty_ldisc_unlock(tty); in tty_ldisc_lock_pair_timeout()
368 WARN_ON_ONCE(tty == tty2); in tty_ldisc_lock_pair_timeout()
369 if (tty2 && tty != tty2) { in tty_ldisc_lock_pair_timeout()
372 ret = __tty_ldisc_lock_nested(tty, timeout); in tty_ldisc_lock_pair_timeout()
377 ret = __tty_ldisc_lock(tty, timeout); in tty_ldisc_lock_pair_timeout()
383 set_bit(TTY_LDISC_HALTED, &tty->flags); in tty_ldisc_lock_pair_timeout()
389 static void tty_ldisc_lock_pair(struct tty_struct *tty, struct tty_struct *tty2) in tty_ldisc_lock_pair() argument
391 tty_ldisc_lock_pair_timeout(tty, tty2, MAX_SCHEDULE_TIMEOUT); in tty_ldisc_lock_pair()
394 static void tty_ldisc_unlock_pair(struct tty_struct *tty, in tty_ldisc_unlock_pair() argument
397 __tty_ldisc_unlock(tty); in tty_ldisc_unlock_pair()
410 void tty_ldisc_flush(struct tty_struct *tty) in tty_ldisc_flush() argument
412 struct tty_ldisc *ld = tty_ldisc_ref(tty); in tty_ldisc_flush()
414 tty_buffer_flush(tty, ld); in tty_ldisc_flush()
436 static void tty_set_termios_ldisc(struct tty_struct *tty, int disc) in tty_set_termios_ldisc() argument
438 down_write(&tty->termios_rwsem); in tty_set_termios_ldisc()
439 tty->termios.c_line = disc; in tty_set_termios_ldisc()
440 up_write(&tty->termios_rwsem); in tty_set_termios_ldisc()
442 tty->disc_data = NULL; in tty_set_termios_ldisc()
443 tty->receive_room = 0; in tty_set_termios_ldisc()
457 static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld) in tty_ldisc_open() argument
459 WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags)); in tty_ldisc_open()
463 ret = ld->ops->open(tty); in tty_ldisc_open()
465 clear_bit(TTY_LDISC_OPEN, &tty->flags); in tty_ldisc_open()
467 tty_ldisc_debug(tty, "%p: opened\n", ld); in tty_ldisc_open()
482 static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld) in tty_ldisc_close() argument
484 lockdep_assert_held_write(&tty->ldisc_sem); in tty_ldisc_close()
485 WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags)); in tty_ldisc_close()
486 clear_bit(TTY_LDISC_OPEN, &tty->flags); in tty_ldisc_close()
488 ld->ops->close(tty); in tty_ldisc_close()
489 tty_ldisc_debug(tty, "%p: closed\n", ld); in tty_ldisc_close()
501 static int tty_ldisc_failto(struct tty_struct *tty, int ld) in tty_ldisc_failto() argument
503 struct tty_ldisc *disc = tty_ldisc_get(tty, ld); in tty_ldisc_failto()
506 lockdep_assert_held_write(&tty->ldisc_sem); in tty_ldisc_failto()
509 tty->ldisc = disc; in tty_ldisc_failto()
510 tty_set_termios_ldisc(tty, ld); in tty_ldisc_failto()
511 if ((r = tty_ldisc_open(tty, disc)) < 0) in tty_ldisc_failto()
525 static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old) in tty_ldisc_restore() argument
528 if (tty_ldisc_failto(tty, old->ops->num) < 0) { in tty_ldisc_restore()
529 const char *name = tty_name(tty); in tty_ldisc_restore()
535 if (tty_ldisc_failto(tty, N_TTY) < 0 && in tty_ldisc_restore()
536 tty_ldisc_failto(tty, N_NULL) < 0) in tty_ldisc_restore()
552 int tty_set_ldisc(struct tty_struct *tty, int disc) in tty_set_ldisc() argument
557 new_ldisc = tty_ldisc_get(tty, disc); in tty_set_ldisc()
561 tty_lock(tty); in tty_set_ldisc()
562 retval = tty_ldisc_lock(tty, 5 * HZ); in tty_set_ldisc()
566 if (!tty->ldisc) { in tty_set_ldisc()
572 if (tty->ldisc->ops->num == disc) in tty_set_ldisc()
575 if (test_bit(TTY_HUPPED, &tty->flags)) { in tty_set_ldisc()
581 old_ldisc = tty->ldisc; in tty_set_ldisc()
584 tty_ldisc_close(tty, old_ldisc); in tty_set_ldisc()
587 tty->ldisc = new_ldisc; in tty_set_ldisc()
588 tty_set_termios_ldisc(tty, disc); in tty_set_ldisc()
590 retval = tty_ldisc_open(tty, new_ldisc); in tty_set_ldisc()
594 tty_ldisc_restore(tty, old_ldisc); in tty_set_ldisc()
597 if (tty->ldisc->ops->num != old_ldisc->ops->num && tty->ops->set_ldisc) { in tty_set_ldisc()
598 down_read(&tty->termios_rwsem); in tty_set_ldisc()
599 tty->ops->set_ldisc(tty); in tty_set_ldisc()
600 up_read(&tty->termios_rwsem); in tty_set_ldisc()
610 tty_ldisc_unlock(tty); in tty_set_ldisc()
614 tty_buffer_restart_work(tty->port); in tty_set_ldisc()
617 tty_unlock(tty); in tty_set_ldisc()
628 static void tty_ldisc_kill(struct tty_struct *tty) in tty_ldisc_kill() argument
630 lockdep_assert_held_write(&tty->ldisc_sem); in tty_ldisc_kill()
631 if (!tty->ldisc) in tty_ldisc_kill()
636 tty_ldisc_close(tty, tty->ldisc); in tty_ldisc_kill()
637 tty_ldisc_put(tty->ldisc); in tty_ldisc_kill()
639 tty->ldisc = NULL; in tty_ldisc_kill()
649 static void tty_reset_termios(struct tty_struct *tty) in tty_reset_termios() argument
651 down_write(&tty->termios_rwsem); in tty_reset_termios()
652 tty->termios = tty->driver->init_termios; in tty_reset_termios()
653 tty->termios.c_ispeed = tty_termios_input_baud_rate(&tty->termios); in tty_reset_termios()
654 tty->termios.c_ospeed = tty_termios_baud_rate(&tty->termios); in tty_reset_termios()
655 up_write(&tty->termios_rwsem); in tty_reset_termios()
673 int tty_ldisc_reinit(struct tty_struct *tty, int disc) in tty_ldisc_reinit() argument
678 lockdep_assert_held_write(&tty->ldisc_sem); in tty_ldisc_reinit()
679 ld = tty_ldisc_get(tty, disc); in tty_ldisc_reinit()
685 if (tty->ldisc) { in tty_ldisc_reinit()
686 tty_ldisc_close(tty, tty->ldisc); in tty_ldisc_reinit()
687 tty_ldisc_put(tty->ldisc); in tty_ldisc_reinit()
691 tty->ldisc = ld; in tty_ldisc_reinit()
692 tty_set_termios_ldisc(tty, disc); in tty_ldisc_reinit()
693 retval = tty_ldisc_open(tty, tty->ldisc); in tty_ldisc_reinit()
695 tty_ldisc_put(tty->ldisc); in tty_ldisc_reinit()
696 tty->ldisc = NULL; in tty_ldisc_reinit()
716 void tty_ldisc_hangup(struct tty_struct *tty, bool reinit) in tty_ldisc_hangup() argument
720 tty_ldisc_debug(tty, "%p: hangup\n", tty->ldisc); in tty_ldisc_hangup()
722 ld = tty_ldisc_ref(tty); in tty_ldisc_hangup()
725 ld->ops->flush_buffer(tty); in tty_ldisc_hangup()
726 tty_driver_flush_buffer(tty); in tty_ldisc_hangup()
727 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && in tty_ldisc_hangup()
729 ld->ops->write_wakeup(tty); in tty_ldisc_hangup()
731 ld->ops->hangup(tty); in tty_ldisc_hangup()
735 wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT); in tty_ldisc_hangup()
736 wake_up_interruptible_poll(&tty->read_wait, EPOLLIN); in tty_ldisc_hangup()
744 tty_ldisc_lock(tty, MAX_SCHEDULE_TIMEOUT); in tty_ldisc_hangup()
746 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) in tty_ldisc_hangup()
747 tty_reset_termios(tty); in tty_ldisc_hangup()
749 if (tty->ldisc) { in tty_ldisc_hangup()
751 if (tty_ldisc_reinit(tty, tty->termios.c_line) < 0 && in tty_ldisc_hangup()
752 tty_ldisc_reinit(tty, N_TTY) < 0) in tty_ldisc_hangup()
753 WARN_ON(tty_ldisc_reinit(tty, N_NULL) < 0); in tty_ldisc_hangup()
755 tty_ldisc_kill(tty); in tty_ldisc_hangup()
757 tty_ldisc_unlock(tty); in tty_ldisc_hangup()
770 int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) in tty_ldisc_setup() argument
772 int retval = tty_ldisc_open(tty, tty->ldisc); in tty_ldisc_setup()
783 tty_ldisc_close(tty, tty->ldisc); in tty_ldisc_setup()
798 void tty_ldisc_release(struct tty_struct *tty) in tty_ldisc_release() argument
800 struct tty_struct *o_tty = tty->link; in tty_ldisc_release()
807 tty_ldisc_lock_pair(tty, o_tty); in tty_ldisc_release()
808 tty_ldisc_kill(tty); in tty_ldisc_release()
811 tty_ldisc_unlock_pair(tty, o_tty); in tty_ldisc_release()
816 tty_ldisc_debug(tty, "released\n"); in tty_ldisc_release()
828 int tty_ldisc_init(struct tty_struct *tty) in tty_ldisc_init() argument
830 struct tty_ldisc *ld = tty_ldisc_get(tty, N_TTY); in tty_ldisc_init()
833 tty->ldisc = ld; in tty_ldisc_init()
844 void tty_ldisc_deinit(struct tty_struct *tty) in tty_ldisc_deinit() argument
847 if (tty->ldisc) in tty_ldisc_deinit()
848 tty_ldisc_put(tty->ldisc); in tty_ldisc_deinit()
849 tty->ldisc = NULL; in tty_ldisc_deinit()