Lines Matching +full:max +full:- +full:rpm

1 // SPDX-License-Identifier: MIT
7 #include <linux/hwmon-sysfs.h>
20 * SF_* - scale factors for particular quantities according to hwmon spec.
21 * - voltage - millivolts
22 * - power - microwatts
23 * - curr - milliamperes
24 * - energy - microjoules
25 * - time - milliseconds
79 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_locked_with_pm_intel_uncore_rmw()
80 struct intel_uncore *uncore = ddat->uncore; in hwm_locked_with_pm_intel_uncore_rmw()
83 with_intel_runtime_pm(uncore->rpm, wakeref) { in hwm_locked_with_pm_intel_uncore_rmw()
84 mutex_lock(&hwmon->hwmon_lock); in hwm_locked_with_pm_intel_uncore_rmw()
88 mutex_unlock(&hwmon->hwmon_lock); in hwm_locked_with_pm_intel_uncore_rmw()
94 * of the field taken from the 32-bit register value might cause a result to
101 struct intel_uncore *uncore = ddat->uncore; in hwm_field_read_and_scale()
105 with_intel_runtime_pm(uncore->rpm, wakeref) in hwm_field_read_and_scale()
114 * hwm_energy - Obtain energy value
116 * The underlying energy hardware register is 32-bits and is subject to
119 * a power draw of 1000 watts, the 32-bit counter will overflow in
123 * 1 watt: (2^32 >> 14) / 1 W / (60 * 60 * 24) secs/day -> 3 days
124 * 1000 watts: (2^32 >> 14) / 1000 W / 60 secs/min -> 4.36 minutes
130 * hwmon->scl_shift_energy of 14 bits we have 57 (63 - 20 + 14) bits before
136 struct intel_uncore *uncore = ddat->uncore; in hwm_energy()
137 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_energy()
138 struct hwm_energy_info *ei = &ddat->ei; in hwm_energy()
143 if (ddat->gt_n >= 0) in hwm_energy()
144 rgaddr = hwmon->rg.energy_status_tile; in hwm_energy()
146 rgaddr = hwmon->rg.energy_status_all; in hwm_energy()
148 with_intel_runtime_pm(uncore->rpm, wakeref) { in hwm_energy()
149 mutex_lock(&hwmon->hwmon_lock); in hwm_energy()
153 if (reg_val >= ei->reg_val_prev) in hwm_energy()
154 ei->accum_energy += reg_val - ei->reg_val_prev; in hwm_energy()
156 ei->accum_energy += UINT_MAX - ei->reg_val_prev + reg_val; in hwm_energy()
157 ei->reg_val_prev = reg_val; in hwm_energy()
159 *energy = mul_u64_u32_shr(ei->accum_energy, SF_ENERGY, in hwm_energy()
160 hwmon->scl_shift_energy); in hwm_energy()
161 mutex_unlock(&hwmon->hwmon_lock); in hwm_energy()
170 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power1_max_interval_show()
175 with_intel_runtime_pm(ddat->uncore->rpm, wakeref) in hwm_power1_max_interval_show()
176 r = intel_uncore_read(ddat->uncore, hwmon->rg.pkg_rapl_limit); in hwm_power1_max_interval_show()
182 * = (4 | x) << (y - 2) in hwm_power1_max_interval_show()
183 * where (y - 2) ensures a 1.x fixed point representation of 1.x in hwm_power1_max_interval_show()
190 out = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w); in hwm_power1_max_interval_show()
201 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power1_max_interval_store()
212 * Max HW supported tau in '1.x * power(2,y)' format, x = 0, y = 0x12 in hwm_power1_max_interval_store()
213 * The hwmon->scl_shift_time default of 0xa results in a max tau of 256 seconds in hwm_power1_max_interval_store()
218 * val must be < max in hwmon interface units. The steps below are in hwm_power1_max_interval_store()
225 max_win = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w); in hwm_power1_max_interval_store()
228 return -EINVAL; in hwm_power1_max_interval_store()
231 val = DIV_ROUND_CLOSEST_ULL((u64)val << hwmon->scl_shift_time, SF_TIME); in hwm_power1_max_interval_store()
239 /* x = (val - (1 << y)) >> (y - 2); */ in hwm_power1_max_interval_store()
240 x = (val - (1ul << y)) << x_w >> y; in hwm_power1_max_interval_store()
245 hwm_locked_with_pm_intel_uncore_rmw(ddat, hwmon->rg.pkg_rapl_limit, in hwm_power1_max_interval_store()
264 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_attributes_visible()
267 return i915_mmio_reg_valid(hwmon->rg.pkg_rapl_limit) ? attr->mode : 0; in hwm_attributes_visible()
301 return -ENXIO; in hwm_pcode_read_i1()
303 return snb_pcode_read_p(&i915->uncore, PCODE_POWER_SETUP, in hwm_pcode_read_i1()
309 return snb_pcode_write_p(&i915->uncore, PCODE_POWER_SETUP, in hwm_pcode_write_i1()
316 struct drm_i915_private *i915 = ddat->uncore->i915; in hwm_in_is_visible()
329 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_in_read()
335 with_intel_runtime_pm(ddat->uncore->rpm, wakeref) in hwm_in_read()
336 reg_value = intel_uncore_read(ddat->uncore, hwmon->rg.gt_perf_status); in hwm_in_read()
341 return -EOPNOTSUPP; in hwm_in_read()
348 struct drm_i915_private *i915 = ddat->uncore->i915; in hwm_power_is_visible()
349 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power_is_visible()
354 return i915_mmio_reg_valid(hwmon->rg.pkg_rapl_limit) ? 0664 : 0; in hwm_power_is_visible()
356 return i915_mmio_reg_valid(hwmon->rg.pkg_power_sku) ? 0444 : 0; in hwm_power_is_visible()
369 * "typical but not guaranteed" min/max values in rg.pkg_power_sku. Follow the
376 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power_max_read()
378 u64 r, min, max; in hwm_power_max_read() local
381 with_intel_runtime_pm(ddat->uncore->rpm, wakeref) in hwm_power_max_read()
382 r = intel_uncore_read(ddat->uncore, hwmon->rg.pkg_rapl_limit); in hwm_power_max_read()
389 hwmon->rg.pkg_rapl_limit, in hwm_power_max_read()
391 hwmon->scl_shift_power, in hwm_power_max_read()
394 with_intel_runtime_pm(ddat->uncore->rpm, wakeref) in hwm_power_max_read()
395 r = intel_uncore_read64(ddat->uncore, hwmon->rg.pkg_power_sku); in hwm_power_max_read()
397 min = mul_u64_u32_shr(min, SF_POWER, hwmon->scl_shift_power); in hwm_power_max_read()
398 max = REG_FIELD_GET(PKG_MAX_PWR, r); in hwm_power_max_read()
399 max = mul_u64_u32_shr(max, SF_POWER, hwmon->scl_shift_power); in hwm_power_max_read()
401 if (min && max) in hwm_power_max_read()
402 *val = clamp_t(u64, *val, min, max); in hwm_power_max_read()
410 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power_max_write()
418 wakeref = intel_runtime_pm_get(ddat->uncore->rpm); in hwm_power_max_write()
419 mutex_lock(&hwmon->hwmon_lock); in hwm_power_max_write()
421 prepare_to_wait(&ddat->waitq, &wait, TASK_INTERRUPTIBLE); in hwm_power_max_write()
423 if (!hwmon->ddat.reset_in_progress) in hwm_power_max_write()
427 ret = -EINTR; in hwm_power_max_write()
431 mutex_unlock(&hwmon->hwmon_lock); in hwm_power_max_write()
432 intel_runtime_pm_put(ddat->uncore->rpm, wakeref); in hwm_power_max_write()
436 finish_wait(&ddat->waitq, &wait); in hwm_power_max_write()
442 intel_uncore_rmw(ddat->uncore, hwmon->rg.pkg_rapl_limit, in hwm_power_max_write()
444 nval = intel_uncore_read(ddat->uncore, hwmon->rg.pkg_rapl_limit); in hwm_power_max_write()
447 ret = -ENODEV; in hwm_power_max_write()
451 /* Computation in 64-bits to avoid overflow. Round to nearest. */ in hwm_power_max_write()
452 nval = DIV_ROUND_CLOSEST_ULL((u64)val << hwmon->scl_shift_power, SF_POWER); in hwm_power_max_write()
455 intel_uncore_rmw(ddat->uncore, hwmon->rg.pkg_rapl_limit, in hwm_power_max_write()
458 mutex_unlock(&hwmon->hwmon_lock); in hwm_power_max_write()
459 intel_runtime_pm_put(ddat->uncore->rpm, wakeref); in hwm_power_max_write()
466 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power_read()
475 hwmon->rg.pkg_power_sku, in hwm_power_read()
477 hwmon->scl_shift_power, in hwm_power_read()
481 ret = hwm_pcode_read_i1(ddat->uncore->i915, &uval); in hwm_power_read()
485 return -ENODEV; in hwm_power_read()
490 return -EOPNOTSUPP; in hwm_power_read()
504 return hwm_pcode_write_i1(ddat->uncore->i915, uval); in hwm_power_write()
506 return -EOPNOTSUPP; in hwm_power_write()
512 struct i915_hwmon *hwmon = i915->hwmon; in i915_hwmon_power_max_disable()
515 if (!hwmon || !i915_mmio_reg_valid(hwmon->rg.pkg_rapl_limit)) in i915_hwmon_power_max_disable()
518 mutex_lock(&hwmon->hwmon_lock); in i915_hwmon_power_max_disable()
520 hwmon->ddat.reset_in_progress = true; in i915_hwmon_power_max_disable()
521 r = intel_uncore_rmw(hwmon->ddat.uncore, hwmon->rg.pkg_rapl_limit, in i915_hwmon_power_max_disable()
525 mutex_unlock(&hwmon->hwmon_lock); in i915_hwmon_power_max_disable()
530 struct i915_hwmon *hwmon = i915->hwmon; in i915_hwmon_power_max_restore()
532 if (!hwmon || !i915_mmio_reg_valid(hwmon->rg.pkg_rapl_limit)) in i915_hwmon_power_max_restore()
535 mutex_lock(&hwmon->hwmon_lock); in i915_hwmon_power_max_restore()
537 intel_uncore_rmw(hwmon->ddat.uncore, hwmon->rg.pkg_rapl_limit, in i915_hwmon_power_max_restore()
539 hwmon->ddat.reset_in_progress = false; in i915_hwmon_power_max_restore()
540 wake_up_all(&hwmon->ddat.waitq); in i915_hwmon_power_max_restore()
542 mutex_unlock(&hwmon->hwmon_lock); in i915_hwmon_power_max_restore()
548 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_energy_is_visible()
553 if (ddat->gt_n >= 0) in hwm_energy_is_visible()
554 rgaddr = hwmon->rg.energy_status_tile; in hwm_energy_is_visible()
556 rgaddr = hwmon->rg.energy_status_all; in hwm_energy_is_visible()
571 return -EOPNOTSUPP; in hwm_energy_read()
578 struct drm_i915_private *i915 = ddat->uncore->i915; in hwm_curr_is_visible()
598 ret = hwm_pcode_read_i1(ddat->uncore->i915, &uval); in hwm_curr_read()
602 return -ENODEV; in hwm_curr_read()
607 return -EOPNOTSUPP; in hwm_curr_read()
619 return hwm_pcode_write_i1(ddat->uncore->i915, uval); in hwm_curr_write()
621 return -EOPNOTSUPP; in hwm_curr_write()
628 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_fan_is_visible()
630 if (attr == hwmon_fan_input && i915_mmio_reg_valid(hwmon->rg.fan_speed)) in hwm_fan_is_visible()
639 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_fan_input_read()
640 struct hwm_fan_info *fi = &ddat->fi; in hwm_fan_input_read()
646 wakeref = intel_runtime_pm_get(ddat->uncore->rpm); in hwm_fan_input_read()
647 mutex_lock(&hwmon->hwmon_lock); in hwm_fan_input_read()
649 reg_val = intel_uncore_read(ddat->uncore, hwmon->rg.fan_speed); in hwm_fan_input_read()
656 rotations = (reg_val - fi->reg_val_prev) / 2; in hwm_fan_input_read()
658 time = jiffies_delta_to_msecs(time_now - fi->time_prev); in hwm_fan_input_read()
660 ret = -EAGAIN; in hwm_fan_input_read()
665 * Calculate fan speed in RPM by time averaging two subsequent in hwm_fan_input_read()
667 * RPM = number of rotations * msecs per minute / time in msecs in hwm_fan_input_read()
671 fi->reg_val_prev = reg_val; in hwm_fan_input_read()
672 fi->time_prev = time_now; in hwm_fan_input_read()
674 mutex_unlock(&hwmon->hwmon_lock); in hwm_fan_input_read()
675 intel_runtime_pm_put(ddat->uncore->rpm, wakeref); in hwm_fan_input_read()
685 return -EOPNOTSUPP; in hwm_fan_read()
728 return -EOPNOTSUPP; in hwm_read()
744 return -EOPNOTSUPP; in hwm_write()
783 return -EOPNOTSUPP; in hwm_gt_read()
800 struct i915_hwmon *hwmon = i915->hwmon; in hwm_get_preregistration_info()
801 struct intel_uncore *uncore = &i915->uncore; in hwm_get_preregistration_info()
802 struct hwm_drvdata *ddat = &hwmon->ddat; in hwm_get_preregistration_info()
810 hwmon->rg.gt_perf_status = GEN12_RPSTAT1; in hwm_get_preregistration_info()
813 hwmon->rg.pkg_power_sku_unit = PCU_PACKAGE_POWER_SKU_UNIT; in hwm_get_preregistration_info()
814 hwmon->rg.pkg_power_sku = PCU_PACKAGE_POWER_SKU; in hwm_get_preregistration_info()
815 hwmon->rg.pkg_rapl_limit = PCU_PACKAGE_RAPL_LIMIT; in hwm_get_preregistration_info()
816 hwmon->rg.energy_status_all = PCU_PACKAGE_ENERGY_STATUS; in hwm_get_preregistration_info()
817 hwmon->rg.energy_status_tile = INVALID_MMIO_REG; in hwm_get_preregistration_info()
818 hwmon->rg.fan_speed = PCU_PWM_FAN_SPEED; in hwm_get_preregistration_info()
820 hwmon->rg.pkg_power_sku_unit = INVALID_MMIO_REG; in hwm_get_preregistration_info()
821 hwmon->rg.pkg_power_sku = INVALID_MMIO_REG; in hwm_get_preregistration_info()
822 hwmon->rg.pkg_rapl_limit = INVALID_MMIO_REG; in hwm_get_preregistration_info()
823 hwmon->rg.energy_status_all = INVALID_MMIO_REG; in hwm_get_preregistration_info()
824 hwmon->rg.energy_status_tile = INVALID_MMIO_REG; in hwm_get_preregistration_info()
825 hwmon->rg.fan_speed = INVALID_MMIO_REG; in hwm_get_preregistration_info()
828 with_intel_runtime_pm(uncore->rpm, wakeref) { in hwm_get_preregistration_info()
830 * The contents of register hwmon->rg.pkg_power_sku_unit do not change, in hwm_get_preregistration_info()
833 if (i915_mmio_reg_valid(hwmon->rg.pkg_power_sku_unit)) in hwm_get_preregistration_info()
835 hwmon->rg.pkg_power_sku_unit); in hwm_get_preregistration_info()
841 if (i915_mmio_reg_valid(hwmon->rg.fan_speed)) { in hwm_get_preregistration_info()
842 ddat->fi.reg_val_prev = intel_uncore_read(uncore, in hwm_get_preregistration_info()
843 hwmon->rg.fan_speed); in hwm_get_preregistration_info()
844 ddat->fi.time_prev = get_jiffies_64(); in hwm_get_preregistration_info()
848 hwmon->scl_shift_power = REG_FIELD_GET(PKG_PWR_UNIT, val_sku_unit); in hwm_get_preregistration_info()
849 hwmon->scl_shift_energy = REG_FIELD_GET(PKG_ENERGY_UNIT, val_sku_unit); in hwm_get_preregistration_info()
850 hwmon->scl_shift_time = REG_FIELD_GET(PKG_TIME_UNIT, val_sku_unit); in hwm_get_preregistration_info()
856 if (i915_mmio_reg_valid(hwmon->rg.energy_status_all)) in hwm_get_preregistration_info()
858 if (i915_mmio_reg_valid(hwmon->rg.energy_status_tile)) { in hwm_get_preregistration_info()
860 hwm_energy(&hwmon->ddat_gt[i], &energy); in hwm_get_preregistration_info()
866 struct device *dev = i915->drm.dev; in i915_hwmon_register()
882 i915->hwmon = hwmon; in i915_hwmon_register()
883 mutex_init(&hwmon->hwmon_lock); in i915_hwmon_register()
884 ddat = &hwmon->ddat; in i915_hwmon_register()
886 ddat->hwmon = hwmon; in i915_hwmon_register()
887 ddat->uncore = &i915->uncore; in i915_hwmon_register()
888 snprintf(ddat->name, sizeof(ddat->name), "i915"); in i915_hwmon_register()
889 ddat->gt_n = -1; in i915_hwmon_register()
890 init_waitqueue_head(&ddat->waitq); in i915_hwmon_register()
893 ddat_gt = hwmon->ddat_gt + i; in i915_hwmon_register()
895 ddat_gt->hwmon = hwmon; in i915_hwmon_register()
896 ddat_gt->uncore = gt->uncore; in i915_hwmon_register()
897 snprintf(ddat_gt->name, sizeof(ddat_gt->name), "i915_gt%u", i); in i915_hwmon_register()
898 ddat_gt->gt_n = i; in i915_hwmon_register()
904 hwmon_dev = hwmon_device_register_with_info(dev, ddat->name, in i915_hwmon_register()
911 ddat->hwmon_dev = hwmon_dev; in i915_hwmon_register()
914 ddat_gt = hwmon->ddat_gt + i; in i915_hwmon_register()
916 * Create per-gt directories only if a per-gt attribute is in i915_hwmon_register()
922 hwmon_dev = hwmon_device_register_with_info(dev, ddat_gt->name, in i915_hwmon_register()
927 ddat_gt->hwmon_dev = hwmon_dev; in i915_hwmon_register()
936 struct i915_hwmon *hwmon = i915->hwmon; in i915_hwmon_unregister()
944 if (hwmon->ddat_gt[i].hwmon_dev) in i915_hwmon_unregister()
945 hwmon_device_unregister(hwmon->ddat_gt[i].hwmon_dev); in i915_hwmon_unregister()
947 if (hwmon->ddat.hwmon_dev) in i915_hwmon_unregister()
948 hwmon_device_unregister(hwmon->ddat.hwmon_dev); in i915_hwmon_unregister()
950 mutex_destroy(&hwmon->hwmon_lock); in i915_hwmon_unregister()
952 kfree(i915->hwmon); in i915_hwmon_unregister()
953 i915->hwmon = NULL; in i915_hwmon_unregister()