Skip to content

Commit 32bd3eb

Browse files
committed
Merge tag 'drm-intel-gt-next-2024-09-06' of https://gitlab.freedesktop.org/drm/i915/kernel into drm-next
Driver Changes: - Expose fan speed via hwmon (Raag) - Correction to Wa_14019159160 on ARL (John H) - Whitelist COMMON_SLICE_CHICKEN1 for UMD access on DG2/MTL/ARL (Dnyaneshwar) - Do not attempt to load the GSC multiple times to avoid hanging GSC HW (Daniele) - Populate /sys/class/drm/cardX/engines/ even if one engine fails (Andi) - Use kmemdup_array instead of kmemdup for multiple allocation (Yu) - Remove extra unlikely() (Hongbo) Signed-off-by: Dave Airlie <[email protected]> From: Joonas Lahtinen <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
2 parents 2ef8d63 + 596a7f1 commit 32bd3eb

File tree

9 files changed

+112
-11
lines changed

9 files changed

+112
-11
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,11 @@ Description: RO. Energy input of device or gt in microjoules.
7575
for the gt.
7676

7777
Only supported for particular Intel i915 graphics platforms.
78+
79+
What: /sys/bus/pci/drivers/i915/.../hwmon/hwmon<i>/fan1_input
80+
Date: November 2024
81+
KernelVersion: 6.12
82+
83+
Description: RO. Fan speed of device in RPM.
84+
85+
Only supported for particular Intel i915 graphics platforms.

drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ static int eb_select_context(struct i915_execbuffer *eb)
825825
struct i915_gem_context *ctx;
826826

827827
ctx = i915_gem_context_lookup(eb->file->driver_priv, eb->args->rsvd1);
828-
if (unlikely(IS_ERR(ctx)))
828+
if (IS_ERR(ctx))
829829
return PTR_ERR(ctx);
830830

831831
eb->gem_context = ctx;

drivers/gpu/drm/i915/gt/intel_gt_regs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,8 @@
15531553
#define VLV_RENDER_C0_COUNT _MMIO(0x138118)
15541554
#define VLV_MEDIA_C0_COUNT _MMIO(0x13811c)
15551555

1556+
#define PCU_PWM_FAN_SPEED _MMIO(0x138140)
1557+
15561558
#define GEN12_RPSTAT1 _MMIO(0x1381b4)
15571559
#define GEN12_VOLTAGE_MASK REG_GENMASK(10, 0)
15581560
#define GEN12_CAGF_MASK REG_GENMASK(19, 11)

drivers/gpu/drm/i915/gt/intel_workarounds.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ static void wa_init_finish(struct i915_wa_list *wal)
111111
{
112112
/* Trim unused entries. */
113113
if (!IS_ALIGNED(wal->count, WA_LIST_CHUNK)) {
114-
struct i915_wa *list = kmemdup(wal->list,
115-
wal->count * sizeof(*list),
116-
GFP_KERNEL);
114+
struct i915_wa *list = kmemdup_array(wal->list, wal->count,
115+
sizeof(*list), GFP_KERNEL);
117116

118117
if (list) {
119118
kfree(wal->list);
@@ -2072,7 +2071,7 @@ static void dg2_whitelist_build(struct intel_engine_cs *engine)
20722071
case RENDER_CLASS:
20732072
/* Required by recommended tuning setting (not a workaround) */
20742073
whitelist_mcr_reg(w, XEHP_COMMON_SLICE_CHICKEN3);
2075-
2074+
whitelist_reg(w, GEN7_COMMON_SLICE_CHICKEN1);
20762075
break;
20772076
default:
20782077
break;
@@ -2087,7 +2086,7 @@ static void xelpg_whitelist_build(struct intel_engine_cs *engine)
20872086
case RENDER_CLASS:
20882087
/* Required by recommended tuning setting (not a workaround) */
20892088
whitelist_mcr_reg(w, XEHP_COMMON_SLICE_CHICKEN3);
2090-
2089+
whitelist_reg(w, GEN7_COMMON_SLICE_CHICKEN1);
20912090
break;
20922091
default:
20932092
break;

drivers/gpu/drm/i915/gt/sysfs_engines.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,8 @@ void intel_engines_add_sysfs(struct drm_i915_private *i915)
530530
err_object:
531531
kobject_put(kobj);
532532
err_engine:
533-
dev_err(kdev, "Failed to add sysfs engine '%s'\n",
534-
engine->name);
535-
break;
533+
dev_warn(kdev, "Failed to add sysfs engine '%s'\n",
534+
engine->name);
536535
}
537536
}
538537
}

drivers/gpu/drm/i915/gt/uc/intel_gsc_uc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void intel_gsc_uc_load_start(struct intel_gsc_uc *gsc)
302302
{
303303
struct intel_gt *gt = gsc_uc_to_gt(gsc);
304304

305-
if (!intel_uc_fw_is_loadable(&gsc->fw))
305+
if (!intel_uc_fw_is_loadable(&gsc->fw) || intel_uc_fw_is_in_error(&gsc->fw))
306306
return;
307307

308308
if (intel_gsc_uc_fw_init_done(gsc))

drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4507,7 +4507,7 @@ static void guc_default_vfuncs(struct intel_engine_cs *engine)
45074507
/* Wa_16019325821 */
45084508
/* Wa_14019159160 */
45094509
if ((engine->class == COMPUTE_CLASS || engine->class == RENDER_CLASS) &&
4510-
IS_GFX_GT_IP_RANGE(engine->gt, IP_VER(12, 70), IP_VER(12, 71)))
4510+
IS_GFX_GT_IP_RANGE(engine->gt, IP_VER(12, 70), IP_VER(12, 74)))
45114511
engine->flags |= I915_ENGINE_USES_WA_HOLD_SWITCHOUT;
45124512

45134513
/*

drivers/gpu/drm/i915/gt/uc/intel_uc_fw.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ static inline bool intel_uc_fw_is_running(struct intel_uc_fw *uc_fw)
258258
return __intel_uc_fw_status(uc_fw) == INTEL_UC_FIRMWARE_RUNNING;
259259
}
260260

261+
static inline bool intel_uc_fw_is_in_error(struct intel_uc_fw *uc_fw)
262+
{
263+
return intel_uc_fw_status_to_error(__intel_uc_fw_status(uc_fw)) != 0;
264+
}
265+
261266
static inline bool intel_uc_fw_is_overridden(const struct intel_uc_fw *uc_fw)
262267
{
263268
return uc_fw->user_overridden;

drivers/gpu/drm/i915/i915_hwmon.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/hwmon.h>
77
#include <linux/hwmon-sysfs.h>
8+
#include <linux/jiffies.h>
89
#include <linux/types.h>
910

1011
#include "i915_drv.h"
@@ -36,18 +37,25 @@ struct hwm_reg {
3637
i915_reg_t pkg_rapl_limit;
3738
i915_reg_t energy_status_all;
3839
i915_reg_t energy_status_tile;
40+
i915_reg_t fan_speed;
3941
};
4042

4143
struct hwm_energy_info {
4244
u32 reg_val_prev;
4345
long accum_energy; /* Accumulated energy for energy1_input */
4446
};
4547

48+
struct hwm_fan_info {
49+
u32 reg_val_prev;
50+
u64 time_prev;
51+
};
52+
4653
struct hwm_drvdata {
4754
struct i915_hwmon *hwmon;
4855
struct intel_uncore *uncore;
4956
struct device *hwmon_dev;
5057
struct hwm_energy_info ei; /* Energy info for energy1_input */
58+
struct hwm_fan_info fi; /* Fan info for fan1_input */
5159
char name[12];
5260
int gt_n;
5361
bool reset_in_progress;
@@ -276,6 +284,7 @@ static const struct hwmon_channel_info * const hwm_info[] = {
276284
HWMON_CHANNEL_INFO(power, HWMON_P_MAX | HWMON_P_RATED_MAX | HWMON_P_CRIT),
277285
HWMON_CHANNEL_INFO(energy, HWMON_E_INPUT),
278286
HWMON_CHANNEL_INFO(curr, HWMON_C_CRIT),
287+
HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT),
279288
NULL
280289
};
281290

@@ -613,6 +622,69 @@ hwm_curr_write(struct hwm_drvdata *ddat, u32 attr, long val)
613622
}
614623
}
615624

625+
static umode_t
626+
hwm_fan_is_visible(const struct hwm_drvdata *ddat, u32 attr)
627+
{
628+
struct i915_hwmon *hwmon = ddat->hwmon;
629+
630+
if (attr == hwmon_fan_input && i915_mmio_reg_valid(hwmon->rg.fan_speed))
631+
return 0444;
632+
633+
return 0;
634+
}
635+
636+
static int
637+
hwm_fan_input_read(struct hwm_drvdata *ddat, long *val)
638+
{
639+
struct i915_hwmon *hwmon = ddat->hwmon;
640+
struct hwm_fan_info *fi = &ddat->fi;
641+
u64 rotations, time_now, time;
642+
intel_wakeref_t wakeref;
643+
u32 reg_val;
644+
int ret = 0;
645+
646+
wakeref = intel_runtime_pm_get(ddat->uncore->rpm);
647+
mutex_lock(&hwmon->hwmon_lock);
648+
649+
reg_val = intel_uncore_read(ddat->uncore, hwmon->rg.fan_speed);
650+
time_now = get_jiffies_64();
651+
652+
/*
653+
* HW register value is accumulated count of pulses from
654+
* PWM fan with the scale of 2 pulses per rotation.
655+
*/
656+
rotations = (reg_val - fi->reg_val_prev) / 2;
657+
658+
time = jiffies_delta_to_msecs(time_now - fi->time_prev);
659+
if (unlikely(!time)) {
660+
ret = -EAGAIN;
661+
goto exit;
662+
}
663+
664+
/*
665+
* Calculate fan speed in RPM by time averaging two subsequent
666+
* readings in minutes.
667+
* RPM = number of rotations * msecs per minute / time in msecs
668+
*/
669+
*val = DIV_ROUND_UP_ULL(rotations * (MSEC_PER_SEC * 60), time);
670+
671+
fi->reg_val_prev = reg_val;
672+
fi->time_prev = time_now;
673+
exit:
674+
mutex_unlock(&hwmon->hwmon_lock);
675+
intel_runtime_pm_put(ddat->uncore->rpm, wakeref);
676+
return ret;
677+
}
678+
679+
static int
680+
hwm_fan_read(struct hwm_drvdata *ddat, u32 attr, long *val)
681+
{
682+
if (attr == hwmon_fan_input)
683+
return hwm_fan_input_read(ddat, val);
684+
685+
return -EOPNOTSUPP;
686+
}
687+
616688
static umode_t
617689
hwm_is_visible(const void *drvdata, enum hwmon_sensor_types type,
618690
u32 attr, int channel)
@@ -628,6 +700,8 @@ hwm_is_visible(const void *drvdata, enum hwmon_sensor_types type,
628700
return hwm_energy_is_visible(ddat, attr);
629701
case hwmon_curr:
630702
return hwm_curr_is_visible(ddat, attr);
703+
case hwmon_fan:
704+
return hwm_fan_is_visible(ddat, attr);
631705
default:
632706
return 0;
633707
}
@@ -648,6 +722,8 @@ hwm_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
648722
return hwm_energy_read(ddat, attr, val);
649723
case hwmon_curr:
650724
return hwm_curr_read(ddat, attr, val);
725+
case hwmon_fan:
726+
return hwm_fan_read(ddat, attr, val);
651727
default:
652728
return -EOPNOTSUPP;
653729
}
@@ -739,12 +815,14 @@ hwm_get_preregistration_info(struct drm_i915_private *i915)
739815
hwmon->rg.pkg_rapl_limit = PCU_PACKAGE_RAPL_LIMIT;
740816
hwmon->rg.energy_status_all = PCU_PACKAGE_ENERGY_STATUS;
741817
hwmon->rg.energy_status_tile = INVALID_MMIO_REG;
818+
hwmon->rg.fan_speed = PCU_PWM_FAN_SPEED;
742819
} else {
743820
hwmon->rg.pkg_power_sku_unit = INVALID_MMIO_REG;
744821
hwmon->rg.pkg_power_sku = INVALID_MMIO_REG;
745822
hwmon->rg.pkg_rapl_limit = INVALID_MMIO_REG;
746823
hwmon->rg.energy_status_all = INVALID_MMIO_REG;
747824
hwmon->rg.energy_status_tile = INVALID_MMIO_REG;
825+
hwmon->rg.fan_speed = INVALID_MMIO_REG;
748826
}
749827

750828
with_intel_runtime_pm(uncore->rpm, wakeref) {
@@ -755,6 +833,16 @@ hwm_get_preregistration_info(struct drm_i915_private *i915)
755833
if (i915_mmio_reg_valid(hwmon->rg.pkg_power_sku_unit))
756834
val_sku_unit = intel_uncore_read(uncore,
757835
hwmon->rg.pkg_power_sku_unit);
836+
837+
/*
838+
* Store the initial fan register value, so that we can use it for
839+
* initial fan speed calculation.
840+
*/
841+
if (i915_mmio_reg_valid(hwmon->rg.fan_speed)) {
842+
ddat->fi.reg_val_prev = intel_uncore_read(uncore,
843+
hwmon->rg.fan_speed);
844+
ddat->fi.time_prev = get_jiffies_64();
845+
}
758846
}
759847

760848
hwmon->scl_shift_power = REG_FIELD_GET(PKG_PWR_UNIT, val_sku_unit);

0 commit comments

Comments
 (0)