@@ -49,7 +49,6 @@ MODULE_PARM_DESC(notify_delay_ms,
49
49
struct zone_device {
50
50
int cpu ;
51
51
bool work_scheduled ;
52
- u32 tj_max ;
53
52
u32 msr_pkg_therm_low ;
54
53
u32 msr_pkg_therm_high ;
55
54
struct delayed_work work ;
@@ -125,7 +124,7 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd,
125
124
struct zone_device * zonedev = tzd -> devdata ;
126
125
unsigned long thres_reg_value ;
127
126
u32 mask , shift , eax , edx ;
128
- int ret ;
127
+ int tj_max , ret ;
129
128
130
129
if (trip >= MAX_NUMBER_OF_TRIPS )
131
130
return - EINVAL ;
@@ -138,14 +137,19 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd,
138
137
shift = THERM_SHIFT_THRESHOLD0 ;
139
138
}
140
139
140
+ tj_max = intel_tcc_get_tjmax (zonedev -> cpu );
141
+ if (tj_max < 0 )
142
+ return tj_max ;
143
+ tj_max *= 1000 ;
144
+
141
145
ret = rdmsr_on_cpu (zonedev -> cpu , MSR_IA32_PACKAGE_THERM_INTERRUPT ,
142
146
& eax , & edx );
143
147
if (ret < 0 )
144
148
return ret ;
145
149
146
150
thres_reg_value = (eax & mask ) >> shift ;
147
151
if (thres_reg_value )
148
- * temp = zonedev -> tj_max - thres_reg_value * 1000 ;
152
+ * temp = tj_max - thres_reg_value * 1000 ;
149
153
else
150
154
* temp = THERMAL_TEMP_INVALID ;
151
155
pr_debug ("sys_get_trip_temp %d\n" , * temp );
@@ -158,9 +162,14 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
158
162
{
159
163
struct zone_device * zonedev = tzd -> devdata ;
160
164
u32 l , h , mask , shift , intr ;
161
- int ret ;
165
+ int tj_max , ret ;
162
166
163
- if (trip >= MAX_NUMBER_OF_TRIPS || temp >= zonedev -> tj_max )
167
+ tj_max = intel_tcc_get_tjmax (zonedev -> cpu );
168
+ if (tj_max < 0 )
169
+ return tj_max ;
170
+ tj_max *= 1000 ;
171
+
172
+ if (trip >= MAX_NUMBER_OF_TRIPS || temp >= tj_max )
164
173
return - EINVAL ;
165
174
166
175
ret = rdmsr_on_cpu (zonedev -> cpu , MSR_IA32_PACKAGE_THERM_INTERRUPT ,
@@ -185,7 +194,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
185
194
if (!temp ) {
186
195
l &= ~intr ;
187
196
} else {
188
- l |= (zonedev -> tj_max - temp )/1000 << shift ;
197
+ l |= (tj_max - temp )/1000 << shift ;
189
198
l |= intr ;
190
199
}
191
200
@@ -307,7 +316,7 @@ static int pkg_thermal_notify(u64 msr_val)
307
316
static int pkg_temp_thermal_device_add (unsigned int cpu )
308
317
{
309
318
int id = topology_logical_die_id (cpu );
310
- u32 tj_max , eax , ebx , ecx , edx ;
319
+ u32 eax , ebx , ecx , edx ;
311
320
struct zone_device * zonedev ;
312
321
int thres_count , err ;
313
322
@@ -321,17 +330,16 @@ static int pkg_temp_thermal_device_add(unsigned int cpu)
321
330
322
331
thres_count = clamp_val (thres_count , 0 , MAX_NUMBER_OF_TRIPS );
323
332
324
- tj_max = intel_tcc_get_tjmax (cpu );
325
- if (tj_max < 0 )
326
- return tj_max ;
333
+ err = intel_tcc_get_tjmax (cpu );
334
+ if (err < 0 )
335
+ return err ;
327
336
328
337
zonedev = kzalloc (sizeof (* zonedev ), GFP_KERNEL );
329
338
if (!zonedev )
330
339
return - ENOMEM ;
331
340
332
341
INIT_DELAYED_WORK (& zonedev -> work , pkg_temp_thermal_threshold_work_fn );
333
342
zonedev -> cpu = cpu ;
334
- zonedev -> tj_max = tj_max ;
335
343
zonedev -> tzone = thermal_zone_device_register ("x86_pkg_temp" ,
336
344
thres_count ,
337
345
(thres_count == MAX_NUMBER_OF_TRIPS ) ? 0x03 : 0x01 ,
0 commit comments