staging: ion: cma heap support map/unmap iommu
authorXu Jianqun <jay.xu@rock-chips.com>
Thu, 21 Jan 2016 11:07:18 +0000 (19:07 +0800)
committerGerrit Code Review <gerrit@rock-chips.com>
Mon, 25 Jan 2016 10:46:27 +0000 (18:46 +0800)
Add apis for cma-heap to map/unmap iommu.

Change-Id: I993d54285691e7015ffa302a4bb776234ca45bcb
Signed-off-by: Xu Jianqun <jay.xu@rock-chips.com>
drivers/staging/android/ion/ion_cma_heap.c

index a3446da4fdc2a6b70a8fb95a8686895156c781c4..f501568d9113eab0ea1c33ea5e5c0dcb0f6616da 100644 (file)
@@ -20,6 +20,9 @@
 #include <linux/errno.h>
 #include <linux/err.h>
 #include <linux/dma-mapping.h>
+#ifdef CONFIG_RK_IOMMU
+#include <linux/rockchip-iovmm.h>
+#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)