From: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
To: daniel.lezcano@oss.qualcomm.com, rafael@kernel.org
Cc: Zhang Rui <rui.zhang@intel.com>,
Lukasz Luba <lukasz.luba@arm.com>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Anvesh Jain P <anvesh.p@oss.qualcomm.com>,
Ulf Hansson <ulf.hansson@oss.qualcomm.com>,
linux-pm@vger.kernel.org,
Daniel Lezcano <daniel.lezcano@kernel.org>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v1 03/12] thermal: core: Validate thermal zone aggregation descriptions
Date: Thu, 19 Nov 2026 10:46:45 +0100 [thread overview]
Message-ID: <20261119094706.3439040-4-daniel.lezcano@oss.qualcomm.com> (raw)
In-Reply-To: <20261119094706.3439040-1-daniel.lezcano@oss.qualcomm.com>
Add a private helper to validate aggregation descriptions before
coefficient initialization and publication. Introduce thermal_aggregation.c
and build it as part of thermal_sys when CONFIG_THERMAL_AGGREGATION
is enabled. Keep aggregation optional and independent of OF support. Check for nonempty entries, valid
source zones, and sources that have not started exiting. Registered
non-aggregated sources already have a temperature callback, so there
is no need to check it again.
Accept the destination operations and reject set_trips because an
aggregate temperature window cannot directly program hardware
thresholds on its individual sources.
Before initialization, use zero to identify unspecified coefficients.
Accept either a complete nonzero coefficient set or an all-zero set
requesting averaging defaults, and reject partial specification. Keep
this check in the validator. Do not apply the presence check after
initialization, where zero is valid for temperature calculation.
Reject aggregated sources because aggregations of aggregated zones are
not supported yet. Inspect each source under its zone lock and document
that callers must hold valid source references and preserve the validated
configuration. Validation does not acquire references or prevent removal.
Leave invocation to the subsequent aggregation initialization changes.
Signed-off-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
---
drivers/thermal/Kconfig | 8 +++
drivers/thermal/Makefile | 1 +
drivers/thermal/thermal_aggregation.c | 76 +++++++++++++++++++++++++++
3 files changed, 85 insertions(+)
create mode 100644 drivers/thermal/thermal_aggregation.c
diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig
index 810eeccedfba..b5185084eac1 100644
--- a/drivers/thermal/Kconfig
+++ b/drivers/thermal/Kconfig
@@ -17,6 +17,14 @@ menuconfig THERMAL
if THERMAL
+config THERMAL_AGGREGATION
+ bool "Thermal zone aggregation"
+ help
+ Allow thermal zones to calculate their temperature from multiple
+ existing thermal zones using signed coefficients and an offset.
+ This also enables discovery of multi-source zones in Device Tree.
+ If unsure, say N.
+
config THERMAL_NETLINK
bool "Thermal netlink management"
depends on NET
diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile
index 3b249195c088..d059ca528908 100644
--- a/drivers/thermal/Makefile
+++ b/drivers/thermal/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_THERMAL) += thermal_sys.o
thermal_sys-y += thermal_core.o thermal_sysfs.o
thermal_sys-y += thermal_trip.o thermal_helpers.o
thermal_sys-y += thermal_thresholds.o
+thermal_sys-$(CONFIG_THERMAL_AGGREGATION) += thermal_aggregation.o
# netlink interface to manage the thermal framework
thermal_sys-$(CONFIG_THERMAL_NETLINK) += thermal_netlink.o
diff --git a/drivers/thermal/thermal_aggregation.c b/drivers/thermal/thermal_aggregation.c
new file mode 100644
index 000000000000..f85f5a487d60
--- /dev/null
+++ b/drivers/thermal/thermal_aggregation.c
@@ -0,0 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/errno.h>
+
+#include "thermal_core.h"
+
+/**
+ * thermal_zone_aggregate_validate() - check an aggregation before initialization
+ * @aggregate: aggregation description to validate before coefficient initialization
+ * @ops: operations of the destination thermal zone
+ *
+ * The caller must hold valid references to the source zones and keep the entries
+ * stable. Take each source lock separately to inspect its parameters and state;
+ * the caller must not hold a thermal zone lock.
+ *
+ * Aggregations of aggregated zones are not supported yet: every source must be
+ * a registered, non-aggregated thermal zone. This also rejects
+ * a source whose parameters already reference this aggregation description.
+ * Source membership and non-aggregation must remain unchanged after validation.
+ * Validation does not acquire references or prevent subsequent source removal.
+ *
+ * Before initialization, zero denotes an unspecified coefficient. Either all
+ * coefficients must be supplied or all must be zero to request averaging
+ * defaults. This presence check must not be applied after initialization:
+ * zero is valid in the temperature calculation.
+ *
+ * Return: 0 on success, -EINVAL for an invalid description, partial coefficient
+ * specification, aggregated sources or destination set_trips,
+ * or -ENODEV for missing or exiting sources.
+ */
+static int __maybe_unused
+thermal_zone_aggregate_validate(struct thermal_zone_aggregate *aggregate,
+ const struct thermal_zone_device_ops *ops)
+{
+ unsigned int initialized = 0;
+ unsigned int i;
+
+ /* An aggregation needs a description and at least one source entry. */
+ if (!aggregate || !aggregate->entries || !aggregate->num_entries)
+ return -EINVAL;
+
+ /*
+ * Destination operations must exist, but cannot program hardware windows:
+ * aggregate temperature boundaries do not directly map to source thresholds.
+ */
+ if (!ops || ops->set_trips)
+ return -EINVAL;
+
+ for (i = 0; i < aggregate->num_entries; i++) {
+ const struct thermal_zone_aggregate_entry *entry = &aggregate->entries[i];
+ struct thermal_zone_device *source = entry->tz;
+
+ /* Reject unresolved sources before inspecting their zone state. */
+ if (IS_ERR_OR_NULL(source))
+ return -ENODEV;
+ /* Before initialization, zero requests a default contribution. */
+ initialized += entry->coefficient != 0;
+
+ guard(thermal_zone)(source);
+ /* A reference protects lifetime, but does not prevent source exit. */
+ if (source->state & TZ_STATE_FLAG_EXIT)
+ return -ENODEV;
+ /* Nested aggregation, including a direct self-dependency, is unsupported. */
+ if (source->tzp && source->tzp->aggregate)
+ return -EINVAL;
+ }
+
+ /*
+ * Require either a complete explicit combination or all-zero coefficients
+ * for averaging defaults; there is no defined default for a partial set.
+ */
+ if (initialized && initialized != aggregate->num_entries)
+ return -EINVAL;
+
+ return 0;
+}
--
2.43.0
next prev parent reply other threads:[~2026-11-19 9:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 9:46 [PATCH v1 00/12] thermal: Add multi-source thermal zone aggregation Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 01/12] thermal: core: Add thermal zone device reference helpers Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 02/12] thermal: core: Introduce private thermal zone aggregation structures Daniel Lezcano
2026-11-19 9:46 ` Daniel Lezcano [this message]
2026-11-19 9:46 ` [PATCH v1 04/12] thermal: core: Initialize thermal zone aggregation coefficients Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 05/12] thermal: core: Dispatch aggregate temperature reads Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 06/12] thermal: core: Calculate aggregated thermal zone temperatures Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 07/12] thermal: core: Initialize aggregation during zone registration Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 08/12] thermal: of: Separate zone parsing from sensor lookup Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 09/12] thermal: of: Track registered hardware temperature sources Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 10/12] thermal: of: Instantiate aggregates after their source zones Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 11/12] dt-bindings: thermal: Describe multi-source zone aggregation Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 12/12] thermal: testing: Add KUnit coverage for " Daniel Lezcano
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=20261119094706.3439040-4-daniel.lezcano@oss.qualcomm.com \
--to=daniel.lezcano@oss.qualcomm.com \
--cc=anvesh.p@oss.qualcomm.com \
--cc=daniel.lezcano@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=rui.zhang@intel.com \
--cc=ulf.hansson@oss.qualcomm.com \
/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