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.
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
)
24 dev
->dma_parms
= kzalloc(sizeof(*dev
->dma_parms
), GFP_KERNEL
);
28 dma_set_max_seg_size(dev
, DMA_BIT_MASK(32));
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
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
;
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
));
84 ret
= configure_dma_max_seg_size(subdrv_dev
);
88 ret
= __exynos_iommu_attach(priv
, subdrv_dev
);
90 clear_dma_max_seg_size(subdrv_dev
);
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
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
);