| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* ARM64 CPU idle arch support |
| 4 |
* |
| 5 |
* Copyright (C) 2014 ARM Ltd. |
| 6 |
* Author: Lorenzo Pieralisi <[email protected]> |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <linux/acpi.h> |
| 10 |
#include <linux/cpuidle.h> |
| 11 |
#include <linux/cpu_pm.h> |
| 12 |
#include <linux/psci.h> |
| 13 |
#include <acpi/processor.h> |
| 14 |
|
| 15 |
#define ARM64_LPI_IS_RETENTION_STATE(arch_flags) (!(arch_flags)) |
| 16 |
|
| 17 |
static int psci_acpi_cpu_init_idle(unsigned int cpu) |
| 18 |
{ |
| 19 |
int i; |
| 20 |
struct acpi_lpi_state *lpi; |
| 21 |
struct acpi_processor *pr = per_cpu(processors, cpu); |
| 22 |
|
| 23 |
if (unlikely(!pr || !pr->flags.has_lpi)) |
| 24 |
return -EINVAL; |
| 25 |
|
| 26 |
/* |
| 27 |
* If the PSCI cpu_suspend function hook has not been initialized |
| 28 |
* idle states must not be enabled, so bail out |
| 29 |
*/ |
| 30 |
if (!psci_ops.cpu_suspend) |
| 31 |
return -EOPNOTSUPP; |
| 32 |
|
| 33 |
for (i = 1; i < pr->power.count; i++) { |
| 34 |
u32 state; |
| 35 |
|
| 36 |
lpi = &pr->power.lpi_states[i]; |
| 37 |
/* |
| 38 |
* Only bits[31:0] represent a PSCI power_state while |
| 39 |
* bits[63:32] must be 0x0 as per ARM ACPI FFH Specification |
| 40 |
*/ |
| 41 |
state = lpi->address; |
| 42 |
if (!psci_power_state_is_valid(state)) { |
| 43 |
pr_warn("Invalid PSCI power state %#x\n", state); |
| 44 |
return -EINVAL; |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
return 0; |
| 49 |
} |
| 50 |
|
| 51 |
int acpi_processor_ffh_lpi_probe(unsigned int cpu) |
| 52 |
{ |
| 53 |
return psci_acpi_cpu_init_idle(cpu); |
| 54 |
} |
| 55 |
|
| 56 |
__cpuidle int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi) |
| 57 |
{ |
| 58 |
u32 state = lpi->address; |
| 59 |
|
| 60 |
if (ARM64_LPI_IS_RETENTION_STATE(lpi->arch_flags)) |
| 61 |
return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM_RCU(psci_cpu_suspend_enter, |
| 62 |
lpi->index, state); |
| 63 |
else |
| 64 |
return CPU_PM_CPU_IDLE_ENTER_PARAM_RCU(psci_cpu_suspend_enter, |
| 65 |
lpi->index, state); |
| 66 |
} |