cpuidle: psci: Attach CPU devices to their PM domains
authorUlf Hansson <ulf.hansson@linaro.org>
Thu, 10 Oct 2019 10:01:48 +0000 (12:01 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Thu, 2 Jan 2020 15:50:28 +0000 (16:50 +0100)
In order to enable a CPU to be power managed through its PM domain, let's
try to attach it by calling psci_dt_attach_cpu() during the cpuidle
initialization.

psci_dt_attach_cpu() returns a pointer to the attached struct device, which
later should be used for runtime PM, hence we need to store it somewhere.
Rather than adding yet another per CPU variable, let's create a per CPU
struct to collect the relevant per CPU variables.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
drivers/cpuidle/cpuidle-psci.c

index 830995b8a56f44cc3d6a5190fddcba229935284d..6a87848be3c3c7d49b54525d4268b2493a759a13 100644 (file)
 
 #include <asm/cpuidle.h>
 
+#include "cpuidle-psci.h"
 #include "dt_idle_states.h"
 
-static DEFINE_PER_CPU_READ_MOSTLY(u32 *, psci_power_state);
+struct psci_cpuidle_data {
+       u32 *psci_states;
+       struct device *dev;
+};
+
+static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data);
 
 static int psci_enter_idle_state(struct cpuidle_device *dev,
                                struct cpuidle_driver *drv, int idx)
 {
-       u32 *state = __this_cpu_read(psci_power_state);
+       u32 *state = __this_cpu_read(psci_cpuidle_data.psci_states);
 
        return CPU_PM_CPU_IDLE_ENTER_PARAM(psci_cpu_suspend_enter,
                                           idx, state[idx]);
@@ -79,6 +85,7 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node,
        int i, ret = 0;
        u32 *psci_states;
        struct device_node *state_node;
+       struct psci_cpuidle_data *data = per_cpu_ptr(&psci_cpuidle_data, cpu);
 
        state_count++; /* Add WFI state too */
        psci_states = kcalloc(state_count, sizeof(*psci_states), GFP_KERNEL);
@@ -104,8 +111,17 @@ static int __init psci_dt_cpu_init_idle(struct device_node *cpu_node,
                goto free_mem;
        }
 
-       /* Idle states parsed correctly, initialize per-cpu pointer */
-       per_cpu(psci_power_state, cpu) = psci_states;
+       /* Currently limit the hierarchical topology to be used in OSI mode. */
+       if (psci_has_osi_support()) {
+               data->dev = psci_dt_attach_cpu(cpu);
+               if (IS_ERR(data->dev)) {
+                       ret = PTR_ERR(data->dev);
+                       goto free_mem;
+               }
+       }
+
+       /* Idle states parsed correctly, store them in the per-cpu struct. */
+       data->psci_states = psci_states;
        return 0;
 
 free_mem: