Skip to contentSkip to conversation

remoteproc: qcom: Add bus scaling capability during bootup

PATCH In review Rishabh Bhatnagar 3 participants 5 messages Mar 28, 2020 – Apr 1, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 remoteproc: qcom: Add bus scaling capability during bootup

During bootup since remote processors cannot request for additional bus bandwidth from the interconect framework, platform driver should provide the proxy resources. This is useful for scenarios where the Q6 tries to access the DDR memory in the initial stages of bootup. For e.g. during bootup or after recovery modem Q6 tries to zero out the bss section in the DDR. Since this is a big chunk of memory if don't bump up the bandwidth we might encounter timeout issues. This patch makes a proxy vote for maximizing the bus bandwidth during bootup and removes it once processor is up.

---
 drivers/remoteproc/qcom_q6v5_pas.c | 43 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
drivers/remoteproc/qcom_q6v5_pas.c +42 -1
index edf9d0e..8f5db8d 100644
@@ -20,6 +20,7 @@
 #include <linux/qcom_scm.h>
 #include <linux/regulator/consumer.h>
 #include <linux/remoteproc.h>
+#include <linux/interconnect.h>
 #include <linux/soc/qcom/mdt_loader.h>
 #include <linux/soc/qcom/smem.h>
 #include <linux/soc/qcom/smem_state.h>
@@ -28,6 +29,9 @@
 #include "qcom_q6v5.h"
 #include "remoteproc_internal.h"
 
+#define PIL_TZ_AVG_BW  0
+#define PIL_TZ_PEAK_BW UINT_MAX
+
 struct adsp_data {
 	int crash_reason_smem;
 	const char *firmware_name;
@@ -62,6 +66,7 @@ struct qcom_adsp {
 	int proxy_pd_count;
 
 	int pas_id;
+	struct icc_path *bus_client;
 	int crash_reason_smem;
 	bool has_aggre2_clk;
 
@@ -124,6 +129,25 @@ static int adsp_load(struct rproc *rproc, const struct firmware *fw)
 
 }
 
+static int do_bus_scaling(struct qcom_adsp *adsp, bool enable)
+{
+	int rc;
+	u32 avg_bw = enable ? PIL_TZ_AVG_BW : 0;
+	u32 peak_bw = enable ? PIL_TZ_PEAK_BW : 0;
+
+	if (adsp->bus_client) {
+		rc = icc_set_bw(adsp->bus_client, avg_bw, peak_bw);
+		if (rc) {
+			dev_err(adsp->dev, "bandwidth request failed(rc:%d)\n",
+				rc);
+			return rc;
+		}
+	} else
+		dev_info(adsp->dev, "Bus scaling not setup for %s\n",
+			adsp->rproc->name);
+	return 0;
+}
+
 static int adsp_start(struct rproc *rproc)
 {
 	struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;
@@ -131,9 +155,13 @@ static int adsp_start(struct rproc *rproc)
 
 	qcom_q6v5_prepare(&adsp->q6v5);
 
+	ret = do_bus_scaling(adsp, true);
+	if (ret)
+		goto disable_irqs;
+
 	ret = adsp_pds_enable(adsp, adsp->active_pds, adsp->active_pd_count);
 	if (ret < 0)
-		goto disable_irqs;
+		goto unscale_bus;
 
 	ret = adsp_pds_enable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
 	if (ret < 0)
@@ -183,6 +211,8 @@ static int adsp_start(struct rproc *rproc)
 	adsp_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
 disable_active_pds:
 	adsp_pds_disable(adsp, adsp->active_pds, adsp->active_pd_count);
+unscale_bus:
+	do_bus_scaling(adsp, false);
 disable_irqs:
 	qcom_q6v5_unprepare(&adsp->q6v5);
 
@@ -198,6 +228,7 @@ static void qcom_pas_handover(struct qcom_q6v5 *q6v5)
 	clk_disable_unprepare(adsp->aggre2_clk);
 	clk_disable_unprepare(adsp->xo);
 	adsp_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
+	do_bus_scaling(adsp, false);
 }
 
 static int adsp_stop(struct rproc *rproc)
@@ -280,6 +311,14 @@ static int adsp_init_regulator(struct qcom_adsp *adsp)
 	return PTR_ERR_OR_ZERO(adsp->px_supply);
 }
 
+static void adsp_init_bus_scaling(struct qcom_adsp *adsp)
+{
+	adsp->bus_client = of_icc_get(adsp->dev, NULL);
+	if (!adsp->bus_client)
+		dev_warn(adsp->dev, "%s: unable to get bus client \n",
+			__func__);
+}
+
 static int adsp_pds_attach(struct device *dev, struct device **devs,
 			   char **pd_names)
 {
@@ -410,6 +449,8 @@ static int adsp_probe(struct platform_device *pdev)
 	if (ret)
 		goto free_rproc;
 
+	adsp_init_bus_scaling(adsp);
+
 	ret = adsp_pds_attach(&pdev->dev, adsp->active_pds,
 			      desc->active_pd_names);
 	if (ret < 0)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#1 lore raw

Hi Rishabh,

Quoted 12 lines · Rishabh Bhatnagar

During bootup since remote processors cannot request for additional bus bandwidth from the interconect framework, platform driver should provide the proxy resources. This is useful for scenarios where the Q6 tries to access the DDR memory in the initial stages of bootup. For e.g. during bootup or after recovery modem Q6 tries to zero out the bss section in the DDR. Since this is a big chunk of memory if don't bump up the bandwidth we might encounter timeout issues. This patch makes a proxy vote for maximizing the bus bandwidth during bootup and removes it once processor is up.

Quoted 1 line

The title of this patch contains "[PATCH 1/2]" but only one patch was sent to the linux-remoteproc mailing list. Is this a mistake and this is a stand alone patch or another patch did not reach the list?

Thanks,
Mathieu

Quoted 119 lines
---
 drivers/remoteproc/qcom_q6v5_pas.c | 43 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
drivers/remoteproc/qcom_q6v5_pas.c +42 -2
index edf9d0e..8f5db8d 100644
@@ -20,6 +20,7 @@
 #include <linux/qcom_scm.h>
 #include <linux/regulator/consumer.h>
 #include <linux/remoteproc.h>
+#include <linux/interconnect.h>
 #include <linux/soc/qcom/mdt_loader.h>
 #include <linux/soc/qcom/smem.h>
 #include <linux/soc/qcom/smem_state.h>
@@ -28,6 +29,9 @@
 #include "qcom_q6v5.h"
 #include "remoteproc_internal.h"
 
+#define PIL_TZ_AVG_BW  0
+#define PIL_TZ_PEAK_BW UINT_MAX
+
 struct adsp_data {
        int crash_reason_smem;
        const char *firmware_name;
@@ -62,6 +66,7 @@ struct qcom_adsp {
        int proxy_pd_count;
 
        int pas_id;
+       struct icc_path *bus_client;
        int crash_reason_smem;
        bool has_aggre2_clk;
 
@@ -124,6 +129,25 @@ static int adsp_load(struct rproc *rproc, const struct firmware *fw)
 
 }
 
+static int do_bus_scaling(struct qcom_adsp *adsp, bool enable)
+{
+       int rc;
+       u32 avg_bw = enable ? PIL_TZ_AVG_BW : 0;
+       u32 peak_bw = enable ? PIL_TZ_PEAK_BW : 0;
+
+       if (adsp->bus_client) {
+               rc = icc_set_bw(adsp->bus_client, avg_bw, peak_bw);
+               if (rc) {
+                       dev_err(adsp->dev, "bandwidth request failed(rc:%d)\n",
+                               rc);
+                       return rc;
+               }
+       } else
+               dev_info(adsp->dev, "Bus scaling not setup for %s\n",
+                       adsp->rproc->name);
+       return 0;
+}
+
 static int adsp_start(struct rproc *rproc)
 {
        struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;
@@ -131,9 +155,13 @@ static int adsp_start(struct rproc *rproc)
 
        qcom_q6v5_prepare(&adsp->q6v5);
 
+       ret = do_bus_scaling(adsp, true);
+       if (ret)
+               goto disable_irqs;
+
        ret = adsp_pds_enable(adsp, adsp->active_pds, adsp->active_pd_count);
        if (ret < 0)
-               goto disable_irqs;
+               goto unscale_bus;
 
        ret = adsp_pds_enable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
        if (ret < 0)
@@ -183,6 +211,8 @@ static int adsp_start(struct rproc *rproc)
        adsp_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
 disable_active_pds:
        adsp_pds_disable(adsp, adsp->active_pds, adsp->active_pd_count);
+unscale_bus:
+       do_bus_scaling(adsp, false);
 disable_irqs:
        qcom_q6v5_unprepare(&adsp->q6v5);
 
@@ -198,6 +228,7 @@ static void qcom_pas_handover(struct qcom_q6v5 *q6v5)
        clk_disable_unprepare(adsp->aggre2_clk);
        clk_disable_unprepare(adsp->xo);
        adsp_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
+       do_bus_scaling(adsp, false);
 }
 
 static int adsp_stop(struct rproc *rproc)
@@ -280,6 +311,14 @@ static int adsp_init_regulator(struct qcom_adsp *adsp)
        return PTR_ERR_OR_ZERO(adsp->px_supply);
 }
 
+static void adsp_init_bus_scaling(struct qcom_adsp *adsp)
+{
+       adsp->bus_client = of_icc_get(adsp->dev, NULL);
+       if (!adsp->bus_client)
+               dev_warn(adsp->dev, "%s: unable to get bus client \n",
+                       __func__);
+}
+
 static int adsp_pds_attach(struct device *dev, struct device **devs,
                           char **pd_names)
 {
@@ -410,6 +449,8 @@ static int adsp_probe(struct platform_device *pdev)
        if (ret)
                goto free_rproc;
 
+       adsp_init_bus_scaling(adsp);
+
        ret = adsp_pds_attach(&pdev->dev, adsp->active_pds,
                              desc->active_pd_names);
        if (ret < 0)
--

The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

maintainer
#2 lore raw
Quoted 16 lines · Mathieu Poirier

Hi Rishabh,

Quoted 12 lines · Rishabh Bhatnagar

During bootup since remote processors cannot request for additional bus bandwidth from the interconect framework, platform driver should provide the proxy resources. This is useful for scenarios where the Q6 tries to access the DDR memory in the initial stages of bootup. For e.g. during bootup or after recovery modem Q6 tries to zero out the bss section in the DDR. Since this is a big chunk of memory if don't bump up the bandwidth we might encounter timeout issues. This patch makes a proxy vote for maximizing the bus bandwidth during bootup and removes it once processor is up.

Quoted 6 lines
Quoted 1 line

The title of this patch contains "[PATCH 1/2]" but only one patch was sent to the linux-remoteproc mailing list. Is this a mistake and this is a stand alone patch or another patch did not reach the list?

I see that you sent another patch [1] that seems to be stand alone but when looking into the code function of_icc_get() is called, which does reference the bindings in [1].

[1]. https://patchwork.kernel.org/patch/11463381/

Quoted 122 lines

Thanks,
Mathieu

Quoted 119 lines
---
 drivers/remoteproc/qcom_q6v5_pas.c | 43 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
drivers/remoteproc/qcom_q6v5_pas.c +42 -2
index edf9d0e..8f5db8d 100644
@@ -20,6 +20,7 @@
 #include <linux/qcom_scm.h>
 #include <linux/regulator/consumer.h>
 #include <linux/remoteproc.h>
+#include <linux/interconnect.h>
 #include <linux/soc/qcom/mdt_loader.h>
 #include <linux/soc/qcom/smem.h>
 #include <linux/soc/qcom/smem_state.h>
@@ -28,6 +29,9 @@
 #include "qcom_q6v5.h"
 #include "remoteproc_internal.h"
 
+#define PIL_TZ_AVG_BW  0
+#define PIL_TZ_PEAK_BW UINT_MAX
+
 struct adsp_data {
        int crash_reason_smem;
        const char *firmware_name;
@@ -62,6 +66,7 @@ struct qcom_adsp {
        int proxy_pd_count;
 
        int pas_id;
+       struct icc_path *bus_client;
        int crash_reason_smem;
        bool has_aggre2_clk;
 
@@ -124,6 +129,25 @@ static int adsp_load(struct rproc *rproc, const struct firmware *fw)
 
 }
 
+static int do_bus_scaling(struct qcom_adsp *adsp, bool enable)
+{
+       int rc;
+       u32 avg_bw = enable ? PIL_TZ_AVG_BW : 0;
+       u32 peak_bw = enable ? PIL_TZ_PEAK_BW : 0;
+
+       if (adsp->bus_client) {
+               rc = icc_set_bw(adsp->bus_client, avg_bw, peak_bw);
+               if (rc) {
+                       dev_err(adsp->dev, "bandwidth request failed(rc:%d)\n",
+                               rc);
+                       return rc;
+               }
+       } else
+               dev_info(adsp->dev, "Bus scaling not setup for %s\n",
+                       adsp->rproc->name);
+       return 0;
+}
+
 static int adsp_start(struct rproc *rproc)
 {
        struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;
@@ -131,9 +155,13 @@ static int adsp_start(struct rproc *rproc)
 
        qcom_q6v5_prepare(&adsp->q6v5);
 
+       ret = do_bus_scaling(adsp, true);
+       if (ret)
+               goto disable_irqs;
+
        ret = adsp_pds_enable(adsp, adsp->active_pds, adsp->active_pd_count);
        if (ret < 0)
-               goto disable_irqs;
+               goto unscale_bus;
 
        ret = adsp_pds_enable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
        if (ret < 0)
@@ -183,6 +211,8 @@ static int adsp_start(struct rproc *rproc)
        adsp_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
 disable_active_pds:
        adsp_pds_disable(adsp, adsp->active_pds, adsp->active_pd_count);
+unscale_bus:
+       do_bus_scaling(adsp, false);
 disable_irqs:
        qcom_q6v5_unprepare(&adsp->q6v5);
 
@@ -198,6 +228,7 @@ static void qcom_pas_handover(struct qcom_q6v5 *q6v5)
        clk_disable_unprepare(adsp->aggre2_clk);
        clk_disable_unprepare(adsp->xo);
        adsp_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
+       do_bus_scaling(adsp, false);
 }
 
 static int adsp_stop(struct rproc *rproc)
@@ -280,6 +311,14 @@ static int adsp_init_regulator(struct qcom_adsp *adsp)
        return PTR_ERR_OR_ZERO(adsp->px_supply);
 }
 
+static void adsp_init_bus_scaling(struct qcom_adsp *adsp)
+{
+       adsp->bus_client = of_icc_get(adsp->dev, NULL);
+       if (!adsp->bus_client)
+               dev_warn(adsp->dev, "%s: unable to get bus client \n",
+                       __func__);
+}
+
 static int adsp_pds_attach(struct device *dev, struct device **devs,
                           char **pd_names)
 {
@@ -410,6 +449,8 @@ static int adsp_probe(struct platform_device *pdev)
        if (ret)
                goto free_rproc;
 
+       adsp_init_bus_scaling(adsp);
+
        ret = adsp_pds_attach(&pdev->dev, adsp->active_pds,
                              desc->active_pd_names);
        if (ret < 0)
--

The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

#3 lore raw
Quoted 25 lines · Mathieu Poirier
Quoted 16 lines · Mathieu Poirier

Hi Rishabh,

Quoted 12 lines · Rishabh Bhatnagar

During bootup since remote processors cannot request for additional bus bandwidth from the interconect framework, platform driver should provide the proxy resources. This is useful for scenarios where the Q6 tries to access the DDR memory in the initial stages of bootup. For e.g. during bootup or after recovery modem Q6 tries to zero out the bss section in the DDR. Since this is a big chunk of memory if don't bump up the bandwidth we might encounter timeout issues. This patch makes a proxy vote for maximizing the bus bandwidth during bootup and removes it once processor is up.

Quoted 6 lines
Quoted 1 line

The title of this patch contains "[PATCH 1/2]" but only one patch was sent to the linux-remoteproc mailing list. Is this a mistake and this is a stand alone patch or another patch did not reach the list?

Quoted 8 lines

I see that you sent another patch [1] that seems to be stand alone but when looking into the code function of_icc_get() is called, which does reference the bindings in [1].

[1]. https://patchwork.kernel.org/patch/11463381/

Quoted 2 lines

Thanks,
Mathieu

Yes its supposed to be a patchset of 2, somehow the numbering got messed up. I'll resend the two patches so that you can take a look.

Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
---
 drivers/remoteproc/qcom_q6v5_pas.c | 43 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
drivers/remoteproc/qcom_q6v5_pas.c +42 -2
index edf9d0e..8f5db8d 100644
@@ -20,6 +20,7 @@
 #include <linux/qcom_scm.h>
 #include <linux/regulator/consumer.h>
 #include <linux/remoteproc.h>
+#include <linux/interconnect.h>
 #include <linux/soc/qcom/mdt_loader.h>
 #include <linux/soc/qcom/smem.h>
 #include <linux/soc/qcom/smem_state.h>
@@ -28,6 +29,9 @@
 #include "qcom_q6v5.h"
 #include "remoteproc_internal.h"
 
+#define PIL_TZ_AVG_BW  0
+#define PIL_TZ_PEAK_BW UINT_MAX
+
 struct adsp_data {
        int crash_reason_smem;
        const char *firmware_name;
@@ -62,6 +66,7 @@ struct qcom_adsp {
        int proxy_pd_count;
 
        int pas_id;
+       struct icc_path *bus_client;
        int crash_reason_smem;
        bool has_aggre2_clk;
 
@@ -124,6 +129,25 @@ static int adsp_load(struct rproc *rproc, const struct firmware *fw)
 
 }
 
+static int do_bus_scaling(struct qcom_adsp *adsp, bool enable)
+{
+       int rc;
+       u32 avg_bw = enable ? PIL_TZ_AVG_BW : 0;
+       u32 peak_bw = enable ? PIL_TZ_PEAK_BW : 0;
+
+       if (adsp->bus_client) {
+               rc = icc_set_bw(adsp->bus_client, avg_bw, peak_bw);
+               if (rc) {
+                       dev_err(adsp->dev, "bandwidth request failed(rc:%d)\n",
+                               rc);
+                       return rc;
+               }
+       } else
+               dev_info(adsp->dev, "Bus scaling not setup for %s\n",
+                       adsp->rproc->name);
+       return 0;
+}
+
 static int adsp_start(struct rproc *rproc)
 {
        struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;
@@ -131,9 +155,13 @@ static int adsp_start(struct rproc *rproc)
 
        qcom_q6v5_prepare(&adsp->q6v5);
 
+       ret = do_bus_scaling(adsp, true);
+       if (ret)
+               goto disable_irqs;
+
        ret = adsp_pds_enable(adsp, adsp->active_pds, adsp->active_pd_count);
        if (ret < 0)
-               goto disable_irqs;
+               goto unscale_bus;
 
        ret = adsp_pds_enable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
        if (ret < 0)
@@ -183,6 +211,8 @@ static int adsp_start(struct rproc *rproc)
        adsp_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
 disable_active_pds:
        adsp_pds_disable(adsp, adsp->active_pds, adsp->active_pd_count);
+unscale_bus:
+       do_bus_scaling(adsp, false);
 disable_irqs:
        qcom_q6v5_unprepare(&adsp->q6v5);
 
@@ -198,6 +228,7 @@ static void qcom_pas_handover(struct qcom_q6v5 *q6v5)
        clk_disable_unprepare(adsp->aggre2_clk);
        clk_disable_unprepare(adsp->xo);
        adsp_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
+       do_bus_scaling(adsp, false);
 }
 
 static int adsp_stop(struct rproc *rproc)
@@ -280,6 +311,14 @@ static int adsp_init_regulator(struct qcom_adsp *adsp)
        return PTR_ERR_OR_ZERO(adsp->px_supply);
 }
 
+static void adsp_init_bus_scaling(struct qcom_adsp *adsp)
+{
+       adsp->bus_client = of_icc_get(adsp->dev, NULL);
+       if (!adsp->bus_client)
+               dev_warn(adsp->dev, "%s: unable to get bus client \n",
+                       __func__);
+}
+
 static int adsp_pds_attach(struct device *dev, struct device **devs,
                           char **pd_names)
 {
@@ -410,6 +449,8 @@ static int adsp_probe(struct platform_device *pdev)
        if (ret)
                goto free_rproc;
 
+       adsp_init_bus_scaling(adsp);
+
        ret = adsp_pds_attach(&pdev->dev, adsp->active_pds,
                              desc->active_pd_names);
        if (ret < 0)
--

The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

#4 lore raw
In reply to Rishabh Bhatnagar
Quoted 21 lines · Rishabh Bhatnagar

During bootup since remote processors cannot request for additional bus bandwidth from the interconect framework, platform driver should provide the proxy resources. This is useful for scenarios where the Q6 tries to access the DDR memory in the initial stages of bootup. For e.g. during bootup or after recovery modem Q6 tries to zero out the bss section in the DDR. Since this is a big chunk of memory if don't bump up the bandwidth we might encounter timeout issues. This patch makes a proxy vote for maximizing the bus bandwidth during bootup and removes it once processor is up.

---
 drivers/remoteproc/qcom_q6v5_pas.c | 43 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
drivers/remoteproc/qcom_q6v5_pas.c +0 -0
index edf9d0e..8f5db8d 100644

drivers/remoteproc/qcom_q6v5_pas.c line 23

Quoted 4 lines
drivers/remoteproc/qcom_q6v5_pas.c +1 -0
@@ -20,6 +20,7 @@
 #include <linux/qcom_scm.h>
 #include <linux/regulator/consumer.h>
 #include <linux/remoteproc.h>
+#include <linux/interconnect.h>

These are sorted alphabetically, please maintain this.

drivers/remoteproc/qcom_q6v5_pas.c line 33

Quoted 9 lines
drivers/remoteproc/qcom_q6v5_pas.c +2 -0
 #include <linux/soc/qcom/mdt_loader.h>
 #include <linux/soc/qcom/smem.h>
 #include <linux/soc/qcom/smem_state.h>
@@ -28,6 +29,9 @@
 #include "qcom_q6v5.h"
 #include "remoteproc_internal.h"
 
+#define PIL_TZ_AVG_BW  0
+#define PIL_TZ_PEAK_BW UINT_MAX

Please just inline these in do_bus_scaling().

drivers/remoteproc/qcom_q6v5_pas.c struct qcom_adsp { · line 69

Quoted 9 lines
drivers/remoteproc/qcom_q6v5_pas.c +2 -0
+
 struct adsp_data {
 	int crash_reason_smem;
 	const char *firmware_name;
@@ -62,6 +66,7 @@ struct qcom_adsp {
 	int proxy_pd_count;
 
 	int pas_id;
+	struct icc_path *bus_client;

Please rename this proxy_path

drivers/remoteproc/qcom_q6v5_pas.c static int adsp_load(struct rproc *rproc, const struct firmware *fw) · line 132

Quoted 8 lines
drivers/remoteproc/qcom_q6v5_pas.c +1 -0
 	int crash_reason_smem;
 	bool has_aggre2_clk;
 
@@ -124,6 +129,25 @@ static int adsp_load(struct rproc *rproc, const struct firmware *fw)
 
 }
 
+static int do_bus_scaling(struct qcom_adsp *adsp, bool enable)

adsp_bus_vote()

drivers/remoteproc/qcom_q6v5_pas.c static int adsp_load(struct rproc *rproc, const struct firmware *fw) · line 134

Quoted 2 lines
drivers/remoteproc/qcom_q6v5_pas.c +2 -0
+{
+	int rc;

This driver uses "int ret".

drivers/remoteproc/qcom_q6v5_pas.c static int adsp_load(struct rproc *rproc, const struct firmware *fw) · line 135

Quoted 1 line
drivers/remoteproc/qcom_q6v5_pas.c +1 -0
+	u32 avg_bw = enable ? PIL_TZ_AVG_BW : 0;

No need to carry a variable for 0 or 0, jut pass 0 in the function call directly.

drivers/remoteproc/qcom_q6v5_pas.c static int adsp_load(struct rproc *rproc, const struct firmware *fw) · line 138

Quoted 3 lines
drivers/remoteproc/qcom_q6v5_pas.c +3 -0
+	u32 peak_bw = enable ? PIL_TZ_PEAK_BW : 0;
+
+	if (adsp->bus_client) {

No need for this check, icc_set_bw(NULL, ..) is a nop.

drivers/remoteproc/qcom_q6v5_pas.c static int adsp_load(struct rproc *rproc, const struct firmware *fw) · line 141

Quoted 3 lines
drivers/remoteproc/qcom_q6v5_pas.c +3 -0
+		rc = icc_set_bw(adsp->bus_client, avg_bw, peak_bw);
+		if (rc) {
+			dev_err(adsp->dev, "bandwidth request failed(rc:%d)\n",

"failed to request bandwidth: %d\n"

drivers/remoteproc/qcom_q6v5_pas.c static int adsp_load(struct rproc *rproc, const struct firmware *fw) · line 146

Quoted 5 lines
drivers/remoteproc/qcom_q6v5_pas.c +5 -0
+				rc);
+			return rc;
+		}
+	} else
+		dev_info(adsp->dev, "Bus scaling not setup for %s\n",

No need to print this.

Quoted 40 lines
drivers/remoteproc/qcom_q6v5_pas.c +12 -1
+			adsp->rproc->name);
+	return 0;
+}
+
 static int adsp_start(struct rproc *rproc)
 {
 	struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;
@@ -131,9 +155,13 @@ static int adsp_start(struct rproc *rproc)
 
 	qcom_q6v5_prepare(&adsp->q6v5);
 
+	ret = do_bus_scaling(adsp, true);
+	if (ret)
+		goto disable_irqs;
+
 	ret = adsp_pds_enable(adsp, adsp->active_pds, adsp->active_pd_count);
 	if (ret < 0)
-		goto disable_irqs;
+		goto unscale_bus;
 
 	ret = adsp_pds_enable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
 	if (ret < 0)
@@ -183,6 +211,8 @@ static int adsp_start(struct rproc *rproc)
 	adsp_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
 disable_active_pds:
 	adsp_pds_disable(adsp, adsp->active_pds, adsp->active_pd_count);
+unscale_bus:
+	do_bus_scaling(adsp, false);
 disable_irqs:
 	qcom_q6v5_unprepare(&adsp->q6v5);
 
@@ -198,6 +228,7 @@ static void qcom_pas_handover(struct qcom_q6v5 *q6v5)
 	clk_disable_unprepare(adsp->aggre2_clk);
 	clk_disable_unprepare(adsp->xo);
 	adsp_pds_disable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
+	do_bus_scaling(adsp, false);
 }
 
 static int adsp_stop(struct rproc *rproc)

drivers/remoteproc/qcom_q6v5_pas.c static int adsp_init_regulator(struct qcom_adsp *adsp) · line 317

Quoted 7 lines
drivers/remoteproc/qcom_q6v5_pas.c +4 -0
@@ -280,6 +311,14 @@ static int adsp_init_regulator(struct qcom_adsp *adsp)
 	return PTR_ERR_OR_ZERO(adsp->px_supply);
 }
 
+static void adsp_init_bus_scaling(struct qcom_adsp *adsp)
+{
+	adsp->bus_client = of_icc_get(adsp->dev, NULL);
+	if (!adsp->bus_client)

!adsp->bus_client means there's no interconnects property in the DT node, you still need to test for errors with IS_ERR().

And in particular you're not guaranteed that the provider has probed, so you need to propagate EPROBE_DEFER.

drivers/remoteproc/qcom_q6v5_pas.c static int adsp_init_regulator(struct qcom_adsp *adsp) · line 319

Quoted 2 lines
drivers/remoteproc/qcom_q6v5_pas.c +2 -0
+		dev_warn(adsp->dev, "%s: unable to get bus client \n",
+			__func__);

This is a dev_err() for the case of IS_ERR().

And please drop the __func__, it doesn't add any value.

drivers/remoteproc/qcom_q6v5_pas.c static int adsp_probe(struct platform_device *pdev) · line 453

Quoted 11 lines
drivers/remoteproc/qcom_q6v5_pas.c +4 -0
+}
+
 static int adsp_pds_attach(struct device *dev, struct device **devs,
 			   char **pd_names)
 {
@@ -410,6 +449,8 @@ static int adsp_probe(struct platform_device *pdev)
 	if (ret)
 		goto free_rproc;
 
+	adsp_init_bus_scaling(adsp);
+

As stated above, you need to propagate actual errors here (i.e. not the case where of_icc_get() returned NULL, but when it returned IS_ERR())

Regards,
bjorn

Quoted 6 lines
drivers/remoteproc/qcom_q6v5_pas.c +0 -0
 	ret = adsp_pds_attach(&pdev->dev, adsp->active_pds,
 			      desc->active_pd_names);
 	if (ret < 0)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project