diff mbox series

[v2,1/3] firmware: arm_scmi: Refactor powercap get/set helpers

Message ID 20230309140724.2152712-2-cristian.marussi@arm.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series Add SCMI v3.2 Powercap disable support | expand

Commit Message

Cristian Marussi March 9, 2023, 2:07 p.m. UTC
Refactor SCMI powercap internal get/set helpers.

Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
---
 drivers/firmware/arm_scmi/powercap.c | 65 +++++++++++++++++++---------
 1 file changed, 45 insertions(+), 20 deletions(-)

Comments

Rafael J. Wysocki March 27, 2023, 5:06 p.m. UTC | #1
On Thu, Mar 9, 2023 at 3:09 PM Cristian Marussi
<cristian.marussi@arm.com> wrote:
>
> Refactor SCMI powercap internal get/set helpers.
>
> Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>

I can apply this series if I get an ACK or preferably Reviewed-by:
from an SCMI person.

However, I think that it would be more appropriate to route it through
ARM/ARM64 anyway.

> ---
>  drivers/firmware/arm_scmi/powercap.c | 65 +++++++++++++++++++---------
>  1 file changed, 45 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/firmware/arm_scmi/powercap.c b/drivers/firmware/arm_scmi/powercap.c
> index 83b90bde755c..2e490492f187 100644
> --- a/drivers/firmware/arm_scmi/powercap.c
> +++ b/drivers/firmware/arm_scmi/powercap.c
> @@ -313,24 +313,33 @@ static int scmi_powercap_xfer_cap_get(const struct scmi_protocol_handle *ph,
>         return ret;
>  }
>
> -static int scmi_powercap_cap_get(const struct scmi_protocol_handle *ph,
> -                                u32 domain_id, u32 *power_cap)
> +static int __scmi_powercap_cap_get(const struct scmi_protocol_handle *ph,
> +                                  const struct scmi_powercap_info *dom,
> +                                  u32 *power_cap)
>  {
> -       struct scmi_powercap_info *dom;
> -       struct powercap_info *pi = ph->get_priv(ph);
> -
> -       if (!power_cap || domain_id >= pi->num_domains)
> -               return -EINVAL;
> -
> -       dom = pi->powercaps + domain_id;
>         if (dom->fc_info && dom->fc_info[POWERCAP_FC_CAP].get_addr) {
>                 *power_cap = ioread32(dom->fc_info[POWERCAP_FC_CAP].get_addr);
>                 trace_scmi_fc_call(SCMI_PROTOCOL_POWERCAP, POWERCAP_CAP_GET,
> -                                  domain_id, *power_cap, 0);
> +                                  dom->id, *power_cap, 0);
>                 return 0;
>         }
>
> -       return scmi_powercap_xfer_cap_get(ph, domain_id, power_cap);
> +       return scmi_powercap_xfer_cap_get(ph, dom->id, power_cap);
> +}
> +
> +static int scmi_powercap_cap_get(const struct scmi_protocol_handle *ph,
> +                                u32 domain_id, u32 *power_cap)
> +{
> +       const struct scmi_powercap_info *dom;
> +
> +       if (!power_cap)
> +               return -EINVAL;
> +
> +       dom = scmi_powercap_dom_info_get(ph, domain_id);
> +       if (!dom)
> +               return -EINVAL;
> +
> +       return __scmi_powercap_cap_get(ph, dom, power_cap);
>  }
>
>  static int scmi_powercap_xfer_cap_set(const struct scmi_protocol_handle *ph,
> @@ -375,17 +384,20 @@ static int scmi_powercap_xfer_cap_set(const struct scmi_protocol_handle *ph,
>         return ret;
>  }
>
> -static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
> -                                u32 domain_id, u32 power_cap,
> -                                bool ignore_dresp)
> +static int __scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
> +                                  struct powercap_info *pi, u32 domain_id,
> +                                  u32 power_cap, bool ignore_dresp)
>  {
> +       int ret = -EINVAL;
>         const struct scmi_powercap_info *pc;
>
>         pc = scmi_powercap_dom_info_get(ph, domain_id);
> -       if (!pc || !pc->powercap_cap_config || !power_cap ||
> -           power_cap < pc->min_power_cap ||
> -           power_cap > pc->max_power_cap)
> -               return -EINVAL;
> +       if (!pc || !pc->powercap_cap_config)
> +               return ret;
> +
> +       if (power_cap &&
> +           (power_cap < pc->min_power_cap || power_cap > pc->max_power_cap))
> +               return ret;
>
>         if (pc->fc_info && pc->fc_info[POWERCAP_FC_CAP].set_addr) {
>                 struct scmi_fc_info *fci = &pc->fc_info[POWERCAP_FC_CAP];
> @@ -394,10 +406,23 @@ static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
>                 ph->hops->fastchannel_db_ring(fci->set_db);
>                 trace_scmi_fc_call(SCMI_PROTOCOL_POWERCAP, POWERCAP_CAP_SET,
>                                    domain_id, power_cap, 0);
> -               return 0;
> +               ret = 0;
> +       } else {
> +               ret = scmi_powercap_xfer_cap_set(ph, pc, power_cap,
> +                                                ignore_dresp);
>         }
>
> -       return scmi_powercap_xfer_cap_set(ph, pc, power_cap, ignore_dresp);
> +       return ret;
> +}
> +
> +static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
> +                                u32 domain_id, u32 power_cap,
> +                                bool ignore_dresp)
> +{
> +       struct powercap_info *pi = ph->get_priv(ph);
> +
> +       return __scmi_powercap_cap_set(ph, pi, domain_id,
> +                                      power_cap, ignore_dresp);
>  }
>
>  static int scmi_powercap_xfer_pai_get(const struct scmi_protocol_handle *ph,
> --
> 2.34.1
>
Cristian Marussi March 27, 2023, 5:28 p.m. UTC | #2
On Mon, Mar 27, 2023 at 07:06:36PM +0200, Rafael J. Wysocki wrote:
> On Thu, Mar 9, 2023 at 3:09 PM Cristian Marussi
> <cristian.marussi@arm.com> wrote:
> >
> > Refactor SCMI powercap internal get/set helpers.
> >
> > Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> 

Hi Rafael,

Thanks for having a look.

> I can apply this series if I get an ACK or preferably Reviewed-by:
> from an SCMI person.
> 

I'll see if I can chase someone for this cycle :D

> However, I think that it would be more appropriate to route it through
> ARM/ARM64 anyway.
> 

Yes, indeed it is what usually happens I think, but I thought
appropriate to Cc you being power related.

Thanks,
Cristian
Sudeep Holla March 29, 2023, 12:04 p.m. UTC | #3
On Mon, Mar 27, 2023 at 07:06:36PM +0200, Rafael J. Wysocki wrote:
> On Thu, Mar 9, 2023 at 3:09 PM Cristian Marussi
> <cristian.marussi@arm.com> wrote:
> >
> > Refactor SCMI powercap internal get/set helpers.
> >
> > Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> 
> I can apply this series if I get an ACK or preferably Reviewed-by:
> from an SCMI person.
>

Sorry, I had looked at this and just delayed asking you about your preference.
I am fine to take it or else

Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> (for SCMI parts)

Please ack 3/3 if you prefer me to take it once you are happy with it.
Rafael J. Wysocki May 24, 2023, 3:12 p.m. UTC | #4
On Wed, Mar 29, 2023 at 2:05 PM Sudeep Holla <sudeep.holla@arm.com> wrote:
>
> On Mon, Mar 27, 2023 at 07:06:36PM +0200, Rafael J. Wysocki wrote:
> > On Thu, Mar 9, 2023 at 3:09 PM Cristian Marussi
> > <cristian.marussi@arm.com> wrote:
> > >
> > > Refactor SCMI powercap internal get/set helpers.
> > >
> > > Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
> >
> > I can apply this series if I get an ACK or preferably Reviewed-by:
> > from an SCMI person.
> >
>
> Sorry, I had looked at this and just delayed asking you about your preference.
> I am fine to take it

Yes, please!

> or else
>
> Reviewed-by: Sudeep Holla <sudeep.holla@arm.com> (for SCMI parts)
>
> Please ack 3/3 if you prefer me to take it once you are happy with it.

Done, thanks!
diff mbox series

Patch

diff --git a/drivers/firmware/arm_scmi/powercap.c b/drivers/firmware/arm_scmi/powercap.c
index 83b90bde755c..2e490492f187 100644
--- a/drivers/firmware/arm_scmi/powercap.c
+++ b/drivers/firmware/arm_scmi/powercap.c
@@ -313,24 +313,33 @@  static int scmi_powercap_xfer_cap_get(const struct scmi_protocol_handle *ph,
 	return ret;
 }
 
-static int scmi_powercap_cap_get(const struct scmi_protocol_handle *ph,
-				 u32 domain_id, u32 *power_cap)
+static int __scmi_powercap_cap_get(const struct scmi_protocol_handle *ph,
+				   const struct scmi_powercap_info *dom,
+				   u32 *power_cap)
 {
-	struct scmi_powercap_info *dom;
-	struct powercap_info *pi = ph->get_priv(ph);
-
-	if (!power_cap || domain_id >= pi->num_domains)
-		return -EINVAL;
-
-	dom = pi->powercaps + domain_id;
 	if (dom->fc_info && dom->fc_info[POWERCAP_FC_CAP].get_addr) {
 		*power_cap = ioread32(dom->fc_info[POWERCAP_FC_CAP].get_addr);
 		trace_scmi_fc_call(SCMI_PROTOCOL_POWERCAP, POWERCAP_CAP_GET,
-				   domain_id, *power_cap, 0);
+				   dom->id, *power_cap, 0);
 		return 0;
 	}
 
-	return scmi_powercap_xfer_cap_get(ph, domain_id, power_cap);
+	return scmi_powercap_xfer_cap_get(ph, dom->id, power_cap);
+}
+
+static int scmi_powercap_cap_get(const struct scmi_protocol_handle *ph,
+				 u32 domain_id, u32 *power_cap)
+{
+	const struct scmi_powercap_info *dom;
+
+	if (!power_cap)
+		return -EINVAL;
+
+	dom = scmi_powercap_dom_info_get(ph, domain_id);
+	if (!dom)
+		return -EINVAL;
+
+	return __scmi_powercap_cap_get(ph, dom, power_cap);
 }
 
 static int scmi_powercap_xfer_cap_set(const struct scmi_protocol_handle *ph,
@@ -375,17 +384,20 @@  static int scmi_powercap_xfer_cap_set(const struct scmi_protocol_handle *ph,
 	return ret;
 }
 
-static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
-				 u32 domain_id, u32 power_cap,
-				 bool ignore_dresp)
+static int __scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
+				   struct powercap_info *pi, u32 domain_id,
+				   u32 power_cap, bool ignore_dresp)
 {
+	int ret = -EINVAL;
 	const struct scmi_powercap_info *pc;
 
 	pc = scmi_powercap_dom_info_get(ph, domain_id);
-	if (!pc || !pc->powercap_cap_config || !power_cap ||
-	    power_cap < pc->min_power_cap ||
-	    power_cap > pc->max_power_cap)
-		return -EINVAL;
+	if (!pc || !pc->powercap_cap_config)
+		return ret;
+
+	if (power_cap &&
+	    (power_cap < pc->min_power_cap || power_cap > pc->max_power_cap))
+		return ret;
 
 	if (pc->fc_info && pc->fc_info[POWERCAP_FC_CAP].set_addr) {
 		struct scmi_fc_info *fci = &pc->fc_info[POWERCAP_FC_CAP];
@@ -394,10 +406,23 @@  static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
 		ph->hops->fastchannel_db_ring(fci->set_db);
 		trace_scmi_fc_call(SCMI_PROTOCOL_POWERCAP, POWERCAP_CAP_SET,
 				   domain_id, power_cap, 0);
-		return 0;
+		ret = 0;
+	} else {
+		ret = scmi_powercap_xfer_cap_set(ph, pc, power_cap,
+						 ignore_dresp);
 	}
 
-	return scmi_powercap_xfer_cap_set(ph, pc, power_cap, ignore_dresp);
+	return ret;
+}
+
+static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph,
+				 u32 domain_id, u32 power_cap,
+				 bool ignore_dresp)
+{
+	struct powercap_info *pi = ph->get_priv(ph);
+
+	return __scmi_powercap_cap_set(ph, pi, domain_id,
+				       power_cap, ignore_dresp);
 }
 
 static int scmi_powercap_xfer_pai_get(const struct scmi_protocol_handle *ph,