linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] soc: qcom: rpmhpd: Use highest corner until sync_state
@ 2022-09-15 20:55 Bjorn Andersson
  2022-10-18  3:06 ` Bjorn Andersson
  0 siblings, 1 reply; 6+ messages in thread
From: Bjorn Andersson @ 2022-09-15 20:55 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio; +Cc: linux-arm-msm, linux-kernel

From: Bjorn Andersson <bjorn.andersson@linaro.org>

In some cases the hardware that the bootloader has left configured
depends on RPMH power domains for their operation up until the point
where the related Linux device driver probes and can inherit that
configuration, or power down the hardware gracefully.

Unfortunately as Linux probes the releavant drivers in sequence there
are periods during the Linux boot flow where either the genpd refcount
will reach 0, or worse where the active performance_state votes does not
meet the requirements of the state that the hardware was left in.

One specific example of this is during boot of e.g. SM8150/SC8180X,
where the display clock controller probes, without any particular
performance state needs (to access its registers). This will drop the
MMCX rail to MIN_SVS, which isn't sufficient to sustain the clock rates
that the later probing MDP is configured to. This results in an
unrecoverable system state.

Handle both these cases by keeping the RPMH power-domais that are
referenced voted for highest state, until sync_state indicates that all
devices referencing the RPMH power-domain driver has been probed.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Reviewed-by: Caleb Connolly <caleb@connolly.tech>
Reviewed-by: Konrad Dybcio <konrad.dybcio@somainline.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
[bjorn: Added print for sync_state errors]
Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com>
---
 drivers/soc/qcom/rpmhpd.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/qcom/rpmhpd.c b/drivers/soc/qcom/rpmhpd.c
index 092f6ab09acf..5f9b71588eda 100644
--- a/drivers/soc/qcom/rpmhpd.c
+++ b/drivers/soc/qcom/rpmhpd.c
@@ -39,6 +39,7 @@
  * @res_name:		Resource name used for cmd-db lookup
  * @addr:		Resource address as looped up using resource name from
  *			cmd-db
+ * @state_synced:	Indicator that sync_state has been invoked for the rpmhpd resource
  */
 struct rpmhpd {
 	struct device	*dev;
@@ -54,6 +55,7 @@ struct rpmhpd {
 	bool		enabled;
 	const char	*res_name;
 	u32		addr;
+	bool		state_synced;
 };
 
 struct rpmhpd_desc {
@@ -493,7 +495,13 @@ static int rpmhpd_aggregate_corner(struct rpmhpd *pd, unsigned int corner)
 	unsigned int this_active_corner = 0, this_sleep_corner = 0;
 	unsigned int peer_active_corner = 0, peer_sleep_corner = 0;
 
-	to_active_sleep(pd, corner, &this_active_corner, &this_sleep_corner);
+	if (pd->state_synced) {
+		to_active_sleep(pd, corner, &this_active_corner, &this_sleep_corner);
+	} else {
+		/* Clamp to highest corner if sync_state hasn't happened */
+		this_active_corner = pd->level_count - 1;
+		this_sleep_corner = pd->level_count - 1;
+	}
 
 	if (peer && peer->enabled)
 		to_active_sleep(peer, peer->corner, &peer_active_corner,
@@ -708,11 +716,40 @@ static int rpmhpd_probe(struct platform_device *pdev)
 	return of_genpd_add_provider_onecell(pdev->dev.of_node, data);
 }
 
+static void rpmhpd_sync_state(struct device *dev)
+{
+	const struct rpmhpd_desc *desc = of_device_get_match_data(dev);
+	struct rpmhpd **rpmhpds = desc->rpmhpds;
+	unsigned int corner;
+	struct rpmhpd *pd;
+	unsigned int i;
+	int ret;
+
+	mutex_lock(&rpmhpd_lock);
+	for (i = 0; i < desc->num_pds; i++) {
+		pd = rpmhpds[i];
+		if (!pd)
+			continue;
+
+		pd->state_synced = true;
+		if (pd->enabled)
+			corner = max(pd->corner, pd->enable_corner);
+		else
+			corner = 0;
+
+		ret = rpmhpd_aggregate_corner(pd, corner);
+		if (ret)
+			dev_err(dev, "failed to sync %s\n", pd->res_name);
+	}
+	mutex_unlock(&rpmhpd_lock);
+}
+
 static struct platform_driver rpmhpd_driver = {
 	.driver = {
 		.name = "qcom-rpmhpd",
 		.of_match_table = rpmhpd_match_table,
 		.suppress_bind_attrs = true,
+		.sync_state = rpmhpd_sync_state,
 	},
 	.probe = rpmhpd_probe,
 };
-- 
2.17.1


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

* Re: [PATCH v2] soc: qcom: rpmhpd: Use highest corner until sync_state
  2022-09-15 20:55 [PATCH v2] soc: qcom: rpmhpd: Use highest corner until sync_state Bjorn Andersson
@ 2022-10-18  3:06 ` Bjorn Andersson
  2022-10-18  3:11   ` Bjorn Andersson
                     ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Bjorn Andersson @ 2022-10-18  3:06 UTC (permalink / raw)
  To: quic_bjorande, agross, Konrad Dybcio; +Cc: linux-arm-msm, linux-kernel

On Thu, 15 Sep 2022 13:55:59 -0700, Bjorn Andersson wrote:
> From: Bjorn Andersson <bjorn.andersson@linaro.org>
> 
> In some cases the hardware that the bootloader has left configured
> depends on RPMH power domains for their operation up until the point
> where the related Linux device driver probes and can inherit that
> configuration, or power down the hardware gracefully.
> 
> [...]

Applied, thanks!

[1/1] soc: qcom: rpmhpd: Use highest corner until sync_state
      commit: 3a39049f88e4e92823bcc43fa8f148cf7dfdda67

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

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

* Re: [PATCH v2] soc: qcom: rpmhpd: Use highest corner until sync_state
  2022-10-18  3:06 ` Bjorn Andersson
@ 2022-10-18  3:11   ` Bjorn Andersson
  2022-10-18  3:12   ` Bjorn Andersson
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Bjorn Andersson @ 2022-10-18  3:11 UTC (permalink / raw)
  To: quic_bjorande, agross, Konrad Dybcio; +Cc: linux-arm-msm, linux-kernel

On Thu, 15 Sep 2022 13:55:59 -0700, Bjorn Andersson wrote:
> From: Bjorn Andersson <bjorn.andersson@linaro.org>
> 
> In some cases the hardware that the bootloader has left configured
> depends on RPMH power domains for their operation up until the point
> where the related Linux device driver probes and can inherit that
> configuration, or power down the hardware gracefully.
> 
> [...]

Applied, thanks!

[1/1] soc: qcom: rpmhpd: Use highest corner until sync_state
      commit: 3a39049f88e4e92823bcc43fa8f148cf7dfdda67

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

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

* Re: [PATCH v2] soc: qcom: rpmhpd: Use highest corner until sync_state
  2022-10-18  3:06 ` Bjorn Andersson
  2022-10-18  3:11   ` Bjorn Andersson
@ 2022-10-18  3:12   ` Bjorn Andersson
  2022-10-18  3:13   ` Bjorn Andersson
  2022-10-18  3:14   ` Bjorn Andersson
  3 siblings, 0 replies; 6+ messages in thread
From: Bjorn Andersson @ 2022-10-18  3:12 UTC (permalink / raw)
  To: quic_bjorande, agross, Konrad Dybcio; +Cc: linux-arm-msm, linux-kernel

On Thu, 15 Sep 2022 13:55:59 -0700, Bjorn Andersson wrote:
> From: Bjorn Andersson <bjorn.andersson@linaro.org>
> 
> In some cases the hardware that the bootloader has left configured
> depends on RPMH power domains for their operation up until the point
> where the related Linux device driver probes and can inherit that
> configuration, or power down the hardware gracefully.
> 
> [...]

Applied, thanks!

[1/1] soc: qcom: rpmhpd: Use highest corner until sync_state
      commit: 3a39049f88e4e92823bcc43fa8f148cf7dfdda67

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

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

* Re: [PATCH v2] soc: qcom: rpmhpd: Use highest corner until sync_state
  2022-10-18  3:06 ` Bjorn Andersson
  2022-10-18  3:11   ` Bjorn Andersson
  2022-10-18  3:12   ` Bjorn Andersson
@ 2022-10-18  3:13   ` Bjorn Andersson
  2022-10-18  3:14   ` Bjorn Andersson
  3 siblings, 0 replies; 6+ messages in thread
From: Bjorn Andersson @ 2022-10-18  3:13 UTC (permalink / raw)
  To: quic_bjorande, agross, Konrad Dybcio; +Cc: linux-arm-msm, linux-kernel

On Thu, 15 Sep 2022 13:55:59 -0700, Bjorn Andersson wrote:
> From: Bjorn Andersson <bjorn.andersson@linaro.org>
> 
> In some cases the hardware that the bootloader has left configured
> depends on RPMH power domains for their operation up until the point
> where the related Linux device driver probes and can inherit that
> configuration, or power down the hardware gracefully.
> 
> [...]

Applied, thanks!

[1/1] soc: qcom: rpmhpd: Use highest corner until sync_state
      commit: 3a39049f88e4e92823bcc43fa8f148cf7dfdda67

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

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

* Re: [PATCH v2] soc: qcom: rpmhpd: Use highest corner until sync_state
  2022-10-18  3:06 ` Bjorn Andersson
                     ` (2 preceding siblings ...)
  2022-10-18  3:13   ` Bjorn Andersson
@ 2022-10-18  3:14   ` Bjorn Andersson
  3 siblings, 0 replies; 6+ messages in thread
From: Bjorn Andersson @ 2022-10-18  3:14 UTC (permalink / raw)
  To: quic_bjorande, agross, Konrad Dybcio; +Cc: linux-arm-msm, linux-kernel

On Thu, 15 Sep 2022 13:55:59 -0700, Bjorn Andersson wrote:
> From: Bjorn Andersson <bjorn.andersson@linaro.org>
> 
> In some cases the hardware that the bootloader has left configured
> depends on RPMH power domains for their operation up until the point
> where the related Linux device driver probes and can inherit that
> configuration, or power down the hardware gracefully.
> 
> [...]

Applied, thanks!

[1/1] soc: qcom: rpmhpd: Use highest corner until sync_state
      commit: 3a39049f88e4e92823bcc43fa8f148cf7dfdda67

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

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

end of thread, other threads:[~2022-10-18  3:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-15 20:55 [PATCH v2] soc: qcom: rpmhpd: Use highest corner until sync_state Bjorn Andersson
2022-10-18  3:06 ` Bjorn Andersson
2022-10-18  3:11   ` Bjorn Andersson
2022-10-18  3:12   ` Bjorn Andersson
2022-10-18  3:13   ` Bjorn Andersson
2022-10-18  3:14   ` Bjorn Andersson

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).