[PATCH 3/6] drm/exynos/iommu: integrate IOMMU/DMA internal API

2018-10-12 Thread Andrzej Hajda
Exynos DRM drivers should work with and without IOMMU. Providing common
API generic to both scenarios should make code cleaner and allow further
code improvements.
The patch removes including of exynos_drm_iommu.h as the file contains
mostly IOMMU specific stuff, instead it exposes exynos_drm_*_dma functions
and puts them into exynos_drm_dma.c.

Signed-off-by: Andrzej Hajda 
---
 drivers/gpu/drm/exynos/Makefile   |  2 +-
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c |  3 +-
 drivers/gpu/drm/exynos/exynos7_drm_decon.c|  3 +-
 drivers/gpu/drm/exynos/exynos_drm_dma.c   | 40 +++
 drivers/gpu/drm/exynos/exynos_drm_drv.c   | 26 +---
 drivers/gpu/drm/exynos/exynos_drm_drv.h   |  9 +
 drivers/gpu/drm/exynos/exynos_drm_fb.c|  1 -
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |  1 -
 drivers/gpu/drm/exynos/exynos_drm_fimc.c  |  3 +-
 drivers/gpu/drm/exynos/exynos_drm_fimd.c  |  3 +-
 drivers/gpu/drm/exynos/exynos_drm_g2d.c   |  3 +-
 drivers/gpu/drm/exynos/exynos_drm_gem.c   |  1 -
 drivers/gpu/drm/exynos/exynos_drm_gsc.c   |  3 +-
 drivers/gpu/drm/exynos/exynos_drm_iommu.h | 12 --
 drivers/gpu/drm/exynos/exynos_drm_rotator.c   |  3 +-
 drivers/gpu/drm/exynos/exynos_drm_scaler.c|  3 +-
 drivers/gpu/drm/exynos/exynos_mixer.c |  3 +-
 17 files changed, 61 insertions(+), 58 deletions(-)
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_dma.c

diff --git a/drivers/gpu/drm/exynos/Makefile b/drivers/gpu/drm/exynos/Makefile
index ab763977ab28..94433838445f 100644
--- a/drivers/gpu/drm/exynos/Makefile
+++ b/drivers/gpu/drm/exynos/Makefile
@@ -4,7 +4,7 @@
 # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
 
 exynosdrm-y := exynos_drm_drv.o exynos_drm_crtc.o exynos_drm_fb.o \
-   exynos_drm_gem.o exynos_drm_plane.o
+   exynos_drm_gem.o exynos_drm_plane.o exynos_drm_dma.o
 
 exynosdrm-$(CONFIG_DRM_FBDEV_EMULATION) += exynos_drm_fbdev.o
 exynosdrm-$(CONFIG_EXYNOS_IOMMU) += exynos_drm_iommu.o
diff --git a/drivers/gpu/drm/exynos/exynos5433_drm_decon.c 
b/drivers/gpu/drm/exynos/exynos5433_drm_decon.c
index b0d80e17ab85..6c821a16e95e 100644
--- a/drivers/gpu/drm/exynos/exynos5433_drm_decon.c
+++ b/drivers/gpu/drm/exynos/exynos5433_drm_decon.c
@@ -25,7 +25,6 @@
 #include "exynos_drm_crtc.h"
 #include "exynos_drm_fb.h"
 #include "exynos_drm_plane.h"
-#include "exynos_drm_iommu.h"
 #include "regs-decon5433.h"
 
 #define DSD_CFG_MUX 0x1004
@@ -588,7 +587,7 @@ static void decon_unbind(struct device *dev, struct device 
*master, void *data)
decon_disable(ctx->crtc);
 
/* detach this sub driver from iommu mapping if supported. */
-   drm_iommu_detach_device(ctx->drm_dev, ctx->dev);
+   exynos_drm_unregister_dma(ctx->drm_dev, ctx->dev);
 }
 
 static const struct component_ops decon_component_ops = {
diff --git a/drivers/gpu/drm/exynos/exynos7_drm_decon.c 
b/drivers/gpu/drm/exynos/exynos7_drm_decon.c
index e78978eea5cb..381aa3d60e37 100644
--- a/drivers/gpu/drm/exynos/exynos7_drm_decon.c
+++ b/drivers/gpu/drm/exynos/exynos7_drm_decon.c
@@ -30,7 +30,6 @@
 #include "exynos_drm_plane.h"
 #include "exynos_drm_drv.h"
 #include "exynos_drm_fb.h"
-#include "exynos_drm_iommu.h"
 #include "regs-decon7.h"
 
 /*
@@ -139,7 +138,7 @@ static int decon_ctx_initialize(struct decon_context *ctx,
 static void decon_ctx_remove(struct decon_context *ctx)
 {
/* detach this sub driver from iommu mapping if supported. */
-   drm_iommu_detach_device(ctx->drm_dev, ctx->dev);
+   exynos_drm_unregister_dma(ctx->drm_dev, ctx->dev);
 }
 
 static u32 decon_calc_clkdiv(struct decon_context *ctx,
diff --git a/drivers/gpu/drm/exynos/exynos_drm_dma.c 
b/drivers/gpu/drm/exynos/exynos_drm_dma.c
new file mode 100644
index ..f01cb102956d
--- /dev/null
+++ b/drivers/gpu/drm/exynos/exynos_drm_dma.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+// Author: Andrzej Hajda 
+
+#include "exynos_drm_drv.h"
+#include "exynos_drm_iommu.h"
+
+int exynos_drm_register_dma(struct drm_device *drm, struct device *dev)
+{
+   struct exynos_drm_private *priv = drm->dev_private;
+   int ret;
+
+   if (!priv->dma_dev) {
+   priv->dma_dev = dev;
+   DRM_INFO("Exynos DRM: using %s device for DMA mapping 
operations\n",
+dev_name(dev));
+   /* create common IOMMU mapping for all Exynos DRM devices */
+   ret = drm_create_iommu_mapping(drm);
+   if (ret < 0) {
+   priv->dma_dev = NULL;
+   DRM_ERROR("failed to create iommu mapping.\n");
+   return -EINVAL;
+   }
+   }
+
+   return drm_iommu_attach_device(drm, dev);
+}
+
+void exynos_drm_unregister_dma(struct drm_device *drm, struct device *dev)
+{
+   if (IS_ENABLED(CONFIG_EXYNOS_IOMMU))
+   

[PATCH 3/6] drm/exynos/iommu: integrate IOMMU/DMA internal API

2018-09-25 Thread Andrzej Hajda
Exynos DRM drivers should work with and without IOMMU. Providing common
API generic to both scenarios should make code cleaner and allow further
code improvements.
The patch removes including of exynos_drm_iommu.h as the file contains
mostly IOMMU specific stuff, instead it exposes exynos_drm_*_dma functions
and puts them into exynos_drm_dma.c.

Signed-off-by: Andrzej Hajda 
---
 drivers/gpu/drm/exynos/Makefile   |  2 +-
 drivers/gpu/drm/exynos/exynos5433_drm_decon.c |  3 +-
 drivers/gpu/drm/exynos/exynos7_drm_decon.c|  3 +-
 drivers/gpu/drm/exynos/exynos_drm_dma.c   | 40 +++
 drivers/gpu/drm/exynos/exynos_drm_drv.c   | 26 +---
 drivers/gpu/drm/exynos/exynos_drm_drv.h   |  9 +
 drivers/gpu/drm/exynos/exynos_drm_fb.c|  1 -
 drivers/gpu/drm/exynos/exynos_drm_fbdev.c |  1 -
 drivers/gpu/drm/exynos/exynos_drm_fimc.c  |  3 +-
 drivers/gpu/drm/exynos/exynos_drm_fimd.c  |  3 +-
 drivers/gpu/drm/exynos/exynos_drm_g2d.c   |  3 +-
 drivers/gpu/drm/exynos/exynos_drm_gem.c   |  1 -
 drivers/gpu/drm/exynos/exynos_drm_gsc.c   |  3 +-
 drivers/gpu/drm/exynos/exynos_drm_iommu.h | 12 --
 drivers/gpu/drm/exynos/exynos_drm_rotator.c   |  3 +-
 drivers/gpu/drm/exynos/exynos_drm_scaler.c|  3 +-
 drivers/gpu/drm/exynos/exynos_mixer.c |  3 +-
 17 files changed, 61 insertions(+), 58 deletions(-)
 create mode 100644 drivers/gpu/drm/exynos/exynos_drm_dma.c

diff --git a/drivers/gpu/drm/exynos/Makefile b/drivers/gpu/drm/exynos/Makefile
index ab763977ab28..94433838445f 100644
--- a/drivers/gpu/drm/exynos/Makefile
+++ b/drivers/gpu/drm/exynos/Makefile
@@ -4,7 +4,7 @@
 # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
 
 exynosdrm-y := exynos_drm_drv.o exynos_drm_crtc.o exynos_drm_fb.o \
-   exynos_drm_gem.o exynos_drm_plane.o
+   exynos_drm_gem.o exynos_drm_plane.o exynos_drm_dma.o
 
 exynosdrm-$(CONFIG_DRM_FBDEV_EMULATION) += exynos_drm_fbdev.o
 exynosdrm-$(CONFIG_EXYNOS_IOMMU) += exynos_drm_iommu.o
diff --git a/drivers/gpu/drm/exynos/exynos5433_drm_decon.c 
b/drivers/gpu/drm/exynos/exynos5433_drm_decon.c
index b0d80e17ab85..6c821a16e95e 100644
--- a/drivers/gpu/drm/exynos/exynos5433_drm_decon.c
+++ b/drivers/gpu/drm/exynos/exynos5433_drm_decon.c
@@ -25,7 +25,6 @@
 #include "exynos_drm_crtc.h"
 #include "exynos_drm_fb.h"
 #include "exynos_drm_plane.h"
-#include "exynos_drm_iommu.h"
 #include "regs-decon5433.h"
 
 #define DSD_CFG_MUX 0x1004
@@ -588,7 +587,7 @@ static void decon_unbind(struct device *dev, struct device 
*master, void *data)
decon_disable(ctx->crtc);
 
/* detach this sub driver from iommu mapping if supported. */
-   drm_iommu_detach_device(ctx->drm_dev, ctx->dev);
+   exynos_drm_unregister_dma(ctx->drm_dev, ctx->dev);
 }
 
 static const struct component_ops decon_component_ops = {
diff --git a/drivers/gpu/drm/exynos/exynos7_drm_decon.c 
b/drivers/gpu/drm/exynos/exynos7_drm_decon.c
index e78978eea5cb..381aa3d60e37 100644
--- a/drivers/gpu/drm/exynos/exynos7_drm_decon.c
+++ b/drivers/gpu/drm/exynos/exynos7_drm_decon.c
@@ -30,7 +30,6 @@
 #include "exynos_drm_plane.h"
 #include "exynos_drm_drv.h"
 #include "exynos_drm_fb.h"
-#include "exynos_drm_iommu.h"
 #include "regs-decon7.h"
 
 /*
@@ -139,7 +138,7 @@ static int decon_ctx_initialize(struct decon_context *ctx,
 static void decon_ctx_remove(struct decon_context *ctx)
 {
/* detach this sub driver from iommu mapping if supported. */
-   drm_iommu_detach_device(ctx->drm_dev, ctx->dev);
+   exynos_drm_unregister_dma(ctx->drm_dev, ctx->dev);
 }
 
 static u32 decon_calc_clkdiv(struct decon_context *ctx,
diff --git a/drivers/gpu/drm/exynos/exynos_drm_dma.c 
b/drivers/gpu/drm/exynos/exynos_drm_dma.c
new file mode 100644
index ..f01cb102956d
--- /dev/null
+++ b/drivers/gpu/drm/exynos/exynos_drm_dma.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+// Author: Andrzej Hajda 
+
+#include "exynos_drm_drv.h"
+#include "exynos_drm_iommu.h"
+
+int exynos_drm_register_dma(struct drm_device *drm, struct device *dev)
+{
+   struct exynos_drm_private *priv = drm->dev_private;
+   int ret;
+
+   if (!priv->dma_dev) {
+   priv->dma_dev = dev;
+   DRM_INFO("Exynos DRM: using %s device for DMA mapping 
operations\n",
+dev_name(dev));
+   /* create common IOMMU mapping for all Exynos DRM devices */
+   ret = drm_create_iommu_mapping(drm);
+   if (ret < 0) {
+   priv->dma_dev = NULL;
+   DRM_ERROR("failed to create iommu mapping.\n");
+   return -EINVAL;
+   }
+   }
+
+   return drm_iommu_attach_device(drm, dev);
+}
+
+void exynos_drm_unregister_dma(struct drm_device *drm, struct device *dev)
+{
+   if (IS_ENABLED(CONFIG_EXYNOS_IOMMU))
+