From 74cc0e7d14c2bd6af82d8bea0e18b9673b050d27 Mon Sep 17 00:00:00 2001 From: Cho KyongHo Date: Mon, 18 Feb 2019 13:10:45 +0900 Subject: [PATCH] [RAMEN9610-12270] media/vb2-dma-sg: add IOMMU_UNCACHED memops flag 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 --- drivers/media/v4l2-core/videobuf2-dma-sg.c | 9 ++++++--- include/media/videobuf2-dma-sg.h | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/media/v4l2-core/videobuf2-dma-sg.c b/drivers/media/v4l2-core/videobuf2-dma-sg.c index 4ad5c3ad9cc7..a3f6eaeb3c53 100644 --- a/drivers/media/v4l2-core/videobuf2-dma-sg.c +++ b/drivers/media/v4l2-core/videobuf2-dma-sg.c @@ -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, diff --git a/include/media/videobuf2-dma-sg.h b/include/media/videobuf2-dma-sg.h index 8175c7204ae5..5bc9121384ea 100644 --- a/include/media/videobuf2-dma-sg.h +++ b/include/media/videobuf2-dma-sg.h @@ -15,6 +15,8 @@ #include +#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) { -- 2.20.1