x86_pkg_temp_thermal.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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. cpuid(6, &eax, &ebx, &ecx, &edx);
  340. thres_count = ebx & 0x07;
  341. if (!thres_count)
  342. return -ENODEV;
  343. thres_count = clamp_val(thres_count, 0, MAX_NUMBER_OF_TRIPS);
  344. err = get_tj_max(cpu, &tj_max);
  345. if (err)
  346. goto err_ret;
  347. mutex_lock(&phy_dev_list_mutex);
  348. phy_dev_entry = kzalloc(sizeof(*phy_dev_entry), GFP_KERNEL);
  349. if (!phy_dev_entry) {
  350. err = -ENOMEM;
  351. goto err_ret_unlock;
  352. }
  353. spin_lock(&pkg_work_lock);
  354. if (topology_physical_package_id(cpu) > max_phy_id)
  355. max_phy_id = topology_physical_package_id(cpu);
  356. pkg_work_scheduled = krealloc(pkg_work_scheduled,
  357. (max_phy_id+1) * sizeof(u8), GFP_ATOMIC);
  358. if (!pkg_work_scheduled) {
  359. spin_unlock(&pkg_work_lock);
  360. err = -ENOMEM;
  361. goto err_ret_free;
  362. }
  363. pkg_work_scheduled[topology_physical_package_id(cpu)] = 0;
  364. spin_unlock(&pkg_work_lock);
  365. phy_dev_entry->phys_proc_id = topology_physical_package_id(cpu);
  366. phy_dev_entry->first_cpu = cpu;
  367. phy_dev_entry->tj_max = tj_max;
  368. phy_dev_entry->ref_cnt = 1;
  369. snprintf(buffer, sizeof(buffer), "pkg-temp-%d\n",
  370. phy_dev_entry->phys_proc_id);
  371. phy_dev_entry->tzone = thermal_zone_device_register(buffer,
  372. thres_count,
  373. (thres_count == MAX_NUMBER_OF_TRIPS) ?
  374. 0x03 : 0x01,
  375. phy_dev_entry, &tzone_ops, NULL, 0, 0);
  376. if (IS_ERR(phy_dev_entry->tzone)) {
  377. err = PTR_ERR(phy_dev_entry->tzone);
  378. goto err_ret_free;
  379. }
  380. /* Store MSR value for package thermal interrupt, to restore at exit */
  381. rdmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
  382. &phy_dev_entry->start_pkg_therm_low,
  383. &phy_dev_entry->start_pkg_therm_high);
  384. list_add_tail(&phy_dev_entry->list, &phy_dev_list);
  385. pr_debug("pkg_temp_thermal_device_add :phy_id %d cpu %d\n",
  386. phy_dev_entry->phys_proc_id, cpu);
  387. mutex_unlock(&phy_dev_list_mutex);
  388. return 0;
  389. err_ret_free:
  390. kfree(phy_dev_entry);
  391. err_ret_unlock:
  392. mutex_unlock(&phy_dev_list_mutex);
  393. err_ret:
  394. return err;
  395. }
  396. static int pkg_temp_thermal_device_remove(unsigned int cpu)
  397. {
  398. struct phy_dev_entry *n;
  399. u16 phys_proc_id = topology_physical_package_id(cpu);
  400. struct phy_dev_entry *phdev =
  401. pkg_temp_thermal_get_phy_entry(cpu);
  402. if (!phdev)
  403. return -ENODEV;
  404. mutex_lock(&phy_dev_list_mutex);
  405. /* If we are loosing the first cpu for this package, we need change */
  406. if (phdev->first_cpu == cpu) {
  407. phdev->first_cpu = find_siblings_cpu(cpu);
  408. pr_debug("thermal_device_remove: first cpu switched %d\n",
  409. phdev->first_cpu);
  410. }
  411. /*
  412. * It is possible that no siblings left as this was the last cpu
  413. * going offline. We don't need to worry about this assignment
  414. * as the phydev entry will be removed in this case and
  415. * thermal zone is removed.
  416. */
  417. --phdev->ref_cnt;
  418. pr_debug("thermal_device_remove: pkg: %d cpu %d ref_cnt %d\n",
  419. phys_proc_id, cpu, phdev->ref_cnt);
  420. if (!phdev->ref_cnt)
  421. list_for_each_entry_safe(phdev, n, &phy_dev_list, list) {
  422. if (phdev->phys_proc_id == phys_proc_id) {
  423. thermal_zone_device_unregister(phdev->tzone);
  424. list_del(&phdev->list);
  425. kfree(phdev);
  426. break;
  427. }
  428. }
  429. mutex_unlock(&phy_dev_list_mutex);
  430. return 0;
  431. }
  432. static int get_core_online(unsigned int cpu)
  433. {
  434. struct cpuinfo_x86 *c = &cpu_data(cpu);
  435. struct phy_dev_entry *phdev = pkg_temp_thermal_get_phy_entry(cpu);
  436. /* Check if there is already an instance for this package */
  437. if (!phdev) {
  438. if (!cpu_has(c, X86_FEATURE_DTHERM) &&
  439. !cpu_has(c, X86_FEATURE_PTS))
  440. return -ENODEV;
  441. if (pkg_temp_thermal_device_add(cpu))
  442. return -ENODEV;
  443. } else {
  444. mutex_lock(&phy_dev_list_mutex);
  445. ++phdev->ref_cnt;
  446. pr_debug("get_core_online: cpu %d ref_cnt %d\n",
  447. cpu, phdev->ref_cnt);
  448. mutex_unlock(&phy_dev_list_mutex);
  449. }
  450. INIT_DELAYED_WORK(&per_cpu(pkg_temp_thermal_threshold_work, cpu),
  451. pkg_temp_thermal_threshold_work_fn);
  452. pr_debug("get_core_online: cpu %d successful\n", cpu);
  453. return 0;
  454. }
  455. static void put_core_offline(unsigned int cpu)
  456. {
  457. if (!pkg_temp_thermal_device_remove(cpu))
  458. cancel_delayed_work_sync(
  459. &per_cpu(pkg_temp_thermal_threshold_work, cpu));
  460. pr_debug("put_core_offline: cpu %d\n", cpu);
  461. }
  462. static int pkg_temp_thermal_cpu_callback(struct notifier_block *nfb,
  463. unsigned long action, void *hcpu)
  464. {
  465. unsigned int cpu = (unsigned long) hcpu;
  466. switch (action) {
  467. case CPU_ONLINE:
  468. case CPU_DOWN_FAILED:
  469. get_core_online(cpu);
  470. break;
  471. case CPU_DOWN_PREPARE:
  472. put_core_offline(cpu);
  473. break;
  474. }
  475. return NOTIFY_OK;
  476. }
  477. static struct notifier_block pkg_temp_thermal_notifier __refdata = {
  478. .notifier_call = pkg_temp_thermal_cpu_callback,
  479. };
  480. static const struct x86_cpu_id __initconst pkg_temp_thermal_ids[] = {
  481. { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_DTHERM },
  482. {}
  483. };
  484. MODULE_DEVICE_TABLE(x86cpu, pkg_temp_thermal_ids);
  485. static int __init pkg_temp_thermal_init(void)
  486. {
  487. int i;
  488. if (!x86_match_cpu(pkg_temp_thermal_ids))
  489. return -ENODEV;
  490. spin_lock_init(&pkg_work_lock);
  491. platform_thermal_package_notify =
  492. pkg_temp_thermal_platform_thermal_notify;
  493. platform_thermal_package_rate_control =
  494. pkg_temp_thermal_platform_thermal_rate_control;
  495. get_online_cpus();
  496. for_each_online_cpu(i)
  497. if (get_core_online(i))
  498. goto err_ret;
  499. register_hotcpu_notifier(&pkg_temp_thermal_notifier);
  500. put_online_cpus();
  501. pkg_temp_debugfs_init(); /* Don't care if fails */
  502. return 0;
  503. err_ret:
  504. get_online_cpus();
  505. for_each_online_cpu(i)
  506. put_core_offline(i);
  507. put_online_cpus();
  508. kfree(pkg_work_scheduled);
  509. platform_thermal_package_notify = NULL;
  510. platform_thermal_package_rate_control = NULL;
  511. return -ENODEV;
  512. }
  513. static void __exit pkg_temp_thermal_exit(void)
  514. {
  515. struct phy_dev_entry *phdev, *n;
  516. int i;
  517. get_online_cpus();
  518. unregister_hotcpu_notifier(&pkg_temp_thermal_notifier);
  519. mutex_lock(&phy_dev_list_mutex);
  520. list_for_each_entry_safe(phdev, n, &phy_dev_list, list) {
  521. /* Retore old MSR value for package thermal interrupt */
  522. wrmsr_on_cpu(phdev->first_cpu,
  523. MSR_IA32_PACKAGE_THERM_INTERRUPT,
  524. phdev->start_pkg_therm_low,
  525. phdev->start_pkg_therm_high);
  526. thermal_zone_device_unregister(phdev->tzone);
  527. list_del(&phdev->list);
  528. kfree(phdev);
  529. }
  530. mutex_unlock(&phy_dev_list_mutex);
  531. platform_thermal_package_notify = NULL;
  532. platform_thermal_package_rate_control = NULL;
  533. for_each_online_cpu(i)
  534. cancel_delayed_work_sync(
  535. &per_cpu(pkg_temp_thermal_threshold_work, i));
  536. put_online_cpus();
  537. kfree(pkg_work_scheduled);
  538. debugfs_remove_recursive(debugfs);
  539. }
  540. module_init(pkg_temp_thermal_init)
  541. module_exit(pkg_temp_thermal_exit)
  542. MODULE_DESCRIPTION("X86 PKG TEMP Thermal Driver");
  543. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
  544. MODULE_LICENSE("GPL v2");