Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
c0c3e8c
(---section submitted PRs START)
kv2019i Mar 23, 2026
199dd94
(---section submitted PRs STOP)
kv2019i Mar 23, 2026
f3b4346
(---section: user LL infra START)
kv2019i Mar 27, 2026
ad8c62b
ipc: move standalone-test check later in ipc_init()
kv2019i Feb 10, 2026
8fe3a09
ipc: ipc-helper: use list_mutex to guard buffer list in userspace LL
kv2019i Feb 13, 2026
a3a1697
zephyr: lib: make sof_heap_alloc/free system calls
kv2019i May 8, 2026
0217b68
schedule: zephyr_ll_user: make the heap accessible from user-space
kv2019i Feb 13, 2026
cf9ac62
schedule: zephyr_ll: convert pdata->sem into a dynamic object
kv2019i Feb 13, 2026
571efcc
schedule: zephyr_ll: replace dynamic k_sem with embedded sys_sem
kv2019i Apr 22, 2026
a340181
schedule: zephyr_ll_user: move user accessible heap to common partition
kv2019i Feb 13, 2026
a64c073
dma: dma_sg: allocate on specific heap
kv2019i Feb 16, 2026
88eedde
buffer: use the buffer heap for also the payload allocations
kv2019i May 5, 2026
5475b94
alloc.h: remove rbrelloac() and rbrealloc_align()
kv2019i Feb 16, 2026
6f572ae
app: overlays: ptl: add ll_usespace_overlay.conf
kv2019i Apr 14, 2026
d915989
app: overlays: ptl: disable cold/dram execution for now
kv2019i May 6, 2026
df11666
app: overlays: ptl: set CONFIG_SOF_ZEPHYR_LL_USER_HEAP_SIZE
kv2019i Apr 29, 2026
a24032a
(---section: user LL infra STOP)
kv2019i Mar 27, 2026
765d311
(---section host-zephyr START)
kv2019i Feb 19, 2026
b887bac
zephyr: userspace: sof_dma: allow circular SG lists
kv2019i Feb 19, 2026
eb7699e
zephyr: lib: dma: make DMA platform data available to user-space
kv2019i Feb 13, 2026
80346bf
audio: host-zephyr: select heap when allocating host buffers
kv2019i Feb 13, 2026
8374eea
audio: host-zephyr: pass component heap to dma_sg_alloc
kv2019i Feb 16, 2026
557df98
audio: host-zephyr: ensure host data heap is set
kv2019i Feb 16, 2026
92d39b0
audio: host-zephyr: make component usable from user-space
kv2019i Apr 10, 2026
5cf90f4
audio: host-zephyr: use module context for allocations
kv2019i May 8, 2026
019a8da
(---section host-zephyr STOP)
kv2019i Feb 19, 2026
6ed1715
(---section dai-zephyr START)
kv2019i Feb 19, 2026
eeaa085
audio: dai-zephyr: make memory allocations user-space compatible
kv2019i May 5, 2026
2b1997a
lib: dai: make dai_get() and dai_put() compatible with user-space
kv2019i Feb 17, 2026
d2be0df
audio: dai-zephyr: rework calls to DMA driver, remove channel pointer
kv2019i Feb 17, 2026
fbd9bb5
audio: dai-zephyr: convert spinlock into mutex for properties
kv2019i Feb 17, 2026
fe3c91a
audio: dai-zephyr: migrate to use dai_get_properties_copy()
kv2019i Feb 18, 2026
0ee5816
dai: zephyr: replace k_mutex with sof_umutex for DAI lock
kv2019i Apr 22, 2026
b74395b
audio: dai-zephyr: use module context for allocations
kv2019i May 8, 2026
24b2759
(---section dai-zephyr STOP)
kv2019i Feb 19, 2026
e259be0
(---section audio module infra START)
kv2019i Mar 3, 2026
011684e
audio: module_adapter: alloc from LL user heap if LL run in user
kv2019i May 5, 2026
528bf1e
audio: copier: export copier endpoint ops to user-space
kv2019i Feb 26, 2026
5cd46cc
(---section schduler changes START)
kv2019i Mar 3, 2026
d6043b3
schedule: zephyr_ll: add zephyr_ll_task_free()
kv2019i Feb 26, 2026
2a9e5ab
schedule: zephyr_ll: add zephyr_ll_grant_access()
kv2019i Feb 26, 2026
591f266
schedule: zephyr_ll_user: make double-mapping conditional
kv2019i Mar 4, 2026
8e50167
schedule: allocate the scheduler objects with sof_heap_alloc
kv2019i Feb 26, 2026
642eed2
WIP: schedule: limit user-LL to core0
kv2019i Feb 26, 2026
c829e5e
zephyr: schedule: allow user-space to access scheduler list
kv2019i Feb 26, 2026
7e3d591
zephyr: wrapper: modify platform_dai_wallclock() for user-space
kv2019i Feb 26, 2026
3e7bb7f
schedule: add scheduler_init_context() and scheduler_free_context()
kv2019i Feb 27, 2026
cffe764
schedule: zephyr_ll: implement scheduler_init_context()
kv2019i Feb 26, 2026
ae76114
schedule: ll_schedule_domain: add domain_thread_init/free ops
kv2019i Mar 4, 2026
8ed2be5
schedule: zephyr_ll: implement thread_init/free domain ops
kv2019i May 5, 2026
d59db81
schedule: zephyr_ll: ISR check is not needed when LL in user-space
kv2019i Mar 31, 2026
a6ca095
zephyr: userspace_helper: add new sys_user_heap_init()
kv2019i Mar 31, 2026
a5442ef
sched: ll_user: add independent heap size config for LL userspace
kv2019i Apr 29, 2026
538b0fd
(---section schduler changes END)
kv2019i Mar 3, 2026
ab7b1c8
(---section audio-user PRs START)
kv2019i Mar 25, 2026
1b9a1a6
schedule: zephyr_domain: use a different thread name for user LL
kv2019i Mar 24, 2026
d556582
WIP: audio: module_adapter: use correct heap when freeing
kv2019i May 5, 2026
7e6e90c
coherent: disable core debug checks for user-space builds
kv2019i Mar 20, 2026
1dc7f59
audio: place component driver list in user-space accessible partition
kv2019i Mar 24, 2026
929498f
audio: module_adapter: make adapter buffering user-space compatible
kv2019i Mar 24, 2026
d943020
audio: pipeline: use LL scheduler mutex for userspace pipeline triggers
kv2019i Feb 26, 2026
714523b
rtos: umutex.h: add new locking interface
kv2019i May 19, 2026
7d8de1c
schedule: zephyr_ll: replace k_mutex with sof_umutex for scheduler lock
kv2019i Apr 22, 2026
754cfc9
audio: pipeline: change locking strategy for user LL builds
kv2019i May 12, 2026
06b623a
audio: buffer: move dp_heap_user lifecycle to IPC and module adapter
kv2019i May 5, 2026
0ebf0db
Revert "audio: buffer: move dp_heap_user lifecycle to IPC and module …
kv2019i May 5, 2026
45774bb
audio: host-zepher: add HOST_DMA_IPC_POSITION_UPDATES Kconfig
kv2019i May 5, 2026
f8e4227
audio: copier_host: make FPI sync group availble to user-space
kv2019i Mar 31, 2026
b6872f9
audio: copier: avoid IRQ lock/unlock in chmap code
kv2019i Mar 31, 2026
c94fd81
audio: module_adapter: avoid IRQ lock/unlock in prepare()
kv2019i Mar 31, 2026
64800ac
audio: module_adapter: make data_blob compatible with user-space
kv2019i Apr 14, 2026
9616963
audio: module-adapter: make generic.c user-space compatible
kv2019i Apr 16, 2026
cdb533e
audio: module_adapter: use module context for allocations
kv2019i May 8, 2026
ed1587c
audio: module: generic: use module context for blob allocations
kv2019i May 8, 2026
bfac06b
audio: make comp_drivers_get() accessible from user-space
kv2019i Apr 15, 2026
1263394
dai: turn dai_get_device() into a syscall
kv2019i Apr 15, 2026
50620df
audio: chain_dma: add user-space memory and scheduling support
kv2019i Apr 21, 2026
4dab52c
audio: chain-dma: use module context for allocations
kv2019i May 8, 2026
267fcea
(---section audio user PRs STOP)
kv2019i Mar 25, 2026
029cb5c
(---section: IPC user support START)
kv2019i Mar 17, 2026
9176e22
userspace: split ipc files into user and kernel features. REVISIT memcpy
kv2019i Apr 1, 2026
10bdb58
ipc4: helper: use LL scheduler lock for userspace builds
kv2019i Mar 26, 2026
5be2c59
WIP: ipc: implement user-space IPC handling for CREATE_PIPELINE
kv2019i Mar 12, 2026
525251d
WIP: ipc: ipc4: route PIPELINE_DELETE to user-space handler
kv2019i Mar 30, 2026
cbcd9a2
ipc: make IPC stack thread size configurable
Apr 1, 2026
f9fc575
ipc: ipc4: use sof_heap_alloc in ipc4_add_comp_dev()
kv2019i Mar 19, 2026
5c77979
ipc: turn ipc_msg_reply() into a system call
kv2019i Mar 30, 2026
3baffea
ipc: ipc4: use correct API to get DMA status
kv2019i Mar 19, 2026
74b7de4
ipc: ipc4: dai: fix direct use of DMA driver calls
kv2019i Apr 16, 2026
5ea5a2c
ipc: use application heap for IPC pipeline and component allocations
kv2019i Mar 20, 2026
be33f6a
ipc4: make fw_reg mutex available to user-space
kv2019i Apr 15, 2026
6f1120c
ipc: ipc4: helper: make ipc4_search_for_drv() userspace compatible
kv2019i Mar 31, 2026
a7ee7c8
WIP: schedule: add multi-core support for user-space LL scheduler
kv2019i Apr 22, 2026
9028a7b
ipc: ipc-helper: trace context not used in user-space
kv2019i Apr 13, 2026
e732bfd
ipc: ipc4: use the core number from IPC config
kv2019i May 5, 2026
34c0a0b
ipc: ipc4: helper: enable limited ipc_comp_connect() in user-space
kv2019i Apr 13, 2026
90e8b8d
WIP: ipc: ipc4: route MOD_CONFIG_GET/SET to user-space handler
kv2019i Apr 10, 2026
75701dc
WIP: ipc: ipc4: route MOD_BIND/UNBIND to user-space handler
kv2019i Apr 10, 2026
e7cad9f
WIP: ipc: ipc4: route MOD_INIT_INSTANCE to user-space handler
kv2019i May 11, 2026
59ff979
WIP: ipc: ipc4: route GLB_SET_PIPELINE_STATE to user-space handler
kv2019i Apr 16, 2026
ae676ca
WIP: ipc: ipc4: route MOD_LARGE_CONFIG_GET/SET user-space
kv2019i Apr 16, 2026
67089d0
(---section: IPC user support STOP)
kv2019i Mar 27, 2026
1872e54
(---section: IPC notifications START)
kv2019i May 8, 2026
3127014
ipc: turn ipc_msg_send() into a system call if SOF_USERSPACE_LL=y
Apr 20, 2026
b5523ed
ipc: make IPC message allocation userspace-safe
Apr 21, 2026
04a8cd6
ipc4: notification: make send_resource_notif() a syscall
Apr 23, 2026
c0c2476
(---section: IPC notifications STOP)
kv2019i May 8, 2026
7fdef66
ipc: add a mod_alloc_ctx context to IPC context
kv2019i May 8, 2026
46aa6f1
zephyr: lib: make vregion_alloc/free system calls
kv2019i May 19, 2026
bdb1c08
(---section test-case START)
kv2019i Feb 19, 2026
6509dd1
zephyr: test: userspace: add pipeline_two_components test
kv2019i Apr 22, 2026
cb8dbb8
(---section WIP mandatory changes START)
kv2019i Feb 19, 2026
76d037c
audio: pipeline: enable position reporting for user-space pipelines
kv2019i Mar 17, 2026
3bb7029
WIP: ipc: expose coldrodata to IPC user thread
kv2019i Apr 16, 2026
0c65bc7
HACK: audio: collection of feature limitations to run LL in user
kv2019i Feb 26, 2026
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
27 changes: 27 additions & 0 deletions app/overlays/ptl/ll_userspace_overlay.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CONFIG_SOF_USERSPACE_LL=y

# Problem with DSP panics due to illegal instruction hit in user-space if cold
# store execution is enabled. Disable it for now until rootcause is found.
CONFIG_COLD_STORE_EXECUTE_DRAM=n

# temporary (but for now mandatory) settings
CONFIG_SOF_ZEPHYR_USERSPACE_MODULE_HEAP_SIZE=16384
CONFIG_SOF_ZEPHYR_LL_USER_HEAP_SIZE=0x1f000

# make the drivers work in user-space
CONFIG_SOF_USERSPACE_INTERFACE_DMA=y
CONFIG_DAI_USERSPACE=y

# disable features that don't work in user-space (at least yet)
CONFIG_COLD_STORE_EXECUTE_DEBUG=n
CONFIG_CROSS_CORE_STREAM=n
CONFIG_INTEL_ADSP_MIC_PRIVACY=n
CONFIG_XRUN_NOTIFICATIONS_ENABLE=n
CONFIG_SOF_BOOT_TEST_ALLOWED=n
CONFIG_SOF_TELEMETRY_PERFORMANCE_MEASUREMENTS=n
CONFIG_SOF_TELEMETRY_IO_PERFORMANCE_MEASUREMENTS=n

# disable llext (hits privilege issues in user-space now)
CONFIG_LLEXT_STORAGE_WRITABLE=n
CONFIG_LLEXT_EXPERIMENTAL=n
CONFIG_MODULES=n
23 changes: 0 additions & 23 deletions posix/include/rtos/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,29 +97,6 @@ static inline void *rballoc(uint32_t flags, size_t bytes)
return rballoc_align(flags, bytes, PLATFORM_DCACHE_ALIGN);
}

/**
* Changes size of the memory block allocated.
* @param ptr Address of the block to resize.
* @param flags Flags, see SOF_MEM_FLAG_...
* @param bytes New size in bytes.
* @param old_bytes Old size in bytes.
* @param alignment Alignment in bytes.
* @return Pointer to the resized memory of NULL if failed.
*/
void *rbrealloc_align(void *ptr, uint32_t flags, size_t bytes,
size_t old_bytes, uint32_t alignment);

/**
* Similar to rballoc_align(), returns resized buffer aligned to
* PLATFORM_DCACHE_ALIGN.
*/
static inline void *rbrealloc(void *ptr, uint32_t flags,
size_t bytes, size_t old_bytes)
{
return rbrealloc_align(ptr, flags, bytes, old_bytes,
PLATFORM_DCACHE_ALIGN);
}

/**
* Frees the memory block.
* @param ptr Pointer to the memory block.
Expand Down
48 changes: 48 additions & 0 deletions posix/include/rtos/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,52 @@ static inline int sys_mutex_unlock(struct sys_mutex *mutex)
return 0;
}

/* provide a no-op implementation for zephyr/sys/sem.h */

struct sys_sem {
};

static inline int sys_sem_init(struct sys_sem *sem, unsigned int initial_count,
unsigned int limit)
{
return 0;
}

static inline int sys_sem_give(struct sys_sem *sem)
{
return 0;
}

static inline int sys_sem_take(struct sys_sem *sem, k_timeout_t timeout)
{
return 0;
}

/**
* @brief User-space accessible mutex stub for host/testbench builds.
*/
struct sof_umutex {
struct k_mutex mutex; /**< Inline k_mutex for POSIX (no dynamic alloc needed) */
};

static inline int sof_umutex_init(struct sof_umutex *umutex)
{
return k_mutex_init(&umutex->mutex);
}

static inline int sof_umutex_lock(struct sof_umutex *umutex, k_timeout_t timeout)
{
return k_mutex_lock(&umutex->mutex, timeout);
}

static inline int sof_umutex_unlock(struct sof_umutex *umutex)
{
return k_mutex_unlock(&umutex->mutex);
}

static inline void sof_umutex_free(struct sof_umutex *umutex)
{
/* No-op on POSIX — no kernel objects to free */
}

#endif
13 changes: 13 additions & 0 deletions posix/include/rtos/umutex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2026 Intel Corporation.
//

#ifndef __POSIX_RTOS_UMUTEX_H__
#define __POSIX_RTOS_UMUTEX_H__

#include <rtos/mutex.h>

/* sof_umutex type and operations are defined in rtos/mutex.h for POSIX */

#endif /* __POSIX_RTOS_UMUTEX_H__ */
6 changes: 4 additions & 2 deletions posix/include/sof/lib/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

struct comp_buffer;
struct comp_dev;
struct k_heap;

/** \addtogroup sof_dma_drivers DMA Drivers
* DMA Drivers API specification.
Expand Down Expand Up @@ -511,13 +512,14 @@ static inline void dma_sg_init(struct dma_sg_elem_array *ea)
ea->elems = NULL;
}

int dma_sg_alloc(struct dma_sg_elem_array *ea,
int dma_sg_alloc(struct k_heap *heap,
struct dma_sg_elem_array *ea,
uint32_t flags,
uint32_t direction,
uint32_t buffer_count, uint32_t buffer_bytes,
uintptr_t dma_buffer_addr, uintptr_t external_addr);

void dma_sg_free(struct dma_sg_elem_array *ea);
void dma_sg_free(struct k_heap *heap, struct dma_sg_elem_array *ea);

/**
* \brief Get the total size of SG buffer
Expand Down
8 changes: 8 additions & 0 deletions src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ config HOST_DMA_STREAM_SYNCHRONIZATION
for each group, different than the default one determined by the system tick frequency.
This feature will allow host lower power consumption in scenarios with deep buffering.

config HOST_DMA_IPC_POSITION_UPDATES
bool "Support for stream position updates via IPC messages"
default y if IPC_MAJOR_3
help
Support firmware functionality to report stream position updates
by sending a IPC message whenever one period of audio is transfferred.
Most platforms provide more efficient ways to query the DMA status.

config COMP_CHAIN_DMA
bool "Chain DMA component"
depends on IPC_MAJOR_4
Expand Down
117 changes: 89 additions & 28 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,16 @@ 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);
if (alloc->vreg)
vregion_free(alloc->vreg, buffer->stream.addr);
else
sof_heap_free(alloc->heap, buffer->stream.addr);
#else
rfree(buffer->stream.addr);
#endif

if (alloc && alloc->vreg) {
vregion_free(alloc->vreg, buffer);
if (!vregion_put(alloc->vreg))
Expand Down Expand Up @@ -254,7 +263,15 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
return NULL;
}

#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
if (alloc->vreg)
stream_addr = vregion_alloc_align(alloc->vreg, VREGION_MEM_TYPE_INTERIM, size, align);
else
stream_addr = sof_heap_alloc(alloc->heap, flags, size, align);
#else
stream_addr = rballoc_align(flags, size, align);
#endif
if (!stream_addr) {
tr_err(&buffer_tr, "could not alloc size = %zu bytes of flags = 0x%x",
size, flags);
Expand All @@ -264,7 +281,15 @@ 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);
if (alloc->vreg)
vregion_free(alloc->vreg, stream_addr);
else
sof_heap_free(alloc->heap, stream_addr);
#else
rfree(stream_addr);
#endif
}

return buffer;
Expand Down Expand Up @@ -292,7 +317,15 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
preferred_size += minimum_size - preferred_size % minimum_size;

for (size = preferred_size; size >= minimum_size; size -= minimum_size) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
if (alloc->vreg)
stream_addr = vregion_alloc_align(alloc->vreg, VREGION_MEM_TYPE_INTERIM, size, align);
else
stream_addr = sof_heap_alloc(alloc->heap, flags, size, align);
#else
stream_addr = rballoc_align(flags, size, align);
#endif
if (stream_addr)
break;
}
Expand All @@ -308,7 +341,15 @@ 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);
if (alloc->vreg)
vregion_free(alloc->vreg, stream_addr);
else
sof_heap_free(alloc->heap, stream_addr);
#else
rfree(stream_addr);
#endif
}

return buffer;
Expand All @@ -329,6 +370,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;
struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc;

CORE_CHECK_STRUCT(&buffer->audio_buffer);

Expand All @@ -341,14 +383,16 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
if (size == audio_stream_get_size(&buffer->stream))
return 0;

if (!alignment)
new_ptr = rbrealloc(audio_stream_get_addr(&buffer->stream),
buffer->flags | SOF_MEM_FLAG_NO_COPY,
size, audio_stream_get_size(&buffer->stream));
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
if (alloc->vreg)
new_ptr = vregion_alloc_align(alloc->vreg, VREGION_MEM_TYPE_INTERIM, size, alignment);
else
new_ptr = rbrealloc_align(audio_stream_get_addr(&buffer->stream),
buffer->flags | SOF_MEM_FLAG_NO_COPY, size,
audio_stream_get_size(&buffer->stream), alignment);
new_ptr = sof_heap_alloc(alloc->heap, buffer->flags, size, alignment);
#else
new_ptr = rballoc_align(buffer->flags, size, alignment);
#endif

/* we couldn't allocate bigger chunk */
if (!new_ptr && size > audio_stream_get_size(&buffer->stream)) {
buf_err(buffer, "resize can't alloc %u bytes of flags 0x%x",
Expand All @@ -357,8 +401,18 @@ 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)
buffer->stream.addr = new_ptr;
if (new_ptr) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
if (alloc->vreg)
vregion_free(alloc->vreg, audio_stream_get_addr(&buffer->stream));
else
sof_heap_free(alloc->heap, audio_stream_get_addr(&buffer->stream));
#else
rfree(audio_stream_get_addr(&buffer->stream));
#endif
audio_stream_set_addr(&buffer->stream, new_ptr);
}

buffer_init_stream(buffer, size);

Expand All @@ -368,10 +422,10 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, size_t minimum_size,
uint32_t alignment)
{
void *ptr = audio_stream_get_addr(&buffer->stream);
const size_t actual_size = audio_stream_get_size(&buffer->stream);
void *new_ptr = NULL;
size_t new_size;
struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc;

CORE_CHECK_STRUCT(&buffer->audio_buffer);

Expand All @@ -389,22 +443,19 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
if (preferred_size == actual_size)
return 0;

if (!alignment) {
for (new_size = preferred_size; new_size >= minimum_size;
new_size -= minimum_size) {
new_ptr = rbrealloc(ptr, buffer->flags | SOF_MEM_FLAG_NO_COPY,
new_size, actual_size);
if (new_ptr)
break;
}
} else {
for (new_size = preferred_size; new_size >= minimum_size;
new_size -= minimum_size) {
new_ptr = rbrealloc_align(ptr, buffer->flags | SOF_MEM_FLAG_NO_COPY,
new_size, actual_size, alignment);
if (new_ptr)
break;
}
for (new_size = preferred_size; new_size >= minimum_size;
new_size -= minimum_size) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
if (alloc->vreg)
new_ptr = vregion_alloc_align(alloc->vreg, VREGION_MEM_TYPE_INTERIM, new_size, alignment);
else
new_ptr = sof_heap_alloc(alloc->heap, buffer->flags, new_size, alignment);
#else
new_ptr = rballoc_align(buffer->flags, new_size, alignment);
#endif
if (new_ptr)
break;
}

/* we couldn't allocate bigger chunk */
Expand All @@ -415,8 +466,18 @@ 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)
buffer->stream.addr = new_ptr;
if (new_ptr) {
#ifdef CONFIG_SOF_USERSPACE_LL
assert(alloc);
if (alloc->vreg)
vregion_free(alloc->vreg, audio_stream_get_addr(&buffer->stream));
else
sof_heap_free(alloc->heap, audio_stream_get_addr(&buffer->stream));
#else
rfree(audio_stream_get_addr(&buffer->stream));
#endif
audio_stream_set_addr(&buffer->stream, new_ptr);
}

buffer_init_stream(buffer, new_size);

Expand Down
Loading