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
10 changes: 8 additions & 2 deletions src/audio/base_fw_intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ static const struct device *uaol_devs[] = {
DT_FOREACH_STATUS_OKAY(intel_adsp_uaol, DEV_AND_COMMA)
};

static void tlv_value_set_uaol_caps(struct sof_tlv *tuple, uint32_t type)
#if !CONFIG_SOF_OS_LINUX_COMPAT_PRIORITY
__cold static void tlv_value_set_uaol_caps(struct sof_tlv *tuple, uint32_t type)
{
const size_t dev_count = ARRAY_SIZE(uaol_devs);
struct uaol_capabilities dev_cap;
Expand All @@ -118,6 +119,8 @@ static void tlv_value_set_uaol_caps(struct sof_tlv *tuple, uint32_t type)
size_t i;
int ret;

assert_can_be_cold();

memset(caps, 0, caps_size);

caps->link_count = dev_count;
Expand All @@ -135,12 +138,15 @@ static void tlv_value_set_uaol_caps(struct sof_tlv *tuple, uint32_t type)

tlv_value_set(tuple, type, caps_size, caps);
}
#endif /* CONFIG_SOF_OS_LINUX_COMPAT_PRIORITY */

static int uaol_stream_id_to_hda_link_stream_id(int uaol_stream_id)
__cold static int uaol_stream_id_to_hda_link_stream_id(int uaol_stream_id)
{
size_t dev_count = ARRAY_SIZE(uaol_devs);
size_t i;

assert_can_be_cold();

for (i = 0; i < dev_count; i++) {
int hda_link_stream_id = uaol_get_mapped_hda_link_stream_id(uaol_devs[i],
uaol_stream_id);
Expand Down
44 changes: 25 additions & 19 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <rtos/interrupt.h>
#include <rtos/alloc.h>
#include <rtos/cache.h>
#include <sof/lib/vregion.h>
#include <sof/list.h>
#include <sof/schedule/dp_schedule.h>
#include <rtos/spinlock.h>
Expand Down Expand Up @@ -146,22 +147,22 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)

struct comp_buffer *buffer = container_of(audio_buffer, struct comp_buffer, audio_buffer);

buf_dbg(buffer, "buffer_free()");
buf_dbg(buffer, "entry");

#if CONFIG_PROBE
if (buffer->probe_cb_free)
buffer->probe_cb_free(buffer->probe_cb_arg);
#endif

struct k_heap *heap = buffer->audio_buffer.heap;
struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc;

rfree(buffer->stream.addr);
sof_heap_free(heap, buffer);
if (heap) {
struct dp_heap_user *mod_heap_user = container_of(heap, struct dp_heap_user, heap);

if (!--mod_heap_user->client_count)
rfree(mod_heap_user);
if (alloc && alloc->vreg) {
vregion_free(alloc->vreg, buffer);
if (!vregion_put(alloc->vreg))
rfree(alloc);
} else {
sof_heap_free(alloc ? alloc->heap : NULL, buffer);
}
}

Expand Down Expand Up @@ -192,19 +193,24 @@ static const struct audio_buffer_ops audio_buffer_ops = {
.set_alignment_constants = comp_buffer_set_alignment_constants,
};

static struct comp_buffer *buffer_alloc_struct(struct k_heap *heap,
static struct comp_buffer *buffer_alloc_struct(struct mod_alloc_ctx *alloc,
void *stream_addr, size_t size,
uint32_t flags, bool is_shared)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need separate is_shared flag when we have defined SOF_MEM_FLAG_COHERENT in the flags field?

Copy link
Copy Markdown
Collaborator Author

@lyakh lyakh Apr 27, 2026

Choose a reason for hiding this comment

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

@jsarha don't know, not my original implementation. Originally the is_shared argument was added in 4a03699

{
struct comp_buffer *buffer;

tr_dbg(&buffer_tr, "buffer_alloc_struct()");
tr_dbg(&buffer_tr, "entry");

/* allocate new buffer, but add coherent if shared with other cores */
if (is_shared)
flags |= SOF_MEM_FLAG_COHERENT;

buffer = sof_heap_alloc(heap, flags, sizeof(*buffer), 0);
if (!alloc || !alloc->vreg)
buffer = sof_heap_alloc(alloc ? alloc->heap : NULL, flags, sizeof(*buffer), 0);
else if (is_shared)
buffer = vregion_alloc_coherent(alloc->vreg, VREGION_MEM_TYPE_INTERIM, sizeof(*buffer));
else
buffer = vregion_alloc(alloc->vreg, VREGION_MEM_TYPE_INTERIM, sizeof(*buffer));
if (!buffer) {
tr_err(&buffer_tr, "could not alloc structure");
return NULL;
Expand All @@ -226,21 +232,21 @@ static struct comp_buffer *buffer_alloc_struct(struct k_heap *heap,

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;
buffer->audio_buffer.alloc = alloc;

comp_buffer_reset_source_list(buffer);
comp_buffer_reset_sink_list(buffer);

return buffer;
}

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(struct mod_alloc_ctx *alloc, size_t size, uint32_t flags,
uint32_t align, bool is_shared)
{
struct comp_buffer *buffer;
void *stream_addr;

tr_dbg(&buffer_tr, "buffer_alloc()");
tr_dbg(&buffer_tr, "entry");

/* validate request */
if (size == 0) {
Expand All @@ -255,7 +261,7 @@ struct comp_buffer *buffer_alloc(struct k_heap *heap, size_t size, uint32_t flag
return NULL;
}

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

struct comp_buffer *buffer_alloc_range(struct k_heap *heap, size_t preferred_size,
struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t preferred_size,
size_t minimum_size,
uint32_t flags, uint32_t align, bool is_shared)
{
Expand Down Expand Up @@ -299,7 +305,7 @@ struct comp_buffer *buffer_alloc_range(struct k_heap *heap, size_t preferred_siz
return NULL;
}

buffer = buffer_alloc_struct(heap, stream_addr, size, flags, is_shared);
buffer = buffer_alloc_struct(alloc, stream_addr, size, flags, is_shared);
if (!buffer) {
tr_err(&buffer_tr, "could not alloc buffer structure");
rfree(stream_addr);
Expand All @@ -310,7 +316,7 @@ struct comp_buffer *buffer_alloc_range(struct k_heap *heap, size_t preferred_siz

void buffer_zero(struct comp_buffer *buffer)
{
buf_dbg(buffer, "stream_zero()");
buf_dbg(buffer, "entry");
CORE_CHECK_STRUCT(&buffer->audio_buffer);

bzero(audio_stream_get_addr(&buffer->stream), audio_stream_get_size(&buffer->stream));
Expand Down
49 changes: 38 additions & 11 deletions src/audio/buffers/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sof/common.h>
#include <sof/trace/trace.h>
#include <sof/lib/uuid.h>
#include <sof/lib/vregion.h>

#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/ring_buffer.h>
Expand Down Expand Up @@ -96,9 +97,15 @@ static void ring_buffer_free(struct sof_audio_buffer *audio_buffer)

struct ring_buffer *ring_buffer = container_of(audio_buffer,
struct ring_buffer, audio_buffer);

sof_heap_free(audio_buffer->heap, (__sparse_force void *)ring_buffer->_data_buffer);
sof_heap_free(audio_buffer->heap, ring_buffer);
struct mod_alloc_ctx *alloc = audio_buffer->alloc;

if (alloc->vreg) {
vregion_free(alloc->vreg, (__sparse_force void *)ring_buffer->_data_buffer);
vregion_free(alloc->vreg, ring_buffer);
} else {
sof_heap_free(alloc->heap, (__sparse_force void *)ring_buffer->_data_buffer);
sof_heap_free(alloc->heap, ring_buffer);
}
}

static void ring_buffer_reset(struct sof_audio_buffer *audio_buffer)
Expand Down Expand Up @@ -287,12 +294,19 @@ struct ring_buffer *ring_buffer_create(struct comp_dev *dev, size_t min_availabl
uint32_t id)
{
struct ring_buffer *ring_buffer;
struct k_heap *heap = dev->mod->priv.resources.heap;
struct mod_alloc_ctx *alloc = dev->mod->priv.resources.alloc;
struct k_heap *heap = alloc->heap;
struct vregion *vreg = alloc->vreg;
int memory_flags = (is_shared ? SOF_MEM_FLAG_COHERENT : 0) |
user_get_buffer_memory_region(dev->drv);

/* allocate ring_buffer structure */
ring_buffer = sof_heap_alloc(heap, memory_flags, sizeof(*ring_buffer), 0);
if (!vreg)
ring_buffer = sof_heap_alloc(heap, memory_flags, sizeof(*ring_buffer), 0);
else if (is_shared)
ring_buffer = vregion_alloc_coherent(vreg, VREGION_MEM_TYPE_INTERIM, sizeof(*ring_buffer));
else
ring_buffer = vregion_alloc(vreg, VREGION_MEM_TYPE_INTERIM, sizeof(*ring_buffer));
if (!ring_buffer)
return NULL;

Expand All @@ -307,7 +321,8 @@ struct ring_buffer *ring_buffer_create(struct comp_dev *dev, size_t min_availabl
audio_buffer_init(&ring_buffer->audio_buffer, BUFFER_TYPE_RING_BUFFER,
is_shared, &ring_buffer_source_ops, &ring_buffer_sink_ops,
&audio_buffer_ops, NULL);
ring_buffer->audio_buffer.heap = heap;
ring_buffer->audio_buffer.alloc = alloc;
ring_buffer->audio_buffer.alloc->heap = heap;

/* set obs/ibs in sink/source interfaces */
sink_set_min_free_space(audio_buffer_get_sink(&ring_buffer->audio_buffer),
Expand Down Expand Up @@ -364,12 +379,21 @@ struct ring_buffer *ring_buffer_create(struct comp_dev *dev, size_t min_availabl
/* allocate data buffer - always in cached memory alias */
ring_buffer->data_buffer_size = ALIGN_UP(ring_buffer->data_buffer_size,
PLATFORM_DCACHE_ALIGN);
ring_buffer->_data_buffer = (__sparse_force __sparse_cache void *)sof_heap_alloc(heap,
user_get_buffer_memory_region(dev->drv),
ring_buffer->data_buffer_size, PLATFORM_DCACHE_ALIGN);
if (!ring_buffer->_data_buffer)

void *data_buf;

if (vreg)
data_buf = vregion_alloc_align(vreg, VREGION_MEM_TYPE_INTERIM, ring_buffer->data_buffer_size,
PLATFORM_DCACHE_ALIGN);
else
data_buf = sof_heap_alloc(heap, user_get_buffer_memory_region(dev->drv),
ring_buffer->data_buffer_size, PLATFORM_DCACHE_ALIGN);

if (!data_buf)
goto err;

ring_buffer->_data_buffer = (__sparse_force __sparse_cache void *)data_buf;

tr_info(&ring_buffer_tr, "Ring buffer created, id: %u shared: %u min_available: %u min_free_space %u, size %u",
id, ring_buffer_is_shared(ring_buffer), min_available, min_free_space,
ring_buffer->data_buffer_size);
Expand All @@ -378,6 +402,9 @@ struct ring_buffer *ring_buffer_create(struct comp_dev *dev, size_t min_availabl
return ring_buffer;
err:
tr_err(&ring_buffer_tr, "Ring buffer creation failure");
sof_heap_free(heap, ring_buffer);
if (vreg)
vregion_free(vreg, ring_buffer);
else
sof_heap_free(heap, ring_buffer);
return NULL;
}
2 changes: 1 addition & 1 deletion src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ static int dai_set_dma_config(struct dai_data *dd, struct comp_dev *dev)

comp_dbg(dev, "entry");

dma_cfg = rballoc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT | SOF_MEM_FLAG_DMA,
dma_cfg = rmalloc(SOF_MEM_FLAG_USER | SOF_MEM_FLAG_COHERENT | SOF_MEM_FLAG_DMA,
sizeof(struct dma_config));
if (!dma_cfg) {
comp_err(dev, "dma_cfg allocation failed");
Expand Down
Loading
Loading