[MIPS] Lasat: Downgrade 64-bit kernel from experimental to broken.
[deliverable/linux.git] / arch / mips / kernel / rtlx.c
index 5a99e3e0c96dcdab47d209ad4b4f3297d69e560a..e14ae09eda2b7a94dd4d264bd9d0b7c864380811 100644 (file)
@@ -17,6 +17,7 @@
  *
  */
 
+#include <linux/device.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/fs.h>
@@ -34,6 +35,7 @@
 #include <linux/sched.h>
 #include <linux/wait.h>
 #include <asm/mipsmtregs.h>
+#include <asm/mips_mt.h>
 #include <asm/cacheflush.h>
 #include <asm/atomic.h>
 #include <asm/cpu.h>
@@ -51,7 +53,7 @@ static char module_name[] = "rtlx";
 static struct chan_waitqueues {
        wait_queue_head_t rt_queue;
        wait_queue_head_t lx_queue;
-       int in_open;
+       atomic_t in_open;
 } channel_wqs[RTLX_CHANNELS];
 
 static struct irqaction irq;
@@ -63,7 +65,7 @@ extern void *vpe_get_shared(int index);
 
 static void rtlx_dispatch(void)
 {
-       do_IRQ(MIPSCPU_INT_BASE + MIPS_CPU_RTLX_IRQ);
+       do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ);
 }
 
 
@@ -144,110 +146,80 @@ static void stopping(int vpe)
 
 int rtlx_open(int index, int can_sleep)
 {
-       int ret;
-       struct rtlx_channel *chan;
        volatile struct rtlx_info **p;
+       struct rtlx_channel *chan;
+       enum rtlx_state state;
+       int ret = 0;
 
        if (index >= RTLX_CHANNELS) {
                printk(KERN_DEBUG "rtlx_open index out of range\n");
                return -ENOSYS;
        }
 
-       if (channel_wqs[index].in_open) {
-               printk(KERN_DEBUG "rtlx_open channel %d already opened\n", index);
-               return -EBUSY;
+       if (atomic_inc_return(&channel_wqs[index].in_open) > 1) {
+               printk(KERN_DEBUG "rtlx_open channel %d already opened\n",
+                      index);
+               ret = -EBUSY;
+               goto out_fail;
        }
 
-       channel_wqs[index].in_open++;
-
        if (rtlx == NULL) {
                if( (p = vpe_get_shared(RTLX_TARG_VPE)) == NULL) {
                        if (can_sleep) {
-                               DECLARE_WAITQUEUE(wait, current);
-
-                               /* go to sleep */
-                               add_wait_queue(&channel_wqs[index].lx_queue, &wait);
-
-                               set_current_state(TASK_INTERRUPTIBLE);
-                               while ((p = vpe_get_shared(RTLX_TARG_VPE)) == NULL) {
-                                       schedule();
-                                       set_current_state(TASK_INTERRUPTIBLE);
-                               }
-
-                               set_current_state(TASK_RUNNING);
-                               remove_wait_queue(&channel_wqs[index].lx_queue, &wait);
-
-                               /* back running */
+                               __wait_event_interruptible(channel_wqs[index].lx_queue,
+                                                          (p = vpe_get_shared(RTLX_TARG_VPE)),
+                                                          ret);
+                               if (ret)
+                                       goto out_fail;
                        } else {
-                               printk( KERN_DEBUG "No SP program loaded, and device "
+                               printk(KERN_DEBUG "No SP program loaded, and device "
                                        "opened with O_NONBLOCK\n");
-                               channel_wqs[index].in_open = 0;
-                               return -ENOSYS;
+                               ret = -ENOSYS;
+                               goto out_fail;
                        }
                }
 
                if (*p == NULL) {
                        if (can_sleep) {
-                               DECLARE_WAITQUEUE(wait, current);
-
-                               /* go to sleep */
-                               add_wait_queue(&channel_wqs[index].lx_queue, &wait);
-
-                               set_current_state(TASK_INTERRUPTIBLE);
-                               while (*p == NULL) {
-                                       schedule();
-
-                                       /* reset task state to interruptable otherwise
-                                          we'll whizz round here like a very fast loopy
-                                          thing. schedule() appears to return with state
-                                          set to TASK_RUNNING.
-
-                                          If the loaded SP program, for whatever reason,
-                                          doesn't set up the shared structure *p will never
-                                          become true. So whoever connected to either /dev/rt?
-                                          or if it was kspd, will then take up rather a lot of
-                                          processor cycles.
-                                       */
-
-                                       set_current_state(TASK_INTERRUPTIBLE);
-                               }
-
-                               set_current_state(TASK_RUNNING);
-                               remove_wait_queue(&channel_wqs[index].lx_queue, &wait);
-
-                               /* back running */
-                       }
-                       else {
+                               __wait_event_interruptible(channel_wqs[index].lx_queue,
+                                                          *p != NULL,
+                                                          ret);
+                               if (ret)
+                                       goto out_fail;
+                       } else {
                                printk(" *vpe_get_shared is NULL. "
                                       "Has an SP program been loaded?\n");
-                               channel_wqs[index].in_open = 0;
-                               return -ENOSYS;
+                               ret = -ENOSYS;
+                               goto out_fail;
                        }
                }
 
                if ((unsigned int)*p < KSEG0) {
                        printk(KERN_WARNING "vpe_get_shared returned an invalid pointer "
                               "maybe an error code %d\n", (int)*p);
-                       channel_wqs[index].in_open = 0;
-                       return -ENOSYS;
+                       ret = -ENOSYS;
+                       goto out_fail;
                }
 
-               if ((ret = rtlx_init(*p)) < 0) {
-                       channel_wqs[index].in_open = 0;
-                       return ret;
-               }
+               if ((ret = rtlx_init(*p)) < 0)
+                       goto out_ret;
        }
 
        chan = &rtlx->channel[index];
 
-       if (chan->lx_state == RTLX_STATE_OPENED) {
-               channel_wqs[index].in_open = 0;
-               return -EBUSY;
-       }
+       state = xchg(&chan->lx_state, RTLX_STATE_OPENED);
+       if (state == RTLX_STATE_OPENED) {
+               ret = -EBUSY;
+               goto out_fail;
+       }
+
+out_fail:
+       smp_mb();
+       atomic_dec(&channel_wqs[index].in_open);
+       smp_mb();
 
-       chan->lx_state = RTLX_STATE_OPENED;
-       channel_wqs[index].in_open = 0;
-       return 0;
+out_ret:
+       return ret;
 }
 
 int rtlx_release(int index)
@@ -268,30 +240,17 @@ unsigned int rtlx_read_poll(int index, int can_sleep)
        /* data available to read? */
        if (chan->lx_read == chan->lx_write) {
                if (can_sleep) {
-                       DECLARE_WAITQUEUE(wait, current);
+                       int ret = 0;
 
-                       /* go to sleep */
-                       add_wait_queue(&channel_wqs[index].lx_queue, &wait);
+                       __wait_event_interruptible(channel_wqs[index].lx_queue,
+                                                  chan->lx_read != chan->lx_write || sp_stopping,
+                                                  ret);
+                       if (ret)
+                               return ret;
 
-                       set_current_state(TASK_INTERRUPTIBLE);
-                       while (chan->lx_read == chan->lx_write) {
-                               schedule();
-
-                               set_current_state(TASK_INTERRUPTIBLE);
-
-                               if (sp_stopping) {
-                                       set_current_state(TASK_RUNNING);
-                                       remove_wait_queue(&channel_wqs[index].lx_queue, &wait);
-                                       return 0;
-                               }
-                       }
-
-                       set_current_state(TASK_RUNNING);
-                       remove_wait_queue(&channel_wqs[index].lx_queue, &wait);
-
-                       /* back running */
-               }
-               else
+                       if (sp_stopping)
+                               return 0;
+               } else
                        return 0;
        }
 
@@ -452,31 +411,28 @@ static ssize_t file_write(struct file *file, const char __user * buffer,
 {
        int minor;
        struct rtlx_channel *rt;
-       DECLARE_WAITQUEUE(wait, current);
 
        minor = iminor(file->f_path.dentry->d_inode);
        rt = &rtlx->channel[minor];
 
        /* any space left... */
        if (!rtlx_write_poll(minor)) {
+               int ret = 0;
 
                if (file->f_flags & O_NONBLOCK)
                        return -EAGAIN;
 
-               add_wait_queue(&channel_wqs[minor].rt_queue, &wait);
-               set_current_state(TASK_INTERRUPTIBLE);
-
-               while (!rtlx_write_poll(minor))
-                       schedule();
-
-               set_current_state(TASK_RUNNING);
-               remove_wait_queue(&channel_wqs[minor].rt_queue, &wait);
+               __wait_event_interruptible(channel_wqs[minor].rt_queue,
+                                          rtlx_write_poll(minor),
+                                          ret);
+               if (ret)
+                       return ret;
        }
 
        return rtlx_write(minor, (void *)buffer, count, 1);
 }
 
-static struct file_operations rtlx_fops = {
+static const struct file_operations rtlx_fops = {
        .owner =   THIS_MODULE,
        .open =    file_open,
        .release = file_release,
@@ -491,14 +447,15 @@ static struct irqaction rtlx_irq = {
        .name           = "RTLX",
 };
 
-static int rtlx_irq_num = MIPSCPU_INT_BASE + MIPS_CPU_RTLX_IRQ;
+static int rtlx_irq_num = MIPS_CPU_IRQ_BASE + MIPS_CPU_RTLX_IRQ;
 
 static char register_chrdev_failed[] __initdata =
        KERN_ERR "rtlx_module_init: unable to register device\n";
 
 static int rtlx_module_init(void)
 {
-       int i;
+       struct device *dev;
+       int i, err;
 
        major = register_chrdev(0, module_name, &rtlx_fops);
        if (major < 0) {
@@ -510,7 +467,14 @@ static int rtlx_module_init(void)
        for (i = 0; i < RTLX_CHANNELS; i++) {
                init_waitqueue_head(&channel_wqs[i].rt_queue);
                init_waitqueue_head(&channel_wqs[i].lx_queue);
-               channel_wqs[i].in_open = 0;
+               atomic_set(&channel_wqs[i].in_open, 0);
+
+               dev = device_create(mt_class, NULL, MKDEV(major, i),
+                                   "%s%d", module_name, i);
+               if (IS_ERR(dev)) {
+                       err = PTR_ERR(dev);
+                       goto out_chrdev;
+               }
        }
 
        /* set up notifiers */
@@ -525,10 +489,21 @@ static int rtlx_module_init(void)
        setup_irq(rtlx_irq_num, &rtlx_irq);
 
        return 0;
+
+out_chrdev:
+       for (i = 0; i < RTLX_CHANNELS; i++)
+               device_destroy(mt_class, MKDEV(major, i));
+
+       return err;
 }
 
 static void __exit rtlx_module_exit(void)
 {
+       int i;
+
+       for (i = 0; i < RTLX_CHANNELS; i++)
+               device_destroy(mt_class, MKDEV(major, i));
+
        unregister_chrdev(major, module_name);
 }
 
This page took 0.027347 seconds and 5 git commands to generate.