From mboxrd@z Thu Jan 1 00:00:00 1970 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 C00D3C61DD6 for ; Wed, 2 Sep 2026 17:56:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6EC8510F302; Wed, 2 Sep 2026 17:56:56 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="JM+pqcPD"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id B551710F302 for ; Wed, 2 Sep 2026 17:56:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1788371815; x=1819907815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qkogBdMUZaLlxr1vJ7MgSWTk9UWhZQMYoV7jwcZ1H7A=; b=JM+pqcPDsu7LbuN4mXbRkc+UhEMtBoG/+3c5YdtKr4PR7I07BvopPHcR WV7006zcC8475eRVzCdBaEBhfS8qSYvS/nUjBK5APB6QrieAkoXaBNtIs TC+vTWOXcJYu1cubgMC8rG7V87sNS0aZxAiIVWmY8DEt71SxLhsayLzAO kuJgHsnXYKJf6GH+juNKRjHeZxDiNwOa0BIb577Ynnpyk9CASdfqLak0j 6x//peIZe7r4qkK6yM3RiVjUFMSPMVk6WUSG/ovDO4v2kQnMGgJ3vx6Gv LhINM0cn5DJ9su9VGigUsrVNZ/j7mpNDM+XCB/WlCdIJcJT5gaTNV5u0Y A==; X-CSE-ConnectionGUID: MHW6ZGNyQZ65+5s9VOhm9Q== X-CSE-MsgGUID: UjcqScEPRKGtsZ8z84u78g== X-IronPort-AV: E=McAfee;i="6800,10657,11894"; a="76393491" X-IronPort-AV: E=Sophos;i="6.25,258,1779174000"; d="scan'208";a="76393491" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2026 10:56:55 -0700 X-CSE-ConnectionGUID: FOb0KDjwQBm8YfcnMRjDVA== X-CSE-MsgGUID: Rxy2+b02R7yF2NIlaYP8cA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,258,1779174000"; d="scan'208";a="273638039" Received: from sinjan-super-server.iind.intel.com ([10.190.239.39]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2026 10:56:52 -0700 From: Karthik Poosa 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 Subject: [PATCH v2 4/5] drm/xe/hwmon: Decode CRI temperature registers as IEEE-754 Date: Wed, 2 Sep 2026 23:25:06 +0530 Message-Id: <20260902175507.3910573-5-karthik.poosa@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260902175507.3910573-1-karthik.poosa@intel.com> References: <20260902175507.3910573-1-karthik.poosa@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" 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 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