-
Notifications
You must be signed in to change notification settings - Fork 350
dax: set instance lifespan from prepare to reset #10503
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 |
|---|---|---|
|
|
@@ -465,7 +465,7 @@ static void check_and_update_settings(struct processing_module *mod) | |
| } | ||
| } | ||
|
|
||
| static int sof_dax_free(struct processing_module *mod) | ||
| static void destroy_instance(struct processing_module *mod) | ||
| { | ||
| struct sof_dax *dax_ctx = module_get_private_data(mod); | ||
|
|
||
|
|
@@ -476,6 +476,51 @@ static int sof_dax_free(struct processing_module *mod) | |
| 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); | ||
| } | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| 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 sof_dax_free(struct processing_module *mod) | ||
| { | ||
| struct sof_dax *dax_ctx = module_get_private_data(mod); | ||
|
|
||
| destroy_instance(mod); | ||
|
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. if |
||
|
|
||
| if (dax_ctx) { | ||
| mod_data_blob_handler_free(mod, dax_ctx->blob_handler); | ||
| dax_ctx->blob_handler = NULL; | ||
| mod_free(mod, dax_ctx); | ||
|
|
@@ -486,12 +531,9 @@ static int sof_dax_free(struct processing_module *mod) | |
|
|
||
| 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) { | ||
|
|
@@ -511,35 +553,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) | ||
|
|
@@ -629,6 +648,11 @@ static int sof_dax_prepare(struct processing_module *mod, struct sof_source **so | |
| return -EINVAL; | ||
| } | ||
|
|
||
| /* dax instance will be established on prepare(), and destroyed on reset() */ | ||
| ret = establish_instance(mod); | ||
| if (ret != 0) | ||
| return ret; | ||
|
|
||
|
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. It might be better to place |
||
| ret = check_media_format(mod); | ||
| if (ret != 0) | ||
| return ret; | ||
|
|
@@ -852,11 +876,21 @@ static int sof_dax_set_configuration(struct processing_module *mod, uint32_t con | |
| return ret; | ||
| } | ||
|
|
||
| static int sof_dax_reset(struct processing_module *mod) { | ||
| struct comp_dev *dev = mod->dev; | ||
|
|
||
| /* dax instance will be established on prepare(), and destroyed on reset() */ | ||
| destroy_instance(mod); | ||
|
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. Simultaneously release following buffers here: 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);Becasue these buffers are also allocated in |
||
| comp_info(dev, "reset"); | ||
| return 0; | ||
| } | ||
|
|
||
| static const struct module_interface dolby_dax_audio_processing_interface = { | ||
| .init = sof_dax_init, | ||
| .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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since only persist and scratch buffers are allocated during entablishment phase, we could be only responsible for releasing them during the destruction phase: