Skip to content
Open
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
111 changes: 53 additions & 58 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)

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

#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
sof_ctx_free(alloc, buffer->stream.addr);
#else
rfree(buffer->stream.addr);
#endif
assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

if (alloc)
sof_ctx_free(alloc, buffer->stream.addr);
else
rfree(buffer->stream.addr);
Comment thread
serhiy-katsyuba-intel marked this conversation as resolved.

if (alloc && alloc->vreg) {
vregion_free(alloc->vreg, buffer);
Expand Down Expand Up @@ -255,12 +255,13 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
return NULL;
}

#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
stream_addr = sof_ctx_alloc(alloc, flags, size, align);
#else
stream_addr = rballoc_align(flags, size, align);
#endif
assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

if (alloc)
stream_addr = sof_ctx_alloc(alloc, flags, size, align);
else
stream_addr = rballoc_align(flags, size, align);
Comment thread
serhiy-katsyuba-intel marked this conversation as resolved.

if (!stream_addr) {
tr_err(&buffer_tr, "could not alloc size = %zu bytes of flags = 0x%x",
size, flags);
Expand All @@ -270,12 +271,11 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
buffer = buffer_alloc_struct(alloc, stream_addr, size, flags, is_shared);
if (!buffer) {
tr_err(&buffer_tr, "could not alloc buffer structure");
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
sof_ctx_free(alloc, stream_addr);
#else
rfree(stream_addr);
#endif

if (alloc)
sof_ctx_free(alloc, stream_addr);
else
rfree(stream_addr);
}

return buffer;
Expand All @@ -302,13 +302,14 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
if (preferred_size % minimum_size)
preferred_size += minimum_size - preferred_size % minimum_size;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

for (size = preferred_size; size >= minimum_size; size -= minimum_size) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
stream_addr = sof_ctx_alloc(alloc, flags, size, align);
#else
stream_addr = rballoc_align(flags, size, align);
#endif
if (alloc)
stream_addr = sof_ctx_alloc(alloc, flags, size, align);
else
stream_addr = rballoc_align(flags, size, align);

if (stream_addr)
break;
}
Expand All @@ -324,12 +325,11 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
buffer = buffer_alloc_struct(alloc, stream_addr, size, flags, is_shared);
if (!buffer) {
tr_err(&buffer_tr, "could not alloc buffer structure");
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
sof_ctx_free(alloc, stream_addr);
#else
rfree(stream_addr);
#endif

if (alloc)
sof_ctx_free(alloc, stream_addr);
else
rfree(stream_addr);
}

return buffer;
Expand All @@ -350,9 +350,7 @@ void buffer_zero(struct comp_buffer *buffer)
int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignment)
{
void *new_ptr = NULL;
#ifdef CONFIG_SOF_USERSPACE_LL
struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc;
#endif

CORE_CHECK_STRUCT(&buffer->audio_buffer);

Expand All @@ -365,12 +363,12 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
if (size == audio_stream_get_size(&buffer->stream))
return 0;

#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
new_ptr = sof_ctx_alloc(alloc, buffer->flags, size, alignment);
#else
new_ptr = rballoc_align(buffer->flags, size, alignment);
#endif
assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

if (alloc)
new_ptr = sof_ctx_alloc(alloc, buffer->flags, size, alignment);
else
new_ptr = rballoc_align(buffer->flags, size, alignment);

/* we couldn't allocate bigger chunk */
if (!new_ptr && size > audio_stream_get_size(&buffer->stream)) {
Expand All @@ -381,12 +379,11 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen

/* use bigger chunk, else just use the old chunk but set smaller */
if (new_ptr) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
sof_ctx_free(alloc, audio_stream_get_addr(&buffer->stream));
#else
rfree(audio_stream_get_addr(&buffer->stream));
#endif
if (alloc)
sof_ctx_free(alloc, audio_stream_get_addr(&buffer->stream));
else
rfree(audio_stream_get_addr(&buffer->stream));

audio_stream_set_addr(&buffer->stream, new_ptr);
}

Expand All @@ -401,9 +398,7 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
const size_t actual_size = audio_stream_get_size(&buffer->stream);
void *new_ptr = NULL;
size_t new_size;
#ifdef CONFIG_SOF_USERSPACE_LL
struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc;
#endif

CORE_CHECK_STRUCT(&buffer->audio_buffer);

Expand All @@ -421,14 +416,15 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
if (preferred_size == actual_size)
return 0;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

for (new_size = preferred_size; new_size >= minimum_size;
new_size -= minimum_size) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
new_ptr = sof_ctx_alloc(alloc, buffer->flags, new_size, alignment);
#else
new_ptr = rballoc_align(buffer->flags, new_size, alignment);
#endif
if (alloc)
new_ptr = sof_ctx_alloc(alloc, buffer->flags, new_size, alignment);
else
new_ptr = rballoc_align(buffer->flags, new_size, alignment);

if (new_ptr)
break;
}
Expand All @@ -442,12 +438,11 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz

/* use bigger chunk, else just use the old chunk but set smaller */
if (new_ptr) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
sof_ctx_free(alloc, audio_stream_get_addr(&buffer->stream));
#else
rfree(audio_stream_get_addr(&buffer->stream));
#endif
if (alloc)
sof_ctx_free(alloc, audio_stream_get_addr(&buffer->stream));
else
rfree(audio_stream_get_addr(&buffer->stream));

audio_stream_set_addr(&buffer->stream, new_ptr);
}

Expand Down
Loading