Lines Matching full:hwmon
6 #include <linux/hwmon-sysfs.h>
7 #include <linux/hwmon.h>
43 * SF_* - scale factors for particular quantities according to hwmon spec.
62 * struct xe_hwmon - xe hwmon data structure
65 /** @hwmon_dev: hwmon device for xe */
81 static struct xe_reg xe_hwmon_get_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg hwmon_reg, in xe_hwmon_get_reg() argument
84 struct xe_device *xe = hwmon->xe; in xe_hwmon_get_reg()
132 drm_warn(&xe->drm, "Unknown xe hwmon reg id: %d\n", hwmon_reg); in xe_hwmon_get_reg()
147 static void xe_hwmon_power_max_read(struct xe_hwmon *hwmon, int channel, long *value) in xe_hwmon_power_max_read() argument
150 struct xe_device *xe = hwmon->xe; in xe_hwmon_power_max_read()
154 rapl_limit = xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, channel); in xe_hwmon_power_max_read()
155 pkg_power_sku = xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU, channel); in xe_hwmon_power_max_read()
167 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power_max_read()
177 *value = mul_u64_u32_shr(reg_val, SF_POWER, hwmon->scl_shift_power); in xe_hwmon_power_max_read()
181 min = mul_u64_u32_shr(min, SF_POWER, hwmon->scl_shift_power); in xe_hwmon_power_max_read()
183 max = mul_u64_u32_shr(max, SF_POWER, hwmon->scl_shift_power); in xe_hwmon_power_max_read()
188 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power_max_read()
191 static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, int channel, long value) in xe_hwmon_power_max_write() argument
193 struct xe_gt *mmio = xe_root_mmio_gt(hwmon->xe); in xe_hwmon_power_max_write()
198 rapl_limit = xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, channel); in xe_hwmon_power_max_write()
200 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power_max_write()
207 drm_warn(&hwmon->xe->drm, "PL1 disable is not supported!\n"); in xe_hwmon_power_max_write()
214 reg_val = DIV_ROUND_CLOSEST_ULL((u64)value << hwmon->scl_shift_power, SF_POWER); in xe_hwmon_power_max_write()
219 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power_max_write()
223 static void xe_hwmon_power_rated_max_read(struct xe_hwmon *hwmon, int channel, long *value) in xe_hwmon_power_rated_max_read() argument
225 struct xe_gt *mmio = xe_root_mmio_gt(hwmon->xe); in xe_hwmon_power_rated_max_read()
226 struct xe_reg reg = xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU, channel); in xe_hwmon_power_rated_max_read()
236 *value = mul_u64_u32_shr(reg_val, SF_POWER, hwmon->scl_shift_power); in xe_hwmon_power_rated_max_read()
254 * the hwmon API. Using x86_64 128 bit arithmetic (see mul_u64_u32_shr()),
256 * hwmon->scl_shift_energy of 14 bits we have 57 (63 - 20 + 14) bits before
260 xe_hwmon_energy_get(struct xe_hwmon *hwmon, int channel, long *energy) in xe_hwmon_energy_get() argument
262 struct xe_gt *mmio = xe_root_mmio_gt(hwmon->xe); in xe_hwmon_energy_get()
263 struct xe_hwmon_energy_info *ei = &hwmon->ei[channel]; in xe_hwmon_energy_get()
266 reg_val = xe_mmio_read32(mmio, xe_hwmon_get_reg(hwmon, REG_PKG_ENERGY_STATUS, in xe_hwmon_energy_get()
277 hwmon->scl_shift_energy); in xe_hwmon_energy_get()
284 struct xe_hwmon *hwmon = dev_get_drvdata(dev); in xe_hwmon_power_max_interval_show() local
285 struct xe_gt *mmio = xe_root_mmio_gt(hwmon->xe); in xe_hwmon_power_max_interval_show()
290 xe_pm_runtime_get(hwmon->xe); in xe_hwmon_power_max_interval_show()
292 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power_max_interval_show()
294 r = xe_mmio_read32(mmio, xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, sensor_index)); in xe_hwmon_power_max_interval_show()
296 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power_max_interval_show()
298 xe_pm_runtime_put(hwmon->xe); in xe_hwmon_power_max_interval_show()
315 /* val in hwmon interface units (millisec) */ in xe_hwmon_power_max_interval_show()
316 out = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w); in xe_hwmon_power_max_interval_show()
325 struct xe_hwmon *hwmon = dev_get_drvdata(dev); in xe_hwmon_power_max_interval_store() local
326 struct xe_gt *mmio = xe_root_mmio_gt(hwmon->xe); in xe_hwmon_power_max_interval_store()
339 * The hwmon->scl_shift_time default of 0xa results in a max tau of 256 seconds. in xe_hwmon_power_max_interval_store()
349 * val must be < max in hwmon interface units. The steps below are in xe_hwmon_power_max_interval_store()
356 max_win = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w); in xe_hwmon_power_max_interval_store()
362 val = DIV_ROUND_CLOSEST_ULL((u64)val << hwmon->scl_shift_time, SF_TIME); in xe_hwmon_power_max_interval_store()
379 xe_pm_runtime_get(hwmon->xe); in xe_hwmon_power_max_interval_store()
381 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power_max_interval_store()
383 r = xe_mmio_rmw32(mmio, xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, sensor_index), in xe_hwmon_power_max_interval_store()
386 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power_max_interval_store()
388 xe_pm_runtime_put(hwmon->xe); in xe_hwmon_power_max_interval_store()
411 struct xe_hwmon *hwmon = dev_get_drvdata(dev); in xe_hwmon_attributes_visible() local
414 xe_pm_runtime_get(hwmon->xe); in xe_hwmon_attributes_visible()
416 ret = xe_reg_is_valid(xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, index)) ? attr->mode : 0; in xe_hwmon_attributes_visible()
418 xe_pm_runtime_put(hwmon->xe); in xe_hwmon_attributes_visible()
443 static int xe_hwmon_pcode_read_i1(const struct xe_hwmon *hwmon, u32 *uval) in xe_hwmon_pcode_read_i1() argument
445 struct xe_tile *root_tile = xe_device_get_root_tile(hwmon->xe); in xe_hwmon_pcode_read_i1()
448 if (hwmon->xe->info.platform == XE_DG2) in xe_hwmon_pcode_read_i1()
456 static int xe_hwmon_pcode_write_i1(const struct xe_hwmon *hwmon, u32 uval) in xe_hwmon_pcode_write_i1() argument
458 struct xe_tile *root_tile = xe_device_get_root_tile(hwmon->xe); in xe_hwmon_pcode_write_i1()
465 static int xe_hwmon_power_curr_crit_read(struct xe_hwmon *hwmon, int channel, in xe_hwmon_power_curr_crit_read() argument
471 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power_curr_crit_read()
473 ret = xe_hwmon_pcode_read_i1(hwmon, &uval); in xe_hwmon_power_curr_crit_read()
480 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power_curr_crit_read()
484 static int xe_hwmon_power_curr_crit_write(struct xe_hwmon *hwmon, int channel, in xe_hwmon_power_curr_crit_write() argument
490 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power_curr_crit_write()
493 ret = xe_hwmon_pcode_write_i1(hwmon, uval); in xe_hwmon_power_curr_crit_write()
495 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power_curr_crit_write()
499 static void xe_hwmon_get_voltage(struct xe_hwmon *hwmon, int channel, long *value) in xe_hwmon_get_voltage() argument
501 struct xe_gt *mmio = xe_root_mmio_gt(hwmon->xe); in xe_hwmon_get_voltage()
504 reg_val = xe_mmio_read32(mmio, xe_hwmon_get_reg(hwmon, REG_GT_PERF_STATUS, channel)); in xe_hwmon_get_voltage()
510 xe_hwmon_power_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) in xe_hwmon_power_is_visible() argument
516 return xe_reg_is_valid(xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT, in xe_hwmon_power_is_visible()
519 return xe_reg_is_valid(xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU, in xe_hwmon_power_is_visible()
523 return (xe_hwmon_pcode_read_i1(hwmon, &uval) || in xe_hwmon_power_is_visible()
527 return xe_reg_is_valid(xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU_UNIT, in xe_hwmon_power_is_visible()
536 xe_hwmon_power_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) in xe_hwmon_power_read() argument
540 xe_hwmon_power_max_read(hwmon, channel, val); in xe_hwmon_power_read()
543 xe_hwmon_power_rated_max_read(hwmon, channel, val); in xe_hwmon_power_read()
546 return xe_hwmon_power_curr_crit_read(hwmon, channel, val, SF_POWER); in xe_hwmon_power_read()
553 xe_hwmon_power_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) in xe_hwmon_power_write() argument
557 return xe_hwmon_power_max_write(hwmon, channel, val); in xe_hwmon_power_write()
559 return xe_hwmon_power_curr_crit_write(hwmon, channel, val, SF_POWER); in xe_hwmon_power_write()
566 xe_hwmon_curr_is_visible(const struct xe_hwmon *hwmon, u32 attr, int channel) in xe_hwmon_curr_is_visible() argument
570 /* hwmon sysfs attribute of current available only for package */ in xe_hwmon_curr_is_visible()
576 return (xe_hwmon_pcode_read_i1(hwmon, &uval) || in xe_hwmon_curr_is_visible()
579 return (xe_hwmon_pcode_read_i1(hwmon, &uval) || in xe_hwmon_curr_is_visible()
589 xe_hwmon_curr_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) in xe_hwmon_curr_read() argument
593 return xe_hwmon_power_curr_crit_read(hwmon, channel, val, SF_CURR); in xe_hwmon_curr_read()
600 xe_hwmon_curr_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) in xe_hwmon_curr_write() argument
604 return xe_hwmon_power_curr_crit_write(hwmon, channel, val, SF_CURR); in xe_hwmon_curr_write()
611 xe_hwmon_in_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) in xe_hwmon_in_is_visible() argument
616 return xe_reg_is_valid(xe_hwmon_get_reg(hwmon, REG_GT_PERF_STATUS, in xe_hwmon_in_is_visible()
624 xe_hwmon_in_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) in xe_hwmon_in_read() argument
628 xe_hwmon_get_voltage(hwmon, channel, val); in xe_hwmon_in_read()
636 xe_hwmon_energy_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) in xe_hwmon_energy_is_visible() argument
641 return xe_reg_is_valid(xe_hwmon_get_reg(hwmon, REG_PKG_ENERGY_STATUS, in xe_hwmon_energy_is_visible()
649 xe_hwmon_energy_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) in xe_hwmon_energy_read() argument
653 xe_hwmon_energy_get(hwmon, channel, val); in xe_hwmon_energy_read()
664 struct xe_hwmon *hwmon = (struct xe_hwmon *)drvdata; in xe_hwmon_is_visible() local
667 xe_pm_runtime_get(hwmon->xe); in xe_hwmon_is_visible()
671 ret = xe_hwmon_power_is_visible(hwmon, attr, channel); in xe_hwmon_is_visible()
674 ret = xe_hwmon_curr_is_visible(hwmon, attr, channel); in xe_hwmon_is_visible()
677 ret = xe_hwmon_in_is_visible(hwmon, attr, channel); in xe_hwmon_is_visible()
680 ret = xe_hwmon_energy_is_visible(hwmon, attr, channel); in xe_hwmon_is_visible()
687 xe_pm_runtime_put(hwmon->xe); in xe_hwmon_is_visible()
696 struct xe_hwmon *hwmon = dev_get_drvdata(dev); in xe_hwmon_read() local
699 xe_pm_runtime_get(hwmon->xe); in xe_hwmon_read()
703 ret = xe_hwmon_power_read(hwmon, attr, channel, val); in xe_hwmon_read()
706 ret = xe_hwmon_curr_read(hwmon, attr, channel, val); in xe_hwmon_read()
709 ret = xe_hwmon_in_read(hwmon, attr, channel, val); in xe_hwmon_read()
712 ret = xe_hwmon_energy_read(hwmon, attr, channel, val); in xe_hwmon_read()
719 xe_pm_runtime_put(hwmon->xe); in xe_hwmon_read()
728 struct xe_hwmon *hwmon = dev_get_drvdata(dev); in xe_hwmon_write() local
731 xe_pm_runtime_get(hwmon->xe); in xe_hwmon_write()
735 ret = xe_hwmon_power_write(hwmon, attr, channel, val); in xe_hwmon_write()
738 ret = xe_hwmon_curr_write(hwmon, attr, channel, val); in xe_hwmon_write()
745 xe_pm_runtime_put(hwmon->xe); in xe_hwmon_write()
785 struct xe_hwmon *hwmon = xe->hwmon; in xe_hwmon_get_preregistration_info() local
795 pkg_power_sku_unit = xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU_UNIT, 0); in xe_hwmon_get_preregistration_info()
798 hwmon->scl_shift_power = REG_FIELD_GET(PKG_PWR_UNIT, val_sku_unit); in xe_hwmon_get_preregistration_info()
799 hwmon->scl_shift_energy = REG_FIELD_GET(PKG_ENERGY_UNIT, val_sku_unit); in xe_hwmon_get_preregistration_info()
800 hwmon->scl_shift_time = REG_FIELD_GET(PKG_TIME_UNIT, val_sku_unit); in xe_hwmon_get_preregistration_info()
808 if (xe_hwmon_is_visible(hwmon, hwmon_energy, hwmon_energy_input, channel)) in xe_hwmon_get_preregistration_info()
809 xe_hwmon_energy_get(hwmon, channel, &energy); in xe_hwmon_get_preregistration_info()
814 struct xe_hwmon *hwmon = arg; in xe_hwmon_mutex_destroy() local
816 mutex_destroy(&hwmon->hwmon_lock); in xe_hwmon_mutex_destroy()
822 struct xe_hwmon *hwmon; in xe_hwmon_register() local
824 /* hwmon is available only for dGfx */ in xe_hwmon_register()
828 /* hwmon is not available on VFs */ in xe_hwmon_register()
832 hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); in xe_hwmon_register()
833 if (!hwmon) in xe_hwmon_register()
836 xe->hwmon = hwmon; in xe_hwmon_register()
838 mutex_init(&hwmon->hwmon_lock); in xe_hwmon_register()
839 if (devm_add_action_or_reset(dev, xe_hwmon_mutex_destroy, hwmon)) in xe_hwmon_register()
842 /* There's only one instance of hwmon per device */ in xe_hwmon_register()
843 hwmon->xe = xe; in xe_hwmon_register()
847 drm_dbg(&xe->drm, "Register xe hwmon interface\n"); in xe_hwmon_register()
849 /* hwmon_dev points to device hwmon<i> */ in xe_hwmon_register()
850 hwmon->hwmon_dev = devm_hwmon_device_register_with_info(dev, "xe", hwmon, in xe_hwmon_register()
854 if (IS_ERR(hwmon->hwmon_dev)) { in xe_hwmon_register()
855 drm_warn(&xe->drm, "Failed to register xe hwmon (%pe)\n", hwmon->hwmon_dev); in xe_hwmon_register()
856 xe->hwmon = NULL; in xe_hwmon_register()