]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/char/tty_ioctl.c
drm/radeon: IGP clean up register and magic numbers.
[linux-2.6-omap-h63xx.git] / drivers / char / tty_ioctl.c
index d769e43f73fb7c7c9905e0c6f6f5e81e45bcefdc..b1a757a5ee271c9c4a4dc5a4b2fc18c35c7fb491 100644 (file)
 #define TERMIOS_OLD    8
 
 
+int tty_chars_in_buffer(struct tty_struct *tty)
+{
+       if (tty->ops->chars_in_buffer)
+               return tty->ops->chars_in_buffer(tty);
+       else
+               return 0;
+}
+
+EXPORT_SYMBOL(tty_chars_in_buffer);
+
+int tty_write_room(struct tty_struct *tty)
+{
+       if (tty->ops->write_room)
+               return tty->ops->write_room(tty);
+       return 2048;
+}
+
+EXPORT_SYMBOL(tty_write_room);
+
+void tty_driver_flush_buffer(struct tty_struct *tty)
+{
+       if (tty->ops->flush_buffer)
+               tty->ops->flush_buffer(tty);
+}
+
+EXPORT_SYMBOL(tty_driver_flush_buffer);
+
+void tty_throttle(struct tty_struct *tty)
+{
+       /* check TTY_THROTTLED first so it indicates our state */
+       if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) &&
+           tty->ops->throttle)
+               tty->ops->throttle(tty);
+}
+EXPORT_SYMBOL(tty_throttle);
+
+void tty_unthrottle(struct tty_struct *tty)
+{
+       if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) &&
+           tty->ops->unthrottle)
+               tty->ops->unthrottle(tty);
+}
+EXPORT_SYMBOL(tty_unthrottle);
+
 /**
  *     tty_wait_until_sent     -       wait for I/O to finish
  *     @tty: tty we are waiting for
@@ -58,17 +102,13 @@ void tty_wait_until_sent(struct tty_struct *tty, long timeout)
 
        printk(KERN_DEBUG "%s wait until sent...\n", tty_name(tty, buf));
 #endif
-       if (!tty->driver->chars_in_buffer)
-               return;
        if (!timeout)
                timeout = MAX_SCHEDULE_TIMEOUT;
-       lock_kernel();
        if (wait_event_interruptible_timeout(tty->write_wait,
-                       !tty->driver->chars_in_buffer(tty), timeout) >= 0) {
-               if (tty->driver->wait_until_sent)
-                       tty->driver->wait_until_sent(tty, timeout);
+                       !tty_chars_in_buffer(tty), timeout) >= 0) {
+               if (tty->ops->wait_until_sent)
+                       tty->ops->wait_until_sent(tty, timeout);
        }
-       unlock_kernel();
 }
 EXPORT_SYMBOL(tty_wait_until_sent);
 
@@ -396,7 +436,7 @@ EXPORT_SYMBOL(tty_termios_hw_change);
 static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
 {
        int canon_change;
-       struct ktermios old_termios = *tty->termios;
+       struct ktermios old_termios;
        struct tty_ldisc *ld;
        unsigned long flags;
 
@@ -408,7 +448,7 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
        /* FIXME: we need to decide on some locking/ordering semantics
           for the set_termios notification eventually */
        mutex_lock(&tty->termios_mutex);
-
+       old_termios = *tty->termios;
        *tty->termios = *new_termios;
        unset_locked_termios(tty->termios, &old_termios, tty->termios_locked);
        canon_change = (old_termios.c_lflag ^ tty->termios->c_lflag) & ICANON;
@@ -444,8 +484,8 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
                }
        }
 
-       if (tty->driver->set_termios)
-               (*tty->driver->set_termios)(tty, &old_termios);
+       if (tty->ops->set_termios)
+               (*tty->ops->set_termios)(tty, &old_termios);
        else
                tty_termios_copy_hw(tty->termios, &old_termios);
 
@@ -480,7 +520,9 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
        if (retval)
                return retval;
 
+       mutex_lock(&tty->termios_mutex);
        memcpy(&tmp_termios, tty->termios, sizeof(struct ktermios));
+       mutex_unlock(&tty->termios_mutex);
 
        if (opt & TERMIOS_TERMIO) {
                if (user_termio_to_kernel_termios(&tmp_termios,
@@ -666,12 +708,14 @@ static int get_tchars(struct tty_struct *tty, struct tchars __user *tchars)
 {
        struct tchars tmp;
 
+       mutex_lock(&tty->termios_mutex);
        tmp.t_intrc = tty->termios->c_cc[VINTR];
        tmp.t_quitc = tty->termios->c_cc[VQUIT];
        tmp.t_startc = tty->termios->c_cc[VSTART];
        tmp.t_stopc = tty->termios->c_cc[VSTOP];
        tmp.t_eofc = tty->termios->c_cc[VEOF];
        tmp.t_brkc = tty->termios->c_cc[VEOL2]; /* what is brkc anyway? */
+       mutex_unlock(&tty->termios_mutex);
        return copy_to_user(tchars, &tmp, sizeof(tmp)) ? -EFAULT : 0;
 }
 
@@ -681,12 +725,14 @@ static int set_tchars(struct tty_struct *tty, struct tchars __user *tchars)
 
        if (copy_from_user(&tmp, tchars, sizeof(tmp)))
                return -EFAULT;
+       mutex_lock(&tty->termios_mutex);
        tty->termios->c_cc[VINTR] = tmp.t_intrc;
        tty->termios->c_cc[VQUIT] = tmp.t_quitc;
        tty->termios->c_cc[VSTART] = tmp.t_startc;
        tty->termios->c_cc[VSTOP] = tmp.t_stopc;
        tty->termios->c_cc[VEOF] = tmp.t_eofc;
        tty->termios->c_cc[VEOL2] = tmp.t_brkc; /* what is brkc anyway? */
+       mutex_unlock(&tty->termios_mutex);
        return 0;
 }
 #endif
@@ -696,6 +742,7 @@ static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
 {
        struct ltchars tmp;
 
+       mutex_lock(&tty->termios_mutex);
        tmp.t_suspc = tty->termios->c_cc[VSUSP];
        /* what is dsuspc anyway? */
        tmp.t_dsuspc = tty->termios->c_cc[VSUSP];
@@ -704,6 +751,7 @@ static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
        tmp.t_flushc = tty->termios->c_cc[VEOL2];
        tmp.t_werasc = tty->termios->c_cc[VWERASE];
        tmp.t_lnextc = tty->termios->c_cc[VLNEXT];
+       mutex_unlock(&tty->termios_mutex);
        return copy_to_user(ltchars, &tmp, sizeof(tmp)) ? -EFAULT : 0;
 }
 
@@ -714,6 +762,7 @@ static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
        if (copy_from_user(&tmp, ltchars, sizeof(tmp)))
                return -EFAULT;
 
+       mutex_lock(&tty->termios_mutex);
        tty->termios->c_cc[VSUSP] = tmp.t_suspc;
        /* what is dsuspc anyway? */
        tty->termios->c_cc[VEOL2] = tmp.t_dsuspc;
@@ -722,6 +771,7 @@ static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
        tty->termios->c_cc[VEOL2] = tmp.t_flushc;
        tty->termios->c_cc[VWERASE] = tmp.t_werasc;
        tty->termios->c_cc[VLNEXT] = tmp.t_lnextc;
+       mutex_unlock(&tty->termios_mutex);
        return 0;
 }
 #endif
@@ -738,8 +788,8 @@ static int send_prio_char(struct tty_struct *tty, char ch)
 {
        int     was_stopped = tty->stopped;
 
-       if (tty->driver->send_xchar) {
-               tty->driver->send_xchar(tty, ch);
+       if (tty->ops->send_xchar) {
+               tty->ops->send_xchar(tty, ch);
                return 0;
        }
 
@@ -748,7 +798,7 @@ static int send_prio_char(struct tty_struct *tty, char ch)
 
        if (was_stopped)
                start_tty(tty);
-       tty->driver->write(tty, &ch, 1);
+       tty->ops->write(tty, &ch, 1);
        if (was_stopped)
                stop_tty(tty);
        tty_write_unlock(tty);
@@ -768,13 +818,14 @@ static int tty_change_softcar(struct tty_struct *tty, int arg)
 {
        int ret = 0;
        int bit = arg ? CLOCAL : 0;
-       struct ktermios old = *tty->termios;
+       struct ktermios old;
 
        mutex_lock(&tty->termios_mutex);
+       old = *tty->termios;
        tty->termios->c_cflag &= ~CLOCAL;
        tty->termios->c_cflag |= bit;
-       if (tty->driver->set_termios)
-               tty->driver->set_termios(tty, &old);
+       if (tty->ops->set_termios)
+               tty->ops->set_termios(tty, &old);
        if ((tty->termios->c_cflag & CLOCAL) != bit)
                ret = -EINVAL;
        mutex_unlock(&tty->termios_mutex);
@@ -916,8 +967,7 @@ int tty_perform_flush(struct tty_struct *tty, unsigned long arg)
                        ld->flush_buffer(tty);
                /* fall through */
        case TCOFLUSH:
-               if (tty->driver->flush_buffer)
-                       tty->driver->flush_buffer(tty);
+               tty_driver_flush_buffer(tty);
                break;
        default:
                tty_ldisc_deref(ld);
@@ -974,9 +1024,7 @@ int n_tty_ioctl(struct tty_struct *tty, struct file *file,
        case TCFLSH:
                return tty_perform_flush(tty, arg);
        case TIOCOUTQ:
-               return put_user(tty->driver->chars_in_buffer ?
-                               tty->driver->chars_in_buffer(tty) : 0,
-                               (int __user *) arg);
+               return put_user(tty_chars_in_buffer(tty), (int __user *) arg);
        case TIOCINQ:
                retval = tty->read_cnt;
                if (L_ICANON(tty))