diff --git a/dsp/msm_audio_ion.c b/dsp/msm_audio_ion.c index 95d4fd4e2bcf..eeea32d87be3 100644 --- a/dsp/msm_audio_ion.c +++ b/dsp/msm_audio_ion.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved. + * Copyright (c) 2013-2019, The Linux Foundation. All rights reserved. */ #include @@ -400,6 +400,43 @@ err: } EXPORT_SYMBOL(msm_audio_ion_alloc); +/** + * msm_audio_ion_dma_map - + * Memory maps for a given DMA buffer + * + * @phys_addr: Physical address of DMA buffer to be mapped + * @iova_base: IOVA address of memory mapped DMA buffer + * @size: buffer size + * @dir: DMA direction + * Returns 0 on success or error on failure + */ +int msm_audio_ion_dma_map(dma_addr_t *phys_addr, dma_addr_t *iova_base, + u32 size, enum dma_data_direction dir) +{ + dma_addr_t iova; + struct device *cb_dev = msm_audio_ion_data.cb_dev; + + if (!phys_addr || !iova_base || !size) + return -EINVAL; + + iova = dma_map_resource(cb_dev, *phys_addr, size, + dir, 0); + if (dma_mapping_error(cb_dev, iova)) { + pr_err("%s: dma_mapping_error\n", __func__); + return -EIO; + } + pr_debug("%s: dma_mapping_success iova:0x%lx\n", __func__, + (unsigned long)iova); + if (msm_audio_ion_data.smmu_enabled) + /* Append the SMMU SID information to the IOVA address */ + iova |= msm_audio_ion_data.smmu_sid_bits; + + *iova_base = iova; + + return 0; +} +EXPORT_SYMBOL(msm_audio_ion_dma_map); + /** * msm_audio_ion_import- * Import ION buffer with given file descriptor diff --git a/include/dsp/msm_audio_ion.h b/include/dsp/msm_audio_ion.h index 09d590b52a31..9ac5ca30e080 100644 --- a/include/dsp/msm_audio_ion.h +++ b/include/dsp/msm_audio_ion.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * Copyright (c) 2013-2015, 2017-2018, The Linux Foundation. All rights reserved. + * Copyright (c) 2013-2015, 2017-2019, The Linux Foundation. All rights reserved. */ #ifndef _LINUX_MSM_AUDIO_ION_H @@ -8,6 +8,7 @@ #include #include #include +#include enum { MSM_AUDIO_ION_INV_CACHES = 0, @@ -26,4 +27,7 @@ int msm_audio_ion_cache_operations(struct audio_buffer *abuff, int cache_op); u32 msm_audio_populate_upper_32_bits(dma_addr_t pa); int msm_audio_ion_get_smmu_info(struct device **cb_dev, u64 *smmu_sid); + +int msm_audio_ion_dma_map(dma_addr_t *phys_addr, dma_addr_t *iova_base, + u32 size, enum dma_data_direction dir); #endif /* _LINUX_MSM_AUDIO_ION_H */