Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / thermal / x86_pkg_temp_thermal.c
1 /*
2  * x86_pkg_temp_thermal driver
3  * Copyright (c) 2013, Intel Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.
16  *
17  */
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/err.h>
23 #include <linux/param.h>
24 #include <linux/device.h>
25 #include <linux/platform_device.h>
26 #include <linux/cpu.h>
27 #include <linux/smp.h>
28 #include <linux/slab.h>
29 #include <linux/pm.h>
30 #include <linux/thermal.h>
31 #include <linux/debugfs.h>
32 #include <linux/work-simple.h>
33 #include <asm/cpu_device_id.h>
34 #include <asm/mce.h>
35
36 /*
37 * Rate control delay: Idea is to introduce denounce effect
38 * This should be long enough to avoid reduce events, when
39 * threshold is set to a temperature, which is constantly
40 * violated, but at the short enough to take any action.
41 * The action can be remove threshold or change it to next
42 * interesting setting. Based on experiments, in around
43 * every 5 seconds under load will give us a significant
44 * temperature change.
45 */
46 #define PKG_TEMP_THERMAL_NOTIFY_DELAY   5000
47 static int notify_delay_ms = PKG_TEMP_THERMAL_NOTIFY_DELAY;
48 module_param(notify_delay_ms, int, 0644);
49 MODULE_PARM_DESC(notify_delay_ms,
50         "User space notification delay in milli seconds.");
51
52 /* Number of trip points in thermal zone. Currently it can't
53 * be more than 2. MSR can allow setting and getting notifications
54 * for only 2 thresholds. This define enforces this, if there
55 * is some wrong values returned by cpuid for number of thresholds.
56 */
57 #define MAX_NUMBER_OF_TRIPS     2
58 /* Limit number of package temp zones */
59 #define MAX_PKG_TEMP_ZONE_IDS   256
60
61 struct phy_dev_entry {
62         struct list_head list;
63         u16 phys_proc_id;
64         u16 first_cpu;
65         u32 tj_max;
66         int ref_cnt;
67         u32 start_pkg_therm_low;
68         u32 start_pkg_therm_high;
69         struct thermal_zone_device *tzone;
70 };
71
72 static const struct thermal_zone_params pkg_temp_tz_params = {
73         .no_hwmon       = true,
74 };
75
76 /* List maintaining number of package instances */
77 static LIST_HEAD(phy_dev_list);
78 static DEFINE_MUTEX(phy_dev_list_mutex);
79
80 /* Interrupt to work function schedule queue */
81 static DEFINE_PER_CPU(struct delayed_work, pkg_temp_thermal_threshold_work);
82
83 /* To track if the work is already scheduled on a package */
84 static u8 *pkg_work_scheduled;
85
86 /* Spin lock to prevent races with pkg_work_scheduled */
87 static spinlock_t pkg_work_lock;
88 static u16 max_phy_id;
89
90 /* Debug counters to show using debugfs */
91 static struct dentry *debugfs;
92 static unsigned int pkg_interrupt_cnt;
93 static unsigned int pkg_work_cnt;
94
95 static int pkg_temp_debugfs_init(void)
96 {
97         struct dentry *d;
98
99         debugfs = debugfs_create_dir("pkg_temp_thermal", NULL);
100         if (!debugfs)
101                 return -ENOENT;
102
103         d = debugfs_create_u32("pkg_thres_interrupt", S_IRUGO, debugfs,
104                                 (u32 *)&pkg_interrupt_cnt);
105         if (!d)
106                 goto err_out;
107
108         d = debugfs_create_u32("pkg_thres_work", S_IRUGO, debugfs,
109                                 (u32 *)&pkg_work_cnt);
110         if (!d)
111                 goto err_out;
112
113         return 0;
114
115 err_out:
116         debugfs_remove_recursive(debugfs);
117         return -ENOENT;
118 }
119
120 static struct phy_dev_entry
121                         *pkg_temp_thermal_get_phy_entry(unsigned int cpu)
122 {
123         u16 phys_proc_id = topology_physical_package_id(cpu);
124         struct phy_dev_entry *phy_ptr;
125
126         mutex_lock(&phy_dev_list_mutex);
127
128         list_for_each_entry(phy_ptr, &phy_dev_list, list)
129                 if (phy_ptr->phys_proc_id == phys_proc_id) {
130                         mutex_unlock(&phy_dev_list_mutex);
131                         return phy_ptr;
132                 }
133
134         mutex_unlock(&phy_dev_list_mutex);
135
136         return NULL;
137 }
138
139 /*
140 * tj-max is is interesting because threshold is set relative to this
141 * temperature.
142 */
143 static int get_tj_max(int cpu, u32 *tj_max)
144 {
145         u32 eax, edx;
146         u32 val;
147         int err;
148
149         err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx);
150         if (err)
151                 goto err_ret;
152         else {
153                 val = (eax >> 16) & 0xff;
154                 if (val)
155                         *tj_max = val * 1000;
156                 else {
157                         err = -EINVAL;
158                         goto err_ret;
159                 }
160         }
161
162         return 0;
163 err_ret:
164         *tj_max = 0;
165         return err;
166 }
167
168 static int sys_get_curr_temp(struct thermal_zone_device *tzd, unsigned long *temp)
169 {
170         u32 eax, edx;
171         struct phy_dev_entry *phy_dev_entry;
172
173         phy_dev_entry = tzd->devdata;
174         rdmsr_on_cpu(phy_dev_entry->first_cpu, MSR_IA32_PACKAGE_THERM_STATUS,
175                         &eax, &edx);
176         if (eax & 0x80000000) {
177                 *temp = phy_dev_entry->tj_max -
178                                 ((eax >> 16) & 0x7f) * 1000;
179                 pr_debug("sys_get_curr_temp %ld\n", *temp);
180                 return 0;
181         }
182
183         return -EINVAL;
184 }
185
186 static int sys_get_trip_temp(struct thermal_zone_device *tzd,
187                 int trip, unsigned long *temp)
188 {
189         u32 eax, edx;
190         struct phy_dev_entry *phy_dev_entry;
191         u32 mask, shift;
192         unsigned long thres_reg_value;
193         int ret;
194
195         if (trip >= MAX_NUMBER_OF_TRIPS)
196                 return -EINVAL;
197
198         phy_dev_entry = tzd->devdata;
199
200         if (trip) {
201                 mask = THERM_MASK_THRESHOLD1;
202                 shift = THERM_SHIFT_THRESHOLD1;
203         } else {
204                 mask = THERM_MASK_THRESHOLD0;
205                 shift = THERM_SHIFT_THRESHOLD0;
206         }
207
208         ret = rdmsr_on_cpu(phy_dev_entry->first_cpu,
209                                 MSR_IA32_PACKAGE_THERM_INTERRUPT, &eax, &edx);
210         if (ret < 0)
211                 return -EINVAL;
212
213         thres_reg_value = (eax & mask) >> shift;
214         if (thres_reg_value)
215                 *temp = phy_dev_entry->tj_max - thres_reg_value * 1000;
216         else
217                 *temp = 0;
218         pr_debug("sys_get_trip_temp %ld\n", *temp);
219
220         return 0;
221 }
222
223 static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
224                                                         unsigned long temp)
225 {
226         u32 l, h;
227         struct phy_dev_entry *phy_dev_entry;
228         u32 mask, shift, intr;
229         int ret;
230
231         phy_dev_entry = tzd->devdata;
232
233         if (trip >= MAX_NUMBER_OF_TRIPS || temp >= phy_dev_entry->tj_max)
234                 return -EINVAL;
235
236         ret = rdmsr_on_cpu(phy_dev_entry->first_cpu,
237                                         MSR_IA32_PACKAGE_THERM_INTERRUPT,
238                                         &l, &h);
239         if (ret < 0)
240                 return -EINVAL;
241
242         if (trip) {
243                 mask = THERM_MASK_THRESHOLD1;
244                 shift = THERM_SHIFT_THRESHOLD1;
245                 intr = THERM_INT_THRESHOLD1_ENABLE;
246         } else {
247                 mask = THERM_MASK_THRESHOLD0;
248                 shift = THERM_SHIFT_THRESHOLD0;
249                 intr = THERM_INT_THRESHOLD0_ENABLE;
250         }
251         l &= ~mask;
252         /*
253         * When users space sets a trip temperature == 0, which is indication
254         * that, it is no longer interested in receiving notifications.
255         */
256         if (!temp)
257                 l &= ~intr;
258         else {
259                 l |= (phy_dev_entry->tj_max - temp)/1000 << shift;
260                 l |= intr;
261         }
262
263         return wrmsr_on_cpu(phy_dev_entry->first_cpu,
264                                         MSR_IA32_PACKAGE_THERM_INTERRUPT,
265                                         l, h);
266 }
267
268 static int sys_get_trip_type(struct thermal_zone_device *thermal,
269                 int trip, enum thermal_trip_type *type)
270 {
271
272         *type = THERMAL_TRIP_PASSIVE;
273
274         return 0;
275 }
276
277 /* Thermal zone callback registry */
278 static struct thermal_zone_device_ops tzone_ops = {
279         .get_temp = sys_get_curr_temp,
280         .get_trip_temp = sys_get_trip_temp,
281         .get_trip_type = sys_get_trip_type,
282         .set_trip_temp = sys_set_trip_temp,
283 };
284
285 static bool pkg_temp_thermal_platform_thermal_rate_control(void)
286 {
287         return true;
288 }
289
290 /* Enable threshold interrupt on local package/cpu */
291 static inline void enable_pkg_thres_interrupt(void)
292 {
293         u32 l, h;
294         u8 thres_0, thres_1;
295
296         rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
297         /* only enable/disable if it had valid threshold value */
298         thres_0 = (l & THERM_MASK_THRESHOLD0) >> THERM_SHIFT_THRESHOLD0;
299         thres_1 = (l & THERM_MASK_THRESHOLD1) >> THERM_SHIFT_THRESHOLD1;
300         if (thres_0)
301                 l |= THERM_INT_THRESHOLD0_ENABLE;
302         if (thres_1)
303                 l |= THERM_INT_THRESHOLD1_ENABLE;
304         wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
305 }
306
307 /* Disable threshold interrupt on local package/cpu */
308 static inline void disable_pkg_thres_interrupt(void)
309 {
310         u32 l, h;
311         rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
312         wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
313                         l & (~THERM_INT_THRESHOLD0_ENABLE) &
314                                 (~THERM_INT_THRESHOLD1_ENABLE), h);
315 }
316
317 static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
318 {
319         __u64 msr_val;
320         int cpu = smp_processor_id();
321         int phy_id = topology_physical_package_id(cpu);
322         struct phy_dev_entry *phdev = pkg_temp_thermal_get_phy_entry(cpu);
323         bool notify = false;
324         unsigned long flags;
325
326         if (!phdev)
327                 return;
328
329         spin_lock_irqsave(&pkg_work_lock, flags);
330         ++pkg_work_cnt;
331         if (unlikely(phy_id > max_phy_id)) {
332                 spin_unlock_irqrestore(&pkg_work_lock, flags);
333                 return;
334         }
335         pkg_work_scheduled[phy_id] = 0;
336         spin_unlock_irqrestore(&pkg_work_lock, flags);
337
338         enable_pkg_thres_interrupt();
339         rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val);
340         if (msr_val & THERM_LOG_THRESHOLD0) {
341                 wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS,
342                                 msr_val & ~THERM_LOG_THRESHOLD0);
343                 notify = true;
344         }
345         if (msr_val & THERM_LOG_THRESHOLD1) {
346                 wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS,
347                                 msr_val & ~THERM_LOG_THRESHOLD1);
348                 notify = true;
349         }
350         if (notify) {
351                 pr_debug("thermal_zone_device_update\n");
352                 thermal_zone_device_update(phdev->tzone);
353         }
354 }
355
356 static void platform_thermal_notify_work(struct swork_event *event)
357 {
358         unsigned long flags;
359         int cpu = smp_processor_id();
360         int phy_id = topology_physical_package_id(cpu);
361
362         /*
363         * When a package is in interrupted state, all CPU's in that package
364         * are in the same interrupt state. So scheduling on any one CPU in
365         * the package is enough and simply return for others.
366         */
367         spin_lock_irqsave(&pkg_work_lock, flags);
368         ++pkg_interrupt_cnt;
369         if (unlikely(phy_id > max_phy_id) || unlikely(!pkg_work_scheduled) ||
370                         pkg_work_scheduled[phy_id]) {
371                 disable_pkg_thres_interrupt();
372                 spin_unlock_irqrestore(&pkg_work_lock, flags);
373                 return;
374         }
375         pkg_work_scheduled[phy_id] = 1;
376         spin_unlock_irqrestore(&pkg_work_lock, flags);
377
378         disable_pkg_thres_interrupt();
379         schedule_delayed_work_on(cpu,
380                                 &per_cpu(pkg_temp_thermal_threshold_work, cpu),
381                                 msecs_to_jiffies(notify_delay_ms));
382 }
383
384 #ifdef CONFIG_PREEMPT_RT_FULL
385 static struct swork_event notify_work;
386
387 static int thermal_notify_work_init(void)
388 {
389         int err;
390
391         err = swork_get();
392         if (err)
393                 return err;
394
395         INIT_SWORK(&notify_work, platform_thermal_notify_work);
396         return 0;
397 }
398
399 static void thermal_notify_work_cleanup(void)
400 {
401         swork_put();
402 }
403
404 static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
405 {
406         swork_queue(&notify_work);
407         return 0;
408 }
409
410 #else  /* !CONFIG_PREEMPT_RT_FULL */
411
412 static int thermal_notify_work_init(void) { return 0; }
413
414 static void thermal_notify_work_cleanup(void) {  }
415
416 static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
417 {
418         platform_thermal_notify_work(NULL);
419
420         return 0;
421 }
422 #endif /* CONFIG_PREEMPT_RT_FULL */
423
424 static int find_siblings_cpu(int cpu)
425 {
426         int i;
427         int id = topology_physical_package_id(cpu);
428
429         for_each_online_cpu(i)
430                 if (i != cpu && topology_physical_package_id(i) == id)
431                         return i;
432
433         return 0;
434 }
435
436 static int pkg_temp_thermal_device_add(unsigned int cpu)
437 {
438         int err;
439         u32 tj_max;
440         struct phy_dev_entry *phy_dev_entry;
441         int thres_count;
442         u32 eax, ebx, ecx, edx;
443         u8 *temp;
444         unsigned long flags;
445
446         cpuid(6, &eax, &ebx, &ecx, &edx);
447         thres_count = ebx & 0x07;
448         if (!thres_count)
449                 return -ENODEV;
450
451         if (topology_physical_package_id(cpu) > MAX_PKG_TEMP_ZONE_IDS)
452                 return -ENODEV;
453
454         thres_count = clamp_val(thres_count, 0, MAX_NUMBER_OF_TRIPS);
455
456         err = get_tj_max(cpu, &tj_max);
457         if (err)
458                 goto err_ret;
459
460         mutex_lock(&phy_dev_list_mutex);
461
462         phy_dev_entry = kzalloc(sizeof(*phy_dev_entry), GFP_KERNEL);
463         if (!phy_dev_entry) {
464                 err = -ENOMEM;
465                 goto err_ret_unlock;
466         }
467
468         spin_lock_irqsave(&pkg_work_lock, flags);
469         if (topology_physical_package_id(cpu) > max_phy_id)
470                 max_phy_id = topology_physical_package_id(cpu);
471         temp = krealloc(pkg_work_scheduled,
472                         (max_phy_id+1) * sizeof(u8), GFP_ATOMIC);
473         if (!temp) {
474                 spin_unlock_irqrestore(&pkg_work_lock, flags);
475                 err = -ENOMEM;
476                 goto err_ret_free;
477         }
478         pkg_work_scheduled = temp;
479         pkg_work_scheduled[topology_physical_package_id(cpu)] = 0;
480         spin_unlock_irqrestore(&pkg_work_lock, flags);
481
482         phy_dev_entry->phys_proc_id = topology_physical_package_id(cpu);
483         phy_dev_entry->first_cpu = cpu;
484         phy_dev_entry->tj_max = tj_max;
485         phy_dev_entry->ref_cnt = 1;
486         phy_dev_entry->tzone = thermal_zone_device_register("x86_pkg_temp",
487                         thres_count,
488                         (thres_count == MAX_NUMBER_OF_TRIPS) ?
489                                 0x03 : 0x01,
490                         phy_dev_entry, &tzone_ops, &pkg_temp_tz_params, 0, 0);
491         if (IS_ERR(phy_dev_entry->tzone)) {
492                 err = PTR_ERR(phy_dev_entry->tzone);
493                 goto err_ret_free;
494         }
495         /* Store MSR value for package thermal interrupt, to restore at exit */
496         rdmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
497                                 &phy_dev_entry->start_pkg_therm_low,
498                                 &phy_dev_entry->start_pkg_therm_high);
499
500         list_add_tail(&phy_dev_entry->list, &phy_dev_list);
501         pr_debug("pkg_temp_thermal_device_add :phy_id %d cpu %d\n",
502                         phy_dev_entry->phys_proc_id, cpu);
503
504         mutex_unlock(&phy_dev_list_mutex);
505
506         return 0;
507
508 err_ret_free:
509         kfree(phy_dev_entry);
510 err_ret_unlock:
511         mutex_unlock(&phy_dev_list_mutex);
512
513 err_ret:
514         return err;
515 }
516
517 static int pkg_temp_thermal_device_remove(unsigned int cpu)
518 {
519         struct phy_dev_entry *n;
520         u16 phys_proc_id = topology_physical_package_id(cpu);
521         struct phy_dev_entry *phdev =
522                         pkg_temp_thermal_get_phy_entry(cpu);
523
524         if (!phdev)
525                 return -ENODEV;
526
527         mutex_lock(&phy_dev_list_mutex);
528         /* If we are loosing the first cpu for this package, we need change */
529         if (phdev->first_cpu == cpu) {
530                 phdev->first_cpu = find_siblings_cpu(cpu);
531                 pr_debug("thermal_device_remove: first cpu switched %d\n",
532                                         phdev->first_cpu);
533         }
534         /*
535         * It is possible that no siblings left as this was the last cpu
536         * going offline. We don't need to worry about this assignment
537         * as the phydev entry will be removed in this case and
538         * thermal zone is removed.
539         */
540         --phdev->ref_cnt;
541         pr_debug("thermal_device_remove: pkg: %d cpu %d ref_cnt %d\n",
542                                         phys_proc_id, cpu, phdev->ref_cnt);
543         if (!phdev->ref_cnt)
544                 list_for_each_entry_safe(phdev, n, &phy_dev_list, list) {
545                         if (phdev->phys_proc_id == phys_proc_id) {
546                                 thermal_zone_device_unregister(phdev->tzone);
547                                 list_del(&phdev->list);
548                                 kfree(phdev);
549                                 break;
550                         }
551                 }
552         mutex_unlock(&phy_dev_list_mutex);
553
554         return 0;
555 }
556
557 static int get_core_online(unsigned int cpu)
558 {
559         struct cpuinfo_x86 *c = &cpu_data(cpu);
560         struct phy_dev_entry *phdev = pkg_temp_thermal_get_phy_entry(cpu);
561
562         /* Check if there is already an instance for this package */
563         if (!phdev) {
564                 if (!cpu_has(c, X86_FEATURE_DTHERM) ||
565                                         !cpu_has(c, X86_FEATURE_PTS))
566                         return -ENODEV;
567                 if (pkg_temp_thermal_device_add(cpu))
568                         return -ENODEV;
569         } else {
570                 mutex_lock(&phy_dev_list_mutex);
571                 ++phdev->ref_cnt;
572                 pr_debug("get_core_online: cpu %d ref_cnt %d\n",
573                                                 cpu, phdev->ref_cnt);
574                 mutex_unlock(&phy_dev_list_mutex);
575         }
576         INIT_DELAYED_WORK(&per_cpu(pkg_temp_thermal_threshold_work, cpu),
577                         pkg_temp_thermal_threshold_work_fn);
578
579         pr_debug("get_core_online: cpu %d successful\n", cpu);
580
581         return 0;
582 }
583
584 static void put_core_offline(unsigned int cpu)
585 {
586         if (!pkg_temp_thermal_device_remove(cpu))
587                 cancel_delayed_work_sync(
588                         &per_cpu(pkg_temp_thermal_threshold_work, cpu));
589
590         pr_debug("put_core_offline: cpu %d\n", cpu);
591 }
592
593 static int pkg_temp_thermal_cpu_callback(struct notifier_block *nfb,
594                                  unsigned long action, void *hcpu)
595 {
596         unsigned int cpu = (unsigned long) hcpu;
597
598         switch (action) {
599         case CPU_ONLINE:
600         case CPU_DOWN_FAILED:
601                 get_core_online(cpu);
602                 break;
603         case CPU_DOWN_PREPARE:
604                 put_core_offline(cpu);
605                 break;
606         }
607         return NOTIFY_OK;
608 }
609
610 static struct notifier_block pkg_temp_thermal_notifier __refdata = {
611         .notifier_call = pkg_temp_thermal_cpu_callback,
612 };
613
614 static const struct x86_cpu_id __initconst pkg_temp_thermal_ids[] = {
615         { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_PTS },
616         {}
617 };
618 MODULE_DEVICE_TABLE(x86cpu, pkg_temp_thermal_ids);
619
620 static int __init pkg_temp_thermal_init(void)
621 {
622         int i;
623
624         if (!x86_match_cpu(pkg_temp_thermal_ids))
625                 return -ENODEV;
626
627         if (!thermal_notify_work_init())
628                 return -ENODEV;
629
630         spin_lock_init(&pkg_work_lock);
631         platform_thermal_package_notify =
632                         pkg_temp_thermal_platform_thermal_notify;
633         platform_thermal_package_rate_control =
634                         pkg_temp_thermal_platform_thermal_rate_control;
635
636         cpu_notifier_register_begin();
637         for_each_online_cpu(i)
638                 if (get_core_online(i))
639                         goto err_ret;
640         __register_hotcpu_notifier(&pkg_temp_thermal_notifier);
641         cpu_notifier_register_done();
642
643         pkg_temp_debugfs_init(); /* Don't care if fails */
644
645         return 0;
646
647 err_ret:
648         for_each_online_cpu(i)
649                 put_core_offline(i);
650         cpu_notifier_register_done();
651         kfree(pkg_work_scheduled);
652         platform_thermal_package_notify = NULL;
653         platform_thermal_package_rate_control = NULL;
654         thermal_notify_work_cleanup();
655         return -ENODEV;
656 }
657
658 static void __exit pkg_temp_thermal_exit(void)
659 {
660         struct phy_dev_entry *phdev, *n;
661         int i;
662
663         cpu_notifier_register_begin();
664         __unregister_hotcpu_notifier(&pkg_temp_thermal_notifier);
665         mutex_lock(&phy_dev_list_mutex);
666         list_for_each_entry_safe(phdev, n, &phy_dev_list, list) {
667                 /* Retore old MSR value for package thermal interrupt */
668                 wrmsr_on_cpu(phdev->first_cpu,
669                         MSR_IA32_PACKAGE_THERM_INTERRUPT,
670                         phdev->start_pkg_therm_low,
671                         phdev->start_pkg_therm_high);
672                 thermal_zone_device_unregister(phdev->tzone);
673                 list_del(&phdev->list);
674                 kfree(phdev);
675         }
676         mutex_unlock(&phy_dev_list_mutex);
677         platform_thermal_package_notify = NULL;
678         platform_thermal_package_rate_control = NULL;
679         thermal_notify_work_cleanup();
680         for_each_online_cpu(i)
681                 cancel_delayed_work_sync(
682                         &per_cpu(pkg_temp_thermal_threshold_work, i));
683         cpu_notifier_register_done();
684
685         kfree(pkg_work_scheduled);
686
687         debugfs_remove_recursive(debugfs);
688 }
689
690 module_init(pkg_temp_thermal_init)
691 module_exit(pkg_temp_thermal_exit)
692
693 MODULE_DESCRIPTION("X86 PKG TEMP Thermal Driver");
694 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
695 MODULE_LICENSE("GPL v2");