linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] cpuidle: psci: Always create the PM domains
@ 2020-09-01 14:28 Ulf Hansson
  2020-09-01 14:28 ` [PATCH v3 1/2] firmware: psci: Extend psci_set_osi_mode() to allow reset to PC mode Ulf Hansson
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Ulf Hansson @ 2020-09-01 14:28 UTC (permalink / raw)
  To: Sudeep Holla, Lorenzo Pieralisi, linux-pm
  Cc: Rafael J . Wysocki, Daniel Lezcano, Mark Rutland, Lina Iyer,
	Lukasz Luba, Vincent Guittot, Stephen Boyd, Bjorn Andersson,
	Benjamin Gaignard, Ulf Hansson, linux-arm-kernel

This coverletter is mainly to help keeping track of the patches part in the
series. Please have a look at each patch for more details.

Kind regards
Ulf Hansson


Ulf Hansson (2):
  firmware: psci: Extend psci_set_osi_mode() to allow reset to PC mode
  cpuidle: psci: Allow PM domain to be initialized even if no OSI mode

 drivers/cpuidle/cpuidle-psci-domain.c | 59 ++++++++++++++-------------
 drivers/firmware/psci/psci.c          | 12 +++---
 include/linux/psci.h                  |  2 +-
 3 files changed, 39 insertions(+), 34 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/2] firmware: psci: Extend psci_set_osi_mode() to allow reset to PC mode
  2020-09-01 14:28 [PATCH v3 0/2] cpuidle: psci: Always create the PM domains Ulf Hansson
@ 2020-09-01 14:28 ` Ulf Hansson
  2020-09-01 14:28 ` [PATCH v3 2/2] cpuidle: psci: Allow PM domain to be initialized even if no OSI mode Ulf Hansson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2020-09-01 14:28 UTC (permalink / raw)
  To: Sudeep Holla, Lorenzo Pieralisi, linux-pm
  Cc: Rafael J . Wysocki, Daniel Lezcano, Mark Rutland, Lina Iyer,
	Lukasz Luba, Vincent Guittot, Stephen Boyd, Bjorn Andersson,
	Benjamin Gaignard, Ulf Hansson, linux-arm-kernel

The current user (cpuidle-psci) of psci_set_osi_mode() only needs to enable
the PSCI OSI mode. Although, as subsequent changes shows, there is a need
to be able to reset back into the PSCI PC mode.

Therefore, let's extend psci_set_osi_mode() to take a bool as in-parameter,
to let the user indicate whether to enable OSI or to switch back to PC
mode.

Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---

Changes in v3:
	- Added reviewed-by tag.

---
 drivers/cpuidle/cpuidle-psci-domain.c |  2 +-
 drivers/firmware/psci/psci.c          | 12 +++++++-----
 include/linux/psci.h                  |  2 +-
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c
index b6e9649ab0da..b6ab0415f450 100644
--- a/drivers/cpuidle/cpuidle-psci-domain.c
+++ b/drivers/cpuidle/cpuidle-psci-domain.c
@@ -278,7 +278,7 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev)
 		goto remove_pd;
 
 	/* Try to enable OSI mode. */
-	ret = psci_set_osi_mode();
+	ret = psci_set_osi_mode(true);
 	if (ret) {
 		pr_warn("failed to enable OSI mode: %d\n", ret);
 		psci_pd_remove_topology(np);
diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c
index 92013ecc2d9e..00af99b6f97c 100644
--- a/drivers/firmware/psci/psci.c
+++ b/drivers/firmware/psci/psci.c
@@ -151,12 +151,15 @@ static u32 psci_get_version(void)
 	return invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0);
 }
 
-int psci_set_osi_mode(void)
+int psci_set_osi_mode(bool enable)
 {
+	unsigned long suspend_mode;
 	int err;
 
-	err = invoke_psci_fn(PSCI_1_0_FN_SET_SUSPEND_MODE,
-			     PSCI_1_0_SUSPEND_MODE_OSI, 0, 0);
+	suspend_mode = enable ? PSCI_1_0_SUSPEND_MODE_OSI :
+			PSCI_1_0_SUSPEND_MODE_PC;
+
+	err = invoke_psci_fn(PSCI_1_0_FN_SET_SUSPEND_MODE, suspend_mode, 0, 0);
 	return psci_to_linux_errno(err);
 }
 
@@ -546,8 +549,7 @@ static int __init psci_1_0_init(struct device_node *np)
 		pr_info("OSI mode supported.\n");
 
 		/* Default to PC mode. */
-		invoke_psci_fn(PSCI_1_0_FN_SET_SUSPEND_MODE,
-			       PSCI_1_0_SUSPEND_MODE_PC, 0, 0);
+		psci_set_osi_mode(false);
 	}
 
 	return 0;
diff --git a/include/linux/psci.h b/include/linux/psci.h
index 14ad9b9ebcd6..2a1bfb890e58 100644
--- a/include/linux/psci.h
+++ b/include/linux/psci.h
@@ -18,7 +18,7 @@ bool psci_tos_resident_on(int cpu);
 
 int psci_cpu_suspend_enter(u32 state);
 bool psci_power_state_is_valid(u32 state);
-int psci_set_osi_mode(void);
+int psci_set_osi_mode(bool enable);
 bool psci_has_osi_support(void);
 
 struct psci_operations {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 2/2] cpuidle: psci: Allow PM domain to be initialized even if no OSI mode
  2020-09-01 14:28 [PATCH v3 0/2] cpuidle: psci: Always create the PM domains Ulf Hansson
  2020-09-01 14:28 ` [PATCH v3 1/2] firmware: psci: Extend psci_set_osi_mode() to allow reset to PC mode Ulf Hansson
@ 2020-09-01 14:28 ` Ulf Hansson
  2020-09-02  9:21 ` [PATCH v3 0/2] cpuidle: psci: Always create the PM domains Ulf Hansson
  2020-09-22  7:51 ` Ulf Hansson
  3 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2020-09-01 14:28 UTC (permalink / raw)
  To: Sudeep Holla, Lorenzo Pieralisi, linux-pm
  Cc: Rafael J . Wysocki, Daniel Lezcano, Mark Rutland, Lina Iyer,
	Lukasz Luba, Vincent Guittot, Stephen Boyd, Bjorn Andersson,
	Benjamin Gaignard, Ulf Hansson, linux-arm-kernel

If the PSCI OSI mode isn't supported or fails to be enabled, the PM domain
topology with the genpd providers isn't initialized. This is perfectly fine
from cpuidle-psci point of view.

However, since the PM domain topology in the DTS files is a description of
the HW, no matter of whether the PSCI OSI mode is supported or not, other
consumers besides the CPUs may rely on it.

Therefore, let's always allow the initialization of the PM domain topology
to succeed, independently of whether the PSCI OSI mode is supported.
Consequentially we need to track if we succeed to enable the OSI mode, as
to know when a domain idlestate can be selected.

Note that, CPU devices are still not being attached to the PM domain
topology, unless the PSCI OSI mode is supported.

Acked-by: Sudeep Holla <sudeep.holla@arm.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---

Changes in v3:
	- Added acked-by tag.
	- Use GENPD_FLAG_ALWAYS_ON to prevent power off, unless OSI has been
	successfully enabled.

---
 drivers/cpuidle/cpuidle-psci-domain.c | 59 ++++++++++++++-------------
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c
index b6ab0415f450..4a031c62f92a 100644
--- a/drivers/cpuidle/cpuidle-psci-domain.c
+++ b/drivers/cpuidle/cpuidle-psci-domain.c
@@ -105,7 +105,7 @@ static void psci_pd_free_states(struct genpd_power_state *states,
 	kfree(states);
 }
 
-static int psci_pd_init(struct device_node *np)
+static int psci_pd_init(struct device_node *np, bool use_osi)
 {
 	struct generic_pm_domain *pd;
 	struct psci_pd_provider *pd_provider;
@@ -135,11 +135,16 @@ static int psci_pd_init(struct device_node *np)
 
 	pd->free_states = psci_pd_free_states;
 	pd->name = kbasename(pd->name);
-	pd->power_off = psci_pd_power_off;
 	pd->states = states;
 	pd->state_count = state_count;
 	pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN;
 
+	/* Allow power off when OSI has been successfully enabled. */
+	if (use_osi)
+		pd->power_off = psci_pd_power_off;
+	else
+		pd->flags |= GENPD_FLAG_ALWAYS_ON;
+
 	/* Use governor for CPU PM domains if it has some states to manage. */
 	pd_gov = state_count > 0 ? &pm_domain_cpu_gov : NULL;
 
@@ -190,7 +195,7 @@ static void psci_pd_remove(void)
 	}
 }
 
-static int psci_pd_init_topology(struct device_node *np, bool add)
+static int psci_pd_init_topology(struct device_node *np)
 {
 	struct device_node *node;
 	struct of_phandle_args child, parent;
@@ -203,9 +208,7 @@ static int psci_pd_init_topology(struct device_node *np, bool add)
 
 		child.np = node;
 		child.args_count = 0;
-
-		ret = add ? of_genpd_add_subdomain(&parent, &child) :
-			of_genpd_remove_subdomain(&parent, &child);
+		ret = of_genpd_add_subdomain(&parent, &child);
 		of_node_put(parent.np);
 		if (ret) {
 			of_node_put(node);
@@ -216,14 +219,20 @@ static int psci_pd_init_topology(struct device_node *np, bool add)
 	return 0;
 }
 
-static int psci_pd_add_topology(struct device_node *np)
+static bool psci_pd_try_set_osi_mode(void)
 {
-	return psci_pd_init_topology(np, true);
-}
+	int ret;
 
-static void psci_pd_remove_topology(struct device_node *np)
-{
-	psci_pd_init_topology(np, false);
+	if (!psci_has_osi_support())
+		return false;
+
+	ret = psci_set_osi_mode(true);
+	if (ret) {
+		pr_warn("failed to enable OSI mode: %d\n", ret);
+		return false;
+	}
+
+	return true;
 }
 
 static void psci_cpuidle_domain_sync_state(struct device *dev)
@@ -244,14 +253,14 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
 	struct device_node *node;
+	bool use_osi;
 	int ret = 0, pd_count = 0;
 
 	if (!np)
 		return -ENODEV;
 
-	/* Currently limit the hierarchical topology to be used in OSI mode. */
-	if (!psci_has_osi_support())
-		return 0;
+	/* If OSI mode is supported, let's try to enable it. */
+	use_osi = psci_pd_try_set_osi_mode();
 
 	/*
 	 * Parse child nodes for the "#power-domain-cells" property and
@@ -261,7 +270,7 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev)
 		if (!of_find_property(node, "#power-domain-cells", NULL))
 			continue;
 
-		ret = psci_pd_init(node);
+		ret = psci_pd_init(node, use_osi);
 		if (ret)
 			goto put_node;
 
@@ -270,30 +279,24 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev)
 
 	/* Bail out if not using the hierarchical CPU topology. */
 	if (!pd_count)
-		return 0;
+		goto no_pd;
 
 	/* Link genpd masters/subdomains to model the CPU topology. */
-	ret = psci_pd_add_topology(np);
+	ret = psci_pd_init_topology(np);
 	if (ret)
 		goto remove_pd;
 
-	/* Try to enable OSI mode. */
-	ret = psci_set_osi_mode(true);
-	if (ret) {
-		pr_warn("failed to enable OSI mode: %d\n", ret);
-		psci_pd_remove_topology(np);
-		goto remove_pd;
-	}
-
 	pr_info("Initialized CPU PM domain topology\n");
 	return 0;
 
 put_node:
 	of_node_put(node);
 remove_pd:
-	if (pd_count)
-		psci_pd_remove();
+	psci_pd_remove();
 	pr_err("failed to create CPU PM domains ret=%d\n", ret);
+no_pd:
+	if (use_osi)
+		psci_set_osi_mode(false);
 	return ret;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/2] cpuidle: psci: Always create the PM domains
  2020-09-01 14:28 [PATCH v3 0/2] cpuidle: psci: Always create the PM domains Ulf Hansson
  2020-09-01 14:28 ` [PATCH v3 1/2] firmware: psci: Extend psci_set_osi_mode() to allow reset to PC mode Ulf Hansson
  2020-09-01 14:28 ` [PATCH v3 2/2] cpuidle: psci: Allow PM domain to be initialized even if no OSI mode Ulf Hansson
@ 2020-09-02  9:21 ` Ulf Hansson
  2020-09-22  7:51 ` Ulf Hansson
  3 siblings, 0 replies; 6+ messages in thread
From: Ulf Hansson @ 2020-09-02  9:21 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: Sudeep Holla, Linux PM, Lorenzo Pieralisi, Daniel Lezcano,
	Mark Rutland, Lina Iyer, Lukasz Luba, Vincent Guittot,
	Stephen Boyd, Bjorn Andersson, Benjamin Gaignard, Linux ARM

On Tue, 1 Sep 2020 at 16:29, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> This coverletter is mainly to help keeping track of the patches part in the
> series. Please have a look at each patch for more details.
>
> Kind regards
> Ulf Hansson
>
>
> Ulf Hansson (2):
>   firmware: psci: Extend psci_set_osi_mode() to allow reset to PC mode
>   cpuidle: psci: Allow PM domain to be initialized even if no OSI mode
>
>  drivers/cpuidle/cpuidle-psci-domain.c | 59 ++++++++++++++-------------
>  drivers/firmware/psci/psci.c          | 12 +++---
>  include/linux/psci.h                  |  2 +-
>  3 files changed, 39 insertions(+), 34 deletions(-)
>
> --
> 2.25.1
>

Rafael, I am having various small series related to cpuidle-psci
that's flying around - and it may start to become a bit confusing of
what belongs where.

Therefore, I would appreciate it if you could pick up @subject series
as soon as you can, to get this off the backlog.

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/2] cpuidle: psci: Always create the PM domains
  2020-09-01 14:28 [PATCH v3 0/2] cpuidle: psci: Always create the PM domains Ulf Hansson
                   ` (2 preceding siblings ...)
  2020-09-02  9:21 ` [PATCH v3 0/2] cpuidle: psci: Always create the PM domains Ulf Hansson
@ 2020-09-22  7:51 ` Ulf Hansson
  2020-09-22 15:52   ` Rafael J. Wysocki
  3 siblings, 1 reply; 6+ messages in thread
From: Ulf Hansson @ 2020-09-22  7:51 UTC (permalink / raw)
  To: Rafael J . Wysocki
  Cc: Linux PM, Sudeep Holla, Lorenzo Pieralisi, Daniel Lezcano,
	Mark Rutland, Lina Iyer, Lukasz Luba, Vincent Guittot,
	Stephen Boyd, Bjorn Andersson, Benjamin Gaignard, Linux ARM

On Tue, 1 Sep 2020 at 16:29, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> This coverletter is mainly to help keeping track of the patches part in the
> series. Please have a look at each patch for more details.
>
> Kind regards
> Ulf Hansson
>
>
> Ulf Hansson (2):
>   firmware: psci: Extend psci_set_osi_mode() to allow reset to PC mode
>   cpuidle: psci: Allow PM domain to be initialized even if no OSI mode
>
>  drivers/cpuidle/cpuidle-psci-domain.c | 59 ++++++++++++++-------------
>  drivers/firmware/psci/psci.c          | 12 +++---
>  include/linux/psci.h                  |  2 +-
>  3 files changed, 39 insertions(+), 34 deletions(-)
>

Rafael, I guess you may have not seen this one. I think it's ready to
get applied as v5.10 material. Do you want me to resend?

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 0/2] cpuidle: psci: Always create the PM domains
  2020-09-22  7:51 ` Ulf Hansson
@ 2020-09-22 15:52   ` Rafael J. Wysocki
  0 siblings, 0 replies; 6+ messages in thread
From: Rafael J. Wysocki @ 2020-09-22 15:52 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Rafael J . Wysocki, Linux PM, Sudeep Holla, Lorenzo Pieralisi,
	Daniel Lezcano, Mark Rutland, Lina Iyer, Lukasz Luba,
	Vincent Guittot, Stephen Boyd, Bjorn Andersson,
	Benjamin Gaignard, Linux ARM

On Tue, Sep 22, 2020 at 9:51 AM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Tue, 1 Sep 2020 at 16:29, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> >
> > This coverletter is mainly to help keeping track of the patches part in the
> > series. Please have a look at each patch for more details.
> >
> > Kind regards
> > Ulf Hansson
> >
> >
> > Ulf Hansson (2):
> >   firmware: psci: Extend psci_set_osi_mode() to allow reset to PC mode
> >   cpuidle: psci: Allow PM domain to be initialized even if no OSI mode
> >
> >  drivers/cpuidle/cpuidle-psci-domain.c | 59 ++++++++++++++-------------
> >  drivers/firmware/psci/psci.c          | 12 +++---
> >  include/linux/psci.h                  |  2 +-
> >  3 files changed, 39 insertions(+), 34 deletions(-)
> >
>
> Rafael, I guess you may have not seen this one.

I have seen it, but I didn't manage to get to it before today, sadly.

> I think it's ready to get applied as v5.10 material. Do you want me to resend?

No need, applied now.

Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-09-22 15:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-01 14:28 [PATCH v3 0/2] cpuidle: psci: Always create the PM domains Ulf Hansson
2020-09-01 14:28 ` [PATCH v3 1/2] firmware: psci: Extend psci_set_osi_mode() to allow reset to PC mode Ulf Hansson
2020-09-01 14:28 ` [PATCH v3 2/2] cpuidle: psci: Allow PM domain to be initialized even if no OSI mode Ulf Hansson
2020-09-02  9:21 ` [PATCH v3 0/2] cpuidle: psci: Always create the PM domains Ulf Hansson
2020-09-22  7:51 ` Ulf Hansson
2020-09-22 15:52   ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).