From patchwork Wed May 31 15:20:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 101525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2973357vqr; Wed, 31 May 2023 08:41:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6hn7dC2wf1kC/jR7mta76gS2fjDhmjizhRfxMvjbcbLjdGhPM7zkIRlK4VrQcp8E0FMNJE X-Received: by 2002:a05:6a20:9155:b0:ff:ca91:68ee with SMTP id x21-20020a056a20915500b000ffca9168eemr5682460pzc.9.1685547691187; Wed, 31 May 2023 08:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685547691; cv=none; d=google.com; s=arc-20160816; b=tqTxv/Djv5LBOHqOz9gOqpsBmuhi1XUAgjGAI7igGAq4fIN7uV5i/2ZSdrbG44SRPf OHLLHXUDKD5T6MIigQp3gBH243v4xCoSTXPkyPm9w/nExIUpDHLoA0R2GJcim0khIvsn IdWI0nabi3rOVbUFd5E5ODiHoX3EK6y9jMvJSkq1S5Ohypi+2zJy776xFMC+iiZYSjHc MMUNMnrnHvet5442/w2kyEJ+RCmmPRfdi9JfuDTuuhpyFufsgnnBa0kIcMhSHyNsoTqH LyMqH1Ro0gt1zHWzVJzdpUiPt7vnUTkkwGcaXKitwfkPGlE17/HfpU2MKAD3scoNiI6/ 3GCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oqu2dWL4QhRULnsUcJUqSjquDZvKurve3RZRQqoWris=; b=ueCxY1n6hscBxmkP5EfBWYMIT0NwxgpxbfAouNs9iwlfqf/vutkLy4a1wjJKJ0IyXl rT0/obuN3S14qPuY0Pd8WWrFD3LLq5OMwhYmKC725QYmUTOKwKKeq0zJap89X81LyEPP LhoztOmIqH0sLQYZmmphyjA8CK/zoKaF8A1GJt8YH179SqQMbtFpL3YeTLU1xJbQPuL7 NfZkyaKozrDFNE3kF87XbGBgUGL3CN8pv57nppXpGEEpt69DwKMqYYBpeFe2ik4NQi+G q1J1S5IRPZ6/b8cvpRl/lTcRsFQ2AEAAB++DNF1RAKARFOgo+5EvyshM5j23+InTUrXr Na8g== 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h28-20020aa796dc000000b0063b57ad9891si3667511pfq.315.2023.05.31.08.41.17; Wed, 31 May 2023 08:41:31 -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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234455AbjEaPVf (ORCPT + 99 others); Wed, 31 May 2023 11:21:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234416AbjEaPVN (ORCPT ); Wed, 31 May 2023 11:21:13 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 563DD121; Wed, 31 May 2023 08:21:12 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6B27D1063; Wed, 31 May 2023 08:21:57 -0700 (PDT) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 360DE3F663; Wed, 31 May 2023 08:21:10 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Cc: 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, Cristian Marussi Subject: [PATCH v3 1/3] firmware: arm_scmi: Refactor powercap get/set helpers Date: Wed, 31 May 2023 16:20:37 +0100 Message-Id: <20230531152039.2363181-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230531152039.2363181-1-cristian.marussi@arm.com> References: <20230531152039.2363181-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767424855965523027?= X-GMAIL-MSGID: =?utf-8?q?1767424855965523027?= Refactor SCMI powercap internal get/set helpers. Reviewed-by: Sudeep Holla Signed-off-by: Cristian Marussi --- v2 --> v3 - rebased on v6.4-rc4 - added tags --- 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, From patchwork Wed May 31 15:20:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 101519 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2962801vqr; Wed, 31 May 2023 08:25:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4BJLdI1An4DUN1iBk4qr7PC9JKeW9GgZleGq+l459E6rVeX4EGYerjrlHe/va7yTIH4gTU X-Received: by 2002:a05:6a20:938b:b0:10f:6c74:7919 with SMTP id x11-20020a056a20938b00b0010f6c747919mr7392039pzh.53.1685546712221; Wed, 31 May 2023 08:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685546712; cv=none; d=google.com; s=arc-20160816; b=0fWBcx7B0/S4io4xJlQgDmzusfv47gkJLHrbgEiQ0ePuaETeR+EvLSSd6qPIx1rvsD FAoO6U6ZkZoGTvM8TCA8yi/tkOqtu9hoF0orfdrfqCC5QU/kwZhJu3rz33xHeEsRATnz Il9X7Dk6vM+6e3vASnWxhjtbvzcJQEHOH5cCkrNqXewZwWrd7rT/3Q6GZmYlcKMBHWh5 bsR0BwSvjrDDPJ/rhZuDoLl2ImgdpZ6mftwgzy9RmUKC0spWMh7+TvvEy1/3nI4sTViW WCCMxqNfKJE1KBFdNfWTjWCZN585r5tyCKeygOjttkWp55MhY2szMPKO6/lwp0/vlFHx +cyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eWwvG5YEeKVWKT0WpzJEDyUPSQGOJfZDgNMNIJzPa48=; b=A91u4oIcyN987mXjeEe4AtEaPbkNCl2XERlHYEoJHxV7E83jFswZ2MsAbvp1KK4TGQ JXnl5VofxV2ZKNHwUin8S4j4kqdfSCjGUE3hrG3WCE1ejDKleJX1o0Au9xdmH1K0ZnUx 9PsSfRVuOoE1Mhmol/+WEaTziGxMeQ90Kvd55hFgitDf7xmpsw6gqBdVHqwHIhmSKz5o XTje0Vfc5R0JQFUP8i5+sm5BMuwVuxB+aV2T8CNWPtaEK5fhzt+7k3mbT2/SNkxUFEbR Bu5/Ou26Q1GOrsqgoHV19Tm2eJ2uBBdnz5qh0m2ZvJjgrPZBQJT5QEgfz4Q7a5Q0ukfT d4Hw== 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w27-20020aa79a1b000000b0064d419dd566si3712155pfj.205.2023.05.31.08.24.58; Wed, 31 May 2023 08:25:12 -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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234560AbjEaPVn (ORCPT + 99 others); Wed, 31 May 2023 11:21:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234419AbjEaPVQ (ORCPT ); Wed, 31 May 2023 11:21:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7FBC3C0; Wed, 31 May 2023 08:21:14 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A1B0A168F; Wed, 31 May 2023 08:21:59 -0700 (PDT) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4E7DC3F663; Wed, 31 May 2023 08:21:12 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Cc: 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, Cristian Marussi Subject: [PATCH v3 2/3] firmware: arm_scmi: Add Powercap protocol enable support Date: Wed, 31 May 2023 16:20:38 +0100 Message-Id: <20230531152039.2363181-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230531152039.2363181-1-cristian.marussi@arm.com> References: <20230531152039.2363181-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767423829355841568?= X-GMAIL-MSGID: =?utf-8?q?1767423829355841568?= SCMI Powercap protocol v3.2 supports disabling the powercap on a zone by zone basis by providing a zero valued powercap. Expose new operations to enable/disable powercapping on a per-zone base. Reviewed-by: Sudeep Holla Signed-off-by: Cristian Marussi --- v2 --> V3 - rebased v6.4-rc4 - added tags v1 --> v2 - simplified enable requested checks --- drivers/firmware/arm_scmi/powercap.c | 110 +++++++++++++++++++++++++-- include/linux/scmi_protocol.h | 18 +++++ 2 files changed, 122 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/arm_scmi/powercap.c b/drivers/firmware/arm_scmi/powercap.c index 2e490492f187..244929cb4f3e 100644 --- a/drivers/firmware/arm_scmi/powercap.c +++ b/drivers/firmware/arm_scmi/powercap.c @@ -108,6 +108,8 @@ struct scmi_powercap_meas_changed_notify_payld { }; struct scmi_powercap_state { + bool enabled; + u32 last_pcap; bool meas_notif_enabled; u64 thresholds; #define THRESH_LOW(p, id) \ @@ -412,6 +414,10 @@ static int __scmi_powercap_cap_set(const struct scmi_protocol_handle *ph, ignore_dresp); } + /* Save the last explicitly set non-zero powercap value */ + if (PROTOCOL_REV_MAJOR(pi->version) >= 0x2 && !ret && power_cap) + pi->states[domain_id].last_pcap = power_cap; + return ret; } @@ -421,6 +427,20 @@ static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph, { struct powercap_info *pi = ph->get_priv(ph); + /* + * Disallow zero as a possible explicitly requested powercap: + * there are enable/disable operations for this. + */ + if (!power_cap) + return -EINVAL; + + /* Just log the last set request if acting on a disabled domain */ + if (PROTOCOL_REV_MAJOR(pi->version) >= 0x2 && + !pi->states[domain_id].enabled) { + pi->states[domain_id].last_pcap = power_cap; + return 0; + } + return __scmi_powercap_cap_set(ph, pi, domain_id, power_cap, ignore_dresp); } @@ -589,11 +609,78 @@ scmi_powercap_measurements_threshold_set(const struct scmi_protocol_handle *ph, return ret; } +static int scmi_powercap_cap_enable_set(const struct scmi_protocol_handle *ph, + u32 domain_id, bool enable) +{ + int ret; + u32 power_cap; + struct powercap_info *pi = ph->get_priv(ph); + + if (PROTOCOL_REV_MAJOR(pi->version) < 0x2) + return -EINVAL; + + if (enable == pi->states[domain_id].enabled) + return 0; + + if (enable) { + /* Cannot enable with a zero powercap. */ + if (!pi->states[domain_id].last_pcap) + return -EINVAL; + + ret = __scmi_powercap_cap_set(ph, pi, domain_id, + pi->states[domain_id].last_pcap, + true); + } else { + ret = __scmi_powercap_cap_set(ph, pi, domain_id, 0, true); + } + + if (ret) + return ret; + + /* + * Update our internal state to reflect final platform state: the SCMI + * server could have ignored a disable request and kept enforcing some + * powercap limit requested by other agents. + */ + ret = scmi_powercap_cap_get(ph, domain_id, &power_cap); + if (!ret) + pi->states[domain_id].enabled = !!power_cap; + + return ret; +} + +static int scmi_powercap_cap_enable_get(const struct scmi_protocol_handle *ph, + u32 domain_id, bool *enable) +{ + int ret; + u32 power_cap; + struct powercap_info *pi = ph->get_priv(ph); + + *enable = true; + if (PROTOCOL_REV_MAJOR(pi->version) < 0x2) + return 0; + + /* + * Report always real platform state; platform could have ignored + * a previous disable request. Default true on any error. + */ + ret = scmi_powercap_cap_get(ph, domain_id, &power_cap); + if (!ret) + *enable = !!power_cap; + + /* Update internal state with current real platform state */ + pi->states[domain_id].enabled = *enable; + + return 0; +} + static const struct scmi_powercap_proto_ops powercap_proto_ops = { .num_domains_get = scmi_powercap_num_domains_get, .info_get = scmi_powercap_dom_info_get, .cap_get = scmi_powercap_cap_get, .cap_set = scmi_powercap_cap_set, + .cap_enable_set = scmi_powercap_cap_enable_set, + .cap_enable_get = scmi_powercap_cap_enable_get, .pai_get = scmi_powercap_pai_get, .pai_set = scmi_powercap_pai_set, .measurements_get = scmi_powercap_measurements_get, @@ -854,6 +941,11 @@ scmi_powercap_protocol_init(const struct scmi_protocol_handle *ph) if (!pinfo->powercaps) return -ENOMEM; + pinfo->states = devm_kcalloc(ph->dev, pinfo->num_domains, + sizeof(*pinfo->states), GFP_KERNEL); + if (!pinfo->states) + return -ENOMEM; + /* * Note that any failure in retrieving any domain attribute leads to * the whole Powercap protocol initialization failure: this way the @@ -868,15 +960,21 @@ scmi_powercap_protocol_init(const struct scmi_protocol_handle *ph) if (pinfo->powercaps[domain].fastchannels) scmi_powercap_domain_init_fc(ph, domain, &pinfo->powercaps[domain].fc_info); - } - pinfo->states = devm_kcalloc(ph->dev, pinfo->num_domains, - sizeof(*pinfo->states), GFP_KERNEL); - if (!pinfo->states) - return -ENOMEM; + /* Grab initial state when disable is supported. */ + if (PROTOCOL_REV_MAJOR(version) >= 0x2) { + ret = __scmi_powercap_cap_get(ph, + &pinfo->powercaps[domain], + &pinfo->states[domain].last_pcap); + if (ret) + return ret; - pinfo->version = version; + pinfo->states[domain].enabled = + !!pinfo->states[domain].last_pcap; + } + } + pinfo->version = version; return ph->set_priv(ph, pinfo); } diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 0ce5746a4470..e6fe4f73ffe6 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -629,11 +629,25 @@ struct scmi_powercap_info { * @num_domains_get: get the count of powercap domains provided by SCMI. * @info_get: get the information for the specified domain. * @cap_get: get the current CAP value for the specified domain. + * On SCMI platforms supporting powercap zone disabling, this could + * report a zero value for a zone where powercapping is disabled. * @cap_set: set the CAP value for the specified domain to the provided value; * if the domain supports setting the CAP with an asynchronous command * this request will finally trigger an asynchronous transfer, but, if * @ignore_dresp here is set to true, this call will anyway return * immediately without waiting for the related delayed response. + * Note that the powercap requested value must NOT be zero, even if + * the platform supports disabling a powercap by setting its cap to + * zero (since SCMI v3.2): there are dedicated operations that should + * be used for that. (@cap_enable_set/get) + * @cap_enable_set: enable or disable the powercapping on the specified domain, + * if supported by the SCMI platform implementation. + * Note that, by the SCMI specification, the platform can + * silently ignore our disable request and decide to enforce + * anyway some other powercap value requested by another agent + * on the system: for this reason @cap_get and @cap_enable_get + * will always report the final platform view of the powercaps. + * @cap_enable_get: get the current CAP enable status for the specified domain. * @pai_get: get the current PAI value for the specified domain. * @pai_set: set the PAI value for the specified domain to the provided value. * @measurements_get: retrieve the current average power measurements for the @@ -662,6 +676,10 @@ struct scmi_powercap_proto_ops { u32 *power_cap); int (*cap_set)(const struct scmi_protocol_handle *ph, u32 domain_id, u32 power_cap, bool ignore_dresp); + int (*cap_enable_set)(const struct scmi_protocol_handle *ph, + u32 domain_id, bool enable); + int (*cap_enable_get)(const struct scmi_protocol_handle *ph, + u32 domain_id, bool *enable); int (*pai_get)(const struct scmi_protocol_handle *ph, u32 domain_id, u32 *pai); int (*pai_set)(const struct scmi_protocol_handle *ph, u32 domain_id, From patchwork Wed May 31 15:20:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 101518 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2962796vqr; Wed, 31 May 2023 08:25:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7i8zAexZgHWdUIMEWV5+Y6wFnAphRBo5m5ZBfHsf86/elRRpMq/80gmJh0aWPJuayUa/8B X-Received: by 2002:a17:90b:1e4a:b0:253:38bf:9757 with SMTP id pi10-20020a17090b1e4a00b0025338bf9757mr4786732pjb.43.1685546712023; Wed, 31 May 2023 08:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685546712; cv=none; d=google.com; s=arc-20160816; b=0gM6/daT9Ifyd1EhShzmxuApa4FmwQG/TZi3R+B3kdzJuB7Ti5qpmYV0ssaBLFBDMi aKBozN5tNuJMyt2vpq6Y+l8fst0NLK7aWUXg/ZiROnDvsZDcpSAJwM5Lj78e2fWcjKJa ucGTAnFuN5CzmX13bSrC6bG567P956tJI06hFXxzXWZp9h+VDp5+XpnVV9Ekz8SXEM5x yaJJLK0rtNnmMEHa/7nOLs6ISpJYo6NVEl67z+ZnDkb1IBvY07ZgLBmHoyCR/dyHLODa g9TtMGNwZBiliGLozbetLkpTDwXXxaiWGpfsSDeYat2fQfwEj6LERNZaoBToPtTYA4py XeLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Q2bo6+FZmddda8NS389RVcTXmbnGw/tDUKHMc88I73k=; b=zwZCung7mWZbN2IBssQ5EL5LT4C53aFLjC2+9vTSXP7XVzPhNE24EuNOfdM8FD5Wb2 ZGxbV5s+TfQePkTgQuMTdBlp4KoAbJVCMv0VG9slz3LrznJJX6wwl5sKiRfU6qVGvMxj jgkWFCkIsvQfiQ1DQBgmfNIL1lP1nFZ4ZgvN1FrUSsi0xi9rcwoQ43pGxB6t/FB09ozy l4HLlMlLxlHg26Z+9uU2qks4k57rZo1VQMYnSvNMLXPh2IqtltKm1ZkjU7HKLcFGzX60 XpElxDB3uRJB8nB9NZjjBXRd4HMzUrxeozAKDruxCw/7C44Uy15rbyg4YEFdUcDqrpNw OQnA== 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qe10-20020a17090b4f8a00b0023d22d0f0fdsi1217456pjb.19.2023.05.31.08.24.58; Wed, 31 May 2023 08:25:11 -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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234604AbjEaPVp (ORCPT + 99 others); Wed, 31 May 2023 11:21:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234420AbjEaPVR (ORCPT ); Wed, 31 May 2023 11:21:17 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B7E07C0; Wed, 31 May 2023 08:21:16 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D675B1756; Wed, 31 May 2023 08:22:01 -0700 (PDT) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8537A3F663; Wed, 31 May 2023 08:21:14 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Cc: 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, Cristian Marussi , "Rafael J . Wysocki" Subject: [PATCH v3 3/3] powercap: arm_scmi: Add support for disabling powercaps on a zone Date: Wed, 31 May 2023 16:20:39 +0100 Message-Id: <20230531152039.2363181-4-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230531152039.2363181-1-cristian.marussi@arm.com> References: <20230531152039.2363181-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767423829111315328?= X-GMAIL-MSGID: =?utf-8?q?1767423829111315328?= Add support to disable/enable powercapping on a zone. Acked-by: Rafael J. Wysocki Signed-off-by: Cristian Marussi --- v2 --> v3 - rebased on v6.4-rc4 - added Acked-by --- drivers/powercap/arm_scmi_powercap.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/powercap/arm_scmi_powercap.c b/drivers/powercap/arm_scmi_powercap.c index 05d0e516176a..5231f6d52ae3 100644 --- a/drivers/powercap/arm_scmi_powercap.c +++ b/drivers/powercap/arm_scmi_powercap.c @@ -70,10 +70,26 @@ static int scmi_powercap_get_power_uw(struct powercap_zone *pz, return 0; } +static int scmi_powercap_zone_enable_set(struct powercap_zone *pz, bool mode) +{ + struct scmi_powercap_zone *spz = to_scmi_powercap_zone(pz); + + return powercap_ops->cap_enable_set(spz->ph, spz->info->id, mode); +} + +static int scmi_powercap_zone_enable_get(struct powercap_zone *pz, bool *mode) +{ + struct scmi_powercap_zone *spz = to_scmi_powercap_zone(pz); + + return powercap_ops->cap_enable_get(spz->ph, spz->info->id, mode); +} + static const struct powercap_zone_ops zone_ops = { .get_max_power_range_uw = scmi_powercap_get_max_power_range_uw, .get_power_uw = scmi_powercap_get_power_uw, .release = scmi_powercap_zone_release, + .set_enable = scmi_powercap_zone_enable_set, + .get_enable = scmi_powercap_zone_enable_get, }; static void scmi_powercap_normalize_cap(const struct scmi_powercap_zone *spz,