Skip to content

Commit 2b1f8ab

Browse files
committed
Merge: power: thermal: Add DLVR support for LNL Platform
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/5125 JIRA: https://issues.redhat.com/browse/RHEL-29349 Signed-off-by: David Arcari <[email protected]> Approved-by: Andrew Halaney <[email protected]> Approved-by: José Ignacio Tornos Martínez <[email protected]> Approved-by: CKI KWF Bot <[email protected]> Approved-by: John W. Linville <[email protected]> Merged-by: Rado Vrbovsky <[email protected]>
2 parents f2414b7 + 20290ad commit 2b1f8ab

26 files changed

+497
-111
lines changed

drivers/net/wireless/intel/iwlwifi/mvm/tt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ static int iwl_mvm_tzone_get_temp(struct thermal_zone_device *device,
638638
}
639639

640640
static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device,
641-
int trip, int temp)
641+
const struct thermal_trip *trip, int temp)
642642
{
643643
struct iwl_mvm *mvm = thermal_zone_device_priv(device);
644644
int ret;

drivers/thermal/imx_thermal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ static int imx_change_mode(struct thermal_zone_device *tz,
330330
return 0;
331331
}
332332

333-
static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip_id,
334-
int temp)
333+
static int imx_set_trip_temp(struct thermal_zone_device *tz,
334+
const struct thermal_trip *trip, int temp)
335335
{
336336
struct imx_thermal_data *data = tz->devdata;
337337
struct thermal_trip trip;

drivers/thermal/intel/int340x_thermal/acpi_thermal_rel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static int acpi_parse_psvt(acpi_handle handle, int *psvt_count, struct psvt **ps
309309

310310
if (knob->type == ACPI_TYPE_STRING) {
311311
memset(&psvt->limit, 0, sizeof(u64));
312-
strncpy(psvt->limit.string, psvt_ptr->limit.str_ptr, knob->string.length);
312+
strscpy(psvt->limit.string, psvt_ptr->limit.str_ptr, ACPI_LIMIT_STR_MAX_LEN);
313313
} else {
314314
psvt->limit.integer = psvt_ptr->limit.integer;
315315
}
@@ -468,7 +468,7 @@ static int fill_psvt(char __user *ubuf)
468468
psvt_user[i].unlimit_coeff = psvts[i].unlimit_coeff;
469469
psvt_user[i].control_knob_type = psvts[i].control_knob_type;
470470
if (psvt_user[i].control_knob_type == ACPI_TYPE_STRING)
471-
strncpy(psvt_user[i].limit.string, psvts[i].limit.string,
471+
strscpy(psvt_user[i].limit.string, psvts[i].limit.string,
472472
ACPI_LIMIT_STR_MAX_LEN);
473473
else
474474
psvt_user[i].limit.integer = psvts[i].limit.integer;

drivers/thermal/intel/int340x_thermal/int3400_thermal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ static int int3400_thermal_probe(struct platform_device *pdev)
578578
if (!adev)
579579
return -ENODEV;
580580

581-
priv = kzalloc(sizeof(struct int3400_thermal_priv), GFP_KERNEL);
581+
priv = kzalloc(sizeof(*priv), GFP_KERNEL);
582582
if (!priv)
583583
return -ENOMEM;
584584

drivers/thermal/intel/int340x_thermal/int3403_thermal.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@ struct int3403_sensor {
2525
struct int34x_thermal_zone *int340x_zone;
2626
};
2727

28-
struct int3403_performance_state {
29-
u64 performance;
30-
u64 power;
31-
u64 latency;
32-
u64 linear;
33-
u64 control;
34-
u64 raw_performace;
35-
char *raw_unit;
36-
int reserved;
37-
};
38-
3928
struct int3403_cdev {
4029
struct thermal_cooling_device *cdev;
4130
unsigned long max_state;

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,
3939
}
4040

4141
static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
42-
int trip, int temp)
42+
const struct thermal_trip *trip, int temp)
4343
{
4444
struct int34x_thermal_zone *d = thermal_zone_device_priv(zone);
45-
char name[] = {'P', 'A', 'T', '0' + trip, '\0'};
45+
unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv);
46+
char name[] = {'P', 'A', 'T', '0' + trip_index, '\0'};
4647
acpi_status status;
4748

48-
if (trip > 9)
49+
if (trip_index > 9)
4950
return -EINVAL;
5051

5152
status = acpi_execute_simple_method(d->adev->handle, name,
@@ -62,16 +63,6 @@ static void int340x_thermal_critical(struct thermal_zone_device *zone)
6263
thermal_zone_device_type(zone));
6364
}
6465

65-
static inline void *int_to_trip_priv(int i)
66-
{
67-
return (void *)(long)i;
68-
}
69-
70-
static inline int trip_priv_to_int(const struct thermal_trip *trip)
71-
{
72-
return (long)trip->priv;
73-
}
74-
7566
static int int340x_thermal_read_trips(struct acpi_device *zone_adev,
7667
struct thermal_trip *zone_trips,
7768
int trip_cnt)
@@ -106,7 +97,7 @@ static int int340x_thermal_read_trips(struct acpi_device *zone_adev,
10697
break;
10798

10899
zone_trips[trip_cnt].type = THERMAL_TRIP_ACTIVE;
109-
zone_trips[trip_cnt].priv = int_to_trip_priv(i);
100+
zone_trips[trip_cnt].priv = THERMAL_INT_TO_TRIP_PRIV(i);
110101
trip_cnt++;
111102
}
112103

@@ -154,6 +145,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
154145
zone_trips[i].type = THERMAL_TRIP_PASSIVE;
155146
zone_trips[i].temperature = THERMAL_TEMP_INVALID;
156147
zone_trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP;
148+
zone_trips[i].priv = THERMAL_INT_TO_TRIP_PRIV(i);
157149
}
158150

159151
trip_cnt = int340x_thermal_read_trips(adev, zone_trips, trip_cnt);
@@ -224,7 +216,7 @@ static int int340x_update_one_trip(struct thermal_trip *trip, void *arg)
224216
break;
225217
case THERMAL_TRIP_ACTIVE:
226218
err = thermal_acpi_active_trip_temp(zone_adev,
227-
trip_priv_to_int(trip),
219+
THERMAL_TRIP_PRIV_TO_INT(trip->priv),
228220
&temp);
229221
break;
230222
default:

drivers/thermal/intel/int340x_thermal/processor_thermal_device.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ void proc_thermal_mmio_remove(struct pci_dev *pdev, struct proc_thermal_device *
440440
proc_thermal_rapl_remove();
441441

442442
if (proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_FIVR ||
443-
proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_DVFS)
443+
proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_DVFS ||
444+
proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_DLVR)
444445
proc_thermal_rfim_remove(pdev);
445446

446447
if (proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_POWER_FLOOR)

drivers/thermal/intel/int340x_thermal/processor_thermal_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct rapl_mmio_regs {
6565
#define PROC_THERMAL_FEATURE_DLVR 0x10
6666
#define PROC_THERMAL_FEATURE_WT_HINT 0x20
6767
#define PROC_THERMAL_FEATURE_POWER_FLOOR 0x40
68+
#define PROC_THERMAL_FEATURE_MSI_SUPPORT 0x80
6869

6970
#if IS_ENABLED(CONFIG_PROC_THERMAL_MMIO_RAPL)
7071
int proc_thermal_rapl_add(struct pci_dev *pdev, struct proc_thermal_device *proc_priv);

drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c

Lines changed: 108 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ static struct proc_thermal_mmio_info proc_thermal_mmio_info[] = {
6363
{ PROC_THERMAL_MMIO_INT_STATUS_1, 0x7200, 8, 0x01 },
6464
};
6565

66+
/* List of supported MSI IDs (sources) */
67+
enum proc_thermal_msi_ids {
68+
PKG_THERMAL,
69+
DDR_THERMAL,
70+
THERM_POWER_FLOOR,
71+
WORKLOAD_CHANGE,
72+
MSI_THERMAL_MAX
73+
};
74+
75+
/* Stores IRQ associated with a MSI ID */
76+
static int proc_thermal_msi_map[MSI_THERMAL_MAX];
77+
6678
#define B0D4_THERMAL_NOTIFY_DELAY 1000
6779
static int notify_delay_ms = B0D4_THERMAL_NOTIFY_DELAY;
6880

@@ -146,22 +158,41 @@ static irqreturn_t proc_thermal_irq_thread_handler(int irq, void *devid)
146158
return IRQ_HANDLED;
147159
}
148160

161+
static int proc_thermal_match_msi_irq(int irq)
162+
{
163+
int i;
164+
165+
if (!use_msi)
166+
goto msi_fail;
167+
168+
for (i = 0; i < MSI_THERMAL_MAX; i++) {
169+
if (proc_thermal_msi_map[i] == irq)
170+
return i;
171+
}
172+
173+
msi_fail:
174+
return -EOPNOTSUPP;
175+
}
176+
149177
static irqreturn_t proc_thermal_irq_handler(int irq, void *devid)
150178
{
151179
struct proc_thermal_pci *pci_info = devid;
152180
struct proc_thermal_device *proc_priv;
153-
int ret = IRQ_HANDLED;
181+
int ret = IRQ_NONE, msi_id;
154182
u32 status;
155183

156184
proc_priv = pci_info->proc_priv;
157185

186+
msi_id = proc_thermal_match_msi_irq(irq);
187+
158188
if (proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_WT_HINT) {
159-
if (proc_thermal_check_wt_intr(pci_info->proc_priv))
189+
if (msi_id == WORKLOAD_CHANGE || proc_thermal_check_wt_intr(pci_info->proc_priv))
160190
ret = IRQ_WAKE_THREAD;
161191
}
162192

163193
if (proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_POWER_FLOOR) {
164-
if (proc_thermal_check_power_floor_intr(pci_info->proc_priv))
194+
if (msi_id == THERM_POWER_FLOOR ||
195+
proc_thermal_check_power_floor_intr(pci_info->proc_priv))
165196
ret = IRQ_WAKE_THREAD;
166197
}
167198

@@ -171,10 +202,11 @@ static irqreturn_t proc_thermal_irq_handler(int irq, void *devid)
171202
* interrupt before scheduling work function for thermal threshold.
172203
*/
173204
proc_thermal_mmio_read(pci_info, PROC_THERMAL_MMIO_INT_STATUS_0, &status);
174-
if (status) {
205+
if (msi_id == PKG_THERMAL || status) {
175206
/* Disable enable interrupt flag */
176207
proc_thermal_mmio_write(pci_info, PROC_THERMAL_MMIO_INT_ENABLE_0, 0);
177208
pkg_thermal_schedule_work(&pci_info->work);
209+
ret = IRQ_HANDLED;
178210
}
179211

180212
pci_write_config_byte(pci_info->pdev, 0xdc, 0x01);
@@ -193,7 +225,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
193225
return 0;
194226
}
195227

196-
static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
228+
static int sys_set_trip_temp(struct thermal_zone_device *tzd,
229+
const struct thermal_trip *trip, int temp)
197230
{
198231
struct proc_thermal_pci *pci_info = thermal_zone_device_priv(tzd);
199232
int tjmax, _temp;
@@ -243,6 +276,57 @@ static struct thermal_zone_params tzone_params = {
243276
.no_hwmon = true,
244277
};
245278

279+
static bool msi_irq;
280+
281+
static void proc_thermal_free_msi(struct pci_dev *pdev, struct proc_thermal_pci *pci_info)
282+
{
283+
int i;
284+
285+
for (i = 0; i < MSI_THERMAL_MAX; i++) {
286+
if (proc_thermal_msi_map[i])
287+
devm_free_irq(&pdev->dev, proc_thermal_msi_map[i], pci_info);
288+
}
289+
290+
pci_free_irq_vectors(pdev);
291+
}
292+
293+
static int proc_thermal_setup_msi(struct pci_dev *pdev, struct proc_thermal_pci *pci_info)
294+
{
295+
int ret, i, irq, count;
296+
297+
count = pci_alloc_irq_vectors(pdev, 1, MSI_THERMAL_MAX, PCI_IRQ_MSI | PCI_IRQ_MSIX);
298+
if (count < 0) {
299+
dev_err(&pdev->dev, "Failed to allocate vectors!\n");
300+
return count;
301+
}
302+
303+
dev_info(&pdev->dev, "msi enabled:%d msix enabled:%d\n", pdev->msi_enabled,
304+
pdev->msix_enabled);
305+
306+
for (i = 0; i < count; i++) {
307+
irq = pci_irq_vector(pdev, i);
308+
309+
ret = devm_request_threaded_irq(&pdev->dev, irq, proc_thermal_irq_handler,
310+
proc_thermal_irq_thread_handler,
311+
0, KBUILD_MODNAME, pci_info);
312+
if (ret) {
313+
dev_err(&pdev->dev, "Request IRQ %d failed\n", irq);
314+
goto err_free_msi_vectors;
315+
}
316+
317+
proc_thermal_msi_map[i] = irq;
318+
}
319+
320+
msi_irq = true;
321+
322+
return 0;
323+
324+
err_free_msi_vectors:
325+
proc_thermal_free_msi(pdev, pci_info);
326+
327+
return ret;
328+
}
329+
246330
static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
247331
{
248332
struct proc_thermal_device *proc_priv;
@@ -252,7 +336,6 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_
252336
.flags = THERMAL_TRIP_FLAG_RW_TEMP,
253337
};
254338
int irq_flag = 0, irq, ret;
255-
bool msi_irq = false;
256339

257340
proc_priv = devm_kzalloc(&pdev->dev, sizeof(*proc_priv), GFP_KERNEL);
258341
if (!proc_priv)
@@ -298,27 +381,24 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_
298381
goto err_del_legacy;
299382
}
300383

301-
if (use_msi && (pdev->msi_enabled || pdev->msix_enabled)) {
302-
/* request and enable interrupt */
303-
ret = pci_alloc_irq_vectors(pdev, 1, 1, PCI_IRQ_ALL_TYPES);
304-
if (ret < 0) {
305-
dev_err(&pdev->dev, "Failed to allocate vectors!\n");
306-
goto err_ret_tzone;
307-
}
384+
if (proc_priv->mmio_feature_mask & PROC_THERMAL_FEATURE_MSI_SUPPORT)
385+
use_msi = true;
308386

309-
irq = pci_irq_vector(pdev, 0);
310-
msi_irq = true;
387+
if (use_msi) {
388+
ret = proc_thermal_setup_msi(pdev, pci_info);
389+
if (ret)
390+
goto err_ret_tzone;
311391
} else {
312392
irq_flag = IRQF_SHARED;
313393
irq = pdev->irq;
314-
}
315394

316-
ret = devm_request_threaded_irq(&pdev->dev, irq,
317-
proc_thermal_irq_handler, proc_thermal_irq_thread_handler,
318-
irq_flag, KBUILD_MODNAME, pci_info);
319-
if (ret) {
320-
dev_err(&pdev->dev, "Request IRQ %d failed\n", pdev->irq);
321-
goto err_free_vectors;
395+
ret = devm_request_threaded_irq(&pdev->dev, irq, proc_thermal_irq_handler,
396+
proc_thermal_irq_thread_handler, irq_flag,
397+
KBUILD_MODNAME, pci_info);
398+
if (ret) {
399+
dev_err(&pdev->dev, "Request IRQ %d failed\n", pdev->irq);
400+
goto err_ret_tzone;
401+
}
322402
}
323403

324404
ret = thermal_zone_device_enable(pci_info->tzone);
@@ -329,7 +409,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, const struct pci_device_
329409

330410
err_free_vectors:
331411
if (msi_irq)
332-
pci_free_irq_vectors(pdev);
412+
proc_thermal_free_msi(pdev, pci_info);
333413
err_ret_tzone:
334414
thermal_zone_device_unregister(pci_info->tzone);
335415
err_del_legacy:
@@ -351,8 +431,8 @@ static void proc_thermal_pci_remove(struct pci_dev *pdev)
351431
proc_thermal_mmio_write(pci_info, PROC_THERMAL_MMIO_THRES_0, 0);
352432
proc_thermal_mmio_write(pci_info, PROC_THERMAL_MMIO_INT_ENABLE_0, 0);
353433

354-
devm_free_irq(&pdev->dev, pdev->irq, pci_info);
355-
pci_free_irq_vectors(pdev);
434+
if (msi_irq)
435+
proc_thermal_free_msi(pdev, pci_info);
356436

357437
thermal_zone_device_unregister(pci_info->tzone);
358438
proc_thermal_mmio_remove(pdev, pci_info->proc_priv);
@@ -407,7 +487,9 @@ static SIMPLE_DEV_PM_OPS(proc_thermal_pci_pm, proc_thermal_pci_suspend,
407487
static const struct pci_device_id proc_thermal_pci_ids[] = {
408488
{ PCI_DEVICE_DATA(INTEL, ADL_THERMAL, PROC_THERMAL_FEATURE_RAPL |
409489
PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_WT_REQ) },
410-
{ PCI_DEVICE_DATA(INTEL, LNLM_THERMAL, PROC_THERMAL_FEATURE_RAPL) },
490+
{ PCI_DEVICE_DATA(INTEL, LNLM_THERMAL, PROC_THERMAL_FEATURE_MSI_SUPPORT |
491+
PROC_THERMAL_FEATURE_RAPL | PROC_THERMAL_FEATURE_DLVR |
492+
PROC_THERMAL_FEATURE_WT_HINT | PROC_THERMAL_FEATURE_POWER_FLOOR) },
411493
{ PCI_DEVICE_DATA(INTEL, MTLP_THERMAL, PROC_THERMAL_FEATURE_RAPL |
412494
PROC_THERMAL_FEATURE_FIVR | PROC_THERMAL_FEATURE_DVFS | PROC_THERMAL_FEATURE_DLVR |
413495
PROC_THERMAL_FEATURE_WT_HINT | PROC_THERMAL_FEATURE_POWER_FLOOR) },

drivers/thermal/intel/int340x_thermal/processor_thermal_mbox.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,4 @@ int processor_thermal_mbox_interrupt_config(struct pci_dev *pdev, bool enable,
156156
EXPORT_SYMBOL_NS_GPL(processor_thermal_mbox_interrupt_config, INT340X_THERMAL);
157157

158158
MODULE_LICENSE("GPL v2");
159+
MODULE_DESCRIPTION("Processor Thermal Mail Box Interface");

0 commit comments

Comments
 (0)