x86_pkg_temp_thermal.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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. unsigned long flags;
  272. if (!phdev)
  273. return;
  274. spin_lock_irqsave(&pkg_work_lock, flags);
  275. ++pkg_work_cnt;
  276. if (unlikely(phy_id > max_phy_id)) {
  277. spin_unlock_irqrestore(&pkg_work_lock, flags);
  278. return;
  279. }
  280. pkg_work_scheduled[phy_id] = 0;
  281. spin_unlock_irqrestore(&pkg_work_lock, flags);
  282. enable_pkg_thres_interrupt();
  283. rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val);
  284. if (msr_val & THERM_LOG_THRESHOLD0) {
  285. wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS,
  286. msr_val & ~THERM_LOG_THRESHOLD0);
  287. notify = true;
  288. }
  289. if (msr_val & THERM_LOG_THRESHOLD1) {
  290. wrmsrl(MSR_IA32_PACKAGE_THERM_STATUS,
  291. msr_val & ~THERM_LOG_THRESHOLD1);
  292. notify = true;
  293. }
  294. if (notify) {
  295. pr_debug("thermal_zone_device_update\n");
  296. thermal_zone_device_update(phdev->tzone);
  297. }
  298. }
  299. static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  300. {
  301. unsigned long flags;
  302. int cpu = smp_processor_id();
  303. int phy_id = topology_physical_package_id(cpu);
  304. /*
  305. * When a package is in interrupted state, all CPU's in that package
  306. * are in the same interrupt state. So scheduling on any one CPU in
  307. * the package is enough and simply return for others.
  308. */
  309. spin_lock_irqsave(&pkg_work_lock, flags);
  310. ++pkg_interrupt_cnt;
  311. if (unlikely(phy_id > max_phy_id) || unlikely(!pkg_work_scheduled) ||
  312. pkg_work_scheduled[phy_id]) {
  313. disable_pkg_thres_interrupt();
  314. spin_unlock_irqrestore(&pkg_work_lock, flags);
  315. return -EINVAL;
  316. }
  317. pkg_work_scheduled[phy_id] = 1;
  318. spin_unlock_irqrestore(&pkg_work_lock, flags);
  319. disable_pkg_thres_interrupt();
  320. schedule_delayed_work_on(cpu,
  321. &per_cpu(pkg_temp_thermal_threshold_work, cpu),
  322. msecs_to_jiffies(notify_delay_ms));
  323. return 0;
  324. }
  325. static int find_siblings_cpu(int cpu)
  326. {
  327. int i;
  328. int id = topology_physical_package_id(cpu);
  329. for_each_online_cpu(i)
  330. if (i != cpu && topology_physical_package_id(i) == id)
  331. return i;
  332. return 0;
  333. }
  334. static int pkg_temp_thermal_device_add(unsigned int cpu)
  335. {
  336. int err;
  337. u32 tj_max;
  338. struct phy_dev_entry *phy_dev_entry;
  339. char buffer[30];
  340. int thres_count;
  341. u32 eax, ebx, ecx, edx;
  342. u8 *temp;
  343. unsigned long flags;
  344. cpuid(6, &eax, &ebx, &ecx, &edx);
  345. thres_count = ebx & 0x07;
  346. if (!thres_count)
  347. return -ENODEV;
  348. if (topology_physical_package_id(cpu) > MAX_PKG_TEMP_ZONE_IDS)
  349. return -ENODEV;
  350. thres_count = clamp_val(thres_count, 0, MAX_NUMBER_OF_TRIPS);
  351. err = get_tj_max(cpu, &tj_max);
  352. if (err)
  353. goto err_ret;
  354. mutex_lock(&phy_dev_list_mutex);
  355. phy_dev_entry = kzalloc(sizeof(*phy_dev_entry), GFP_KERNEL);
  356. if (!phy_dev_entry) {
  357. err = -ENOMEM;
  358. goto err_ret_unlock;
  359. }
  360. spin_lock_irqsave(&pkg_work_lock, flags);
  361. if (topology_physical_package_id(cpu) > max_phy_id)
  362. max_phy_id = topology_physical_package_id(cpu);
  363. temp = krealloc(pkg_work_scheduled,
  364. (max_phy_id+1) * sizeof(u8), GFP_ATOMIC);
  365. if (!temp) {
  366. spin_unlock_irqrestore(&pkg_work_lock, flags);
  367. err = -ENOMEM;
  368. goto err_ret_free;
  369. }
  370. pkg_work_scheduled = temp;
  371. pkg_work_scheduled[topology_physical_package_id(cpu)] = 0;
  372. spin_unlock_irqrestore(&pkg_work_lock, flags);
  373. phy_dev_entry->phys_proc_id = topology_physical_package_id(cpu);
  374. phy_dev_entry->first_cpu = cpu;
  375. phy_dev_entry->tj_max = tj_max;
  376. phy_dev_entry->ref_cnt = 1;
  377. snprintf(buffer, sizeof(buffer), "pkg-temp-%d\n",
  378. phy_dev_entry->phys_proc_id);
  379. phy_dev_entry->tzone = thermal_zone_device_register(buffer,
  380. thres_count,
  381. (thres_count == MAX_NUMBER_OF_TRIPS) ?
  382. 0x03 : 0x01,
  383. phy_dev_entry, &tzone_ops, NULL, 0, 0);
  384. if (IS_ERR(phy_dev_entry->tzone)) {
  385. err = PTR_ERR(phy_dev_entry->tzone);
  386. goto err_ret_free;
  387. }
  388. /* Store MSR value for package thermal interrupt, to restore at exit */
  389. rdmsr_on_cpu(cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
  390. &phy_dev_entry->start_pkg_therm_low,
  391. &phy_dev_entry->start_pkg_therm_high);
  392. list_add_tail(&phy_dev_entry->list, &phy_dev_list);
  393. pr_debug("pkg_temp_thermal_device_add :phy_id %d cpu %d\n",
  394. phy_dev_entry->phys_proc_id, cpu);
  395. mutex_unlock(&phy_dev_list_mutex);
  396. return 0;
  397. err_ret_free:
  398. kfree(phy_dev_entry);
  399. err_ret_unlock:
  400. mutex_unlock(&phy_dev_list_mutex);
  401. err_ret:
  402. return err;
  403. }
  404. static int pkg_temp_thermal_device_remove(unsigned int cpu)
  405. {
  406. struct phy_dev_entry *n;
  407. u16 phys_proc_id = topology_physical_package_id(cpu);
  408. struct phy_dev_entry *phdev =
  409. pkg_temp_thermal_get_phy_entry(cpu);
  410. if (!phdev)
  411. return -ENODEV;
  412. mutex_lock(&phy_dev_list_mutex);
  413. /* If we are loosing the first cpu for this package, we need change */
  414. if (phdev->first_cpu == cpu) {
  415. phdev->first_cpu = find_siblings_cpu(cpu);
  416. pr_debug("thermal_device_remove: first cpu switched %d\n",
  417. phdev->first_cpu);
  418. }
  419. /*
  420. * It is possible that no siblings left as this was the last cpu
  421. * going offline. We don't need to worry about this assignment
  422. * as the phydev entry will be removed in this case and
  423. * thermal zone is removed.
  424. */
  425. --phdev->ref_cnt;
  426. pr_debug("thermal_device_remove: pkg: %d cpu %d ref_cnt %d\n",
  427. phys_proc_id, cpu, phdev->ref_cnt);
  428. if (!phdev->ref_cnt)
  429. list_for_each_entry_safe(phdev, n, &phy_dev_list, list) {
  430. if (phdev->phys_proc_id == phys_proc_id) {
  431. thermal_zone_device_unregister(phdev->tzone);
  432. list_del(&phdev->list);
  433. kfree(phdev);
  434. break;
  435. }
  436. }
  437. mutex_unlock(&phy_dev_list_mutex);
  438. return 0;
  439. }
  440. static int get_core_online(unsigned int cpu)
  441. {
  442. struct cpuinfo_x86 *c = &cpu_data(cpu);
  443. struct phy_dev_entry *phdev = pkg_temp_thermal_get_phy_entry(cpu);
  444. /* Check if there is already an instance for this package */
  445. if (!phdev) {
  446. if (!cpu_has(c, X86_FEATURE_DTHERM) ||
  447. !cpu_has(c, X86_FEATURE_PTS))
  448. return -ENODEV;
  449. if (pkg_temp_thermal_device_add(cpu))
  450. return -ENODEV;
  451. } else {
  452. mutex_lock(&phy_dev_list_mutex);
  453. ++phdev->ref_cnt;
  454. pr_debug("get_core_online: cpu %d ref_cnt %d\n",
  455. cpu, phdev->ref_cnt);
  456. mutex_unlock(&phy_dev_list_mutex);
  457. }
  458. INIT_DELAYED_WORK(&per_cpu(pkg_temp_thermal_threshold_work, cpu),
  459. pkg_temp_thermal_threshold_work_fn);
  460. pr_debug("get_core_online: cpu %d successful\n", cpu);
  461. return 0;
  462. }
  463. static void put_core_offline(unsigned int cpu)
  464. {
  465. if (!pkg_temp_thermal_device_remove(cpu))
  466. cancel_delayed_work_sync(
  467. &per_cpu(pkg_temp_thermal_threshold_work, cpu));
  468. pr_debug("put_core_offline: cpu %d\n", cpu);
  469. }
  470. static int pkg_temp_thermal_cpu_callback(struct notifier_block *nfb,
  471. unsigned long action, void *hcpu)
  472. {
  473. unsigned int cpu = (unsigned long) hcpu;
  474. switch (action) {
  475. case CPU_ONLINE:
  476. case CPU_DOWN_FAILED:
  477. get_core_online(cpu);
  478. break;
  479. case CPU_DOWN_PREPARE:
  480. put_core_offline(cpu);
  481. break;
  482. }
  483. return NOTIFY_OK;
  484. }
  485. static struct notifier_block pkg_temp_thermal_notifier __refdata = {
  486. .notifier_call = pkg_temp_thermal_cpu_callback,
  487. };
  488. static const struct x86_cpu_id __initconst pkg_temp_thermal_ids[] = {
  489. { X86_VENDOR_INTEL, X86_FAMILY_ANY, X86_MODEL_ANY, X86_FEATURE_PTS },
  490. {}
  491. };
  492. MODULE_DEVICE_TABLE(x86cpu, pkg_temp_thermal_ids);
  493. static int __init pkg_temp_thermal_init(void)
  494. {
  495. int i;
  496. if (!x86_match_cpu(pkg_temp_thermal_ids))
  497. return -ENODEV;
  498. spin_lock_init(&pkg_work_lock);
  499. platform_thermal_package_notify =
  500. pkg_temp_thermal_platform_thermal_notify;
  501. platform_thermal_package_rate_control =
  502. pkg_temp_thermal_platform_thermal_rate_control;
  503. get_online_cpus();
  504. for_each_online_cpu(i)
  505. if (get_core_online(i))
  506. goto err_ret;
  507. register_hotcpu_notifier(&pkg_temp_thermal_notifier);
  508. put_online_cpus();
  509. pkg_temp_debugfs_init(); /* Don't care if fails */
  510. return 0;
  511. err_ret:
  512. for_each_online_cpu(i)
  513. put_core_offline(i);
  514. put_online_cpus();
  515. kfree(pkg_work_scheduled);
  516. platform_thermal_package_notify = NULL;
  517. platform_thermal_package_rate_control = NULL;
  518. return -ENODEV;
  519. }
  520. static void __exit pkg_temp_thermal_exit(void)
  521. {
  522. struct phy_dev_entry *phdev, *n;
  523. int i;
  524. get_online_cpus();
  525. unregister_hotcpu_notifier(&pkg_temp_thermal_notifier);
  526. mutex_lock(&phy_dev_list_mutex);
  527. list_for_each_entry_safe(phdev, n, &phy_dev_list, list) {
  528. /* Retore old MSR value for package thermal interrupt */
  529. wrmsr_on_cpu(phdev->first_cpu,
  530. MSR_IA32_PACKAGE_THERM_INTERRUPT,
  531. phdev->start_pkg_therm_low,
  532. phdev->start_pkg_therm_high);
  533. thermal_zone_device_unregister(phdev->tzone);
  534. list_del(&phdev->list);
  535. kfree(phdev);
  536. }
  537. mutex_unlock(&phy_dev_list_mutex);
  538. platform_thermal_package_notify = NULL;
  539. platform_thermal_package_rate_control = NULL;
  540. for_each_online_cpu(i)
  541. cancel_delayed_work_sync(
  542. &per_cpu(pkg_temp_thermal_threshold_work, i));
  543. put_online_cpus();
  544. kfree(pkg_work_scheduled);
  545. debugfs_remove_recursive(debugfs);
  546. }
  547. module_init(pkg_temp_thermal_init)
  548. module_exit(pkg_temp_thermal_exit)
  549. MODULE_DESCRIPTION("X86 PKG TEMP Thermal Driver");
  550. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
  551. MODULE_LICENSE("GPL v2");