3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
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.
13 #include <drm/exynos_drm.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/iommu.h>
17 #include <linux/kref.h>
19 #include <asm/dma-iommu.h>
21 #include "exynos_drm_drv.h"
22 #include "exynos_drm_iommu.h"
25 * drm_create_iommu_mapping - create a mapping structure
27 * @drm_dev: DRM device
29 int drm_create_iommu_mapping(struct drm_device *drm_dev)
31 struct dma_iommu_mapping *mapping = NULL;
32 struct exynos_drm_private *priv = drm_dev->dev_private;
35 priv->da_start = EXYNOS_DEV_ADDR_START;
36 if (!priv->da_space_size)
37 priv->da_space_size = EXYNOS_DEV_ADDR_SIZE;
39 mapping = arm_iommu_create_mapping(&platform_bus_type, priv->da_start,
43 return PTR_ERR(mapping);
45 priv->mapping = mapping;
51 * drm_release_iommu_mapping - release iommu mapping structure
53 * @drm_dev: DRM device
55 * if mapping->kref becomes 0 then all things related to iommu mapping
58 void drm_release_iommu_mapping(struct drm_device *drm_dev)
60 struct exynos_drm_private *priv = drm_dev->dev_private;
62 arm_iommu_release_mapping(priv->mapping);
66 * drm_iommu_attach_device- attach device to iommu mapping
68 * @drm_dev: DRM device
69 * @subdrv_dev: device to be attach
71 * This function should be called by sub drivers to attach it to iommu
74 int drm_iommu_attach_device(struct drm_device *drm_dev,
75 struct device *subdrv_dev)
77 struct exynos_drm_private *priv = drm_dev->dev_private;
83 subdrv_dev->dma_parms = devm_kzalloc(subdrv_dev,
84 sizeof(*subdrv_dev->dma_parms),
86 if (!subdrv_dev->dma_parms)
89 dma_set_max_seg_size(subdrv_dev, 0xffffffffu);
91 if (subdrv_dev->archdata.mapping)
92 arm_iommu_detach_device(subdrv_dev);
94 ret = arm_iommu_attach_device(subdrv_dev, priv->mapping);
96 DRM_DEBUG_KMS("failed iommu attach.\n");
104 * drm_iommu_detach_device -detach device address space mapping from device
106 * @drm_dev: DRM device
107 * @subdrv_dev: device to be detached
109 * This function should be called by sub drivers to detach it from iommu
112 void drm_iommu_detach_device(struct drm_device *drm_dev,
113 struct device *subdrv_dev)
115 struct exynos_drm_private *priv = drm_dev->dev_private;
116 struct dma_iommu_mapping *mapping = priv->mapping;
118 if (!mapping || !mapping->domain)
121 arm_iommu_detach_device(subdrv_dev);