Skip to content

Commit 02a49aa

Browse files
committed
thermal: intel: intel_soc_dts_iosf: Rework critical trip setup
Critical trip points appear in the DTS thermal zones only after those thermal zones have been registered via intel_soc_dts_iosf_init(). Moreover, they are "created" by changing the type of an existing trip point from THERMAL_TRIP_PASSIVE to THERMAL_TRIP_CRITICAL via intel_soc_dts_iosf_add_read_only_critical_trip(), the caller of which has to be careful enough to pass at least 1 as the number of read-only trip points to intel_soc_dts_iosf_init() beforehand. This is questionable, because user space may have started to use the trips at the time when intel_soc_dts_iosf_add_read_only_critical_trip() runs and there is no synchronization between it and sys_set_trip_temp(). To address it, use the observation that nonzero number of read-only trip points is only passed to intel_soc_dts_iosf_init() when critical trip points are going to be used, so in fact that function may get all of the information regarding the critical trip points upfront and it can configure them before registering the corresponding thermal zones. Accordingly, replace the read_only_trip_count argument of intel_soc_dts_iosf_init() with a pair of new arguments related to critical trip points: a bool one indicating whether or not critical trip points are to be used at all and an int one representing the critical trip point temperature offset relative to Tj_max. Use these arguments to configure the critical trip points before the registration of the thermal zones and to compute the number of writeable trip points in add_dts_thermal_zone(). Modify both callers of intel_soc_dts_iosf_init() to take these changes into account and drop the intel_soc_dts_iosf_add_read_only_critical_trip() call, that is not necessary any more, from intel_soc_thermal_init(), which also allows it to return success right after requesting the IRQ. Finally, drop intel_soc_dts_iosf_add_read_only_critical_trip() altogether, because it does not have any more users. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Srinivas Pandruvada <[email protected]>
1 parent 5bc3da3 commit 02a49aa

File tree

4 files changed

+27
-51
lines changed

4 files changed

+27
-51
lines changed

drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev,
5959
* ACPI/MSR. So we don't want to fail for auxiliary DTSs.
6060
*/
6161
proc_priv->soc_dts = intel_soc_dts_iosf_init(
62-
INTEL_SOC_DTS_INTERRUPT_MSI, 0);
62+
INTEL_SOC_DTS_INTERRUPT_MSI, false, 0);
6363

6464
if (!IS_ERR(proc_priv->soc_dts) && pdev->irq) {
6565
ret = pci_enable_msi(pdev);

drivers/thermal/intel/intel_soc_dts_iosf.c

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts)
257257
}
258258

259259
static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
260-
int read_only_trip_cnt)
260+
bool critical_trip)
261261
{
262+
int writable_trip_cnt = SOC_MAX_DTS_TRIPS;
262263
char name[10];
263264
unsigned long trip;
264-
int writable_trip_cnt;
265265
int trip_mask;
266266
unsigned long ptps;
267267
u32 store_ptps;
@@ -276,7 +276,9 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
276276

277277
dts->id = id;
278278

279-
writable_trip_cnt = SOC_MAX_DTS_TRIPS - read_only_trip_cnt;
279+
if (critical_trip)
280+
writable_trip_cnt--;
281+
280282
trip_mask = GENMASK(writable_trip_cnt - 1, 0);
281283

282284
/* Check if the writable trip we provide is not used by BIOS */
@@ -315,25 +317,6 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
315317
return ret;
316318
}
317319

318-
int intel_soc_dts_iosf_add_read_only_critical_trip(
319-
struct intel_soc_dts_sensors *sensors, int critical_offset)
320-
{
321-
int i, j;
322-
323-
for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) {
324-
struct intel_soc_dts_sensor_entry *entry = &sensors->soc_dts[i];
325-
int temp = sensors->tj_max - critical_offset;
326-
unsigned long mask = entry->trip_mask;
327-
328-
j = find_first_zero_bit(&mask, SOC_MAX_DTS_TRIPS);
329-
if (j < SOC_MAX_DTS_TRIPS)
330-
return configure_trip(entry, j, THERMAL_TRIP_CRITICAL, temp);
331-
}
332-
333-
return -EINVAL;
334-
}
335-
EXPORT_SYMBOL_GPL(intel_soc_dts_iosf_add_read_only_critical_trip);
336-
337320
void intel_soc_dts_iosf_interrupt_handler(struct intel_soc_dts_sensors *sensors)
338321
{
339322
u32 sticky_out;
@@ -375,8 +358,9 @@ static void dts_trips_reset(struct intel_soc_dts_sensors *sensors, int dts_index
375358
configure_trip(&sensors->soc_dts[dts_index], 1, 0, 0);
376359
}
377360

378-
struct intel_soc_dts_sensors *intel_soc_dts_iosf_init(
379-
enum intel_soc_dts_interrupt_type intr_type, int read_only_trip_count)
361+
struct intel_soc_dts_sensors *
362+
intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
363+
bool critical_trip, int crit_offset)
380364
{
381365
struct intel_soc_dts_sensors *sensors;
382366
int tj_max;
@@ -386,9 +370,6 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init(
386370
if (!iosf_mbi_available())
387371
return ERR_PTR(-ENODEV);
388372

389-
if (read_only_trip_count > SOC_MAX_DTS_TRIPS)
390-
return ERR_PTR(-EINVAL);
391-
392373
tj_max = intel_tcc_get_tjmax(-1);
393374
if (tj_max < 0)
394375
return ERR_PTR(tj_max);
@@ -403,22 +384,30 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init(
403384
sensors->tj_max = tj_max * 1000;
404385

405386
for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) {
387+
enum thermal_trip_type trip_type;
388+
int temp;
389+
406390
sensors->soc_dts[i].sensors = sensors;
407391

408392
ret = configure_trip(&sensors->soc_dts[i], 0,
409393
THERMAL_TRIP_PASSIVE, 0);
410394
if (ret)
411395
goto err_reset_trips;
412396

413-
ret = configure_trip(&sensors->soc_dts[i], 1,
414-
THERMAL_TRIP_PASSIVE, 0);
397+
if (critical_trip) {
398+
trip_type = THERMAL_TRIP_CRITICAL;
399+
temp = sensors->tj_max - crit_offset;
400+
} else {
401+
trip_type = THERMAL_TRIP_PASSIVE;
402+
temp = 0;
403+
}
404+
ret = configure_trip(&sensors->soc_dts[i], 1, trip_type, temp);
415405
if (ret)
416406
goto err_reset_trips;
417407
}
418408

419409
for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) {
420-
ret = add_dts_thermal_zone(i, &sensors->soc_dts[i],
421-
read_only_trip_count);
410+
ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], critical_trip);
422411
if (ret)
423412
goto err_remove_zone;
424413
}

drivers/thermal/intel/intel_soc_dts_iosf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ struct intel_soc_dts_sensors {
4242
struct intel_soc_dts_sensor_entry soc_dts[SOC_MAX_DTS_SENSORS];
4343
};
4444

45-
struct intel_soc_dts_sensors *intel_soc_dts_iosf_init(
46-
enum intel_soc_dts_interrupt_type intr_type, int read_only_trip_count);
45+
46+
struct intel_soc_dts_sensors *
47+
intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
48+
bool critical_trip, int crit_offset);
4749
void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors);
4850
void intel_soc_dts_iosf_interrupt_handler(
4951
struct intel_soc_dts_sensors *sensors);
50-
int intel_soc_dts_iosf_add_read_only_critical_trip(
51-
struct intel_soc_dts_sensors *sensors, int critical_offset);
5252
#endif

drivers/thermal/intel/intel_soc_dts_thermal.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ static int __init intel_soc_thermal_init(void)
5151
return -ENODEV;
5252

5353
/* Create a zone with 2 trips with marked as read only */
54-
soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, 1);
54+
soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, true,
55+
crit_offset);
5556
if (IS_ERR(soc_dts)) {
5657
err = PTR_ERR(soc_dts);
5758
return err;
@@ -88,21 +89,7 @@ static int __init intel_soc_thermal_init(void)
8889
}
8990
}
9091

91-
err = intel_soc_dts_iosf_add_read_only_critical_trip(soc_dts,
92-
crit_offset);
93-
if (err)
94-
goto error_trips;
95-
9692
return 0;
97-
98-
error_trips:
99-
if (soc_dts_thres_irq) {
100-
free_irq(soc_dts_thres_irq, soc_dts);
101-
acpi_unregister_gsi(soc_dts_thres_gsi);
102-
}
103-
intel_soc_dts_iosf_exit(soc_dts);
104-
105-
return err;
10693
}
10794

10895
static void __exit intel_soc_thermal_exit(void)

0 commit comments

Comments
 (0)