blob: 4466a2f969d7ba5d5cafee13b7359047955cd07a [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 *
Len Brown26717172010-03-08 14:07:30 -050049 */
50
51/* un-comment DEBUG to enable pr_debug() statements */
52#define DEBUG
53
54#include <linux/kernel.h>
55#include <linux/cpuidle.h>
Thomas Gleixner76962ca2015-04-03 02:02:34 +020056#include <linux/tick.h>
Len Brown26717172010-03-08 14:07:30 -050057#include <trace/events/power.h>
58#include <linux/sched.h>
Shaohua Li2a2d31c2011-01-10 09:38:12 +080059#include <linux/notifier.h>
60#include <linux/cpu.h>
Paul Gortmaker02c4fae2016-06-17 01:28:33 -040061#include <linux/moduleparam.h>
Andi Kleenb66b8b92012-01-26 00:09:07 +010062#include <asm/cpu_device_id.h>
Dave Hansendb73c5a2016-06-02 17:19:32 -070063#include <asm/intel-family.h>
H. Peter Anvinbc83ccc2010-09-17 15:36:40 -070064#include <asm/mwait.h>
Len Brown14796fc2011-01-18 20:48:27 -050065#include <asm/msr.h>
Len Brown26717172010-03-08 14:07:30 -050066
Len Brownd70e28f2016-03-13 00:33:48 -050067#define INTEL_IDLE_VERSION "0.4.1"
Len Brown26717172010-03-08 14:07:30 -050068#define PREFIX "intel_idle: "
69
Len Brown26717172010-03-08 14:07:30 -050070static struct cpuidle_driver intel_idle_driver = {
71 .name = "intel_idle",
72 .owner = THIS_MODULE,
73};
74/* intel_idle.max_cstate=0 disables driver */
Len Brown137ecc72013-02-01 21:35:35 -050075static int max_cstate = CPUIDLE_STATE_MAX - 1;
Len Brown26717172010-03-08 14:07:30 -050076
Len Brownc4236282010-05-28 02:22:03 -040077static unsigned int mwait_substates;
Len Brown26717172010-03-08 14:07:30 -050078
Shaohua Li2a2d31c2011-01-10 09:38:12 +080079#define LAPIC_TIMER_ALWAYS_RELIABLE 0xFFFFFFFF
Len Brown26717172010-03-08 14:07:30 -050080/* Reliable LAPIC Timer States, bit 1 for C1 etc. */
Len Brownd13780d2010-07-07 00:12:03 -040081static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
Len Brown26717172010-03-08 14:07:30 -050082
Andi Kleenb66b8b92012-01-26 00:09:07 +010083struct idle_cpu {
84 struct cpuidle_state *state_table;
85
86 /*
87 * Hardware C-state auto-demotion may not always be optimal.
88 * Indicate which enable bits to clear here.
89 */
90 unsigned long auto_demotion_disable_flags;
Len Brown8c058d532014-07-31 15:21:24 -040091 bool byt_auto_demotion_disable_flag;
Len Brown32e95182013-02-02 01:31:56 -050092 bool disable_promotion_to_c1e;
Andi Kleenb66b8b92012-01-26 00:09:07 +010093};
94
95static const struct idle_cpu *icpu;
Namhyung Kim3265eba2010-08-08 03:10:03 +090096static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053097static int intel_idle(struct cpuidle_device *dev,
98 struct cpuidle_driver *drv, int index);
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +010099static void intel_idle_freeze(struct cpuidle_device *dev,
100 struct cpuidle_driver *drv, int index);
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200101static int intel_idle_cpu_init(int cpu);
Len Brown26717172010-03-08 14:07:30 -0500102
103static struct cpuidle_state *cpuidle_state_table;
104
105/*
Len Brown956d0332011-01-12 02:51:20 -0500106 * Set this flag for states where the HW flushes the TLB for us
107 * and so we don't need cross-calls to keep it consistent.
108 * If this flag is set, SW flushes the TLB, so even if the
109 * HW doesn't do the flushing, this flag is safe to use.
110 */
111#define CPUIDLE_FLAG_TLB_FLUSHED 0x10000
112
113/*
Len Brownb1beab42013-01-31 19:55:37 -0500114 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
115 * the C-state (top nibble) and sub-state (bottom nibble)
116 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
117 *
118 * We store the hint at the top of our "flags" for each state.
119 */
120#define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
121#define MWAIT2flg(eax) ((eax & 0xFF) << 24)
122
123/*
Len Brown26717172010-03-08 14:07:30 -0500124 * States are indexed by the cstate number,
125 * which is also the index into the MWAIT hint array.
126 * Thus C0 is a dummy.
127 */
Jiang Liuba0dc812014-01-09 15:30:26 +0800128static struct cpuidle_state nehalem_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500129 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100130 .name = "C1-NHM",
Len Brown26717172010-03-08 14:07:30 -0500131 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100132 .flags = MWAIT2flg(0x00),
Len Brown26717172010-03-08 14:07:30 -0500133 .exit_latency = 3,
Len Brown26717172010-03-08 14:07:30 -0500134 .target_residency = 6,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100135 .enter = &intel_idle,
136 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500137 {
Len Brown32e95182013-02-02 01:31:56 -0500138 .name = "C1E-NHM",
139 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100140 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500141 .exit_latency = 10,
142 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100143 .enter = &intel_idle,
144 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500145 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100146 .name = "C3-NHM",
Len Brown26717172010-03-08 14:07:30 -0500147 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100148 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500149 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500150 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100151 .enter = &intel_idle,
152 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500153 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100154 .name = "C6-NHM",
Len Brown26717172010-03-08 14:07:30 -0500155 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100156 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500157 .exit_latency = 200,
Len Brown26717172010-03-08 14:07:30 -0500158 .target_residency = 800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100159 .enter = &intel_idle,
160 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500161 {
162 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500163};
164
Jiang Liuba0dc812014-01-09 15:30:26 +0800165static struct cpuidle_state snb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500166 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100167 .name = "C1-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400168 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100169 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500170 .exit_latency = 2,
171 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100172 .enter = &intel_idle,
173 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500174 {
175 .name = "C1E-SNB",
176 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100177 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500178 .exit_latency = 10,
179 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100180 .enter = &intel_idle,
181 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500182 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100183 .name = "C3-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400184 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100185 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400186 .exit_latency = 80,
Len Brownddbd5502010-12-13 18:28:22 -0500187 .target_residency = 211,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100188 .enter = &intel_idle,
189 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500190 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100191 .name = "C6-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400192 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100193 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400194 .exit_latency = 104,
Len Brownddbd5502010-12-13 18:28:22 -0500195 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100196 .enter = &intel_idle,
197 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500198 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100199 .name = "C7-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400200 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100201 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400202 .exit_latency = 109,
Len Brownddbd5502010-12-13 18:28:22 -0500203 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100204 .enter = &intel_idle,
205 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500206 {
207 .enter = NULL }
Len Brownd13780d2010-07-07 00:12:03 -0400208};
209
Len Brown718987d2014-02-14 02:30:00 -0500210static struct cpuidle_state byt_cstates[] = {
211 {
212 .name = "C1-BYT",
213 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100214 .flags = MWAIT2flg(0x00),
Len Brown718987d2014-02-14 02:30:00 -0500215 .exit_latency = 1,
216 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100217 .enter = &intel_idle,
218 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500219 {
Len Brown718987d2014-02-14 02:30:00 -0500220 .name = "C6N-BYT",
221 .desc = "MWAIT 0x58",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100222 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400223 .exit_latency = 300,
Len Brown718987d2014-02-14 02:30:00 -0500224 .target_residency = 275,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100225 .enter = &intel_idle,
226 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500227 {
228 .name = "C6S-BYT",
229 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100230 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400231 .exit_latency = 500,
Len Brown718987d2014-02-14 02:30:00 -0500232 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100233 .enter = &intel_idle,
234 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500235 {
236 .name = "C7-BYT",
237 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100238 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500239 .exit_latency = 1200,
Len Brownd7ef7672015-03-24 23:23:20 -0400240 .target_residency = 4000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100241 .enter = &intel_idle,
242 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500243 {
244 .name = "C7S-BYT",
245 .desc = "MWAIT 0x64",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100246 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500247 .exit_latency = 10000,
248 .target_residency = 20000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100249 .enter = &intel_idle,
250 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500251 {
252 .enter = NULL }
253};
254
Len Browncab07a52015-03-27 20:54:01 -0400255static struct cpuidle_state cht_cstates[] = {
256 {
257 .name = "C1-CHT",
258 .desc = "MWAIT 0x00",
259 .flags = MWAIT2flg(0x00),
260 .exit_latency = 1,
261 .target_residency = 1,
262 .enter = &intel_idle,
263 .enter_freeze = intel_idle_freeze, },
264 {
265 .name = "C6N-CHT",
266 .desc = "MWAIT 0x58",
267 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
268 .exit_latency = 80,
269 .target_residency = 275,
270 .enter = &intel_idle,
271 .enter_freeze = intel_idle_freeze, },
272 {
273 .name = "C6S-CHT",
274 .desc = "MWAIT 0x52",
275 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
276 .exit_latency = 200,
277 .target_residency = 560,
278 .enter = &intel_idle,
279 .enter_freeze = intel_idle_freeze, },
280 {
281 .name = "C7-CHT",
282 .desc = "MWAIT 0x60",
283 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
284 .exit_latency = 1200,
285 .target_residency = 4000,
286 .enter = &intel_idle,
287 .enter_freeze = intel_idle_freeze, },
288 {
289 .name = "C7S-CHT",
290 .desc = "MWAIT 0x64",
291 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
292 .exit_latency = 10000,
293 .target_residency = 20000,
294 .enter = &intel_idle,
295 .enter_freeze = intel_idle_freeze, },
296 {
297 .enter = NULL }
298};
299
Jiang Liuba0dc812014-01-09 15:30:26 +0800300static struct cpuidle_state ivb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500301 {
Len Brown6edab082012-06-01 19:45:32 -0400302 .name = "C1-IVB",
303 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100304 .flags = MWAIT2flg(0x00),
Len Brown6edab082012-06-01 19:45:32 -0400305 .exit_latency = 1,
306 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100307 .enter = &intel_idle,
308 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500309 {
Len Brown32e95182013-02-02 01:31:56 -0500310 .name = "C1E-IVB",
311 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100312 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500313 .exit_latency = 10,
314 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100315 .enter = &intel_idle,
316 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500317 {
Len Brown6edab082012-06-01 19:45:32 -0400318 .name = "C3-IVB",
319 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100320 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400321 .exit_latency = 59,
322 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100323 .enter = &intel_idle,
324 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500325 {
Len Brown6edab082012-06-01 19:45:32 -0400326 .name = "C6-IVB",
327 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100328 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400329 .exit_latency = 80,
330 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100331 .enter = &intel_idle,
332 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500333 {
Len Brown6edab082012-06-01 19:45:32 -0400334 .name = "C7-IVB",
335 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100336 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400337 .exit_latency = 87,
338 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100339 .enter = &intel_idle,
340 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500341 {
342 .enter = NULL }
Len Brown6edab082012-06-01 19:45:32 -0400343};
344
Len Brown0138d8f2014-04-04 01:21:07 -0400345static struct cpuidle_state ivt_cstates[] = {
346 {
347 .name = "C1-IVT",
348 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100349 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400350 .exit_latency = 1,
351 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100352 .enter = &intel_idle,
353 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400354 {
355 .name = "C1E-IVT",
356 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100357 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400358 .exit_latency = 10,
359 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100360 .enter = &intel_idle,
361 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400362 {
363 .name = "C3-IVT",
364 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100365 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400366 .exit_latency = 59,
367 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100368 .enter = &intel_idle,
369 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400370 {
371 .name = "C6-IVT",
372 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100373 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400374 .exit_latency = 82,
375 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100376 .enter = &intel_idle,
377 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400378 {
379 .enter = NULL }
380};
381
382static struct cpuidle_state ivt_cstates_4s[] = {
383 {
384 .name = "C1-IVT-4S",
385 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100386 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400387 .exit_latency = 1,
388 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100389 .enter = &intel_idle,
390 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400391 {
392 .name = "C1E-IVT-4S",
393 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100394 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400395 .exit_latency = 10,
396 .target_residency = 250,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100397 .enter = &intel_idle,
398 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400399 {
400 .name = "C3-IVT-4S",
401 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100402 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400403 .exit_latency = 59,
404 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100405 .enter = &intel_idle,
406 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400407 {
408 .name = "C6-IVT-4S",
409 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100410 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400411 .exit_latency = 84,
412 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100413 .enter = &intel_idle,
414 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400415 {
416 .enter = NULL }
417};
418
419static struct cpuidle_state ivt_cstates_8s[] = {
420 {
421 .name = "C1-IVT-8S",
422 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100423 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400424 .exit_latency = 1,
425 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100426 .enter = &intel_idle,
427 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400428 {
429 .name = "C1E-IVT-8S",
430 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100431 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400432 .exit_latency = 10,
433 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100434 .enter = &intel_idle,
435 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400436 {
437 .name = "C3-IVT-8S",
438 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100439 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400440 .exit_latency = 59,
441 .target_residency = 600,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100442 .enter = &intel_idle,
443 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400444 {
445 .name = "C6-IVT-8S",
446 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100447 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400448 .exit_latency = 88,
449 .target_residency = 700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100450 .enter = &intel_idle,
451 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400452 {
453 .enter = NULL }
454};
455
Jiang Liuba0dc812014-01-09 15:30:26 +0800456static struct cpuidle_state hsw_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500457 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500458 .name = "C1-HSW",
459 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100460 .flags = MWAIT2flg(0x00),
Len Brown85a4d2d2013-01-31 14:40:49 -0500461 .exit_latency = 2,
462 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100463 .enter = &intel_idle,
464 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500465 {
Len Brown32e95182013-02-02 01:31:56 -0500466 .name = "C1E-HSW",
467 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100468 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500469 .exit_latency = 10,
470 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100471 .enter = &intel_idle,
472 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500473 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500474 .name = "C3-HSW",
475 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100476 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500477 .exit_latency = 33,
478 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100479 .enter = &intel_idle,
480 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500481 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500482 .name = "C6-HSW",
483 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100484 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500485 .exit_latency = 133,
486 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100487 .enter = &intel_idle,
488 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500489 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500490 .name = "C7s-HSW",
491 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100492 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500493 .exit_latency = 166,
494 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100495 .enter = &intel_idle,
496 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500497 {
Len Brown86239ce2013-02-27 13:18:50 -0500498 .name = "C8-HSW",
499 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100500 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500501 .exit_latency = 300,
502 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100503 .enter = &intel_idle,
504 .enter_freeze = intel_idle_freeze, },
Len Brown86239ce2013-02-27 13:18:50 -0500505 {
506 .name = "C9-HSW",
507 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100508 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500509 .exit_latency = 600,
510 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100511 .enter = &intel_idle,
512 .enter_freeze = intel_idle_freeze, },
Len Brown86239ce2013-02-27 13:18:50 -0500513 {
514 .name = "C10-HSW",
515 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100516 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500517 .exit_latency = 2600,
518 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100519 .enter = &intel_idle,
520 .enter_freeze = intel_idle_freeze, },
Len Brown86239ce2013-02-27 13:18:50 -0500521 {
Len Browne022e7e2013-02-01 23:37:30 -0500522 .enter = NULL }
Len Brown85a4d2d2013-01-31 14:40:49 -0500523};
Len Browna138b562014-02-04 23:56:40 -0500524static struct cpuidle_state bdw_cstates[] = {
525 {
526 .name = "C1-BDW",
527 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100528 .flags = MWAIT2flg(0x00),
Len Browna138b562014-02-04 23:56:40 -0500529 .exit_latency = 2,
530 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100531 .enter = &intel_idle,
532 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500533 {
534 .name = "C1E-BDW",
535 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100536 .flags = MWAIT2flg(0x01),
Len Browna138b562014-02-04 23:56:40 -0500537 .exit_latency = 10,
538 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100539 .enter = &intel_idle,
540 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500541 {
542 .name = "C3-BDW",
543 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100544 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500545 .exit_latency = 40,
546 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100547 .enter = &intel_idle,
548 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500549 {
550 .name = "C6-BDW",
551 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100552 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500553 .exit_latency = 133,
554 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100555 .enter = &intel_idle,
556 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500557 {
558 .name = "C7s-BDW",
559 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100560 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500561 .exit_latency = 166,
562 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100563 .enter = &intel_idle,
564 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500565 {
566 .name = "C8-BDW",
567 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100568 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500569 .exit_latency = 300,
570 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100571 .enter = &intel_idle,
572 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500573 {
574 .name = "C9-BDW",
575 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100576 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500577 .exit_latency = 600,
578 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100579 .enter = &intel_idle,
580 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500581 {
582 .name = "C10-BDW",
583 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100584 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500585 .exit_latency = 2600,
586 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100587 .enter = &intel_idle,
588 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500589 {
590 .enter = NULL }
591};
Len Brown85a4d2d2013-01-31 14:40:49 -0500592
Len Brown493f1332015-03-25 23:20:37 -0400593static struct cpuidle_state skl_cstates[] = {
594 {
595 .name = "C1-SKL",
596 .desc = "MWAIT 0x00",
597 .flags = MWAIT2flg(0x00),
598 .exit_latency = 2,
599 .target_residency = 2,
600 .enter = &intel_idle,
601 .enter_freeze = intel_idle_freeze, },
602 {
603 .name = "C1E-SKL",
604 .desc = "MWAIT 0x01",
605 .flags = MWAIT2flg(0x01),
606 .exit_latency = 10,
607 .target_residency = 20,
608 .enter = &intel_idle,
609 .enter_freeze = intel_idle_freeze, },
610 {
611 .name = "C3-SKL",
612 .desc = "MWAIT 0x10",
613 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
614 .exit_latency = 70,
615 .target_residency = 100,
616 .enter = &intel_idle,
617 .enter_freeze = intel_idle_freeze, },
618 {
619 .name = "C6-SKL",
620 .desc = "MWAIT 0x20",
621 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400622 .exit_latency = 85,
Len Brown493f1332015-03-25 23:20:37 -0400623 .target_residency = 200,
624 .enter = &intel_idle,
625 .enter_freeze = intel_idle_freeze, },
626 {
627 .name = "C7s-SKL",
628 .desc = "MWAIT 0x33",
629 .flags = MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED,
630 .exit_latency = 124,
631 .target_residency = 800,
632 .enter = &intel_idle,
633 .enter_freeze = intel_idle_freeze, },
634 {
635 .name = "C8-SKL",
636 .desc = "MWAIT 0x40",
637 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400638 .exit_latency = 200,
Len Brown493f1332015-03-25 23:20:37 -0400639 .target_residency = 800,
640 .enter = &intel_idle,
641 .enter_freeze = intel_idle_freeze, },
642 {
Len Brown135919a2015-09-09 13:35:05 -0400643 .name = "C9-SKL",
644 .desc = "MWAIT 0x50",
645 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
646 .exit_latency = 480,
647 .target_residency = 5000,
648 .enter = &intel_idle,
649 .enter_freeze = intel_idle_freeze, },
650 {
Len Brown493f1332015-03-25 23:20:37 -0400651 .name = "C10-SKL",
652 .desc = "MWAIT 0x60",
653 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
654 .exit_latency = 890,
655 .target_residency = 5000,
656 .enter = &intel_idle,
657 .enter_freeze = intel_idle_freeze, },
658 {
659 .enter = NULL }
660};
661
Len Brownf9e71652016-04-06 17:00:58 -0400662static struct cpuidle_state skx_cstates[] = {
663 {
664 .name = "C1-SKX",
665 .desc = "MWAIT 0x00",
666 .flags = MWAIT2flg(0x00),
667 .exit_latency = 2,
668 .target_residency = 2,
669 .enter = &intel_idle,
670 .enter_freeze = intel_idle_freeze, },
671 {
672 .name = "C1E-SKX",
673 .desc = "MWAIT 0x01",
674 .flags = MWAIT2flg(0x01),
675 .exit_latency = 10,
676 .target_residency = 20,
677 .enter = &intel_idle,
678 .enter_freeze = intel_idle_freeze, },
679 {
680 .name = "C6-SKX",
681 .desc = "MWAIT 0x20",
682 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
683 .exit_latency = 133,
684 .target_residency = 600,
685 .enter = &intel_idle,
686 .enter_freeze = intel_idle_freeze, },
687 {
688 .enter = NULL }
689};
690
Jiang Liuba0dc812014-01-09 15:30:26 +0800691static struct cpuidle_state atom_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500692 {
Len Brown32e95182013-02-02 01:31:56 -0500693 .name = "C1E-ATM",
Len Brown26717172010-03-08 14:07:30 -0500694 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100695 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500696 .exit_latency = 10,
697 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100698 .enter = &intel_idle,
699 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500700 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100701 .name = "C2-ATM",
Len Brown26717172010-03-08 14:07:30 -0500702 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100703 .flags = MWAIT2flg(0x10),
Len Brown26717172010-03-08 14:07:30 -0500704 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500705 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100706 .enter = &intel_idle,
707 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500708 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100709 .name = "C4-ATM",
Len Brown26717172010-03-08 14:07:30 -0500710 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100711 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500712 .exit_latency = 100,
Len Brown26717172010-03-08 14:07:30 -0500713 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100714 .enter = &intel_idle,
715 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500716 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100717 .name = "C6-ATM",
Len Brown7fcca7d2010-10-05 13:43:14 -0400718 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100719 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown7fcca7d2010-10-05 13:43:14 -0400720 .exit_latency = 140,
Len Brown7fcca7d2010-10-05 13:43:14 -0400721 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100722 .enter = &intel_idle,
723 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500724 {
725 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500726};
Jiang Liu88390992014-01-09 15:30:27 +0800727static struct cpuidle_state avn_cstates[] = {
Len Brownfab04b22013-11-09 00:30:17 -0500728 {
729 .name = "C1-AVN",
730 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100731 .flags = MWAIT2flg(0x00),
Len Brownfab04b22013-11-09 00:30:17 -0500732 .exit_latency = 2,
733 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100734 .enter = &intel_idle,
735 .enter_freeze = intel_idle_freeze, },
Len Brownfab04b22013-11-09 00:30:17 -0500736 {
737 .name = "C6-AVN",
738 .desc = "MWAIT 0x51",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100739 .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownfab04b22013-11-09 00:30:17 -0500740 .exit_latency = 15,
741 .target_residency = 45,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100742 .enter = &intel_idle,
743 .enter_freeze = intel_idle_freeze, },
Jiang Liu88390992014-01-09 15:30:27 +0800744 {
745 .enter = NULL }
Len Brownfab04b22013-11-09 00:30:17 -0500746};
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700747static struct cpuidle_state knl_cstates[] = {
748 {
749 .name = "C1-KNL",
750 .desc = "MWAIT 0x00",
751 .flags = MWAIT2flg(0x00),
752 .exit_latency = 1,
753 .target_residency = 2,
754 .enter = &intel_idle,
755 .enter_freeze = intel_idle_freeze },
756 {
757 .name = "C6-KNL",
758 .desc = "MWAIT 0x10",
759 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
760 .exit_latency = 120,
761 .target_residency = 500,
762 .enter = &intel_idle,
763 .enter_freeze = intel_idle_freeze },
764 {
765 .enter = NULL }
766};
Len Brown26717172010-03-08 14:07:30 -0500767
Len Brown5dcef692016-04-06 17:00:47 -0400768static struct cpuidle_state bxt_cstates[] = {
769 {
770 .name = "C1-BXT",
771 .desc = "MWAIT 0x00",
772 .flags = MWAIT2flg(0x00),
773 .exit_latency = 2,
774 .target_residency = 2,
775 .enter = &intel_idle,
776 .enter_freeze = intel_idle_freeze, },
777 {
778 .name = "C1E-BXT",
779 .desc = "MWAIT 0x01",
780 .flags = MWAIT2flg(0x01),
781 .exit_latency = 10,
782 .target_residency = 20,
783 .enter = &intel_idle,
784 .enter_freeze = intel_idle_freeze, },
785 {
786 .name = "C6-BXT",
787 .desc = "MWAIT 0x20",
788 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
789 .exit_latency = 133,
790 .target_residency = 133,
791 .enter = &intel_idle,
792 .enter_freeze = intel_idle_freeze, },
793 {
794 .name = "C7s-BXT",
795 .desc = "MWAIT 0x31",
796 .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
797 .exit_latency = 155,
798 .target_residency = 155,
799 .enter = &intel_idle,
800 .enter_freeze = intel_idle_freeze, },
801 {
802 .name = "C8-BXT",
803 .desc = "MWAIT 0x40",
804 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
805 .exit_latency = 1000,
806 .target_residency = 1000,
807 .enter = &intel_idle,
808 .enter_freeze = intel_idle_freeze, },
809 {
810 .name = "C9-BXT",
811 .desc = "MWAIT 0x50",
812 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
813 .exit_latency = 2000,
814 .target_residency = 2000,
815 .enter = &intel_idle,
816 .enter_freeze = intel_idle_freeze, },
817 {
818 .name = "C10-BXT",
819 .desc = "MWAIT 0x60",
820 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
821 .exit_latency = 10000,
822 .target_residency = 10000,
823 .enter = &intel_idle,
824 .enter_freeze = intel_idle_freeze, },
825 {
826 .enter = NULL }
827};
828
Jacob Pan0080d652016-06-17 01:28:34 -0400829static struct cpuidle_state dnv_cstates[] = {
830 {
831 .name = "C1-DNV",
832 .desc = "MWAIT 0x00",
833 .flags = MWAIT2flg(0x00),
834 .exit_latency = 2,
835 .target_residency = 2,
836 .enter = &intel_idle,
837 .enter_freeze = intel_idle_freeze, },
838 {
839 .name = "C1E-DNV",
840 .desc = "MWAIT 0x01",
841 .flags = MWAIT2flg(0x01),
842 .exit_latency = 10,
843 .target_residency = 20,
844 .enter = &intel_idle,
845 .enter_freeze = intel_idle_freeze, },
846 {
847 .name = "C6-DNV",
848 .desc = "MWAIT 0x20",
849 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
850 .exit_latency = 50,
851 .target_residency = 500,
852 .enter = &intel_idle,
853 .enter_freeze = intel_idle_freeze, },
854 {
855 .enter = NULL }
856};
857
Len Brown26717172010-03-08 14:07:30 -0500858/**
859 * intel_idle
860 * @dev: cpuidle_device
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530861 * @drv: cpuidle driver
Deepthi Dharware978aa72011-10-28 16:20:09 +0530862 * @index: index of cpuidle state
Len Brown26717172010-03-08 14:07:30 -0500863 *
Yanmin Zhang63ff07b2012-01-10 15:48:21 -0800864 * Must be called under local_irq_disable().
Len Brown26717172010-03-08 14:07:30 -0500865 */
Chris Metcalf6727ad92016-10-07 17:02:55 -0700866static __cpuidle int intel_idle(struct cpuidle_device *dev,
867 struct cpuidle_driver *drv, int index)
Len Brown26717172010-03-08 14:07:30 -0500868{
869 unsigned long ecx = 1; /* break on interrupt flag */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530870 struct cpuidle_state *state = &drv->states[index];
Len Brownb1beab42013-01-31 19:55:37 -0500871 unsigned long eax = flg2MWAIT(state->flags);
Len Brown26717172010-03-08 14:07:30 -0500872 unsigned int cstate;
Len Brown26717172010-03-08 14:07:30 -0500873 int cpu = smp_processor_id();
874
875 cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) + 1;
876
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400877 /*
Len Brownc8381cc2010-10-15 20:43:06 -0400878 * leave_mm() to avoid costly and often unnecessary wakeups
879 * for flushing the user TLB's associated with the active mm.
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400880 */
Len Brownc8381cc2010-10-15 20:43:06 -0400881 if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400882 leave_mm(cpu);
883
Len Brown26717172010-03-08 14:07:30 -0500884 if (!(lapic_timer_reliable_states & (1 << (cstate))))
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200885 tick_broadcast_enter();
Len Brown26717172010-03-08 14:07:30 -0500886
Peter Zijlstra16824252013-12-12 15:08:36 +0100887 mwait_idle_with_hints(eax, ecx);
Len Brown26717172010-03-08 14:07:30 -0500888
Len Brown26717172010-03-08 14:07:30 -0500889 if (!(lapic_timer_reliable_states & (1 << (cstate))))
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200890 tick_broadcast_exit();
Len Brown26717172010-03-08 14:07:30 -0500891
Deepthi Dharware978aa72011-10-28 16:20:09 +0530892 return index;
Len Brown26717172010-03-08 14:07:30 -0500893}
894
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100895/**
896 * intel_idle_freeze - simplified "enter" callback routine for suspend-to-idle
897 * @dev: cpuidle_device
898 * @drv: cpuidle driver
899 * @index: state index
900 */
901static void intel_idle_freeze(struct cpuidle_device *dev,
902 struct cpuidle_driver *drv, int index)
903{
904 unsigned long ecx = 1; /* break on interrupt flag */
905 unsigned long eax = flg2MWAIT(drv->states[index].flags);
906
907 mwait_idle_with_hints(eax, ecx);
908}
909
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800910static void __setup_broadcast_timer(void *arg)
911{
Thomas Gleixner76962ca2015-04-03 02:02:34 +0200912 unsigned long on = (unsigned long)arg;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800913
Thomas Gleixner76962ca2015-04-03 02:02:34 +0200914 if (on)
915 tick_broadcast_enable();
916 else
917 tick_broadcast_disable();
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800918}
919
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200920static int cpu_hotplug_notify(struct notifier_block *n,
921 unsigned long action, void *hcpu)
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800922{
923 int hotcpu = (unsigned long)hcpu;
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200924 struct cpuidle_device *dev;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800925
Prarit Bhargavae2401452013-10-23 09:44:51 -0400926 switch (action & ~CPU_TASKS_FROZEN) {
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800927 case CPU_ONLINE:
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200928
929 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
930 smp_call_function_single(hotcpu, __setup_broadcast_timer,
931 (void *)true, 1);
932
933 /*
934 * Some systems can hotplug a cpu at runtime after
935 * the kernel has booted, we have to initialize the
936 * driver in this case
937 */
938 dev = per_cpu_ptr(intel_idle_cpuidle_devices, hotcpu);
Richard Cochran08820542016-04-06 17:00:56 -0400939 if (dev->registered)
940 break;
941
942 if (intel_idle_cpu_init(hotcpu))
943 return NOTIFY_BAD;
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200944
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800945 break;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800946 }
947 return NOTIFY_OK;
948}
949
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200950static struct notifier_block cpu_hotplug_notifier = {
951 .notifier_call = cpu_hotplug_notify,
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800952};
953
Len Brown14796fc2011-01-18 20:48:27 -0500954static void auto_demotion_disable(void *dummy)
955{
956 unsigned long long msr_bits;
957
958 rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
Andi Kleenb66b8b92012-01-26 00:09:07 +0100959 msr_bits &= ~(icpu->auto_demotion_disable_flags);
Len Brown14796fc2011-01-18 20:48:27 -0500960 wrmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
961}
Len Brown32e95182013-02-02 01:31:56 -0500962static void c1e_promotion_disable(void *dummy)
963{
964 unsigned long long msr_bits;
965
966 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
967 msr_bits &= ~0x2;
968 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
969}
Len Brown14796fc2011-01-18 20:48:27 -0500970
Andi Kleenb66b8b92012-01-26 00:09:07 +0100971static const struct idle_cpu idle_cpu_nehalem = {
972 .state_table = nehalem_cstates,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100973 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
Len Brown32e95182013-02-02 01:31:56 -0500974 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100975};
976
977static const struct idle_cpu idle_cpu_atom = {
978 .state_table = atom_cstates,
979};
980
981static const struct idle_cpu idle_cpu_lincroft = {
982 .state_table = atom_cstates,
983 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
984};
985
986static const struct idle_cpu idle_cpu_snb = {
987 .state_table = snb_cstates,
Len Brown32e95182013-02-02 01:31:56 -0500988 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100989};
990
Len Brown718987d2014-02-14 02:30:00 -0500991static const struct idle_cpu idle_cpu_byt = {
992 .state_table = byt_cstates,
993 .disable_promotion_to_c1e = true,
Len Brown8c058d532014-07-31 15:21:24 -0400994 .byt_auto_demotion_disable_flag = true,
Len Brown718987d2014-02-14 02:30:00 -0500995};
996
Len Browncab07a52015-03-27 20:54:01 -0400997static const struct idle_cpu idle_cpu_cht = {
998 .state_table = cht_cstates,
999 .disable_promotion_to_c1e = true,
1000 .byt_auto_demotion_disable_flag = true,
1001};
1002
Len Brown6edab082012-06-01 19:45:32 -04001003static const struct idle_cpu idle_cpu_ivb = {
1004 .state_table = ivb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001005 .disable_promotion_to_c1e = true,
Len Brown6edab082012-06-01 19:45:32 -04001006};
1007
Len Brown0138d8f2014-04-04 01:21:07 -04001008static const struct idle_cpu idle_cpu_ivt = {
1009 .state_table = ivt_cstates,
1010 .disable_promotion_to_c1e = true,
1011};
1012
Len Brown85a4d2d2013-01-31 14:40:49 -05001013static const struct idle_cpu idle_cpu_hsw = {
1014 .state_table = hsw_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001015 .disable_promotion_to_c1e = true,
Len Brown85a4d2d2013-01-31 14:40:49 -05001016};
1017
Len Browna138b562014-02-04 23:56:40 -05001018static const struct idle_cpu idle_cpu_bdw = {
1019 .state_table = bdw_cstates,
1020 .disable_promotion_to_c1e = true,
1021};
1022
Len Brown493f1332015-03-25 23:20:37 -04001023static const struct idle_cpu idle_cpu_skl = {
1024 .state_table = skl_cstates,
1025 .disable_promotion_to_c1e = true,
1026};
1027
Len Brownf9e71652016-04-06 17:00:58 -04001028static const struct idle_cpu idle_cpu_skx = {
1029 .state_table = skx_cstates,
1030 .disable_promotion_to_c1e = true,
1031};
Len Brown493f1332015-03-25 23:20:37 -04001032
Len Brownfab04b22013-11-09 00:30:17 -05001033static const struct idle_cpu idle_cpu_avn = {
1034 .state_table = avn_cstates,
1035 .disable_promotion_to_c1e = true,
1036};
1037
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001038static const struct idle_cpu idle_cpu_knl = {
1039 .state_table = knl_cstates,
1040};
1041
Len Brown5dcef692016-04-06 17:00:47 -04001042static const struct idle_cpu idle_cpu_bxt = {
1043 .state_table = bxt_cstates,
1044 .disable_promotion_to_c1e = true,
1045};
1046
Jacob Pan0080d652016-06-17 01:28:34 -04001047static const struct idle_cpu idle_cpu_dnv = {
1048 .state_table = dnv_cstates,
1049 .disable_promotion_to_c1e = true,
1050};
1051
Andi Kleenb66b8b92012-01-26 00:09:07 +01001052#define ICPU(model, cpu) \
1053 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&cpu }
1054
Mathias Kraused5cdc3c2015-03-25 22:15:14 +01001055static const struct x86_cpu_id intel_idle_ids[] __initconst = {
Dave Hansendb73c5a2016-06-02 17:19:32 -07001056 ICPU(INTEL_FAM6_NEHALEM_EP, idle_cpu_nehalem),
1057 ICPU(INTEL_FAM6_NEHALEM, idle_cpu_nehalem),
Dave Hansen4b3b2342016-06-29 12:27:37 -07001058 ICPU(INTEL_FAM6_NEHALEM_G, idle_cpu_nehalem),
Dave Hansendb73c5a2016-06-02 17:19:32 -07001059 ICPU(INTEL_FAM6_WESTMERE, idle_cpu_nehalem),
1060 ICPU(INTEL_FAM6_WESTMERE_EP, idle_cpu_nehalem),
1061 ICPU(INTEL_FAM6_NEHALEM_EX, idle_cpu_nehalem),
1062 ICPU(INTEL_FAM6_ATOM_PINEVIEW, idle_cpu_atom),
1063 ICPU(INTEL_FAM6_ATOM_LINCROFT, idle_cpu_lincroft),
1064 ICPU(INTEL_FAM6_WESTMERE_EX, idle_cpu_nehalem),
1065 ICPU(INTEL_FAM6_SANDYBRIDGE, idle_cpu_snb),
1066 ICPU(INTEL_FAM6_SANDYBRIDGE_X, idle_cpu_snb),
1067 ICPU(INTEL_FAM6_ATOM_CEDARVIEW, idle_cpu_atom),
1068 ICPU(INTEL_FAM6_ATOM_SILVERMONT1, idle_cpu_byt),
1069 ICPU(INTEL_FAM6_ATOM_AIRMONT, idle_cpu_cht),
1070 ICPU(INTEL_FAM6_IVYBRIDGE, idle_cpu_ivb),
1071 ICPU(INTEL_FAM6_IVYBRIDGE_X, idle_cpu_ivt),
1072 ICPU(INTEL_FAM6_HASWELL_CORE, idle_cpu_hsw),
1073 ICPU(INTEL_FAM6_HASWELL_X, idle_cpu_hsw),
1074 ICPU(INTEL_FAM6_HASWELL_ULT, idle_cpu_hsw),
1075 ICPU(INTEL_FAM6_HASWELL_GT3E, idle_cpu_hsw),
1076 ICPU(INTEL_FAM6_ATOM_SILVERMONT2, idle_cpu_avn),
1077 ICPU(INTEL_FAM6_BROADWELL_CORE, idle_cpu_bdw),
1078 ICPU(INTEL_FAM6_BROADWELL_GT3E, idle_cpu_bdw),
1079 ICPU(INTEL_FAM6_BROADWELL_X, idle_cpu_bdw),
1080 ICPU(INTEL_FAM6_BROADWELL_XEON_D, idle_cpu_bdw),
1081 ICPU(INTEL_FAM6_SKYLAKE_MOBILE, idle_cpu_skl),
1082 ICPU(INTEL_FAM6_SKYLAKE_DESKTOP, idle_cpu_skl),
1083 ICPU(INTEL_FAM6_KABYLAKE_MOBILE, idle_cpu_skl),
1084 ICPU(INTEL_FAM6_KABYLAKE_DESKTOP, idle_cpu_skl),
1085 ICPU(INTEL_FAM6_SKYLAKE_X, idle_cpu_skx),
1086 ICPU(INTEL_FAM6_XEON_PHI_KNL, idle_cpu_knl),
1087 ICPU(INTEL_FAM6_ATOM_GOLDMONT, idle_cpu_bxt),
Jacob Pan0080d652016-06-17 01:28:34 -04001088 ICPU(INTEL_FAM6_ATOM_DENVERTON, idle_cpu_dnv),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001089 {}
1090};
Andi Kleenb66b8b92012-01-26 00:09:07 +01001091
Len Brown26717172010-03-08 14:07:30 -05001092/*
1093 * intel_idle_probe()
1094 */
Bartlomiej Zolnierkiewicz00f3e752013-08-30 12:27:45 +02001095static int __init intel_idle_probe(void)
Len Brown26717172010-03-08 14:07:30 -05001096{
Len Brownc4236282010-05-28 02:22:03 -04001097 unsigned int eax, ebx, ecx;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001098 const struct x86_cpu_id *id;
Len Brown26717172010-03-08 14:07:30 -05001099
1100 if (max_cstate == 0) {
1101 pr_debug(PREFIX "disabled\n");
1102 return -EPERM;
1103 }
1104
Andi Kleenb66b8b92012-01-26 00:09:07 +01001105 id = x86_match_cpu(intel_idle_ids);
1106 if (!id) {
1107 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
1108 boot_cpu_data.x86 == 6)
1109 pr_debug(PREFIX "does not run on family %d model %d\n",
1110 boot_cpu_data.x86, boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001111 return -ENODEV;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001112 }
Len Brown26717172010-03-08 14:07:30 -05001113
1114 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
1115 return -ENODEV;
1116
Len Brownc4236282010-05-28 02:22:03 -04001117 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001118
1119 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
Thomas Renninger5c2a9f02011-12-04 22:17:29 +01001120 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
1121 !mwait_substates)
Len Brown26717172010-03-08 14:07:30 -05001122 return -ENODEV;
Len Brown26717172010-03-08 14:07:30 -05001123
Len Brownc4236282010-05-28 02:22:03 -04001124 pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001125
Andi Kleenb66b8b92012-01-26 00:09:07 +01001126 icpu = (const struct idle_cpu *)id->driver_data;
1127 cpuidle_state_table = icpu->state_table;
Len Brown26717172010-03-08 14:07:30 -05001128
1129 pr_debug(PREFIX "v" INTEL_IDLE_VERSION
1130 " model 0x%X\n", boot_cpu_data.x86_model);
1131
Len Brown26717172010-03-08 14:07:30 -05001132 return 0;
1133}
1134
1135/*
1136 * intel_idle_cpuidle_devices_uninit()
Richard Cochranca424892016-04-06 17:00:53 -04001137 * Unregisters the cpuidle devices.
Len Brown26717172010-03-08 14:07:30 -05001138 */
1139static void intel_idle_cpuidle_devices_uninit(void)
1140{
1141 int i;
1142 struct cpuidle_device *dev;
1143
1144 for_each_online_cpu(i) {
1145 dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
1146 cpuidle_unregister_device(dev);
1147 }
Len Brown26717172010-03-08 14:07:30 -05001148}
Len Brown0138d8f2014-04-04 01:21:07 -04001149
1150/*
Len Brownd70e28f2016-03-13 00:33:48 -05001151 * ivt_idle_state_table_update(void)
1152 *
1153 * Tune IVT multi-socket targets
1154 * Assumption: num_sockets == (max_package_num + 1)
1155 */
1156static void ivt_idle_state_table_update(void)
1157{
1158 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1159 int cpu, package_num, num_sockets = 1;
1160
1161 for_each_online_cpu(cpu) {
1162 package_num = topology_physical_package_id(cpu);
1163 if (package_num + 1 > num_sockets) {
1164 num_sockets = package_num + 1;
1165
1166 if (num_sockets > 4) {
1167 cpuidle_state_table = ivt_cstates_8s;
1168 return;
1169 }
1170 }
1171 }
1172
1173 if (num_sockets > 2)
1174 cpuidle_state_table = ivt_cstates_4s;
1175
1176 /* else, 1 and 2 socket systems use default ivt_cstates */
1177}
Len Brown5dcef692016-04-06 17:00:47 -04001178
1179/*
1180 * Translate IRTL (Interrupt Response Time Limit) MSR to usec
1181 */
1182
1183static unsigned int irtl_ns_units[] = {
1184 1, 32, 1024, 32768, 1048576, 33554432, 0, 0 };
1185
1186static unsigned long long irtl_2_usec(unsigned long long irtl)
1187{
1188 unsigned long long ns;
1189
Jan Beulich3451ab32016-06-27 00:35:12 -06001190 if (!irtl)
1191 return 0;
1192
Jan Beulichbef45092016-06-27 00:35:48 -06001193 ns = irtl_ns_units[(irtl >> 10) & 0x7];
Len Brown5dcef692016-04-06 17:00:47 -04001194
1195 return div64_u64((irtl & 0x3FF) * ns, 1000);
1196}
1197/*
1198 * bxt_idle_state_table_update(void)
1199 *
1200 * On BXT, we trust the IRTL to show the definitive maximum latency
1201 * We use the same value for target_residency.
1202 */
1203static void bxt_idle_state_table_update(void)
1204{
1205 unsigned long long msr;
Jan Beulich3451ab32016-06-27 00:35:12 -06001206 unsigned int usec;
Len Brown5dcef692016-04-06 17:00:47 -04001207
1208 rdmsrl(MSR_PKGC6_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001209 usec = irtl_2_usec(msr);
1210 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001211 bxt_cstates[2].exit_latency = usec;
1212 bxt_cstates[2].target_residency = usec;
1213 }
1214
1215 rdmsrl(MSR_PKGC7_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001216 usec = irtl_2_usec(msr);
1217 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001218 bxt_cstates[3].exit_latency = usec;
1219 bxt_cstates[3].target_residency = usec;
1220 }
1221
1222 rdmsrl(MSR_PKGC8_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001223 usec = irtl_2_usec(msr);
1224 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001225 bxt_cstates[4].exit_latency = usec;
1226 bxt_cstates[4].target_residency = usec;
1227 }
1228
1229 rdmsrl(MSR_PKGC9_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001230 usec = irtl_2_usec(msr);
1231 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001232 bxt_cstates[5].exit_latency = usec;
1233 bxt_cstates[5].target_residency = usec;
1234 }
1235
1236 rdmsrl(MSR_PKGC10_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001237 usec = irtl_2_usec(msr);
1238 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001239 bxt_cstates[6].exit_latency = usec;
1240 bxt_cstates[6].target_residency = usec;
1241 }
1242
1243}
Len Brownd70e28f2016-03-13 00:33:48 -05001244/*
1245 * sklh_idle_state_table_update(void)
1246 *
1247 * On SKL-H (model 0x5e) disable C8 and C9 if:
1248 * C10 is enabled and SGX disabled
1249 */
1250static void sklh_idle_state_table_update(void)
1251{
1252 unsigned long long msr;
1253 unsigned int eax, ebx, ecx, edx;
1254
1255
1256 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1257 if (max_cstate <= 7)
1258 return;
1259
1260 /* if PC10 not present in CPUID.MWAIT.EDX */
1261 if ((mwait_substates & (0xF << 28)) == 0)
1262 return;
1263
1264 rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr);
1265
1266 /* PC10 is not enabled in PKG C-state limit */
1267 if ((msr & 0xF) != 8)
1268 return;
1269
1270 ecx = 0;
1271 cpuid(7, &eax, &ebx, &ecx, &edx);
1272
1273 /* if SGX is present */
1274 if (ebx & (1 << 2)) {
1275
1276 rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
1277
1278 /* if SGX is enabled */
1279 if (msr & (1 << 18))
1280 return;
1281 }
1282
1283 skl_cstates[5].disabled = 1; /* C8-SKL */
1284 skl_cstates[6].disabled = 1; /* C9-SKL */
1285}
1286/*
Len Brown0138d8f2014-04-04 01:21:07 -04001287 * intel_idle_state_table_update()
1288 *
1289 * Update the default state_table for this CPU-id
Len Brown0138d8f2014-04-04 01:21:07 -04001290 */
Len Brownd70e28f2016-03-13 00:33:48 -05001291
1292static void intel_idle_state_table_update(void)
Len Brown0138d8f2014-04-04 01:21:07 -04001293{
Len Brownd70e28f2016-03-13 00:33:48 -05001294 switch (boot_cpu_data.x86_model) {
Len Brown0138d8f2014-04-04 01:21:07 -04001295
Dave Hansendb73c5a2016-06-02 17:19:32 -07001296 case INTEL_FAM6_IVYBRIDGE_X:
Len Brownd70e28f2016-03-13 00:33:48 -05001297 ivt_idle_state_table_update();
1298 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001299 case INTEL_FAM6_ATOM_GOLDMONT:
Len Brown5dcef692016-04-06 17:00:47 -04001300 bxt_idle_state_table_update();
1301 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001302 case INTEL_FAM6_SKYLAKE_DESKTOP:
Len Brownd70e28f2016-03-13 00:33:48 -05001303 sklh_idle_state_table_update();
1304 break;
Len Brown0138d8f2014-04-04 01:21:07 -04001305 }
Len Brown0138d8f2014-04-04 01:21:07 -04001306}
1307
Len Brown26717172010-03-08 14:07:30 -05001308/*
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301309 * intel_idle_cpuidle_driver_init()
1310 * allocate, initialize cpuidle_states
1311 */
Richard Cochran5469c822016-04-06 17:00:49 -04001312static void __init intel_idle_cpuidle_driver_init(void)
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301313{
1314 int cstate;
1315 struct cpuidle_driver *drv = &intel_idle_driver;
1316
Len Brown0138d8f2014-04-04 01:21:07 -04001317 intel_idle_state_table_update();
1318
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301319 drv->state_count = 1;
1320
Len Browne022e7e2013-02-01 23:37:30 -05001321 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
Len Brown24bfa952014-02-14 00:50:34 -05001322 int num_substates, mwait_hint, mwait_cstate;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301323
Len Brown7dd0e0a2015-05-27 17:11:37 -04001324 if ((cpuidle_state_table[cstate].enter == NULL) &&
1325 (cpuidle_state_table[cstate].enter_freeze == NULL))
Len Browne022e7e2013-02-01 23:37:30 -05001326 break;
1327
1328 if (cstate + 1 > max_cstate) {
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301329 printk(PREFIX "max_cstate %d reached\n",
1330 max_cstate);
1331 break;
1332 }
1333
Len Browne022e7e2013-02-01 23:37:30 -05001334 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
1335 mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301336
Len Brown24bfa952014-02-14 00:50:34 -05001337 /* number of sub-states for this state in CPUID.MWAIT */
Len Browne022e7e2013-02-01 23:37:30 -05001338 num_substates = (mwait_substates >> ((mwait_cstate + 1) * 4))
1339 & MWAIT_SUBSTATE_MASK;
1340
Len Brown24bfa952014-02-14 00:50:34 -05001341 /* if NO sub-states for this state in CPUID, skip it */
1342 if (num_substates == 0)
Len Browne022e7e2013-02-01 23:37:30 -05001343 continue;
1344
Len Brownd70e28f2016-03-13 00:33:48 -05001345 /* if state marked as disabled, skip it */
1346 if (cpuidle_state_table[cstate].disabled != 0) {
1347 pr_debug(PREFIX "state %s is disabled",
1348 cpuidle_state_table[cstate].name);
1349 continue;
1350 }
1351
1352
Len Browne022e7e2013-02-01 23:37:30 -05001353 if (((mwait_cstate + 1) > 2) &&
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301354 !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
1355 mark_tsc_unstable("TSC halts in idle"
1356 " states deeper than C2");
1357
1358 drv->states[drv->state_count] = /* structure copy */
1359 cpuidle_state_table[cstate];
1360
1361 drv->state_count += 1;
1362 }
1363
Len Brown8c058d532014-07-31 15:21:24 -04001364 if (icpu->byt_auto_demotion_disable_flag) {
1365 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
1366 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
1367 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301368}
1369
1370
1371/*
Thomas Renninger65b7f832012-01-17 22:40:08 +01001372 * intel_idle_cpu_init()
Len Brown26717172010-03-08 14:07:30 -05001373 * allocate, initialize, register cpuidle_devices
Thomas Renninger65b7f832012-01-17 22:40:08 +01001374 * @cpu: cpu/core to initialize
Len Brown26717172010-03-08 14:07:30 -05001375 */
Daniel Lezcano25ac7762012-07-05 15:23:25 +02001376static int intel_idle_cpu_init(int cpu)
Len Brown26717172010-03-08 14:07:30 -05001377{
Len Brown26717172010-03-08 14:07:30 -05001378 struct cpuidle_device *dev;
1379
Thomas Renninger65b7f832012-01-17 22:40:08 +01001380 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
Len Brown26717172010-03-08 14:07:30 -05001381
Thomas Renninger65b7f832012-01-17 22:40:08 +01001382 dev->cpu = cpu;
Len Brown26717172010-03-08 14:07:30 -05001383
Thomas Renninger65b7f832012-01-17 22:40:08 +01001384 if (cpuidle_register_device(dev)) {
1385 pr_debug(PREFIX "cpuidle_register_device %d failed!\n", cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001386 return -EIO;
Len Brown26717172010-03-08 14:07:30 -05001387 }
1388
Andi Kleenb66b8b92012-01-26 00:09:07 +01001389 if (icpu->auto_demotion_disable_flags)
Thomas Renninger65b7f832012-01-17 22:40:08 +01001390 smp_call_function_single(cpu, auto_demotion_disable, NULL, 1);
1391
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001392 if (icpu->disable_promotion_to_c1e)
1393 smp_call_function_single(cpu, c1e_promotion_disable, NULL, 1);
1394
Len Brown26717172010-03-08 14:07:30 -05001395 return 0;
1396}
Len Brown26717172010-03-08 14:07:30 -05001397
1398static int __init intel_idle_init(void)
1399{
Thomas Renninger65b7f832012-01-17 22:40:08 +01001400 int retval, i;
Len Brown26717172010-03-08 14:07:30 -05001401
Thomas Renningerd1896042010-11-03 17:06:14 +01001402 /* Do not load intel_idle at all for now if idle= is passed */
1403 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
1404 return -ENODEV;
1405
Len Brown26717172010-03-08 14:07:30 -05001406 retval = intel_idle_probe();
1407 if (retval)
1408 return retval;
1409
Richard Cochrane9df69c2016-04-06 17:00:52 -04001410 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
1411 if (intel_idle_cpuidle_devices == NULL)
1412 return -ENOMEM;
1413
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301414 intel_idle_cpuidle_driver_init();
Len Brown26717172010-03-08 14:07:30 -05001415 retval = cpuidle_register_driver(&intel_idle_driver);
1416 if (retval) {
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001417 struct cpuidle_driver *drv = cpuidle_get_driver();
Len Brown26717172010-03-08 14:07:30 -05001418 printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001419 drv ? drv->name : "none");
Richard Cochrane9df69c2016-04-06 17:00:52 -04001420 free_percpu(intel_idle_cpuidle_devices);
Len Brown26717172010-03-08 14:07:30 -05001421 return retval;
1422 }
1423
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301424 cpu_notifier_register_begin();
1425
Thomas Renninger65b7f832012-01-17 22:40:08 +01001426 for_each_online_cpu(i) {
1427 retval = intel_idle_cpu_init(i);
1428 if (retval) {
Richard Cochranb69ef2c2016-04-06 17:00:55 -04001429 intel_idle_cpuidle_devices_uninit();
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301430 cpu_notifier_register_done();
Thomas Renninger65b7f832012-01-17 22:40:08 +01001431 cpuidle_unregister_driver(&intel_idle_driver);
Richard Cochranca424892016-04-06 17:00:53 -04001432 free_percpu(intel_idle_cpuidle_devices);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001433 return retval;
1434 }
Len Brown26717172010-03-08 14:07:30 -05001435 }
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301436 __register_cpu_notifier(&cpu_hotplug_notifier);
1437
Richard Cochran2259a812016-04-06 17:00:54 -04001438 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
1439 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
1440 else
1441 on_each_cpu(__setup_broadcast_timer, (void *)true, 1);
1442
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301443 cpu_notifier_register_done();
Len Brown26717172010-03-08 14:07:30 -05001444
Richard Cochran2259a812016-04-06 17:00:54 -04001445 pr_debug(PREFIX "lapic_timer_reliable_states 0x%x\n",
1446 lapic_timer_reliable_states);
1447
Len Brown26717172010-03-08 14:07:30 -05001448 return 0;
1449}
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001450device_initcall(intel_idle_init);
Len Brown26717172010-03-08 14:07:30 -05001451
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001452/*
1453 * We are not really modular, but we used to support that. Meaning we also
1454 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
1455 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
1456 * is the easiest way (currently) to continue doing that.
1457 */
Len Brown26717172010-03-08 14:07:30 -05001458module_param(max_cstate, int, 0444);