Skip to content

Commit 1e94cb6

Browse files
committed
Merge back earlier thermal control updates for 6.17
2 parents 9bf3eb1 + 866032d commit 1e94cb6

File tree

6 files changed

+92
-4
lines changed

6 files changed

+92
-4
lines changed

Documentation/driver-api/thermal/intel_dptf.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ All these controls needs admin privilege to update.
206206
Update a new temperature target in milli degree celsius for hardware to
207207
use for the temperature control.
208208

209+
``thermal_tolerance`` (RW)
210+
This attribute ranges from 0 to 7, where 0 represents
211+
the most aggressive control to avoid any temperature overshoots, and
212+
7 represents a more graceful approach, favoring performance even at
213+
the expense of temperature overshoots.
214+
Note: This level may not scale linearly. For example, a value of 3 does
215+
not necessarily imply a 50% improvement in performance compared to a
216+
value of 0.
217+
209218
Given that this is platform temperature control, it is expected that a
210219
single user-level manager owns and manages the controls. If multiple
211220
user-level software applications attempt to write different targets, it

drivers/thermal/intel/int340x_thermal/platform_temperature_control.c

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include <linux/kernel.h>
4040
#include <linux/module.h>
41+
#include <linux/debugfs.h>
4142
#include <linux/pci.h>
4243
#include "processor_thermal_device.h"
4344

@@ -49,14 +50,16 @@ struct mmio_reg {
4950
};
5051

5152
#define MAX_ATTR_GROUP_NAME_LEN 32
52-
#define PTC_MAX_ATTRS 3
53+
#define PTC_MAX_ATTRS 4
5354

5455
struct ptc_data {
5556
u32 offset;
57+
struct pci_dev *pdev;
5658
struct attribute_group ptc_attr_group;
5759
struct attribute *ptc_attrs[PTC_MAX_ATTRS];
5860
struct device_attribute temperature_target_attr;
5961
struct device_attribute enable_attr;
62+
struct device_attribute thermal_tolerance_attr;
6063
char group_name[MAX_ATTR_GROUP_NAME_LEN];
6164
};
6265

@@ -78,6 +81,7 @@ static u32 ptc_offsets[PTC_MAX_INSTANCES] = {0x5B20, 0x5B28, 0x5B30};
7881
static const char * const ptc_strings[] = {
7982
"temperature_target",
8083
"enable",
84+
"thermal_tolerance",
8185
NULL
8286
};
8387

@@ -177,6 +181,8 @@ PTC_SHOW(temperature_target);
177181
PTC_STORE(temperature_target);
178182
PTC_SHOW(enable);
179183
PTC_STORE(enable);
184+
PTC_SHOW(thermal_tolerance);
185+
PTC_STORE(thermal_tolerance);
180186

181187
#define ptc_init_attribute(_name)\
182188
do {\
@@ -193,9 +199,11 @@ static int ptc_create_groups(struct pci_dev *pdev, int instance, struct ptc_data
193199

194200
ptc_init_attribute(temperature_target);
195201
ptc_init_attribute(enable);
202+
ptc_init_attribute(thermal_tolerance);
196203

197204
data->ptc_attrs[index++] = &data->temperature_target_attr.attr;
198205
data->ptc_attrs[index++] = &data->enable_attr.attr;
206+
data->ptc_attrs[index++] = &data->thermal_tolerance_attr.attr;
199207
data->ptc_attrs[index] = NULL;
200208

201209
snprintf(data->group_name, MAX_ATTR_GROUP_NAME_LEN,
@@ -209,6 +217,63 @@ static int ptc_create_groups(struct pci_dev *pdev, int instance, struct ptc_data
209217
}
210218

211219
static struct ptc_data ptc_instance[PTC_MAX_INSTANCES];
220+
static struct dentry *ptc_debugfs;
221+
222+
#define PTC_TEMP_OVERRIDE_ENABLE_INDEX 4
223+
#define PTC_TEMP_OVERRIDE_INDEX 5
224+
225+
static ssize_t ptc_temperature_write(struct file *file, const char __user *data,
226+
size_t count, loff_t *ppos)
227+
{
228+
struct ptc_data *ptc_instance = file->private_data;
229+
struct pci_dev *pdev = ptc_instance->pdev;
230+
char buf[32];
231+
ssize_t len;
232+
u32 value;
233+
234+
len = min(count, sizeof(buf) - 1);
235+
if (copy_from_user(buf, data, len))
236+
return -EFAULT;
237+
238+
buf[len] = '\0';
239+
if (kstrtouint(buf, 0, &value))
240+
return -EINVAL;
241+
242+
if (ptc_mmio_regs[PTC_TEMP_OVERRIDE_INDEX].units)
243+
value /= ptc_mmio_regs[PTC_TEMP_OVERRIDE_INDEX].units;
244+
245+
if (value > ptc_mmio_regs[PTC_TEMP_OVERRIDE_INDEX].mask)
246+
return -EINVAL;
247+
248+
if (!value) {
249+
ptc_mmio_write(pdev, ptc_instance->offset, PTC_TEMP_OVERRIDE_ENABLE_INDEX, 0);
250+
} else {
251+
ptc_mmio_write(pdev, ptc_instance->offset, PTC_TEMP_OVERRIDE_INDEX, value);
252+
ptc_mmio_write(pdev, ptc_instance->offset, PTC_TEMP_OVERRIDE_ENABLE_INDEX, 1);
253+
}
254+
255+
return count;
256+
}
257+
258+
static const struct file_operations ptc_fops = {
259+
.open = simple_open,
260+
.write = ptc_temperature_write,
261+
.llseek = generic_file_llseek,
262+
};
263+
264+
static void ptc_create_debugfs(void)
265+
{
266+
ptc_debugfs = debugfs_create_dir("platform_temperature_control", NULL);
267+
268+
debugfs_create_file("temperature_0", 0200, ptc_debugfs, &ptc_instance[0], &ptc_fops);
269+
debugfs_create_file("temperature_1", 0200, ptc_debugfs, &ptc_instance[1], &ptc_fops);
270+
debugfs_create_file("temperature_2", 0200, ptc_debugfs, &ptc_instance[2], &ptc_fops);
271+
}
272+
273+
static void ptc_delete_debugfs(void)
274+
{
275+
debugfs_remove_recursive(ptc_debugfs);
276+
}
212277

213278
int proc_thermal_ptc_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv)
214279
{
@@ -217,8 +282,11 @@ int proc_thermal_ptc_add(struct pci_dev *pdev, struct proc_thermal_device *proc_
217282

218283
for (i = 0; i < PTC_MAX_INSTANCES; i++) {
219284
ptc_instance[i].offset = ptc_offsets[i];
285+
ptc_instance[i].pdev = pdev;
220286
ptc_create_groups(pdev, i, &ptc_instance[i]);
221287
}
288+
289+
ptc_create_debugfs();
222290
}
223291

224292
return 0;
@@ -234,6 +302,8 @@ void proc_thermal_ptc_remove(struct pci_dev *pdev)
234302

235303
for (i = 0; i < PTC_MAX_INSTANCES; i++)
236304
sysfs_remove_group(&pdev->dev.kobj, &ptc_instance[i].ptc_attr_group);
305+
306+
ptc_delete_debugfs();
237307
}
238308
}
239309
EXPORT_SYMBOL_GPL(proc_thermal_ptc_remove);

drivers/thermal/intel/int340x_thermal/processor_thermal_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define PCI_DEVICE_ID_INTEL_SKL_THERMAL 0x1903
3232
#define PCI_DEVICE_ID_INTEL_TGL_THERMAL 0x9A03
3333
#define PCI_DEVICE_ID_INTEL_PTL_THERMAL 0xB01D
34+
#define PCI_DEVICE_ID_INTEL_WCL_THERMAL 0xFD1D
3435

3536
struct power_config {
3637
u32 index;

drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ static const struct pci_device_id proc_thermal_pci_ids[] = {
499499
PROC_THERMAL_FEATURE_DLVR | PROC_THERMAL_FEATURE_DVFS |
500500
PROC_THERMAL_FEATURE_MSI_SUPPORT | PROC_THERMAL_FEATURE_WT_HINT |
501501
PROC_THERMAL_FEATURE_POWER_FLOOR | PROC_THERMAL_FEATURE_PTC) },
502+
{ PCI_DEVICE_DATA(INTEL, WCL_THERMAL, PROC_THERMAL_FEATURE_MSI_SUPPORT |
503+
PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_DLVR |
504+
PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WT_HINT |
505+
PROC_THERMAL_FEATURE_POWER_FLOOR | PROC_THERMAL_FEATURE_PTC) },
502506
{ },
503507
};
504508

drivers/thermal/intel/int340x_thermal/processor_thermal_rfim.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ int proc_thermal_rfim_add(struct pci_dev *pdev, struct proc_thermal_device *proc
442442
switch (pdev->device) {
443443
case PCI_DEVICE_ID_INTEL_LNLM_THERMAL:
444444
case PCI_DEVICE_ID_INTEL_PTL_THERMAL:
445+
case PCI_DEVICE_ID_INTEL_WCL_THERMAL:
445446
dlvr_mmio_regs_table = lnl_dlvr_mmio_regs;
446447
dlvr_mapping = lnl_dlvr_mapping;
447448
break;

drivers/thermal/thermal_sysfs.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ temp_show(struct device *dev, struct device_attribute *attr, char *buf)
4040

4141
ret = thermal_zone_get_temp(tz, &temperature);
4242

43-
if (ret)
44-
return ret;
43+
if (!ret)
44+
return sprintf(buf, "%d\n", temperature);
4545

46-
return sprintf(buf, "%d\n", temperature);
46+
if (ret == -EAGAIN)
47+
return -ENODATA;
48+
49+
return ret;
4750
}
4851

4952
static ssize_t

0 commit comments

Comments
 (0)