From patchwork Mon Jan 23 14:26: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: 47171 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1643512wrn; Mon, 23 Jan 2023 06:40:51 -0800 (PST) X-Google-Smtp-Source: AMrXdXtHPO16HnjEq2p3Oi3D0/q9utFaVKRGmpTzwApaU+h3MeQ8cMQChT6XrBJjj45iIcSKJObJ X-Received: by 2002:a17:907:2159:b0:849:e96f:521b with SMTP id rk25-20020a170907215900b00849e96f521bmr21763376ejb.32.1674484851520; Mon, 23 Jan 2023 06:40:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674484851; cv=none; d=google.com; s=arc-20160816; b=QD+3/1naQeuMUt9YwOWUrxX4NsVmgEOwjC2GAyzjOBNAx+Pm7Jqo6iDhcdZ4NKb6XI XFGhWk2vM6EL4hLRUCc+CAQ4alLIDviWiuSysK4eCnbuKAF3Lz9kXvw7c2GstfZivgy5 tksrwKEMokWdjHsBAWzgLQ+YLSzivP2+mYzNQ6WJg1CCTmHqVdF0NU27yRyk+giE2VbG p+Gm5uW3yQBIPiUpobhvwy5e2JQhN9zVqG3eLoqPFaK2TpPUwLlGaNDDNrWBW1LWln3m WjRDzZ+UMPzICoXV9uTMyUEP7hEGXYMA/Xeqtv5mdXME5j57Cj2g+mthYFsCNtOYhZSq r5nQ== 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=tLKd5zXKu3JtvB9zLHm5bocpmJ0iCR7wjd4eXqakDBc=; b=Re3lUBYOWnZ5m47Bn/SC7EzSqnzekDRxZRxl+GABBEX/t6I35sG5vKkbhcfu6wurNh /VP0gH6xy2Uo0G76ajs6QENxJTxTPl1QeZEDi189qpkuYWqypJjAGX/5QHDiCJHYQq6X BS0jZ8srMYXxcaU/tvk4b5MFxawHJkZ4dzfzEtczQxr84FH4fkX3DvZ0n4e3sRlKZTBq r/3WvUHJRtkbfUTSjTkOnDA4fQyqoNan3pPcHCJrwZnY1vC7tuDtmofXVDD8z+5Sx8Hx AMLlPnrHqYxeO/ftjpU6MlfP06ZFyznhE6uVMFayzJmuZmRFy7J2gJcvUVCxabjlJ7vO RFUw== 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 xj1-20020a170906db0100b007add5af39f6si47060036ejb.929.2023.01.23.06.40.26; Mon, 23 Jan 2023 06:40:51 -0800 (PST) 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 S232306AbjAWO1Q (ORCPT + 99 others); Mon, 23 Jan 2023 09:27:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231287AbjAWO1O (ORCPT ); Mon, 23 Jan 2023 09:27:14 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 969E623DA5; Mon, 23 Jan 2023 06:27:13 -0800 (PST) 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 10F0C143D; Mon, 23 Jan 2023 06:27:55 -0800 (PST) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9B8353F64C; Mon, 23 Jan 2023 06:27:11 -0800 (PST) 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, 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 1/3] firmware: arm_scmi: Refactor powercap get/set helpers Date: Mon, 23 Jan 2023 14:26:38 +0000 Message-Id: <20230123142640.1895975-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123142640.1895975-1-cristian.marussi@arm.com> References: <20230123142640.1895975-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 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?1755824627840297296?= X-GMAIL-MSGID: =?utf-8?q?1755824627840297296?= Refactor SCMI powercap internal get/set helpers. Signed-off-by: Cristian Marussi --- 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 Mon Jan 23 14:26: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: 47172 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1643546wrn; Mon, 23 Jan 2023 06:40:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXsDfsf528hN1RNdR78HLzPnlkNdqgXdierpP24VisQaI31xdklJuOydcGun1soApi/tT1zO X-Received: by 2002:a05:6402:14d0:b0:498:1995:ac54 with SMTP id f16-20020a05640214d000b004981995ac54mr23915406edx.40.1674484857471; Mon, 23 Jan 2023 06:40:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674484857; cv=none; d=google.com; s=arc-20160816; b=e0B00piMT9EEzYWHQzXFtwvKfU0azLkUQGmxbtbfskb07MLQLTP+DuYtyRv0rD1euf hzIInbaIvr2Z613/DnJcwTvhEVf5guU1kHt+GRtptGTKWyk/HbaXQ5bLzPTxSjiUazuj qyf3mu0mXSwdqcoWZ2Z5MzBLbGhCCpIxU7oboYADurrFFgfVDPUuDWbfkUHbx6NQeart 1X3QcgnKloWCQEtR3I5aql5ZEWtdqBqkOqWNOjSGZhGA0mmpdAUqBFigzegSryid3mqL CV5dnF1nu+5HBng2tIdgibw4a6cLhEEP4P6qKWtvDhI6az/s72Ok+VFFRcVxKnMhoWg6 gidQ== 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=JlU+mrtArj2xznRUk/rImI5X+WIeSP6aZ8MBdhuvXPU=; b=NjI/DewPzd16tU3zOd2M+Zo+qc7Bj2R8kPSxtYD20XWqEGYtt473JABQYOs3WeEcBA ndv7VzplX8//MhkNTJfUUDoqI4sMVqtFSTXEozKR9wkW9iBC++1QGkgG748fp88UisIL yvV67oakWiT9XZpq5SfPCJkl8cy1ZmQAwdDv8NUKRsZfYD2vHzanzvL0MShyEepnBQap c1TAJwyD78cnNHTioNKIpcf1JvVdpWhVpYelt80+XmR6ciw0EPX218I3Ez7mxA37Amiz HyBnfzStFQ5YER92bS5nQ1JYDGMM7VmYBgVg/wAULTJR9MdxUOMs4eaKtH4ktSquXRU7 fDYg== 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 r10-20020a05640251ca00b00484ae4dfc25si41522985edd.62.2023.01.23.06.40.33; Mon, 23 Jan 2023 06:40:57 -0800 (PST) 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 S232315AbjAWO1S (ORCPT + 99 others); Mon, 23 Jan 2023 09:27:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbjAWO1Q (ORCPT ); Mon, 23 Jan 2023 09:27:16 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 86CFE28852; Mon, 23 Jan 2023 06:27:15 -0800 (PST) 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 063FA1474; Mon, 23 Jan 2023 06:27:57 -0800 (PST) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 90A893F64C; Mon, 23 Jan 2023 06:27:13 -0800 (PST) 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, 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 2/3] firmware: arm_scmi: Add Powercap protocol enable support Date: Mon, 23 Jan 2023 14:26:39 +0000 Message-Id: <20230123142640.1895975-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123142640.1895975-1-cristian.marussi@arm.com> References: <20230123142640.1895975-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 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?1755824634234240107?= X-GMAIL-MSGID: =?utf-8?q?1755824634234240107?= 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. Signed-off-by: Cristian Marussi --- 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..e11a7460c1de 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 Mon Jan 23 14:26:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 47173 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1643656wrn; Mon, 23 Jan 2023 06:41:09 -0800 (PST) X-Google-Smtp-Source: AMrXdXtAENEFKrbBPPZU/TNxOonXjcTQIkltunh6NyHpb0e+6+ldrdLUMmcXk+L5qxXH3UnK+D1v X-Received: by 2002:a17:906:a09:b0:7af:1139:de77 with SMTP id w9-20020a1709060a0900b007af1139de77mr31504373ejf.4.1674484869032; Mon, 23 Jan 2023 06:41:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674484869; cv=none; d=google.com; s=arc-20160816; b=zOkT5Ti0H272GCX2+el9k8NFrl3Pit3B+26CmlLcH2b0YmGMuZ9k6k++wMI0wg2P0M ZvWUetPHoUISEKo/3a5YxS+9m+VJ6ZmoBjTMLbDYBdkZ50+En+JlEjsgRsBsj8yE8nOd 8Rc2x4PAcQKkSwrlL7//2S42lJ+zMO4qIuaC5rwFcNg4MgC9hoHO8Guc4TDGjXjjvHed 7QqNsRZDIUhbErsHNFVP03xuf7kudoyPLf9txUz5nSvnT9NhbaYqWLEtCsVgrsytdUOx WaXSLJwUBqjisyvTL5LnQfNvsPH+FI1qz70ZjoIso/I9D+SeZaNx8ZyCvTUw4WKary1P kLog== 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=5Sp2u+Kfi+Sdgr0NN0diHsLCgz3V/vsnAiKyNV3uXuw=; b=uGDpTJsG6x81zfgPyrcMYWRBeLon1hIlULrm2Yac4jVP7/mtBSjS3fYMeJjZgs3sCD gzI8+g86NHSDEmzllatQ08OhQWFZeW7F8wCWd2yq4BbmZt36t8oHXuWSNq8fUyjAK0/f wTW2/QcRBEI6yO0zIrpaKLwSuVLR1zuDo6okGEViAlSYI6mm0+YbPH64jE5JmTdwOKZE r0+fFjSLasEAZ6v8jU7unI/NGhVThfMQgeXbqsmdPPduYQA1nErPNX8AuOhkaCEZKQbP Aza+OOZqPuwjrEqBZAlqDYY5MlDoQMlpKbl4zpk6pY7IVEnmAv9uHWs0FFiWV2Q+DQVj XUxw== 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 qk41-20020a1709077fa900b0086f53c24da4si30240367ejc.635.2023.01.23.06.40.45; Mon, 23 Jan 2023 06:41:09 -0800 (PST) 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 S232334AbjAWO1V (ORCPT + 99 others); Mon, 23 Jan 2023 09:27:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232311AbjAWO1S (ORCPT ); Mon, 23 Jan 2023 09:27:18 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9791E24108; Mon, 23 Jan 2023 06:27:17 -0800 (PST) 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 18DD9150C; Mon, 23 Jan 2023 06:27:59 -0800 (PST) Received: from e120937-lin.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 857193F64C; Mon, 23 Jan 2023 06:27:15 -0800 (PST) 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, 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 3/3] powercap: arm_scmi: Add support for disabling powercaps on a zone Date: Mon, 23 Jan 2023 14:26:40 +0000 Message-Id: <20230123142640.1895975-4-cristian.marussi@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230123142640.1895975-1-cristian.marussi@arm.com> References: <20230123142640.1895975-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 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?1755824645957521231?= X-GMAIL-MSGID: =?utf-8?q?1755824645957521231?= Add support to disable/enable powercapping on a zone. Cc: "Rafael J. Wysocki" Signed-off-by: Cristian Marussi --- 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,