V4L/DVB: v4l videobuf: move video_copy_to_user and copy_stream to core
authorHans Verkuil <hverkuil@xs4all.nl>
Sun, 28 Mar 2010 12:22:53 +0000 (09:22 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Wed, 19 May 2010 15:57:53 +0000 (12:57 -0300)
The video_copy_to_user and copy_stream ops are almost identical for all
videobuf memtype variants. All that is needed is to use the new vaddr
op and these functions can be moved into the core, ensuring we have just
one single implementation instead of three.

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/videobuf-core.c
drivers/media/video/videobuf-dma-contig.c
drivers/media/video/videobuf-dma-sg.c
drivers/media/video/videobuf-vmalloc.c
include/media/videobuf-core.h

index fabe45c4163ec0a563d5fbabe3cd2bcccb2612eb..f1dfcff44e1b856f49a718aeb53bfa753d33f3d4 100644 (file)
@@ -793,6 +793,49 @@ done:
        return retval;
 }
 
+static int __videobuf_copy_to_user(struct videobuf_queue *q,
+                                  struct videobuf_buffer *buf,
+                                  char __user *data, size_t count,
+                                  int nonblocking)
+{
+       void *vaddr = CALL(q, vaddr, buf);
+
+       /* copy to userspace */
+       if (count > buf->size - q->read_off)
+               count = buf->size - q->read_off;
+
+       if (copy_to_user(data, vaddr + q->read_off, count))
+               return -EFAULT;
+
+       return count;
+}
+
+static int __videobuf_copy_stream(struct videobuf_queue *q,
+                                 struct videobuf_buffer *buf,
+                                 char __user *data, size_t count, size_t pos,
+                                 int vbihack, int nonblocking)
+{
+       unsigned int *fc = CALL(q, vaddr, buf);
+
+       if (vbihack) {
+               /* dirty, undocumented hack -- pass the frame counter
+                       * within the last four bytes of each vbi data block.
+                       * We need that one to maintain backward compatibility
+                       * to all vbi decoding software out there ... */
+               fc += (buf->size >> 2) - 1;
+               *fc = buf->field_count >> 1;
+               dprintk(1, "vbihack: %d\n", *fc);
+       }
+
+       /* copy stuff using the common method */
+       count = __videobuf_copy_to_user(q, buf, data, count, nonblocking);
+
+       if ((count == -EFAULT) && (pos == 0))
+               return -EFAULT;
+
+       return count;
+}
+
 ssize_t videobuf_read_one(struct videobuf_queue *q,
                          char __user *data, size_t count, loff_t *ppos,
                          int nonblocking)
@@ -861,7 +904,7 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
        }
 
        /* Copy to userspace */
-       retval = CALL(q, video_copy_to_user, q, data, count, nonblocking);
+       retval = __videobuf_copy_to_user(q, q->read_buf, data, count, nonblocking);
        if (retval < 0)
                goto done;
 
@@ -1003,7 +1046,7 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
                }
 
                if (q->read_buf->state == VIDEOBUF_DONE) {
-                       rc = CALL(q, copy_stream, q, data + retval, count,
+                       rc = __videobuf_copy_stream(q, q->read_buf, data + retval, count,
                                        retval, vbihack, nonblocking);
                        if (rc < 0) {
                                retval = rc;
index 7226ca47cbf514baf93fca7fb0f994e9bf78d645..0a0ff85140b7e4d2cfe395cbe5cc09eae2ab18f0 100644 (file)
@@ -353,67 +353,12 @@ error:
        return -ENOMEM;
 }
 
-static int __videobuf_copy_to_user(struct videobuf_queue *q,
-                                  char __user *data, size_t count,
-                                  int nonblocking)
-{
-       struct videobuf_dma_contig_memory *mem = q->read_buf->priv;
-       void *vaddr;
-
-       BUG_ON(!mem);
-       MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
-       BUG_ON(!mem->vaddr);
-
-       /* copy to userspace */
-       if (count > q->read_buf->size - q->read_off)
-               count = q->read_buf->size - q->read_off;
-
-       vaddr = mem->vaddr;
-
-       if (copy_to_user(data, vaddr + q->read_off, count))
-               return -EFAULT;
-
-       return count;
-}
-
-static int __videobuf_copy_stream(struct videobuf_queue *q,
-                                 char __user *data, size_t count, size_t pos,
-                                 int vbihack, int nonblocking)
-{
-       unsigned int  *fc;
-       struct videobuf_dma_contig_memory *mem = q->read_buf->priv;
-
-       BUG_ON(!mem);
-       MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
-
-       if (vbihack) {
-               /* dirty, undocumented hack -- pass the frame counter
-                       * within the last four bytes of each vbi data block.
-                       * We need that one to maintain backward compatibility
-                       * to all vbi decoding software out there ... */
-               fc = (unsigned int *)mem->vaddr;
-               fc += (q->read_buf->size >> 2) - 1;
-               *fc = q->read_buf->field_count >> 1;
-               dev_dbg(q->dev, "vbihack: %d\n", *fc);
-       }
-
-       /* copy stuff using the common method */
-       count = __videobuf_copy_to_user(q, data, count, nonblocking);
-
-       if ((count == -EFAULT) && (pos == 0))
-               return -EFAULT;
-
-       return count;
-}
-
 static struct videobuf_qtype_ops qops = {
        .magic        = MAGIC_QTYPE_OPS,
 
        .alloc        = __videobuf_alloc,
        .iolock       = __videobuf_iolock,
        .mmap_mapper  = __videobuf_mmap_mapper,
-       .video_copy_to_user = __videobuf_copy_to_user,
-       .copy_stream  = __videobuf_copy_stream,
        .vaddr        = __videobuf_to_vaddr,
 };
 
index 43e78ee24a1099f829e7c4c0d5fe3f52d9661a80..5c55bd392ea3728d313656731968080fb425e58f 100644 (file)
@@ -644,53 +644,6 @@ done:
        return retval;
 }
 
-static int __videobuf_copy_to_user(struct videobuf_queue *q,
-                               char __user *data, size_t count,
-                               int nonblocking)
-{
-       struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
-       BUG_ON(!mem);
-       MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
-
-       /* copy to userspace */
-       if (count > q->read_buf->size - q->read_off)
-               count = q->read_buf->size - q->read_off;
-
-       if (copy_to_user(data, mem->dma.vmalloc+q->read_off, count))
-               return -EFAULT;
-
-       return count;
-}
-
-static int __videobuf_copy_stream(struct videobuf_queue *q,
-                               char __user *data, size_t count, size_t pos,
-                               int vbihack, int nonblocking)
-{
-       unsigned int *fc;
-       struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
-       BUG_ON(!mem);
-       MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
-
-       if (vbihack) {
-               /* dirty, undocumented hack -- pass the frame counter
-                * within the last four bytes of each vbi data block.
-                * We need that one to maintain backward compatibility
-                * to all vbi decoding software out there ... */
-               fc  = (unsigned int *)mem->dma.vmalloc;
-               fc += (q->read_buf->size >> 2) - 1;
-               *fc = q->read_buf->field_count >> 1;
-               dprintk(1, "vbihack: %d\n", *fc);
-       }
-
-       /* copy stuff using the common method */
-       count = __videobuf_copy_to_user(q, data, count, nonblocking);
-
-       if ((count == -EFAULT) && (0 == pos))
-               return -EFAULT;
-
-       return count;
-}
-
 static struct videobuf_qtype_ops sg_ops = {
        .magic        = MAGIC_QTYPE_OPS,
 
@@ -698,8 +651,6 @@ static struct videobuf_qtype_ops sg_ops = {
        .iolock       = __videobuf_iolock,
        .sync         = __videobuf_sync,
        .mmap_mapper  = __videobuf_mmap_mapper,
-       .video_copy_to_user = __videobuf_copy_to_user,
-       .copy_stream  = __videobuf_copy_stream,
        .vaddr        = __videobuf_to_vaddr,
 };
 
index 6db412abeacdbc3d3092ae3034fc27efd34be8d7..ad655839827b6440d7754946f51ea0e20a2cf880 100644 (file)
@@ -315,55 +315,6 @@ error:
        return -ENOMEM;
 }
 
-static int __videobuf_copy_to_user(struct videobuf_queue *q,
-                                  char __user *data, size_t count,
-                                  int nonblocking)
-{
-       struct videobuf_vmalloc_memory *mem = q->read_buf->priv;
-       BUG_ON(!mem);
-       MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
-
-       BUG_ON(!mem->vmalloc);
-
-       /* copy to userspace */
-       if (count > q->read_buf->size - q->read_off)
-               count = q->read_buf->size - q->read_off;
-
-       if (copy_to_user(data, mem->vmalloc+q->read_off, count))
-               return -EFAULT;
-
-       return count;
-}
-
-static int __videobuf_copy_stream(struct videobuf_queue *q,
-                                 char __user *data, size_t count, size_t pos,
-                                 int vbihack, int nonblocking)
-{
-       unsigned int *fc;
-       struct videobuf_vmalloc_memory *mem = q->read_buf->priv;
-       BUG_ON(!mem);
-       MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
-
-       if (vbihack) {
-               /* dirty, undocumented hack -- pass the frame counter
-                       * within the last four bytes of each vbi data block.
-                       * We need that one to maintain backward compatibility
-                       * to all vbi decoding software out there ... */
-               fc  = (unsigned int *)mem->vmalloc;
-               fc += (q->read_buf->size >> 2) - 1;
-               *fc = q->read_buf->field_count >> 1;
-               dprintk(1, "vbihack: %d\n", *fc);
-       }
-
-       /* copy stuff using the common method */
-       count = __videobuf_copy_to_user(q, data, count, nonblocking);
-
-       if ((count == -EFAULT) && (0 == pos))
-               return -EFAULT;
-
-       return count;
-}
-
 static struct videobuf_qtype_ops qops = {
        .magic        = MAGIC_QTYPE_OPS,
 
@@ -371,8 +322,6 @@ static struct videobuf_qtype_ops qops = {
        .iolock       = __videobuf_iolock,
        .sync         = __videobuf_sync,
        .mmap_mapper  = __videobuf_mmap_mapper,
-       .video_copy_to_user = __videobuf_copy_to_user,
-       .copy_stream  = __videobuf_copy_stream,
        .vaddr        = videobuf_to_vmalloc,
 };
 
index f73e297e373526c1bce8c7e51d752f35abb1a8a4..821a530f4957024bbbafd94b78a40d62eac4976c 100644 (file)
@@ -134,16 +134,6 @@ struct videobuf_qtype_ops {
                                 struct v4l2_framebuffer *fbuf);
        int (*sync)             (struct videobuf_queue *q,
                                 struct videobuf_buffer *buf);
-       int (*video_copy_to_user)(struct videobuf_queue *q,
-                                char __user *data,
-                                size_t count,
-                                int nonblocking);
-       int (*copy_stream)      (struct videobuf_queue *q,
-                                char __user *data,
-                                size_t count,
-                                size_t pos,
-                                int vbihack,
-                                int nonblocking);
        int (*mmap_mapper)      (struct videobuf_queue *q,
                                struct vm_area_struct *vma);
 };