@@ -53,6 +53,7 @@ struct zone_device {
53
53
u32 msr_pkg_therm_high ;
54
54
struct delayed_work work ;
55
55
struct thermal_zone_device * tzone ;
56
+ struct thermal_trip * trips ;
56
57
struct cpumask cpumask ;
57
58
};
58
59
@@ -138,40 +139,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
138
139
return - EINVAL ;
139
140
}
140
141
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
-
175
142
static int
176
143
sys_set_trip_temp (struct thermal_zone_device * tzd , int trip , int temp )
177
144
{
@@ -212,18 +179,9 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
212
179
l , h );
213
180
}
214
181
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
-
222
182
/* Thermal zone callback registry */
223
183
static struct thermal_zone_device_ops tzone_ops = {
224
184
.get_temp = sys_get_curr_temp ,
225
- .get_trip_temp = sys_get_trip_temp ,
226
- .get_trip_type = sys_get_trip_type ,
227
185
.set_trip_temp = sys_set_trip_temp ,
228
186
};
229
187
@@ -323,6 +281,48 @@ static int pkg_thermal_notify(u64 msr_val)
323
281
return 0 ;
324
282
}
325
283
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
+
326
326
static int pkg_temp_thermal_device_add (unsigned int cpu )
327
327
{
328
328
int id = topology_logical_die_id (cpu );
@@ -348,24 +348,27 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
348
348
if (!zonedev )
349
349
return - ENOMEM ;
350
350
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
+
351
357
INIT_DELAYED_WORK (& zonedev -> work , pkg_temp_thermal_threshold_work_fn );
352
358
zonedev -> cpu = cpu ;
353
359
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 ,
356
362
(thres_count == MAX_NUMBER_OF_TRIPS ) ? 0x03 : 0x01 ,
357
363
zonedev , & tzone_ops , & pkg_temp_tz_params , 0 , 0 );
358
364
if (IS_ERR (zonedev -> tzone )) {
359
365
err = PTR_ERR (zonedev -> tzone );
360
- kfree (zonedev );
361
- return err ;
366
+ goto out_kfree_trips ;
362
367
}
363
368
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
+
369
372
/* Store MSR value for package thermal interrupt, to restore at exit */
370
373
rdmsr (MSR_IA32_PACKAGE_THERM_INTERRUPT , zonedev -> msr_pkg_therm_low ,
371
374
zonedev -> msr_pkg_therm_high );
@@ -374,7 +377,16 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
374
377
raw_spin_lock_irq (& pkg_temp_lock );
375
378
zones [id ] = zonedev ;
376
379
raw_spin_unlock_irq (& pkg_temp_lock );
380
+
377
381
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 ;
378
390
}
379
391
380
392
static int pkg_thermal_cpu_offline (unsigned int cpu )
@@ -458,8 +470,10 @@ static int pkg_thermal_cpu_offline(unsigned int cpu)
458
470
raw_spin_unlock_irq (& pkg_temp_lock );
459
471
460
472
/* Final cleanup if this is the last cpu */
461
- if (lastcpu )
473
+ if (lastcpu ) {
474
+ kfree (zonedev -> trips );
462
475
kfree (zonedev );
476
+ }
463
477
return 0 ;
464
478
}
465
479
0 commit comments