From 677ccd1b5629a27340541e4978456975917fb9fc Mon Sep 17 00:00:00 2001 From: Kunlei Zhang Date: Thu, 4 Feb 2021 20:02:15 +0800 Subject: [PATCH] dsp: adm: avoid FNN model memory unmap when closing non-FNN port In VoIP FNN and audio record concurrence, FNN model shared memory is wrong to unmap when audio record stop. Fix it by checking FNN topology and app type to ensure the memory is unmapped properly. Change-Id: If24b6aa75d41b629a3ef33b9585d9d7d82aa9b25 Signed-off-by: Kunlei Zhang --- dsp/q6adm.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/dsp/q6adm.c b/dsp/q6adm.c index e776459c9bc8..fa8167ccd6f3 100644 --- a/dsp/q6adm.c +++ b/dsp/q6adm.c @@ -109,6 +109,7 @@ struct adm_ctl { uint32_t copp_token; int tx_port_id; bool hyp_assigned; + int fnn_app_type; }; static struct adm_ctl this_adm; @@ -2313,7 +2314,7 @@ static void send_adm_cal_type(int cal_index, int path, int port_id, int acdb_id, int sample_rate) { struct cal_block_data *cal_block = NULL; - int ret; + int ret, port_idx, topology; int dest_perms[2] = {PERM_READ | PERM_WRITE, PERM_READ | PERM_WRITE}; int source_vm[1] = {VMID_HLOS}; int dest_vm[2] = {VMID_LPASS, VMID_ADSP_HEAP}; @@ -2326,13 +2327,21 @@ static void send_adm_cal_type(int cal_index, int path, int port_id, goto done; } + port_idx = adm_validate_and_get_port_index(port_id); + if (port_idx < 0) { + pr_err("%s: Invalid port id: 0x%x", __func__, port_id); + goto done; + } + mutex_lock(&this_adm.cal_data[cal_index]->lock); cal_block = adm_find_cal(cal_index, path, app_type, acdb_id, sample_rate); if (cal_block == NULL) goto unlock; - if (cal_block->cma_mem) { + topology = atomic_read(&this_adm.copp.topology[port_idx][copp_idx]); + if (cal_block->cma_mem && + topology == VPM_TX_VOICE_FLUENCE_NN_COPP_TOPOLOGY) { if (cal_block->cal_data.paddr == 0 || cal_block->map_data.map_size <= 0) { pr_err("%s: No address to map!\n", __func__); @@ -2351,6 +2360,7 @@ static void send_adm_cal_type(int cal_index, int path, int port_id, } this_adm.tx_port_id = port_id; this_adm.hyp_assigned = true; + this_adm.fnn_app_type = app_type; pr_debug("%s: hyp_assign_phys success in tx_port_id 0x%x\n", __func__, this_adm.tx_port_id); } @@ -3877,7 +3887,7 @@ int adm_close(int port_id, int perf_mode, int copp_idx) { struct apr_hdr close; - int ret = 0, port_idx; + int ret = 0, port_idx, app_type, topology; int copp_id = RESET_COPP_ID; bool result = false; int dest_perms[1] = {PERM_READ | PERM_WRITE | PERM_EXEC}; @@ -3903,6 +3913,8 @@ int adm_close(int port_id, int perf_mode, int copp_idx) } port_channel_map[port_idx].set_channel_map = false; + topology = atomic_read(&this_adm.copp.topology[port_idx][copp_idx]); + app_type = atomic_read(&this_adm.copp.app_type[port_idx][copp_idx]); if (this_adm.copp.adm_delay[port_idx][copp_idx] && perf_mode == LEGACY_PCM_MODE) { atomic_set(&this_adm.copp.adm_delay_stat[port_idx][copp_idx], @@ -3984,7 +3996,9 @@ int adm_close(int port_id, int perf_mode, int copp_idx) ret = apr_send_pkt(this_adm.apr, (uint32_t *)&close); if (ret < 0) { pr_err("%s: ADM close failed %d\n", __func__, ret); - if (this_adm.tx_port_id == port_id) { + if (this_adm.tx_port_id == port_id && + this_adm.fnn_app_type == app_type && + topology == VPM_TX_VOICE_FLUENCE_NN_COPP_TOPOLOGY) { mutex_lock(&this_adm.cal_data[cal_index]->lock); cal_block = cal_utils_get_only_cal_block( this_adm.cal_data[cal_index]); @@ -4069,7 +4083,9 @@ int adm_close(int port_id, int perf_mode, int copp_idx) rtac_remove_adm_device(port_id, copp_id); } - if (this_adm.tx_port_id == port_id) { + if (this_adm.tx_port_id == port_id && + this_adm.fnn_app_type == app_type && + topology == VPM_TX_VOICE_FLUENCE_NN_COPP_TOPOLOGY) { mutex_lock(&this_adm.cal_data[cal_index]->lock); cal_block = cal_utils_get_only_cal_block( this_adm.cal_data[cal_index]); @@ -5687,6 +5703,7 @@ int __init adm_init(void) this_adm.ffecns_port_id = -1; this_adm.tx_port_id = -1; this_adm.hyp_assigned = false; + this_adm.fnn_app_type = -1; init_waitqueue_head(&this_adm.matrix_map_wait); init_waitqueue_head(&this_adm.adm_wait);