diff --git a/app/boards/intel_adsp_ace30_ptl.conf b/app/boards/intel_adsp_ace30_ptl.conf index a90abefa38e5..78c170e920da 100644 --- a/app/boards/intel_adsp_ace30_ptl.conf +++ b/app/boards/intel_adsp_ace30_ptl.conf @@ -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 diff --git a/app/debug_overlay.conf b/app/debug_overlay.conf index 650b3c09f7f2..4cc9a9207f3f 100644 --- a/app/debug_overlay.conf +++ b/app/debug_overlay.conf @@ -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 diff --git a/src/include/sof/sof_syscall.h b/src/include/sof/sof_syscall.h new file mode 100644 index 000000000000..963dd8fb49f1 --- /dev/null +++ b/src/include/sof/sof_syscall.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2025, Intel Corporation. + */ + +#ifndef SOF_SYSCALL +#define SOF_SYSCALL + +#include + +#include + +__syscall uint32_t sof_local_lock(void); +__syscall void sof_local_unlock(uint32_t flags); + +#include + +#endif diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 071219fd9d04..a87c7e162f7a 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -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( diff --git a/zephyr/boot_test.c b/zephyr/boot_test.c index 4cbbfa597d8b..22cbead7ead4 100644 --- a/zephyr/boot_test.c +++ b/zephyr/boot_test.c @@ -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); diff --git a/zephyr/syscall/sof_local_lock.c b/zephyr/syscall/sof_local_lock.c new file mode 100644 index 000000000000..06524a0a6f6b --- /dev/null +++ b/zephyr/syscall/sof_local_lock.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2025 Intel Corporation. + +#include +#include + +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 + +static inline void z_vrfy_sof_local_unlock(uint32_t flags) +{ + z_impl_sof_local_unlock(flags); +} +#include +#endif /* CONFIG_USERSPACE */ diff --git a/zephyr/test/CMakeLists.txt b/zephyr/test/CMakeLists.txt index e0718b8e0754..f757ea73a995 100644 --- a/zephyr/test/CMakeLists.txt +++ b/zephyr/test/CMakeLists.txt @@ -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() diff --git a/zephyr/test/userspace/cache.c b/zephyr/test/userspace/cache.c new file mode 100644 index 000000000000..18df6373be18 --- /dev/null +++ b/zephyr/test/userspace/cache.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright(c) 2025 Intel Corporation. + */ + +#include + +#include +#include +#include +#include + +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(); +} diff --git a/zephyr/test/userspace/local_lock.c b/zephyr/test/userspace/local_lock.c new file mode 100644 index 000000000000..0be0a8eb5635 --- /dev/null +++ b/zephyr/test/userspace/local_lock.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright(c) 2025 Intel Corporation. + */ + +#include +#include + +#include +#include +#include + +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(); +} diff --git a/zephyr/test/vmh.c b/zephyr/test/vmh.c index 26e044a2d9f0..4a1b7365c4be 100644 --- a/zephyr/test/vmh.c +++ b/zephyr/test/vmh.c @@ -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 */ @@ -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}; @@ -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 */