From 9fd06e95cc82771c49181b4d72c6c25888353748 Mon Sep 17 00:00:00 2001 From: Jun Lai Date: Thu, 4 Jun 2026 15:15:25 +0800 Subject: [PATCH 1/2] dax: update p_dax pointer state on mock version It is necessary cause p_dax is used in dax.c now. Signed-off-by: Jun Lai --- src/audio/module_adapter/module/dolby/dax_mock.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/audio/module_adapter/module/dolby/dax_mock.c b/src/audio/module_adapter/module/dolby/dax_mock.c index c8889699a7e8..92803cad0820 100644 --- a/src/audio/module_adapter/module/dolby/dax_mock.c +++ b/src/audio/module_adapter/module/dolby/dax_mock.c @@ -29,11 +29,13 @@ uint32_t dax_query_period_frames(struct sof_dax *dax_ctx) int dax_free(struct sof_dax *dax_ctx) { + dax_ctx->p_dax = NULL; return 0; } int dax_init(struct sof_dax *dax_ctx) { + dax_ctx->p_dax = dax_ctx->persist_buffer.addr; return 0; } @@ -81,7 +83,7 @@ int dax_set_ctc_enable(int32_t enable, struct sof_dax *dax_ctx) const char *dax_get_version(void) { - return ""; + return "mock_version"; } void *dax_find_params(uint32_t query_id, From 13a3dbbdb7e011ab36dd5bbe9bb01d8fae1e656a Mon Sep 17 00:00:00 2001 From: Jun Lai Date: Thu, 4 Jun 2026 15:18:33 +0800 Subject: [PATCH 2/2] dax: fix race condition on the tuning buffer While the tuning buffer is being updated, it may also be being used simultaneously in the process thread. Signed-off-by: Jun Lai --- src/audio/module_adapter/module/dolby/dax.c | 41 +++++++++++++++------ src/audio/module_adapter/module/dolby/dax.h | 1 + 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/audio/module_adapter/module/dolby/dax.c b/src/audio/module_adapter/module/dolby/dax.c index 984bd2c11680..fd7dd8d8ee60 100644 --- a/src/audio/module_adapter/module/dolby/dax.c +++ b/src/audio/module_adapter/module/dolby/dax.c @@ -25,6 +25,7 @@ SOF_DEFINE_REG_UUID(dolby_dax_audio_processing); #define DAX_CP_MASK 0x8 #define DAX_VOLUME_MASK 0x10 #define DAX_CTC_MASK 0x20 +#define DAX_TUNING_FILE_MASK 0x40 #define DAX_PROCESSING_MASK 0x10000 #define DAX_RESET_MASK 0x20000 #define DAX_FREE_MASK 0x40000 @@ -241,24 +242,21 @@ static bool is_enabled(struct processing_module *mod) return dax_ctx->enable && dax_ctx->p_dax; } -static int set_tuning_file(struct processing_module *mod, void *value, uint32_t size) +static int set_tuning_file(struct processing_module *mod) { - int ret = 0; + int ret = -EINVAL; struct comp_dev *dev = mod->dev; struct dax_adapter_data *adapter_data = module_get_private_data(mod); struct sof_dax *dax_ctx = &adapter_data->dax_ctx; - if (dax_buffer_alloc(mod, &dax_ctx->tuning_file_buffer, size) != 0) { - comp_err(dev, "allocate %u bytes failed for tuning file", size); - ret = -ENOMEM; - } else { - memcpy_s(dax_ctx->tuning_file_buffer.addr, - dax_ctx->tuning_file_buffer.free, - value, - size); + if (adapter_data->tmp_tuning_buf.addr && adapter_data->tmp_tuning_buf.size > 0) { + dax_buffer_release(mod, &dax_ctx->tuning_file_buffer); + dax_ctx->tuning_file_buffer = adapter_data->tmp_tuning_buf; + memset(&adapter_data->tmp_tuning_buf, 0, sizeof(adapter_data->tmp_tuning_buf)); + ret = 0; } - comp_info(dev, "allocated: tuning %u, ret %d", dax_ctx->tuning_file_buffer.size, ret); + comp_info(dev, "apply tuning %p, ret %d", dax_ctx->tuning_file_buffer.addr, ret); return ret; } @@ -367,7 +365,19 @@ static int dax_set_param_wrapper(struct processing_module *mod, switch (id) { case DAX_PARAM_ID_TUNING_FILE: - set_tuning_file(mod, value, size); + if (dax_buffer_alloc(mod, &adapter_data->tmp_tuning_buf, size) != 0) { + comp_err(dev, "allocate %u bytes failed for tuning file", size); + ret = -ENOMEM; + } else { + memcpy_s(adapter_data->tmp_tuning_buf.addr, + adapter_data->tmp_tuning_buf.free, + value, + size); + flag_process(adapter_data, DAX_TUNING_FILE_MASK, DAX_FLAG_SET); + comp_info(dev, "allocated: tuning %p, size %u", + adapter_data->tmp_tuning_buf.addr, + adapter_data->tmp_tuning_buf.size); + } break; case DAX_PARAM_ID_ENABLE: tmp_val = *((int32_t *)value); @@ -488,6 +498,12 @@ static void check_and_update_settings(struct processing_module *mod) if (!is_enabled(mod)) return; + if (flag_process(adapter_data, DAX_TUNING_FILE_MASK, DAX_FLAG_READ_AND_CLEAR)) { + set_tuning_file(mod); + flag_process(adapter_data, DAX_DEVICE_MASK, DAX_FLAG_SET); + flag_process(adapter_data, DAX_VOLUME_MASK, DAX_FLAG_SET); + } + if (flag_process(adapter_data, DAX_DEVICE_MASK, DAX_FLAG_READ_AND_CLEAR)) { set_device(mod, dax_ctx->out_device); set_tuning_device(mod, dax_ctx->tuning_device); @@ -547,6 +563,7 @@ static int sof_dax_free(struct processing_module *mod) dax_buffer_release(mod, &dax_ctx->tuning_file_buffer); mod_data_blob_handler_free(mod, dax_ctx->blob_handler); dax_ctx->blob_handler = NULL; + dax_buffer_release(mod, &adapter_data->tmp_tuning_buf); mod_free(mod, adapter_data); module_set_private_data(mod, NULL); } diff --git a/src/audio/module_adapter/module/dolby/dax.h b/src/audio/module_adapter/module/dolby/dax.h index da0419fa3766..a7130b52b461 100644 --- a/src/audio/module_adapter/module/dolby/dax.h +++ b/src/audio/module_adapter/module/dolby/dax.h @@ -24,6 +24,7 @@ struct dax_adapter_data { atomic_t proc_flags; uint32_t comp_id; int32_t priority; + struct dax_buffer tmp_tuning_buf; }; /**