Linux 4.9.243
[linux/fpc-iii.git] / drivers / gpu / drm / exynos / exynos_drm_iommu.c
blob0f373702414e32342fa98d09ac597d3996f24c58
1 /* exynos_drm_iommu.c
3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 * Author: Inki Dae <inki.dae@samsung.com>
6 * 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.
12 #include <drm/drmP.h>
13 #include <drm/exynos_drm.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/iommu.h>
18 #include "exynos_drm_drv.h"
19 #include "exynos_drm_iommu.h"
21 static inline int configure_dma_max_seg_size(struct device *dev)
23 if (!dev->dma_parms)
24 dev->dma_parms = kzalloc(sizeof(*dev->dma_parms), GFP_KERNEL);
25 if (!dev->dma_parms)
26 return -ENOMEM;
28 dma_set_max_seg_size(dev, DMA_BIT_MASK(32));
29 return 0;
32 static inline void clear_dma_max_seg_size(struct device *dev)
34 kfree(dev->dma_parms);
35 dev->dma_parms = NULL;
39 * drm_create_iommu_mapping - create a mapping structure
41 * @drm_dev: DRM device
43 int drm_create_iommu_mapping(struct drm_device *drm_dev)
45 struct exynos_drm_private *priv = drm_dev->dev_private;
47 return __exynos_iommu_create_mapping(priv, EXYNOS_DEV_ADDR_START,
48 EXYNOS_DEV_ADDR_SIZE);
52 * drm_release_iommu_mapping - release iommu mapping structure
54 * @drm_dev: DRM device
56 void drm_release_iommu_mapping(struct drm_device *drm_dev)
58 struct exynos_drm_private *priv = drm_dev->dev_private;
60 __exynos_iommu_release_mapping(priv);
64 * drm_iommu_attach_device- attach device to iommu mapping
66 * @drm_dev: DRM device
67 * @subdrv_dev: device to be attach
69 * This function should be called by sub drivers to attach it to iommu
70 * mapping.
72 int drm_iommu_attach_device(struct drm_device *drm_dev,
73 struct device *subdrv_dev)
75 struct exynos_drm_private *priv = drm_dev->dev_private;
76 int ret;
78 if (get_dma_ops(priv->dma_dev) != get_dma_ops(subdrv_dev)) {
79 DRM_ERROR("Device %s lacks support for IOMMU\n",
80 dev_name(subdrv_dev));
81 return -EINVAL;
84 ret = configure_dma_max_seg_size(subdrv_dev);
85 if (ret)
86 return ret;
88 ret = __exynos_iommu_attach(priv, subdrv_dev);
89 if (ret)
90 clear_dma_max_seg_size(subdrv_dev);
92 return 0;
96 * drm_iommu_detach_device -detach device address space mapping from device
98 * @drm_dev: DRM device
99 * @subdrv_dev: device to be detached
101 * This function should be called by sub drivers to detach it from iommu
102 * mapping
104 void drm_iommu_detach_device(struct drm_device *drm_dev,
105 struct device *subdrv_dev)
107 struct exynos_drm_private *priv = drm_dev->dev_private;
109 __exynos_iommu_detach(priv, subdrv_dev);
110 clear_dma_max_seg_size(subdrv_dev);