Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. |
Olav Haugan | ff0116e | 2015-05-28 17:21:45 -0700 | [diff] [blame] | 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 | |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 21 | #ifdef CONFIG_QCOM_LAZY_MAPPING |
Olav Haugan | ff0116e | 2015-05-28 17:21:45 -0700 | [diff] [blame] | 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, |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 29 | unsigned long attrs); |
Olav Haugan | ff0116e | 2015-05-28 17:21:45 -0700 | [diff] [blame] | 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, 0); |
| 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 | { |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 43 | 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 Haugan | ff0116e | 2015-05-28 17:21:45 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void 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 Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 52 | int msm_dma_unmap_all_for_dev(struct device *dev); |
Olav Haugan | ff0116e | 2015-05-28 17:21:45 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * Below is private function only to be called by framework (ION) and not by |
| 56 | * clients. |
| 57 | */ |
Olav Haugan | ff0116e | 2015-05-28 17:21:45 -0700 | [diff] [blame] | 58 | void msm_dma_buf_freed(void *buffer); |
| 59 | |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 60 | #else /*CONFIG_QCOM_LAZY_MAPPING*/ |
| 61 | |
| 62 | static 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 | |
| 70 | static 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 | |
| 78 | static 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 | |
| 85 | static 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 Daly | 2d9b2f6 | 2016-09-19 18:25:00 -0700 | [diff] [blame] | 92 | static inline int msm_dma_unmap_all_for_dev(struct device *dev) |
Laura Abbott | 29defcc | 2014-08-01 16:13:40 -0700 | [diff] [blame] | 93 | { |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static inline void msm_dma_buf_freed(void *buffer) {} |
| 98 | #endif /*CONFIG_QCOM_LAZY_MAPPING*/ |
| 99 | |
Olav Haugan | ff0116e | 2015-05-28 17:21:45 -0700 | [diff] [blame] | 100 | #endif |