Lines Matching full:hwmon
6 #include <linux/hwmon.h>
7 #include <linux/hwmon-sysfs.h>
19 * SF_* - scale factors for particular quantities according to hwmon spec.
47 struct i915_hwmon *hwmon; member
71 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_locked_with_pm_intel_uncore_rmw() local
76 mutex_lock(&hwmon->hwmon_lock); in hwm_locked_with_pm_intel_uncore_rmw()
80 mutex_unlock(&hwmon->hwmon_lock); in hwm_locked_with_pm_intel_uncore_rmw()
120 * the hwmon API. Using x86_64 128 bit arithmetic (see mul_u64_u32_shr()),
122 * hwmon->scl_shift_energy of 14 bits we have 57 (63 - 20 + 14) bits before
129 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_energy() local
136 rgaddr = hwmon->rg.energy_status_tile; in hwm_energy()
138 rgaddr = hwmon->rg.energy_status_all; in hwm_energy()
141 mutex_lock(&hwmon->hwmon_lock); in hwm_energy()
152 hwmon->scl_shift_energy); in hwm_energy()
153 mutex_unlock(&hwmon->hwmon_lock); in hwm_energy()
162 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power1_max_interval_show() local
168 r = intel_uncore_read(ddat->uncore, hwmon->rg.pkg_rapl_limit); in hwm_power1_max_interval_show()
181 /* val in hwmon interface units (millisec) */ in hwm_power1_max_interval_show()
182 out = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w); in hwm_power1_max_interval_show()
193 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power1_max_interval_store() local
205 * The hwmon->scl_shift_time default of 0xa results in a max tau of 256 seconds in hwm_power1_max_interval_store()
210 * val must be < max in hwmon interface units. The steps below are in hwm_power1_max_interval_store()
217 max_win = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w); in hwm_power1_max_interval_store()
223 val = DIV_ROUND_CLOSEST_ULL((u64)val << hwmon->scl_shift_time, SF_TIME); in hwm_power1_max_interval_store()
237 hwm_locked_with_pm_intel_uncore_rmw(ddat, hwmon->rg.pkg_rapl_limit, in hwm_power1_max_interval_store()
256 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_attributes_visible() local
259 return i915_mmio_reg_valid(hwmon->rg.pkg_rapl_limit) ? attr->mode : 0; in hwm_attributes_visible()
320 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_in_read() local
327 reg_value = intel_uncore_read(ddat->uncore, hwmon->rg.gt_perf_status); in hwm_in_read()
340 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power_is_visible() local
345 return i915_mmio_reg_valid(hwmon->rg.pkg_rapl_limit) ? 0664 : 0; in hwm_power_is_visible()
347 return i915_mmio_reg_valid(hwmon->rg.pkg_power_sku) ? 0444 : 0; in hwm_power_is_visible()
367 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power_max_read() local
373 r = intel_uncore_read(ddat->uncore, hwmon->rg.pkg_rapl_limit); in hwm_power_max_read()
380 hwmon->rg.pkg_rapl_limit, in hwm_power_max_read()
382 hwmon->scl_shift_power, in hwm_power_max_read()
386 r = intel_uncore_read64(ddat->uncore, hwmon->rg.pkg_power_sku); in hwm_power_max_read()
388 min = mul_u64_u32_shr(min, SF_POWER, hwmon->scl_shift_power); in hwm_power_max_read()
390 max = mul_u64_u32_shr(max, SF_POWER, hwmon->scl_shift_power); in hwm_power_max_read()
401 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power_max_write() local
410 mutex_lock(&hwmon->hwmon_lock); in hwm_power_max_write()
414 if (!hwmon->ddat.reset_in_progress) in hwm_power_max_write()
422 mutex_unlock(&hwmon->hwmon_lock); in hwm_power_max_write()
433 intel_uncore_rmw(ddat->uncore, hwmon->rg.pkg_rapl_limit, in hwm_power_max_write()
435 nval = intel_uncore_read(ddat->uncore, hwmon->rg.pkg_rapl_limit); in hwm_power_max_write()
443 nval = DIV_ROUND_CLOSEST_ULL((u64)val << hwmon->scl_shift_power, SF_POWER); in hwm_power_max_write()
446 intel_uncore_rmw(ddat->uncore, hwmon->rg.pkg_rapl_limit, in hwm_power_max_write()
449 mutex_unlock(&hwmon->hwmon_lock); in hwm_power_max_write()
457 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_power_read() local
466 hwmon->rg.pkg_power_sku, in hwm_power_read()
468 hwmon->scl_shift_power, in hwm_power_read()
503 struct i915_hwmon *hwmon = i915->hwmon; in i915_hwmon_power_max_disable() local
506 if (!hwmon || !i915_mmio_reg_valid(hwmon->rg.pkg_rapl_limit)) in i915_hwmon_power_max_disable()
509 mutex_lock(&hwmon->hwmon_lock); in i915_hwmon_power_max_disable()
511 hwmon->ddat.reset_in_progress = true; in i915_hwmon_power_max_disable()
512 r = intel_uncore_rmw(hwmon->ddat.uncore, hwmon->rg.pkg_rapl_limit, in i915_hwmon_power_max_disable()
516 mutex_unlock(&hwmon->hwmon_lock); in i915_hwmon_power_max_disable()
521 struct i915_hwmon *hwmon = i915->hwmon; in i915_hwmon_power_max_restore() local
523 if (!hwmon || !i915_mmio_reg_valid(hwmon->rg.pkg_rapl_limit)) in i915_hwmon_power_max_restore()
526 mutex_lock(&hwmon->hwmon_lock); in i915_hwmon_power_max_restore()
528 intel_uncore_rmw(hwmon->ddat.uncore, hwmon->rg.pkg_rapl_limit, in i915_hwmon_power_max_restore()
530 hwmon->ddat.reset_in_progress = false; in i915_hwmon_power_max_restore()
531 wake_up_all(&hwmon->ddat.waitq); in i915_hwmon_power_max_restore()
533 mutex_unlock(&hwmon->hwmon_lock); in i915_hwmon_power_max_restore()
539 struct i915_hwmon *hwmon = ddat->hwmon; in hwm_energy_is_visible() local
545 rgaddr = hwmon->rg.energy_status_tile; in hwm_energy_is_visible()
547 rgaddr = hwmon->rg.energy_status_all; in hwm_energy_is_visible()
724 struct i915_hwmon *hwmon = i915->hwmon; in hwm_get_preregistration_info() local
726 struct hwm_drvdata *ddat = &hwmon->ddat; in hwm_get_preregistration_info()
734 hwmon->rg.gt_perf_status = GEN12_RPSTAT1; in hwm_get_preregistration_info()
737 hwmon->rg.pkg_power_sku_unit = PCU_PACKAGE_POWER_SKU_UNIT; in hwm_get_preregistration_info()
738 hwmon->rg.pkg_power_sku = PCU_PACKAGE_POWER_SKU; in hwm_get_preregistration_info()
739 hwmon->rg.pkg_rapl_limit = PCU_PACKAGE_RAPL_LIMIT; in hwm_get_preregistration_info()
740 hwmon->rg.energy_status_all = PCU_PACKAGE_ENERGY_STATUS; in hwm_get_preregistration_info()
741 hwmon->rg.energy_status_tile = INVALID_MMIO_REG; in hwm_get_preregistration_info()
743 hwmon->rg.pkg_power_sku_unit = GT0_PACKAGE_POWER_SKU_UNIT; in hwm_get_preregistration_info()
744 hwmon->rg.pkg_power_sku = INVALID_MMIO_REG; in hwm_get_preregistration_info()
745 hwmon->rg.pkg_rapl_limit = GT0_PACKAGE_RAPL_LIMIT; in hwm_get_preregistration_info()
746 hwmon->rg.energy_status_all = GT0_PLATFORM_ENERGY_STATUS; in hwm_get_preregistration_info()
747 hwmon->rg.energy_status_tile = GT0_PACKAGE_ENERGY_STATUS; in hwm_get_preregistration_info()
749 hwmon->rg.pkg_power_sku_unit = INVALID_MMIO_REG; in hwm_get_preregistration_info()
750 hwmon->rg.pkg_power_sku = INVALID_MMIO_REG; in hwm_get_preregistration_info()
751 hwmon->rg.pkg_rapl_limit = INVALID_MMIO_REG; in hwm_get_preregistration_info()
752 hwmon->rg.energy_status_all = INVALID_MMIO_REG; in hwm_get_preregistration_info()
753 hwmon->rg.energy_status_tile = INVALID_MMIO_REG; in hwm_get_preregistration_info()
758 * The contents of register hwmon->rg.pkg_power_sku_unit do not change, in hwm_get_preregistration_info()
761 if (i915_mmio_reg_valid(hwmon->rg.pkg_power_sku_unit)) in hwm_get_preregistration_info()
763 hwmon->rg.pkg_power_sku_unit); in hwm_get_preregistration_info()
766 hwmon->scl_shift_power = REG_FIELD_GET(PKG_PWR_UNIT, val_sku_unit); in hwm_get_preregistration_info()
767 hwmon->scl_shift_energy = REG_FIELD_GET(PKG_ENERGY_UNIT, val_sku_unit); in hwm_get_preregistration_info()
768 hwmon->scl_shift_time = REG_FIELD_GET(PKG_TIME_UNIT, val_sku_unit); in hwm_get_preregistration_info()
774 if (i915_mmio_reg_valid(hwmon->rg.energy_status_all)) in hwm_get_preregistration_info()
776 if (i915_mmio_reg_valid(hwmon->rg.energy_status_tile)) { in hwm_get_preregistration_info()
778 hwm_energy(&hwmon->ddat_gt[i], &energy); in hwm_get_preregistration_info()
785 struct i915_hwmon *hwmon; in i915_hwmon_register() local
792 /* hwmon is available only for dGfx */ in i915_hwmon_register()
796 hwmon = kzalloc(sizeof(*hwmon), GFP_KERNEL); in i915_hwmon_register()
797 if (!hwmon) in i915_hwmon_register()
800 i915->hwmon = hwmon; in i915_hwmon_register()
801 mutex_init(&hwmon->hwmon_lock); in i915_hwmon_register()
802 ddat = &hwmon->ddat; in i915_hwmon_register()
804 ddat->hwmon = hwmon; in i915_hwmon_register()
811 ddat_gt = hwmon->ddat_gt + i; in i915_hwmon_register()
813 ddat_gt->hwmon = hwmon; in i915_hwmon_register()
821 /* hwmon_dev points to device hwmon<i> */ in i915_hwmon_register()
832 ddat_gt = hwmon->ddat_gt + i; in i915_hwmon_register()
854 struct i915_hwmon *hwmon = i915->hwmon; in i915_hwmon_unregister() local
858 if (!hwmon) in i915_hwmon_unregister()
862 if (hwmon->ddat_gt[i].hwmon_dev) in i915_hwmon_unregister()
863 hwmon_device_unregister(hwmon->ddat_gt[i].hwmon_dev); in i915_hwmon_unregister()
865 if (hwmon->ddat.hwmon_dev) in i915_hwmon_unregister()
866 hwmon_device_unregister(hwmon->ddat.hwmon_dev); in i915_hwmon_unregister()
868 mutex_destroy(&hwmon->hwmon_lock); in i915_hwmon_unregister()
870 kfree(i915->hwmon); in i915_hwmon_unregister()
871 i915->hwmon = NULL; in i915_hwmon_unregister()