9 #include <linux/types.h>
11 #include <linux/errno.h>
12 #include <linux/sched.h>
13 #include <linux/kernel.h>
15 #include <linux/tty.h>
16 #include <linux/fcntl.h>
17 #include <linux/string.h>
19 #include <linux/module.h>
20 #include <linux/bitops.h>
25 #include <asm/uaccess.h>
27 #undef TTY_DEBUG_WAIT_UNTIL_SENT
34 #define TERMIOS_FLUSH 1
35 #define TERMIOS_WAIT 2
36 #define TERMIOS_TERMIO 4
51 if (tty->
ops->chars_in_buffer)
52 return tty->
ops->chars_in_buffer(tty);
71 if (tty->
ops->write_room)
72 return tty->
ops->write_room(tty);
87 if (tty->
ops->flush_buffer)
88 tty->
ops->flush_buffer(tty);
108 tty->
ops->throttle(tty);
130 tty->
ops->unthrottle)
131 tty->
ops->unthrottle(tty);
149 #ifdef TTY_DEBUG_WAIT_UNTIL_SENT
158 if (tty->
ops->wait_until_sent)
159 tty->
ops->wait_until_sent(tty, timeout);
175 #define NOSET_MASK(x, y, z) (x = ((x) & ~(z)) | ((y) & (z)))
187 for (i = 0; i <
NCCS; i++)
188 termios->
c_cc[i] = locked->
c_cc[i] ?
200 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
201 9600, 19200, 38400, 57600, 115200, 230400, 460800,
203 76800, 153600, 307200, 614400, 921600
205 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000,
206 2500000, 3000000, 3500000, 4000000
211 static const tcflag_t baud_bits[] = {
219 static const tcflag_t baud_bits[] = {
227 static int n_baud_table =
ARRAY_SIZE(baud_table);
255 if (cbaud < 1 || cbaud + 15 > n_baud_table)
260 return baud_table[cbaud];
291 if (cbaud < 1 || cbaud + 15 > n_baud_table)
296 return baud_table[cbaud];
329 int ifound = -1, ofound = -1;
330 int iclose = ibaud/50, oclose = obaud/50;
361 if (obaud - oclose <= baud_table[i] &&
362 obaud + oclose >= baud_table[i]) {
366 if (ibaud - iclose <= baud_table[i] &&
367 ibaud + iclose >= baud_table[i]) {
370 if (ofound == i && !ibinput)
379 }
while (++i < n_baud_table);
390 if (ifound == -1 && (ibaud != obaud || ibinput))
393 if (ifound == -1 || ofound == -1) {
395 "speed data as your architecture needs updating.\n");
435 "set SPD_* flags is deprecated\n");
512 old_termios = tty->termios;
513 tty->termios = *new_termios;
514 unset_locked_termios(&tty->termios, &old_termios, &tty->
termios_locked);
517 if (tty->
link && tty->
link->packet) {
519 (tty->termios.c_lflag &
EXTPROC);
523 int new_flow = (
I_IXON(tty) &&
526 if ((old_flow != new_flow) || extproc) {
528 if (old_flow != new_flow) {
537 spin_unlock_irqrestore(&tty->
ctrl_lock, flags);
542 if (tty->
ops->set_termios)
543 (*tty->
ops->set_termios)(tty, &old_termios);
549 if (ld->
ops->set_termios)
550 (ld->
ops->set_termios)(tty, &old_termios);
581 tmp_termios = tty->termios;
586 (
struct termio __user *)arg))
591 (
struct termios __user *)arg))
600 (
struct termios __user *)arg))
613 ld->
ops->flush_buffer(tty);
635 *kterm = tty->termios;
649 copy_termios(tty, &kterm);
668 static int set_termiox(
struct tty_struct *tty,
void __user *arg,
int opt)
680 if ((opt & TERMIOS_FLUSH) && ld->
ops->flush_buffer)
681 ld->
ops->flush_buffer(tty);
684 if (opt & TERMIOS_WAIT) {
691 if (tty->
ops->set_termiox)
692 tty->
ops->set_termiox(tty, &tnew);
706 static int get_sgflags(
struct tty_struct *tty)
710 if (!(tty->termios.c_lflag &
ICANON)) {
711 if (tty->termios.c_lflag &
ISIG)
716 if (tty->termios.c_lflag &
ECHO)
718 if (tty->termios.c_oflag &
OPOST)
719 if (tty->termios.c_oflag &
ONLCR)
729 tmp.sg_ispeed = tty->termios.c_ispeed;
730 tmp.sg_ospeed = tty->termios.c_ospeed;
731 tmp.sg_erase = tty->termios.c_cc[
VERASE];
732 tmp.sg_kill = tty->termios.c_cc[
VKILL];
733 tmp.sg_flags = get_sgflags(tty);
739 static void set_sgflags(
struct ktermios *termios,
int flags)
776 static int set_sgttyb(
struct tty_struct *tty,
struct sgttyb __user *sgttyb)
790 termios = tty->termios;
793 set_sgflags(&termios,
tmp.sg_flags);
811 tmp.t_intrc = tty->termios.c_cc[
VINTR];
812 tmp.t_quitc = tty->termios.c_cc[
VQUIT];
813 tmp.t_startc = tty->termios.c_cc[
VSTART];
814 tmp.t_stopc = tty->termios.c_cc[
VSTOP];
815 tmp.t_eofc = tty->termios.c_cc[
VEOF];
816 tmp.t_brkc = tty->termios.c_cc[
VEOL2];
821 static int set_tchars(
struct tty_struct *tty,
struct tchars __user *tchars)
828 tty->termios.c_cc[
VINTR] =
tmp.t_intrc;
829 tty->termios.c_cc[
VQUIT] =
tmp.t_quitc;
830 tty->termios.c_cc[
VSTART] =
tmp.t_startc;
831 tty->termios.c_cc[
VSTOP] =
tmp.t_stopc;
832 tty->termios.c_cc[
VEOF] =
tmp.t_eofc;
833 tty->termios.c_cc[
VEOL2] =
tmp.t_brkc;
845 tmp.t_suspc = tty->termios.c_cc[
VSUSP];
847 tmp.t_dsuspc = tty->termios.c_cc[
VSUSP];
850 tmp.t_flushc = tty->termios.c_cc[
VEOL2];
852 tmp.t_lnextc = tty->termios.c_cc[
VLNEXT];
857 static int set_ltchars(
struct tty_struct *tty,
struct ltchars __user *ltchars)
865 tty->termios.c_cc[
VSUSP] =
tmp.t_suspc;
867 tty->termios.c_cc[
VEOL2] =
tmp.t_dsuspc;
870 tty->termios.c_cc[
VEOL2] =
tmp.t_flushc;
872 tty->termios.c_cc[
VLNEXT] =
tmp.t_lnextc;
886 static int send_prio_char(
struct tty_struct *tty,
char ch)
888 int was_stopped = tty->
stopped;
890 if (tty->
ops->send_xchar) {
891 tty->
ops->send_xchar(tty, ch);
900 tty->
ops->write(tty, &ch, 1);
916 static int tty_change_softcar(
struct tty_struct *tty,
int arg)
924 tty->termios.c_cflag &= ~
CLOCAL;
925 tty->termios.c_cflag |=
bit;
926 if (tty->
ops->set_termios)
927 tty->
ops->set_termios(tty, &old);
928 if ((tty->termios.c_cflag &
CLOCAL) != bit)
947 unsigned int cmd,
unsigned long arg)
958 real_tty = tty->
link;
965 return get_sgttyb(real_tty, (
struct sgttyb
__user *) arg);
968 return set_sgttyb(real_tty, (
struct sgttyb
__user *) arg);
972 return get_tchars(real_tty, p);
974 return set_tchars(real_tty, p);
978 return get_ltchars(real_tty, p);
980 return set_ltchars(real_tty, p);
983 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_OLD);
985 return set_termios(real_tty, p, TERMIOS_WAIT | TERMIOS_OLD);
987 return set_termios(real_tty, p, TERMIOS_OLD);
990 copy_termios(real_tty, &kterm);
996 copy_termios(real_tty, &kterm);
1001 copy_termios(real_tty, &kterm);
1006 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT);
1008 return set_termios(real_tty, p, TERMIOS_WAIT);
1010 return set_termios(real_tty, p, 0);
1013 return get_termio(real_tty, p);
1015 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_TERMIO);
1017 return set_termios(real_tty, p, TERMIOS_WAIT | TERMIOS_TERMIO);
1019 return set_termios(real_tty, p, TERMIOS_TERMIO);
1022 copy_termios_locked(real_tty, &kterm);
1029 copy_termios_locked(real_tty, &kterm);
1031 (
struct termios
__user *) arg))
1039 copy_termios_locked(real_tty, &kterm);
1046 copy_termios_locked(real_tty, &kterm);
1048 (
struct termios
__user *) arg))
1068 return set_termiox(real_tty, p, 0);
1070 return set_termiox(real_tty, p, TERMIOS_WAIT);
1072 return set_termiox(real_tty, p, TERMIOS_FLUSH);
1075 copy_termios(real_tty, &kterm);
1082 return tty_change_softcar(real_tty, arg);
1099 if (ld && ld->
ops->flush_buffer)
1100 ld->
ops->flush_buffer(tty);
1103 if (ld && ld->
ops->flush_buffer)
1104 ld->
ops->flush_buffer(tty);
1119 unsigned int cmd,
unsigned long arg)
1121 unsigned long flags;
1144 return send_prio_char(tty,
STOP_CHAR(tty));
1169 tty->
link->ctrl_status = 0;
1173 spin_unlock_irqrestore(&tty->
ctrl_lock, flags);
1183 #ifdef CONFIG_COMPAT
1185 unsigned int cmd,
unsigned long arg)
1190 return tty_mode_ioctl(tty, file, cmd, (
unsigned long) compat_ptr(arg));