From 60cc03517fa5c6bb1b60344c0968cd047f85dc6a Mon Sep 17 00:00:00 2001 From: Vignesh Kulothungan Date: Mon, 29 Jan 2018 16:21:22 -0800 Subject: [PATCH] ASoC: dsp: Update ADM driver to support Instance ID Add support to set and get ADM module params with Instance ID support. Maintain support for non Instance ID set and get param structures as well. Use common pack and set param functions to set and get parameters to DSP instead of handling them at an individual module level. CRs-Fixed: 2151551 Change-Id: I5ef920448dd827d8a315e248087997f703061263 Signed-off-by: Vignesh Kulothungan --- asoc/msm-pcm-routing-v2.c | 63 +- asoc/msm-qti-pp-config.c | 114 +- dsp/q6adm.c | 2407 +++++++++++++----------------------- include/dsp/apr_audio-v2.h | 293 ++--- include/dsp/q6adm-v2.h | 21 + 5 files changed, 1088 insertions(+), 1810 deletions(-) diff --git a/asoc/msm-pcm-routing-v2.c b/asoc/msm-pcm-routing-v2.c index 2b6a69f0bb29..5e825506e74c 100644 --- a/asoc/msm-pcm-routing-v2.c +++ b/asoc/msm-pcm-routing-v2.c @@ -11517,10 +11517,11 @@ static int msm_routing_put_module_cfg_control(struct snd_kcontrol *kcontrol, int ret = 0; unsigned long copp; struct msm_pcm_routing_bdai_data *bedai; - char *param_data = NULL; - uint32_t *update_param_data = NULL; - uint32_t param_size = sizeof(uint32_t) + - sizeof(struct adm_param_data_v5); + u8 *packed_params = NULL; + struct param_hdr_v3 param_hdr; + u32 packed_param_size = (sizeof(struct param_hdr_v3) + + sizeof(uint32_t)); + int dir = ucontrol->value.integer.value[0] ? SESSION_TYPE_TX : SESSION_TYPE_RX; int app_type = ucontrol->value.integer.value[1]; @@ -11535,15 +11536,17 @@ static int msm_routing_put_module_cfg_control(struct snd_kcontrol *kcontrol, __func__, app_type, module_id, instance_id, param_id, param_value); - param_data = kzalloc(param_size, GFP_KERNEL); - if (!param_data) + packed_params = kzalloc(packed_param_size, GFP_KERNEL); + if (!packed_params) return -ENOMEM; - update_param_data = (uint32_t *)param_data; - *update_param_data++ = module_id; - *update_param_data++ = param_id; - *update_param_data++ = sizeof(uint32_t); - *update_param_data++ = param_value; + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = module_id; + param_hdr.instance_id = instance_id; + param_hdr.param_id = param_id; + param_hdr.param_size = sizeof(uint32_t); + + packed_param_size = 0; mutex_lock(&routing_lock); for (be_id = 0; be_id < MSM_BACKEND_DAI_MAX; be_id++) { @@ -11571,10 +11574,20 @@ static int msm_routing_put_module_cfg_control(struct snd_kcontrol *kcontrol, if (!test_bit(copp_idx, &copp)) continue; - ret = adm_send_params_v5(bedai->port_id, - copp_idx, - param_data, - param_size); + ret = q6common_pack_pp_params(packed_params, + ¶m_hdr, + (u8 *) ¶m_value, + &packed_param_size); + if (ret) { + pr_err("%s: Failed to pack params, error %d\n", + __func__, ret); + goto done; + } + + ret = adm_set_pp_params(bedai->port_id, + copp_idx, NULL, + packed_params, + packed_param_size); if (ret) { pr_err("%s: Setting param failed with err=%d\n", __func__, ret); @@ -11586,7 +11599,7 @@ static int msm_routing_put_module_cfg_control(struct snd_kcontrol *kcontrol, } done: mutex_unlock(&routing_lock); - kfree(param_data); + kfree(packed_params); return ret; } @@ -11662,22 +11675,24 @@ int msm_routing_get_rms_value_control(struct snd_kcontrol *kcontrol, int be_idx = 0; char *param_value; int *update_param_value; - uint32_t param_length = sizeof(uint32_t); - uint32_t param_payload_len = RMS_PAYLOAD_LEN * sizeof(uint32_t); + uint32_t param_size = (RMS_PAYLOAD_LEN + 1) * sizeof(uint32_t); + struct param_hdr_v3 param_hdr; - param_value = kzalloc(param_length + param_payload_len, GFP_KERNEL); + param_value = kzalloc(param_size, GFP_KERNEL); if (!param_value) return -ENOMEM; + memset(¶m_hdr, 0, sizeof(param_hdr)); for (be_idx = 0; be_idx < MSM_BACKEND_DAI_MAX; be_idx++) if (msm_bedais[be_idx].port_id == SLIMBUS_0_TX) break; if ((be_idx < MSM_BACKEND_DAI_MAX) && msm_bedais[be_idx].active) { - rc = adm_get_params(SLIMBUS_0_TX, 0, - RMS_MODULEID_APPI_PASSTHRU, - RMS_PARAM_FIRST_SAMPLE, - param_length + param_payload_len, - param_value); + param_hdr.module_id = RMS_MODULEID_APPI_PASSTHRU; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = RMS_PARAM_FIRST_SAMPLE; + param_hdr.param_size = param_size; + rc = adm_get_pp_params(SLIMBUS_0_TX, 0, ADM_CLIENT_ID_DEFAULT, + NULL, ¶m_hdr, (u8 *) param_value); if (rc) { pr_err("%s: get parameters failed:%d\n", __func__, rc); kfree(param_value); diff --git a/asoc/msm-qti-pp-config.c b/asoc/msm-qti-pp-config.c index 00a29d71a55b..f210745fa69d 100644 --- a/asoc/msm-qti-pp-config.c +++ b/asoc/msm-qti-pp-config.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. +/* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -21,6 +21,7 @@ #include #include #include +#include #include "msm-qti-pp-config.h" #include "msm-pcm-routing-v2.h" @@ -263,6 +264,11 @@ int msm_qti_pp_send_stereo_to_custom_stereo_cmd(int port_id, int copp_idx, update_params_value32 = (int *)params_value; if (avail_length < 2 * sizeof(uint32_t)) goto skip_send_cmd; + + /* + * This module is internal to ADSP and cannot be configured with + * an instance id + */ *update_params_value32++ = MTMX_MODULE_ID_DEFAULT_CHMIXER; *update_params_value32++ = DEFAULT_CHMIXER_PARAM_ID_COEFF; avail_length = avail_length - (2 * sizeof(uint32_t)); @@ -329,14 +335,13 @@ static int msm_qti_pp_get_rms_value_control(struct snd_kcontrol *kcontrol, int be_idx = 0, copp_idx; char *param_value; int *update_param_value; - uint32_t param_length = sizeof(uint32_t); - uint32_t param_payload_len = RMS_PAYLOAD_LEN * sizeof(uint32_t); + uint32_t param_size = (RMS_PAYLOAD_LEN + 1) * sizeof(uint32_t); struct msm_pcm_routing_bdai_data msm_bedai; + struct param_hdr_v3 param_hdr; - param_value = kzalloc(param_length + param_payload_len, GFP_KERNEL); + param_value = kzalloc(param_size, GFP_KERNEL); if (!param_value) return -ENOMEM; - msm_pcm_routing_acquire_lock(); for (be_idx = 0; be_idx < MSM_BACKEND_DAI_MAX; be_idx++) { msm_pcm_routing_get_bedai_info(be_idx, &msm_bedai); @@ -356,11 +361,13 @@ static int msm_qti_pp_get_rms_value_control(struct snd_kcontrol *kcontrol, rc = -EINVAL; goto get_rms_value_err; } - rc = adm_get_params(SLIMBUS_0_TX, copp_idx, - RMS_MODULEID_APPI_PASSTHRU, - RMS_PARAM_FIRST_SAMPLE, - param_length + param_payload_len, - param_value); + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = RMS_MODULEID_APPI_PASSTHRU; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = RMS_PARAM_FIRST_SAMPLE; + param_hdr.param_size = param_size; + rc = adm_get_pp_params(SLIMBUS_0_TX, copp_idx, ADM_CLIENT_ID_DEFAULT, + NULL, ¶m_hdr, param_value); if (rc) { pr_err("%s: get parameters failed rc=%d\n", __func__, rc); rc = -EINVAL; @@ -692,64 +699,83 @@ static void msm_qti_pp_asphere_init_state(void) static int msm_qti_pp_asphere_send_params(int port_id, int copp_idx, bool force) { - char *params_value = NULL; - uint32_t *update_params_value = NULL; - uint32_t param_size = sizeof(uint32_t) + - sizeof(struct adm_param_data_v5); - int params_length = 0, param_count = 0, ret = 0; + u8 *packed_params = NULL; + u32 packed_params_size = 0; + u32 param_size = 0; + struct param_hdr_v3 param_hdr; bool set_enable = force || (asphere_state.enabled != asphere_state.enabled_prev); bool set_strength = asphere_state.enabled == 1 && (set_enable || (asphere_state.strength != asphere_state.strength_prev)); + int param_count = 0; + int ret = 0; if (set_enable) param_count++; if (set_strength) param_count++; - params_length = param_count * param_size; + + if (param_count == 0) { + pr_debug("%s: Nothing to send, exiting\n", __func__); + return 0; + } pr_debug("%s: port_id %d, copp_id %d, forced %d, param_count %d\n", - __func__, port_id, copp_idx, force, param_count); + __func__, port_id, copp_idx, force, param_count); pr_debug("%s: enable prev:%u cur:%u, strength prev:%u cur:%u\n", __func__, asphere_state.enabled_prev, asphere_state.enabled, asphere_state.strength_prev, asphere_state.strength); - if (params_length > 0) - params_value = kzalloc(params_length, GFP_KERNEL); - if (!params_value) { - pr_err("%s, params memory alloc failed\n", __func__); + packed_params_size = + param_count * (sizeof(struct param_hdr_v3) + sizeof(uint32_t)); + packed_params = kzalloc(packed_params_size, GFP_KERNEL); + if (!packed_params) return -ENOMEM; - } - update_params_value = (uint32_t *)params_value; - params_length = 0; + + memset(¶m_hdr, 0, sizeof(param_hdr)); + packed_params_size = 0; + param_hdr.module_id = AUDPROC_MODULE_ID_AUDIOSPHERE; + param_hdr.instance_id = INSTANCE_ID_0; if (set_strength) { /* add strength command */ - *update_params_value++ = AUDPROC_MODULE_ID_AUDIOSPHERE; - *update_params_value++ = AUDPROC_PARAM_ID_AUDIOSPHERE_STRENGTH; - *update_params_value++ = sizeof(uint32_t); - *update_params_value++ = asphere_state.strength; - params_length += param_size; + param_hdr.param_id = AUDPROC_PARAM_ID_AUDIOSPHERE_STRENGTH; + param_hdr.param_size = sizeof(asphere_state.strength); + ret = q6common_pack_pp_params(packed_params + + packed_params_size, + ¶m_hdr, + (u8 *) &asphere_state.strength, + ¶m_size); + if (ret) { + pr_err("%s: Failed to pack params for audio sphere" + " strength, error %d\n", __func__, ret); + goto done; + } + packed_params_size += param_size; } if (set_enable) { /* add enable command */ - *update_params_value++ = AUDPROC_MODULE_ID_AUDIOSPHERE; - *update_params_value++ = AUDPROC_PARAM_ID_AUDIOSPHERE_ENABLE; - *update_params_value++ = sizeof(uint32_t); - *update_params_value++ = asphere_state.enabled; - params_length += param_size; - } - pr_debug("%s, param length: %d\n", __func__, params_length); - if (params_length) { - ret = adm_send_params_v5(port_id, copp_idx, - params_value, params_length); + param_hdr.param_id = AUDPROC_PARAM_ID_AUDIOSPHERE_ENABLE; + param_hdr.param_size = sizeof(asphere_state.enabled); + q6common_pack_pp_params(packed_params + packed_params_size, + ¶m_hdr, + (u8 *) &asphere_state.enabled, + ¶m_size); if (ret) { - pr_err("%s: setting param failed with err=%d\n", - __func__, ret); - kfree(params_value); - return -EINVAL; + pr_err("%s: Failed to pack params for audio sphere" + " enable, error %d\n", __func__, ret); + goto done; } + packed_params_size += param_size; } - kfree(params_value); + + pr_debug("%s: packed data size: %d\n", __func__, packed_params_size); + ret = adm_set_pp_params(port_id, copp_idx, NULL, packed_params, + packed_params_size); + if (ret) + pr_err("%s: set param failed with err=%d\n", __func__, ret); + +done: + kfree(packed_params); return 0; } diff --git a/dsp/q6adm.c b/dsp/q6adm.c index f8aef943439f..8ebab78ac1e4 100644 --- a/dsp/q6adm.c +++ b/dsp/q6adm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "adsp_err.h" @@ -32,8 +33,8 @@ #define RESET_COPP_ID 99 #define INVALID_COPP_ID 0xFF /* Used for inband payload copy, max size is 4k */ -/* 2 is to account for module & param ID in payload */ -#define ADM_GET_PARAMETER_LENGTH (4096 - APR_HDR_SIZE - 2 * sizeof(uint32_t)) +/* 3 is to account for module, instance & param ID in payload */ +#define ADM_GET_PARAMETER_LENGTH (4096 - APR_HDR_SIZE - 3 * sizeof(uint32_t)) #define ULL_SUPPORTED_BITS_PER_SAMPLE 16 #define ULL_SUPPORTED_SAMPLE_RATE 48000 @@ -124,8 +125,8 @@ static struct adm_multi_ch_map multi_ch_maps[2] = { }; static int adm_get_parameters[MAX_COPPS_PER_PORT * ADM_GET_PARAMETER_LENGTH]; -static int adm_module_topo_list[ - MAX_COPPS_PER_PORT * ADM_GET_TOPO_MODULE_LIST_LENGTH]; +static int adm_module_topo_list[MAX_COPPS_PER_PORT * + ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH]; static struct mutex dts_srs_lock; void msm_dts_srs_acquire_lock(void) @@ -316,266 +317,109 @@ static int adm_get_next_available_copp(int port_idx) int srs_trumedia_open(int port_id, int copp_idx, __s32 srs_tech_id, void *srs_params) { - struct adm_cmd_set_pp_params_inband_v5 *adm_params = NULL; - struct adm_cmd_set_pp_params_v5 *adm_params_ = NULL; - __s32 sz = 0, param_id, module_id = SRS_TRUMEDIA_MODULE_ID, outband = 0; - int ret = 0, port_idx; + struct param_hdr_v3 param_hdr; + struct mem_mapping_hdr mem_hdr; + u32 total_param_size = 0; + bool outband = false; + int port_idx; + int ret = 0; pr_debug("SRS - %s", __func__); + memset(¶m_hdr, 0, sizeof(param_hdr)); + memset(&mem_hdr, 0, sizeof(mem_hdr)); port_id = afe_convert_virtual_to_portid(port_id); port_idx = adm_validate_and_get_port_index(port_id); if (port_idx < 0) { pr_err("%s: Invalid port_id %#x\n", __func__, port_id); return -EINVAL; } + + param_hdr.module_id = SRS_TRUMEDIA_MODULE_ID; + param_hdr.instance_id = INSTANCE_ID_0; + switch (srs_tech_id) { case SRS_ID_GLOBAL: { - struct srs_trumedia_params_GLOBAL *glb_params = NULL; - - sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + + param_hdr.param_id = SRS_TRUMEDIA_PARAMS; + param_hdr.param_size = sizeof(struct srs_trumedia_params_GLOBAL); - adm_params = kzalloc(sz, GFP_KERNEL); - if (!adm_params) { - pr_err("%s, adm params memory alloc failed\n", - __func__); - return -ENOMEM; - } - adm_params->payload_size = - sizeof(struct srs_trumedia_params_GLOBAL) + - sizeof(struct adm_param_data_v5); - param_id = SRS_TRUMEDIA_PARAMS; - adm_params->params.param_size = - sizeof(struct srs_trumedia_params_GLOBAL); - glb_params = (struct srs_trumedia_params_GLOBAL *) - ((u8 *)adm_params + - sizeof(struct adm_cmd_set_pp_params_inband_v5)); - memcpy(glb_params, srs_params, - sizeof(struct srs_trumedia_params_GLOBAL)); break; } case SRS_ID_WOWHD: { - struct srs_trumedia_params_WOWHD *whd_params = NULL; - - sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + - sizeof(struct srs_trumedia_params_WOWHD); - adm_params = kzalloc(sz, GFP_KERNEL); - if (!adm_params) { - pr_err("%s, adm params memory alloc failed\n", - __func__); - return -ENOMEM; - } - adm_params->payload_size = - sizeof(struct srs_trumedia_params_WOWHD) + - sizeof(struct adm_param_data_v5); - param_id = SRS_TRUMEDIA_PARAMS_WOWHD; - adm_params->params.param_size = - sizeof(struct srs_trumedia_params_WOWHD); - whd_params = (struct srs_trumedia_params_WOWHD *) - ((u8 *)adm_params + - sizeof(struct adm_cmd_set_pp_params_inband_v5)); - memcpy(whd_params, srs_params, - sizeof(struct srs_trumedia_params_WOWHD)); + param_hdr.param_id = SRS_TRUMEDIA_PARAMS_WOWHD; + param_hdr.param_size = sizeof(struct srs_trumedia_params_WOWHD); break; } case SRS_ID_CSHP: { - struct srs_trumedia_params_CSHP *chp_params = NULL; - - sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + - sizeof(struct srs_trumedia_params_CSHP); - adm_params = kzalloc(sz, GFP_KERNEL); - if (!adm_params) { - pr_err("%s, adm params memory alloc failed\n", - __func__); - return -ENOMEM; - } - adm_params->payload_size = - sizeof(struct srs_trumedia_params_CSHP) + - sizeof(struct adm_param_data_v5); - param_id = SRS_TRUMEDIA_PARAMS_CSHP; - adm_params->params.param_size = - sizeof(struct srs_trumedia_params_CSHP); - chp_params = (struct srs_trumedia_params_CSHP *) - ((u8 *)adm_params + - sizeof(struct adm_cmd_set_pp_params_inband_v5)); - memcpy(chp_params, srs_params, - sizeof(struct srs_trumedia_params_CSHP)); + param_hdr.param_id = SRS_TRUMEDIA_PARAMS_CSHP; + param_hdr.param_size = sizeof(struct srs_trumedia_params_CSHP); break; } case SRS_ID_HPF: { - struct srs_trumedia_params_HPF *hpf_params = NULL; - - sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + - sizeof(struct srs_trumedia_params_HPF); - adm_params = kzalloc(sz, GFP_KERNEL); - if (!adm_params) { - pr_err("%s, adm params memory alloc failed\n", - __func__); - return -ENOMEM; - } - adm_params->payload_size = - sizeof(struct srs_trumedia_params_HPF) + - sizeof(struct adm_param_data_v5); - param_id = SRS_TRUMEDIA_PARAMS_HPF; - adm_params->params.param_size = - sizeof(struct srs_trumedia_params_HPF); - hpf_params = (struct srs_trumedia_params_HPF *) - ((u8 *)adm_params + - sizeof(struct adm_cmd_set_pp_params_inband_v5)); - memcpy(hpf_params, srs_params, - sizeof(struct srs_trumedia_params_HPF)); + param_hdr.param_id = SRS_TRUMEDIA_PARAMS_HPF; + param_hdr.param_size = sizeof(struct srs_trumedia_params_HPF); break; } case SRS_ID_AEQ: { - int *update_params_ptr = (int *)this_adm.outband_memmap.kvaddr; + u8 *update_params_ptr = (u8 *) this_adm.outband_memmap.kvaddr; - outband = 1; - adm_params = kzalloc(sizeof(struct adm_cmd_set_pp_params_v5), - GFP_KERNEL); - adm_params_ = (struct adm_cmd_set_pp_params_v5 *)adm_params; - if (!adm_params_) { - pr_err("%s, adm params memory alloc failed\n", - __func__); - return -ENOMEM; - } + outband = true; - sz = sizeof(struct srs_trumedia_params_AEQ); if (update_params_ptr == NULL) { pr_err("ADM_SRS_TRUMEDIA - %s: null memmap for AEQ params\n", __func__); ret = -EINVAL; goto fail_cmd; } - param_id = SRS_TRUMEDIA_PARAMS_AEQ; - *update_params_ptr++ = module_id; - *update_params_ptr++ = param_id; - *update_params_ptr++ = sz; - memcpy(update_params_ptr, srs_params, sz); - adm_params_->payload_size = sz + 12; + param_hdr.param_id = SRS_TRUMEDIA_PARAMS_AEQ; + param_hdr.param_size = sizeof(struct srs_trumedia_params_AEQ); + ret = q6common_pack_pp_params(update_params_ptr, ¶m_hdr, + srs_params, &total_param_size); + if (ret) { + pr_err("%s: Failed to pack param header and data, error %d\n", + __func__, ret); + goto fail_cmd; + } break; } case SRS_ID_HL: { - struct srs_trumedia_params_HL *hl_params = NULL; - - sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + - sizeof(struct srs_trumedia_params_HL); - adm_params = kzalloc(sz, GFP_KERNEL); - if (!adm_params) { - pr_err("%s, adm params memory alloc failed\n", - __func__); - return -ENOMEM; - } - adm_params->payload_size = - sizeof(struct srs_trumedia_params_HL) + - sizeof(struct adm_param_data_v5); - param_id = SRS_TRUMEDIA_PARAMS_HL; - adm_params->params.param_size = - sizeof(struct srs_trumedia_params_HL); - hl_params = (struct srs_trumedia_params_HL *) - ((u8 *)adm_params + - sizeof(struct adm_cmd_set_pp_params_inband_v5)); - memcpy(hl_params, srs_params, - sizeof(struct srs_trumedia_params_HL)); + param_hdr.param_id = SRS_TRUMEDIA_PARAMS_HL; + param_hdr.param_size = sizeof(struct srs_trumedia_params_HL); break; } case SRS_ID_GEQ: { - struct srs_trumedia_params_GEQ *geq_params = NULL; - - sz = sizeof(struct adm_cmd_set_pp_params_inband_v5) + - sizeof(struct srs_trumedia_params_GEQ); - adm_params = kzalloc(sz, GFP_KERNEL); - if (!adm_params) { - pr_err("%s, adm params memory alloc failed\n", - __func__); - return -ENOMEM; - } - adm_params->payload_size = - sizeof(struct srs_trumedia_params_GEQ) + - sizeof(struct adm_param_data_v5); - param_id = SRS_TRUMEDIA_PARAMS_GEQ; - adm_params->params.param_size = - sizeof(struct srs_trumedia_params_GEQ); - geq_params = (struct srs_trumedia_params_GEQ *) - ((u8 *)adm_params + - sizeof(struct adm_cmd_set_pp_params_inband_v5)); - memcpy(geq_params, srs_params, - sizeof(struct srs_trumedia_params_GEQ)); - pr_debug("SRS - %s: GEQ params prepared\n", __func__); + param_hdr.param_id = SRS_TRUMEDIA_PARAMS_GEQ; + param_hdr.param_size = sizeof(struct srs_trumedia_params_GEQ); break; } default: goto fail_cmd; } - adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - adm_params->hdr.src_svc = APR_SVC_ADM; - adm_params->hdr.src_domain = APR_DOMAIN_APPS; - adm_params->hdr.src_port = port_id; - adm_params->hdr.dest_svc = APR_SVC_ADM; - adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; - adm_params->hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - adm_params->hdr.token = port_idx << 16 | copp_idx; - adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; if (outband && this_adm.outband_memmap.paddr) { - adm_params->hdr.pkt_size = - sizeof(struct adm_cmd_set_pp_params_v5); - adm_params->payload_addr_lsw = lower_32_bits( - this_adm.outband_memmap.paddr); - adm_params->payload_addr_msw = msm_audio_populate_upper_32_bits( - this_adm.outband_memmap.paddr); - adm_params->mem_map_handle = atomic_read(&this_adm. - mem_map_handles[ADM_SRS_TRUMEDIA]); - } else { - adm_params->hdr.pkt_size = sz; - adm_params->payload_addr_lsw = 0; - adm_params->payload_addr_msw = 0; - adm_params->mem_map_handle = 0; + mem_hdr.data_payload_addr_lsw = + lower_32_bits(this_adm.outband_memmap.paddr); + mem_hdr.data_payload_addr_msw = + msm_audio_populate_upper_32_bits( + this_adm.outband_memmap.paddr); + mem_hdr.mem_map_handle = atomic_read( + &this_adm.mem_map_handles[ADM_SRS_TRUMEDIA]); - adm_params->params.module_id = module_id; - adm_params->params.param_id = param_id; - adm_params->params.reserved = 0; + ret = adm_set_pp_params(port_id, copp_idx, &mem_hdr, NULL, + total_param_size); + } else { + ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, + param_hdr, + (u8 *) srs_params); } - pr_debug("SRS - %s: Command was sent now check Q6 - port id = %d, size %d, module id %x, param id %x.\n", - __func__, adm_params->hdr.dest_port, - adm_params->payload_size, module_id, param_id); - - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - ret = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); - if (ret < 0) { + if (ret < 0) pr_err("SRS - %s: ADM enable for port %d failed\n", __func__, port_id); - ret = -EINVAL; - goto fail_cmd; - } - /* Wait for the callback with copp id */ - ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!ret) { - pr_err("%s: SRS set params timed out port = %d\n", - __func__, port_id); - ret = -EINVAL; - goto fail_cmd; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - ret = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto fail_cmd; - } fail_cmd: - kfree(adm_params); return ret; } EXPORT_SYMBOL(srs_trumedia_open); @@ -636,7 +480,7 @@ int adm_programable_channel_mixer(int port_id, int copp_idx, int session_id, int channel_index) { struct adm_cmd_set_pspd_mtmx_strtr_params_v5 *adm_params = NULL; - struct adm_param_data_v5 data_v5; + struct param_hdr_v3 data_v5; int ret = 0, port_idx, sz = 0, param_size = 0; u16 *adm_pspd_params; u16 *ptr; @@ -668,8 +512,8 @@ int adm_programable_channel_mixer(int port_id, int copp_idx, int session_id, roundup(param_size, 4); sz = sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5) + - sizeof(struct default_chmixer_param_id_coeff) + - sizeof(struct adm_param_data_v5) + param_size; + sizeof(struct default_chmixer_param_id_coeff) + + sizeof(struct param_hdr_v3) + param_size; pr_debug("%s: sz = %d\n", __func__, sz); adm_params = kzalloc(sz, GFP_KERNEL); if (!adm_params) @@ -687,13 +531,17 @@ int adm_programable_channel_mixer(int port_id, int copp_idx, int session_id, &this_adm.copp.id[port_idx][copp_idx]); adm_params->reserved = 0; + /* + * This module is internal to ADSP and cannot be configured with + * an instance id + */ data_v5.module_id = MTMX_MODULE_ID_DEFAULT_CHMIXER; data_v5.param_id = DEFAULT_CHMIXER_PARAM_ID_COEFF; data_v5.reserved = 0; data_v5.param_size = param_size; adm_params->payload_size = - sizeof(struct default_chmixer_param_id_coeff) + - sizeof(struct adm_param_data_v5) + data_v5.param_size; + sizeof(struct default_chmixer_param_id_coeff) + + sizeof(struct param_hdr_v3) + data_v5.param_size; adm_pspd_params = (u16 *)((u8 *)adm_params + sizeof(struct adm_cmd_set_pspd_mtmx_strtr_params_v5)); memcpy(adm_pspd_params, &data_v5, sizeof(data_v5)); @@ -955,321 +803,306 @@ EXPORT_SYMBOL(adm_set_stereo_to_custom_stereo); int adm_dolby_dap_send_params(int port_id, int copp_idx, char *params, uint32_t params_length) { - struct adm_cmd_set_pp_params_v5 *adm_params = NULL; - int sz, rc = 0; - int port_idx; - - pr_debug("%s:\n", __func__); - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0) { - pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); - return -EINVAL; - } - - sz = sizeof(struct adm_cmd_set_pp_params_v5) + params_length; - adm_params = kzalloc(sz, GFP_KERNEL); - if (!adm_params) { - pr_err("%s, adm params memory alloc failed", __func__); - return -ENOMEM; - } - - memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_set_pp_params_v5)), - params, params_length); - adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - adm_params->hdr.pkt_size = sz; - adm_params->hdr.src_svc = APR_SVC_ADM; - adm_params->hdr.src_domain = APR_DOMAIN_APPS; - adm_params->hdr.src_port = port_id; - adm_params->hdr.dest_svc = APR_SVC_ADM; - adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; - adm_params->hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - adm_params->hdr.token = port_idx << 16 | copp_idx; - adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - adm_params->payload_addr_lsw = 0; - adm_params->payload_addr_msw = 0; - adm_params->mem_map_handle = 0; - adm_params->payload_size = params_length; - - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); - if (rc < 0) { - pr_err("%s: Set params failed port = 0x%x rc %d\n", - __func__, port_id, rc); - rc = -EINVAL; - goto dolby_dap_send_param_return; - } - /* Wait for the callback */ - rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!rc) { - pr_err("%s: Set params timed out port = 0x%x\n", - __func__, port_id); - rc = -EINVAL; - goto dolby_dap_send_param_return; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - rc = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto dolby_dap_send_param_return; - } - rc = 0; -dolby_dap_send_param_return: - kfree(adm_params); - return rc; + /* Use as wrapper for adm_set_pp_params until no longer used */ + return adm_set_pp_params(port_id, copp_idx, NULL, params, + params_length); } EXPORT_SYMBOL(adm_dolby_dap_send_params); -/** - * adm_get_params_v5 - - * command to retrieve ADM params for given module - * - * @port_id: Port ID number - * @copp_idx: copp index of ADM copp - * @params: params pointer - * @param_length: length of params - * - * Returns 0 on success or error on failure +/* + * With pre-packed data, only the opcode differes from V5 and V6. + * Use q6common_pack_pp_params to pack the data correctly. */ -int adm_send_params_v5(int port_id, int copp_idx, char *params, - uint32_t params_length) +int adm_set_pp_params(int port_id, int copp_idx, + struct mem_mapping_hdr *mem_hdr, u8 *param_data, + u32 param_size) { - struct adm_cmd_set_pp_params_v5 *adm_params = NULL; - int rc = 0; - int sz, port_idx; + struct adm_cmd_set_pp_params *adm_set_params = NULL; + int size = 0; + int port_idx = 0; + atomic_t *copp_stat = NULL; + int ret = 0; - pr_debug("%s:\n", __func__); port_id = afe_convert_virtual_to_portid(port_id); port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0) { - pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); + if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { + pr_err("%s: Invalid port_idx 0x%x\n", __func__, port_idx); + return -EINVAL; + } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { + pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx); return -EINVAL; } - sz = sizeof(struct adm_cmd_set_pp_params_v5) + params_length; - adm_params = kzalloc(sz, GFP_KERNEL); - if (!adm_params) { - pr_err("%s, adm params memory alloc failed", __func__); + /* Only add params_size in inband case */ + size = sizeof(struct adm_cmd_set_pp_params); + if (param_data != NULL) + size += param_size; + adm_set_params = kzalloc(size, GFP_KERNEL); + if (!adm_set_params) return -ENOMEM; + + adm_set_params->apr_hdr.hdr_field = + APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), + APR_PKT_VER); + adm_set_params->apr_hdr.pkt_size = size; + adm_set_params->apr_hdr.src_svc = APR_SVC_ADM; + adm_set_params->apr_hdr.src_domain = APR_DOMAIN_APPS; + adm_set_params->apr_hdr.src_port = port_id; + adm_set_params->apr_hdr.dest_svc = APR_SVC_ADM; + adm_set_params->apr_hdr.dest_domain = APR_DOMAIN_ADSP; + adm_set_params->apr_hdr.dest_port = + atomic_read(&this_adm.copp.id[port_idx][copp_idx]); + adm_set_params->apr_hdr.token = port_idx << 16 | copp_idx; + + if (q6common_is_instance_id_supported()) + adm_set_params->apr_hdr.opcode = ADM_CMD_SET_PP_PARAMS_V6; + else + adm_set_params->apr_hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; + + adm_set_params->payload_size = param_size; + + if (mem_hdr != NULL) { + /* Out of Band Case */ + adm_set_params->mem_hdr = *mem_hdr; + } else if (param_data != NULL) { + /* + * In band case. Parameter data must be pre-packed with its + * header before calling this function. Use + * q6common_pack_pp_params to pack parameter data and header + * correctly. + */ + memcpy(&adm_set_params->param_data, param_data, param_size); + } else { + pr_err("%s: Received NULL pointers for both memory header and param data\n", + __func__); + ret = -EINVAL; + goto done; } - memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_set_pp_params_v5)), - params, params_length); - adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - adm_params->hdr.pkt_size = sz; - adm_params->hdr.src_svc = APR_SVC_ADM; - adm_params->hdr.src_domain = APR_DOMAIN_APPS; - adm_params->hdr.src_port = port_id; - adm_params->hdr.dest_svc = APR_SVC_ADM; - adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; - adm_params->hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - adm_params->hdr.token = port_idx << 16 | copp_idx; - adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - adm_params->payload_addr_lsw = 0; - adm_params->payload_addr_msw = 0; - adm_params->mem_map_handle = 0; - adm_params->payload_size = params_length; + copp_stat = &this_adm.copp.stat[port_idx][copp_idx]; + atomic_set(copp_stat, -1); + ret = apr_send_pkt(this_adm.apr, (uint32_t *) adm_set_params); + if (ret < 0) { + pr_err("%s: Set params APR send failed port = 0x%x ret %d\n", + __func__, port_id, ret); + goto done; + } + ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], + atomic_read(copp_stat) >= 0, + msecs_to_jiffies(TIMEOUT_MS)); + if (!ret) { + pr_err("%s: Set params timed out port = 0x%x\n", __func__, + port_id); + ret = -ETIMEDOUT; + goto done; + } + if (atomic_read(copp_stat) > 0) { + pr_err("%s: DSP returned error[%s]\n", __func__, + adsp_err_get_err_str(atomic_read(copp_stat))); + ret = adsp_err_get_lnx_err_code(atomic_read(copp_stat)); + goto done; + } - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); - if (rc < 0) { - pr_err("%s: Set params failed port = 0x%x rc %d\n", - __func__, port_id, rc); - rc = -EINVAL; - goto send_param_return; - } - /* Wait for the callback */ - rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!rc) { - pr_err("%s: Set params timed out port = 0x%x\n", - __func__, port_id); - rc = -EINVAL; - goto send_param_return; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - rc = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto send_param_return; - } - rc = 0; -send_param_return: - kfree(adm_params); - return rc; + ret = 0; +done: + kfree(adm_set_params); + return ret; } -EXPORT_SYMBOL(adm_send_params_v5); +EXPORT_SYMBOL(adm_set_pp_params); + +int adm_pack_and_set_one_pp_param(int port_id, int copp_idx, + struct param_hdr_v3 param_hdr, u8 *param_data) +{ + u8 *packed_data = NULL; + u32 total_size = 0; + int ret = 0; + + total_size = sizeof(union param_hdrs) + param_hdr.param_size; + packed_data = kzalloc(total_size, GFP_KERNEL); + if (!packed_data) + return -ENOMEM; + + ret = q6common_pack_pp_params(packed_data, ¶m_hdr, param_data, + &total_size); + if (ret) { + pr_err("%s: Failed to pack parameter data, error %d\n", + __func__, ret); + goto done; + } + + ret = adm_set_pp_params(port_id, copp_idx, NULL, packed_data, + total_size); + if (ret) + pr_err("%s: Failed to set parameter data, error %d\n", __func__, + ret); +done: + kfree(packed_data); + return ret; +} +EXPORT_SYMBOL(adm_pack_and_set_one_pp_param); int adm_get_params_v2(int port_id, int copp_idx, uint32_t module_id, - uint32_t param_id, uint32_t params_length, - char *params, uint32_t client_id) + uint32_t param_id, uint32_t params_length, char *params, + uint32_t client_id) { - struct adm_cmd_get_pp_params_v5 *adm_params = NULL; - int rc = 0, i = 0; - int port_idx, idx; - int *params_data = (int *)params; - uint64_t sz = 0; + struct param_hdr_v3 param_hdr; - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0) { - pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); - return -EINVAL; - } + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = module_id; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = param_id; + param_hdr.param_size = params_length; - sz = (uint64_t)sizeof(struct adm_cmd_get_pp_params_v5) + - (uint64_t)params_length; - /* - * Check if the value of "sz" (which is ultimately assigned to - * "hdr.pkt_size") crosses U16_MAX. - */ - if (sz > U16_MAX) { - pr_err("%s: Invalid params_length\n", __func__); - return -EINVAL; - } - adm_params = kzalloc(sz, GFP_KERNEL); - if (!adm_params) { - pr_err("%s: adm params memory alloc failed", __func__); - return -ENOMEM; - } - - memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_get_pp_params_v5)), - params, params_length); - adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - adm_params->hdr.pkt_size = sz; - adm_params->hdr.src_svc = APR_SVC_ADM; - adm_params->hdr.src_domain = APR_DOMAIN_APPS; - adm_params->hdr.src_port = port_id; - adm_params->hdr.dest_svc = APR_SVC_ADM; - adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; - adm_params->hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - adm_params->hdr.token = port_idx << 16 | client_id << 8 | copp_idx; - adm_params->hdr.opcode = ADM_CMD_GET_PP_PARAMS_V5; - adm_params->data_payload_addr_lsw = 0; - adm_params->data_payload_addr_msw = 0; - adm_params->mem_map_handle = 0; - adm_params->module_id = module_id; - adm_params->param_id = param_id; - adm_params->param_max_size = params_length; - adm_params->reserved = 0; - - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); - if (rc < 0) { - pr_err("%s: Failed to Get Params on port_id 0x%x %d\n", - __func__, port_id, rc); - rc = -EINVAL; - goto adm_get_param_return; - } - /* Wait for the callback with copp id */ - rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!rc) { - pr_err("%s: get params timed out port_id = 0x%x\n", __func__, - port_id); - rc = -EINVAL; - goto adm_get_param_return; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - rc = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto adm_get_param_return; - } - idx = ADM_GET_PARAMETER_LENGTH * copp_idx; - - if (adm_get_parameters[idx] < 0) { - pr_err("%s: Size is invalid %d\n", __func__, - adm_get_parameters[idx]); - rc = -EINVAL; - goto adm_get_param_return; - } - if ((params_data) && - (ARRAY_SIZE(adm_get_parameters) > - idx) && - (ARRAY_SIZE(adm_get_parameters) >= - 1+adm_get_parameters[idx]+idx) && - (params_length/sizeof(uint32_t) >= - adm_get_parameters[idx])) { - for (i = 0; i < adm_get_parameters[idx]; i++) - params_data[i] = adm_get_parameters[1+i+idx]; - - } else { - pr_err("%s: Get param data not copied! get_param array size %zd, index %d, params array size %zd, index %d\n", - __func__, ARRAY_SIZE(adm_get_parameters), - (1+adm_get_parameters[idx]+idx), - params_length/sizeof(int), - adm_get_parameters[idx]); - } - rc = 0; -adm_get_param_return: - kfree(adm_params); - - return rc; + return adm_get_pp_params(port_id, copp_idx, client_id, NULL, ¶m_hdr, + params); } -/** - * adm_get_params - - * command to retrieve ADM params for given module - * - * @port_id: Port ID number - * @copp_idx: copp index of ADM copp - * @module_id: module ID - * @param_id: Param index - * @param_length: length of params - * @params: params pointer - * - * Returns 0 on success or error on failure - */ int adm_get_params(int port_id, int copp_idx, uint32_t module_id, uint32_t param_id, uint32_t params_length, char *params) { return adm_get_params_v2(port_id, copp_idx, module_id, param_id, params_length, params, 0); } -EXPORT_SYMBOL(adm_get_params); -/** - * adm_get_pp_topo_module_list - - * command to update PP top module list - * - * @port_id: Port ID number - * @copp_idx: copp index of ADM copp - * @param_length: length of params - * @params: pointer with PP top module params - * - * Returns 0 on success or error on failure +/* + * Only one parameter can be requested at a time. Therefore, packing and sending + * the request can be handled locally. */ +int adm_get_pp_params(int port_id, int copp_idx, uint32_t client_id, + struct mem_mapping_hdr *mem_hdr, + struct param_hdr_v3 *param_hdr, u8 *returned_param_data) +{ + struct adm_cmd_get_pp_params adm_get_params; + int total_size = 0; + int get_param_array_sz = ARRAY_SIZE(adm_get_parameters); + int returned_param_size = 0; + int returned_param_size_in_bytes = 0; + int port_idx = 0; + int idx = 0; + atomic_t *copp_stat = NULL; + int ret = 0; + + if (param_hdr == NULL) { + pr_err("%s: Received NULL pointer for parameter header\n", + __func__); + return -EINVAL; + } + + port_id = afe_convert_virtual_to_portid(port_id); + port_idx = adm_validate_and_get_port_index(port_id); + if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { + pr_err("%s: Invalid port_idx 0x%x\n", __func__, port_idx); + return -EINVAL; + } + if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { + pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx); + return -EINVAL; + } + + memset(&adm_get_params, 0, sizeof(adm_get_params)); + + if (mem_hdr != NULL) + adm_get_params.mem_hdr = *mem_hdr; + + q6common_pack_pp_params((u8 *) &adm_get_params.param_hdr, param_hdr, + NULL, &total_size); + + /* Pack APR header after filling body so total_size has correct value */ + adm_get_params.apr_hdr.pkt_size = total_size; + adm_get_params.apr_hdr.src_svc = APR_SVC_ADM; + adm_get_params.apr_hdr.src_domain = APR_DOMAIN_APPS; + adm_get_params.apr_hdr.src_port = port_id; + adm_get_params.apr_hdr.dest_svc = APR_SVC_ADM; + adm_get_params.apr_hdr.dest_domain = APR_DOMAIN_ADSP; + adm_get_params.apr_hdr.dest_port = + atomic_read(&this_adm.copp.id[port_idx][copp_idx]); + adm_get_params.apr_hdr.token = + port_idx << 16 | client_id << 8 | copp_idx; + + if (q6common_is_instance_id_supported()) + adm_get_params.apr_hdr.opcode = ADM_CMD_GET_PP_PARAMS_V6; + else + adm_get_params.apr_hdr.opcode = ADM_CMD_GET_PP_PARAMS_V5; + + copp_stat = &this_adm.copp.stat[port_idx][copp_idx]; + atomic_set(copp_stat, -1); + ret = apr_send_pkt(this_adm.apr, (uint32_t *) &adm_get_params); + if (ret) { + pr_err("%s: Get params APR send failed port = 0x%x ret %d\n", + __func__, port_id, ret); + ret = -EINVAL; + goto done; + } + ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], + atomic_read(copp_stat) >= 0, + msecs_to_jiffies(TIMEOUT_MS)); + if (!ret) { + pr_err("%s: Get params timed out port = 0x%x\n", __func__, + port_id); + ret = -ETIMEDOUT; + goto done; + } + if (atomic_read(copp_stat) > 0) { + pr_err("%s: DSP returned error[%s]\n", __func__, + adsp_err_get_err_str(atomic_read(copp_stat))); + ret = adsp_err_get_lnx_err_code(atomic_read(copp_stat)); + goto done; + } + + ret = 0; + + /* Copy data to caller if sent in band */ + if (!returned_param_data) { + pr_debug("%s: Received NULL pointer for param destination, not copying payload\n", + __func__); + return 0; + } + + idx = ADM_GET_PARAMETER_LENGTH * copp_idx; + returned_param_size = adm_get_parameters[idx]; + if (returned_param_size < 0 || + returned_param_size + idx + 1 > get_param_array_sz) { + pr_err("%s: Invalid parameter size %d\n", __func__, + returned_param_size); + return -EINVAL; + } + + returned_param_size_in_bytes = returned_param_size * sizeof(uint32_t); + if (param_hdr->param_size < returned_param_size_in_bytes) { + pr_err("%s: Provided buffer is not big enough, provided buffer size(%d) size needed(%d)\n", + __func__, param_hdr->param_size, + returned_param_size_in_bytes); + return -EINVAL; + } + + memcpy(returned_param_data, &adm_get_parameters[idx + 1], + returned_param_size_in_bytes); +done: + return ret; +} +EXPORT_SYMBOL(adm_get_pp_params); + int adm_get_pp_topo_module_list(int port_id, int copp_idx, int32_t param_length, char *params) { - struct adm_cmd_get_pp_topo_module_list_t *adm_pp_module_list = NULL; - int sz, rc = 0, i = 0; - int port_idx, idx; - int32_t *params_data = (int32_t *)params; + return adm_get_pp_topo_module_list_v2(port_id, copp_idx, param_length, + (int32_t *) params); +} +EXPORT_SYMBOL(adm_get_pp_topo_module_list); + +int adm_get_pp_topo_module_list_v2(int port_id, int copp_idx, + int32_t param_length, + int32_t *returned_params) +{ + struct adm_cmd_get_pp_topo_module_list adm_get_module_list; + bool iid_supported = q6common_is_instance_id_supported(); int *topo_list; + int num_modules = 0; + int list_size = 0; + int port_idx, idx; + int i = 0; + atomic_t *copp_stat = NULL; + int ret = 0; pr_debug("%s : port_id %x", __func__, port_id); port_id = afe_convert_virtual_to_portid(port_id); @@ -1284,81 +1117,96 @@ int adm_get_pp_topo_module_list(int port_id, int copp_idx, int32_t param_length, return -EINVAL; } - sz = sizeof(struct adm_cmd_get_pp_topo_module_list_t) + param_length; - adm_pp_module_list = kzalloc(sz, GFP_KERNEL); - if (!adm_pp_module_list) { - pr_err("%s, adm params memory alloc failed", __func__); - return -ENOMEM; + memset(&adm_get_module_list, 0, sizeof(adm_get_module_list)); + + adm_get_module_list.apr_hdr.pkt_size = sizeof(adm_get_module_list); + adm_get_module_list.apr_hdr.src_svc = APR_SVC_ADM; + adm_get_module_list.apr_hdr.src_domain = APR_DOMAIN_APPS; + adm_get_module_list.apr_hdr.src_port = port_id; + adm_get_module_list.apr_hdr.dest_svc = APR_SVC_ADM; + adm_get_module_list.apr_hdr.dest_domain = APR_DOMAIN_ADSP; + adm_get_module_list.apr_hdr.dest_port = + atomic_read(&this_adm.copp.id[port_idx][copp_idx]); + adm_get_module_list.apr_hdr.token = port_idx << 16 | copp_idx; + /* + * Out of band functionality is not currently utilized. + * Assume in band. + */ + if (iid_supported) { + adm_get_module_list.apr_hdr.opcode = + ADM_CMD_GET_PP_TOPO_MODULE_LIST_V2; + adm_get_module_list.param_max_size = param_length; + } else { + adm_get_module_list.apr_hdr.opcode = + ADM_CMD_GET_PP_TOPO_MODULE_LIST; + + if (param_length > U16_MAX) { + pr_err("%s: Invalid param length for V1 %d\n", __func__, + param_length); + return -EINVAL; + } + adm_get_module_list.param_max_size = param_length << 16; } - memcpy(((u8 *)adm_pp_module_list + - sizeof(struct adm_cmd_get_pp_topo_module_list_t)), - params, param_length); - adm_pp_module_list->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - adm_pp_module_list->hdr.pkt_size = sz; - adm_pp_module_list->hdr.src_svc = APR_SVC_ADM; - adm_pp_module_list->hdr.src_domain = APR_DOMAIN_APPS; - adm_pp_module_list->hdr.src_port = port_id; - adm_pp_module_list->hdr.dest_svc = APR_SVC_ADM; - adm_pp_module_list->hdr.dest_domain = APR_DOMAIN_ADSP; - adm_pp_module_list->hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - adm_pp_module_list->hdr.token = port_idx << 16 | copp_idx; - adm_pp_module_list->hdr.opcode = ADM_CMD_GET_PP_TOPO_MODULE_LIST; - adm_pp_module_list->param_max_size = param_length; - /* Payload address and mmap handle set to zero by kzalloc */ + copp_stat = &this_adm.copp.stat[port_idx][copp_idx]; + atomic_set(copp_stat, -1); + ret = apr_send_pkt(this_adm.apr, (uint32_t *) &adm_get_module_list); + if (ret) { + pr_err("%s: APR send pkt failed for port_id: 0x%x failed ret %d\n", + __func__, port_id, ret); + ret = -EINVAL; + goto done; + } + ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], + atomic_read(copp_stat) >= 0, + msecs_to_jiffies(TIMEOUT_MS)); + if (!ret) { + pr_err("%s: Timeout for port_id: 0x%x\n", __func__, port_id); + ret = -ETIMEDOUT; + goto done; + } + if (atomic_read(copp_stat) > 0) { + pr_err("%s: DSP returned error[%s]\n", __func__, + adsp_err_get_err_str(atomic_read(copp_stat))); + ret = adsp_err_get_lnx_err_code(atomic_read(copp_stat)); + goto done; + } - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); + ret = 0; - rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_pp_module_list); - if (rc < 0) { - pr_err("%s: Failed to Get Params on port %d\n", __func__, - port_id); - rc = -EINVAL; - goto adm_pp_module_list_l; + if (returned_params) { + /* + * When processing ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST IID is + * added since it is not present. Therefore, there is no need to + * do anything different if IID is not supported here as it is + * already taken care of. + */ + idx = ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH * copp_idx; + num_modules = adm_module_topo_list[idx]; + if (num_modules < 0 || num_modules > MAX_MODULES_IN_TOPO) { + pr_err("%s: Invalid number of modules returned %d\n", + __func__, num_modules); + return -EINVAL; + } + + list_size = num_modules * sizeof(struct module_instance_info); + if (param_length < list_size) { + pr_err("%s: Provided buffer not big enough to hold module-instance list, provided size %d, needed size %d\n", + __func__, param_length, list_size); + return -EINVAL; + } + + topo_list = (int32_t *) (&adm_module_topo_list[idx]); + memcpy(returned_params, topo_list, list_size); + for (i = 1; i <= num_modules; i += 2) { + pr_debug("module = 0x%x instance = 0x%x\n", + returned_params[i], returned_params[i + 1]); + } } - /* Wait for the callback with copp id */ - rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!rc) { - pr_err("%s: get params timed out port = %d\n", __func__, - port_id); - rc = -EINVAL; - goto adm_pp_module_list_l; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - rc = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto adm_pp_module_list_l; - } - if (params_data) { - idx = ADM_GET_TOPO_MODULE_LIST_LENGTH * copp_idx; - topo_list = (int *)(adm_module_topo_list + idx); - if (param_length <= ADM_GET_TOPO_MODULE_LIST_LENGTH && - idx < - (MAX_COPPS_PER_PORT * ADM_GET_TOPO_MODULE_LIST_LENGTH)) - memcpy(params_data, topo_list, param_length); - else - pr_debug("%s: i/p size:%d > MAX param size:%d\n", - __func__, param_length, - (int)ADM_GET_TOPO_MODULE_LIST_LENGTH); - for (i = 1; i <= params_data[0]; i++) - pr_debug("module = 0x%x\n", params_data[i]); - } - rc = 0; -adm_pp_module_list_l: - kfree(adm_pp_module_list); - pr_debug("%s : rc = %d ", __func__, rc); - return rc; +done: + return ret; } -EXPORT_SYMBOL(adm_get_pp_topo_module_list); +EXPORT_SYMBOL(adm_get_pp_topo_module_list_v2); static void adm_callback_debug_print(struct apr_client_data *data) { @@ -1440,6 +1288,114 @@ int adm_get_multi_ch_map(char *channel_map, int path) } EXPORT_SYMBOL(adm_get_multi_ch_map); +static int adm_process_get_param_response(u32 opcode, u32 idx, u32 *payload, + u32 payload_size) +{ + struct adm_cmd_rsp_get_pp_params_v5 *v5_rsp = NULL; + struct adm_cmd_rsp_get_pp_params_v6 *v6_rsp = NULL; + u32 *param_data = NULL; + int data_size = 0; + int struct_size = 0; + + if (payload == NULL) { + pr_err("%s: Payload is NULL\n", __func__); + return -EINVAL; + } + + switch (opcode) { + case ADM_CMDRSP_GET_PP_PARAMS_V5: + struct_size = sizeof(struct adm_cmd_rsp_get_pp_params_v5); + v5_rsp = (struct adm_cmd_rsp_get_pp_params_v5 *) payload; + data_size = v5_rsp->param_hdr.param_size; + param_data = v5_rsp->param_data; + break; + case ADM_CMDRSP_GET_PP_PARAMS_V6: + struct_size = sizeof(struct adm_cmd_rsp_get_pp_params_v6); + v6_rsp = (struct adm_cmd_rsp_get_pp_params_v6 *) payload; + data_size = v6_rsp->param_hdr.param_size; + param_data = v6_rsp->param_data; + break; + default: + pr_err("%s: Invalid opcode %d\n", __func__, opcode); + return -EINVAL; + } + + /* + * Just store the returned parameter data, not the header. The calling + * function is expected to know what it asked for. Therefore, there is + * no difference between V5 and V6. + */ + if ((payload_size >= struct_size + data_size) && + (ARRAY_SIZE(adm_get_parameters) > idx) && + (ARRAY_SIZE(adm_get_parameters) >= idx + 1 + data_size)) { + /* + * data_size is expressed in number of bytes, store in number of + * ints + */ + adm_get_parameters[idx] = + data_size / sizeof(*adm_get_parameters); + pr_debug("%s: GET_PP PARAM: received parameter length: 0x%x\n", + __func__, adm_get_parameters[idx]); + /* store params after param_size */ + memcpy(&adm_get_parameters[idx + 1], param_data, data_size); + return 0; + } + + pr_err("%s: Invalid parameter combination, payload_size %d, idx %d\n", + __func__, payload_size, idx); + return -EINVAL; +} + +static int adm_process_get_topo_list_response(u32 opcode, int copp_idx, + u32 num_modules, u32 *payload, + u32 payload_size) +{ + u32 *fill_list = NULL; + int idx = 0; + int i = 0; + int j = 0; + + if (payload == NULL) { + pr_err("%s: Payload is NULL\n", __func__); + return -EINVAL; + } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { + pr_err("%s: Invalid COPP index %d\n", __func__, copp_idx); + return -EINVAL; + } + + idx = ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH * copp_idx; + fill_list = adm_module_topo_list + idx; + *fill_list++ = num_modules; + for (i = 0; i < num_modules; i++) { + if (j > payload_size / sizeof(u32)) { + pr_err("%s: Invalid number of modules specified %d\n", + __func__, num_modules); + return -EINVAL; + } + + /* store module ID */ + *fill_list++ = payload[j]; + j++; + + switch (opcode) { + case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST_V2: + /* store instance ID */ + *fill_list++ = payload[j]; + j++; + break; + case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST: + /* Insert IID 0 when repacking */ + *fill_list++ = INSTANCE_ID_0; + break; + default: + pr_err("%s: Invalid opcode %d\n", __func__, opcode); + return -EINVAL; + } + } + + return 0; +} + static void adm_reset_data(void) { int i, j; @@ -1501,7 +1457,9 @@ static void adm_reset_data(void) static int32_t adm_callback(struct apr_client_data *data, void *priv) { uint32_t *payload; - int i, port_idx, copp_idx, idx, client_id; + int port_idx, copp_idx, idx, client_id; + int num_modules; + int ret; if (data == NULL) { pr_err("%s: data parameter is null\n", __func__); @@ -1548,8 +1506,9 @@ static int32_t adm_callback(struct apr_client_data *data, void *priv) } switch (payload[0]) { case ADM_CMD_SET_PP_PARAMS_V5: - pr_debug("%s: ADM_CMD_SET_PP_PARAMS_V5\n", - __func__); + case ADM_CMD_SET_PP_PARAMS_V6: + pr_debug("%s: ADM_CMD_SET_PP_PARAMS\n", + __func__); if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING) this_adm.sourceTrackingData. apr_cmd_status = payload[1]; @@ -1605,8 +1564,9 @@ static int32_t adm_callback(struct apr_client_data *data, void *priv) } break; case ADM_CMD_GET_PP_PARAMS_V5: - pr_debug("%s: ADM_CMD_GET_PP_PARAMS_V5\n", - __func__); + case ADM_CMD_GET_PP_PARAMS_V6: + pr_debug("%s: ADM_CMD_GET_PP_PARAMS\n", + __func__); /* Should only come here if there is an APR */ /* error or malformed APR packet. Otherwise */ /* response will be returned as */ @@ -1643,11 +1603,12 @@ static int32_t adm_callback(struct apr_client_data *data, void *priv) &this_adm.copp.wait[port_idx][copp_idx]); break; case ADM_CMD_GET_PP_TOPO_MODULE_LIST: + case ADM_CMD_GET_PP_TOPO_MODULE_LIST_V2: pr_debug("%s:ADM_CMD_GET_PP_TOPO_MODULE_LIST\n", __func__); if (payload[1] != 0) - pr_err("%s: ADM get topo list error = %d,\n", - __func__, payload[1]); + pr_err("%s: ADM get topo list error = %d\n", + __func__, payload[1]); break; default: pr_err("%s: Unknown Cmd: 0x%x\n", __func__, @@ -1682,80 +1643,60 @@ static int32_t adm_callback(struct apr_client_data *data, void *priv) } break; case ADM_CMDRSP_GET_PP_PARAMS_V5: - pr_debug("%s: ADM_CMDRSP_GET_PP_PARAMS_V5\n", __func__); - if (payload[0] != 0) - pr_err("%s: ADM_CMDRSP_GET_PP_PARAMS_V5 returned error = 0x%x\n", - __func__, payload[0]); + case ADM_CMDRSP_GET_PP_PARAMS_V6: + pr_debug("%s: ADM_CMDRSP_GET_PP_PARAMS\n", __func__); if (client_id == ADM_CLIENT_ID_SOURCE_TRACKING) this_adm.sourceTrackingData.apr_cmd_status = - payload[0]; + payload[0]; else if (rtac_make_adm_callback(payload, - data->payload_size)) + data->payload_size)) break; idx = ADM_GET_PARAMETER_LENGTH * copp_idx; - if ((payload[0] == 0) && (data->payload_size > - (4 * sizeof(*payload))) && - (data->payload_size - 4 >= - payload[3]) && - (ARRAY_SIZE(adm_get_parameters) > - idx) && - (ARRAY_SIZE(adm_get_parameters)-idx-1 >= - payload[3])) { - adm_get_parameters[idx] = payload[3] / - sizeof(uint32_t); - /* - * payload[3] is param_size which is - * expressed in number of bytes - */ - pr_debug("%s: GET_PP PARAM:received parameter length: 0x%x\n", - __func__, adm_get_parameters[idx]); - /* storing param size then params */ - for (i = 0; i < payload[3] / - sizeof(uint32_t); i++) - adm_get_parameters[idx+1+i] = - payload[4+i]; - } else if (payload[0] == 0) { + if (payload[0] == 0 && data->payload_size > 0) { + pr_debug("%s: Received parameter data in band\n", + __func__); + ret = adm_process_get_param_response( + data->opcode, idx, payload, + data->payload_size); + if (ret) + pr_err("%s: Failed to process get param response, error %d\n", + __func__, ret); + } else if (payload[0] == 0 && data->payload_size == 0) { adm_get_parameters[idx] = -1; - pr_err("%s: Out of band case, setting size to %d\n", + pr_debug("%s: Out of band case, setting size to %d\n", __func__, adm_get_parameters[idx]); } else { adm_get_parameters[idx] = -1; - pr_err("%s: GET_PP_PARAMS failed, setting size to %d\n", - __func__, adm_get_parameters[idx]); + pr_err("%s: ADM_CMDRSP_GET_PP_PARAMS returned error 0x%x\n", + __func__, payload[0]); } - atomic_set(&this_adm.copp.stat - [port_idx][copp_idx], payload[0]); + atomic_set(&this_adm.copp.stat[port_idx][copp_idx], + payload[0]); wake_up(&this_adm.copp.wait[port_idx][copp_idx]); break; case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST: + case ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST_V2: pr_debug("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST\n", __func__); - if (payload[0] != 0) { - pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST", - __func__); - pr_err(":err = 0x%x\n", payload[0]); - } else if (payload[1] > - ((ADM_GET_TOPO_MODULE_LIST_LENGTH / - sizeof(uint32_t)) - 1)) { - pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST", - __func__); - pr_err(":size = %d\n", payload[1]); + num_modules = payload[1]; + pr_debug("%s: Num modules %d\n", __func__, num_modules); + if (payload[0]) { + pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST, error = %d\n", + __func__, payload[0]); + } else if (num_modules > MAX_MODULES_IN_TOPO) { + pr_err("%s: ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST invalid num modules received, num modules = %d\n", + __func__, num_modules); } else { - idx = ADM_GET_TOPO_MODULE_LIST_LENGTH * - copp_idx; - pr_debug("%s:Num modules payload[1] %d\n", - __func__, payload[1]); - adm_module_topo_list[idx] = payload[1]; - for (i = 1; i <= payload[1]; i++) { - adm_module_topo_list[idx+i] = - payload[1+i]; - pr_debug("%s:payload[%d] = %x\n", - __func__, (i+1), payload[1+i]); - } + ret = adm_process_get_topo_list_response( + data->opcode, copp_idx, num_modules, + payload, data->payload_size); + if (ret) + pr_err("%s: Failed to process get topo modules list response, error %d\n", + __func__, ret); } - atomic_set(&this_adm.copp.stat - [port_idx][copp_idx], payload[0]); + atomic_set(&this_adm.copp.stat[port_idx][copp_idx], + payload[0]); wake_up(&this_adm.copp.wait[port_idx][copp_idx]); break; case ADM_CMDRSP_SHARED_MEM_MAP_REGIONS: @@ -2036,21 +1977,16 @@ static void send_adm_custom_topology(void) } static int send_adm_cal_block(int port_id, int copp_idx, - struct cal_block_data *cal_block, int perf_mode, - int app_type, int acdb_id, int sample_rate) + struct cal_block_data *cal_block, int perf_mode) { - s32 result = 0; - struct adm_cmd_set_pp_params_v5 adm_params; - int port_idx; + struct mem_mapping_hdr mem_hdr; + int payload_size = 0; + int port_idx = 0; + int topology = 0; + int result = 0; + + pr_debug("%s: Port id 0x%x,\n", __func__, port_id); - pr_debug("%s: Port id 0x%x sample_rate %d ,\n", __func__, - port_id, sample_rate); - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0) { - pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); - return -EINVAL; - } if (!cal_block) { pr_debug("%s: No ADM cal to send for port_id = 0x%x!\n", __func__, port_id); @@ -2058,75 +1994,39 @@ static int send_adm_cal_block(int port_id, int copp_idx, goto done; } if (cal_block->cal_data.size <= 0) { - pr_debug("%s: No ADM cal send for port_id = 0x%x!\n", - __func__, port_id); + pr_debug("%s: No ADM cal sent for port_id = 0x%x!\n", __func__, + port_id); result = -EINVAL; goto done; } + memset(&mem_hdr, 0, sizeof(mem_hdr)); + port_id = afe_convert_virtual_to_portid(port_id); + port_idx = adm_validate_and_get_port_index(port_id); + if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { + pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); + return -EINVAL; + } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { + pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx); + return -EINVAL; + } + + topology = atomic_read(&this_adm.copp.topology[port_idx][copp_idx]); if (perf_mode == LEGACY_PCM_MODE && - ((atomic_read(&this_adm.copp.topology[port_idx][copp_idx])) == - DS2_ADM_COPP_TOPOLOGY_ID)) { + topology == DS2_ADM_COPP_TOPOLOGY_ID) { pr_err("%s: perf_mode %d, topology 0x%x\n", __func__, perf_mode, - atomic_read( - &this_adm.copp.topology[port_idx][copp_idx])); + topology); goto done; } - adm_params.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(20), APR_PKT_VER); - adm_params.hdr.pkt_size = sizeof(adm_params); - adm_params.hdr.src_svc = APR_SVC_ADM; - adm_params.hdr.src_domain = APR_DOMAIN_APPS; - adm_params.hdr.src_port = port_id; - adm_params.hdr.dest_svc = APR_SVC_ADM; - adm_params.hdr.dest_domain = APR_DOMAIN_ADSP; + mem_hdr.data_payload_addr_lsw = + lower_32_bits(cal_block->cal_data.paddr); + mem_hdr.data_payload_addr_msw = + msm_audio_populate_upper_32_bits(cal_block->cal_data.paddr); + mem_hdr.mem_map_handle = cal_block->map_data.q6map_handle; + payload_size = cal_block->cal_data.size; - adm_params.hdr.token = port_idx << 16 | copp_idx; - adm_params.hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - adm_params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - adm_params.payload_addr_lsw = lower_32_bits(cal_block->cal_data.paddr); - adm_params.payload_addr_msw = msm_audio_populate_upper_32_bits( - cal_block->cal_data.paddr); - adm_params.mem_map_handle = cal_block->map_data.q6map_handle; - adm_params.payload_size = cal_block->cal_data.size; - - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - pr_debug("%s: Sending SET_PARAMS payload = 0x%pK, size = %d\n", - __func__, &cal_block->cal_data.paddr, - adm_params.payload_size); - result = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_params); - if (result < 0) { - pr_err("%s: Set params failed port 0x%x result %d\n", - __func__, port_id, result); - pr_debug("%s: Set params failed port = 0x%x payload = 0x%pK result %d\n", - __func__, port_id, &cal_block->cal_data.paddr, result); - result = -EINVAL; - goto done; - } - /* Wait for the callback */ - result = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!result) { - pr_err("%s: Set params timed out port = 0x%x\n", - __func__, port_id); - pr_debug("%s: Set params timed out port = 0x%x, payload = 0x%pK\n", - __func__, port_id, &cal_block->cal_data.paddr); - result = -EINVAL; - goto done; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - result = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto done; - } + adm_set_pp_params(port_id, copp_idx, &mem_hdr, NULL, payload_size); done: return result; @@ -2255,8 +2155,7 @@ static int adm_remap_and_send_cal_block(int cal_index, int port_id, __func__, cal_index); goto done; } - ret = send_adm_cal_block(port_id, copp_idx, cal_block, perf_mode, - app_type, acdb_id, sample_rate); + ret = send_adm_cal_block(port_id, copp_idx, cal_block, perf_mode); if (ret < 0) pr_debug("%s: No cal sent for cal_index %d, port_id = 0x%x! ret %d sample_rate %d\n", __func__, cal_index, port_id, ret, sample_rate); @@ -2808,10 +2707,10 @@ EXPORT_SYMBOL(adm_open); */ void adm_copp_mfc_cfg(int port_id, int copp_idx, int dst_sample_rate) { - struct audproc_mfc_output_media_fmt mfc_cfg; + struct audproc_mfc_param_media_fmt mfc_cfg; struct adm_cmd_device_open_v5 open; + struct param_hdr_v3 param_hdr; int port_idx; - int sz = 0; int rc = 0; int i = 0; @@ -2828,32 +2727,15 @@ void adm_copp_mfc_cfg(int port_id, int copp_idx, int dst_sample_rate) goto fail_cmd; } - sz = sizeof(struct audproc_mfc_output_media_fmt); + memset(&mfc_cfg, 0, sizeof(mfc_cfg)); + memset(&open, 0, sizeof(open)); + memset(¶m_hdr, 0, sizeof(param_hdr)); + + param_hdr.module_id = AUDPROC_MODULE_ID_MFC; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT; + param_hdr.param_size = sizeof(mfc_cfg); - mfc_cfg.params.hdr.hdr_field = - APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - mfc_cfg.params.hdr.pkt_size = sz; - mfc_cfg.params.hdr.src_svc = APR_SVC_ADM; - mfc_cfg.params.hdr.src_domain = APR_DOMAIN_APPS; - mfc_cfg.params.hdr.src_port = port_id; - mfc_cfg.params.hdr.dest_svc = APR_SVC_ADM; - mfc_cfg.params.hdr.dest_domain = APR_DOMAIN_ADSP; - mfc_cfg.params.hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - mfc_cfg.params.hdr.token = port_idx << 16 | copp_idx; - mfc_cfg.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - mfc_cfg.params.payload_addr_lsw = 0; - mfc_cfg.params.payload_addr_msw = 0; - mfc_cfg.params.mem_map_handle = 0; - mfc_cfg.params.payload_size = sizeof(mfc_cfg) - - sizeof(mfc_cfg.params); - mfc_cfg.data.module_id = AUDPROC_MODULE_ID_MFC; - mfc_cfg.data.param_id = - AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT; - mfc_cfg.data.param_size = mfc_cfg.params.payload_size - - sizeof(mfc_cfg.data); - mfc_cfg.data.reserved = 0; mfc_cfg.sampling_rate = dst_sample_rate; mfc_cfg.bits_per_sample = atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]); @@ -2879,31 +2761,12 @@ void adm_copp_mfc_cfg(int port_id, int copp_idx, int dst_sample_rate) mfc_cfg.bits_per_sample, mfc_cfg.num_channels, mfc_cfg.sampling_rate); - rc = apr_send_pkt(this_adm.apr, (uint32_t *)&mfc_cfg); + rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, + (uint8_t *) &mfc_cfg); + if (rc) + pr_err("%s: Failed to set media format configuration data, err %d\n", + __func__, rc); - if (rc < 0) { - pr_err("%s: port_id: for[0x%x] failed %d\n", - __func__, port_id, rc); - goto fail_cmd; - } - /* Wait for the callback with copp id */ - rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!rc) { - pr_err("%s: mfc_cfg Set params timed out for port_id: for [0x%x]\n", - __func__, port_id); - goto fail_cmd; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - goto fail_cmd; - } - rc = 0; fail_cmd: return; } @@ -3727,79 +3590,25 @@ static int adm_init_cal_data(void) int adm_set_volume(int port_id, int copp_idx, int volume) { struct audproc_volume_ctrl_master_gain audproc_vol; - int sz = 0; + struct param_hdr_v3 param_hdr; int rc = 0; - int port_idx; pr_debug("%s: port_id %d, volume %d\n", __func__, port_id, volume); - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0) { - pr_err("%s: Invalid port_id %#x\n", __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } - if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { - pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); - return -EINVAL; - } + memset(&audproc_vol, 0, sizeof(audproc_vol)); + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = AUDPROC_MODULE_ID_VOL_CTRL; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = AUDPROC_PARAM_ID_VOL_CTRL_MASTER_GAIN; + param_hdr.param_size = sizeof(audproc_vol); - sz = sizeof(struct audproc_volume_ctrl_master_gain); - audproc_vol.params.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - audproc_vol.params.hdr.pkt_size = sz; - audproc_vol.params.hdr.src_svc = APR_SVC_ADM; - audproc_vol.params.hdr.src_domain = APR_DOMAIN_APPS; - audproc_vol.params.hdr.src_port = port_id; - audproc_vol.params.hdr.dest_svc = APR_SVC_ADM; - audproc_vol.params.hdr.dest_domain = APR_DOMAIN_ADSP; - audproc_vol.params.hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - audproc_vol.params.hdr.token = port_idx << 16 | copp_idx; - audproc_vol.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - audproc_vol.params.payload_addr_lsw = 0; - audproc_vol.params.payload_addr_msw = 0; - audproc_vol.params.mem_map_handle = 0; - audproc_vol.params.payload_size = sizeof(audproc_vol) - - sizeof(audproc_vol.params); - audproc_vol.data.module_id = AUDPROC_MODULE_ID_VOL_CTRL; - audproc_vol.data.param_id = AUDPROC_PARAM_ID_VOL_CTRL_MASTER_GAIN; - audproc_vol.data.param_size = audproc_vol.params.payload_size - - sizeof(audproc_vol.data); - audproc_vol.data.reserved = 0; audproc_vol.master_gain = volume; - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - rc = apr_send_pkt(this_adm.apr, (uint32_t *)&audproc_vol); - if (rc < 0) { - pr_err("%s: Set params failed port = %#x\n", - __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } - /* Wait for the callback */ - rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!rc) { - pr_err("%s: Vol cntrl Set params timed out port = %#x\n", - __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - rc = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto fail_cmd; - } - rc = 0; -fail_cmd: + rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, + (uint8_t *) &audproc_vol); + if (rc) + pr_err("%s: Failed to set volume, err %d\n", __func__, rc); + return rc; } EXPORT_SYMBOL(adm_set_volume); @@ -3818,53 +3627,20 @@ int adm_set_softvolume(int port_id, int copp_idx, struct audproc_softvolume_params *softvol_param) { struct audproc_soft_step_volume_params audproc_softvol; - int sz = 0; + struct param_hdr_v3 param_hdr; int rc = 0; - int port_idx; pr_debug("%s: period %d step %d curve %d\n", __func__, softvol_param->period, softvol_param->step, softvol_param->rampingcurve); - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0) { - pr_err("%s: Invalid port_id %#x\n", __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } + memset(&audproc_softvol, 0, sizeof(audproc_softvol)); + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = AUDPROC_MODULE_ID_VOL_CTRL; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = AUDPROC_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS; + param_hdr.param_size = sizeof(audproc_softvol); - if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { - pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); - return -EINVAL; - } - - sz = sizeof(struct audproc_soft_step_volume_params); - - audproc_softvol.params.hdr.hdr_field = - APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - audproc_softvol.params.hdr.pkt_size = sz; - audproc_softvol.params.hdr.src_svc = APR_SVC_ADM; - audproc_softvol.params.hdr.src_domain = APR_DOMAIN_APPS; - audproc_softvol.params.hdr.src_port = port_id; - audproc_softvol.params.hdr.dest_svc = APR_SVC_ADM; - audproc_softvol.params.hdr.dest_domain = APR_DOMAIN_ADSP; - audproc_softvol.params.hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - audproc_softvol.params.hdr.token = port_idx << 16 | copp_idx; - audproc_softvol.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - audproc_softvol.params.payload_addr_lsw = 0; - audproc_softvol.params.payload_addr_msw = 0; - audproc_softvol.params.mem_map_handle = 0; - audproc_softvol.params.payload_size = sizeof(audproc_softvol) - - sizeof(audproc_softvol.params); - audproc_softvol.data.module_id = AUDPROC_MODULE_ID_VOL_CTRL; - audproc_softvol.data.param_id = - AUDPROC_PARAM_ID_SOFT_VOL_STEPPING_PARAMETERS; - audproc_softvol.data.param_size = audproc_softvol.params.payload_size - - sizeof(audproc_softvol.data); - audproc_softvol.data.reserved = 0; audproc_softvol.period = softvol_param->period; audproc_softvol.step = softvol_param->step; audproc_softvol.ramping_curve = softvol_param->rampingcurve; @@ -3873,36 +3649,11 @@ int adm_set_softvolume(int port_id, int copp_idx, audproc_softvol.period, audproc_softvol.step, audproc_softvol.ramping_curve); - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - rc = apr_send_pkt(this_adm.apr, (uint32_t *)&audproc_softvol); - if (rc < 0) { - pr_err("%s: Set params failed port = %#x\n", - __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } - /* Wait for the callback */ - rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!rc) { - pr_err("%s: Soft volume Set params timed out port = %#x\n", - __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - rc = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto fail_cmd; - } - rc = 0; -fail_cmd: + rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, + (uint8_t *) &audproc_softvol); + if (rc) + pr_err("%s: Failed to set soft volume, err %d\n", __func__, rc); + return rc; } EXPORT_SYMBOL(adm_set_softvolume); @@ -3919,79 +3670,27 @@ EXPORT_SYMBOL(adm_set_softvolume); */ int adm_set_mic_gain(int port_id, int copp_idx, int volume) { - struct adm_set_mic_gain_params mic_gain_params; + struct admx_mic_gain mic_gain_params; + struct param_hdr_v3 param_hdr; int rc = 0; - int sz, port_idx; - pr_debug("%s:\n", __func__); - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0) { - pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); - return -EINVAL; - } + pr_debug("%s: Setting mic gain to %d at port_id 0x%x\n", __func__, + volume, port_id); - sz = sizeof(struct adm_set_mic_gain_params); + memset(&mic_gain_params, 0, sizeof(mic_gain_params)); + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = ADM_MODULE_IDX_MIC_GAIN_CTRL; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = ADM_PARAM_IDX_MIC_GAIN; + param_hdr.param_size = sizeof(mic_gain_params); - mic_gain_params.params.hdr.hdr_field = - APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - mic_gain_params.params.hdr.pkt_size = sz; - mic_gain_params.params.hdr.src_svc = APR_SVC_ADM; - mic_gain_params.params.hdr.src_domain = APR_DOMAIN_APPS; - mic_gain_params.params.hdr.src_port = port_id; - mic_gain_params.params.hdr.dest_svc = APR_SVC_ADM; - mic_gain_params.params.hdr.dest_domain = APR_DOMAIN_ADSP; - mic_gain_params.params.hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - mic_gain_params.params.hdr.token = port_idx << 16 | copp_idx; - mic_gain_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - mic_gain_params.params.payload_addr_lsw = 0; - mic_gain_params.params.payload_addr_msw = 0; - mic_gain_params.params.mem_map_handle = 0; - mic_gain_params.params.payload_size = - sizeof(struct adm_param_data_v5) + - sizeof(struct admx_mic_gain); - mic_gain_params.data.module_id = ADM_MODULE_IDX_MIC_GAIN_CTRL; - mic_gain_params.data.param_id = ADM_PARAM_IDX_MIC_GAIN; - mic_gain_params.data.param_size = - sizeof(struct admx_mic_gain); - mic_gain_params.data.reserved = 0; - mic_gain_params.mic_gain_data.tx_mic_gain = volume; - mic_gain_params.mic_gain_data.reserved = 0; - pr_debug("%s: Mic Gain set to %d at port_id 0x%x\n", - __func__, volume, port_id); + mic_gain_params.tx_mic_gain = volume; + + rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, + (uint8_t *) &mic_gain_params); + if (rc) + pr_err("%s: Failed to set mic gain, err %d\n", __func__, rc); - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - rc = apr_send_pkt(this_adm.apr, (uint32_t *)&mic_gain_params); - if (rc < 0) { - pr_err("%s: Set params failed port = %#x\n", - __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } - /* Wait for the callback */ - rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!rc) { - pr_err("%s: Mic Gain Set params timed out port = %#x\n", - __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - rc = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto fail_cmd; - } - rc = 0; -fail_cmd: return rc; } EXPORT_SYMBOL(adm_set_mic_gain); @@ -4009,88 +3708,29 @@ EXPORT_SYMBOL(adm_set_mic_gain); int adm_send_set_multichannel_ec_primary_mic_ch(int port_id, int copp_idx, int primary_mic_ch) { - struct adm_set_sec_primary_ch_params sec_primary_ch_params; + struct admx_sec_primary_mic_ch sec_primary_ch_params; + struct param_hdr_v3 param_hdr; int rc = 0; - int sz, port_idx; pr_debug("%s port_id 0x%x, copp_idx 0x%x, primary_mic_ch %d\n", __func__, port_id, copp_idx, primary_mic_ch); - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0) { - pr_err("%s: Invalid port_id 0x%x\n", __func__, port_id); - return -EINVAL; - } - if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { - pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx); - return -EINVAL; - } + memset(&sec_primary_ch_params, 0, sizeof(sec_primary_ch_params)); + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = AUDPROC_MODULE_ID_VOICE_TX_SECNS; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = AUDPROC_PARAM_IDX_SEC_PRIMARY_MIC_CH; + param_hdr.param_size = sizeof(sec_primary_ch_params); - sz = sizeof(struct adm_set_sec_primary_ch_params); + sec_primary_ch_params.version = 0; + sec_primary_ch_params.sec_primary_mic_ch = primary_mic_ch; - sec_primary_ch_params.params.hdr.hdr_field = - APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - sec_primary_ch_params.params.hdr.pkt_size = sz; - sec_primary_ch_params.params.hdr.src_svc = APR_SVC_ADM; - sec_primary_ch_params.params.hdr.src_domain = APR_DOMAIN_APPS; - sec_primary_ch_params.params.hdr.src_port = port_id; - sec_primary_ch_params.params.hdr.dest_svc = APR_SVC_ADM; - sec_primary_ch_params.params.hdr.dest_domain = APR_DOMAIN_ADSP; - sec_primary_ch_params.params.hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - sec_primary_ch_params.params.hdr.token = port_idx << 16 | copp_idx; - sec_primary_ch_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - sec_primary_ch_params.params.payload_addr_lsw = 0; - sec_primary_ch_params.params.payload_addr_msw = 0; - sec_primary_ch_params.params.mem_map_handle = 0; - sec_primary_ch_params.params.payload_size = - sizeof(struct adm_param_data_v5) + - sizeof(struct admx_sec_primary_mic_ch); - sec_primary_ch_params.data.module_id = - AUDPROC_MODULE_ID_VOICE_TX_SECNS; - sec_primary_ch_params.data.param_id = - AUDPROC_PARAM_IDX_SEC_PRIMARY_MIC_CH; - sec_primary_ch_params.data.param_size = - sizeof(struct admx_sec_primary_mic_ch); - sec_primary_ch_params.data.reserved = 0; - sec_primary_ch_params.sec_primary_mic_ch_data.version = 0; - sec_primary_ch_params.sec_primary_mic_ch_data.reserved = 0; - sec_primary_ch_params.sec_primary_mic_ch_data.sec_primary_mic_ch = - primary_mic_ch; - sec_primary_ch_params.sec_primary_mic_ch_data.reserved1 = 0; + rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, + (uint8_t *) &sec_primary_ch_params); + if (rc) + pr_err("%s: Failed to set primary mic chanel, err %d\n", + __func__, rc); - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - rc = apr_send_pkt(this_adm.apr, (uint32_t *)&sec_primary_ch_params); - if (rc < 0) { - pr_err("%s: Set params failed port = %#x\n", - __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } - /* Wait for the callback */ - rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!rc) { - pr_err("%s: Mic Set params timed out port = %#x\n", - __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - rc = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto fail_cmd; - } - rc = 0; -fail_cmd: return rc; } EXPORT_SYMBOL(adm_send_set_multichannel_ec_primary_mic_ch); @@ -4108,86 +3748,57 @@ EXPORT_SYMBOL(adm_send_set_multichannel_ec_primary_mic_ch); */ int adm_param_enable(int port_id, int copp_idx, int module_id, int enable) { - struct audproc_enable_param_t adm_mod_enable; - int sz = 0; - int rc = 0; - int port_idx; + struct module_instance_info mod_inst_info; - pr_debug("%s port_id %d, module_id 0x%x, enable %d\n", - __func__, port_id, module_id, enable); - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0) { - pr_err("%s: Invalid port_id %#x\n", __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } + memset(&mod_inst_info, 0, sizeof(mod_inst_info)); + mod_inst_info.module_id = module_id; + mod_inst_info.instance_id = INSTANCE_ID_0; - if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { - pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); + return adm_param_enable_v2(port_id, copp_idx, mod_inst_info, enable); +} + +/** + * adm_param_enable_v2 - + * command to send params to ADM for given module + * + * @port_id: Port ID number + * @copp_idx: copp index assigned + * @mod_inst_info: module and instance ID info + * @enable: flag to enable or disable module + * + * Returns 0 on success or error on failure + */ +int adm_param_enable_v2(int port_id, int copp_idx, + struct module_instance_info mod_inst_info, int enable) +{ + uint32_t enable_param; + struct param_hdr_v3 param_hdr; + int rc = 0; + + if (enable < 0 || enable > 1) { + pr_err("%s: Invalid value for enable %d\n", __func__, enable); return -EINVAL; } - sz = sizeof(struct audproc_enable_param_t); + pr_debug("%s port_id %d, module_id 0x%x, instance_id 0x%x, enable %d\n", + __func__, port_id, mod_inst_info.module_id, + mod_inst_info.instance_id, enable); - adm_mod_enable.pp_params.hdr.hdr_field = - APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - adm_mod_enable.pp_params.hdr.pkt_size = sz; - adm_mod_enable.pp_params.hdr.src_svc = APR_SVC_ADM; - adm_mod_enable.pp_params.hdr.src_domain = APR_DOMAIN_APPS; - adm_mod_enable.pp_params.hdr.src_port = port_id; - adm_mod_enable.pp_params.hdr.dest_svc = APR_SVC_ADM; - adm_mod_enable.pp_params.hdr.dest_domain = APR_DOMAIN_ADSP; - adm_mod_enable.pp_params.hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - adm_mod_enable.pp_params.hdr.token = port_idx << 16 | copp_idx; - adm_mod_enable.pp_params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - adm_mod_enable.pp_params.payload_addr_lsw = 0; - adm_mod_enable.pp_params.payload_addr_msw = 0; - adm_mod_enable.pp_params.mem_map_handle = 0; - adm_mod_enable.pp_params.payload_size = sizeof(adm_mod_enable) - - sizeof(adm_mod_enable.pp_params) + - sizeof(adm_mod_enable.pp_params.params); - adm_mod_enable.pp_params.params.module_id = module_id; - adm_mod_enable.pp_params.params.param_id = AUDPROC_PARAM_ID_ENABLE; - adm_mod_enable.pp_params.params.param_size = - adm_mod_enable.pp_params.payload_size - - sizeof(adm_mod_enable.pp_params.params); - adm_mod_enable.pp_params.params.reserved = 0; - adm_mod_enable.enable = enable; + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = mod_inst_info.module_id; + param_hdr.instance_id = mod_inst_info.instance_id; + param_hdr.param_id = AUDPROC_PARAM_ID_ENABLE; + param_hdr.param_size = sizeof(enable_param); - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); + enable_param = enable; + + rc = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, + (uint8_t *) &enable_param); + if (rc) + pr_err("%s: Failed to set enable of module(%d) instance(%d) to %d, err %d\n", + __func__, mod_inst_info.module_id, + mod_inst_info.instance_id, enable, rc); - rc = apr_send_pkt(this_adm.apr, (uint32_t *)&adm_mod_enable); - if (rc < 0) { - pr_err("%s: Set params failed port = %#x\n", - __func__, port_id); - rc = -EINVAL; - goto fail_cmd; - } - /* Wait for the callback */ - rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!rc) { - pr_err("%s: module %x enable %d timed out on port = %#x\n", - __func__, module_id, enable, port_id); - rc = -EINVAL; - goto fail_cmd; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - rc = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto fail_cmd; - } - rc = 0; -fail_cmd: return rc; } @@ -4211,26 +3822,11 @@ int adm_send_calibration(int port_id, int copp_idx, int path, int perf_mode, int cal_type, char *params, int size) { - struct adm_cmd_set_pp_params_v5 *adm_params = NULL; - int sz, rc = 0; - int port_idx; + int rc = 0; pr_debug("%s:port_id %d, path %d, perf_mode %d, cal_type %d, size %d\n", __func__, port_id, path, perf_mode, cal_type, size); - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0) { - pr_err("%s: Invalid port_id %#x\n", __func__, port_id); - rc = -EINVAL; - goto end; - } - - if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { - pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); - return -EINVAL; - } - /* Maps audio_dev_ctrl path definition to ACDB definition */ if (get_cal_path(path) != RX_DEVICE) { pr_err("%s: acdb_path %d\n", __func__, path); @@ -4238,64 +3834,9 @@ int adm_send_calibration(int port_id, int copp_idx, int path, int perf_mode, goto end; } - sz = sizeof(struct adm_cmd_set_pp_params_v5) + size; - adm_params = kzalloc(sz, GFP_KERNEL); - if (!adm_params) { - pr_err("%s, adm params memory alloc failed", __func__); - rc = -ENOMEM; - goto end; - } - - memcpy(((u8 *)adm_params + sizeof(struct adm_cmd_set_pp_params_v5)), - params, size); - - adm_params->hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - adm_params->hdr.pkt_size = sz; - adm_params->hdr.src_svc = APR_SVC_ADM; - adm_params->hdr.src_domain = APR_DOMAIN_APPS; - adm_params->hdr.src_port = port_id; - adm_params->hdr.dest_svc = APR_SVC_ADM; - adm_params->hdr.dest_domain = APR_DOMAIN_ADSP; - adm_params->hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - adm_params->hdr.token = port_idx << 16 | copp_idx; - adm_params->hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - /* payload address and mmap handle initialized to zero by kzalloc */ - adm_params->payload_size = size; - - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - rc = apr_send_pkt(this_adm.apr, (uint32_t *)adm_params); - if (rc < 0) { - pr_err("%s: Set params failed port = %#x\n", - __func__, port_id); - rc = -EINVAL; - goto end; - } - /* Wait for the callback */ - rc = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!rc) { - pr_err("%s: Set params timed out port = %#x\n", - __func__, port_id); - rc = -EINVAL; - goto end; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - rc = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto end; - } - rc = 0; + rc = adm_set_pp_params(port_id, copp_idx, NULL, (u8 *) params, size); end: - kfree(adm_params); return rc; } EXPORT_SYMBOL(adm_send_calibration); @@ -4526,78 +4067,24 @@ EXPORT_SYMBOL(adm_store_cal_data); */ int adm_send_compressed_device_mute(int port_id, int copp_idx, bool mute_on) { - struct adm_set_compressed_device_mute mute_params; + u32 mute_param = mute_on ? 1 : 0; + struct param_hdr_v3 param_hdr; int ret = 0; - int port_idx; pr_debug("%s port_id: 0x%x, copp_idx %d, mute_on: %d\n", __func__, port_id, copp_idx, mute_on); - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { - pr_err("%s: Invalid port_id %#x copp_idx %d\n", - __func__, port_id, copp_idx); - ret = -EINVAL; - goto end; - } - mute_params.command.hdr.hdr_field = - APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - mute_params.command.hdr.pkt_size = - sizeof(struct adm_set_compressed_device_mute); - mute_params.command.hdr.src_svc = APR_SVC_ADM; - mute_params.command.hdr.src_domain = APR_DOMAIN_APPS; - mute_params.command.hdr.src_port = port_id; - mute_params.command.hdr.dest_svc = APR_SVC_ADM; - mute_params.command.hdr.dest_domain = APR_DOMAIN_ADSP; - mute_params.command.hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - mute_params.command.hdr.token = port_idx << 16 | copp_idx; - mute_params.command.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - mute_params.command.payload_addr_lsw = 0; - mute_params.command.payload_addr_msw = 0; - mute_params.command.mem_map_handle = 0; - mute_params.command.payload_size = sizeof(mute_params) - - sizeof(mute_params.command); - mute_params.params.module_id = AUDPROC_MODULE_ID_COMPRESSED_MUTE; - mute_params.params.param_id = AUDPROC_PARAM_ID_COMPRESSED_MUTE; - mute_params.params.param_size = mute_params.command.payload_size - - sizeof(mute_params.params); - mute_params.params.reserved = 0; - mute_params.mute_on = mute_on; + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = AUDPROC_MODULE_ID_COMPRESSED_MUTE; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = AUDPROC_PARAM_ID_COMPRESSED_MUTE; + param_hdr.param_size = sizeof(mute_param); - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - ret = apr_send_pkt(this_adm.apr, (uint32_t *)&mute_params); - if (ret < 0) { - pr_err("%s: device mute for port %d copp %d failed, ret %d\n", - __func__, port_id, copp_idx, ret); - ret = -EINVAL; - goto end; - } + ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, + (uint8_t *) &mute_param); + if (ret) + pr_err("%s: Failed to set mute, err %d\n", __func__, ret); - /* Wait for the callback */ - ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!ret) { - pr_err("%s: send device mute for port %d copp %d failed\n", - __func__, port_id, copp_idx); - ret = -EINVAL; - goto end; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - ret = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto end; - } - ret = 0; -end: return ret; } EXPORT_SYMBOL(adm_send_compressed_device_mute); @@ -4614,78 +4101,31 @@ EXPORT_SYMBOL(adm_send_compressed_device_mute); */ int adm_send_compressed_device_latency(int port_id, int copp_idx, int latency) { - struct adm_set_compressed_device_latency latency_params; - int port_idx; + u32 latency_param; + struct param_hdr_v3 param_hdr; int ret = 0; pr_debug("%s port_id: 0x%x, copp_idx %d latency: %d\n", __func__, port_id, copp_idx, latency); - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { - pr_err("%s: Invalid port_id %#x copp_idx %d\n", - __func__, port_id, copp_idx); - ret = -EINVAL; - goto end; + + if (latency < 0) { + pr_err("%s: Invalid value for latency %d", __func__, latency); + return -EINVAL; } - latency_params.command.hdr.hdr_field = - APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - latency_params.command.hdr.pkt_size = - sizeof(struct adm_set_compressed_device_latency); - latency_params.command.hdr.src_svc = APR_SVC_ADM; - latency_params.command.hdr.src_domain = APR_DOMAIN_APPS; - latency_params.command.hdr.src_port = port_id; - latency_params.command.hdr.dest_svc = APR_SVC_ADM; - latency_params.command.hdr.dest_domain = APR_DOMAIN_ADSP; - latency_params.command.hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - latency_params.command.hdr.token = port_idx << 16 | copp_idx; - latency_params.command.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - latency_params.command.payload_addr_lsw = 0; - latency_params.command.payload_addr_msw = 0; - latency_params.command.mem_map_handle = 0; - latency_params.command.payload_size = sizeof(latency_params) - - sizeof(latency_params.command); - latency_params.params.module_id = AUDPROC_MODULE_ID_COMPRESSED_LATENCY; - latency_params.params.param_id = AUDPROC_PARAM_ID_COMPRESSED_LATENCY; - latency_params.params.param_size = latency_params.command.payload_size - - sizeof(latency_params.params); - latency_params.params.reserved = 0; - latency_params.latency = latency; + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = AUDPROC_MODULE_ID_COMPRESSED_LATENCY; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = AUDPROC_PARAM_ID_COMPRESSED_LATENCY; + param_hdr.param_size = sizeof(latency_param); - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - ret = apr_send_pkt(this_adm.apr, (uint32_t *)&latency_params); - if (ret < 0) { - pr_err("%s: send device latency err %d for port %d copp %d\n", - __func__, port_id, copp_idx, ret); - ret = -EINVAL; - goto end; - } + latency_param = latency; + + ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, + (uint8_t *) &latency_param); + if (ret) + pr_err("%s: Failed to set latency, err %d\n", __func__, ret); - /* Wait for the callback */ - ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!ret) { - pr_err("%s: send device latency for port %d failed\n", __func__, - port_id); - ret = -EINVAL; - goto end; - } else if (atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - ret = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto end; - } - ret = 0; -end: return ret; } EXPORT_SYMBOL(adm_send_compressed_device_latency); @@ -4705,9 +4145,10 @@ EXPORT_SYMBOL(adm_send_compressed_device_latency); int adm_swap_speaker_channels(int port_id, int copp_idx, int sample_rate, bool spk_swap) { - struct audproc_mfc_output_media_fmt mfc_cfg; + struct audproc_mfc_param_media_fmt mfc_cfg; + struct param_hdr_v3 param_hdr; uint16_t num_channels; - int port_idx; + int port_idx = 0; int ret = 0; pr_debug("%s: Enter, port_id %d, copp_idx %d\n", @@ -4716,50 +4157,27 @@ int adm_swap_speaker_channels(int port_id, int copp_idx, port_idx = adm_validate_and_get_port_index(port_id); if (port_idx < 0 || port_idx >= AFE_MAX_PORTS) { pr_err("%s: Invalid port_id %#x\n", __func__, port_id); - ret = -EINVAL; - goto done; + return -EINVAL; + } else if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { + pr_err("%s: Invalid copp_idx 0x%x\n", __func__, copp_idx); + return -EINVAL; } - if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { - pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); - ret = -EINVAL; - goto done; - } - - num_channels = atomic_read( - &this_adm.copp.channels[port_idx][copp_idx]); + num_channels = atomic_read(&this_adm.copp.channels[port_idx][copp_idx]); if (num_channels != 2) { pr_debug("%s: Invalid number of channels: %d\n", __func__, num_channels); - ret = -EINVAL; - goto done; + return -EINVAL; } memset(&mfc_cfg, 0, sizeof(mfc_cfg)); - mfc_cfg.params.hdr.hdr_field = - APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - mfc_cfg.params.hdr.pkt_size = - sizeof(mfc_cfg); - mfc_cfg.params.hdr.src_svc = APR_SVC_ADM; - mfc_cfg.params.hdr.src_domain = APR_DOMAIN_APPS; - mfc_cfg.params.hdr.src_port = port_id; - mfc_cfg.params.hdr.dest_svc = APR_SVC_ADM; - mfc_cfg.params.hdr.dest_domain = APR_DOMAIN_ADSP; - mfc_cfg.params.hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - mfc_cfg.params.hdr.token = port_idx << 16 | copp_idx; - mfc_cfg.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - mfc_cfg.params.payload_addr_lsw = 0; - mfc_cfg.params.payload_addr_msw = 0; - mfc_cfg.params.mem_map_handle = 0; - mfc_cfg.params.payload_size = sizeof(mfc_cfg) - - sizeof(mfc_cfg.params); - mfc_cfg.data.module_id = AUDPROC_MODULE_ID_MFC; - mfc_cfg.data.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT; - mfc_cfg.data.param_size = mfc_cfg.params.payload_size - - sizeof(mfc_cfg.data); - mfc_cfg.data.reserved = 0; + memset(¶m_hdr, 0, sizeof(param_hdr)); + + param_hdr.module_id = AUDPROC_MODULE_ID_MFC; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = AUDPROC_PARAM_ID_MFC_OUTPUT_MEDIA_FORMAT; + param_hdr.param_size = sizeof(mfc_cfg); + mfc_cfg.sampling_rate = sample_rate; mfc_cfg.bits_per_sample = atomic_read(&this_adm.copp.bit_width[port_idx][copp_idx]); @@ -4778,45 +4196,16 @@ int adm_swap_speaker_channels(int port_id, int copp_idx, (uint16_t) PCM_CHANNEL_FR; } - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - pr_debug("%s: mfc config: port_idx %d copp_idx %d copp SR %d copp BW %d copp chan %d\n", - __func__, port_idx, copp_idx, mfc_cfg.sampling_rate, - mfc_cfg.bits_per_sample, mfc_cfg.num_channels); - - ret = apr_send_pkt(this_adm.apr, (uint32_t *)&mfc_cfg); + ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, + (u8 *) &mfc_cfg); if (ret < 0) { - pr_err("%s: port_id: for[0x%x] failed %d\n", - __func__, port_id, ret); - goto done; - } - /* Wait for the callback with copp id */ - ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!ret) { - pr_err("%s: mfc_cfg Set params timed out for port_id: for [0x%x]\n", - __func__, port_id); - ret = -ETIMEDOUT; - goto done; - } - - if (atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx]))); - ret = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [port_idx][copp_idx])); - goto done; + pr_err("%s: Failed to set swap speaker channels on port[0x%x] failed %d\n", + __func__, port_id, ret); + return ret; } pr_debug("%s: mfc_cfg Set params returned success", __func__); - ret = 0; - -done: - return ret; + return 0; } EXPORT_SYMBOL(adm_swap_speaker_channels); @@ -4833,108 +4222,41 @@ EXPORT_SYMBOL(adm_swap_speaker_channels); int adm_set_sound_focus(int port_id, int copp_idx, struct sound_focus_param soundFocusData) { - struct adm_set_fluence_soundfocus_param soundfocus_params; - int sz = 0; + struct adm_param_fluence_soundfocus_t soundfocus_params; + struct param_hdr_v3 param_hdr; int ret = 0; - int port_idx; int i; pr_debug("%s: Enter, port_id %d, copp_idx %d\n", __func__, port_id, copp_idx); - port_id = afe_convert_virtual_to_portid(port_id); - port_idx = adm_validate_and_get_port_index(port_id); - if (port_idx < 0) { - pr_err("%s: Invalid port_id %#x\n", __func__, port_id); + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = VOICEPROC_MODULE_ID_GENERIC_TX; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS; + param_hdr.param_size = sizeof(soundfocus_params); - ret = -EINVAL; - goto done; - } - - if (copp_idx < 0 || copp_idx >= MAX_COPPS_PER_PORT) { - pr_err("%s: Invalid copp_num: %d\n", __func__, copp_idx); - - ret = -EINVAL; - goto done; - } - - sz = sizeof(struct adm_set_fluence_soundfocus_param); - soundfocus_params.params.hdr.hdr_field = - APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, APR_HDR_LEN(APR_HDR_SIZE), - APR_PKT_VER); - soundfocus_params.params.hdr.pkt_size = sz; - soundfocus_params.params.hdr.src_svc = APR_SVC_ADM; - soundfocus_params.params.hdr.src_domain = APR_DOMAIN_APPS; - soundfocus_params.params.hdr.src_port = port_id; - soundfocus_params.params.hdr.dest_svc = APR_SVC_ADM; - soundfocus_params.params.hdr.dest_domain = APR_DOMAIN_ADSP; - soundfocus_params.params.hdr.dest_port = - atomic_read(&this_adm.copp.id[port_idx][copp_idx]); - soundfocus_params.params.hdr.token = port_idx << 16 | - ADM_CLIENT_ID_SOURCE_TRACKING << 8 | copp_idx; - soundfocus_params.params.hdr.opcode = ADM_CMD_SET_PP_PARAMS_V5; - soundfocus_params.params.payload_addr_lsw = 0; - soundfocus_params.params.payload_addr_msw = 0; - soundfocus_params.params.mem_map_handle = 0; - soundfocus_params.params.payload_size = sizeof(soundfocus_params) - - sizeof(soundfocus_params.params); - soundfocus_params.data.module_id = VOICEPROC_MODULE_ID_GENERIC_TX; - soundfocus_params.data.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS; - soundfocus_params.data.param_size = - soundfocus_params.params.payload_size - - sizeof(soundfocus_params.data); - soundfocus_params.data.reserved = 0; - - memset(&(soundfocus_params.soundfocus_data), 0xFF, - sizeof(struct adm_param_fluence_soundfocus_t)); + memset(&(soundfocus_params), 0xFF, sizeof(soundfocus_params)); for (i = 0; i < MAX_SECTORS; i++) { - soundfocus_params.soundfocus_data.start_angles[i] = + soundfocus_params.start_angles[i] = soundFocusData.start_angle[i]; - soundfocus_params.soundfocus_data.enables[i] = - soundFocusData.enable[i]; + soundfocus_params.enables[i] = soundFocusData.enable[i]; pr_debug("%s: start_angle[%d] = %d\n", __func__, i, soundFocusData.start_angle[i]); pr_debug("%s: enable[%d] = %d\n", __func__, i, soundFocusData.enable[i]); } - soundfocus_params.soundfocus_data.gain_step = - soundFocusData.gain_step; + soundfocus_params.gain_step = soundFocusData.gain_step; pr_debug("%s: gain_step = %d\n", __func__, soundFocusData.gain_step); - soundfocus_params.soundfocus_data.reserved = 0; + soundfocus_params.reserved = 0; - atomic_set(&this_adm.copp.stat[port_idx][copp_idx], -1); - ret = apr_send_pkt(this_adm.apr, (uint32_t *)&soundfocus_params); - if (ret < 0) { - pr_err("%s: Set params failed\n", __func__); + ret = adm_pack_and_set_one_pp_param(port_id, copp_idx, param_hdr, + (uint8_t *) &soundfocus_params); + if (ret) + pr_err("%s: Failed to set sound focus params, err %d\n", + __func__, ret); - ret = -EINVAL; - goto done; - } - /* Wait for the callback */ - ret = wait_event_timeout(this_adm.copp.wait[port_idx][copp_idx], - atomic_read(&this_adm.copp.stat[port_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!ret) { - pr_err("%s: Set params timed out\n", __func__); - - ret = -EINVAL; - goto done; - } - - if (this_adm.sourceTrackingData.apr_cmd_status != 0) { - pr_err("%s - set params returned error [%s]\n", - __func__, adsp_err_get_err_str( - this_adm.sourceTrackingData.apr_cmd_status)); - - ret = adsp_err_get_lnx_err_code( - this_adm.sourceTrackingData.apr_cmd_status); - goto done; - } - - ret = 0; - -done: pr_debug("%s: Exit, ret=%d\n", __func__, ret); return ret; @@ -4956,28 +4278,29 @@ int adm_get_sound_focus(int port_id, int copp_idx, { int ret = 0, i; char *params_value; - uint32_t param_payload_len = sizeof(struct adm_param_data_v5) + - sizeof(struct adm_param_fluence_soundfocus_t); - struct adm_param_fluence_soundfocus_t *soundfocus_params; + uint32_t max_param_size = 0; + struct adm_param_fluence_soundfocus_t *soundfocus_params = NULL; + struct param_hdr_v3 param_hdr; pr_debug("%s: Enter, port_id %d, copp_idx %d\n", __func__, port_id, copp_idx); - params_value = kzalloc(param_payload_len, GFP_KERNEL); - if (!params_value) { - ret = -ENOMEM; - goto done; - } - ret = adm_get_params_v2(port_id, copp_idx, - VOICEPROC_MODULE_ID_GENERIC_TX, - VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS, - param_payload_len, - params_value, - ADM_CLIENT_ID_SOURCE_TRACKING); + max_param_size = sizeof(struct adm_param_fluence_soundfocus_t) + + sizeof(union param_hdrs); + params_value = kzalloc(max_param_size, GFP_KERNEL); + if (!params_value) + return -ENOMEM; + + memset(¶m_hdr, 0, sizeof(param_hdr)); + param_hdr.module_id = VOICEPROC_MODULE_ID_GENERIC_TX; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOUNDFOCUS; + param_hdr.param_size = max_param_size; + ret = adm_get_pp_params(port_id, copp_idx, + ADM_CLIENT_ID_SOURCE_TRACKING, NULL, ¶m_hdr, + params_value); if (ret) { pr_err("%s: get parameters failed ret:%d\n", __func__, ret); - - kfree(params_value); ret = -EINVAL; goto done; } @@ -4986,8 +4309,6 @@ int adm_get_sound_focus(int port_id, int copp_idx, pr_err("%s - get params returned error [%s]\n", __func__, adsp_err_get_err_str( this_adm.sourceTrackingData.apr_cmd_status)); - - kfree(params_value); ret = adsp_err_get_lnx_err_code( this_adm.sourceTrackingData.apr_cmd_status); goto done; @@ -5007,11 +4328,10 @@ int adm_get_sound_focus(int port_id, int copp_idx, soundFocusData->gain_step = soundfocus_params->gain_step; pr_debug("%s: gain_step = %d\n", __func__, soundFocusData->gain_step); - kfree(params_value); - done: pr_debug("%s: Exit, ret = %d\n", __func__, ret); + kfree(params_value); return ret; } EXPORT_SYMBOL(adm_get_sound_focus); @@ -5083,9 +4403,12 @@ static int adm_source_tracking_alloc_map_memory(void) int adm_get_source_tracking(int port_id, int copp_idx, struct source_tracking_param *sourceTrackingData) { - struct adm_cmd_get_pp_params_v5 admp; - int p_idx, ret = 0, i; - struct adm_param_fluence_sourcetracking_t *source_tracking_params; + struct adm_param_fluence_sourcetracking_t *source_tracking_params = + NULL; + struct mem_mapping_hdr mem_hdr; + struct param_hdr_v3 param_hdr; + int i = 0; + int ret = 0; pr_debug("%s: Enter, port_id %d, copp_idx %d\n", __func__, port_id, copp_idx); @@ -5099,68 +4422,36 @@ int adm_get_source_tracking(int port_id, int copp_idx, } } - port_id = afe_convert_virtual_to_portid(port_id); - p_idx = adm_validate_and_get_port_index(port_id); - if (p_idx < 0) { - pr_err("%s - invalid port index %i, port id %i, copp idx %i\n", - __func__, p_idx, port_id, copp_idx); - - ret = -EINVAL; - goto done; - } - - admp.hdr.hdr_field = APR_HDR_FIELD(APR_MSG_TYPE_SEQ_CMD, - APR_HDR_LEN(APR_HDR_SIZE), APR_PKT_VER); - admp.hdr.pkt_size = sizeof(admp); - admp.hdr.src_svc = APR_SVC_ADM; - admp.hdr.src_domain = APR_DOMAIN_APPS; - admp.hdr.src_port = port_id; - admp.hdr.dest_svc = APR_SVC_ADM; - admp.hdr.dest_domain = APR_DOMAIN_ADSP; - admp.hdr.dest_port = atomic_read(&this_adm.copp.id[p_idx][copp_idx]); - admp.hdr.token = p_idx << 16 | ADM_CLIENT_ID_SOURCE_TRACKING << 8 | - copp_idx; - admp.hdr.opcode = ADM_CMD_GET_PP_PARAMS_V5; - admp.data_payload_addr_lsw = + memset(&mem_hdr, 0, sizeof(mem_hdr)); + memset(¶m_hdr, 0, sizeof(param_hdr)); + mem_hdr.data_payload_addr_lsw = lower_32_bits(this_adm.sourceTrackingData.memmap.paddr); - admp.data_payload_addr_msw = - msm_audio_populate_upper_32_bits( - this_adm.sourceTrackingData.memmap.paddr); - admp.mem_map_handle = atomic_read(&this_adm.mem_map_handles[ - ADM_MEM_MAP_INDEX_SOURCE_TRACKING]); - admp.module_id = VOICEPROC_MODULE_ID_GENERIC_TX; - admp.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOURCETRACKING; - admp.param_max_size = sizeof(struct adm_param_fluence_sourcetracking_t) - + sizeof(struct adm_param_data_v5); - admp.reserved = 0; + mem_hdr.data_payload_addr_msw = msm_audio_populate_upper_32_bits( + this_adm.sourceTrackingData.memmap.paddr); + mem_hdr.mem_map_handle = atomic_read( + &this_adm.mem_map_handles[ADM_MEM_MAP_INDEX_SOURCE_TRACKING]); - atomic_set(&this_adm.copp.stat[p_idx][copp_idx], -1); + param_hdr.module_id = VOICEPROC_MODULE_ID_GENERIC_TX; + param_hdr.instance_id = INSTANCE_ID_0; + param_hdr.param_id = VOICEPROC_PARAM_ID_FLUENCE_SOURCETRACKING; + /* + * This size should be the max size of the calibration data + header. + * Use the union size to ensure max size is used. + */ + param_hdr.param_size = + sizeof(struct adm_param_fluence_sourcetracking_t) + + sizeof(union param_hdrs); - ret = apr_send_pkt(this_adm.apr, (uint32_t *)&admp); - if (ret < 0) { - pr_err("%s - failed to get Source Tracking Params\n", - __func__); - - ret = -EINVAL; - goto done; - } - ret = wait_event_timeout(this_adm.copp.wait[p_idx][copp_idx], - atomic_read(&this_adm.copp.stat[p_idx][copp_idx]) >= 0, - msecs_to_jiffies(TIMEOUT_MS)); - if (!ret) { - pr_err("%s - get params timed out\n", __func__); - - ret = -EINVAL; - goto done; - } else if (atomic_read(&this_adm.copp.stat - [p_idx][copp_idx]) > 0) { - pr_err("%s: DSP returned error[%s]\n", - __func__, adsp_err_get_err_str( - atomic_read(&this_adm.copp.stat - [p_idx][copp_idx]))); - ret = adsp_err_get_lnx_err_code( - atomic_read(&this_adm.copp.stat - [p_idx][copp_idx])); + /* + * Retrieving parameters out of band, so no need to provide a buffer for + * the returned parameter data as it will be at the memory location + * provided. + */ + ret = adm_get_pp_params(port_id, copp_idx, + ADM_CLIENT_ID_SOURCE_TRACKING, &mem_hdr, + ¶m_hdr, NULL); + if (ret) { + pr_err("%s: Failed to get params, error %d\n", __func__, ret); goto done; } @@ -5174,9 +4465,11 @@ int adm_get_source_tracking(int port_id, int copp_idx, goto done; } - source_tracking_params = (struct adm_param_fluence_sourcetracking_t *) - (this_adm.sourceTrackingData.memmap.kvaddr + - sizeof(struct adm_param_data_v5)); + /* How do we know what the param data was retrieved with for hdr size */ + source_tracking_params = + (struct adm_param_fluence_sourcetracking_t + *) (this_adm.sourceTrackingData.memmap.kvaddr + + sizeof(struct param_hdr_v1)); for (i = 0; i < MAX_SECTORS; i++) { sourceTrackingData->vad[i] = source_tracking_params->vad[i]; pr_debug("%s: vad[%d] = %d\n", @@ -5212,36 +4505,16 @@ int __init adm_init(void) { int i = 0, j; - this_adm.apr = NULL; this_adm.ec_ref_rx = -1; - this_adm.num_ec_ref_rx_chans = 0; - this_adm.ec_ref_rx_bit_width = 0; - this_adm.ec_ref_rx_sampling_rate = 0; - atomic_set(&this_adm.matrix_map_stat, 0); init_waitqueue_head(&this_adm.matrix_map_wait); - atomic_set(&this_adm.adm_stat, 0); init_waitqueue_head(&this_adm.adm_wait); for (i = 0; i < AFE_MAX_PORTS; i++) { for (j = 0; j < MAX_COPPS_PER_PORT; j++) { atomic_set(&this_adm.copp.id[i][j], RESET_COPP_ID); - atomic_set(&this_adm.copp.cnt[i][j], 0); - atomic_set(&this_adm.copp.topology[i][j], 0); - atomic_set(&this_adm.copp.mode[i][j], 0); - atomic_set(&this_adm.copp.stat[i][j], 0); - atomic_set(&this_adm.copp.rate[i][j], 0); - atomic_set(&this_adm.copp.channels[i][j], 0); - atomic_set(&this_adm.copp.bit_width[i][j], 0); - atomic_set(&this_adm.copp.app_type[i][j], 0); - atomic_set(&this_adm.copp.acdb_id[i][j], 0); init_waitqueue_head(&this_adm.copp.wait[i][j]); - atomic_set(&this_adm.copp.adm_delay_stat[i][j], 0); init_waitqueue_head( &this_adm.copp.adm_delay_wait[i][j]); - atomic_set(&this_adm.copp.topology[i][j], 0); - this_adm.copp.adm_delay[i][j] = 0; - this_adm.copp.adm_status[i][j] = - ADM_STATUS_CALIBRATION_REQUIRED; } } @@ -5253,9 +4526,6 @@ int __init adm_init(void) this_adm.sourceTrackingData.memmap.kvaddr = NULL; this_adm.sourceTrackingData.memmap.paddr = 0; this_adm.sourceTrackingData.apr_cmd_status = -1; - atomic_set(&this_adm.mem_map_handles[ADM_MEM_MAP_INDEX_SOURCE_TRACKING], - 0); - mutex_init(&dts_srs_lock); return 0; } @@ -5264,6 +4534,5 @@ void adm_exit(void) { if (this_adm.apr) adm_reset_data(); - mutex_destroy(&dts_srs_lock); adm_delete_cal_data(); } diff --git a/include/dsp/apr_audio-v2.h b/include/dsp/apr_audio-v2.h index d068e683ff75..8438c37bea70 100644 --- a/include/dsp/apr_audio-v2.h +++ b/include/dsp/apr_audio-v2.h @@ -500,54 +500,38 @@ struct adm_cmd_device_open_v6 { #define ADM_CMD_SET_PP_PARAMS_V5 0x00010328 #define ADM_CMD_SET_PP_PARAMS_V6 0x0001035D -/* Payload of the #ADM_CMD_SET_PP_PARAMS_V5 command. - * If the data_payload_addr_lsw and data_payload_addr_msw element - * are NULL, a series of adm_param_datastructures immediately - * follows, whose total size is data_payload_size bytes. +/* + * Structure of the ADM Set PP Params command. Parameter data must be + * pre-packed with correct header for either V2 or V3 when sent in-band. + * Use q6core_pack_pp_params to pack the header and data correctly depending on + * Instance ID support. */ -struct adm_cmd_set_pp_params_v5 { - struct apr_hdr hdr; - u32 payload_addr_lsw; -/* LSW of parameter data payload address. */ - u32 payload_addr_msw; -/* MSW of parameter data payload address. */ +struct adm_cmd_set_pp_params { + /* APR Header */ + struct apr_hdr apr_hdr; - u32 mem_map_handle; -/* Memory map handle returned by ADM_CMD_SHARED_MEM_MAP_REGIONS - * command - * - * If mem_map_handle is zero implies the message is in - * the payload - */ + /* The memory mapping header to be used when sending out of band */ + struct mem_mapping_hdr mem_hdr; - u32 payload_size; -/* Size in bytes of the variable payload accompanying this - * message or - * in shared memory. This is used for parsing the parameter - * payload. - */ + /* + * Size in bytes of the variable payload accompanying this + * message or + * in shared memory. This is used for parsing the parameter + * payload. + */ + u32 payload_size; + + /* + * Parameter data for in band payload. This should be structured as the + * parameter header immediately followed by the parameter data. Multiple + * parameters can be set in one command by repeating the header followed + * by the data for as many parameters as need to be set. + * Use q6core_pack_pp_params to pack the header and data correctly + * depending on Instance ID support. + */ + u8 param_data[0]; } __packed; -/* Payload format for COPP parameter data. - * Immediately following this structure are param_size bytes - * of parameter - * data. - */ -struct adm_param_data_v5 { - u32 module_id; - /* Unique ID of the module. */ - u32 param_id; - /* Unique ID of the parameter. */ - u16 param_size; - /* Data size of the param_id/module_id combination. - * This value is a - * multiple of 4 bytes. - */ - u16 reserved; - /* Reserved for future enhancements. - * This field must be set to zero. - */ -} __packed; #define ASM_STREAM_CMD_REGISTER_PP_EVENTS 0x00013213 #define ASM_STREAM_PP_EVENT 0x00013214 @@ -591,25 +575,6 @@ struct adm_cmd_set_pspd_mtmx_strtr_params_v5 { u16 reserved; } __packed; -/* Defined specifically for in-band use, includes params */ -struct adm_cmd_set_pp_params_inband_v5 { - struct apr_hdr hdr; - /* LSW of parameter data payload address.*/ - u32 payload_addr_lsw; - /* MSW of parameter data payload address.*/ - u32 payload_addr_msw; - /* Memory map handle returned by ADM_CMD_SHARED_MEM_MAP_REGIONS */ - /* command. If mem_map_handle is zero implies the message is in */ - /* the payload */ - u32 mem_map_handle; - /* Size in bytes of the variable payload accompanying this */ - /* message or in shared memory. This is used for parsing the */ - /* parameter payload. */ - u32 payload_size; - /* Parameters passed for in band payload */ - struct adm_param_data_v5 params; -} __packed; - /* Returns the status and COPP ID to an #ADM_CMD_DEVICE_OPEN_V5 command. */ #define ADM_CMDRSP_DEVICE_OPEN_V5 0x00010329 @@ -642,42 +607,19 @@ struct adm_cmd_rsp_device_open_v5 { #define ADM_CMD_GET_PP_PARAMS_V5 0x0001032A #define ADM_CMD_GET_PP_PARAMS_V6 0x0001035E -/* Payload an #ADM_CMD_GET_PP_PARAMS_V5 command. */ -struct adm_cmd_get_pp_params_v5 { - struct apr_hdr hdr; - u32 data_payload_addr_lsw; - /* LSW of parameter data payload address.*/ +/* + * Structure of the ADM Get PP Params command. Parameter header must be + * packed correctly for either V2 or V3. Use q6core_pack_pp_params to pack the + * header correctly depending on Instance ID support. + */ +struct adm_cmd_get_pp_params { + struct apr_hdr apr_hdr; - u32 data_payload_addr_msw; - /* MSW of parameter data payload address.*/ + /* The memory mapping header to be used when requesting outband */ + struct mem_mapping_hdr mem_hdr; - /* If the mem_map_handle is non zero, - * on ACK, the ParamData payloads begin at - * the address specified (out-of-band). - */ - - u32 mem_map_handle; - /* Memory map handle returned - * by ADM_CMD_SHARED_MEM_MAP_REGIONS command. - * If the mem_map_handle is 0, it implies that - * the ACK's payload will contain the ParamData (in-band). - */ - - u32 module_id; - /* Unique ID of the module. */ - - u32 param_id; - /* Unique ID of the parameter. */ - - u16 param_max_size; - /* Maximum data size of the parameter - *ID/module ID combination. This - * field is a multiple of 4 bytes. - */ - u16 reserved; - /* Reserved for future enhancements. - * This field must be set to zero. - */ + /* Parameter header for in band payload. */ + union param_hdrs param_hdr; } __packed; /* Returns parameter values @@ -689,15 +631,49 @@ struct adm_cmd_get_pp_params_v5 { * which returns parameter values in response * to an #ADM_CMD_GET_PP_PARAMS_V5 command. * Immediately following this - * structure is the adm_param_data_v5 + * structure is the param_hdr_v1 * structure containing the pre/postprocessing * parameter data. For an in-band * scenario, the variable payload depends * on the size of the parameter. */ struct adm_cmd_rsp_get_pp_params_v5 { - u32 status; /* Status message (error code).*/ + u32 status; + + /* The header that identifies the subsequent parameter data */ + struct param_hdr_v1 param_hdr; + + /* The parameter data returned */ + u32 param_data[0]; +} __packed; + +/* + * Returns parameter values in response to an #ADM_CMD_GET_PP_PARAMS_V5/6 + * command. + */ +#define ADM_CMDRSP_GET_PP_PARAMS_V6 0x0001035F + +/* + * Payload of the #ADM_CMDRSP_GET_PP_PARAMS_V6 message, + * which returns parameter values in response + * to an #ADM_CMD_GET_PP_PARAMS_V6 command. + * Immediately following this + * structure is the param_hdr_v3 + * structure containing the pre/postprocessing + * parameter data. For an in-band + * scenario, the variable payload depends + * on the size of the parameter. + */ +struct adm_cmd_rsp_get_pp_params_v6 { + /* Status message (error code).*/ + u32 status; + + /* The header that identifies the subsequent parameter data */ + struct param_hdr_v3 param_hdr; + + /* The parameter data returned */ + u32 param_data[0]; } __packed; /* Structure for holding soft stepping volume parameters. */ @@ -730,9 +706,40 @@ struct audproc_softvolume_params { #define AUDPROC_CHMIXER_PARAM_ID_COEFF 0x00010342 +struct adm_cmd_set_pp_params_v5 { + struct apr_hdr hdr; + u32 payload_addr_lsw; + /* LSW of parameter data payload address.*/ + u32 payload_addr_msw; + /* MSW of parameter data payload address.*/ + + u32 mem_map_handle; + /* + * Memory map handle returned by ADM_CMD_SHARED_MEM_MAP_REGIONS + * command. + * If mem_map_handle is zero implies the message is in + * the payload + */ + + u32 payload_size; + /* + * Size in bytes of the variable payload accompanying this + * message or + * in shared memory. This is used for parsing the parameter + * payload. + */ +} __packed; + struct audproc_mfc_output_media_fmt { struct adm_cmd_set_pp_params_v5 params; - struct adm_param_data_v5 data; + struct param_hdr_v1 data; + uint32_t sampling_rate; + uint16_t bits_per_sample; + uint16_t num_channels; + uint16_t channel_type[8]; +} __packed; + +struct audproc_mfc_param_media_fmt { uint32_t sampling_rate; uint16_t bits_per_sample; uint16_t num_channels; @@ -740,8 +747,6 @@ struct audproc_mfc_output_media_fmt { } __packed; struct audproc_volume_ctrl_master_gain { - struct adm_cmd_set_pp_params_v5 params; - struct adm_param_data_v5 data; /* Linear gain in Q13 format. */ uint16_t master_gain; /* Clients must set this field to zero. */ @@ -749,8 +754,6 @@ struct audproc_volume_ctrl_master_gain { } __packed; struct audproc_soft_step_volume_params { - struct adm_cmd_set_pp_params_v5 params; - struct adm_param_data_v5 data; /* * Period in milliseconds. * Supported values: 0 to 15000 @@ -772,7 +775,6 @@ struct audproc_soft_step_volume_params { } __packed; struct audproc_enable_param_t { - struct adm_cmd_set_pp_params_inband_v5 pp_params; /* * Specifies whether the Audio processing module is enabled. * This parameter is generic/common parameter to configure or @@ -7614,12 +7616,6 @@ struct admx_mic_gain { /*< Clients must set this field to zero. */ } __packed; -struct adm_set_mic_gain_params { - struct adm_cmd_set_pp_params_v5 params; - struct adm_param_data_v5 data; - struct admx_mic_gain mic_gain_data; -} __packed; - /* end_addtogroup audio_pp_param_ids */ /* @ingroup audio_pp_module_ids @@ -7977,56 +7973,23 @@ struct adm_qensemble_param_set_new_angle { #define ADM_CMD_GET_PP_TOPO_MODULE_LIST 0x00010349 #define ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST 0x00010350 +#define ADM_CMD_GET_PP_TOPO_MODULE_LIST_V2 0x00010360 +#define ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST_V2 0x00010361 #define AUDPROC_PARAM_ID_ENABLE 0x00010904 - /* - * Payload of the ADM_CMD_GET_PP_TOPO_MODULE_LIST command. - */ -struct adm_cmd_get_pp_topo_module_list_t { - struct apr_hdr hdr; - /* Lower 32 bits of the 64-bit parameter data payload address. */ - uint32_t data_payload_addr_lsw; - /* - * Upper 32 bits of the 64-bit parameter data payload address. - * - * - * The size of the shared memory, if specified, must be large enough to - * contain the entire parameter data payload, including the module ID, - * parameter ID, parameter size, and parameter values. - */ - uint32_t data_payload_addr_msw; - /* - * Unique identifier for an address. - * - * This memory map handle is returned by the aDSP through the - * #ADM_CMD_SHARED_MEM_MAP_REGIONS command. - * - * @values - * - Non-NULL -- On acknowledgment, the parameter data payloads begin at - * the address specified (out-of-band) - * - NULL -- The acknowledgment's payload contains the parameter data - * (in-band) @tablebulletend - */ - uint32_t mem_map_handle; +/* + * Payload of the ADM_CMD_GET_PP_TOPO_MODULE_LIST command. + */ +struct adm_cmd_get_pp_topo_module_list { + struct apr_hdr apr_hdr; + + /* The memory mapping header to be used when requesting out of band */ + struct mem_mapping_hdr mem_hdr; + /* * Maximum data size of the list of modules. This * field is a multiple of 4 bytes. */ - uint16_t param_max_size; - /* This field must be set to zero. */ - uint16_t reserved; -} __packed; - -/* - * Payload of the ADM_CMDRSP_GET_PP_TOPO_MODULE_LIST message, which returns - * module ids in response to an ADM_CMD_GET_PP_TOPO_MODULE_LIST command. - * Immediately following this structure is the acknowledgment module id - * data variable payload containing the pre/postprocessing module id - * values. For an in-band scenario, the variable payload depends on the size - * of the parameter. - */ -struct adm_cmd_rsp_get_pp_topo_module_list_t { - /* Status message (error code). */ - uint32_t status; + uint32_t param_max_size; } __packed; struct audproc_topology_module_id_info_t { @@ -10926,18 +10889,14 @@ enum { #define AUDPROC_PARAM_ID_COMPRESSED_MUTE 0x00010771 struct adm_set_compressed_device_mute { - struct adm_cmd_set_pp_params_v5 command; - struct adm_param_data_v5 params; - u32 mute_on; + u32 mute_on; } __packed; #define AUDPROC_MODULE_ID_COMPRESSED_LATENCY 0x0001076E #define AUDPROC_PARAM_ID_COMPRESSED_LATENCY 0x0001076F struct adm_set_compressed_device_latency { - struct adm_cmd_set_pp_params_v5 command; - struct adm_param_data_v5 params; - u32 latency; + u32 latency; } __packed; #define VOICEPROC_MODULE_ID_GENERIC_TX 0x00010EF6 @@ -10967,12 +10926,6 @@ struct adm_param_fluence_soundfocus_t { uint16_t reserved; } __packed; -struct adm_set_fluence_soundfocus_param { - struct adm_cmd_set_pp_params_v5 params; - struct adm_param_data_v5 data; - struct adm_param_fluence_soundfocus_t soundfocus_data; -} __packed; - struct adm_param_fluence_sourcetracking_t { uint8_t vad[MAX_SECTORS]; uint16_t doa_speech; @@ -11002,10 +10955,4 @@ struct admx_sec_primary_mic_ch { uint16_t reserved1; } __packed; - -struct adm_set_sec_primary_ch_params { - struct adm_cmd_set_pp_params_v5 params; - struct adm_param_data_v5 data; - struct admx_sec_primary_mic_ch sec_primary_mic_ch_data; -} __packed; #endif /*_APR_AUDIO_V2_H_ */ diff --git a/include/dsp/q6adm-v2.h b/include/dsp/q6adm-v2.h index 881943b464c3..0f7e7b240428 100644 --- a/include/dsp/q6adm-v2.h +++ b/include/dsp/q6adm-v2.h @@ -25,6 +25,8 @@ #define MAX_MODULES_IN_TOPO 16 #define ADM_GET_TOPO_MODULE_LIST_LENGTH\ ((MAX_MODULES_IN_TOPO + 1) * sizeof(uint32_t)) +#define ADM_GET_TOPO_MODULE_INSTANCE_LIST_LENGTH \ + ((MAX_MODULES_IN_TOPO + 1) * 2 * sizeof(uint32_t)) #define AUD_PROC_BLOCK_SIZE 4096 #define AUD_VOL_BLOCK_SIZE 4096 #define AUDIO_RX_CALIBRATION_SIZE (AUD_PROC_BLOCK_SIZE + \ @@ -94,12 +96,24 @@ void adm_copp_mfc_cfg(int port_id, int copp_idx, int dst_sample_rate); int adm_get_params(int port_id, int copp_idx, uint32_t module_id, uint32_t param_id, uint32_t params_length, char *params); +int adm_get_pp_params(int port_id, int copp_idx, uint32_t client_id, + struct mem_mapping_hdr *mem_hdr, + struct param_hdr_v3 *param_hdr, u8 *returned_param_data); + int adm_send_params_v5(int port_id, int copp_idx, char *params, uint32_t params_length); int adm_dolby_dap_send_params(int port_id, int copp_idx, char *params, uint32_t params_length); +int adm_set_pp_params(int port_id, int copp_idx, + struct mem_mapping_hdr *mem_hdr, u8 *param_data, + u32 params_size); + +int adm_pack_and_set_one_pp_param(int port_id, int copp_idx, + struct param_hdr_v3 param_hdr, + u8 *param_data); + int adm_open(int port, int path, int rate, int mode, int topology, int perf_mode, uint16_t bits_per_sample, int app_type, int acdbdev_id); @@ -146,6 +160,10 @@ int adm_set_stereo_to_custom_stereo(int port_id, int copp_idx, int adm_get_pp_topo_module_list(int port_id, int copp_idx, int32_t param_length, char *params); +int adm_get_pp_topo_module_list_v2(int port_id, int copp_idx, + int32_t param_length, + int32_t *returned_params); + int adm_set_volume(int port_id, int copp_idx, int volume); int adm_set_softvolume(int port_id, int copp_idx, @@ -158,6 +176,9 @@ int adm_send_set_multichannel_ec_primary_mic_ch(int port_id, int copp_idx, int adm_param_enable(int port_id, int copp_idx, int module_id, int enable); +int adm_param_enable_v2(int port_id, int copp_idx, + struct module_instance_info mod_inst_info, int enable); + int adm_send_calibration(int port_id, int copp_idx, int path, int perf_mode, int cal_type, char *params, int size);