Skip to content

Commit f6e64b6

Browse files
avpatelpalmer-dabbelt
authored andcommitted
RISC-V: Enable CPU_IDLE drivers
We force select CPU_PM and provide asm/cpuidle.h so that we can use CPU IDLE drivers for Linux RISC-V kernel. Signed-off-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Anup Patel <apatel@vetanamicro.com> Reviewed-by: Guo Ren <guoren@kernel.org> Reviewed-by: Atish Patra <atishp@rivosinc.com> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent e783362 commit f6e64b6

5 files changed

Lines changed: 35 additions & 1 deletion

File tree

arch/riscv/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ config RISCV
4646
select CLONE_BACKWARDS
4747
select CLINT_TIMER if !MMU
4848
select COMMON_CLK
49+
select CPU_PM if CPU_IDLE
4950
select EDAC_SUPPORT
5051
select GENERIC_ARCH_TOPOLOGY if SMP
5152
select GENERIC_ATOMIC64 if !64BIT
@@ -547,4 +548,10 @@ source "kernel/power/Kconfig"
547548

548549
endmenu
549550

551+
menu "CPU Power Management"
552+
553+
source "drivers/cpuidle/Kconfig"
554+
555+
endmenu
556+
550557
source "arch/riscv/kvm/Kconfig"

arch/riscv/configs/defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CONFIG_SOC_SIFIVE=y
2020
CONFIG_SOC_VIRT=y
2121
CONFIG_SMP=y
2222
CONFIG_HOTPLUG_CPU=y
23+
CONFIG_CPU_IDLE=y
2324
CONFIG_VIRTUALIZATION=y
2425
CONFIG_KVM=m
2526
CONFIG_JUMP_LABEL=y

arch/riscv/configs/rv32_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ CONFIG_SOC_VIRT=y
2020
CONFIG_ARCH_RV32I=y
2121
CONFIG_SMP=y
2222
CONFIG_HOTPLUG_CPU=y
23+
CONFIG_CPU_IDLE=y
2324
CONFIG_VIRTUALIZATION=y
2425
CONFIG_KVM=m
2526
CONFIG_JUMP_LABEL=y

arch/riscv/include/asm/cpuidle.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (C) 2021 Allwinner Ltd
4+
* Copyright (C) 2021 Western Digital Corporation or its affiliates.
5+
*/
6+
7+
#ifndef _ASM_RISCV_CPUIDLE_H
8+
#define _ASM_RISCV_CPUIDLE_H
9+
10+
#include <asm/barrier.h>
11+
#include <asm/processor.h>
12+
13+
static inline void cpu_do_idle(void)
14+
{
15+
/*
16+
* Add mb() here to ensure that all
17+
* IO/MEM accesses are completed prior
18+
* to entering WFI.
19+
*/
20+
mb();
21+
wait_for_interrupt();
22+
}
23+
24+
#endif

arch/riscv/kernel/process.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <asm/string.h>
2424
#include <asm/switch_to.h>
2525
#include <asm/thread_info.h>
26+
#include <asm/cpuidle.h>
2627

2728
register unsigned long gp_in_global __asm__("gp");
2829

@@ -37,7 +38,7 @@ extern asmlinkage void ret_from_kernel_thread(void);
3738

3839
void arch_cpu_idle(void)
3940
{
40-
wait_for_interrupt();
41+
cpu_do_idle();
4142
raw_local_irq_enable();
4243
}
4344

0 commit comments

Comments
 (0)