2019-06-04 08:11:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-07-17 09:30:07 +00:00
|
|
|
/*
|
|
|
|
* ARM64 CPU idle arch support
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 ARM Ltd.
|
|
|
|
* Author: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
|
|
|
|
*/
|
|
|
|
|
2016-07-19 17:52:58 +00:00
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/cpuidle.h>
|
|
|
|
#include <linux/cpu_pm.h>
|
2019-08-09 11:03:11 +00:00
|
|
|
#include <linux/psci.h>
|
2016-07-19 17:52:58 +00:00
|
|
|
#include <acpi/processor.h>
|
|
|
|
|
2017-11-15 17:11:50 +00:00
|
|
|
#define ARM64_LPI_IS_RETENTION_STATE(arch_flags) (!(arch_flags))
|
|
|
|
|
2019-08-09 11:03:12 +00:00
|
|
|
static int psci_acpi_cpu_init_idle(unsigned int cpu)
|
|
|
|
{
|
|
|
|
int i, count;
|
|
|
|
struct acpi_lpi_state *lpi;
|
|
|
|
struct acpi_processor *pr = per_cpu(processors, cpu);
|
|
|
|
|
2022-02-25 19:06:45 +00:00
|
|
|
if (unlikely(!pr || !pr->flags.has_lpi))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2019-08-09 11:03:12 +00:00
|
|
|
/*
|
|
|
|
* If the PSCI cpu_suspend function hook has not been initialized
|
|
|
|
* idle states must not be enabled, so bail out
|
|
|
|
*/
|
|
|
|
if (!psci_ops.cpu_suspend)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
count = pr->power.count - 1;
|
|
|
|
if (count <= 0)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
u32 state;
|
|
|
|
|
|
|
|
lpi = &pr->power.lpi_states[i + 1];
|
|
|
|
/*
|
|
|
|
* Only bits[31:0] represent a PSCI power_state while
|
|
|
|
* bits[63:32] must be 0x0 as per ARM ACPI FFH Specification
|
|
|
|
*/
|
|
|
|
state = lpi->address;
|
|
|
|
if (!psci_power_state_is_valid(state)) {
|
|
|
|
pr_warn("Invalid PSCI power state %#x\n", state);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-19 17:52:58 +00:00
|
|
|
int acpi_processor_ffh_lpi_probe(unsigned int cpu)
|
|
|
|
{
|
2019-08-09 11:03:12 +00:00
|
|
|
return psci_acpi_cpu_init_idle(cpu);
|
2016-07-19 17:52:58 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 19:44:02 +00:00
|
|
|
__cpuidle int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi)
|
2016-07-19 17:52:58 +00:00
|
|
|
{
|
2019-08-09 11:03:12 +00:00
|
|
|
u32 state = lpi->address;
|
|
|
|
|
2017-11-15 17:11:50 +00:00
|
|
|
if (ARM64_LPI_IS_RETENTION_STATE(lpi->arch_flags))
|
2023-01-17 10:26:29 +00:00
|
|
|
return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM_RCU(psci_cpu_suspend_enter,
|
2019-08-09 11:03:12 +00:00
|
|
|
lpi->index, state);
|
2017-11-15 17:11:50 +00:00
|
|
|
else
|
2023-01-17 10:26:29 +00:00
|
|
|
return CPU_PM_CPU_IDLE_ENTER_PARAM_RCU(psci_cpu_suspend_enter,
|
2019-08-09 11:03:12 +00:00
|
|
|
lpi->index, state);
|
2016-07-19 17:52:58 +00:00
|
|
|
}
|