Commit d81268ee authored by Ashutosh Dixit's avatar Ashutosh Dixit Committed by Rodrigo Vivi

drm/i915/hwmon: Get mutex and rpm ref just once in hwm_power_max_write

In preparation for follow-on patches, refactor hwm_power_max_write to take
hwmon_lock and runtime pm wakeref at start of the function and release them
at the end, therefore acquiring these just once each.
Signed-off-by: default avatarAshutosh Dixit <ashutosh.dixit@intel.com>
Reviewed-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230420164041.1428455-2-ashutosh.dixit@intel.com
parent 80ab3179
...@@ -396,31 +396,33 @@ hwm_power_max_write(struct hwm_drvdata *ddat, long val) ...@@ -396,31 +396,33 @@ hwm_power_max_write(struct hwm_drvdata *ddat, long val)
{ {
struct i915_hwmon *hwmon = ddat->hwmon; struct i915_hwmon *hwmon = ddat->hwmon;
intel_wakeref_t wakeref; intel_wakeref_t wakeref;
int ret = 0;
u32 nval; u32 nval;
mutex_lock(&hwmon->hwmon_lock);
wakeref = intel_runtime_pm_get(ddat->uncore->rpm);
/* Disable PL1 limit and verify, because the limit cannot be disabled on all platforms */ /* Disable PL1 limit and verify, because the limit cannot be disabled on all platforms */
if (val == PL1_DISABLE) { if (val == PL1_DISABLE) {
mutex_lock(&hwmon->hwmon_lock); intel_uncore_rmw(ddat->uncore, hwmon->rg.pkg_rapl_limit,
with_intel_runtime_pm(ddat->uncore->rpm, wakeref) { PKG_PWR_LIM_1_EN, 0);
intel_uncore_rmw(ddat->uncore, hwmon->rg.pkg_rapl_limit, nval = intel_uncore_read(ddat->uncore, hwmon->rg.pkg_rapl_limit);
PKG_PWR_LIM_1_EN, 0);
nval = intel_uncore_read(ddat->uncore, hwmon->rg.pkg_rapl_limit);
}
mutex_unlock(&hwmon->hwmon_lock);
if (nval & PKG_PWR_LIM_1_EN) if (nval & PKG_PWR_LIM_1_EN)
return -ENODEV; ret = -ENODEV;
return 0; goto exit;
} }
/* Computation in 64-bits to avoid overflow. Round to nearest. */ /* Computation in 64-bits to avoid overflow. Round to nearest. */
nval = DIV_ROUND_CLOSEST_ULL((u64)val << hwmon->scl_shift_power, SF_POWER); nval = DIV_ROUND_CLOSEST_ULL((u64)val << hwmon->scl_shift_power, SF_POWER);
nval = PKG_PWR_LIM_1_EN | REG_FIELD_PREP(PKG_PWR_LIM_1, nval); nval = PKG_PWR_LIM_1_EN | REG_FIELD_PREP(PKG_PWR_LIM_1, nval);
hwm_locked_with_pm_intel_uncore_rmw(ddat, hwmon->rg.pkg_rapl_limit, intel_uncore_rmw(ddat->uncore, hwmon->rg.pkg_rapl_limit,
PKG_PWR_LIM_1_EN | PKG_PWR_LIM_1, PKG_PWR_LIM_1_EN | PKG_PWR_LIM_1, nval);
nval); exit:
return 0; intel_runtime_pm_put(ddat->uncore->rpm, wakeref);
mutex_unlock(&hwmon->hwmon_lock);
return ret;
} }
static int static int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment