All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrzej Hajda <a.hajda@samsung.com>
To: Inki Dae <inki.dae@samsung.com>
Cc: linux-samsung-soc@vger.kernel.org,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	dri-devel@lists.freedesktop.org,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Subject: [PATCH 5/6] drm/exynos/iommu: replace preprocessor conditionals with C conditionals
Date: Fri, 12 Oct 2018 12:53:45 +0200	[thread overview]
Message-ID: <20181012105346.3754-6-a.hajda@samsung.com> (raw)
In-Reply-To: <20181012105346.3754-1-a.hajda@samsung.com>

Using C conditionals is preferred solution - it provides better code
coverage, makes code more clear.

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
 drivers/gpu/drm/exynos/exynos_drm_iommu.c | 108 ++++++++--------------
 1 file changed, 36 insertions(+), 72 deletions(-)

diff --git a/drivers/gpu/drm/exynos/exynos_drm_iommu.c b/drivers/gpu/drm/exynos/exynos_drm_iommu.c
index 564f1529d77e..14558dedc043 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_iommu.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_iommu.c
@@ -12,84 +12,30 @@
 #include <drm/drmP.h>
 #include <drm/exynos_drm.h>
 
+#include <linux/dma-iommu.h>
 #include <linux/dma-mapping.h>
 #include <linux/iommu.h>
 
 #include "exynos_drm_drv.h"
 #include "exynos_drm_iommu.h"
 
-#define EXYNOS_DEV_ADDR_START	0x20000000
-#define EXYNOS_DEV_ADDR_SIZE	0x40000000
-
 #if defined(CONFIG_ARM_DMA_USE_IOMMU)
 #include <asm/dma-iommu.h>
-
-static inline int __exynos_iommu_create_mapping(struct exynos_drm_private *priv,
-					unsigned long start, unsigned long size)
-{
-	priv->mapping = arm_iommu_create_mapping(&platform_bus_type, start,
-						 size);
-	return IS_ERR(priv->mapping);
-}
-
-static inline void
-__exynos_iommu_release_mapping(struct exynos_drm_private *priv)
-{
-	arm_iommu_release_mapping(priv->mapping);
-}
-
-static inline int __exynos_iommu_attach(struct exynos_drm_private *priv,
-					struct device *dev)
-{
-	if (dev->archdata.mapping)
-		arm_iommu_detach_device(dev);
-
-	return arm_iommu_attach_device(dev, priv->mapping);
-}
-
-static inline void __exynos_iommu_detach(struct exynos_drm_private *priv,
-					 struct device *dev)
-{
-	arm_iommu_detach_device(dev);
-}
-
-#elif defined(CONFIG_IOMMU_DMA)
-#include <linux/dma-iommu.h>
-
-static inline int __exynos_iommu_create_mapping(struct exynos_drm_private *priv,
-					unsigned long start, unsigned long size)
-{
-	priv->mapping = iommu_get_domain_for_dev(priv->dma_dev);
-	return 0;
-}
-
-static inline void __exynos_iommu_release_mapping(struct exynos_drm_private *priv)
-{
-	priv->mapping = NULL;
-}
-
-static inline int __exynos_iommu_attach(struct exynos_drm_private *priv,
-					struct device *dev)
-{
-	struct iommu_domain *domain = priv->mapping;
-
-	if (dev != priv->dma_dev)
-		return iommu_attach_device(domain, dev);
-	return 0;
-}
-
-static inline void __exynos_iommu_detach(struct exynos_drm_private *priv,
-					 struct device *dev)
-{
-	struct iommu_domain *domain = priv->mapping;
-
-	if (dev != priv->dma_dev)
-		iommu_detach_device(domain, dev);
-}
 #else
-#error Unsupported architecture and IOMMU/DMA-mapping glue code
+#define arm_iommu_create_mapping(...)	({ NULL; })
+#define arm_iommu_attach_device(...)	({ -ENODEV; })
+#define arm_iommu_release_mapping(...)	({ })
+#define arm_iommu_detach_device(...)	({ })
+#define to_dma_iommu_mapping(dev) NULL
 #endif
 
+#if !defined(CONFIG_IOMMU_DMA)
+#define iommu_dma_init_domain(...) ({ -EINVAL; })
+#endif
+
+#define EXYNOS_DEV_ADDR_START	0x20000000
+#define EXYNOS_DEV_ADDR_SIZE	0x40000000
+
 static inline int configure_dma_max_seg_size(struct device *dev)
 {
 	if (!dev->dma_parms)
@@ -116,8 +62,13 @@ int drm_create_iommu_mapping(struct drm_device *drm_dev)
 {
 	struct exynos_drm_private *priv = drm_dev->dev_private;
 
-	return __exynos_iommu_create_mapping(priv, EXYNOS_DEV_ADDR_START,
-					     EXYNOS_DEV_ADDR_SIZE);
+	if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU))
+		priv->mapping = arm_iommu_create_mapping(&platform_bus_type,
+			EXYNOS_DEV_ADDR_START, EXYNOS_DEV_ADDR_SIZE);
+	else if (IS_ENABLED(CONFIG_IOMMU_DMA))
+		priv->mapping = iommu_get_domain_for_dev(priv->dma_dev);
+
+	return IS_ERR(priv->mapping);
 }
 
 /*
@@ -129,7 +80,8 @@ void drm_release_iommu_mapping(struct drm_device *drm_dev)
 {
 	struct exynos_drm_private *priv = drm_dev->dev_private;
 
-	__exynos_iommu_release_mapping(priv);
+	arm_iommu_release_mapping(priv->mapping);
+	priv->mapping = NULL;
 }
 
 /*
@@ -157,7 +109,15 @@ int drm_iommu_attach_device(struct drm_device *drm_dev,
 	if (ret)
 		return ret;
 
-	ret = __exynos_iommu_attach(priv, subdrv_dev);
+	if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) {
+		if (to_dma_iommu_mapping(subdrv_dev))
+			arm_iommu_detach_device(subdrv_dev);
+
+		ret = arm_iommu_attach_device(subdrv_dev, priv->mapping);
+	} else if (IS_ENABLED(CONFIG_IOMMU_DMA)) {
+		ret = iommu_attach_device(priv->mapping, subdrv_dev);
+	}
+
 	if (ret)
 		clear_dma_max_seg_size(subdrv_dev);
 
@@ -178,6 +138,10 @@ void drm_iommu_detach_device(struct drm_device *drm_dev,
 {
 	struct exynos_drm_private *priv = drm_dev->dev_private;
 
-	__exynos_iommu_detach(priv, subdrv_dev);
+	if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU))
+		arm_iommu_detach_device(subdrv_dev);
+	else if (IS_ENABLED(CONFIG_IOMMU_DMA))
+		iommu_detach_device(priv->mapping, subdrv_dev);
+
 	clear_dma_max_seg_size(subdrv_dev);
 }
-- 
2.18.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2018-10-12 10:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20181012105351eucas1p15810c2ba3d38803d44e26a09f4a9e600@eucas1p1.samsung.com>
2018-10-12 10:53 ` [PATCH 0/6] drm/exynos/iommu: refactoring Andrzej Hajda
     [not found]   ` <CGME20181012105351eucas1p189cdf7fe2e5a738584fc3c29db99b418@eucas1p1.samsung.com>
2018-10-12 10:53     ` [PATCH 1/6] drm/exynos: simplify DMA mapping Andrzej Hajda
     [not found]   ` <CGME20181012105351eucas1p17eae01902839c7687260080feb21ef60@eucas1p1.samsung.com>
2018-10-12 10:53     ` [PATCH 2/6] drm/exynos/iommu: remove DRM_EXYNOS_IOMMU Kconfig symbol Andrzej Hajda
     [not found]   ` <CGME20181012105352eucas1p19cef6070271b6b3d81c1dc69f2ab94a7@eucas1p1.samsung.com>
2018-10-12 10:53     ` [PATCH 3/6] drm/exynos/iommu: integrate IOMMU/DMA internal API Andrzej Hajda
     [not found]   ` <CGME20181012105352eucas1p13627181190c88d0f295411082be12af2@eucas1p1.samsung.com>
2018-10-12 10:53     ` [PATCH 4/6] drm/exynos/iommu: move IOMMU specific stuff into exynos_drm_iommu.c Andrzej Hajda
     [not found]   ` <CGME20181012105352eucas1p1632502a2266a59a5db820ed43b4954a8@eucas1p1.samsung.com>
2018-10-12 10:53     ` Andrzej Hajda [this message]
     [not found]   ` <CGME20181012105353eucas1p1ef92f1f906411cc4bb09be3825795bbf@eucas1p1.samsung.com>
2018-10-12 10:53     ` [PATCH 6/6] drm/exynos/iommu: merge IOMMU and DMA code Andrzej Hajda
2018-10-12 10:56   ` [PATCH 0/6] drm/exynos/iommu: refactoring Andrzej Hajda
2018-11-27 14:36   ` Andrzej Hajda
2018-11-28  1:41     ` Inki Dae
     [not found] <20180925082308.1388-1-a.hajda@samsung.com>
     [not found] ` <CGME20180925082314eucas1p27428784088ab6ccd9d6d11ce0ab5063e@eucas1p2.samsung.com>
2018-09-25  8:23   ` [PATCH 5/6] drm/exynos/iommu: replace preprocessor conditionals with C conditionals Andrzej Hajda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181012105346.3754-6-a.hajda@samsung.com \
    --to=a.hajda@samsung.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=inki.dae@samsung.com \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.