Skip to content

Commit dcfd151

Browse files
Mallesh-Koujalagirodrigovivi
authored andcommitted
drm/xe/hwmon: Remove type casting
Refactor: eliminate type casts by using proper u32 declarations. v2: - Address review comments. (Karthik) v3: - Use the proper u32 type and drop cast. (Lucas De Marchi) - Modify variable when actually using u64 value. - Change r value to reg_value with u32 type. v4: - Remove newline between trailer and Signed-off-by. (Lucas De Marchi) - Change reg_val to val for more user-friendly logging. - Use mul_u32_u32 function since both values are u32. v5: - mul_u32_u32 function with shift. (Lucas De Marchi) Fixes: 7596d83 ("drm/xe/hwmon: Add support to manage power limits though mailbox") Signed-off-by: Mallesh Koujalagi <mallesh.koujalagi@intel.com> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com> Link: https://lore.kernel.org/r/20250912113458.2815172-1-mallesh.koujalagi@intel.com Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> (cherry picked from commit 4e1d3b5) Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
1 parent fef8b64 commit dcfd151

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

drivers/gpu/drm/xe/xe_hwmon.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,15 @@ static struct xe_reg xe_hwmon_get_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg
286286
*/
287287
static void xe_hwmon_power_max_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *value)
288288
{
289-
u64 reg_val = 0, min, max;
289+
u32 reg_val = 0;
290290
struct xe_device *xe = hwmon->xe;
291291
struct xe_reg rapl_limit, pkg_power_sku;
292292
struct xe_mmio *mmio = xe_root_tile_mmio(xe);
293293

294294
mutex_lock(&hwmon->hwmon_lock);
295295

296296
if (hwmon->xe->info.has_mbx_power_limits) {
297-
xe_hwmon_pcode_read_power_limit(hwmon, attr, channel, (u32 *)&reg_val);
297+
xe_hwmon_pcode_read_power_limit(hwmon, attr, channel, &reg_val);
298298
} else {
299299
rapl_limit = xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, channel);
300300
pkg_power_sku = xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU, channel);
@@ -304,19 +304,21 @@ static void xe_hwmon_power_max_read(struct xe_hwmon *hwmon, u32 attr, int channe
304304
/* Check if PL limits are disabled. */
305305
if (!(reg_val & PWR_LIM_EN)) {
306306
*value = PL_DISABLE;
307-
drm_info(&hwmon->xe->drm, "%s disabled for channel %d, val 0x%016llx\n",
307+
drm_info(&hwmon->xe->drm, "%s disabled for channel %d, val 0x%08x\n",
308308
PWR_ATTR_TO_STR(attr), channel, reg_val);
309309
goto unlock;
310310
}
311311

312312
reg_val = REG_FIELD_GET(PWR_LIM_VAL, reg_val);
313-
*value = mul_u64_u32_shr(reg_val, SF_POWER, hwmon->scl_shift_power);
313+
*value = mul_u32_u32(reg_val, SF_POWER) >> hwmon->scl_shift_power;
314314

315315
/* For platforms with mailbox power limit support clamping would be done by pcode. */
316316
if (!hwmon->xe->info.has_mbx_power_limits) {
317-
reg_val = xe_mmio_read64_2x32(mmio, pkg_power_sku);
318-
min = REG_FIELD_GET(PKG_MIN_PWR, reg_val);
319-
max = REG_FIELD_GET(PKG_MAX_PWR, reg_val);
317+
u64 pkg_pwr, min, max;
318+
319+
pkg_pwr = xe_mmio_read64_2x32(mmio, pkg_power_sku);
320+
min = REG_FIELD_GET(PKG_MIN_PWR, pkg_pwr);
321+
max = REG_FIELD_GET(PKG_MAX_PWR, pkg_pwr);
320322
min = mul_u64_u32_shr(min, SF_POWER, hwmon->scl_shift_power);
321323
max = mul_u64_u32_shr(max, SF_POWER, hwmon->scl_shift_power);
322324
if (min && max)
@@ -493,8 +495,8 @@ xe_hwmon_power_max_interval_show(struct device *dev, struct device_attribute *at
493495
{
494496
struct xe_hwmon *hwmon = dev_get_drvdata(dev);
495497
struct xe_mmio *mmio = xe_root_tile_mmio(hwmon->xe);
496-
u32 x, y, x_w = 2; /* 2 bits */
497-
u64 r, tau4, out;
498+
u32 reg_val, x, y, x_w = 2; /* 2 bits */
499+
u64 tau4, out;
498500
int channel = (to_sensor_dev_attr(attr)->index % 2) ? CHANNEL_PKG : CHANNEL_CARD;
499501
u32 power_attr = (to_sensor_dev_attr(attr)->index > 1) ? PL2_HWMON_ATTR : PL1_HWMON_ATTR;
500502

@@ -505,23 +507,24 @@ xe_hwmon_power_max_interval_show(struct device *dev, struct device_attribute *at
505507
mutex_lock(&hwmon->hwmon_lock);
506508

507509
if (hwmon->xe->info.has_mbx_power_limits) {
508-
ret = xe_hwmon_pcode_read_power_limit(hwmon, power_attr, channel, (u32 *)&r);
510+
ret = xe_hwmon_pcode_read_power_limit(hwmon, power_attr, channel, &reg_val);
509511
if (ret) {
510512
drm_err(&hwmon->xe->drm,
511-
"power interval read fail, ch %d, attr %d, r 0%llx, ret %d\n",
512-
channel, power_attr, r, ret);
513-
r = 0;
513+
"power interval read fail, ch %d, attr %d, val 0x%08x, ret %d\n",
514+
channel, power_attr, reg_val, ret);
515+
reg_val = 0;
514516
}
515517
} else {
516-
r = xe_mmio_read32(mmio, xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, channel));
518+
reg_val = xe_mmio_read32(mmio, xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT,
519+
channel));
517520
}
518521

519522
mutex_unlock(&hwmon->hwmon_lock);
520523

521524
xe_pm_runtime_put(hwmon->xe);
522525

523-
x = REG_FIELD_GET(PWR_LIM_TIME_X, r);
524-
y = REG_FIELD_GET(PWR_LIM_TIME_Y, r);
526+
x = REG_FIELD_GET(PWR_LIM_TIME_X, reg_val);
527+
y = REG_FIELD_GET(PWR_LIM_TIME_Y, reg_val);
525528

526529
/*
527530
* tau = (1 + (x / 4)) * power(2,y), x = bits(23:22), y = bits(21:17)

0 commit comments

Comments
 (0)