@@ -500,6 +500,34 @@ hwm_energy_read(struct hwm_drvdata *ddat, u32 attr, long *val)
}
}
+/**
+ * i915_hwmon_get_energy - obtains energy value
+ * @gt: intel_gt structure
+ * @energy: pointer to store energy in uJ
+ *
+ * This function checks for the validity of the underlying energy
+ * hardware register and obtains per-gt level energy
+ * values.
+ *
+ * Return: 0 on success, -EOPNOTSUPP if register is invalid
+ */
+int
+i915_hwmon_get_energy(struct intel_gt *gt, long *energy)
+{
+ struct i915_hwmon *hwmon = gt->i915->hwmon;
+ struct hwm_drvdata *ddat = &hwmon->ddat;
+ struct hwm_drvdata *ddat_gt = hwmon->ddat_gt + gt->info.id;
+
+ if (hwm_energy_is_visible(ddat_gt, hwmon_energy_input))
+ hwm_energy(ddat_gt, energy);
+ else if (!HAS_EXTRA_GT_LIST(gt->i915) && hwm_energy_is_visible(ddat, hwmon_energy_input))
+ hwm_energy(ddat, energy);
+ else
+ return -EOPNOTSUPP;
+
+ return 0;
+}
+
static umode_t
hwm_curr_is_visible(const struct hwm_drvdata *ddat, u32 attr)
{
@@ -8,13 +8,16 @@
#define __I915_HWMON_H__
struct drm_i915_private;
+struct intel_gt;
#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 intel_gt *gt, 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) { };
+static inline int i915_hwmon_get_energy(struct intel_gt *gt, long *energy) { return -EOPNOTSUPP; }
#endif
#endif /* __I915_HWMON_H__ */