From: Heng-Ruey Hsu <henry...@chromium.org>

DMA allocations for MMAP type are uncached by default. But for
some cases, CPU has to access the buffers. ie: memcpy for format
converter. Supporting cacheable MMAP improves huge performance.

Signed-off-by: Heng-Ruey Hsu <henry...@chromium.org>
Tested-by: Heng-ruey Hsu <henry...@chromium.org>
Reviewed-by: Tomasz Figa <tf...@chromium.org>
Signed-off-by: Thierry Escande <thierry.esca...@collabora.com>
---
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-dma-contig.c 
b/drivers/media/v4l2-core/videobuf2-dma-contig.c
index fb6a177..c953c24 100644
--- a/drivers/media/v4l2-core/videobuf2-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf2-dma-contig.c
@@ -42,6 +42,12 @@ struct vb2_dc_buf {
 };
 
 /*********************************************/
+/*           Forward declarations            */
+/*********************************************/
+
+static struct sg_table *vb2_dc_get_base_sgt(struct vb2_dc_buf *buf);
+
+/*********************************************/
 /*        scatterlist table functions        */
 /*********************************************/
 
@@ -129,6 +135,10 @@ static void vb2_dc_put(void *buf_priv)
                sg_free_table(buf->sgt_base);
                kfree(buf->sgt_base);
        }
+       if (buf->dma_sgt) {
+               sg_free_table(buf->dma_sgt);
+               kfree(buf->dma_sgt);
+       }
        dma_free_attrs(buf->dev, buf->size, buf->cookie, buf->dma_addr,
                       buf->attrs);
        put_device(buf->dev);
@@ -170,6 +180,10 @@ static void *vb2_dc_alloc(struct device *dev, unsigned 
long attrs,
        buf->handler.put = vb2_dc_put;
        buf->handler.arg = buf;
 
+       if (!(buf->attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
+            (buf->attrs & DMA_ATTR_NON_CONSISTENT))
+               buf->dma_sgt = vb2_dc_get_base_sgt(buf);
+
        atomic_inc(&buf->refcount);
 
        return buf;
@@ -205,6 +219,11 @@ static int vb2_dc_mmap(void *buf_priv, struct 
vm_area_struct *vma)
 
        vma->vm_ops->open(vma);
 
+       if ((buf->attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
+           (buf->attrs & DMA_ATTR_NON_CONSISTENT) &&
+           !buf->dma_sgt)
+               buf->dma_sgt = vb2_dc_get_base_sgt(buf);
+
        pr_debug("%s: mapped dma addr 0x%08lx at 0x%08lx, size %ld\n",
                __func__, (unsigned long)buf->dma_addr, vma->vm_start,
                buf->size);
-- 
2.7.4

Reply via email to