From 9da1bda27c2212dff804b9cacc6664a0e5d626f3 Mon Sep 17 00:00:00 2001 From: Xu Jianqun Date: Thu, 21 Jan 2016 19:07:18 +0800 Subject: [PATCH] staging: ion: cma heap support map/unmap iommu Add apis for cma-heap to map/unmap iommu. Change-Id: I993d54285691e7015ffa302a4bb776234ca45bcb Signed-off-by: Xu Jianqun --- drivers/staging/android/ion/ion_cma_heap.c | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c index a3446da4fdc2..f501568d9113 100644 --- a/drivers/staging/android/ion/ion_cma_heap.c +++ b/drivers/staging/android/ion/ion_cma_heap.c @@ -20,6 +20,9 @@ #include #include #include +#ifdef CONFIG_RK_IOMMU +#include +#endif #include "ion.h" #include "ion_priv.h" @@ -159,6 +162,45 @@ static void ion_cma_unmap_kernel(struct ion_heap *heap, { } +#ifdef CONFIG_RK_IOMMU +static int ion_cma_map_iommu(struct ion_buffer *buffer, + struct device *iommu_dev, + struct ion_iommu_map *data, + unsigned long iova_length, + unsigned long flags) +{ + int ret = 0; + struct ion_cma_buffer_info *info = buffer->priv_virt; + + data->iova_addr = rockchip_iovmm_map(iommu_dev, + info->table->sgl, + 0, + iova_length); + pr_debug("%s: map %pad -> %lx\n", __func__, + &info->table->sgl->dma_address, + data->iova_addr); + if (IS_ERR_VALUE(data->iova_addr)) { + pr_err("%s: failed: %lx\n", __func__, data->iova_addr); + ret = data->iova_addr; + goto out; + } + + data->mapped_size = iova_length; + +out: + return ret; +} + +void ion_cma_unmap_iommu(struct device *iommu_dev, struct ion_iommu_map *data) +{ + pr_debug("%s: unmap %x@%lx\n", + __func__, + data->mapped_size, + data->iova_addr); + rockchip_iovmm_unmap(iommu_dev, data->iova_addr); +} +#endif + static struct ion_heap_ops ion_cma_ops = { .allocate = ion_cma_allocate, .free = ion_cma_free, @@ -168,6 +210,10 @@ static struct ion_heap_ops ion_cma_ops = { .map_user = ion_cma_mmap, .map_kernel = ion_cma_map_kernel, .unmap_kernel = ion_cma_unmap_kernel, +#ifdef CONFIG_RK_IOMMU + .map_iommu = ion_cma_map_iommu, + .unmap_iommu = ion_cma_unmap_iommu, +#endif }; struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *data) -- 2.34.1