aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorMarek Szyprowski <m.szyprowski@samsung.com>2016-06-17 03:54:26 -0400
committerInki Dae <daeinki@gmail.com>2016-07-13 10:06:06 -0400
commit17879a4100f15156b415f37190576f30a5cfae00 (patch)
treebed5c345f441ef5357c3a584f0d710c3fafb7915 /drivers
parenta9abb34f440bcd0ef6ef74c01b8f889a073996f3 (diff)
drm/exynos: iommu: move ARM specific code to exynos_drm_iommu.h
This patch moves all ARM 32bit DMA-mapping/IOMMU dependant code from exynos_drm_iommu.c to .h, to let it compile conditionally and prepare for adding support for other architectures/IOMMU glue code (like ARM 64bit with IOMMU-DMA glue). Later, when ARM 32bit and 64bit will be unified, this code can be removed. Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Signed-off-by: Inki Dae <inki.dae@samsung.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_iommu.c39
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_iommu.h36
2 files changed, 42 insertions, 33 deletions
diff --git a/drivers/gpu/drm/exynos/exynos_drm_iommu.c b/drivers/gpu/drm/exynos/exynos_drm_iommu.c
index 0229bad43bd1..0f373702414e 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_iommu.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_iommu.c
@@ -14,9 +14,6 @@
14 14
15#include <linux/dma-mapping.h> 15#include <linux/dma-mapping.h>
16#include <linux/iommu.h> 16#include <linux/iommu.h>
17#include <linux/kref.h>
18
19#include <asm/dma-iommu.h>
20 17
21#include "exynos_drm_drv.h" 18#include "exynos_drm_drv.h"
22#include "exynos_drm_iommu.h" 19#include "exynos_drm_iommu.h"
@@ -45,33 +42,22 @@ static inline void clear_dma_max_seg_size(struct device *dev)
45 */ 42 */
46int drm_create_iommu_mapping(struct drm_device *drm_dev) 43int drm_create_iommu_mapping(struct drm_device *drm_dev)
47{ 44{
48 struct dma_iommu_mapping *mapping = NULL;
49 struct exynos_drm_private *priv = drm_dev->dev_private; 45 struct exynos_drm_private *priv = drm_dev->dev_private;
50 46
51 mapping = arm_iommu_create_mapping(&platform_bus_type, 47 return __exynos_iommu_create_mapping(priv, EXYNOS_DEV_ADDR_START,
52 EXYNOS_DEV_ADDR_START, EXYNOS_DEV_ADDR_SIZE); 48 EXYNOS_DEV_ADDR_SIZE);
53
54 if (IS_ERR(mapping))
55 return PTR_ERR(mapping);
56
57 priv->mapping = mapping;
58
59 return 0;
60} 49}
61 50
62/* 51/*
63 * drm_release_iommu_mapping - release iommu mapping structure 52 * drm_release_iommu_mapping - release iommu mapping structure
64 * 53 *
65 * @drm_dev: DRM device 54 * @drm_dev: DRM device
66 *
67 * if mapping->kref becomes 0 then all things related to iommu mapping
68 * will be released
69 */ 55 */
70void drm_release_iommu_mapping(struct drm_device *drm_dev) 56void drm_release_iommu_mapping(struct drm_device *drm_dev)
71{ 57{
72 struct exynos_drm_private *priv = drm_dev->dev_private; 58 struct exynos_drm_private *priv = drm_dev->dev_private;
73 59
74 arm_iommu_release_mapping(priv->mapping); 60 __exynos_iommu_release_mapping(priv);
75} 61}
76 62
77/* 63/*
@@ -89,9 +75,6 @@ int drm_iommu_attach_device(struct drm_device *drm_dev,
89 struct exynos_drm_private *priv = drm_dev->dev_private; 75 struct exynos_drm_private *priv = drm_dev->dev_private;
90 int ret; 76 int ret;
91 77
92 if (!priv->mapping)
93 return 0;
94
95 if (get_dma_ops(priv->dma_dev) != get_dma_ops(subdrv_dev)) { 78 if (get_dma_ops(priv->dma_dev) != get_dma_ops(subdrv_dev)) {
96 DRM_ERROR("Device %s lacks support for IOMMU\n", 79 DRM_ERROR("Device %s lacks support for IOMMU\n",
97 dev_name(subdrv_dev)); 80 dev_name(subdrv_dev));
@@ -102,15 +85,9 @@ int drm_iommu_attach_device(struct drm_device *drm_dev,
102 if (ret) 85 if (ret)
103 return ret; 86 return ret;
104 87
105 if (subdrv_dev->archdata.mapping) 88 ret = __exynos_iommu_attach(priv, subdrv_dev);
106 arm_iommu_detach_device(subdrv_dev); 89 if (ret)
107
108 ret = arm_iommu_attach_device(subdrv_dev, priv->mapping);
109 if (ret < 0) {
110 DRM_DEBUG_KMS("failed iommu attach.\n");
111 clear_dma_max_seg_size(subdrv_dev); 90 clear_dma_max_seg_size(subdrv_dev);
112 return ret;
113 }
114 91
115 return 0; 92 return 0;
116} 93}
@@ -128,11 +105,7 @@ void drm_iommu_detach_device(struct drm_device *drm_dev,
128 struct device *subdrv_dev) 105 struct device *subdrv_dev)
129{ 106{
130 struct exynos_drm_private *priv = drm_dev->dev_private; 107 struct exynos_drm_private *priv = drm_dev->dev_private;
131 struct dma_iommu_mapping *mapping = priv->mapping;
132
133 if (!mapping || !mapping->domain)
134 return;
135 108
136 arm_iommu_detach_device(subdrv_dev); 109 __exynos_iommu_detach(priv, subdrv_dev);
137 clear_dma_max_seg_size(subdrv_dev); 110 clear_dma_max_seg_size(subdrv_dev);
138} 111}
diff --git a/drivers/gpu/drm/exynos/exynos_drm_iommu.h b/drivers/gpu/drm/exynos/exynos_drm_iommu.h
index 5ffebe02ee4d..22e1df2ac62e 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_iommu.h
+++ b/drivers/gpu/drm/exynos/exynos_drm_iommu.h
@@ -17,6 +17,42 @@
17 17
18#ifdef CONFIG_DRM_EXYNOS_IOMMU 18#ifdef CONFIG_DRM_EXYNOS_IOMMU
19 19
20#if defined(CONFIG_ARM_DMA_USE_IOMMU)
21#include <asm/dma-iommu.h>
22
23static inline int __exynos_iommu_create_mapping(struct exynos_drm_private *priv,
24 unsigned long start, unsigned long size)
25{
26 priv->mapping = arm_iommu_create_mapping(&platform_bus_type, start,
27 size);
28 return IS_ERR(priv->mapping);
29}
30
31static inline void
32__exynos_iommu_release_mapping(struct exynos_drm_private *priv)
33{
34 arm_iommu_release_mapping(priv->mapping);
35}
36
37static inline int __exynos_iommu_attach(struct exynos_drm_private *priv,
38 struct device *dev)
39{
40 if (dev->archdata.mapping)
41 arm_iommu_detach_device(dev);
42
43 return arm_iommu_attach_device(dev, priv->mapping);
44}
45
46static inline void __exynos_iommu_detach(struct exynos_drm_private *priv,
47 struct device *dev)
48{
49 arm_iommu_detach_device(dev);
50}
51
52#else
53#error Unsupported architecture and IOMMU/DMA-mapping glue code
54#endif
55
20int drm_create_iommu_mapping(struct drm_device *drm_dev); 56int drm_create_iommu_mapping(struct drm_device *drm_dev);
21 57
22void drm_release_iommu_mapping(struct drm_device *drm_dev); 58void drm_release_iommu_mapping(struct drm_device *drm_dev);