From bf4c54a4a39495d7105e99bdead2024ecc1be24c Mon Sep 17 00:00:00 2001 From: Janghyuck Kim Date: Wed, 2 May 2018 14:32:19 +0900 Subject: [PATCH] [COMMON] media: m2m1shot: support IO coherency IO coherency is supported by checking dma-coherent property and passed IOMMU_CACHE property to ion_iovmm_map(). Change-Id: I5afb0849ebf11030e6c765e160e50dd973f8df79 Signed-off-by: Janghyuck Kim --- drivers/media/m2m1shot-helper.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/media/m2m1shot-helper.c b/drivers/media/m2m1shot-helper.c index 3b7f00cb7944..98f56a90b795 100644 --- a/drivers/media/m2m1shot-helper.c +++ b/drivers/media/m2m1shot-helper.c @@ -52,22 +52,28 @@ void m2m1shot_unmap_dma_buf(struct device *dev, } EXPORT_SYMBOL(m2m1shot_unmap_dma_buf); +static inline bool is_dma_coherent(struct device *dev) +{ + return device_get_dma_attr(dev) == DEV_DMA_COHERENT; +} + int m2m1shot_dma_addr_map(struct device *dev, struct m2m1shot_buffer_dma *buf, int plane_idx, enum dma_data_direction dir) { struct m2m1shot_buffer_plane_dma *plane = &buf->plane[plane_idx]; dma_addr_t iova; + int prot = IOMMU_READ; + + if (dir == DMA_FROM_DEVICE) + prot |= IOMMU_WRITE; + if (is_dma_coherent(dev)) + prot |= IOMMU_CACHE; if (plane->dmabuf) { iova = ion_iovmm_map(plane->attachment, 0, - plane->bytes_used, dir, 0); + plane->bytes_used, dir, prot); } else { - int prot = IOMMU_READ; - - if (dir == DMA_FROM_DEVICE) - prot |= IOMMU_WRITE; - down_read(¤t->mm->mmap_sem); iova = exynos_iovmm_map_userptr(dev, buf->buffer->plane[plane_idx].userptr, @@ -101,6 +107,9 @@ void m2m1shot_sync_for_device(struct device *dev, struct m2m1shot_buffer_plane_dma *plane, enum dma_data_direction dir) { + if (is_dma_coherent(dev)) + return; + if (plane->dmabuf) dma_sync_sg_for_device(dev, plane->sgt->sgl, plane->sgt->orig_nents, dir); @@ -114,6 +123,9 @@ void m2m1shot_sync_for_cpu(struct device *dev, struct m2m1shot_buffer_plane_dma *plane, enum dma_data_direction dir) { + if (is_dma_coherent(dev)) + return; + if (plane->dmabuf) dma_sync_sg_for_cpu(dev, plane->sgt->sgl, plane->sgt->orig_nents, dir); -- 2.20.1