Skip to content

Commit b1a929c

Browse files
committed
userspace: make the shared heap depend on a Kconfig option
Add a SOF_ZEPHYR_USE_SHARED_HEAP Kconfig option to explicitly enable or disable the shared heap. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 532eb44 commit b1a929c

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

zephyr/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,16 @@ config SOF_ZEPHYR_HEAP_SIZE
3838
NOTE: Keep in mind that the heap size should not be greater than the physical
3939
memory size of the system defined in DT (and this includes baseFW text/data).
4040

41+
config SOF_USERSPACE_USE_SHARED_HEAP
42+
bool "Use shared heap for SOF userspace modules"
43+
depends on USERSPACE
44+
help
45+
When set a shared heap will be used for audio buffers between SOF
46+
kernel and userspace modules.
47+
4148
config SOF_ZEPHYR_SHARED_BUFFER_HEAP_SIZE
4249
hex "Size of the shared buffer heap for SOF userspace modules"
50+
default 0x0 if !SOF_USERSPACE_USE_SHARED_HEAP
4351
default 0x1E000 if SOC_INTEL_ACE15_MTPM || SOC_INTEL_ACE20_LNL
4452
default 0x1A000 if SOC_INTEL_ACE30
4553
default 0x0

zephyr/include/rtos/alloc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static inline void heap_trace_all(int force) {}
129129

130130
/** @}*/
131131

132-
#if CONFIG_USERSPACE
132+
#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
133133
/**
134134
* Returns the start address of shared memory heap for buffers.
135135
*

zephyr/lib/alloc.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ static uint8_t __aligned(PLATFORM_DCACHE_ALIGN) heapmem[HEAPMEM_SIZE];
105105
#undef SHARED_BUFFER_HEAP_MEM_SIZE
106106
#define SHARED_BUFFER_HEAP_MEM_SIZE ROUND_UP(CONFIG_SOF_ZEPHYR_SHARED_BUFFER_HEAP_SIZE, \
107107
HOST_PAGE_SIZE)
108+
#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
108109
__section(".shared_heap_mem")
109110
static uint8_t __aligned(HOST_PAGE_SIZE) shared_heapmem[SHARED_BUFFER_HEAP_MEM_SIZE];
111+
#endif
110112
#endif /* CONFIG_USERSPACE */
111113
__section(".heap_mem")
112114
static uint8_t __aligned(HOST_PAGE_SIZE) heapmem[HEAPMEM_SIZE - SHARED_BUFFER_HEAP_MEM_SIZE];
@@ -149,7 +151,7 @@ extern char _end[], _heap_sentry[];
149151

150152
static struct k_heap sof_heap;
151153

152-
#if CONFIG_USERSPACE
154+
#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
153155
static struct k_heap shared_buffer_heap;
154156

155157
static bool is_shared_buffer_heap_pointer(void *ptr)
@@ -181,7 +183,7 @@ size_t get_shared_buffer_heap_size(void)
181183
{
182184
return ROUND_DOWN(SHARED_BUFFER_HEAP_MEM_SIZE, HOST_PAGE_SIZE);
183185
}
184-
#endif /* CONFIG_USERSPACE */
186+
#endif /* CONFIG_SOF_USERSPACE_USE_SHARED_HEAP */
185187

186188
#if CONFIG_L3_HEAP
187189
static struct k_heap l3_heap;
@@ -466,7 +468,7 @@ void *rmalloc_align(uint32_t flags, size_t bytes, uint32_t alignment)
466468
#else
467469
k_panic();
468470
#endif
469-
#if CONFIG_USERSPACE
471+
#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
470472
} else if (flags & SOF_MEM_FLAG_USER_SHARED_BUFFER) {
471473
heap = &shared_buffer_heap;
472474
#endif
@@ -555,7 +557,7 @@ void *rballoc_align(uint32_t flags, size_t bytes,
555557
tr_err(&zephyr_tr, "L3_HEAP not available.");
556558
return NULL;
557559
#endif
558-
#if CONFIG_USERSPACE
560+
#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
559561
} else if (flags & SOF_MEM_FLAG_USER_SHARED_BUFFER) {
560562
heap = &shared_buffer_heap;
561563
#endif /* CONFIG_USERSPACE */
@@ -598,7 +600,7 @@ void rfree(void *ptr)
598600
}
599601
#endif
600602

601-
#if CONFIG_USERSPACE
603+
#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
602604
if (is_shared_buffer_heap_pointer(ptr)) {
603605
heap_free(&shared_buffer_heap, ptr);
604606
return;
@@ -637,7 +639,7 @@ static int heap_init(void)
637639
{
638640
sys_heap_init(&sof_heap.heap, heapmem, HEAPMEM_SIZE - SHARED_BUFFER_HEAP_MEM_SIZE);
639641

640-
#if CONFIG_USERSPACE
642+
#if CONFIG_SOF_USERSPACE_USE_SHARED_HEAP
641643
sys_heap_init(&shared_buffer_heap.heap, shared_heapmem, SHARED_BUFFER_HEAP_MEM_SIZE);
642644
#endif
643645

0 commit comments

Comments
 (0)