2019-01-29 00:43:33 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-07-20 09:01:55 -04:00
|
|
|
/*
|
2020-06-24 11:31:54 -04:00
|
|
|
* Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
|
2017-07-20 09:01:55 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/dma-buf.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/of_device.h>
|
|
|
|
#include <linux/export.h>
|
2019-12-23 17:59:27 -05:00
|
|
|
#include <linux/ion.h>
|
2017-11-04 01:48:23 -04:00
|
|
|
#include <ipc/apr.h>
|
2017-08-01 12:32:15 -04:00
|
|
|
#include <dsp/msm_audio_ion.h>
|
2017-07-20 09:01:55 -04:00
|
|
|
|
|
|
|
#define MSM_AUDIO_ION_PROBED (1 << 0)
|
|
|
|
|
|
|
|
#define MSM_AUDIO_ION_PHYS_ADDR(alloc_data) \
|
|
|
|
alloc_data->table->sgl->dma_address
|
|
|
|
|
|
|
|
#define MSM_AUDIO_SMMU_SID_OFFSET 32
|
|
|
|
|
|
|
|
struct msm_audio_ion_private {
|
2018-03-12 01:41:27 -04:00
|
|
|
bool smmu_enabled;
|
2017-07-20 09:01:55 -04:00
|
|
|
struct device *cb_dev;
|
2020-06-24 11:31:54 -04:00
|
|
|
struct device *cb_cma_dev;
|
2017-07-20 09:01:55 -04:00
|
|
|
u8 device_status;
|
|
|
|
struct list_head alloc_list;
|
|
|
|
struct mutex list_mutex;
|
|
|
|
u64 smmu_sid_bits;
|
|
|
|
u32 smmu_version;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct msm_audio_alloc_data {
|
|
|
|
size_t len;
|
2017-11-04 01:48:23 -04:00
|
|
|
void *vaddr;
|
2017-07-20 09:01:55 -04:00
|
|
|
struct dma_buf *dma_buf;
|
|
|
|
struct dma_buf_attachment *attach;
|
|
|
|
struct sg_table *table;
|
|
|
|
struct list_head list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct msm_audio_ion_private msm_audio_ion_data = {0,};
|
|
|
|
|
|
|
|
static void msm_audio_ion_add_allocation(
|
|
|
|
struct msm_audio_ion_private *msm_audio_ion_data,
|
|
|
|
struct msm_audio_alloc_data *alloc_data)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Since these APIs can be invoked by multiple
|
|
|
|
* clients, there is need to make sure the list
|
|
|
|
* of allocations is always protected
|
|
|
|
*/
|
|
|
|
mutex_lock(&(msm_audio_ion_data->list_mutex));
|
|
|
|
list_add_tail(&(alloc_data->list),
|
|
|
|
&(msm_audio_ion_data->alloc_list));
|
|
|
|
mutex_unlock(&(msm_audio_ion_data->list_mutex));
|
|
|
|
}
|
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
static int msm_audio_dma_buf_map(struct dma_buf *dma_buf,
|
2020-06-24 11:31:54 -04:00
|
|
|
dma_addr_t *addr, size_t *len,
|
|
|
|
bool cma_mem)
|
2017-11-04 01:48:23 -04:00
|
|
|
{
|
|
|
|
|
2020-08-18 09:03:35 -04:00
|
|
|
struct msm_audio_alloc_data *alloc_data = NULL;
|
2017-11-04 01:48:23 -04:00
|
|
|
struct device *cb_dev;
|
2018-03-12 01:41:27 -04:00
|
|
|
unsigned long ionflag = 0;
|
2017-11-04 01:48:23 -04:00
|
|
|
int rc = 0;
|
|
|
|
|
2020-06-24 11:31:54 -04:00
|
|
|
if (cma_mem)
|
|
|
|
cb_dev = msm_audio_ion_data.cb_cma_dev;
|
|
|
|
else
|
|
|
|
cb_dev = msm_audio_ion_data.cb_dev;
|
2017-11-04 01:48:23 -04:00
|
|
|
|
|
|
|
/* Data required per buffer mapping */
|
|
|
|
alloc_data = kzalloc(sizeof(*alloc_data), GFP_KERNEL);
|
|
|
|
if (!alloc_data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
alloc_data->dma_buf = dma_buf;
|
|
|
|
alloc_data->len = dma_buf->size;
|
|
|
|
*len = dma_buf->size;
|
|
|
|
|
|
|
|
/* Attach the dma_buf to context bank device */
|
|
|
|
alloc_data->attach = dma_buf_attach(alloc_data->dma_buf,
|
|
|
|
cb_dev);
|
|
|
|
if (IS_ERR(alloc_data->attach)) {
|
|
|
|
rc = PTR_ERR(alloc_data->attach);
|
|
|
|
dev_err(cb_dev,
|
|
|
|
"%s: Fail to attach dma_buf to CB, rc = %d\n",
|
|
|
|
__func__, rc);
|
2018-03-12 01:41:27 -04:00
|
|
|
goto free_alloc_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For uncached buffers, avoid cache maintanance */
|
|
|
|
rc = dma_buf_get_flags(alloc_data->dma_buf, &ionflag);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(cb_dev, "%s: dma_buf_get_flags failed: %d\n",
|
|
|
|
__func__, rc);
|
|
|
|
goto detach_dma_buf;
|
2017-11-04 01:48:23 -04:00
|
|
|
}
|
|
|
|
|
2018-03-12 01:41:27 -04:00
|
|
|
if (!(ionflag & ION_FLAG_CACHED))
|
|
|
|
alloc_data->attach->dma_map_attrs |= DMA_ATTR_SKIP_CPU_SYNC;
|
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
/*
|
|
|
|
* Get the scatter-gather list.
|
|
|
|
* There is no info as this is a write buffer or
|
|
|
|
* read buffer, hence the request is bi-directional
|
|
|
|
* to accommodate both read and write mappings.
|
|
|
|
*/
|
|
|
|
alloc_data->table = dma_buf_map_attachment(alloc_data->attach,
|
|
|
|
DMA_BIDIRECTIONAL);
|
|
|
|
if (IS_ERR(alloc_data->table)) {
|
|
|
|
rc = PTR_ERR(alloc_data->table);
|
|
|
|
dev_err(cb_dev,
|
|
|
|
"%s: Fail to map attachment, rc = %d\n",
|
|
|
|
__func__, rc);
|
2018-03-12 01:41:27 -04:00
|
|
|
goto detach_dma_buf;
|
2017-11-04 01:48:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* physical address from mapping */
|
|
|
|
*addr = MSM_AUDIO_ION_PHYS_ADDR(alloc_data);
|
|
|
|
|
|
|
|
msm_audio_ion_add_allocation(&msm_audio_ion_data,
|
|
|
|
alloc_data);
|
|
|
|
return rc;
|
|
|
|
|
2018-03-12 01:41:27 -04:00
|
|
|
detach_dma_buf:
|
2017-11-04 01:48:23 -04:00
|
|
|
dma_buf_detach(alloc_data->dma_buf,
|
|
|
|
alloc_data->attach);
|
2018-03-12 01:41:27 -04:00
|
|
|
free_alloc_data:
|
2017-11-04 01:48:23 -04:00
|
|
|
kfree(alloc_data);
|
2020-08-18 09:03:35 -04:00
|
|
|
alloc_data = NULL;
|
2017-11-04 01:48:23 -04:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-06-24 11:31:54 -04:00
|
|
|
static int msm_audio_dma_buf_unmap(struct dma_buf *dma_buf, bool cma_mem)
|
2017-11-04 01:48:23 -04:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
struct msm_audio_alloc_data *alloc_data = NULL;
|
|
|
|
struct list_head *ptr, *next;
|
2020-06-24 11:31:54 -04:00
|
|
|
struct device *cb_dev;
|
2017-11-04 01:48:23 -04:00
|
|
|
bool found = false;
|
|
|
|
|
2020-06-24 11:31:54 -04:00
|
|
|
if (cma_mem)
|
|
|
|
cb_dev = msm_audio_ion_data.cb_cma_dev;
|
|
|
|
else
|
|
|
|
cb_dev = msm_audio_ion_data.cb_dev;
|
2017-11-04 01:48:23 -04:00
|
|
|
/*
|
|
|
|
* Though list_for_each_safe is delete safe, lock
|
|
|
|
* should be explicitly acquired to avoid race condition
|
|
|
|
* on adding elements to the list.
|
|
|
|
*/
|
|
|
|
mutex_lock(&(msm_audio_ion_data.list_mutex));
|
|
|
|
list_for_each_safe(ptr, next,
|
|
|
|
&(msm_audio_ion_data.alloc_list)) {
|
|
|
|
|
|
|
|
alloc_data = list_entry(ptr, struct msm_audio_alloc_data,
|
|
|
|
list);
|
|
|
|
|
|
|
|
if (alloc_data->dma_buf == dma_buf) {
|
|
|
|
found = true;
|
|
|
|
dma_buf_unmap_attachment(alloc_data->attach,
|
|
|
|
alloc_data->table,
|
|
|
|
DMA_BIDIRECTIONAL);
|
|
|
|
|
|
|
|
dma_buf_detach(alloc_data->dma_buf,
|
|
|
|
alloc_data->attach);
|
|
|
|
|
|
|
|
dma_buf_put(alloc_data->dma_buf);
|
|
|
|
|
|
|
|
list_del(&(alloc_data->list));
|
|
|
|
kfree(alloc_data);
|
2020-08-18 09:03:35 -04:00
|
|
|
alloc_data = NULL;
|
2017-11-04 01:48:23 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&(msm_audio_ion_data.list_mutex));
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
dev_err(cb_dev,
|
|
|
|
"%s: cannot find allocation, dma_buf %pK",
|
|
|
|
__func__, dma_buf);
|
|
|
|
rc = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int msm_audio_ion_get_phys(struct dma_buf *dma_buf,
|
|
|
|
dma_addr_t *addr, size_t *len)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
2020-06-24 11:31:54 -04:00
|
|
|
rc = msm_audio_dma_buf_map(dma_buf, addr, len, false);
|
2017-11-04 01:48:23 -04:00
|
|
|
if (rc) {
|
|
|
|
pr_err("%s: failed to map DMA buf, err = %d\n",
|
|
|
|
__func__, rc);
|
|
|
|
goto err;
|
|
|
|
}
|
2018-03-12 01:41:27 -04:00
|
|
|
if (msm_audio_ion_data.smmu_enabled) {
|
|
|
|
/* Append the SMMU SID information to the IOVA address */
|
|
|
|
*addr |= msm_audio_ion_data.smmu_sid_bits;
|
|
|
|
}
|
2017-11-04 01:48:23 -04:00
|
|
|
|
|
|
|
pr_debug("phys=%pK, len=%zd, rc=%d\n", &(*addr), *len, rc);
|
|
|
|
err:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-06-26 09:11:06 -04:00
|
|
|
int msm_audio_ion_get_smmu_info(struct device **cb_dev,
|
|
|
|
u64 *smmu_sid)
|
|
|
|
{
|
|
|
|
if (!cb_dev || !smmu_sid) {
|
|
|
|
pr_err("%s: Invalid params\n",
|
|
|
|
__func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!msm_audio_ion_data.cb_dev ||
|
|
|
|
!msm_audio_ion_data.smmu_sid_bits) {
|
|
|
|
pr_err("%s: Params not initialized\n",
|
|
|
|
__func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*cb_dev = msm_audio_ion_data.cb_dev;
|
|
|
|
*smmu_sid = msm_audio_ion_data.smmu_sid_bits;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
static void *msm_audio_ion_map_kernel(struct dma_buf *dma_buf)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
void *addr = NULL;
|
|
|
|
struct msm_audio_alloc_data *alloc_data = NULL;
|
|
|
|
|
|
|
|
rc = dma_buf_begin_cpu_access(dma_buf, DMA_BIDIRECTIONAL);
|
|
|
|
if (rc) {
|
|
|
|
pr_err("%s: kmap dma_buf_begin_cpu_access fail\n", __func__);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2018-03-03 04:44:55 -05:00
|
|
|
addr = dma_buf_vmap(dma_buf);
|
2017-11-04 01:48:23 -04:00
|
|
|
if (!addr) {
|
2018-03-03 04:44:55 -05:00
|
|
|
pr_err("%s: kernel mapping of dma_buf failed\n",
|
2017-11-04 01:48:23 -04:00
|
|
|
__func__);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TBD: remove the below section once new API
|
|
|
|
* for mapping kernel virtual address is available.
|
|
|
|
*/
|
|
|
|
mutex_lock(&(msm_audio_ion_data.list_mutex));
|
|
|
|
list_for_each_entry(alloc_data, &(msm_audio_ion_data.alloc_list),
|
|
|
|
list) {
|
|
|
|
if (alloc_data->dma_buf == dma_buf) {
|
|
|
|
alloc_data->vaddr = addr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&(msm_audio_ion_data.list_mutex));
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2018-10-15 15:21:06 -04:00
|
|
|
static int msm_audio_ion_unmap_kernel(struct dma_buf *dma_buf)
|
2017-11-04 01:48:23 -04:00
|
|
|
{
|
2018-03-03 04:44:55 -05:00
|
|
|
int rc = 0;
|
2017-11-04 01:48:23 -04:00
|
|
|
void *vaddr = NULL;
|
|
|
|
struct msm_audio_alloc_data *alloc_data = NULL;
|
|
|
|
struct device *cb_dev = msm_audio_ion_data.cb_dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TBD: remove the below section once new API
|
|
|
|
* for unmapping kernel virtual address is available.
|
|
|
|
*/
|
|
|
|
mutex_lock(&(msm_audio_ion_data.list_mutex));
|
|
|
|
list_for_each_entry(alloc_data, &(msm_audio_ion_data.alloc_list),
|
|
|
|
list) {
|
|
|
|
if (alloc_data->dma_buf == dma_buf) {
|
|
|
|
vaddr = alloc_data->vaddr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&(msm_audio_ion_data.list_mutex));
|
|
|
|
|
|
|
|
if (!vaddr) {
|
|
|
|
dev_err(cb_dev,
|
|
|
|
"%s: cannot find allocation for dma_buf %pK",
|
|
|
|
__func__, dma_buf);
|
2018-10-15 15:21:06 -04:00
|
|
|
rc = -EINVAL;
|
2017-11-04 01:48:23 -04:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2018-03-03 04:44:55 -05:00
|
|
|
dma_buf_vunmap(dma_buf, vaddr);
|
2017-11-04 01:48:23 -04:00
|
|
|
|
|
|
|
rc = dma_buf_end_cpu_access(dma_buf, DMA_BIDIRECTIONAL);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(cb_dev, "%s: kmap dma_buf_end_cpu_access fail\n",
|
|
|
|
__func__);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
2018-10-15 15:21:06 -04:00
|
|
|
return rc;
|
2017-11-04 01:48:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int msm_audio_ion_map_buf(struct dma_buf *dma_buf, dma_addr_t *paddr,
|
2018-03-17 02:29:29 -04:00
|
|
|
size_t *plen, void **vaddr)
|
2017-11-04 01:48:23 -04:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
2020-08-18 09:03:35 -04:00
|
|
|
if (!dma_buf || !paddr || !vaddr || !plen) {
|
|
|
|
pr_err("%s: Invalid params\n", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
rc = msm_audio_ion_get_phys(dma_buf, paddr, plen);
|
|
|
|
if (rc) {
|
|
|
|
pr_err("%s: ION Get Physical for AUDIO failed, rc = %d\n",
|
|
|
|
__func__, rc);
|
2019-06-27 01:57:57 -04:00
|
|
|
dma_buf_put(dma_buf);
|
2017-11-04 01:48:23 -04:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2018-03-17 02:29:29 -04:00
|
|
|
*vaddr = msm_audio_ion_map_kernel(dma_buf);
|
|
|
|
if (IS_ERR_OR_NULL(*vaddr)) {
|
2017-11-04 01:48:23 -04:00
|
|
|
pr_err("%s: ION memory mapping for AUDIO failed\n", __func__);
|
|
|
|
rc = -ENOMEM;
|
2020-06-24 11:31:54 -04:00
|
|
|
msm_audio_dma_buf_unmap(dma_buf, false);
|
2017-11-04 01:48:23 -04:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-03-12 01:41:27 -04:00
|
|
|
static u32 msm_audio_ion_get_smmu_sid_mode32(void)
|
|
|
|
{
|
|
|
|
if (msm_audio_ion_data.smmu_enabled)
|
|
|
|
return upper_32_bits(msm_audio_ion_data.smmu_sid_bits);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-04 16:14:16 -04:00
|
|
|
/**
|
|
|
|
* msm_audio_ion_alloc -
|
|
|
|
* Allocs ION memory for given client name
|
|
|
|
*
|
2017-11-04 01:48:23 -04:00
|
|
|
* @dma_buf: dma_buf for the ION memory
|
2017-10-04 16:14:16 -04:00
|
|
|
* @bufsz: buffer size
|
|
|
|
* @paddr: Physical address to be assigned with allocated region
|
2017-11-04 01:48:23 -04:00
|
|
|
* @plen: length of allocated region to be assigned
|
2017-10-04 16:14:16 -04:00
|
|
|
* vaddr: virtual address to be assigned
|
|
|
|
*
|
|
|
|
* Returns 0 on success or error on failure
|
|
|
|
*/
|
2017-11-04 01:48:23 -04:00
|
|
|
int msm_audio_ion_alloc(struct dma_buf **dma_buf, size_t bufsz,
|
|
|
|
dma_addr_t *paddr, size_t *plen, void **vaddr)
|
2017-07-20 09:01:55 -04:00
|
|
|
{
|
|
|
|
int rc = -EINVAL;
|
|
|
|
unsigned long err_ion_ptr = 0;
|
|
|
|
|
2018-06-25 22:03:09 -04:00
|
|
|
if (!(msm_audio_ion_data.device_status & MSM_AUDIO_ION_PROBED)) {
|
2017-07-20 09:01:55 -04:00
|
|
|
pr_debug("%s:probe is not done, deferred\n", __func__);
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
}
|
2017-11-04 01:48:23 -04:00
|
|
|
if (!dma_buf || !paddr || !vaddr || !bufsz || !plen) {
|
2017-07-20 09:01:55 -04:00
|
|
|
pr_err("%s: Invalid params\n", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-03-12 01:41:27 -04:00
|
|
|
if (msm_audio_ion_data.smmu_enabled == true) {
|
|
|
|
pr_debug("%s: system heap is used\n", __func__);
|
|
|
|
*dma_buf = ion_alloc(bufsz, ION_HEAP(ION_SYSTEM_HEAP_ID), 0);
|
|
|
|
} else {
|
|
|
|
pr_debug("%s: audio heap is used\n", __func__);
|
|
|
|
*dma_buf = ion_alloc(bufsz, ION_HEAP(ION_AUDIO_HEAP_ID), 0);
|
|
|
|
}
|
2017-11-04 01:48:23 -04:00
|
|
|
if (IS_ERR_OR_NULL((void *)(*dma_buf))) {
|
|
|
|
if (IS_ERR((void *)(*dma_buf)))
|
|
|
|
err_ion_ptr = PTR_ERR((int *)(*dma_buf));
|
2018-03-12 01:41:27 -04:00
|
|
|
pr_err("%s: ION alloc fail err ptr=%ld, smmu_enabled=%d\n",
|
|
|
|
__func__, err_ion_ptr, msm_audio_ion_data.smmu_enabled);
|
2017-11-04 01:48:23 -04:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err;
|
2017-07-20 09:01:55 -04:00
|
|
|
}
|
|
|
|
|
2018-03-17 02:29:29 -04:00
|
|
|
rc = msm_audio_ion_map_buf(*dma_buf, paddr, plen, vaddr);
|
2017-07-20 09:01:55 -04:00
|
|
|
if (rc) {
|
2017-11-04 01:48:23 -04:00
|
|
|
pr_err("%s: failed to map ION buf, rc = %d\n", __func__, rc);
|
2019-06-27 01:57:57 -04:00
|
|
|
goto err;
|
2017-07-20 09:01:55 -04:00
|
|
|
}
|
|
|
|
pr_debug("%s: mapped address = %pK, size=%zd\n", __func__,
|
|
|
|
*vaddr, bufsz);
|
|
|
|
|
2018-03-17 02:29:29 -04:00
|
|
|
memset(*vaddr, 0, bufsz);
|
2017-07-20 09:01:55 -04:00
|
|
|
|
|
|
|
err:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(msm_audio_ion_alloc);
|
|
|
|
|
2018-12-12 17:25:06 -05:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
/**
|
|
|
|
* msm_audio_ion_import-
|
|
|
|
* Import ION buffer with given file descriptor
|
|
|
|
*
|
|
|
|
* @dma_buf: dma_buf for the ION memory
|
|
|
|
* @fd: file descriptor for the ION memory
|
|
|
|
* @ionflag: flags associated with ION buffer
|
|
|
|
* @bufsz: buffer size
|
|
|
|
* @paddr: Physical address to be assigned with allocated region
|
|
|
|
* @plen: length of allocated region to be assigned
|
2020-06-24 11:31:54 -04:00
|
|
|
* @vaddr: virtual address to be assigned
|
2017-11-04 01:48:23 -04:00
|
|
|
*
|
|
|
|
* Returns 0 on success or error on failure
|
|
|
|
*/
|
|
|
|
int msm_audio_ion_import(struct dma_buf **dma_buf, int fd,
|
2017-07-20 09:01:55 -04:00
|
|
|
unsigned long *ionflag, size_t bufsz,
|
2017-11-04 01:48:23 -04:00
|
|
|
dma_addr_t *paddr, size_t *plen, void **vaddr)
|
2017-07-20 09:01:55 -04:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
2018-06-25 22:03:09 -04:00
|
|
|
if (!(msm_audio_ion_data.device_status & MSM_AUDIO_ION_PROBED)) {
|
2018-03-12 01:41:27 -04:00
|
|
|
pr_debug("%s: probe is not done, deferred\n", __func__);
|
2017-07-20 09:01:55 -04:00
|
|
|
return -EPROBE_DEFER;
|
|
|
|
}
|
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
if (!dma_buf || !paddr || !vaddr || !plen) {
|
2017-07-20 09:01:55 -04:00
|
|
|
pr_err("%s: Invalid params\n", __func__);
|
2018-02-02 06:36:46 -05:00
|
|
|
return -EINVAL;
|
2017-07-20 09:01:55 -04:00
|
|
|
}
|
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
/* bufsz should be 0 and fd shouldn't be 0 as of now */
|
|
|
|
*dma_buf = dma_buf_get(fd);
|
|
|
|
pr_debug("%s: dma_buf =%pK, fd=%d\n", __func__, *dma_buf, fd);
|
|
|
|
if (IS_ERR_OR_NULL((void *)(*dma_buf))) {
|
|
|
|
pr_err("%s: dma_buf_get failed\n", __func__);
|
2017-07-20 09:01:55 -04:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ionflag != NULL) {
|
2018-02-02 06:36:46 -05:00
|
|
|
rc = dma_buf_get_flags(*dma_buf, ionflag);
|
|
|
|
if (rc) {
|
|
|
|
pr_err("%s: could not get flags for the dma_buf\n",
|
|
|
|
__func__);
|
|
|
|
goto err_ion_flag;
|
|
|
|
}
|
2017-07-20 09:01:55 -04:00
|
|
|
}
|
|
|
|
|
2018-03-17 02:29:29 -04:00
|
|
|
rc = msm_audio_ion_map_buf(*dma_buf, paddr, plen, vaddr);
|
2017-07-20 09:01:55 -04:00
|
|
|
if (rc) {
|
2017-11-04 01:48:23 -04:00
|
|
|
pr_err("%s: failed to map ION buf, rc = %d\n", __func__, rc);
|
2019-06-27 01:57:57 -04:00
|
|
|
goto err;
|
2017-07-20 09:01:55 -04:00
|
|
|
}
|
|
|
|
pr_debug("%s: mapped address = %pK, size=%zd\n", __func__,
|
|
|
|
*vaddr, bufsz);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
err_ion_flag:
|
|
|
|
dma_buf_put(*dma_buf);
|
2017-07-20 09:01:55 -04:00
|
|
|
err:
|
2017-11-04 01:48:23 -04:00
|
|
|
*dma_buf = NULL;
|
2017-07-20 09:01:55 -04:00
|
|
|
return rc;
|
|
|
|
}
|
2017-11-04 01:48:23 -04:00
|
|
|
EXPORT_SYMBOL(msm_audio_ion_import);
|
2017-07-20 09:01:55 -04:00
|
|
|
|
2020-06-24 11:31:54 -04:00
|
|
|
/**
|
|
|
|
* msm_audio_ion_import_cma-
|
|
|
|
* Import ION buffer with given file descriptor
|
|
|
|
*
|
|
|
|
* @dma_buf: dma_buf for the ION memory
|
|
|
|
* @fd: file descriptor for the ION memory
|
|
|
|
* @ionflag: flags associated with ION buffer
|
|
|
|
* @bufsz: buffer size
|
|
|
|
* @paddr: Physical address to be assigned with allocated region
|
|
|
|
* @plen: length of allocated region to be assigned
|
|
|
|
* vaddr: virtual address to be assigned
|
|
|
|
*
|
|
|
|
* Returns 0 on success or error on failure
|
|
|
|
*/
|
|
|
|
int msm_audio_ion_import_cma(struct dma_buf **dma_buf, int fd,
|
|
|
|
unsigned long *ionflag, size_t bufsz,
|
|
|
|
dma_addr_t *paddr, size_t *plen, void **vaddr)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (!(msm_audio_ion_data.device_status & MSM_AUDIO_ION_PROBED)) {
|
|
|
|
pr_debug("%s: probe is not done, deferred\n", __func__);
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dma_buf || !paddr || !vaddr || !plen ||
|
|
|
|
!msm_audio_ion_data.cb_cma_dev) {
|
|
|
|
pr_err("%s: Invalid params\n", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bufsz should be 0 and fd shouldn't be 0 as of now */
|
|
|
|
*dma_buf = dma_buf_get(fd);
|
|
|
|
pr_debug("%s: dma_buf =%pK, fd=%d\n", __func__, *dma_buf, fd);
|
|
|
|
if (IS_ERR_OR_NULL((void *)(*dma_buf))) {
|
|
|
|
pr_err("%s: dma_buf_get failed\n", __func__);
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ionflag != NULL) {
|
|
|
|
rc = dma_buf_get_flags(*dma_buf, ionflag);
|
|
|
|
if (rc) {
|
|
|
|
pr_err("%s: could not get flags for the dma_buf\n",
|
|
|
|
__func__);
|
|
|
|
goto err_ion_flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
msm_audio_dma_buf_map(*dma_buf, paddr, plen, true);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_ion_flag:
|
|
|
|
dma_buf_put(*dma_buf);
|
|
|
|
err:
|
|
|
|
*dma_buf = NULL;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(msm_audio_ion_import_cma);
|
|
|
|
|
2017-10-04 16:14:16 -04:00
|
|
|
/**
|
|
|
|
* msm_audio_ion_free -
|
|
|
|
* fress ION memory for given client and handle
|
|
|
|
*
|
2017-11-04 01:48:23 -04:00
|
|
|
* @dma_buf: dma_buf for the ION memory
|
2017-10-04 16:14:16 -04:00
|
|
|
*
|
|
|
|
* Returns 0 on success or error on failure
|
|
|
|
*/
|
2017-11-04 01:48:23 -04:00
|
|
|
int msm_audio_ion_free(struct dma_buf *dma_buf)
|
2017-07-20 09:01:55 -04:00
|
|
|
{
|
2018-10-15 15:21:06 -04:00
|
|
|
int ret = 0;
|
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
if (!dma_buf) {
|
|
|
|
pr_err("%s: dma_buf invalid\n", __func__);
|
2017-07-20 09:01:55 -04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-10-15 15:21:06 -04:00
|
|
|
ret = msm_audio_ion_unmap_kernel(dma_buf);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-11-04 01:48:23 -04:00
|
|
|
|
2020-06-24 11:31:54 -04:00
|
|
|
msm_audio_dma_buf_unmap(dma_buf, false);
|
2017-07-20 09:01:55 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(msm_audio_ion_free);
|
|
|
|
|
2020-06-24 11:31:54 -04:00
|
|
|
/**
|
|
|
|
* msm_audio_ion_free_cma -
|
|
|
|
* fress ION memory for given client and handle
|
|
|
|
*
|
|
|
|
* @dma_buf: dma_buf for the ION memory
|
|
|
|
*
|
|
|
|
* Returns 0 on success or error on failure
|
|
|
|
*/
|
|
|
|
int msm_audio_ion_free_cma(struct dma_buf *dma_buf)
|
|
|
|
{
|
|
|
|
if (!dma_buf) {
|
|
|
|
pr_err("%s: dma_buf invalid\n", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
msm_audio_dma_buf_unmap(dma_buf, true);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(msm_audio_ion_free_cma);
|
|
|
|
|
2017-10-04 16:14:16 -04:00
|
|
|
/**
|
|
|
|
* msm_audio_ion_mmap -
|
|
|
|
* Audio ION memory map
|
|
|
|
*
|
2017-11-04 01:48:23 -04:00
|
|
|
* @abuff: audio buf pointer
|
2017-10-04 16:14:16 -04:00
|
|
|
* @vma: virtual mem area
|
|
|
|
*
|
|
|
|
* Returns 0 on success or error on failure
|
|
|
|
*/
|
2017-11-04 01:48:23 -04:00
|
|
|
int msm_audio_ion_mmap(struct audio_buffer *abuff,
|
2017-07-20 09:01:55 -04:00
|
|
|
struct vm_area_struct *vma)
|
|
|
|
{
|
2017-11-04 01:48:23 -04:00
|
|
|
struct msm_audio_alloc_data *alloc_data = NULL;
|
2017-07-20 09:01:55 -04:00
|
|
|
struct sg_table *table;
|
|
|
|
unsigned long addr = vma->vm_start;
|
|
|
|
unsigned long offset = vma->vm_pgoff * PAGE_SIZE;
|
|
|
|
struct scatterlist *sg;
|
|
|
|
unsigned int i;
|
|
|
|
struct page *page;
|
2017-11-04 01:48:23 -04:00
|
|
|
int ret = 0;
|
|
|
|
bool found = false;
|
|
|
|
struct device *cb_dev = msm_audio_ion_data.cb_dev;
|
2017-07-20 09:01:55 -04:00
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
mutex_lock(&(msm_audio_ion_data.list_mutex));
|
|
|
|
list_for_each_entry(alloc_data, &(msm_audio_ion_data.alloc_list),
|
|
|
|
list) {
|
|
|
|
if (alloc_data->dma_buf == abuff->dma_buf) {
|
|
|
|
found = true;
|
|
|
|
table = alloc_data->table;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mutex_unlock(&(msm_audio_ion_data.list_mutex));
|
2017-07-20 09:01:55 -04:00
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
if (!found) {
|
|
|
|
dev_err(cb_dev,
|
|
|
|
"%s: cannot find allocation, dma_buf %pK",
|
|
|
|
__func__, abuff->dma_buf);
|
2017-07-20 09:01:55 -04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/* uncached */
|
|
|
|
vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
|
|
|
|
|
|
|
|
/* We need to check if a page is associated with this sg list because:
|
|
|
|
* If the allocation came from a carveout we currently don't have
|
|
|
|
* pages associated with carved out memory. This might change in the
|
|
|
|
* future and we can remove this check and the else statement.
|
|
|
|
*/
|
|
|
|
page = sg_page(table->sgl);
|
|
|
|
if (page) {
|
|
|
|
pr_debug("%s: page is NOT null\n", __func__);
|
|
|
|
for_each_sg(table->sgl, sg, table->nents, i) {
|
|
|
|
unsigned long remainder = vma->vm_end - addr;
|
|
|
|
unsigned long len = sg->length;
|
|
|
|
|
|
|
|
page = sg_page(sg);
|
|
|
|
|
|
|
|
if (offset >= len) {
|
|
|
|
offset -= len;
|
|
|
|
continue;
|
|
|
|
} else if (offset) {
|
|
|
|
page += offset / PAGE_SIZE;
|
|
|
|
len -= offset;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
len = min(len, remainder);
|
|
|
|
pr_debug("vma=%pK, addr=%x len=%ld vm_start=%x vm_end=%x vm_page_prot=%lu\n",
|
|
|
|
vma, (unsigned int)addr, len,
|
|
|
|
(unsigned int)vma->vm_start,
|
|
|
|
(unsigned int)vma->vm_end,
|
2017-10-26 01:59:48 -04:00
|
|
|
(unsigned long)pgprot_val(vma->vm_page_prot));
|
2017-07-20 09:01:55 -04:00
|
|
|
remap_pfn_range(vma, addr, page_to_pfn(page), len,
|
|
|
|
vma->vm_page_prot);
|
|
|
|
addr += len;
|
|
|
|
if (addr >= vma->vm_end)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pr_debug("%s: page is NULL\n", __func__);
|
2017-11-04 01:48:23 -04:00
|
|
|
ret = -EINVAL;
|
2017-07-20 09:01:55 -04:00
|
|
|
}
|
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
return ret;
|
2017-07-20 09:01:55 -04:00
|
|
|
}
|
2017-11-04 01:48:23 -04:00
|
|
|
EXPORT_SYMBOL(msm_audio_ion_mmap);
|
2017-07-20 09:01:55 -04:00
|
|
|
|
2018-02-02 06:36:46 -05:00
|
|
|
/**
|
|
|
|
* msm_audio_ion_cache_operations-
|
|
|
|
* Cache operations on cached Audio ION buffers
|
|
|
|
*
|
|
|
|
* @abuff: audio buf pointer
|
|
|
|
* @cache_op: cache operation to be performed
|
|
|
|
*
|
|
|
|
* Returns 0 on success or error on failure
|
|
|
|
*/
|
|
|
|
int msm_audio_ion_cache_operations(struct audio_buffer *abuff, int cache_op)
|
|
|
|
{
|
|
|
|
unsigned long ionflag = 0;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (!abuff) {
|
|
|
|
pr_err("%s: Invalid params: %pK\n", __func__, abuff);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
rc = dma_buf_get_flags(abuff->dma_buf, &ionflag);
|
|
|
|
if (rc) {
|
|
|
|
pr_err("%s: dma_buf_get_flags failed: %d\n", __func__, rc);
|
|
|
|
goto cache_op_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Has to be CACHED */
|
|
|
|
if (ionflag & ION_FLAG_CACHED) {
|
|
|
|
/* MSM_AUDIO_ION_INV_CACHES or MSM_AUDIO_ION_CLEAN_CACHES */
|
|
|
|
switch (cache_op) {
|
|
|
|
case MSM_AUDIO_ION_INV_CACHES:
|
|
|
|
case MSM_AUDIO_ION_CLEAN_CACHES:
|
2018-03-03 04:24:56 -05:00
|
|
|
dma_buf_begin_cpu_access(abuff->dma_buf,
|
|
|
|
DMA_BIDIRECTIONAL);
|
|
|
|
dma_buf_end_cpu_access(abuff->dma_buf,
|
|
|
|
DMA_BIDIRECTIONAL);
|
2018-02-02 06:36:46 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pr_err("%s: Invalid cache operation %d\n",
|
|
|
|
__func__, cache_op);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pr_err("%s: Cache ops called on uncached buffer: %pK\n",
|
|
|
|
__func__, abuff->dma_buf);
|
|
|
|
rc = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cache_op_failed:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(msm_audio_ion_cache_operations);
|
|
|
|
|
2017-10-04 16:14:16 -04:00
|
|
|
/**
|
2017-11-04 01:48:23 -04:00
|
|
|
* msm_audio_populate_upper_32_bits -
|
|
|
|
* retrieve upper 32bits of 64bit address
|
2017-10-04 16:14:16 -04:00
|
|
|
*
|
2017-11-04 01:48:23 -04:00
|
|
|
* @pa: 64bit physical address
|
2017-10-04 16:14:16 -04:00
|
|
|
*
|
|
|
|
*/
|
2017-11-04 01:48:23 -04:00
|
|
|
u32 msm_audio_populate_upper_32_bits(dma_addr_t pa)
|
2017-07-20 09:01:55 -04:00
|
|
|
{
|
2017-11-04 01:48:23 -04:00
|
|
|
if (sizeof(dma_addr_t) == sizeof(u32))
|
2018-03-12 01:41:27 -04:00
|
|
|
return msm_audio_ion_get_smmu_sid_mode32();
|
2017-11-04 01:48:23 -04:00
|
|
|
else
|
|
|
|
return upper_32_bits(pa);
|
2017-07-20 09:01:55 -04:00
|
|
|
}
|
2017-11-04 01:48:23 -04:00
|
|
|
EXPORT_SYMBOL(msm_audio_populate_upper_32_bits);
|
2017-07-20 09:01:55 -04:00
|
|
|
|
|
|
|
static int msm_audio_smmu_init(struct device *dev)
|
|
|
|
{
|
|
|
|
INIT_LIST_HEAD(&msm_audio_ion_data.alloc_list);
|
|
|
|
mutex_init(&(msm_audio_ion_data.list_mutex));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id msm_audio_ion_dt_match[] = {
|
|
|
|
{ .compatible = "qcom,msm-audio-ion" },
|
2020-06-24 11:31:54 -04:00
|
|
|
{ .compatible = "qcom,msm-audio-ion-cma"},
|
2017-07-20 09:01:55 -04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, msm_audio_ion_dt_match);
|
|
|
|
|
|
|
|
static int msm_audio_ion_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
2018-03-12 01:41:27 -04:00
|
|
|
u64 smmu_sid = 0;
|
|
|
|
u64 smmu_sid_mask = 0;
|
|
|
|
const char *msm_audio_ion_dt = "qcom,smmu-enabled";
|
2017-07-20 09:01:55 -04:00
|
|
|
const char *msm_audio_ion_smmu = "qcom,smmu-version";
|
|
|
|
const char *msm_audio_ion_smmu_sid_mask = "qcom,smmu-sid-mask";
|
2018-03-12 01:41:27 -04:00
|
|
|
bool smmu_enabled;
|
2017-07-20 09:01:55 -04:00
|
|
|
enum apr_subsys_state q6_state;
|
|
|
|
struct device *dev = &pdev->dev;
|
2017-11-04 01:48:23 -04:00
|
|
|
struct of_phandle_args iommuspec;
|
2017-07-20 09:01:55 -04:00
|
|
|
|
2018-03-12 01:41:27 -04:00
|
|
|
|
2017-07-20 09:01:55 -04:00
|
|
|
if (dev->of_node == NULL) {
|
|
|
|
dev_err(dev,
|
|
|
|
"%s: device tree is not found\n",
|
|
|
|
__func__);
|
2018-03-12 01:41:27 -04:00
|
|
|
msm_audio_ion_data.smmu_enabled = 0;
|
2017-07-20 09:01:55 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-24 11:31:54 -04:00
|
|
|
if (of_device_is_compatible(dev->of_node, "qcom,msm-audio-ion-cma")) {
|
|
|
|
msm_audio_ion_data.cb_cma_dev = dev;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-12 01:41:27 -04:00
|
|
|
smmu_enabled = of_property_read_bool(dev->of_node,
|
|
|
|
msm_audio_ion_dt);
|
|
|
|
msm_audio_ion_data.smmu_enabled = smmu_enabled;
|
|
|
|
|
|
|
|
if (!smmu_enabled) {
|
|
|
|
dev_dbg(dev, "%s: SMMU is Disabled\n", __func__);
|
|
|
|
goto exit;
|
2017-11-04 01:48:23 -04:00
|
|
|
}
|
2018-03-12 01:41:27 -04:00
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
q6_state = apr_get_q6_state();
|
|
|
|
if (q6_state == APR_SUBSYS_DOWN) {
|
|
|
|
dev_dbg(dev,
|
|
|
|
"defering %s, adsp_state %d\n",
|
|
|
|
__func__, q6_state);
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
}
|
|
|
|
dev_dbg(dev, "%s: adsp is ready\n", __func__);
|
2017-07-20 09:01:55 -04:00
|
|
|
|
2018-03-12 01:41:27 -04:00
|
|
|
rc = of_property_read_u32(dev->of_node,
|
|
|
|
msm_audio_ion_smmu,
|
|
|
|
&msm_audio_ion_data.smmu_version);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(dev,
|
|
|
|
"%s: qcom,smmu_version missing in DT node\n",
|
|
|
|
__func__);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
dev_dbg(dev, "%s: SMMU is Enabled. SMMU version is (%d)",
|
|
|
|
__func__, msm_audio_ion_data.smmu_version);
|
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
/* Get SMMU SID information from Devicetree */
|
|
|
|
rc = of_property_read_u64(dev->of_node,
|
|
|
|
msm_audio_ion_smmu_sid_mask,
|
|
|
|
&smmu_sid_mask);
|
|
|
|
if (rc) {
|
|
|
|
dev_err(dev,
|
|
|
|
"%s: qcom,smmu-sid-mask missing in DT node, using default\n",
|
|
|
|
__func__);
|
|
|
|
smmu_sid_mask = 0xFFFFFFFFFFFFFFFF;
|
2017-07-20 09:01:55 -04:00
|
|
|
}
|
2018-03-12 01:41:27 -04:00
|
|
|
|
2017-11-04 01:48:23 -04:00
|
|
|
rc = of_parse_phandle_with_args(dev->of_node, "iommus",
|
|
|
|
"#iommu-cells", 0, &iommuspec);
|
|
|
|
if (rc)
|
|
|
|
dev_err(dev, "%s: could not get smmu SID, ret = %d\n",
|
|
|
|
__func__, rc);
|
|
|
|
else
|
|
|
|
smmu_sid = (iommuspec.args[0] & smmu_sid_mask);
|
|
|
|
|
|
|
|
msm_audio_ion_data.smmu_sid_bits =
|
|
|
|
smmu_sid << MSM_AUDIO_SMMU_SID_OFFSET;
|
|
|
|
|
|
|
|
if (msm_audio_ion_data.smmu_version == 0x2) {
|
|
|
|
rc = msm_audio_smmu_init(dev);
|
|
|
|
} else {
|
|
|
|
dev_err(dev, "%s: smmu version invalid %d\n",
|
|
|
|
__func__, msm_audio_ion_data.smmu_version);
|
|
|
|
rc = -EINVAL;
|
|
|
|
}
|
|
|
|
if (rc)
|
|
|
|
dev_err(dev, "%s: smmu init failed, err = %d\n",
|
|
|
|
__func__, rc);
|
2017-07-20 09:01:55 -04:00
|
|
|
|
2018-03-12 01:41:27 -04:00
|
|
|
exit:
|
2017-07-20 09:01:55 -04:00
|
|
|
if (!rc)
|
|
|
|
msm_audio_ion_data.device_status |= MSM_AUDIO_ION_PROBED;
|
|
|
|
|
2018-04-26 01:29:47 -04:00
|
|
|
msm_audio_ion_data.cb_dev = dev;
|
|
|
|
|
2017-07-20 09:01:55 -04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int msm_audio_ion_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device *audio_cb_dev;
|
|
|
|
|
|
|
|
audio_cb_dev = msm_audio_ion_data.cb_dev;
|
|
|
|
|
2018-03-12 01:41:27 -04:00
|
|
|
msm_audio_ion_data.smmu_enabled = 0;
|
2017-07-20 09:01:55 -04:00
|
|
|
msm_audio_ion_data.device_status = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver msm_audio_ion_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "msm-audio-ion",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.of_match_table = msm_audio_ion_dt_match,
|
2018-06-29 03:14:37 -04:00
|
|
|
.suppress_bind_attrs = true,
|
2017-07-20 09:01:55 -04:00
|
|
|
},
|
|
|
|
.probe = msm_audio_ion_probe,
|
|
|
|
.remove = msm_audio_ion_remove,
|
|
|
|
};
|
|
|
|
|
2017-10-04 16:14:16 -04:00
|
|
|
int __init msm_audio_ion_init(void)
|
2017-07-20 09:01:55 -04:00
|
|
|
{
|
|
|
|
return platform_driver_register(&msm_audio_ion_driver);
|
|
|
|
}
|
|
|
|
|
2017-12-04 06:53:15 -05:00
|
|
|
void msm_audio_ion_exit(void)
|
2017-07-20 09:01:55 -04:00
|
|
|
{
|
|
|
|
platform_driver_unregister(&msm_audio_ion_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("MSM Audio ION module");
|
|
|
|
MODULE_LICENSE("GPL v2");
|