backports: disable DMA shared buffer support for kernel < 3.5 in v4l2
authorHauke Mehrtens <hauke@hauke-m.de>
Sun, 15 Jun 2014 12:15:05 +0000 (14:15 +0200)
committerHauke Mehrtens <hauke@hauke-m.de>
Sun, 15 Jun 2014 16:31:17 +0000 (18:31 +0200)
v4l2 uses the DMA shared buffers API of kernel >= 3.5. When the v4l2
backport is be compiled against older kernel versions a backport of the
DMA shared buffers is used. Instead of using this backport this patch
will remove usage of the DMA shared buffers on these old kernel
versions. This allows us to remove DMA shared buffers from backports.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
patches/collateral-evolutions/media/0002-no_dmabuf/v4l2.patch [new file with mode: 0644]

diff --git a/patches/collateral-evolutions/media/0002-no_dmabuf/v4l2.patch b/patches/collateral-evolutions/media/0002-no_dmabuf/v4l2.patch
new file mode 100644 (file)
index 0000000..a535c2d
--- /dev/null
@@ -0,0 +1,375 @@
+--- a/drivers/media/v4l2-core/Kconfig
++++ b/drivers/media/v4l2-core/Kconfig
+@@ -59,7 +59,7 @@ config VIDEOBUF_DVB
+ # Used by drivers that need Videobuf2 modules
+ config VIDEOBUF2_CORE
+-      select DMA_SHARED_BUFFER
++      select DMA_SHARED_BUFFER if !BACKPORT_KERNEL_3_5
+       tristate
+ config VIDEOBUF2_MEMOPS
+@@ -70,13 +70,13 @@ config VIDEOBUF2_DMA_CONTIG
+       depends on HAS_DMA
+       select VIDEOBUF2_CORE
+       select VIDEOBUF2_MEMOPS
+-      select DMA_SHARED_BUFFER
++      select DMA_SHARED_BUFFER if !BACKPORT_KERNEL_3_5
+ config VIDEOBUF2_VMALLOC
+       tristate
+       select VIDEOBUF2_CORE
+       select VIDEOBUF2_MEMOPS
+-      select DMA_SHARED_BUFFER
++      select DMA_SHARED_BUFFER if !BACKPORT_KERNEL_3_5
+ config VIDEOBUF2_DMA_SG
+       tristate
+--- a/drivers/media/v4l2-core/v4l2-mem2mem.c
++++ b/drivers/media/v4l2-core/v4l2-mem2mem.c
+@@ -439,6 +439,7 @@ int v4l2_m2m_create_bufs(struct file *fi
+ }
+ EXPORT_SYMBOL_GPL(v4l2_m2m_create_bufs);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ /**
+  * v4l2_m2m_expbuf() - export a source or destination buffer, depending on
+  * the type
+@@ -452,6 +453,7 @@ int v4l2_m2m_expbuf(struct file *file, s
+       return vb2_expbuf(vq, eb);
+ }
+ EXPORT_SYMBOL_GPL(v4l2_m2m_expbuf);
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ /**
+  * v4l2_m2m_streamon() - turn on streaming for a video queue
+  */
+@@ -798,6 +800,7 @@ int v4l2_m2m_ioctl_dqbuf(struct file *fi
+ }
+ EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_dqbuf);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ int v4l2_m2m_ioctl_expbuf(struct file *file, void *priv,
+                               struct v4l2_exportbuffer *eb)
+ {
+@@ -806,6 +809,7 @@ int v4l2_m2m_ioctl_expbuf(struct file *f
+       return v4l2_m2m_expbuf(file, fh->m2m_ctx, eb);
+ }
+ EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_expbuf);
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ int v4l2_m2m_ioctl_streamon(struct file *file, void *priv,
+                               enum v4l2_buf_type type)
+--- a/drivers/media/v4l2-core/videobuf2-core.c
++++ b/drivers/media/v4l2-core/videobuf2-core.c
+@@ -250,6 +250,7 @@ static void __vb2_buf_userptr_put(struct
+       }
+ }
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ /**
+  * __vb2_plane_dmabuf_put() - release memory associated with
+  * a DMABUF shared plane
+@@ -278,6 +279,7 @@ static void __vb2_buf_dmabuf_put(struct
+       for (plane = 0; plane < vb->num_planes; ++plane)
+               __vb2_plane_dmabuf_put(vb, &vb->planes[plane]);
+ }
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ /**
+  * __setup_lengths() - setup initial lengths for every plane in
+@@ -421,8 +423,10 @@ static void __vb2_free_mem(struct vb2_qu
+               /* Free MMAP buffers or release USERPTR buffers */
+               if (q->memory == V4L2_MEMORY_MMAP)
+                       __vb2_buf_mem_free(vb);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+               else if (q->memory == V4L2_MEMORY_DMABUF)
+                       __vb2_buf_dmabuf_put(vb);
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+               else
+                       __vb2_buf_userptr_put(vb);
+       }
+@@ -777,6 +781,7 @@ static int __verify_mmap_ops(struct vb2_
+       return 0;
+ }
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ /**
+  * __verify_dmabuf_ops() - verify that all memory operations required for
+  * DMABUF queue type have been provided
+@@ -790,6 +795,7 @@ static int __verify_dmabuf_ops(struct vb
+       return 0;
+ }
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ /**
+  * __verify_memory_type() - Check whether the memory type and buffer type
+@@ -823,10 +829,12 @@ static int __verify_memory_type(struct v
+               return -EINVAL;
+       }
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+       if (memory == V4L2_MEMORY_DMABUF && __verify_dmabuf_ops(q)) {
+               dprintk(1, "DMABUF for current setup unsupported\n");
+               return -EINVAL;
+       }
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+       /*
+        * Place the busy tests at the end: -EBUSY can be ignored when
+@@ -1421,6 +1429,7 @@ err:
+       return ret;
+ }
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ /**
+  * __qbuf_dmabuf() - handle qbuf of a DMABUF buffer
+  */
+@@ -1538,6 +1547,7 @@ err:
+       return ret;
+ }
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ /**
+  * __enqueue_in_driver() - enqueue a vb2_buffer in driver for processing
+@@ -1613,9 +1623,11 @@ static int __buf_prepare(struct vb2_buff
+               up_read(mmap_sem);
+               break;
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+       case V4L2_MEMORY_DMABUF:
+               ret = __qbuf_dmabuf(vb, b);
+               break;
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+       default:
+               WARN(1, "Invalid queue type\n");
+               ret = -EINVAL;
+@@ -1980,8 +1992,10 @@ EXPORT_SYMBOL_GPL(vb2_wait_for_all_buffe
+  */
+ static void __vb2_dqbuf(struct vb2_buffer *vb)
+ {
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+       struct vb2_queue *q = vb->vb2_queue;
+       unsigned int i;
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+       /* nothing to do if the buffer is already dequeued */
+       if (vb->state == VB2_BUF_STATE_DEQUEUED)
+@@ -1989,6 +2003,7 @@ static void __vb2_dqbuf(struct vb2_buffe
+       vb->state = VB2_BUF_STATE_DEQUEUED;
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+       /* unmap DMABUF buffer */
+       if (q->memory == V4L2_MEMORY_DMABUF)
+               for (i = 0; i < vb->num_planes; ++i) {
+@@ -1997,6 +2012,7 @@ static void __vb2_dqbuf(struct vb2_buffe
+                       call_void_memop(vb, unmap_dmabuf, vb->planes[i].mem_priv);
+                       vb->planes[i].dbuf_mapped = 0;
+               }
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ }
+ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking)
+@@ -2277,6 +2293,7 @@ static int __find_plane_by_offset(struct
+       return -EINVAL;
+ }
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ /**
+  * vb2_expbuf() - Export a buffer as a file descriptor
+  * @q:                videobuf2 queue
+@@ -2354,6 +2371,7 @@ int vb2_expbuf(struct vb2_queue *q, stru
+       return 0;
+ }
+ EXPORT_SYMBOL_GPL(vb2_expbuf);
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ /**
+  * vb2_mmap() - map video buffers into application address space
+@@ -3269,6 +3287,7 @@ int vb2_ioctl_streamoff(struct file *fil
+ }
+ EXPORT_SYMBOL_GPL(vb2_ioctl_streamoff);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ int vb2_ioctl_expbuf(struct file *file, void *priv, struct v4l2_exportbuffer *p)
+ {
+       struct video_device *vdev = video_devdata(file);
+@@ -3278,6 +3297,7 @@ int vb2_ioctl_expbuf(struct file *file,
+       return vb2_expbuf(vdev->queue, p);
+ }
+ EXPORT_SYMBOL_GPL(vb2_ioctl_expbuf);
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ /* v4l2_file_operations helpers */
+--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
++++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
+@@ -267,6 +267,7 @@ static int vb2_dc_mmap(void *buf_priv, s
+ }
+ #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0)) */
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ /*********************************************/
+ /*         DMABUF ops for exporters          */
+ /*********************************************/
+@@ -460,6 +461,7 @@ static struct dma_buf *vb2_dc_get_dmabuf
+       return dbuf;
+ }
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ /*********************************************/
+ /*       callbacks for USERPTR buffers       */
+@@ -744,6 +746,7 @@ fail_buf:
+       return ERR_PTR(ret);
+ }
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ /*********************************************/
+ /*       callbacks for DMABUF buffers        */
+ /*********************************************/
+@@ -849,6 +852,7 @@ static void *vb2_dc_attach_dmabuf(void *
+       return buf;
+ }
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ /*********************************************/
+ /*       DMA CONTIG exported functions       */
+@@ -857,7 +861,9 @@ static void *vb2_dc_attach_dmabuf(void *
+ const struct vb2_mem_ops vb2_dma_contig_memops = {
+       .alloc          = vb2_dc_alloc,
+       .put            = vb2_dc_put,
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+       .get_dmabuf     = vb2_dc_get_dmabuf,
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+       .cookie         = vb2_dc_cookie,
+       .vaddr          = vb2_dc_vaddr,
+       .mmap           = vb2_dc_mmap,
+@@ -865,10 +871,12 @@ const struct vb2_mem_ops vb2_dma_contig_
+       .put_userptr    = vb2_dc_put_userptr,
+       .prepare        = vb2_dc_prepare,
+       .finish         = vb2_dc_finish,
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+       .map_dmabuf     = vb2_dc_map_dmabuf,
+       .unmap_dmabuf   = vb2_dc_unmap_dmabuf,
+       .attach_dmabuf  = vb2_dc_attach_dmabuf,
+       .detach_dmabuf  = vb2_dc_detach_dmabuf,
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+       .num_users      = vb2_dc_num_users,
+ };
+ EXPORT_SYMBOL_GPL(vb2_dma_contig_memops);
+--- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
++++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
+@@ -30,7 +30,9 @@ struct vb2_vmalloc_buf {
+       unsigned int                    n_pages;
+       atomic_t                        refcount;
+       struct vb2_vmarea_handler       handler;
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+       struct dma_buf                  *dbuf;
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ };
+ static void vb2_vmalloc_put(void *buf_priv);
+@@ -208,6 +210,7 @@ static int vb2_vmalloc_mmap(void *buf_pr
+       return 0;
+ }
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ /*********************************************/
+ /*       callbacks for DMABUF buffers        */
+ /*********************************************/
+@@ -257,6 +260,7 @@ static void *vb2_vmalloc_attach_dmabuf(v
+       return buf;
+ }
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ const struct vb2_mem_ops vb2_vmalloc_memops = {
+@@ -264,10 +268,12 @@ const struct vb2_mem_ops vb2_vmalloc_mem
+       .put            = vb2_vmalloc_put,
+       .get_userptr    = vb2_vmalloc_get_userptr,
+       .put_userptr    = vb2_vmalloc_put_userptr,
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+       .map_dmabuf     = vb2_vmalloc_map_dmabuf,
+       .unmap_dmabuf   = vb2_vmalloc_unmap_dmabuf,
+       .attach_dmabuf  = vb2_vmalloc_attach_dmabuf,
+       .detach_dmabuf  = vb2_vmalloc_detach_dmabuf,
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+       .vaddr          = vb2_vmalloc_vaddr,
+       .mmap           = vb2_vmalloc_mmap,
+       .num_users      = vb2_vmalloc_num_users,
+--- a/include/media/v4l2-mem2mem.h
++++ b/include/media/v4l2-mem2mem.h
+@@ -117,8 +117,10 @@ int v4l2_m2m_dqbuf(struct file *file, st
+ int v4l2_m2m_create_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                        struct v4l2_create_buffers *create);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ int v4l2_m2m_expbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                  struct v4l2_exportbuffer *eb);
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                     enum v4l2_buf_type type);
+@@ -240,8 +242,10 @@ int v4l2_m2m_ioctl_create_bufs(struct fi
+                               struct v4l2_create_buffers *create);
+ int v4l2_m2m_ioctl_querybuf(struct file *file, void *fh,
+                               struct v4l2_buffer *buf);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ int v4l2_m2m_ioctl_expbuf(struct file *file, void *fh,
+                               struct v4l2_exportbuffer *eb);
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ int v4l2_m2m_ioctl_qbuf(struct file *file, void *fh,
+                               struct v4l2_buffer *buf);
+ int v4l2_m2m_ioctl_dqbuf(struct file *file, void *fh,
+--- a/include/media/videobuf2-core.h
++++ b/include/media/videobuf2-core.h
+@@ -84,7 +84,9 @@ struct vb2_threadio_data;
+ struct vb2_mem_ops {
+       void            *(*alloc)(void *alloc_ctx, unsigned long size, gfp_t gfp_flags);
+       void            (*put)(void *buf_priv);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+       struct dma_buf *(*get_dmabuf)(void *buf_priv, unsigned long flags);
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+       void            *(*get_userptr)(void *alloc_ctx, unsigned long vaddr,
+                                       unsigned long size, int write);
+@@ -93,11 +95,13 @@ struct vb2_mem_ops {
+       void            (*prepare)(void *buf_priv);
+       void            (*finish)(void *buf_priv);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+       void            *(*attach_dmabuf)(void *alloc_ctx, struct dma_buf *dbuf,
+                               unsigned long size, int write);
+       void            (*detach_dmabuf)(void *buf_priv);
+       int             (*map_dmabuf)(void *buf_priv);
+       void            (*unmap_dmabuf)(void *buf_priv);
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+       void            *(*vaddr)(void *buf_priv);
+       void            *(*cookie)(void *buf_priv);
+@@ -445,7 +449,9 @@ int __must_check vb2_queue_init(struct v
+ void vb2_queue_release(struct vb2_queue *q);
+ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb);
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking);
+ int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);
+@@ -601,8 +607,10 @@ int vb2_ioctl_qbuf(struct file *file, vo
+ int vb2_ioctl_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p);
+ int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i);
+ int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
+ int vb2_ioctl_expbuf(struct file *file, void *priv,
+       struct v4l2_exportbuffer *p);
++#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */
+ /* struct v4l2_file_operations helpers */