From: Srinivas Kandagatla
This patch adds support to memory map and unmap regions commands in
q6asm module.
Signed-off-by: Srinivas Kandagatla
---
sound/soc/qcom/qdsp6/q6asm.c | 312 +++
sound/soc/qcom/qdsp6/q6asm.h | 5 +
2 files changed, 317 insertions(+)
diff --git a/sound/soc/qcom/qdsp6/q6asm.c b/sound/soc/qcom/qdsp6/q6asm.c
index 768d9b446da9..412275edb15c 100644
--- a/sound/soc/qcom/qdsp6/q6asm.c
+++ b/sound/soc/qcom/qdsp6/q6asm.c
@@ -17,10 +17,47 @@
#include "q6dsp-errno.h"
#include "q6dsp-common.h"
+#define ASM_CMD_SHARED_MEM_MAP_REGIONS 0x00010D92
+#define ASM_CMDRSP_SHARED_MEM_MAP_REGIONS 0x00010D93
+#define ASM_CMD_SHARED_MEM_UNMAP_REGIONS 0x00010D94
+
#define ASM_SYNC_IO_MODE 0x0001
#define ASM_ASYNC_IO_MODE 0x0002
#define ASM_TUN_READ_IO_MODE 0x0004 /* tunnel read write mode */
#define ASM_TUN_WRITE_IO_MODE 0x0008 /* tunnel read write mode */
+#define ASM_SHIFT_GAPLESS_MODE_FLAG31
+#define ADSP_MEMORY_MAP_SHMEM8_4K_POOL 3
+
+struct avs_cmd_shared_mem_map_regions {
+ struct apr_hdr hdr;
+ u16 mem_pool_id;
+ u16 num_regions;
+ u32 property_flag;
+} __packed;
+
+struct avs_shared_map_region_payload {
+ u32 shm_addr_lsw;
+ u32 shm_addr_msw;
+ u32 mem_size_bytes;
+} __packed;
+
+struct avs_cmd_shared_mem_unmap_regions {
+ struct apr_hdr hdr;
+ u32 mem_map_handle;
+} __packed;
+
+struct audio_buffer {
+ phys_addr_t phys;
+ uint32_t used;
+ uint32_t size; /* size of buffer */
+};
+
+struct audio_port_data {
+ struct audio_buffer *buf;
+ uint32_t num_periods;
+ uint32_t dsp_buf;
+ uint32_t mem_map_handle;
+};
struct audio_client {
int session;
@@ -30,6 +67,8 @@ struct audio_client {
uint32_t io_mode;
struct apr_device *adev;
struct mutex lock;
+ /* idx:1 out port, 0: in port */
+ struct audio_port_data port[2];
wait_queue_head_t cmd_wait;
int perf_mode;
int stream_id;
@@ -63,6 +102,237 @@ static bool q6asm_is_valid_audio_client(struct
audio_client *ac)
return false;
}
+static inline void q6asm_add_hdr(struct audio_client *ac, struct apr_hdr *hdr,
+uint32_t pkt_size, bool cmd_flg,
+uint32_t stream_id)
+{
+ hdr->hdr_field = APR_SEQ_CMD_HDR_FIELD;
+ hdr->src_svc = ac->adev->svc_id;
+ hdr->src_domain = APR_DOMAIN_APPS;
+ hdr->dest_svc = APR_SVC_ASM;
+ hdr->dest_domain = APR_DOMAIN_ADSP;
+ hdr->src_port = ((ac->session << 8) & 0xFF00) | (stream_id);
+ hdr->dest_port = ((ac->session << 8) & 0xFF00) | (stream_id);
+ hdr->pkt_size = pkt_size;
+ if (cmd_flg)
+ hdr->token = ac->session;
+}
+
+static int q6asm_apr_send_session_pkt(struct q6asm *a, struct audio_client *ac,
+ void *data)
+{
+ int rc;
+
+ mutex_lock(&a->session_lock);
+ a->mem_state = 1;
+ rc = apr_send_pkt(a->adev, data);
+ if (rc < 0)
+ goto err;
+
+ rc = wait_event_timeout(a->mem_wait, (a->mem_state <= 0), 5 * HZ);
+ if (!rc) {
+ dev_err(a->dev, "CMD timeout \n");
+ rc = -ETIMEDOUT;
+ } else if (a->mem_state < 0) {
+ rc = q6dsp_errno(a->mem_state);
+ }
+
+err:
+ mutex_unlock(&a->session_lock);
+ return rc;
+}
+
+static int __q6asm_memory_unmap(struct audio_client *ac,
+ phys_addr_t buf_add, int dir)
+{
+ struct avs_cmd_shared_mem_unmap_regions mem_unmap;
+ struct q6asm *a = dev_get_drvdata(ac->dev);
+ int rc;
+
+ if (ac->port[dir].mem_map_handle == 0) {
+ dev_err(ac->dev, "invalid mem handle\n");
+ return -EINVAL;
+ }
+
+ mem_unmap.hdr.hdr_field = APR_SEQ_CMD_HDR_FIELD;
+ mem_unmap.hdr.src_port = 0;
+ mem_unmap.hdr.dest_port = 0;
+ mem_unmap.hdr.pkt_size = sizeof(mem_unmap);
+ mem_unmap.hdr.token = ((ac->session << 8) | dir);
+
+ mem_unmap.hdr.opcode = ASM_CMD_SHARED_MEM_UNMAP_REGIONS;
+ mem_unmap.mem_map_handle = ac->port[dir].mem_map_handle;
+
+ rc = q6asm_apr_send_session_pkt(a, ac, &mem_unmap);
+ if (rc < 0)
+ return rc;
+
+ ac->port[dir].mem_map_handle = 0;
+
+ return 0;
+}
+
+/**
+ * q6asm_unmap_memory_regions() - unmap memory regions in the dsp.
+ *
+ * @dir: direction of audio stream
+ * @ac: audio client instanace
+ *
+ * Return: Will be an negative value on failure or zero on success
+ */
+int q6asm_unmap_memory_regions(unsigned int dir, struct audio_client *ac)
+{
+ struct audio_port_data *port;
+ int cnt = 0;
+ int rc = 0;
+
+ mutex_lock(&ac->lock);
+ port = &ac->port[dir];
+ if (!port->buf) {
+ rc = -EINVAL;
+