Skip to content

Commit 97e9037

Browse files
committed
module: adapter: use module memory APIs
Convert rmalloc and rballoc APIs to mod_alloc APIs. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent a2624fc commit 97e9037

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

src/audio/module_adapter/module_adapter.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -337,23 +337,31 @@ int module_adapter_prepare(struct comp_dev *dev)
337337

338338
module_adapter_check_data(mod, dev, sink);
339339

340+
/* get memory flags for input and output */
340341
memory_flags = user_get_buffer_memory_region(dev->drv);
342+
341343
/* allocate memory for input buffers */
342344
if (mod->max_sources) {
343345
mod->input_buffers =
344-
rzalloc(memory_flags, sizeof(*mod->input_buffers) * mod->max_sources);
346+
mod_alloc_ext(mod, memory_flags,
347+
sizeof(*mod->input_buffers) * mod->max_sources, 0);
348+
345349
if (!mod->input_buffers) {
346350
comp_err(dev, "failed to allocate input buffers");
347351
return -ENOMEM;
348352
}
349353
} else {
350354
mod->input_buffers = NULL;
351355
}
356+
memset(mod->input_buffers, 0, sizeof(*mod->input_buffers) * mod->max_sources);
352357

353358
/* allocate memory for output buffers */
359+
//TODO: check if shared memory is needed
354360
if (mod->max_sinks) {
355361
mod->output_buffers =
356-
rzalloc(memory_flags, sizeof(*mod->output_buffers) * mod->max_sinks);
362+
mod_alloc_ext(mod, memory_flags,
363+
sizeof(*mod->output_buffers) * mod->max_sinks, 0);
364+
357365
if (!mod->output_buffers) {
358366
comp_err(dev, "failed to allocate output buffers");
359367
ret = -ENOMEM;
@@ -362,6 +370,7 @@ int module_adapter_prepare(struct comp_dev *dev)
362370
} else {
363371
mod->output_buffers = NULL;
364372
}
373+
memset(mod->output_buffers, 0, sizeof(*mod->output_buffers) * mod->max_sinks);
365374

366375
/*
367376
* no need to allocate intermediate sink buffers if the module produces only period bytes
@@ -419,7 +428,8 @@ int module_adapter_prepare(struct comp_dev *dev)
419428
size_t size = MAX(mod->deep_buff_bytes, mod->period_bytes);
420429

421430
list_for_item(blist, &dev->bsource_list) {
422-
mod->input_buffers[i].data = rballoc(memory_flags, size);
431+
mod->input_buffers[i].data = mod_alloc_ext(mod, memory_flags, size, 0);
432+
423433
if (!mod->input_buffers[i].data) {
424434
comp_err(mod->dev, "Failed to alloc input buffer data");
425435
ret = -ENOMEM;
@@ -431,7 +441,8 @@ int module_adapter_prepare(struct comp_dev *dev)
431441
/* allocate memory for output buffer data */
432442
i = 0;
433443
list_for_item(blist, &dev->bsink_list) {
434-
mod->output_buffers[i].data = rballoc(memory_flags, md->mpd.out_buff_size);
444+
mod->output_buffers[i].data = mod_alloc_ext(mod, memory_flags,
445+
md->mpd.out_buff_size, 0);
435446
if (!mod->output_buffers[i].data) {
436447
comp_err(mod->dev, "Failed to alloc output buffer data");
437448
ret = -ENOMEM;
@@ -497,16 +508,16 @@ int module_adapter_prepare(struct comp_dev *dev)
497508

498509
out_data_free:
499510
for (i = 0; i < mod->num_of_sinks; i++)
500-
rfree(mod->output_buffers[i].data);
511+
mod_free(mod, mod->output_buffers[i].data);
501512

502513
in_data_free:
503514
for (i = 0; i < mod->num_of_sources; i++)
504-
rfree(mod->input_buffers[i].data);
515+
mod_free(mod, mod->input_buffers[i].data);
505516

506517
in_out_free:
507-
rfree(mod->output_buffers);
518+
mod_free(mod, mod->output_buffers);
508519
mod->output_buffers = NULL;
509-
rfree(mod->input_buffers);
520+
mod_free(mod, mod->input_buffers);
510521
mod->input_buffers = NULL;
511522
return ret;
512523
}
@@ -529,10 +540,9 @@ int module_adapter_params(struct comp_dev *dev, struct sof_ipc_stream_params *pa
529540

530541
/* allocate stream_params each time */
531542
if (mod->stream_params)
532-
rfree(mod->stream_params);
543+
mod_free(mod, mod->stream_params);
533544

534-
mod->stream_params = rzalloc(SOF_MEM_FLAG_USER,
535-
sizeof(*mod->stream_params) + params->ext_data_length);
545+
mod->stream_params = mod_alloc(mod, sizeof(*mod->stream_params) + params->ext_data_length);
536546
if (!mod->stream_params)
537547
return -ENOMEM;
538548

@@ -1212,15 +1222,14 @@ int module_adapter_reset(struct comp_dev *dev)
12121222

12131223
if (IS_PROCESSING_MODE_RAW_DATA(mod)) {
12141224
for (i = 0; i < mod->num_of_sinks; i++)
1215-
rfree((__sparse_force void *)mod->output_buffers[i].data);
1225+
mod_free(mod, (__sparse_force void *)mod->output_buffers[i].data);
12161226
for (i = 0; i < mod->num_of_sources; i++)
1217-
rfree((__sparse_force void *)mod->input_buffers[i].data);
1227+
mod_free(mod, (__sparse_force void *)mod->input_buffers[i].data);
12181228
}
12191229

12201230
if (IS_PROCESSING_MODE_RAW_DATA(mod) || IS_PROCESSING_MODE_AUDIO_STREAM(mod)) {
1221-
rfree(mod->output_buffers);
1222-
rfree(mod->input_buffers);
1223-
1231+
mod_free(mod, mod->output_buffers);
1232+
mod_free(mod, mod->input_buffers);
12241233
mod->num_of_sources = 0;
12251234
mod->num_of_sinks = 0;
12261235
}
@@ -1234,7 +1243,7 @@ int module_adapter_reset(struct comp_dev *dev)
12341243
buffer_zero(buffer);
12351244
}
12361245

1237-
rfree(mod->stream_params);
1246+
mod_free(mod, mod->stream_params);
12381247
mod->stream_params = NULL;
12391248

12401249
comp_dbg(dev, "done");
@@ -1268,7 +1277,8 @@ void module_adapter_free(struct comp_dev *dev)
12681277

12691278
mod_free_all(mod);
12701279

1271-
rfree(mod->stream_params);
1280+
mod_free(mod, mod->stream_params);
1281+
12721282
module_adapter_mem_free(mod);
12731283
}
12741284
EXPORT_SYMBOL(module_adapter_free);

0 commit comments

Comments
 (0)