[RAMEN9610-12270] media/vb2-dma-sg: add IOMMU_UNCACHED memops flag
authorCho KyongHo <pullip.cho@samsung.com>
Mon, 18 Feb 2019 04:10:45 +0000 (13:10 +0900)
committerhskang <hs1218.kang@samsung.com>
Wed, 20 Feb 2019 01:00:39 +0000 (10:00 +0900)
VB2_DMA_SG_MEMFLAG_IOMMU_UNCACHED is introduced to prevent configuring
IOMMU_CACHE to iovmm_map() and ion_iovmm_map() which force shareable
mapping to the page table of the client device.
It is required by some shareable devices(devices with I/O Cache
coherency) which does not want to create shareable mappings for some
buffers.

Change-Id: Ic0c380a35cb6044d8d92500716081d45535965fe
Signed-off-by: Cho KyongHo <pullip.cho@samsung.com>
drivers/media/v4l2-core/videobuf2-dma-sg.c
include/media/videobuf2-dma-sg.h

index 4ad5c3ad9cc77d70b549955803046140a109b1d2..a3f6eaeb3c535df9f3dd7bc424b0a65cfb7b7040 100644 (file)
@@ -150,7 +150,8 @@ static void *vb2_dma_sg_alloc(struct device *dev, unsigned long dma_attrs,
 
        sgt = &buf->sg_table;
 
-       if (device_get_dma_attr(dev) == DEV_DMA_COHERENT)
+       if (!(memflags & VB2_DMA_SG_MEMFLAG_IOMMU_UNCACHED) &&
+           (device_get_dma_attr(dev) == DEV_DMA_COHERENT))
                ioprot |= IOMMU_CACHE;
 
        buf->iova = iovmm_map(buf->dev, sgt->sgl, 0, size,
@@ -303,7 +304,8 @@ static void *vb2_dma_sg_get_userptr(struct device *dev, unsigned long vaddr,
        for_each_sg(sgt->sgl, s, sgt->orig_nents, i)
                s->dma_address = sg_phys(s);
 
-       if (device_get_dma_attr(dev) == DEV_DMA_COHERENT)
+       if (!(memflags & VB2_DMA_SG_MEMFLAG_IOMMU_UNCACHED) &&
+           (device_get_dma_attr(dev) == DEV_DMA_COHERENT))
                ioprot |= IOMMU_CACHE;
 
        buf->iova = iovmm_map(buf->dev, sgt->sgl, 0, size,
@@ -621,7 +623,8 @@ static int vb2_dma_sg_map_dmabuf(void *mem_priv, size_t size, int memflags)
         */
        if ((dmabuf_container_get_count(buf->db_attach->dmabuf) < 0) &&
            ((buf->iova == 0) || IS_ERR_VALUE(buf->iova))) {
-               if (device_get_dma_attr(buf->dev) == DEV_DMA_COHERENT)
+               if (!(memflags & VB2_DMA_SG_MEMFLAG_IOMMU_UNCACHED) &&
+                   (device_get_dma_attr(buf->dev) == DEV_DMA_COHERENT))
                        ioprot |= IOMMU_CACHE;
 
                buf->iova = ion_iovmm_map(buf->db_attach, 0, buf->size,
index 8175c7204ae5a8c703d73ea400751187f702e3bd..5bc9121384ea35ffd65a78f1e9b15669ae9a529c 100644 (file)
@@ -15,6 +15,8 @@
 
 #include <media/videobuf2-v4l2.h>
 
+#define VB2_DMA_SG_MEMFLAG_IOMMU_UNCACHED      16
+
 static inline struct sg_table *vb2_dma_sg_plane_desc(
                struct vb2_buffer *vb, unsigned int plane_no)
 {