Skip to content

Commit 6649182

Browse files
vlsunilpalmer-dabbelt
authored andcommitted
cpuidle: RISC-V: Move few functions to arch/riscv
To support ACPI Low Power Idle (LPI), few functions are required which are currently static functions in the DT based cpuidle driver. Hence, move them under arch/riscv so that ACPI driver also can use them. Since they are no longer static functions, append "riscv_" prefix to the function name. Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://lore.kernel.org/r/20240118062930.245937-2-sunilvl@ventanamicro.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 6613476 commit 6649182

File tree

3 files changed

+57
-44
lines changed

3 files changed

+57
-44
lines changed

arch/riscv/include/asm/suspend.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@ int hibernate_resume_nonboot_cpu_disable(void);
5555
asmlinkage void hibernate_restore_image(unsigned long resume_satp, unsigned long satp_temp,
5656
unsigned long cpu_resume);
5757
asmlinkage int hibernate_core_restore_code(void);
58+
bool riscv_sbi_hsm_is_supported(void);
59+
bool riscv_sbi_suspend_state_is_valid(u32 state);
60+
int riscv_sbi_hart_suspend(u32 state);
5861
#endif

arch/riscv/kernel/suspend.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,53 @@ static int __init sbi_system_suspend_init(void)
128128
}
129129

130130
arch_initcall(sbi_system_suspend_init);
131+
132+
static int sbi_suspend_finisher(unsigned long suspend_type,
133+
unsigned long resume_addr,
134+
unsigned long opaque)
135+
{
136+
struct sbiret ret;
137+
138+
ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_SUSPEND,
139+
suspend_type, resume_addr, opaque, 0, 0, 0);
140+
141+
return (ret.error) ? sbi_err_map_linux_errno(ret.error) : 0;
142+
}
143+
144+
int riscv_sbi_hart_suspend(u32 state)
145+
{
146+
if (state & SBI_HSM_SUSP_NON_RET_BIT)
147+
return cpu_suspend(state, sbi_suspend_finisher);
148+
else
149+
return sbi_suspend_finisher(state, 0, 0);
150+
}
151+
152+
bool riscv_sbi_suspend_state_is_valid(u32 state)
153+
{
154+
if (state > SBI_HSM_SUSPEND_RET_DEFAULT &&
155+
state < SBI_HSM_SUSPEND_RET_PLATFORM)
156+
return false;
157+
158+
if (state > SBI_HSM_SUSPEND_NON_RET_DEFAULT &&
159+
state < SBI_HSM_SUSPEND_NON_RET_PLATFORM)
160+
return false;
161+
162+
return true;
163+
}
164+
165+
bool riscv_sbi_hsm_is_supported(void)
166+
{
167+
/*
168+
* The SBI HSM suspend function is only available when:
169+
* 1) SBI version is 0.3 or higher
170+
* 2) SBI HSM extension is available
171+
*/
172+
if (sbi_spec_version < sbi_mk_version(0, 3) ||
173+
!sbi_probe_extension(SBI_EXT_HSM)) {
174+
pr_info("HSM suspend not available\n");
175+
return false;
176+
}
177+
178+
return true;
179+
}
131180
#endif /* CONFIG_RISCV_SBI */

drivers/cpuidle/cpuidle-riscv-sbi.c

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -73,36 +73,16 @@ static inline bool sbi_is_domain_state_available(void)
7373
return data->available;
7474
}
7575

76-
static int sbi_suspend_finisher(unsigned long suspend_type,
77-
unsigned long resume_addr,
78-
unsigned long opaque)
79-
{
80-
struct sbiret ret;
81-
82-
ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_SUSPEND,
83-
suspend_type, resume_addr, opaque, 0, 0, 0);
84-
85-
return (ret.error) ? sbi_err_map_linux_errno(ret.error) : 0;
86-
}
87-
88-
static int sbi_suspend(u32 state)
89-
{
90-
if (state & SBI_HSM_SUSP_NON_RET_BIT)
91-
return cpu_suspend(state, sbi_suspend_finisher);
92-
else
93-
return sbi_suspend_finisher(state, 0, 0);
94-
}
95-
9676
static __cpuidle int sbi_cpuidle_enter_state(struct cpuidle_device *dev,
9777
struct cpuidle_driver *drv, int idx)
9878
{
9979
u32 *states = __this_cpu_read(sbi_cpuidle_data.states);
10080
u32 state = states[idx];
10181

10282
if (state & SBI_HSM_SUSP_NON_RET_BIT)
103-
return CPU_PM_CPU_IDLE_ENTER_PARAM(sbi_suspend, idx, state);
83+
return CPU_PM_CPU_IDLE_ENTER_PARAM(riscv_sbi_hart_suspend, idx, state);
10484
else
105-
return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(sbi_suspend,
85+
return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(riscv_sbi_hart_suspend,
10686
idx, state);
10787
}
10888

@@ -133,7 +113,7 @@ static __cpuidle int __sbi_enter_domain_idle_state(struct cpuidle_device *dev,
133113
else
134114
state = states[idx];
135115

136-
ret = sbi_suspend(state) ? -1 : idx;
116+
ret = riscv_sbi_hart_suspend(state) ? -1 : idx;
137117

138118
ct_cpuidle_exit();
139119

@@ -206,17 +186,6 @@ static const struct of_device_id sbi_cpuidle_state_match[] = {
206186
{ },
207187
};
208188

209-
static bool sbi_suspend_state_is_valid(u32 state)
210-
{
211-
if (state > SBI_HSM_SUSPEND_RET_DEFAULT &&
212-
state < SBI_HSM_SUSPEND_RET_PLATFORM)
213-
return false;
214-
if (state > SBI_HSM_SUSPEND_NON_RET_DEFAULT &&
215-
state < SBI_HSM_SUSPEND_NON_RET_PLATFORM)
216-
return false;
217-
return true;
218-
}
219-
220189
static int sbi_dt_parse_state_node(struct device_node *np, u32 *state)
221190
{
222191
int err = of_property_read_u32(np, "riscv,sbi-suspend-param", state);
@@ -226,7 +195,7 @@ static int sbi_dt_parse_state_node(struct device_node *np, u32 *state)
226195
return err;
227196
}
228197

229-
if (!sbi_suspend_state_is_valid(*state)) {
198+
if (!riscv_sbi_suspend_state_is_valid(*state)) {
230199
pr_warn("Invalid SBI suspend state %#x\n", *state);
231200
return -EINVAL;
232201
}
@@ -607,16 +576,8 @@ static int __init sbi_cpuidle_init(void)
607576
int ret;
608577
struct platform_device *pdev;
609578

610-
/*
611-
* The SBI HSM suspend function is only available when:
612-
* 1) SBI version is 0.3 or higher
613-
* 2) SBI HSM extension is available
614-
*/
615-
if ((sbi_spec_version < sbi_mk_version(0, 3)) ||
616-
!sbi_probe_extension(SBI_EXT_HSM)) {
617-
pr_info("HSM suspend not available\n");
579+
if (!riscv_sbi_hsm_is_supported())
618580
return 0;
619-
}
620581

621582
ret = platform_driver_register(&sbi_cpuidle_driver);
622583
if (ret)

0 commit comments

Comments
 (0)