Skip to content

Commit d3ecaf1

Browse files
dlezcanoDaniel Lezcano
authored andcommitted
thermal/drivers/intel: Use generic thermal_zone_get_trip() function
The thermal framework gives the possibility to register the trip points with the thermal zone. When that is done, no get_trip_* ops are needed and they can be removed. Convert ops content logic into generic trip points and register them with the thermal zone. Signed-off-by: Daniel Lezcano <[email protected]> Reviewed-by: Srinivas Pandruvada <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0d2d586 commit d3ecaf1

File tree

1 file changed

+67
-53
lines changed

1 file changed

+67
-53
lines changed

drivers/thermal/intel/x86_pkg_temp_thermal.c

Lines changed: 67 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct zone_device {
5353
u32 msr_pkg_therm_high;
5454
struct delayed_work work;
5555
struct thermal_zone_device *tzone;
56+
struct thermal_trip *trips;
5657
struct cpumask cpumask;
5758
};
5859

@@ -138,40 +139,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
138139
return -EINVAL;
139140
}
140141

141-
static int sys_get_trip_temp(struct thermal_zone_device *tzd,
142-
int trip, int *temp)
143-
{
144-
struct zone_device *zonedev = tzd->devdata;
145-
unsigned long thres_reg_value;
146-
u32 mask, shift, eax, edx;
147-
int ret;
148-
149-
if (trip >= MAX_NUMBER_OF_TRIPS)
150-
return -EINVAL;
151-
152-
if (trip) {
153-
mask = THERM_MASK_THRESHOLD1;
154-
shift = THERM_SHIFT_THRESHOLD1;
155-
} else {
156-
mask = THERM_MASK_THRESHOLD0;
157-
shift = THERM_SHIFT_THRESHOLD0;
158-
}
159-
160-
ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
161-
&eax, &edx);
162-
if (ret < 0)
163-
return ret;
164-
165-
thres_reg_value = (eax & mask) >> shift;
166-
if (thres_reg_value)
167-
*temp = zonedev->tj_max - thres_reg_value * 1000;
168-
else
169-
*temp = THERMAL_TEMP_INVALID;
170-
pr_debug("sys_get_trip_temp %d\n", *temp);
171-
172-
return 0;
173-
}
174-
175142
static int
176143
sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
177144
{
@@ -212,18 +179,9 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
212179
l, h);
213180
}
214181

215-
static int sys_get_trip_type(struct thermal_zone_device *thermal, int trip,
216-
enum thermal_trip_type *type)
217-
{
218-
*type = THERMAL_TRIP_PASSIVE;
219-
return 0;
220-
}
221-
222182
/* Thermal zone callback registry */
223183
static struct thermal_zone_device_ops tzone_ops = {
224184
.get_temp = sys_get_curr_temp,
225-
.get_trip_temp = sys_get_trip_temp,
226-
.get_trip_type = sys_get_trip_type,
227185
.set_trip_temp = sys_set_trip_temp,
228186
};
229187

@@ -323,6 +281,48 @@ static int pkg_thermal_notify(u64 msr_val)
323281
return 0;
324282
}
325283

284+
static struct thermal_trip *pkg_temp_thermal_trips_init(int cpu, int tj_max, int num_trips)
285+
{
286+
struct thermal_trip *trips;
287+
unsigned long thres_reg_value;
288+
u32 mask, shift, eax, edx;
289+
int ret, i;
290+
291+
trips = kzalloc(sizeof(*trips) * num_trips, GFP_KERNEL);
292+
if (!trips)
293+
return ERR_PTR(-ENOMEM);
294+
295+
for (i = 0; i < num_trips; i++) {
296+
297+
if (i) {
298+
mask = THERM_MASK_THRESHOLD1;
299+
shift = THERM_SHIFT_THRESHOLD1;
300+
} else {
301+
mask = THERM_MASK_THRESHOLD0;
302+
shift = THERM_SHIFT_THRESHOLD0;
303+
}
304+
305+
ret = rdmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
306+
&eax, &edx);
307+
if (ret < 0) {
308+
kfree(trips);
309+
return ERR_PTR(ret);
310+
}
311+
312+
thres_reg_value = (eax & mask) >> shift;
313+
314+
trips[i].temperature = thres_reg_value ?
315+
tj_max - thres_reg_value * 1000 : THERMAL_TEMP_INVALID;
316+
317+
trips[i].type = THERMAL_TRIP_PASSIVE;
318+
319+
pr_debug("%s: cpu=%d, trip=%d, temp=%d\n",
320+
__func__, cpu, i, trips[i].temperature);
321+
}
322+
323+
return trips;
324+
}
325+
326326
static int pkg_temp_thermal_device_add(unsigned int cpu)
327327
{
328328
int id = topology_logical_die_id(cpu);
@@ -348,24 +348,27 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
348348
if (!zonedev)
349349
return -ENOMEM;
350350

351+
zonedev->trips = pkg_temp_thermal_trips_init(cpu, tj_max, thres_count);
352+
if (IS_ERR(zonedev->trips)) {
353+
err = PTR_ERR(zonedev->trips);
354+
goto out_kfree_zonedev;
355+
}
356+
351357
INIT_DELAYED_WORK(&zonedev->work, pkg_temp_thermal_threshold_work_fn);
352358
zonedev->cpu = cpu;
353359
zonedev->tj_max = tj_max;
354-
zonedev->tzone = thermal_zone_device_register("x86_pkg_temp",
355-
thres_count,
360+
zonedev->tzone = thermal_zone_device_register_with_trips("x86_pkg_temp",
361+
zonedev->trips, thres_count,
356362
(thres_count == MAX_NUMBER_OF_TRIPS) ? 0x03 : 0x01,
357363
zonedev, &tzone_ops, &pkg_temp_tz_params, 0, 0);
358364
if (IS_ERR(zonedev->tzone)) {
359365
err = PTR_ERR(zonedev->tzone);
360-
kfree(zonedev);
361-
return err;
366+
goto out_kfree_trips;
362367
}
363368
err = thermal_zone_device_enable(zonedev->tzone);
364-
if (err) {
365-
thermal_zone_device_unregister(zonedev->tzone);
366-
kfree(zonedev);
367-
return err;
368-
}
369+
if (err)
370+
goto out_unregister_tz;
371+
369372
/* Store MSR value for package thermal interrupt, to restore at exit */
370373
rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, zonedev->msr_pkg_therm_low,
371374
zonedev->msr_pkg_therm_high);
@@ -374,7 +377,16 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
374377
raw_spin_lock_irq(&pkg_temp_lock);
375378
zones[id] = zonedev;
376379
raw_spin_unlock_irq(&pkg_temp_lock);
380+
377381
return 0;
382+
383+
out_unregister_tz:
384+
thermal_zone_device_unregister(zonedev->tzone);
385+
out_kfree_trips:
386+
kfree(zonedev->trips);
387+
out_kfree_zonedev:
388+
kfree(zonedev);
389+
return err;
378390
}
379391

380392
static int pkg_thermal_cpu_offline(unsigned int cpu)
@@ -458,8 +470,10 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
458470
raw_spin_unlock_irq(&pkg_temp_lock);
459471

460472
/* Final cleanup if this is the last cpu */
461-
if (lastcpu)
473+
if (lastcpu) {
474+
kfree(zonedev->trips);
462475
kfree(zonedev);
476+
}
463477
return 0;
464478
}
465479

0 commit comments

Comments
 (0)