Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / acpi / riscv / cpuidle.c
blob624f9bbdb58c471862489d420bc4c49ac212c362
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2024, Ventana Micro Systems Inc
4 * Author: Sunil V L <sunilvl@ventanamicro.com>
6 */
8 #include <linux/acpi.h>
9 #include <acpi/processor.h>
10 #include <linux/cpu_pm.h>
11 #include <linux/cpuidle.h>
12 #include <linux/suspend.h>
13 #include <asm/cpuidle.h>
14 #include <asm/sbi.h>
15 #include <asm/suspend.h>
17 #define RISCV_FFH_LPI_TYPE_MASK GENMASK_ULL(63, 60)
18 #define RISCV_FFH_LPI_RSVD_MASK GENMASK_ULL(59, 32)
20 #define RISCV_FFH_LPI_TYPE_SBI BIT_ULL(60)
22 static int acpi_cpu_init_idle(unsigned int cpu)
24 int i;
25 struct acpi_lpi_state *lpi;
26 struct acpi_processor *pr = per_cpu(processors, cpu);
28 if (unlikely(!pr || !pr->flags.has_lpi))
29 return -EINVAL;
31 if (!riscv_sbi_hsm_is_supported())
32 return -ENODEV;
34 if (pr->power.count <= 1)
35 return -ENODEV;
37 for (i = 1; i < pr->power.count; i++) {
38 u32 state;
40 lpi = &pr->power.lpi_states[i];
43 * Validate Entry Method as per FFH spec.
44 * bits[63:60] should be 0x1
45 * bits[59:32] should be 0x0
46 * bits[31:0] represent a SBI power_state
48 if (((lpi->address & RISCV_FFH_LPI_TYPE_MASK) != RISCV_FFH_LPI_TYPE_SBI) ||
49 (lpi->address & RISCV_FFH_LPI_RSVD_MASK)) {
50 pr_warn("Invalid LPI entry method %#llx\n", lpi->address);
51 return -EINVAL;
54 state = lpi->address;
55 if (!riscv_sbi_suspend_state_is_valid(state)) {
56 pr_warn("Invalid SBI power state %#x\n", state);
57 return -EINVAL;
61 return 0;
64 int acpi_processor_ffh_lpi_probe(unsigned int cpu)
66 return acpi_cpu_init_idle(cpu);
69 int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi)
71 u32 state = lpi->address;
73 if (state & SBI_HSM_SUSP_NON_RET_BIT)
74 return CPU_PM_CPU_IDLE_ENTER_PARAM(riscv_sbi_hart_suspend,
75 lpi->index,
76 state);
77 else
78 return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(riscv_sbi_hart_suspend,
79 lpi->index,
80 state);