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
4 changes: 4 additions & 0 deletions app/boards/intel_adsp_ace30_ptl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ CONFIG_LOG_MODE_DEFERRED=y
CONFIG_LOG_OUTPUT_FORMAT_LINUX_TIMESTAMP=y
CONFIG_LOG_TIMESTAMP_64BIT=y
CONFIG_WINSTREAM_CONSOLE=n

CONFIG_USERSPACE=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_MAX_THREAD_BYTES=3
5 changes: 2 additions & 3 deletions app/debug_overlay.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
CONFIG_DEBUG=y
CONFIG_ASSERT=y

# Disabled until DSP panic #8621 is fixed
# CONFIG_ZTEST=y
# CONFIG_SOF_BOOT_TEST=y
CONFIG_ZTEST=y
CONFIG_SOF_BOOT_TEST=y

CONFIG_DAI_VERBOSE_GLITCH_WARNINGS=y

Expand Down
18 changes: 18 additions & 0 deletions src/include/sof/sof_syscall.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 2025, Intel Corporation.
*/

#ifndef SOF_SYSCALL
#define SOF_SYSCALL

#include <zephyr/toolchain.h>

#include <stdint.h>

__syscall uint32_t sof_local_lock(void);
__syscall void sof_local_unlock(uint32_t flags);

#include <zephyr/syscalls/sof_syscall.h>

#endif
5 changes: 5 additions & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,11 @@ if(NOT DEFINED PLATFORM)
endif()
zephyr_include_directories(${SOF_PLATFORM_PATH}/${PLATFORM}/include)

zephyr_library_sources_ifdef(CONFIG_USERSPACE
syscall/sof_local_lock.c
)
zephyr_syscall_header(${SOF_SRC_PATH}/include/sof/sof_syscall.h)

# Mandatory Files used on all platforms.
# Commented files will be added/removed as integration dictates.
zephyr_library_sources(
Expand Down
3 changes: 2 additions & 1 deletion zephyr/boot_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ LOG_MODULE_REGISTER(sof_boot_test, LOG_LEVEL_DBG);

ZTEST_SUITE(sof_boot, NULL, NULL, NULL, NULL, NULL);

void sys_run_boot_tests(void)
int sys_run_boot_tests(void)
{
ztest_run_all(NULL, false, 1, 1);
return 0;
}
SYS_INIT(sys_run_boot_tests, APPLICATION, 99);

33 changes: 33 additions & 0 deletions zephyr/syscall/sof_local_lock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2025 Intel Corporation.

#include <sof/sof_syscall.h>
#include <rtos/interrupt.h>

uint32_t z_impl_sof_local_lock(void)
{
uint32_t flags;

irq_local_disable(flags);
return flags;
}

void z_impl_sof_local_unlock(uint32_t flags)
{
irq_local_enable(flags);
}

#ifdef CONFIG_USERSPACE
static inline uint32_t z_vrfy_sof_local_lock(void)
{
return z_impl_sof_local_lock();
}
#include <zephyr/syscalls/sof_local_lock_mrsh.c>

static inline void z_vrfy_sof_local_unlock(uint32_t flags)
{
z_impl_sof_local_unlock(flags);
}
#include <zephyr/syscalls/sof_local_unlock_mrsh.c>
#endif /* CONFIG_USERSPACE */
15 changes: 11 additions & 4 deletions zephyr/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
if (CONFIG_ACE_VERSION_1_5)
zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST
vmh.c
)
if (CONFIG_ACE_VERSION_1_5 OR CONFIG_ACE_VERSION_2_0 OR CONFIG_ACE_VERSION_3_0)
zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST
vmh.c
)
endif()

if (CONFIG_ACE_VERSION_3_0)
zephyr_library_sources_ifdef(CONFIG_SOF_BOOT_TEST
userspace/cache.c
userspace/local_lock.c
)
endif()
53 changes: 53 additions & 0 deletions zephyr/test/userspace/cache.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: BSD-3-Clause
/*
* Copyright(c) 2025 Intel Corporation.
*/

#include <sof/boot_test.h>

#include <zephyr/kernel.h>
#include <rtos/cache.h>
#include <zephyr/ztest.h>
#include <zephyr/logging/log.h>

LOG_MODULE_DECLARE(sof_boot_test, LOG_LEVEL_DBG);

#define USER_STACKSIZE 2048

static struct k_thread user_thread;
static K_THREAD_STACK_DEFINE(user_stack, USER_STACKSIZE);

static void user_function(void *p1, void *p2, void *p3)
{
char stack_buf[64];

__ASSERT(k_is_user_context(), "isn't user");

LOG_INF("SOF thread %s (%s)",
k_is_user_context() ? "UserSpace!" : "privileged mode.",
CONFIG_BOARD_TARGET);

/*
* Use rtos/cache.h calls as these are also used by
* src/audio code.
*/

dcache_writeback_region(stack_buf, sizeof(stack_buf));

dcache_invalidate_region(stack_buf, sizeof(stack_buf));
}

static void test_user_thread_cache(void)
{
k_thread_create(&user_thread, user_stack, USER_STACKSIZE,
user_function, NULL, NULL, NULL,
-1, K_USER, K_MSEC(0));
k_thread_join(&user_thread, K_FOREVER);
}

ZTEST(sof_boot, user_space_cache)
{
test_user_thread_cache();

ztest_test_pass();
}
61 changes: 61 additions & 0 deletions zephyr/test/userspace/local_lock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: BSD-3-Clause
/*
* Copyright(c) 2025 Intel Corporation.
*/

#include <sof/boot_test.h>
#include <sof/sof_syscall.h>

#include <zephyr/kernel.h>
#include <zephyr/ztest.h>
#include <zephyr/logging/log.h>

LOG_MODULE_DECLARE(sof_boot_test, LOG_LEVEL_DBG);

#define USER_STACKSIZE 2048

static struct k_thread user_thread;
static K_THREAD_STACK_DEFINE(user_stack, USER_STACKSIZE);

static void user_function(void *p1, void *p2, void *p3)
{
__ASSERT(k_is_user_context(), "isn't user");
LOG_INF("SOF thread %s (%s)",
k_is_user_context() ? "UserSpace!" : "privileged mode.",
CONFIG_BOARD_TARGET);
}

static void user_lock_function(void *p1, void *p2, void *p3)
{
uint32_t flags = sof_local_lock();

__ASSERT(k_is_user_context(), "isn't user");
LOG_INF("SOF thread %s (%s)",
k_is_user_context() ? "UserSpace!" : "privileged mode.",
CONFIG_BOARD_TARGET);
sof_local_unlock(flags);
}

static void test_user_thread(void)
{
k_thread_create(&user_thread, user_stack, USER_STACKSIZE,
user_function, NULL, NULL, NULL,
-1, K_USER, K_MSEC(0));
k_thread_join(&user_thread, K_FOREVER);
}

static void test_user_thread_with_lock(void)
{
k_thread_create(&user_thread, user_stack, USER_STACKSIZE,
user_lock_function, NULL, NULL, NULL,
-1, K_USER, K_MSEC(0));
k_thread_join(&user_thread, K_FOREVER);
}

ZTEST(sof_boot, user_space)
{
test_user_thread();
test_user_thread_with_lock();

ztest_test_pass();
}
5 changes: 2 additions & 3 deletions zephyr/test/vmh.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ static void test_vmh_multiple_allocs(struct vmh_heap *heap, int num_allocs,
{
void *ptrs[num_allocs];
uint32_t alloc_size;
bool success;
int ret;

/* Perform multiple allocations */
Expand Down Expand Up @@ -192,7 +191,7 @@ static void test_vmh_alloc_free(bool allocating_continuously)
/* Test case for vmh_alloc and vmh_free with and without config */
static void test_heap_creation(void)
{
test_vmh_init_and_free_heap(NULL, 0, false, true);
test_vmh_init_and_free_heap(NULL, false, true);

/* Try to setup with pre defined heap config */
struct vmh_heap_config config = {0};
Expand All @@ -205,7 +204,7 @@ static void test_heap_creation(void)

config.block_bundles_table[1].number_of_blocks = 512;

test_vmh_init_and_free_heap(&config, 0, false, true);
test_vmh_init_and_free_heap(&config, false, true);
}

/* Test case for alloc/free on configured heap */
Expand Down
Loading