Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/overlays/mtl/dax_overlay.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CONFIG_COMP_DOLBY_DAX_AUDIO_PROCESSING=y
CONFIG_COMP_DOLBY_DAX_AUDIO_PROCESSING_MOCK=n
CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL=n
CONFIG_SOF_STACK_SIZE=8192
CONFIG_IDC_TIMEOUT_US=50000

# LLEXT
CONFIG_LLEXT_HEAP_SIZE=32
Expand Down
1 change: 1 addition & 0 deletions app/overlays/ptl/dax_overlay.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CONFIG_COMP_DOLBY_DAX_AUDIO_PROCESSING=y
CONFIG_COMP_DOLBY_DAX_AUDIO_PROCESSING_MOCK=n
CONFIG_KCPS_DYNAMIC_CLOCK_CONTROL=n
CONFIG_SOF_STACK_SIZE=8192
CONFIG_IDC_TIMEOUT_US=50000

# LLEXT
CONFIG_LLEXT_HEAP_SIZE=32
149 changes: 110 additions & 39 deletions src/audio/module_adapter/module/dolby/dax.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ 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_PROCESSING_MASK 0x10000
#define DAX_RESET_MASK 0x20000
#define DAX_FREE_MASK 0x40000

#define DAX_SWITCH_ENABLE_CONTROL_ID 0
#define DAX_SWITCH_CP_CONTROL_ID 1
Expand Down Expand Up @@ -181,6 +184,53 @@ static void dax_buffer_produce(struct dax_buffer *dax_buff, uint32_t bytes)
dax_buff->free = dax_buff->size - dax_buff->avail;
}

static void destroy_instance(struct processing_module *mod)
{
struct sof_dax *dax_ctx = module_get_private_data(mod);

dax_free(dax_ctx); /* free internal dax instance in dax_ctx */
dax_buffer_release(mod, &dax_ctx->persist_buffer);
dax_buffer_release(mod, &dax_ctx->scratch_buffer);
}

static int establish_instance(struct processing_module *mod)
{
int ret = 0;
struct comp_dev *dev = mod->dev;
struct sof_dax *dax_ctx = module_get_private_data(mod);
uint32_t persist_sz;
uint32_t scratch_sz;

persist_sz = dax_query_persist_memory(dax_ctx);
if (dax_buffer_alloc(mod, &dax_ctx->persist_buffer, persist_sz) != 0) {
comp_err(dev, "allocate %u bytes failed for persist", persist_sz);
ret = -ENOMEM;
goto err;
}
scratch_sz = dax_query_scratch_memory(dax_ctx);
if (dax_buffer_alloc(mod, &dax_ctx->scratch_buffer, scratch_sz) != 0) {
comp_err(dev, "allocate %u bytes failed for scratch", scratch_sz);
ret = -ENOMEM;
goto err;
}
ret = dax_init(dax_ctx);
if (ret != 0) {
comp_err(dev, "dax instance initialization failed, ret %d", ret);
goto err;
}

/* set DAX_ENABLE_MASK bit to trigger the fully update of kcontrol values */
dax_ctx->update_flags |= DAX_ENABLE_MASK;

comp_info(dev, "allocated: persist %u, scratch %u. version: %s",
persist_sz, scratch_sz, dax_get_version());
return 0;

err:
destroy_instance(mod);
return ret;
}

static int set_tuning_file(struct processing_module *mod, void *value, uint32_t size)
{
int ret = 0;
Expand Down Expand Up @@ -463,33 +513,63 @@ static void check_and_update_settings(struct processing_module *mod)
}
}

static int sof_dax_reset(struct processing_module *mod)
{
struct sof_dax *dax_ctx = module_get_private_data(mod);

/* dax instance will be established on prepare(), and destroyed on reset() */
if (dax_ctx) {
if (dax_ctx->update_flags & DAX_PROCESSING_MASK) {
dax_ctx->update_flags |= DAX_RESET_MASK;
} else {
destroy_instance(mod);
dax_buffer_release(mod, &dax_ctx->input_buffer);
dax_buffer_release(mod, &dax_ctx->output_buffer);
}
}

return 0;
}

static int sof_dax_free(struct processing_module *mod)
{
struct sof_dax *dax_ctx = module_get_private_data(mod);

if (dax_ctx) {
dax_free(dax_ctx);
dax_buffer_release(mod, &dax_ctx->persist_buffer);
dax_buffer_release(mod, &dax_ctx->scratch_buffer);
dax_buffer_release(mod, &dax_ctx->tuning_file_buffer);
dax_buffer_release(mod, &dax_ctx->input_buffer);
dax_buffer_release(mod, &dax_ctx->output_buffer);
mod_data_blob_handler_free(mod, dax_ctx->blob_handler);
dax_ctx->blob_handler = NULL;
mod_free(mod, dax_ctx);
module_set_private_data(mod, NULL);
if (dax_ctx->update_flags & DAX_PROCESSING_MASK) {
dax_ctx->update_flags |= DAX_FREE_MASK;
} else {
sof_dax_reset(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;
mod_free(mod, dax_ctx);
module_set_private_data(mod, NULL);
}
}
return 0;
}

static void check_and_update_state(struct processing_module *mod)
{
struct sof_dax *dax_ctx = module_get_private_data(mod);

if (!dax_ctx)
return;

if (dax_ctx->update_flags & DAX_FREE_MASK) {
sof_dax_free(mod);
} else if (dax_ctx->update_flags & DAX_RESET_MASK) {
sof_dax_reset(mod);
dax_ctx->update_flags &= ~DAX_RESET_MASK;
}
}

static int sof_dax_init(struct processing_module *mod)
{
int ret;
struct comp_dev *dev = mod->dev;
struct module_data *md = &mod->priv;
struct sof_dax *dax_ctx;
uint32_t persist_sz;
uint32_t scratch_sz;

md->private = mod_zalloc(mod, sizeof(struct sof_dax));
if (!md->private) {
Expand All @@ -509,35 +589,12 @@ static int sof_dax_init(struct processing_module *mod)
dax_ctx->blob_handler = mod_data_blob_handler_new(mod);
if (!dax_ctx->blob_handler) {
comp_err(dev, "create blob handler failed");
ret = -ENOMEM;
goto err;
}

persist_sz = dax_query_persist_memory(dax_ctx);
if (dax_buffer_alloc(mod, &dax_ctx->persist_buffer, persist_sz) != 0) {
comp_err(dev, "allocate %u bytes failed for persist", persist_sz);
ret = -ENOMEM;
goto err;
}
scratch_sz = dax_query_scratch_memory(dax_ctx);
if (dax_buffer_alloc(mod, &dax_ctx->scratch_buffer, scratch_sz) != 0) {
comp_err(dev, "allocate %u bytes failed for scratch", scratch_sz);
ret = -ENOMEM;
goto err;
}
ret = dax_init(dax_ctx);
if (ret != 0) {
comp_err(dev, "dax instance initialization failed, ret %d", ret);
goto err;
mod_free(mod, dax_ctx);
module_set_private_data(mod, NULL);
return -ENOMEM;
}

comp_info(dev, "allocated: persist %u, scratch %u. version: %s",
persist_sz, scratch_sz, dax_get_version());
return 0;

err:
sof_dax_free(mod);
return ret;
}

static int check_media_format(struct processing_module *mod)
Expand Down Expand Up @@ -631,6 +688,11 @@ static int sof_dax_prepare(struct processing_module *mod, struct sof_source **so
if (ret != 0)
return ret;

/* dax instance will be established on prepare(), and destroyed on reset() */
ret = establish_instance(mod);
if (ret != 0)
return ret;

dax_ctx->sof_period_bytes = dev->frames *
dax_ctx->output_media_format.num_channels *
dax_ctx->output_media_format.bytes_per_sample;
Expand Down Expand Up @@ -680,6 +742,12 @@ static int sof_dax_process(struct processing_module *mod, struct sof_source **so
struct dax_buffer *dax_output_buffer = &dax_ctx->output_buffer;
uint32_t consumed_bytes, processed_bytes, produced_bytes;

if (!dax_ctx) {
comp_err(mod->dev, "invalid dax context");
return -EINVAL;
}

dax_ctx->update_flags |= DAX_PROCESSING_MASK;
/* source stream -> internal input buffer */
consumed_bytes = MIN(source_get_data_available(source), dax_input_buffer->free);
source_get_data(source, consumed_bytes, (void *)&buf, (void *)&bufstart, &bufsz);
Expand Down Expand Up @@ -711,6 +779,8 @@ static int sof_dax_process(struct processing_module *mod, struct sof_source **so
dax_buffer_consume(dax_output_buffer, produced_bytes);
sink_commit_buffer(sink, produced_bytes);
}
dax_ctx->update_flags &= ~DAX_PROCESSING_MASK;
check_and_update_state(mod);

return 0;
}
Expand Down Expand Up @@ -855,6 +925,7 @@ static const struct module_interface dolby_dax_audio_processing_interface = {
.prepare = sof_dax_prepare,
.process = sof_dax_process,
.set_configuration = sof_dax_set_configuration,
.reset = sof_dax_reset,
.free = sof_dax_free,
};

Expand Down