OSDN Git Service

Merge "ARM: dts: msm: remove CARVEOUT ION for msm8996 ivi multi-gvm vplatform"
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / msm_dma_iommu_mapping.h
1 /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 and
5  * only version 2 as published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12
13 #ifndef _LINUX_MSM_DMA_IOMMU_MAPPING_H
14 #define _LINUX_MSM_DMA_IOMMU_MAPPING_H
15
16 #include <linux/device.h>
17 #include <linux/dma-buf.h>
18 #include <linux/scatterlist.h>
19 #include <linux/dma-mapping.h>
20
21 #ifdef CONFIG_IOMMU_API
22 /*
23 * This function is not taking a reference to the dma_buf here. It is expected
24 * that clients hold reference to the dma_buf until they are done with mapping
25 * and unmapping.
26 */
27 int msm_dma_map_sg_attrs(struct device *dev, struct scatterlist *sg, int nents,
28                    enum dma_data_direction dir, struct dma_buf *dma_buf,
29                    struct dma_attrs *attrs);
30
31 static inline int msm_dma_map_sg_lazy(struct device *dev,
32                                struct scatterlist *sg, int nents,
33                                enum dma_data_direction dir,
34                                struct dma_buf *dma_buf)
35 {
36         return msm_dma_map_sg_attrs(dev, sg, nents, dir, dma_buf, NULL);
37 }
38
39 static inline int msm_dma_map_sg(struct device *dev, struct scatterlist *sg,
40                                   int nents, enum dma_data_direction dir,
41                                   struct dma_buf *dma_buf)
42 {
43         DEFINE_DMA_ATTRS(attrs);
44
45         init_dma_attrs(&attrs);
46         dma_set_attr(DMA_ATTR_NO_DELAYED_UNMAP, &attrs);
47         return msm_dma_map_sg_attrs(dev, sg, nents, dir, dma_buf, &attrs);
48 }
49
50 void msm_dma_unmap_sg(struct device *dev, struct scatterlist *sgl, int nents,
51                       enum dma_data_direction dir, struct dma_buf *dma_buf);
52
53 int msm_dma_unmap_all_for_dev(struct device *dev);
54
55 /*
56  * Below is private function only to be called by framework (ION) and not by
57  * clients.
58  */
59 void msm_dma_buf_freed(void *buffer);
60
61 #else /*CONFIG_IOMMU_API*/
62
63 static inline int msm_dma_map_sg_attrs(struct device *dev,
64                         struct scatterlist *sg, int nents,
65                         enum dma_data_direction dir, struct dma_buf *dma_buf,
66                         struct dma_attrs *attr)
67 {
68         return -EINVAL;
69 }
70
71 static inline int msm_dma_map_sg_lazy(struct device *dev,
72                                struct scatterlist *sg, int nents,
73                                enum dma_data_direction dir,
74                                struct dma_buf *dma_buf)
75 {
76         return -EINVAL;
77 }
78
79 static inline int msm_dma_map_sg(struct device *dev, struct scatterlist *sg,
80                                   int nents, enum dma_data_direction dir,
81                                   struct dma_buf *dma_buf)
82 {
83         return -EINVAL;
84 }
85
86 static inline void msm_dma_unmap_sg(struct device *dev,
87                                         struct scatterlist *sgl, int nents,
88                                         enum dma_data_direction dir,
89                                         struct dma_buf *dma_buf)
90 {
91 }
92
93 static inline int msm_dma_unmap_all_for_dev(struct device *dev)
94 {
95         return 0;
96 }
97
98 static inline void msm_dma_buf_freed(void *buffer) {}
99 #endif /*CONFIG_IOMMU_API*/
100
101 #endif