[Intel-gfx] [PATCH v2 2/3] drm/i915/hwmon: Add helper function to obtain energy values
Riana Tauro
riana.tauro at intel.com
Mon Nov 7 04:52:39 UTC 2022
Add an interface to obtain hwmon energy values. This is used
by selftest to verify power consumption
v2 : use i915_hwmon prefix (Anshuman)
Signed-off-by: Riana Tauro <riana.tauro at intel.com>
---
drivers/gpu/drm/i915/i915_hwmon.c | 23 ++++++++++++++++++++---
drivers/gpu/drm/i915/i915_hwmon.h | 1 +
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c
index 9e9781493025..8fa861ac0712 100644
--- a/drivers/gpu/drm/i915/i915_hwmon.c
+++ b/drivers/gpu/drm/i915/i915_hwmon.c
@@ -138,7 +138,7 @@ hwm_field_scale_and_write(struct hwm_drvdata *ddat, i915_reg_t rgadr,
* hwmon->scl_shift_energy of 14 bits we have 57 (63 - 20 + 14) bits before
* energy1_input overflows. This at 1000 W is an overflow duration of 278 years.
*/
-static void
+static int
hwm_energy(struct hwm_drvdata *ddat, long *energy)
{
struct intel_uncore *uncore = ddat->uncore;
@@ -153,6 +153,9 @@ hwm_energy(struct hwm_drvdata *ddat, long *energy)
else
rgaddr = hwmon->rg.energy_status_all;
+ if (!i915_mmio_reg_valid(rgaddr))
+ return -EOPNOTSUPP;
+
mutex_lock(&hwmon->hwmon_lock);
with_intel_runtime_pm(uncore->rpm, wakeref)
@@ -167,6 +170,21 @@ hwm_energy(struct hwm_drvdata *ddat, long *energy)
*energy = mul_u64_u32_shr(ei->accum_energy, SF_ENERGY,
hwmon->scl_shift_energy);
mutex_unlock(&hwmon->hwmon_lock);
+
+ return 0;
+}
+
+/*
+ * i915_hwmon_get_energy - obtains energy value
+ * Returns: 0 on success or a negative error code
+ */
+int
+i915_hwmon_get_energy(struct drm_i915_private *i915, long *energy)
+{
+ struct i915_hwmon *hwmon = i915->hwmon;
+ struct hwm_drvdata *ddat = &hwmon->ddat;
+
+ return hwm_energy(ddat, energy);
}
static ssize_t
@@ -441,8 +459,7 @@ hwm_energy_read(struct hwm_drvdata *ddat, u32 attr, long *val)
{
switch (attr) {
case hwmon_energy_input:
- hwm_energy(ddat, val);
- return 0;
+ return hwm_energy(ddat, val);
default:
return -EOPNOTSUPP;
}
diff --git a/drivers/gpu/drm/i915/i915_hwmon.h b/drivers/gpu/drm/i915/i915_hwmon.h
index 7ca9cf2c34c9..a6c8efeb868d 100644
--- a/drivers/gpu/drm/i915/i915_hwmon.h
+++ b/drivers/gpu/drm/i915/i915_hwmon.h
@@ -12,6 +12,7 @@ struct drm_i915_private;
#if IS_REACHABLE(CONFIG_HWMON)
void i915_hwmon_register(struct drm_i915_private *i915);
void i915_hwmon_unregister(struct drm_i915_private *i915);
+int i915_hwmon_get_energy(struct drm_i915_private *i915, long *energy);
#else
static inline void i915_hwmon_register(struct drm_i915_private *i915) { };
static inline void i915_hwmon_unregister(struct drm_i915_private *i915) { };
--
2.25.1
More information about the Intel-gfx
mailing list