Linux-Next discussions
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Dave Airlie <airlied@redhat.com>, DRI <dri-devel@lists.freedesktop.org>
Cc: Dnyaneshwar Bhadane <dnyaneshwar.bhadane@intel.com>,
	Karthik Poosa <karthik.poosa@intel.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux Next Mailing List <linux-next@vger.kernel.org>,
	Mallesh Koujalagi <mallesh.koujalagi@intel.com>,
	Matthew Brost <matthew.brost@intel.com>,
	Matt Roper <matthew.d.roper@intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Vinay Belgaumkar <vinay.belgaumkar@intel.com>
Subject: linux-next: manual merge of the drm tree with the drm-xe-fixes tree
Date: Fri, 20 Nov 2026 15:07:41 +0000	[thread overview]
Message-ID: <awBiPWrQJAygBnaS@sirena.org.uk> (raw)

[-- Attachment #1: Type: text/plain, Size: 25754 bytes --]

Hi all,

Today's linux-next merge of the drm tree got a conflict in:

  drivers/gpu/drm/xe/xe_hwmon.c

between commits:

  94099304b80e8 ("drm/xe/hwmon: Fix pcode power limit handling")
  c9d8ef7f6835d ("drm/xe/hwmon: Decode mailbox temperature as sign-magnitude")
  d37dcdaa99b18 ("drm/xe/hwmon: Fix thermal sensor data handling")
  f2a144e9891b3 ("drm/xe/hwmon: Add helpers to validate thermal sensor readings")
  dbd199c775cbe ("drm/xe/hwmon: Handle unavailable memory controller sensors")
  808951ee16738 ("drm/xe/hwmon: Report errors using structured xe_log API")
  58417a6534dd3 ("drm/xe/hwmon: Propagate all hardware read errors")

from the drm-xe-fixes tree and commits:

  58c84a1dffe21 ("drm/xe/hwmon: Report errors using structured xe_log API")
  c5b502e43f7cd ("drm/xe/hwmon: Fix pcode power limit handling")
  1bbbd7d98fa58 ("drm/xe/hwmon: Decode mailbox temperature as sign-magnitude")
  ca6e33701de86 ("drm/xe/hwmon: Fix thermal sensor data handling")
  054805851f2e1 ("drm/xe/hwmon: Add helpers to validate thermal sensor readings")
  99ceaebb88894 ("drm/xe/hwmon: Handle unavailable memory controller sensors")
  8fdd3d4c55ecb ("drm/xe/hwmon: Detect unavailable PCIe thermal sensors")
  0d4033d899609 ("drm/xe/hwmon: Consolidate temperature sensor availability checks")
  87ce4876e3f50 ("drm/xe/hwmon: Cache temperature availability to reduce probe time")
  b6ccfa0bed5b7 ("drm/xe/hwmon: use CRI-specific package and VRAM temperature registers")
  993338420540a ("drm/xe/hwmon: Add platform-aware VRAM thermal channel support")
  24ec15d646179 ("drm/xe/hwmon: Decode CRI temperature registers as IEEE-754")
  ae4cd659d22dc ("drm/xe/hwmon: Update memory controller temperature offset for CRI")
  32b98ee8d317b ("drm/xe/hwmon: add PCIe temperature support for CRI")
  0dd554733ae8a ("drm/xe/hwmon: Simplify temperature channels config")
  a3d7376b9d671 ("drm/xe: Validate thermal sensor count before reads")
  4289dded4329b ("drm/xe/hwmon: Propagate all hardware read errors")
  72fde60e3ed74 ("drm/xe/hwmon: Use overflows_type() for temperature range check")
  a5b29fce26597 ("Merge tag 'drm-xe-next-2026-11-05' of https://gitlab.freedesktop.org/drm/xe/kernel into drm-next")

from the drm tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

diff --combined drivers/gpu/drm/xe/xe_hwmon.c
index daa3f61617a02,defe8aaca7c11..0000000000000
--- a/drivers/gpu/drm/xe/xe_hwmon.c
+++ b/drivers/gpu/drm/xe/xe_hwmon.c
@@@ -6,6 -6,7 +6,7 @@@
  #include <linux/hwmon-sysfs.h>
  #include <linux/hwmon.h>
  #include <linux/jiffies.h>
+ #include <linux/overflow.h>
  #include <linux/types.h>
  #include <linux/units.h>
  
@@@ -40,7 -41,11 +41,11 @@@ enum xe_hwmon_reg_operation 
  	REG_READ64,
  };
  
- #define MAX_VRAM_CHANNELS      (16)
+ #define MAX_VRAM_CHANNELS	80
+ #define FIXED_VRAM_CHANNELS	16
+ 
+ /* Each MSU enable bit maps to one VRAM subsystem of 4 channels. */
+ #define VRAM_CHANNELS_PER_MSU	4
  
  enum xe_hwmon_channel {
  	CHANNEL_CARD,
@@@ -49,6 -54,7 +54,7 @@@
  	CHANNEL_MCTRL,
  	CHANNEL_PCIE,
  	CHANNEL_VRAM_N,
+ 	/* Compile-time upper bound; actual channel count is hwmon->temp.vram_count */
  	CHANNEL_VRAM_N_MAX = CHANNEL_VRAM_N + MAX_VRAM_CHANNELS - 1,
  	CHANNEL_MAX,
  };
@@@ -102,8 -108,15 +108,15 @@@ enum sensor_attr_power 
  
  #define PWR_ATTR_TO_STR(attr)	(((attr) == hwmon_power_max) ? "PL1" : "PL2")
  
- /* Index of memory controller in READ_THERMAL_DATA output */
+ /* Sensor byte indices in READ_THERMAL_DATA output for BMG. */
  #define TEMP_INDEX_MCTRL	2
+ #define TEMP_INDEX_PCIE		10
+ #define BMG_G21_TEMP_INDEX_PCIE	8
+ 
+ /* Sensor byte indices in READ_THERMAL_DATA output for CRI. */
+ #define CRI_TEMP_INDEX_MCTRL	16
+ #define CRI_TEMP_MCTRL_COUNT	4
+ #define CRI_TEMP_INDEX_PCIE	20
  
  /* Mailbox sentinel reported for an unavailable temperature sensor */
  #define TEMP_MBX_INVALID	0xFF
@@@ -145,16 -158,22 +158,22 @@@ struct xe_hwmon_thermal_info 
  		/** @data: temperature limits as little-endian dwords */
  		__le32 data[DIV_ROUND_UP(TEMP_LIMIT_MAX, sizeof(u32))];
  	};
- 	/** @count: no of temperature sensors available for the platform */
+ 	/** @count: temperature sensors count from READ_THERMAL_CONFIG */
  	u8 count;
+ 	/** @vram_count: exclusive upper bound for VRAM temperature channel indices */
+ 	u8 vram_count;
+ 	/** @available: temperature sensor availability cached at registration */
+ 	bool available[CHANNEL_MAX];
+ 	/** @msu_mask: VRAM subsystem enable mask read from MMIO */
+ 	u32 msu_mask;
  	union {
  		/** @value: per-sensor raw mailbox temperature; bit7=sign, bits6:0=magnitude */
  		u8 value[U8_MAX + 1];
  		/** @dword: sensor values as little-endian dwords, u32-aligned for pcode reads */
  		__le32 dword[DIV_ROUND_UP(U8_MAX + 1, sizeof(u32))];
  	};
- 	/** @vram_label: vram label names */
- 	char vram_label[MAX_VRAM_CHANNELS][MAX_LABEL_SIZE];
+ 	/** @vram_label: vram label names, dynamically allocated based on vram_count */
+ 	char (*vram_label)[MAX_LABEL_SIZE];
  };
  
  /**
@@@ -297,6 -316,14 +316,14 @@@ static int xe_hwmon_pcode_set_default_p
  	return ret;
  }
  
+ static bool xe_hwmon_vram_channel_enabled(const struct xe_hwmon *hwmon, int index)
+ {
+ 	if (hwmon->xe->info.platform == XE_CRESCENTISLAND)
+ 		return hwmon->temp.msu_mask & BIT(index / VRAM_CHANNELS_PER_MSU);
+ 
+ 	return true;
+ }
+ 
  static struct xe_reg xe_hwmon_get_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg hwmon_reg,
  				      int channel)
  {
@@@ -304,12 -331,21 +331,21 @@@
  
  	switch (hwmon_reg) {
  	case REG_TEMP:
- 		if (xe->info.platform == XE_BATTLEMAGE || xe->info.platform == XE_CRESCENTISLAND) {
+ 		if (xe->info.platform == XE_CRESCENTISLAND) {
+ 			if (channel == CHANNEL_PKG)
+ 				return CRI_PACKAGE_TEMPERATURE;
+ 			else if (channel == CHANNEL_VRAM)
+ 				return CRI_VRAM_TEMPERATURE;
+ 			else if (in_range(channel, CHANNEL_VRAM_N, hwmon->temp.vram_count) &&
+ 				 xe_hwmon_vram_channel_enabled(hwmon, channel - CHANNEL_VRAM_N))
+ 				return CRI_VRAM_TEMPERATURE_N(channel - CHANNEL_VRAM_N);
+ 		} else if (xe->info.platform == XE_BATTLEMAGE) {
  			if (channel == CHANNEL_PKG)
  				return BMG_PACKAGE_TEMPERATURE;
  			else if (channel == CHANNEL_VRAM)
  				return BMG_VRAM_TEMPERATURE;
- 			else if (in_range(channel, CHANNEL_VRAM_N, MAX_VRAM_CHANNELS))
+ 			else if (in_range(channel, CHANNEL_VRAM_N, hwmon->temp.vram_count) &&
+ 				 xe_hwmon_vram_channel_enabled(hwmon, channel - CHANNEL_VRAM_N))
  				return BMG_VRAM_TEMPERATURE_N(channel - CHANNEL_VRAM_N);
  		} else if (xe->info.platform == XE_DG2) {
  			if (channel == CHANNEL_PKG)
@@@ -810,30 -846,24 +846,24 @@@ static const struct attribute_group *hw
  	NULL
  };
  
+ static const u32 hwmon_temp_config[CHANNEL_MAX + 1] = {
+ 	[CHANNEL_CARD] = HWMON_T_LABEL,
+ 	[CHANNEL_PKG] = HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT |
+ 			 HWMON_T_LABEL | HWMON_T_MAX,
+ 	[CHANNEL_VRAM ... CHANNEL_PCIE] = HWMON_T_CRIT | HWMON_T_EMERGENCY |
+ 					 HWMON_T_INPUT | HWMON_T_LABEL,
+ 	[CHANNEL_VRAM_N ... CHANNEL_VRAM_N_MAX] = HWMON_T_CRIT | HWMON_T_EMERGENCY |
+ 							 HWMON_T_INPUT | HWMON_T_LABEL,
+ 	[CHANNEL_MAX] = 0, /* hwmon config terminator */
+ };
+ 
+ static const struct hwmon_channel_info hwmon_temp_info = {
+ 	.type = hwmon_temp,
+ 	.config = hwmon_temp_config,
+ };
+ 
  static const struct hwmon_channel_info * const hwmon_info[] = {
- 	HWMON_CHANNEL_INFO(temp,
- 			   HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL |
- 			   HWMON_T_MAX,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL,
- 			   HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | HWMON_T_LABEL),
+ 	&hwmon_temp_info,
  	HWMON_CHANNEL_INFO(power, HWMON_P_MAX | HWMON_P_RATED_MAX | HWMON_P_LABEL | HWMON_P_CRIT |
  			   HWMON_P_CAP,
  			   HWMON_P_MAX | HWMON_P_RATED_MAX | HWMON_P_LABEL | HWMON_P_CAP),
@@@ -847,9 -877,31 +877,31 @@@
  static int xe_hwmon_pcode_read_thermal_info(struct xe_hwmon *hwmon)
  {
  	struct xe_tile *root_tile = xe_device_get_root_tile(hwmon->xe);
+ 	struct xe_mmio *mmio = xe_root_tile_mmio(hwmon->xe);
  	u32 config = 0, data0 = 0, data1 = 0;
  	int ret;
  
+ 	/*
+ 	 * Only CRI reports dynamic VRAM channel state. Fixed-channel platforms
+ 	 * set the count up front so those sensors stay visible even if the thermal
+ 	 * mailbox reads below fail.
+ 	 */
+ 	if (hwmon->xe->info.has_fixed_vram_channels)
+ 		hwmon->temp.vram_count = FIXED_VRAM_CHANNELS;
+ 
+ 	if (hwmon->xe->info.platform == XE_CRESCENTISLAND) {
+ 		hwmon->temp.msu_mask = xe_mmio_read32(mmio, CRI_MSU_VRAM_ENABLE);
+ 		hwmon->temp.vram_count = fls(hwmon->temp.msu_mask) * VRAM_CHANNELS_PER_MSU;
+ 		drm_dbg(&hwmon->xe->drm, "MSU VRAM enable mask 0x%x, VRAM channel bound %d\n",
+ 			hwmon->temp.msu_mask, hwmon->temp.vram_count);
+ 		if (hwmon->temp.vram_count > MAX_VRAM_CHANNELS) {
+ 			drm_warn(&hwmon->xe->drm,
+ 				 "VRAM channel bound %d exceeds max %d, clamping\n",
+ 				 hwmon->temp.vram_count, MAX_VRAM_CHANNELS);
+ 			hwmon->temp.vram_count = MAX_VRAM_CHANNELS;
+ 		}
+ 	}
+ 
  	ret = xe_pcode_read(root_tile, PCODE_MBOX(PCODE_THERMAL_INFO, READ_THERMAL_LIMITS, 0),
  			    &data0, &data1);
  	if (ret)
@@@ -902,17 -954,43 +954,43 @@@ static int mbx_temp_decode(u8 value
  	return (value & TEMP_MBX_SIGN) ? -temp : temp;
  }
  
+ static u8 xe_hwmon_pcie_temp_index(const struct xe_hwmon *hwmon)
+ {
+ 	if (hwmon->xe->info.platform == XE_CRESCENTISLAND)
+ 		return CRI_TEMP_INDEX_PCIE;
+ 
+ 	if (hwmon->xe->info.subplatform == XE_SUBPLATFORM_BATTLEMAGE_G21)
+ 		return BMG_G21_TEMP_INDEX_PCIE;
+ 
+ 	return TEMP_INDEX_PCIE;
+ }
+ 
  static int get_mc_temp(struct xe_hwmon *hwmon, long *val)
  {
  	struct xe_tile *root_tile = xe_device_get_root_tile(hwmon->xe);
- 	int ret, i, count = 0;
+ 	int ret, i, start, end, count = 0;
  	s32 average = 0;
+ 	u32 data = 0;
  
  	guard(mutex)(&hwmon->hwmon_lock);
  
- 	for (i = 0; i < DIV_ROUND_UP(hwmon->temp.count, sizeof(u32)); i++) {
- 		u32 data = 0;
+ 	/* CRI relocated the memory controller temperatures to READ_THERMAL_DATA bytes 16..19. */
+ 	if (hwmon->xe->info.platform == XE_CRESCENTISLAND) {
+ 		start = CRI_TEMP_INDEX_MCTRL;
+ 		end = CRI_TEMP_INDEX_MCTRL + CRI_TEMP_MCTRL_COUNT;
+ 	} else {
+ 		start = TEMP_INDEX_MCTRL;
+ 		end = min_t(int, hwmon->temp.count - 1, xe_hwmon_pcie_temp_index(hwmon));
+ 	}
  
+ 	if (end <= start || end > hwmon->temp.count) {
+ 		drm_warn(&hwmon->xe->drm,
+ 			 "memory controller range [%d, %d) is invalid for temperature count %d\n",
+ 			 start, end, hwmon->temp.count);
+ 		return -ENODATA;
+ 	}
+ 
+ 	for (i = start / sizeof(u32); i < DIV_ROUND_UP(end, sizeof(u32)); i++) {
  		ret = xe_pcode_read(root_tile, PCODE_MBOX(PCODE_THERMAL_INFO, READ_THERMAL_DATA, i),
  				    &data, NULL);
  		if (ret)
@@@ -921,7 -999,7 +999,7 @@@
  		hwmon->temp.dword[i] = cpu_to_le32(data);
  	}
  
- 	for (i = TEMP_INDEX_MCTRL; i < hwmon->temp.count - 1; i++) {
+ 	for (i = start; i < end; i++) {
  		if (!mbx_temp_valid(hwmon, hwmon->temp.value[i]))
  			continue;
  		average += mbx_temp_decode(hwmon->temp.value[i]);
@@@ -941,23 -1019,36 +1019,36 @@@
  	return 0;
  }
  
- static int get_pcie_temp(struct xe_hwmon *hwmon, long *val)
+ static int get_pcie_temp(const struct xe_hwmon *hwmon, long *val)
  {
  	struct xe_tile *root_tile = xe_device_get_root_tile(hwmon->xe);
  	u32 data = 0;
+ 	int index;
  	int ret;
  
+ 	index = xe_hwmon_pcie_temp_index(hwmon);
+ 	if (index >= hwmon->temp.count) {
+ 		drm_warn(&hwmon->xe->drm,
+ 			 "PCIe temperature index %d out of range for temperature count %d\n",
+ 			 index, hwmon->temp.count);
+ 		return -ENODATA;
+ 	}
+ 
  	ret = xe_pcode_read(root_tile, PCODE_MBOX(PCODE_THERMAL_INFO, READ_THERMAL_DATA,
- 						  PCIE_SENSOR_GROUP_ID), &data, NULL);
+ 						  index / sizeof(data)),
+ 						  &data, NULL);
  	if (ret)
  		return ret;
  
- 	/* Sensor offset is different for G21 */
- 	if (hwmon->xe->info.subplatform != XE_SUBPLATFORM_BATTLEMAGE_G21)
- 		data = REG_FIELD_GET(PCIE_SENSOR_MASK, data);
- 
+ 	data >>= (index % sizeof(data)) * BITS_PER_BYTE;
  	data = REG_FIELD_GET(TEMP_MASK, data);
- 	*val = mbx_temp_decode(data) * MILLIDEGREE_PER_DEGREE;
+ 	if (!mbx_temp_valid(hwmon, data)) {
+ 		drm_dbg(&hwmon->xe->drm, "PCIe temperature not available\n");
+ 		return -ENXIO;
+ 	}
+ 
+ 	if (val)
+ 		*val = mbx_temp_decode(data) * MILLIDEGREE_PER_DEGREE;
  
  	return 0;
  }
@@@ -1056,19 -1147,70 +1147,70 @@@ static void xe_hwmon_get_voltage(struc
  	*value = DIV_ROUND_CLOSEST(REG_FIELD_GET(VOLTAGE_MASK, reg_val) * 2500, SF_VOLTAGE);
  }
  
- static inline bool is_vram_ch_available(struct xe_hwmon *hwmon, int channel)
+ static bool xe_hwmon_temp_probe(struct xe_hwmon *hwmon, int channel)
  {
  	struct xe_mmio *mmio = xe_root_tile_mmio(hwmon->xe);
- 	int vram_id = channel - CHANNEL_VRAM_N;
- 	struct xe_reg vram_reg;
+ 	struct xe_reg reg;
+ 	u32 reg_val;
  
- 	vram_reg = xe_hwmon_get_reg(hwmon, REG_TEMP, channel);
- 	if (!xe_reg_is_valid(vram_reg) || !xe_mmio_read32(mmio, vram_reg))
+ 	switch (channel) {
+ 	case CHANNEL_PKG:
+ 	case CHANNEL_VRAM:
+ 	case CHANNEL_VRAM_N...CHANNEL_VRAM_N_MAX:
+ 		reg = xe_hwmon_get_reg(hwmon, REG_TEMP, channel);
+ 		if (!xe_reg_is_valid(reg))
+ 			return false;
+ 
+ 		/*
+ 		 * On CRI, VRAM channel presence comes from the MSU enable mask
+ 		 * (applied in xe_hwmon_get_reg()); the temperature register's
+ 		 * 0xffffffff sentinel is not reliable for VRAM channels.
+ 		 */
+ 		if (hwmon->xe->info.platform == XE_CRESCENTISLAND && channel >= CHANNEL_VRAM_N)
+ 			return true;
+ 
+ 		reg_val = xe_mmio_read32(mmio, reg);
+ 		if (!mmio_temp_valid(hwmon, reg_val)) {
+ 			drm_dbg(&hwmon->xe->drm,
+ 				"channel %d temperature unavailable, val 0x%x\n", channel, reg_val);
+ 			return false;
+ 		}
+ 
+ 		return true;
+ 	case CHANNEL_MCTRL:
+ 		return hwmon->temp.count && !get_mc_temp(hwmon, NULL);
+ 	case CHANNEL_PCIE:
+ 		return hwmon->temp.count && !get_pcie_temp(hwmon, NULL);
+ 	default:
  		return false;
+ 	}
+ }
  
- 	/* Create label only for available vram channel */
- 	sprintf(hwmon->temp.vram_label[vram_id], "vram_ch_%d", vram_id);
- 	return true;
+ static int xe_hwmon_init_temp_info(struct xe_hwmon *hwmon)
+ {
+ 	struct device *dev = hwmon->xe->drm.dev;
+ 	int channel;
+ 
+ 	if (hwmon->xe->info.has_mbx_thermal_info && xe_hwmon_pcode_read_thermal_info(hwmon))
+ 		drm_warn(&hwmon->xe->drm, "Thermal mailbox not supported by card firmware\n");
+ 
+ 	/* vram_count is known only after reading thermal info above. */
+ 	if (hwmon->temp.vram_count) {
+ 		hwmon->temp.vram_label = devm_kcalloc(dev, hwmon->temp.vram_count,
+ 						      MAX_LABEL_SIZE, GFP_KERNEL);
+ 		if (!hwmon->temp.vram_label)
+ 			return -ENOMEM;
+ 	}
+ 
+ 	for (channel = 0; channel < CHANNEL_MAX; channel++) {
+ 		hwmon->temp.available[channel] = xe_hwmon_temp_probe(hwmon, channel);
+ 		if (hwmon->temp.available[channel] && hwmon->temp.vram_label &&
+ 		    in_range(channel, CHANNEL_VRAM_N, hwmon->temp.vram_count))
+ 			snprintf(hwmon->temp.vram_label[channel - CHANNEL_VRAM_N], MAX_LABEL_SIZE,
+ 				 "vram_ch_%d", channel - CHANNEL_VRAM_N);
+ 	}
+ 
+ 	return 0;
  }
  
  static umode_t
@@@ -1078,14 -1220,13 +1220,13 @@@ xe_hwmon_temp_is_visible(struct xe_hwmo
  	case hwmon_temp_emergency:
  		switch (channel) {
  		case CHANNEL_PKG:
- 			return hwmon->temp.limit[TEMP_LIMIT_PKG_SHUTDOWN] ? 0444 : 0;
- 		case CHANNEL_VRAM:
- 			return hwmon->temp.limit[TEMP_LIMIT_MEM_SHUTDOWN] ? 0444 : 0;
  		case CHANNEL_MCTRL:
  		case CHANNEL_PCIE:
- 			return hwmon->temp.count ? 0444 : 0;
+ 			return (hwmon->temp.available[channel] &&
+ 				hwmon->temp.limit[TEMP_LIMIT_PKG_SHUTDOWN]) ? 0444 : 0;
+ 		case CHANNEL_VRAM:
  		case CHANNEL_VRAM_N...CHANNEL_VRAM_N_MAX:
- 			return (is_vram_ch_available(hwmon, channel) &&
+ 			return (hwmon->temp.available[channel] &&
  				hwmon->temp.limit[TEMP_LIMIT_MEM_SHUTDOWN]) ? 0444 : 0;
  		default:
  			return 0;
@@@ -1093,14 -1234,13 +1234,13 @@@
  	case hwmon_temp_crit:
  		switch (channel) {
  		case CHANNEL_PKG:
- 			return hwmon->temp.limit[TEMP_LIMIT_PKG_CRIT] ? 0444 : 0;
- 		case CHANNEL_VRAM:
- 			return hwmon->temp.limit[TEMP_LIMIT_MEM_CRIT] ? 0444 : 0;
  		case CHANNEL_MCTRL:
  		case CHANNEL_PCIE:
- 			return hwmon->temp.count ? 0444 : 0;
+ 			return (hwmon->temp.available[channel] &&
+ 				hwmon->temp.limit[TEMP_LIMIT_PKG_CRIT]) ? 0444 : 0;
+ 		case CHANNEL_VRAM:
  		case CHANNEL_VRAM_N...CHANNEL_VRAM_N_MAX:
- 			return (is_vram_ch_available(hwmon, channel) &&
+ 			return (hwmon->temp.available[channel] &&
  				hwmon->temp.limit[TEMP_LIMIT_MEM_CRIT]) ? 0444 : 0;
  		default:
  			return 0;
@@@ -1108,7 -1248,8 +1248,8 @@@
  	case hwmon_temp_max:
  		switch (channel) {
  		case CHANNEL_PKG:
- 			return hwmon->temp.limit[TEMP_LIMIT_PKG_MAX] ? 0444 : 0;
+ 			return (hwmon->temp.available[channel] &&
+ 				hwmon->temp.limit[TEMP_LIMIT_PKG_MAX]) ? 0444 : 0;
  		default:
  			return 0;
  		}
@@@ -1117,13 -1258,10 +1258,10 @@@
  		switch (channel) {
  		case CHANNEL_PKG:
  		case CHANNEL_VRAM:
- 			return xe_reg_is_valid(xe_hwmon_get_reg(hwmon, REG_TEMP,
- 								channel)) ? 0444 : 0;
  		case CHANNEL_MCTRL:
  		case CHANNEL_PCIE:
- 			return hwmon->temp.count ? 0444 : 0;
  		case CHANNEL_VRAM_N...CHANNEL_VRAM_N_MAX:
- 			return is_vram_ch_available(hwmon, channel) ? 0444 : 0;
+ 			return hwmon->temp.available[channel] ? 0444 : 0;
  		default:
  			return 0;
  		}
@@@ -1132,6 -1270,70 +1270,70 @@@
  	}
  }
  
+ #define IEEE754_SIGN		REG_BIT(31)
+ #define IEEE754_EXP_MASK	REG_GENMASK(30, 23)
+ #define IEEE754_MANTISSA_MASK	REG_GENMASK(22, 0)
+ #define IEEE754_EXP_BIAS	127 /* Exponent bias to obtain the actual exponent */
+ #define IEEE754_MANTISSA_BITS	23 /* Mantissa width and implicit leading-1 bit position */
+ #define IEEE754_EXP_SPECIAL	0xff /* reserved exponent value encoding infinity or NaN */
+ 
+ /**
+  * xe_hwmon_temperature_decode - Decode an IEEE-754 temperature register value
+  * @reg_val: The raw register value to decode
+  * @temperature: Pointer to store the decoded temperature in millidegrees Celsius.
+  *
+  * 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_FIELD_GET(IEEE754_EXP_MASK, reg_val);
+ 	u32 mantissa = REG_FIELD_GET(IEEE754_MANTISSA_MASK, reg_val);
+ 	s64 value;
+ 	int shift;
+ 
+ 	/* Exponent 0xff encodes infinity or NaN. */
+ 	if (exponent == IEEE754_EXP_SPECIAL)
+ 		return -EINVAL;
+ 
+ 	/* Subnormal values are smaller than one millidegree Celsius. */
+ 	if (!exponent) {
+ 		*temperature = 0;
+ 		return 0;
+ 	}
+ 
+ 	value = (s64)(mantissa | BIT(IEEE754_MANTISSA_BITS)) * MILLIDEGREE_PER_DEGREE;
+ 	shift = exponent - (IEEE754_EXP_BIAS + IEEE754_MANTISSA_BITS);
+ 	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;
+ 	}
+ 
+ 	/* Ensure the decoded value fits in a long. */
+ 	if (overflows_type(value, *temperature))
+ 		return -ERANGE;
+ 
+ 	if (reg_val & IEEE754_SIGN)
+ 		value = -value;
+ 
+ 	*temperature = value;
+ 	return 0;
+ }
+ 
  static int
  xe_hwmon_temp_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)
  {
@@@ -1141,26 -1343,33 +1343,33 @@@
  	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 (!mmio_temp_valid(hwmon, reg_val)) {
+ 				drm_dbg(&hwmon->xe->drm,
+ 					"channel %d temperature invalid, val 0x%llx\n",
+ 					channel, reg_val);
+ 				return -ENXIO;
+ 			}
+ 			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;
@@@ -1567,8 -1776,10 +1776,10 @@@ static int xe_hwmon_read_label(struct d
  			*str = "mctrl";
  		else if (channel == CHANNEL_PCIE)
  			*str = "pcie";
- 		else if (in_range(channel, CHANNEL_VRAM_N, MAX_VRAM_CHANNELS))
+ 		else if (in_range(channel, CHANNEL_VRAM_N, hwmon->temp.vram_count))
  			*str = hwmon->temp.vram_label[channel - CHANNEL_VRAM_N];
+ 		else
+ 			return -EOPNOTSUPP;
  		return 0;
  	case hwmon_power:
  	case hwmon_energy:
@@@ -1596,7 -1807,7 +1807,7 @@@ static const struct hwmon_chip_info hwm
  	.info = hwmon_info,
  };
  
- static void
+ static int
  xe_hwmon_get_preregistration_info(struct xe_hwmon *hwmon)
  {
  	struct xe_mmio *mmio = xe_root_tile_mmio(hwmon->xe);
@@@ -1653,15 -1864,14 +1864,14 @@@
  		if (xe_hwmon_is_visible(hwmon, hwmon_fan, hwmon_fan_input, channel))
  			xe_hwmon_fan_input_read(hwmon, channel, &fan_speed);
  
- 	if (hwmon->xe->info.has_mbx_thermal_info && xe_hwmon_pcode_read_thermal_info(hwmon))
- 		drm_warn(&hwmon->xe->drm, "Thermal mailbox not supported by card firmware\n");
+ 	return xe_hwmon_init_temp_info(hwmon);
  }
  
  int xe_hwmon_register(struct xe_device *xe)
  {
  	struct device *dev = xe->drm.dev;
  	struct xe_hwmon *hwmon;
- 	int ret, err;
+ 	int ret;
  
  	/* hwmon is available only for dGfx */
  	if (!IS_DGFX(xe))
@@@ -1683,7 -1893,9 +1893,9 @@@
  	hwmon->xe = xe;
  	xe->hwmon = hwmon;
  
- 	xe_hwmon_get_preregistration_info(hwmon);
+ 	ret = xe_hwmon_get_preregistration_info(hwmon);
+ 	if (ret)
+ 		goto err_null_hwmon;
  
  	drm_dbg(&xe->drm, "Register xe hwmon interface\n");
  
@@@ -1692,13 -1904,15 +1904,15 @@@
  								&hwmon_chip_info,
  								hwmon_groups);
  	if (IS_ERR(hwmon->hwmon_dev)) {
- 		err = PTR_ERR(hwmon->hwmon_dev);
- 		xe_log_err(xe, HWMON, err,
- 			   "Failed to register xe hwmon\n");
- 		xe->hwmon = NULL;
- 		return err;
+ 		ret = PTR_ERR(hwmon->hwmon_dev);
+ 		xe_log_err(xe, HWMON, ret, "Failed to register xe hwmon\n");
+ 		goto err_null_hwmon;
  	}
  
  	return 0;
+ 
+ err_null_hwmon:
+ 	xe->hwmon = NULL;
+ 	return ret;
  }
  MODULE_IMPORT_NS("INTEL_PMT_TELEMETRY");

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

                 reply	other threads:[~2026-11-20 15:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=awBiPWrQJAygBnaS@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=airlied@redhat.com \
    --cc=dnyaneshwar.bhadane@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=karthik.poosa@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=mallesh.koujalagi@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=matthew.d.roper@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=vinay.belgaumkar@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