Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)
notifier_unregister_all(NULL, buffer);

rfree(buffer->stream.addr);
rfree(buffer);
sof_heap_free(buffer->audio_buffer.heap, buffer);
}

APP_TASK_DATA static const struct source_ops comp_buffer_source_ops = {
Expand Down Expand Up @@ -189,7 +189,8 @@ static const struct audio_buffer_ops audio_buffer_ops = {
.set_alignment_constants = comp_buffer_set_alignment_constants,
};

static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size,
static struct comp_buffer *buffer_alloc_struct(struct k_heap *heap,
void *stream_addr, size_t size,
uint32_t flags, bool is_shared)
{
struct comp_buffer *buffer;
Expand All @@ -200,13 +201,14 @@ static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size,
if (is_shared)
flags |= SOF_MEM_FLAG_COHERENT;

buffer = rzalloc(flags, sizeof(*buffer));

buffer = sof_heap_alloc(heap, flags, sizeof(*buffer), 0);
if (!buffer) {
tr_err(&buffer_tr, "could not alloc structure");
return NULL;
}

memset(buffer, 0, sizeof(*buffer));

buffer->flags = flags;
/* Force channels to 2 for init to prevent bad call to clz in buffer_init_stream */
buffer->stream.runtime_stream_params.channels = 2;
Expand All @@ -221,14 +223,15 @@ static struct comp_buffer *buffer_alloc_struct(void *stream_addr, size_t size,

audio_stream_set_underrun(&buffer->stream, !!(flags & SOF_BUF_UNDERRUN_PERMITTED));
audio_stream_set_overrun(&buffer->stream, !!(flags & SOF_BUF_OVERRUN_PERMITTED));
buffer->audio_buffer.heap = heap;

comp_buffer_reset_source_list(buffer);
comp_buffer_reset_sink_list(buffer);

return buffer;
}

struct comp_buffer *buffer_alloc(size_t size, uint32_t flags, uint32_t align,
struct comp_buffer *buffer_alloc(struct k_heap *heap, size_t size, uint32_t flags, uint32_t align,
bool is_shared)
{
struct comp_buffer *buffer;
Expand All @@ -249,7 +252,7 @@ struct comp_buffer *buffer_alloc(size_t size, uint32_t flags, uint32_t align,
return NULL;
}

buffer = buffer_alloc_struct(stream_addr, size, flags, is_shared);
buffer = buffer_alloc_struct(heap, stream_addr, size, flags, is_shared);
if (!buffer) {
tr_err(&buffer_tr, "could not alloc buffer structure");
rfree(stream_addr);
Expand All @@ -258,7 +261,8 @@ struct comp_buffer *buffer_alloc(size_t size, uint32_t flags, uint32_t align,
return buffer;
}

struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_size,
struct comp_buffer *buffer_alloc_range(struct k_heap *heap, size_t preferred_size,
size_t minimum_size,
uint32_t flags, uint32_t align, bool is_shared)
{
struct comp_buffer *buffer;
Expand Down Expand Up @@ -292,7 +296,7 @@ struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_siz
return NULL;
}

buffer = buffer_alloc_struct(stream_addr, size, flags, is_shared);
buffer = buffer_alloc_struct(heap, stream_addr, size, flags, is_shared);
if (!buffer) {
tr_err(&buffer_tr, "could not alloc buffer structure");
rfree(stream_addr);
Expand Down
2 changes: 1 addition & 1 deletion src/audio/chain_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ __cold static int chain_task_init(struct comp_dev *dev, uint8_t host_dma_id, uin

fifo_size = ALIGN_UP_INTERNAL(fifo_size, addr_align);
/* allocate not shared buffer */
cd->dma_buffer = buffer_alloc(fifo_size, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA,
cd->dma_buffer = buffer_alloc(NULL, fifo_size, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA,
addr_align, BUFFER_USAGE_NOT_SHARED);

if (!cd->dma_buffer) {
Expand Down
2 changes: 1 addition & 1 deletion src/audio/copier/copier_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ __cold int create_multi_endpoint_buffer(struct comp_dev *dev,
ipc_buf.size = buf_size;
ipc_buf.comp.pipeline_id = config->pipeline_id;
ipc_buf.comp.core = config->core;
buffer = buffer_new(&ipc_buf, BUFFER_USAGE_NOT_SHARED);
buffer = buffer_new(NULL, &ipc_buf, BUFFER_USAGE_NOT_SHARED);
if (!buffer)
return -ENOMEM;

Expand Down
3 changes: 2 additions & 1 deletion src/audio/dai-legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ int dai_common_params(struct dai_data *dd, struct comp_dev *dev,
return err;
}
} else {
dd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA,
dd->dma_buffer = buffer_alloc(NULL, buffer_size,
SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA,
addr_align, BUFFER_USAGE_NOT_SHARED);
if (!dd->dma_buffer) {
comp_err(dev, "failed to alloc dma buffer");
Expand Down
2 changes: 1 addition & 1 deletion src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ static int dai_set_dma_buffer(struct dai_data *dd, struct comp_dev *dev,
return err;
}
} else {
dd->dma_buffer = buffer_alloc_range(buffer_size_preferred, buffer_size,
dd->dma_buffer = buffer_alloc_range(NULL, buffer_size_preferred, buffer_size,
SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA,
addr_align, BUFFER_USAGE_NOT_SHARED);
if (!dd->dma_buffer) {
Expand Down
3 changes: 2 additions & 1 deletion src/audio/host-legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,8 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
goto out;
}
} else {
hd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA,
hd->dma_buffer = buffer_alloc(NULL, buffer_size,
SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA,
addr_align, BUFFER_USAGE_NOT_SHARED);
if (!hd->dma_buffer) {
comp_err(dev, "failed to alloc dma buffer");
Expand Down
2 changes: 1 addition & 1 deletion src/audio/host-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ int host_common_params(struct host_data *hd, struct comp_dev *dev,
}
} else {
/* allocate not shared buffer */
hd->dma_buffer = buffer_alloc_range(buffer_size_preferred, buffer_size,
hd->dma_buffer = buffer_alloc_range(NULL, buffer_size_preferred, buffer_size,
SOF_MEM_FLAG_USER | SOF_MEM_FLAG_DMA,
addr_align, BUFFER_USAGE_NOT_SHARED);
if (!hd->dma_buffer) {
Expand Down
3 changes: 2 additions & 1 deletion src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ int module_adapter_prepare(struct comp_dev *dev)
if (list_is_empty(&mod->raw_data_buffers_list)) {
for (i = 0; i < mod->num_of_sinks; i++) {
/* allocate not shared buffer */
struct comp_buffer *buffer = buffer_alloc(buff_size, memory_flags,
struct comp_buffer *buffer = buffer_alloc(md->resources.heap, buff_size,
memory_flags,
PLATFORM_DCACHE_ALIGN,
BUFFER_USAGE_NOT_SHARED);
uint32_t flags;
Expand Down
6 changes: 5 additions & 1 deletion src/audio/src/src_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ int src_params_general(struct processing_module *mod,
/* free any existing delay lines. TODO reuse if same size */
mod_free(mod, cd->delay_lines);

cd->delay_lines = mod_balloc(mod, delay_lines_size);
cd->delay_lines = mod_alloc(mod, delay_lines_size);
if (!cd->delay_lines) {
comp_err(dev, "failed to alloc cd->delay_lines, delay_lines_size = %zu",
delay_lines_size);
Expand Down Expand Up @@ -683,9 +683,13 @@ int src_reset(struct processing_module *mod)

__cold int src_free(struct processing_module *mod)
{
struct comp_data *cd = module_get_private_data(mod);

assert_can_be_cold();

comp_info(mod->dev, "entry");
mod_free(mod, cd->delay_lines);
mod_free(mod, cd);

return 0;
}
10 changes: 7 additions & 3 deletions src/include/sof/audio/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,16 @@ struct buffer_cb_free {
buffer->cb_type = type; \
} while (0)

struct k_heap;

/* pipeline buffer creation and destruction */
struct comp_buffer *buffer_alloc(size_t size, uint32_t flags, uint32_t align,
struct comp_buffer *buffer_alloc(struct k_heap *heap, size_t size, uint32_t flags, uint32_t align,
bool is_shared);
struct comp_buffer *buffer_alloc_range(size_t preferred_size, size_t minimum_size,
struct comp_buffer *buffer_alloc_range(struct k_heap *heap, size_t preferred_size,
size_t minimum_size,
uint32_t flags, uint32_t align, bool is_shared);
struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is_shared);
struct comp_buffer *buffer_new(struct k_heap *heap, const struct sof_ipc_buffer *desc,
bool is_shared);

int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignment);
int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, size_t minimum_size,
Expand Down
1 change: 0 additions & 1 deletion src/include/sof/lib/notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ enum notify_id {
NOTIFIER_ID_BUFFER_FREE, /* struct buffer_cb_free* */
NOTIFIER_ID_DMA_COPY, /* struct dma_cb_data* */
NOTIFIER_ID_LL_POST_RUN, /* NULL */
NOTIFIER_ID_LL_PRE_RUN, /* NULL */
NOTIFIER_ID_DMA_IRQ, /* struct dma_chan_data * */
NOTIFIER_ID_DAI_TRIGGER, /* struct dai_group * */
NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE, /* struct mic_privacy_settings * */
Expand Down
9 changes: 0 additions & 9 deletions src/include/sof/lib_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,6 @@ void lib_manager_get_instance_bss_address(uint32_t instance_id,
const struct sof_man_module *mod,
void __sparse_cache **va_addr, size_t *size);

/*
* \brief Free module
*
* param[in] component_id - component id coming from ipc config. This function reguires valid
* lib_id and module_id fields of component id.
*
* Function is responsible to free module resources in HP memory.
*/
int lib_manager_free_module(const uint32_t component_id);
/*
* \brief Load library
*
Expand Down
1 change: 1 addition & 0 deletions src/include/sof/llext_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ int llext_manager_free_module(const uint32_t component_id);
int llext_manager_add_library(uint32_t module_id);

int llext_manager_add_domain(const uint32_t component_id, struct k_mem_domain *domain);
int llext_manager_rm_domain(const uint32_t component_id, struct k_mem_domain *domain);

bool comp_is_llext(struct comp_dev *comp);
#else
Expand Down
5 changes: 3 additions & 2 deletions src/ipc/ipc-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ __cold static bool valid_ipc_buffer_desc(const struct sof_ipc_buffer *desc)
}

/* create a new component in the pipeline */
__cold struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is_shared)
__cold struct comp_buffer *buffer_new(struct k_heap *heap, const struct sof_ipc_buffer *desc,
bool is_shared)
{
struct comp_buffer *buffer;
uint32_t flags = desc->flags;
Expand Down Expand Up @@ -78,7 +79,7 @@ __cold struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc, bool is
desc->caps, flags);

/* allocate buffer */
buffer = buffer_alloc(desc->size, flags, PLATFORM_DCACHE_ALIGN,
buffer = buffer_alloc(heap, desc->size, flags, PLATFORM_DCACHE_ALIGN,
is_shared);
if (buffer) {
buffer->stream.runtime_stream_params.id = desc->comp.id;
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/ipc3/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ int ipc_buffer_new(struct ipc *ipc, const struct sof_ipc_buffer *desc)
}

/* register buffer with pipeline */
buffer = buffer_new(desc, BUFFER_USAGE_NOT_SHARED);
buffer = buffer_new(NULL, desc, BUFFER_USAGE_NOT_SHARED);
if (!buffer) {
tr_err(&ipc_tr, "buffer_new() failed");
return -ENOMEM;
Expand Down
27 changes: 20 additions & 7 deletions src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ __cold int ipc_pipeline_free(struct ipc *ipc, uint32_t comp_id)

__cold static struct comp_buffer *ipc4_create_buffer(struct comp_dev *src, bool is_shared,
uint32_t buf_size, uint32_t src_queue,
uint32_t dst_queue)
uint32_t dst_queue, struct k_heap *heap)
{
struct sof_ipc_buffer ipc_buf;

Expand All @@ -403,7 +403,7 @@ __cold static struct comp_buffer *ipc4_create_buffer(struct comp_dev *src, bool
ipc_buf.comp.id = IPC4_COMP_ID(src_queue, dst_queue);
ipc_buf.comp.pipeline_id = src->ipc_config.pipeline_id;
ipc_buf.comp.core = cpu_get_id();
return buffer_new(&ipc_buf, is_shared);
return buffer_new(heap, &ipc_buf, is_shared);
}

#if CONFIG_CROSS_CORE_STREAM
Expand Down Expand Up @@ -504,13 +504,28 @@ __cold int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)
return IPC4_INVALID_RESOURCE_ID;
}

struct k_heap *dp_heap;

#if CONFIG_ZEPHYR_DP_SCHEDULER
if (source->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP &&
sink->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) {
tr_err(&ipc_tr, "DP to DP binding is not supported: can't bind %x to %x",
src_id, sink_id);
return IPC4_INVALID_REQUEST;
}

struct comp_dev *dp;

if (sink->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP)
dp = sink;
else if (source->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP)
dp = source;
else
dp = NULL;

dp_heap = dp && dp->mod ? dp->mod->priv.resources.heap : NULL;
#else
dp_heap = NULL;
#endif /* CONFIG_ZEPHYR_DP_SCHEDULER */
bool cross_core_bind = source->ipc_config.core != sink->ipc_config.core;

Expand Down Expand Up @@ -580,7 +595,7 @@ __cold int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)
buf_size = ibs * 2;

buffer = ipc4_create_buffer(source, cross_core_bind, buf_size, bu->extension.r.src_queue,
bu->extension.r.dst_queue);
bu->extension.r.dst_queue, dp_heap);
if (!buffer) {
tr_err(&ipc_tr, "failed to allocate buffer to bind %#x to %#x", src_id, sink_id);
return IPC4_OUT_OF_MEMORY;
Expand All @@ -604,12 +619,10 @@ __cold int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)

if (sink->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP ||
source->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP) {
bool dp_on_source = source->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_DP;
struct sof_source *src = audio_buffer_get_source(&buffer->audio_buffer);
struct sof_sink *snk = audio_buffer_get_sink(&buffer->audio_buffer);

ring_buffer = ring_buffer_create(dp_on_source ? source : sink,
source_get_min_available(src),
ring_buffer = ring_buffer_create(dp, source_get_min_available(src),
sink_get_min_free_space(snk),
audio_buffer_is_shared(&buffer->audio_buffer),
buf_get_id(buffer));
Expand All @@ -619,7 +632,7 @@ __cold int ipc_comp_connect(struct ipc *ipc, ipc_pipe_comp_connect *_connect)
}

/* data destination module needs to use ring_buffer */
audio_buffer_attach_secondary_buffer(&buffer->audio_buffer, dp_on_source,
audio_buffer_attach_secondary_buffer(&buffer->audio_buffer, dp == source,
&ring_buffer->audio_buffer);
}

Expand Down
12 changes: 10 additions & 2 deletions src/library_manager/lib_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,15 @@ static uintptr_t lib_manager_allocate_module(const struct sof_man_module *mod,
return 0;
}

int lib_manager_free_module(const uint32_t component_id)
/*
* \brief Free module
*
* param[in] component_id - component id coming from ipc config. This function reguires valid
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "reguires" should be "requires".

Suggested change
* param[in] component_id - component id coming from ipc config. This function reguires valid
* param[in] component_id - component id coming from ipc config. This function requires valid

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets fix incrementally

* lib_id and module_id fields of component id.
*
* Function is responsible to free module resources in HP memory.
*/
static int lib_manager_free_module(const uint32_t component_id)
{
const struct sof_man_module *mod;
const uint32_t module_id = IPC4_MOD_ID(component_id);
Expand Down Expand Up @@ -422,7 +430,7 @@ static uintptr_t lib_manager_allocate_module(const struct comp_ipc_config *ipc_c
return 0;
}

int lib_manager_free_module(const uint32_t component_id)
static int lib_manager_free_module(const uint32_t component_id)
{
/* Since we cannot allocate the freeing is not considered to be an error */
tr_warn(&lib_manager_tr, "Dynamic module freeing is not supported");
Expand Down
Loading
Loading