.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * ARM64 CPU idle arch support |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2014 ARM Ltd. |
---|
5 | 6 | * Author: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or modify |
---|
8 | | - * it under the terms of the GNU General Public License version 2 as |
---|
9 | | - * published by the Free Software Foundation. |
---|
10 | 7 | */ |
---|
11 | 8 | |
---|
12 | 9 | #include <linux/acpi.h> |
---|
.. | .. |
---|
14 | 11 | #include <linux/cpu_pm.h> |
---|
15 | 12 | #include <linux/of.h> |
---|
16 | 13 | #include <linux/of_device.h> |
---|
| 14 | +#include <linux/psci.h> |
---|
17 | 15 | |
---|
18 | 16 | #include <asm/cpuidle.h> |
---|
19 | 17 | #include <asm/cpu_ops.h> |
---|
20 | 18 | |
---|
21 | 19 | int arm_cpuidle_init(unsigned int cpu) |
---|
22 | 20 | { |
---|
| 21 | + const struct cpu_operations *ops = get_cpu_ops(cpu); |
---|
23 | 22 | int ret = -EOPNOTSUPP; |
---|
24 | 23 | |
---|
25 | | - if (cpu_ops[cpu] && cpu_ops[cpu]->cpu_suspend && |
---|
26 | | - cpu_ops[cpu]->cpu_init_idle) |
---|
27 | | - ret = cpu_ops[cpu]->cpu_init_idle(cpu); |
---|
| 24 | + if (ops && ops->cpu_suspend && ops->cpu_init_idle) |
---|
| 25 | + ret = ops->cpu_init_idle(cpu); |
---|
28 | 26 | |
---|
29 | 27 | return ret; |
---|
30 | 28 | } |
---|
.. | .. |
---|
39 | 37 | int arm_cpuidle_suspend(int index) |
---|
40 | 38 | { |
---|
41 | 39 | int cpu = smp_processor_id(); |
---|
| 40 | + const struct cpu_operations *ops = get_cpu_ops(cpu); |
---|
42 | 41 | |
---|
43 | | - return cpu_ops[cpu]->cpu_suspend(index); |
---|
| 42 | + return ops->cpu_suspend(index); |
---|
44 | 43 | } |
---|
45 | | -EXPORT_SYMBOL_GPL(arm_cpuidle_suspend); |
---|
46 | 44 | |
---|
47 | 45 | #ifdef CONFIG_ACPI |
---|
48 | 46 | |
---|
.. | .. |
---|
50 | 48 | |
---|
51 | 49 | #define ARM64_LPI_IS_RETENTION_STATE(arch_flags) (!(arch_flags)) |
---|
52 | 50 | |
---|
| 51 | +static int psci_acpi_cpu_init_idle(unsigned int cpu) |
---|
| 52 | +{ |
---|
| 53 | + int i, count; |
---|
| 54 | + struct acpi_lpi_state *lpi; |
---|
| 55 | + struct acpi_processor *pr = per_cpu(processors, cpu); |
---|
| 56 | + |
---|
| 57 | + if (unlikely(!pr || !pr->flags.has_lpi)) |
---|
| 58 | + return -EINVAL; |
---|
| 59 | + |
---|
| 60 | + /* |
---|
| 61 | + * If the PSCI cpu_suspend function hook has not been initialized |
---|
| 62 | + * idle states must not be enabled, so bail out |
---|
| 63 | + */ |
---|
| 64 | + if (!psci_ops.cpu_suspend) |
---|
| 65 | + return -EOPNOTSUPP; |
---|
| 66 | + |
---|
| 67 | + count = pr->power.count - 1; |
---|
| 68 | + if (count <= 0) |
---|
| 69 | + return -ENODEV; |
---|
| 70 | + |
---|
| 71 | + for (i = 0; i < count; i++) { |
---|
| 72 | + u32 state; |
---|
| 73 | + |
---|
| 74 | + lpi = &pr->power.lpi_states[i + 1]; |
---|
| 75 | + /* |
---|
| 76 | + * Only bits[31:0] represent a PSCI power_state while |
---|
| 77 | + * bits[63:32] must be 0x0 as per ARM ACPI FFH Specification |
---|
| 78 | + */ |
---|
| 79 | + state = lpi->address; |
---|
| 80 | + if (!psci_power_state_is_valid(state)) { |
---|
| 81 | + pr_warn("Invalid PSCI power state %#x\n", state); |
---|
| 82 | + return -EINVAL; |
---|
| 83 | + } |
---|
| 84 | + } |
---|
| 85 | + |
---|
| 86 | + return 0; |
---|
| 87 | +} |
---|
| 88 | + |
---|
53 | 89 | int acpi_processor_ffh_lpi_probe(unsigned int cpu) |
---|
54 | 90 | { |
---|
55 | | - return arm_cpuidle_init(cpu); |
---|
| 91 | + return psci_acpi_cpu_init_idle(cpu); |
---|
56 | 92 | } |
---|
57 | 93 | |
---|
58 | 94 | int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi) |
---|
59 | 95 | { |
---|
| 96 | + u32 state = lpi->address; |
---|
| 97 | + |
---|
60 | 98 | if (ARM64_LPI_IS_RETENTION_STATE(lpi->arch_flags)) |
---|
61 | | - return CPU_PM_CPU_IDLE_ENTER_RETENTION(arm_cpuidle_suspend, |
---|
62 | | - lpi->index); |
---|
| 99 | + return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(psci_cpu_suspend_enter, |
---|
| 100 | + lpi->index, state); |
---|
63 | 101 | else |
---|
64 | | - return CPU_PM_CPU_IDLE_ENTER(arm_cpuidle_suspend, lpi->index); |
---|
| 102 | + return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter, |
---|
| 103 | + lpi->index, state); |
---|
65 | 104 | } |
---|
66 | 105 | #endif |
---|