From b22ce6da92f2fca793fa17aeaa0d5399f40f8987 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Wed, 8 Nov 2023 16:51:40 -0800 Subject: [PATCH 1/6] zephyr: cpu: use arch_cpu_start instead of arch_start_cpu This uses arch_cpu_start() instead of arch_start_cpu() as it has been renamed to align with the CPU namespace. Signed-off-by: Daniel Leung --- zephyr/lib/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zephyr/lib/cpu.c b/zephyr/lib/cpu.c index 3dde19dc38bc..8efe99c1532f 100644 --- a/zephyr/lib/cpu.c +++ b/zephyr/lib/cpu.c @@ -155,7 +155,7 @@ int cpu_enable_core(int id) atomic_clear(&start_flag); atomic_clear(&ready_flag); - arch_start_cpu(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, + arch_cpu_start(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, secondary_init, &start_flag); while (!atomic_get(&ready_flag)) @@ -255,7 +255,7 @@ int cpu_enable_secondary_core(int id) atomic_clear(&start_flag); atomic_clear(&ready_flag); - arch_start_cpu(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, + arch_cpu_start(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, secondary_init, &start_flag); while (!atomic_get(&ready_flag)) From 11c251a506ea171831fd04f1c5b0c2e94eade396 Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Fri, 3 Nov 2023 11:57:30 -0700 Subject: [PATCH 2/6] zephyr: use k_smp_cpu_start/_resume for secondary core power up This changes the seconday core power up routine to use the newly introduced k_smp_cpu_start() and k_smp_cpu_resume(). This removes the need to mirror part of the SMP start up code from Zephyr, and no longer need to call into Zephyr private kernel code. Signed-off-by: Daniel Leung --- zephyr/lib/cpu.c | 55 +++++++++--------------------------------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/zephyr/lib/cpu.c b/zephyr/lib/cpu.c index 8efe99c1532f..9424cdc140e2 100644 --- a/zephyr/lib/cpu.c +++ b/zephyr/lib/cpu.c @@ -19,6 +19,7 @@ /* Zephyr includes */ #include #include +#include #include #include @@ -27,37 +28,13 @@ extern K_KERNEL_STACK_ARRAY_DEFINE(z_interrupt_stacks, CONFIG_MP_MAX_NUM_CPUS, CONFIG_ISR_STACK_SIZE); -static atomic_t start_flag; static atomic_t ready_flag; -/* Zephyr kernel_internal.h interface */ -extern void smp_timer_init(void); - -static FUNC_NORETURN void secondary_init(void *arg) +static void secondary_init(void *arg) { - struct k_thread dummy_thread; - - /* - * This is an open-coded version of zephyr/kernel/smp.c - * smp_init_top(). We do this so that we can call SOF - * secondary_core_init() for each core. - */ - atomic_set(&ready_flag, 1); - z_smp_thread_init(arg, &dummy_thread); - smp_timer_init(); secondary_core_init(sof_get()); - -#ifdef CONFIG_THREAD_STACK_INFO - dummy_thread.stack_info.start = (uintptr_t)z_interrupt_stacks + - arch_curr_cpu()->id * Z_KERNEL_STACK_LEN(CONFIG_ISR_STACK_SIZE); - dummy_thread.stack_info.size = Z_KERNEL_STACK_LEN(CONFIG_ISR_STACK_SIZE); -#endif - - z_smp_thread_swap(); - - CODE_UNREACHABLE; /* LCOV_EXCL_LINE */ } #if CONFIG_ZEPHYR_NATIVE_DRIVERS @@ -131,13 +108,10 @@ void cpu_notify_state_exit(enum pm_state state) int cpu_enable_core(int id) { + bool cpu_resume = true; + /* only called from single core, no RMW lock */ __ASSERT_NO_MSG(cpu_is_primary(arch_proc_id())); - /* - * This is an open-coded version of zephyr/kernel/smp.c - * z_smp_start_cpu(). We do this, so we can use a customized - * secondary_init() for SOF. - */ if (arch_cpu_active(id)) return 0; @@ -149,20 +123,19 @@ int cpu_enable_core(int id) * and the idle thread stack. */ if (pm_state_next_get(id)->state == PM_STATE_ACTIVE) - z_init_cpu(id); + cpu_resume = false; #endif - atomic_clear(&start_flag); atomic_clear(&ready_flag); - arch_cpu_start(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, - secondary_init, &start_flag); + if (cpu_resume) + k_smp_cpu_resume(id, secondary_init, NULL, true, false); + else + k_smp_cpu_start(id, secondary_init, NULL); while (!atomic_get(&ready_flag)) k_busy_wait(100); - atomic_set(&start_flag, 1); - return 0; } @@ -248,21 +221,13 @@ int cpu_enable_secondary_core(int id) if (arch_cpu_active(id)) return 0; -#if ZEPHYR_VERSION(3, 0, 99) <= ZEPHYR_VERSION_CODE - z_init_cpu(id); -#endif - - atomic_clear(&start_flag); atomic_clear(&ready_flag); - arch_cpu_start(id, z_interrupt_stacks[id], CONFIG_ISR_STACK_SIZE, - secondary_init, &start_flag); + k_smp_cpu_start(id, secondary_init, NULL); while (!atomic_get(&ready_flag)) k_busy_wait(100); - atomic_set(&start_flag, 1); - return 0; } From 5553bcfe4aacc8500181800b6a27dbc38e825a39 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Mon, 22 Jan 2024 12:50:19 -0500 Subject: [PATCH 3/6] app: fix filter in sample.yaml nxp_adsp_imx8ulp needs to be in allowed platforms. Signed-off-by: Anas Nashif --- app/sample.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/sample.yaml b/app/sample.yaml index 84a3929a6f7e..f370e42ac8aa 100644 --- a/app/sample.yaml +++ b/app/sample.yaml @@ -11,8 +11,13 @@ tests: tags: sof build_only: true platform_allow: - intel_adsp_cavs25 intel_adsp_ace15_mtpm intel_adsp_ace20_lnl - nxp_adsp_imx8 nxp_adsp_imx8x nxp_adsp_imx8m + - intel_adsp_cavs25 + - intel_adsp_ace15_mtpm + - intel_adsp_ace20_lnl + - nxp_adsp_imx8 + - nxp_adsp_imx8x + - nxp_adsp_imx8m + - nxp_adsp_imx8ulp integration_platforms: - intel_adsp_cavs25 # TGL From b4214e582080103532c89dd68c35a65528c7f139 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Fri, 1 Dec 2023 07:54:10 -0500 Subject: [PATCH 4/6] zephyr: use arch_xtensa_uncached_ptr/arch_xtensa_cached_ptr Use direct call to function instead of going over a redefine. Signed-off-by: Anas Nashif --- zephyr/lib/alloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zephyr/lib/alloc.c b/zephyr/lib/alloc.c index 4c4baa325e6e..cba457ea0613 100644 --- a/zephyr/lib/alloc.c +++ b/zephyr/lib/alloc.c @@ -116,7 +116,7 @@ static inline uintptr_t get_l3_heap_start(void) * - main_fw_load_offset * - main fw size in manifest */ - return (uintptr_t)z_soc_uncached_ptr((__sparse_force void __sparse_cache *) + return (uintptr_t)arch_xtensa_uncached_ptr((__sparse_force void __sparse_cache *) ROUND_UP(IMR_L3_HEAP_BASE, L3_MEM_PAGE_SIZE)); } @@ -146,7 +146,7 @@ static bool is_l3_heap_pointer(void *ptr) uintptr_t l3_heap_end = l3_heap_start + get_l3_heap_size(); if (is_cached(ptr)) - ptr = z_soc_uncached_ptr((__sparse_force void __sparse_cache *)ptr); + ptr = arch_xtensa_uncached_ptr((__sparse_force void __sparse_cache *)ptr); if ((POINTER_TO_UINT(ptr) >= l3_heap_start) && (POINTER_TO_UINT(ptr) < l3_heap_end)) return true; @@ -199,7 +199,7 @@ static void __sparse_cache *heap_alloc_aligned_cached(struct k_heap *h, #ifdef CONFIG_SOF_ZEPHYR_HEAP_CACHED if (ptr) - ptr = z_soc_cached_ptr((__sparse_force void *)ptr); + ptr = arch_xtensa_cached_ptr((__sparse_force void *)ptr); #endif return ptr; @@ -212,7 +212,7 @@ static void heap_free(struct k_heap *h, void *mem) void *mem_uncached; if (is_cached(mem)) { - mem_uncached = z_soc_uncached_ptr((__sparse_force void __sparse_cache *)mem); + mem_uncached = arch_xtensa_uncached_ptr((__sparse_force void __sparse_cache *)mem); sys_cache_data_flush_and_invd_range(mem, sys_heap_usable_size(&h->heap, mem_uncached)); From 7a0ff76e05cab6b1d99767258680a7b8711dd476 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Thu, 6 Apr 2023 13:13:48 +0000 Subject: [PATCH 5/6] app: zephyr still requires cmake version 3.20.0 Set min. cmake version required to what zephyr uses. Signed-off-by: Anas Nashif --- app/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index da9db799d387..ed6e53025fed 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 -cmake_minimum_required(VERSION 3.21.0) +cmake_minimum_required(VERSION 3.20.0) find_package(Zephyr HINTS $ENV{ZEPHYR_BASE}) project(sample_sof) From bb4f1638e37f71ac97daaada55d9370173508074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Wed, 31 Jan 2024 08:51:46 +0100 Subject: [PATCH 6/6] zephyr: include: sof: trace: Fix the trace level setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Header has a guard to not reinclude logging header if it was already included but inside this guard there is a definition of SOF_ZEPHYR_TRACE_LEVEL which is later on used. So if log.h is already earlier included SOF_ZEPHYR_TRACE_LEVEL is not defined and compilation fails. Moving this definition outside of the guard because if log.h is already included LOG_LEVEL_INF is available. Signed-off-by: Krzysztof Chruściński --- zephyr/include/sof/trace/trace.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/zephyr/include/sof/trace/trace.h b/zephyr/include/sof/trace/trace.h index 656b859fb514..44ba60dd7338 100644 --- a/zephyr/include/sof/trace/trace.h +++ b/zephyr/include/sof/trace/trace.h @@ -9,12 +9,11 @@ #ifndef ZEPHYR_INCLUDE_LOGGING_LOG_H_ #include #include +#endif /* Level of SOF trace on Zephyr */ #define SOF_ZEPHYR_TRACE_LEVEL LOG_LEVEL_INF -#endif - /* printk supports uint64_t so use it until LOG is ready */ #define USE_PRINTK 1