@@ -19,6 +19,7 @@ config RISCV
select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
select ARCH_ENABLE_THP_MIGRATION if TRANSPARENT_HUGEPAGE
select ARCH_HAS_BINFMT_FLAT
+ select ARCH_HAS_CPU_FINALIZE_INIT
select ARCH_HAS_CURRENT_STACK_POINTER
select ARCH_HAS_DEBUG_VIRTUAL if MMU
select ARCH_HAS_DEBUG_VM_PGTABLE
@@ -1081,6 +1082,15 @@ endmenu # "Power management options"
menu "CPU Power Management"
+config RISCV_ZAWRS_IDLE
+ bool "Idle thread using ZAWRS extensions"
+ depends on RISCV_ISA_ZAWRS
+ default y
+ help
+ Adds support to implement idle thread using ZAWRS extension.
+
+ If you don't know what to do here, say Y.
+
source "drivers/cpuidle/Kconfig"
source "drivers/cpufreq/Kconfig"
@@ -10,15 +10,6 @@
#include <asm/barrier.h>
#include <asm/processor.h>
-static inline void cpu_do_idle(void)
-{
- /*
- * Add mb() here to ensure that all
- * IO/MEM accesses are completed prior
- * to entering WFI.
- */
- mb();
- wait_for_interrupt();
-}
+void cpu_do_idle(void);
#endif
@@ -12,6 +12,7 @@
#include <vdso/processor.h>
+#include <asm/insn-def.h>
#include <asm/ptrace.h>
/*
@@ -157,6 +158,21 @@ static inline void wait_for_interrupt(void)
__asm__ __volatile__ ("wfi");
}
+static inline void wrs_nto(unsigned long *addr)
+{
+ int val;
+
+ __asm__ __volatile__(
+#ifdef CONFIG_64BIT
+ "lr.d %[p], %[v]\n\t"
+#else
+ "lr.w %[p], %[v]\n\t"
+#endif
+ ZAWRS_WRS_NTO "\n\t"
+ : [p] "=&r" (val), [v] "+A" (*addr)
+ : : "memory");
+}
+
extern phys_addr_t dma32_phys_limit;
struct device_node;
@@ -183,6 +199,8 @@ extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);
#define GET_UNALIGN_CTL(tsk, addr) get_unalign_ctl((tsk), (addr))
#define SET_UNALIGN_CTL(tsk, val) set_unalign_ctl((tsk), (val))
+extern void select_idle_routine(void);
+
#endif /* __ASSEMBLY__ */
#endif /* _ASM_RISCV_PROCESSOR_H */
@@ -22,6 +22,11 @@ bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
return phys_id == cpuid_to_hartid_map(cpu);
}
+void __init arch_cpu_finalize_init(void)
+{
+ select_idle_routine();
+}
+
/*
* Returns the hart ID of the given device tree node, or -ENODEV if the node
* isn't an enabled and valid RISC-V hart node.
@@ -15,6 +15,7 @@
#include <linux/tick.h>
#include <linux/ptrace.h>
#include <linux/uaccess.h>
+#include <linux/static_call.h>
#include <asm/unistd.h>
#include <asm/processor.h>
@@ -37,11 +38,49 @@ EXPORT_SYMBOL(__stack_chk_guard);
extern asmlinkage void ret_from_fork(void);
-void arch_cpu_idle(void)
+static __cpuidle void default_idle(void)
+{
+ /*
+ * Add mb() here to ensure that all
+ * IO/MEM accesses are completed prior
+ * to entering WFI.
+ */
+ mb();
+ wait_for_interrupt();
+}
+
+static __cpuidle void wrs_idle(void)
+{
+ /*
+ * Add mb() here to ensure that all
+ * IO/MEM accesses are completed prior
+ * to entering WRS.NTO.
+ */
+ mb();
+ wrs_nto(¤t_thread_info()->flags);
+}
+
+DEFINE_STATIC_CALL_NULL(riscv_idle, default_idle);
+
+void __cpuidle cpu_do_idle(void)
+{
+ static_call(riscv_idle)();
+}
+
+void __cpuidle arch_cpu_idle(void)
{
cpu_do_idle();
}
+void __init select_idle_routine(void)
+{
+ if (IS_ENABLED(CONFIG_RISCV_ZAWRS_IDLE) &&
+ riscv_has_extension_likely(RISCV_ISA_EXT_ZAWRS))
+ static_call_update(riscv_idle, wrs_idle);
+ else
+ static_call_update(riscv_idle, default_idle);
+}
+
int set_unalign_ctl(struct task_struct *tsk, unsigned int val)
{
if (!unaligned_ctl_available())