Skip to content
Draft
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
2 changes: 1 addition & 1 deletion scripts/gen-doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if [ ! -z "$ZEPHYR_BASE" ]; then
VENV_DIR="$ZEPHYR_BASE/.venv"
echo "Using Zephyr environment at $ZEPHYR_BASE"
elif [ ! -z "$SOF_WORKSPACE" ]; then
VENV_DIR="$SOF_WORKSPACE/zephyr/.venv"
VENV_DIR="$SOF_WORKSPACE/.venv"
echo "Using SOF/Zephyr environment at $SOF_WORKSPACE"
else
# fallback to the zephyr default from the getting started guide
Expand Down
1 change: 1 addition & 0 deletions src/include/ipc/topology.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct sof_ipc_comp {
#define SOF_MEM_CAPS_L3 BIT(8) /**< L3 memory */
/* Don't forget to update when adding a new bit to the ABI. */
#define SOF_MEM_CAPS_LOWEST_INVALID BIT(9) /**< Used for input validation */
#define SOF_MEM_CAPS_MMU_SHD BIT(10) /**< MMU shared memory */

/*
* overrun will cause ring buffer overwrite, instead of XRUN.
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ace30/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
/**
* size of HPSRAM system heap
*/
#define HEAPMEM_SIZE 0xD0000
#define HEAPMEM_SIZE CONFIG_SOF_ZEPHYR_HEAP_SIZE

#if CONFIG_COLD_STORE_EXECUTE_DRAM && \
(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE || !defined(LL_EXTENSION_BUILD))
Expand Down
2 changes: 1 addition & 1 deletion src/platform/lunarlake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
/**
* size of HPSRAM system heap
*/
#define HEAPMEM_SIZE 0xF0000
#define HEAPMEM_SIZE CONFIG_SOF_ZEPHYR_HEAP_SIZE

#if CONFIG_COLD_STORE_EXECUTE_DRAM && \
(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE || !defined(LL_EXTENSION_BUILD))
Expand Down
2 changes: 1 addition & 1 deletion src/platform/meteorlake/include/platform/lib/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
/**
* size of HPSRAM system heap
*/
#define HEAPMEM_SIZE 0xF0000
#define HEAPMEM_SIZE CONFIG_SOF_ZEPHYR_HEAP_SIZE

#if CONFIG_COLD_STORE_EXECUTE_DRAM && \
(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE || !defined(LL_EXTENSION_BUILD))
Expand Down
44 changes: 44 additions & 0 deletions zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ config SOF_STAGING

rsource "../Kconfig.sof"

config SOF_USERSPACE
bool "Enable SOF support for userspace modules"
default n
help
SOF userspace modules support will enable modules to run in DP
processing mode as userspace code and data. This feature is WIP
and is not yest ready for production, for developers only.

config SOF_ZEPHYR_HEAP_CACHED
bool "Cached Zephyr heap for SOF memory non-shared zones"
default y if CAVS || ACE
Expand All @@ -19,6 +27,42 @@ config SOF_ZEPHYR_HEAP_CACHED
Enable cached heap by mapping cached SOF memory zones to different
Zephyr sys_heap objects and enable caching for non-shared zones.

config SOF_ZEPHYR_HEAP_SIZE
hex "Size of the Zephyr heap for SOF"
default 0xF0000 if SOC_INTEL_ACE15_MTPM || SOC_INTEL_ACE20_LNL
default 0xD0000 if SOC_INTEL_ACE30
default 0x0
help
Support scaling of the heap size for different platforms and different types
of heaps. This is the default heap size for most users.
TODO: Currently this setting is only available on platforms with a
simplified heap size configuration. i.e. a single macro that defines the
heap size. This is not the case for all platforms.
NOTE: Keep in mind that the heap size should not be greater than the physical
memory size of the system defined in DT (and this includes baseFW text/data).

config SOF_ZEPHYR_VIRTUAL_HEAP_SIZE
hex "Size of the Zephyr virtual heap for SOF"
depends on VIRTUAL_HEAP
default 0x40000 if SOC_INTEL_ACE30
default 0x0
help
Support scaling of the virtual address heap size for different platforms.
NOTE: Keep in mind that the heap size should not be greater than the physical
memory size of the system defined in DT (and this includes baseFW text/data).

config SOF_ZEPHYR_USER_HEAP_SIZE
hex "Size of the Zephyr userspace heap for SOF"
depends on SOF_STAGING
depends on SOF_USERSPACE
default 0x20000 if SOC_INTEL_ACE30
default 0x0
help
Support scaling of the userspace address heap size for different platforms.
NOTE: Keep in mind that the heap size should not be greater than the physical
memory size of the system defined in DT (and this includes baseFW text/data
alongside the default SOF heap size).

config ZEPHYR_NATIVE_DRIVERS
bool "Use Zephyr native drivers"
default n
Expand Down
40 changes: 40 additions & 0 deletions zephyr/include/rtos/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,46 @@ void rfree(void *ptr);
/* TODO: remove - debug only - only needed for linking */
static inline void heap_trace_all(int force) {}

#if CONFIG_SOF_USERSPACE

/**
* Returns whether pointer is in userspace heap.
* @return True is userspace pointer.
*/
bool s_heap_user_is_pointer(void *ptr);

/**
* Returns the start of user memory heap.
* @return Pointer to the user memory heap start address.
*/
uintptr_t s_heap_user_get_start(void);

/**
* Returns the size of user memory heap.
* @return Size of the user memory region which can be used for user heap.
*/
static inline size_t s_get_heap_get_user_size(void)
{
return ROUND_DOWN(CONFIG_SOF_ZEPHYR_USER_HEAP_SIZE, CONFIG_MMU_PAGE_SIZE);
}
#else

static inline bool s_heap_user_is_pointer(void *ptr)
{
return false;
}

static inline uintptr_t s_heap_user_get_start(void)
{
return 0;
}

static inline size_t s_get_heap_get_user_size(void)
{
return 0;
}
#endif

/** @}*/

#endif /* __ZEPHYR_RTOS_ALLOC_H__ */
52 changes: 50 additions & 2 deletions zephyr/lib/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <sof/trace/trace.h>
#include <rtos/symbol.h>
#include <rtos/wait.h>

#if CONFIG_VIRTUAL_HEAP
#include <sof/lib/regions_mm.h>

Expand All @@ -27,7 +28,7 @@ struct vmh_heap *virtual_buffers_heap;
#undef HEAPMEM_SIZE
/* Buffers are allocated from virtual space so we can safely reduce the heap size.
*/
#define HEAPMEM_SIZE 0x40000
#define HEAPMEM_SIZE CONFIG_SOF_ZEPHYR_VIRTUAL_HEAP_SIZE
#endif /* CONFIG_VIRTUAL_HEAP */


Expand Down Expand Up @@ -97,7 +98,13 @@ static uint8_t __aligned(PLATFORM_DCACHE_ALIGN) heapmem[HEAPMEM_SIZE];
* to allow memory management driver to control unused
* memory pages.
*/
__section(".heap_mem") static uint8_t __aligned(PLATFORM_DCACHE_ALIGN) heapmem[HEAPMEM_SIZE];

__section(".heap_mem") static uint8_t __aligned(HOST_PAGE_SIZE) heapmem[HEAPMEM_SIZE];

#if CONFIG_SOF_USERSPACE
#define USER_HEAP_MEM_SIZE CONFIG_SOF_ZEPHYR_USER_HEAP_SIZE
__section(".heap_mem") static uint8_t __aligned(HOST_PAGE_SIZE) user_heapmem[USER_HEAP_MEM_SIZE];
#endif

#elif defined(CONFIG_ARCH_POSIX)

Expand All @@ -124,6 +131,35 @@ extern char _end[], _heap_sentry[];

static struct k_heap sof_heap;

#if CONFIG_SOF_USERSPACE
static struct k_heap sof_user_heap;

/**
* Returns the start of user memory heap.
* @return Pointer to the user memory heap start address.
*/
bool s_heap_user_is_pointer(void *ptr)
{
if (is_cached(ptr))
ptr = sys_cache_uncached_ptr_get((__sparse_force void __sparse_cache *)ptr);

if ((POINTER_TO_UINT(ptr) >= (uintptr_t)&user_heapmem[0]) &&
(POINTER_TO_UINT(ptr) < (uintptr_t)&user_heapmem[CONFIG_SOF_ZEPHYR_USER_HEAP_SIZE]))
return true;

return false;
}

/**
* Returns the start of user memory heap.
* @return Pointer to the user memory heap start address.
*/
uintptr_t s_heap_user_get_start(void)
{
return (uintptr_t)ROUND_UP(&user_heapmem[0], CONFIG_MMU_PAGE_SIZE);
}
#endif

#if CONFIG_L3_HEAP
static struct k_heap l3_heap;

Expand Down Expand Up @@ -400,6 +436,10 @@ void *rmalloc(enum mem_zone zone, uint32_t flags, uint32_t caps, size_t bytes)
return ptr;
#else
k_panic();
#endif
#if CONFIG_USERSPACE
} else if (caps & SOF_MEM_CAPS_MMU_SHD) {
heap = &sof_user_heap;
#endif
} else {
heap = &sof_heap;
Expand Down Expand Up @@ -503,6 +543,11 @@ void *rballoc_align(uint32_t flags, uint32_t caps, size_t bytes,
return virtual_heap_alloc(virtual_buffers_heap, flags, caps, bytes, align);
#endif /* CONFIG_VIRTUAL_HEAP */

#if CONFIG_SOF_USERSPACE
if (caps & SOF_MEM_CAPS_MMU_SHD)
heap = &sof_user_heap;
#endif

if (flags & SOF_MEM_FLAG_COHERENT)
return heap_alloc_aligned(heap, align, bytes);

Expand Down Expand Up @@ -540,6 +585,9 @@ static int heap_init(void)
{
sys_heap_init(&sof_heap.heap, heapmem, HEAPMEM_SIZE);

#if CONFIG_SOF_USERSPACE
sys_heap_init(&sof_user_heap.heap, user_heapmem, USER_HEAP_MEM_SIZE);
#endif
#if CONFIG_L3_HEAP
sys_heap_init(&l3_heap.heap, UINT_TO_POINTER(get_l3_heap_start()), get_l3_heap_size());
#endif
Expand Down
Loading