drivers/gpu/drm/xe/xe_hwmon.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_hwmon.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/xe/xe_hwmon.c
Extension
.c
Size
46648 bytes
Lines
1586
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct xe_hwmon_energy_info {
	/** @reg_val_prev: previous energy reg val */
	u32 reg_val_prev;
	/** @accum_energy: accumulated energy */
	long accum_energy;
};

/**
 * struct xe_hwmon_fan_info - to cache previous fan reading
 */
struct xe_hwmon_fan_info {
	/** @reg_val_prev: previous fan reg val */
	u32 reg_val_prev;
	/** @time_prev: previous timestamp */
	u64 time_prev;
};

/**
 * struct xe_hwmon_thermal_info - to store temperature data
 */
struct xe_hwmon_thermal_info {
	union {
		/** @limit: temperatures limits */
		u8 limit[TEMP_LIMIT_MAX];
		/** @data: temperature limits in dwords */
		u32 data[DIV_ROUND_UP(TEMP_LIMIT_MAX, sizeof(u32))];
	};
	/** @count: no of temperature sensors available for the platform */
	u8 count;
	/** @value: signed value from each sensor */
	s8 value[U8_MAX];
	/** @vram_label: vram label names */
	char vram_label[MAX_VRAM_CHANNELS][MAX_LABEL_SIZE];
};

/**
 * struct xe_hwmon - xe hwmon data structure
 */
struct xe_hwmon {
	/** @hwmon_dev: hwmon device for xe */
	struct device *hwmon_dev;
	/** @xe: Xe device */
	struct xe_device *xe;
	/** @hwmon_lock: lock for rw attributes*/
	struct mutex hwmon_lock;
	/** @scl_shift_power: pkg power unit */
	int scl_shift_power;
	/** @scl_shift_energy: pkg energy unit */
	int scl_shift_energy;
	/** @scl_shift_time: pkg time unit */
	int scl_shift_time;
	/** @ei: Energy info for energyN_input */
	struct xe_hwmon_energy_info ei[CHANNEL_MAX];
	/** @fi: Fan info for fanN_input */
	struct xe_hwmon_fan_info fi[FAN_MAX];
	/** @boot_power_limit_read: is boot power limits read */
	bool boot_power_limit_read;
	/** @pl1_on_boot: power limit PL1 on boot */
	u32 pl1_on_boot[CHANNEL_MAX];
	/** @pl2_on_boot: power limit PL2 on boot */
	u32 pl2_on_boot[CHANNEL_MAX];
	/** @temp: Temperature info */
	struct xe_hwmon_thermal_info temp;
};

static inline int prepare_power_limit_param2(const struct xe_hwmon *hwmon)
{
	if (hwmon->boot_power_limit_read) {
		if (hwmon->xe->info.platform >= XE_CRESCENTISLAND)
			return READ_PL_ACCEPTED;
		else
			return READ_PL_FROM_PCODE;
	} else {
		return READ_PL_FROM_FW;
	}
}

static int xe_hwmon_pcode_read_power_limit(const struct xe_hwmon *hwmon, u32 attr, int channel,
					   u32 *uval)
{
	struct xe_tile *root_tile = xe_device_get_root_tile(hwmon->xe);
	u32 val0 = 0, val1 = 0;
	int ret = 0;

	ret = xe_pcode_read(root_tile, PCODE_MBOX(PCODE_POWER_SETUP,
						  (channel == CHANNEL_CARD) ?
						  READ_PSYSGPU_POWER_LIMIT :
						  READ_PACKAGE_POWER_LIMIT,
						  prepare_power_limit_param2(hwmon)), &val0, &val1);

Annotation

Implementation Notes