From: Tony K Nadackal <tony.kn@xxxxxxxxxxx>
This patch adds support for IOMMU s5p-jpeg driver if the Exynos IOMMU
and ARM DMA IOMMU configurations are supported. The address space is
created with size limited to 256M and base address set to 0x20000000.
Signed-off-by: Tony K Nadackal <tony.kn@xxxxxxxxxxx>
Signed-off-by: Thierry Escande <thierry.escande@xxxxxxxxxxxxx>
---
drivers/media/platform/s5p-jpeg/jpeg-core.c | 77 +++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
+#if defined(CONFIG_EXYNOS_IOMMU) && defined(CONFIG_ARM_DMA_USE_IOMMU)
+static int jpeg_iommu_init(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ int err;
+
+ mapping = arm_iommu_create_mapping(&platform_bus_type, 0x20000000,
+ SZ_512M);
+ if (IS_ERR(mapping)) {
+ dev_err(dev, "IOMMU mapping failed\n");
+ return PTR_ERR(mapping);
+ }
+
+ dev->dma_parms = devm_kzalloc(dev, sizeof(*dev->dma_parms), GFP_KERNEL);
+ if (!dev->dma_parms) {
+ err = -ENOMEM;
+ goto error_alloc;
+ }
+
+ err = dma_set_max_seg_size(dev, 0xffffffffu);
+ if (err)
+ goto error;
+
+ err = arm_iommu_attach_device(dev, mapping);
+ if (err)
+ goto error;
+
+ return 0;
+
+error:
+ devm_kfree(dev, dev->dma_parms);
+ dev->dma_parms = NULL;
+
+error_alloc:
+ arm_iommu_release_mapping(mapping);
+ mapping = NULL;
+
+ return err;
+}
+
+static void jpeg_iommu_deinit(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+
+ if (mapping) {
+ arm_iommu_detach_device(dev);
+ devm_kfree(dev, dev->dma_parms);
+ dev->dma_parms = NULL;
+ arm_iommu_release_mapping(mapping);
+ mapping = NULL;
+ }
+}
/*
* ============================================================================
* Device file operations
@@ -2816,6 +2882,13 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
+ ret = jpeg_iommu_init(pdev);
@@ -2962,6 +3035,10 @@ static int s5p_jpeg_remove(struct platform_device *pdev)
+ jpeg_iommu_deinit(pdev);
return 0;
}