drivers/gpu/drm/i915/i915_hwmon.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/i915/i915_hwmon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/i915/i915_hwmon.c- Extension
.c- Size
- 25511 bytes
- Lines
- 997
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/hwmon.hlinux/hwmon-sysfs.hlinux/jiffies.hlinux/types.hlinux/units.hdrm/intel/intel_pcode_regs.hdrm/intel/mchbar_regs.hi915_drv.hi915_hwmon.hi915_reg.hintel_pcode.hgt/intel_gt.hgt/intel_gt_regs.h
Detected Declarations
struct hwm_regstruct hwm_energy_infostruct hwm_fan_infostruct hwm_drvdatastruct i915_hwmonfunction hwm_locked_with_pm_intel_uncore_rmwfunction with_intel_runtime_pmfunction hwm_field_read_and_scalefunction bitsfunction with_intel_runtime_pmfunction hwm_power1_max_interval_showfunction hwm_power1_max_interval_storefunction hwm_attributes_visiblefunction hwm_pcode_read_i1function hwm_pcode_write_i1function hwm_temp_is_visiblefunction hwm_temp_readfunction hwm_in_is_visiblefunction hwm_in_readfunction hwm_power_is_visiblefunction hwm_power_max_readfunction hwm_power_max_writefunction hwm_power_readfunction hwm_power_writefunction i915_hwmon_power_max_disablefunction i915_hwmon_power_max_restorefunction hwm_energy_is_visiblefunction hwm_energy_readfunction hwm_curr_is_visiblefunction hwm_curr_readfunction hwm_curr_writefunction hwm_fan_is_visiblefunction hwm_fan_input_readfunction hwm_fan_readfunction hwm_is_visiblefunction hwm_readfunction hwm_writefunction hwm_gt_is_visiblefunction hwm_gt_readfunction hwm_get_preregistration_infofunction with_intel_runtime_pmfunction i915_hwmon_registerfunction for_each_gtfunction for_each_gtfunction i915_hwmon_unregister
Annotated Snippet
struct hwm_reg {
i915_reg_t gt_perf_status;
i915_reg_t pkg_temp;
i915_reg_t pkg_power_sku_unit;
i915_reg_t pkg_power_sku;
i915_reg_t pkg_rapl_limit;
i915_reg_t energy_status_all;
i915_reg_t energy_status_tile;
i915_reg_t fan_speed;
};
struct hwm_energy_info {
u32 reg_val_prev;
long accum_energy; /* Accumulated energy for energy1_input */
};
struct hwm_fan_info {
u32 reg_val_prev;
u64 time_prev;
};
struct hwm_drvdata {
struct i915_hwmon *hwmon;
struct intel_uncore *uncore;
struct device *hwmon_dev;
struct hwm_energy_info ei; /* Energy info for energy1_input */
struct hwm_fan_info fi; /* Fan info for fan1_input */
char name[12];
int gt_n;
bool reset_in_progress;
wait_queue_head_t waitq;
};
struct i915_hwmon {
struct hwm_drvdata ddat;
struct hwm_drvdata ddat_gt[I915_MAX_GT];
struct mutex hwmon_lock; /* counter overflow logic and rmw */
struct hwm_reg rg;
int scl_shift_power;
int scl_shift_energy;
int scl_shift_time;
};
static void
hwm_locked_with_pm_intel_uncore_rmw(struct hwm_drvdata *ddat,
i915_reg_t reg, u32 clear, u32 set)
{
struct i915_hwmon *hwmon = ddat->hwmon;
struct intel_uncore *uncore = ddat->uncore;
intel_wakeref_t wakeref;
with_intel_runtime_pm(uncore->rpm, wakeref) {
mutex_lock(&hwmon->hwmon_lock);
intel_uncore_rmw(uncore, reg, clear, set);
mutex_unlock(&hwmon->hwmon_lock);
}
}
/*
* This function's return type of u64 allows for the case where the scaling
* of the field taken from the 32-bit register value might cause a result to
* exceed 32 bits.
*/
static u64
hwm_field_read_and_scale(struct hwm_drvdata *ddat, i915_reg_t rgadr,
u32 field_msk, int nshift, u32 scale_factor)
{
struct intel_uncore *uncore = ddat->uncore;
intel_wakeref_t wakeref;
u32 reg_value;
with_intel_runtime_pm(uncore->rpm, wakeref)
reg_value = intel_uncore_read(uncore, rgadr);
reg_value = REG_FIELD_GET(field_msk, reg_value);
return mul_u64_u32_shr(reg_value, scale_factor, nshift);
}
/*
* hwm_energy - Obtain energy value
*
* The underlying energy hardware register is 32-bits and is subject to
* overflow. How long before overflow? For example, with an example
* scaling bit shift of 14 bits (see register *PACKAGE_POWER_SKU_UNIT) and
* a power draw of 1000 watts, the 32-bit counter will overflow in
* approximately 4.36 minutes.
*
Annotation
- Immediate include surface: `linux/hwmon.h`, `linux/hwmon-sysfs.h`, `linux/jiffies.h`, `linux/types.h`, `linux/units.h`, `drm/intel/intel_pcode_regs.h`, `drm/intel/mchbar_regs.h`, `i915_drv.h`.
- Detected declarations: `struct hwm_reg`, `struct hwm_energy_info`, `struct hwm_fan_info`, `struct hwm_drvdata`, `struct i915_hwmon`, `function hwm_locked_with_pm_intel_uncore_rmw`, `function with_intel_runtime_pm`, `function hwm_field_read_and_scale`, `function bits`, `function with_intel_runtime_pm`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.