@@ -56,16 +56,19 @@ static int psci_enter_domain_idle_state(struct cpuidle_device *dev,
u32 *states = data->psci_states;
struct device *pd_dev = data->dev;
u32 state;
- int ret;
+ int ret = 0;
/* Do runtime PM to manage a hierarchical CPU toplogy. */
pm_runtime_put_sync_suspend(pd_dev);
state = psci_get_domain_state();
- if (!state)
+ if (!state && states)
state = states[idx];
- ret = psci_enter_state(idx, state);
+ if (state)
+ ret = psci_cpu_suspend_enter(state);
+ else
+ cpu_do_idle();
pm_runtime_get_sync(pd_dev);
@@ -181,6 +184,7 @@ static int __init psci_dt_cpu_init_topology(struct cpuidle_driver *drv,
drv->states[state_count - 1].enter =
psci_enter_domain_idle_state;
psci_cpuidle_use_cpuhp = true;
+ return 1;
}
return 0;
@@ -195,6 +199,13 @@ static int __init psci_dt_cpu_init_idle(struct cpuidle_driver *drv,
struct device_node *state_node;
struct psci_cpuidle_data *data = per_cpu_ptr(&psci_cpuidle_data, cpu);
+ /*
+ * Special case when WFI is the only state, as we may still need to
+ * initialize data, if the hierarchical topology is used.
+ */
+ if (!state_count)
+ return psci_dt_cpu_init_topology(drv, data, 1, cpu);
+
state_count++; /* Add WFI state too */
psci_states = kcalloc(state_count, sizeof(*psci_states), GFP_KERNEL);
if (!psci_states)
@@ -226,7 +237,7 @@ static int __init psci_dt_cpu_init_idle(struct cpuidle_driver *drv,
/* Idle states parsed correctly, store them in the per-cpu struct. */
data->psci_states = psci_states;
- return 0;
+ return state_count;
free_mem:
kfree(psci_states);
@@ -285,33 +296,35 @@ static int __init psci_idle_init_cpu(int cpu)
return -ENOMEM;
drv->cpumask = (struct cpumask *)cpumask_of(cpu);
+ drv->state_count = 1;
/*
- * Initialize idle states data, starting at index 1, since
- * by default idle state 0 is the quiescent state reached
- * by the cpu by executing the wfi instruction.
- *
- * If no DT idle states are detected (ret == 0) let the driver
- * initialization fail accordingly since there is no reason to
- * initialize the idle driver if only wfi is supported, the
- * default archictectural back-end already executes wfi
- * on idle entry.
+ * Initialize idle states data, starting at index 1, since by default
+ * idle state 0 is the quiescent state reached by the cpu by executing
+ * the wfi instruction. If no DT idle states are detected (ret == 0),
+ * we may still use the hierarchical topology.
*/
ret = dt_init_idle_driver(drv, psci_idle_state_match, 1);
- if (ret <= 0) {
- ret = ret ? : -ENODEV;
+ if (ret < 0)
goto out_kfree_drv;
- }
/*
* Initialize PSCI idle states.
*/
ret = psci_cpu_init_idle(drv, cpu, ret);
- if (ret) {
+ if (ret < 0) {
pr_err("CPU %d failed to PSCI idle\n", cpu);
goto out_kfree_drv;
}
+ /* If there are no idle states to manage, but the wfi state and we also
+ * don't use the hierarchical topology, let the driver initialization
+ * fail. Instead, let's rely on the default architectural back-end to
+ * execute wfi on idle entry.
+ */
+ if (!ret)
+ goto out_kfree_drv;
+
ret = cpuidle_register(drv, NULL);
if (ret)
goto out_kfree_drv;
It's possible that only the WFI state is supported for the CPU, while also a shared idle state exists for a group of CPUs. When the hierarchical topology is used, the shared idle state may not be compatible with arm,idle-state, rather with "domain-idle-state", which makes dt_init_idle_driver() to return zero. This leads to that the cpuidle-psci driver bails out during initialization, avoiding to register a cpuidle driver and instead relies on the default architectural back-end (called via cpu_do_idle()). In other words, the shared idle state becomes unused. Let's fix this behaviour, by allowing the dt_init_idle_driver() to return 0 and then continue with the initialization. If it turns out that the hierarchical topology is used and we have some additional states to manage, then continue with the cpuidle driver registration, otherwise bail out, as we did before. Reported-by: Benjamin Gaignard <benjamin.gaignard@st.com> Fixes: a65a397f2451 ("cpuidle: psci: Add support for PM domains by using genpd") Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> --- drivers/cpuidle/cpuidle-psci.c | 47 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-) -- 2.20.1