Skip to content

Commit b35816b

Browse files
committed
wip: module code for test
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 5dc9116 commit b35816b

File tree

3 files changed

+91
-10
lines changed

3 files changed

+91
-10
lines changed

src/audio/module_adapter/module/memory.c

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)
411440
EXPORT_SYMBOL(mod_free_all);
412441

413442
struct 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

446519
err:

src/audio/module_adapter/module_adapter.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
6363
int ret;
6464
struct module_config *dst;
6565
const struct module_interface *const interface = drv->adapter_ops;
66+
struct pipeline *pipeline = NULL;
6667

6768
comp_cl_dbg(drv, "start");
6869

@@ -72,7 +73,18 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
7273
return NULL;
7374
}
7475

75-
struct processing_module *mod = module_adapter_mem_alloc(drv, config);
76+
#if CONFIG_IPC_MAJOR_4
77+
struct ipc_comp_dev *ipc_pipe;
78+
struct ipc *ipc = ipc_get();
79+
80+
/* set the pipeline pointer if ipc_pipe is valid */
81+
ipc_pipe = ipc_get_comp_by_ppl_id(ipc, COMP_TYPE_PIPELINE, config->pipeline_id,
82+
IPC_COMP_IGNORE_REMOTE);
83+
if (ipc_pipe) {
84+
pipeline = ipc_pipe->pipeline;
85+
}
86+
#endif
87+
struct processing_module *mod = module_adapter_mem_alloc(drv, config, pipeline);
7688

7789
if (!mod)
7890
return NULL;
@@ -107,14 +119,9 @@ struct comp_dev *module_adapter_new_ext(const struct comp_driver *drv,
107119
goto err;
108120

109121
#if CONFIG_IPC_MAJOR_4
110-
struct ipc_comp_dev *ipc_pipe;
111-
struct ipc *ipc = ipc_get();
112-
113-
/* set the pipeline pointer if ipc_pipe is valid */
114-
ipc_pipe = ipc_get_comp_by_ppl_id(ipc, COMP_TYPE_PIPELINE, config->pipeline_id,
115-
IPC_COMP_IGNORE_REMOTE);
122+
/* set up ipc4 configuration items if needed from topology */
116123
if (ipc_pipe) {
117-
dev->pipeline = ipc_pipe->pipeline;
124+
dev->pipeline = pipeline;
118125

119126
/* LL modules have the same period as the pipeline */
120127
if (dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_LL)

src/include/sof/audio/module_adapter/module/generic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ static inline void *mod_zalloc(struct processing_module *mod, size_t size)
228228
int mod_free(struct processing_module *mod, const void *ptr);
229229
void module_adapter_mem_free(struct processing_module *mod);
230230
struct processing_module *module_adapter_mem_alloc(const struct comp_driver *drv,
231-
const struct comp_ipc_config *config);
231+
const struct comp_ipc_config *config,
232+
struct pipeline *pipeline);
232233
#if CONFIG_COMP_BLOB
233234
struct comp_data_blob_handler *mod_data_blob_handler_new(struct processing_module *mod);
234235
void mod_data_blob_handler_free(struct processing_module *mod, struct comp_data_blob_handler *dbh);

0 commit comments

Comments
 (0)