Skip to content

Commit fd84a31

Browse files
committed
audio: module_adapter: use system user heap for allocs
When SOF is built with LL pipes in user-space, module adapter should allocate all resources from the user system heap. Add support for this by modifying allocs to use sof_heap_alloc() and initialize the heap with sof_sys_user_heap_get(). This will return a user-space heap in case SOF is built with CONFIG_SOF_USERSPACE_LL. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 1f4b8f0 commit fd84a31

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

src/audio/module_adapter/module_adapter.c

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
101101
}
102102
mod_heap = NULL;
103103
} else {
104+
#ifdef CONFIG_SOF_USERSPACE_LL
105+
mod_heap = sof_sys_user_heap_get();
106+
comp_cl_dbg(drv, "using ll user heap for module");
107+
#else
104108
mod_heap = drv->user_heap;
109+
#endif
105110
heap_size = 0;
106111
mod_vreg = NULL;
107112
}
@@ -118,7 +123,7 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
118123
goto emod;
119124
}
120125

121-
struct mod_alloc_ctx *alloc = rmalloc(flags, sizeof(*alloc));
126+
struct mod_alloc_ctx *alloc = sof_heap_alloc(mod_heap, flags, sizeof(*alloc), 0);
122127

123128
if (!alloc)
124129
goto ealloc;
@@ -154,7 +159,7 @@ static struct processing_module *module_adapter_mem_alloc(const struct comp_driv
154159
return mod;
155160

156161
edev:
157-
rfree(alloc);
162+
sof_heap_free(mod_heap, alloc);
158163
ealloc:
159164
if (mod_vreg)
160165
vregion_free(mod_vreg, mod);
@@ -184,11 +189,11 @@ static void module_adapter_mem_free(struct processing_module *mod)
184189
vregion_free(mod_vreg, mod->dev);
185190
vregion_free(mod_vreg, mod);
186191
if (!vregion_put(mod_vreg))
187-
rfree(alloc);
192+
sof_heap_free(alloc->heap, alloc);
188193
} else {
189194
sof_heap_free(mod_heap, mod->dev);
190195
sof_heap_free(mod_heap, mod);
191-
rfree(alloc);
196+
sof_heap_free(mod_heap, alloc);
192197
}
193198
}
194199

@@ -527,24 +532,28 @@ int module_adapter_prepare(struct comp_dev *dev)
527532
/* allocate memory for input buffers */
528533
if (mod->max_sources) {
529534
mod->input_buffers =
530-
rzalloc(memory_flags, sizeof(*mod->input_buffers) * mod->max_sources);
535+
sof_heap_alloc(sof_sys_user_heap_get(), memory_flags,
536+
sizeof(*mod->input_buffers) * mod->max_sources, 0);
531537
if (!mod->input_buffers) {
532538
comp_err(dev, "failed to allocate input buffers");
533539
return -ENOMEM;
534540
}
541+
memset(mod->input_buffers, 0, sizeof(*mod->input_buffers) * mod->max_sources);
535542
} else {
536543
mod->input_buffers = NULL;
537544
}
538545

539546
/* allocate memory for output buffers */
540547
if (mod->max_sinks) {
541548
mod->output_buffers =
542-
rzalloc(memory_flags, sizeof(*mod->output_buffers) * mod->max_sinks);
549+
sof_heap_alloc(sof_sys_user_heap_get(), memory_flags,
550+
sizeof(*mod->output_buffers) * mod->max_sinks, 0);
543551
if (!mod->output_buffers) {
544552
comp_err(dev, "failed to allocate output buffers");
545553
ret = -ENOMEM;
546554
goto in_out_free;
547555
}
556+
memset(mod->output_buffers, 0, sizeof(*mod->output_buffers) * mod->max_sinks);
548557
} else {
549558
mod->output_buffers = NULL;
550559
}
@@ -605,7 +614,8 @@ int module_adapter_prepare(struct comp_dev *dev)
605614
size_t size = MAX(mod->deep_buff_bytes, mod->period_bytes);
606615

607616
list_for_item(blist, &dev->bsource_list) {
608-
mod->input_buffers[i].data = rballoc(memory_flags, size);
617+
mod->input_buffers[i].data = sof_heap_alloc(sof_sys_user_heap_get(),
618+
memory_flags, size, 0);
609619
if (!mod->input_buffers[i].data) {
610620
comp_err(mod->dev, "Failed to alloc input buffer data");
611621
ret = -ENOMEM;
@@ -617,7 +627,9 @@ int module_adapter_prepare(struct comp_dev *dev)
617627
/* allocate memory for output buffer data */
618628
i = 0;
619629
list_for_item(blist, &dev->bsink_list) {
620-
mod->output_buffers[i].data = rballoc(memory_flags, md->mpd.out_buff_size);
630+
mod->output_buffers[i].data = sof_heap_alloc(sof_sys_user_heap_get(),
631+
memory_flags,
632+
md->mpd.out_buff_size, 0);
621633
if (!mod->output_buffers[i].data) {
622634
comp_err(mod->dev, "Failed to alloc output buffer data");
623635
ret = -ENOMEM;
@@ -686,16 +698,16 @@ int module_adapter_prepare(struct comp_dev *dev)
686698

687699
out_data_free:
688700
for (i = 0; i < mod->num_of_sinks; i++)
689-
rfree(mod->output_buffers[i].data);
701+
sof_heap_free(sof_sys_user_heap_get(), mod->output_buffers[i].data);
690702

691703
in_data_free:
692704
for (i = 0; i < mod->num_of_sources; i++)
693-
rfree(mod->input_buffers[i].data);
705+
sof_heap_free(sof_sys_user_heap_get(), mod->input_buffers[i].data);
694706

695707
in_out_free:
696-
rfree(mod->output_buffers);
708+
sof_heap_free(sof_sys_user_heap_get(), mod->output_buffers);
697709
mod->output_buffers = NULL;
698-
rfree(mod->input_buffers);
710+
sof_heap_free(sof_sys_user_heap_get(), mod->input_buffers);
699711
mod->input_buffers = NULL;
700712
return ret;
701713
}
@@ -1407,14 +1419,16 @@ int module_adapter_reset(struct comp_dev *dev)
14071419

14081420
if (IS_PROCESSING_MODE_RAW_DATA(mod)) {
14091421
for (i = 0; i < mod->num_of_sinks; i++)
1410-
rfree((__sparse_force void *)mod->output_buffers[i].data);
1422+
sof_heap_free(sof_sys_user_heap_get(),
1423+
(__sparse_force void *)mod->output_buffers[i].data);
14111424
for (i = 0; i < mod->num_of_sources; i++)
1412-
rfree((__sparse_force void *)mod->input_buffers[i].data);
1425+
sof_heap_free(sof_sys_user_heap_get(),
1426+
(__sparse_force void *)mod->input_buffers[i].data);
14131427
}
14141428

14151429
if (IS_PROCESSING_MODE_RAW_DATA(mod) || IS_PROCESSING_MODE_AUDIO_STREAM(mod)) {
1416-
rfree(mod->output_buffers);
1417-
rfree(mod->input_buffers);
1430+
sof_heap_free(sof_sys_user_heap_get(), mod->output_buffers);
1431+
sof_heap_free(sof_sys_user_heap_get(), mod->input_buffers);
14181432

14191433
mod->num_of_sources = 0;
14201434
mod->num_of_sinks = 0;

0 commit comments

Comments
 (0)