blob: a46eb87f8a2c2e50130c2129a7355a76229569ae [file] [log] [blame]
Laura Abbott29defcc2014-08-01 16:13:40 -07001/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
Olav Hauganff0116e2015-05-28 17:21:45 -07002 *
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
Laura Abbott29defcc2014-08-01 16:13:40 -070021#ifdef CONFIG_QCOM_LAZY_MAPPING
Olav Hauganff0116e2015-05-28 17:21:45 -070022/*
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 */
27int msm_dma_map_sg_attrs(struct device *dev, struct scatterlist *sg, int nents,
28 enum dma_data_direction dir, struct dma_buf *dma_buf,
Laura Abbott29defcc2014-08-01 16:13:40 -070029 unsigned long attrs);
Olav Hauganff0116e2015-05-28 17:21:45 -070030
31static 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, 0);
37}
38
39static 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{
Laura Abbott29defcc2014-08-01 16:13:40 -070043 unsigned long attrs;
44
45 attrs = DMA_ATTR_NO_DELAYED_UNMAP;
46 return msm_dma_map_sg_attrs(dev, sg, nents, dir, dma_buf, attrs);
Olav Hauganff0116e2015-05-28 17:21:45 -070047}
48
49void msm_dma_unmap_sg(struct device *dev, struct scatterlist *sgl, int nents,
50 enum dma_data_direction dir, struct dma_buf *dma_buf);
51
Laura Abbott29defcc2014-08-01 16:13:40 -070052int msm_dma_unmap_all_for_dev(struct device *dev);
Olav Hauganff0116e2015-05-28 17:21:45 -070053
54/*
55 * Below is private function only to be called by framework (ION) and not by
56 * clients.
57 */
Olav Hauganff0116e2015-05-28 17:21:45 -070058void msm_dma_buf_freed(void *buffer);
59
Laura Abbott29defcc2014-08-01 16:13:40 -070060#else /*CONFIG_QCOM_LAZY_MAPPING*/
61
62static inline int msm_dma_map_sg_attrs(struct device *dev,
63 struct scatterlist *sg, int nents,
64 enum dma_data_direction dir, struct dma_buf *dma_buf,
65 unsigned long attrs)
66{
67 return -EINVAL;
68}
69
70static inline int msm_dma_map_sg_lazy(struct device *dev,
71 struct scatterlist *sg, int nents,
72 enum dma_data_direction dir,
73 struct dma_buf *dma_buf)
74{
75 return -EINVAL;
76}
77
78static inline int msm_dma_map_sg(struct device *dev, struct scatterlist *sg,
79 int nents, enum dma_data_direction dir,
80 struct dma_buf *dma_buf)
81{
82 return -EINVAL;
83}
84
85static inline void msm_dma_unmap_sg(struct device *dev,
86 struct scatterlist *sgl, int nents,
87 enum dma_data_direction dir,
88 struct dma_buf *dma_buf)
89{
90}
91
Patrick Daly2d9b2f62016-09-19 18:25:00 -070092static inline int msm_dma_unmap_all_for_dev(struct device *dev)
Laura Abbott29defcc2014-08-01 16:13:40 -070093{
94 return 0;
95}
96
97static inline void msm_dma_buf_freed(void *buffer) {}
98#endif /*CONFIG_QCOM_LAZY_MAPPING*/
99
Olav Hauganff0116e2015-05-28 17:21:45 -0700100#endif