Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / ieee1394 / video1394.c
index d68c465..4e3bd62 100644 (file)
  *
  * NOTES:
  *
- * jds -- add private data to file to keep track of iso contexts associated
- * with each open -- so release won't kill all iso transfers.
- * 
- * Damien Douxchamps: Fix failure when the number of DMA pages per frame is
- * one.
- * 
  * ioctl return codes:
  * EFAULT is only for invalid address for the argp
  * EINVAL for out of range values
  * ENOTTY for unsupported ioctl request
  *
  */
-
-/* Markus Tavenrath <speedygoo@speedygoo.de> :
-   - fixed checks for valid buffer-numbers in video1394_icotl
-   - changed the ways the dma prg's are used, now it's possible to use
-     even a single dma buffer
-*/
 #include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
 #include <linux/poll.h>
 #include <linux/smp_lock.h>
 #include <linux/delay.h>
-#include <linux/devfs_fs_kernel.h>
 #include <linux/bitops.h>
 #include <linux/types.h>
 #include <linux/vmalloc.h>
 #include <linux/timex.h>
 #include <linux/mm.h>
-#include <linux/ioctl32.h>
 #include <linux/compat.h>
 #include <linux/cdev.h>
 
 
 #define ISO_CHANNELS 64
 
-#ifndef virt_to_page
-#define virt_to_page(x) MAP_NR(x)
-#endif
-
-#ifndef vmalloc_32
-#define vmalloc_32(x) vmalloc(x)
-#endif
-
 struct it_dma_prg {
        struct dma_cmd begin;
        quadlet_t data[4];
@@ -206,14 +184,12 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc,
        struct dma_iso_ctx *d;
        int i;
 
-       d = kmalloc(sizeof(struct dma_iso_ctx), GFP_KERNEL);
-       if (d == NULL) {
+       d = kzalloc(sizeof(*d), GFP_KERNEL);
+       if (!d) {
                PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma_iso_ctx");
                return NULL;
        }
 
-       memset(d, 0, sizeof *d);
-
        d->ohci = ohci;
        d->type = type;
        d->channel = channel;
@@ -251,9 +227,8 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc,
        }
        d->ctx = d->iso_tasklet.context;
 
-       d->prg_reg = kmalloc(d->num_desc * sizeof(struct dma_prog_region),
-                       GFP_KERNEL);
-       if (d->prg_reg == NULL) {
+       d->prg_reg = kmalloc(d->num_desc * sizeof(*d->prg_reg), GFP_KERNEL);
+       if (!d->prg_reg) {
                PRINT(KERN_ERR, ohci->host->id, "Failed to allocate ir prg regs");
                free_dma_iso_ctx(d);
                return NULL;
@@ -268,15 +243,14 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc,
                d->cmdPtr = OHCI1394_IsoRcvCommandPtr+32*d->ctx;
                d->ctxMatch = OHCI1394_IsoRcvContextMatch+32*d->ctx;
 
-               d->ir_prg = kmalloc(d->num_desc * sizeof(struct dma_cmd *),
+               d->ir_prg = kzalloc(d->num_desc * sizeof(*d->ir_prg),
                                    GFP_KERNEL);
 
-               if (d->ir_prg == NULL) {
+               if (!d->ir_prg) {
                        PRINT(KERN_ERR, ohci->host->id, "Failed to allocate dma ir prg");
                        free_dma_iso_ctx(d);
                        return NULL;
                }
-               memset(d->ir_prg, 0, d->num_desc * sizeof(struct dma_cmd *));
 
                d->nb_cmd = d->buf_size / PAGE_SIZE + 1;
                d->left_size = (d->frame_size % PAGE_SIZE) ?
@@ -297,16 +271,15 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc,
                d->ctrlClear = OHCI1394_IsoXmitContextControlClear+16*d->ctx;
                d->cmdPtr = OHCI1394_IsoXmitCommandPtr+16*d->ctx;
 
-               d->it_prg = kmalloc(d->num_desc * sizeof(struct it_dma_prg *),
+               d->it_prg = kzalloc(d->num_desc * sizeof(*d->it_prg),
                                    GFP_KERNEL);
 
-               if (d->it_prg == NULL) {
+               if (!d->it_prg) {
                        PRINT(KERN_ERR, ohci->host->id,
                              "Failed to allocate dma it prg");
                        free_dma_iso_ctx(d);
                        return NULL;
                }
-               memset(d->it_prg, 0, d->num_desc*sizeof(struct it_dma_prg *));
 
                d->packet_size = packet_size;
 
@@ -337,47 +310,24 @@ alloc_dma_iso_ctx(struct ti_ohci *ohci, int type, int num_desc,
                }
        }
 
-       d->buffer_status = kmalloc(d->num_desc * sizeof(unsigned int),
-                                  GFP_KERNEL);
-       d->buffer_prg_assignment = kmalloc(d->num_desc * sizeof(unsigned int),
-                                  GFP_KERNEL);
-       d->buffer_time = kmalloc(d->num_desc * sizeof(struct timeval),
-                                  GFP_KERNEL);
-       d->last_used_cmd = kmalloc(d->num_desc * sizeof(unsigned int),
-                                  GFP_KERNEL);
-       d->next_buffer = kmalloc(d->num_desc * sizeof(int),
-                                GFP_KERNEL);
-
-       if (d->buffer_status == NULL) {
-               PRINT(KERN_ERR, ohci->host->id, "Failed to allocate buffer_status");
-               free_dma_iso_ctx(d);
-               return NULL;
-       }
-       if (d->buffer_prg_assignment == NULL) {
-               PRINT(KERN_ERR, ohci->host->id, "Failed to allocate buffer_prg_assignment");
-               free_dma_iso_ctx(d);
-               return NULL;
-       }
-       if (d->buffer_time == NULL) {
-               PRINT(KERN_ERR, ohci->host->id, "Failed to allocate buffer_time");
+       d->buffer_status =
+           kzalloc(d->num_desc * sizeof(*d->buffer_status), GFP_KERNEL);
+       d->buffer_prg_assignment =
+           kzalloc(d->num_desc * sizeof(*d->buffer_prg_assignment), GFP_KERNEL);
+       d->buffer_time =
+           kzalloc(d->num_desc * sizeof(*d->buffer_time), GFP_KERNEL);
+       d->last_used_cmd =
+           kzalloc(d->num_desc * sizeof(*d->last_used_cmd), GFP_KERNEL);
+       d->next_buffer =
+           kzalloc(d->num_desc * sizeof(*d->next_buffer), GFP_KERNEL);
+
+       if (!d->buffer_status || !d->buffer_prg_assignment || !d->buffer_time ||
+           !d->last_used_cmd || !d->next_buffer) {
+               PRINT(KERN_ERR, ohci->host->id,
+                     "Failed to allocate dma_iso_ctx member");
                free_dma_iso_ctx(d);
                return NULL;
        }
-       if (d->last_used_cmd == NULL) {
-               PRINT(KERN_ERR, ohci->host->id, "Failed to allocate last_used_cmd");
-               free_dma_iso_ctx(d);
-               return NULL;
-       }
-       if (d->next_buffer == NULL) {
-               PRINT(KERN_ERR, ohci->host->id, "Failed to allocate next_buffer");
-               free_dma_iso_ctx(d);
-               return NULL;
-       }
-       memset(d->buffer_status, 0, d->num_desc * sizeof(unsigned int));
-       memset(d->buffer_prg_assignment, 0, d->num_desc * sizeof(unsigned int));
-       memset(d->buffer_time, 0, d->num_desc * sizeof(struct timeval));
-       memset(d->last_used_cmd, 0, d->num_desc * sizeof(unsigned int));
-       memset(d->next_buffer, -1, d->num_desc * sizeof(int));
 
         spin_lock_init(&d->lock);
 
@@ -539,7 +489,7 @@ static void wakeup_dma_ir_ctx(unsigned long l)
                if (d->ir_prg[i][d->nb_cmd-1].status & cpu_to_le32(0xFFFF0000)) {
                        reset_ir_status(d, i);
                        d->buffer_status[d->buffer_prg_assignment[i]] = VIDEO1394_BUFFER_READY;
-                       do_gettimeofday(&d->buffer_time[i]);
+                       do_gettimeofday(&d->buffer_time[d->buffer_prg_assignment[i]]);
                }
        }
 
@@ -793,7 +743,7 @@ static int __video1394_ioctl(struct file *file,
                        if (i == ISO_CHANNELS) {
                            PRINT(KERN_ERR, ohci->host->id, 
                                  "No free channel found");
-                           return EAGAIN;
+                           return -EAGAIN;
                        }
                        if (!(ohci->ISO_channel_usage & mask)) {
                            v.channel = i;
@@ -883,7 +833,7 @@ static int __video1394_ioctl(struct file *file,
                              v.channel);
                }
 
-               if (copy_to_user((void *)arg, &v, sizeof(v))) {
+               if (copy_to_user(argp, &v, sizeof(v))) {
                        /* FIXME : free allocated dma resources */
                        return -EFAULT;
                }
@@ -1046,7 +996,6 @@ static int __video1394_ioctl(struct file *file,
 
                /* set time of buffer */
                v.filltime = d->buffer_time[v.buffer];
-//             printk("Buffer %d time %d\n", v.buffer, (d->buffer_time[v.buffer]).tv_usec);
 
                /*
                 * Look ahead to see how many more buffers have been received
@@ -1085,7 +1034,7 @@ static int __video1394_ioctl(struct file *file,
                }
 
                if (d->flags & VIDEO1394_VARIABLE_PACKET_SIZE) {
-                       int buf_size = d->nb_cmd * sizeof(unsigned int);
+                       int buf_size = d->nb_cmd * sizeof(*psizes);
                        struct video1394_queue_variable __user *p = argp;
                        unsigned int __user *qv;
 
@@ -1104,7 +1053,7 @@ static int __video1394_ioctl(struct file *file,
 
                spin_lock_irqsave(&d->lock,flags);
 
-               // last_buffer is last_prg
+               /* last_buffer is last_prg */
                next_prg = (d->last_buffer + 1) % d->num_desc;
                if (d->buffer_status[v.buffer]!=VIDEO1394_BUFFER_FREE) {
                        PRINT(KERN_ERR, ohci->host->id,
@@ -1251,13 +1200,12 @@ static int video1394_open(struct inode *inode, struct file *file)
         if (ohci == NULL)
                 return -EIO;
 
-       ctx = kmalloc(sizeof(struct file_ctx), GFP_KERNEL);
-       if (ctx == NULL)  {
+       ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+       if (!ctx)  {
                PRINT(KERN_ERR, ohci->host->id, "Cannot malloc file_ctx");
                return -ENOMEM;
        }
 
-       memset(ctx, 0, sizeof(struct file_ctx));
        ctx->ohci = ohci;
        INIT_LIST_HEAD(&ctx->context_list);
        ctx->current_ctx = NULL;
@@ -1370,12 +1318,9 @@ 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_simple_device_add(hpsb_protocol_class, MKDEV(
+       class_device_create(hpsb_protocol_class, NULL, MKDEV(
                IEEE1394_MAJOR, minor), 
                NULL, "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
-       devfs_mk_cdev(MKDEV(IEEE1394_MAJOR, minor),
-                      S_IFCHR | S_IRUSR | S_IWUSR,
-                      "%s/%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
 }
 
 
@@ -1383,12 +1328,9 @@ static void video1394_remove_host (struct hpsb_host *host)
 {
        struct ti_ohci *ohci = hpsb_get_hostinfo(&video1394_highlevel, host);
 
-       if (ohci) {
-               class_simple_device_remove(MKDEV(IEEE1394_MAJOR, 
+       if (ohci)
+               class_device_destroy(hpsb_protocol_class, MKDEV(IEEE1394_MAJOR,
                        IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id));
-               devfs_remove("%s/%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
-       }
-       
        return;
 }
 
@@ -1529,12 +1471,8 @@ static long video1394_compat_ioctl(struct file *f, unsigned cmd, unsigned long a
 static void __exit video1394_exit_module (void)
 {
        hpsb_unregister_protocol(&video1394_driver);
-
        hpsb_unregister_highlevel(&video1394_highlevel);
-
-       devfs_remove(VIDEO1394_DRIVER_NAME);
        cdev_del(&video1394_cdev);
-
        PRINT_G(KERN_INFO, "Removed " VIDEO1394_DRIVER_NAME " module");
 }
 
@@ -1551,15 +1489,12 @@ static int __init video1394_init_module (void)
                return ret;
         }
 
-       devfs_mk_dir(VIDEO1394_DRIVER_NAME);
-
        hpsb_register_highlevel(&video1394_highlevel);
 
        ret = hpsb_register_protocol(&video1394_driver);
        if (ret) {
                PRINT_G(KERN_ERR, "video1394: failed to register protocol");
                hpsb_unregister_highlevel(&video1394_highlevel);
-               devfs_remove(VIDEO1394_DRIVER_NAME);
                cdev_del(&video1394_cdev);
                return ret;
        }
@@ -1571,4 +1506,3 @@ static int __init video1394_init_module (void)
 
 module_init(video1394_init_module);
 module_exit(video1394_exit_module);
-MODULE_ALIAS_CHARDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_VIDEO1394 * 16);