x86_pkg_temp_thermal.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/err.h>
  22. #include <linux/param.h>
  23. #include <linux/device.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/cpu.h>
  26. #include <linux/smp.h>
  27. #include <linux/slab.h>
  28. #include <linux/pm.h>
  29. #include <linux/thermal.h>
  30. #include <linux/debugfs.h>
  31. #include <asm/cpu_device_id.h>
  32. #include <asm/mce.h>
  33. /*
  34. * Rate control delay: Idea is to introduce denounce effect
  35. * This should be long enough to avoid reduce events, when
  36. * threshold is set to a temperature, which is constantly
  37. * violated, but at the short enough to take any action.
  38. * The action can be remove threshold or change it to next
  39. * interesting setting. Based on experiments, in around
  40. * every 5 seconds under load will give us a significant
  41. * temperature change.
  42. */
  43. #define PKG_TEMP_THERMAL_NOTIFY_DELAY 5000
  44. static int notify_delay_ms = PKG_TEMP_THERMAL_NOTIFY_DELAY;
  45. module_param(notify_delay_ms, int, 0644);
  46. MODULE_PARM_DESC(notify_delay_ms,
  47. "User space notification delay in milli seconds.");
  48. /* Number of trip points in thermal zone. Currently it can't
  49. * be more than 2. MSR can allow setting and getting notifications
  50. * for only 2 thresholds. This define enforces this, if there
  51. * is some wrong values returned by cpuid for number of thresholds.
  52. */
  53. #define MAX_NUMBER_OF_TRIPS 2
  54. struct phy_dev_entry {
  55. struct list_head list;
  56. u16 phys_proc_id;
  57. u16 first_cpu;
  58. u32 tj_max;
  59. int ref_cnt;
  60. u32 start_pkg_therm_low;
  61. u32 start_pkg_therm_high;
  62. struct thermal_zone_device *tzone;
  63. };
  64. /* List maintaining number of package instances */
  65. static LIST_HEAD(phy_dev_list);
  66. static DEFINE_MUTEX(phy_dev_list_mutex);
  67. /* Interrupt to work function schedule queue */
  68. static DEFINE_PER_CPU(struct delayed_work, pkg_temp_thermal_threshold_work);
  69. /* To track if the work is already scheduled on a package */
  70. static u8 *pkg_work_scheduled;
  71. /* Spin lock to prevent races with pkg_work_scheduled */
  72. static spinlock_t pkg_work_lock;
  73. static u16 max_phy_id;
  74. /* Debug counters to show using debugfs */
  75. static struct dentry *debugfs;
  76. static unsigned int pkg_interrupt_cnt;
  77. static unsigned int pkg_work_cnt;
  78. static int pkg_temp_debugfs_init(void)
  79. {
  80. struct dentry *d;
  81. debugfs = debugfs_create_dir("pkg_temp_thermal", NULL);
  82. if (!debugfs)
  83. return -ENOENT;
  84. d = debugfs_create_u32("pkg_thres_interrupt", S_IRUGO, debugfs,
  85. (u32 *)&pkg_interrupt_cnt);
  86. if (!d)
  87. goto err_out;
  88. d = debugfs_create_u32("pkg_thres_work", S_IRUGO, debugfs,
  89. (u32 *)&pkg_work_cnt);
  90. if (!d)
  91. goto err_out;
  92. return 0;
  93. err_out:
  94. debugfs_remove_recursive(debugfs);
  95. return -ENOENT;
  96. }
  97. static struct phy_dev_entry
  98. *pkg_temp_thermal_get_phy_entry(unsigned int cpu)
  99. {
  100. u16 phys_proc_id = topology_physical_package_id(cpu);
  101. struct phy_dev_entry *phy_ptr;
  102. mutex_lock(&phy_dev_list_mutex);
  103. list_for_each_entry(phy_ptr, &phy_dev_list, list)
  104. if (phy_ptr->phys_proc_id == phys_proc_id) {
  105. mutex_unlock(&phy_dev_list_mutex);
  106. return phy_ptr;
  107. }
  108. mutex_unlock(&phy_dev_list_mutex);
  109. return NULL;
  110. }
  111. /*
  112. * tj-max is is interesting because threshold is set relative to this
  113. * temperature.
  114. */
  115. static int get_tj_max(int cpu, u32 *tj_max)
  116. {
  117. u32 eax, edx;
  118. u32 val;
  119. int err;
  120. err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx);
  121. if (err)
  122. goto err_ret;
  123. else {
  124. val = (eax >> 16) & 0xff;
  125. if (val)
  126. *tj_max = val * 1000;
  127. else {
  128. err = -EINVAL;
  129. goto err_ret;
  130. }
  131. }
  132. return 0;
  133. err_ret:
  134. *tj_max = 0;
  135. return err;
  136. }
  137. static int sys_get_curr_temp(struct thermal_zone_device *tzd, unsigned long *temp)
  138. {
  139. u32 eax, edx;
  140. struct phy_dev_entry *phy_dev_entry;
  141. phy_dev_entry = tzd->devdata;
  142. rdmsr_on_cpu(phy_dev_entry->first_cpu, MSR_IA32_PACKAGE_THERM_STATUS,
  143. &eax, &edx);
  144. if (eax & 0x80000000) {
  145. *temp = phy_dev_entry->tj_max -
  146. ((eax >> 16) & 0x7f) * 1000;
  147. pr_debug("sys_get_curr_temp %ld\n", *temp);
  148. return 0;
  149. }
  150. return -EINVAL;
  151. }
  152. static int sys_get_trip_temp(struct thermal_zone_device *tzd,
  153. int trip, unsigned long *temp)
  154. {
  155. u32 eax, edx;
  156. struct phy_dev_entry *phy_dev_entry;
  157. u32 mask, shift;
  158. unsigned long thres_reg_value;
  159. int ret;
  160. if (trip >= MAX_NUMBER_OF_TRIPS)
  161. return -EINVAL;
  162. phy_dev_entry = tzd->devdata;
  163. if (trip) {
  164. mask = THERM_MASK_THRESHOLD1;
  165. shift = THERM_SHIFT_THRESHOLD1;
  166. } else {
  167. mask = THERM_MASK_THRESHOLD0;
  168. shift = THERM_SHIFT_THRESHOLD0;
  169. }
  170. ret = rdmsr_on_cpu(phy_dev_entry->first_cpu,
  171. MSR_IA32_PACKAGE_THERM_INTERRUPT, &eax, &edx);
  172. if (ret < 0)
  173. return -EINVAL;
  174. thres_reg_value = (eax & mask) >> shift;
  175. if (thres_reg_value)
  176. *temp = phy_dev_entry->tj_max - thres_reg_value * 1000;
  177. else
  178. *temp = 0;
  179. pr_debug("sys_get_trip_temp %ld\n", *temp);
  180. return 0;
  181. }
  182. int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
  183. unsigned long temp)
  184. {
  185. u32 l, h;
  186. struct phy_dev_entry *phy_dev_entry;
  187. u32 mask, shift, intr;
  188. int ret;
  189. phy_dev_entry = tzd->devdata;
  190. if (trip >= MAX_NUMBER_OF_TRIPS || temp >= phy_dev_entry->tj_max)
  191. return -EINVAL;
  192. ret = rdmsr_on_cpu(phy_dev_entry->first_cpu,
  193. MSR_IA32_PACKAGE_THERM_INTERRUPT,
  194. &l, &h);
  195. if (ret < 0)
  196. return -EINVAL;
  197. if (trip) {
  198. mask = THERM_MASK_THRESHOLD1;
  199. shift = THERM_SHIFT_THRESHOLD1;
  200. intr = THERM_INT_THRESHOLD1_ENABLE;
  201. } else {
  202. mask = THERM_MASK_THRESHOLD0;
  203. shift = THERM_SHIFT_THRESHOLD0;
  204. intr = THERM_INT_THRESHOLD0_ENABLE;
  205. }
  206. l &= ~mask;
  207. /*
  208. * When users space sets a trip temperature == 0, which is indication
  209. * that, it is no longer interested in receiving notifications.
  210. */
  211. if (!temp)
  212. l &= ~intr;
  213. else {
  214. l |= (phy_dev_entry->tj_max - temp)/1000 << shift;
  215. l |= intr;
  216. }
  217. return wrmsr_on_cpu(phy_dev_entry->first_cpu,
  218. MSR_IA32_PACKAGE_THERM_INTERRUPT,
  219. l, h);
  220. }
  221. static int sys_get_trip_type(struct thermal_zone_device *thermal,
  222. int trip, enum thermal_trip_type *type)
  223. {
  224. *type = THERMAL_TRIP_PASSIVE;
  225. return 0;
  226. }
  227. /* Thermal zone callback registry */
  228. static struct thermal_zone_device_ops tzone_ops = {
  229. .get_temp = sys_get_curr_temp,
  230. .get_trip_temp = sys_get_trip_temp,
  231. .get_trip_type = sys_get_trip_type,
  232. .set_trip_temp = sys_set_trip_temp,
  233. };
  234. static bool pkg_temp_thermal_platform_thermal_rate_control(void)
  235. {
  236. return true;
  237. }
  238. /* Enable threshold interrupt on local package/cpu */
  239. static inline void enable_pkg_thres_interrupt(void)
  240. {
  241. u32 l, h;
  242. u8 thres_0, thres_1;
  243. rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
  244. /* only enable/disable if it had valid threshold value */
  245. thres_0 = (l & THERM_MASK_THRESHOLD0) >> THERM_SHIFT_THRESHOLD0;
  246. thres_1 = (l & THERM_MASK_THRESHOLD1) >> THERM_SHIFT_THRESHOLD1;
  247. if (thres_0)
  248. l |= THERM_INT_THRESHOLD0_ENABLE;
  249. if (thres_1)
  250. l |= THERM_INT_THRESHOLD1_ENABLE;
  251. wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
  252. }
  253. /* Disable threshold interrupt on local package/cpu */
  254. static inline void disable_pkg_thres_interrupt(void)
  255. {
  256. u32 l, h;
  257. rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h);
  258. wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT,
  259. l & (~THERM_INT_THRESHOLD0_ENABLE) &
  260. (~THERM_INT_THRESHOLD1_ENABLE), h);
  261. }
  262. static void pkg_temp_thermal_threshold_work_fn(struct work_struct *work)
  263. {
  264. __u64 msr_val;
  265. int cpu = smp_processor_id();
  266. int phy_id = topology_physical_package_id(cpu);
  267. struct phy_dev_entry *phdev = pkg_temp_thermal_get_phy_entry(cpu);
  268. bool notify = false;
  269. if (!phdev)
  270. return;
  271. spin_lock(&pkg_work_lock);
  272. ++pkg_work_cnt;
  273. if (unlikely(phy_id > max_phy_id)) {
  274. spin_unlock(&pkg_work_lock);
  275. return;
  276. }
  277. pkg_work_scheduled[phy_id] = 0;
  278. spin_unlock(&pkg_work_lock);
  279. enable_pkg_thres_interrupt();
  280. rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val);
  281. if (msr_val & THERM_LOG_THRESHOLD0) {
  282. wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS,
  283. msr_val & ~THERM_LOG_THRESHOLD0);
  284. notify = true;
  285. }
  286. if (msr_val & THERM_LOG_THRESHOLD1) {
  287. wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS,
  288. msr_val & ~THERM_LOG_THRESHOLD1);
  289. notify = true;
  290. }
  291. if (notify) {
  292. pr_debug("thermal_zone_device_update\n");
  293. thermal_zone_device_update(phdev->tzone);
  294. }
  295. }
  296. static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  297. {
  298. unsigned long flags;
  299. int cpu = smp_processor_id();
  300. int phy_id = topology_physical_package_id(cpu);
  301. /*
  302. * When a package is in interrupted state, all CPU's in that package
  303. * are in the same interrupt state. So scheduling on any one CPU in
  304. * the package is enough and simply return for others.
  305. */
  306. spin_lock_irqsave(&pkg_work_lock, flags);
  307. ++pkg_interrupt_cnt;
  308. if (unlikely(phy_id > max_phy_id) || unlikely(!pkg_work_scheduled) ||
  309. pkg_work_scheduled[phy_id]) {
  310. disable_pkg_thres_interrupt();
  311. spin_unlock_irqrestore(&pkg_work_lock, flags);
  312. return -EINVAL;
  313. }
  314. pkg_work_scheduled[phy_id] = 1;
  315. spin_unlock_irqrestore(&pkg_work_lock, flags);
  316. disable_pkg_thres_interrupt();
  317. schedule_delayed_work_on(cpu,
  318. &per_cpu(pkg_temp_thermal_threshold_work, cpu),
  319. msecs_to_jiffies(notify_delay_ms));
  320. return 0;
  321. }
  322. static int find_siblings_cpu(int cpu)
  323. {
  324. int i;
  325. int id = topology_physical_package_id(cpu);
  326. for_each_online_cpu(i)
  327. if (i != cpu && topology_physical_package_id(i) == id)
  328. return i;
  329. return 0;
  330. }
  331. static int pkg_temp_thermal_device_add(unsigned int cpu)
  332. {
  333. int err;
  334. u32 tj_max;
  335. struct phy_dev_entry *phy_dev_entry;
  336. char buffer[30];
  337. int thres_count;
  338. u32 eax, ebx, ecx, edx;
  339. u8 *temp;
  340. cpuid(6, &eax, &ebx, &ecx, &edx);
  341. thres_count = ebx & 0x07;
  342. if (!thres_count)
  343. return -ENODEV;
  344. thres_count = clamp_val(thres_count, 0, MAX_NUMBER_OF_TRIPS);
  345. err = get_tj_max(cpu, &tj_max);
  346. if (err)
  347. goto err_ret;
  348. mutex_lock(&phy_dev_list_mutex);
  349. phy_dev_entry = kzalloc(sizeof(*phy_dev_entry), GFP_KERNEL);
  350. if (!phy_dev_entry) {
  351. err = -ENOMEM;
  352. goto err_ret_unlock;
  353. }
  354. spin_lock(&pkg_work_lock);
  355. if (topology_physical_package_id(cpu) > max_phy_id)
  356. max_phy_id = topology_physical_package_id(cpu);
  357. temp = krealloc(pkg_work_scheduled,
  358. (max_phy_id+1) * sizeof(u8), GFP_ATOMIC);
  359. if (!temp) {
  360. spin_unlock(&pkg_work_lock);
  361. err = -ENOMEM;
  362. goto err_ret_free;
  363. }
  364. pkg_work_scheduled = temp;
  365. pkg_work_scheduled[topology_physical_package_id(cpu)] = 0;
  366. spin_unlock(&pkg_work_lock);
  367. phy_dev_entry->phys_proc_id = topology_physical_package_id(cpu);
  368. phy_dev_entry->first_cpu = cpu;
  369. phy_dev_entry->tj_max = tj_max;
  370. phy_dev_entry->ref_cnt = 1;
  371. snprintf(buffer, sizeof(buffer), "pkg-temp-%d\n",
  372. phy_dev_entry->phys_proc_id);
  373. phy_dev_entry->tzone = thermal_zone_device_register(buffer,
  374. thres_count,
  375. (thres_count == MAX_NUMBER_OF_TRIPS) ?
  376. 0x03 : 0x01,
  377. phy_dev_entry, &tzone_ops, NULL, 0, 0);
  378. if (IS_ERR(phy_dev_entry->tzone)) {
  379. err = PTR_ERR(phy_dev_entry->tzone);
  380. goto err_ret_free;
  381. }
  382. /* Store MSR value for package thermal interrupt, to restore at exit */
  383. rdmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
  384. &phy_dev_entry->start_pkg_therm_low,
  385. &phy_dev_entry->start_pkg_therm_high);
  386. list_add_tail(&phy_dev_entry->list, &phy_dev_list);
  387. pr_debug("pkg_temp_thermal_device_add :phy_id %d cpu %d\n",
  388. phy_dev_entry->phys_proc_id, cpu);
  389. mutex_unlock(&phy_dev_list_mutex);
  390. return 0;
  391. err_ret_free:
  392. kfree(phy_dev_entry);
  393. err_ret_unlock:
  394. mutex_unlock(&phy_dev_list_mutex);
  395. err_ret:
  396. return err;
  397. }
  398. static int pkg_temp_thermal_device_remove(unsigned int cpu)
  399. {
  400. struct phy_dev_entry *n;
  401. u16 phys_proc_id = topology_physical_package_id(cpu);
  402. struct phy_dev_entry *phdev =
  403. pkg_temp_thermal_get_phy_entry(cpu);
  404. if (!phdev)
  405. return -ENODEV;
  406. mutex_lock(&phy_dev_list_mutex);
  407. /* If we are loosing the first cpu for this package, we need change */
  408. if (phdev->first_cpu == cpu) {
  409. phdev->first_cpu = find_siblings_cpu(cpu);
  410. pr_debug("thermal_device_remove: first cpu switched %d\n",
  411. phdev->first_cpu);
  412. }
  413. /*
  414. * It is possible that no siblings left as this was the last cpu
  415. * going offline. We don't need to worry about this assignment
  416. * as the phydev entry will be removed in this case and
  417. * thermal zone is removed.
  418. */
  419. --phdev->ref_cnt;
  420. pr_debug("thermal_device_remove: pkg: %d cpu %d ref_cnt %d\n",
  421. phys_proc_id, cpu, phdev->ref_cnt);
  422. if (!phdev->ref_cnt)
  423. list_for_each_entry_safe(phdev, n, &phy_dev_list, list) {
  424. if (phdev->phys_proc_id == phys_proc_id) {
  425. thermal_zone_device_unregister(phdev->tzone);
  426. list_del(&phdev->list);
  427. kfree(phdev);
  428. break;
  429. }
  430. }
  431. mutex_unlock(&phy_dev_list_mutex);
  432. return 0;
  433. }
  434. static int get_core_online(unsigned int cpu)
  435. {
  436. struct cpuinfo_x86 *c = &cpu_data(cpu);
  437. struct phy_dev_entry *phdev = pkg_temp_thermal_get_phy_entry(cpu);
  438. /* Check if there is already an instance for this package */
  439. if (!phdev) {
  440. if (!cpu_has(c, X86_FEATURE_DTHERM) ||
  441. !cpu_has(c, X86_FEATURE_PTS))
  442. return -ENODEV;
  443. if (pkg_temp_thermal_device_add(cpu))
  444. return -ENODEV;
  445. } else {
  446. mutex_lock(&phy_dev_list_mutex);
  447. ++phdev->ref_cnt;
  448. pr_debug("get_core_online: cpu %d ref_cnt %d\n",
  449. cpu, phdev->ref_cnt);
  450. mutex_unlock(&phy_dev_list_mutex);
  451. }
  452. INIT_DELAYED_WORK(&per_cpu(pkg_temp_thermal_threshold_work, cpu),
  453. pkg_temp_thermal_threshold_work_fn);
  454. pr_debug("get_core_online: cpu %d successful\n", cpu);
  455. return 0;
  456. }
  457. static void put_core_offline(unsigned int cpu)
  458. {
  459. if (!pkg_temp_thermal_device_remove(cpu))
  460. cancel_delayed_work_sync(
  461. &per_cpu(pkg_temp_thermal_threshold_work, cpu));
  462. pr_debug("put_core_offline: cpu %d\n", cpu);
  463. }
  464. static int pkg_temp_thermal_cpu_callback(struct notifier_block *nfb,
  465. unsigned long action, void *hcpu)
  466. {
  467. unsigned int cpu = (unsigned long) hcpu;
  468. switch (action) {
  469. case CPU_ONLINE:
  470. case CPU_DOWN_FAILED:
  471. get_core_online(cpu);
  472. break;
  473. case CPU_DOWN_PREPARE:
  474. put_core_offline(cpu);
  475. break;
  476. }
  477. return NOTIFY_OK;
  478. }
  479. static struct notifier_block pkg_temp_thermal_notifier __refdata = {
  480. .notifier_call = pkg_temp_thermal_cpu_callback,
  481. };
  482. static const struct x86_cpu_id __initconst pkg_temp_thermal_ids[] = {
  483. { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_PTS },
  484. {}
  485. };
  486. MODULE_DEVICE_TABLE(x86cpu, pkg_temp_thermal_ids);
  487. static int __init pkg_temp_thermal_init(void)
  488. {
  489. int i;
  490. if (!x86_match_cpu(pkg_temp_thermal_ids))
  491. return -ENODEV;
  492. spin_lock_init(&pkg_work_lock);
  493. platform_thermal_package_notify =
  494. pkg_temp_thermal_platform_thermal_notify;
  495. platform_thermal_package_rate_control =
  496. pkg_temp_thermal_platform_thermal_rate_control;
  497. get_online_cpus();
  498. for_each_online_cpu(i)
  499. if (get_core_online(i))
  500. goto err_ret;
  501. register_hotcpu_notifier(&pkg_temp_thermal_notifier);
  502. put_online_cpus();
  503. pkg_temp_debugfs_init(); /* Don't care if fails */
  504. return 0;
  505. err_ret:
  506. get_online_cpus();
  507. for_each_online_cpu(i)
  508. put_core_offline(i);
  509. put_online_cpus();
  510. kfree(pkg_work_scheduled);
  511. platform_thermal_package_notify = NULL;
  512. platform_thermal_package_rate_control = NULL;
  513. return -ENODEV;
  514. }
  515. static void __exit pkg_temp_thermal_exit(void)
  516. {
  517. struct phy_dev_entry *phdev, *n;
  518. int i;
  519. get_online_cpus();
  520. unregister_hotcpu_notifier(&pkg_temp_thermal_notifier);
  521. mutex_lock(&phy_dev_list_mutex);
  522. list_for_each_entry_safe(phdev, n, &phy_dev_list, list) {
  523. /* Retore old MSR value for package thermal interrupt */
  524. wrmsr_on_cpu(phdev->first_cpu,
  525. MSR_IA32_PACKAGE_THERM_INTERRUPT,
  526. phdev->start_pkg_therm_low,
  527. phdev->start_pkg_therm_high);
  528. thermal_zone_device_unregister(phdev->tzone);
  529. list_del(&phdev->list);
  530. kfree(phdev);
  531. }
  532. mutex_unlock(&phy_dev_list_mutex);
  533. platform_thermal_package_notify = NULL;
  534. platform_thermal_package_rate_control = NULL;
  535. for_each_online_cpu(i)
  536. cancel_delayed_work_sync(
  537. &per_cpu(pkg_temp_thermal_threshold_work, i));
  538. put_online_cpus();
  539. kfree(pkg_work_scheduled);
  540. debugfs_remove_recursive(debugfs);
  541. }
  542. module_init(pkg_temp_thermal_init)
  543. module_exit(pkg_temp_thermal_exit)
  544. MODULE_DESCRIPTION("X86 PKG TEMP Thermal Driver");
  545. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
  546. MODULE_LICENSE("GPL v2");