[media] v4l: vb2: add prepare/finish callbacks to allocators
authorMarek Szyprowski <m.szyprowski@samsung.com>
Thu, 14 Jun 2012 13:37:43 +0000 (10:37 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sun, 25 Nov 2012 19:12:12 +0000 (17:12 -0200)
This patch adds support for prepare/finish callbacks in VB2 allocators. These
callback are used for buffer flushing.

Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Tested-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/v4l2-core/videobuf2-core.c
include/media/videobuf2-core.h

index a51dad6bd394cd431e2da4939706550a011fda15..613dea16a30470067338ad69833bac83a96bf585 100644 (file)
@@ -844,6 +844,7 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
 {
        struct vb2_queue *q = vb->vb2_queue;
        unsigned long flags;
+       unsigned int plane;
 
        if (vb->state != VB2_BUF_STATE_ACTIVE)
                return;
@@ -854,6 +855,10 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state)
        dprintk(4, "Done processing on buffer %d, state: %d\n",
                        vb->v4l2_buf.index, vb->state);
 
+       /* sync buffers */
+       for (plane = 0; plane < vb->num_planes; ++plane)
+               call_memop(q, finish, vb->planes[plane].mem_priv);
+
        /* Add the buffer to the done buffers list */
        spin_lock_irqsave(&q->done_lock, flags);
        vb->state = state;
@@ -1136,9 +1141,15 @@ err:
 static void __enqueue_in_driver(struct vb2_buffer *vb)
 {
        struct vb2_queue *q = vb->vb2_queue;
+       unsigned int plane;
 
        vb->state = VB2_BUF_STATE_ACTIVE;
        atomic_inc(&q->queued_count);
+
+       /* sync buffers */
+       for (plane = 0; plane < vb->num_planes; ++plane)
+               call_memop(q, prepare, vb->planes[plane].mem_priv);
+
        q->ops->buf_queue(vb);
 }
 
index 689ae4ac2572a672a62639ebedb017545888f304..24b9c90194f285faa57b42243cdb459330124921 100644 (file)
@@ -56,6 +56,10 @@ struct vb2_fileio_data;
  *             dmabuf
  * @unmap_dmabuf: releases access control to the dmabuf - allocator is notified
  *               that this driver is done using the dmabuf for now
+ * @prepare:   called every time the buffer is passed from userspace to the
+ *             driver, useful for cache synchronisation, optional
+ * @finish:    called every time the buffer is passed back from the driver
+ *             to the userspace, also optional
  * @vaddr:     return a kernel virtual address to a given memory buffer
  *             associated with the passed private structure or NULL if no
  *             such mapping exists
@@ -82,6 +86,9 @@ struct vb2_mem_ops {
                                        unsigned long size, int write);
        void            (*put_userptr)(void *buf_priv);
 
+       void            (*prepare)(void *buf_priv);
+       void            (*finish)(void *buf_priv);
+
        void            *(*attach_dmabuf)(void *alloc_ctx, struct dma_buf *dbuf,
                                unsigned long size, int write);
        void            (*detach_dmabuf)(void *buf_priv);