GNU Linux-libre 4.9.297-gnu1
[releases.git] / drivers / media / platform / s5p-mfc / s5p_mfc_iommu.h
1 /*
2  * Copyright (C) 2015 Samsung Electronics Co.Ltd
3  * Authors: Marek Szyprowski <m.szyprowski@samsung.com>
4  *
5  * This program is free software; you can redistribute  it and/or modify it
6  * under  the terms of  the GNU General  Public License as published by the
7  * Free Software Foundation;  either version 2 of the  License, or (at your
8  * option) any later version.
9  */
10
11 #ifndef S5P_MFC_IOMMU_H_
12 #define S5P_MFC_IOMMU_H_
13
14 #define S5P_MFC_IOMMU_DMA_BASE  0x20000000lu
15 #define S5P_MFC_IOMMU_DMA_SIZE  SZ_256M
16
17 #if defined(CONFIG_EXYNOS_IOMMU) && defined(CONFIG_ARM_DMA_USE_IOMMU)
18
19 #include <asm/dma-iommu.h>
20
21 static inline bool exynos_is_iommu_available(struct device *dev)
22 {
23         return dev->archdata.iommu != NULL;
24 }
25
26 static inline void exynos_unconfigure_iommu(struct device *dev)
27 {
28         struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
29
30         arm_iommu_detach_device(dev);
31         arm_iommu_release_mapping(mapping);
32 }
33
34 static inline int exynos_configure_iommu(struct device *dev,
35                                          unsigned int base, unsigned int size)
36 {
37         struct dma_iommu_mapping *mapping = NULL;
38         int ret;
39
40         /* Disable the default mapping created by device core */
41         if (to_dma_iommu_mapping(dev))
42                 exynos_unconfigure_iommu(dev);
43
44         mapping = arm_iommu_create_mapping(dev->bus, base, size);
45         if (IS_ERR(mapping)) {
46                 pr_warn("Failed to create IOMMU mapping for device %s\n",
47                         dev_name(dev));
48                 return PTR_ERR(mapping);
49         }
50
51         ret = arm_iommu_attach_device(dev, mapping);
52         if (ret) {
53                 pr_warn("Failed to attached device %s to IOMMU_mapping\n",
54                                 dev_name(dev));
55                 arm_iommu_release_mapping(mapping);
56                 return ret;
57         }
58
59         return 0;
60 }
61
62 #else
63
64 static inline bool exynos_is_iommu_available(struct device *dev)
65 {
66         return false;
67 }
68
69 static inline int exynos_configure_iommu(struct device *dev,
70                                          unsigned int base, unsigned int size)
71 {
72         return -ENOSYS;
73 }
74
75 static inline void exynos_unconfigure_iommu(struct device *dev) { }
76
77 #endif
78
79 #endif /* S5P_MFC_IOMMU_H_ */