Lines Matching refs:tty

94 static inline void put_tty_queue_nolock(unsigned char c, struct tty_struct *tty)  in put_tty_queue_nolock()  argument
96 if (tty->read_cnt < N_TTY_BUF_SIZE) { in put_tty_queue_nolock()
97 tty->read_buf[tty->read_head] = c; in put_tty_queue_nolock()
98 tty->read_head = (tty->read_head + 1) & (N_TTY_BUF_SIZE-1); in put_tty_queue_nolock()
99 tty->read_cnt++; in put_tty_queue_nolock()
103 static inline void put_tty_queue(unsigned char c, struct tty_struct *tty) in put_tty_queue() argument
110 spin_lock_irqsave(&tty->read_lock, flags); in put_tty_queue()
111 put_tty_queue_nolock(c, tty); in put_tty_queue()
112 spin_unlock_irqrestore(&tty->read_lock, flags); in put_tty_queue()
127 static void check_unthrottle(struct tty_struct * tty) in check_unthrottle() argument
129 if (tty->count && in check_unthrottle()
130 test_and_clear_bit(TTY_THROTTLED, &tty->flags) && in check_unthrottle()
131 tty->driver.unthrottle) in check_unthrottle()
132 tty->driver.unthrottle(tty); in check_unthrottle()
143 static void reset_buffer_flags(struct tty_struct *tty) in reset_buffer_flags() argument
147 spin_lock_irqsave(&tty->read_lock, flags); in reset_buffer_flags()
148 tty->read_head = tty->read_tail = tty->read_cnt = 0; in reset_buffer_flags()
149 spin_unlock_irqrestore(&tty->read_lock, flags); in reset_buffer_flags()
150 tty->canon_head = tty->canon_data = tty->erasing = 0; in reset_buffer_flags()
151 memset(&tty->read_flags, 0, sizeof tty->read_flags); in reset_buffer_flags()
152 check_unthrottle(tty); in reset_buffer_flags()
168 void n_tty_flush_buffer(struct tty_struct * tty) in n_tty_flush_buffer() argument
171 reset_buffer_flags(tty); in n_tty_flush_buffer()
173 if (!tty->link) in n_tty_flush_buffer()
176 if (tty->link->packet) { in n_tty_flush_buffer()
177 tty->ctrl_status |= TIOCPKT_FLUSHREAD; in n_tty_flush_buffer()
178 wake_up_interruptible(&tty->link->read_wait); in n_tty_flush_buffer()
190 ssize_t n_tty_chars_in_buffer(struct tty_struct *tty) in n_tty_chars_in_buffer() argument
195 spin_lock_irqsave(&tty->read_lock, flags); in n_tty_chars_in_buffer()
196 if (!tty->icanon) { in n_tty_chars_in_buffer()
197 n = tty->read_cnt; in n_tty_chars_in_buffer()
198 } else if (tty->canon_data) { in n_tty_chars_in_buffer()
199 n = (tty->canon_head > tty->read_tail) ? in n_tty_chars_in_buffer()
200 tty->canon_head - tty->read_tail : in n_tty_chars_in_buffer()
201 tty->canon_head + (N_TTY_BUF_SIZE - tty->read_tail); in n_tty_chars_in_buffer()
203 spin_unlock_irqrestore(&tty->read_lock, flags); in n_tty_chars_in_buffer()
211 static int opost(unsigned char c, struct tty_struct *tty) in opost() argument
215 space = tty->driver.write_room(tty); in opost()
219 if (O_OPOST(tty)) { in opost()
222 if (O_ONLRET(tty)) in opost()
223 tty->column = 0; in opost()
224 if (O_ONLCR(tty)) { in opost()
227 tty->driver.put_char(tty, '\r'); in opost()
228 tty->column = 0; in opost()
230 tty->canon_column = tty->column; in opost()
233 if (O_ONOCR(tty) && tty->column == 0) in opost()
235 if (O_OCRNL(tty)) { in opost()
237 if (O_ONLRET(tty)) in opost()
238 tty->canon_column = tty->column = 0; in opost()
241 tty->canon_column = tty->column = 0; in opost()
244 spaces = 8 - (tty->column & 7); in opost()
245 if (O_TABDLY(tty) == XTABS) { in opost()
248 tty->column += spaces; in opost()
249 tty->driver.write(tty, 0, " ", spaces); in opost()
252 tty->column += spaces; in opost()
255 if (tty->column > 0) in opost()
256 tty->column--; in opost()
259 if (O_OLCUC(tty)) in opost()
262 tty->column++; in opost()
266 tty->driver.put_char(tty, c); in opost()
284 static ssize_t opost_block(struct tty_struct * tty, in opost_block() argument
292 space = tty->driver.write_room(tty); in opost_block()
306 if (O_ONLRET(tty)) in opost_block()
307 tty->column = 0; in opost_block()
308 if (O_ONLCR(tty)) in opost_block()
310 tty->canon_column = tty->column; in opost_block()
313 if (O_ONOCR(tty) && tty->column == 0) in opost_block()
315 if (O_OCRNL(tty)) { in opost_block()
317 if (O_ONLRET(tty)) in opost_block()
318 tty->canon_column = tty->column = 0; in opost_block()
321 tty->canon_column = tty->column = 0; in opost_block()
326 if (tty->column > 0) in opost_block()
327 tty->column--; in opost_block()
330 if (O_OLCUC(tty)) in opost_block()
333 tty->column++; in opost_block()
338 if (tty->driver.flush_chars) in opost_block()
339 tty->driver.flush_chars(tty); in opost_block()
340 i = tty->driver.write(tty, 0, buf, i); in opost_block()
346 static inline void put_char(unsigned char c, struct tty_struct *tty) in put_char() argument
348 tty->driver.put_char(tty, c); in put_char()
353 static void echo_char(unsigned char c, struct tty_struct *tty) in echo_char() argument
355 if (L_ECHOCTL(tty) && iscntrl(c) && c != '\t') { in echo_char()
356 put_char('^', tty); in echo_char()
357 put_char(c ^ 0100, tty); in echo_char()
358 tty->column += 2; in echo_char()
360 opost(c, tty); in echo_char()
363 static inline void finish_erasing(struct tty_struct *tty) in finish_erasing() argument
365 if (tty->erasing) { in finish_erasing()
366 put_char('/', tty); in finish_erasing()
367 tty->column += 2; in finish_erasing()
368 tty->erasing = 0; in finish_erasing()
382 static void eraser(unsigned char c, struct tty_struct *tty) in eraser() argument
388 if (tty->read_head == tty->canon_head) { in eraser()
392 if (c == ERASE_CHAR(tty)) in eraser()
394 else if (c == WERASE_CHAR(tty)) in eraser()
397 if (!L_ECHO(tty)) { in eraser()
398 spin_lock_irqsave(&tty->read_lock, flags); in eraser()
399 tty->read_cnt -= ((tty->read_head - tty->canon_head) & in eraser()
401 tty->read_head = tty->canon_head; in eraser()
402 spin_unlock_irqrestore(&tty->read_lock, flags); in eraser()
405 if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { in eraser()
406 spin_lock_irqsave(&tty->read_lock, flags); in eraser()
407 tty->read_cnt -= ((tty->read_head - tty->canon_head) & in eraser()
409 tty->read_head = tty->canon_head; in eraser()
410 spin_unlock_irqrestore(&tty->read_lock, flags); in eraser()
411 finish_erasing(tty); in eraser()
412 echo_char(KILL_CHAR(tty), tty); in eraser()
414 if (L_ECHOK(tty)) in eraser()
415 opost('\n', tty); in eraser()
422 while (tty->read_head != tty->canon_head) { in eraser()
423 head = (tty->read_head - 1) & (N_TTY_BUF_SIZE-1); in eraser()
424 c = tty->read_buf[head]; in eraser()
432 spin_lock_irqsave(&tty->read_lock, flags); in eraser()
433 tty->read_head = head; in eraser()
434 tty->read_cnt--; in eraser()
435 spin_unlock_irqrestore(&tty->read_lock, flags); in eraser()
436 if (L_ECHO(tty)) { in eraser()
437 if (L_ECHOPRT(tty)) { in eraser()
438 if (!tty->erasing) { in eraser()
439 put_char('\\', tty); in eraser()
440 tty->column++; in eraser()
441 tty->erasing = 1; in eraser()
443 echo_char(c, tty); in eraser()
444 } else if (kill_type == ERASE && !L_ECHOE(tty)) { in eraser()
445 echo_char(ERASE_CHAR(tty), tty); in eraser()
447 unsigned int col = tty->canon_column; in eraser()
448 unsigned long tail = tty->canon_head; in eraser()
451 while (tail != tty->read_head) { in eraser()
452 c = tty->read_buf[tail]; in eraser()
456 if (L_ECHOCTL(tty)) in eraser()
464 if (tty->column > 0x80000000) in eraser()
465 tty->column = 0; in eraser()
468 while (tty->column > col) { in eraser()
470 put_char('\b', tty); in eraser()
471 if (tty->column > 0) in eraser()
472 tty->column--; in eraser()
475 if (iscntrl(c) && L_ECHOCTL(tty)) { in eraser()
476 put_char('\b', tty); in eraser()
477 put_char(' ', tty); in eraser()
478 put_char('\b', tty); in eraser()
479 if (tty->column > 0) in eraser()
480 tty->column--; in eraser()
482 if (!iscntrl(c) || L_ECHOCTL(tty)) { in eraser()
483 put_char('\b', tty); in eraser()
484 put_char(' ', tty); in eraser()
485 put_char('\b', tty); in eraser()
486 if (tty->column > 0) in eraser()
487 tty->column--; in eraser()
494 if (tty->read_head == tty->canon_head) in eraser()
495 finish_erasing(tty); in eraser()
510 static inline void isig(int sig, struct tty_struct *tty, int flush) in isig() argument
512 if (tty->pgrp > 0) in isig()
513 kill_pg(tty->pgrp, sig, 1); in isig()
514 if (flush || !L_NOFLSH(tty)) { in isig()
515 n_tty_flush_buffer(tty); in isig()
516 if (tty->driver.flush_buffer) in isig()
517 tty->driver.flush_buffer(tty); in isig()
531 static inline void n_tty_receive_break(struct tty_struct *tty) in n_tty_receive_break() argument
533 if (I_IGNBRK(tty)) in n_tty_receive_break()
535 if (I_BRKINT(tty)) { in n_tty_receive_break()
536 isig(SIGINT, tty, 1); in n_tty_receive_break()
539 if (I_PARMRK(tty)) { in n_tty_receive_break()
540 put_tty_queue('\377', tty); in n_tty_receive_break()
541 put_tty_queue('\0', tty); in n_tty_receive_break()
543 put_tty_queue('\0', tty); in n_tty_receive_break()
544 wake_up_interruptible(&tty->read_wait); in n_tty_receive_break()
560 static inline void n_tty_receive_overrun(struct tty_struct *tty) in n_tty_receive_overrun() argument
564 tty->num_overrun++; in n_tty_receive_overrun()
565 if (time_before(tty->overrun_time, jiffies - HZ)) { in n_tty_receive_overrun()
566 printk(KERN_WARNING "%s: %d input overrun(s)\n", tty_name(tty, buf), in n_tty_receive_overrun()
567 tty->num_overrun); in n_tty_receive_overrun()
568 tty->overrun_time = jiffies; in n_tty_receive_overrun()
569 tty->num_overrun = 0; in n_tty_receive_overrun()
581 static inline void n_tty_receive_parity_error(struct tty_struct *tty, in n_tty_receive_parity_error() argument
584 if (I_IGNPAR(tty)) { in n_tty_receive_parity_error()
587 if (I_PARMRK(tty)) { in n_tty_receive_parity_error()
588 put_tty_queue('\377', tty); in n_tty_receive_parity_error()
589 put_tty_queue('\0', tty); in n_tty_receive_parity_error()
590 put_tty_queue(c, tty); in n_tty_receive_parity_error()
591 } else if (I_INPCK(tty)) in n_tty_receive_parity_error()
592 put_tty_queue('\0', tty); in n_tty_receive_parity_error()
594 put_tty_queue(c, tty); in n_tty_receive_parity_error()
595 wake_up_interruptible(&tty->read_wait); in n_tty_receive_parity_error()
608 static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c) in n_tty_receive_char() argument
612 if (tty->raw) { in n_tty_receive_char()
613 put_tty_queue(c, tty); in n_tty_receive_char()
617 if (tty->stopped && !tty->flow_stopped && in n_tty_receive_char()
618 I_IXON(tty) && I_IXANY(tty)) { in n_tty_receive_char()
619 start_tty(tty); in n_tty_receive_char()
623 if (I_ISTRIP(tty)) in n_tty_receive_char()
625 if (I_IUCLC(tty) && L_IEXTEN(tty)) in n_tty_receive_char()
628 if (tty->closing) { in n_tty_receive_char()
629 if (I_IXON(tty)) { in n_tty_receive_char()
630 if (c == START_CHAR(tty)) in n_tty_receive_char()
631 start_tty(tty); in n_tty_receive_char()
632 else if (c == STOP_CHAR(tty)) in n_tty_receive_char()
633 stop_tty(tty); in n_tty_receive_char()
644 if (!test_bit(c, &tty->process_char_map) || tty->lnext) { in n_tty_receive_char()
645 finish_erasing(tty); in n_tty_receive_char()
646 tty->lnext = 0; in n_tty_receive_char()
647 if (L_ECHO(tty)) { in n_tty_receive_char()
648 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { in n_tty_receive_char()
649 put_char('\a', tty); /* beep if no space */ in n_tty_receive_char()
653 if (tty->canon_head == tty->read_head) in n_tty_receive_char()
654 tty->canon_column = tty->column; in n_tty_receive_char()
655 echo_char(c, tty); in n_tty_receive_char()
657 if (I_PARMRK(tty) && c == (unsigned char) '\377') in n_tty_receive_char()
658 put_tty_queue(c, tty); in n_tty_receive_char()
659 put_tty_queue(c, tty); in n_tty_receive_char()
664 if (I_IGNCR(tty)) in n_tty_receive_char()
666 if (I_ICRNL(tty)) in n_tty_receive_char()
668 } else if (c == '\n' && I_INLCR(tty)) in n_tty_receive_char()
670 if (I_IXON(tty)) { in n_tty_receive_char()
671 if (c == START_CHAR(tty)) { in n_tty_receive_char()
672 start_tty(tty); in n_tty_receive_char()
675 if (c == STOP_CHAR(tty)) { in n_tty_receive_char()
676 stop_tty(tty); in n_tty_receive_char()
680 if (L_ISIG(tty)) { in n_tty_receive_char()
683 if (c == INTR_CHAR(tty)) in n_tty_receive_char()
686 if (c == QUIT_CHAR(tty)) in n_tty_receive_char()
689 if (c == SUSP_CHAR(tty)) { in n_tty_receive_char()
691 isig(signal, tty, 0); in n_tty_receive_char()
695 if (tty->icanon) { in n_tty_receive_char()
696 if (c == ERASE_CHAR(tty) || c == KILL_CHAR(tty) || in n_tty_receive_char()
697 (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char()
698 eraser(c, tty); in n_tty_receive_char()
701 if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) { in n_tty_receive_char()
702 tty->lnext = 1; in n_tty_receive_char()
703 if (L_ECHO(tty)) { in n_tty_receive_char()
704 finish_erasing(tty); in n_tty_receive_char()
705 if (L_ECHOCTL(tty)) { in n_tty_receive_char()
706 put_char('^', tty); in n_tty_receive_char()
707 put_char('\b', tty); in n_tty_receive_char()
712 if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && in n_tty_receive_char()
713 L_IEXTEN(tty)) { in n_tty_receive_char()
714 unsigned long tail = tty->canon_head; in n_tty_receive_char()
716 finish_erasing(tty); in n_tty_receive_char()
717 echo_char(c, tty); in n_tty_receive_char()
718 opost('\n', tty); in n_tty_receive_char()
719 while (tail != tty->read_head) { in n_tty_receive_char()
720 echo_char(tty->read_buf[tail], tty); in n_tty_receive_char()
726 if (L_ECHO(tty) || L_ECHONL(tty)) { in n_tty_receive_char()
727 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { in n_tty_receive_char()
728 put_char('\a', tty); in n_tty_receive_char()
731 opost('\n', tty); in n_tty_receive_char()
735 if (c == EOF_CHAR(tty)) { in n_tty_receive_char()
736 if (tty->canon_head != tty->read_head) in n_tty_receive_char()
737 set_bit(TTY_PUSH, &tty->flags); in n_tty_receive_char()
741 if ((c == EOL_CHAR(tty)) || in n_tty_receive_char()
742 (c == EOL2_CHAR(tty) && L_IEXTEN(tty))) { in n_tty_receive_char()
746 if (L_ECHO(tty)) { in n_tty_receive_char()
747 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { in n_tty_receive_char()
748 put_char('\a', tty); in n_tty_receive_char()
752 if (tty->canon_head == tty->read_head) in n_tty_receive_char()
753 tty->canon_column = tty->column; in n_tty_receive_char()
754 echo_char(c, tty); in n_tty_receive_char()
760 if (I_PARMRK(tty) && c == (unsigned char) '\377') in n_tty_receive_char()
761 put_tty_queue(c, tty); in n_tty_receive_char()
764 spin_lock_irqsave(&tty->read_lock, flags); in n_tty_receive_char()
765 set_bit(tty->read_head, &tty->read_flags); in n_tty_receive_char()
766 put_tty_queue_nolock(c, tty); in n_tty_receive_char()
767 tty->canon_head = tty->read_head; in n_tty_receive_char()
768 tty->canon_data++; in n_tty_receive_char()
769 spin_unlock_irqrestore(&tty->read_lock, flags); in n_tty_receive_char()
770 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_tty_receive_char()
771 if (waitqueue_active(&tty->read_wait)) in n_tty_receive_char()
772 wake_up_interruptible(&tty->read_wait); in n_tty_receive_char()
777 finish_erasing(tty); in n_tty_receive_char()
778 if (L_ECHO(tty)) { in n_tty_receive_char()
779 if (tty->read_cnt >= N_TTY_BUF_SIZE-1) { in n_tty_receive_char()
780 put_char('\a', tty); /* beep if no space */ in n_tty_receive_char()
784 opost('\n', tty); in n_tty_receive_char()
787 if (tty->canon_head == tty->read_head) in n_tty_receive_char()
788 tty->canon_column = tty->column; in n_tty_receive_char()
789 echo_char(c, tty); in n_tty_receive_char()
793 if (I_PARMRK(tty) && c == (unsigned char) '\377') in n_tty_receive_char()
794 put_tty_queue(c, tty); in n_tty_receive_char()
796 put_tty_queue(c, tty); in n_tty_receive_char()
809 static int n_tty_receive_room(struct tty_struct *tty) in n_tty_receive_room() argument
811 int left = N_TTY_BUF_SIZE - tty->read_cnt - 1; in n_tty_receive_room()
819 if (tty->icanon && !tty->canon_data) in n_tty_receive_room()
836 static void n_tty_write_wakeup(struct tty_struct *tty) in n_tty_write_wakeup() argument
838 if (tty->fasync) in n_tty_write_wakeup()
840 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_tty_write_wakeup()
841 kill_fasync(&tty->fasync, SIGIO, POLL_OUT); in n_tty_write_wakeup()
859 static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp, in n_tty_receive_buf() argument
868 if (!tty->read_buf) in n_tty_receive_buf()
871 if (tty->real_raw) { in n_tty_receive_buf()
872 spin_lock_irqsave(&tty->read_lock, cpuflags); in n_tty_receive_buf()
873 i = MIN(count, MIN(N_TTY_BUF_SIZE - tty->read_cnt, in n_tty_receive_buf()
874 N_TTY_BUF_SIZE - tty->read_head)); in n_tty_receive_buf()
875 memcpy(tty->read_buf + tty->read_head, cp, i); in n_tty_receive_buf()
876 tty->read_head = (tty->read_head + i) & (N_TTY_BUF_SIZE-1); in n_tty_receive_buf()
877 tty->read_cnt += i; in n_tty_receive_buf()
881 i = MIN(count, MIN(N_TTY_BUF_SIZE - tty->read_cnt, in n_tty_receive_buf()
882 N_TTY_BUF_SIZE - tty->read_head)); in n_tty_receive_buf()
883 memcpy(tty->read_buf + tty->read_head, cp, i); in n_tty_receive_buf()
884 tty->read_head = (tty->read_head + i) & (N_TTY_BUF_SIZE-1); in n_tty_receive_buf()
885 tty->read_cnt += i; in n_tty_receive_buf()
886 spin_unlock_irqrestore(&tty->read_lock, cpuflags); in n_tty_receive_buf()
893 n_tty_receive_char(tty, *p); in n_tty_receive_buf()
896 n_tty_receive_break(tty); in n_tty_receive_buf()
900 n_tty_receive_parity_error(tty, *p); in n_tty_receive_buf()
903 n_tty_receive_overrun(tty); in n_tty_receive_buf()
907 tty_name(tty, buf), flags); in n_tty_receive_buf()
911 if (tty->driver.flush_chars) in n_tty_receive_buf()
912 tty->driver.flush_chars(tty); in n_tty_receive_buf()
915 if (!tty->icanon && (tty->read_cnt >= tty->minimum_to_wake)) { in n_tty_receive_buf()
916 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_tty_receive_buf()
917 if (waitqueue_active(&tty->read_wait)) in n_tty_receive_buf()
918 wake_up_interruptible(&tty->read_wait); in n_tty_receive_buf()
926 if (n_tty_receive_room(tty) < TTY_THRESHOLD_THROTTLE) { in n_tty_receive_buf()
928 if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && in n_tty_receive_buf()
929 tty->driver.throttle) in n_tty_receive_buf()
930 tty->driver.throttle(tty); in n_tty_receive_buf()
952 static void n_tty_set_termios(struct tty_struct *tty, struct termios * old) in n_tty_set_termios() argument
954 if (!tty) in n_tty_set_termios()
957 tty->icanon = (L_ICANON(tty) != 0); in n_tty_set_termios()
958 if (test_bit(TTY_HW_COOK_IN, &tty->flags)) { in n_tty_set_termios()
959 tty->raw = 1; in n_tty_set_termios()
960 tty->real_raw = 1; in n_tty_set_termios()
963 if (I_ISTRIP(tty) || I_IUCLC(tty) || I_IGNCR(tty) || in n_tty_set_termios()
964 I_ICRNL(tty) || I_INLCR(tty) || L_ICANON(tty) || in n_tty_set_termios()
965 I_IXON(tty) || L_ISIG(tty) || L_ECHO(tty) || in n_tty_set_termios()
966 I_PARMRK(tty)) { in n_tty_set_termios()
967 memset(tty->process_char_map, 0, 256/8); in n_tty_set_termios()
969 if (I_IGNCR(tty) || I_ICRNL(tty)) in n_tty_set_termios()
970 set_bit('\r', &tty->process_char_map); in n_tty_set_termios()
971 if (I_INLCR(tty)) in n_tty_set_termios()
972 set_bit('\n', &tty->process_char_map); in n_tty_set_termios()
974 if (L_ICANON(tty)) { in n_tty_set_termios()
975 set_bit(ERASE_CHAR(tty), &tty->process_char_map); in n_tty_set_termios()
976 set_bit(KILL_CHAR(tty), &tty->process_char_map); in n_tty_set_termios()
977 set_bit(EOF_CHAR(tty), &tty->process_char_map); in n_tty_set_termios()
978 set_bit('\n', &tty->process_char_map); in n_tty_set_termios()
979 set_bit(EOL_CHAR(tty), &tty->process_char_map); in n_tty_set_termios()
980 if (L_IEXTEN(tty)) { in n_tty_set_termios()
981 set_bit(WERASE_CHAR(tty), in n_tty_set_termios()
982 &tty->process_char_map); in n_tty_set_termios()
983 set_bit(LNEXT_CHAR(tty), in n_tty_set_termios()
984 &tty->process_char_map); in n_tty_set_termios()
985 set_bit(EOL2_CHAR(tty), in n_tty_set_termios()
986 &tty->process_char_map); in n_tty_set_termios()
987 if (L_ECHO(tty)) in n_tty_set_termios()
988 set_bit(REPRINT_CHAR(tty), in n_tty_set_termios()
989 &tty->process_char_map); in n_tty_set_termios()
992 if (I_IXON(tty)) { in n_tty_set_termios()
993 set_bit(START_CHAR(tty), &tty->process_char_map); in n_tty_set_termios()
994 set_bit(STOP_CHAR(tty), &tty->process_char_map); in n_tty_set_termios()
996 if (L_ISIG(tty)) { in n_tty_set_termios()
997 set_bit(INTR_CHAR(tty), &tty->process_char_map); in n_tty_set_termios()
998 set_bit(QUIT_CHAR(tty), &tty->process_char_map); in n_tty_set_termios()
999 set_bit(SUSP_CHAR(tty), &tty->process_char_map); in n_tty_set_termios()
1001 clear_bit(__DISABLED_CHAR, &tty->process_char_map); in n_tty_set_termios()
1002 tty->raw = 0; in n_tty_set_termios()
1003 tty->real_raw = 0; in n_tty_set_termios()
1005 tty->raw = 1; in n_tty_set_termios()
1006 if ((I_IGNBRK(tty) || (!I_BRKINT(tty) && !I_PARMRK(tty))) && in n_tty_set_termios()
1007 (I_IGNPAR(tty) || !I_INPCK(tty)) && in n_tty_set_termios()
1008 (tty->driver.flags & TTY_DRIVER_REAL_RAW)) in n_tty_set_termios()
1009 tty->real_raw = 1; in n_tty_set_termios()
1011 tty->real_raw = 0; in n_tty_set_termios()
1025 static void n_tty_close(struct tty_struct *tty) in n_tty_close() argument
1027 n_tty_flush_buffer(tty); in n_tty_close()
1028 if (tty->read_buf) { in n_tty_close()
1029 free_buf(tty->read_buf); in n_tty_close()
1030 tty->read_buf = 0; in n_tty_close()
1044 static int n_tty_open(struct tty_struct *tty) in n_tty_open() argument
1046 if (!tty) in n_tty_open()
1050 if (!tty->read_buf) { in n_tty_open()
1051 tty->read_buf = alloc_buf(); in n_tty_open()
1052 if (!tty->read_buf) in n_tty_open()
1055 memset(tty->read_buf, 0, N_TTY_BUF_SIZE); in n_tty_open()
1056 reset_buffer_flags(tty); in n_tty_open()
1057 tty->column = 0; in n_tty_open()
1058 n_tty_set_termios(tty, 0); in n_tty_open()
1059 tty->minimum_to_wake = 1; in n_tty_open()
1060 tty->closing = 0; in n_tty_open()
1064 static inline int input_available_p(struct tty_struct *tty, int amt) in input_available_p() argument
1066 if (tty->icanon) { in input_available_p()
1067 if (tty->canon_data) in input_available_p()
1069 } else if (tty->read_cnt >= (amt ? amt : 1)) in input_available_p()
1092 static inline int copy_from_read_buf(struct tty_struct *tty, in copy_from_read_buf() argument
1102 spin_lock_irqsave(&tty->read_lock, flags); in copy_from_read_buf()
1103 n = MIN(*nr, MIN(tty->read_cnt, N_TTY_BUF_SIZE - tty->read_tail)); in copy_from_read_buf()
1104 spin_unlock_irqrestore(&tty->read_lock, flags); in copy_from_read_buf()
1107 retval = copy_to_user(*b, &tty->read_buf[tty->read_tail], n); in copy_from_read_buf()
1109 spin_lock_irqsave(&tty->read_lock, flags); in copy_from_read_buf()
1110 tty->read_tail = (tty->read_tail + n) & (N_TTY_BUF_SIZE-1); in copy_from_read_buf()
1111 tty->read_cnt -= n; in copy_from_read_buf()
1112 spin_unlock_irqrestore(&tty->read_lock, flags); in copy_from_read_buf()
1129 static int job_control(struct tty_struct *tty, struct file *file) in job_control() argument
1138 current->tty == tty) { in job_control()
1139 if (tty->pgrp <= 0) in job_control()
1141 else if (current->pgrp != tty->pgrp) { in job_control()
1168 static ssize_t read_chan(struct tty_struct *tty, struct file *file, in read_chan() argument
1182 if (!tty->read_buf) { in read_chan()
1187 c = job_control(tty, file); in read_chan()
1193 if (!tty->icanon) { in read_chan()
1194 time = (HZ / 10) * TIME_CHAR(tty); in read_chan()
1195 minimum = MIN_CHAR(tty); in read_chan()
1198 tty->minimum_to_wake = 1; in read_chan()
1199 else if (!waitqueue_active(&tty->read_wait) || in read_chan()
1200 (tty->minimum_to_wake > minimum)) in read_chan()
1201 tty->minimum_to_wake = minimum; in read_chan()
1208 tty->minimum_to_wake = minimum = 1; in read_chan()
1216 if (down_trylock(&tty->atomic_read)) in read_chan()
1220 if (down_interruptible(&tty->atomic_read)) in read_chan()
1224 add_wait_queue(&tty->read_wait, &wait); in read_chan()
1225 set_bit(TTY_DONT_FLIP, &tty->flags); in read_chan()
1228 if (tty->packet && tty->link->ctrl_status) { in read_chan()
1232 cs = tty->link->ctrl_status; in read_chan()
1233 tty->link->ctrl_status = 0; in read_chan()
1243 if (((minimum - (b - buf)) < tty->minimum_to_wake) && in read_chan()
1245 tty->minimum_to_wake = (minimum - (b - buf)); in read_chan()
1247 if (!input_available_p(tty, 0)) { in read_chan()
1248 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { in read_chan()
1264 clear_bit(TTY_DONT_FLIP, &tty->flags); in read_chan()
1266 set_bit(TTY_DONT_FLIP, &tty->flags); in read_chan()
1272 if (tty->packet && b == buf) { in read_chan()
1277 if (tty->icanon) { in read_chan()
1279 while (nr && tty->read_cnt) { in read_chan()
1282 eol = test_and_clear_bit(tty->read_tail, in read_chan()
1283 &tty->read_flags); in read_chan()
1284 c = tty->read_buf[tty->read_tail]; in read_chan()
1285 spin_lock_irqsave(&tty->read_lock, flags); in read_chan()
1286 tty->read_tail = ((tty->read_tail+1) & in read_chan()
1288 tty->read_cnt--; in read_chan()
1294 if (--tty->canon_data < 0) in read_chan()
1295 tty->canon_data = 0; in read_chan()
1297 spin_unlock_irqrestore(&tty->read_lock, flags); in read_chan()
1308 uncopied = copy_from_read_buf(tty, &b, &nr); in read_chan()
1309 uncopied += copy_from_read_buf(tty, &b, &nr); in read_chan()
1323 if (n_tty_chars_in_buffer(tty) <= TTY_THRESHOLD_UNTHROTTLE) in read_chan()
1324 check_unthrottle(tty); in read_chan()
1331 clear_bit(TTY_DONT_FLIP, &tty->flags); in read_chan()
1332 up(&tty->atomic_read); in read_chan()
1333 remove_wait_queue(&tty->read_wait, &wait); in read_chan()
1335 if (!waitqueue_active(&tty->read_wait)) in read_chan()
1336 tty->minimum_to_wake = minimum; in read_chan()
1343 clear_bit(TTY_PUSH, &tty->flags); in read_chan()
1344 } else if (test_and_clear_bit(TTY_PUSH, &tty->flags)) in read_chan()
1365 static ssize_t write_chan(struct tty_struct * tty, struct file * file, in write_chan() argument
1374 if (L_TOSTOP(tty) && in write_chan()
1377 retval = tty_check_change(tty); in write_chan()
1382 add_wait_queue(&tty->write_wait, &wait); in write_chan()
1389 if (tty_hung_up_p(file) || (tty->link && !tty->link->count)) { in write_chan()
1393 if (O_OPOST(tty) && !(test_bit(TTY_HW_COOK_OUT, &tty->flags))) { in write_chan()
1395 ssize_t num = opost_block(tty, b, nr); in write_chan()
1407 if (opost(c, tty) < 0) in write_chan()
1411 if (tty->driver.flush_chars) in write_chan()
1412 tty->driver.flush_chars(tty); in write_chan()
1414 c = tty->driver.write(tty, 1, b, nr); in write_chan()
1432 remove_wait_queue(&tty->write_wait, &wait); in write_chan()
1455 static unsigned int normal_poll(struct tty_struct * tty, struct file * file, poll_table *wait) in normal_poll() argument
1459 poll_wait(file, &tty->read_wait, wait); in normal_poll()
1460 poll_wait(file, &tty->write_wait, wait); in normal_poll()
1461 if (input_available_p(tty, TIME_CHAR(tty) ? 0 : MIN_CHAR(tty))) in normal_poll()
1463 if (tty->packet && tty->link->ctrl_status) in normal_poll()
1465 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in normal_poll()
1470 if (MIN_CHAR(tty) && !TIME_CHAR(tty)) in normal_poll()
1471 tty->minimum_to_wake = MIN_CHAR(tty); in normal_poll()
1473 tty->minimum_to_wake = 1; in normal_poll()
1475 if (tty->driver.chars_in_buffer(tty) < WAKEUP_CHARS && in normal_poll()
1476 tty->driver.write_room(tty) > 0) in normal_poll()