@@ -150,8 +150,20 @@ void *mod_balloc_align(struct processing_module *mod, size_t size, size_t alignm
150150 return NULL ;
151151 }
152152
153+ #if CONFIG_SOF_VREGIONS
154+ /* do we need to use the dynamic heap or the static heap? */
155+ struct vregion * vregion = module_get_vregion (mod );
156+ if (mod -> priv .state != MODULE_INITIALIZED ) {
157+ /* lifetime allocator */
158+ ptr = vregion_alloc_align (vregion , VREGION_MEM_TYPE_LIFETIME , size , alignment );
159+ } else {
160+ /* interim allocator */
161+ ptr = vregion_alloc_align (vregion , VREGION_MEM_TYPE_INTERIM , size , alignment );
162+ }
163+ #else
153164 /* Allocate memory for module */
154165 ptr = rballoc_align (SOF_MEM_FLAG_USER , size , alignment );
166+ #endif
155167
156168 if (!ptr ) {
157169 comp_err (mod -> dev , "Failed to alloc %zu bytes %zu alignment for comp %#x." ,
@@ -201,8 +213,20 @@ void *mod_alloc_ext(struct processing_module *mod, uint32_t flags, size_t size,
201213 return NULL ;
202214 }
203215
216+ #if CONFIG_SOF_VREGIONS
217+ /* do we need to use the dynamic heap or the static heap? */
218+ struct vregion * vregion = module_get_vregion (mod );
219+ if (mod -> priv .state != MODULE_INITIALIZED ) {
220+ /* static allocator */
221+ ptr = vregion_alloc_align (vregion , VREGION_MEM_TYPE_LIFETIME , size , alignment );
222+ } else {
223+ /* dynamic allocator */
224+ ptr = vregion_alloc_align (vregion , VREGION_MEM_TYPE_INTERIM , size , alignment );
225+ }
226+ #else
204227 /* Allocate memory for module */
205228 ptr = rmalloc_align (flags , size , alignment );
229+ #endif
206230 if (!ptr ) {
207231 comp_err (mod -> dev , "Failed to alloc %zu bytes %zu alignment for comp %#x." ,
208232 size , alignment , dev_comp_id (mod -> dev ));
@@ -302,7 +326,12 @@ static int free_contents(struct processing_module *mod, struct module_resource *
302326
303327 switch (container -> type ) {
304328 case MOD_RES_HEAP :
329+ #if CONFIG_SOF_VREGIONS
330+ struct vregion * vregion = module_get_vregion (mod );
331+ vregion_free (vregion , container -> ptr );
332+ #else
305333 rfree (container -> ptr );
334+ #endif
306335 res -> heap_usage -= container -> size ;
307336 return 0 ;
308337#if CONFIG_COMP_BLOB
@@ -411,16 +440,55 @@ void mod_free_all(struct processing_module *mod)
411440EXPORT_SYMBOL (mod_free_all );
412441
413442struct processing_module * module_adapter_mem_alloc (const struct comp_driver * drv ,
414- const struct comp_ipc_config * config )
443+ const struct comp_ipc_config * config ,
444+ struct pipeline * pipeline )
415445{
416446 struct comp_dev * dev = comp_alloc (drv , sizeof (* dev ));
417447 struct processing_module * mod ;
448+ struct vregion * vregion ;
418449
419450 if (!dev ) {
420451 comp_cl_err (drv , "failed to allocate memory for comp_dev" );
421452 return NULL ;
422453 }
423454
455+ /* check for pipeline */
456+ if (!pipeline || !pipeline -> vregion ) {
457+ comp_cl_err (drv , "failed to get pipeline" );
458+ return NULL ;
459+ }
460+
461+ #if CONFIG_SOF_VREGIONS
462+
463+ /* TODO: determine if our user domain is different from the LL pipeline domain */
464+ if (config -> proc_domain == COMP_PROCESSING_DOMAIN_DP ) {
465+ // TODO: get the text, heap, stack and shared sizes from topology too
466+ /* create a vregion region for all resources */
467+ size_t interim_size = 0x4000 ; /* 16kB scratch */
468+ size_t lifetime_size = 0x20000 ; /* 128kB batch */
469+ size_t shared_size = 0x4000 ; /* 16kB shared */
470+ size_t text_size = 0x4000 ; /* 16kB text */
471+
472+ vregion = vregion_create (lifetime_size , interim_size , shared_size ,
473+ 0 , text_size );
474+ if (!vregion ) {
475+ //comp_err(dev, "failed to create vregion for DP module");
476+ goto err ;
477+ }
478+ } else {
479+ /* LL modules use pipeline vregion */
480+ vregion = pipeline -> vregion ;
481+ }
482+
483+ /* allocate module in correct vregion*/
484+ //TODO: add coherent flag for cross core DP modules
485+ mod = vregion_alloc (vregion , VREGION_MEM_TYPE_LIFETIME , sizeof (* mod ));
486+ if (!mod ) {
487+ comp_err (dev , "failed to allocate memory for module" );
488+ goto err ;
489+ }
490+ #else
491+
424492 /* allocate module information.
425493 * for DP shared modules this struct must be accessible from all cores
426494 * Unfortunately at this point there's no information of components the module
@@ -432,6 +500,7 @@ struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv
432500
433501 mod = module_driver_heap_rzalloc (drv -> user_heap , flags ,
434502 sizeof (* mod ));
503+ #endif
435504 if (!mod ) {
436505 comp_err (dev , "failed to allocate memory for module" );
437506 goto err ;
@@ -441,6 +510,10 @@ struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv
441510 mod -> dev = dev ;
442511 dev -> mod = mod ;
443512
513+ /* set virtual region for DP module only otherwise we use pipeline vregion */
514+ if (config -> proc_domain == COMP_PROCESSING_DOMAIN_DP )
515+ mod -> vregion = vregion ;
516+
444517 return mod ;
445518
446519err :
0 commit comments