blob: 22e1df2ac62eaf428974566e28512856d2672f36 [file] [log] [blame]
Inki Dae0519f9a2012-10-20 07:53:42 -07001/* exynos_drm_iommu.h
2 *
3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * Authoer: Inki Dae <inki.dae@samsung.com>
5 *
Inki Daed81aecb2012-12-18 02:30:17 +09006 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
Inki Dae0519f9a2012-10-20 07:53:42 -070010 */
11
12#ifndef _EXYNOS_DRM_IOMMU_H_
13#define _EXYNOS_DRM_IOMMU_H_
14
15#define EXYNOS_DEV_ADDR_START 0x20000000
16#define EXYNOS_DEV_ADDR_SIZE 0x40000000
Inki Dae0519f9a2012-10-20 07:53:42 -070017
18#ifdef CONFIG_DRM_EXYNOS_IOMMU
19
Marek Szyprowski17879a42016-06-17 09:54:26 +020020#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
Inki Dae0519f9a2012-10-20 07:53:42 -070056int drm_create_iommu_mapping(struct drm_device *drm_dev);
57
58void drm_release_iommu_mapping(struct drm_device *drm_dev);
59
60int drm_iommu_attach_device(struct drm_device *drm_dev,
61 struct device *subdrv_dev);
62
63void drm_iommu_detach_device(struct drm_device *dev_dev,
64 struct device *subdrv_dev);
65
66static inline bool is_drm_iommu_supported(struct drm_device *drm_dev)
67{
Marek Szyprowskif43c3592016-02-29 17:50:53 +090068 struct exynos_drm_private *priv = drm_dev->dev_private;
Inki Dae0519f9a2012-10-20 07:53:42 -070069
Marek Szyprowskif43c3592016-02-29 17:50:53 +090070 return priv->mapping ? true : false;
Inki Dae0519f9a2012-10-20 07:53:42 -070071}
72
73#else
74
Inki Dae0519f9a2012-10-20 07:53:42 -070075static inline int drm_create_iommu_mapping(struct drm_device *drm_dev)
76{
77 return 0;
78}
79
80static inline void drm_release_iommu_mapping(struct drm_device *drm_dev)
81{
82}
83
84static inline int drm_iommu_attach_device(struct drm_device *drm_dev,
85 struct device *subdrv_dev)
86{
87 return 0;
88}
89
90static inline void drm_iommu_detach_device(struct drm_device *drm_dev,
91 struct device *subdrv_dev)
92{
93}
94
95static inline bool is_drm_iommu_supported(struct drm_device *drm_dev)
96{
97 return false;
98}
99
Inki Dae0519f9a2012-10-20 07:53:42 -0700100#endif
101#endif