Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 2 | /* |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 3 | * Thermal throttle event support code (such as syslog messaging and rate |
| 4 | * limiting) that was factored out from x86_64 (mce_intel.c) and i386 (p4.c). |
Ingo Molnar | cb6f3c1 | 2009-04-08 12:31:19 +0200 | [diff] [blame] | 5 | * |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 6 | * This allows consistent reporting of CPU thermal throttle events. |
| 7 | * |
| 8 | * Maintains a counter in /sys that keeps track of the number of thermal |
| 9 | * events, such that the user knows how bad the thermal problem might be |
Borislav Petkov | 9b052ea | 2017-01-23 19:35:07 +0100 | [diff] [blame] | 10 | * (since the logging to syslog is rate limited). |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 11 | * |
| 12 | * Author: Dmitriy Zavin (dmitriyz@google.com) |
| 13 | * |
| 14 | * Credits: Adapted from Zwane Mwaikambo's original code in mce_intel.c. |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 15 | * Inspired by Ross Biro's and Al Borchers' counter code. |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 16 | */ |
Hidetoshi Seto | a65c88d | 2009-06-15 17:25:27 +0900 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
Ingo Molnar | cb6f3c1 | 2009-04-08 12:31:19 +0200 | [diff] [blame] | 18 | #include <linux/notifier.h> |
| 19 | #include <linux/jiffies.h> |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 20 | #include <linux/kernel.h> |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 21 | #include <linux/percpu.h> |
Paul Gortmaker | 69c60c8 | 2011-05-26 12:22:53 -0400 | [diff] [blame] | 22 | #include <linux/export.h> |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 23 | #include <linux/types.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/smp.h> |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 26 | #include <linux/cpu.h> |
Ingo Molnar | cb6f3c1 | 2009-04-08 12:31:19 +0200 | [diff] [blame] | 27 | |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 28 | #include <asm/processor.h> |
Borislav Petkov | 68b5e432 | 2018-11-09 23:13:13 +0100 | [diff] [blame] | 29 | #include <asm/traps.h> |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 30 | #include <asm/apic.h> |
Hidetoshi Seto | a65c88d | 2009-06-15 17:25:27 +0900 | [diff] [blame] | 31 | #include <asm/mce.h> |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 32 | #include <asm/msr.h> |
Seiji Aguchi | cf910e8 | 2013-06-20 11:46:53 -0400 | [diff] [blame] | 33 | #include <asm/trace/irq_vectors.h> |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 34 | |
Borislav Petkov | 3bfaf95 | 2018-12-05 21:05:13 +0100 | [diff] [blame] | 35 | #include "internal.h" |
| 36 | |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 37 | /* How long to wait between reporting thermal events */ |
Ingo Molnar | cb6f3c1 | 2009-04-08 12:31:19 +0200 | [diff] [blame] | 38 | #define CHECK_INTERVAL (300 * HZ) |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 39 | |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 40 | #define THERMAL_THROTTLING_EVENT 0 |
| 41 | #define POWER_LIMIT_EVENT 1 |
| 42 | |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 43 | /* |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 44 | * Current thermal event state: |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 45 | */ |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 46 | struct _thermal_state { |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 47 | bool new_event; |
| 48 | int event; |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 49 | u64 next_check; |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 50 | unsigned long count; |
| 51 | unsigned long last_count; |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 54 | struct thermal_state { |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 55 | struct _thermal_state core_throttle; |
| 56 | struct _thermal_state core_power_limit; |
| 57 | struct _thermal_state package_throttle; |
| 58 | struct _thermal_state package_power_limit; |
R, Durgadoss | 9e76a97 | 2011-01-03 17:22:04 +0530 | [diff] [blame] | 59 | struct _thermal_state core_thresh0; |
| 60 | struct _thermal_state core_thresh1; |
Srinivas Pandruvada | 25cdce1 | 2013-05-17 23:42:01 +0000 | [diff] [blame] | 61 | struct _thermal_state pkg_thresh0; |
| 62 | struct _thermal_state pkg_thresh1; |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
R, Durgadoss | 9e76a97 | 2011-01-03 17:22:04 +0530 | [diff] [blame] | 65 | /* Callback to handle core threshold interrupts */ |
| 66 | int (*platform_thermal_notify)(__u64 msr_val); |
Fenghua Yu | f21bbec | 2011-01-20 20:12:40 -0800 | [diff] [blame] | 67 | EXPORT_SYMBOL(platform_thermal_notify); |
R, Durgadoss | 9e76a97 | 2011-01-03 17:22:04 +0530 | [diff] [blame] | 68 | |
Srinivas Pandruvada | 25cdce1 | 2013-05-17 23:42:01 +0000 | [diff] [blame] | 69 | /* Callback to handle core package threshold_interrupts */ |
| 70 | int (*platform_thermal_package_notify)(__u64 msr_val); |
| 71 | EXPORT_SYMBOL_GPL(platform_thermal_package_notify); |
| 72 | |
| 73 | /* Callback support of rate control, return true, if |
| 74 | * callback has rate control */ |
| 75 | bool (*platform_thermal_package_rate_control)(void); |
| 76 | EXPORT_SYMBOL_GPL(platform_thermal_package_rate_control); |
| 77 | |
| 78 | |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 79 | static DEFINE_PER_CPU(struct thermal_state, thermal_state); |
| 80 | |
| 81 | static atomic_t therm_throt_en = ATOMIC_INIT(0); |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 82 | |
Yong Wang | a2202aa | 2009-11-10 09:38:24 +0800 | [diff] [blame] | 83 | static u32 lvtthmr_init __read_mostly; |
| 84 | |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 85 | #ifdef CONFIG_SYSFS |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 86 | #define define_therm_throt_device_one_ro(_name) \ |
| 87 | static DEVICE_ATTR(_name, 0444, \ |
| 88 | therm_throt_device_show_##_name, \ |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 89 | NULL) \ |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 90 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 91 | #define define_therm_throt_device_show_func(event, name) \ |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 92 | \ |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 93 | static ssize_t therm_throt_device_show_##event##_##name( \ |
| 94 | struct device *dev, \ |
| 95 | struct device_attribute *attr, \ |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 96 | char *buf) \ |
Ingo Molnar | cb6f3c1 | 2009-04-08 12:31:19 +0200 | [diff] [blame] | 97 | { \ |
| 98 | unsigned int cpu = dev->id; \ |
| 99 | ssize_t ret; \ |
| 100 | \ |
| 101 | preempt_disable(); /* CPU hotplug */ \ |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 102 | if (cpu_online(cpu)) { \ |
Ingo Molnar | cb6f3c1 | 2009-04-08 12:31:19 +0200 | [diff] [blame] | 103 | ret = sprintf(buf, "%lu\n", \ |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 104 | per_cpu(thermal_state, cpu).event.name); \ |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 105 | } else \ |
Ingo Molnar | cb6f3c1 | 2009-04-08 12:31:19 +0200 | [diff] [blame] | 106 | ret = 0; \ |
| 107 | preempt_enable(); \ |
| 108 | \ |
| 109 | return ret; \ |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 112 | define_therm_throt_device_show_func(core_throttle, count); |
| 113 | define_therm_throt_device_one_ro(core_throttle_count); |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 114 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 115 | define_therm_throt_device_show_func(core_power_limit, count); |
| 116 | define_therm_throt_device_one_ro(core_power_limit_count); |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 117 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 118 | define_therm_throt_device_show_func(package_throttle, count); |
| 119 | define_therm_throt_device_one_ro(package_throttle_count); |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 120 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 121 | define_therm_throt_device_show_func(package_power_limit, count); |
| 122 | define_therm_throt_device_one_ro(package_power_limit_count); |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 123 | |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 124 | static struct attribute *thermal_throttle_attrs[] = { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 125 | &dev_attr_core_throttle_count.attr, |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 126 | NULL |
| 127 | }; |
| 128 | |
Arvind Yadav | 45bd07a | 2017-07-20 17:00:32 +0530 | [diff] [blame] | 129 | static const struct attribute_group thermal_attr_group = { |
Ingo Molnar | cb6f3c1 | 2009-04-08 12:31:19 +0200 | [diff] [blame] | 130 | .attrs = thermal_throttle_attrs, |
| 131 | .name = "thermal_throttle" |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 132 | }; |
| 133 | #endif /* CONFIG_SYSFS */ |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 134 | |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 135 | #define CORE_LEVEL 0 |
| 136 | #define PACKAGE_LEVEL 1 |
| 137 | |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 138 | /*** |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 139 | * therm_throt_process - Process thermal throttling event from interrupt |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 140 | * @curr: Whether the condition is current or not (boolean), since the |
| 141 | * thermal interrupt normally gets called both when the thermal |
| 142 | * event begins and once the event has ended. |
| 143 | * |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 144 | * This function is called by the thermal interrupt after the |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 145 | * IRQ has been acknowledged. |
| 146 | * |
| 147 | * It will take care of rate limiting and printing messages to the syslog. |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 148 | */ |
Borislav Petkov | 9b052ea | 2017-01-23 19:35:07 +0100 | [diff] [blame] | 149 | static void therm_throt_process(bool new_event, int event, int level) |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 150 | { |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 151 | struct _thermal_state *state; |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 152 | unsigned int this_cpu = smp_processor_id(); |
| 153 | bool old_event; |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 154 | u64 now; |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 155 | struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 156 | |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 157 | now = get_jiffies_64(); |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 158 | if (level == CORE_LEVEL) { |
| 159 | if (event == THERMAL_THROTTLING_EVENT) |
| 160 | state = &pstate->core_throttle; |
| 161 | else if (event == POWER_LIMIT_EVENT) |
| 162 | state = &pstate->core_power_limit; |
| 163 | else |
Borislav Petkov | 9b052ea | 2017-01-23 19:35:07 +0100 | [diff] [blame] | 164 | return; |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 165 | } else if (level == PACKAGE_LEVEL) { |
| 166 | if (event == THERMAL_THROTTLING_EVENT) |
| 167 | state = &pstate->package_throttle; |
| 168 | else if (event == POWER_LIMIT_EVENT) |
| 169 | state = &pstate->package_power_limit; |
| 170 | else |
Borislav Petkov | 9b052ea | 2017-01-23 19:35:07 +0100 | [diff] [blame] | 171 | return; |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 172 | } else |
Borislav Petkov | 9b052ea | 2017-01-23 19:35:07 +0100 | [diff] [blame] | 173 | return; |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 174 | |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 175 | old_event = state->new_event; |
| 176 | state->new_event = new_event; |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 177 | |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 178 | if (new_event) |
| 179 | state->count++; |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 180 | |
Ingo Molnar | b417c9f | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 181 | if (time_before64(now, state->next_check) && |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 182 | state->count != state->last_count) |
Borislav Petkov | 9b052ea | 2017-01-23 19:35:07 +0100 | [diff] [blame] | 183 | return; |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 184 | |
Ingo Molnar | 3967684 | 2009-09-22 15:50:24 +0200 | [diff] [blame] | 185 | state->next_check = now + CHECK_INTERVAL; |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 186 | state->last_count = state->count; |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 187 | |
| 188 | /* if we just entered the thermal event */ |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 189 | if (new_event) { |
| 190 | if (event == THERMAL_THROTTLING_EVENT) |
Chen Yucong | 1b74dde | 2016-02-02 11:45:02 +0800 | [diff] [blame] | 191 | pr_crit("CPU%d: %s temperature above threshold, cpu clock throttled (total events = %lu)\n", |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 192 | this_cpu, |
| 193 | level == CORE_LEVEL ? "Core" : "Package", |
| 194 | state->count); |
Borislav Petkov | 9b052ea | 2017-01-23 19:35:07 +0100 | [diff] [blame] | 195 | return; |
Hugh Dickins | 4e5c25d | 2009-08-16 15:54:37 +0100 | [diff] [blame] | 196 | } |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 197 | if (old_event) { |
| 198 | if (event == THERMAL_THROTTLING_EVENT) |
Chen Yucong | 1b74dde | 2016-02-02 11:45:02 +0800 | [diff] [blame] | 199 | pr_info("CPU%d: %s temperature/speed normal\n", this_cpu, |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 200 | level == CORE_LEVEL ? "Core" : "Package"); |
Borislav Petkov | 9b052ea | 2017-01-23 19:35:07 +0100 | [diff] [blame] | 201 | return; |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 202 | } |
Dmitriy Zavin | 15d5f83 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 203 | } |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 204 | |
Srinivas Pandruvada | 25cdce1 | 2013-05-17 23:42:01 +0000 | [diff] [blame] | 205 | static int thresh_event_valid(int level, int event) |
R, Durgadoss | 9e76a97 | 2011-01-03 17:22:04 +0530 | [diff] [blame] | 206 | { |
| 207 | struct _thermal_state *state; |
| 208 | unsigned int this_cpu = smp_processor_id(); |
| 209 | struct thermal_state *pstate = &per_cpu(thermal_state, this_cpu); |
| 210 | u64 now = get_jiffies_64(); |
| 211 | |
Srinivas Pandruvada | 25cdce1 | 2013-05-17 23:42:01 +0000 | [diff] [blame] | 212 | if (level == PACKAGE_LEVEL) |
| 213 | state = (event == 0) ? &pstate->pkg_thresh0 : |
| 214 | &pstate->pkg_thresh1; |
| 215 | else |
| 216 | state = (event == 0) ? &pstate->core_thresh0 : |
| 217 | &pstate->core_thresh1; |
R, Durgadoss | 9e76a97 | 2011-01-03 17:22:04 +0530 | [diff] [blame] | 218 | |
| 219 | if (time_before64(now, state->next_check)) |
| 220 | return 0; |
| 221 | |
| 222 | state->next_check = now + CHECK_INTERVAL; |
Srinivas Pandruvada | 25cdce1 | 2013-05-17 23:42:01 +0000 | [diff] [blame] | 223 | |
R, Durgadoss | 9e76a97 | 2011-01-03 17:22:04 +0530 | [diff] [blame] | 224 | return 1; |
| 225 | } |
| 226 | |
Fenghua Yu | 6bb2ff8 | 2013-05-21 15:35:17 -0400 | [diff] [blame] | 227 | static bool int_pln_enable; |
| 228 | static int __init int_pln_enable_setup(char *s) |
| 229 | { |
| 230 | int_pln_enable = true; |
| 231 | |
| 232 | return 1; |
| 233 | } |
| 234 | __setup("int_pln_enable", int_pln_enable_setup); |
| 235 | |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 236 | #ifdef CONFIG_SYSFS |
Ingo Molnar | cb6f3c1 | 2009-04-08 12:31:19 +0200 | [diff] [blame] | 237 | /* Add/Remove thermal_throttle interface for CPU device: */ |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 238 | static int thermal_throttle_add_dev(struct device *dev, unsigned int cpu) |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 239 | { |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 240 | int err; |
Sergey Senozhatsky | 51e3c1b | 2010-08-20 10:36:34 +0300 | [diff] [blame] | 241 | struct cpuinfo_x86 *c = &cpu_data(cpu); |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 242 | |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 243 | err = sysfs_create_group(&dev->kobj, &thermal_attr_group); |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 244 | if (err) |
| 245 | return err; |
| 246 | |
Fenghua Yu | 6bb2ff8 | 2013-05-21 15:35:17 -0400 | [diff] [blame] | 247 | if (cpu_has(c, X86_FEATURE_PLN) && int_pln_enable) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 248 | err = sysfs_add_file_to_group(&dev->kobj, |
| 249 | &dev_attr_core_power_limit_count.attr, |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 250 | thermal_attr_group.name); |
Jin Dongming | b62be8e | 2010-08-26 17:29:05 +0900 | [diff] [blame] | 251 | if (cpu_has(c, X86_FEATURE_PTS)) { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 252 | err = sysfs_add_file_to_group(&dev->kobj, |
| 253 | &dev_attr_package_throttle_count.attr, |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 254 | thermal_attr_group.name); |
Fenghua Yu | 6bb2ff8 | 2013-05-21 15:35:17 -0400 | [diff] [blame] | 255 | if (cpu_has(c, X86_FEATURE_PLN) && int_pln_enable) |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 256 | err = sysfs_add_file_to_group(&dev->kobj, |
| 257 | &dev_attr_package_power_limit_count.attr, |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 258 | thermal_attr_group.name); |
Jin Dongming | b62be8e | 2010-08-26 17:29:05 +0900 | [diff] [blame] | 259 | } |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 260 | |
| 261 | return err; |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 262 | } |
| 263 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 264 | static void thermal_throttle_remove_dev(struct device *dev) |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 265 | { |
Kay Sievers | 8a25a2f | 2011-12-21 14:29:42 -0800 | [diff] [blame] | 266 | sysfs_remove_group(&dev->kobj, &thermal_attr_group); |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 269 | /* Get notified when a cpu comes on/off. Be hotplug friendly. */ |
Thomas Gleixner | 33d9730 | 2016-11-21 13:15:32 +0100 | [diff] [blame] | 270 | static int thermal_throttle_online(unsigned int cpu) |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 271 | { |
Sebastian Andrzej Siewior | d6526e7 | 2016-11-17 19:35:22 +0100 | [diff] [blame] | 272 | struct device *dev = get_cpu_device(cpu); |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 273 | |
Sebastian Andrzej Siewior | d6526e7 | 2016-11-17 19:35:22 +0100 | [diff] [blame] | 274 | return thermal_throttle_add_dev(dev, cpu); |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 275 | } |
| 276 | |
Thomas Gleixner | 33d9730 | 2016-11-21 13:15:32 +0100 | [diff] [blame] | 277 | static int thermal_throttle_offline(unsigned int cpu) |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 278 | { |
Sebastian Andrzej Siewior | d6526e7 | 2016-11-17 19:35:22 +0100 | [diff] [blame] | 279 | struct device *dev = get_cpu_device(cpu); |
| 280 | |
| 281 | thermal_throttle_remove_dev(dev); |
| 282 | return 0; |
| 283 | } |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 284 | |
| 285 | static __init int thermal_throttle_init_device(void) |
| 286 | { |
Thomas Gleixner | 33d9730 | 2016-11-21 13:15:32 +0100 | [diff] [blame] | 287 | int ret; |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 288 | |
| 289 | if (!atomic_read(&therm_throt_en)) |
| 290 | return 0; |
| 291 | |
Thomas Gleixner | 33d9730 | 2016-11-21 13:15:32 +0100 | [diff] [blame] | 292 | ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/therm:online", |
| 293 | thermal_throttle_online, |
| 294 | thermal_throttle_offline); |
| 295 | return ret < 0 ? ret : 0; |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 296 | } |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 297 | device_initcall(thermal_throttle_init_device); |
Hidetoshi Seto | a65c88d | 2009-06-15 17:25:27 +0900 | [diff] [blame] | 298 | |
Dmitriy Zavin | 3222b36 | 2006-09-26 10:52:42 +0200 | [diff] [blame] | 299 | #endif /* CONFIG_SYSFS */ |
Hidetoshi Seto | a65c88d | 2009-06-15 17:25:27 +0900 | [diff] [blame] | 300 | |
Srinivas Pandruvada | 25cdce1 | 2013-05-17 23:42:01 +0000 | [diff] [blame] | 301 | static void notify_package_thresholds(__u64 msr_val) |
| 302 | { |
| 303 | bool notify_thres_0 = false; |
| 304 | bool notify_thres_1 = false; |
| 305 | |
| 306 | if (!platform_thermal_package_notify) |
| 307 | return; |
| 308 | |
| 309 | /* lower threshold check */ |
| 310 | if (msr_val & THERM_LOG_THRESHOLD0) |
| 311 | notify_thres_0 = true; |
| 312 | /* higher threshold check */ |
| 313 | if (msr_val & THERM_LOG_THRESHOLD1) |
| 314 | notify_thres_1 = true; |
| 315 | |
| 316 | if (!notify_thres_0 && !notify_thres_1) |
| 317 | return; |
| 318 | |
| 319 | if (platform_thermal_package_rate_control && |
| 320 | platform_thermal_package_rate_control()) { |
| 321 | /* Rate control is implemented in callback */ |
| 322 | platform_thermal_package_notify(msr_val); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | /* lower threshold reached */ |
| 327 | if (notify_thres_0 && thresh_event_valid(PACKAGE_LEVEL, 0)) |
| 328 | platform_thermal_package_notify(msr_val); |
| 329 | /* higher threshold reached */ |
| 330 | if (notify_thres_1 && thresh_event_valid(PACKAGE_LEVEL, 1)) |
| 331 | platform_thermal_package_notify(msr_val); |
| 332 | } |
| 333 | |
R, Durgadoss | 9e76a97 | 2011-01-03 17:22:04 +0530 | [diff] [blame] | 334 | static void notify_thresholds(__u64 msr_val) |
| 335 | { |
| 336 | /* check whether the interrupt handler is defined; |
| 337 | * otherwise simply return |
| 338 | */ |
| 339 | if (!platform_thermal_notify) |
| 340 | return; |
| 341 | |
| 342 | /* lower threshold reached */ |
Srinivas Pandruvada | 25cdce1 | 2013-05-17 23:42:01 +0000 | [diff] [blame] | 343 | if ((msr_val & THERM_LOG_THRESHOLD0) && |
| 344 | thresh_event_valid(CORE_LEVEL, 0)) |
R, Durgadoss | 9e76a97 | 2011-01-03 17:22:04 +0530 | [diff] [blame] | 345 | platform_thermal_notify(msr_val); |
| 346 | /* higher threshold reached */ |
Srinivas Pandruvada | 25cdce1 | 2013-05-17 23:42:01 +0000 | [diff] [blame] | 347 | if ((msr_val & THERM_LOG_THRESHOLD1) && |
| 348 | thresh_event_valid(CORE_LEVEL, 1)) |
R, Durgadoss | 9e76a97 | 2011-01-03 17:22:04 +0530 | [diff] [blame] | 349 | platform_thermal_notify(msr_val); |
| 350 | } |
| 351 | |
Hidetoshi Seto | a65c88d | 2009-06-15 17:25:27 +0900 | [diff] [blame] | 352 | /* Thermal transition interrupt handler */ |
Hidetoshi Seto | 8363fc8 | 2009-06-15 17:26:36 +0900 | [diff] [blame] | 353 | static void intel_thermal_interrupt(void) |
Hidetoshi Seto | a65c88d | 2009-06-15 17:25:27 +0900 | [diff] [blame] | 354 | { |
| 355 | __u64 msr_val; |
| 356 | |
Srinivas Pandruvada | a212116 | 2016-03-23 21:07:39 -0700 | [diff] [blame] | 357 | if (static_cpu_has(X86_FEATURE_HWP)) |
| 358 | wrmsrl_safe(MSR_HWP_STATUS, 0); |
| 359 | |
Hidetoshi Seto | a65c88d | 2009-06-15 17:25:27 +0900 | [diff] [blame] | 360 | rdmsrl(MSR_IA32_THERM_STATUS, msr_val); |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 361 | |
R, Durgadoss | 9e76a97 | 2011-01-03 17:22:04 +0530 | [diff] [blame] | 362 | /* Check for violation of core thermal thresholds*/ |
| 363 | notify_thresholds(msr_val); |
| 364 | |
Borislav Petkov | 9b052ea | 2017-01-23 19:35:07 +0100 | [diff] [blame] | 365 | therm_throt_process(msr_val & THERM_STATUS_PROCHOT, |
| 366 | THERMAL_THROTTLING_EVENT, |
| 367 | CORE_LEVEL); |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 368 | |
Fenghua Yu | 6bb2ff8 | 2013-05-21 15:35:17 -0400 | [diff] [blame] | 369 | if (this_cpu_has(X86_FEATURE_PLN) && int_pln_enable) |
Fenghua Yu | 29e9bf1 | 2011-11-04 13:31:23 -0700 | [diff] [blame] | 370 | therm_throt_process(msr_val & THERM_STATUS_POWER_LIMIT, |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 371 | POWER_LIMIT_EVENT, |
Fenghua Yu | 29e9bf1 | 2011-11-04 13:31:23 -0700 | [diff] [blame] | 372 | CORE_LEVEL); |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 373 | |
Christoph Lameter | fe50421 | 2011-03-12 12:50:46 +0100 | [diff] [blame] | 374 | if (this_cpu_has(X86_FEATURE_PTS)) { |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 375 | rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val); |
Srinivas Pandruvada | 25cdce1 | 2013-05-17 23:42:01 +0000 | [diff] [blame] | 376 | /* check violations of package thermal thresholds */ |
| 377 | notify_package_thresholds(msr_val); |
Fenghua Yu | 29e9bf1 | 2011-11-04 13:31:23 -0700 | [diff] [blame] | 378 | therm_throt_process(msr_val & PACKAGE_THERM_STATUS_PROCHOT, |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 379 | THERMAL_THROTTLING_EVENT, |
Fenghua Yu | 29e9bf1 | 2011-11-04 13:31:23 -0700 | [diff] [blame] | 380 | PACKAGE_LEVEL); |
Fenghua Yu | 6bb2ff8 | 2013-05-21 15:35:17 -0400 | [diff] [blame] | 381 | if (this_cpu_has(X86_FEATURE_PLN) && int_pln_enable) |
Fenghua Yu | 29e9bf1 | 2011-11-04 13:31:23 -0700 | [diff] [blame] | 382 | therm_throt_process(msr_val & |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 383 | PACKAGE_THERM_STATUS_POWER_LIMIT, |
| 384 | POWER_LIMIT_EVENT, |
Fenghua Yu | 29e9bf1 | 2011-11-04 13:31:23 -0700 | [diff] [blame] | 385 | PACKAGE_LEVEL); |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 386 | } |
Hidetoshi Seto | a65c88d | 2009-06-15 17:25:27 +0900 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | static void unexpected_thermal_interrupt(void) |
| 390 | { |
Chen Yucong | 1b74dde | 2016-02-02 11:45:02 +0800 | [diff] [blame] | 391 | pr_err("CPU%d: Unexpected LVT thermal interrupt!\n", |
| 392 | smp_processor_id()); |
Hidetoshi Seto | a65c88d | 2009-06-15 17:25:27 +0900 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static void (*smp_thermal_vector)(void) = unexpected_thermal_interrupt; |
| 396 | |
Borislav Petkov | 68b5e432 | 2018-11-09 23:13:13 +0100 | [diff] [blame] | 397 | asmlinkage __visible void __irq_entry smp_thermal_interrupt(struct pt_regs *regs) |
Seiji Aguchi | cf910e8 | 2013-06-20 11:46:53 -0400 | [diff] [blame] | 398 | { |
| 399 | entering_irq(); |
| 400 | trace_thermal_apic_entry(THERMAL_APIC_VECTOR); |
Thomas Gleixner | 0f42ae2 | 2017-08-28 08:47:28 +0200 | [diff] [blame] | 401 | inc_irq_stat(irq_thermal_count); |
| 402 | smp_thermal_vector(); |
Seiji Aguchi | cf910e8 | 2013-06-20 11:46:53 -0400 | [diff] [blame] | 403 | trace_thermal_apic_exit(THERMAL_APIC_VECTOR); |
| 404 | exiting_ack_irq(); |
| 405 | } |
| 406 | |
Hidetoshi Seto | 70fe440 | 2009-12-14 17:57:00 +0900 | [diff] [blame] | 407 | /* Thermal monitoring depends on APIC, ACPI and clock modulation */ |
| 408 | static int intel_thermal_supported(struct cpuinfo_x86 *c) |
| 409 | { |
Borislav Petkov | 93984fb | 2016-04-04 22:25:00 +0200 | [diff] [blame] | 410 | if (!boot_cpu_has(X86_FEATURE_APIC)) |
Hidetoshi Seto | 70fe440 | 2009-12-14 17:57:00 +0900 | [diff] [blame] | 411 | return 0; |
| 412 | if (!cpu_has(c, X86_FEATURE_ACPI) || !cpu_has(c, X86_FEATURE_ACC)) |
| 413 | return 0; |
| 414 | return 1; |
| 415 | } |
| 416 | |
Yong Wang | ce6b5d7 | 2009-11-11 15:51:25 +0800 | [diff] [blame] | 417 | void __init mcheck_intel_therm_init(void) |
Yong Wang | a2202aa | 2009-11-10 09:38:24 +0800 | [diff] [blame] | 418 | { |
| 419 | /* |
| 420 | * This function is only called on boot CPU. Save the init thermal |
| 421 | * LVT value on BSP and use that value to restore APs' thermal LVT |
| 422 | * entry BIOS programmed later |
| 423 | */ |
Hidetoshi Seto | 70fe440 | 2009-12-14 17:57:00 +0900 | [diff] [blame] | 424 | if (intel_thermal_supported(&boot_cpu_data)) |
Yong Wang | a2202aa | 2009-11-10 09:38:24 +0800 | [diff] [blame] | 425 | lvtthmr_init = apic_read(APIC_LVTTHMR); |
| 426 | } |
| 427 | |
Hidetoshi Seto | cffd377 | 2009-11-12 15:52:40 +0900 | [diff] [blame] | 428 | void intel_init_thermal(struct cpuinfo_x86 *c) |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 429 | { |
| 430 | unsigned int cpu = smp_processor_id(); |
| 431 | int tm2 = 0; |
| 432 | u32 l, h; |
| 433 | |
Hidetoshi Seto | 70fe440 | 2009-12-14 17:57:00 +0900 | [diff] [blame] | 434 | if (!intel_thermal_supported(c)) |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 435 | return; |
| 436 | |
| 437 | /* |
| 438 | * First check if its enabled already, in which case there might |
| 439 | * be some SMM goo which handles it, so we can't even put a handler |
| 440 | * since it might be delivered via SMI already: |
| 441 | */ |
| 442 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); |
Yong Wang | a2202aa | 2009-11-10 09:38:24 +0800 | [diff] [blame] | 443 | |
Youquan Song | e503f9e | 2011-04-22 00:22:43 +0800 | [diff] [blame] | 444 | h = lvtthmr_init; |
Yong Wang | a2202aa | 2009-11-10 09:38:24 +0800 | [diff] [blame] | 445 | /* |
| 446 | * The initial value of thermal LVT entries on all APs always reads |
| 447 | * 0x10000 because APs are woken up by BSP issuing INIT-SIPI-SIPI |
| 448 | * sequence to them and LVT registers are reset to 0s except for |
| 449 | * the mask bits which are set to 1s when APs receive INIT IPI. |
Youquan Song | e503f9e | 2011-04-22 00:22:43 +0800 | [diff] [blame] | 450 | * If BIOS takes over the thermal interrupt and sets its interrupt |
| 451 | * delivery mode to SMI (not fixed), it restores the value that the |
| 452 | * BIOS has programmed on AP based on BSP's info we saved since BIOS |
| 453 | * is always setting the same value for all threads/cores. |
Yong Wang | a2202aa | 2009-11-10 09:38:24 +0800 | [diff] [blame] | 454 | */ |
Youquan Song | e503f9e | 2011-04-22 00:22:43 +0800 | [diff] [blame] | 455 | if ((h & APIC_DM_FIXED_MASK) != APIC_DM_FIXED) |
| 456 | apic_write(APIC_LVTTHMR, lvtthmr_init); |
Yong Wang | a2202aa | 2009-11-10 09:38:24 +0800 | [diff] [blame] | 457 | |
Yong Wang | a2202aa | 2009-11-10 09:38:24 +0800 | [diff] [blame] | 458 | |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 459 | if ((l & MSR_IA32_MISC_ENABLE_TM1) && (h & APIC_DM_SMI)) { |
Rakib Mullick | d286c3a | 2014-09-19 01:22:15 +0600 | [diff] [blame] | 460 | if (system_state == SYSTEM_BOOTING) |
Chen Yucong | 1b74dde | 2016-02-02 11:45:02 +0800 | [diff] [blame] | 461 | pr_debug("CPU%d: Thermal monitoring handled by SMI\n", cpu); |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 462 | return; |
| 463 | } |
| 464 | |
Bartlomiej Zolnierkiewicz | f3a0867 | 2009-07-29 00:04:59 +0200 | [diff] [blame] | 465 | /* early Pentium M models use different method for enabling TM2 */ |
| 466 | if (cpu_has(c, X86_FEATURE_TM2)) { |
| 467 | if (c->x86 == 6 && (c->x86_model == 9 || c->x86_model == 13)) { |
| 468 | rdmsr(MSR_THERM2_CTL, l, h); |
| 469 | if (l & MSR_THERM2_CTL_TM_SELECT) |
| 470 | tm2 = 1; |
| 471 | } else if (l & MSR_IA32_MISC_ENABLE_TM2) |
| 472 | tm2 = 1; |
| 473 | } |
| 474 | |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 475 | /* We'll mask the thermal vector in the lapic till we're ready: */ |
| 476 | h = THERMAL_APIC_VECTOR | APIC_DM_FIXED | APIC_LVT_MASKED; |
| 477 | apic_write(APIC_LVTTHMR, h); |
| 478 | |
| 479 | rdmsr(MSR_IA32_THERM_INTERRUPT, l, h); |
Fenghua Yu | 6bb2ff8 | 2013-05-21 15:35:17 -0400 | [diff] [blame] | 480 | if (cpu_has(c, X86_FEATURE_PLN) && !int_pln_enable) |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 481 | wrmsr(MSR_IA32_THERM_INTERRUPT, |
Fenghua Yu | 6bb2ff8 | 2013-05-21 15:35:17 -0400 | [diff] [blame] | 482 | (l | (THERM_INT_LOW_ENABLE |
| 483 | | THERM_INT_HIGH_ENABLE)) & ~THERM_INT_PLN_ENABLE, h); |
| 484 | else if (cpu_has(c, X86_FEATURE_PLN) && int_pln_enable) |
| 485 | wrmsr(MSR_IA32_THERM_INTERRUPT, |
| 486 | l | (THERM_INT_LOW_ENABLE |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 487 | | THERM_INT_HIGH_ENABLE | THERM_INT_PLN_ENABLE), h); |
| 488 | else |
| 489 | wrmsr(MSR_IA32_THERM_INTERRUPT, |
| 490 | l | (THERM_INT_LOW_ENABLE | THERM_INT_HIGH_ENABLE), h); |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 491 | |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 492 | if (cpu_has(c, X86_FEATURE_PTS)) { |
| 493 | rdmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, l, h); |
Fenghua Yu | 6bb2ff8 | 2013-05-21 15:35:17 -0400 | [diff] [blame] | 494 | if (cpu_has(c, X86_FEATURE_PLN) && !int_pln_enable) |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 495 | wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, |
Fenghua Yu | 6bb2ff8 | 2013-05-21 15:35:17 -0400 | [diff] [blame] | 496 | (l | (PACKAGE_THERM_INT_LOW_ENABLE |
| 497 | | PACKAGE_THERM_INT_HIGH_ENABLE)) |
| 498 | & ~PACKAGE_THERM_INT_PLN_ENABLE, h); |
| 499 | else if (cpu_has(c, X86_FEATURE_PLN) && int_pln_enable) |
| 500 | wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, |
| 501 | l | (PACKAGE_THERM_INT_LOW_ENABLE |
Fenghua Yu | 0199114 | 2010-07-29 17:13:45 -0700 | [diff] [blame] | 502 | | PACKAGE_THERM_INT_HIGH_ENABLE |
| 503 | | PACKAGE_THERM_INT_PLN_ENABLE), h); |
| 504 | else |
| 505 | wrmsr(MSR_IA32_PACKAGE_THERM_INTERRUPT, |
| 506 | l | (PACKAGE_THERM_INT_LOW_ENABLE |
| 507 | | PACKAGE_THERM_INT_HIGH_ENABLE), h); |
Fenghua Yu | 55d435a | 2010-07-29 17:13:44 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Hidetoshi Seto | 8363fc8 | 2009-06-15 17:26:36 +0900 | [diff] [blame] | 510 | smp_thermal_vector = intel_thermal_interrupt; |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 511 | |
| 512 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); |
| 513 | wrmsr(MSR_IA32_MISC_ENABLE, l | MSR_IA32_MISC_ENABLE_TM1, h); |
| 514 | |
| 515 | /* Unmask the thermal vector: */ |
| 516 | l = apic_read(APIC_LVTTHMR); |
| 517 | apic_write(APIC_LVTTHMR, l & ~APIC_LVT_MASKED); |
| 518 | |
Chen Yucong | 1b74dde | 2016-02-02 11:45:02 +0800 | [diff] [blame] | 519 | pr_info_once("CPU0: Thermal monitoring enabled (%s)\n", |
| 520 | tm2 ? "TM2" : "TM1"); |
Hidetoshi Seto | 895287c | 2009-06-15 17:26:10 +0900 | [diff] [blame] | 521 | |
| 522 | /* enable thermal throttle processing */ |
| 523 | atomic_set(&therm_throt_en, 1); |
| 524 | } |