mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Philip Radford <philip.radford@arm.com>
To: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org,
	linux-pm@vger.kernel.org
Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com,
	f.fainelli@gmail.com, vincent.guittot@linaro.org,
	etienne.carriere@st.com, peng.fan@oss.nxp.com,
	michal.simek@amd.com, quic_sibis@quicinc.com,
	dan.carpenter@linaro.org, d-gole@ti.com,
	souvik.chakravarty@arm.com,
	Philip Radford <philip.radford@arm.com>
Subject: [PATCH v10 13/13] powercap: arm_scmi: Synthetic zone enable/disable
Date: Tue,  3 Nov 2026 23:10:07 +0000	[thread overview]
Message-ID: <20261103231007.537082-14-philip.radford@arm.com> (raw)
In-Reply-To: <20261103231007.537082-1-philip.radford@arm.com>

The synthetic instance root contols the same set of top-level SCMI domains
already handled by the control-type enable/disable helpers previously
introduced.

Add synthetic zone enabled attribute to the existing per-instance helpers
instead of duplicating the enable-state tracking and rollback logic.

Signed-off-by: Philip Radford <philip.radford@arm.com>
---
V9->V10
- add synthetic-root enable helper with per-zone state snapshot and roolback
- abort synthetic-root enables writes if any root child zone is not configurable
- restore each changed child zone to its previous state on failure
---
 drivers/powercap/arm_scmi_powercap.c | 104 +++++++++++++++++++++++++++
 1 file changed, 104 insertions(+)

diff --git a/drivers/powercap/arm_scmi_powercap.c b/drivers/powercap/arm_scmi_powercap.c
index d0255fd42007..0e86ad605189 100644
--- a/drivers/powercap/arm_scmi_powercap.c
+++ b/drivers/powercap/arm_scmi_powercap.c
@@ -489,10 +489,114 @@ static int instance_root_get_constraint(struct powercap_zone *pz, int cid, u64 *
 	return -EOPNOTSUPP;
 }
 
+static int scmi_powercap_set_root_children_enable_state(struct scmi_powercap_root *pr,
+							bool mode)
+{
+	struct scmi_powercap_zone_state *states;
+	struct scmi_powercap_zone *spz;
+	int num_zones = 0, nr_states = 0;
+	int i, ret = 0;
+
+	for (i = 0; i < pr->num_zones; i++) {
+		spz = &pr->spzones[i];
+
+		if (scmi_powercap_is_control_type_child(spz))
+			num_zones++;
+	}
+
+	states = kcalloc(num_zones, sizeof(*states), GFP_KERNEL);
+	if (!states)
+		return -ENOMEM;
+
+	for (i = 0; i < pr->num_zones; i++) {
+		spz = &pr->spzones[i];
+
+		if (!scmi_powercap_is_control_type_child(spz))
+			continue;
+
+		if (!spz->info->cpli[0].cap_config) {
+			ret = -EOPNOTSUPP;
+			goto out_free;
+		}
+
+		states[nr_states].spz = spz;
+
+		ret = powercap_ops->cap_enable_get(spz->ph, spz->info->id,
+			&states[nr_states].prev_enabled);
+
+		if (ret)
+			goto out_free;
+
+		nr_states++;
+	}
+
+	for (i = 0; i < nr_states; i++) {
+		spz = states[i].spz;
+
+		if (states[i].prev_enabled == mode)
+			continue;
+
+		ret = powercap_ops->cap_enable_set(spz->ph, spz->info->id, mode);
+		if (ret)
+			goto revert;
+
+		states[i].changed = true;
+	}
+
+	pr->enabled = mode;
+	goto out_free;
+
+revert:
+	while (i--) {
+		spz = states[i].spz;
+
+		if (!states[i].changed)
+			continue;
+
+		powercap_ops->cap_enable_set(spz->ph, spz->info->id,
+			states[i].prev_enabled);
+	}
+
+out_free:
+	kfree(states);
+	return ret;
+}
+
+static int instance_root_set_enable(struct powercap_zone *pz, bool mode)
+{
+	struct scmi_powercap_root *pr = to_scmi_powercap_root(pz);
+	int ret;
+
+	mutex_lock(&scmi_powercap_roots_lock);
+	ret = scmi_powercap_set_root_children_enable_state(pr, mode);
+	mutex_unlock(&scmi_powercap_roots_lock);
+
+	return ret;
+}
+
+static int instance_root_get_enable(struct powercap_zone *pz, bool *mode)
+{
+	struct scmi_powercap_root *pr = to_scmi_powercap_root(pz);
+	int ret;
+
+	if (!mode)
+		return -EINVAL;
+
+	mutex_lock(&scmi_powercap_roots_lock);
+	ret = scmi_powercap_read_root_children_enable_state(pr, mode);
+	if (!ret)
+		pr->enabled = *mode;
+	mutex_unlock(&scmi_powercap_roots_lock);
+
+	return ret;
+}
+
 static const struct powercap_zone_ops instance_root_ops = {
 	.get_max_power_range_uw = scmi_powercap_get_max_power_range_uw,
 	.get_power_uw = instance_root_get_power_uw,
 	.release = instance_root_release,
+	.set_enable = instance_root_set_enable,
+	.get_enable = instance_root_get_enable,
 };
 
 static const struct powercap_zone_constraint_ops instance_root_const_ops = {
-- 
2.34.1


      parent reply	other threads:[~2026-11-03 23:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 23:09 [PATCH v10 00/13] Add support for SCMIv4.0 Powercap Extensions Philip Radford
2026-11-03 23:09 ` [PATCH v10 01/13] powercap: Add enable disable control-type Philip Radford
2026-11-03 23:09 ` [PATCH v10 02/13] firmware: arm_scmi: Add an optional custom parameter to fastchannel helpers Philip Radford
2026-11-03 23:09 ` [PATCH v10 03/13] firmware: arm_scmi: Refactor powercap domain layout Philip Radford
2026-11-03 23:09 ` [PATCH v10 04/13] firmware: arm_scmi: Add SCMIv4.0 Powercap basic support Philip Radford
2026-11-03 23:09 ` [PATCH v10 05/13] firmware: arm_scmi: Add SCMIv4.0 Powercap FCs support Philip Radford
2026-11-03 23:10 ` [PATCH v10 06/13] firmware: arm_scmi: Add SCMIV4.0 Powercap notifications support Philip Radford
2026-11-03 23:10 ` [PATCH v10 07/13] firmware: arm_scmi: Extend powercap report to include MAI Philip Radford
2026-11-03 23:10 ` [PATCH v10 08/13] include: trace: Add new parameter to trace_scmi_fc_call Philip Radford
2026-11-03 23:10 ` [PATCH v10 09/13] powercap: arm_scmi: Enable multiple constraints support Philip Radford
2026-11-03 23:10 ` [PATCH v10 10/13] firmware: arm_scmi: add Powercap MAI get/set support Philip Radford
2026-11-03 23:10 ` [PATCH v10 11/13] powercap: arm_scmi: Create synthetic parent node for multi-instance Philip Radford
2026-11-03 23:10 ` [PATCH v10 12/13] powercap: arm_scmi: Add get_power_uw to synthetic node Philip Radford
2026-11-03 23:10 ` Philip Radford [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261103231007.537082-14-philip.radford@arm.com \
    --to=philip.radford@arm.com \
    --cc=arm-scmi@vger.kernel.org \
    --cc=d-gole@ti.com \
    --cc=dan.carpenter@linaro.org \
    --cc=etienne.carriere@st.com \
    --cc=f.fainelli@gmail.com \
    --cc=james.quinlan@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=michal.simek@amd.com \
    --cc=peng.fan@oss.nxp.com \
    --cc=quic_sibis@quicinc.com \
    --cc=souvik.chakravarty@arm.com \
    --cc=sudeep.holla@arm.com \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®