Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3172603rwl; Mon, 27 Mar 2023 10:09:57 -0700 (PDT) X-Google-Smtp-Source: AKy350bgv8nJOqFxUxxZokSp/HifxtG4+D62BdghkxDEgv8tTiN+T/ASTYsHiJYxVGXEOnCHLKBj X-Received: by 2002:a17:906:5812:b0:931:85f8:6d00 with SMTP id m18-20020a170906581200b0093185f86d00mr13537693ejq.47.1679936997628; Mon, 27 Mar 2023 10:09:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679936997; cv=none; d=google.com; s=arc-20160816; b=I2yG6jacWH9qYmlS6wI6lC6c+fxod2BG8bWpYOpOHJuuTb0AmFJmj45jfLzdZCnXKt uKRdBe5F6S22gCrwqrL0tFCFBf1JSEYW1UICcuMacUt5p/wb6btgMu4Q74kCUngMzIen CmQ+g843iKohodXU27TvMNVvZKpqs28Q5FLINfiG53KvrtU7QwZ4t/F0iZ4rpODPvxEC IXLwdOk+61JKJxEBZkiUsENusBMFcp3uZN9v5p9txmuFqXu+xUuGLV/xCqZvmdc39RpV cO95evBNQ/O0Ev3wi3ryeUQUnFE7TwAUx0QMi8GRsFCOq+SofDICQXXzuUgMMHOgBAxm fWtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=JndTjXFy5LDhJ06vuvRSNbMruL8vLvBEcbWG9MIP/o8=; b=v5WVe9g5lvEpgwRjTGX+HASx3JtLB+aBuG1gW9/BPcVOM/ScfFPGXH15mgeZdTnpQ6 iihyGVbpuGNZkJhffppIRCZyOPhsITomYlb+0eufrZStOVuHu4NLWY9RIvVZBFr5APVZ O+mRzp4Yhhk8dgjYlSv1RobG5YotM72CYmzWR5IYYmyx3QeMEfa55LIPZAY0lHE5E4ZN szJnUltU12eZCQWeED7vvm277lYTJ8qxZG1UwhZJPEmKezi6rVhhRpIvdshFwu5khvi6 QZXK6LFs5+NPQ9znUBOb7R/FP94TViU7kRDgC/PwUhPeqUussiy9Iiodf75v3Kx7l3up dBBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb34-20020a170907962200b0093a0ef38401si19233097ejc.94.2023.03.27.10.09.32; Mon, 27 Mar 2023 10:09:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232851AbjC0RIw convert rfc822-to-8bit (ORCPT + 99 others); Mon, 27 Mar 2023 13:08:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231956AbjC0RIa (ORCPT ); Mon, 27 Mar 2023 13:08:30 -0400 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6D0D3AA2; Mon, 27 Mar 2023 10:07:27 -0700 (PDT) Received: by mail-ed1-f49.google.com with SMTP id cn12so39095941edb.4; Mon, 27 Mar 2023 10:07:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679936807; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rYJe8F65O4jssLoudktBYu87ax2vScUAeJoZjXvj+pA=; b=ax4PQdLGfH2tlyGScgcrnGJt2YhZMdTh/0ASNfM6Mp4xeEZJv5ZJiE09JCkQV0rhF+ 5vHTC9DaFXhsZprrQxeIU7k3BK7/ISjUb0oA73NOr3Bx9wc6LilVnmSdZZ3KCXyIcja2 6m/3Ul/fgtADHuqYhNUPuvr7QCqGAmNb/wrSaN1L3UwSRha2Pl4HmUErOWR05mQHHoIU X5RB2/veKVPEINGthCz08GPk0jEhrflyHS0rce1ovpU8Ux/gNE+qHG60LAdW1k3/1sWw JhgQC8ZFJesZ6kNC9VhJ/wFOKIw5VbqnHnz6h4/aFNARerPFDKuodt2TxCkvTYAAd1bS Q0QQ== X-Gm-Message-State: AAQBX9c14DmbYDTS+jfAm0cjTgpR4h1fdWeLe1Yndrb/liNRduN2LRHB 8qKh6ITt0D/DJqfAWJCzZLLFX55HMpkADjVQq7EPc0oW X-Received: by 2002:a50:9f82:0:b0:4fa:3c0b:74b with SMTP id c2-20020a509f82000000b004fa3c0b074bmr6398781edf.3.1679936807303; Mon, 27 Mar 2023 10:06:47 -0700 (PDT) MIME-Version: 1.0 References: <20230309140724.2152712-1-cristian.marussi@arm.com> <20230309140724.2152712-2-cristian.marussi@arm.com> In-Reply-To: <20230309140724.2152712-2-cristian.marussi@arm.com> From: "Rafael J. Wysocki" Date: Mon, 27 Mar 2023 19:06:36 +0200 Message-ID: Subject: Re: [PATCH v2 1/3] firmware: arm_scmi: Refactor powercap get/set helpers To: Cristian Marussi Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, sudeep.holla@arm.com, james.quinlan@broadcom.com, Jonathan.Cameron@huawei.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, tarek.el-sherbiny@arm.com, nicola.mazzucato@arm.com, souvik.chakravarty@arm.com, wleavitt@marvell.com, wbartczak@marvell.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 9, 2023 at 3:09 PM Cristian Marussi wrote: > > Refactor SCMI powercap internal get/set helpers. > > Signed-off-by: Cristian Marussi 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 >