Lines Matching full:hwmon
6 #include <linux/hwmon-sysfs.h>
7 #include <linux/hwmon.h>
35 * SF_* - scale factors for particular quantities according to hwmon spec.
54 * struct xe_hwmon - xe hwmon data structure
57 /** @hwmon_dev: hwmon device for xe */
73 static u32 xe_hwmon_get_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg hwmon_reg) in xe_hwmon_get_reg() argument
75 struct xe_device *xe = gt_to_xe(hwmon->gt); in xe_hwmon_get_reg()
108 drm_warn(&xe->drm, "Unknown xe hwmon reg id: %d\n", hwmon_reg); in xe_hwmon_get_reg()
115 static void xe_hwmon_process_reg(struct xe_hwmon *hwmon, enum xe_hwmon_reg hwmon_reg, in xe_hwmon_process_reg() argument
121 reg.raw = xe_hwmon_get_reg(hwmon, hwmon_reg); in xe_hwmon_process_reg()
128 *value = xe_mmio_read32(hwmon->gt, reg); in xe_hwmon_process_reg()
131 *value = xe_mmio_rmw32(hwmon->gt, reg, clr, set); in xe_hwmon_process_reg()
134 *value = xe_mmio_read64_2x32(hwmon->gt, reg); in xe_hwmon_process_reg()
137 drm_warn(>_to_xe(hwmon->gt)->drm, "Invalid xe hwmon reg operation: %d\n", in xe_hwmon_process_reg()
151 static void xe_hwmon_power_max_read(struct xe_hwmon *hwmon, long *value) in xe_hwmon_power_max_read() argument
155 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power_max_read()
157 xe_hwmon_process_reg(hwmon, REG_PKG_RAPL_LIMIT, REG_READ32, ®_val, 0, 0); in xe_hwmon_power_max_read()
165 *value = mul_u64_u32_shr(reg_val, SF_POWER, hwmon->scl_shift_power); in xe_hwmon_power_max_read()
167 xe_hwmon_process_reg(hwmon, REG_PKG_POWER_SKU, REG_READ64, ®_val, 0, 0); in xe_hwmon_power_max_read()
169 min = mul_u64_u32_shr(min, SF_POWER, hwmon->scl_shift_power); in xe_hwmon_power_max_read()
171 max = mul_u64_u32_shr(max, SF_POWER, hwmon->scl_shift_power); in xe_hwmon_power_max_read()
176 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power_max_read()
179 static int xe_hwmon_power_max_write(struct xe_hwmon *hwmon, long value) in xe_hwmon_power_max_write() argument
184 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power_max_write()
188 xe_hwmon_process_reg(hwmon, REG_PKG_RAPL_LIMIT, REG_RMW32, ®_val, in xe_hwmon_power_max_write()
190 xe_hwmon_process_reg(hwmon, REG_PKG_RAPL_LIMIT, REG_READ32, ®_val, in xe_hwmon_power_max_write()
200 reg_val = DIV_ROUND_CLOSEST_ULL((u64)value << hwmon->scl_shift_power, SF_POWER); in xe_hwmon_power_max_write()
203 xe_hwmon_process_reg(hwmon, REG_PKG_RAPL_LIMIT, REG_RMW32, ®_val, in xe_hwmon_power_max_write()
206 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power_max_write()
210 static void xe_hwmon_power_rated_max_read(struct xe_hwmon *hwmon, long *value) in xe_hwmon_power_rated_max_read() argument
214 xe_hwmon_process_reg(hwmon, REG_PKG_POWER_SKU, REG_READ32, ®_val, 0, 0); in xe_hwmon_power_rated_max_read()
216 *value = mul_u64_u32_shr(reg_val, SF_POWER, hwmon->scl_shift_power); in xe_hwmon_power_rated_max_read()
234 * the hwmon API. Using x86_64 128 bit arithmetic (see mul_u64_u32_shr()),
236 * hwmon->scl_shift_energy of 14 bits we have 57 (63 - 20 + 14) bits before
240 xe_hwmon_energy_get(struct xe_hwmon *hwmon, long *energy) in xe_hwmon_energy_get() argument
242 struct xe_hwmon_energy_info *ei = &hwmon->ei; in xe_hwmon_energy_get()
245 xe_hwmon_process_reg(hwmon, REG_PKG_ENERGY_STATUS, REG_READ32, in xe_hwmon_energy_get()
256 hwmon->scl_shift_energy); in xe_hwmon_energy_get()
263 struct xe_hwmon *hwmon = dev_get_drvdata(dev); in xe_hwmon_power1_max_interval_show() local
267 xe_device_mem_access_get(gt_to_xe(hwmon->gt)); in xe_hwmon_power1_max_interval_show()
269 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power1_max_interval_show()
271 xe_hwmon_process_reg(hwmon, REG_PKG_RAPL_LIMIT, in xe_hwmon_power1_max_interval_show()
274 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power1_max_interval_show()
276 xe_device_mem_access_put(gt_to_xe(hwmon->gt)); in xe_hwmon_power1_max_interval_show()
293 /* val in hwmon interface units (millisec) */ in xe_hwmon_power1_max_interval_show()
294 out = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w); in xe_hwmon_power1_max_interval_show()
303 struct xe_hwmon *hwmon = dev_get_drvdata(dev); in xe_hwmon_power1_max_interval_store() local
315 * The hwmon->scl_shift_time default of 0xa results in a max tau of 256 seconds. in xe_hwmon_power1_max_interval_store()
325 * val must be < max in hwmon interface units. The steps below are in xe_hwmon_power1_max_interval_store()
332 max_win = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w); in xe_hwmon_power1_max_interval_store()
338 val = DIV_ROUND_CLOSEST_ULL((u64)val << hwmon->scl_shift_time, SF_TIME); in xe_hwmon_power1_max_interval_store()
355 xe_device_mem_access_get(gt_to_xe(hwmon->gt)); in xe_hwmon_power1_max_interval_store()
357 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power1_max_interval_store()
359 xe_hwmon_process_reg(hwmon, REG_PKG_RAPL_LIMIT, REG_RMW32, (u64 *)&r, in xe_hwmon_power1_max_interval_store()
362 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power1_max_interval_store()
364 xe_device_mem_access_put(gt_to_xe(hwmon->gt)); in xe_hwmon_power1_max_interval_store()
382 struct xe_hwmon *hwmon = dev_get_drvdata(dev); in xe_hwmon_attributes_visible() local
385 xe_device_mem_access_get(gt_to_xe(hwmon->gt)); in xe_hwmon_attributes_visible()
388 ret = xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT) ? attr->mode : 0; in xe_hwmon_attributes_visible()
390 xe_device_mem_access_put(gt_to_xe(hwmon->gt)); in xe_hwmon_attributes_visible()
432 static int xe_hwmon_power_curr_crit_read(struct xe_hwmon *hwmon, long *value, u32 scale_factor) in xe_hwmon_power_curr_crit_read() argument
437 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power_curr_crit_read()
439 ret = xe_hwmon_pcode_read_i1(hwmon->gt, &uval); in xe_hwmon_power_curr_crit_read()
446 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power_curr_crit_read()
450 static int xe_hwmon_power_curr_crit_write(struct xe_hwmon *hwmon, long value, u32 scale_factor) in xe_hwmon_power_curr_crit_write() argument
455 mutex_lock(&hwmon->hwmon_lock); in xe_hwmon_power_curr_crit_write()
458 ret = xe_hwmon_pcode_write_i1(hwmon->gt, uval); in xe_hwmon_power_curr_crit_write()
460 mutex_unlock(&hwmon->hwmon_lock); in xe_hwmon_power_curr_crit_write()
464 static void xe_hwmon_get_voltage(struct xe_hwmon *hwmon, long *value) in xe_hwmon_get_voltage() argument
468 xe_hwmon_process_reg(hwmon, REG_GT_PERF_STATUS, in xe_hwmon_get_voltage()
475 xe_hwmon_power_is_visible(struct xe_hwmon *hwmon, u32 attr, int chan) in xe_hwmon_power_is_visible() argument
481 return xe_hwmon_get_reg(hwmon, REG_PKG_RAPL_LIMIT) ? 0664 : 0; in xe_hwmon_power_is_visible()
483 return xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU) ? 0444 : 0; in xe_hwmon_power_is_visible()
485 return (xe_hwmon_pcode_read_i1(hwmon->gt, &uval) || in xe_hwmon_power_is_visible()
493 xe_hwmon_power_read(struct xe_hwmon *hwmon, u32 attr, int chan, long *val) in xe_hwmon_power_read() argument
497 xe_hwmon_power_max_read(hwmon, val); in xe_hwmon_power_read()
500 xe_hwmon_power_rated_max_read(hwmon, val); in xe_hwmon_power_read()
503 return xe_hwmon_power_curr_crit_read(hwmon, val, SF_POWER); in xe_hwmon_power_read()
510 xe_hwmon_power_write(struct xe_hwmon *hwmon, u32 attr, int chan, long val) in xe_hwmon_power_write() argument
514 return xe_hwmon_power_max_write(hwmon, val); in xe_hwmon_power_write()
516 return xe_hwmon_power_curr_crit_write(hwmon, val, SF_POWER); in xe_hwmon_power_write()
523 xe_hwmon_curr_is_visible(const struct xe_hwmon *hwmon, u32 attr) in xe_hwmon_curr_is_visible() argument
529 return (xe_hwmon_pcode_read_i1(hwmon->gt, &uval) || in xe_hwmon_curr_is_visible()
537 xe_hwmon_curr_read(struct xe_hwmon *hwmon, u32 attr, long *val) in xe_hwmon_curr_read() argument
541 return xe_hwmon_power_curr_crit_read(hwmon, val, SF_CURR); in xe_hwmon_curr_read()
548 xe_hwmon_curr_write(struct xe_hwmon *hwmon, u32 attr, long val) in xe_hwmon_curr_write() argument
552 return xe_hwmon_power_curr_crit_write(hwmon, val, SF_CURR); in xe_hwmon_curr_write()
559 xe_hwmon_in_is_visible(struct xe_hwmon *hwmon, u32 attr) in xe_hwmon_in_is_visible() argument
563 return xe_hwmon_get_reg(hwmon, REG_GT_PERF_STATUS) ? 0444 : 0; in xe_hwmon_in_is_visible()
570 xe_hwmon_in_read(struct xe_hwmon *hwmon, u32 attr, long *val) in xe_hwmon_in_read() argument
574 xe_hwmon_get_voltage(hwmon, val); in xe_hwmon_in_read()
582 xe_hwmon_energy_is_visible(struct xe_hwmon *hwmon, u32 attr) in xe_hwmon_energy_is_visible() argument
586 return xe_hwmon_get_reg(hwmon, REG_PKG_ENERGY_STATUS) ? 0444 : 0; in xe_hwmon_energy_is_visible()
593 xe_hwmon_energy_read(struct xe_hwmon *hwmon, u32 attr, long *val) in xe_hwmon_energy_read() argument
597 xe_hwmon_energy_get(hwmon, val); in xe_hwmon_energy_read()
608 struct xe_hwmon *hwmon = (struct xe_hwmon *)drvdata; in xe_hwmon_is_visible() local
611 xe_device_mem_access_get(gt_to_xe(hwmon->gt)); in xe_hwmon_is_visible()
615 ret = xe_hwmon_power_is_visible(hwmon, attr, channel); in xe_hwmon_is_visible()
618 ret = xe_hwmon_curr_is_visible(hwmon, attr); in xe_hwmon_is_visible()
621 ret = xe_hwmon_in_is_visible(hwmon, attr); in xe_hwmon_is_visible()
624 ret = xe_hwmon_energy_is_visible(hwmon, attr); in xe_hwmon_is_visible()
631 xe_device_mem_access_put(gt_to_xe(hwmon->gt)); in xe_hwmon_is_visible()
640 struct xe_hwmon *hwmon = dev_get_drvdata(dev); in xe_hwmon_read() local
643 xe_device_mem_access_get(gt_to_xe(hwmon->gt)); in xe_hwmon_read()
647 ret = xe_hwmon_power_read(hwmon, attr, channel, val); in xe_hwmon_read()
650 ret = xe_hwmon_curr_read(hwmon, attr, val); in xe_hwmon_read()
653 ret = xe_hwmon_in_read(hwmon, attr, val); in xe_hwmon_read()
656 ret = xe_hwmon_energy_read(hwmon, attr, val); in xe_hwmon_read()
663 xe_device_mem_access_put(gt_to_xe(hwmon->gt)); in xe_hwmon_read()
672 struct xe_hwmon *hwmon = dev_get_drvdata(dev); in xe_hwmon_write() local
675 xe_device_mem_access_get(gt_to_xe(hwmon->gt)); in xe_hwmon_write()
679 ret = xe_hwmon_power_write(hwmon, attr, channel, val); in xe_hwmon_write()
682 ret = xe_hwmon_curr_write(hwmon, attr, val); in xe_hwmon_write()
689 xe_device_mem_access_put(gt_to_xe(hwmon->gt)); in xe_hwmon_write()
708 struct xe_hwmon *hwmon = xe->hwmon; in xe_hwmon_get_preregistration_info() local
716 if (xe_hwmon_get_reg(hwmon, REG_PKG_POWER_SKU_UNIT)) { in xe_hwmon_get_preregistration_info()
717 xe_hwmon_process_reg(hwmon, REG_PKG_POWER_SKU_UNIT, in xe_hwmon_get_preregistration_info()
719 hwmon->scl_shift_power = REG_FIELD_GET(PKG_PWR_UNIT, val_sku_unit); in xe_hwmon_get_preregistration_info()
720 hwmon->scl_shift_energy = REG_FIELD_GET(PKG_ENERGY_UNIT, val_sku_unit); in xe_hwmon_get_preregistration_info()
721 hwmon->scl_shift_time = REG_FIELD_GET(PKG_TIME_UNIT, val_sku_unit); in xe_hwmon_get_preregistration_info()
728 if (xe_hwmon_is_visible(hwmon, hwmon_energy, hwmon_energy_input, 0)) in xe_hwmon_get_preregistration_info()
729 xe_hwmon_energy_get(hwmon, &energy); in xe_hwmon_get_preregistration_info()
734 struct xe_hwmon *hwmon = arg; in xe_hwmon_mutex_destroy() local
736 mutex_destroy(&hwmon->hwmon_lock); in xe_hwmon_mutex_destroy()
742 struct xe_hwmon *hwmon; in xe_hwmon_register() local
744 /* hwmon is available only for dGfx */ in xe_hwmon_register()
748 hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); in xe_hwmon_register()
749 if (!hwmon) in xe_hwmon_register()
752 xe->hwmon = hwmon; in xe_hwmon_register()
754 mutex_init(&hwmon->hwmon_lock); in xe_hwmon_register()
755 if (devm_add_action_or_reset(dev, xe_hwmon_mutex_destroy, hwmon)) in xe_hwmon_register()
759 hwmon->gt = xe->tiles[0].primary_gt; in xe_hwmon_register()
763 drm_dbg(&xe->drm, "Register xe hwmon interface\n"); in xe_hwmon_register()
765 /* hwmon_dev points to device hwmon<i> */ in xe_hwmon_register()
766 hwmon->hwmon_dev = devm_hwmon_device_register_with_info(dev, "xe", hwmon, in xe_hwmon_register()
770 if (IS_ERR(hwmon->hwmon_dev)) { in xe_hwmon_register()
771 drm_warn(&xe->drm, "Failed to register xe hwmon (%pe)\n", hwmon->hwmon_dev); in xe_hwmon_register()
772 xe->hwmon = NULL; in xe_hwmon_register()