x86_pkg_temp_thermal.c 16 KB

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