]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/char/n_r3964.c
tty: The big operations rework
[linux-2.6-omap-h63xx.git] / drivers / char / n_r3964.c
index 65f2d3a96b85dd80e9400e9c730482596f009e9f..902169062332483a8449a4f68b8c69756600b544 100644 (file)
@@ -376,8 +376,9 @@ static void put_char(struct r3964_info *pInfo, unsigned char ch)
        if (tty == NULL)
                return;
 
-       if (tty->driver->put_char) {
-               tty->driver->put_char(tty, ch);
+       /* FIXME: put_char should not be called from an IRQ */
+       if (tty->ops->put_char) {
+               tty->ops->put_char(tty, ch);
        }
        pInfo->bcc ^= ch;
 }
@@ -386,12 +387,9 @@ static void flush(struct r3964_info *pInfo)
 {
        struct tty_struct *tty = pInfo->tty;
 
-       if (tty == NULL)
+       if (tty == NULL || tty->ops->flush_chars == NULL)
                return;
-
-       if (tty->driver->flush_chars) {
-               tty->driver->flush_chars(tty);
-       }
+       tty->ops->flush_chars(tty);
 }
 
 static void trigger_transmit(struct r3964_info *pInfo)
@@ -449,12 +447,11 @@ static void transmit_block(struct r3964_info *pInfo)
        struct r3964_block_header *pBlock = pInfo->tx_first;
        int room = 0;
 
-       if ((tty == NULL) || (pBlock == NULL)) {
+       if (tty == NULL || pBlock == NULL) {
                return;
        }
 
-       if (tty->driver->write_room)
-               room = tty->driver->write_room(tty);
+       room = tty_write_room(tty);
 
        TRACE_PS("transmit_block %p, room %d, length %d",
                 pBlock, room, pBlock->length);
@@ -1071,37 +1068,32 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
        struct r3964_client_info *pClient;
        struct r3964_message *pMsg;
        struct r3964_client_message theMsg;
-       DECLARE_WAITQUEUE(wait, current);
-
        int count;
 
        TRACE_L("read()");
 
+       lock_kernel();
+
        pClient = findClient(pInfo, task_pid(current));
        if (pClient) {
                pMsg = remove_msg(pInfo, pClient);
                if (pMsg == NULL) {
                        /* no messages available. */
                        if (file->f_flags & O_NONBLOCK) {
+                               unlock_kernel();
                                return -EAGAIN;
                        }
                        /* block until there is a message: */
-                       add_wait_queue(&pInfo->read_wait, &wait);
-repeat:
-                       current->state = TASK_INTERRUPTIBLE;
-                       pMsg = remove_msg(pInfo, pClient);
-                       if (!pMsg && !signal_pending(current)) {
-                               schedule();
-                               goto repeat;
-                       }
-                       current->state = TASK_RUNNING;
-                       remove_wait_queue(&pInfo->read_wait, &wait);
+                       wait_event_interruptible(pInfo->read_wait,
+                                       (pMsg = remove_msg(pInfo, pClient)));
                }
 
                /* If we still haven't got a message, we must have been signalled */
 
-               if (!pMsg)
+               if (!pMsg) {
+                       unlock_kernel();
                        return -EINTR;
+               }
 
                /* deliver msg to client process: */
                theMsg.msg_id = pMsg->msg_id;
@@ -1112,12 +1104,15 @@ repeat:
                kfree(pMsg);
                TRACE_M("r3964_read - msg kfree %p", pMsg);
 
-               if (copy_to_user(buf, &theMsg, count))
+               if (copy_to_user(buf, &theMsg, count)) {
+                       unlock_kernel();
                        return -EFAULT;
+               }
 
                TRACE_PS("read - return %d", count);
                return count;
        }
+       unlock_kernel();
        return -EPERM;
 }
 
@@ -1166,6 +1161,8 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
        pHeader->locks = 0;
        pHeader->owner = NULL;
 
+       lock_kernel();
+
        pClient = findClient(pInfo, task_pid(current));
        if (pClient) {
                pHeader->owner = pClient;
@@ -1183,6 +1180,8 @@ static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
        add_tx_queue(pInfo, pHeader);
        trigger_transmit(pInfo);
 
+       unlock_kernel();
+
        return 0;
 }