@@ -65,6 +65,7 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
6565 struct processing_module * mod ;
6666 struct module_config * dst ;
6767 const struct module_interface * const interface = drv -> adapter_ops ;
68+ struct vregion * vregion = NULL ;
6869
6970 comp_cl_dbg (drv , "start" );
7071
@@ -81,6 +82,33 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
8182 }
8283 dev -> ipc_config = * config ;
8384
85+ #if CONFIG_SOF_VREGIONS
86+
87+ /* TODO: determine if our user domain is different from the LL pipeline domain */
88+ if (config -> proc_domain == COMP_PROCESSING_DOMAIN_DP ) {
89+ // TODO: get the text, heap, stack and shared sizes from topology too
90+ /* create a vregion region for all resources */
91+ size_t interim_size = 0x4000 ; /* 16kB scratch */
92+ size_t lifetime_size = 0x20000 ; /* 128kB batch */
93+ size_t shared_size = 0x4000 ; /* 16kB shared */
94+ size_t text_size = 0x4000 ; /* 16kB text */
95+ vregion = vregion_create (lifetime_size , interim_size , shared_size , 0 , text_size );
96+ if (!vregion ) {
97+ comp_err (dev , "failed to create vregion for DP module" );
98+ goto err_pipe ;
99+ }
100+ } else {
101+ vregion = dev -> pipeline -> vregion ;
102+ }
103+
104+ /* allocate module in correct vregion*/
105+ //TODO: add coherent flag for cross core DP modules
106+ mod = vregion_alloc (vregion , VREGION_MEM_TYPE_LIFETIME , sizeof (* mod ));
107+ if (!mod ) {
108+ comp_err (dev , "failed to allocate memory for module" );
109+ goto err_pipe ;
110+ }
111+ #else
84112 /* allocate module information.
85113 * for DP shared modules this struct must be accessible from all cores
86114 * Unfortunately at this point there's no information of components the module
@@ -95,7 +123,9 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
95123 comp_err (dev , "failed to allocate memory for module" );
96124 goto err ;
97125 }
98-
126+ #endif
127+ memset (mod , 0 , sizeof (* mod ));
128+ mod -> vregion = vregion ;
99129 dst = & mod -> priv .cfg ;
100130
101131 module_set_private_data (mod , mod_priv );
@@ -184,6 +214,7 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
184214 rfree (mod -> priv .cfg .input_pins );
185215#endif
186216 rfree (mod );
217+ err_pipe :
187218 rfree (dev );
188219 return NULL ;
189220}
@@ -354,20 +385,35 @@ int module_adapter_prepare(struct comp_dev *dev)
354385 memory_flags = user_get_buffer_memory_region (dev -> drv );
355386 /* allocate memory for input buffers */
356387 if (mod -> max_sources ) {
388+ //TODO: check if shared memory is needed
389+ struct vregion * vregion = module_get_vregion (mod );
357390 mod -> input_buffers =
391+ #if CONFIG_SOF_VREGIONS
392+ vregion_alloc (vregion , VREGION_MEM_TYPE_LIFETIME_SHARED ,
393+ sizeof (* mod -> input_buffers ) * mod -> max_sources );
394+ #else
358395 rzalloc (memory_flags , sizeof (* mod -> input_buffers ) * mod -> max_sources );
396+ #endif
359397 if (!mod -> input_buffers ) {
360398 comp_err (dev , "failed to allocate input buffers" );
361399 return - ENOMEM ;
362400 }
363401 } else {
364402 mod -> input_buffers = NULL ;
365403 }
404+ memset (mod -> input_buffers , 0 , sizeof (* mod -> input_buffers ) * mod -> max_sources );
366405
367406 /* allocate memory for output buffers */
407+ //TODO: check if shared memory is needed
368408 if (mod -> max_sinks ) {
409+ struct vregion * vregion = module_get_vregion (mod );
369410 mod -> output_buffers =
411+ #if CONFIG_SOF_VREGIONS
412+ vregion_alloc (vregion , VREGION_MEM_TYPE_LIFETIME_SHARED ,
413+ sizeof (* mod -> output_buffers ) * mod -> max_sinks );
414+ #else
370415 rzalloc (memory_flags , sizeof (* mod -> output_buffers ) * mod -> max_sinks );
416+ #endif
371417 if (!mod -> output_buffers ) {
372418 comp_err (dev , "failed to allocate output buffers" );
373419 ret = - ENOMEM ;
@@ -376,6 +422,7 @@ int module_adapter_prepare(struct comp_dev *dev)
376422 } else {
377423 mod -> output_buffers = NULL ;
378424 }
425+ memset (mod -> output_buffers , 0 , sizeof (* mod -> output_buffers ) * mod -> max_sinks );
379426
380427 /*
381428 * no need to allocate intermediate sink buffers if the module produces only period bytes
@@ -432,8 +479,15 @@ int module_adapter_prepare(struct comp_dev *dev)
432479 /* allocate memory for input buffer data */
433480 size_t size = MAX (mod -> deep_buff_bytes , mod -> period_bytes );
434481
482+ // TODO: check if shared memory is needed
435483 list_for_item (blist , & dev -> bsource_list ) {
484+ #if CONFIG_SOF_VREGIONS
485+ struct vregion * vregion = module_get_vregion (mod );
486+ mod -> input_buffers [i ].data = vregion_alloc_align (vregion , VREGION_MEM_TYPE_LIFETIME_SHARED ,
487+ size , 0 );
488+ #else
436489 mod -> input_buffers [i ].data = rballoc (memory_flags , size );
490+ #endif
437491 if (!mod -> input_buffers [i ].data ) {
438492 comp_err (mod -> dev , "Failed to alloc input buffer data" );
439493 ret = - ENOMEM ;
@@ -445,7 +499,13 @@ int module_adapter_prepare(struct comp_dev *dev)
445499 /* allocate memory for output buffer data */
446500 i = 0 ;
447501 list_for_item (blist , & dev -> bsink_list ) {
502+ #if CONFIG_SOF_VREGIONS
503+ struct vregion * vregion = module_get_vregion (mod );
504+ mod -> output_buffers [i ].data = vregion_alloc_align (vregion , VREGION_MEM_TYPE_LIFETIME_SHARED ,
505+ size , 0 );
506+ #else
448507 mod -> output_buffers [i ].data = rballoc (memory_flags , md -> mpd .out_buff_size );
508+ #endif
449509 if (!mod -> output_buffers [i ].data ) {
450510 comp_err (mod -> dev , "Failed to alloc output buffer data" );
451511 ret = - ENOMEM ;
@@ -1224,17 +1284,32 @@ int module_adapter_reset(struct comp_dev *dev)
12241284 return ret ;
12251285 }
12261286
1287+ #if CONFIG_SOF_VREGIONS
1288+ if (IS_PROCESSING_MODE_RAW_DATA (mod )) {
1289+ struct vregion * vregion = module_get_vregion (mod );
1290+ for (i = 0 ; i < mod -> num_of_sinks ; i ++ )
1291+ vregion_free (vregion , (__sparse_force void * )mod -> output_buffers [i ].data );
1292+ for (i = 0 ; i < mod -> num_of_sources ; i ++ )
1293+ vregion_free (vregion , (__sparse_force void * )mod -> input_buffers [i ].data );
1294+ }
1295+ #else
12271296 if (IS_PROCESSING_MODE_RAW_DATA (mod )) {
12281297 for (i = 0 ; i < mod -> num_of_sinks ; i ++ )
12291298 rfree ((__sparse_force void * )mod -> output_buffers [i ].data );
12301299 for (i = 0 ; i < mod -> num_of_sources ; i ++ )
12311300 rfree ((__sparse_force void * )mod -> input_buffers [i ].data );
12321301 }
1302+ #endif
12331303
12341304 if (IS_PROCESSING_MODE_RAW_DATA (mod ) || IS_PROCESSING_MODE_AUDIO_STREAM (mod )) {
1305+ #if CONFIG_SOF_VREGIONS
1306+ struct vregion * vregion = module_get_vregion (mod );
1307+ vregion_free (vregion , mod -> output_buffers );
1308+ vregion_free (vregion , mod -> input_buffers );
1309+ #else
12351310 rfree (mod -> output_buffers );
12361311 rfree (mod -> input_buffers );
1237-
1312+ #endif
12381313 mod -> num_of_sources = 0 ;
12391314 mod -> num_of_sinks = 0 ;
12401315 }
@@ -1287,7 +1362,17 @@ void module_adapter_free(struct comp_dev *dev)
12871362#endif
12881363
12891364 rfree (mod -> stream_params );
1365+ #if CONFIG_SOF_VREGIONS
1366+ struct vregion * vregion = module_get_vregion (mod );
1367+ vregion_free (vregion , (__sparse_force void * )mod );
1368+
1369+ /* free the vregion if its a separate instance from the pipeline */
1370+ if (dev -> pipeline -> vregion != vregion )
1371+ vregion_destroy (vregion );
1372+ #else
1373+
12901374 rfree (mod );
1375+ #endif
12911376 rfree (dev );
12921377}
12931378EXPORT_SYMBOL (module_adapter_free );
0 commit comments