@@ -181,6 +181,51 @@ static void dax_buffer_produce(struct dax_buffer *dax_buff, uint32_t bytes)
181181 dax_buff -> free = dax_buff -> size - dax_buff -> avail ;
182182}
183183
184+ static void destroy_instance (struct processing_module * mod )
185+ {
186+ struct sof_dax * dax_ctx = module_get_private_data (mod );
187+
188+ dax_free (dax_ctx ); /* free internal dax instance in dax_ctx */
189+ dax_buffer_release (mod , & dax_ctx -> persist_buffer );
190+ dax_buffer_release (mod , & dax_ctx -> scratch_buffer );
191+ }
192+
193+ static int establish_instance (struct processing_module * mod )
194+ {
195+ int ret = 0 ;
196+ struct comp_dev * dev = mod -> dev ;
197+ struct sof_dax * dax_ctx = module_get_private_data (mod );
198+ uint32_t persist_sz ;
199+ uint32_t scratch_sz ;
200+
201+ persist_sz = dax_query_persist_memory (dax_ctx );
202+ if (dax_buffer_alloc (mod , & dax_ctx -> persist_buffer , persist_sz ) != 0 ) {
203+ comp_err (dev , "allocate %u bytes failed for persist" , persist_sz );
204+ ret = - ENOMEM ;
205+ goto err ;
206+ }
207+ scratch_sz = dax_query_scratch_memory (dax_ctx );
208+ if (dax_buffer_alloc (mod , & dax_ctx -> scratch_buffer , scratch_sz ) != 0 ) {
209+ comp_err (dev , "allocate %u bytes failed for scratch" , scratch_sz );
210+ ret = - ENOMEM ;
211+ goto err ;
212+ }
213+ ret = dax_init (dax_ctx );
214+ if (ret != 0 ) {
215+ comp_err (dev , "dax instance initialization failed, ret %d" , ret );
216+ goto err ;
217+ }
218+ dax_ctx -> update_flags |= DAX_ENABLE_MASK ;
219+
220+ comp_info (dev , "allocated: persist %u, scratch %u. version: %s" ,
221+ persist_sz , scratch_sz , dax_get_version ());
222+ return 0 ;
223+
224+ err :
225+ destroy_instance (mod );
226+ return ret ;
227+ }
228+
184229static int set_tuning_file (struct processing_module * mod , void * value , uint32_t size )
185230{
186231 int ret = 0 ;
@@ -463,17 +508,23 @@ static void check_and_update_settings(struct processing_module *mod)
463508 }
464509}
465510
511+ static int sof_dax_reset (struct processing_module * mod ) {
512+ struct sof_dax * dax_ctx = module_get_private_data (mod );
513+
514+ /* dax instance will be established on prepare(), and destroyed on reset() */
515+ destroy_instance (mod );
516+ dax_buffer_release (mod , & dax_ctx -> input_buffer );
517+ dax_buffer_release (mod , & dax_ctx -> output_buffer );
518+ return 0 ;
519+ }
520+
466521static int sof_dax_free (struct processing_module * mod )
467522{
468523 struct sof_dax * dax_ctx = module_get_private_data (mod );
469524
470525 if (dax_ctx ) {
471- dax_free (dax_ctx );
472- dax_buffer_release (mod , & dax_ctx -> persist_buffer );
473- dax_buffer_release (mod , & dax_ctx -> scratch_buffer );
526+ sof_dax_reset (mod );
474527 dax_buffer_release (mod , & dax_ctx -> tuning_file_buffer );
475- dax_buffer_release (mod , & dax_ctx -> input_buffer );
476- dax_buffer_release (mod , & dax_ctx -> output_buffer );
477528 mod_data_blob_handler_free (mod , dax_ctx -> blob_handler );
478529 dax_ctx -> blob_handler = NULL ;
479530 mod_free (mod , dax_ctx );
@@ -484,12 +535,9 @@ static int sof_dax_free(struct processing_module *mod)
484535
485536static int sof_dax_init (struct processing_module * mod )
486537{
487- int ret ;
488538 struct comp_dev * dev = mod -> dev ;
489539 struct module_data * md = & mod -> priv ;
490540 struct sof_dax * dax_ctx ;
491- uint32_t persist_sz ;
492- uint32_t scratch_sz ;
493541
494542 md -> private = mod_zalloc (mod , sizeof (struct sof_dax ));
495543 if (!md -> private ) {
@@ -509,35 +557,12 @@ static int sof_dax_init(struct processing_module *mod)
509557 dax_ctx -> blob_handler = mod_data_blob_handler_new (mod );
510558 if (!dax_ctx -> blob_handler ) {
511559 comp_err (dev , "create blob handler failed" );
512- ret = - ENOMEM ;
513- goto err ;
514- }
515-
516- persist_sz = dax_query_persist_memory (dax_ctx );
517- if (dax_buffer_alloc (mod , & dax_ctx -> persist_buffer , persist_sz ) != 0 ) {
518- comp_err (dev , "allocate %u bytes failed for persist" , persist_sz );
519- ret = - ENOMEM ;
520- goto err ;
521- }
522- scratch_sz = dax_query_scratch_memory (dax_ctx );
523- if (dax_buffer_alloc (mod , & dax_ctx -> scratch_buffer , scratch_sz ) != 0 ) {
524- comp_err (dev , "allocate %u bytes failed for scratch" , scratch_sz );
525- ret = - ENOMEM ;
526- goto err ;
527- }
528- ret = dax_init (dax_ctx );
529- if (ret != 0 ) {
530- comp_err (dev , "dax instance initialization failed, ret %d" , ret );
531- goto err ;
560+ mod_free (mod , dax_ctx );
561+ module_set_private_data (mod , NULL );
562+ return - ENOMEM ;
532563 }
533564
534- comp_info (dev , "allocated: persist %u, scratch %u. version: %s" ,
535- persist_sz , scratch_sz , dax_get_version ());
536565 return 0 ;
537-
538- err :
539- sof_dax_free (mod );
540- return ret ;
541566}
542567
543568static int check_media_format (struct processing_module * mod )
@@ -631,6 +656,11 @@ static int sof_dax_prepare(struct processing_module *mod, struct sof_source **so
631656 if (ret != 0 )
632657 return ret ;
633658
659+ /* dax instance will be established on prepare(), and destroyed on reset() */
660+ ret = establish_instance (mod );
661+ if (ret != 0 )
662+ return ret ;
663+
634664 dax_ctx -> sof_period_bytes = dev -> frames *
635665 dax_ctx -> output_media_format .num_channels *
636666 dax_ctx -> output_media_format .bytes_per_sample ;
@@ -855,6 +885,7 @@ static const struct module_interface dolby_dax_audio_processing_interface = {
855885 .prepare = sof_dax_prepare ,
856886 .process = sof_dax_process ,
857887 .set_configuration = sof_dax_set_configuration ,
888+ .reset = sof_dax_reset ,
858889 .free = sof_dax_free ,
859890};
860891
0 commit comments