From: Karthik Poosa <karthik.poosa@intel.com>
To: intel-xe@lists.freedesktop.org
Cc: rodrigo.vivi@intel.com, anshuman.gupta@intel.com,
badal.nilawar@intel.com, raag.jadav@intel.com,
riana.tauro@intel.com, sk.anirban@intel.com,
mallesh.koujalagi@intel.com, soham.purkait@intel.com,
Karthik Poosa <karthik.poosa@intel.com>
Subject: [PATCH v2 4/5] drm/xe/hwmon: Decode CRI temperature registers as IEEE-754
Date: Wed, 2 Sep 2026 23:25:06 +0530 [thread overview]
Message-ID: <20260902175507.3910573-5-karthik.poosa@intel.com> (raw)
In-Reply-To: <20260902175507.3910573-1-karthik.poosa@intel.com>
CRI temperature registers encode package and VRAM temperatures as
IEEE-754 floating-point values. Decode these values before exposing
them through hwmon.
Use integer-based IEEE-754 decoding since kernel code does not use
floating-point operations and hwmon reports integer temperatures.
Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>
Assisted-by: GitHub Copilot; Model: MAI-Code-1.1-Flash
---
drivers/gpu/drm/xe/xe_hwmon.c | 81 +++++++++++++++++++++++++++++------
1 file changed, 67 insertions(+), 14 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
index 2a5d91fa3afa..639fdb09ab3e 100644
--- a/drivers/gpu/drm/xe/xe_hwmon.c
+++ b/drivers/gpu/drm/xe/xe_hwmon.c
@@ -1150,6 +1150,58 @@ xe_hwmon_temp_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)
}
}
+/**
+ * xe_hwmon_temperature_decode - Decode an IEEE-754 temperature register value
+ * @reg_val: The raw register value to decode
+ *
+ * IEEE-754 single-precision format:
+ *
+ * 31 30 23 22 0
+ * +--+-----------------------------+----------------------------+
+ * | S| exponent | fraction |
+ * +--+-----------------------------+----------------------------+
+ *
+ * value = (-1)^S * 1.fraction * 2^(exponent - 127)
+ *
+ * Return: 0 on success or an error if @reg_val is non-finite or cannot be
+ * represented in millidegrees Celsius.
+ */
+static int xe_hwmon_temperature_decode(u32 reg_val, long *temperature)
+{
+ u32 exponent = (reg_val >> 23) & 0xff;
+ u32 mantissa = reg_val & 0x7fffff;
+ s64 value;
+ int shift;
+
+ /* Exponent 0xff encodes infinity or NaN. */
+ if (exponent == 0xff)
+ return -EINVAL;
+
+ /* Subnormal values are smaller than one millidegree Celsius. */
+ if (!exponent) {
+ *temperature = 0;
+ return 0;
+ }
+
+ value = (s64)(mantissa | BIT(23)) * MILLIDEGREE_PER_DEGREE;
+ shift = exponent - 150;
+ if (shift >= 0) {
+ if (shift >= BITS_PER_LONG || value > (LONG_MAX >> shift))
+ return -ERANGE;
+ value <<= shift;
+ } else if (shift > -64) {
+ value >>= -shift;
+ } else {
+ value = 0;
+ }
+
+ if (reg_val & BIT(31))
+ value = -value;
+
+ *temperature = value;
+ return 0;
+}
+
static int
xe_hwmon_temp_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)
{
@@ -1159,26 +1211,27 @@ xe_hwmon_temp_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)
switch (attr) {
case hwmon_temp_input:
switch (channel) {
- case CHANNEL_PKG:
- case CHANNEL_VRAM:
- reg_val = xe_mmio_read32(mmio, xe_hwmon_get_reg(hwmon, REG_TEMP, channel));
-
- /* HW register value is in degrees Celsius, convert to millidegrees. */
- *val = REG_FIELD_GET(TEMP_MASK, reg_val) * MILLIDEGREE_PER_DEGREE;
- return 0;
case CHANNEL_MCTRL:
return get_mc_temp(hwmon, val);
case CHANNEL_PCIE:
return get_pcie_temp(hwmon, val);
+ case CHANNEL_PKG:
+ case CHANNEL_VRAM:
case CHANNEL_VRAM_N...CHANNEL_VRAM_N_MAX:
reg_val = xe_mmio_read32(mmio, xe_hwmon_get_reg(hwmon, REG_TEMP, channel));
- /*
- * This temperature format is 24 bit [31:8] signed integer and 8 bit
- * [7:0] fraction.
- */
- *val = (s32)(REG_FIELD_GET(TEMP_MASK_VRAM_N, reg_val)) *
- (REG_FIELD_GET(TEMP_SIGN_MASK, reg_val) ? -1 : 1) *
- MILLIDEGREE_PER_DEGREE;
+ if (hwmon->xe->info.platform >= XE_CRESCENTISLAND) {
+ return xe_hwmon_temperature_decode((u32)reg_val, val);
+ } else if (channel >= CHANNEL_VRAM_N) {
+ /*
+ * This temperature format is 24 bit [31:8] signed integer and 8 bit
+ * [7:0] fraction for platforms before CRI.
+ */
+ *val = (s32)REG_FIELD_GET(TEMP_MASK_VRAM_N, reg_val) *
+ (REG_FIELD_GET(TEMP_SIGN_MASK, reg_val) ? -1 : 1) *
+ MILLIDEGREE_PER_DEGREE;
+ } else {
+ *val = REG_FIELD_GET(TEMP_MASK, reg_val) * MILLIDEGREE_PER_DEGREE;
+ }
return 0;
default:
return -EOPNOTSUPP;
--
2.25.1
next prev parent reply other threads:[~2026-09-02 17:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 17:55 [PATCH v2 0/5] drm/xe/hwmon: Update hwmon thermal mailbox handling Karthik Poosa
2026-09-02 17:55 ` [PATCH v2 1/5] drm/xe/hwmon: Detect unavailable temperature sensors Karthik Poosa
2026-09-02 17:55 ` [PATCH v2 2/5] drm/xe/hwmon: Use VRAM temperature sensor count from thermal config on CRI Karthik Poosa
2026-09-02 18:10 ` sashiko-bot
2026-09-02 18:43 ` Rodrigo Vivi
2026-09-02 17:55 ` [PATCH v2 3/5] drm/xe/hwmon: Correct group selection for memory controller temperature Karthik Poosa
2026-09-02 18:17 ` sashiko-bot
2026-09-02 17:55 ` Karthik Poosa [this message]
2026-09-02 18:08 ` [PATCH v2 4/5] drm/xe/hwmon: Decode CRI temperature registers as IEEE-754 sashiko-bot
2026-09-02 17:55 ` [PATCH v2 5/5] drm/xe/hwmon: Disable memory controller and PCIe temperatures on CRI Karthik Poosa
2026-09-02 18:07 ` sashiko-bot
2026-09-03 6:11 ` Poosa, Karthik
2026-09-02 18:28 ` ✓ CI.KUnit: success for drm/xe/hwmon: Update hwmon thermal mailbox handling (rev2) Patchwork
2026-09-02 19:22 ` ✗ Xe.CI.BAT: failure " Patchwork
2026-09-03 9:37 ` ✗ Xe.CI.FULL: " Patchwork
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=20260902175507.3910573-5-karthik.poosa@intel.com \
--to=karthik.poosa@intel.com \
--cc=anshuman.gupta@intel.com \
--cc=badal.nilawar@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=mallesh.koujalagi@intel.com \
--cc=raag.jadav@intel.com \
--cc=riana.tauro@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=sk.anirban@intel.com \
--cc=soham.purkait@intel.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