Skip to content

Commit dac328d

Browse files
raagjadavrodrigovivi
authored andcommitted
drm/xe/hwmon: expose package and vram temperature
Add hwmon support for temp2_input and temp3_input attributes, which will expose package and vram temperature in millidegree Celsius. With this in place we can monitor temperature using lm-sensors tool. v2: Reuse existing channels (Badal, Karthik) Signed-off-by: Raag Jadav <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Reviewed-by: Badal Nilawar <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Rodrigo Vivi <[email protected]>
1 parent 9c9dc9b commit dac328d

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,19 @@ Contact: [email protected]
108108
Description: RO. Package current voltage in millivolt.
109109

110110
Only supported for particular Intel Xe graphics platforms.
111+
112+
What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon<i>/temp2_input
113+
Date: March 2025
114+
KernelVersion: 6.14
115+
116+
Description: RO. Package temperature in millidegree Celsius.
117+
118+
Only supported for particular Intel Xe graphics platforms.
119+
120+
What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon<i>/temp3_input
121+
Date: March 2025
122+
KernelVersion: 6.14
123+
124+
Description: RO. VRAM temperature in millidegree Celsius.
125+
126+
Only supported for particular Intel Xe graphics platforms.

drivers/gpu/drm/xe/regs/xe_mchbar_regs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434

3535
#define PCU_CR_PACKAGE_ENERGY_STATUS XE_REG(MCHBAR_MIRROR_BASE_SNB + 0x593c)
3636

37+
#define PCU_CR_PACKAGE_TEMPERATURE XE_REG(MCHBAR_MIRROR_BASE_SNB + 0x5978)
38+
#define TEMP_MASK REG_GENMASK(7, 0)
39+
3740
#define PCU_CR_PACKAGE_RAPL_LIMIT XE_REG(MCHBAR_MIRROR_BASE_SNB + 0x59a0)
3841
#define PKG_PWR_LIM_1 REG_GENMASK(14, 0)
3942
#define PKG_PWR_LIM_1_EN REG_BIT(15)

drivers/gpu/drm/xe/regs/xe_pcode_regs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#define BMG_PACKAGE_POWER_SKU XE_REG(0x138098)
2222
#define BMG_PACKAGE_POWER_SKU_UNIT XE_REG(0x1380dc)
2323
#define BMG_PACKAGE_ENERGY_STATUS XE_REG(0x138120)
24+
#define BMG_VRAM_TEMPERATURE XE_REG(0x1382c0)
25+
#define BMG_PACKAGE_TEMPERATURE XE_REG(0x138434)
2426
#define BMG_PACKAGE_RAPL_LIMIT XE_REG(0x138440)
2527
#define BMG_PLATFORM_ENERGY_STATUS XE_REG(0x138458)
2628
#define BMG_PLATFORM_POWER_LIMIT XE_REG(0x138460)

drivers/gpu/drm/xe/xe_hwmon.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/hwmon-sysfs.h>
77
#include <linux/hwmon.h>
88
#include <linux/types.h>
9+
#include <linux/units.h>
910

1011
#include <drm/drm_managed.h>
1112
#include "regs/xe_gt_regs.h"
@@ -20,6 +21,7 @@
2021
#include "xe_pm.h"
2122

2223
enum xe_hwmon_reg {
24+
REG_TEMP,
2325
REG_PKG_RAPL_LIMIT,
2426
REG_PKG_POWER_SKU,
2527
REG_PKG_POWER_SKU_UNIT,
@@ -36,6 +38,7 @@ enum xe_hwmon_reg_operation {
3638
enum xe_hwmon_channel {
3739
CHANNEL_CARD,
3840
CHANNEL_PKG,
41+
CHANNEL_VRAM,
3942
CHANNEL_MAX,
4043
};
4144

@@ -84,6 +87,19 @@ static struct xe_reg xe_hwmon_get_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg
8487
struct xe_device *xe = hwmon->xe;
8588

8689
switch (hwmon_reg) {
90+
case REG_TEMP:
91+
if (xe->info.platform == XE_BATTLEMAGE) {
92+
if (channel == CHANNEL_PKG)
93+
return BMG_PACKAGE_TEMPERATURE;
94+
else if (channel == CHANNEL_VRAM)
95+
return BMG_VRAM_TEMPERATURE;
96+
} else if (xe->info.platform == XE_DG2) {
97+
if (channel == CHANNEL_PKG)
98+
return PCU_CR_PACKAGE_TEMPERATURE;
99+
else if (channel == CHANNEL_VRAM)
100+
return BMG_VRAM_TEMPERATURE;
101+
}
102+
break;
87103
case REG_PKG_RAPL_LIMIT:
88104
if (xe->info.platform == XE_BATTLEMAGE) {
89105
if (channel == CHANNEL_PKG)
@@ -431,6 +447,8 @@ static const struct attribute_group *hwmon_groups[] = {
431447
};
432448

433449
static const struct hwmon_channel_info * const hwmon_info[] = {
450+
HWMON_CHANNEL_INFO(temp, HWMON_T_LABEL, HWMON_T_INPUT | HWMON_T_LABEL,
451+
HWMON_T_INPUT | HWMON_T_LABEL),
434452
HWMON_CHANNEL_INFO(power, HWMON_P_MAX | HWMON_P_RATED_MAX | HWMON_P_LABEL,
435453
HWMON_P_MAX | HWMON_P_RATED_MAX | HWMON_P_CRIT | HWMON_P_LABEL),
436454
HWMON_CHANNEL_INFO(curr, HWMON_C_LABEL, HWMON_C_CRIT | HWMON_C_LABEL),
@@ -506,6 +524,36 @@ static void xe_hwmon_get_voltage(struct xe_hwmon *hwmon, int channel, long *valu
506524
*value = DIV_ROUND_CLOSEST(REG_FIELD_GET(VOLTAGE_MASK, reg_val) * 2500, SF_VOLTAGE);
507525
}
508526

527+
static umode_t
528+
xe_hwmon_temp_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)
529+
{
530+
switch (attr) {
531+
case hwmon_temp_input:
532+
case hwmon_temp_label:
533+
return xe_reg_is_valid(xe_hwmon_get_reg(hwmon, REG_TEMP, channel)) ? 0444 : 0;
534+
default:
535+
return 0;
536+
}
537+
}
538+
539+
static int
540+
xe_hwmon_temp_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)
541+
{
542+
struct xe_mmio *mmio = xe_root_tile_mmio(hwmon->xe);
543+
u64 reg_val;
544+
545+
switch (attr) {
546+
case hwmon_temp_input:
547+
reg_val = xe_mmio_read32(mmio, xe_hwmon_get_reg(hwmon, REG_TEMP, channel));
548+
549+
/* HW register value is in degrees Celsius, convert to millidegrees. */
550+
*val = REG_FIELD_GET(TEMP_MASK, reg_val) * MILLIDEGREE_PER_DEGREE;
551+
return 0;
552+
default:
553+
return -EOPNOTSUPP;
554+
}
555+
}
556+
509557
static umode_t
510558
xe_hwmon_power_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)
511559
{
@@ -667,6 +715,9 @@ xe_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type,
667715
xe_pm_runtime_get(hwmon->xe);
668716

669717
switch (type) {
718+
case hwmon_temp:
719+
ret = xe_hwmon_temp_is_visible(hwmon, attr, channel);
720+
break;
670721
case hwmon_power:
671722
ret = xe_hwmon_power_is_visible(hwmon, attr, channel);
672723
break;
@@ -699,6 +750,9 @@ xe_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
699750
xe_pm_runtime_get(hwmon->xe);
700751

701752
switch (type) {
753+
case hwmon_temp:
754+
ret = xe_hwmon_temp_read(hwmon, attr, channel, val);
755+
break;
702756
case hwmon_power:
703757
ret = xe_hwmon_power_read(hwmon, attr, channel, val);
704758
break;
@@ -752,6 +806,12 @@ static int xe_hwmon_read_label(struct device *dev,
752806
u32 attr, int channel, const char **str)
753807
{
754808
switch (type) {
809+
case hwmon_temp:
810+
if (channel == CHANNEL_PKG)
811+
*str = "pkg";
812+
else if (channel == CHANNEL_VRAM)
813+
*str = "vram";
814+
return 0;
755815
case hwmon_power:
756816
case hwmon_energy:
757817
case hwmon_curr:

0 commit comments

Comments
 (0)