]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/exynos/iommu: integrate IOMMU/DMA internal API
authorAndrzej Hajda <a.hajda@samsung.com>
Fri, 12 Oct 2018 10:53:43 +0000 (12:53 +0200)
committerInki Dae <inki.dae@samsung.com>
Tue, 4 Dec 2018 04:23:17 +0000 (13:23 +0900)
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 <a.hajda@samsung.com>
Signed-off-by: Inki Dae <inki.dae@samsung.com>
17 files changed:
drivers/gpu/drm/exynos/Makefile
drivers/gpu/drm/exynos/exynos5433_drm_decon.c
drivers/gpu/drm/exynos/exynos7_drm_decon.c
drivers/gpu/drm/exynos/exynos_drm_dma.c [new file with mode: 0644]
drivers/gpu/drm/exynos/exynos_drm_drv.c
drivers/gpu/drm/exynos/exynos_drm_drv.h
drivers/gpu/drm/exynos/exynos_drm_fb.c
drivers/gpu/drm/exynos/exynos_drm_fbdev.c
drivers/gpu/drm/exynos/exynos_drm_fimc.c
drivers/gpu/drm/exynos/exynos_drm_fimd.c
drivers/gpu/drm/exynos/exynos_drm_g2d.c
drivers/gpu/drm/exynos/exynos_drm_gem.c
drivers/gpu/drm/exynos/exynos_drm_gsc.c
drivers/gpu/drm/exynos/exynos_drm_iommu.h
drivers/gpu/drm/exynos/exynos_drm_rotator.c
drivers/gpu/drm/exynos/exynos_drm_scaler.c
drivers/gpu/drm/exynos/exynos_mixer.c

index ab763977ab28c0f8f5f6e6949b6f12bb9bf9ad22..94433838445f528bda9e1a31963a3c56b47d71ec 100644 (file)
@@ -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
index ce08d77336f07ba8fad6fdc3a59d359187418678..40723f395ecc825bed03b111c90afab17f8d2c9a 100644 (file)
@@ -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
@@ -579,7 +578,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 = {
index e78978eea5cb518d91390067b91c41492a11183b..381aa3d60e37a86d7bc0be1c4a8737ace9098498 100644 (file)
@@ -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 (file)
index 0000000..f01cb10
--- /dev/null
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// Copyright (c) 2012 Samsung Electronics Co., Ltd.
+// Author: Andrzej Hajda <a.hajda@samsung.com>
+
+#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))
+               drm_iommu_detach_device(drm, dev);
+}
+
+void exynos_drm_cleanup_dma(struct drm_device *drm)
+{
+       if (IS_ENABLED(CONFIG_EXYNOS_IOMMU))
+               drm_release_iommu_mapping(drm);
+}
index 3cf21d84a3d9a30ae7577e75ff6bb748432ddbbf..2c75e789b2a7e9faf80aa9c6eac3ef5b65fa98e6 100644 (file)
@@ -30,7 +30,6 @@
 #include "exynos_drm_ipp.h"
 #include "exynos_drm_vidi.h"
 #include "exynos_drm_g2d.h"
-#include "exynos_drm_iommu.h"
 
 #define DRIVER_NAME    "exynos"
 #define DRIVER_DESC    "Samsung SoC DRM"
 #define DRIVER_MAJOR   1
 #define DRIVER_MINOR   1
 
-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);
-}
-
 static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
 {
        struct drm_exynos_file_private *file_priv;
@@ -367,7 +345,7 @@ err_unbind_all:
        component_unbind_all(drm->dev, drm);
 err_mode_config_cleanup:
        drm_mode_config_cleanup(drm);
-       drm_release_iommu_mapping(drm);
+       exynos_drm_cleanup_dma(drm);
        kfree(private);
 err_free_drm:
        drm_dev_put(drm);
@@ -386,7 +364,7 @@ static void exynos_drm_unbind(struct device *dev)
 
        component_unbind_all(drm->dev, drm);
        drm_mode_config_cleanup(drm);
-       drm_release_iommu_mapping(drm);
+       exynos_drm_cleanup_dma(drm);
 
        kfree(drm->dev_private);
        drm->dev_private = NULL;
index 1d4c3c425404c84a332d51da60a36ecae6a5cea1..71eb240bc1f4f7d7c7dc1ab342cf03216ef98a44 100644 (file)
@@ -214,7 +214,16 @@ static inline struct device *to_dma_dev(struct drm_device *dev)
        return priv->dma_dev;
 }
 
+static inline bool is_drm_iommu_supported(struct drm_device *drm_dev)
+{
+       struct exynos_drm_private *priv = drm_dev->dev_private;
+
+       return priv->mapping ? true : false;
+}
+
 int exynos_drm_register_dma(struct drm_device *drm, struct device *dev);
+void exynos_drm_unregister_dma(struct drm_device *drm, struct device *dev);
+void exynos_drm_cleanup_dma(struct drm_device *drm);
 
 #ifdef CONFIG_DRM_EXYNOS_DPI
 struct drm_encoder *exynos_dpi_probe(struct device *dev);
index 9f52382e19ee338e18dbe8212b0d1a69c604d3e9..31eb538a44ae1950c7f94fa9b994abb154b525df 100644 (file)
@@ -24,7 +24,6 @@
 #include "exynos_drm_drv.h"
 #include "exynos_drm_fb.h"
 #include "exynos_drm_fbdev.h"
-#include "exynos_drm_iommu.h"
 #include "exynos_drm_crtc.h"
 
 static int check_fb_gem_memory_type(struct drm_device *drm_dev,
index 01d182289efa38fd75a83cd399b02bbfd1e590c0..ce9604ca8041d7b03a783e1cad743a7480074cc3 100644 (file)
@@ -23,7 +23,6 @@
 #include "exynos_drm_drv.h"
 #include "exynos_drm_fb.h"
 #include "exynos_drm_fbdev.h"
-#include "exynos_drm_iommu.h"
 
 #define MAX_CONNECTOR          4
 #define PREFERRED_BPP          32
index 68bfe2cd76d6659e8b25e2076f593992eac60ed3..90dfea0aec4d3cdcf33d6635c843f5dc578812a3 100644 (file)
@@ -25,7 +25,6 @@
 #include <drm/exynos_drm.h>
 #include "regs-fimc.h"
 #include "exynos_drm_drv.h"
-#include "exynos_drm_iommu.h"
 #include "exynos_drm_ipp.h"
 
 /*
@@ -1149,7 +1148,7 @@ static void fimc_unbind(struct device *dev, struct device *master,
        struct exynos_drm_ipp *ipp = &ctx->ipp;
 
        exynos_drm_ipp_unregister(drm_dev, ipp);
-       drm_iommu_detach_device(drm_dev, dev);
+       exynos_drm_unregister_dma(drm_dev, dev);
 }
 
 static const struct component_ops fimc_component_ops = {
index 5b3d51460294e85427ce8b25a0066b3cc1ca5702..e3d6a8584715a7966b2d87bfa546bdddf0f90605 100644 (file)
@@ -32,7 +32,6 @@
 #include "exynos_drm_fb.h"
 #include "exynos_drm_crtc.h"
 #include "exynos_drm_plane.h"
-#include "exynos_drm_iommu.h"
 
 /*
  * FIMD stands for Fully Interactive Mobile Display and
@@ -1021,7 +1020,7 @@ static void fimd_unbind(struct device *dev, struct device *master,
 
        fimd_disable(ctx->crtc);
 
-       drm_iommu_detach_device(ctx->drm_dev, ctx->dev);
+       exynos_drm_unregister_dma(ctx->drm_dev, ctx->dev);
 
        if (ctx->encoder)
                exynos_dpi_remove(ctx->encoder);
index 86624ec20cde72915ddab869440738e8a68195bc..24c536d6d9cf866afda4c9839fdbc6e61a5a8854 100644 (file)
@@ -25,7 +25,6 @@
 #include "exynos_drm_drv.h"
 #include "exynos_drm_g2d.h"
 #include "exynos_drm_gem.h"
-#include "exynos_drm_iommu.h"
 
 #define G2D_HW_MAJOR_VER               4
 #define G2D_HW_MINOR_VER               1
@@ -1430,7 +1429,7 @@ static void g2d_unbind(struct device *dev, struct device *master, void *data)
        priv->g2d_dev = NULL;
 
        cancel_work_sync(&g2d->runqueue_work);
-       drm_iommu_detach_device(g2d->drm_dev, dev);
+       exynos_drm_unregister_dma(g2d->drm_dev, dev);
 }
 
 static const struct component_ops g2d_component_ops = {
index 34ace85feb6883e3dcf9793d5057a5c1de2ebb21..df66c383a877a583be0e457a0f866a8b5f3b819f 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "exynos_drm_drv.h"
 #include "exynos_drm_gem.h"
-#include "exynos_drm_iommu.h"
 
 static int exynos_drm_alloc_buf(struct exynos_drm_gem *exynos_gem)
 {
index d2607da9f3d3a1b6cf46a6c6616d3fb03c8a7e6a..f048d97fe9e2e9b522b0366b868e9ca09f156c97 100644 (file)
@@ -24,7 +24,6 @@
 #include <drm/exynos_drm.h>
 #include "regs-gsc.h"
 #include "exynos_drm_drv.h"
-#include "exynos_drm_iommu.h"
 #include "exynos_drm_ipp.h"
 
 /*
@@ -1190,7 +1189,7 @@ static void gsc_unbind(struct device *dev, struct device *master,
        struct exynos_drm_ipp *ipp = &ctx->ipp;
 
        exynos_drm_ipp_unregister(drm_dev, ipp);
-       drm_iommu_detach_device(drm_dev, dev);
+       exynos_drm_unregister_dma(drm_dev, dev);
 }
 
 static const struct component_ops gsc_component_ops = {
index c9e9c66479037a3b1252a6265cbced1196ba0d8f..5aaece0a3a2905e2ba2cef828c26a9e8777799ab 100644 (file)
@@ -96,13 +96,6 @@ int drm_iommu_attach_device(struct drm_device *drm_dev,
 void drm_iommu_detach_device(struct drm_device *dev_dev,
                                struct device *subdrv_dev);
 
-static inline bool is_drm_iommu_supported(struct drm_device *drm_dev)
-{
-       struct exynos_drm_private *priv = drm_dev->dev_private;
-
-       return priv->mapping ? true : false;
-}
-
 #else
 
 static inline int drm_create_iommu_mapping(struct drm_device *drm_dev)
@@ -125,10 +118,5 @@ static inline void drm_iommu_detach_device(struct drm_device *drm_dev,
 {
 }
 
-static inline bool is_drm_iommu_supported(struct drm_device *drm_dev)
-{
-       return false;
-}
-
 #endif
 #endif
index 7d4b5a136a18673e4f017232b72727d848c58b69..8d67b2a54be3b66f68e008d07a6203140bf2f7f4 100644 (file)
@@ -23,7 +23,6 @@
 #include <drm/exynos_drm.h>
 #include "regs-rotator.h"
 #include "exynos_drm_drv.h"
-#include "exynos_drm_iommu.h"
 #include "exynos_drm_ipp.h"
 
 /*
@@ -263,7 +262,7 @@ static void rotator_unbind(struct device *dev, struct device *master,
        struct exynos_drm_ipp *ipp = &rot->ipp;
 
        exynos_drm_ipp_unregister(drm_dev, ipp);
-       drm_iommu_detach_device(rot->drm_dev, rot->dev);
+       exynos_drm_unregister_dma(rot->drm_dev, rot->dev);
 }
 
 static const struct component_ops rotator_component_ops = {
index 74e761c162dd7f6e4c047406212a81daf4a4134d..71270efa64f3f35e7d983488b13202192936b245 100644 (file)
@@ -23,7 +23,6 @@
 #include "regs-scaler.h"
 #include "exynos_drm_fb.h"
 #include "exynos_drm_drv.h"
-#include "exynos_drm_iommu.h"
 #include "exynos_drm_ipp.h"
 
 #define scaler_read(offset)            readl(scaler->regs + (offset))
@@ -473,7 +472,7 @@ static void scaler_unbind(struct device *dev, struct device *master,
        struct exynos_drm_ipp *ipp = &scaler->ipp;
 
        exynos_drm_ipp_unregister(drm_dev, ipp);
-       drm_iommu_detach_device(scaler->drm_dev, scaler->dev);
+       exynos_drm_unregister_dma(scaler->drm_dev, scaler->dev);
 }
 
 static const struct component_ops scaler_component_ops = {
index 52193de577d20fbba51fa577e9b7ab7989e8dac2..5a47af8e76c00907dfeb980595902b7e6657937d 100644 (file)
@@ -40,7 +40,6 @@
 #include "exynos_drm_crtc.h"
 #include "exynos_drm_fb.h"
 #include "exynos_drm_plane.h"
-#include "exynos_drm_iommu.h"
 
 #define MIXER_WIN_NR           3
 #define VP_DEFAULT_WIN         2
@@ -883,7 +882,7 @@ static int mixer_initialize(struct mixer_context *mixer_ctx,
 
 static void mixer_ctx_remove(struct mixer_context *mixer_ctx)
 {
-       drm_iommu_detach_device(mixer_ctx->drm_dev, mixer_ctx->dev);
+       exynos_drm_unregister_dma(mixer_ctx->drm_dev, mixer_ctx->dev);
 }
 
 static int mixer_enable_vblank(struct exynos_drm_crtc *crtc)