1 /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
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.
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.
13 #ifndef _LINUX_MSM_DMA_IOMMU_MAPPING_H
14 #define _LINUX_MSM_DMA_IOMMU_MAPPING_H
16 #include <linux/device.h>
17 #include <linux/dma-buf.h>
18 #include <linux/scatterlist.h>
19 #include <linux/dma-mapping.h>
21 #ifdef CONFIG_IOMMU_API
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
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);
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)
36 return msm_dma_map_sg_attrs(dev, sg, nents, dir, dma_buf, NULL);
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)
43 DEFINE_DMA_ATTRS(attrs);
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);
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);
53 int msm_dma_unmap_all_for_dev(struct device *dev);
56 * Below is private function only to be called by framework (ION) and not by
59 void msm_dma_buf_freed(void *buffer);
61 #else /*CONFIG_IOMMU_API*/
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)
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)
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)
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)
93 static inline int msm_dma_unmap_all_for_dev(struct device *dev)
98 static inline void msm_dma_buf_freed(void *buffer) {}
99 #endif /*CONFIG_IOMMU_API*/