Skip to content

Commit 0368ed0

Browse files
committed
wip: vregion: add module support for vregion.
Make modules use the vregion for allocations. TODO: abstract usage. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent cc92627 commit 0368ed0

File tree

3 files changed

+132
-5
lines changed

3 files changed

+132
-5
lines changed

src/audio/module_adapter/module/generic.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,20 @@ void *mod_balloc_align(struct processing_module *mod, size_t size, size_t alignm
194194
return NULL;
195195
}
196196

197-
/* Allocate buffer memory for module */
197+
#if CONFIG_SOF_VREGIONS
198+
/* do we need to use the dynamic heap or the static heap? */
199+
struct vregion *vregion = module_get_vregion(mod);
200+
if (mod->priv.state != MODULE_INITIALIZED) {
201+
/* lifetime allocator */
202+
ptr = vregion_alloc_align(vregion, VREGION_MEM_TYPE_LIFETIME, size, alignment);
203+
} else {
204+
/* interim allocator */
205+
ptr = vregion_alloc_align(vregion, VREGION_MEM_TYPE_INTERIM, size, alignment);
206+
}
207+
#else
208+
/* Allocate memory for module */
198209
ptr = rballoc_align(SOF_MEM_FLAG_USER, size, alignment);
210+
#endif
199211

200212
if (!ptr) {
201213
comp_err(mod->dev, "Failed to alloc %zu bytes %zu alignment for comp %#x.",
@@ -244,8 +256,20 @@ void *mod_alloc_align(struct processing_module *mod, size_t size, size_t alignme
244256
return NULL;
245257
}
246258

259+
#if CONFIG_SOF_VREGIONS
260+
/* do we need to use the dynamic heap or the static heap? */
261+
struct vregion *vregion = module_get_vregion(mod);
262+
if (mod->priv.state != MODULE_INITIALIZED) {
263+
/* static allocator */
264+
ptr = vregion_alloc_align(vregion, VREGION_MEM_TYPE_LIFETIME, size, alignment);
265+
} else {
266+
/* dynamic allocator */
267+
ptr = vregion_alloc_align(vregion, VREGION_MEM_TYPE_INTERIM, size, alignment);
268+
}
269+
#else
247270
/* Allocate memory for module */
248271
ptr = rmalloc_align(SOF_MEM_FLAG_USER, size, alignment);
272+
#endif
249273

250274
if (!ptr) {
251275
comp_err(mod->dev, "Failed to alloc %zu bytes %zu alignment for comp %#x.",
@@ -346,7 +370,12 @@ static int free_contents(struct processing_module *mod, struct module_resource *
346370

347371
switch (container->type) {
348372
case MOD_RES_HEAP:
373+
#if CONFIG_SOF_VREGIONS
374+
struct vregion *vregion = module_get_vregion(mod);
375+
vregion_free(vregion, container->ptr);
376+
#else
349377
rfree(container->ptr);
378+
#endif
350379
res->heap_usage -= container->size;
351380
return 0;
352381
#if CONFIG_COMP_BLOB

src/audio/module_adapter/module_adapter.c

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
12931378
EXPORT_SYMBOL(module_adapter_free);

src/include/module/module/base.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,17 @@ struct processing_module {
8585
struct module_data priv; /**< module private data */
8686
uint32_t period_bytes; /** pipeline period bytes */
8787

88+
/* virtual region iff not using the parent pipeline region.
89+
* i.e. a DP module in a different memory domain from rest of pipeline.
90+
*/
91+
struct vregion *vregion;
92+
8893
/*
8994
* Fields below can only be accessed by the SOF and must be moved to a new structure.
9095
* Below #ifdef is a temporary solution used until work on separating a common interface
9196
* for loadable modules is completed.
9297
*/
93-
#ifdef SOF_MODULE_API_PRIVATE
98+
//#ifdef SOF_MODULE_API_PRIVATE
9499
struct sof_ipc_stream_params *stream_params;
95100
/* list of sink buffers to save produced output, to be used in Raw data
96101
* processing mode
@@ -189,7 +194,15 @@ struct processing_module {
189194
#if CONFIG_USERSPACE
190195
struct userspace_context *user_ctx;
191196
#endif /* CONFIG_USERSPACE */
192-
#endif /* SOF_MODULE_PRIVATE */
197+
//#endif /* SOF_MODULE_PRIVATE */
193198
};
194199

200+
static inline struct vregion *module_get_vregion(struct processing_module *mod)
201+
{
202+
if (mod->vregion)
203+
return mod->vregion;
204+
else
205+
return mod->dev->pipeline->vregion;
206+
}
207+
195208
#endif /* __MODULE_MODULE_BASE__ */

0 commit comments

Comments
 (0)