From patchwork Wed May 4 09:36:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cristian Marussi X-Patchwork-Id: 12837588 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4650C433EF for ; Wed, 4 May 2022 09:52:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=N9bLTBJubYcq19MuSLMBfHC8JyUerCT8r8dYOLUzuKw=; b=l5LBG/KgbEwWqw SoJOzvcFTfuK07qLpxgvpOms7ZoXaOnQ5gVzoutevd88s9lb5uaCHk8Vq24zZFQ5D7+O6OX2sh/HH 8Uqq7jN1EbVbnPgzkuQvaAMkIEhVpIyi9MnLztfHibwlTRbb8N7m/pBw9NnfptzHrUaYJQUj43Rjj DGWwa3W80yb4YWZnQxFL403IwQJhpqn/sa+kmLM3Y/bQvbA8t2XFtaFFeQj1iRIbxcCfllPqTYbNs DWEqtOqrfpPFINvmJYveRxhmEk+G4L2WP1w6RB1RyR7cYIOUbstLaVwtFJ5Ls+NHfXbIvNHNiOJBY UFY01demMIu0593x89kQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmBf8-00A3Zs-G1; Wed, 04 May 2022 09:51:14 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmBRA-009w9o-NH for linux-arm-kernel@lists.infradead.org; Wed, 04 May 2022 09:36:52 +0000 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 035EB1516; Wed, 4 May 2022 02:36:48 -0700 (PDT) Received: from e120937-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6A4333FA50; Wed, 4 May 2022 02:36:46 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, Jonathan.Cameron@Huawei.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, daniel.lezcano@linaro.org, tarek.el-sherbiny@arm.com, adrian.slatineanu@arm.com, souvik.chakravarty@arm.com, Cristian Marussi Subject: [PATCH 4/7] firmware: arm_scmi: Add SCMIv3.1 Powercap FastChannels support Date: Wed, 4 May 2022 10:36:06 +0100 Message-Id: <20220504093609.3077646-5-cristian.marussi@arm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220504093609.3077646-1-cristian.marussi@arm.com> References: <20220504093609.3077646-1-cristian.marussi@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220504_023648_904938_68978E25 X-CRM114-Status: GOOD ( 15.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add SCMIv3.1 Powercap protocol FastChannel support using common helpers provided by the SCMI core with scmi_proto_helpers_ops operations. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/powercap.c | 169 +++++++++++++++++++++------ include/linux/scmi_protocol.h | 2 + 2 files changed, 138 insertions(+), 33 deletions(-) diff --git a/drivers/firmware/arm_scmi/powercap.c b/drivers/firmware/arm_scmi/powercap.c index 7f2dcb944c4e..314c89bbd3d6 100644 --- a/drivers/firmware/arm_scmi/powercap.c +++ b/drivers/firmware/arm_scmi/powercap.c @@ -7,6 +7,7 @@ #define pr_fmt(fmt) "SCMI Notifications POWERCAP - " fmt +#include #include #include @@ -26,6 +27,12 @@ enum scmi_powercap_protocol_cmd { POWERCAP_DESCRIBE_FASTCHANNEL = 0xc, }; +enum { + POWERCAP_FC_CAP, + POWERCAP_FC_PAI, + POWERCAP_FC_MAX, +}; + struct scmi_msg_resp_powercap_domain_attributes { __le32 attributes; #define SUPPORTS_POWERCAP_CAP_CHANGE_NOTIFY(x) ((x) & BIT(31)) @@ -35,6 +42,7 @@ struct scmi_msg_resp_powercap_domain_attributes { #define SUPPORTS_POWERCAP_CAP_CONFIGURATION(x) ((x) & BIT(27)) #define SUPPORTS_POWERCAP_MONITORING(x) ((x) & BIT(26)) #define SUPPORTS_POWERCAP_PAI_CONFIGURATION(x) ((x) & BIT(25)) +#define SUPPORTS_POWERCAP_FASTCHANNELS(x) ((x) & BIT(22)) #define POWERCAP_POWER_UNIT(x) \ (FIELD_GET(GENMASK(24, 23), (x))) #define SUPPORTS_POWER_UNITS_MW(x) \ @@ -186,6 +194,8 @@ scmi_powercap_domain_attributes_get(const struct scmi_protocol_handle *ph, SUPPORTS_POWER_UNITS_MW(flags); dom_info->powercap_scale_uw = SUPPORTS_POWER_UNITS_UW(flags); + dom_info->fastchannels = + SUPPORTS_POWERCAP_FASTCHANNELS(flags); strscpy(dom_info->name, resp->name, SCMI_MAX_STR_SIZE); @@ -265,15 +275,11 @@ scmi_powercap_dom_info_get(const struct scmi_protocol_handle *ph, u32 domain_id) return pi->powercaps + domain_id; } -static int scmi_powercap_cap_get(const struct scmi_protocol_handle *ph, - u32 domain_id, u32 *power_cap) +static int scmi_powercap_xfer_cap_get(const struct scmi_protocol_handle *ph, + u32 domain_id, u32 *power_cap) { int ret; struct scmi_xfer *t; - struct powercap_info *pi = ph->get_priv(ph); - - if (!power_cap || domain_id >= pi->num_domains) - return -EINVAL; ret = ph->xops->xfer_get_init(ph, POWERCAP_CAP_GET, sizeof(u32), sizeof(u32), &t); @@ -290,20 +296,31 @@ static int scmi_powercap_cap_get(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_get(const struct scmi_protocol_handle *ph, + u32 domain_id, 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); + return 0; + } + + return scmi_powercap_xfer_cap_get(ph, domain_id, power_cap); +} + +static int scmi_powercap_xfer_cap_set(const struct scmi_protocol_handle *ph, + const struct scmi_powercap_info *pc, + u32 power_cap, bool ignore_dresp) { int ret; struct scmi_xfer *t; struct scmi_msg_powercap_set_cap_or_pai *msg; - 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; ret = ph->xops->xfer_get_init(ph, POWERCAP_CAP_SET, sizeof(*msg), 0, &t); @@ -311,7 +328,7 @@ static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph, return ret; msg = t->tx.buf; - msg->domain = cpu_to_le32(domain_id); + msg->domain = cpu_to_le32(pc->id); msg->flags = cpu_to_le32(!!pc->async_powercap_cap_set << 1 | !!ignore_dresp); msg->value = cpu_to_le32(power_cap); @@ -324,10 +341,10 @@ static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph, struct scmi_msg_resp_powercap_cap_set_complete *resp; resp = t->rx.buf; - if (le32_to_cpu(resp->domain) == domain_id) + if (le32_to_cpu(resp->domain) == pc->id) dev_dbg(ph->dev, "Powercap ID %d CAP set async to %u\n", - domain_id, + pc->id, get_unaligned_le32(&resp->power_cap)); else ret = -EPROTO; @@ -338,16 +355,35 @@ static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph, return ret; } -static int scmi_powercap_pai_get(const struct scmi_protocol_handle *ph, - u32 domain_id, u32 *pai) +static int scmi_powercap_cap_set(const struct scmi_protocol_handle *ph, + u32 domain_id, u32 power_cap, + bool ignore_dresp) { - int ret; - struct scmi_xfer *t; - struct powercap_info *pi = ph->get_priv(ph); + const struct scmi_powercap_info *pc; - if (!pai || domain_id >= pi->num_domains) + 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->fc_info && pc->fc_info[POWERCAP_FC_CAP].set_addr) { + struct scmi_fc_info *fci = &pc->fc_info[POWERCAP_FC_CAP]; + + iowrite32(power_cap, fci->set_addr); + ph->hops->fastchannel_db_ring(fci->set_db); + return 0; + } + + return scmi_powercap_xfer_cap_set(ph, pc, power_cap, ignore_dresp); +} + +static int scmi_powercap_xfer_pai_get(const struct scmi_protocol_handle *ph, + u32 domain_id, u32 *pai) +{ + int ret; + struct scmi_xfer *t; + ret = ph->xops->xfer_get_init(ph, POWERCAP_PAI_GET, sizeof(u32), sizeof(u32), &t); if (ret) @@ -363,18 +399,30 @@ static int scmi_powercap_pai_get(const struct scmi_protocol_handle *ph, return ret; } -static int scmi_powercap_pai_set(const struct scmi_protocol_handle *ph, - u32 domain_id, u32 pai) +static int scmi_powercap_pai_get(const struct scmi_protocol_handle *ph, + u32 domain_id, u32 *pai) +{ + struct scmi_powercap_info *dom; + struct powercap_info *pi = ph->get_priv(ph); + + if (!pai || domain_id >= pi->num_domains) + return -EINVAL; + + dom = pi->powercaps + domain_id; + if (dom->fc_info && dom->fc_info[POWERCAP_FC_PAI].get_addr) { + *pai = ioread32(dom->fc_info[POWERCAP_FC_PAI].get_addr); + return 0; + } + + return scmi_powercap_xfer_pai_get(ph, domain_id, pai); +} + +static int scmi_powercap_xfer_pai_set(const struct scmi_protocol_handle *ph, + u32 domain_id, u32 pai) { int ret; struct scmi_xfer *t; struct scmi_msg_powercap_set_cap_or_pai *msg; - const struct scmi_powercap_info *pc; - - pc = scmi_powercap_dom_info_get(ph, domain_id); - if (!pc || !pc->powercap_pai_config || !pai || - pai < pc->min_pai || pai > pc->max_pai) - return -EINVAL; ret = ph->xops->xfer_get_init(ph, POWERCAP_PAI_SET, sizeof(*msg), 0, &t); @@ -392,6 +440,27 @@ static int scmi_powercap_pai_set(const struct scmi_protocol_handle *ph, return ret; } +static int scmi_powercap_pai_set(const struct scmi_protocol_handle *ph, + u32 domain_id, u32 pai) +{ + const struct scmi_powercap_info *pc; + + pc = scmi_powercap_dom_info_get(ph, domain_id); + if (!pc || !pc->powercap_pai_config || !pai || + pai < pc->min_pai || pai > pc->max_pai) + return -EINVAL; + + if (pc->fc_info && pc->fc_info[POWERCAP_FC_PAI].set_addr) { + struct scmi_fc_info *fci = &pc->fc_info[POWERCAP_FC_PAI]; + + iowrite32(pai, fci->set_addr); + ph->hops->fastchannel_db_ring(fci->set_db); + return 0; + } + + return scmi_powercap_xfer_pai_set(ph, domain_id, pai); +} + static int scmi_powercap_measurements_get(const struct scmi_protocol_handle *ph, u32 domain_id, u32 *average_power, u32 *pai) @@ -468,6 +537,36 @@ static const struct scmi_powercap_proto_ops powercap_proto_ops = { .measurements_threshold_get = scmi_powercap_measurements_threshold_get, }; +static void scmi_powercap_domain_init_fc(const struct scmi_protocol_handle *ph, + u32 domain, struct scmi_fc_info **p_fc) +{ + struct scmi_fc_info *fc; + + fc = devm_kcalloc(ph->dev, POWERCAP_FC_MAX, sizeof(*fc), GFP_KERNEL); + if (!fc) + return; + + ph->hops->fastchannel_init(ph, POWERCAP_DESCRIBE_FASTCHANNEL, + POWERCAP_CAP_SET, 4, domain, + &fc[POWERCAP_FC_CAP].set_addr, + &fc[POWERCAP_FC_CAP].set_db); + + ph->hops->fastchannel_init(ph, POWERCAP_DESCRIBE_FASTCHANNEL, + POWERCAP_CAP_GET, 4, domain, + &fc[POWERCAP_FC_CAP].get_addr, NULL); + + ph->hops->fastchannel_init(ph, POWERCAP_DESCRIBE_FASTCHANNEL, + POWERCAP_PAI_SET, 4, domain, + &fc[POWERCAP_FC_PAI].set_addr, + &fc[POWERCAP_FC_PAI].set_db); + + ph->hops->fastchannel_init(ph, POWERCAP_DESCRIBE_FASTCHANNEL, + POWERCAP_PAI_GET, 4, domain, + &fc[POWERCAP_FC_PAI].get_addr, NULL); + + *p_fc = fc; +} + static int scmi_powercap_notify(const struct scmi_protocol_handle *ph, u32 domain, int message_id, bool enable) { @@ -681,6 +780,10 @@ scmi_powercap_protocol_init(const struct scmi_protocol_handle *ph) ret = scmi_powercap_domain_attributes_get(ph, pinfo, domain); if (ret) return ret; + + if (pinfo->powercaps[domain].fastchannels) + scmi_powercap_domain_init_fc(ph, domain, + &pinfo->powercaps[domain].fc_info); } pinfo->domain_thresholds = devm_kcalloc(ph->dev, pinfo->num_domains, diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 0216f70d57a8..6f24715ca2fd 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -600,6 +600,7 @@ struct scmi_powercap_info { bool powercap_pai_config; bool powercap_scale_mw; bool powercap_scale_uw; + bool fastchannels; char name[SCMI_MAX_STR_SIZE]; unsigned int min_pai; unsigned int max_pai; @@ -611,6 +612,7 @@ struct scmi_powercap_info { unsigned int accuracy; #define SCMI_POWERCAP_ROOT_ZONE_ID 0xFFFFFFFFUL unsigned int parent_id; + struct scmi_fc_info *fc_info; }; /**