headers: remove sched.h from interrupt.h
[safe/jmp/linux-2.6] / drivers / ieee1394 / video1394.c
index af78b84..949064a 100644 (file)
@@ -30,6 +30,7 @@
  */
 #include <linux/kernel.h>
 #include <linux/list.h>
+#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/interrupt.h>
 #include <linux/wait.h>
@@ -39,7 +40,6 @@
 #include <linux/pci.h>
 #include <linux/fs.h>
 #include <linux/poll.h>
-#include <linux/smp_lock.h>
 #include <linux/delay.h>
 #include <linux/bitops.h>
 #include <linux/types.h>
@@ -129,7 +129,7 @@ struct file_ctx {
 #define DBGMSG(card, fmt, args...) \
 printk(KERN_INFO "video1394_%d: " fmt "\n" , card , ## args)
 #else
-#define DBGMSG(card, fmt, args...)
+#define DBGMSG(card, fmt, args...) do {} while (0)
 #endif
 
 /* print general (card independent) information */
@@ -489,6 +489,9 @@ static void wakeup_dma_ir_ctx(unsigned long l)
                        reset_ir_status(d, i);
                        d->buffer_status[d->buffer_prg_assignment[i]] = VIDEO1394_BUFFER_READY;
                        do_gettimeofday(&d->buffer_time[d->buffer_prg_assignment[i]]);
+                       dma_region_sync_for_cpu(&d->dma,
+                               d->buffer_prg_assignment[i] * d->buf_size,
+                               d->buf_size);
                }
        }
 
@@ -714,8 +717,8 @@ static inline unsigned video1394_buffer_state(struct dma_iso_ctx *d,
        return ret;
 }
 
-static int __video1394_ioctl(struct file *file,
-                            unsigned int cmd, unsigned long arg)
+static long video1394_ioctl(struct file *file,
+                           unsigned int cmd, unsigned long arg)
 {
        struct file_ctx *ctx = (struct file_ctx *)file->private_data;
        struct ti_ohci *ohci = ctx->ohci;
@@ -884,13 +887,14 @@ static int __video1394_ioctl(struct file *file,
                struct dma_iso_ctx *d;
                int next_prg;
 
-               if (copy_from_user(&v, argp, sizeof(v)))
+               if (unlikely(copy_from_user(&v, argp, sizeof(v))))
                        return -EFAULT;
 
                d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, v.channel);
-               if (d == NULL) return -EFAULT;
+               if (unlikely(d == NULL))
+                       return -EFAULT;
 
-               if ((v.buffer<0) || (v.buffer>=d->num_desc - 1)) {
+               if (unlikely(v.buffer >= d->num_desc - 1)) {
                        PRINT(KERN_ERR, ohci->host->id,
                              "Buffer %d out of range",v.buffer);
                        return -EINVAL;
@@ -898,7 +902,7 @@ static int __video1394_ioctl(struct file *file,
 
                spin_lock_irqsave(&d->lock,flags);
 
-               if (d->buffer_status[v.buffer]==VIDEO1394_BUFFER_QUEUED) {
+               if (unlikely(d->buffer_status[v.buffer]==VIDEO1394_BUFFER_QUEUED)) {
                        PRINT(KERN_ERR, ohci->host->id,
                              "Buffer %d is already used",v.buffer);
                        spin_unlock_irqrestore(&d->lock,flags);
@@ -949,13 +953,14 @@ static int __video1394_ioctl(struct file *file,
                struct dma_iso_ctx *d;
                int i = 0;
 
-               if (copy_from_user(&v, argp, sizeof(v)))
+               if (unlikely(copy_from_user(&v, argp, sizeof(v))))
                        return -EFAULT;
 
                d = find_ctx(&ctx->context_list, OHCI_ISO_RECEIVE, v.channel);
-               if (d == NULL) return -EFAULT;
+               if (unlikely(d == NULL))
+                       return -EFAULT;
 
-               if ((v.buffer<0) || (v.buffer>d->num_desc - 1)) {
+               if (unlikely(v.buffer > d->num_desc - 1)) {
                        PRINT(KERN_ERR, ohci->host->id,
                              "Buffer %d out of range",v.buffer);
                        return -EINVAL;
@@ -1008,7 +1013,7 @@ static int __video1394_ioctl(struct file *file,
                spin_unlock_irqrestore(&d->lock, flags);
 
                v.buffer=i;
-               if (copy_to_user(argp, &v, sizeof(v)))
+               if (unlikely(copy_to_user(argp, &v, sizeof(v))))
                        return -EFAULT;
 
                return 0;
@@ -1026,7 +1031,7 @@ static int __video1394_ioctl(struct file *file,
                d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
                if (d == NULL) return -EFAULT;
 
-               if ((v.buffer<0) || (v.buffer>=d->num_desc - 1)) {
+               if (v.buffer >= d->num_desc - 1) {
                        PRINT(KERN_ERR, ohci->host->id,
                              "Buffer %d out of range",v.buffer);
                        return -EINVAL;
@@ -1094,6 +1099,8 @@ static int __video1394_ioctl(struct file *file,
                        DBGMSG(ohci->host->id, "Starting iso transmit DMA ctx=%d",
                               d->ctx);
                        put_timestamp(ohci, d, d->last_buffer);
+                       dma_region_sync_for_device(&d->dma,
+                               v.buffer * d->buf_size, d->buf_size);
 
                        /* Tell the controller where the first program is */
                        reg_write(ohci, d->cmdPtr,
@@ -1109,6 +1116,9 @@ static int __video1394_ioctl(struct file *file,
                                      "Waking up iso transmit dma ctx=%d",
                                      d->ctx);
                                put_timestamp(ohci, d, d->last_buffer);
+                               dma_region_sync_for_device(&d->dma,
+                                       v.buffer * d->buf_size, d->buf_size);
+
                                reg_write(ohci, d->ctrlSet, 0x1000);
                        }
                }
@@ -1128,7 +1138,7 @@ static int __video1394_ioctl(struct file *file,
                d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
                if (d == NULL) return -EFAULT;
 
-               if ((v.buffer<0) || (v.buffer>=d->num_desc-1)) {
+               if (v.buffer >= d->num_desc - 1) {
                        PRINT(KERN_ERR, ohci->host->id,
                              "Buffer %d out of range",v.buffer);
                        return -EINVAL;
@@ -1156,15 +1166,6 @@ static int __video1394_ioctl(struct file *file,
        }
 }
 
-static long video1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
-{
-       int err;
-       lock_kernel();
-       err = __video1394_ioctl(file, cmd, arg);
-       unlock_kernel();
-       return err;
-}
-
 /*
  *     This maps the vmalloced and reserved buffer to user space.
  *
@@ -1177,17 +1178,14 @@ static long video1394_ioctl(struct file *file, unsigned int cmd, unsigned long a
 static int video1394_mmap(struct file *file, struct vm_area_struct *vma)
 {
        struct file_ctx *ctx = (struct file_ctx *)file->private_data;
-       int res = -EINVAL;
 
-       lock_kernel();
        if (ctx->current_ctx == NULL) {
                PRINT(KERN_ERR, ctx->ohci->host->id,
                                "Current iso context not set");
-       } else
-               res = dma_region_mmap(&ctx->current_ctx->dma, file, vma);
-       unlock_kernel();
+               return -EINVAL;
+       }
 
-       return res;
+       return dma_region_mmap(&ctx->current_ctx->dma, file, vma);
 }
 
 static unsigned int video1394_poll(struct file *file, poll_table *pt)
@@ -1198,14 +1196,12 @@ static unsigned int video1394_poll(struct file *file, poll_table *pt)
        struct dma_iso_ctx *d;
        int i;
 
-       lock_kernel();
        ctx = file->private_data;
        d = ctx->current_ctx;
        if (d == NULL) {
                PRINT(KERN_ERR, ctx->ohci->host->id,
                                "Current iso context not set");
-               mask = POLLERR;
-               goto done;
+               return POLLERR;
        }
 
        poll_wait(file, &d->waitq, pt);
@@ -1218,8 +1214,6 @@ static unsigned int video1394_poll(struct file *file, poll_table *pt)
                }
        }
        spin_unlock_irqrestore(&d->lock, flags);
-done:
-       unlock_kernel();
 
        return mask;
 }
@@ -1255,7 +1249,6 @@ static int video1394_release(struct inode *inode, struct file *file)
        struct list_head *lh, *next;
        u64 mask;
 
-       lock_kernel();
        list_for_each_safe(lh, next, &ctx->context_list) {
                struct dma_iso_ctx *d;
                d = list_entry(lh, struct dma_iso_ctx, link);
@@ -1276,7 +1269,6 @@ static int video1394_release(struct inode *inode, struct file *file)
        kfree(ctx);
        file->private_data = NULL;
 
-       unlock_kernel();
        return 0;
 }
 
@@ -1285,7 +1277,7 @@ static long video1394_compat_ioctl(struct file *f, unsigned cmd, unsigned long a
 #endif
 
 static struct cdev video1394_cdev;
-static struct file_operations video1394_fops=
+static const struct file_operations video1394_fops=
 {
        .owner =        THIS_MODULE,
        .unlocked_ioctl = video1394_ioctl,
@@ -1302,7 +1294,8 @@ static struct file_operations video1394_fops=
 /*
  * Export information about protocols/devices supported by this driver.
  */
-static struct ieee1394_device_id video1394_id_table[] = {
+#ifdef MODULE
+static const struct ieee1394_device_id video1394_id_table[] = {
        {
                .match_flags    = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
                .specifier_id   = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
@@ -1322,14 +1315,10 @@ static struct ieee1394_device_id video1394_id_table[] = {
 };
 
 MODULE_DEVICE_TABLE(ieee1394, video1394_id_table);
+#endif /* MODULE */
 
 static struct hpsb_protocol_driver video1394_driver = {
-       .name           = "1394 Digital Camera Driver",
-       .id_table       = video1394_id_table,
-       .driver         = {
-               .name   = VIDEO1394_DRIVER_NAME,
-               .bus    = &ieee1394_bus_type,
-       },
+       .name = VIDEO1394_DRIVER_NAME,
 };
 
 
@@ -1353,9 +1342,8 @@ static void video1394_add_host (struct hpsb_host *host)
        hpsb_set_hostinfo_key(&video1394_highlevel, host, ohci->host->id);
 
        minor = IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id;
-       class_device_create(hpsb_protocol_class, NULL, MKDEV(
-               IEEE1394_MAJOR, minor), 
-               NULL, "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
+       device_create(hpsb_protocol_class, NULL, MKDEV(IEEE1394_MAJOR, minor),
+                     NULL, "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
 }
 
 
@@ -1364,8 +1352,8 @@ static void video1394_remove_host (struct hpsb_host *host)
        struct ti_ohci *ohci = hpsb_get_hostinfo(&video1394_highlevel, host);
 
        if (ohci)
-               class_device_destroy(hpsb_protocol_class, MKDEV(IEEE1394_MAJOR,
-                       IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id));
+               device_destroy(hpsb_protocol_class, MKDEV(IEEE1394_MAJOR,
+                              IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id));
        return;
 }
 
@@ -1515,9 +1503,10 @@ static int __init video1394_init_module (void)
 {
        int ret;
 
+       hpsb_init_highlevel(&video1394_highlevel);
+
        cdev_init(&video1394_cdev, &video1394_fops);
        video1394_cdev.owner = THIS_MODULE;
-       kobject_set_name(&video1394_cdev.kobj, VIDEO1394_DRIVER_NAME);
        ret = cdev_add(&video1394_cdev, IEEE1394_VIDEO1394_DEV, 16);
        if (ret) {
                PRINT_G(KERN_ERR, "video1394: unable to get minor device block");