UPSTREAM: coresight: etmv4: Fix CPU power management setup in probe() function
The current probe() function calls a pair of cpuhp_xxx API functions to
setup CPU hotplug handling. The hotplug lock is held for the duration of
the two calls and other CPU related code using cpus_read_lock() /
cpus_read_unlock() calls.
The problem is that on error states, goto: statements bypass the
cpus_read_unlock() call. This code has increased in complexity as the
driver has developed.
This patch introduces a pair of helper functions etm4_pm_setup_cpuslocked()
and etm4_pm_clear() which correct the issues above and group the PM code a
little better.
The two functions etm4_cpu_pm_register() and etm4_cpu_pm_unregister() are
dropped as these call cpu_pm_register_notifier() / ..unregister_notifier()
dependent on CONFIG_CPU_PM - but this define is used to nop these functions
out in the pm headers - so the wrapper functions are superfluous.
Bug: 254441685
Fixes: f188b5e76aae ("coresight: etm4x: Save/restore state across CPU low power states")
Fixes: e9f5d63f84 ("hwtracing/coresight-etm4x: Use cpuhp_setup_state_nocalls_cpuslocked()")
Fixes: 58eb457be0 ("hwtracing/coresight-etm4x: Convert to hotplug state machine")
Signed-off-by: Mike Leach <mike.leach@linaro.org>
Cc: stable <stable@vger.kernel.org>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Link: https://lore.kernel.org/r/20200701160852.2782823-3-mathieu.poirier@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 9b6a3f3633a5cc928b78627764793b60cb62e0f6)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: Id0f8c17c0fa622cbb7f131010ed6a35eb4edb5a1
This commit is contained in:
@@ -1369,18 +1369,57 @@ static struct notifier_block etm4_cpu_pm_nb = {
|
|||||||
.notifier_call = etm4_cpu_pm_notify,
|
.notifier_call = etm4_cpu_pm_notify,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int etm4_cpu_pm_register(void)
|
/* Setup PM. Called with cpus locked. Deals with error conditions and counts */
|
||||||
|
static int etm4_pm_setup_cpuslocked(void)
|
||||||
{
|
{
|
||||||
if (IS_ENABLED(CONFIG_CPU_PM))
|
int ret;
|
||||||
return cpu_pm_register_notifier(&etm4_cpu_pm_nb);
|
|
||||||
|
|
||||||
|
if (etm4_count++)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ret = cpu_pm_register_notifier(&etm4_cpu_pm_nb);
|
||||||
|
if (ret)
|
||||||
|
goto reduce_count;
|
||||||
|
|
||||||
|
ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING,
|
||||||
|
"arm/coresight4:starting",
|
||||||
|
etm4_starting_cpu, etm4_dying_cpu);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
goto unregister_notifier;
|
||||||
|
|
||||||
|
ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN,
|
||||||
|
"arm/coresight4:online",
|
||||||
|
etm4_online_cpu, NULL);
|
||||||
|
|
||||||
|
/* HP dyn state ID returned in ret on success */
|
||||||
|
if (ret > 0) {
|
||||||
|
hp_online = ret;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void etm4_cpu_pm_unregister(void)
|
/* failed dyn state - remove others */
|
||||||
{
|
cpuhp_remove_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING);
|
||||||
if (IS_ENABLED(CONFIG_CPU_PM))
|
|
||||||
|
unregister_notifier:
|
||||||
cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
|
cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
|
||||||
|
|
||||||
|
reduce_count:
|
||||||
|
--etm4_count;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void etm4_pm_clear(void)
|
||||||
|
{
|
||||||
|
if (--etm4_count != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cpu_pm_unregister_notifier(&etm4_cpu_pm_nb);
|
||||||
|
cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
|
||||||
|
if (hp_online) {
|
||||||
|
cpuhp_remove_state_nocalls(hp_online);
|
||||||
|
hp_online = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
|
static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
|
||||||
@@ -1437,24 +1476,15 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
|
|||||||
etm4_init_arch_data, drvdata, 1))
|
etm4_init_arch_data, drvdata, 1))
|
||||||
dev_err(dev, "ETM arch init failed\n");
|
dev_err(dev, "ETM arch init failed\n");
|
||||||
|
|
||||||
if (!etm4_count++) {
|
ret = etm4_pm_setup_cpuslocked();
|
||||||
cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ARM_CORESIGHT_STARTING,
|
|
||||||
"arm/coresight4:starting",
|
|
||||||
etm4_starting_cpu, etm4_dying_cpu);
|
|
||||||
ret = cpuhp_setup_state_nocalls_cpuslocked(CPUHP_AP_ONLINE_DYN,
|
|
||||||
"arm/coresight4:online",
|
|
||||||
etm4_online_cpu, NULL);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err_arch_supported;
|
|
||||||
hp_online = ret;
|
|
||||||
|
|
||||||
ret = etm4_cpu_pm_register();
|
|
||||||
if (ret)
|
|
||||||
goto err_arch_supported;
|
|
||||||
}
|
|
||||||
|
|
||||||
cpus_read_unlock();
|
cpus_read_unlock();
|
||||||
|
|
||||||
|
/* etm4_pm_setup_cpuslocked() does its own cleanup - exit on error */
|
||||||
|
if (ret) {
|
||||||
|
etmdrvdata[drvdata->cpu] = NULL;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (etm4_arch_supported(drvdata->arch) == false) {
|
if (etm4_arch_supported(drvdata->arch) == false) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto err_arch_supported;
|
goto err_arch_supported;
|
||||||
@@ -1494,13 +1524,7 @@ static int etm4_probe(struct amba_device *adev, const struct amba_id *id)
|
|||||||
|
|
||||||
err_arch_supported:
|
err_arch_supported:
|
||||||
etmdrvdata[drvdata->cpu] = NULL;
|
etmdrvdata[drvdata->cpu] = NULL;
|
||||||
if (--etm4_count == 0) {
|
etm4_pm_clear();
|
||||||
etm4_cpu_pm_unregister();
|
|
||||||
|
|
||||||
cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
|
|
||||||
if (hp_online)
|
|
||||||
cpuhp_remove_state_nocalls(hp_online);
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user