blob: c96649292b556f18647f1dc2a3fa075cfe176ae8 [file] [log] [blame]
Len Brown26717172010-03-08 14:07:30 -05001/*
2 * intel_idle.c - native hardware idle loop for modern Intel processors
3 *
Len Brownfab04b22013-11-09 00:30:17 -05004 * Copyright (c) 2013, Intel Corporation.
Len Brown26717172010-03-08 14:07:30 -05005 * Len Brown <len.brown@intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms and conditions of the GNU General Public License,
9 * version 2, as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21/*
22 * intel_idle is a cpuidle driver that loads on specific Intel processors
23 * in lieu of the legacy ACPI processor_idle driver. The intent is to
24 * make Linux more efficient on these processors, as intel_idle knows
25 * more than ACPI, as well as make Linux more immune to ACPI BIOS bugs.
26 */
27
28/*
29 * Design Assumptions
30 *
31 * All CPUs have same idle states as boot CPU
32 *
33 * Chipset BM_STS (bus master status) bit is a NOP
34 * for preventing entry into deep C-stats
35 */
36
37/*
38 * Known limitations
39 *
40 * The driver currently initializes for_each_online_cpu() upon modprobe.
41 * It it unaware of subsequent processors hot-added to the system.
42 * This means that if you boot with maxcpus=n and later online
43 * processors above n, those processors will use C1 only.
44 *
45 * ACPI has a .suspend hack to turn off deep c-statees during suspend
46 * to avoid complications with the lapic timer workaround.
47 * Have not seen issues with suspend, but may need same workaround here.
48 *
49 * There is currently no kernel-based automatic probing/loading mechanism
50 * if the driver is built as a module.
51 */
52
53/* un-comment DEBUG to enable pr_debug() statements */
54#define DEBUG
55
56#include <linux/kernel.h>
57#include <linux/cpuidle.h>
Thomas Gleixner76962ca2015-04-03 02:02:34 +020058#include <linux/tick.h>
Len Brown26717172010-03-08 14:07:30 -050059#include <trace/events/power.h>
60#include <linux/sched.h>
Shaohua Li2a2d31c2011-01-10 09:38:12 +080061#include <linux/notifier.h>
62#include <linux/cpu.h>
Paul Gortmaker7c52d552011-05-27 12:33:10 -040063#include <linux/module.h>
Andi Kleenb66b8b92012-01-26 00:09:07 +010064#include <asm/cpu_device_id.h>
H. Peter Anvinbc83ccc2010-09-17 15:36:40 -070065#include <asm/mwait.h>
Len Brown14796fc2011-01-18 20:48:27 -050066#include <asm/msr.h>
Len Brown26717172010-03-08 14:07:30 -050067
Len Brownd70e28f2016-03-13 00:33:48 -050068#define INTEL_IDLE_VERSION "0.4.1"
Len Brown26717172010-03-08 14:07:30 -050069#define PREFIX "intel_idle: "
70
Len Brown26717172010-03-08 14:07:30 -050071static struct cpuidle_driver intel_idle_driver = {
72 .name = "intel_idle",
73 .owner = THIS_MODULE,
74};
75/* intel_idle.max_cstate=0 disables driver */
Len Brown137ecc72013-02-01 21:35:35 -050076static int max_cstate = CPUIDLE_STATE_MAX - 1;
Len Brown26717172010-03-08 14:07:30 -050077
Len Brownc4236282010-05-28 02:22:03 -040078static unsigned int mwait_substates;
Len Brown26717172010-03-08 14:07:30 -050079
Shaohua Li2a2d31c2011-01-10 09:38:12 +080080#define LAPIC_TIMER_ALWAYS_RELIABLE 0xFFFFFFFF
Len Brown26717172010-03-08 14:07:30 -050081/* Reliable LAPIC Timer States, bit 1 for C1 etc. */
Len Brownd13780d2010-07-07 00:12:03 -040082static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
Len Brown26717172010-03-08 14:07:30 -050083
Andi Kleenb66b8b92012-01-26 00:09:07 +010084struct idle_cpu {
85 struct cpuidle_state *state_table;
86
87 /*
88 * Hardware C-state auto-demotion may not always be optimal.
89 * Indicate which enable bits to clear here.
90 */
91 unsigned long auto_demotion_disable_flags;
Len Brown8c058d532014-07-31 15:21:24 -040092 bool byt_auto_demotion_disable_flag;
Len Brown32e95182013-02-02 01:31:56 -050093 bool disable_promotion_to_c1e;
Andi Kleenb66b8b92012-01-26 00:09:07 +010094};
95
96static const struct idle_cpu *icpu;
Namhyung Kim3265eba2010-08-08 03:10:03 +090097static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053098static int intel_idle(struct cpuidle_device *dev,
99 struct cpuidle_driver *drv, int index);
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100100static void intel_idle_freeze(struct cpuidle_device *dev,
101 struct cpuidle_driver *drv, int index);
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200102static int intel_idle_cpu_init(int cpu);
Len Brown26717172010-03-08 14:07:30 -0500103
104static struct cpuidle_state *cpuidle_state_table;
105
106/*
Len Brown956d0332011-01-12 02:51:20 -0500107 * Set this flag for states where the HW flushes the TLB for us
108 * and so we don't need cross-calls to keep it consistent.
109 * If this flag is set, SW flushes the TLB, so even if the
110 * HW doesn't do the flushing, this flag is safe to use.
111 */
112#define CPUIDLE_FLAG_TLB_FLUSHED 0x10000
113
114/*
Len Brownb1beab42013-01-31 19:55:37 -0500115 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
116 * the C-state (top nibble) and sub-state (bottom nibble)
117 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
118 *
119 * We store the hint at the top of our "flags" for each state.
120 */
121#define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
122#define MWAIT2flg(eax) ((eax & 0xFF) << 24)
123
124/*
Len Brown26717172010-03-08 14:07:30 -0500125 * States are indexed by the cstate number,
126 * which is also the index into the MWAIT hint array.
127 * Thus C0 is a dummy.
128 */
Jiang Liuba0dc812014-01-09 15:30:26 +0800129static struct cpuidle_state nehalem_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500130 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100131 .name = "C1-NHM",
Len Brown26717172010-03-08 14:07:30 -0500132 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100133 .flags = MWAIT2flg(0x00),
Len Brown26717172010-03-08 14:07:30 -0500134 .exit_latency = 3,
Len Brown26717172010-03-08 14:07:30 -0500135 .target_residency = 6,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100136 .enter = &intel_idle,
137 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500138 {
Len Brown32e95182013-02-02 01:31:56 -0500139 .name = "C1E-NHM",
140 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100141 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500142 .exit_latency = 10,
143 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100144 .enter = &intel_idle,
145 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500146 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100147 .name = "C3-NHM",
Len Brown26717172010-03-08 14:07:30 -0500148 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100149 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500150 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500151 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100152 .enter = &intel_idle,
153 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500154 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100155 .name = "C6-NHM",
Len Brown26717172010-03-08 14:07:30 -0500156 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100157 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500158 .exit_latency = 200,
Len Brown26717172010-03-08 14:07:30 -0500159 .target_residency = 800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100160 .enter = &intel_idle,
161 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500162 {
163 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500164};
165
Jiang Liuba0dc812014-01-09 15:30:26 +0800166static struct cpuidle_state snb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500167 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100168 .name = "C1-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400169 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100170 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500171 .exit_latency = 2,
172 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100173 .enter = &intel_idle,
174 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500175 {
176 .name = "C1E-SNB",
177 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100178 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500179 .exit_latency = 10,
180 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100181 .enter = &intel_idle,
182 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500183 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100184 .name = "C3-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400185 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100186 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400187 .exit_latency = 80,
Len Brownddbd5502010-12-13 18:28:22 -0500188 .target_residency = 211,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100189 .enter = &intel_idle,
190 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500191 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100192 .name = "C6-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400193 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100194 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400195 .exit_latency = 104,
Len Brownddbd5502010-12-13 18:28:22 -0500196 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100197 .enter = &intel_idle,
198 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500199 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100200 .name = "C7-SNB",
Len Brownd13780d2010-07-07 00:12:03 -0400201 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100202 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400203 .exit_latency = 109,
Len Brownddbd5502010-12-13 18:28:22 -0500204 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100205 .enter = &intel_idle,
206 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500207 {
208 .enter = NULL }
Len Brownd13780d2010-07-07 00:12:03 -0400209};
210
Len Brown718987d2014-02-14 02:30:00 -0500211static struct cpuidle_state byt_cstates[] = {
212 {
213 .name = "C1-BYT",
214 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100215 .flags = MWAIT2flg(0x00),
Len Brown718987d2014-02-14 02:30:00 -0500216 .exit_latency = 1,
217 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100218 .enter = &intel_idle,
219 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500220 {
Len Brown718987d2014-02-14 02:30:00 -0500221 .name = "C6N-BYT",
222 .desc = "MWAIT 0x58",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100223 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400224 .exit_latency = 300,
Len Brown718987d2014-02-14 02:30:00 -0500225 .target_residency = 275,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100226 .enter = &intel_idle,
227 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500228 {
229 .name = "C6S-BYT",
230 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100231 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400232 .exit_latency = 500,
Len Brown718987d2014-02-14 02:30:00 -0500233 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100234 .enter = &intel_idle,
235 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500236 {
237 .name = "C7-BYT",
238 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100239 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500240 .exit_latency = 1200,
Len Brownd7ef7672015-03-24 23:23:20 -0400241 .target_residency = 4000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100242 .enter = &intel_idle,
243 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500244 {
245 .name = "C7S-BYT",
246 .desc = "MWAIT 0x64",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100247 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500248 .exit_latency = 10000,
249 .target_residency = 20000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100250 .enter = &intel_idle,
251 .enter_freeze = intel_idle_freeze, },
Len Brown718987d2014-02-14 02:30:00 -0500252 {
253 .enter = NULL }
254};
255
Len Browncab07a52015-03-27 20:54:01 -0400256static struct cpuidle_state cht_cstates[] = {
257 {
258 .name = "C1-CHT",
259 .desc = "MWAIT 0x00",
260 .flags = MWAIT2flg(0x00),
261 .exit_latency = 1,
262 .target_residency = 1,
263 .enter = &intel_idle,
264 .enter_freeze = intel_idle_freeze, },
265 {
266 .name = "C6N-CHT",
267 .desc = "MWAIT 0x58",
268 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
269 .exit_latency = 80,
270 .target_residency = 275,
271 .enter = &intel_idle,
272 .enter_freeze = intel_idle_freeze, },
273 {
274 .name = "C6S-CHT",
275 .desc = "MWAIT 0x52",
276 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
277 .exit_latency = 200,
278 .target_residency = 560,
279 .enter = &intel_idle,
280 .enter_freeze = intel_idle_freeze, },
281 {
282 .name = "C7-CHT",
283 .desc = "MWAIT 0x60",
284 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
285 .exit_latency = 1200,
286 .target_residency = 4000,
287 .enter = &intel_idle,
288 .enter_freeze = intel_idle_freeze, },
289 {
290 .name = "C7S-CHT",
291 .desc = "MWAIT 0x64",
292 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
293 .exit_latency = 10000,
294 .target_residency = 20000,
295 .enter = &intel_idle,
296 .enter_freeze = intel_idle_freeze, },
297 {
298 .enter = NULL }
299};
300
Jiang Liuba0dc812014-01-09 15:30:26 +0800301static struct cpuidle_state ivb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500302 {
Len Brown6edab082012-06-01 19:45:32 -0400303 .name = "C1-IVB",
304 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100305 .flags = MWAIT2flg(0x00),
Len Brown6edab082012-06-01 19:45:32 -0400306 .exit_latency = 1,
307 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100308 .enter = &intel_idle,
309 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500310 {
Len Brown32e95182013-02-02 01:31:56 -0500311 .name = "C1E-IVB",
312 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100313 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500314 .exit_latency = 10,
315 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100316 .enter = &intel_idle,
317 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500318 {
Len Brown6edab082012-06-01 19:45:32 -0400319 .name = "C3-IVB",
320 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100321 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400322 .exit_latency = 59,
323 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100324 .enter = &intel_idle,
325 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500326 {
Len Brown6edab082012-06-01 19:45:32 -0400327 .name = "C6-IVB",
328 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100329 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400330 .exit_latency = 80,
331 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100332 .enter = &intel_idle,
333 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500334 {
Len Brown6edab082012-06-01 19:45:32 -0400335 .name = "C7-IVB",
336 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100337 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400338 .exit_latency = 87,
339 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100340 .enter = &intel_idle,
341 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500342 {
343 .enter = NULL }
Len Brown6edab082012-06-01 19:45:32 -0400344};
345
Len Brown0138d8f2014-04-04 01:21:07 -0400346static struct cpuidle_state ivt_cstates[] = {
347 {
348 .name = "C1-IVT",
349 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100350 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400351 .exit_latency = 1,
352 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100353 .enter = &intel_idle,
354 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400355 {
356 .name = "C1E-IVT",
357 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100358 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400359 .exit_latency = 10,
360 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100361 .enter = &intel_idle,
362 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400363 {
364 .name = "C3-IVT",
365 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100366 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400367 .exit_latency = 59,
368 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100369 .enter = &intel_idle,
370 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400371 {
372 .name = "C6-IVT",
373 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100374 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400375 .exit_latency = 82,
376 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100377 .enter = &intel_idle,
378 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400379 {
380 .enter = NULL }
381};
382
383static struct cpuidle_state ivt_cstates_4s[] = {
384 {
385 .name = "C1-IVT-4S",
386 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100387 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400388 .exit_latency = 1,
389 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100390 .enter = &intel_idle,
391 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400392 {
393 .name = "C1E-IVT-4S",
394 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100395 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400396 .exit_latency = 10,
397 .target_residency = 250,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100398 .enter = &intel_idle,
399 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400400 {
401 .name = "C3-IVT-4S",
402 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100403 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400404 .exit_latency = 59,
405 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100406 .enter = &intel_idle,
407 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400408 {
409 .name = "C6-IVT-4S",
410 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100411 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400412 .exit_latency = 84,
413 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100414 .enter = &intel_idle,
415 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400416 {
417 .enter = NULL }
418};
419
420static struct cpuidle_state ivt_cstates_8s[] = {
421 {
422 .name = "C1-IVT-8S",
423 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100424 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400425 .exit_latency = 1,
426 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100427 .enter = &intel_idle,
428 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400429 {
430 .name = "C1E-IVT-8S",
431 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100432 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400433 .exit_latency = 10,
434 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100435 .enter = &intel_idle,
436 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400437 {
438 .name = "C3-IVT-8S",
439 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100440 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400441 .exit_latency = 59,
442 .target_residency = 600,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100443 .enter = &intel_idle,
444 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400445 {
446 .name = "C6-IVT-8S",
447 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100448 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400449 .exit_latency = 88,
450 .target_residency = 700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100451 .enter = &intel_idle,
452 .enter_freeze = intel_idle_freeze, },
Len Brown0138d8f2014-04-04 01:21:07 -0400453 {
454 .enter = NULL }
455};
456
Jiang Liuba0dc812014-01-09 15:30:26 +0800457static struct cpuidle_state hsw_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500458 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500459 .name = "C1-HSW",
460 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100461 .flags = MWAIT2flg(0x00),
Len Brown85a4d2d2013-01-31 14:40:49 -0500462 .exit_latency = 2,
463 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100464 .enter = &intel_idle,
465 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500466 {
Len Brown32e95182013-02-02 01:31:56 -0500467 .name = "C1E-HSW",
468 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100469 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500470 .exit_latency = 10,
471 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100472 .enter = &intel_idle,
473 .enter_freeze = intel_idle_freeze, },
Len Brown32e95182013-02-02 01:31:56 -0500474 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500475 .name = "C3-HSW",
476 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100477 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500478 .exit_latency = 33,
479 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100480 .enter = &intel_idle,
481 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500482 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500483 .name = "C6-HSW",
484 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100485 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500486 .exit_latency = 133,
487 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100488 .enter = &intel_idle,
489 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500490 {
Len Brown85a4d2d2013-01-31 14:40:49 -0500491 .name = "C7s-HSW",
492 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100493 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500494 .exit_latency = 166,
495 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100496 .enter = &intel_idle,
497 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500498 {
Len Brown86239ce2013-02-27 13:18:50 -0500499 .name = "C8-HSW",
500 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100501 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500502 .exit_latency = 300,
503 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100504 .enter = &intel_idle,
505 .enter_freeze = intel_idle_freeze, },
Len Brown86239ce2013-02-27 13:18:50 -0500506 {
507 .name = "C9-HSW",
508 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100509 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500510 .exit_latency = 600,
511 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100512 .enter = &intel_idle,
513 .enter_freeze = intel_idle_freeze, },
Len Brown86239ce2013-02-27 13:18:50 -0500514 {
515 .name = "C10-HSW",
516 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100517 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500518 .exit_latency = 2600,
519 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100520 .enter = &intel_idle,
521 .enter_freeze = intel_idle_freeze, },
Len Brown86239ce2013-02-27 13:18:50 -0500522 {
Len Browne022e7e2013-02-01 23:37:30 -0500523 .enter = NULL }
Len Brown85a4d2d2013-01-31 14:40:49 -0500524};
Len Browna138b562014-02-04 23:56:40 -0500525static struct cpuidle_state bdw_cstates[] = {
526 {
527 .name = "C1-BDW",
528 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100529 .flags = MWAIT2flg(0x00),
Len Browna138b562014-02-04 23:56:40 -0500530 .exit_latency = 2,
531 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100532 .enter = &intel_idle,
533 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500534 {
535 .name = "C1E-BDW",
536 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100537 .flags = MWAIT2flg(0x01),
Len Browna138b562014-02-04 23:56:40 -0500538 .exit_latency = 10,
539 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100540 .enter = &intel_idle,
541 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500542 {
543 .name = "C3-BDW",
544 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100545 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500546 .exit_latency = 40,
547 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100548 .enter = &intel_idle,
549 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500550 {
551 .name = "C6-BDW",
552 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100553 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500554 .exit_latency = 133,
555 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100556 .enter = &intel_idle,
557 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500558 {
559 .name = "C7s-BDW",
560 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100561 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500562 .exit_latency = 166,
563 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100564 .enter = &intel_idle,
565 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500566 {
567 .name = "C8-BDW",
568 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100569 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500570 .exit_latency = 300,
571 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100572 .enter = &intel_idle,
573 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500574 {
575 .name = "C9-BDW",
576 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100577 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500578 .exit_latency = 600,
579 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100580 .enter = &intel_idle,
581 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500582 {
583 .name = "C10-BDW",
584 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100585 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500586 .exit_latency = 2600,
587 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100588 .enter = &intel_idle,
589 .enter_freeze = intel_idle_freeze, },
Len Browna138b562014-02-04 23:56:40 -0500590 {
591 .enter = NULL }
592};
Len Brown85a4d2d2013-01-31 14:40:49 -0500593
Len Brown493f1332015-03-25 23:20:37 -0400594static struct cpuidle_state skl_cstates[] = {
595 {
596 .name = "C1-SKL",
597 .desc = "MWAIT 0x00",
598 .flags = MWAIT2flg(0x00),
599 .exit_latency = 2,
600 .target_residency = 2,
601 .enter = &intel_idle,
602 .enter_freeze = intel_idle_freeze, },
603 {
604 .name = "C1E-SKL",
605 .desc = "MWAIT 0x01",
606 .flags = MWAIT2flg(0x01),
607 .exit_latency = 10,
608 .target_residency = 20,
609 .enter = &intel_idle,
610 .enter_freeze = intel_idle_freeze, },
611 {
612 .name = "C3-SKL",
613 .desc = "MWAIT 0x10",
614 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
615 .exit_latency = 70,
616 .target_residency = 100,
617 .enter = &intel_idle,
618 .enter_freeze = intel_idle_freeze, },
619 {
620 .name = "C6-SKL",
621 .desc = "MWAIT 0x20",
622 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400623 .exit_latency = 85,
Len Brown493f1332015-03-25 23:20:37 -0400624 .target_residency = 200,
625 .enter = &intel_idle,
626 .enter_freeze = intel_idle_freeze, },
627 {
628 .name = "C7s-SKL",
629 .desc = "MWAIT 0x33",
630 .flags = MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED,
631 .exit_latency = 124,
632 .target_residency = 800,
633 .enter = &intel_idle,
634 .enter_freeze = intel_idle_freeze, },
635 {
636 .name = "C8-SKL",
637 .desc = "MWAIT 0x40",
638 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400639 .exit_latency = 200,
Len Brown493f1332015-03-25 23:20:37 -0400640 .target_residency = 800,
641 .enter = &intel_idle,
642 .enter_freeze = intel_idle_freeze, },
643 {
Len Brown135919a2015-09-09 13:35:05 -0400644 .name = "C9-SKL",
645 .desc = "MWAIT 0x50",
646 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
647 .exit_latency = 480,
648 .target_residency = 5000,
649 .enter = &intel_idle,
650 .enter_freeze = intel_idle_freeze, },
651 {
Len Brown493f1332015-03-25 23:20:37 -0400652 .name = "C10-SKL",
653 .desc = "MWAIT 0x60",
654 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
655 .exit_latency = 890,
656 .target_residency = 5000,
657 .enter = &intel_idle,
658 .enter_freeze = intel_idle_freeze, },
659 {
660 .enter = NULL }
661};
662
Len Brownf9e71652016-04-06 17:00:58 -0400663static struct cpuidle_state skx_cstates[] = {
664 {
665 .name = "C1-SKX",
666 .desc = "MWAIT 0x00",
667 .flags = MWAIT2flg(0x00),
668 .exit_latency = 2,
669 .target_residency = 2,
670 .enter = &intel_idle,
671 .enter_freeze = intel_idle_freeze, },
672 {
673 .name = "C1E-SKX",
674 .desc = "MWAIT 0x01",
675 .flags = MWAIT2flg(0x01),
676 .exit_latency = 10,
677 .target_residency = 20,
678 .enter = &intel_idle,
679 .enter_freeze = intel_idle_freeze, },
680 {
681 .name = "C6-SKX",
682 .desc = "MWAIT 0x20",
683 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
684 .exit_latency = 133,
685 .target_residency = 600,
686 .enter = &intel_idle,
687 .enter_freeze = intel_idle_freeze, },
688 {
689 .enter = NULL }
690};
691
Jiang Liuba0dc812014-01-09 15:30:26 +0800692static struct cpuidle_state atom_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500693 {
Len Brown32e95182013-02-02 01:31:56 -0500694 .name = "C1E-ATM",
Len Brown26717172010-03-08 14:07:30 -0500695 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100696 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500697 .exit_latency = 10,
698 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100699 .enter = &intel_idle,
700 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500701 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100702 .name = "C2-ATM",
Len Brown26717172010-03-08 14:07:30 -0500703 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100704 .flags = MWAIT2flg(0x10),
Len Brown26717172010-03-08 14:07:30 -0500705 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500706 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100707 .enter = &intel_idle,
708 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500709 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100710 .name = "C4-ATM",
Len Brown26717172010-03-08 14:07:30 -0500711 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100712 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500713 .exit_latency = 100,
Len Brown26717172010-03-08 14:07:30 -0500714 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100715 .enter = &intel_idle,
716 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500717 {
Thomas Renninger15e123e2011-02-27 22:36:43 +0100718 .name = "C6-ATM",
Len Brown7fcca7d2010-10-05 13:43:14 -0400719 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100720 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown7fcca7d2010-10-05 13:43:14 -0400721 .exit_latency = 140,
Len Brown7fcca7d2010-10-05 13:43:14 -0400722 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100723 .enter = &intel_idle,
724 .enter_freeze = intel_idle_freeze, },
Len Browne022e7e2013-02-01 23:37:30 -0500725 {
726 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500727};
Jiang Liu88390992014-01-09 15:30:27 +0800728static struct cpuidle_state avn_cstates[] = {
Len Brownfab04b22013-11-09 00:30:17 -0500729 {
730 .name = "C1-AVN",
731 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100732 .flags = MWAIT2flg(0x00),
Len Brownfab04b22013-11-09 00:30:17 -0500733 .exit_latency = 2,
734 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100735 .enter = &intel_idle,
736 .enter_freeze = intel_idle_freeze, },
Len Brownfab04b22013-11-09 00:30:17 -0500737 {
738 .name = "C6-AVN",
739 .desc = "MWAIT 0x51",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100740 .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownfab04b22013-11-09 00:30:17 -0500741 .exit_latency = 15,
742 .target_residency = 45,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100743 .enter = &intel_idle,
744 .enter_freeze = intel_idle_freeze, },
Jiang Liu88390992014-01-09 15:30:27 +0800745 {
746 .enter = NULL }
Len Brownfab04b22013-11-09 00:30:17 -0500747};
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700748static struct cpuidle_state knl_cstates[] = {
749 {
750 .name = "C1-KNL",
751 .desc = "MWAIT 0x00",
752 .flags = MWAIT2flg(0x00),
753 .exit_latency = 1,
754 .target_residency = 2,
755 .enter = &intel_idle,
756 .enter_freeze = intel_idle_freeze },
757 {
758 .name = "C6-KNL",
759 .desc = "MWAIT 0x10",
760 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
761 .exit_latency = 120,
762 .target_residency = 500,
763 .enter = &intel_idle,
764 .enter_freeze = intel_idle_freeze },
765 {
766 .enter = NULL }
767};
Len Brown26717172010-03-08 14:07:30 -0500768
Len Brown5dcef692016-04-06 17:00:47 -0400769static struct cpuidle_state bxt_cstates[] = {
770 {
771 .name = "C1-BXT",
772 .desc = "MWAIT 0x00",
773 .flags = MWAIT2flg(0x00),
774 .exit_latency = 2,
775 .target_residency = 2,
776 .enter = &intel_idle,
777 .enter_freeze = intel_idle_freeze, },
778 {
779 .name = "C1E-BXT",
780 .desc = "MWAIT 0x01",
781 .flags = MWAIT2flg(0x01),
782 .exit_latency = 10,
783 .target_residency = 20,
784 .enter = &intel_idle,
785 .enter_freeze = intel_idle_freeze, },
786 {
787 .name = "C6-BXT",
788 .desc = "MWAIT 0x20",
789 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
790 .exit_latency = 133,
791 .target_residency = 133,
792 .enter = &intel_idle,
793 .enter_freeze = intel_idle_freeze, },
794 {
795 .name = "C7s-BXT",
796 .desc = "MWAIT 0x31",
797 .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
798 .exit_latency = 155,
799 .target_residency = 155,
800 .enter = &intel_idle,
801 .enter_freeze = intel_idle_freeze, },
802 {
803 .name = "C8-BXT",
804 .desc = "MWAIT 0x40",
805 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
806 .exit_latency = 1000,
807 .target_residency = 1000,
808 .enter = &intel_idle,
809 .enter_freeze = intel_idle_freeze, },
810 {
811 .name = "C9-BXT",
812 .desc = "MWAIT 0x50",
813 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
814 .exit_latency = 2000,
815 .target_residency = 2000,
816 .enter = &intel_idle,
817 .enter_freeze = intel_idle_freeze, },
818 {
819 .name = "C10-BXT",
820 .desc = "MWAIT 0x60",
821 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
822 .exit_latency = 10000,
823 .target_residency = 10000,
824 .enter = &intel_idle,
825 .enter_freeze = intel_idle_freeze, },
826 {
827 .enter = NULL }
828};
829
Len Brown26717172010-03-08 14:07:30 -0500830/**
831 * intel_idle
832 * @dev: cpuidle_device
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530833 * @drv: cpuidle driver
Deepthi Dharware978aa72011-10-28 16:20:09 +0530834 * @index: index of cpuidle state
Len Brown26717172010-03-08 14:07:30 -0500835 *
Yanmin Zhang63ff07b2012-01-10 15:48:21 -0800836 * Must be called under local_irq_disable().
Len Brown26717172010-03-08 14:07:30 -0500837 */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530838static int intel_idle(struct cpuidle_device *dev,
839 struct cpuidle_driver *drv, int index)
Len Brown26717172010-03-08 14:07:30 -0500840{
841 unsigned long ecx = 1; /* break on interrupt flag */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530842 struct cpuidle_state *state = &drv->states[index];
Len Brownb1beab42013-01-31 19:55:37 -0500843 unsigned long eax = flg2MWAIT(state->flags);
Len Brown26717172010-03-08 14:07:30 -0500844 unsigned int cstate;
Len Brown26717172010-03-08 14:07:30 -0500845 int cpu = smp_processor_id();
846
847 cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) + 1;
848
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400849 /*
Len Brownc8381cc2010-10-15 20:43:06 -0400850 * leave_mm() to avoid costly and often unnecessary wakeups
851 * for flushing the user TLB's associated with the active mm.
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400852 */
Len Brownc8381cc2010-10-15 20:43:06 -0400853 if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400854 leave_mm(cpu);
855
Len Brown26717172010-03-08 14:07:30 -0500856 if (!(lapic_timer_reliable_states & (1 << (cstate))))
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200857 tick_broadcast_enter();
Len Brown26717172010-03-08 14:07:30 -0500858
Peter Zijlstra16824252013-12-12 15:08:36 +0100859 mwait_idle_with_hints(eax, ecx);
Len Brown26717172010-03-08 14:07:30 -0500860
Len Brown26717172010-03-08 14:07:30 -0500861 if (!(lapic_timer_reliable_states & (1 << (cstate))))
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200862 tick_broadcast_exit();
Len Brown26717172010-03-08 14:07:30 -0500863
Deepthi Dharware978aa72011-10-28 16:20:09 +0530864 return index;
Len Brown26717172010-03-08 14:07:30 -0500865}
866
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100867/**
868 * intel_idle_freeze - simplified "enter" callback routine for suspend-to-idle
869 * @dev: cpuidle_device
870 * @drv: cpuidle driver
871 * @index: state index
872 */
873static void intel_idle_freeze(struct cpuidle_device *dev,
874 struct cpuidle_driver *drv, int index)
875{
876 unsigned long ecx = 1; /* break on interrupt flag */
877 unsigned long eax = flg2MWAIT(drv->states[index].flags);
878
879 mwait_idle_with_hints(eax, ecx);
880}
881
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800882static void __setup_broadcast_timer(void *arg)
883{
Thomas Gleixner76962ca2015-04-03 02:02:34 +0200884 unsigned long on = (unsigned long)arg;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800885
Thomas Gleixner76962ca2015-04-03 02:02:34 +0200886 if (on)
887 tick_broadcast_enable();
888 else
889 tick_broadcast_disable();
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800890}
891
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200892static int cpu_hotplug_notify(struct notifier_block *n,
893 unsigned long action, void *hcpu)
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800894{
895 int hotcpu = (unsigned long)hcpu;
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200896 struct cpuidle_device *dev;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800897
Prarit Bhargavae2401452013-10-23 09:44:51 -0400898 switch (action & ~CPU_TASKS_FROZEN) {
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800899 case CPU_ONLINE:
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200900
901 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
902 smp_call_function_single(hotcpu, __setup_broadcast_timer,
903 (void *)true, 1);
904
905 /*
906 * Some systems can hotplug a cpu at runtime after
907 * the kernel has booted, we have to initialize the
908 * driver in this case
909 */
910 dev = per_cpu_ptr(intel_idle_cpuidle_devices, hotcpu);
Richard Cochran08820542016-04-06 17:00:56 -0400911 if (dev->registered)
912 break;
913
914 if (intel_idle_cpu_init(hotcpu))
915 return NOTIFY_BAD;
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200916
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800917 break;
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800918 }
919 return NOTIFY_OK;
920}
921
Daniel Lezcano25ac7762012-07-05 15:23:25 +0200922static struct notifier_block cpu_hotplug_notifier = {
923 .notifier_call = cpu_hotplug_notify,
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800924};
925
Len Brown14796fc2011-01-18 20:48:27 -0500926static void auto_demotion_disable(void *dummy)
927{
928 unsigned long long msr_bits;
929
930 rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
Andi Kleenb66b8b92012-01-26 00:09:07 +0100931 msr_bits &= ~(icpu->auto_demotion_disable_flags);
Len Brown14796fc2011-01-18 20:48:27 -0500932 wrmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr_bits);
933}
Len Brown32e95182013-02-02 01:31:56 -0500934static void c1e_promotion_disable(void *dummy)
935{
936 unsigned long long msr_bits;
937
938 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
939 msr_bits &= ~0x2;
940 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
941}
Len Brown14796fc2011-01-18 20:48:27 -0500942
Andi Kleenb66b8b92012-01-26 00:09:07 +0100943static const struct idle_cpu idle_cpu_nehalem = {
944 .state_table = nehalem_cstates,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100945 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
Len Brown32e95182013-02-02 01:31:56 -0500946 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100947};
948
949static const struct idle_cpu idle_cpu_atom = {
950 .state_table = atom_cstates,
951};
952
953static const struct idle_cpu idle_cpu_lincroft = {
954 .state_table = atom_cstates,
955 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
956};
957
958static const struct idle_cpu idle_cpu_snb = {
959 .state_table = snb_cstates,
Len Brown32e95182013-02-02 01:31:56 -0500960 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100961};
962
Len Brown718987d2014-02-14 02:30:00 -0500963static const struct idle_cpu idle_cpu_byt = {
964 .state_table = byt_cstates,
965 .disable_promotion_to_c1e = true,
Len Brown8c058d532014-07-31 15:21:24 -0400966 .byt_auto_demotion_disable_flag = true,
Len Brown718987d2014-02-14 02:30:00 -0500967};
968
Len Browncab07a52015-03-27 20:54:01 -0400969static const struct idle_cpu idle_cpu_cht = {
970 .state_table = cht_cstates,
971 .disable_promotion_to_c1e = true,
972 .byt_auto_demotion_disable_flag = true,
973};
974
Len Brown6edab082012-06-01 19:45:32 -0400975static const struct idle_cpu idle_cpu_ivb = {
976 .state_table = ivb_cstates,
Len Brown32e95182013-02-02 01:31:56 -0500977 .disable_promotion_to_c1e = true,
Len Brown6edab082012-06-01 19:45:32 -0400978};
979
Len Brown0138d8f2014-04-04 01:21:07 -0400980static const struct idle_cpu idle_cpu_ivt = {
981 .state_table = ivt_cstates,
982 .disable_promotion_to_c1e = true,
983};
984
Len Brown85a4d2d2013-01-31 14:40:49 -0500985static const struct idle_cpu idle_cpu_hsw = {
986 .state_table = hsw_cstates,
Len Brown32e95182013-02-02 01:31:56 -0500987 .disable_promotion_to_c1e = true,
Len Brown85a4d2d2013-01-31 14:40:49 -0500988};
989
Len Browna138b562014-02-04 23:56:40 -0500990static const struct idle_cpu idle_cpu_bdw = {
991 .state_table = bdw_cstates,
992 .disable_promotion_to_c1e = true,
993};
994
Len Brown493f1332015-03-25 23:20:37 -0400995static const struct idle_cpu idle_cpu_skl = {
996 .state_table = skl_cstates,
997 .disable_promotion_to_c1e = true,
998};
999
Len Brownf9e71652016-04-06 17:00:58 -04001000static const struct idle_cpu idle_cpu_skx = {
1001 .state_table = skx_cstates,
1002 .disable_promotion_to_c1e = true,
1003};
Len Brown493f1332015-03-25 23:20:37 -04001004
Len Brownfab04b22013-11-09 00:30:17 -05001005static const struct idle_cpu idle_cpu_avn = {
1006 .state_table = avn_cstates,
1007 .disable_promotion_to_c1e = true,
1008};
1009
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001010static const struct idle_cpu idle_cpu_knl = {
1011 .state_table = knl_cstates,
1012};
1013
Len Brown5dcef692016-04-06 17:00:47 -04001014static const struct idle_cpu idle_cpu_bxt = {
1015 .state_table = bxt_cstates,
1016 .disable_promotion_to_c1e = true,
1017};
1018
Andi Kleenb66b8b92012-01-26 00:09:07 +01001019#define ICPU(model, cpu) \
1020 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, (unsigned long)&cpu }
1021
Mathias Kraused5cdc3c2015-03-25 22:15:14 +01001022static const struct x86_cpu_id intel_idle_ids[] __initconst = {
Andi Kleenb66b8b92012-01-26 00:09:07 +01001023 ICPU(0x1a, idle_cpu_nehalem),
1024 ICPU(0x1e, idle_cpu_nehalem),
1025 ICPU(0x1f, idle_cpu_nehalem),
Ben Hutchings8bf11932012-02-16 04:13:14 +00001026 ICPU(0x25, idle_cpu_nehalem),
1027 ICPU(0x2c, idle_cpu_nehalem),
1028 ICPU(0x2e, idle_cpu_nehalem),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001029 ICPU(0x1c, idle_cpu_atom),
1030 ICPU(0x26, idle_cpu_lincroft),
Ben Hutchings8bf11932012-02-16 04:13:14 +00001031 ICPU(0x2f, idle_cpu_nehalem),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001032 ICPU(0x2a, idle_cpu_snb),
1033 ICPU(0x2d, idle_cpu_snb),
Jan Kiszkaacead1b2014-01-25 22:24:22 +01001034 ICPU(0x36, idle_cpu_atom),
Len Brown718987d2014-02-14 02:30:00 -05001035 ICPU(0x37, idle_cpu_byt),
Len Browncab07a52015-03-27 20:54:01 -04001036 ICPU(0x4c, idle_cpu_cht),
Len Brown6edab082012-06-01 19:45:32 -04001037 ICPU(0x3a, idle_cpu_ivb),
Len Brown0138d8f2014-04-04 01:21:07 -04001038 ICPU(0x3e, idle_cpu_ivt),
Len Brown85a4d2d2013-01-31 14:40:49 -05001039 ICPU(0x3c, idle_cpu_hsw),
1040 ICPU(0x3f, idle_cpu_hsw),
1041 ICPU(0x45, idle_cpu_hsw),
Len Brown0b158412013-03-15 10:55:31 -04001042 ICPU(0x46, idle_cpu_hsw),
Len Browna138b562014-02-04 23:56:40 -05001043 ICPU(0x4d, idle_cpu_avn),
1044 ICPU(0x3d, idle_cpu_bdw),
Len Brownbea570772015-02-10 15:42:03 -05001045 ICPU(0x47, idle_cpu_bdw),
Len Browna138b562014-02-04 23:56:40 -05001046 ICPU(0x4f, idle_cpu_bdw),
1047 ICPU(0x56, idle_cpu_bdw),
Len Brown493f1332015-03-25 23:20:37 -04001048 ICPU(0x4e, idle_cpu_skl),
1049 ICPU(0x5e, idle_cpu_skl),
Len Brown3ce093d2016-04-06 17:00:59 -04001050 ICPU(0x8e, idle_cpu_skl),
1051 ICPU(0x9e, idle_cpu_skl),
Len Brownf9e71652016-04-06 17:00:58 -04001052 ICPU(0x55, idle_cpu_skx),
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001053 ICPU(0x57, idle_cpu_knl),
Len Brown5dcef692016-04-06 17:00:47 -04001054 ICPU(0x5c, idle_cpu_bxt),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001055 {}
1056};
1057MODULE_DEVICE_TABLE(x86cpu, intel_idle_ids);
1058
Len Brown26717172010-03-08 14:07:30 -05001059/*
1060 * intel_idle_probe()
1061 */
Bartlomiej Zolnierkiewicz00f3e752013-08-30 12:27:45 +02001062static int __init intel_idle_probe(void)
Len Brown26717172010-03-08 14:07:30 -05001063{
Len Brownc4236282010-05-28 02:22:03 -04001064 unsigned int eax, ebx, ecx;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001065 const struct x86_cpu_id *id;
Len Brown26717172010-03-08 14:07:30 -05001066
1067 if (max_cstate == 0) {
1068 pr_debug(PREFIX "disabled\n");
1069 return -EPERM;
1070 }
1071
Andi Kleenb66b8b92012-01-26 00:09:07 +01001072 id = x86_match_cpu(intel_idle_ids);
1073 if (!id) {
1074 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
1075 boot_cpu_data.x86 == 6)
1076 pr_debug(PREFIX "does not run on family %d model %d\n",
1077 boot_cpu_data.x86, boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001078 return -ENODEV;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001079 }
Len Brown26717172010-03-08 14:07:30 -05001080
1081 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
1082 return -ENODEV;
1083
Len Brownc4236282010-05-28 02:22:03 -04001084 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001085
1086 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
Thomas Renninger5c2a9f02011-12-04 22:17:29 +01001087 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
1088 !mwait_substates)
Len Brown26717172010-03-08 14:07:30 -05001089 return -ENODEV;
Len Brown26717172010-03-08 14:07:30 -05001090
Len Brownc4236282010-05-28 02:22:03 -04001091 pr_debug(PREFIX "MWAIT substates: 0x%x\n", mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001092
Andi Kleenb66b8b92012-01-26 00:09:07 +01001093 icpu = (const struct idle_cpu *)id->driver_data;
1094 cpuidle_state_table = icpu->state_table;
Len Brown26717172010-03-08 14:07:30 -05001095
1096 pr_debug(PREFIX "v" INTEL_IDLE_VERSION
1097 " model 0x%X\n", boot_cpu_data.x86_model);
1098
Len Brown26717172010-03-08 14:07:30 -05001099 return 0;
1100}
1101
1102/*
1103 * intel_idle_cpuidle_devices_uninit()
Richard Cochranca424892016-04-06 17:00:53 -04001104 * Unregisters the cpuidle devices.
Len Brown26717172010-03-08 14:07:30 -05001105 */
1106static void intel_idle_cpuidle_devices_uninit(void)
1107{
1108 int i;
1109 struct cpuidle_device *dev;
1110
1111 for_each_online_cpu(i) {
1112 dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
1113 cpuidle_unregister_device(dev);
1114 }
Len Brown26717172010-03-08 14:07:30 -05001115}
Len Brown0138d8f2014-04-04 01:21:07 -04001116
1117/*
Len Brownd70e28f2016-03-13 00:33:48 -05001118 * ivt_idle_state_table_update(void)
1119 *
1120 * Tune IVT multi-socket targets
1121 * Assumption: num_sockets == (max_package_num + 1)
1122 */
1123static void ivt_idle_state_table_update(void)
1124{
1125 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1126 int cpu, package_num, num_sockets = 1;
1127
1128 for_each_online_cpu(cpu) {
1129 package_num = topology_physical_package_id(cpu);
1130 if (package_num + 1 > num_sockets) {
1131 num_sockets = package_num + 1;
1132
1133 if (num_sockets > 4) {
1134 cpuidle_state_table = ivt_cstates_8s;
1135 return;
1136 }
1137 }
1138 }
1139
1140 if (num_sockets > 2)
1141 cpuidle_state_table = ivt_cstates_4s;
1142
1143 /* else, 1 and 2 socket systems use default ivt_cstates */
1144}
Len Brown5dcef692016-04-06 17:00:47 -04001145
1146/*
1147 * Translate IRTL (Interrupt Response Time Limit) MSR to usec
1148 */
1149
1150static unsigned int irtl_ns_units[] = {
1151 1, 32, 1024, 32768, 1048576, 33554432, 0, 0 };
1152
1153static unsigned long long irtl_2_usec(unsigned long long irtl)
1154{
1155 unsigned long long ns;
1156
1157 ns = irtl_ns_units[(irtl >> 10) & 0x3];
1158
1159 return div64_u64((irtl & 0x3FF) * ns, 1000);
1160}
1161/*
1162 * bxt_idle_state_table_update(void)
1163 *
1164 * On BXT, we trust the IRTL to show the definitive maximum latency
1165 * We use the same value for target_residency.
1166 */
1167static void bxt_idle_state_table_update(void)
1168{
1169 unsigned long long msr;
1170
1171 rdmsrl(MSR_PKGC6_IRTL, msr);
1172 if (msr) {
1173 unsigned int usec = irtl_2_usec(msr);
1174
1175 bxt_cstates[2].exit_latency = usec;
1176 bxt_cstates[2].target_residency = usec;
1177 }
1178
1179 rdmsrl(MSR_PKGC7_IRTL, msr);
1180 if (msr) {
1181 unsigned int usec = irtl_2_usec(msr);
1182
1183 bxt_cstates[3].exit_latency = usec;
1184 bxt_cstates[3].target_residency = usec;
1185 }
1186
1187 rdmsrl(MSR_PKGC8_IRTL, msr);
1188 if (msr) {
1189 unsigned int usec = irtl_2_usec(msr);
1190
1191 bxt_cstates[4].exit_latency = usec;
1192 bxt_cstates[4].target_residency = usec;
1193 }
1194
1195 rdmsrl(MSR_PKGC9_IRTL, msr);
1196 if (msr) {
1197 unsigned int usec = irtl_2_usec(msr);
1198
1199 bxt_cstates[5].exit_latency = usec;
1200 bxt_cstates[5].target_residency = usec;
1201 }
1202
1203 rdmsrl(MSR_PKGC10_IRTL, msr);
1204 if (msr) {
1205 unsigned int usec = irtl_2_usec(msr);
1206
1207 bxt_cstates[6].exit_latency = usec;
1208 bxt_cstates[6].target_residency = usec;
1209 }
1210
1211}
Len Brownd70e28f2016-03-13 00:33:48 -05001212/*
1213 * sklh_idle_state_table_update(void)
1214 *
1215 * On SKL-H (model 0x5e) disable C8 and C9 if:
1216 * C10 is enabled and SGX disabled
1217 */
1218static void sklh_idle_state_table_update(void)
1219{
1220 unsigned long long msr;
1221 unsigned int eax, ebx, ecx, edx;
1222
1223
1224 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1225 if (max_cstate <= 7)
1226 return;
1227
1228 /* if PC10 not present in CPUID.MWAIT.EDX */
1229 if ((mwait_substates & (0xF << 28)) == 0)
1230 return;
1231
1232 rdmsrl(MSR_NHM_SNB_PKG_CST_CFG_CTL, msr);
1233
1234 /* PC10 is not enabled in PKG C-state limit */
1235 if ((msr & 0xF) != 8)
1236 return;
1237
1238 ecx = 0;
1239 cpuid(7, &eax, &ebx, &ecx, &edx);
1240
1241 /* if SGX is present */
1242 if (ebx & (1 << 2)) {
1243
1244 rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
1245
1246 /* if SGX is enabled */
1247 if (msr & (1 << 18))
1248 return;
1249 }
1250
1251 skl_cstates[5].disabled = 1; /* C8-SKL */
1252 skl_cstates[6].disabled = 1; /* C9-SKL */
1253}
1254/*
Len Brown0138d8f2014-04-04 01:21:07 -04001255 * intel_idle_state_table_update()
1256 *
1257 * Update the default state_table for this CPU-id
Len Brown0138d8f2014-04-04 01:21:07 -04001258 */
Len Brownd70e28f2016-03-13 00:33:48 -05001259
1260static void intel_idle_state_table_update(void)
Len Brown0138d8f2014-04-04 01:21:07 -04001261{
Len Brownd70e28f2016-03-13 00:33:48 -05001262 switch (boot_cpu_data.x86_model) {
Len Brown0138d8f2014-04-04 01:21:07 -04001263
Len Brownd70e28f2016-03-13 00:33:48 -05001264 case 0x3e: /* IVT */
1265 ivt_idle_state_table_update();
1266 break;
Len Brown5dcef692016-04-06 17:00:47 -04001267 case 0x5c: /* BXT */
1268 bxt_idle_state_table_update();
1269 break;
Len Brownd70e28f2016-03-13 00:33:48 -05001270 case 0x5e: /* SKL-H */
1271 sklh_idle_state_table_update();
1272 break;
Len Brown0138d8f2014-04-04 01:21:07 -04001273 }
Len Brown0138d8f2014-04-04 01:21:07 -04001274}
1275
Len Brown26717172010-03-08 14:07:30 -05001276/*
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301277 * intel_idle_cpuidle_driver_init()
1278 * allocate, initialize cpuidle_states
1279 */
Richard Cochran5469c822016-04-06 17:00:49 -04001280static void __init intel_idle_cpuidle_driver_init(void)
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301281{
1282 int cstate;
1283 struct cpuidle_driver *drv = &intel_idle_driver;
1284
Len Brown0138d8f2014-04-04 01:21:07 -04001285 intel_idle_state_table_update();
1286
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301287 drv->state_count = 1;
1288
Len Browne022e7e2013-02-01 23:37:30 -05001289 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
Len Brown24bfa952014-02-14 00:50:34 -05001290 int num_substates, mwait_hint, mwait_cstate;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301291
Len Brown7dd0e0a2015-05-27 17:11:37 -04001292 if ((cpuidle_state_table[cstate].enter == NULL) &&
1293 (cpuidle_state_table[cstate].enter_freeze == NULL))
Len Browne022e7e2013-02-01 23:37:30 -05001294 break;
1295
1296 if (cstate + 1 > max_cstate) {
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301297 printk(PREFIX "max_cstate %d reached\n",
1298 max_cstate);
1299 break;
1300 }
1301
Len Browne022e7e2013-02-01 23:37:30 -05001302 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
1303 mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301304
Len Brown24bfa952014-02-14 00:50:34 -05001305 /* number of sub-states for this state in CPUID.MWAIT */
Len Browne022e7e2013-02-01 23:37:30 -05001306 num_substates = (mwait_substates >> ((mwait_cstate + 1) * 4))
1307 & MWAIT_SUBSTATE_MASK;
1308
Len Brown24bfa952014-02-14 00:50:34 -05001309 /* if NO sub-states for this state in CPUID, skip it */
1310 if (num_substates == 0)
Len Browne022e7e2013-02-01 23:37:30 -05001311 continue;
1312
Len Brownd70e28f2016-03-13 00:33:48 -05001313 /* if state marked as disabled, skip it */
1314 if (cpuidle_state_table[cstate].disabled != 0) {
1315 pr_debug(PREFIX "state %s is disabled",
1316 cpuidle_state_table[cstate].name);
1317 continue;
1318 }
1319
1320
Len Browne022e7e2013-02-01 23:37:30 -05001321 if (((mwait_cstate + 1) > 2) &&
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301322 !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
1323 mark_tsc_unstable("TSC halts in idle"
1324 " states deeper than C2");
1325
1326 drv->states[drv->state_count] = /* structure copy */
1327 cpuidle_state_table[cstate];
1328
1329 drv->state_count += 1;
1330 }
1331
Len Brown8c058d532014-07-31 15:21:24 -04001332 if (icpu->byt_auto_demotion_disable_flag) {
1333 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
1334 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
1335 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301336}
1337
1338
1339/*
Thomas Renninger65b7f832012-01-17 22:40:08 +01001340 * intel_idle_cpu_init()
Len Brown26717172010-03-08 14:07:30 -05001341 * allocate, initialize, register cpuidle_devices
Thomas Renninger65b7f832012-01-17 22:40:08 +01001342 * @cpu: cpu/core to initialize
Len Brown26717172010-03-08 14:07:30 -05001343 */
Daniel Lezcano25ac7762012-07-05 15:23:25 +02001344static int intel_idle_cpu_init(int cpu)
Len Brown26717172010-03-08 14:07:30 -05001345{
Len Brown26717172010-03-08 14:07:30 -05001346 struct cpuidle_device *dev;
1347
Thomas Renninger65b7f832012-01-17 22:40:08 +01001348 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
Len Brown26717172010-03-08 14:07:30 -05001349
Thomas Renninger65b7f832012-01-17 22:40:08 +01001350 dev->cpu = cpu;
Len Brown26717172010-03-08 14:07:30 -05001351
Thomas Renninger65b7f832012-01-17 22:40:08 +01001352 if (cpuidle_register_device(dev)) {
1353 pr_debug(PREFIX "cpuidle_register_device %d failed!\n", cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001354 return -EIO;
Len Brown26717172010-03-08 14:07:30 -05001355 }
1356
Andi Kleenb66b8b92012-01-26 00:09:07 +01001357 if (icpu->auto_demotion_disable_flags)
Thomas Renninger65b7f832012-01-17 22:40:08 +01001358 smp_call_function_single(cpu, auto_demotion_disable, NULL, 1);
1359
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001360 if (icpu->disable_promotion_to_c1e)
1361 smp_call_function_single(cpu, c1e_promotion_disable, NULL, 1);
1362
Len Brown26717172010-03-08 14:07:30 -05001363 return 0;
1364}
Len Brown26717172010-03-08 14:07:30 -05001365
1366static int __init intel_idle_init(void)
1367{
Thomas Renninger65b7f832012-01-17 22:40:08 +01001368 int retval, i;
Len Brown26717172010-03-08 14:07:30 -05001369
Thomas Renningerd1896042010-11-03 17:06:14 +01001370 /* Do not load intel_idle at all for now if idle= is passed */
1371 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
1372 return -ENODEV;
1373
Len Brown26717172010-03-08 14:07:30 -05001374 retval = intel_idle_probe();
1375 if (retval)
1376 return retval;
1377
Richard Cochrane9df69c2016-04-06 17:00:52 -04001378 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
1379 if (intel_idle_cpuidle_devices == NULL)
1380 return -ENOMEM;
1381
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301382 intel_idle_cpuidle_driver_init();
Len Brown26717172010-03-08 14:07:30 -05001383 retval = cpuidle_register_driver(&intel_idle_driver);
1384 if (retval) {
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001385 struct cpuidle_driver *drv = cpuidle_get_driver();
Len Brown26717172010-03-08 14:07:30 -05001386 printk(KERN_DEBUG PREFIX "intel_idle yielding to %s",
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001387 drv ? drv->name : "none");
Richard Cochrane9df69c2016-04-06 17:00:52 -04001388 free_percpu(intel_idle_cpuidle_devices);
Len Brown26717172010-03-08 14:07:30 -05001389 return retval;
1390 }
1391
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301392 cpu_notifier_register_begin();
1393
Thomas Renninger65b7f832012-01-17 22:40:08 +01001394 for_each_online_cpu(i) {
1395 retval = intel_idle_cpu_init(i);
1396 if (retval) {
Richard Cochranb69ef2c2016-04-06 17:00:55 -04001397 intel_idle_cpuidle_devices_uninit();
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301398 cpu_notifier_register_done();
Thomas Renninger65b7f832012-01-17 22:40:08 +01001399 cpuidle_unregister_driver(&intel_idle_driver);
Richard Cochranca424892016-04-06 17:00:53 -04001400 free_percpu(intel_idle_cpuidle_devices);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001401 return retval;
1402 }
Len Brown26717172010-03-08 14:07:30 -05001403 }
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301404 __register_cpu_notifier(&cpu_hotplug_notifier);
1405
Richard Cochran2259a812016-04-06 17:00:54 -04001406 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
1407 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
1408 else
1409 on_each_cpu(__setup_broadcast_timer, (void *)true, 1);
1410
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301411 cpu_notifier_register_done();
Len Brown26717172010-03-08 14:07:30 -05001412
Richard Cochran2259a812016-04-06 17:00:54 -04001413 pr_debug(PREFIX "lapic_timer_reliable_states 0x%x\n",
1414 lapic_timer_reliable_states);
1415
Len Brown26717172010-03-08 14:07:30 -05001416 return 0;
1417}
1418
1419static void __exit intel_idle_exit(void)
1420{
Richard Cochran3e66a9a2016-04-06 17:00:57 -04001421 struct cpuidle_device *dev;
1422 int i;
1423
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301424 cpu_notifier_register_begin();
Daniel Lezcano25ac7762012-07-05 15:23:25 +02001425
1426 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
Shaohua Li39a74fd2012-01-10 15:48:19 -08001427 on_each_cpu(__setup_broadcast_timer, (void *)false, 1);
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301428 __unregister_cpu_notifier(&cpu_hotplug_notifier);
Richard Cochran3e66a9a2016-04-06 17:00:57 -04001429
1430 for_each_possible_cpu(i) {
1431 dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
1432 cpuidle_unregister_device(dev);
1433 }
Srivatsa S. Bhat07494d52014-03-11 02:10:30 +05301434
1435 cpu_notifier_register_done();
Richard Cochran51319912016-04-06 17:00:51 -04001436
1437 cpuidle_unregister_driver(&intel_idle_driver);
Richard Cochranca424892016-04-06 17:00:53 -04001438 free_percpu(intel_idle_cpuidle_devices);
Len Brown26717172010-03-08 14:07:30 -05001439}
1440
1441module_init(intel_idle_init);
1442module_exit(intel_idle_exit);
1443
Len Brown26717172010-03-08 14:07:30 -05001444module_param(max_cstate, int, 0444);
Len Brown26717172010-03-08 14:07:30 -05001445
1446MODULE_AUTHOR("Len Brown <len.brown@intel.com>");
1447MODULE_DESCRIPTION("Cpuidle driver for Intel Hardware v" INTEL_IDLE_VERSION);
1448MODULE_LICENSE("GPL");