blob: d103adc57778ce1e9aed9b8ba2f8eb86c5e69665 [file] [log] [blame]
Len Brown26717172010-03-08 14:07:30 -05001/*
2 * intel_idle.c - native hardware idle loop for modern Intel processors
3 *
Len Brownfab04b22013-11-09 00:30:17 -05004 * Copyright (c) 2013, Intel Corporation.
Len Brown26717172010-03-08 14:07:30 -05005 * Len Brown <len.brown@intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21/*
22 * intel_idle is a cpuidle driver that loads on specific Intel processors
23 * in lieu of the legacy ACPI processor_idle driver. The intent is to
24 * make Linux more efficient on these processors, as intel_idle knows
25 * more than ACPI, as well as make Linux more immune to ACPI BIOS bugs.
26 */
27
28/*
29 * Design Assumptions
30 *
31 * All CPUs have same idle states as boot CPU
32 *
33 * Chipset BM_STS (bus master status) bit is a NOP
34 * for preventing entry into deep C-stats
35 */
36
37/*
38 * Known limitations
39 *
40 * The driver currently initializes for_each_online_cpu() upon modprobe.
41 * It it unaware of subsequent processors hot-added to the system.
42 * This means that if you boot with maxcpus=n and later online
43 * processors above n, those processors will use C1 only.
44 *
45 * ACPI has a .suspend hack to turn off deep c-statees during suspend
46 * to avoid complications with the lapic timer workaround.
47 * Have not seen issues with suspend, but may need same workaround here.
48 *
49 * There is currently no kernel-based automatic probing/loading mechanism
50 * if the driver is built as a module.
51 */
52
53/* un-comment DEBUG to enable pr_debug() statements */
54#define DEBUG
55
56#include <linux/kernel.h>
57#include <linux/cpuidle.h>
Thomas Gleixner76962ca2015-04-03 02:02:34 +020058#include <linux/tick.h>
Len Brown26717172010-03-08 14:07:30 -050059#include <trace/events/power.h>
60#include <linux/sched.h>
Shaohua Li2a2d31c2011-01-10 09:38:12 +080061#include <linux/notifier.h>
62#include <linux/cpu.h>
Paul Gortmaker7c52d552011-05-27 12:33:10 -040063#include <linux/module.h>
Andi Kleenb66b8b92012-01-26 00:09:07 +010064#include <asm/cpu_device_id.h>
Dave Hansendb73c5a2016-06-02 17:19:32 -070065#include <asm/intel-family.h>
H. Peter Anvinbc83ccc2010-09-17 15:36:40 -070066#include <asm/mwait.h>
Len Brown14796fc2011-01-18 20:48:27 -050067#include <asm/msr.h>
Len Brown26717172010-03-08 14:07:30 -050068
Len Brownd70e28f2016-03-13 00:33:48 -050069#define INTEL_IDLE_VERSION "0.4.1"
Len Brown26717172010-03-08 14:07:30 -050070#define PREFIX "intel_idle: "
71
Len Brown26717172010-03-08 14:07:30 -050072static struct cpuidle_driver intel_idle_driver = {
73 .name = "intel_idle",
74 .owner = THIS_MODULE,
75};
76/* intel_idle.max_cstate=0 disables driver */
Len Brown137ecc72013-02-01 21:35:35 -050077static int max_cstate = CPUIDLE_STATE_MAX - 1;
Len Brown26717172010-03-08 14:07:30 -050078
Len Brownc4236282010-05-28 02:22:03 -040079static unsigned int mwait_substates;
Len Brown26717172010-03-08 14:07:30 -050080
Shaohua Li2a2d31c2011-01-10 09:38:12 +080081#define LAPIC_TIMER_ALWAYS_RELIABLE 0xFFFFFFFF
Len Brown26717172010-03-08 14:07:30 -050082/* Reliable LAPIC Timer States, bit 1 for C1 etc. */
Len Brownd13780d2010-07-07 00:12:03 -040083static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
Len Brown26717172010-03-08 14:07:30 -050084
Andi Kleenb66b8b92012-01-26 00:09:07 +010085struct idle_cpu {
86 struct cpuidle_state *state_table;
87
88 /*
89 * Hardware C-state auto-demotion may not always be optimal.
90 * Indicate which enable bits to clear here.
91 */
92 unsigned long auto_demotion_disable_flags;
Len Brown8c058d532014-07-31 15:21:24 -040093 bool byt_auto_demotion_disable_flag;
Len Brown32e95182013-02-02 01:31:56 -050094 bool disable_promotion_to_c1e;
Andi Kleenb66b8b92012-01-26 00:09:07 +010095};
96
97static const struct idle_cpu *icpu;
Namhyung Kim3265eba2010-08-08 03:10:03 +090098static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053099static int intel_idle(struct cpuidle_device *dev,
100 struct cpuidle_driver *drv, int index);
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100101static void intel_idle_freeze(struct cpuidle_device *dev,
102 struct cpuidle_driver *drv, int index);
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200103static int intel_idle_cpu_init(int cpu);
Len Brown26717172010-03-08 14:07:30 -0500104
105static struct cpuidle_state *cpuidle_state_table;
106
107/*
Len Brown956d0332011-01-12 02:51:20 -0500108 * Set this flag for states where the HW flushes the TLB for us
109 * and so we don't need cross-calls to keep it consistent.
110 * If this flag is set, SW flushes the TLB, so even if the
111 * HW doesn't do the flushing, this flag is safe to use.
112 */
113#define CPUIDLE_FLAG_TLB_FLUSHED 0x10000
114
115/*
Len Brownb1beab42013-01-31 19:55:37 -0500116 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
117 * the C-state (top nibble) and sub-state (bottom nibble)
118 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
119 *
120 * We store the hint at the top of our "flags" for each state.
121 */
122#define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
123#define MWAIT2flg(eax) ((eax & 0xFF) << 24)
124
125/*
Len Brown26717172010-03-08 14:07:30 -0500126 * States are indexed by the cstate number,
127 * which is also the index into the MWAIT hint array.
128 * Thus C0 is a dummy.
129 */
Jiang Liuba0dc812014-01-09 15:30:26 +0800130static struct cpuidle_state nehalem_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500131 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100132 .name = "C1-NHM",
Len Brown26717172010-03-08 14:07:30 -0500133 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100134 .flags = MWAIT2flg(0x00),
Len Brown26717172010-03-08 14:07:30 -0500135 .exit_latency = 3,
Len Brown26717172010-03-08 14:07:30 -0500136 .target_residency = 6,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100137 .enter = &intel_idle,
138 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500139 {
Len Brown32e95182013-02-02 01:31:56 -0500140 .name = "C1E-NHM",
141 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100142 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500143 .exit_latency = 10,
144 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100145 .enter = &intel_idle,
146 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500147 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100148 .name = "C3-NHM",
Len Brown26717172010-03-08 14:07:30 -0500149 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100150 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500151 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500152 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100153 .enter = &intel_idle,
154 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500155 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100156 .name = "C6-NHM",
Len Brown26717172010-03-08 14:07:30 -0500157 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100158 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500159 .exit_latency = 200,
Len Brown26717172010-03-08 14:07:30 -0500160 .target_residency = 800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100161 .enter = &intel_idle,
162 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500163 {
164 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500165};
166
Jiang Liuba0dc812014-01-09 15:30:26 +0800167static struct cpuidle_state snb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500168 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100169 .name = "C1-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400170 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100171 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500172 .exit_latency = 2,
173 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100174 .enter = &intel_idle,
175 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500176 {
177 .name = "C1E-SNB",
178 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100179 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500180 .exit_latency = 10,
181 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100182 .enter = &intel_idle,
183 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500184 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100185 .name = "C3-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400186 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100187 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400188 .exit_latency = 80,
Len Brownddbd5502010-12-13 18:28:22 -0500189 .target_residency = 211,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100190 .enter = &intel_idle,
191 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500192 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100193 .name = "C6-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400194 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100195 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400196 .exit_latency = 104,
Len Brownddbd5502010-12-13 18:28:22 -0500197 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100198 .enter = &intel_idle,
199 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500200 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100201 .name = "C7-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400202 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100203 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400204 .exit_latency = 109,
Len Brownddbd5502010-12-13 18:28:22 -0500205 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100206 .enter = &intel_idle,
207 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500208 {
209 .enter = NULL }
Len Brownd13780d2010-07-07 00:12:03 -0400210};
211
Len Brown718987d2014-02-14 02:30:00 -0500212static struct cpuidle_state byt_cstates[] = {
213 {
214 .name = "C1-BYT",
215 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100216 .flags = MWAIT2flg(0x00),
Len Brown718987d2014-02-14 02:30:00 -0500217 .exit_latency = 1,
218 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100219 .enter = &intel_idle,
220 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500221 {
Len Brown718987d2014-02-14 02:30:00 -0500222 .name = "C6N-BYT",
223 .desc = "MWAIT 0x58",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100224 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400225 .exit_latency = 300,
Len Brown718987d2014-02-14 02:30:00 -0500226 .target_residency = 275,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100227 .enter = &intel_idle,
228 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500229 {
230 .name = "C6S-BYT",
231 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100232 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400233 .exit_latency = 500,
Len Brown718987d2014-02-14 02:30:00 -0500234 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100235 .enter = &intel_idle,
236 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500237 {
238 .name = "C7-BYT",
239 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100240 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500241 .exit_latency = 1200,
Len Brownd7ef7672015-03-24 23:23:20 -0400242 .target_residency = 4000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100243 .enter = &intel_idle,
244 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500245 {
246 .name = "C7S-BYT",
247 .desc = "MWAIT 0x64",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100248 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500249 .exit_latency = 10000,
250 .target_residency = 20000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100251 .enter = &intel_idle,
252 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500253 {
254 .enter = NULL }
255};
256
Len Browncab07a52015-03-27 20:54:01 -0400257static struct cpuidle_state cht_cstates[] = {
258 {
259 .name = "C1-CHT",
260 .desc = "MWAIT 0x00",
261 .flags = MWAIT2flg(0x00),
262 .exit_latency = 1,
263 .target_residency = 1,
264 .enter = &intel_idle,
265 .enter_freeze = intel_idle_freeze, },
266 {
267 .name = "C6N-CHT",
268 .desc = "MWAIT 0x58",
269 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
270 .exit_latency = 80,
271 .target_residency = 275,
272 .enter = &intel_idle,
273 .enter_freeze = intel_idle_freeze, },
274 {
275 .name = "C6S-CHT",
276 .desc = "MWAIT 0x52",
277 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
278 .exit_latency = 200,
279 .target_residency = 560,
280 .enter = &intel_idle,
281 .enter_freeze = intel_idle_freeze, },
282 {
283 .name = "C7-CHT",
284 .desc = "MWAIT 0x60",
285 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
286 .exit_latency = 1200,
287 .target_residency = 4000,
288 .enter = &intel_idle,
289 .enter_freeze = intel_idle_freeze, },
290 {
291 .name = "C7S-CHT",
292 .desc = "MWAIT 0x64",
293 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
294 .exit_latency = 10000,
295 .target_residency = 20000,
296 .enter = &intel_idle,
297 .enter_freeze = intel_idle_freeze, },
298 {
299 .enter = NULL }
300};
301
Jiang Liuba0dc812014-01-09 15:30:26 +0800302static struct cpuidle_state ivb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500303 {
Len Brown6edab082012-06-01 19:45:32 -0400304 .name = "C1-IVB",
305 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100306 .flags = MWAIT2flg(0x00),
Len Brown6edab082012-06-01 19:45:32 -0400307 .exit_latency = 1,
308 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100309 .enter = &intel_idle,
310 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500311 {
Len Brown32e95182013-02-02 01:31:56 -0500312 .name = "C1E-IVB",
313 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100314 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500315 .exit_latency = 10,
316 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100317 .enter = &intel_idle,
318 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500319 {
Len Brown6edab082012-06-01 19:45:32 -0400320 .name = "C3-IVB",
321 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100322 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400323 .exit_latency = 59,
324 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100325 .enter = &intel_idle,
326 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500327 {
Len Brown6edab082012-06-01 19:45:32 -0400328 .name = "C6-IVB",
329 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100330 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400331 .exit_latency = 80,
332 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100333 .enter = &intel_idle,
334 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500335 {
Len Brown6edab082012-06-01 19:45:32 -0400336 .name = "C7-IVB",
337 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100338 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400339 .exit_latency = 87,
340 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100341 .enter = &intel_idle,
342 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500343 {
344 .enter = NULL }
Len Brown6edab082012-06-01 19:45:32 -0400345};
346
Len Brown0138d8f2014-04-04 01:21:07 -0400347static struct cpuidle_state ivt_cstates[] = {
348 {
349 .name = "C1-IVT",
350 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100351 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400352 .exit_latency = 1,
353 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100354 .enter = &intel_idle,
355 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400356 {
357 .name = "C1E-IVT",
358 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100359 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400360 .exit_latency = 10,
361 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100362 .enter = &intel_idle,
363 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400364 {
365 .name = "C3-IVT",
366 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100367 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400368 .exit_latency = 59,
369 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100370 .enter = &intel_idle,
371 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400372 {
373 .name = "C6-IVT",
374 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100375 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400376 .exit_latency = 82,
377 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100378 .enter = &intel_idle,
379 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400380 {
381 .enter = NULL }
382};
383
384static struct cpuidle_state ivt_cstates_4s[] = {
385 {
386 .name = "C1-IVT-4S",
387 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100388 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400389 .exit_latency = 1,
390 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100391 .enter = &intel_idle,
392 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400393 {
394 .name = "C1E-IVT-4S",
395 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100396 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400397 .exit_latency = 10,
398 .target_residency = 250,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100399 .enter = &intel_idle,
400 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400401 {
402 .name = "C3-IVT-4S",
403 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100404 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400405 .exit_latency = 59,
406 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100407 .enter = &intel_idle,
408 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400409 {
410 .name = "C6-IVT-4S",
411 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100412 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400413 .exit_latency = 84,
414 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100415 .enter = &intel_idle,
416 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400417 {
418 .enter = NULL }
419};
420
421static struct cpuidle_state ivt_cstates_8s[] = {
422 {
423 .name = "C1-IVT-8S",
424 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100425 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400426 .exit_latency = 1,
427 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100428 .enter = &intel_idle,
429 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400430 {
431 .name = "C1E-IVT-8S",
432 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100433 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400434 .exit_latency = 10,
435 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100436 .enter = &intel_idle,
437 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400438 {
439 .name = "C3-IVT-8S",
440 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100441 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400442 .exit_latency = 59,
443 .target_residency = 600,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100444 .enter = &intel_idle,
445 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400446 {
447 .name = "C6-IVT-8S",
448 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100449 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400450 .exit_latency = 88,
451 .target_residency = 700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100452 .enter = &intel_idle,
453 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400454 {
455 .enter = NULL }
456};
457
Jiang Liuba0dc812014-01-09 15:30:26 +0800458static struct cpuidle_state hsw_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500459 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500460 .name = "C1-HSW",
461 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100462 .flags = MWAIT2flg(0x00),
Len Brown85a4d2d2013-01-31 14:40:49 -0500463 .exit_latency = 2,
464 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100465 .enter = &intel_idle,
466 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500467 {
Len Brown32e95182013-02-02 01:31:56 -0500468 .name = "C1E-HSW",
469 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100470 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500471 .exit_latency = 10,
472 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100473 .enter = &intel_idle,
474 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500475 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500476 .name = "C3-HSW",
477 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100478 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500479 .exit_latency = 33,
480 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100481 .enter = &intel_idle,
482 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500483 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500484 .name = "C6-HSW",
485 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100486 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500487 .exit_latency = 133,
488 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100489 .enter = &intel_idle,
490 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500491 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500492 .name = "C7s-HSW",
493 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100494 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500495 .exit_latency = 166,
496 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100497 .enter = &intel_idle,
498 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500499 {
Len Brown86239ce2013-02-27 13:18:50 -0500500 .name = "C8-HSW",
501 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100502 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500503 .exit_latency = 300,
504 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100505 .enter = &intel_idle,
506 .enter_freeze = intel_idle_freeze, },
Len Brown86239ce2013-02-27 13:18:50 -0500507 {
508 .name = "C9-HSW",
509 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100510 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500511 .exit_latency = 600,
512 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100513 .enter = &intel_idle,
514 .enter_freeze = intel_idle_freeze, },
Len Brown86239ce2013-02-27 13:18:50 -0500515 {
516 .name = "C10-HSW",
517 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100518 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500519 .exit_latency = 2600,
520 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100521 .enter = &intel_idle,
522 .enter_freeze = intel_idle_freeze, },
Len Brown86239ce2013-02-27 13:18:50 -0500523 {
Len Browne022e7e2013-02-01 23:37:30 -0500524 .enter = NULL }
Len Brown85a4d2d2013-01-31 14:40:49 -0500525};
Len Browna138b562014-02-04 23:56:40 -0500526static struct cpuidle_state bdw_cstates[] = {
527 {
528 .name = "C1-BDW",
529 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100530 .flags = MWAIT2flg(0x00),
Len Browna138b562014-02-04 23:56:40 -0500531 .exit_latency = 2,
532 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100533 .enter = &intel_idle,
534 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500535 {
536 .name = "C1E-BDW",
537 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100538 .flags = MWAIT2flg(0x01),
Len Browna138b562014-02-04 23:56:40 -0500539 .exit_latency = 10,
540 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100541 .enter = &intel_idle,
542 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500543 {
544 .name = "C3-BDW",
545 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100546 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500547 .exit_latency = 40,
548 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100549 .enter = &intel_idle,
550 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500551 {
552 .name = "C6-BDW",
553 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100554 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500555 .exit_latency = 133,
556 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100557 .enter = &intel_idle,
558 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500559 {
560 .name = "C7s-BDW",
561 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100562 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500563 .exit_latency = 166,
564 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100565 .enter = &intel_idle,
566 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500567 {
568 .name = "C8-BDW",
569 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100570 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500571 .exit_latency = 300,
572 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100573 .enter = &intel_idle,
574 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500575 {
576 .name = "C9-BDW",
577 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100578 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500579 .exit_latency = 600,
580 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100581 .enter = &intel_idle,
582 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500583 {
584 .name = "C10-BDW",
585 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100586 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500587 .exit_latency = 2600,
588 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100589 .enter = &intel_idle,
590 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500591 {
592 .enter = NULL }
593};
Len Brown85a4d2d2013-01-31 14:40:49 -0500594
Len Brown493f1332015-03-25 23:20:37 -0400595static struct cpuidle_state skl_cstates[] = {
596 {
597 .name = "C1-SKL",
598 .desc = "MWAIT 0x00",
599 .flags = MWAIT2flg(0x00),
600 .exit_latency = 2,
601 .target_residency = 2,
602 .enter = &intel_idle,
603 .enter_freeze = intel_idle_freeze, },
604 {
605 .name = "C1E-SKL",
606 .desc = "MWAIT 0x01",
607 .flags = MWAIT2flg(0x01),
608 .exit_latency = 10,
609 .target_residency = 20,
610 .enter = &intel_idle,
611 .enter_freeze = intel_idle_freeze, },
612 {
613 .name = "C3-SKL",
614 .desc = "MWAIT 0x10",
615 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
616 .exit_latency = 70,
617 .target_residency = 100,
618 .enter = &intel_idle,
619 .enter_freeze = intel_idle_freeze, },
620 {
621 .name = "C6-SKL",
622 .desc = "MWAIT 0x20",
623 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400624 .exit_latency = 85,
Len Brown493f1332015-03-25 23:20:37 -0400625 .target_residency = 200,
626 .enter = &intel_idle,
627 .enter_freeze = intel_idle_freeze, },
628 {
629 .name = "C7s-SKL",
630 .desc = "MWAIT 0x33",
631 .flags = MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED,
632 .exit_latency = 124,
633 .target_residency = 800,
634 .enter = &intel_idle,
635 .enter_freeze = intel_idle_freeze, },
636 {
637 .name = "C8-SKL",
638 .desc = "MWAIT 0x40",
639 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400640 .exit_latency = 200,
Len Brown493f1332015-03-25 23:20:37 -0400641 .target_residency = 800,
642 .enter = &intel_idle,
643 .enter_freeze = intel_idle_freeze, },
644 {
Len Brown135919a2015-09-09 13:35:05 -0400645 .name = "C9-SKL",
646 .desc = "MWAIT 0x50",
647 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
648 .exit_latency = 480,
649 .target_residency = 5000,
650 .enter = &intel_idle,
651 .enter_freeze = intel_idle_freeze, },
652 {
Len Brown493f1332015-03-25 23:20:37 -0400653 .name = "C10-SKL",
654 .desc = "MWAIT 0x60",
655 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
656 .exit_latency = 890,
657 .target_residency = 5000,
658 .enter = &intel_idle,
659 .enter_freeze = intel_idle_freeze, },
660 {
661 .enter = NULL }
662};
663
Len Brownf9e71652016-04-06 17:00:58 -0400664static struct cpuidle_state skx_cstates[] = {
665 {
666 .name = "C1-SKX",
667 .desc = "MWAIT 0x00",
668 .flags = MWAIT2flg(0x00),
669 .exit_latency = 2,
670 .target_residency = 2,
671 .enter = &intel_idle,
672 .enter_freeze = intel_idle_freeze, },
673 {
674 .name = "C1E-SKX",
675 .desc = "MWAIT 0x01",
676 .flags = MWAIT2flg(0x01),
677 .exit_latency = 10,
678 .target_residency = 20,
679 .enter = &intel_idle,
680 .enter_freeze = intel_idle_freeze, },
681 {
682 .name = "C6-SKX",
683 .desc = "MWAIT 0x20",
684 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
685 .exit_latency = 133,
686 .target_residency = 600,
687 .enter = &intel_idle,
688 .enter_freeze = intel_idle_freeze, },
689 {
690 .enter = NULL }
691};
692
Jiang Liuba0dc812014-01-09 15:30:26 +0800693static struct cpuidle_state atom_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500694 {
Len Brown32e95182013-02-02 01:31:56 -0500695 .name = "C1E-ATM",
Len Brown26717172010-03-08 14:07:30 -0500696 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100697 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500698 .exit_latency = 10,
699 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100700 .enter = &intel_idle,
701 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500702 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100703 .name = "C2-ATM",
Len Brown26717172010-03-08 14:07:30 -0500704 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100705 .flags = MWAIT2flg(0x10),
Len Brown26717172010-03-08 14:07:30 -0500706 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500707 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100708 .enter = &intel_idle,
709 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500710 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100711 .name = "C4-ATM",
Len Brown26717172010-03-08 14:07:30 -0500712 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100713 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500714 .exit_latency = 100,
Len Brown26717172010-03-08 14:07:30 -0500715 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100716 .enter = &intel_idle,
717 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500718 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100719 .name = "C6-ATM",
Len Brown7fcca7d2010-10-05 13:43:14 -0400720 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100721 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown7fcca7d2010-10-05 13:43:14 -0400722 .exit_latency = 140,
Len Brown7fcca7d2010-10-05 13:43:14 -0400723 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100724 .enter = &intel_idle,
725 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500726 {
727 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500728};
Jiang Liu88390992014-01-09 15:30:27 +0800729static struct cpuidle_state avn_cstates[] = {
Len Brownfab04b22013-11-09 00:30:17 -0500730 {
731 .name = "C1-AVN",
732 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100733 .flags = MWAIT2flg(0x00),
Len Brownfab04b22013-11-09 00:30:17 -0500734 .exit_latency = 2,
735 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100736 .enter = &intel_idle,
737 .enter_freeze = intel_idle_freeze, },
Len Brownfab04b22013-11-09 00:30:17 -0500738 {
739 .name = "C6-AVN",
740 .desc = "MWAIT 0x51",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100741 .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownfab04b22013-11-09 00:30:17 -0500742 .exit_latency = 15,
743 .target_residency = 45,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100744 .enter = &intel_idle,
745 .enter_freeze = intel_idle_freeze, },
Jiang Liu88390992014-01-09 15:30:27 +0800746 {
747 .enter = NULL }
Len Brownfab04b22013-11-09 00:30:17 -0500748};
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700749static struct cpuidle_state knl_cstates[] = {
750 {
751 .name = "C1-KNL",
752 .desc = "MWAIT 0x00",
753 .flags = MWAIT2flg(0x00),
754 .exit_latency = 1,
755 .target_residency = 2,
756 .enter = &intel_idle,
757 .enter_freeze = intel_idle_freeze },
758 {
759 .name = "C6-KNL",
760 .desc = "MWAIT 0x10",
761 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
762 .exit_latency = 120,
763 .target_residency = 500,
764 .enter = &intel_idle,
765 .enter_freeze = intel_idle_freeze },
766 {
767 .enter = NULL }
768};
Len Brown26717172010-03-08 14:07:30 -0500769
Len Brown5dcef692016-04-06 17:00:47 -0400770static struct cpuidle_state bxt_cstates[] = {
771 {
772 .name = "C1-BXT",
773 .desc = "MWAIT 0x00",
774 .flags = MWAIT2flg(0x00),
775 .exit_latency = 2,
776 .target_residency = 2,
777 .enter = &intel_idle,
778 .enter_freeze = intel_idle_freeze, },
779 {
780 .name = "C1E-BXT",
781 .desc = "MWAIT 0x01",
782 .flags = MWAIT2flg(0x01),
783 .exit_latency = 10,
784 .target_residency = 20,
785 .enter = &intel_idle,
786 .enter_freeze = intel_idle_freeze, },
787 {
788 .name = "C6-BXT",
789 .desc = "MWAIT 0x20",
790 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
791 .exit_latency = 133,
792 .target_residency = 133,
793 .enter = &intel_idle,
794 .enter_freeze = intel_idle_freeze, },
795 {
796 .name = "C7s-BXT",
797 .desc = "MWAIT 0x31",
798 .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
799 .exit_latency = 155,
800 .target_residency = 155,
801 .enter = &intel_idle,
802 .enter_freeze = intel_idle_freeze, },
803 {
804 .name = "C8-BXT",
805 .desc = "MWAIT 0x40",
806 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
807 .exit_latency = 1000,
808 .target_residency = 1000,
809 .enter = &intel_idle,
810 .enter_freeze = intel_idle_freeze, },
811 {
812 .name = "C9-BXT",
813 .desc = "MWAIT 0x50",
814 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
815 .exit_latency = 2000,
816 .target_residency = 2000,
817 .enter = &intel_idle,
818 .enter_freeze = intel_idle_freeze, },
819 {
820 .name = "C10-BXT",
821 .desc = "MWAIT 0x60",
822 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
823 .exit_latency = 10000,
824 .target_residency = 10000,
825 .enter = &intel_idle,
826 .enter_freeze = intel_idle_freeze, },
827 {
828 .enter = NULL }
829};
830
Len Brown26717172010-03-08 14:07:30 -0500831/**
832 * intel_idle
833 * @dev: cpuidle_device
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530834 * @drv: cpuidle driver
Deepthi Dharware978aa72011-10-28 16:20:09 +0530835 * @index: index of cpuidle state
Len Brown26717172010-03-08 14:07:30 -0500836 *
Yanmin Zhang63ff07b2012-01-10 15:48:21 -0800837 * Must be called under local_irq_disable().
Len Brown26717172010-03-08 14:07:30 -0500838 */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530839static int intel_idle(struct cpuidle_device *dev,
840 struct cpuidle_driver *drv, int index)
Len Brown26717172010-03-08 14:07:30 -0500841{
842 unsigned long ecx = 1; /* break on interrupt flag */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530843 struct cpuidle_state *state = &drv->states[index];
Len Brownb1beab42013-01-31 19:55:37 -0500844 unsigned long eax = flg2MWAIT(state->flags);
Len Brown26717172010-03-08 14:07:30 -0500845 unsigned int cstate;
Len Brown26717172010-03-08 14:07:30 -0500846 int cpu = smp_processor_id();
847
848 cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) + 1;
849
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400850 /*
Len Brownc8381cc2010-10-15 20:43:06 -0400851 * leave_mm() to avoid costly and often unnecessary wakeups
852 * for flushing the user TLB's associated with the active mm.
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400853 */
Len Brownc8381cc2010-10-15 20:43:06 -0400854 if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400855 leave_mm(cpu);
856
Len Brown26717172010-03-08 14:07:30 -0500857 if (!(lapic_timer_reliable_states & (1 << (cstate))))
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200858 tick_broadcast_enter();
Len Brown26717172010-03-08 14:07:30 -0500859
Peter Zijlstra16824252013-12-12 15:08:36 +0100860 mwait_idle_with_hints(eax, ecx);
Len Brown26717172010-03-08 14:07:30 -0500861
Len Brown26717172010-03-08 14:07:30 -0500862 if (!(lapic_timer_reliable_states & (1 << (cstate))))
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200863 tick_broadcast_exit();
Len Brown26717172010-03-08 14:07:30 -0500864
Deepthi Dharware978aa72011-10-28 16:20:09 +0530865 return index;
Len Brown26717172010-03-08 14:07:30 -0500866}
867
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100868/**
869 * intel_idle_freeze - simplified "enter" callback routine for suspend-to-idle
870 * @dev: cpuidle_device
871 * @drv: cpuidle driver
872 * @index: state index
873 */
874static void intel_idle_freeze(struct cpuidle_device *dev,
875 struct cpuidle_driver *drv, int index)
876{
877 unsigned long ecx = 1; /* break on interrupt flag */
878 unsigned long eax = flg2MWAIT(drv->states[index].flags);
879
880 mwait_idle_with_hints(eax, ecx);
881}
882
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800883static void __setup_broadcast_timer(void *arg)
884{
Thomas Gleixner76962ca2015-04-03 02:02:34 +0200885 unsigned long on = (unsigned long)arg;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800886
Thomas Gleixner76962ca2015-04-03 02:02:34 +0200887 if (on)
888 tick_broadcast_enable();
889 else
890 tick_broadcast_disable();
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800891}
892
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200893static int cpu_hotplug_notify(struct notifier_block *n,
894 unsigned long action, void *hcpu)
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800895{
896 int hotcpu = (unsigned long)hcpu;
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200897 struct cpuidle_device *dev;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800898
Prarit Bhargavae2401452013-10-23 09:44:51 -0400899 switch (action & ~CPU_TASKS_FROZEN) {
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800900 case CPU_ONLINE:
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200901
902 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
903 smp_call_function_single(hotcpu, __setup_broadcast_timer,
904 (void *)true, 1);
905
906 /*
907 * Some systems can hotplug a cpu at runtime after
908 * the kernel has booted, we have to initialize the
909 * driver in this case
910 */
911 dev = per_cpu_ptr(intel_idle_cpuidle_devices, hotcpu);
Richard Cochran08820542016-04-06 17:00:56 -0400912 if (dev->registered)
913 break;
914
915 if (intel_idle_cpu_init(hotcpu))
916 return NOTIFY_BAD;
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200917
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800918 break;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800919 }
920 return NOTIFY_OK;
921}
922
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200923static struct notifier_block cpu_hotplug_notifier = {
924 .notifier_call = cpu_hotplug_notify,
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800925};
926
Len Brown14796fc2011-01-18 20:48:27 -0500927static void auto_demotion_disable(void *dummy)
928{
929 unsigned long long msr_bits;
930
931 rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
Andi Kleenb66b8b92012-01-26 00:09:07 +0100932 msr_bits &= ~(icpu->auto_demotion_disable_flags);
Len Brown14796fc2011-01-18 20:48:27 -0500933 wrmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
934}
Len Brown32e95182013-02-02 01:31:56 -0500935static void c1e_promotion_disable(void *dummy)
936{
937 unsigned long long msr_bits;
938
939 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
940 msr_bits &= ~0x2;
941 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
942}
Len Brown14796fc2011-01-18 20:48:27 -0500943
Andi Kleenb66b8b92012-01-26 00:09:07 +0100944static const struct idle_cpu idle_cpu_nehalem = {
945 .state_table = nehalem_cstates,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100946 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
Len Brown32e95182013-02-02 01:31:56 -0500947 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100948};
949
950static const struct idle_cpu idle_cpu_atom = {
951 .state_table = atom_cstates,
952};
953
954static const struct idle_cpu idle_cpu_lincroft = {
955 .state_table = atom_cstates,
956 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
957};
958
959static const struct idle_cpu idle_cpu_snb = {
960 .state_table = snb_cstates,
Len Brown32e95182013-02-02 01:31:56 -0500961 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100962};
963
Len Brown718987d2014-02-14 02:30:00 -0500964static const struct idle_cpu idle_cpu_byt = {
965 .state_table = byt_cstates,
966 .disable_promotion_to_c1e = true,
Len Brown8c058d532014-07-31 15:21:24 -0400967 .byt_auto_demotion_disable_flag = true,
Len Brown718987d2014-02-14 02:30:00 -0500968};
969
Len Browncab07a52015-03-27 20:54:01 -0400970static const struct idle_cpu idle_cpu_cht = {
971 .state_table = cht_cstates,
972 .disable_promotion_to_c1e = true,
973 .byt_auto_demotion_disable_flag = true,
974};
975
Len Brown6edab082012-06-01 19:45:32 -0400976static const struct idle_cpu idle_cpu_ivb = {
977 .state_table = ivb_cstates,
Len Brown32e95182013-02-02 01:31:56 -0500978 .disable_promotion_to_c1e = true,
Len Brown6edab082012-06-01 19:45:32 -0400979};
980
Len Brown0138d8f2014-04-04 01:21:07 -0400981static const struct idle_cpu idle_cpu_ivt = {
982 .state_table = ivt_cstates,
983 .disable_promotion_to_c1e = true,
984};
985
Len Brown85a4d2d2013-01-31 14:40:49 -0500986static const struct idle_cpu idle_cpu_hsw = {
987 .state_table = hsw_cstates,
Len Brown32e95182013-02-02 01:31:56 -0500988 .disable_promotion_to_c1e = true,
Len Brown85a4d2d2013-01-31 14:40:49 -0500989};
990
Len Browna138b562014-02-04 23:56:40 -0500991static const struct idle_cpu idle_cpu_bdw = {
992 .state_table = bdw_cstates,
993 .disable_promotion_to_c1e = true,
994};
995
Len Brown493f1332015-03-25 23:20:37 -0400996static const struct idle_cpu idle_cpu_skl = {
997 .state_table = skl_cstates,
998 .disable_promotion_to_c1e = true,
999};
1000
Len Brownf9e71652016-04-06 17:00:58 -04001001static const struct idle_cpu idle_cpu_skx = {
1002 .state_table = skx_cstates,
1003 .disable_promotion_to_c1e = true,
1004};
Len Brown493f1332015-03-25 23:20:37 -04001005
Len Brownfab04b22013-11-09 00:30:17 -05001006static const struct idle_cpu idle_cpu_avn = {
1007 .state_table = avn_cstates,
1008 .disable_promotion_to_c1e = true,
1009};
1010
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001011static const struct idle_cpu idle_cpu_knl = {
1012 .state_table = knl_cstates,
1013};
1014
Len Brown5dcef692016-04-06 17:00:47 -04001015static const struct idle_cpu idle_cpu_bxt = {
1016 .state_table = bxt_cstates,
1017 .disable_promotion_to_c1e = true,
1018};
1019
Andi Kleenb66b8b92012-01-26 00:09:07 +01001020#define ICPU(model, cpu) \
1021 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&cpu }
1022
Mathias Kraused5cdc3c2015-03-25 22:15:14 +01001023static const struct x86_cpu_id intel_idle_ids[] __initconst = {
Dave Hansendb73c5a2016-06-02 17:19:32 -07001024 ICPU(INTEL_FAM6_NEHALEM_EP, idle_cpu_nehalem),
1025 ICPU(INTEL_FAM6_NEHALEM, idle_cpu_nehalem),
Dave Hansen4b3b2342016-06-29 12:27:37 -07001026 ICPU(INTEL_FAM6_NEHALEM_G, idle_cpu_nehalem),
Dave Hansendb73c5a2016-06-02 17:19:32 -07001027 ICPU(INTEL_FAM6_WESTMERE, idle_cpu_nehalem),
1028 ICPU(INTEL_FAM6_WESTMERE_EP, idle_cpu_nehalem),
1029 ICPU(INTEL_FAM6_NEHALEM_EX, idle_cpu_nehalem),
1030 ICPU(INTEL_FAM6_ATOM_PINEVIEW, idle_cpu_atom),
1031 ICPU(INTEL_FAM6_ATOM_LINCROFT, idle_cpu_lincroft),
1032 ICPU(INTEL_FAM6_WESTMERE_EX, idle_cpu_nehalem),
1033 ICPU(INTEL_FAM6_SANDYBRIDGE, idle_cpu_snb),
1034 ICPU(INTEL_FAM6_SANDYBRIDGE_X, idle_cpu_snb),
1035 ICPU(INTEL_FAM6_ATOM_CEDARVIEW, idle_cpu_atom),
1036 ICPU(INTEL_FAM6_ATOM_SILVERMONT1, idle_cpu_byt),
1037 ICPU(INTEL_FAM6_ATOM_AIRMONT, idle_cpu_cht),
1038 ICPU(INTEL_FAM6_IVYBRIDGE, idle_cpu_ivb),
1039 ICPU(INTEL_FAM6_IVYBRIDGE_X, idle_cpu_ivt),
1040 ICPU(INTEL_FAM6_HASWELL_CORE, idle_cpu_hsw),
1041 ICPU(INTEL_FAM6_HASWELL_X, idle_cpu_hsw),
1042 ICPU(INTEL_FAM6_HASWELL_ULT, idle_cpu_hsw),
1043 ICPU(INTEL_FAM6_HASWELL_GT3E, idle_cpu_hsw),
1044 ICPU(INTEL_FAM6_ATOM_SILVERMONT2, idle_cpu_avn),
1045 ICPU(INTEL_FAM6_BROADWELL_CORE, idle_cpu_bdw),
1046 ICPU(INTEL_FAM6_BROADWELL_GT3E, idle_cpu_bdw),
1047 ICPU(INTEL_FAM6_BROADWELL_X, idle_cpu_bdw),
1048 ICPU(INTEL_FAM6_BROADWELL_XEON_D, idle_cpu_bdw),
1049 ICPU(INTEL_FAM6_SKYLAKE_MOBILE, idle_cpu_skl),
1050 ICPU(INTEL_FAM6_SKYLAKE_DESKTOP, idle_cpu_skl),
1051 ICPU(INTEL_FAM6_KABYLAKE_MOBILE, idle_cpu_skl),
1052 ICPU(INTEL_FAM6_KABYLAKE_DESKTOP, idle_cpu_skl),
1053 ICPU(INTEL_FAM6_SKYLAKE_X, idle_cpu_skx),
1054 ICPU(INTEL_FAM6_XEON_PHI_KNL, idle_cpu_knl),
1055 ICPU(INTEL_FAM6_ATOM_GOLDMONT, idle_cpu_bxt),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001056 {}
1057};
1058MODULE_DEVICE_TABLE(x86cpu, intel_idle_ids);
1059
Len Brown26717172010-03-08 14:07:30 -05001060/*
1061 * intel_idle_probe()
1062 */
Bartlomiej Zolnierkiewicz00f3e752013-08-30 12:27:45 +02001063static int __init intel_idle_probe(void)
Len Brown26717172010-03-08 14:07:30 -05001064{
Len Brownc4236282010-05-28 02:22:03 -04001065 unsigned int eax, ebx, ecx;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001066 const struct x86_cpu_id *id;
Len Brown26717172010-03-08 14:07:30 -05001067
1068 if (max_cstate == 0) {
1069 pr_debug(PREFIX "disabled\n");
1070 return -EPERM;
1071 }
1072
Andi Kleenb66b8b92012-01-26 00:09:07 +01001073 id = x86_match_cpu(intel_idle_ids);
1074 if (!id) {
1075 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
1076 boot_cpu_data.x86 == 6)
1077 pr_debug(PREFIX "does not run on family %d model %d\n",
1078 boot_cpu_data.x86, boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001079 return -ENODEV;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001080 }
Len Brown26717172010-03-08 14:07:30 -05001081
1082 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
1083 return -ENODEV;
1084
Len Brownc4236282010-05-28 02:22:03 -04001085 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001086
1087 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
Thomas Renninger5c2a9f02011-12-04 22:17:29 +01001088 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
1089 !mwait_substates)
Len Brown26717172010-03-08 14:07:30 -05001090 return -ENODEV;
Len Brown26717172010-03-08 14:07:30 -05001091
Len Brownc4236282010-05-28 02:22:03 -04001092 pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001093
Andi Kleenb66b8b92012-01-26 00:09:07 +01001094 icpu = (const struct idle_cpu *)id->driver_data;
1095 cpuidle_state_table = icpu->state_table;
Len Brown26717172010-03-08 14:07:30 -05001096
1097 pr_debug(PREFIX "v" INTEL_IDLE_VERSION
1098 " model 0x%X\n", boot_cpu_data.x86_model);
1099
Len Brown26717172010-03-08 14:07:30 -05001100 return 0;
1101}
1102
1103/*
1104 * intel_idle_cpuidle_devices_uninit()
Richard Cochranca424892016-04-06 17:00:53 -04001105 * Unregisters the cpuidle devices.
Len Brown26717172010-03-08 14:07:30 -05001106 */
1107static void intel_idle_cpuidle_devices_uninit(void)
1108{
1109 int i;
1110 struct cpuidle_device *dev;
1111
1112 for_each_online_cpu(i) {
1113 dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
1114 cpuidle_unregister_device(dev);
1115 }
Len Brown26717172010-03-08 14:07:30 -05001116}
Len Brown0138d8f2014-04-04 01:21:07 -04001117
1118/*
Len Brownd70e28f2016-03-13 00:33:48 -05001119 * ivt_idle_state_table_update(void)
1120 *
1121 * Tune IVT multi-socket targets
1122 * Assumption: num_sockets == (max_package_num + 1)
1123 */
1124static void ivt_idle_state_table_update(void)
1125{
1126 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1127 int cpu, package_num, num_sockets = 1;
1128
1129 for_each_online_cpu(cpu) {
1130 package_num = topology_physical_package_id(cpu);
1131 if (package_num + 1 > num_sockets) {
1132 num_sockets = package_num + 1;
1133
1134 if (num_sockets > 4) {
1135 cpuidle_state_table = ivt_cstates_8s;
1136 return;
1137 }
1138 }
1139 }
1140
1141 if (num_sockets > 2)
1142 cpuidle_state_table = ivt_cstates_4s;
1143
1144 /* else, 1 and 2 socket systems use default ivt_cstates */
1145}
Len Brown5dcef692016-04-06 17:00:47 -04001146
1147/*
1148 * Translate IRTL (Interrupt Response Time Limit) MSR to usec
1149 */
1150
1151static unsigned int irtl_ns_units[] = {
1152 1, 32, 1024, 32768, 1048576, 33554432, 0, 0 };
1153
1154static unsigned long long irtl_2_usec(unsigned long long irtl)
1155{
1156 unsigned long long ns;
1157
1158 ns = irtl_ns_units[(irtl >> 10) & 0x3];
1159
1160 return div64_u64((irtl & 0x3FF) * ns, 1000);
1161}
1162/*
1163 * bxt_idle_state_table_update(void)
1164 *
1165 * On BXT, we trust the IRTL to show the definitive maximum latency
1166 * We use the same value for target_residency.
1167 */
1168static void bxt_idle_state_table_update(void)
1169{
1170 unsigned long long msr;
1171
1172 rdmsrl(MSR_PKGC6_IRTL, msr);
1173 if (msr) {
1174 unsigned int usec = irtl_2_usec(msr);
1175
1176 bxt_cstates[2].exit_latency = usec;
1177 bxt_cstates[2].target_residency = usec;
1178 }
1179
1180 rdmsrl(MSR_PKGC7_IRTL, msr);
1181 if (msr) {
1182 unsigned int usec = irtl_2_usec(msr);
1183
1184 bxt_cstates[3].exit_latency = usec;
1185 bxt_cstates[3].target_residency = usec;
1186 }
1187
1188 rdmsrl(MSR_PKGC8_IRTL, msr);
1189 if (msr) {
1190 unsigned int usec = irtl_2_usec(msr);
1191
1192 bxt_cstates[4].exit_latency = usec;
1193 bxt_cstates[4].target_residency = usec;
1194 }
1195
1196 rdmsrl(MSR_PKGC9_IRTL, msr);
1197 if (msr) {
1198 unsigned int usec = irtl_2_usec(msr);
1199
1200 bxt_cstates[5].exit_latency = usec;
1201 bxt_cstates[5].target_residency = usec;
1202 }
1203
1204 rdmsrl(MSR_PKGC10_IRTL, msr);
1205 if (msr) {
1206 unsigned int usec = irtl_2_usec(msr);
1207
1208 bxt_cstates[6].exit_latency = usec;
1209 bxt_cstates[6].target_residency = usec;
1210 }
1211
1212}
Len Brownd70e28f2016-03-13 00:33:48 -05001213/*
1214 * sklh_idle_state_table_update(void)
1215 *
1216 * On SKL-H (model 0x5e) disable C8 and C9 if:
1217 * C10 is enabled and SGX disabled
1218 */
1219static void sklh_idle_state_table_update(void)
1220{
1221 unsigned long long msr;
1222 unsigned int eax, ebx, ecx, edx;
1223
1224
1225 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1226 if (max_cstate <= 7)
1227 return;
1228
1229 /* if PC10 not present in CPUID.MWAIT.EDX */
1230 if ((mwait_substates & (0xF << 28)) == 0)
1231 return;
1232
1233 rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr);
1234
1235 /* PC10 is not enabled in PKG C-state limit */
1236 if ((msr & 0xF) != 8)
1237 return;
1238
1239 ecx = 0;
1240 cpuid(7, &eax, &ebx, &ecx, &edx);
1241
1242 /* if SGX is present */
1243 if (ebx & (1 << 2)) {
1244
1245 rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
1246
1247 /* if SGX is enabled */
1248 if (msr & (1 << 18))
1249 return;
1250 }
1251
1252 skl_cstates[5].disabled = 1; /* C8-SKL */
1253 skl_cstates[6].disabled = 1; /* C9-SKL */
1254}
1255/*
Len Brown0138d8f2014-04-04 01:21:07 -04001256 * intel_idle_state_table_update()
1257 *
1258 * Update the default state_table for this CPU-id
Len Brown0138d8f2014-04-04 01:21:07 -04001259 */
Len Brownd70e28f2016-03-13 00:33:48 -05001260
1261static void intel_idle_state_table_update(void)
Len Brown0138d8f2014-04-04 01:21:07 -04001262{
Len Brownd70e28f2016-03-13 00:33:48 -05001263 switch (boot_cpu_data.x86_model) {
Len Brown0138d8f2014-04-04 01:21:07 -04001264
Dave Hansendb73c5a2016-06-02 17:19:32 -07001265 case INTEL_FAM6_IVYBRIDGE_X:
Len Brownd70e28f2016-03-13 00:33:48 -05001266 ivt_idle_state_table_update();
1267 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001268 case INTEL_FAM6_ATOM_GOLDMONT:
Len Brown5dcef692016-04-06 17:00:47 -04001269 bxt_idle_state_table_update();
1270 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001271 case INTEL_FAM6_SKYLAKE_DESKTOP:
Len Brownd70e28f2016-03-13 00:33:48 -05001272 sklh_idle_state_table_update();
1273 break;
Len Brown0138d8f2014-04-04 01:21:07 -04001274 }
Len Brown0138d8f2014-04-04 01:21:07 -04001275}
1276
Len Brown26717172010-03-08 14:07:30 -05001277/*
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301278 * intel_idle_cpuidle_driver_init()
1279 * allocate, initialize cpuidle_states
1280 */
Richard Cochran5469c822016-04-06 17:00:49 -04001281static void __init intel_idle_cpuidle_driver_init(void)
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301282{
1283 int cstate;
1284 struct cpuidle_driver *drv = &intel_idle_driver;
1285
Len Brown0138d8f2014-04-04 01:21:07 -04001286 intel_idle_state_table_update();
1287
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301288 drv->state_count = 1;
1289
Len Browne022e7e2013-02-01 23:37:30 -05001290 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
Len Brown24bfa952014-02-14 00:50:34 -05001291 int num_substates, mwait_hint, mwait_cstate;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301292
Len Brown7dd0e0a2015-05-27 17:11:37 -04001293 if ((cpuidle_state_table[cstate].enter == NULL) &&
1294 (cpuidle_state_table[cstate].enter_freeze == NULL))
Len Browne022e7e2013-02-01 23:37:30 -05001295 break;
1296
1297 if (cstate + 1 > max_cstate) {
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301298 printk(PREFIX "max_cstate %d reached\n",
1299 max_cstate);
1300 break;
1301 }
1302
Len Browne022e7e2013-02-01 23:37:30 -05001303 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
1304 mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301305
Len Brown24bfa952014-02-14 00:50:34 -05001306 /* number of sub-states for this state in CPUID.MWAIT */
Len Browne022e7e2013-02-01 23:37:30 -05001307 num_substates = (mwait_substates >> ((mwait_cstate + 1) * 4))
1308 & MWAIT_SUBSTATE_MASK;
1309
Len Brown24bfa952014-02-14 00:50:34 -05001310 /* if NO sub-states for this state in CPUID, skip it */
1311 if (num_substates == 0)
Len Browne022e7e2013-02-01 23:37:30 -05001312 continue;
1313
Len Brownd70e28f2016-03-13 00:33:48 -05001314 /* if state marked as disabled, skip it */
1315 if (cpuidle_state_table[cstate].disabled != 0) {
1316 pr_debug(PREFIX "state %s is disabled",
1317 cpuidle_state_table[cstate].name);
1318 continue;
1319 }
1320
1321
Len Browne022e7e2013-02-01 23:37:30 -05001322 if (((mwait_cstate + 1) > 2) &&
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301323 !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
1324 mark_tsc_unstable("TSC halts in idle"
1325 " states deeper than C2");
1326
1327 drv->states[drv->state_count] = /* structure copy */
1328 cpuidle_state_table[cstate];
1329
1330 drv->state_count += 1;
1331 }
1332
Len Brown8c058d532014-07-31 15:21:24 -04001333 if (icpu->byt_auto_demotion_disable_flag) {
1334 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
1335 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
1336 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301337}
1338
1339
1340/*
Thomas Renninger65b7f832012-01-17 22:40:08 +01001341 * intel_idle_cpu_init()
Len Brown26717172010-03-08 14:07:30 -05001342 * allocate, initialize, register cpuidle_devices
Thomas Renninger65b7f832012-01-17 22:40:08 +01001343 * @cpu: cpu/core to initialize
Len Brown26717172010-03-08 14:07:30 -05001344 */
Daniel Lezcano25ac7762012-07-05 15:23:25 +02001345static int intel_idle_cpu_init(int cpu)
Len Brown26717172010-03-08 14:07:30 -05001346{
Len Brown26717172010-03-08 14:07:30 -05001347 struct cpuidle_device *dev;
1348
Thomas Renninger65b7f832012-01-17 22:40:08 +01001349 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
Len Brown26717172010-03-08 14:07:30 -05001350
Thomas Renninger65b7f832012-01-17 22:40:08 +01001351 dev->cpu = cpu;
Len Brown26717172010-03-08 14:07:30 -05001352
Thomas Renninger65b7f832012-01-17 22:40:08 +01001353 if (cpuidle_register_device(dev)) {
1354 pr_debug(PREFIX "cpuidle_register_device %d failed!\n", cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001355 return -EIO;
Len Brown26717172010-03-08 14:07:30 -05001356 }
1357
Andi Kleenb66b8b92012-01-26 00:09:07 +01001358 if (icpu->auto_demotion_disable_flags)
Thomas Renninger65b7f832012-01-17 22:40:08 +01001359 smp_call_function_single(cpu, auto_demotion_disable, NULL, 1);
1360
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001361 if (icpu->disable_promotion_to_c1e)
1362 smp_call_function_single(cpu, c1e_promotion_disable, NULL, 1);
1363
Len Brown26717172010-03-08 14:07:30 -05001364 return 0;
1365}
Len Brown26717172010-03-08 14:07:30 -05001366
1367static int __init intel_idle_init(void)
1368{
Thomas Renninger65b7f832012-01-17 22:40:08 +01001369 int retval, i;
Len Brown26717172010-03-08 14:07:30 -05001370
Thomas Renningerd1896042010-11-03 17:06:14 +01001371 /* Do not load intel_idle at all for now if idle= is passed */
1372 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
1373 return -ENODEV;
1374
Len Brown26717172010-03-08 14:07:30 -05001375 retval = intel_idle_probe();
1376 if (retval)
1377 return retval;
1378
Richard Cochrane9df69c2016-04-06 17:00:52 -04001379 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
1380 if (intel_idle_cpuidle_devices == NULL)
1381 return -ENOMEM;
1382
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301383 intel_idle_cpuidle_driver_init();
Len Brown26717172010-03-08 14:07:30 -05001384 retval = cpuidle_register_driver(&intel_idle_driver);
1385 if (retval) {
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001386 struct cpuidle_driver *drv = cpuidle_get_driver();
Len Brown26717172010-03-08 14:07:30 -05001387 printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001388 drv ? drv->name : "none");
Richard Cochrane9df69c2016-04-06 17:00:52 -04001389 free_percpu(intel_idle_cpuidle_devices);
Len Brown26717172010-03-08 14:07:30 -05001390 return retval;
1391 }
1392
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301393 cpu_notifier_register_begin();
1394
Thomas Renninger65b7f832012-01-17 22:40:08 +01001395 for_each_online_cpu(i) {
1396 retval = intel_idle_cpu_init(i);
1397 if (retval) {
Richard Cochranb69ef2c2016-04-06 17:00:55 -04001398 intel_idle_cpuidle_devices_uninit();
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301399 cpu_notifier_register_done();
Thomas Renninger65b7f832012-01-17 22:40:08 +01001400 cpuidle_unregister_driver(&intel_idle_driver);
Richard Cochranca424892016-04-06 17:00:53 -04001401 free_percpu(intel_idle_cpuidle_devices);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001402 return retval;
1403 }
Len Brown26717172010-03-08 14:07:30 -05001404 }
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301405 __register_cpu_notifier(&cpu_hotplug_notifier);
1406
Richard Cochran2259a812016-04-06 17:00:54 -04001407 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
1408 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
1409 else
1410 on_each_cpu(__setup_broadcast_timer, (void *)true, 1);
1411
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301412 cpu_notifier_register_done();
Len Brown26717172010-03-08 14:07:30 -05001413
Richard Cochran2259a812016-04-06 17:00:54 -04001414 pr_debug(PREFIX "lapic_timer_reliable_states 0x%x\n",
1415 lapic_timer_reliable_states);
1416
Len Brown26717172010-03-08 14:07:30 -05001417 return 0;
1418}
1419
1420static void __exit intel_idle_exit(void)
1421{
Richard Cochran3e66a9a2016-04-06 17:00:57 -04001422 struct cpuidle_device *dev;
1423 int i;
1424
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301425 cpu_notifier_register_begin();
Daniel Lezcano25ac7762012-07-05 15:23:25 +02001426
1427 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
Shaohua Li39a74fd2012-01-10 15:48:19 -08001428 on_each_cpu(__setup_broadcast_timer, (void *)false, 1);
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301429 __unregister_cpu_notifier(&cpu_hotplug_notifier);
Richard Cochran3e66a9a2016-04-06 17:00:57 -04001430
1431 for_each_possible_cpu(i) {
1432 dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
1433 cpuidle_unregister_device(dev);
1434 }
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301435
1436 cpu_notifier_register_done();
Richard Cochran51319912016-04-06 17:00:51 -04001437
1438 cpuidle_unregister_driver(&intel_idle_driver);
Richard Cochranca424892016-04-06 17:00:53 -04001439 free_percpu(intel_idle_cpuidle_devices);
Len Brown26717172010-03-08 14:07:30 -05001440}
1441
1442module_init(intel_idle_init);
1443module_exit(intel_idle_exit);
1444
Len Brown26717172010-03-08 14:07:30 -05001445module_param(max_cstate, int, 0444);
Len Brown26717172010-03-08 14:07:30 -05001446
1447MODULE_AUTHOR("Len Brown <len.brown@intel.com>");
1448MODULE_DESCRIPTION("Cpuidle driver for Intel Hardware v" INTEL_IDLE_VERSION);
1449MODULE_LICENSE("GPL");