Merge to Fedora kernel-2.6.18-1.2255_FC5-vs2.0.2.2-rc9 patched with stable patch...
[linux-2.6.git] / drivers / char / hvsi.c
index 35babe6..017f755 100644 (file)
@@ -197,7 +197,7 @@ static inline void print_state(struct hvsi_struct *hp)
        };
        const char *name = state_names[hp->state];
 
-       if (hp->state > (sizeof(state_names)/sizeof(char*)))
+       if (hp->state > ARRAY_SIZE(state_names))
                name = "UNKNOWN";
 
        pr_debug("hvsi%i: state = %s\n", hp->index, name);
@@ -291,15 +291,13 @@ static void dump_packet(uint8_t *packet)
        dump_hex(packet, header->len);
 }
 
-/* can't use hvc_get_chars because that strips CRs */
 static int hvsi_read(struct hvsi_struct *hp, char *buf, int count)
 {
        unsigned long got;
 
-       if (plpar_hcall(H_GET_TERM_CHAR, hp->vtermno, 0, 0, 0, &got,
-                       (unsigned long *)buf, (unsigned long *)buf+1) == H_Success)
-               return got;
-       return 0;
+       got = hvc_get_chars(hp->vtermno, buf, count);
+
+       return got;
 }
 
 static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
@@ -313,7 +311,8 @@ static void hvsi_recv_control(struct hvsi_struct *hp, uint8_t *packet,
                                /* CD went away; no more connection */
                                pr_debug("hvsi%i: CD dropped\n", hp->index);
                                hp->mctrl &= TIOCM_CD;
-                               if (!(hp->tty->flags & CLOCAL))
+                               /* If userland hasn't done an open(2) yet, hp->tty is NULL. */
+                               if (hp->tty && !(hp->tty->flags & CLOCAL))
                                        *to_hangup = hp->tty;
                        }
                        break;
@@ -631,27 +630,10 @@ static int __init poll_for_state(struct hvsi_struct *hp, int state)
 /* wait for irq handler to change our state */
 static int wait_for_state(struct hvsi_struct *hp, int state)
 {
-       unsigned long end_jiffies = jiffies + HVSI_TIMEOUT;
-       unsigned long timeout;
        int ret = 0;
 
-       DECLARE_WAITQUEUE(myself, current);
-       set_current_state(TASK_INTERRUPTIBLE);
-       add_wait_queue(&hp->stateq, &myself);
-
-       for (;;) {
-               set_current_state(TASK_INTERRUPTIBLE);
-               if (hp->state == state)
-                       break;
-               timeout = end_jiffies - jiffies;
-               if (time_after(jiffies, end_jiffies)) {
-                       ret = -EIO;
-                       break;
-               }
-               schedule_timeout(timeout);
-       }
-       remove_wait_queue(&hp->stateq, &myself);
-       set_current_state(TASK_RUNNING);
+       if (!wait_event_timeout(hp->stateq, (hp->state == state), HVSI_TIMEOUT))
+               ret = -EIO;
 
        return ret;
 }
@@ -868,24 +850,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
 /* wait for hvsi_write_worker to empty hp->outbuf */
 static void hvsi_flush_output(struct hvsi_struct *hp)
 {
-       unsigned long end_jiffies = jiffies + HVSI_TIMEOUT;
-       unsigned long timeout;
-
-       DECLARE_WAITQUEUE(myself, current);
-       set_current_state(TASK_UNINTERRUPTIBLE);
-       add_wait_queue(&hp->emptyq, &myself);
-
-       for (;;) {
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               if (hp->n_outbuf <= 0)
-                       break;
-               timeout = end_jiffies - jiffies;
-               if (time_after(jiffies, end_jiffies))
-                       break;
-               schedule_timeout(timeout);
-       }
-       remove_wait_queue(&hp->emptyq, &myself);
-       set_current_state(TASK_RUNNING);
+       wait_event_timeout(hp->emptyq, (hp->n_outbuf <= 0), HVSI_TIMEOUT);
 
        /* 'writer' could still be pending if it didn't see n_outbuf = 0 yet */
        cancel_delayed_work(&hp->writer);
@@ -1022,10 +987,7 @@ static void hvsi_write_worker(void *arg)
                start_j = 0;
 #endif /* DEBUG */
                wake_up_all(&hp->emptyq);
-               if (test_bit(TTY_DO_WRITE_WAKEUP, &hp->tty->flags)
-                               && hp->tty->ldisc.write_wakeup)
-                       hp->tty->ldisc.write_wakeup(hp->tty);
-               wake_up_interruptible(&hp->tty->write_wait);
+               tty_wakeup(hp->tty);
        }
 
 out:
@@ -1190,7 +1152,6 @@ static int __init hvsi_init(void)
                return -ENOMEM;
 
        hvsi_driver->owner = THIS_MODULE;
-       hvsi_driver->devfs_name = "hvsi/";
        hvsi_driver->driver_name = "hvsi";
        hvsi_driver->name = "hvsi";
        hvsi_driver->major = HVSI_MAJOR;
@@ -1205,7 +1166,7 @@ static int __init hvsi_init(void)
                struct hvsi_struct *hp = &hvsi_ports[i];
                int ret = 1;
 
-               ret = request_irq(hp->virq, hvsi_interrupt, SA_INTERRUPT, "hvsi", hp);
+               ret = request_irq(hp->virq, hvsi_interrupt, IRQF_DISABLED, "hvsi", hp);
                if (ret)
                        printk(KERN_ERR "HVSI: couldn't reserve irq 0x%x (error %i)\n",
                                hp->virq, ret);
@@ -1215,7 +1176,7 @@ static int __init hvsi_init(void)
        if (tty_register_driver(hvsi_driver))
                panic("Couldn't register hvsi console driver\n");
 
-       printk(KERN_INFO "HVSI: registered %i devices\n", hvsi_count);
+       printk(KERN_DEBUG "HVSI: registered %i devices\n", hvsi_count);
 
        return 0;
 }
@@ -1331,18 +1292,17 @@ static int __init hvsi_console_init(void)
                INIT_WORK(&hp->handshaker, hvsi_handshaker, hp);
                init_waitqueue_head(&hp->emptyq);
                init_waitqueue_head(&hp->stateq);
-               hp->lock = SPIN_LOCK_UNLOCKED;
+               spin_lock_init(&hp->lock);
                hp->index = hvsi_count;
                hp->inbuf_end = hp->inbuf;
                hp->state = HVSI_CLOSED;
                hp->vtermno = *vtermno;
-               hp->virq = virt_irq_create_mapping(irq[0]);
+               hp->virq = irq_create_mapping(NULL, irq[0]);
                if (hp->virq == NO_IRQ) {
                        printk(KERN_ERR "%s: couldn't create irq mapping for 0x%x\n",
-                               __FUNCTION__, hp->virq);
+                               __FUNCTION__, irq[0]);
                        continue;
-               } else
-                       hp->virq = irq_offset_up(hp->virq);
+               }
 
                hvsi_count++;
        }