Skip to content

Commit 1c7576f

Browse files
committed
audio: module_adapter: make adapter buffering user-space compatible
Replace all calls to rzalloc() and rballoc() with calls to sof_heap_alloc() with heap set based on how SOF is built. If audio pipelines are run fully in user-space, the sof_sys_user_heap_get() should be used. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 6cbf702 commit 1c7576f

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

src/audio/module_adapter/module_adapter.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -519,24 +519,28 @@ int module_adapter_prepare(struct comp_dev *dev)
519519
/* allocate memory for input buffers */
520520
if (mod->max_sources) {
521521
mod->input_buffers =
522-
rzalloc(memory_flags, sizeof(*mod->input_buffers) * mod->max_sources);
522+
sof_heap_alloc(sof_sys_user_heap_get(), memory_flags,
523+
sizeof(*mod->input_buffers) * mod->max_sources, 0);
523524
if (!mod->input_buffers) {
524525
comp_err(dev, "failed to allocate input buffers");
525526
return -ENOMEM;
526527
}
528+
memset(mod->input_buffers, 0, sizeof(*mod->input_buffers) * mod->max_sources);
527529
} else {
528530
mod->input_buffers = NULL;
529531
}
530532

531533
/* allocate memory for output buffers */
532534
if (mod->max_sinks) {
533535
mod->output_buffers =
534-
rzalloc(memory_flags, sizeof(*mod->output_buffers) * mod->max_sinks);
536+
sof_heap_alloc(sof_sys_user_heap_get(), memory_flags,
537+
sizeof(*mod->output_buffers) * mod->max_sources, 0);
535538
if (!mod->output_buffers) {
536539
comp_err(dev, "failed to allocate output buffers");
537540
ret = -ENOMEM;
538541
goto in_out_free;
539542
}
543+
memset(mod->input_buffers, 0, sizeof(*mod->output_buffers) * mod->max_sources);
540544
} else {
541545
mod->output_buffers = NULL;
542546
}
@@ -597,7 +601,8 @@ int module_adapter_prepare(struct comp_dev *dev)
597601
size_t size = MAX(mod->deep_buff_bytes, mod->period_bytes);
598602

599603
list_for_item(blist, &dev->bsource_list) {
600-
mod->input_buffers[i].data = rballoc(memory_flags, size);
604+
mod->input_buffers[i].data = sof_heap_alloc(sof_sys_user_heap_get(),
605+
memory_flags, size, 0);
601606
if (!mod->input_buffers[i].data) {
602607
comp_err(mod->dev, "Failed to alloc input buffer data");
603608
ret = -ENOMEM;
@@ -609,7 +614,9 @@ int module_adapter_prepare(struct comp_dev *dev)
609614
/* allocate memory for output buffer data */
610615
i = 0;
611616
list_for_item(blist, &dev->bsink_list) {
612-
mod->output_buffers[i].data = rballoc(memory_flags, md->mpd.out_buff_size);
617+
mod->output_buffers[i].data = sof_heap_alloc(sof_sys_user_heap_get(),
618+
memory_flags,
619+
md->mpd.out_buff_size, 0);
613620
if (!mod->output_buffers[i].data) {
614621
comp_err(mod->dev, "Failed to alloc output buffer data");
615622
ret = -ENOMEM;
@@ -684,16 +691,16 @@ int module_adapter_prepare(struct comp_dev *dev)
684691

685692
out_data_free:
686693
for (i = 0; i < mod->num_of_sinks; i++)
687-
rfree(mod->output_buffers[i].data);
694+
sof_heap_free(sof_sys_user_heap_get(), mod->output_buffers[i].data);
688695

689696
in_data_free:
690697
for (i = 0; i < mod->num_of_sources; i++)
691-
rfree(mod->input_buffers[i].data);
698+
sof_heap_free(sof_sys_user_heap_get(), mod->input_buffers[i].data);
692699

693700
in_out_free:
694-
rfree(mod->output_buffers);
701+
sof_heap_free(sof_sys_user_heap_get(), mod->output_buffers);
695702
mod->output_buffers = NULL;
696-
rfree(mod->input_buffers);
703+
sof_heap_free(sof_sys_user_heap_get(), mod->input_buffers);
697704
mod->input_buffers = NULL;
698705
return ret;
699706
}
@@ -1405,14 +1412,16 @@ int module_adapter_reset(struct comp_dev *dev)
14051412

14061413
if (IS_PROCESSING_MODE_RAW_DATA(mod)) {
14071414
for (i = 0; i < mod->num_of_sinks; i++)
1408-
rfree((__sparse_force void *)mod->output_buffers[i].data);
1415+
sof_heap_free(sof_sys_user_heap_get(),
1416+
(__sparse_force void *)mod->output_buffers[i].data);
14091417
for (i = 0; i < mod->num_of_sources; i++)
1410-
rfree((__sparse_force void *)mod->input_buffers[i].data);
1418+
sof_heap_free(sof_sys_user_heap_get(),
1419+
(__sparse_force void *)mod->input_buffers[i].data);
14111420
}
14121421

14131422
if (IS_PROCESSING_MODE_RAW_DATA(mod) || IS_PROCESSING_MODE_AUDIO_STREAM(mod)) {
1414-
rfree(mod->output_buffers);
1415-
rfree(mod->input_buffers);
1423+
sof_heap_free(sof_sys_user_heap_get(), mod->output_buffers);
1424+
sof_heap_free(sof_sys_user_heap_get(), mod->input_buffers);
14161425

14171426
mod->num_of_sources = 0;
14181427
mod->num_of_sinks = 0;

0 commit comments

Comments
 (0)