Commit 39f69368 authored by Andrzej Hajda's avatar Andrzej Hajda Committed by Inki Dae

drm/exynos/iommu: replace preprocessor conditionals with C conditionals

Using C conditionals is preferred solution - it provides better code
coverage, makes code more clear.
Signed-off-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
Signed-off-by: default avatarInki Dae <inki.dae@samsung.com>
parent a0b68a71
...@@ -12,84 +12,30 @@ ...@@ -12,84 +12,30 @@
#include <drm/drmP.h> #include <drm/drmP.h>
#include <drm/exynos_drm.h> #include <drm/exynos_drm.h>
#include <linux/dma-iommu.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/iommu.h> #include <linux/iommu.h>
#include "exynos_drm_drv.h" #include "exynos_drm_drv.h"
#include "exynos_drm_iommu.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) #if defined(CONFIG_ARM_DMA_USE_IOMMU)
#include <asm/dma-iommu.h> #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 #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 #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) static inline int configure_dma_max_seg_size(struct device *dev)
{ {
if (!dev->dma_parms) if (!dev->dma_parms)
...@@ -116,8 +62,13 @@ int drm_create_iommu_mapping(struct drm_device *drm_dev) ...@@ -116,8 +62,13 @@ int drm_create_iommu_mapping(struct drm_device *drm_dev)
{ {
struct exynos_drm_private *priv = drm_dev->dev_private; struct exynos_drm_private *priv = drm_dev->dev_private;
return __exynos_iommu_create_mapping(priv, EXYNOS_DEV_ADDR_START, if (IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU))
EXYNOS_DEV_ADDR_SIZE); 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) ...@@ -129,7 +80,8 @@ void drm_release_iommu_mapping(struct drm_device *drm_dev)
{ {
struct exynos_drm_private *priv = drm_dev->dev_private; 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, ...@@ -157,7 +109,15 @@ int drm_iommu_attach_device(struct drm_device *drm_dev,
if (ret) if (ret)
return 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) if (ret)
clear_dma_max_seg_size(subdrv_dev); clear_dma_max_seg_size(subdrv_dev);
...@@ -178,6 +138,10 @@ void drm_iommu_detach_device(struct drm_device *drm_dev, ...@@ -178,6 +138,10 @@ void drm_iommu_detach_device(struct drm_device *drm_dev,
{ {
struct exynos_drm_private *priv = drm_dev->dev_private; 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); clear_dma_max_seg_size(subdrv_dev);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment