Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * ARM64 CPU idle arch support
0004  *
0005  * Copyright (C) 2014 ARM Ltd.
0006  * Author: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
0007  */
0008 
0009 #include <linux/acpi.h>
0010 #include <linux/cpuidle.h>
0011 #include <linux/cpu_pm.h>
0012 #include <linux/of.h>
0013 #include <linux/of_device.h>
0014 #include <linux/psci.h>
0015 
0016 #ifdef CONFIG_ACPI
0017 
0018 #include <acpi/processor.h>
0019 
0020 #define ARM64_LPI_IS_RETENTION_STATE(arch_flags) (!(arch_flags))
0021 
0022 static int psci_acpi_cpu_init_idle(unsigned int cpu)
0023 {
0024     int i, count;
0025     struct acpi_lpi_state *lpi;
0026     struct acpi_processor *pr = per_cpu(processors, cpu);
0027 
0028     if (unlikely(!pr || !pr->flags.has_lpi))
0029         return -EINVAL;
0030 
0031     /*
0032      * If the PSCI cpu_suspend function hook has not been initialized
0033      * idle states must not be enabled, so bail out
0034      */
0035     if (!psci_ops.cpu_suspend)
0036         return -EOPNOTSUPP;
0037 
0038     count = pr->power.count - 1;
0039     if (count <= 0)
0040         return -ENODEV;
0041 
0042     for (i = 0; i < count; i++) {
0043         u32 state;
0044 
0045         lpi = &pr->power.lpi_states[i + 1];
0046         /*
0047          * Only bits[31:0] represent a PSCI power_state while
0048          * bits[63:32] must be 0x0 as per ARM ACPI FFH Specification
0049          */
0050         state = lpi->address;
0051         if (!psci_power_state_is_valid(state)) {
0052             pr_warn("Invalid PSCI power state %#x\n", state);
0053             return -EINVAL;
0054         }
0055     }
0056 
0057     return 0;
0058 }
0059 
0060 int acpi_processor_ffh_lpi_probe(unsigned int cpu)
0061 {
0062     return psci_acpi_cpu_init_idle(cpu);
0063 }
0064 
0065 int acpi_processor_ffh_lpi_enter(struct acpi_lpi_state *lpi)
0066 {
0067     u32 state = lpi->address;
0068 
0069     if (ARM64_LPI_IS_RETENTION_STATE(lpi->arch_flags))
0070         return CPU_PM_CPU_IDLE_ENTER_RETENTION_PARAM(psci_cpu_suspend_enter,
0071                         lpi->index, state);
0072     else
0073         return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter,
0074                          lpi->index, state);
0075 }
0076 #endif