msm: QDSP5: audio: Migrate to ION
PMEM is deprecated, switch to ION.
Change-Id: I3ebfd979f1c8060e72edeaa31afed31ca838706d
Signed-off-by: Sidipotu Ashok <sashok@codeaurora.org>
diff --git a/arch/arm/mach-msm/qdsp5/audio_aac.c b/arch/arm/mach-msm/qdsp5/audio_aac.c
index 725819f..15e0590 100644
--- a/arch/arm/mach-msm/qdsp5/audio_aac.c
+++ b/arch/arm/mach-msm/qdsp5/audio_aac.c
@@ -31,10 +31,10 @@
#include <linux/delay.h>
#include <linux/list.h>
#include <linux/earlysuspend.h>
-#include <linux/android_pmem.h>
#include <linux/slab.h>
#include <linux/msm_audio_aac.h>
#include <linux/memory_alloc.h>
+#include <linux/ion.h>
#include <mach/msm_adsp.h>
#include <mach/iommu.h>
@@ -181,6 +181,9 @@
int eq_needs_commit;
audpp_cmd_cfg_object_params_eqalizer eq;
audpp_cmd_cfg_object_params_volume vol_pan;
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+ struct ion_handle *output_buff_handle;
};
static int auddec_dsp_config(struct audio *audio, int enable);
@@ -1508,10 +1511,11 @@
audio->event_abort = 1;
wake_up(&audio->event_wait);
audaac_reset_event_queue(audio);
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->read_phys);
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
#ifdef CONFIG_DEBUG_FS
if (audio->dentry)
@@ -1653,8 +1657,13 @@
{
struct audio *audio = NULL;
int rc, dec_attrb, decid, index, offset = 0;
- unsigned pmem_sz = DMASZ;
+ unsigned mem_sz = DMASZ;
struct audaac_event *e_node = NULL;
+ int len = 0;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
#ifdef CONFIG_DEBUG_FS
/* 4 bytes represents decoder number, 1 byte for terminate string */
char name[sizeof "msm_aac_" + 5];
@@ -1696,61 +1705,92 @@
}
audio->dec_id = decid & MSM_AUD_DECODER_MASK;
- while (pmem_sz >= DMASZ_MIN) {
- MM_DBG("pmemsz = %d\n", pmem_sz);
- audio->phys = allocate_contiguous_ebi_nomap(pmem_sz, SZ_4K);
- if (audio->phys) {
- audio->map_v_write = ioremap(audio->phys, pmem_sz);
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write buffers, \
- freeing instance 0x%08x\n",
- (int)audio);
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(audio->phys);
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- }
- audio->data = audio->map_v_write;
- MM_DBG("write buf: phy addr 0x%08x kernel addr \
- 0x%08x\n", audio->phys, (int)audio->data);
- break;
- } else if (pmem_sz == DMASZ_MIN) {
- MM_ERR("could not allocate write buffers, freeing \
- instance 0x%08x\n", (int)audio);
- rc = -ENOMEM;
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- } else
- pmem_sz >>= 1;
- }
- audio->out_dma_sz = pmem_sz;
-
- audio->read_phys = allocate_contiguous_ebi_nomap(PCM_BUFSZ_MIN *
- PCM_BUF_MAX_COUNT, SZ_4K);
- if (!audio->read_phys) {
- MM_ERR("could not allocate read buffers, freeing instance \
- 0x%08x\n", (int)audio);
+ client = msm_ion_client_create(UINT_MAX, "Audio_AAC_client");
+ if (IS_ERR_OR_NULL(client)) {
+ MM_ERR("Unable to create ION client\n");
rc = -ENOMEM;
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
+ goto client_create_error;
}
- audio->map_v_read = ioremap(audio->read_phys,
- PCM_BUFSZ_MIN * PCM_BUF_MAX_COUNT);
+ audio->client = client;
+
+ MM_DBG("allocating mem sz = %d\n", mem_sz);
+ handle = ion_alloc(client, mem_sz, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
+ }
+
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client, handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers,freeing instance 0x%08x\n",
+ (int)audio);
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
+
+ audio->out_dma_sz = mem_sz;
+
+ mem_sz = (PCM_BUFSZ_MIN * PCM_BUF_MAX_COUNT);
+ MM_DBG("allocating mem sz = %d\n", mem_sz);
+ handle = ion_alloc(client, mem_sz,
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate I/P buffers\n");
+ rc = -ENOMEM;
+ goto input_buff_alloc_error;
+ }
+
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(client , handle, &addr, &len);
+ if (rc) {
+ MM_ERR("I/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ goto input_buff_get_phys_error;
+ } else {
+ MM_INFO("out Got valid phy: %x sz: %x\n",
+ (unsigned int) audio->read_phys, (unsigned int) len);
+ }
+ audio->read_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ goto input_buff_get_flags_error;
+ }
+
+ audio->map_v_read = ion_map_kernel(client,
+ handle, ionflag);
if (IS_ERR(audio->map_v_read)) {
MM_ERR("could not map read buffers, freeing instance \
0x%08x\n", (int)audio);
rc = -ENOMEM;
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- free_contiguous_memory_by_paddr(audio->read_phys);
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
+ goto input_buff_map_error;
}
audio->read_data = audio->map_v_read;
MM_DBG("read buf: phy addr 0x%08x kernel addr 0x%08x\n",
@@ -1873,10 +1913,20 @@
done:
return rc;
err:
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->read_phys);
+ ion_unmap_kernel(client, audio->input_buff_handle);
+input_buff_map_error:
+input_buff_get_flags_error:
+input_buff_get_phys_error:
+ ion_free(client, audio->input_buff_handle);
+input_buff_alloc_error:
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_phys_error:
+output_buff_get_flags_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
audpp_adec_free(audio->dec_id);
kfree(audio);
return rc;
diff --git a/arch/arm/mach-msm/qdsp5/audio_aac_in.c b/arch/arm/mach-msm/qdsp5/audio_aac_in.c
index 79a828a..99e10a4 100644
--- a/arch/arm/mach-msm/qdsp5/audio_aac_in.c
+++ b/arch/arm/mach-msm/qdsp5/audio_aac_in.c
@@ -32,8 +32,8 @@
#include <linux/dma-mapping.h>
#include <linux/delay.h>
#include <linux/msm_audio_aac.h>
-#include <linux/android_pmem.h>
#include <linux/memory_alloc.h>
+#include <linux/ion.h>
#include "audmgr.h"
@@ -147,6 +147,9 @@
int enabled;
int running;
int stopped; /* set when stopped, cleared on flush */
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+ struct ion_handle *output_buff_handle;
};
struct audio_frame {
@@ -1248,16 +1251,17 @@
if ((audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) && \
(audio->out_data)) {
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->out_phys);
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
audio->out_data = NULL;
}
if (audio->data) {
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->phys);
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
audio->data = NULL;
}
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
return 0;
}
@@ -1270,6 +1274,11 @@
int rc;
int encid;
int dma_size = 0;
+ int len = 0;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
mutex_lock(&audio->lock);
if (audio->opened) {
@@ -1352,52 +1361,103 @@
audaac_in_flush(audio);
audaac_out_flush(audio);
- audio->phys = allocate_contiguous_ebi_nomap(dma_size, SZ_4K);
- if (audio->phys) {
- audio->map_v_read = ioremap(
- audio->phys, dma_size);
- if (IS_ERR(audio->map_v_read)) {
- MM_ERR("could not map DMA buffers\n");
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(audio->phys);
- goto evt_error;
- }
- audio->data = audio->map_v_read;
- } else {
- MM_ERR("could not allocate read buffers\n");
+
+ client = msm_ion_client_create(UINT_MAX, "Audio_AAC_in_client");
+ if (IS_ERR_OR_NULL(client)) {
+ MM_ERR("Unable to create ION client\n");
rc = -ENOMEM;
- goto evt_error;
+ goto client_create_error;
}
- MM_DBG("Memory addr = 0x%8x phy addr = 0x%8x\n",\
- (int) audio->data, (int) audio->phys);
+ audio->client = client;
+
+ MM_DBG("allocating mem sz = %d\n", dma_size);
+ handle = ion_alloc(client, dma_size, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
+ }
+
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client , handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ rc = -ENOMEM;
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ rc = -ENOMEM;
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_read = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_read)) {
+ MM_ERR("could not map read buffers,freeing instance 0x%08x\n",
+ (int)audio);
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_read;
+ MM_DBG("read buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
audio->out_data = NULL;
if (audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) {
- audio->out_phys = allocate_contiguous_ebi_nomap(BUFFER_SIZE,
- SZ_4K);
- if (!audio->out_phys) {
- MM_ERR("could not allocate write buffers\n");
+
+ MM_DBG("allocating BUFFER_SIZE %d\n", BUFFER_SIZE);
+ handle = ion_alloc(client, BUFFER_SIZE,
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate I/P buffers\n");
rc = -ENOMEM;
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->phys);
- goto evt_error;
- } else {
- audio->map_v_write = ioremap(
- audio->out_phys, BUFFER_SIZE);
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write phys address\n");
- rc = -ENOMEM;
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->phys);
- free_contiguous_memory_by_paddr(\
- audio->out_phys);
- goto evt_error;
- }
- audio->out_data = audio->map_v_write;
- MM_DBG("wr buf: phy addr 0x%08x kernel addr 0x%08x\n",
- audio->out_phys, (int)audio->out_data);
+ goto input_buff_alloc_error;
}
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(client , handle, &addr, &len);
+ if (rc) {
+ MM_ERR("I/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ rc = -ENOMEM;
+ goto input_buff_get_phys_error;
+ } else {
+ MM_INFO("Got valid phy: %x sz: %x\n",
+ (unsigned int) addr,
+ (unsigned int) len);
+ }
+ audio->out_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ rc = -ENOMEM;
+ goto input_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client,
+ handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto input_buff_map_error;
+ }
+ audio->out_data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ (unsigned int)addr,
+ (unsigned int)audio->out_data);
+
/* Initialize buffer */
audio->out[0].data = audio->out_data + 0;
audio->out[0].addr = audio->out_phys + 0;
@@ -1419,7 +1479,19 @@
done:
mutex_unlock(&audio->lock);
return rc;
-evt_error:
+input_buff_map_error:
+input_buff_get_flags_error:
+input_buff_get_phys_error:
+ ion_free(client, audio->input_buff_handle);
+input_buff_alloc_error:
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_phys_error:
+output_buff_get_flags_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
msm_adsp_put(audio->audrec);
if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL)
msm_adsp_put(audio->audpre);
diff --git a/arch/arm/mach-msm/qdsp5/audio_amrnb.c b/arch/arm/mach-msm/qdsp5/audio_amrnb.c
index 1a1002e..45fa045 100644
--- a/arch/arm/mach-msm/qdsp5/audio_amrnb.c
+++ b/arch/arm/mach-msm/qdsp5/audio_amrnb.c
@@ -39,10 +39,10 @@
#include <linux/delay.h>
#include <linux/list.h>
#include <linux/earlysuspend.h>
-#include <linux/android_pmem.h>
#include <linux/slab.h>
#include <linux/msm_audio.h>
#include <linux/memory_alloc.h>
+#include <linux/ion.h>
#include <mach/msm_adsp.h>
#include <mach/iommu.h>
@@ -179,6 +179,9 @@
int eq_needs_commit;
audpp_cmd_cfg_object_params_eqalizer eq;
audpp_cmd_cfg_object_params_volume vol_pan;
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+ struct ion_handle *output_buff_handle;
};
struct audpp_cmd_cfg_adec_params_amrnb {
@@ -784,6 +787,10 @@
uint16_t enable_mask;
int enable;
int prev_state;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ int len = 0;
MM_DBG("cmd = %d\n", cmd);
@@ -970,23 +977,53 @@
MM_DBG("allocate PCM buf %d\n",
config.buffer_count *
config.buffer_size);
- audio->read_phys = allocate_contiguous_ebi_nomap(
- config.buffer_size *
- config.buffer_count,
- SZ_4K);
- if (!audio->read_phys) {
+ handle = ion_alloc(audio->client,
+ (config.buffer_size *
+ config.buffer_count),
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to alloc I/P buffs\n");
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
break;
- }
- audio->map_v_read = ioremap(
- audio->read_phys,
- config.buffer_size *
- config.buffer_count);
+ }
+
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(audio->client ,
+ handle, &addr, &len);
+ if (rc) {
+ MM_ERR("Invalid phy: %x sz: %x\n",
+ (unsigned int) addr,
+ (unsigned int) len);
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ } else {
+ MM_INFO("Got valid phy: %x sz: %x\n",
+ (unsigned int) audio->read_phys,
+ (unsigned int) len);
+ }
+ audio->read_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(audio->client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ }
+ audio->map_v_read = ion_map_kernel(
+ audio->client,
+ handle, ionflag);
if (IS_ERR(audio->map_v_read)) {
MM_ERR("failed to map read buf\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
- free_contiguous_memory_by_paddr(
- audio->read_phys);
} else {
uint8_t index;
uint32_t offset = 0;
@@ -1295,12 +1332,13 @@
audio->event_abort = 1;
wake_up(&audio->event_wait);
audamrnb_reset_event_queue(audio);
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- if (audio->read_data) {
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->read_phys);
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
+ if (audio->input_buff_handle != NULL) {
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
}
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
#ifdef CONFIG_DEBUG_FS
if (audio->dentry)
@@ -1439,6 +1477,12 @@
struct audio *audio = NULL;
int rc, dec_attrb, decid, i;
struct audamrnb_event *e_node = NULL;
+ unsigned mem_sz = DMASZ;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
+ int len = 0;
#ifdef CONFIG_DEBUG_FS
/* 4 bytes represents decoder number, 1 byte for terminate string */
char name[sizeof "msm_amrnb_" + 5];
@@ -1482,30 +1526,50 @@
audio->dec_id = decid & MSM_AUD_DECODER_MASK;
- audio->phys = allocate_contiguous_ebi_nomap(DMASZ, SZ_4K);
- if (!audio->phys) {
- MM_ERR("could not allocate write buffers, freeing instance \
- 0x%08x\n", (int)audio);
+ client = msm_ion_client_create(UINT_MAX, "Audio_AMR_NB_Client");
+ if (IS_ERR_OR_NULL(client)) {
+ pr_err("Unable to create ION client\n");
rc = -ENOMEM;
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- } else {
- audio->map_v_write = ioremap(
- audio->phys, DMASZ);
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write buffers, freeing \
- instance 0x%08x freeing\n", (int)audio);
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(audio->phys);
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- }
- audio->data = audio->map_v_write;
- MM_DBG("write buf: phy addr 0x%08x kernel addr \
- 0x%08x\n", audio->phys, (int)audio->data);
+ goto client_create_error;
}
+ audio->client = client;
+
+ handle = ion_alloc(client, mem_sz, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
+ }
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client, handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK) {
rc = audmgr_open(&audio->audmgr);
@@ -1536,6 +1600,8 @@
goto err;
}
+ audio->input_buff_handle = NULL;
+
mutex_init(&audio->lock);
mutex_init(&audio->write_lock);
mutex_init(&audio->read_lock);
@@ -1590,8 +1656,14 @@
done:
return rc;
err:
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_phys_error:
+output_buff_get_flags_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
audpp_adec_free(audio->dec_id);
kfree(audio);
return rc;
diff --git a/arch/arm/mach-msm/qdsp5/audio_amrnb_in.c b/arch/arm/mach-msm/qdsp5/audio_amrnb_in.c
index ac2b5ca..39578c1 100644
--- a/arch/arm/mach-msm/qdsp5/audio_amrnb_in.c
+++ b/arch/arm/mach-msm/qdsp5/audio_amrnb_in.c
@@ -36,8 +36,8 @@
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/msm_audio_amrnb.h>
-#include <linux/android_pmem.h>
#include <linux/memory_alloc.h>
+#include <linux/ion.h>
#include "audmgr.h"
@@ -151,6 +151,9 @@
uint8_t enabled;
uint8_t running;
uint8_t stopped; /* set when stopped, cleared on flush */
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+
};
struct audio_frame {
@@ -1207,8 +1210,8 @@
audio->opened = 0;
if ((audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) && \
(audio->out_data)) {
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->out_phys);
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
audio->out_data = NULL;
}
if (audio->data) {
@@ -1221,6 +1224,7 @@
dma_size, audio->data, audio->phys);
audio->data = NULL;
}
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
return 0;
}
@@ -1233,6 +1237,11 @@
int32_t rc;
int encid;
int32_t dma_size = 0;
+ int len = 0;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
mutex_lock(&audio->lock);
if (audio->opened) {
@@ -1320,34 +1329,60 @@
goto evt_error;
}
+ client = msm_ion_client_create(UINT_MAX, "Audio_AMRNB_in_client");
+ if (IS_ERR_OR_NULL(client)) {
+ MM_ERR("Unable to create ION client\n");
+ rc = -ENOMEM;
+ goto client_create_error;
+ }
+ audio->client = client;
+
audio->out_data = NULL;
if (audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) {
- audio->out_phys = allocate_contiguous_ebi_nomap(BUFFER_SIZE,
- SZ_4K);
- if (!audio->out_phys) {
- MM_ERR("could not allocate write buffers\n");
+ MM_DBG("allocating BUFFER_SIZE %d\n", BUFFER_SIZE);
+ handle = ion_alloc(client, BUFFER_SIZE,
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate write buffers\n");
rc = -ENOMEM;
- dma_free_coherent(NULL,
- dma_size, audio->data, audio->phys);
- goto evt_error;
- } else {
- audio->map_v_write = ioremap(
- audio->out_phys, BUFFER_SIZE);
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write phys address\n");
- rc = -ENOMEM;
- dma_free_coherent(NULL,
- dma_size, audio->data, audio->phys);
- free_contiguous_memory_by_paddr(\
- audio->out_phys);
- goto evt_error;
- }
- audio->out_data = audio->map_v_write;
- MM_DBG("wr buf: phy addr 0x%08x kernel addr 0x%08x\n",
- audio->out_phys,
- (uint32_t)audio->out_data);
+ goto input_buff_alloc_error;
}
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(client , handle, &addr, &len);
+ if (rc) {
+ MM_ERR("I/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ rc = -ENOMEM;
+ goto input_buff_get_phys_error;
+ } else {
+ MM_INFO("Got valid phy: %x sz: %x\n",
+ (unsigned int) addr,
+ (unsigned int) len);
+ }
+ audio->out_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ rc = -ENOMEM;
+ goto input_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client,
+ handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto input_buff_map_error;
+ }
+ audio->out_data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ (unsigned int)addr,
+ (unsigned int)audio->out_data);
+
/* Initialize buffer */
audio->out[0].data = audio->out_data + 0;
audio->out[0].addr = audio->out_phys + 0;
@@ -1369,6 +1404,14 @@
done:
mutex_unlock(&audio->lock);
return rc;
+input_buff_map_error:
+input_buff_get_phys_error:
+input_buff_get_flags_error:
+ ion_free(client, audio->input_buff_handle);
+input_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
+ dma_free_coherent(NULL, dma_size, audio->data, audio->phys);
evt_error:
msm_adsp_put(audio->audrec);
if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL)
diff --git a/arch/arm/mach-msm/qdsp5/audio_amrwb.c b/arch/arm/mach-msm/qdsp5/audio_amrwb.c
index b85b153..66b9354 100644
--- a/arch/arm/mach-msm/qdsp5/audio_amrwb.c
+++ b/arch/arm/mach-msm/qdsp5/audio_amrwb.c
@@ -38,10 +38,10 @@
#include <linux/delay.h>
#include <linux/list.h>
#include <linux/earlysuspend.h>
-#include <linux/android_pmem.h>
#include <linux/slab.h>
#include <linux/msm_audio.h>
#include <linux/memory_alloc.h>
+#include <linux/ion.h>
#include <mach/msm_adsp.h>
#include <mach/iommu.h>
@@ -180,6 +180,9 @@
int eq_needs_commit;
audpp_cmd_cfg_object_params_eqalizer eq;
audpp_cmd_cfg_object_params_volume vol_pan;
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+ struct ion_handle *output_buff_handle;
};
static int auddec_dsp_config(struct audio *audio, int enable);
@@ -773,6 +776,10 @@
uint16_t enable_mask;
int enable;
int prev_state;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ int len = 0;
MM_DBG("cmd = %d\n", cmd);
@@ -966,23 +973,53 @@
if ((config.pcm_feedback) && (!audio->read_data)) {
MM_DBG("allocate PCM buf %d\n", config.buffer_count *
config.buffer_size);
- audio->read_phys = allocate_contiguous_ebi_nomap(
- config.buffer_size *
- config.buffer_count,
- SZ_4K);
- if (!audio->read_phys) {
+ handle = ion_alloc(audio->client,
+ (config.buffer_size *
+ config.buffer_count),
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to alloc I/P buffs\n");
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
break;
- }
- audio->map_v_read = ioremap(
- audio->read_phys,
- config.buffer_size *
- config.buffer_count);
+ }
+
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(audio->client ,
+ handle, &addr, &len);
+ if (rc) {
+ MM_ERR("Invalid phy: %x sz: %x\n",
+ (unsigned int) addr,
+ (unsigned int) len);
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ } else {
+ MM_INFO("Got valid phy: %x sz: %x\n",
+ (unsigned int) audio->read_phys,
+ (unsigned int) len);
+ }
+ audio->read_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(audio->client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ }
+ audio->map_v_read = ion_map_kernel(
+ audio->client,
+ handle, ionflag);
if (IS_ERR(audio->map_v_read)) {
MM_ERR("failed to map mem for read buf\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
- free_contiguous_memory_by_paddr(
- audio->read_phys);
} else {
uint8_t index;
uint32_t offset = 0;
@@ -1024,7 +1061,8 @@
}
/* Only useful in tunnel-mode */
-static int audamrwb_fsync(struct file *file, loff_t a, loff_t b, int datasync)
+static int audamrwb_fsync(struct file *file, loff_t a, loff_t b,
+ int datasync)
{
struct audio *audio = file->private_data;
struct buffer *frame;
@@ -1363,12 +1401,13 @@
audio->event_abort = 1;
wake_up(&audio->event_wait);
audamrwb_reset_event_queue(audio);
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- if (audio->read_data) {
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->read_phys);
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
+ if (audio->input_buff_handle != NULL) {
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
}
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
#ifdef CONFIG_DEBUG_FS
if (audio->dentry)
@@ -1509,8 +1548,14 @@
static int audamrwb_open(struct inode *inode, struct file *file)
{
struct audio *audio = NULL;
- int rc, dec_attrb, decid, i;
+ int rc = 0, dec_attrb, decid, i;
struct audamrwb_event *e_node = NULL;
+ unsigned mem_sz = DMASZ;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
+ int len = 0;
#ifdef CONFIG_DEBUG_FS
/* 4 bytes represents decoder number, 1 byte for terminate string */
char name[sizeof "msm_amrwb_" + 5];
@@ -1545,30 +1590,49 @@
audio->dec_id = decid & MSM_AUD_DECODER_MASK;
- audio->phys = allocate_contiguous_ebi_nomap(DMASZ, SZ_4K);
- if (!audio->phys) {
- MM_ERR("could not allocate write buffers, freeing instance \
- 0x%08x\n", (int)audio);
+ client = msm_ion_client_create(UINT_MAX, "Audio_AMR_WB_Client");
+ if (IS_ERR_OR_NULL(client)) {
+ pr_err("Unable to create ION client\n");
rc = -ENOMEM;
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- } else {
- audio->map_v_write = ioremap(audio->phys, DMASZ);
-
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write buffers, freeing \
- instance 0x%08x\n", (int)audio);
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(audio->phys);
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- }
- audio->data = audio->map_v_write;
- MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
- audio->phys, (int)audio->data);
+ goto client_create_error;
}
+ audio->client = client;
+
+ handle = ion_alloc(client, mem_sz, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ goto output_buff_alloc_error;
+ }
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client, handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK) {
rc = audmgr_open(&audio->audmgr);
@@ -1599,6 +1663,7 @@
goto err;
}
+ audio->input_buff_handle = NULL;
mutex_init(&audio->lock);
mutex_init(&audio->write_lock);
mutex_init(&audio->read_lock);
@@ -1658,8 +1723,14 @@
done:
return rc;
err:
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_phys_error:
+output_buff_get_flags_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
audpp_adec_free(audio->dec_id);
kfree(audio);
return rc;
diff --git a/arch/arm/mach-msm/qdsp5/audio_evrc.c b/arch/arm/mach-msm/qdsp5/audio_evrc.c
index 489929b..1d4148a 100644
--- a/arch/arm/mach-msm/qdsp5/audio_evrc.c
+++ b/arch/arm/mach-msm/qdsp5/audio_evrc.c
@@ -33,10 +33,10 @@
#include <linux/delay.h>
#include <linux/list.h>
#include <linux/earlysuspend.h>
-#include <linux/android_pmem.h>
#include <linux/slab.h>
#include <linux/msm_audio.h>
#include <linux/memory_alloc.h>
+#include <linux/ion.h>
#include <mach/msm_adsp.h>
#include <mach/iommu.h>
@@ -175,6 +175,9 @@
int eq_needs_commit;
audpp_cmd_cfg_object_params_eqalizer eq;
audpp_cmd_cfg_object_params_volume vol_pan;
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+ struct ion_handle *output_buff_handle;
};
static int auddec_dsp_config(struct audio *audio, int enable);
@@ -770,6 +773,10 @@
uint16_t enable_mask;
int enable;
int prev_state;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ int len = 0;
MM_DBG("cmd = %d\n", cmd);
@@ -955,25 +962,54 @@
MM_DBG("allocate PCM buf %d\n",
config.buffer_count *
config.buffer_size);
- audio->read_phys =
- allocate_contiguous_ebi_nomap(
- config.buffer_size *
- config.buffer_count,
- SZ_4K);
- if (!audio->read_phys) {
+ handle = ion_alloc(audio->client,
+ (config.buffer_size *
+ config.buffer_count),
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to alloc I/P buffs\n");
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
break;
}
- audio->map_v_read = ioremap(
- audio->read_phys,
- config.buffer_size *
- config.buffer_count);
+
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(audio->client ,
+ handle, &addr, &len);
+ if (rc) {
+ MM_ERR("Invalid phy: %x sz: %x\n",
+ (unsigned int) addr,
+ (unsigned int) len);
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ } else {
+ MM_INFO("Got valid phy: %x sz: %x\n",
+ (unsigned int) audio->read_phys,
+ (unsigned int) len);
+ }
+ audio->read_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(audio->client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ }
+ audio->map_v_read = ion_map_kernel(
+ audio->client,
+ handle, ionflag);
if (IS_ERR(audio->map_v_read)) {
MM_ERR("failed to map mem"
" for read buf\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
- free_contiguous_memory_by_paddr(
- audio->read_phys);
} else {
uint8_t index;
uint32_t offset = 0;
@@ -1287,12 +1323,13 @@
audio->event_abort = 1;
wake_up(&audio->event_wait);
audevrc_reset_event_queue(audio);
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- if (audio->read_data) {
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->read_phys);
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
+ if (audio->input_buff_handle != NULL) {
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
}
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
#ifdef CONFIG_DEBUG_FS
if (audio->dentry)
@@ -1431,6 +1468,13 @@
struct audio *audio = NULL;
int rc, dec_attrb, decid, i;
struct audevrc_event *e_node = NULL;
+ unsigned mem_sz = DMASZ;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
+ int len = 0;
+
#ifdef CONFIG_DEBUG_FS
/* 4 bytes represents decoder number, 1 byte for terminate string */
char name[sizeof "msm_evrc_" + 5];
@@ -1473,29 +1517,50 @@
audio->dec_id = decid & MSM_AUD_DECODER_MASK;
- audio->phys = allocate_contiguous_ebi_nomap(DMASZ, SZ_4K);
- if (!audio->phys) {
- MM_ERR("could not allocate write buffers, freeing instance \
- 0x%08x\n", (int)audio);
+ client = msm_ion_client_create(UINT_MAX, "Audio_EVRC_Client");
+ if (IS_ERR_OR_NULL(client)) {
+ pr_err("Unable to create ION client\n");
rc = -ENOMEM;
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- } else {
- audio->map_v_write = ioremap(audio->phys, DMASZ);
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write buffers, freeing \
- instance 0x%08x\n", (int)audio);
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(audio->phys);
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- }
- audio->data = audio->map_v_write;
- MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
- audio->phys, (int)audio->data);
+ goto client_create_error;
}
+ audio->client = client;
+
+ handle = ion_alloc(client, mem_sz, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
+ }
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client, handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK) {
rc = audmgr_open(&audio->audmgr);
@@ -1527,6 +1592,8 @@
goto err;
}
+ audio->input_buff_handle = NULL;
+
/* Initialize all locks of audio instance */
mutex_init(&audio->lock);
mutex_init(&audio->write_lock);
@@ -1582,8 +1649,14 @@
done:
return rc;
err:
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_phys_error:
+output_buff_get_flags_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
audpp_adec_free(audio->dec_id);
kfree(audio);
return rc;
diff --git a/arch/arm/mach-msm/qdsp5/audio_evrc_in.c b/arch/arm/mach-msm/qdsp5/audio_evrc_in.c
index e13b072..e955c4b 100644
--- a/arch/arm/mach-msm/qdsp5/audio_evrc_in.c
+++ b/arch/arm/mach-msm/qdsp5/audio_evrc_in.c
@@ -33,6 +33,7 @@
#include <linux/memory_alloc.h>
+#include <linux/ion.h>
#include <asm/atomic.h>
#include <asm/ioctls.h>
@@ -150,6 +151,9 @@
int enabled;
int running;
int stopped; /* set when stopped, cleared on flush */
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+ struct ion_handle *output_buff_handle;
};
struct audio_frame {
@@ -1003,7 +1007,8 @@
spin_unlock_irqrestore(&audio->dsp_lock, flags);
}
-static int audevrc_in_fsync(struct file *file,loff_t a, loff_t b, int datasync)
+static int audevrc_in_fsync(struct file *file, loff_t a, loff_t b,
+ int datasync)
{
struct audio_evrc_in *audio = file->private_data;
@@ -1190,15 +1195,16 @@
audio->opened = 0;
if ((audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) && \
(audio->out_data)) {
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->out_phys);
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
audio->out_data = NULL;
}
if (audio->data) {
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->phys);
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
audio->data = NULL;
}
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
return 0;
}
@@ -1211,6 +1217,11 @@
int rc;
int encid;
int dma_size = 0;
+ int len = 0;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
mutex_lock(&audio->lock);
if (audio->opened) {
@@ -1290,51 +1301,101 @@
audevrc_in_flush(audio);
audevrc_out_flush(audio);
- audio->phys = allocate_contiguous_ebi_nomap(dma_size, SZ_4K);
- if (!audio->phys) {
- MM_ERR("could not allocate physical read buffers\n");
+ client = msm_ion_client_create(UINT_MAX, "Audio_EVRC_in_client");
+ if (IS_ERR_OR_NULL(client)) {
+ MM_ERR("Unable to create ION client\n");
rc = -ENOMEM;
- goto evt_error;
- } else {
- audio->map_v_read = ioremap(audio->phys, dma_size);
- if (IS_ERR(audio->map_v_read)) {
- MM_ERR("could not map physical address\n");
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(audio->phys);
- goto evt_error;
- }
- audio->data = audio->map_v_read;
- MM_DBG("read buf: phy addr 0x%08x kernel addr 0x%08x\n",
- audio->phys, (int)audio->data);
+ goto client_create_error;
}
+ audio->client = client;
+
+ MM_DBG("allocating mem sz = %d\n", dma_size);
+ handle = ion_alloc(client, dma_size, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
+ }
+
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client , handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ rc = -ENOMEM;
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ rc = -ENOMEM;
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_read = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_read)) {
+ MM_ERR("could not map read buffers,freeing instance 0x%08x\n",
+ (int)audio);
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_read;
+ MM_DBG("read buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
+
audio->out_data = NULL;
if (audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) {
- audio->out_phys = allocate_contiguous_ebi_nomap(BUFFER_SIZE,
- SZ_4K);
- if (!audio->out_phys) {
- MM_ERR("could not allocate physical write buffers\n");
+ MM_DBG("allocating BUFFER_SIZE %d\n", BUFFER_SIZE);
+ handle = ion_alloc(client, BUFFER_SIZE,
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate I/P buffers\n");
rc = -ENOMEM;
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->phys);
- goto evt_error;
- } else {
- audio->map_v_write = ioremap(
- audio->out_phys, BUFFER_SIZE);
-
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write phys address\n");
- rc = -ENOMEM;
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->phys);
- free_contiguous_memory_by_paddr(\
- audio->out_phys);
- goto evt_error;
- }
- audio->out_data = audio->map_v_write;
- MM_DBG("wr buf: phy addr 0x%08x kernel addr 0x%08x\n",
- audio->out_phys, (int)audio->out_data);
+ goto input_buff_alloc_error;
}
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(client , handle, &addr, &len);
+ if (rc) {
+ MM_ERR("I/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ rc = -ENOMEM;
+ goto input_buff_alloc_error;
+ } else {
+ MM_INFO("Got valid phy: %x sz: %x\n",
+ (unsigned int) addr,
+ (unsigned int) len);
+ }
+ audio->out_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ rc = -ENOMEM;
+ goto input_buff_alloc_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client,
+ handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto input_buff_map_error;
+ }
+ audio->out_data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ (unsigned int)addr,
+ (unsigned int)audio->out_data);
+
/* Initialize buffer */
audio->out[0].data = audio->out_data + 0;
audio->out[0].addr = audio->out_phys + 0;
@@ -1356,7 +1417,17 @@
done:
mutex_unlock(&audio->lock);
return rc;
-evt_error:
+input_buff_map_error:
+ ion_free(client, audio->input_buff_handle);
+input_buff_alloc_error:
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_phys_error:
+output_buff_get_flags_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
msm_adsp_put(audio->audrec);
if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL)
msm_adsp_put(audio->audpre);
diff --git a/arch/arm/mach-msm/qdsp5/audio_lpa.c b/arch/arm/mach-msm/qdsp5/audio_lpa.c
index 8754337..14a9e57 100644
--- a/arch/arm/mach-msm/qdsp5/audio_lpa.c
+++ b/arch/arm/mach-msm/qdsp5/audio_lpa.c
@@ -37,8 +37,8 @@
#include <linux/debugfs.h>
#include <linux/delay.h>
#include <linux/earlysuspend.h>
+#include <linux/ion.h>
#include <linux/list.h>
-#include <linux/android_pmem.h>
#include <linux/slab.h>
#include <linux/msm_audio.h>
@@ -137,9 +137,9 @@
union msm_audio_event_payload payload;
};
-struct audlpa_pmem_region {
+struct audlpa_ion_region {
struct list_head list;
- struct file *file;
+ struct ion_handle *handle;
int fd;
void *vaddr;
unsigned long paddr;
@@ -217,9 +217,10 @@
struct mutex get_event_lock;
int event_abort;
- struct list_head pmem_region_queue;
+ struct list_head ion_region_queue;
int buffer_count;
int buffer_size;
+ struct ion_client *client;
};
static int auddec_dsp_config(struct audio *audio, int enable);
@@ -227,7 +228,7 @@
static void audio_dsp_event(void *private, unsigned id, uint16_t *msg);
static void audpcm_post_event(struct audio *audio, int type,
union msm_audio_event_payload payload);
-static unsigned long audlpa_pmem_fixup(struct audio *audio, void *addr,
+static unsigned long audlpa_ion_fixup(struct audio *audio, void *addr,
unsigned long len, int ref_up);
static void audpcm_async_send_data(struct audio *audio,
unsigned needed);
@@ -679,7 +680,7 @@
if (drv_evt && drv_evt->event_type == AUDIO_EVENT_WRITE_DONE) {
mutex_lock(&audio->lock);
- audlpa_pmem_fixup(audio, drv_evt->payload.aio_buf.buf_addr,
+ audlpa_ion_fixup(audio, drv_evt->payload.aio_buf.buf_addr,
drv_evt->payload.aio_buf.buf_len, 0);
mutex_unlock(&audio->lock);
}
@@ -689,94 +690,118 @@
return rc;
}
-static int audlpa_pmem_check(struct audio *audio,
+static int audlpa_ion_check(struct audio *audio,
void *vaddr, unsigned long len)
{
- struct audlpa_pmem_region *region_elt;
- struct audlpa_pmem_region t = { .vaddr = vaddr, .len = len };
+ struct audlpa_ion_region *region_elt;
+ struct audlpa_ion_region t = {.vaddr = vaddr, .len = len };
- list_for_each_entry(region_elt, &audio->pmem_region_queue, list) {
+ list_for_each_entry(region_elt, &audio->ion_region_queue, list) {
if (CONTAINS(region_elt, &t) || CONTAINS(&t, region_elt) ||
OVERLAPS(region_elt, &t)) {
- MM_ERR("region (vaddr %p len %ld)"
+ MM_ERR("[%p]:region (vaddr %p len %ld)"
" clashes with registered region"
" (vaddr %p paddr %p len %ld)\n",
- vaddr, len,
+ audio, vaddr, len,
region_elt->vaddr,
- (void *)region_elt->paddr,
- region_elt->len);
+ (void *)region_elt->paddr, region_elt->len);
return -EINVAL;
}
}
return 0;
}
-
-static int audlpa_pmem_add(struct audio *audio,
- struct msm_audio_pmem_info *info)
+static int audlpa_ion_add(struct audio *audio,
+ struct msm_audio_ion_info *info)
{
- unsigned long paddr, kvaddr, len;
- struct file *file;
- struct audlpa_pmem_region *region;
+ ion_phys_addr_t paddr;
+ size_t len;
+ unsigned long kvaddr;
+ struct audlpa_ion_region *region;
int rc = -EINVAL;
+ struct ion_handle *handle;
+ unsigned long ionflag;
- MM_DBG("\n"); /* Macro prints the file name and function */
+ MM_ERR("\n"); /* Macro prints the file name and function */
region = kmalloc(sizeof(*region), GFP_KERNEL);
if (!region) {
rc = -ENOMEM;
goto end;
}
-
- if (get_pmem_file(info->fd, &paddr, &kvaddr, &len, &file)) {
- kfree(region);
- goto end;
+ handle = ion_import_dma_buf(audio->client, info->fd);
+ if (IS_ERR_OR_NULL(handle)) {
+ pr_err("%s: could not get handle of the given fd\n", __func__);
+ goto import_error;
}
-
- rc = audlpa_pmem_check(audio, info->vaddr, len);
+ rc = ion_handle_get_flags(audio->client, handle, &ionflag);
+ if (rc) {
+ pr_err("%s: could not get flags for the handle\n", __func__);
+ goto flag_error;
+ }
+ kvaddr = (unsigned long)ion_map_kernel(audio->client, handle, ionflag);
+ if (IS_ERR_OR_NULL((void *)kvaddr)) {
+ pr_err("%s: could not get virtual address\n", __func__);
+ goto map_error;
+ }
+ rc = ion_phys(audio->client, handle, &paddr, &len);
+ if (rc) {
+ pr_err("%s: could not get physical address\n", __func__);
+ goto ion_error;
+ }
+ rc = audlpa_ion_check(audio, info->vaddr, len);
if (rc < 0) {
- put_pmem_file(file);
- kfree(region);
- goto end;
+ MM_ERR("audpcm_ion_check failed\n");
+ goto ion_error;
}
-
+ region->handle = handle;
region->vaddr = info->vaddr;
region->fd = info->fd;
region->paddr = paddr;
region->kvaddr = kvaddr;
region->len = len;
- region->file = file;
region->ref_cnt = 0;
- MM_DBG("add region paddr %lx vaddr %p, len %lu\n", region->paddr,
- region->vaddr, region->len);
- list_add_tail(®ion->list, &audio->pmem_region_queue);
+ MM_DBG("[%p]:add region paddr %lx vaddr %p, len %lu kvaddr %lx\n",
+ audio, region->paddr, region->vaddr,
+ region->len, region->kvaddr);
+ list_add_tail(®ion->list, &audio->ion_region_queue);
+
+ return rc;
+
+ion_error:
+ ion_unmap_kernel(audio->client, handle);
+map_error:
+flag_error:
+ ion_free(audio->client, handle);
+import_error:
+ kfree(region);
end:
return rc;
}
-static int audlpa_pmem_remove(struct audio *audio,
- struct msm_audio_pmem_info *info)
+static int audlpa_ion_remove(struct audio *audio,
+ struct msm_audio_ion_info *info)
{
- struct audlpa_pmem_region *region;
+ struct audlpa_ion_region *region;
struct list_head *ptr, *next;
int rc = -EINVAL;
- MM_DBG("info fd %d vaddr %p\n", info->fd, info->vaddr);
+ list_for_each_safe(ptr, next, &audio->ion_region_queue) {
+ region = list_entry(ptr, struct audlpa_ion_region, list);
- list_for_each_safe(ptr, next, &audio->pmem_region_queue) {
- region = list_entry(ptr, struct audlpa_pmem_region, list);
-
- if ((region->fd == info->fd) &&
+ if (region != NULL && (region->fd == info->fd) &&
(region->vaddr == info->vaddr)) {
if (region->ref_cnt) {
- MM_DBG("region %p in use ref_cnt %d\n",
- region, region->ref_cnt);
+ MM_DBG("%s[%p]:region %p in use ref_cnt %d\n",
+ __func__, audio, region,
+ region->ref_cnt);
break;
}
MM_DBG("remove region fd %d vaddr %p\n",
info->fd, info->vaddr);
list_del(®ion->list);
- put_pmem_file(region->file);
+ ion_unmap_kernel(audio->client, region->handle);
+ ion_free(audio->client, region->handle);
kfree(region);
rc = 0;
break;
@@ -786,23 +811,20 @@
return rc;
}
-static int audlpa_pmem_lookup_vaddr(struct audio *audio, void *addr,
- unsigned long len, struct audlpa_pmem_region **region)
+static int audlpa_ion_lookup_vaddr(struct audio *audio, void *addr,
+ unsigned long len, struct audlpa_ion_region **region)
{
- struct audlpa_pmem_region *region_elt;
-
+ struct audlpa_ion_region *region_elt;
int match_count = 0;
-
*region = NULL;
/* returns physical address or zero */
- list_for_each_entry(region_elt, &audio->pmem_region_queue,
- list) {
+ list_for_each_entry(region_elt, &audio->ion_region_queue, list) {
if (addr >= region_elt->vaddr &&
addr < region_elt->vaddr + region_elt->len &&
addr + len <= region_elt->vaddr + region_elt->len) {
/* offset since we could pass vaddr inside a registerd
- * pmem buffer
+ * ion buffer
*/
match_count++;
@@ -812,31 +834,33 @@
}
if (match_count > 1) {
- MM_ERR("multiple hits for vaddr %p, len %ld\n", addr, len);
- list_for_each_entry(region_elt,
- &audio->pmem_region_queue, list) {
+ MM_ERR("%s[%p]:multiple hits for vaddr %p, len %ld\n",
+ __func__, audio, addr, len);
+ list_for_each_entry(region_elt, &audio->ion_region_queue,
+ list) {
if (addr >= region_elt->vaddr &&
- addr < region_elt->vaddr + region_elt->len &&
- addr + len <= region_elt->vaddr + region_elt->len)
- MM_ERR("\t%p, %ld --> %p\n", region_elt->vaddr,
+ addr < region_elt->vaddr + region_elt->len &&
+ addr + len <= region_elt->vaddr + region_elt->len)
+ MM_ERR("\t%s[%p]:%p, %ld --> %p\n",
+ __func__, audio,
+ region_elt->vaddr,
region_elt->len,
(void *)region_elt->paddr);
}
}
-
return *region ? 0 : -1;
}
-
-unsigned long audlpa_pmem_fixup(struct audio *audio, void *addr,
+static unsigned long audlpa_ion_fixup(struct audio *audio, void *addr,
unsigned long len, int ref_up)
{
- struct audlpa_pmem_region *region;
+ struct audlpa_ion_region *region;
unsigned long paddr;
int ret;
- ret = audlpa_pmem_lookup_vaddr(audio, addr, len, ®ion);
+ ret = audlpa_ion_lookup_vaddr(audio, addr, len, ®ion);
if (ret) {
- MM_ERR("lookup (%p, %ld) failed\n", addr, len);
+ MM_ERR("%s[%p]:lookup (%p, %ld) failed\n",
+ __func__, audio, addr, len);
return 0;
}
if (ref_up)
@@ -870,10 +894,9 @@
buf_node->buf.buf_addr, buf_node->buf.buf_len,
buf_node->buf.data_len);
- buf_node->paddr = audlpa_pmem_fixup(
+ buf_node->paddr = audlpa_ion_fixup(
audio, buf_node->buf.buf_addr,
buf_node->buf.buf_len, 1);
-
if (dir) {
/* write */
if (!buf_node->paddr ||
@@ -1042,23 +1065,23 @@
rc = audpp_pause(audio->dec_id, (int) arg);
break;
- case AUDIO_REGISTER_PMEM: {
- struct msm_audio_pmem_info info;
- MM_DBG("AUDIO_REGISTER_PMEM\n");
+ case AUDIO_REGISTER_ION: {
+ struct msm_audio_ion_info info;
+ MM_ERR("AUDIO_REGISTER_ION\n");
if (copy_from_user(&info, (void *) arg, sizeof(info)))
rc = -EFAULT;
else
- rc = audlpa_pmem_add(audio, &info);
+ rc = audlpa_ion_add(audio, &info);
break;
}
- case AUDIO_DEREGISTER_PMEM: {
- struct msm_audio_pmem_info info;
- MM_DBG("AUDIO_DEREGISTER_PMEM\n");
+ case AUDIO_DEREGISTER_ION: {
+ struct msm_audio_ion_info info;
+ MM_ERR("AUDIO_DEREGISTER_ION\n");
if (copy_from_user(&info, (void *) arg, sizeof(info)))
rc = -EFAULT;
else
- rc = audlpa_pmem_remove(audio, &info);
+ rc = audlpa_ion_remove(audio, &info);
break;
}
@@ -1175,7 +1198,8 @@
return rc;
}
-int audlpa_fsync(struct file *file, loff_t a, loff_t b, int datasync)
+int audlpa_fsync(struct file *file, loff_t a, loff_t b,
+ int datasync)
{
struct audio *audio = file->private_data;
@@ -1185,21 +1209,21 @@
return audlpa_async_fsync(audio);
}
-static void audpcm_reset_pmem_region(struct audio *audio)
+static void audpcm_reset_ion_region(struct audio *audio)
{
- struct audlpa_pmem_region *region;
+ struct audlpa_ion_region *region;
struct list_head *ptr, *next;
- list_for_each_safe(ptr, next, &audio->pmem_region_queue) {
- region = list_entry(ptr, struct audlpa_pmem_region, list);
+ list_for_each_safe(ptr, next, &audio->ion_region_queue) {
+ region = list_entry(ptr, struct audlpa_ion_region, list);
list_del(®ion->list);
- put_pmem_file(region->file);
+ ion_unmap_kernel(audio->client, region->handle);
+ ion_free(audio->client, region->handle);
kfree(region);
}
return;
}
-
static int audio_release(struct inode *inode, struct file *file)
{
struct audio *audio = file->private_data;
@@ -1210,7 +1234,7 @@
if (audio->rmt_resource_released == 0)
rmt_put_resource(audio);
audpcm_async_flush(audio);
- audpcm_reset_pmem_region(audio);
+ audpcm_reset_ion_region(audio);
msm_adsp_put(audio->audplay);
audpp_adec_free(audio->dec_id);
@@ -1221,16 +1245,12 @@
audio->event_abort = 1;
wake_up(&audio->event_wait);
audpcm_reset_event_queue(audio);
- MM_DBG("pmem area = 0x%8x\n", (unsigned int)audio->data);
- if (audio->data) {
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- }
mutex_unlock(&audio->lock);
#ifdef CONFIG_DEBUG_FS
if (audio->dentry)
debugfs_remove(audio->dentry);
#endif
+ ion_client_destroy(audio->client);
kfree(audio);
return 0;
}
@@ -1416,7 +1436,7 @@
spin_lock_init(&audio->dsp_lock);
init_waitqueue_head(&audio->write_wait);
INIT_LIST_HEAD(&audio->out_queue);
- INIT_LIST_HEAD(&audio->pmem_region_queue);
+ INIT_LIST_HEAD(&audio->ion_region_queue);
INIT_LIST_HEAD(&audio->free_event_queue);
INIT_LIST_HEAD(&audio->event_queue);
init_waitqueue_head(&audio->wait);
@@ -1456,6 +1476,14 @@
break;
}
}
+
+ audio->client = msm_ion_client_create(UINT_MAX, "Audio_LPA_Client");
+ if (IS_ERR_OR_NULL(audio->client)) {
+ pr_err("Unable to create ION client\n");
+ goto err;
+ }
+ MM_DBG("Ion client created\n");
+
done:
return rc;
err:
diff --git a/arch/arm/mach-msm/qdsp5/audio_mp3.c b/arch/arm/mach-msm/qdsp5/audio_mp3.c
index 9346107..427dc8f 100644
--- a/arch/arm/mach-msm/qdsp5/audio_mp3.c
+++ b/arch/arm/mach-msm/qdsp5/audio_mp3.c
@@ -31,10 +31,10 @@
#include <linux/delay.h>
#include <linux/earlysuspend.h>
#include <linux/list.h>
-#include <linux/android_pmem.h>
#include <linux/slab.h>
#include <linux/msm_audio.h>
#include <linux/memory_alloc.h>
+#include <linux/ion.h>
#include <mach/msm_adsp.h>
#include <mach/iommu.h>
@@ -136,9 +136,9 @@
union msm_audio_event_payload payload;
};
-struct audmp3_pmem_region {
+struct audmp3_ion_region {
struct list_head list;
- struct file *file;
+ struct ion_handle *handle;
int fd;
void *vaddr;
unsigned long paddr;
@@ -241,13 +241,16 @@
struct mutex get_event_lock;
int event_abort;
- struct list_head pmem_region_queue; /* protected by lock */
+ struct list_head ion_region_queue; /* protected by lock */
struct audmp3_drv_operations drv_ops;
int eq_enable;
int eq_needs_commit;
audpp_cmd_cfg_object_params_eqalizer eq;
audpp_cmd_cfg_object_params_volume vol_pan;
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+ struct ion_handle *output_buff_handle;
};
static int auddec_dsp_config(struct audio *audio, int enable);
@@ -259,7 +262,7 @@
static void audio_dsp_event(void *private, unsigned id, uint16_t *msg);
static void audmp3_post_event(struct audio *audio, int type,
union msm_audio_event_payload payload);
-static unsigned long audmp3_pmem_fixup(struct audio *audio, void *addr,
+static unsigned long audmp3_ion_fixup(struct audio *audio, void *addr,
unsigned long len, int ref_up);
static int rmt_put_resource(struct audio *audio)
@@ -1021,7 +1024,7 @@
if (drv_evt->event_type == AUDIO_EVENT_WRITE_DONE ||
drv_evt->event_type == AUDIO_EVENT_READ_DONE) {
mutex_lock(&audio->lock);
- audmp3_pmem_fixup(audio, drv_evt->payload.aio_buf.buf_addr,
+ audmp3_ion_fixup(audio, drv_evt->payload.aio_buf.buf_addr,
drv_evt->payload.aio_buf.buf_len, 0);
mutex_unlock(&audio->lock);
}
@@ -1036,13 +1039,13 @@
return rc;
}
-static int audmp3_pmem_check(struct audio *audio,
+static int audmp3_ion_check(struct audio *audio,
void *vaddr, unsigned long len)
{
- struct audmp3_pmem_region *region_elt;
- struct audmp3_pmem_region t = { .vaddr = vaddr, .len = len };
+ struct audmp3_ion_region *region_elt;
+ struct audmp3_ion_region t = { .vaddr = vaddr, .len = len };
- list_for_each_entry(region_elt, &audio->pmem_region_queue, list) {
+ list_for_each_entry(region_elt, &audio->ion_region_queue, list) {
if (CONTAINS(region_elt, &t) || CONTAINS(&t, region_elt) ||
OVERLAPS(region_elt, &t)) {
MM_ERR("region (vaddr %p len %ld)"
@@ -1059,13 +1062,17 @@
return 0;
}
-static int audmp3_pmem_add(struct audio *audio,
- struct msm_audio_pmem_info *info)
+static int audmp3_ion_add(struct audio *audio,
+ struct msm_audio_ion_info *info)
{
- unsigned long paddr, kvaddr, len;
- struct file *file;
- struct audmp3_pmem_region *region;
+ ion_phys_addr_t paddr;
+ size_t len;
+ unsigned long kvaddr;
+ struct audmp3_ion_region *region;
int rc = -EINVAL;
+ struct ion_handle *handle;
+ unsigned long ionflag;
+ void *temp_ptr;
MM_DBG("\n"); /* Macro prints the file name and function */
region = kmalloc(sizeof(*region), GFP_KERNEL);
@@ -1075,55 +1082,84 @@
goto end;
}
- if (get_pmem_file(info->fd, &paddr, &kvaddr, &len, &file)) {
- kfree(region);
- goto end;
+ handle = ion_import_dma_buf(audio->client, info->fd);
+ if (IS_ERR_OR_NULL(handle)) {
+ pr_err("%s: could not get handle of the given fd\n", __func__);
+ goto import_error;
}
- rc = audmp3_pmem_check(audio, info->vaddr, len);
+ rc = ion_handle_get_flags(audio->client, handle, &ionflag);
+ if (rc) {
+ pr_err("%s: could not get flags for the handle\n", __func__);
+ goto flag_error;
+ }
+
+ temp_ptr = ion_map_kernel(audio->client, handle, ionflag);
+ if (IS_ERR_OR_NULL(temp_ptr)) {
+ pr_err("%s: could not get virtual address\n", __func__);
+ goto map_error;
+ }
+ kvaddr = (unsigned long) temp_ptr;
+
+ rc = ion_phys(audio->client, handle, &paddr, &len);
+ if (rc) {
+ pr_err("%s: could not get physical address\n", __func__);
+ goto ion_error;
+ }
+
+ rc = audmp3_ion_check(audio, info->vaddr, len);
if (rc < 0) {
- put_pmem_file(file);
- kfree(region);
- goto end;
+ MM_ERR("audpcm_ion_check failed\n");
+ goto ion_error;
}
+ region->handle = handle;
region->vaddr = info->vaddr;
region->fd = info->fd;
region->paddr = paddr;
region->kvaddr = kvaddr;
region->len = len;
- region->file = file;
region->ref_cnt = 0;
- MM_DBG("add region paddr %lx vaddr %p, len %lu\n", region->paddr,
- region->vaddr, region->len);
- list_add_tail(®ion->list, &audio->pmem_region_queue);
+ MM_DBG("[%p]:add region paddr %lx vaddr %p, len %lu kvaddr %lx\n",
+ audio, region->paddr, region->vaddr,
+ region->len, region->kvaddr);
+ list_add_tail(®ion->list, &audio->ion_region_queue);
+ return rc;
+
+ion_error:
+ ion_unmap_kernel(audio->client, handle);
+map_error:
+flag_error:
+ ion_free(audio->client, handle);
+import_error:
+ kfree(region);
end:
return rc;
}
-static int audmp3_pmem_remove(struct audio *audio,
- struct msm_audio_pmem_info *info)
+static int audmp3_ion_remove(struct audio *audio,
+ struct msm_audio_ion_info *info)
{
- struct audmp3_pmem_region *region;
+ struct audmp3_ion_region *region;
struct list_head *ptr, *next;
int rc = -EINVAL;
- MM_DBG("info fd %d vaddr %p\n", info->fd, info->vaddr);
+ list_for_each_safe(ptr, next, &audio->ion_region_queue) {
+ region = list_entry(ptr, struct audmp3_ion_region, list);
- list_for_each_safe(ptr, next, &audio->pmem_region_queue) {
- region = list_entry(ptr, struct audmp3_pmem_region, list);
-
- if ((region->fd == info->fd) &&
+ if (region != NULL && (region->fd == info->fd) &&
(region->vaddr == info->vaddr)) {
if (region->ref_cnt) {
- MM_DBG("region %p in use ref_cnt %d\n",
- region, region->ref_cnt);
+ MM_DBG("%s[%p]:region %p in use ref_cnt %d\n",
+ __func__, audio, region,
+ region->ref_cnt);
break;
}
- MM_DBG("remove region fd %d vaddr %p \n",
- info->fd, info->vaddr);
+ MM_DBG("remove region fd %d vaddr %p\n",
+ info->fd, info->vaddr);
list_del(®ion->list);
- put_pmem_file(region->file);
+ ion_unmap_kernel(audio->client, region->handle);
+ ion_free(audio->client, region->handle);
kfree(region);
rc = 0;
break;
@@ -1133,23 +1169,20 @@
return rc;
}
-static int audmp3_pmem_lookup_vaddr(struct audio *audio, void *addr,
- unsigned long len, struct audmp3_pmem_region **region)
+static int audmp3_ion_lookup_vaddr(struct audio *audio, void *addr,
+ unsigned long len, struct audmp3_ion_region **region)
{
- struct audmp3_pmem_region *region_elt;
-
+ struct audmp3_ion_region *region_elt;
int match_count = 0;
-
*region = NULL;
/* returns physical address or zero */
- list_for_each_entry(region_elt, &audio->pmem_region_queue,
- list) {
+ list_for_each_entry(region_elt, &audio->ion_region_queue, list) {
if (addr >= region_elt->vaddr &&
addr < region_elt->vaddr + region_elt->len &&
addr + len <= region_elt->vaddr + region_elt->len) {
/* offset since we could pass vaddr inside a registerd
- * pmem buffer
+ * ion buffer
*/
match_count++;
@@ -1159,29 +1192,31 @@
}
if (match_count > 1) {
- MM_ERR("multiple hits for vaddr %p, len %ld\n", addr, len);
- list_for_each_entry(region_elt,
- &audio->pmem_region_queue, list) {
+ MM_ERR("%s[%p]:multiple hits for vaddr %p, len %ld\n",
+ __func__, audio, addr, len);
+ list_for_each_entry(region_elt, &audio->ion_region_queue,
+ list) {
if (addr >= region_elt->vaddr &&
- addr < region_elt->vaddr + region_elt->len &&
- addr + len <= region_elt->vaddr + region_elt->len)
- MM_ERR("\t%p, %ld --> %p\n", region_elt->vaddr,
+ addr < region_elt->vaddr + region_elt->len &&
+ addr + len <= region_elt->vaddr + region_elt->len)
+ MM_ERR("\t%s[%p]:%p, %ld --> %p\n",
+ __func__, audio,
+ region_elt->vaddr,
region_elt->len,
(void *)region_elt->paddr);
}
}
-
return *region ? 0 : -1;
}
-unsigned long audmp3_pmem_fixup(struct audio *audio, void *addr,
+unsigned long audmp3_ion_fixup(struct audio *audio, void *addr,
unsigned long len, int ref_up)
{
- struct audmp3_pmem_region *region;
+ struct audmp3_ion_region *region;
unsigned long paddr;
int ret;
- ret = audmp3_pmem_lookup_vaddr(audio, addr, len, ®ion);
+ ret = audmp3_ion_lookup_vaddr(audio, addr, len, ®ion);
if (ret) {
MM_ERR("lookup (%p, %ld) failed\n", addr, len);
return 0;
@@ -1217,7 +1252,7 @@
buf_node->buf.buf_addr, buf_node->buf.buf_len,
buf_node->buf.data_len);
- buf_node->paddr = audmp3_pmem_fixup(
+ buf_node->paddr = audmp3_ion_fixup(
audio, buf_node->buf.buf_addr,
buf_node->buf.buf_len, 1);
@@ -1276,6 +1311,10 @@
uint16_t enable_mask;
int enable;
int prev_state;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ int len = 0;
MM_DBG("cmd = %d\n", cmd);
@@ -1481,25 +1520,50 @@
MM_DBG("allocate PCM buffer %d\n",
config.buffer_count *
config.buffer_size);
- audio->read_phys =
- allocate_contiguous_ebi_nomap(
- config.buffer_size *
- config.buffer_count,
- SZ_4K);
- if (!audio->read_phys) {
+
+ handle = ion_alloc(audio->client,
+ (config.buffer_size *
+ config.buffer_count),
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to alloc I/P buffs\n");
rc = -ENOMEM;
break;
}
- audio->map_v_read = ioremap(
- audio->read_phys,
- config.buffer_size *
- config.buffer_count);
+
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(audio->client ,
+ handle, &addr, &len);
+ if (rc) {
+ MM_ERR("Invalid phy: %x sz: %x\n",
+ (unsigned int) addr,
+ (unsigned int) len);
+ rc = -ENOMEM;
+ break;
+ } else {
+ MM_INFO("Got valid phy: %x sz: %x\n",
+ (unsigned int) audio->read_phys,
+ (unsigned int) len);
+ }
+ audio->read_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(audio->client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags\n");
+ rc = -ENOMEM;
+ break;
+ }
+
+ audio->map_v_read = ion_map_kernel(
+ audio->client,
+ handle, ionflag);
if (IS_ERR(audio->map_v_read)) {
MM_ERR("map of read buf failed\n");
rc = -ENOMEM;
- free_contiguous_memory_by_paddr(
- audio->read_phys);
+ ion_free(audio->client, handle);
} else {
uint8_t index;
uint32_t offset = 0;
@@ -1539,23 +1603,23 @@
rc = audpp_pause(audio->dec_id, (int) arg);
break;
- case AUDIO_REGISTER_PMEM: {
- struct msm_audio_pmem_info info;
- MM_DBG("AUDIO_REGISTER_PMEM\n");
+ case AUDIO_REGISTER_ION: {
+ struct msm_audio_ion_info info;
+ MM_DBG("AUDIO_REGISTER_ION\n");
if (copy_from_user(&info, (void *) arg, sizeof(info)))
rc = -EFAULT;
else
- rc = audmp3_pmem_add(audio, &info);
+ rc = audmp3_ion_add(audio, &info);
break;
}
- case AUDIO_DEREGISTER_PMEM: {
- struct msm_audio_pmem_info info;
- MM_DBG("AUDIO_DEREGISTER_PMEM\n");
+ case AUDIO_DEREGISTER_ION: {
+ struct msm_audio_ion_info info;
+ MM_DBG("AUDIO_DEREGISTER_ION\n");
if (copy_from_user(&info, (void *) arg, sizeof(info)))
rc = -EFAULT;
else
- rc = audmp3_pmem_remove(audio, &info);
+ rc = audmp3_ion_remove(audio, &info);
break;
}
case AUDIO_ASYNC_WRITE:
@@ -1939,16 +2003,16 @@
}
return rc;
}
-
-static void audmp3_reset_pmem_region(struct audio *audio)
+static void audmp3_reset_ion_region(struct audio *audio)
{
- struct audmp3_pmem_region *region;
+ struct audmp3_ion_region *region;
struct list_head *ptr, *next;
- list_for_each_safe(ptr, next, &audio->pmem_region_queue) {
- region = list_entry(ptr, struct audmp3_pmem_region, list);
+ list_for_each_safe(ptr, next, &audio->ion_region_queue) {
+ region = list_entry(ptr, struct audmp3_ion_region, list);
list_del(®ion->list);
- put_pmem_file(region->file);
+ ion_unmap_kernel(audio->client, region->handle);
+ ion_free(audio->client, region->handle);
kfree(region);
}
@@ -1966,7 +2030,7 @@
rmt_put_resource(audio);
audio->drv_ops.out_flush(audio);
audio->drv_ops.in_flush(audio);
- audmp3_reset_pmem_region(audio);
+ audmp3_reset_ion_region(audio);
msm_adsp_put(audio->audplay);
audpp_adec_free(audio->dec_id);
@@ -1977,20 +2041,18 @@
audio->event_abort = 1;
wake_up(&audio->event_wait);
audmp3_reset_event_queue(audio);
- MM_DBG("pmem area = 0x%8x\n", (unsigned int)audio->data);
- if (audio->data) {
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- }
- if (audio->read_data) {
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->read_phys);
- }
mutex_unlock(&audio->lock);
#ifdef CONFIG_DEBUG_FS
if (audio->dentry)
debugfs_remove(audio->dentry);
#endif
+ if (!(audio->drv_status & ADRV_STATUS_AIO_INTF)) {
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
+ }
+ ion_client_destroy(audio->client);
kfree(audio);
return 0;
}
@@ -2129,7 +2191,13 @@
struct audio *audio = NULL;
int rc, i, dec_attrb, decid;
struct audmp3_event *e_node = NULL;
- unsigned pmem_sz = DMASZ_MAX;
+ unsigned mem_sz = DMASZ_MAX;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
+ int len = 0;
+
#ifdef CONFIG_DEBUG_FS
/* 4 bytes represents decoder number, 1 byte for terminate string */
char name[sizeof "msm_mp3_" + 5];
@@ -2171,43 +2239,57 @@
}
audio->dec_id = decid & MSM_AUD_DECODER_MASK;
+ client = msm_ion_client_create(UINT_MAX, "Audio_MP3_Client");
+ if (IS_ERR_OR_NULL(client)) {
+ pr_err("Unable to create ION client\n");
+ rc = -ENOMEM;
+ goto client_create_error;
+ }
+ audio->client = client;
+
/* Non AIO interface */
if (!(file->f_flags & O_NONBLOCK)) {
- while (pmem_sz >= DMASZ_MIN) {
- MM_DBG("pmemsz = %d\n", pmem_sz);
- audio->phys = allocate_contiguous_ebi_nomap(pmem_sz,
- SZ_4K);
- if (audio->phys) {
- audio->map_v_write = ioremap(
- audio->phys, pmem_sz);
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write \
- buffers, freeing instance \
- 0x%08x\n", (int)audio);
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(
- audio->phys);
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- }
- audio->data = audio->map_v_write;
- MM_DBG("write buf: phy addr 0x%08x kernel addr\
- 0x%08x\n", audio->phys,\
- (int)audio->data);
- break;
- } else if (pmem_sz == DMASZ_MIN) {
- MM_ERR("could not allocate write buffers, \
- freeing instance 0x%08x\n",
- (int)audio);
- rc = -ENOMEM;
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- } else
- pmem_sz >>= 1;
+
+ MM_DBG("memsz = %d\n", mem_sz);
+
+ handle = ion_alloc(client, mem_sz, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
}
- audio->out_dma_sz = pmem_sz;
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client , handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
+
+ audio->out_dma_sz = mem_sz;
}
if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK) {
@@ -2276,7 +2358,7 @@
init_waitqueue_head(&audio->read_wait);
INIT_LIST_HEAD(&audio->out_queue);
INIT_LIST_HEAD(&audio->in_queue);
- INIT_LIST_HEAD(&audio->pmem_region_queue);
+ INIT_LIST_HEAD(&audio->ion_region_queue);
INIT_LIST_HEAD(&audio->free_event_queue);
INIT_LIST_HEAD(&audio->event_queue);
init_waitqueue_head(&audio->wait);
@@ -2315,13 +2397,18 @@
break;
}
}
+
done:
return rc;
err:
- if (audio->data) {
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- }
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_flags_error:
+output_buff_get_phys_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
audpp_adec_free(audio->dec_id);
kfree(audio);
return rc;
diff --git a/arch/arm/mach-msm/qdsp5/audio_pcm.c b/arch/arm/mach-msm/qdsp5/audio_pcm.c
index 49c781f..880de09 100644
--- a/arch/arm/mach-msm/qdsp5/audio_pcm.c
+++ b/arch/arm/mach-msm/qdsp5/audio_pcm.c
@@ -38,7 +38,7 @@
#include <linux/delay.h>
#include <linux/earlysuspend.h>
#include <linux/list.h>
-#include <linux/android_pmem.h>
+#include <linux/ion.h>
#include <linux/slab.h>
#include <linux/msm_audio.h>
@@ -134,11 +134,10 @@
union msm_audio_event_payload payload;
};
-struct audpcm_pmem_region {
+struct audpcm_ion_region {
struct list_head list;
- struct file *file;
+ struct ion_handle *handle;
int fd;
- void *vaddr_ref;
void *vaddr;
unsigned long paddr;
unsigned long kvaddr;
@@ -222,8 +221,10 @@
struct mutex get_event_lock;
int event_abort;
- struct list_head pmem_region_queue;
+ struct list_head ion_region_queue;
struct audpcm_drv_operations drv_ops;
+ struct ion_client *client;
+ struct ion_handle *output_buff_handle;
};
static int auddec_dsp_config(struct audio *audio, int enable);
@@ -232,7 +233,7 @@
static void audio_dsp_event(void *private, unsigned id, uint16_t *msg);
static void audpcm_post_event(struct audio *audio, int type,
union msm_audio_event_payload payload);
-static unsigned long audpcm_pmem_fixup(struct audio *audio, void *addr,
+static unsigned long audpcm_ion_fixup(struct audio *audio, void *addr,
unsigned long len, int ref_up);
static int rmt_put_resource(struct audio *audio)
@@ -762,7 +763,7 @@
if (drv_evt && drv_evt->event_type == AUDIO_EVENT_WRITE_DONE) {
mutex_lock(&audio->lock);
- audpcm_pmem_fixup(audio, drv_evt->payload.aio_buf.buf_addr,
+ audpcm_ion_fixup(audio, drv_evt->payload.aio_buf.buf_addr,
drv_evt->payload.aio_buf.buf_len, 0);
mutex_unlock(&audio->lock);
}
@@ -772,104 +773,118 @@
return rc;
}
-static int audpcm_pmem_check(struct audio *audio,
+static int audpcm_ion_check(struct audio *audio,
void *vaddr, unsigned long len)
{
- struct audpcm_pmem_region *region_elt;
- struct audpcm_pmem_region t = { .vaddr = vaddr, .len = len };
+ struct audpcm_ion_region *region_elt;
+ struct audpcm_ion_region t = {.vaddr = vaddr, .len = len };
- list_for_each_entry(region_elt, &audio->pmem_region_queue, list) {
+ list_for_each_entry(region_elt, &audio->ion_region_queue, list) {
if (CONTAINS(region_elt, &t) || CONTAINS(&t, region_elt) ||
OVERLAPS(region_elt, &t)) {
- MM_ERR("region (vaddr %p len %ld)"
+ MM_ERR("[%p]:region (vaddr %p len %ld)"
" clashes with registered region"
" (vaddr %p paddr %p len %ld)\n",
- vaddr, len,
+ audio, vaddr, len,
region_elt->vaddr,
- (void *)region_elt->paddr,
- region_elt->len);
+ (void *)region_elt->paddr, region_elt->len);
return -EINVAL;
}
}
return 0;
}
-
-static int audpcm_pmem_add(struct audio *audio,
- struct msm_audio_pmem_info *info)
+static int audpcm_ion_add(struct audio *audio,
+ struct msm_audio_ion_info *info)
{
- unsigned long paddr, kvaddr, len;
- struct file *file;
- struct audpcm_pmem_region *region;
- struct vm_area_struct *vma;
+ ion_phys_addr_t paddr;
+ size_t len;
+ unsigned long kvaddr;
+ struct audpcm_ion_region *region;
int rc = -EINVAL;
+ struct ion_handle *handle;
+ unsigned long ionflag;
- MM_DBG("\n"); /* Macro prints the file name and function */
+ MM_ERR("\n"); /* Macro prints the file name and function */
region = kmalloc(sizeof(*region), GFP_KERNEL);
- if (!region)
- return -ENOMEM;
- if (get_pmem_file(info->fd, &paddr, &kvaddr, &len, &file)) {
- kfree(region);
- return -EINVAL;
+ if (!region) {
+ rc = -ENOMEM;
+ goto end;
}
-
- vma = find_vma_intersection(current->active_mm,
- (unsigned long) info->vaddr, (unsigned long) info->vaddr+1);
-
- if (vma && ((vma->vm_end - vma->vm_start) == len)) {
- rc = audpcm_pmem_check(audio, (void *) vma->vm_start, len);
- if (rc < 0) {
- put_pmem_file(file);
- kfree(region);
- return rc;
- }
- region->vaddr = (void *) vma->vm_start;
- region->vaddr_ref = info->vaddr;
- MM_DBG("Valid VMA region vma->vm_start = 0x%8x \
- vma->vm_end = 0x%8x\n", (int) vma->vm_start,
- (int) vma->vm_end);
- } else {
- MM_ERR("No valid VMA region found\n");
- put_pmem_file(file);
- kfree(region);
- return rc;
+ handle = ion_import_dma_buf(audio->client, info->fd);
+ if (IS_ERR_OR_NULL(handle)) {
+ pr_err("%s: could not get handle of the given fd\n", __func__);
+ goto import_error;
}
+ rc = ion_handle_get_flags(audio->client, handle, &ionflag);
+ if (rc) {
+ pr_err("%s: could not get flags for the handle\n", __func__);
+ goto flag_error;
+ }
+ kvaddr = (unsigned long)ion_map_kernel(audio->client, handle, ionflag);
+ if (IS_ERR_OR_NULL((void *)kvaddr)) {
+ pr_err("%s: could not get virtual address\n", __func__);
+ goto map_error;
+ }
+ rc = ion_phys(audio->client, handle, &paddr, &len);
+ if (rc) {
+ pr_err("%s: could not get physical address\n", __func__);
+ goto ion_error;
+ }
+ rc = audpcm_ion_check(audio, info->vaddr, len);
+ if (rc < 0) {
+ MM_ERR("audpcm_ion_check failed\n");
+ goto ion_error;
+ }
+ region->handle = handle;
+ region->vaddr = info->vaddr;
region->fd = info->fd;
region->paddr = paddr;
region->kvaddr = kvaddr;
region->len = len;
- region->file = file;
region->ref_cnt = 0;
- MM_DBG("add region paddr %lx vaddr %p, len %lu\n", region->paddr,
- region->vaddr, region->len);
- list_add_tail(®ion->list, &audio->pmem_region_queue);
+ MM_DBG("[%p]:add region paddr %lx vaddr %p, len %lu kvaddr %lx\n",
+ audio, region->paddr, region->vaddr,
+ region->len, region->kvaddr);
+ list_add_tail(®ion->list, &audio->ion_region_queue);
+
+ return rc;
+
+ion_error:
+ ion_unmap_kernel(audio->client, handle);
+map_error:
+flag_error:
+ ion_free(audio->client, handle);
+import_error:
+ kfree(region);
+end:
return rc;
}
-static int audpcm_pmem_remove(struct audio *audio,
- struct msm_audio_pmem_info *info)
+static int audpcm_ion_remove(struct audio *audio,
+ struct msm_audio_ion_info *info)
{
- struct audpcm_pmem_region *region;
+ struct audpcm_ion_region *region;
struct list_head *ptr, *next;
int rc = -EINVAL;
- MM_DBG("info fd %d vaddr %p\n", info->fd, info->vaddr);
+ list_for_each_safe(ptr, next, &audio->ion_region_queue) {
+ region = list_entry(ptr, struct audpcm_ion_region, list);
- list_for_each_safe(ptr, next, &audio->pmem_region_queue) {
- region = list_entry(ptr, struct audpcm_pmem_region, list);
-
- if ((region->fd == info->fd) &&
- (region->vaddr_ref == info->vaddr)) {
+ if (region != NULL && (region->fd == info->fd) &&
+ (region->vaddr == info->vaddr)) {
if (region->ref_cnt) {
- MM_DBG("region %p in use ref_cnt %d\n",
- region, region->ref_cnt);
+ MM_DBG("%s[%p]:region %p in use ref_cnt %d\n",
+ __func__, audio, region,
+ region->ref_cnt);
break;
}
- MM_DBG("remove region fd %d vaddr %p \n", info->fd,
- info->vaddr);
+ MM_DBG("remove region fd %d vaddr %p\n",
+ info->fd, info->vaddr);
list_del(®ion->list);
- put_pmem_file(region->file);
+ ion_unmap_kernel(audio->client, region->handle);
+ ion_free(audio->client, region->handle);
kfree(region);
rc = 0;
break;
@@ -879,24 +894,22 @@
return rc;
}
-static int audpcm_pmem_lookup_vaddr(struct audio *audio, void *addr,
- unsigned long len, struct audpcm_pmem_region **region)
+static int audpcm_ion_lookup_vaddr(struct audio *audio, void *addr,
+ unsigned long len, struct audpcm_ion_region **region)
{
- struct audpcm_pmem_region *region_elt;
-
+ struct audpcm_ion_region *region_elt;
int match_count = 0;
-
*region = NULL;
/* returns physical address or zero */
- list_for_each_entry(region_elt, &audio->pmem_region_queue,
- list) {
+ list_for_each_entry(region_elt, &audio->ion_region_queue, list) {
if (addr >= region_elt->vaddr &&
addr < region_elt->vaddr + region_elt->len &&
addr + len <= region_elt->vaddr + region_elt->len) {
/* offset since we could pass vaddr inside a registerd
- * pmem buffer
+ * ion buffer
*/
+
match_count++;
if (!*region)
*region = region_elt;
@@ -904,31 +917,33 @@
}
if (match_count > 1) {
- MM_ERR("multiple hits for vaddr %p, len %ld\n", addr, len);
- list_for_each_entry(region_elt,
- &audio->pmem_region_queue, list) {
+ MM_ERR("%s[%p]:multiple hits for vaddr %p, len %ld\n",
+ __func__, audio, addr, len);
+ list_for_each_entry(region_elt, &audio->ion_region_queue,
+ list) {
if (addr >= region_elt->vaddr &&
addr < region_elt->vaddr + region_elt->len &&
addr + len <= region_elt->vaddr + region_elt->len)
- MM_ERR("\t%p, %ld --> %p\n", region_elt->vaddr,
+ MM_ERR("\t%s[%p]:%p, %ld --> %p\n",
+ __func__, audio,
+ region_elt->vaddr,
region_elt->len,
(void *)region_elt->paddr);
}
}
-
return *region ? 0 : -1;
}
-
-static unsigned long audpcm_pmem_fixup(struct audio *audio, void *addr,
+static unsigned long audpcm_ion_fixup(struct audio *audio, void *addr,
unsigned long len, int ref_up)
{
- struct audpcm_pmem_region *region;
+ struct audpcm_ion_region *region;
unsigned long paddr;
int ret;
- ret = audpcm_pmem_lookup_vaddr(audio, addr, len, ®ion);
+ ret = audpcm_ion_lookup_vaddr(audio, addr, len, ®ion);
if (ret) {
- MM_ERR("lookup (%p, %ld) failed\n", addr, len);
+ MM_ERR("%s[%p]:lookup (%p, %ld) failed\n",
+ __func__, audio, addr, len);
return 0;
}
if (ref_up)
@@ -961,7 +976,7 @@
buf_node, dir, buf_node->buf.buf_addr,
buf_node->buf.buf_len, buf_node->buf.data_len);
- buf_node->paddr = audpcm_pmem_fixup(
+ buf_node->paddr = audpcm_ion_fixup(
audio, buf_node->buf.buf_addr,
buf_node->buf.buf_len, 1);
if (dir) {
@@ -1125,23 +1140,23 @@
rc = audpp_pause(audio->dec_id, (int) arg);
break;
- case AUDIO_REGISTER_PMEM: {
- struct msm_audio_pmem_info info;
- MM_DBG("AUDIO_REGISTER_PMEM\n");
+ case AUDIO_REGISTER_ION: {
+ struct msm_audio_ion_info info;
+ MM_ERR("AUDIO_REGISTER_ION\n");
if (copy_from_user(&info, (void *) arg, sizeof(info)))
rc = -EFAULT;
else
- rc = audpcm_pmem_add(audio, &info);
+ rc = audpcm_ion_add(audio, &info);
break;
}
- case AUDIO_DEREGISTER_PMEM: {
- struct msm_audio_pmem_info info;
- MM_DBG("AUDIO_DEREGISTER_PMEM\n");
+ case AUDIO_DEREGISTER_ION: {
+ struct msm_audio_ion_info info;
+ MM_ERR("AUDIO_DEREGISTER_ION\n");
if (copy_from_user(&info, (void *) arg, sizeof(info)))
rc = -EFAULT;
else
- rc = audpcm_pmem_remove(audio, &info);
+ rc = audpcm_ion_remove(audio, &info);
break;
}
@@ -1340,15 +1355,16 @@
return rc;
}
-static void audpcm_reset_pmem_region(struct audio *audio)
+static void audpcm_reset_ion_region(struct audio *audio)
{
- struct audpcm_pmem_region *region;
+ struct audpcm_ion_region *region;
struct list_head *ptr, *next;
- list_for_each_safe(ptr, next, &audio->pmem_region_queue) {
- region = list_entry(ptr, struct audpcm_pmem_region, list);
+ list_for_each_safe(ptr, next, &audio->ion_region_queue) {
+ region = list_entry(ptr, struct audpcm_ion_region, list);
list_del(®ion->list);
- put_pmem_file(region->file);
+ ion_unmap_kernel(audio->client, region->handle);
+ ion_free(audio->client, region->handle);
kfree(region);
}
@@ -1365,7 +1381,7 @@
if (audio->rmt_resource_released == 0)
rmt_put_resource(audio);
audio->drv_ops.out_flush(audio);
- audpcm_reset_pmem_region(audio);
+ audpcm_reset_ion_region(audio);
msm_adsp_put(audio->audplay);
audpp_adec_free(audio->dec_id);
@@ -1376,16 +1392,12 @@
audio->event_abort = 1;
wake_up(&audio->event_wait);
audpcm_reset_event_queue(audio);
- MM_DBG("pmem area = 0x%8x\n", (unsigned int)audio->data);
- if (audio->data) {
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- }
mutex_unlock(&audio->lock);
#ifdef CONFIG_DEBUG_FS
if (audio->dentry)
debugfs_remove(audio->dentry);
#endif
+ ion_client_destroy(audio->client);
kfree(audio);
return 0;
}
@@ -1506,7 +1518,13 @@
struct audio *audio = NULL;
int rc, i, dec_attrb, decid;
struct audpcm_event *e_node = NULL;
- unsigned pmem_sz = DMASZ_MAX;
+ unsigned mem_sz = DMASZ_MAX;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
+ int len = 0;
+
#ifdef CONFIG_DEBUG_FS
/* 4 bytes represents decoder number, 1 byte for terminate string */
@@ -1543,44 +1561,57 @@
}
audio->dec_id = decid & MSM_AUD_DECODER_MASK;
+ client = msm_ion_client_create(UINT_MAX, "Audio_PCM_Client");
+ if (IS_ERR_OR_NULL(client)) {
+ pr_err("Unable to create ION client\n");
+ rc = -ENOMEM;
+ goto client_create_error;
+ }
+ audio->client = client;
+
/* Non AIO interface */
if (!(file->f_flags & O_NONBLOCK)) {
- while (pmem_sz >= DMASZ_MIN) {
- MM_DBG("pmemsz = %d\n", pmem_sz);
- audio->phys = allocate_contiguous_ebi_nomap(pmem_sz,
- SZ_4K);
- if (audio->phys) {
- audio->map_v_write = ioremap(
- audio->phys, pmem_sz);
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write\
- buffers\n");
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(
- audio->phys);
- audpp_adec_free(audio->dec_id);
- MM_DBG("audio instance 0x%08x\
- freeing\n", (int)audio);
- kfree(audio);
- goto done;
- }
- audio->data = audio->map_v_write;
- MM_DBG("write buf: phy addr 0x%08x kernel addr\
- 0x%08x\n", audio->phys,\
- (int)audio->data);
- break;
- } else if (pmem_sz == DMASZ_MIN) {
- MM_ERR("could not allocate write buffers\n");
- rc = -ENOMEM;
- audpp_adec_free(audio->dec_id);
- MM_DBG("audio instance 0x%08x freeing\n",\
- (int)audio);
- kfree(audio);
- goto done;
- } else
- pmem_sz >>= 1;
+
+ MM_DBG("memsz = %d\n", mem_sz);
+
+ handle = ion_alloc(client, mem_sz, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
}
- audio->out_dma_sz = pmem_sz;
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client , handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
+
+ audio->out_dma_sz = mem_sz;
}
rc = audmgr_open(&audio->audmgr);
@@ -1631,7 +1662,7 @@
spin_lock_init(&audio->dsp_lock);
init_waitqueue_head(&audio->write_wait);
INIT_LIST_HEAD(&audio->out_queue);
- INIT_LIST_HEAD(&audio->pmem_region_queue);
+ INIT_LIST_HEAD(&audio->ion_region_queue);
INIT_LIST_HEAD(&audio->free_event_queue);
INIT_LIST_HEAD(&audio->event_queue);
init_waitqueue_head(&audio->wait);
@@ -1674,10 +1705,14 @@
done:
return rc;
err:
- if (audio->data) {
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- }
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_flags_error:
+output_buff_get_phys_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
audpp_adec_free(audio->dec_id);
MM_DBG("audio instance 0x%08x freeing\n", (int)audio);
kfree(audio);
diff --git a/arch/arm/mach-msm/qdsp5/audio_pcm_in.c b/arch/arm/mach-msm/qdsp5/audio_pcm_in.c
index 851980d..716dbd2 100644
--- a/arch/arm/mach-msm/qdsp5/audio_pcm_in.c
+++ b/arch/arm/mach-msm/qdsp5/audio_pcm_in.c
@@ -2,7 +2,7 @@
*
* pcm audio input device
*
- * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
+ * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
*
* This code is based in part on arch/arm/mach-msm/qdsp5v2/audio_pcm_in.c,
* Copyright (C) 2008 Google, Inc.
@@ -26,6 +26,7 @@
#include <linux/kthread.h>
#include <linux/wait.h>
#include <linux/dma-mapping.h>
+#include <linux/ion.h>
#include <linux/delay.h>
@@ -114,6 +115,8 @@
* All the coeff should be passed from user space */
int iir_enable;
audpreproc_cmd_cfg_iir_tuning_filter_params iir_cfg;
+ struct ion_client *client;
+ struct ion_handle *output_buff_handle;
};
static int audpcm_in_dsp_enable(struct audio_in *audio, int enable);
@@ -764,9 +767,11 @@
audio->audpre = NULL;
audio->opened = 0;
if (audio->data) {
- free_contiguous_memory((void *)audio->data);
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
audio->data = NULL;
}
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
return 0;
}
@@ -777,6 +782,11 @@
{
struct audio_in *audio = &the_audio_in;
int rc;
+ int len = 0;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
int encid;
mutex_lock(&audio->lock);
@@ -827,23 +837,53 @@
audpcm_in_flush(audio);
- audio->data = allocate_contiguous_memory(DMASZ, MEMTYPE_EBI1,
- SZ_4K, 0);
- if (!audio->data) {
- MM_ERR("could not allocate read buffers\n");
+ client = msm_ion_client_create(UINT_MAX, "Audio_PCM_in_client");
+ if (IS_ERR_OR_NULL(client)) {
+ MM_ERR("Unable to create ION client\n");
rc = -ENOMEM;
- goto evt_error;
- } else {
- audio->phys = memory_pool_node_paddr(audio->data);
- if (!audio->phys) {
- MM_ERR("could not get physical address\n");
- rc = -ENOMEM;
- free_contiguous_memory(audio->data);
- goto evt_error;
- }
- MM_DBG("read buf: phy addr 0x%08x kernel addr 0x%08x\n",
- audio->phys, (int)audio->data);
+ goto client_create_error;
}
+ audio->client = client;
+
+ MM_DBG("allocating mem sz = %d\n", DMASZ);
+ handle = ion_alloc(client, DMASZ, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
+ }
+
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client , handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ rc = -ENOMEM;
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ rc = -ENOMEM;
+ goto output_buff_get_flags_error;
+ }
+
+ audio->data = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->data)) {
+ MM_ERR("could not map read buffers,freeing instance 0x%08x\n",
+ (int)audio);
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ MM_DBG("read buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
file->private_data = audio;
audio->opened = 1;
@@ -851,7 +891,13 @@
done:
mutex_unlock(&audio->lock);
return rc;
-evt_error:
+output_buff_map_error:
+output_buff_get_phys_error:
+output_buff_get_flags_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
msm_adsp_put(audio->audrec);
msm_adsp_put(audio->audpre);
audpreproc_aenc_free(audio->enc_id);
diff --git a/arch/arm/mach-msm/qdsp5/audio_qcelp.c b/arch/arm/mach-msm/qdsp5/audio_qcelp.c
index f436759..dc257cd 100644
--- a/arch/arm/mach-msm/qdsp5/audio_qcelp.c
+++ b/arch/arm/mach-msm/qdsp5/audio_qcelp.c
@@ -34,10 +34,10 @@
#include <linux/debugfs.h>
#include <linux/earlysuspend.h>
#include <linux/list.h>
-#include <linux/android_pmem.h>
#include <linux/slab.h>
#include <linux/msm_audio.h>
#include <linux/memory_alloc.h>
+#include <linux/ion.h>
#include <mach/msm_adsp.h>
#include <mach/iommu.h>
@@ -170,6 +170,9 @@
int eq_needs_commit;
audpp_cmd_cfg_object_params_eqalizer eq;
audpp_cmd_cfg_object_params_volume vol_pan;
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+ struct ion_handle *output_buff_handle;
};
static int auddec_dsp_config(struct audio *audio, int enable);
@@ -767,6 +770,10 @@
uint16_t enable_mask;
int enable;
int prev_state;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ int len = 0;
MM_DBG("cmd = %d\n", cmd);
@@ -956,24 +963,53 @@
if ((config.pcm_feedback) && (!audio->read_data)) {
MM_DBG("allocate PCM buf %d\n",
config.buffer_count * config.buffer_size);
- audio->read_phys =
- allocate_contiguous_ebi_nomap(
- config.buffer_size *
- config.buffer_count,
- SZ_4K);
- if (!audio->read_phys) {
+ handle = ion_alloc(audio->client,
+ (config.buffer_size *
+ config.buffer_count),
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to alloc I/P buffs\n");
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
break;
}
- audio->map_v_read = ioremap(
- audio->read_phys,
- config.buffer_size *
- config.buffer_count);
+
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(audio->client ,
+ handle, &addr, &len);
+ if (rc) {
+ MM_ERR("Invalid phy: %x sz: %x\n",
+ (unsigned int) addr,
+ (unsigned int) len);
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ } else {
+ MM_INFO("Got valid phy: %x sz: %x\n",
+ (unsigned int) audio->read_phys,
+ (unsigned int) len);
+ }
+ audio->read_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(audio->client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ }
+ audio->map_v_read = ion_map_kernel(
+ audio->client,
+ handle, ionflag);
if (IS_ERR(audio->map_v_read)) {
MM_ERR("failed to map read buf\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
- free_contiguous_memory_by_paddr(
- audio->read_phys);
} else {
uint8_t index;
uint32_t offset = 0;
@@ -1019,7 +1055,8 @@
}
/* Only useful in tunnel-mode */
-static int audqcelp_fsync(struct file *file, loff_t a, loff_t b, int datasync)
+static int audqcelp_fsync(struct file *file, loff_t a, loff_t b,
+ int datasync)
{
struct audio *audio = file->private_data;
int rc = 0;
@@ -1287,12 +1324,13 @@
audio->event_abort = 1;
wake_up(&audio->event_wait);
audqcelp_reset_event_queue(audio);
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- if (audio->read_data) {
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->read_phys);
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
+ if (audio->input_buff_handle != NULL) {
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
}
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
#ifdef CONFIG_DEBUG_FS
if (audio->dentry)
@@ -1431,6 +1469,12 @@
struct audio *audio = NULL;
int rc, dec_attrb, decid, i;
struct audqcelp_event *e_node = NULL;
+ unsigned mem_sz = DMASZ;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
+ int len = 0;
#ifdef CONFIG_DEBUG_FS
/* 4 bytes represents decoder number, 1 byte for terminate string */
char name[sizeof "msm_qcelp_" + 5];
@@ -1471,29 +1515,50 @@
}
audio->dec_id = decid & MSM_AUD_DECODER_MASK;
- audio->phys = allocate_contiguous_ebi_nomap(DMASZ, SZ_4K);
- if (!audio->phys) {
- MM_ERR("could not allocate write buffers, freeing instance \
- 0x%08x\n", (int)audio);
+ client = msm_ion_client_create(UINT_MAX, "Audio_QCELP_Client");
+ if (IS_ERR_OR_NULL(client)) {
+ pr_err("Unable to create ION client\n");
rc = -ENOMEM;
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- } else {
- audio->map_v_write = ioremap(audio->phys, DMASZ);
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write buffers, freeing \
- instance 0x%08x\n", (int)audio);
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(audio->phys);
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- }
- audio->data = audio->map_v_write;
- MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
- audio->phys, (int)audio->data);
+ goto client_create_error;
}
+ audio->client = client;
+
+ handle = ion_alloc(client, mem_sz, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
+ }
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client, handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK) {
rc = audmgr_open(&audio->audmgr);
@@ -1524,6 +1589,8 @@
goto err;
}
+ audio->input_buff_handle = NULL;
+
/* Initialize all locks of audio instance */
mutex_init(&audio->lock);
mutex_init(&audio->write_lock);
@@ -1580,8 +1647,14 @@
done:
return rc;
err:
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_phys_error:
+output_buff_get_flags_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
audpp_adec_free(audio->dec_id);
kfree(audio);
return rc;
diff --git a/arch/arm/mach-msm/qdsp5/audio_qcelp_in.c b/arch/arm/mach-msm/qdsp5/audio_qcelp_in.c
index 92036e5..99a169d 100644
--- a/arch/arm/mach-msm/qdsp5/audio_qcelp_in.c
+++ b/arch/arm/mach-msm/qdsp5/audio_qcelp_in.c
@@ -33,6 +33,7 @@
#include <linux/memory_alloc.h>
+#include <linux/ion.h>
#include <asm/atomic.h>
#include <asm/ioctls.h>
@@ -151,6 +152,9 @@
int enabled;
int running;
int stopped; /* set when stopped, cleared on flush */
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+ struct ion_handle *output_buff_handle;
};
struct audio_frame {
@@ -1004,7 +1008,8 @@
spin_unlock_irqrestore(&audio->dsp_lock, flags);
}
-static int audqcelp_in_fsync(struct file *file, loff_t a, loff_t b, int datasync)
+static int audqcelp_in_fsync(struct file *file, loff_t a, loff_t b,
+ int datasync)
{
struct audio_qcelp_in *audio = file->private_data;
@@ -1192,16 +1197,17 @@
if ((audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) && \
(audio->out_data)) {
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->out_phys);
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
audio->out_data = NULL;
}
if (audio->data) {
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->phys);
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
audio->data = NULL;
}
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
return 0;
}
@@ -1214,6 +1220,11 @@
int rc;
int encid;
int dma_size = 0;
+ int len = 0;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
mutex_lock(&audio->lock);
if (audio->opened) {
@@ -1293,52 +1304,101 @@
audqcelp_in_flush(audio);
audqcelp_out_flush(audio);
- audio->phys = allocate_contiguous_ebi_nomap(dma_size, SZ_4K);
- if (!audio->phys) {
- MM_ERR("could not allocate physical read buffers\n");
+ client = msm_ion_client_create(UINT_MAX, "Audio_QCELP_in_client");
+ if (IS_ERR_OR_NULL(client)) {
+ MM_ERR("Unable to create ION client\n");
rc = -ENOMEM;
- goto evt_error;
- } else {
- audio->map_v_read = ioremap(audio->phys, dma_size);
- if (IS_ERR(audio->map_v_read)) {
- MM_ERR("could not map physical address\n");
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(audio->phys);
- goto evt_error;
- }
- audio->data = audio->map_v_read;
- MM_DBG("read buf: phy addr 0x%08x kernel addr 0x%08x\n",
- audio->phys, (int)audio->data);
+ goto client_create_error;
}
+ audio->client = client;
+
+ MM_DBG("allocating mem sz = %d\n", dma_size);
+ handle = ion_alloc(client, dma_size, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
+ }
+
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client , handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ rc = -ENOMEM;
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ rc = -ENOMEM;
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_read = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_read)) {
+ MM_ERR("could not map read buffers,freeing instance 0x%08x\n",
+ (int)audio);
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_read;
+ MM_DBG("read buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
audio->out_data = NULL;
if (audio->mode == MSM_AUD_ENC_MODE_NONTUNNEL) {
- audio->out_phys = allocate_contiguous_ebi_nomap(BUFFER_SIZE,
- SZ_4K);
- if (!audio->out_phys) {
- MM_ERR("could not allocate physical write buffers\n");
+ MM_DBG("allocating BUFFER_SIZE %d\n", BUFFER_SIZE);
+ handle = ion_alloc(client, BUFFER_SIZE,
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate I/P buffers\n");
rc = -ENOMEM;
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->phys);
- goto evt_error;
- } else {
- audio->map_v_write = ioremap(
- audio->out_phys, BUFFER_SIZE);
-
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write phys address\n");
- rc = -ENOMEM;
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->phys);
- free_contiguous_memory_by_paddr(\
- audio->out_phys);
- goto evt_error;
- }
- audio->out_data = audio->map_v_write;
- MM_DBG("wr buf: phy addr 0x%08x kernel addr 0x%08x\n",
- audio->out_phys, (int)audio->out_data);
+ goto input_buff_alloc_error;
}
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(client , handle, &addr, &len);
+ if (rc) {
+ MM_ERR("I/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ rc = -ENOMEM;
+ goto input_buff_get_phys_error;
+ } else {
+ MM_INFO("Got valid phy: %x sz: %x\n",
+ (unsigned int) addr,
+ (unsigned int) len);
+ }
+ audio->out_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ rc = -ENOMEM;
+ goto input_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client,
+ handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto input_buff_map_error;
+ }
+ audio->out_data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ (unsigned int)addr,
+ (unsigned int)audio->out_data);
+
/* Initialize buffer */
audio->out[0].data = audio->out_data + 0;
audio->out[0].addr = audio->out_phys + 0;
@@ -1360,7 +1420,19 @@
done:
mutex_unlock(&audio->lock);
return rc;
-evt_error:
+input_buff_map_error:
+input_buff_get_flags_error:
+input_buff_get_phys_error:
+ ion_free(client, audio->input_buff_handle);
+input_buff_alloc_error:
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_phys_error:
+output_buff_get_flags_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
msm_adsp_put(audio->audrec);
if (audio->mode == MSM_AUD_ENC_MODE_TUNNEL)
msm_adsp_put(audio->audpre);
diff --git a/arch/arm/mach-msm/qdsp5/audio_wma.c b/arch/arm/mach-msm/qdsp5/audio_wma.c
index 162a6f1..e28e704 100644
--- a/arch/arm/mach-msm/qdsp5/audio_wma.c
+++ b/arch/arm/mach-msm/qdsp5/audio_wma.c
@@ -37,11 +37,11 @@
#include <linux/delay.h>
#include <linux/list.h>
#include <linux/earlysuspend.h>
-#include <linux/android_pmem.h>
#include <linux/slab.h>
#include <linux/msm_audio.h>
#include <linux/msm_audio_wma.h>
#include <linux/memory_alloc.h>
+#include <linux/ion.h>
#include <mach/msm_adsp.h>
#include <mach/iommu.h>
@@ -187,6 +187,9 @@
int eq_needs_commit;
audpp_cmd_cfg_object_params_eqalizer eq;
audpp_cmd_cfg_object_params_volume vol_pan;
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+ struct ion_handle *output_buff_handle;
};
static int auddec_dsp_config(struct audio *audio, int enable);
@@ -815,6 +818,10 @@
uint16_t enable_mask;
int enable;
int prev_state;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ int len = 0;
MM_DBG("cmd = %d\n", cmd);
@@ -1034,24 +1041,54 @@
MM_DBG("allocate PCM buffer %d\n",
config.buffer_count *
config.buffer_size);
- audio->read_phys =
- allocate_contiguous_ebi_nomap(
- config.buffer_size *
- config.buffer_count,
- SZ_4K);
- if (!audio->read_phys) {
+ handle = ion_alloc(audio->client,
+ (config.buffer_size *
+ config.buffer_count),
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to alloc I/P buffs\n");
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
break;
}
- audio->map_v_read = ioremap(
- audio->read_phys,
- config.buffer_size *
- config.buffer_count);
+
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(audio->client ,
+ handle, &addr, &len);
+ if (rc) {
+ MM_ERR("Invalid phy: %x sz: %x\n",
+ (unsigned int) addr,
+ (unsigned int) len);
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ } else {
+ MM_INFO("Got valid phy: %x sz: %x\n",
+ (unsigned int) audio->read_phys,
+ (unsigned int) len);
+ }
+ audio->read_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(audio->client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ }
+
+ audio->map_v_read = ion_map_kernel(
+ audio->client,
+ handle, ionflag);
if (IS_ERR(audio->map_v_read)) {
MM_ERR("map of read buf failed\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
- free_contiguous_memory_by_paddr(
- audio->read_phys);
} else {
uint8_t index;
uint32_t offset = 0;
@@ -1098,7 +1135,8 @@
}
/* Only useful in tunnel-mode */
-static int audio_fsync(struct file *file, loff_t a, loff_t b, int datasync)
+static int audio_fsync(struct file *file, loff_t a, loff_t b,
+ int datasync)
{
struct audio *audio = file->private_data;
struct buffer *frame;
@@ -1433,12 +1471,13 @@
audio->event_abort = 1;
wake_up(&audio->event_wait);
audwma_reset_event_queue(audio);
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- if (audio->read_data) {
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->read_phys);
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
+ if (audio->input_buff_handle != NULL) {
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
}
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
#ifdef CONFIG_DEBUG_FS
if (audio->dentry)
@@ -1580,8 +1619,13 @@
{
struct audio *audio = NULL;
int rc, dec_attrb, decid, i;
- unsigned pmem_sz = DMASZ_MAX;
+ unsigned mem_sz = DMASZ_MAX;
struct audwma_event *e_node = NULL;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
+ int len = 0;
#ifdef CONFIG_DEBUG_FS
/* 4 bytes represents decoder number, 1 byte for terminate string */
char name[sizeof "msm_wma_" + 5];
@@ -1624,36 +1668,52 @@
}
audio->dec_id = decid & MSM_AUD_DECODER_MASK;
- while (pmem_sz >= DMASZ_MIN) {
- MM_DBG("pmemsz = %d\n", pmem_sz);
- audio->phys = allocate_contiguous_ebi_nomap(pmem_sz, SZ_4K);
- if (audio->phys) {
- audio->map_v_write = ioremap(audio->phys, pmem_sz);
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write buffers, \
- freeing instance 0x%08x\n",
- (int)audio);
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(audio->phys);
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- }
- audio->data = audio->map_v_write;
- MM_DBG("write buf: phy addr 0x%08x kernel addr \
- 0x%08x\n", audio->phys, (int)audio->data);
- break;
- } else if (pmem_sz == DMASZ_MIN) {
- MM_ERR("could not allocate write buffers, freeing \
- instance 0x%08x\n", (int)audio);
- rc = -ENOMEM;
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- } else
- pmem_sz >>= 1;
+ client = msm_ion_client_create(UINT_MAX, "Audio_WMA_Client");
+ if (IS_ERR_OR_NULL(client)) {
+ pr_err("Unable to create ION client\n");
+ rc = -ENOMEM;
+ goto client_create_error;
}
- audio->out_dma_sz = pmem_sz;
+ audio->client = client;
+
+ handle = ion_alloc(client, mem_sz, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
+ }
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client, handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
+
+ audio->out_dma_sz = mem_sz;
if (audio->pcm_feedback == TUNNEL_MODE_PLAYBACK) {
rc = audmgr_open(&audio->audmgr);
@@ -1684,6 +1744,7 @@
goto err;
}
+ audio->input_buff_handle = NULL;
mutex_init(&audio->lock);
mutex_init(&audio->write_lock);
mutex_init(&audio->read_lock);
@@ -1748,8 +1809,14 @@
done:
return rc;
err:
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_phys_error:
+output_buff_get_flags_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
audpp_adec_free(audio->dec_id);
kfree(audio);
return rc;
diff --git a/arch/arm/mach-msm/qdsp5/audio_wmapro.c b/arch/arm/mach-msm/qdsp5/audio_wmapro.c
index 641b1c7..87afcf0 100644
--- a/arch/arm/mach-msm/qdsp5/audio_wmapro.c
+++ b/arch/arm/mach-msm/qdsp5/audio_wmapro.c
@@ -36,11 +36,11 @@
#include <linux/delay.h>
#include <linux/list.h>
#include <linux/earlysuspend.h>
-#include <linux/android_pmem.h>
#include <linux/slab.h>
#include <linux/msm_audio.h>
#include <linux/memory_alloc.h>
#include <linux/msm_audio_wmapro.h>
+#include <linux/ion.h>
#include <mach/msm_adsp.h>
#include <mach/qdsp5/qdsp5audppcmdi.h>
@@ -186,6 +186,9 @@
int eq_needs_commit;
audpp_cmd_cfg_object_params_eqalizer eq;
audpp_cmd_cfg_object_params_volume vol_pan;
+ struct ion_client *client;
+ struct ion_handle *input_buff_handle;
+ struct ion_handle *output_buff_handle;
};
static int auddec_dsp_config(struct audio *audio, int enable);
@@ -803,6 +806,10 @@
uint16_t enable_mask;
int enable;
int prev_state;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ int len = 0;
MM_DBG("cmd = %d\n", cmd);
@@ -1031,25 +1038,54 @@
MM_DBG("allocate PCM buffer %d\n",
config.buffer_count *
config.buffer_size);
- audio->read_phys =
- allocate_contiguous_ebi_nomap(
- config.buffer_size *
- config.buffer_count,
- SZ_4K);
- if (!audio->read_phys) {
+ handle = ion_alloc(audio->client,
+ (config.buffer_size *
+ config.buffer_count),
+ SZ_4K, ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to alloc I/P buffs\n");
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
break;
}
- audio->map_v_read = ioremap(
- audio->read_phys,
- config.buffer_size *
- config.buffer_count);
+ audio->input_buff_handle = handle;
+
+ rc = ion_phys(audio->client ,
+ handle, &addr, &len);
+ if (rc) {
+ MM_ERR("Invalid phy: %x sz: %x\n",
+ (unsigned int) addr,
+ (unsigned int) len);
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ } else {
+ MM_INFO("Got valid phy: %x sz: %x\n",
+ (unsigned int) audio->read_phys,
+ (unsigned int) len);
+ }
+ audio->read_phys = (int32_t)addr;
+
+ rc = ion_handle_get_flags(audio->client,
+ handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
+ rc = -ENOMEM;
+ break;
+ }
+
+ audio->map_v_read = ion_map_kernel(
+ audio->client,
+ handle, ionflag);
if (IS_ERR(audio->map_v_read)) {
MM_ERR("map of read buf failed\n");
+ ion_free(audio->client, handle);
+ audio->input_buff_handle = NULL;
rc = -ENOMEM;
- free_contiguous_memory_by_paddr(
- audio->read_phys);
} else {
uint8_t index;
uint32_t offset = 0;
@@ -1096,7 +1132,8 @@
}
/* Only useful in tunnel-mode */
-static int audio_fsync(struct file *file, loff_t a, loff_t b, int datasync)
+static int audio_fsync(struct file *file, loff_t a, loff_t b,
+ int datasync)
{
struct audio *audio = file->private_data;
struct buffer *frame;
@@ -1429,12 +1466,13 @@
audio->event_abort = 1;
wake_up(&audio->event_wait);
audwmapro_reset_event_queue(audio);
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
- if (audio->read_data) {
- iounmap(audio->map_v_read);
- free_contiguous_memory_by_paddr(audio->read_phys);
+ ion_unmap_kernel(audio->client, audio->output_buff_handle);
+ ion_free(audio->client, audio->output_buff_handle);
+ if (audio->input_buff_handle != NULL) {
+ ion_unmap_kernel(audio->client, audio->input_buff_handle);
+ ion_free(audio->client, audio->input_buff_handle);
}
+ ion_client_destroy(audio->client);
mutex_unlock(&audio->lock);
#ifdef CONFIG_DEBUG_FS
if (audio->dentry)
@@ -1576,8 +1614,13 @@
{
struct audio *audio = NULL;
int rc, dec_attrb, decid, i;
- unsigned pmem_sz = DMASZ_MAX;
+ unsigned mem_sz = DMASZ_MAX;
struct audwmapro_event *e_node = NULL;
+ unsigned long ionflag = 0;
+ ion_phys_addr_t addr = 0;
+ struct ion_handle *handle = NULL;
+ struct ion_client *client = NULL;
+ int len = 0;
#ifdef CONFIG_DEBUG_FS
/* 4 bytes represents decoder number, 1 byte for terminate string */
char name[sizeof "msm_wmapro_" + 5];
@@ -1620,36 +1663,52 @@
}
audio->dec_id = decid & MSM_AUD_DECODER_MASK;
- while (pmem_sz >= DMASZ_MIN) {
- MM_DBG("pmemsz = %d\n", pmem_sz);
- audio->phys = allocate_contiguous_ebi_nomap(pmem_sz, SZ_4K);
- if (audio->phys) {
- audio->map_v_write = ioremap(audio->phys, pmem_sz);
- if (IS_ERR(audio->map_v_write)) {
- MM_ERR("could not map write buffers, \
- freeing instance 0x%08x\n",
- (int)audio);
- rc = -ENOMEM;
- free_contiguous_memory_by_paddr(audio->phys);
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- }
- audio->data = audio->map_v_write;
- MM_DBG("write buf: phy addr 0x%08x kernel addr \
- 0x%08x\n", audio->phys, (int)audio->data);
- break;
- } else if (pmem_sz == DMASZ_MIN) {
- MM_ERR("could not allocate write buffers, freeing \
- instance 0x%08x\n", (int)audio);
- rc = -ENOMEM;
- audpp_adec_free(audio->dec_id);
- kfree(audio);
- goto done;
- } else
- pmem_sz >>= 1;
+ client = msm_ion_client_create(UINT_MAX, "Audio_WMA_PRO_Client");
+ if (IS_ERR_OR_NULL(client)) {
+ pr_err("Unable to create ION client\n");
+ rc = -ENOMEM;
+ goto client_create_error;
}
- audio->out_dma_sz = pmem_sz;
+ audio->client = client;
+
+ handle = ion_alloc(client, mem_sz, SZ_4K,
+ ION_HEAP(ION_AUDIO_HEAP_ID));
+ if (IS_ERR_OR_NULL(handle)) {
+ MM_ERR("Unable to create allocate O/P buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_alloc_error;
+ }
+ audio->output_buff_handle = handle;
+
+ rc = ion_phys(client, handle, &addr, &len);
+ if (rc) {
+ MM_ERR("O/P buffers:Invalid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ goto output_buff_get_phys_error;
+ } else {
+ MM_INFO("O/P buffers:valid phy: %x sz: %x\n",
+ (unsigned int) addr, (unsigned int) len);
+ }
+ audio->phys = (int32_t)addr;
+
+
+ rc = ion_handle_get_flags(client, handle, &ionflag);
+ if (rc) {
+ MM_ERR("could not get flags for the handle\n");
+ goto output_buff_get_flags_error;
+ }
+
+ audio->map_v_write = ion_map_kernel(client, handle, ionflag);
+ if (IS_ERR(audio->map_v_write)) {
+ MM_ERR("could not map write buffers\n");
+ rc = -ENOMEM;
+ goto output_buff_map_error;
+ }
+ audio->data = audio->map_v_write;
+ MM_DBG("write buf: phy addr 0x%08x kernel addr 0x%08x\n",
+ audio->phys, (int)audio->data);
+
+ audio->out_dma_sz = mem_sz;
rc = audmgr_open(&audio->audmgr);
if (rc) {
@@ -1677,6 +1736,7 @@
goto err;
}
+ audio->input_buff_handle = NULL;
mutex_init(&audio->lock);
mutex_init(&audio->write_lock);
mutex_init(&audio->read_lock);
@@ -1735,8 +1795,14 @@
done:
return rc;
err:
- iounmap(audio->map_v_write);
- free_contiguous_memory_by_paddr(audio->phys);
+ ion_unmap_kernel(client, audio->output_buff_handle);
+output_buff_map_error:
+output_buff_get_phys_error:
+output_buff_get_flags_error:
+ ion_free(client, audio->output_buff_handle);
+output_buff_alloc_error:
+ ion_client_destroy(client);
+client_create_error:
audpp_adec_free(audio->dec_id);
kfree(audio);
return rc;