blob: a6fa32c7e0680236b84144b15c79d5b4a598d21c [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};
Andy Shevchenko625fd9d2017-04-04 19:32:08 +0000727static struct cpuidle_state tangier_cstates[] = {
728 {
729 .name = "C1-TNG",
730 .desc = "MWAIT 0x00",
731 .flags = MWAIT2flg(0x00),
732 .exit_latency = 1,
733 .target_residency = 4,
734 .enter = &intel_idle,
735 .enter_freeze = intel_idle_freeze, },
736 {
737 .name = "C4-TNG",
738 .desc = "MWAIT 0x30",
739 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
740 .exit_latency = 100,
741 .target_residency = 400,
742 .enter = &intel_idle,
743 .enter_freeze = intel_idle_freeze, },
744 {
745 .name = "C6-TNG",
746 .desc = "MWAIT 0x52",
747 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
748 .exit_latency = 140,
749 .target_residency = 560,
750 .enter = &intel_idle,
751 .enter_freeze = intel_idle_freeze, },
752 {
753 .name = "C7-TNG",
754 .desc = "MWAIT 0x60",
755 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
756 .exit_latency = 1200,
757 .target_residency = 4000,
758 .enter = &intel_idle,
759 .enter_freeze = intel_idle_freeze, },
760 {
761 .name = "C9-TNG",
762 .desc = "MWAIT 0x64",
763 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
764 .exit_latency = 10000,
765 .target_residency = 20000,
766 .enter = &intel_idle,
767 .enter_freeze = intel_idle_freeze, },
768 {
769 .enter = NULL }
770};
Jiang Liu88390992014-01-09 15:30:27 +0800771static struct cpuidle_state avn_cstates[] = {
Len Brownfab04b22013-11-09 00:30:17 -0500772 {
773 .name = "C1-AVN",
774 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100775 .flags = MWAIT2flg(0x00),
Len Brownfab04b22013-11-09 00:30:17 -0500776 .exit_latency = 2,
777 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100778 .enter = &intel_idle,
779 .enter_freeze = intel_idle_freeze, },
Len Brownfab04b22013-11-09 00:30:17 -0500780 {
781 .name = "C6-AVN",
782 .desc = "MWAIT 0x51",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100783 .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownfab04b22013-11-09 00:30:17 -0500784 .exit_latency = 15,
785 .target_residency = 45,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100786 .enter = &intel_idle,
787 .enter_freeze = intel_idle_freeze, },
Jiang Liu88390992014-01-09 15:30:27 +0800788 {
789 .enter = NULL }
Len Brownfab04b22013-11-09 00:30:17 -0500790};
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700791static struct cpuidle_state knl_cstates[] = {
792 {
793 .name = "C1-KNL",
794 .desc = "MWAIT 0x00",
795 .flags = MWAIT2flg(0x00),
796 .exit_latency = 1,
797 .target_residency = 2,
798 .enter = &intel_idle,
799 .enter_freeze = intel_idle_freeze },
800 {
801 .name = "C6-KNL",
802 .desc = "MWAIT 0x10",
803 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
804 .exit_latency = 120,
805 .target_residency = 500,
806 .enter = &intel_idle,
807 .enter_freeze = intel_idle_freeze },
808 {
809 .enter = NULL }
810};
Len Brown26717172010-03-08 14:07:30 -0500811
Len Brown5dcef692016-04-06 17:00:47 -0400812static struct cpuidle_state bxt_cstates[] = {
813 {
814 .name = "C1-BXT",
815 .desc = "MWAIT 0x00",
816 .flags = MWAIT2flg(0x00),
817 .exit_latency = 2,
818 .target_residency = 2,
819 .enter = &intel_idle,
820 .enter_freeze = intel_idle_freeze, },
821 {
822 .name = "C1E-BXT",
823 .desc = "MWAIT 0x01",
824 .flags = MWAIT2flg(0x01),
825 .exit_latency = 10,
826 .target_residency = 20,
827 .enter = &intel_idle,
828 .enter_freeze = intel_idle_freeze, },
829 {
830 .name = "C6-BXT",
831 .desc = "MWAIT 0x20",
832 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
833 .exit_latency = 133,
834 .target_residency = 133,
835 .enter = &intel_idle,
836 .enter_freeze = intel_idle_freeze, },
837 {
838 .name = "C7s-BXT",
839 .desc = "MWAIT 0x31",
840 .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
841 .exit_latency = 155,
842 .target_residency = 155,
843 .enter = &intel_idle,
844 .enter_freeze = intel_idle_freeze, },
845 {
846 .name = "C8-BXT",
847 .desc = "MWAIT 0x40",
848 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
849 .exit_latency = 1000,
850 .target_residency = 1000,
851 .enter = &intel_idle,
852 .enter_freeze = intel_idle_freeze, },
853 {
854 .name = "C9-BXT",
855 .desc = "MWAIT 0x50",
856 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
857 .exit_latency = 2000,
858 .target_residency = 2000,
859 .enter = &intel_idle,
860 .enter_freeze = intel_idle_freeze, },
861 {
862 .name = "C10-BXT",
863 .desc = "MWAIT 0x60",
864 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
865 .exit_latency = 10000,
866 .target_residency = 10000,
867 .enter = &intel_idle,
868 .enter_freeze = intel_idle_freeze, },
869 {
870 .enter = NULL }
871};
872
Jacob Pan0080d652016-06-17 01:28:34 -0400873static struct cpuidle_state dnv_cstates[] = {
874 {
875 .name = "C1-DNV",
876 .desc = "MWAIT 0x00",
877 .flags = MWAIT2flg(0x00),
878 .exit_latency = 2,
879 .target_residency = 2,
880 .enter = &intel_idle,
881 .enter_freeze = intel_idle_freeze, },
882 {
883 .name = "C1E-DNV",
884 .desc = "MWAIT 0x01",
885 .flags = MWAIT2flg(0x01),
886 .exit_latency = 10,
887 .target_residency = 20,
888 .enter = &intel_idle,
889 .enter_freeze = intel_idle_freeze, },
890 {
891 .name = "C6-DNV",
892 .desc = "MWAIT 0x20",
893 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
894 .exit_latency = 50,
895 .target_residency = 500,
896 .enter = &intel_idle,
897 .enter_freeze = intel_idle_freeze, },
898 {
899 .enter = NULL }
900};
901
Len Brown26717172010-03-08 14:07:30 -0500902/**
903 * intel_idle
904 * @dev: cpuidle_device
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530905 * @drv: cpuidle driver
Deepthi Dharware978aa72011-10-28 16:20:09 +0530906 * @index: index of cpuidle state
Len Brown26717172010-03-08 14:07:30 -0500907 *
Yanmin Zhang63ff07b2012-01-10 15:48:21 -0800908 * Must be called under local_irq_disable().
Len Brown26717172010-03-08 14:07:30 -0500909 */
Chris Metcalf6727ad92016-10-07 17:02:55 -0700910static __cpuidle int intel_idle(struct cpuidle_device *dev,
911 struct cpuidle_driver *drv, int index)
Len Brown26717172010-03-08 14:07:30 -0500912{
913 unsigned long ecx = 1; /* break on interrupt flag */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530914 struct cpuidle_state *state = &drv->states[index];
Len Brownb1beab42013-01-31 19:55:37 -0500915 unsigned long eax = flg2MWAIT(state->flags);
Len Brown26717172010-03-08 14:07:30 -0500916 unsigned int cstate;
Len Brown26717172010-03-08 14:07:30 -0500917 int cpu = smp_processor_id();
918
919 cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) + 1;
920
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400921 /*
Len Brownc8381cc2010-10-15 20:43:06 -0400922 * leave_mm() to avoid costly and often unnecessary wakeups
923 * for flushing the user TLB's associated with the active mm.
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400924 */
Len Brownc8381cc2010-10-15 20:43:06 -0400925 if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400926 leave_mm(cpu);
927
Len Brown26717172010-03-08 14:07:30 -0500928 if (!(lapic_timer_reliable_states & (1 << (cstate))))
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200929 tick_broadcast_enter();
Len Brown26717172010-03-08 14:07:30 -0500930
Peter Zijlstra16824252013-12-12 15:08:36 +0100931 mwait_idle_with_hints(eax, ecx);
Len Brown26717172010-03-08 14:07:30 -0500932
Len Brown26717172010-03-08 14:07:30 -0500933 if (!(lapic_timer_reliable_states & (1 << (cstate))))
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200934 tick_broadcast_exit();
Len Brown26717172010-03-08 14:07:30 -0500935
Deepthi Dharware978aa72011-10-28 16:20:09 +0530936 return index;
Len Brown26717172010-03-08 14:07:30 -0500937}
938
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100939/**
940 * intel_idle_freeze - simplified "enter" callback routine for suspend-to-idle
941 * @dev: cpuidle_device
942 * @drv: cpuidle driver
943 * @index: state index
944 */
945static void intel_idle_freeze(struct cpuidle_device *dev,
946 struct cpuidle_driver *drv, int index)
947{
948 unsigned long ecx = 1; /* break on interrupt flag */
949 unsigned long eax = flg2MWAIT(drv->states[index].flags);
950
951 mwait_idle_with_hints(eax, ecx);
952}
953
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800954static void __setup_broadcast_timer(void *arg)
955{
Thomas Gleixner76962ca2015-04-03 02:02:34 +0200956 unsigned long on = (unsigned long)arg;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800957
Thomas Gleixner76962ca2015-04-03 02:02:34 +0200958 if (on)
959 tick_broadcast_enable();
960 else
961 tick_broadcast_disable();
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800962}
963
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200964static int cpu_hotplug_notify(struct notifier_block *n,
965 unsigned long action, void *hcpu)
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800966{
967 int hotcpu = (unsigned long)hcpu;
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200968 struct cpuidle_device *dev;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800969
Prarit Bhargavae2401452013-10-23 09:44:51 -0400970 switch (action & ~CPU_TASKS_FROZEN) {
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800971 case CPU_ONLINE:
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200972
973 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
974 smp_call_function_single(hotcpu, __setup_broadcast_timer,
975 (void *)true, 1);
976
977 /*
978 * Some systems can hotplug a cpu at runtime after
979 * the kernel has booted, we have to initialize the
980 * driver in this case
981 */
982 dev = per_cpu_ptr(intel_idle_cpuidle_devices, hotcpu);
Richard Cochran08820542016-04-06 17:00:56 -0400983 if (dev->registered)
984 break;
985
986 if (intel_idle_cpu_init(hotcpu))
987 return NOTIFY_BAD;
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200988
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800989 break;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800990 }
991 return NOTIFY_OK;
992}
993
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200994static struct notifier_block cpu_hotplug_notifier = {
995 .notifier_call = cpu_hotplug_notify,
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800996};
997
Len Brown14796fc2011-01-18 20:48:27 -0500998static void auto_demotion_disable(void *dummy)
999{
1000 unsigned long long msr_bits;
1001
1002 rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
Andi Kleenb66b8b92012-01-26 00:09:07 +01001003 msr_bits &= ~(icpu->auto_demotion_disable_flags);
Len Brown14796fc2011-01-18 20:48:27 -05001004 wrmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
1005}
Len Brown32e95182013-02-02 01:31:56 -05001006static void c1e_promotion_disable(void *dummy)
1007{
1008 unsigned long long msr_bits;
1009
1010 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
1011 msr_bits &= ~0x2;
1012 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
1013}
Len Brown14796fc2011-01-18 20:48:27 -05001014
Andi Kleenb66b8b92012-01-26 00:09:07 +01001015static const struct idle_cpu idle_cpu_nehalem = {
1016 .state_table = nehalem_cstates,
Andi Kleenb66b8b92012-01-26 00:09:07 +01001017 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
Len Brown32e95182013-02-02 01:31:56 -05001018 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +01001019};
1020
1021static const struct idle_cpu idle_cpu_atom = {
1022 .state_table = atom_cstates,
1023};
1024
Andy Shevchenko625fd9d2017-04-04 19:32:08 +00001025static const struct idle_cpu idle_cpu_tangier = {
1026 .state_table = tangier_cstates,
1027};
1028
Andi Kleenb66b8b92012-01-26 00:09:07 +01001029static const struct idle_cpu idle_cpu_lincroft = {
1030 .state_table = atom_cstates,
1031 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
1032};
1033
1034static const struct idle_cpu idle_cpu_snb = {
1035 .state_table = snb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001036 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +01001037};
1038
Len Brown718987d2014-02-14 02:30:00 -05001039static const struct idle_cpu idle_cpu_byt = {
1040 .state_table = byt_cstates,
1041 .disable_promotion_to_c1e = true,
Len Brown8c058d532014-07-31 15:21:24 -04001042 .byt_auto_demotion_disable_flag = true,
Len Brown718987d2014-02-14 02:30:00 -05001043};
1044
Len Browncab07a52015-03-27 20:54:01 -04001045static const struct idle_cpu idle_cpu_cht = {
1046 .state_table = cht_cstates,
1047 .disable_promotion_to_c1e = true,
1048 .byt_auto_demotion_disable_flag = true,
1049};
1050
Len Brown6edab082012-06-01 19:45:32 -04001051static const struct idle_cpu idle_cpu_ivb = {
1052 .state_table = ivb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001053 .disable_promotion_to_c1e = true,
Len Brown6edab082012-06-01 19:45:32 -04001054};
1055
Len Brown0138d8f2014-04-04 01:21:07 -04001056static const struct idle_cpu idle_cpu_ivt = {
1057 .state_table = ivt_cstates,
1058 .disable_promotion_to_c1e = true,
1059};
1060
Len Brown85a4d2d2013-01-31 14:40:49 -05001061static const struct idle_cpu idle_cpu_hsw = {
1062 .state_table = hsw_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001063 .disable_promotion_to_c1e = true,
Len Brown85a4d2d2013-01-31 14:40:49 -05001064};
1065
Len Browna138b562014-02-04 23:56:40 -05001066static const struct idle_cpu idle_cpu_bdw = {
1067 .state_table = bdw_cstates,
1068 .disable_promotion_to_c1e = true,
1069};
1070
Len Brown493f1332015-03-25 23:20:37 -04001071static const struct idle_cpu idle_cpu_skl = {
1072 .state_table = skl_cstates,
1073 .disable_promotion_to_c1e = true,
1074};
1075
Len Brownf9e71652016-04-06 17:00:58 -04001076static const struct idle_cpu idle_cpu_skx = {
1077 .state_table = skx_cstates,
1078 .disable_promotion_to_c1e = true,
1079};
Len Brown493f1332015-03-25 23:20:37 -04001080
Len Brownfab04b22013-11-09 00:30:17 -05001081static const struct idle_cpu idle_cpu_avn = {
1082 .state_table = avn_cstates,
1083 .disable_promotion_to_c1e = true,
1084};
1085
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001086static const struct idle_cpu idle_cpu_knl = {
1087 .state_table = knl_cstates,
1088};
1089
Len Brown5dcef692016-04-06 17:00:47 -04001090static const struct idle_cpu idle_cpu_bxt = {
1091 .state_table = bxt_cstates,
1092 .disable_promotion_to_c1e = true,
1093};
1094
Jacob Pan0080d652016-06-17 01:28:34 -04001095static const struct idle_cpu idle_cpu_dnv = {
1096 .state_table = dnv_cstates,
1097 .disable_promotion_to_c1e = true,
1098};
1099
Andi Kleenb66b8b92012-01-26 00:09:07 +01001100#define ICPU(model, cpu) \
1101 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&cpu }
1102
Mathias Kraused5cdc3c2015-03-25 22:15:14 +01001103static const struct x86_cpu_id intel_idle_ids[] __initconst = {
Dave Hansendb73c5a2016-06-02 17:19:32 -07001104 ICPU(INTEL_FAM6_NEHALEM_EP, idle_cpu_nehalem),
1105 ICPU(INTEL_FAM6_NEHALEM, idle_cpu_nehalem),
Dave Hansen4b3b2342016-06-29 12:27:37 -07001106 ICPU(INTEL_FAM6_NEHALEM_G, idle_cpu_nehalem),
Dave Hansendb73c5a2016-06-02 17:19:32 -07001107 ICPU(INTEL_FAM6_WESTMERE, idle_cpu_nehalem),
1108 ICPU(INTEL_FAM6_WESTMERE_EP, idle_cpu_nehalem),
1109 ICPU(INTEL_FAM6_NEHALEM_EX, idle_cpu_nehalem),
Peter Zijlstra1739ba82018-08-07 10:17:27 -07001110 ICPU(INTEL_FAM6_ATOM_BONNELL, idle_cpu_atom),
1111 ICPU(INTEL_FAM6_ATOM_BONNELL_MID, idle_cpu_lincroft),
Dave Hansendb73c5a2016-06-02 17:19:32 -07001112 ICPU(INTEL_FAM6_WESTMERE_EX, idle_cpu_nehalem),
1113 ICPU(INTEL_FAM6_SANDYBRIDGE, idle_cpu_snb),
1114 ICPU(INTEL_FAM6_SANDYBRIDGE_X, idle_cpu_snb),
Peter Zijlstra1739ba82018-08-07 10:17:27 -07001115 ICPU(INTEL_FAM6_ATOM_SALTWELL, idle_cpu_atom),
1116 ICPU(INTEL_FAM6_ATOM_SILVERMONT, idle_cpu_byt),
1117 ICPU(INTEL_FAM6_ATOM_SILVERMONT_MID, idle_cpu_tangier),
Dave Hansendb73c5a2016-06-02 17:19:32 -07001118 ICPU(INTEL_FAM6_ATOM_AIRMONT, idle_cpu_cht),
1119 ICPU(INTEL_FAM6_IVYBRIDGE, idle_cpu_ivb),
1120 ICPU(INTEL_FAM6_IVYBRIDGE_X, idle_cpu_ivt),
1121 ICPU(INTEL_FAM6_HASWELL_CORE, idle_cpu_hsw),
1122 ICPU(INTEL_FAM6_HASWELL_X, idle_cpu_hsw),
1123 ICPU(INTEL_FAM6_HASWELL_ULT, idle_cpu_hsw),
1124 ICPU(INTEL_FAM6_HASWELL_GT3E, idle_cpu_hsw),
Peter Zijlstra1739ba82018-08-07 10:17:27 -07001125 ICPU(INTEL_FAM6_ATOM_SILVERMONT_X, idle_cpu_avn),
Dave Hansendb73c5a2016-06-02 17:19:32 -07001126 ICPU(INTEL_FAM6_BROADWELL_CORE, idle_cpu_bdw),
1127 ICPU(INTEL_FAM6_BROADWELL_GT3E, idle_cpu_bdw),
1128 ICPU(INTEL_FAM6_BROADWELL_X, idle_cpu_bdw),
1129 ICPU(INTEL_FAM6_BROADWELL_XEON_D, idle_cpu_bdw),
1130 ICPU(INTEL_FAM6_SKYLAKE_MOBILE, idle_cpu_skl),
1131 ICPU(INTEL_FAM6_SKYLAKE_DESKTOP, idle_cpu_skl),
1132 ICPU(INTEL_FAM6_KABYLAKE_MOBILE, idle_cpu_skl),
1133 ICPU(INTEL_FAM6_KABYLAKE_DESKTOP, idle_cpu_skl),
1134 ICPU(INTEL_FAM6_SKYLAKE_X, idle_cpu_skx),
1135 ICPU(INTEL_FAM6_XEON_PHI_KNL, idle_cpu_knl),
1136 ICPU(INTEL_FAM6_ATOM_GOLDMONT, idle_cpu_bxt),
Peter Zijlstra1739ba82018-08-07 10:17:27 -07001137 ICPU(INTEL_FAM6_ATOM_GOLDMONT_X, idle_cpu_dnv),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001138 {}
1139};
Andi Kleenb66b8b92012-01-26 00:09:07 +01001140
Len Brown26717172010-03-08 14:07:30 -05001141/*
1142 * intel_idle_probe()
1143 */
Bartlomiej Zolnierkiewicz00f3e752013-08-30 12:27:45 +02001144static int __init intel_idle_probe(void)
Len Brown26717172010-03-08 14:07:30 -05001145{
Len Brownc4236282010-05-28 02:22:03 -04001146 unsigned int eax, ebx, ecx;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001147 const struct x86_cpu_id *id;
Len Brown26717172010-03-08 14:07:30 -05001148
1149 if (max_cstate == 0) {
1150 pr_debug(PREFIX "disabled\n");
1151 return -EPERM;
1152 }
1153
Andi Kleenb66b8b92012-01-26 00:09:07 +01001154 id = x86_match_cpu(intel_idle_ids);
1155 if (!id) {
1156 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
1157 boot_cpu_data.x86 == 6)
1158 pr_debug(PREFIX "does not run on family %d model %d\n",
1159 boot_cpu_data.x86, boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001160 return -ENODEV;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001161 }
Len Brown26717172010-03-08 14:07:30 -05001162
1163 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
1164 return -ENODEV;
1165
Len Brownc4236282010-05-28 02:22:03 -04001166 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001167
1168 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
Thomas Renninger5c2a9f02011-12-04 22:17:29 +01001169 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
1170 !mwait_substates)
Len Brown26717172010-03-08 14:07:30 -05001171 return -ENODEV;
Len Brown26717172010-03-08 14:07:30 -05001172
Len Brownc4236282010-05-28 02:22:03 -04001173 pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001174
Andi Kleenb66b8b92012-01-26 00:09:07 +01001175 icpu = (const struct idle_cpu *)id->driver_data;
1176 cpuidle_state_table = icpu->state_table;
Len Brown26717172010-03-08 14:07:30 -05001177
1178 pr_debug(PREFIX "v" INTEL_IDLE_VERSION
1179 " model 0x%X\n", boot_cpu_data.x86_model);
1180
Len Brown26717172010-03-08 14:07:30 -05001181 return 0;
1182}
1183
1184/*
1185 * intel_idle_cpuidle_devices_uninit()
Richard Cochranca424892016-04-06 17:00:53 -04001186 * Unregisters the cpuidle devices.
Len Brown26717172010-03-08 14:07:30 -05001187 */
1188static void intel_idle_cpuidle_devices_uninit(void)
1189{
1190 int i;
1191 struct cpuidle_device *dev;
1192
1193 for_each_online_cpu(i) {
1194 dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
1195 cpuidle_unregister_device(dev);
1196 }
Len Brown26717172010-03-08 14:07:30 -05001197}
Len Brown0138d8f2014-04-04 01:21:07 -04001198
1199/*
Len Brownd70e28f2016-03-13 00:33:48 -05001200 * ivt_idle_state_table_update(void)
1201 *
1202 * Tune IVT multi-socket targets
1203 * Assumption: num_sockets == (max_package_num + 1)
1204 */
1205static void ivt_idle_state_table_update(void)
1206{
1207 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1208 int cpu, package_num, num_sockets = 1;
1209
1210 for_each_online_cpu(cpu) {
1211 package_num = topology_physical_package_id(cpu);
1212 if (package_num + 1 > num_sockets) {
1213 num_sockets = package_num + 1;
1214
1215 if (num_sockets > 4) {
1216 cpuidle_state_table = ivt_cstates_8s;
1217 return;
1218 }
1219 }
1220 }
1221
1222 if (num_sockets > 2)
1223 cpuidle_state_table = ivt_cstates_4s;
1224
1225 /* else, 1 and 2 socket systems use default ivt_cstates */
1226}
Len Brown5dcef692016-04-06 17:00:47 -04001227
1228/*
1229 * Translate IRTL (Interrupt Response Time Limit) MSR to usec
1230 */
1231
1232static unsigned int irtl_ns_units[] = {
1233 1, 32, 1024, 32768, 1048576, 33554432, 0, 0 };
1234
1235static unsigned long long irtl_2_usec(unsigned long long irtl)
1236{
1237 unsigned long long ns;
1238
Jan Beulich3451ab32016-06-27 00:35:12 -06001239 if (!irtl)
1240 return 0;
1241
Jan Beulichbef45092016-06-27 00:35:48 -06001242 ns = irtl_ns_units[(irtl >> 10) & 0x7];
Len Brown5dcef692016-04-06 17:00:47 -04001243
1244 return div64_u64((irtl & 0x3FF) * ns, 1000);
1245}
1246/*
1247 * bxt_idle_state_table_update(void)
1248 *
1249 * On BXT, we trust the IRTL to show the definitive maximum latency
1250 * We use the same value for target_residency.
1251 */
1252static void bxt_idle_state_table_update(void)
1253{
1254 unsigned long long msr;
Jan Beulich3451ab32016-06-27 00:35:12 -06001255 unsigned int usec;
Len Brown5dcef692016-04-06 17:00:47 -04001256
1257 rdmsrl(MSR_PKGC6_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001258 usec = irtl_2_usec(msr);
1259 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001260 bxt_cstates[2].exit_latency = usec;
1261 bxt_cstates[2].target_residency = usec;
1262 }
1263
1264 rdmsrl(MSR_PKGC7_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001265 usec = irtl_2_usec(msr);
1266 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001267 bxt_cstates[3].exit_latency = usec;
1268 bxt_cstates[3].target_residency = usec;
1269 }
1270
1271 rdmsrl(MSR_PKGC8_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001272 usec = irtl_2_usec(msr);
1273 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001274 bxt_cstates[4].exit_latency = usec;
1275 bxt_cstates[4].target_residency = usec;
1276 }
1277
1278 rdmsrl(MSR_PKGC9_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001279 usec = irtl_2_usec(msr);
1280 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001281 bxt_cstates[5].exit_latency = usec;
1282 bxt_cstates[5].target_residency = usec;
1283 }
1284
1285 rdmsrl(MSR_PKGC10_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001286 usec = irtl_2_usec(msr);
1287 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001288 bxt_cstates[6].exit_latency = usec;
1289 bxt_cstates[6].target_residency = usec;
1290 }
1291
1292}
Len Brownd70e28f2016-03-13 00:33:48 -05001293/*
1294 * sklh_idle_state_table_update(void)
1295 *
1296 * On SKL-H (model 0x5e) disable C8 and C9 if:
1297 * C10 is enabled and SGX disabled
1298 */
1299static void sklh_idle_state_table_update(void)
1300{
1301 unsigned long long msr;
1302 unsigned int eax, ebx, ecx, edx;
1303
1304
1305 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1306 if (max_cstate <= 7)
1307 return;
1308
1309 /* if PC10 not present in CPUID.MWAIT.EDX */
1310 if ((mwait_substates & (0xF << 28)) == 0)
1311 return;
1312
1313 rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr);
1314
1315 /* PC10 is not enabled in PKG C-state limit */
1316 if ((msr & 0xF) != 8)
1317 return;
1318
1319 ecx = 0;
1320 cpuid(7, &eax, &ebx, &ecx, &edx);
1321
1322 /* if SGX is present */
1323 if (ebx & (1 << 2)) {
1324
1325 rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
1326
1327 /* if SGX is enabled */
1328 if (msr & (1 << 18))
1329 return;
1330 }
1331
1332 skl_cstates[5].disabled = 1; /* C8-SKL */
1333 skl_cstates[6].disabled = 1; /* C9-SKL */
1334}
1335/*
Len Brown0138d8f2014-04-04 01:21:07 -04001336 * intel_idle_state_table_update()
1337 *
1338 * Update the default state_table for this CPU-id
Len Brown0138d8f2014-04-04 01:21:07 -04001339 */
Len Brownd70e28f2016-03-13 00:33:48 -05001340
1341static void intel_idle_state_table_update(void)
Len Brown0138d8f2014-04-04 01:21:07 -04001342{
Len Brownd70e28f2016-03-13 00:33:48 -05001343 switch (boot_cpu_data.x86_model) {
Len Brown0138d8f2014-04-04 01:21:07 -04001344
Dave Hansendb73c5a2016-06-02 17:19:32 -07001345 case INTEL_FAM6_IVYBRIDGE_X:
Len Brownd70e28f2016-03-13 00:33:48 -05001346 ivt_idle_state_table_update();
1347 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001348 case INTEL_FAM6_ATOM_GOLDMONT:
Len Brown5dcef692016-04-06 17:00:47 -04001349 bxt_idle_state_table_update();
1350 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001351 case INTEL_FAM6_SKYLAKE_DESKTOP:
Len Brownd70e28f2016-03-13 00:33:48 -05001352 sklh_idle_state_table_update();
1353 break;
Len Brown0138d8f2014-04-04 01:21:07 -04001354 }
Len Brown0138d8f2014-04-04 01:21:07 -04001355}
1356
Len Brown26717172010-03-08 14:07:30 -05001357/*
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301358 * intel_idle_cpuidle_driver_init()
1359 * allocate, initialize cpuidle_states
1360 */
Richard Cochran5469c822016-04-06 17:00:49 -04001361static void __init intel_idle_cpuidle_driver_init(void)
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301362{
1363 int cstate;
1364 struct cpuidle_driver *drv = &intel_idle_driver;
1365
Len Brown0138d8f2014-04-04 01:21:07 -04001366 intel_idle_state_table_update();
1367
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301368 drv->state_count = 1;
1369
Len Browne022e7e2013-02-01 23:37:30 -05001370 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
Len Brown24bfa952014-02-14 00:50:34 -05001371 int num_substates, mwait_hint, mwait_cstate;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301372
Len Brown7dd0e0a2015-05-27 17:11:37 -04001373 if ((cpuidle_state_table[cstate].enter == NULL) &&
1374 (cpuidle_state_table[cstate].enter_freeze == NULL))
Len Browne022e7e2013-02-01 23:37:30 -05001375 break;
1376
1377 if (cstate + 1 > max_cstate) {
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301378 printk(PREFIX "max_cstate %d reached\n",
1379 max_cstate);
1380 break;
1381 }
1382
Len Browne022e7e2013-02-01 23:37:30 -05001383 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
1384 mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301385
Len Brown24bfa952014-02-14 00:50:34 -05001386 /* number of sub-states for this state in CPUID.MWAIT */
Len Browne022e7e2013-02-01 23:37:30 -05001387 num_substates = (mwait_substates >> ((mwait_cstate + 1) * 4))
1388 & MWAIT_SUBSTATE_MASK;
1389
Len Brown24bfa952014-02-14 00:50:34 -05001390 /* if NO sub-states for this state in CPUID, skip it */
1391 if (num_substates == 0)
Len Browne022e7e2013-02-01 23:37:30 -05001392 continue;
1393
Len Brownd70e28f2016-03-13 00:33:48 -05001394 /* if state marked as disabled, skip it */
1395 if (cpuidle_state_table[cstate].disabled != 0) {
1396 pr_debug(PREFIX "state %s is disabled",
1397 cpuidle_state_table[cstate].name);
1398 continue;
1399 }
1400
1401
Len Browne022e7e2013-02-01 23:37:30 -05001402 if (((mwait_cstate + 1) > 2) &&
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301403 !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
1404 mark_tsc_unstable("TSC halts in idle"
1405 " states deeper than C2");
1406
1407 drv->states[drv->state_count] = /* structure copy */
1408 cpuidle_state_table[cstate];
1409
1410 drv->state_count += 1;
1411 }
1412
Len Brown8c058d532014-07-31 15:21:24 -04001413 if (icpu->byt_auto_demotion_disable_flag) {
1414 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
1415 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
1416 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301417}
1418
1419
1420/*
Thomas Renninger65b7f832012-01-17 22:40:08 +01001421 * intel_idle_cpu_init()
Len Brown26717172010-03-08 14:07:30 -05001422 * allocate, initialize, register cpuidle_devices
Thomas Renninger65b7f832012-01-17 22:40:08 +01001423 * @cpu: cpu/core to initialize
Len Brown26717172010-03-08 14:07:30 -05001424 */
Daniel Lezcano25ac7762012-07-05 15:23:25 +02001425static int intel_idle_cpu_init(int cpu)
Len Brown26717172010-03-08 14:07:30 -05001426{
Len Brown26717172010-03-08 14:07:30 -05001427 struct cpuidle_device *dev;
1428
Thomas Renninger65b7f832012-01-17 22:40:08 +01001429 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
Len Brown26717172010-03-08 14:07:30 -05001430
Thomas Renninger65b7f832012-01-17 22:40:08 +01001431 dev->cpu = cpu;
Len Brown26717172010-03-08 14:07:30 -05001432
Thomas Renninger65b7f832012-01-17 22:40:08 +01001433 if (cpuidle_register_device(dev)) {
1434 pr_debug(PREFIX "cpuidle_register_device %d failed!\n", cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001435 return -EIO;
Len Brown26717172010-03-08 14:07:30 -05001436 }
1437
Andi Kleenb66b8b92012-01-26 00:09:07 +01001438 if (icpu->auto_demotion_disable_flags)
Thomas Renninger65b7f832012-01-17 22:40:08 +01001439 smp_call_function_single(cpu, auto_demotion_disable, NULL, 1);
1440
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001441 if (icpu->disable_promotion_to_c1e)
1442 smp_call_function_single(cpu, c1e_promotion_disable, NULL, 1);
1443
Len Brown26717172010-03-08 14:07:30 -05001444 return 0;
1445}
Len Brown26717172010-03-08 14:07:30 -05001446
1447static int __init intel_idle_init(void)
1448{
Thomas Renninger65b7f832012-01-17 22:40:08 +01001449 int retval, i;
Len Brown26717172010-03-08 14:07:30 -05001450
Thomas Renningerd1896042010-11-03 17:06:14 +01001451 /* Do not load intel_idle at all for now if idle= is passed */
1452 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
1453 return -ENODEV;
1454
Len Brown26717172010-03-08 14:07:30 -05001455 retval = intel_idle_probe();
1456 if (retval)
1457 return retval;
1458
Richard Cochrane9df69c2016-04-06 17:00:52 -04001459 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
1460 if (intel_idle_cpuidle_devices == NULL)
1461 return -ENOMEM;
1462
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301463 intel_idle_cpuidle_driver_init();
Len Brown26717172010-03-08 14:07:30 -05001464 retval = cpuidle_register_driver(&intel_idle_driver);
1465 if (retval) {
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001466 struct cpuidle_driver *drv = cpuidle_get_driver();
Len Brown26717172010-03-08 14:07:30 -05001467 printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001468 drv ? drv->name : "none");
Richard Cochrane9df69c2016-04-06 17:00:52 -04001469 free_percpu(intel_idle_cpuidle_devices);
Len Brown26717172010-03-08 14:07:30 -05001470 return retval;
1471 }
1472
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301473 cpu_notifier_register_begin();
1474
Thomas Renninger65b7f832012-01-17 22:40:08 +01001475 for_each_online_cpu(i) {
1476 retval = intel_idle_cpu_init(i);
1477 if (retval) {
Richard Cochranb69ef2c2016-04-06 17:00:55 -04001478 intel_idle_cpuidle_devices_uninit();
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301479 cpu_notifier_register_done();
Thomas Renninger65b7f832012-01-17 22:40:08 +01001480 cpuidle_unregister_driver(&intel_idle_driver);
Richard Cochranca424892016-04-06 17:00:53 -04001481 free_percpu(intel_idle_cpuidle_devices);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001482 return retval;
1483 }
Len Brown26717172010-03-08 14:07:30 -05001484 }
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301485 __register_cpu_notifier(&cpu_hotplug_notifier);
1486
Richard Cochran2259a812016-04-06 17:00:54 -04001487 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
1488 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
1489 else
1490 on_each_cpu(__setup_broadcast_timer, (void *)true, 1);
1491
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301492 cpu_notifier_register_done();
Len Brown26717172010-03-08 14:07:30 -05001493
Richard Cochran2259a812016-04-06 17:00:54 -04001494 pr_debug(PREFIX "lapic_timer_reliable_states 0x%x\n",
1495 lapic_timer_reliable_states);
1496
Len Brown26717172010-03-08 14:07:30 -05001497 return 0;
1498}
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001499device_initcall(intel_idle_init);
Len Brown26717172010-03-08 14:07:30 -05001500
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001501/*
1502 * We are not really modular, but we used to support that. Meaning we also
1503 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
1504 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
1505 * is the easiest way (currently) to continue doing that.
1506 */
Len Brown26717172010-03-08 14:07:30 -05001507module_param(max_cstate, int, 0444);