diff --git a/arch/arm/core/aarch64/CMakeLists.txt b/arch/arm/core/aarch64/CMakeLists.txt index da10c9aa781..cb8b8cfde63 100644 --- a/arch/arm/core/aarch64/CMakeLists.txt +++ b/arch/arm/core/aarch64/CMakeLists.txt @@ -8,7 +8,6 @@ if (CONFIG_COVERAGE) endif () zephyr_library_sources( - cpu_idle.S fatal.c irq_init.c irq_manage.c @@ -19,6 +18,15 @@ zephyr_library_sources( vector_table.S ) +# Workaround aarch64 QEMU not responding to host OS signals +# during 'wfi'. +# See https://github.com/zephyrproject-rtos/sdk-ng/issues/255 +if (CONFIG_SOC_QEMU_CORTEX_A53) + zephyr_library_sources(cpu_idle_qemu.c) +else () + zephyr_library_sources(cpu_idle.S) +endif () + zephyr_library_sources_ifdef(CONFIG_GEN_SW_ISR_TABLE isr_wrapper.S) zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c) zephyr_library_sources_ifdef(CONFIG_ARM_MMU arm_mmu.c) diff --git a/arch/arm/core/aarch64/cpu_idle_qemu.c b/arch/arm/core/aarch64/cpu_idle_qemu.c new file mode 100644 index 00000000000..1af5eeaa757 --- /dev/null +++ b/arch/arm/core/aarch64/cpu_idle_qemu.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2020 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + + /** + * @file + * + * @brief Workaround aarch64 QEMU not responding to host OS signals + * during 'wfi'. + * See https://github.com/zephyrproject-rtos/sdk-ng/issues/255 + */ + +#include + +void arch_cpu_idle(void) +{ + /* Do nothing but unconditionally unlock interrupts and return to the + * caller. + */ + + __asm__ volatile("msr daifclr, %0\n\t" + : : "i" (DAIFSET_IRQ) + : "memory", "cc"); +} + +void arch_cpu_atomic_idle(unsigned int key) +{ + /* Do nothing but restore IRQ state */ + arch_irq_unlock(key); +} diff --git a/tests/kernel/context/src/main.c b/tests/kernel/context/src/main.c index 7eb16697141..bb4859cb924 100644 --- a/tests/kernel/context/src/main.c +++ b/tests/kernel/context/src/main.c @@ -91,9 +91,13 @@ #endif /* Cortex-M1, Nios II, and RISCV without CONFIG_RISCV_HAS_CPU_IDLE - * do have a power saving instruction, so k_cpu_idle() returns immediately + * do have a power saving instruction, so k_cpu_idle() returns immediately. + * + * Includes workaround on QEMU aarch64, see + * https://github.com/zephyrproject-rtos/sdk-ng/issues/255 */ #if !defined(CONFIG_CPU_CORTEX_M1) && !defined(CONFIG_NIOS2) && \ + !defined(CONFIG_SOC_QEMU_CORTEX_A53) && \ (!defined(CONFIG_RISCV) || defined(CONFIG_RISCV_HAS_CPU_IDLE)) #define HAS_POWERSAVE_INSTRUCTION #endif