-
Notifications
You must be signed in to change notification settings - Fork 350
dax: set instance lifespan from prepare to reset #10526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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; | ||
|
|
@@ -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) { | ||
|
|
@@ -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) | ||
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will suggest a new atomic variable in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is so far the best approach in my mind, although it is not ideal. But it should be fair enough given process calls will be much longer than reset
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ack - DP/LL are different threads. DP thread is always preempted by synchronous LL thread every 1ms. So this solution looks fine to protect shared module resources.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh that is critical. So basically we can assume the variable access on both threads won't get conflict. Then I assume the lock/atomic can be deferred. |
||
| /* 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); | ||
|
|
@@ -694,6 +762,10 @@ static int sof_dax_process(struct processing_module *mod, struct sof_source **so | |
| source_release_data(source, consumed_bytes); | ||
|
|
||
| check_and_update_settings(mod); | ||
| if (dax_ctx->enable && !dax_ctx->p_dax) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this case happen? |
||
| comp_err(mod->dev, "dax instance is not ready"); | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| /* internal input buffer -> internal output buffer */ | ||
| processed_bytes = dax_process(dax_ctx); | ||
|
|
@@ -711,6 +783,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; | ||
| } | ||
|
|
@@ -855,6 +929,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, | ||
| }; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.