Skip to content

Commit 563aa88

Browse files
committed
rtos: alloc.h: add sof_sys_user_heap_get()
Add sof_sys_user_heap_get() to get heap object to use for SOF audio application heap allocations. When SOF is built with CONFIG_SOF_USERSPACE_LL, this will return a heap that can be used for user-space code. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1 parent 3db6d48 commit 563aa88

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

posix/include/rtos/alloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
141141
size_t alignment);
142142
void sof_heap_free(struct k_heap *heap, void *addr);
143143
struct k_heap *sof_sys_heap_get(void);
144+
struct k_heap *sof_sys_user_heap_get(void);
144145

145146
/**
146147
* Calculates length of the null-terminated string.

src/platform/library/lib/alloc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,8 @@ struct k_heap *sof_sys_heap_get(void)
7575
{
7676
return NULL;
7777
}
78+
79+
struct k_heap *sof_sys_user_heap_get(void)
80+
{
81+
return NULL;
82+
}

zephyr/include/rtos/alloc.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes,
127127
void sof_heap_free(struct k_heap *heap, void *addr);
128128
struct k_heap *sof_sys_heap_get(void);
129129

130+
/**
131+
* Returns heap object to use for SOF heap allocations
132+
* for audio application code.
133+
*
134+
* This should not be used for heap allocations for objects that
135+
* are only used in SOF kernel space.
136+
*
137+
* Note: audio modules should use mod_alloc() instead!
138+
*/
139+
struct k_heap *sof_sys_user_heap_get(void);
140+
130141
/* TODO: remove - debug only - only needed for linking */
131142
static inline void heap_trace_all(int force) {}
132143

zephyr/lib/alloc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <sof/lib/notifier.h>
1414
#include <sof/lib/pm_runtime.h>
1515
#include <sof/audio/pipeline.h>
16+
#include <sof/schedule/ll_schedule_domain.h> /* for zephyr_ll_user_heap() */
1617
#include <sof/trace/trace.h>
1718
#include <rtos/symbol.h>
1819
#include <rtos/wait.h>
@@ -380,6 +381,16 @@ struct k_heap *sof_sys_heap_get(void)
380381
return &sof_heap;
381382
}
382383

384+
struct k_heap *sof_sys_user_heap_get(void)
385+
{
386+
#ifdef CONFIG_SOF_USERSPACE_LL
387+
return zephyr_ll_user_heap();
388+
#else
389+
/* let sof_heap_alloc() pick */
390+
return NULL;
391+
#endif
392+
}
393+
383394
static void *heap_alloc_aligned(struct k_heap *h, size_t min_align, size_t bytes)
384395
{
385396
k_spinlock_key_t key;

0 commit comments

Comments
 (0)