drivers/thermal/intel/int340x_thermal/processor_thermal_wt_hint.c

Source file repositories/reference/linux-study-clean/drivers/thermal/intel/int340x_thermal/processor_thermal_wt_hint.c

File Facts

System
Linux kernel
Corpus path
drivers/thermal/intel/int340x_thermal/processor_thermal_wt_hint.c
Extension
.c
Size
7647 bytes
Lines
298
Domain
Driver Families
Bucket
drivers/thermal
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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

// SPDX-License-Identifier: GPL-2.0-only
/*
 * processor thermal device interface for reading workload type hints
 * from the user space. The hints are provided by the firmware.
 *
 * Operation:
 * When user space enables workload type prediction:
 * - Use mailbox to:
 *	Configure notification delay
 *	Enable processor thermal device interrupt
 *
 * - The predicted workload type can be read from MMIO:
 *	Offset 0x5B18 shows if there was an interrupt
 *	active for change in workload type and also
 *	predicted workload type.
 *
 * Two interface functions are provided to call when there is a
 * thermal device interrupt:
 * - proc_thermal_check_wt_intr():
 *     Check if the interrupt is for change in workload type. Called from
 *     interrupt context.
 *
 * - proc_thermal_wt_intr_callback():
 *     Callback for interrupt processing in thread context. This involves
 *	sending notification to user space that there is a change in the
 *     workload type.
 *
 * Copyright (c) 2023, Intel Corporation.
 */

#include <linux/bitfield.h>
#include <linux/pci.h>
#include "processor_thermal_device.h"

#define SOC_WT				GENMASK_ULL(47, 40)

#define SOC_WT_SLOW_PREDICTION_INT_ENABLE_BIT	22
#define SOC_WT_PREDICTION_INT_ENABLE_BIT	23

#define SOC_WT_PREDICTION_INT_ACTIVE	BIT(2)

/*
 * Closest possible to 1 Second is 1024 ms with programmed time delay
 * of 0x0A.
 */
static u8 notify_delay = 0x0A;
static u16 notify_delay_ms = 1024;

static DEFINE_MUTEX(wt_lock);
static u8 wt_enable;
static u8 wt_slow_enable;

/* Show current predicted workload type index */
static ssize_t workload_type_index_show(struct device *dev,
					struct device_attribute *attr,
					char *buf)
{
	struct proc_thermal_device *proc_priv;
	struct pci_dev *pdev = to_pci_dev(dev);
	u64 status = 0;
	int wt;

	mutex_lock(&wt_lock);
	if (!wt_enable && !wt_slow_enable) {
		mutex_unlock(&wt_lock);
		return -ENODATA;
	}

	proc_priv = pci_get_drvdata(pdev);

	status = readq(proc_priv->mmio_base + SOC_WT_RES_INT_STATUS_OFFSET);

	mutex_unlock(&wt_lock);

	wt = FIELD_GET(SOC_WT, status);

	return sysfs_emit(buf, "%d\n", wt);
}

static DEVICE_ATTR_RO(workload_type_index);

static ssize_t workload_hint_enable_show(struct device *dev,
					 struct device_attribute *attr,
					 char *buf)
{
	return sysfs_emit(buf, "%d\n", wt_enable);
}

static ssize_t workload_hint_enable(struct device *dev, u8 enable_bit, u8 *status,
				    struct device_attribute *attr,

Annotation

Implementation Notes