blob: b2ccce5fb0718303971dec46581482ff1d2e7e76 [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
Joe Perches654d08a2017-06-09 12:29:20 -070054#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
55
Len Brown26717172010-03-08 14:07:30 -050056#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 Gortmaker02c4fae2016-06-17 01:28:33 -040063#include <linux/moduleparam.h>
Andi Kleenb66b8b92012-01-26 00:09:07 +010064#include <asm/cpu_device_id.h>
Dave Hansendb73c5a2016-06-02 17:19:32 -070065#include <asm/intel-family.h>
H. Peter Anvinbc83ccc2010-09-17 15:36:40 -070066#include <asm/mwait.h>
Len Brown14796fc2011-01-18 20:48:27 -050067#include <asm/msr.h>
Len Brown26717172010-03-08 14:07:30 -050068
Len Brownd70e28f2016-03-13 00:33:48 -050069#define INTEL_IDLE_VERSION "0.4.1"
Len Brown26717172010-03-08 14:07:30 -050070
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. Wysocki28ba0862017-08-10 00:14:45 +0200100static void intel_idle_s2idle(struct cpuidle_device *dev,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100101 struct cpuidle_driver *drv, int index);
Len Brown26717172010-03-08 14:07:30 -0500102static struct cpuidle_state *cpuidle_state_table;
103
104/*
Len Brown956d0332011-01-12 02:51:20 -0500105 * Set this flag for states where the HW flushes the TLB for us
106 * and so we don't need cross-calls to keep it consistent.
107 * If this flag is set, SW flushes the TLB, so even if the
108 * HW doesn't do the flushing, this flag is safe to use.
109 */
110#define CPUIDLE_FLAG_TLB_FLUSHED 0x10000
111
112/*
Len Brownb1beab42013-01-31 19:55:37 -0500113 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
114 * the C-state (top nibble) and sub-state (bottom nibble)
115 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
116 *
117 * We store the hint at the top of our "flags" for each state.
118 */
119#define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
120#define MWAIT2flg(eax) ((eax & 0xFF) << 24)
121
122/*
Len Brown26717172010-03-08 14:07:30 -0500123 * States are indexed by the cstate number,
124 * which is also the index into the MWAIT hint array.
125 * Thus C0 is a dummy.
126 */
Jiang Liuba0dc812014-01-09 15:30:26 +0800127static struct cpuidle_state nehalem_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500128 {
Len Brownde09cdd2017-02-28 16:32:44 -0500129 .name = "C1",
Len Brown26717172010-03-08 14:07:30 -0500130 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100131 .flags = MWAIT2flg(0x00),
Len Brown26717172010-03-08 14:07:30 -0500132 .exit_latency = 3,
Len Brown26717172010-03-08 14:07:30 -0500133 .target_residency = 6,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100134 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200135 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500136 {
Len Brownde09cdd2017-02-28 16:32:44 -0500137 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500138 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100139 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500140 .exit_latency = 10,
141 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100142 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200143 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500144 {
Len Brownde09cdd2017-02-28 16:32:44 -0500145 .name = "C3",
Len Brown26717172010-03-08 14:07:30 -0500146 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100147 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500148 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500149 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100150 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200151 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500152 {
Len Brownde09cdd2017-02-28 16:32:44 -0500153 .name = "C6",
Len Brown26717172010-03-08 14:07:30 -0500154 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100155 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500156 .exit_latency = 200,
Len Brown26717172010-03-08 14:07:30 -0500157 .target_residency = 800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100158 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200159 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500160 {
161 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500162};
163
Jiang Liuba0dc812014-01-09 15:30:26 +0800164static struct cpuidle_state snb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500165 {
Len Brownde09cdd2017-02-28 16:32:44 -0500166 .name = "C1",
Len Brownd13780d2010-07-07 00:12:03 -0400167 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100168 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500169 .exit_latency = 2,
170 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100171 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200172 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500173 {
Len Brownde09cdd2017-02-28 16:32:44 -0500174 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500175 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100176 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500177 .exit_latency = 10,
178 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100179 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200180 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500181 {
Len Brownde09cdd2017-02-28 16:32:44 -0500182 .name = "C3",
Len Brownd13780d2010-07-07 00:12:03 -0400183 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100184 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400185 .exit_latency = 80,
Len Brownddbd5502010-12-13 18:28:22 -0500186 .target_residency = 211,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100187 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200188 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500189 {
Len Brownde09cdd2017-02-28 16:32:44 -0500190 .name = "C6",
Len Brownd13780d2010-07-07 00:12:03 -0400191 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100192 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400193 .exit_latency = 104,
Len Brownddbd5502010-12-13 18:28:22 -0500194 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100195 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200196 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500197 {
Len Brownde09cdd2017-02-28 16:32:44 -0500198 .name = "C7",
Len Brownd13780d2010-07-07 00:12:03 -0400199 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100200 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400201 .exit_latency = 109,
Len Brownddbd5502010-12-13 18:28:22 -0500202 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100203 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200204 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500205 {
206 .enter = NULL }
Len Brownd13780d2010-07-07 00:12:03 -0400207};
208
Len Brown718987d2014-02-14 02:30:00 -0500209static struct cpuidle_state byt_cstates[] = {
210 {
Len Brownde09cdd2017-02-28 16:32:44 -0500211 .name = "C1",
Len Brown718987d2014-02-14 02:30:00 -0500212 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100213 .flags = MWAIT2flg(0x00),
Len Brown718987d2014-02-14 02:30:00 -0500214 .exit_latency = 1,
215 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100216 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200217 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500218 {
Len Brownde09cdd2017-02-28 16:32:44 -0500219 .name = "C6N",
Len Brown718987d2014-02-14 02:30:00 -0500220 .desc = "MWAIT 0x58",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100221 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400222 .exit_latency = 300,
Len Brown718987d2014-02-14 02:30:00 -0500223 .target_residency = 275,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100224 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200225 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500226 {
Len Brownde09cdd2017-02-28 16:32:44 -0500227 .name = "C6S",
Len Brown718987d2014-02-14 02:30:00 -0500228 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100229 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400230 .exit_latency = 500,
Len Brown718987d2014-02-14 02:30:00 -0500231 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100232 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200233 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500234 {
Len Brownde09cdd2017-02-28 16:32:44 -0500235 .name = "C7",
Len Brown718987d2014-02-14 02:30:00 -0500236 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100237 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500238 .exit_latency = 1200,
Len Brownd7ef7672015-03-24 23:23:20 -0400239 .target_residency = 4000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100240 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200241 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500242 {
Len Brownde09cdd2017-02-28 16:32:44 -0500243 .name = "C7S",
Len Brown718987d2014-02-14 02:30:00 -0500244 .desc = "MWAIT 0x64",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100245 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500246 .exit_latency = 10000,
247 .target_residency = 20000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100248 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200249 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500250 {
251 .enter = NULL }
252};
253
Len Browncab07a52015-03-27 20:54:01 -0400254static struct cpuidle_state cht_cstates[] = {
255 {
Len Brownde09cdd2017-02-28 16:32:44 -0500256 .name = "C1",
Len Browncab07a52015-03-27 20:54:01 -0400257 .desc = "MWAIT 0x00",
258 .flags = MWAIT2flg(0x00),
259 .exit_latency = 1,
260 .target_residency = 1,
261 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200262 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400263 {
Len Brownde09cdd2017-02-28 16:32:44 -0500264 .name = "C6N",
Len Browncab07a52015-03-27 20:54:01 -0400265 .desc = "MWAIT 0x58",
266 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
267 .exit_latency = 80,
268 .target_residency = 275,
269 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200270 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400271 {
Len Brownde09cdd2017-02-28 16:32:44 -0500272 .name = "C6S",
Len Browncab07a52015-03-27 20:54:01 -0400273 .desc = "MWAIT 0x52",
274 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
275 .exit_latency = 200,
276 .target_residency = 560,
277 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200278 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400279 {
Len Brownde09cdd2017-02-28 16:32:44 -0500280 .name = "C7",
Len Browncab07a52015-03-27 20:54:01 -0400281 .desc = "MWAIT 0x60",
282 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
283 .exit_latency = 1200,
284 .target_residency = 4000,
285 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200286 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400287 {
Len Brownde09cdd2017-02-28 16:32:44 -0500288 .name = "C7S",
Len Browncab07a52015-03-27 20:54:01 -0400289 .desc = "MWAIT 0x64",
290 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
291 .exit_latency = 10000,
292 .target_residency = 20000,
293 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200294 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400295 {
296 .enter = NULL }
297};
298
Jiang Liuba0dc812014-01-09 15:30:26 +0800299static struct cpuidle_state ivb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500300 {
Len Brownde09cdd2017-02-28 16:32:44 -0500301 .name = "C1",
Len Brown6edab082012-06-01 19:45:32 -0400302 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100303 .flags = MWAIT2flg(0x00),
Len Brown6edab082012-06-01 19:45:32 -0400304 .exit_latency = 1,
305 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100306 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200307 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500308 {
Len Brownde09cdd2017-02-28 16:32:44 -0500309 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500310 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100311 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500312 .exit_latency = 10,
313 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100314 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200315 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500316 {
Len Brownde09cdd2017-02-28 16:32:44 -0500317 .name = "C3",
Len Brown6edab082012-06-01 19:45:32 -0400318 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100319 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400320 .exit_latency = 59,
321 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100322 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200323 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500324 {
Len Brownde09cdd2017-02-28 16:32:44 -0500325 .name = "C6",
Len Brown6edab082012-06-01 19:45:32 -0400326 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100327 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400328 .exit_latency = 80,
329 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100330 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200331 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500332 {
Len Brownde09cdd2017-02-28 16:32:44 -0500333 .name = "C7",
Len Brown6edab082012-06-01 19:45:32 -0400334 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100335 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400336 .exit_latency = 87,
337 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100338 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200339 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500340 {
341 .enter = NULL }
Len Brown6edab082012-06-01 19:45:32 -0400342};
343
Len Brown0138d8f2014-04-04 01:21:07 -0400344static struct cpuidle_state ivt_cstates[] = {
345 {
Len Brownde09cdd2017-02-28 16:32:44 -0500346 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400347 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100348 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400349 .exit_latency = 1,
350 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100351 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200352 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400353 {
Len Brownde09cdd2017-02-28 16:32:44 -0500354 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400355 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100356 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400357 .exit_latency = 10,
358 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100359 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200360 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400361 {
Len Brownde09cdd2017-02-28 16:32:44 -0500362 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400363 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100364 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400365 .exit_latency = 59,
366 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100367 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200368 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400369 {
Len Brownde09cdd2017-02-28 16:32:44 -0500370 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400371 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100372 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400373 .exit_latency = 82,
374 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100375 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200376 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400377 {
378 .enter = NULL }
379};
380
381static struct cpuidle_state ivt_cstates_4s[] = {
382 {
Len Brownde09cdd2017-02-28 16:32:44 -0500383 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400384 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100385 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400386 .exit_latency = 1,
387 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100388 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200389 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400390 {
Len Brownde09cdd2017-02-28 16:32:44 -0500391 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400392 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100393 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400394 .exit_latency = 10,
395 .target_residency = 250,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100396 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200397 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400398 {
Len Brownde09cdd2017-02-28 16:32:44 -0500399 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400400 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100401 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400402 .exit_latency = 59,
403 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100404 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200405 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400406 {
Len Brownde09cdd2017-02-28 16:32:44 -0500407 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400408 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100409 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400410 .exit_latency = 84,
411 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100412 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200413 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400414 {
415 .enter = NULL }
416};
417
418static struct cpuidle_state ivt_cstates_8s[] = {
419 {
Len Brownde09cdd2017-02-28 16:32:44 -0500420 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400421 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100422 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400423 .exit_latency = 1,
424 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100425 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200426 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400427 {
Len Brownde09cdd2017-02-28 16:32:44 -0500428 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400429 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100430 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400431 .exit_latency = 10,
432 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100433 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200434 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400435 {
Len Brownde09cdd2017-02-28 16:32:44 -0500436 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400437 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100438 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400439 .exit_latency = 59,
440 .target_residency = 600,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100441 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200442 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400443 {
Len Brownde09cdd2017-02-28 16:32:44 -0500444 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400445 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100446 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400447 .exit_latency = 88,
448 .target_residency = 700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100449 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200450 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400451 {
452 .enter = NULL }
453};
454
Jiang Liuba0dc812014-01-09 15:30:26 +0800455static struct cpuidle_state hsw_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500456 {
Len Brownde09cdd2017-02-28 16:32:44 -0500457 .name = "C1",
Len Brown85a4d2d2013-01-31 14:40:49 -0500458 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100459 .flags = MWAIT2flg(0x00),
Len Brown85a4d2d2013-01-31 14:40:49 -0500460 .exit_latency = 2,
461 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100462 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200463 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500464 {
Len Brownde09cdd2017-02-28 16:32:44 -0500465 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500466 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100467 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500468 .exit_latency = 10,
469 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100470 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200471 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500472 {
Len Brownde09cdd2017-02-28 16:32:44 -0500473 .name = "C3",
Len Brown85a4d2d2013-01-31 14:40:49 -0500474 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100475 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500476 .exit_latency = 33,
477 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100478 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200479 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500480 {
Len Brownde09cdd2017-02-28 16:32:44 -0500481 .name = "C6",
Len Brown85a4d2d2013-01-31 14:40:49 -0500482 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100483 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500484 .exit_latency = 133,
485 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100486 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200487 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500488 {
Len Brownde09cdd2017-02-28 16:32:44 -0500489 .name = "C7s",
Len Brown85a4d2d2013-01-31 14:40:49 -0500490 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100491 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500492 .exit_latency = 166,
493 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100494 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200495 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500496 {
Len Brownde09cdd2017-02-28 16:32:44 -0500497 .name = "C8",
Len Brown86239ce2013-02-27 13:18:50 -0500498 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100499 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500500 .exit_latency = 300,
501 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100502 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200503 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500504 {
Len Brownde09cdd2017-02-28 16:32:44 -0500505 .name = "C9",
Len Brown86239ce2013-02-27 13:18:50 -0500506 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100507 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500508 .exit_latency = 600,
509 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100510 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200511 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500512 {
Len Brownde09cdd2017-02-28 16:32:44 -0500513 .name = "C10",
Len Brown86239ce2013-02-27 13:18:50 -0500514 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100515 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500516 .exit_latency = 2600,
517 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100518 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200519 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500520 {
Len Browne022e7e2013-02-01 23:37:30 -0500521 .enter = NULL }
Len Brown85a4d2d2013-01-31 14:40:49 -0500522};
Len Browna138b562014-02-04 23:56:40 -0500523static struct cpuidle_state bdw_cstates[] = {
524 {
Len Brownde09cdd2017-02-28 16:32:44 -0500525 .name = "C1",
Len Browna138b562014-02-04 23:56:40 -0500526 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100527 .flags = MWAIT2flg(0x00),
Len Browna138b562014-02-04 23:56:40 -0500528 .exit_latency = 2,
529 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100530 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200531 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500532 {
Len Brownde09cdd2017-02-28 16:32:44 -0500533 .name = "C1E",
Len Browna138b562014-02-04 23:56:40 -0500534 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100535 .flags = MWAIT2flg(0x01),
Len Browna138b562014-02-04 23:56:40 -0500536 .exit_latency = 10,
537 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100538 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200539 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500540 {
Len Brownde09cdd2017-02-28 16:32:44 -0500541 .name = "C3",
Len Browna138b562014-02-04 23:56:40 -0500542 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100543 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500544 .exit_latency = 40,
545 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100546 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200547 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500548 {
Len Brownde09cdd2017-02-28 16:32:44 -0500549 .name = "C6",
Len Browna138b562014-02-04 23:56:40 -0500550 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100551 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500552 .exit_latency = 133,
553 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100554 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200555 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500556 {
Len Brownde09cdd2017-02-28 16:32:44 -0500557 .name = "C7s",
Len Browna138b562014-02-04 23:56:40 -0500558 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100559 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500560 .exit_latency = 166,
561 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100562 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200563 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500564 {
Len Brownde09cdd2017-02-28 16:32:44 -0500565 .name = "C8",
Len Browna138b562014-02-04 23:56:40 -0500566 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100567 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500568 .exit_latency = 300,
569 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100570 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200571 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500572 {
Len Brownde09cdd2017-02-28 16:32:44 -0500573 .name = "C9",
Len Browna138b562014-02-04 23:56:40 -0500574 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100575 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500576 .exit_latency = 600,
577 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100578 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200579 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500580 {
Len Brownde09cdd2017-02-28 16:32:44 -0500581 .name = "C10",
Len Browna138b562014-02-04 23:56:40 -0500582 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100583 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500584 .exit_latency = 2600,
585 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100586 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200587 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500588 {
589 .enter = NULL }
590};
Len Brown85a4d2d2013-01-31 14:40:49 -0500591
Len Brown493f1332015-03-25 23:20:37 -0400592static struct cpuidle_state skl_cstates[] = {
593 {
Len Brownde09cdd2017-02-28 16:32:44 -0500594 .name = "C1",
Len Brown493f1332015-03-25 23:20:37 -0400595 .desc = "MWAIT 0x00",
596 .flags = MWAIT2flg(0x00),
597 .exit_latency = 2,
598 .target_residency = 2,
599 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200600 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400601 {
Len Brownde09cdd2017-02-28 16:32:44 -0500602 .name = "C1E",
Len Brown493f1332015-03-25 23:20:37 -0400603 .desc = "MWAIT 0x01",
604 .flags = MWAIT2flg(0x01),
605 .exit_latency = 10,
606 .target_residency = 20,
607 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200608 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400609 {
Len Brownde09cdd2017-02-28 16:32:44 -0500610 .name = "C3",
Len Brown493f1332015-03-25 23:20:37 -0400611 .desc = "MWAIT 0x10",
612 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
613 .exit_latency = 70,
614 .target_residency = 100,
615 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200616 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400617 {
Len Brownde09cdd2017-02-28 16:32:44 -0500618 .name = "C6",
Len Brown493f1332015-03-25 23:20:37 -0400619 .desc = "MWAIT 0x20",
620 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400621 .exit_latency = 85,
Len Brown493f1332015-03-25 23:20:37 -0400622 .target_residency = 200,
623 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200624 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400625 {
Len Brownde09cdd2017-02-28 16:32:44 -0500626 .name = "C7s",
Len Brown493f1332015-03-25 23:20:37 -0400627 .desc = "MWAIT 0x33",
628 .flags = MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED,
629 .exit_latency = 124,
630 .target_residency = 800,
631 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200632 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400633 {
Len Brownde09cdd2017-02-28 16:32:44 -0500634 .name = "C8",
Len Brown493f1332015-03-25 23:20:37 -0400635 .desc = "MWAIT 0x40",
636 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400637 .exit_latency = 200,
Len Brown493f1332015-03-25 23:20:37 -0400638 .target_residency = 800,
639 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200640 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400641 {
Len Brownde09cdd2017-02-28 16:32:44 -0500642 .name = "C9",
Len Brown135919a2015-09-09 13:35:05 -0400643 .desc = "MWAIT 0x50",
644 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
645 .exit_latency = 480,
646 .target_residency = 5000,
647 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200648 .enter_s2idle = intel_idle_s2idle, },
Len Brown135919a2015-09-09 13:35:05 -0400649 {
Len Brownde09cdd2017-02-28 16:32:44 -0500650 .name = "C10",
Len Brown493f1332015-03-25 23:20:37 -0400651 .desc = "MWAIT 0x60",
652 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
653 .exit_latency = 890,
654 .target_residency = 5000,
655 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200656 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400657 {
658 .enter = NULL }
659};
660
Len Brownf9e71652016-04-06 17:00:58 -0400661static struct cpuidle_state skx_cstates[] = {
662 {
Len Brownde09cdd2017-02-28 16:32:44 -0500663 .name = "C1",
Len Brownf9e71652016-04-06 17:00:58 -0400664 .desc = "MWAIT 0x00",
665 .flags = MWAIT2flg(0x00),
666 .exit_latency = 2,
667 .target_residency = 2,
668 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200669 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400670 {
Len Brownde09cdd2017-02-28 16:32:44 -0500671 .name = "C1E",
Len Brownf9e71652016-04-06 17:00:58 -0400672 .desc = "MWAIT 0x01",
673 .flags = MWAIT2flg(0x01),
674 .exit_latency = 10,
675 .target_residency = 20,
676 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200677 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400678 {
Len Brownde09cdd2017-02-28 16:32:44 -0500679 .name = "C6",
Len Brownf9e71652016-04-06 17:00:58 -0400680 .desc = "MWAIT 0x20",
681 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
682 .exit_latency = 133,
683 .target_residency = 600,
684 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200685 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400686 {
687 .enter = NULL }
688};
689
Jiang Liuba0dc812014-01-09 15:30:26 +0800690static struct cpuidle_state atom_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500691 {
Len Brownde09cdd2017-02-28 16:32:44 -0500692 .name = "C1E",
Len Brown26717172010-03-08 14:07:30 -0500693 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100694 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500695 .exit_latency = 10,
696 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100697 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200698 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500699 {
Len Brownde09cdd2017-02-28 16:32:44 -0500700 .name = "C2",
Len Brown26717172010-03-08 14:07:30 -0500701 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100702 .flags = MWAIT2flg(0x10),
Len Brown26717172010-03-08 14:07:30 -0500703 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500704 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100705 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200706 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500707 {
Len Brownde09cdd2017-02-28 16:32:44 -0500708 .name = "C4",
Len Brown26717172010-03-08 14:07:30 -0500709 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100710 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500711 .exit_latency = 100,
Len Brown26717172010-03-08 14:07:30 -0500712 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100713 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200714 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500715 {
Len Brownde09cdd2017-02-28 16:32:44 -0500716 .name = "C6",
Len Brown7fcca7d2010-10-05 13:43:14 -0400717 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100718 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown7fcca7d2010-10-05 13:43:14 -0400719 .exit_latency = 140,
Len Brown7fcca7d2010-10-05 13:43:14 -0400720 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100721 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200722 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500723 {
724 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500725};
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300726static struct cpuidle_state tangier_cstates[] = {
727 {
Len Brownde09cdd2017-02-28 16:32:44 -0500728 .name = "C1",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300729 .desc = "MWAIT 0x00",
730 .flags = MWAIT2flg(0x00),
731 .exit_latency = 1,
732 .target_residency = 4,
733 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200734 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300735 {
Len Brownde09cdd2017-02-28 16:32:44 -0500736 .name = "C4",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300737 .desc = "MWAIT 0x30",
738 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
739 .exit_latency = 100,
740 .target_residency = 400,
741 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200742 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300743 {
Len Brownde09cdd2017-02-28 16:32:44 -0500744 .name = "C6",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300745 .desc = "MWAIT 0x52",
746 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
747 .exit_latency = 140,
748 .target_residency = 560,
749 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200750 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300751 {
Len Brownde09cdd2017-02-28 16:32:44 -0500752 .name = "C7",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300753 .desc = "MWAIT 0x60",
754 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
755 .exit_latency = 1200,
756 .target_residency = 4000,
757 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200758 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300759 {
Len Brownde09cdd2017-02-28 16:32:44 -0500760 .name = "C9",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300761 .desc = "MWAIT 0x64",
762 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
763 .exit_latency = 10000,
764 .target_residency = 20000,
765 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200766 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300767 {
768 .enter = NULL }
769};
Jiang Liu88390992014-01-09 15:30:27 +0800770static struct cpuidle_state avn_cstates[] = {
Len Brownfab04b22013-11-09 00:30:17 -0500771 {
Len Brownde09cdd2017-02-28 16:32:44 -0500772 .name = "C1",
Len Brownfab04b22013-11-09 00:30:17 -0500773 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100774 .flags = MWAIT2flg(0x00),
Len Brownfab04b22013-11-09 00:30:17 -0500775 .exit_latency = 2,
776 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100777 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200778 .enter_s2idle = intel_idle_s2idle, },
Len Brownfab04b22013-11-09 00:30:17 -0500779 {
Len Brownde09cdd2017-02-28 16:32:44 -0500780 .name = "C6",
Len Brownfab04b22013-11-09 00:30:17 -0500781 .desc = "MWAIT 0x51",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100782 .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownfab04b22013-11-09 00:30:17 -0500783 .exit_latency = 15,
784 .target_residency = 45,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100785 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200786 .enter_s2idle = intel_idle_s2idle, },
Jiang Liu88390992014-01-09 15:30:27 +0800787 {
788 .enter = NULL }
Len Brownfab04b22013-11-09 00:30:17 -0500789};
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700790static struct cpuidle_state knl_cstates[] = {
791 {
Len Brownde09cdd2017-02-28 16:32:44 -0500792 .name = "C1",
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700793 .desc = "MWAIT 0x00",
794 .flags = MWAIT2flg(0x00),
795 .exit_latency = 1,
796 .target_residency = 2,
797 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200798 .enter_s2idle = intel_idle_s2idle },
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700799 {
Len Brownde09cdd2017-02-28 16:32:44 -0500800 .name = "C6",
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700801 .desc = "MWAIT 0x10",
802 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
803 .exit_latency = 120,
804 .target_residency = 500,
805 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200806 .enter_s2idle = intel_idle_s2idle },
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700807 {
808 .enter = NULL }
809};
Len Brown26717172010-03-08 14:07:30 -0500810
Len Brown5dcef692016-04-06 17:00:47 -0400811static struct cpuidle_state bxt_cstates[] = {
812 {
Len Brownde09cdd2017-02-28 16:32:44 -0500813 .name = "C1",
Len Brown5dcef692016-04-06 17:00:47 -0400814 .desc = "MWAIT 0x00",
815 .flags = MWAIT2flg(0x00),
816 .exit_latency = 2,
817 .target_residency = 2,
818 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200819 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400820 {
Len Brownde09cdd2017-02-28 16:32:44 -0500821 .name = "C1E",
Len Brown5dcef692016-04-06 17:00:47 -0400822 .desc = "MWAIT 0x01",
823 .flags = MWAIT2flg(0x01),
824 .exit_latency = 10,
825 .target_residency = 20,
826 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200827 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400828 {
Len Brownde09cdd2017-02-28 16:32:44 -0500829 .name = "C6",
Len Brown5dcef692016-04-06 17:00:47 -0400830 .desc = "MWAIT 0x20",
831 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
832 .exit_latency = 133,
833 .target_residency = 133,
834 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200835 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400836 {
Len Brownde09cdd2017-02-28 16:32:44 -0500837 .name = "C7s",
Len Brown5dcef692016-04-06 17:00:47 -0400838 .desc = "MWAIT 0x31",
839 .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
840 .exit_latency = 155,
841 .target_residency = 155,
842 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200843 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400844 {
Len Brownde09cdd2017-02-28 16:32:44 -0500845 .name = "C8",
Len Brown5dcef692016-04-06 17:00:47 -0400846 .desc = "MWAIT 0x40",
847 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
848 .exit_latency = 1000,
849 .target_residency = 1000,
850 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200851 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400852 {
Len Brownde09cdd2017-02-28 16:32:44 -0500853 .name = "C9",
Len Brown5dcef692016-04-06 17:00:47 -0400854 .desc = "MWAIT 0x50",
855 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
856 .exit_latency = 2000,
857 .target_residency = 2000,
858 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200859 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400860 {
Len Brownde09cdd2017-02-28 16:32:44 -0500861 .name = "C10",
Len Brown5dcef692016-04-06 17:00:47 -0400862 .desc = "MWAIT 0x60",
863 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
864 .exit_latency = 10000,
865 .target_residency = 10000,
866 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200867 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400868 {
869 .enter = NULL }
870};
871
Jacob Pan0080d652016-06-17 01:28:34 -0400872static struct cpuidle_state dnv_cstates[] = {
873 {
Len Brownde09cdd2017-02-28 16:32:44 -0500874 .name = "C1",
Jacob Pan0080d652016-06-17 01:28:34 -0400875 .desc = "MWAIT 0x00",
876 .flags = MWAIT2flg(0x00),
877 .exit_latency = 2,
878 .target_residency = 2,
879 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200880 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400881 {
Len Brownde09cdd2017-02-28 16:32:44 -0500882 .name = "C1E",
Jacob Pan0080d652016-06-17 01:28:34 -0400883 .desc = "MWAIT 0x01",
884 .flags = MWAIT2flg(0x01),
885 .exit_latency = 10,
886 .target_residency = 20,
887 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200888 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400889 {
Len Brownde09cdd2017-02-28 16:32:44 -0500890 .name = "C6",
Jacob Pan0080d652016-06-17 01:28:34 -0400891 .desc = "MWAIT 0x20",
892 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
893 .exit_latency = 50,
894 .target_residency = 500,
895 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200896 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400897 {
898 .enter = NULL }
899};
900
Len Brown26717172010-03-08 14:07:30 -0500901/**
902 * intel_idle
903 * @dev: cpuidle_device
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530904 * @drv: cpuidle driver
Deepthi Dharware978aa72011-10-28 16:20:09 +0530905 * @index: index of cpuidle state
Len Brown26717172010-03-08 14:07:30 -0500906 *
Yanmin Zhang63ff07b2012-01-10 15:48:21 -0800907 * Must be called under local_irq_disable().
Len Brown26717172010-03-08 14:07:30 -0500908 */
Chris Metcalf6727ad92016-10-07 17:02:55 -0700909static __cpuidle int intel_idle(struct cpuidle_device *dev,
910 struct cpuidle_driver *drv, int index)
Len Brown26717172010-03-08 14:07:30 -0500911{
912 unsigned long ecx = 1; /* break on interrupt flag */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530913 struct cpuidle_state *state = &drv->states[index];
Len Brownb1beab42013-01-31 19:55:37 -0500914 unsigned long eax = flg2MWAIT(state->flags);
Len Brown26717172010-03-08 14:07:30 -0500915 unsigned int cstate;
Jason Baron0563bb72017-10-06 13:19:45 -0400916 bool uninitialized_var(tick);
Andy Lutomirski67535732017-11-04 04:16:12 -0700917 int cpu = smp_processor_id();
Len Brown26717172010-03-08 14:07:30 -0500918
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400919 /*
Andy Lutomirski67535732017-11-04 04:16:12 -0700920 * leave_mm() to avoid costly and often unnecessary wakeups
921 * for flushing the user TLB's associated with the active mm.
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400922 */
Andy Lutomirski67535732017-11-04 04:16:12 -0700923 if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
924 leave_mm(cpu);
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400925
Jason Baron0563bb72017-10-06 13:19:45 -0400926 if (!static_cpu_has(X86_FEATURE_ARAT)) {
927 cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
928 MWAIT_CSTATE_MASK) + 1;
929 tick = false;
930 if (!(lapic_timer_reliable_states & (1 << (cstate)))) {
931 tick = true;
932 tick_broadcast_enter();
933 }
934 }
Len Brown26717172010-03-08 14:07:30 -0500935
Peter Zijlstra16824252013-12-12 15:08:36 +0100936 mwait_idle_with_hints(eax, ecx);
Len Brown26717172010-03-08 14:07:30 -0500937
Jason Baron0563bb72017-10-06 13:19:45 -0400938 if (!static_cpu_has(X86_FEATURE_ARAT) && tick)
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200939 tick_broadcast_exit();
Len Brown26717172010-03-08 14:07:30 -0500940
Deepthi Dharware978aa72011-10-28 16:20:09 +0530941 return index;
Len Brown26717172010-03-08 14:07:30 -0500942}
943
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100944/**
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200945 * intel_idle_s2idle - simplified "enter" callback routine for suspend-to-idle
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100946 * @dev: cpuidle_device
947 * @drv: cpuidle driver
948 * @index: state index
949 */
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200950static void intel_idle_s2idle(struct cpuidle_device *dev,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100951 struct cpuidle_driver *drv, int index)
952{
953 unsigned long ecx = 1; /* break on interrupt flag */
954 unsigned long eax = flg2MWAIT(drv->states[index].flags);
955
956 mwait_idle_with_hints(eax, ecx);
957}
958
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +0100959static void __setup_broadcast_timer(bool on)
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800960{
Thomas Gleixner76962ca2015-04-03 02:02:34 +0200961 if (on)
962 tick_broadcast_enable();
963 else
964 tick_broadcast_disable();
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800965}
966
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +0100967static void auto_demotion_disable(void)
Len Brown14796fc2011-01-18 20:48:27 -0500968{
969 unsigned long long msr_bits;
970
Len Brown6cfb2372017-01-07 23:23:25 -0500971 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
Andi Kleenb66b8b92012-01-26 00:09:07 +0100972 msr_bits &= ~(icpu->auto_demotion_disable_flags);
Len Brown6cfb2372017-01-07 23:23:25 -0500973 wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
Len Brown14796fc2011-01-18 20:48:27 -0500974}
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +0100975static void c1e_promotion_disable(void)
Len Brown32e95182013-02-02 01:31:56 -0500976{
977 unsigned long long msr_bits;
978
979 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
980 msr_bits &= ~0x2;
981 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
982}
Len Brown14796fc2011-01-18 20:48:27 -0500983
Andi Kleenb66b8b92012-01-26 00:09:07 +0100984static const struct idle_cpu idle_cpu_nehalem = {
985 .state_table = nehalem_cstates,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100986 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
Len Brown32e95182013-02-02 01:31:56 -0500987 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100988};
989
990static const struct idle_cpu idle_cpu_atom = {
991 .state_table = atom_cstates,
992};
993
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300994static const struct idle_cpu idle_cpu_tangier = {
995 .state_table = tangier_cstates,
996};
997
Andi Kleenb66b8b92012-01-26 00:09:07 +0100998static const struct idle_cpu idle_cpu_lincroft = {
999 .state_table = atom_cstates,
1000 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
1001};
1002
1003static const struct idle_cpu idle_cpu_snb = {
1004 .state_table = snb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001005 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +01001006};
1007
Len Brown718987d2014-02-14 02:30:00 -05001008static const struct idle_cpu idle_cpu_byt = {
1009 .state_table = byt_cstates,
1010 .disable_promotion_to_c1e = true,
Len Brown8c058d532014-07-31 15:21:24 -04001011 .byt_auto_demotion_disable_flag = true,
Len Brown718987d2014-02-14 02:30:00 -05001012};
1013
Len Browncab07a52015-03-27 20:54:01 -04001014static const struct idle_cpu idle_cpu_cht = {
1015 .state_table = cht_cstates,
1016 .disable_promotion_to_c1e = true,
1017 .byt_auto_demotion_disable_flag = true,
1018};
1019
Len Brown6edab082012-06-01 19:45:32 -04001020static const struct idle_cpu idle_cpu_ivb = {
1021 .state_table = ivb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001022 .disable_promotion_to_c1e = true,
Len Brown6edab082012-06-01 19:45:32 -04001023};
1024
Len Brown0138d8f2014-04-04 01:21:07 -04001025static const struct idle_cpu idle_cpu_ivt = {
1026 .state_table = ivt_cstates,
1027 .disable_promotion_to_c1e = true,
1028};
1029
Len Brown85a4d2d2013-01-31 14:40:49 -05001030static const struct idle_cpu idle_cpu_hsw = {
1031 .state_table = hsw_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001032 .disable_promotion_to_c1e = true,
Len Brown85a4d2d2013-01-31 14:40:49 -05001033};
1034
Len Browna138b562014-02-04 23:56:40 -05001035static const struct idle_cpu idle_cpu_bdw = {
1036 .state_table = bdw_cstates,
1037 .disable_promotion_to_c1e = true,
1038};
1039
Len Brown493f1332015-03-25 23:20:37 -04001040static const struct idle_cpu idle_cpu_skl = {
1041 .state_table = skl_cstates,
1042 .disable_promotion_to_c1e = true,
1043};
1044
Len Brownf9e71652016-04-06 17:00:58 -04001045static const struct idle_cpu idle_cpu_skx = {
1046 .state_table = skx_cstates,
1047 .disable_promotion_to_c1e = true,
1048};
Len Brown493f1332015-03-25 23:20:37 -04001049
Len Brownfab04b22013-11-09 00:30:17 -05001050static const struct idle_cpu idle_cpu_avn = {
1051 .state_table = avn_cstates,
1052 .disable_promotion_to_c1e = true,
1053};
1054
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001055static const struct idle_cpu idle_cpu_knl = {
1056 .state_table = knl_cstates,
1057};
1058
Len Brown5dcef692016-04-06 17:00:47 -04001059static const struct idle_cpu idle_cpu_bxt = {
1060 .state_table = bxt_cstates,
1061 .disable_promotion_to_c1e = true,
1062};
1063
Jacob Pan0080d652016-06-17 01:28:34 -04001064static const struct idle_cpu idle_cpu_dnv = {
1065 .state_table = dnv_cstates,
1066 .disable_promotion_to_c1e = true,
1067};
1068
Andi Kleenb66b8b92012-01-26 00:09:07 +01001069#define ICPU(model, cpu) \
Len Browna4c44752017-11-09 02:19:39 -05001070 { X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long)&cpu }
Andi Kleenb66b8b92012-01-26 00:09:07 +01001071
Mathias Kraused5cdc3c2015-03-25 22:15:14 +01001072static const struct x86_cpu_id intel_idle_ids[] __initconst = {
Dave Hansendb73c5a2016-06-02 17:19:32 -07001073 ICPU(INTEL_FAM6_NEHALEM_EP, idle_cpu_nehalem),
1074 ICPU(INTEL_FAM6_NEHALEM, idle_cpu_nehalem),
Dave Hansen4b3b2342016-06-29 12:27:37 -07001075 ICPU(INTEL_FAM6_NEHALEM_G, idle_cpu_nehalem),
Dave Hansendb73c5a2016-06-02 17:19:32 -07001076 ICPU(INTEL_FAM6_WESTMERE, idle_cpu_nehalem),
1077 ICPU(INTEL_FAM6_WESTMERE_EP, idle_cpu_nehalem),
1078 ICPU(INTEL_FAM6_NEHALEM_EX, idle_cpu_nehalem),
1079 ICPU(INTEL_FAM6_ATOM_PINEVIEW, idle_cpu_atom),
1080 ICPU(INTEL_FAM6_ATOM_LINCROFT, idle_cpu_lincroft),
1081 ICPU(INTEL_FAM6_WESTMERE_EX, idle_cpu_nehalem),
1082 ICPU(INTEL_FAM6_SANDYBRIDGE, idle_cpu_snb),
1083 ICPU(INTEL_FAM6_SANDYBRIDGE_X, idle_cpu_snb),
1084 ICPU(INTEL_FAM6_ATOM_CEDARVIEW, idle_cpu_atom),
1085 ICPU(INTEL_FAM6_ATOM_SILVERMONT1, idle_cpu_byt),
Andy Shevchenko5e7ec262016-10-25 17:11:39 +03001086 ICPU(INTEL_FAM6_ATOM_MERRIFIELD, idle_cpu_tangier),
Dave Hansendb73c5a2016-06-02 17:19:32 -07001087 ICPU(INTEL_FAM6_ATOM_AIRMONT, idle_cpu_cht),
1088 ICPU(INTEL_FAM6_IVYBRIDGE, idle_cpu_ivb),
1089 ICPU(INTEL_FAM6_IVYBRIDGE_X, idle_cpu_ivt),
1090 ICPU(INTEL_FAM6_HASWELL_CORE, idle_cpu_hsw),
1091 ICPU(INTEL_FAM6_HASWELL_X, idle_cpu_hsw),
1092 ICPU(INTEL_FAM6_HASWELL_ULT, idle_cpu_hsw),
1093 ICPU(INTEL_FAM6_HASWELL_GT3E, idle_cpu_hsw),
1094 ICPU(INTEL_FAM6_ATOM_SILVERMONT2, idle_cpu_avn),
1095 ICPU(INTEL_FAM6_BROADWELL_CORE, idle_cpu_bdw),
1096 ICPU(INTEL_FAM6_BROADWELL_GT3E, idle_cpu_bdw),
1097 ICPU(INTEL_FAM6_BROADWELL_X, idle_cpu_bdw),
1098 ICPU(INTEL_FAM6_BROADWELL_XEON_D, idle_cpu_bdw),
1099 ICPU(INTEL_FAM6_SKYLAKE_MOBILE, idle_cpu_skl),
1100 ICPU(INTEL_FAM6_SKYLAKE_DESKTOP, idle_cpu_skl),
1101 ICPU(INTEL_FAM6_KABYLAKE_MOBILE, idle_cpu_skl),
1102 ICPU(INTEL_FAM6_KABYLAKE_DESKTOP, idle_cpu_skl),
1103 ICPU(INTEL_FAM6_SKYLAKE_X, idle_cpu_skx),
1104 ICPU(INTEL_FAM6_XEON_PHI_KNL, idle_cpu_knl),
Piotr Luca2c1bc62016-10-13 17:30:58 +02001105 ICPU(INTEL_FAM6_XEON_PHI_KNM, idle_cpu_knl),
Dave Hansendb73c5a2016-06-02 17:19:32 -07001106 ICPU(INTEL_FAM6_ATOM_GOLDMONT, idle_cpu_bxt),
David E. Box1b2e8762017-04-22 23:06:25 -07001107 ICPU(INTEL_FAM6_ATOM_GEMINI_LAKE, idle_cpu_bxt),
Jacob Pan0080d652016-06-17 01:28:34 -04001108 ICPU(INTEL_FAM6_ATOM_DENVERTON, idle_cpu_dnv),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001109 {}
1110};
Andi Kleenb66b8b92012-01-26 00:09:07 +01001111
Len Brown26717172010-03-08 14:07:30 -05001112/*
1113 * intel_idle_probe()
1114 */
Bartlomiej Zolnierkiewicz00f3e752013-08-30 12:27:45 +02001115static int __init intel_idle_probe(void)
Len Brown26717172010-03-08 14:07:30 -05001116{
Len Brownc4236282010-05-28 02:22:03 -04001117 unsigned int eax, ebx, ecx;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001118 const struct x86_cpu_id *id;
Len Brown26717172010-03-08 14:07:30 -05001119
1120 if (max_cstate == 0) {
Joe Perches654d08a2017-06-09 12:29:20 -07001121 pr_debug("disabled\n");
Len Brown26717172010-03-08 14:07:30 -05001122 return -EPERM;
1123 }
1124
Andi Kleenb66b8b92012-01-26 00:09:07 +01001125 id = x86_match_cpu(intel_idle_ids);
1126 if (!id) {
1127 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
1128 boot_cpu_data.x86 == 6)
Joe Perches654d08a2017-06-09 12:29:20 -07001129 pr_debug("does not run on family %d model %d\n",
1130 boot_cpu_data.x86, boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001131 return -ENODEV;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001132 }
Len Brown26717172010-03-08 14:07:30 -05001133
Len Browna4c44752017-11-09 02:19:39 -05001134 if (!boot_cpu_has(X86_FEATURE_MWAIT)) {
1135 pr_debug("Please enable MWAIT in BIOS SETUP\n");
1136 return -ENODEV;
1137 }
1138
Len Brown26717172010-03-08 14:07:30 -05001139 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
1140 return -ENODEV;
1141
Len Brownc4236282010-05-28 02:22:03 -04001142 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001143
1144 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
Thomas Renninger5c2a9f02011-12-04 22:17:29 +01001145 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
1146 !mwait_substates)
Len Brown26717172010-03-08 14:07:30 -05001147 return -ENODEV;
Len Brown26717172010-03-08 14:07:30 -05001148
Joe Perches654d08a2017-06-09 12:29:20 -07001149 pr_debug("MWAIT substates: 0x%x\n", mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001150
Andi Kleenb66b8b92012-01-26 00:09:07 +01001151 icpu = (const struct idle_cpu *)id->driver_data;
1152 cpuidle_state_table = icpu->state_table;
Len Brown26717172010-03-08 14:07:30 -05001153
Joe Perches654d08a2017-06-09 12:29:20 -07001154 pr_debug("v" INTEL_IDLE_VERSION " model 0x%X\n",
1155 boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001156
Len Brown26717172010-03-08 14:07:30 -05001157 return 0;
1158}
1159
1160/*
1161 * intel_idle_cpuidle_devices_uninit()
Richard Cochranca424892016-04-06 17:00:53 -04001162 * Unregisters the cpuidle devices.
Len Brown26717172010-03-08 14:07:30 -05001163 */
1164static void intel_idle_cpuidle_devices_uninit(void)
1165{
1166 int i;
1167 struct cpuidle_device *dev;
1168
1169 for_each_online_cpu(i) {
1170 dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
1171 cpuidle_unregister_device(dev);
1172 }
Len Brown26717172010-03-08 14:07:30 -05001173}
Len Brown0138d8f2014-04-04 01:21:07 -04001174
1175/*
Len Brownd70e28f2016-03-13 00:33:48 -05001176 * ivt_idle_state_table_update(void)
1177 *
1178 * Tune IVT multi-socket targets
1179 * Assumption: num_sockets == (max_package_num + 1)
1180 */
1181static void ivt_idle_state_table_update(void)
1182{
1183 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1184 int cpu, package_num, num_sockets = 1;
1185
1186 for_each_online_cpu(cpu) {
1187 package_num = topology_physical_package_id(cpu);
1188 if (package_num + 1 > num_sockets) {
1189 num_sockets = package_num + 1;
1190
1191 if (num_sockets > 4) {
1192 cpuidle_state_table = ivt_cstates_8s;
1193 return;
1194 }
1195 }
1196 }
1197
1198 if (num_sockets > 2)
1199 cpuidle_state_table = ivt_cstates_4s;
1200
1201 /* else, 1 and 2 socket systems use default ivt_cstates */
1202}
Len Brown5dcef692016-04-06 17:00:47 -04001203
1204/*
1205 * Translate IRTL (Interrupt Response Time Limit) MSR to usec
1206 */
1207
1208static unsigned int irtl_ns_units[] = {
1209 1, 32, 1024, 32768, 1048576, 33554432, 0, 0 };
1210
1211static unsigned long long irtl_2_usec(unsigned long long irtl)
1212{
1213 unsigned long long ns;
1214
Jan Beulich3451ab32016-06-27 00:35:12 -06001215 if (!irtl)
1216 return 0;
1217
Jan Beulichbef45092016-06-27 00:35:48 -06001218 ns = irtl_ns_units[(irtl >> 10) & 0x7];
Len Brown5dcef692016-04-06 17:00:47 -04001219
1220 return div64_u64((irtl & 0x3FF) * ns, 1000);
1221}
1222/*
1223 * bxt_idle_state_table_update(void)
1224 *
1225 * On BXT, we trust the IRTL to show the definitive maximum latency
1226 * We use the same value for target_residency.
1227 */
1228static void bxt_idle_state_table_update(void)
1229{
1230 unsigned long long msr;
Jan Beulich3451ab32016-06-27 00:35:12 -06001231 unsigned int usec;
Len Brown5dcef692016-04-06 17:00:47 -04001232
1233 rdmsrl(MSR_PKGC6_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001234 usec = irtl_2_usec(msr);
1235 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001236 bxt_cstates[2].exit_latency = usec;
1237 bxt_cstates[2].target_residency = usec;
1238 }
1239
1240 rdmsrl(MSR_PKGC7_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001241 usec = irtl_2_usec(msr);
1242 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001243 bxt_cstates[3].exit_latency = usec;
1244 bxt_cstates[3].target_residency = usec;
1245 }
1246
1247 rdmsrl(MSR_PKGC8_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001248 usec = irtl_2_usec(msr);
1249 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001250 bxt_cstates[4].exit_latency = usec;
1251 bxt_cstates[4].target_residency = usec;
1252 }
1253
1254 rdmsrl(MSR_PKGC9_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001255 usec = irtl_2_usec(msr);
1256 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001257 bxt_cstates[5].exit_latency = usec;
1258 bxt_cstates[5].target_residency = usec;
1259 }
1260
1261 rdmsrl(MSR_PKGC10_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001262 usec = irtl_2_usec(msr);
1263 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001264 bxt_cstates[6].exit_latency = usec;
1265 bxt_cstates[6].target_residency = usec;
1266 }
1267
1268}
Len Brownd70e28f2016-03-13 00:33:48 -05001269/*
1270 * sklh_idle_state_table_update(void)
1271 *
1272 * On SKL-H (model 0x5e) disable C8 and C9 if:
1273 * C10 is enabled and SGX disabled
1274 */
1275static void sklh_idle_state_table_update(void)
1276{
1277 unsigned long long msr;
1278 unsigned int eax, ebx, ecx, edx;
1279
1280
1281 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1282 if (max_cstate <= 7)
1283 return;
1284
1285 /* if PC10 not present in CPUID.MWAIT.EDX */
1286 if ((mwait_substates & (0xF << 28)) == 0)
1287 return;
1288
Len Brown6cfb2372017-01-07 23:23:25 -05001289 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr);
Len Brownd70e28f2016-03-13 00:33:48 -05001290
1291 /* PC10 is not enabled in PKG C-state limit */
1292 if ((msr & 0xF) != 8)
1293 return;
1294
1295 ecx = 0;
1296 cpuid(7, &eax, &ebx, &ecx, &edx);
1297
1298 /* if SGX is present */
1299 if (ebx & (1 << 2)) {
1300
1301 rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
1302
1303 /* if SGX is enabled */
1304 if (msr & (1 << 18))
1305 return;
1306 }
1307
1308 skl_cstates[5].disabled = 1; /* C8-SKL */
1309 skl_cstates[6].disabled = 1; /* C9-SKL */
1310}
1311/*
Len Brown0138d8f2014-04-04 01:21:07 -04001312 * intel_idle_state_table_update()
1313 *
1314 * Update the default state_table for this CPU-id
Len Brown0138d8f2014-04-04 01:21:07 -04001315 */
Len Brownd70e28f2016-03-13 00:33:48 -05001316
1317static void intel_idle_state_table_update(void)
Len Brown0138d8f2014-04-04 01:21:07 -04001318{
Len Brownd70e28f2016-03-13 00:33:48 -05001319 switch (boot_cpu_data.x86_model) {
Len Brown0138d8f2014-04-04 01:21:07 -04001320
Dave Hansendb73c5a2016-06-02 17:19:32 -07001321 case INTEL_FAM6_IVYBRIDGE_X:
Len Brownd70e28f2016-03-13 00:33:48 -05001322 ivt_idle_state_table_update();
1323 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001324 case INTEL_FAM6_ATOM_GOLDMONT:
David E. Box1b2e8762017-04-22 23:06:25 -07001325 case INTEL_FAM6_ATOM_GEMINI_LAKE:
Len Brown5dcef692016-04-06 17:00:47 -04001326 bxt_idle_state_table_update();
1327 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001328 case INTEL_FAM6_SKYLAKE_DESKTOP:
Len Brownd70e28f2016-03-13 00:33:48 -05001329 sklh_idle_state_table_update();
1330 break;
Len Brown0138d8f2014-04-04 01:21:07 -04001331 }
Len Brown0138d8f2014-04-04 01:21:07 -04001332}
1333
Len Brown26717172010-03-08 14:07:30 -05001334/*
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301335 * intel_idle_cpuidle_driver_init()
1336 * allocate, initialize cpuidle_states
1337 */
Richard Cochran5469c822016-04-06 17:00:49 -04001338static void __init intel_idle_cpuidle_driver_init(void)
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301339{
1340 int cstate;
1341 struct cpuidle_driver *drv = &intel_idle_driver;
1342
Len Brown0138d8f2014-04-04 01:21:07 -04001343 intel_idle_state_table_update();
1344
Rafael J. Wysocki1b39e3f2017-08-29 03:14:37 +02001345 cpuidle_poll_state_init(drv);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301346 drv->state_count = 1;
1347
Len Browne022e7e2013-02-01 23:37:30 -05001348 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
Len Brown24bfa952014-02-14 00:50:34 -05001349 int num_substates, mwait_hint, mwait_cstate;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301350
Len Brown7dd0e0a2015-05-27 17:11:37 -04001351 if ((cpuidle_state_table[cstate].enter == NULL) &&
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +02001352 (cpuidle_state_table[cstate].enter_s2idle == NULL))
Len Browne022e7e2013-02-01 23:37:30 -05001353 break;
1354
1355 if (cstate + 1 > max_cstate) {
Joe Perches654d08a2017-06-09 12:29:20 -07001356 pr_info("max_cstate %d reached\n", max_cstate);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301357 break;
1358 }
1359
Len Browne022e7e2013-02-01 23:37:30 -05001360 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
1361 mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301362
Len Brown24bfa952014-02-14 00:50:34 -05001363 /* number of sub-states for this state in CPUID.MWAIT */
Len Browne022e7e2013-02-01 23:37:30 -05001364 num_substates = (mwait_substates >> ((mwait_cstate + 1) * 4))
1365 & MWAIT_SUBSTATE_MASK;
1366
Len Brown24bfa952014-02-14 00:50:34 -05001367 /* if NO sub-states for this state in CPUID, skip it */
1368 if (num_substates == 0)
Len Browne022e7e2013-02-01 23:37:30 -05001369 continue;
1370
Len Brownd70e28f2016-03-13 00:33:48 -05001371 /* if state marked as disabled, skip it */
1372 if (cpuidle_state_table[cstate].disabled != 0) {
Joe Perches654d08a2017-06-09 12:29:20 -07001373 pr_debug("state %s is disabled\n",
1374 cpuidle_state_table[cstate].name);
Len Brownd70e28f2016-03-13 00:33:48 -05001375 continue;
1376 }
1377
1378
Len Browne022e7e2013-02-01 23:37:30 -05001379 if (((mwait_cstate + 1) > 2) &&
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301380 !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
1381 mark_tsc_unstable("TSC halts in idle"
1382 " states deeper than C2");
1383
1384 drv->states[drv->state_count] = /* structure copy */
1385 cpuidle_state_table[cstate];
1386
1387 drv->state_count += 1;
1388 }
1389
Len Brown8c058d532014-07-31 15:21:24 -04001390 if (icpu->byt_auto_demotion_disable_flag) {
1391 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
1392 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
1393 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301394}
1395
1396
1397/*
Thomas Renninger65b7f832012-01-17 22:40:08 +01001398 * intel_idle_cpu_init()
Len Brown26717172010-03-08 14:07:30 -05001399 * allocate, initialize, register cpuidle_devices
Thomas Renninger65b7f832012-01-17 22:40:08 +01001400 * @cpu: cpu/core to initialize
Len Brown26717172010-03-08 14:07:30 -05001401 */
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001402static int intel_idle_cpu_init(unsigned int cpu)
Len Brown26717172010-03-08 14:07:30 -05001403{
Len Brown26717172010-03-08 14:07:30 -05001404 struct cpuidle_device *dev;
1405
Thomas Renninger65b7f832012-01-17 22:40:08 +01001406 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001407 dev->cpu = cpu;
Len Brown26717172010-03-08 14:07:30 -05001408
Thomas Renninger65b7f832012-01-17 22:40:08 +01001409 if (cpuidle_register_device(dev)) {
Joe Perches654d08a2017-06-09 12:29:20 -07001410 pr_debug("cpuidle_register_device %d failed!\n", cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001411 return -EIO;
Len Brown26717172010-03-08 14:07:30 -05001412 }
1413
Andi Kleenb66b8b92012-01-26 00:09:07 +01001414 if (icpu->auto_demotion_disable_flags)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001415 auto_demotion_disable();
Thomas Renninger65b7f832012-01-17 22:40:08 +01001416
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001417 if (icpu->disable_promotion_to_c1e)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001418 c1e_promotion_disable();
1419
1420 return 0;
1421}
1422
1423static int intel_idle_cpu_online(unsigned int cpu)
1424{
1425 struct cpuidle_device *dev;
1426
1427 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
1428 __setup_broadcast_timer(true);
1429
1430 /*
1431 * Some systems can hotplug a cpu at runtime after
1432 * the kernel has booted, we have to initialize the
1433 * driver in this case
1434 */
1435 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
1436 if (!dev->registered)
1437 return intel_idle_cpu_init(cpu);
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001438
Len Brown26717172010-03-08 14:07:30 -05001439 return 0;
1440}
Len Brown26717172010-03-08 14:07:30 -05001441
1442static int __init intel_idle_init(void)
1443{
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001444 int retval;
Len Brown26717172010-03-08 14:07:30 -05001445
Thomas Renningerd1896042010-11-03 17:06:14 +01001446 /* Do not load intel_idle at all for now if idle= is passed */
1447 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
1448 return -ENODEV;
1449
Len Brown26717172010-03-08 14:07:30 -05001450 retval = intel_idle_probe();
1451 if (retval)
1452 return retval;
1453
Richard Cochrane9df69c2016-04-06 17:00:52 -04001454 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
1455 if (intel_idle_cpuidle_devices == NULL)
1456 return -ENOMEM;
1457
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301458 intel_idle_cpuidle_driver_init();
Len Brown26717172010-03-08 14:07:30 -05001459 retval = cpuidle_register_driver(&intel_idle_driver);
1460 if (retval) {
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001461 struct cpuidle_driver *drv = cpuidle_get_driver();
Joe Perches654d08a2017-06-09 12:29:20 -07001462 printk(KERN_DEBUG pr_fmt("intel_idle yielding to %s\n"),
1463 drv ? drv->name : "none");
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001464 goto init_driver_fail;
Len Brown26717172010-03-08 14:07:30 -05001465 }
1466
Richard Cochran2259a812016-04-06 17:00:54 -04001467 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
1468 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
Richard Cochran2259a812016-04-06 17:00:54 -04001469
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001470 retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online",
1471 intel_idle_cpu_online, NULL);
1472 if (retval < 0)
1473 goto hp_setup_fail;
Len Brown26717172010-03-08 14:07:30 -05001474
Joe Perches654d08a2017-06-09 12:29:20 -07001475 pr_debug("lapic_timer_reliable_states 0x%x\n",
1476 lapic_timer_reliable_states);
Richard Cochran2259a812016-04-06 17:00:54 -04001477
Len Brown26717172010-03-08 14:07:30 -05001478 return 0;
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001479
1480hp_setup_fail:
1481 intel_idle_cpuidle_devices_uninit();
1482 cpuidle_unregister_driver(&intel_idle_driver);
1483init_driver_fail:
1484 free_percpu(intel_idle_cpuidle_devices);
1485 return retval;
1486
Len Brown26717172010-03-08 14:07:30 -05001487}
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001488device_initcall(intel_idle_init);
Len Brown26717172010-03-08 14:07:30 -05001489
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001490/*
1491 * We are not really modular, but we used to support that. Meaning we also
1492 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
1493 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
1494 * is the easiest way (currently) to continue doing that.
1495 */
Len Brown26717172010-03-08 14:07:30 -05001496module_param(max_cstate, int, 0444);