blob: 7833e650789f815fca66db5ab786a89ceb6f4eed [file] [log] [blame]
Thomas Gleixnera61127c2019-05-29 16:57:49 -07001// SPDX-License-Identifier: GPL-2.0-only
Len Brown26717172010-03-08 14:07:30 -05002/*
3 * intel_idle.c - native hardware idle loop for modern Intel processors
4 *
Len Brownfab04b22013-11-09 00:30:17 -05005 * Copyright (c) 2013, Intel Corporation.
Len Brown26717172010-03-08 14:07:30 -05006 * Len Brown <len.brown@intel.com>
Len Brown26717172010-03-08 14:07:30 -05007 */
8
9/*
10 * intel_idle is a cpuidle driver that loads on specific Intel processors
11 * in lieu of the legacy ACPI processor_idle driver. The intent is to
12 * make Linux more efficient on these processors, as intel_idle knows
13 * more than ACPI, as well as make Linux more immune to ACPI BIOS bugs.
14 */
15
16/*
17 * Design Assumptions
18 *
19 * All CPUs have same idle states as boot CPU
20 *
21 * Chipset BM_STS (bus master status) bit is a NOP
22 * for preventing entry into deep C-stats
23 */
24
25/*
26 * Known limitations
27 *
28 * The driver currently initializes for_each_online_cpu() upon modprobe.
29 * It it unaware of subsequent processors hot-added to the system.
30 * This means that if you boot with maxcpus=n and later online
31 * processors above n, those processors will use C1 only.
32 *
33 * ACPI has a .suspend hack to turn off deep c-statees during suspend
34 * to avoid complications with the lapic timer workaround.
35 * Have not seen issues with suspend, but may need same workaround here.
36 *
Len Brown26717172010-03-08 14:07:30 -050037 */
38
39/* un-comment DEBUG to enable pr_debug() statements */
40#define DEBUG
41
Joe Perches654d08a2017-06-09 12:29:20 -070042#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
43
Rafael J. Wysocki18734952019-12-13 09:56:01 +010044#include <linux/acpi.h>
Len Brown26717172010-03-08 14:07:30 -050045#include <linux/kernel.h>
46#include <linux/cpuidle.h>
Thomas Gleixner76962ca2015-04-03 02:02:34 +020047#include <linux/tick.h>
Len Brown26717172010-03-08 14:07:30 -050048#include <trace/events/power.h>
49#include <linux/sched.h>
Shaohua Li2a2d31c2011-01-10 09:38:12 +080050#include <linux/notifier.h>
51#include <linux/cpu.h>
Paul Gortmaker02c4fae2016-06-17 01:28:33 -040052#include <linux/moduleparam.h>
Andi Kleenb66b8b92012-01-26 00:09:07 +010053#include <asm/cpu_device_id.h>
Dave Hansendb73c5a2016-06-02 17:19:32 -070054#include <asm/intel-family.h>
H. Peter Anvinbc83ccc2010-09-17 15:36:40 -070055#include <asm/mwait.h>
Len Brown14796fc2011-01-18 20:48:27 -050056#include <asm/msr.h>
Len Brown26717172010-03-08 14:07:30 -050057
Len Brownd70e28f2016-03-13 00:33:48 -050058#define INTEL_IDLE_VERSION "0.4.1"
Len Brown26717172010-03-08 14:07:30 -050059
Len Brown26717172010-03-08 14:07:30 -050060static struct cpuidle_driver intel_idle_driver = {
61 .name = "intel_idle",
62 .owner = THIS_MODULE,
63};
64/* intel_idle.max_cstate=0 disables driver */
Len Brown137ecc72013-02-01 21:35:35 -050065static int max_cstate = CPUIDLE_STATE_MAX - 1;
Len Brown26717172010-03-08 14:07:30 -050066
Len Brownc4236282010-05-28 02:22:03 -040067static unsigned int mwait_substates;
Len Brown26717172010-03-08 14:07:30 -050068
Shaohua Li2a2d31c2011-01-10 09:38:12 +080069#define LAPIC_TIMER_ALWAYS_RELIABLE 0xFFFFFFFF
Len Brown26717172010-03-08 14:07:30 -050070/* Reliable LAPIC Timer States, bit 1 for C1 etc. */
Len Brownd13780d2010-07-07 00:12:03 -040071static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
Len Brown26717172010-03-08 14:07:30 -050072
Andi Kleenb66b8b92012-01-26 00:09:07 +010073struct idle_cpu {
74 struct cpuidle_state *state_table;
75
76 /*
77 * Hardware C-state auto-demotion may not always be optimal.
78 * Indicate which enable bits to clear here.
79 */
80 unsigned long auto_demotion_disable_flags;
Len Brown8c058d532014-07-31 15:21:24 -040081 bool byt_auto_demotion_disable_flag;
Len Brown32e95182013-02-02 01:31:56 -050082 bool disable_promotion_to_c1e;
Rafael J. Wysockibff8e602019-12-13 09:56:21 +010083 bool use_acpi;
Andi Kleenb66b8b92012-01-26 00:09:07 +010084};
85
86static const struct idle_cpu *icpu;
Namhyung Kim3265eba2010-08-08 03:10:03 +090087static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053088static int intel_idle(struct cpuidle_device *dev,
89 struct cpuidle_driver *drv, int index);
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +020090static void intel_idle_s2idle(struct cpuidle_device *dev,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +010091 struct cpuidle_driver *drv, int index);
Len Brown26717172010-03-08 14:07:30 -050092static struct cpuidle_state *cpuidle_state_table;
93
94/*
Rafael J. Wysockibff8e602019-12-13 09:56:21 +010095 * Enable this state by default even if the ACPI _CST does not list it.
96 */
97#define CPUIDLE_FLAG_ALWAYS_ENABLE BIT(15)
98
99/*
Len Brown956d0332011-01-12 02:51:20 -0500100 * Set this flag for states where the HW flushes the TLB for us
101 * and so we don't need cross-calls to keep it consistent.
102 * If this flag is set, SW flushes the TLB, so even if the
103 * HW doesn't do the flushing, this flag is safe to use.
104 */
105#define CPUIDLE_FLAG_TLB_FLUSHED 0x10000
106
107/*
Len Brownb1beab42013-01-31 19:55:37 -0500108 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
109 * the C-state (top nibble) and sub-state (bottom nibble)
110 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
111 *
112 * We store the hint at the top of our "flags" for each state.
113 */
114#define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
115#define MWAIT2flg(eax) ((eax & 0xFF) << 24)
116
117/*
Len Brown26717172010-03-08 14:07:30 -0500118 * States are indexed by the cstate number,
119 * which is also the index into the MWAIT hint array.
120 * Thus C0 is a dummy.
121 */
Jiang Liuba0dc812014-01-09 15:30:26 +0800122static struct cpuidle_state nehalem_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500123 {
Len Brownde09cdd2017-02-28 16:32:44 -0500124 .name = "C1",
Len Brown26717172010-03-08 14:07:30 -0500125 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100126 .flags = MWAIT2flg(0x00),
Len Brown26717172010-03-08 14:07:30 -0500127 .exit_latency = 3,
Len Brown26717172010-03-08 14:07:30 -0500128 .target_residency = 6,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100129 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200130 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500131 {
Len Brownde09cdd2017-02-28 16:32:44 -0500132 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500133 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100134 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500135 .exit_latency = 10,
136 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100137 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200138 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500139 {
Len Brownde09cdd2017-02-28 16:32:44 -0500140 .name = "C3",
Len Brown26717172010-03-08 14:07:30 -0500141 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100142 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500143 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500144 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100145 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200146 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500147 {
Len Brownde09cdd2017-02-28 16:32:44 -0500148 .name = "C6",
Len Brown26717172010-03-08 14:07:30 -0500149 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100150 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500151 .exit_latency = 200,
Len Brown26717172010-03-08 14:07:30 -0500152 .target_residency = 800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100153 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200154 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500155 {
156 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500157};
158
Jiang Liuba0dc812014-01-09 15:30:26 +0800159static struct cpuidle_state snb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500160 {
Len Brownde09cdd2017-02-28 16:32:44 -0500161 .name = "C1",
Len Brownd13780d2010-07-07 00:12:03 -0400162 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100163 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500164 .exit_latency = 2,
165 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100166 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200167 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500168 {
Len Brownde09cdd2017-02-28 16:32:44 -0500169 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500170 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100171 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500172 .exit_latency = 10,
173 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100174 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200175 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500176 {
Len Brownde09cdd2017-02-28 16:32:44 -0500177 .name = "C3",
Len Brownd13780d2010-07-07 00:12:03 -0400178 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100179 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400180 .exit_latency = 80,
Len Brownddbd5502010-12-13 18:28:22 -0500181 .target_residency = 211,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100182 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200183 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500184 {
Len Brownde09cdd2017-02-28 16:32:44 -0500185 .name = "C6",
Len Brownd13780d2010-07-07 00:12:03 -0400186 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100187 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400188 .exit_latency = 104,
Len Brownddbd5502010-12-13 18:28:22 -0500189 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100190 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200191 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500192 {
Len Brownde09cdd2017-02-28 16:32:44 -0500193 .name = "C7",
Len Brownd13780d2010-07-07 00:12:03 -0400194 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100195 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400196 .exit_latency = 109,
Len Brownddbd5502010-12-13 18:28:22 -0500197 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100198 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200199 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500200 {
201 .enter = NULL }
Len Brownd13780d2010-07-07 00:12:03 -0400202};
203
Len Brown718987d2014-02-14 02:30:00 -0500204static struct cpuidle_state byt_cstates[] = {
205 {
Len Brownde09cdd2017-02-28 16:32:44 -0500206 .name = "C1",
Len Brown718987d2014-02-14 02:30:00 -0500207 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100208 .flags = MWAIT2flg(0x00),
Len Brown718987d2014-02-14 02:30:00 -0500209 .exit_latency = 1,
210 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100211 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200212 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500213 {
Len Brownde09cdd2017-02-28 16:32:44 -0500214 .name = "C6N",
Len Brown718987d2014-02-14 02:30:00 -0500215 .desc = "MWAIT 0x58",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100216 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400217 .exit_latency = 300,
Len Brown718987d2014-02-14 02:30:00 -0500218 .target_residency = 275,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100219 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200220 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500221 {
Len Brownde09cdd2017-02-28 16:32:44 -0500222 .name = "C6S",
Len Brown718987d2014-02-14 02:30:00 -0500223 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100224 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400225 .exit_latency = 500,
Len Brown718987d2014-02-14 02:30:00 -0500226 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100227 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200228 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500229 {
Len Brownde09cdd2017-02-28 16:32:44 -0500230 .name = "C7",
Len Brown718987d2014-02-14 02:30:00 -0500231 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100232 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500233 .exit_latency = 1200,
Len Brownd7ef7672015-03-24 23:23:20 -0400234 .target_residency = 4000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100235 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200236 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500237 {
Len Brownde09cdd2017-02-28 16:32:44 -0500238 .name = "C7S",
Len Brown718987d2014-02-14 02:30:00 -0500239 .desc = "MWAIT 0x64",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100240 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500241 .exit_latency = 10000,
242 .target_residency = 20000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100243 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200244 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500245 {
246 .enter = NULL }
247};
248
Len Browncab07a52015-03-27 20:54:01 -0400249static struct cpuidle_state cht_cstates[] = {
250 {
Len Brownde09cdd2017-02-28 16:32:44 -0500251 .name = "C1",
Len Browncab07a52015-03-27 20:54:01 -0400252 .desc = "MWAIT 0x00",
253 .flags = MWAIT2flg(0x00),
254 .exit_latency = 1,
255 .target_residency = 1,
256 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200257 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400258 {
Len Brownde09cdd2017-02-28 16:32:44 -0500259 .name = "C6N",
Len Browncab07a52015-03-27 20:54:01 -0400260 .desc = "MWAIT 0x58",
261 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
262 .exit_latency = 80,
263 .target_residency = 275,
264 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200265 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400266 {
Len Brownde09cdd2017-02-28 16:32:44 -0500267 .name = "C6S",
Len Browncab07a52015-03-27 20:54:01 -0400268 .desc = "MWAIT 0x52",
269 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
270 .exit_latency = 200,
271 .target_residency = 560,
272 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200273 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400274 {
Len Brownde09cdd2017-02-28 16:32:44 -0500275 .name = "C7",
Len Browncab07a52015-03-27 20:54:01 -0400276 .desc = "MWAIT 0x60",
277 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
278 .exit_latency = 1200,
279 .target_residency = 4000,
280 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200281 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400282 {
Len Brownde09cdd2017-02-28 16:32:44 -0500283 .name = "C7S",
Len Browncab07a52015-03-27 20:54:01 -0400284 .desc = "MWAIT 0x64",
285 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
286 .exit_latency = 10000,
287 .target_residency = 20000,
288 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200289 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400290 {
291 .enter = NULL }
292};
293
Jiang Liuba0dc812014-01-09 15:30:26 +0800294static struct cpuidle_state ivb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500295 {
Len Brownde09cdd2017-02-28 16:32:44 -0500296 .name = "C1",
Len Brown6edab082012-06-01 19:45:32 -0400297 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100298 .flags = MWAIT2flg(0x00),
Len Brown6edab082012-06-01 19:45:32 -0400299 .exit_latency = 1,
300 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100301 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200302 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500303 {
Len Brownde09cdd2017-02-28 16:32:44 -0500304 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500305 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100306 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500307 .exit_latency = 10,
308 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100309 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200310 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500311 {
Len Brownde09cdd2017-02-28 16:32:44 -0500312 .name = "C3",
Len Brown6edab082012-06-01 19:45:32 -0400313 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100314 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400315 .exit_latency = 59,
316 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100317 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200318 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500319 {
Len Brownde09cdd2017-02-28 16:32:44 -0500320 .name = "C6",
Len Brown6edab082012-06-01 19:45:32 -0400321 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100322 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400323 .exit_latency = 80,
324 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100325 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200326 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500327 {
Len Brownde09cdd2017-02-28 16:32:44 -0500328 .name = "C7",
Len Brown6edab082012-06-01 19:45:32 -0400329 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100330 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400331 .exit_latency = 87,
332 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100333 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200334 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500335 {
336 .enter = NULL }
Len Brown6edab082012-06-01 19:45:32 -0400337};
338
Len Brown0138d8f2014-04-04 01:21:07 -0400339static struct cpuidle_state ivt_cstates[] = {
340 {
Len Brownde09cdd2017-02-28 16:32:44 -0500341 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400342 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100343 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400344 .exit_latency = 1,
345 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100346 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200347 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400348 {
Len Brownde09cdd2017-02-28 16:32:44 -0500349 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400350 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100351 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown0138d8f2014-04-04 01:21:07 -0400352 .exit_latency = 10,
353 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100354 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200355 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400356 {
Len Brownde09cdd2017-02-28 16:32:44 -0500357 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400358 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100359 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400360 .exit_latency = 59,
361 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100362 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200363 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400364 {
Len Brownde09cdd2017-02-28 16:32:44 -0500365 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400366 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100367 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400368 .exit_latency = 82,
369 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100370 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200371 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400372 {
373 .enter = NULL }
374};
375
376static struct cpuidle_state ivt_cstates_4s[] = {
377 {
Len Brownde09cdd2017-02-28 16:32:44 -0500378 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400379 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100380 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400381 .exit_latency = 1,
382 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100383 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200384 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400385 {
Len Brownde09cdd2017-02-28 16:32:44 -0500386 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400387 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100388 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown0138d8f2014-04-04 01:21:07 -0400389 .exit_latency = 10,
390 .target_residency = 250,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100391 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200392 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400393 {
Len Brownde09cdd2017-02-28 16:32:44 -0500394 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400395 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100396 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400397 .exit_latency = 59,
398 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100399 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200400 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400401 {
Len Brownde09cdd2017-02-28 16:32:44 -0500402 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400403 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100404 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400405 .exit_latency = 84,
406 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100407 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200408 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400409 {
410 .enter = NULL }
411};
412
413static struct cpuidle_state ivt_cstates_8s[] = {
414 {
Len Brownde09cdd2017-02-28 16:32:44 -0500415 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400416 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100417 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400418 .exit_latency = 1,
419 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100420 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200421 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400422 {
Len Brownde09cdd2017-02-28 16:32:44 -0500423 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400424 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100425 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown0138d8f2014-04-04 01:21:07 -0400426 .exit_latency = 10,
427 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100428 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200429 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400430 {
Len Brownde09cdd2017-02-28 16:32:44 -0500431 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400432 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100433 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400434 .exit_latency = 59,
435 .target_residency = 600,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100436 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200437 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400438 {
Len Brownde09cdd2017-02-28 16:32:44 -0500439 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400440 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100441 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400442 .exit_latency = 88,
443 .target_residency = 700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100444 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200445 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400446 {
447 .enter = NULL }
448};
449
Jiang Liuba0dc812014-01-09 15:30:26 +0800450static struct cpuidle_state hsw_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500451 {
Len Brownde09cdd2017-02-28 16:32:44 -0500452 .name = "C1",
Len Brown85a4d2d2013-01-31 14:40:49 -0500453 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100454 .flags = MWAIT2flg(0x00),
Len Brown85a4d2d2013-01-31 14:40:49 -0500455 .exit_latency = 2,
456 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100457 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200458 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500459 {
Len Brownde09cdd2017-02-28 16:32:44 -0500460 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500461 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100462 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500463 .exit_latency = 10,
464 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100465 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200466 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500467 {
Len Brownde09cdd2017-02-28 16:32:44 -0500468 .name = "C3",
Len Brown85a4d2d2013-01-31 14:40:49 -0500469 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100470 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500471 .exit_latency = 33,
472 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100473 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200474 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500475 {
Len Brownde09cdd2017-02-28 16:32:44 -0500476 .name = "C6",
Len Brown85a4d2d2013-01-31 14:40:49 -0500477 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100478 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500479 .exit_latency = 133,
480 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100481 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200482 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500483 {
Len Brownde09cdd2017-02-28 16:32:44 -0500484 .name = "C7s",
Len Brown85a4d2d2013-01-31 14:40:49 -0500485 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100486 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500487 .exit_latency = 166,
488 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100489 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200490 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500491 {
Len Brownde09cdd2017-02-28 16:32:44 -0500492 .name = "C8",
Len Brown86239ce2013-02-27 13:18:50 -0500493 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100494 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500495 .exit_latency = 300,
496 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100497 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200498 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500499 {
Len Brownde09cdd2017-02-28 16:32:44 -0500500 .name = "C9",
Len Brown86239ce2013-02-27 13:18:50 -0500501 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100502 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500503 .exit_latency = 600,
504 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100505 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200506 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500507 {
Len Brownde09cdd2017-02-28 16:32:44 -0500508 .name = "C10",
Len Brown86239ce2013-02-27 13:18:50 -0500509 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100510 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500511 .exit_latency = 2600,
512 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100513 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200514 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500515 {
Len Browne022e7e2013-02-01 23:37:30 -0500516 .enter = NULL }
Len Brown85a4d2d2013-01-31 14:40:49 -0500517};
Len Browna138b562014-02-04 23:56:40 -0500518static struct cpuidle_state bdw_cstates[] = {
519 {
Len Brownde09cdd2017-02-28 16:32:44 -0500520 .name = "C1",
Len Browna138b562014-02-04 23:56:40 -0500521 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100522 .flags = MWAIT2flg(0x00),
Len Browna138b562014-02-04 23:56:40 -0500523 .exit_latency = 2,
524 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100525 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200526 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500527 {
Len Brownde09cdd2017-02-28 16:32:44 -0500528 .name = "C1E",
Len Browna138b562014-02-04 23:56:40 -0500529 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100530 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Browna138b562014-02-04 23:56:40 -0500531 .exit_latency = 10,
532 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100533 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200534 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500535 {
Len Brownde09cdd2017-02-28 16:32:44 -0500536 .name = "C3",
Len Browna138b562014-02-04 23:56:40 -0500537 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100538 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500539 .exit_latency = 40,
540 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100541 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200542 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500543 {
Len Brownde09cdd2017-02-28 16:32:44 -0500544 .name = "C6",
Len Browna138b562014-02-04 23:56:40 -0500545 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100546 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500547 .exit_latency = 133,
548 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100549 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200550 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500551 {
Len Brownde09cdd2017-02-28 16:32:44 -0500552 .name = "C7s",
Len Browna138b562014-02-04 23:56:40 -0500553 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100554 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500555 .exit_latency = 166,
556 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100557 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200558 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500559 {
Len Brownde09cdd2017-02-28 16:32:44 -0500560 .name = "C8",
Len Browna138b562014-02-04 23:56:40 -0500561 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100562 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500563 .exit_latency = 300,
564 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100565 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200566 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500567 {
Len Brownde09cdd2017-02-28 16:32:44 -0500568 .name = "C9",
Len Browna138b562014-02-04 23:56:40 -0500569 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100570 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500571 .exit_latency = 600,
572 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100573 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200574 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500575 {
Len Brownde09cdd2017-02-28 16:32:44 -0500576 .name = "C10",
Len Browna138b562014-02-04 23:56:40 -0500577 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100578 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500579 .exit_latency = 2600,
580 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100581 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200582 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500583 {
584 .enter = NULL }
585};
Len Brown85a4d2d2013-01-31 14:40:49 -0500586
Len Brown493f1332015-03-25 23:20:37 -0400587static struct cpuidle_state skl_cstates[] = {
588 {
Len Brownde09cdd2017-02-28 16:32:44 -0500589 .name = "C1",
Len Brown493f1332015-03-25 23:20:37 -0400590 .desc = "MWAIT 0x00",
591 .flags = MWAIT2flg(0x00),
592 .exit_latency = 2,
593 .target_residency = 2,
594 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200595 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400596 {
Len Brownde09cdd2017-02-28 16:32:44 -0500597 .name = "C1E",
Len Brown493f1332015-03-25 23:20:37 -0400598 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100599 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown493f1332015-03-25 23:20:37 -0400600 .exit_latency = 10,
601 .target_residency = 20,
602 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200603 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400604 {
Len Brownde09cdd2017-02-28 16:32:44 -0500605 .name = "C3",
Len Brown493f1332015-03-25 23:20:37 -0400606 .desc = "MWAIT 0x10",
607 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
608 .exit_latency = 70,
609 .target_residency = 100,
610 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200611 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400612 {
Len Brownde09cdd2017-02-28 16:32:44 -0500613 .name = "C6",
Len Brown493f1332015-03-25 23:20:37 -0400614 .desc = "MWAIT 0x20",
615 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400616 .exit_latency = 85,
Len Brown493f1332015-03-25 23:20:37 -0400617 .target_residency = 200,
618 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200619 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400620 {
Len Brownde09cdd2017-02-28 16:32:44 -0500621 .name = "C7s",
Len Brown493f1332015-03-25 23:20:37 -0400622 .desc = "MWAIT 0x33",
623 .flags = MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED,
624 .exit_latency = 124,
625 .target_residency = 800,
626 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200627 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400628 {
Len Brownde09cdd2017-02-28 16:32:44 -0500629 .name = "C8",
Len Brown493f1332015-03-25 23:20:37 -0400630 .desc = "MWAIT 0x40",
631 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400632 .exit_latency = 200,
Len Brown493f1332015-03-25 23:20:37 -0400633 .target_residency = 800,
634 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200635 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400636 {
Len Brownde09cdd2017-02-28 16:32:44 -0500637 .name = "C9",
Len Brown135919a2015-09-09 13:35:05 -0400638 .desc = "MWAIT 0x50",
639 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
640 .exit_latency = 480,
641 .target_residency = 5000,
642 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200643 .enter_s2idle = intel_idle_s2idle, },
Len Brown135919a2015-09-09 13:35:05 -0400644 {
Len Brownde09cdd2017-02-28 16:32:44 -0500645 .name = "C10",
Len Brown493f1332015-03-25 23:20:37 -0400646 .desc = "MWAIT 0x60",
647 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
648 .exit_latency = 890,
649 .target_residency = 5000,
650 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200651 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400652 {
653 .enter = NULL }
654};
655
Len Brownf9e71652016-04-06 17:00:58 -0400656static struct cpuidle_state skx_cstates[] = {
657 {
Len Brownde09cdd2017-02-28 16:32:44 -0500658 .name = "C1",
Len Brownf9e71652016-04-06 17:00:58 -0400659 .desc = "MWAIT 0x00",
660 .flags = MWAIT2flg(0x00),
661 .exit_latency = 2,
662 .target_residency = 2,
663 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200664 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400665 {
Len Brownde09cdd2017-02-28 16:32:44 -0500666 .name = "C1E",
Len Brownf9e71652016-04-06 17:00:58 -0400667 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100668 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brownf9e71652016-04-06 17:00:58 -0400669 .exit_latency = 10,
670 .target_residency = 20,
671 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200672 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400673 {
Len Brownde09cdd2017-02-28 16:32:44 -0500674 .name = "C6",
Len Brownf9e71652016-04-06 17:00:58 -0400675 .desc = "MWAIT 0x20",
676 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
677 .exit_latency = 133,
678 .target_residency = 600,
679 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200680 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400681 {
682 .enter = NULL }
683};
684
Jiang Liuba0dc812014-01-09 15:30:26 +0800685static struct cpuidle_state atom_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500686 {
Len Brownde09cdd2017-02-28 16:32:44 -0500687 .name = "C1E",
Len Brown26717172010-03-08 14:07:30 -0500688 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100689 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500690 .exit_latency = 10,
691 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100692 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200693 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500694 {
Len Brownde09cdd2017-02-28 16:32:44 -0500695 .name = "C2",
Len Brown26717172010-03-08 14:07:30 -0500696 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100697 .flags = MWAIT2flg(0x10),
Len Brown26717172010-03-08 14:07:30 -0500698 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500699 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100700 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200701 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500702 {
Len Brownde09cdd2017-02-28 16:32:44 -0500703 .name = "C4",
Len Brown26717172010-03-08 14:07:30 -0500704 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100705 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500706 .exit_latency = 100,
Len Brown26717172010-03-08 14:07:30 -0500707 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100708 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200709 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500710 {
Len Brownde09cdd2017-02-28 16:32:44 -0500711 .name = "C6",
Len Brown7fcca7d2010-10-05 13:43:14 -0400712 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100713 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown7fcca7d2010-10-05 13:43:14 -0400714 .exit_latency = 140,
Len Brown7fcca7d2010-10-05 13:43:14 -0400715 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100716 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200717 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500718 {
719 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500720};
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300721static struct cpuidle_state tangier_cstates[] = {
722 {
Len Brownde09cdd2017-02-28 16:32:44 -0500723 .name = "C1",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300724 .desc = "MWAIT 0x00",
725 .flags = MWAIT2flg(0x00),
726 .exit_latency = 1,
727 .target_residency = 4,
728 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200729 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300730 {
Len Brownde09cdd2017-02-28 16:32:44 -0500731 .name = "C4",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300732 .desc = "MWAIT 0x30",
733 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
734 .exit_latency = 100,
735 .target_residency = 400,
736 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200737 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300738 {
Len Brownde09cdd2017-02-28 16:32:44 -0500739 .name = "C6",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300740 .desc = "MWAIT 0x52",
741 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
742 .exit_latency = 140,
743 .target_residency = 560,
744 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200745 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300746 {
Len Brownde09cdd2017-02-28 16:32:44 -0500747 .name = "C7",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300748 .desc = "MWAIT 0x60",
749 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
750 .exit_latency = 1200,
751 .target_residency = 4000,
752 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200753 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300754 {
Len Brownde09cdd2017-02-28 16:32:44 -0500755 .name = "C9",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300756 .desc = "MWAIT 0x64",
757 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
758 .exit_latency = 10000,
759 .target_residency = 20000,
760 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200761 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300762 {
763 .enter = NULL }
764};
Jiang Liu88390992014-01-09 15:30:27 +0800765static struct cpuidle_state avn_cstates[] = {
Len Brownfab04b22013-11-09 00:30:17 -0500766 {
Len Brownde09cdd2017-02-28 16:32:44 -0500767 .name = "C1",
Len Brownfab04b22013-11-09 00:30:17 -0500768 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100769 .flags = MWAIT2flg(0x00),
Len Brownfab04b22013-11-09 00:30:17 -0500770 .exit_latency = 2,
771 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100772 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200773 .enter_s2idle = intel_idle_s2idle, },
Len Brownfab04b22013-11-09 00:30:17 -0500774 {
Len Brownde09cdd2017-02-28 16:32:44 -0500775 .name = "C6",
Len Brownfab04b22013-11-09 00:30:17 -0500776 .desc = "MWAIT 0x51",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100777 .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownfab04b22013-11-09 00:30:17 -0500778 .exit_latency = 15,
779 .target_residency = 45,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100780 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200781 .enter_s2idle = intel_idle_s2idle, },
Jiang Liu88390992014-01-09 15:30:27 +0800782 {
783 .enter = NULL }
Len Brownfab04b22013-11-09 00:30:17 -0500784};
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700785static struct cpuidle_state knl_cstates[] = {
786 {
Len Brownde09cdd2017-02-28 16:32:44 -0500787 .name = "C1",
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700788 .desc = "MWAIT 0x00",
789 .flags = MWAIT2flg(0x00),
790 .exit_latency = 1,
791 .target_residency = 2,
792 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200793 .enter_s2idle = intel_idle_s2idle },
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700794 {
Len Brownde09cdd2017-02-28 16:32:44 -0500795 .name = "C6",
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700796 .desc = "MWAIT 0x10",
797 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
798 .exit_latency = 120,
799 .target_residency = 500,
800 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200801 .enter_s2idle = intel_idle_s2idle },
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700802 {
803 .enter = NULL }
804};
Len Brown26717172010-03-08 14:07:30 -0500805
Len Brown5dcef692016-04-06 17:00:47 -0400806static struct cpuidle_state bxt_cstates[] = {
807 {
Len Brownde09cdd2017-02-28 16:32:44 -0500808 .name = "C1",
Len Brown5dcef692016-04-06 17:00:47 -0400809 .desc = "MWAIT 0x00",
810 .flags = MWAIT2flg(0x00),
811 .exit_latency = 2,
812 .target_residency = 2,
813 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200814 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400815 {
Len Brownde09cdd2017-02-28 16:32:44 -0500816 .name = "C1E",
Len Brown5dcef692016-04-06 17:00:47 -0400817 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100818 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown5dcef692016-04-06 17:00:47 -0400819 .exit_latency = 10,
820 .target_residency = 20,
821 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200822 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400823 {
Len Brownde09cdd2017-02-28 16:32:44 -0500824 .name = "C6",
Len Brown5dcef692016-04-06 17:00:47 -0400825 .desc = "MWAIT 0x20",
826 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
827 .exit_latency = 133,
828 .target_residency = 133,
829 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200830 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400831 {
Len Brownde09cdd2017-02-28 16:32:44 -0500832 .name = "C7s",
Len Brown5dcef692016-04-06 17:00:47 -0400833 .desc = "MWAIT 0x31",
834 .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
835 .exit_latency = 155,
836 .target_residency = 155,
837 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200838 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400839 {
Len Brownde09cdd2017-02-28 16:32:44 -0500840 .name = "C8",
Len Brown5dcef692016-04-06 17:00:47 -0400841 .desc = "MWAIT 0x40",
842 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
843 .exit_latency = 1000,
844 .target_residency = 1000,
845 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200846 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400847 {
Len Brownde09cdd2017-02-28 16:32:44 -0500848 .name = "C9",
Len Brown5dcef692016-04-06 17:00:47 -0400849 .desc = "MWAIT 0x50",
850 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
851 .exit_latency = 2000,
852 .target_residency = 2000,
853 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200854 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400855 {
Len Brownde09cdd2017-02-28 16:32:44 -0500856 .name = "C10",
Len Brown5dcef692016-04-06 17:00:47 -0400857 .desc = "MWAIT 0x60",
858 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
859 .exit_latency = 10000,
860 .target_residency = 10000,
861 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200862 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400863 {
864 .enter = NULL }
865};
866
Jacob Pan0080d652016-06-17 01:28:34 -0400867static struct cpuidle_state dnv_cstates[] = {
868 {
Len Brownde09cdd2017-02-28 16:32:44 -0500869 .name = "C1",
Jacob Pan0080d652016-06-17 01:28:34 -0400870 .desc = "MWAIT 0x00",
871 .flags = MWAIT2flg(0x00),
872 .exit_latency = 2,
873 .target_residency = 2,
874 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200875 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400876 {
Len Brownde09cdd2017-02-28 16:32:44 -0500877 .name = "C1E",
Jacob Pan0080d652016-06-17 01:28:34 -0400878 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100879 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Jacob Pan0080d652016-06-17 01:28:34 -0400880 .exit_latency = 10,
881 .target_residency = 20,
882 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200883 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400884 {
Len Brownde09cdd2017-02-28 16:32:44 -0500885 .name = "C6",
Jacob Pan0080d652016-06-17 01:28:34 -0400886 .desc = "MWAIT 0x20",
887 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
888 .exit_latency = 50,
889 .target_residency = 500,
890 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200891 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400892 {
893 .enter = NULL }
894};
895
Len Brown26717172010-03-08 14:07:30 -0500896/**
897 * intel_idle
898 * @dev: cpuidle_device
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530899 * @drv: cpuidle driver
Deepthi Dharware978aa72011-10-28 16:20:09 +0530900 * @index: index of cpuidle state
Len Brown26717172010-03-08 14:07:30 -0500901 *
Yanmin Zhang63ff07b2012-01-10 15:48:21 -0800902 * Must be called under local_irq_disable().
Len Brown26717172010-03-08 14:07:30 -0500903 */
Chris Metcalf6727ad92016-10-07 17:02:55 -0700904static __cpuidle int intel_idle(struct cpuidle_device *dev,
905 struct cpuidle_driver *drv, int index)
Len Brown26717172010-03-08 14:07:30 -0500906{
907 unsigned long ecx = 1; /* break on interrupt flag */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530908 struct cpuidle_state *state = &drv->states[index];
Len Brownb1beab42013-01-31 19:55:37 -0500909 unsigned long eax = flg2MWAIT(state->flags);
Len Brown26717172010-03-08 14:07:30 -0500910 unsigned int cstate;
Jason Baron0563bb72017-10-06 13:19:45 -0400911 bool uninitialized_var(tick);
Andy Lutomirski67535732017-11-04 04:16:12 -0700912 int cpu = smp_processor_id();
Len Brown26717172010-03-08 14:07:30 -0500913
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400914 /*
Andy Lutomirski67535732017-11-04 04:16:12 -0700915 * leave_mm() to avoid costly and often unnecessary wakeups
916 * for flushing the user TLB's associated with the active mm.
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400917 */
Andy Lutomirski67535732017-11-04 04:16:12 -0700918 if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
919 leave_mm(cpu);
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400920
Jason Baron0563bb72017-10-06 13:19:45 -0400921 if (!static_cpu_has(X86_FEATURE_ARAT)) {
922 cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
923 MWAIT_CSTATE_MASK) + 1;
924 tick = false;
925 if (!(lapic_timer_reliable_states & (1 << (cstate)))) {
926 tick = true;
927 tick_broadcast_enter();
928 }
929 }
Len Brown26717172010-03-08 14:07:30 -0500930
Peter Zijlstra16824252013-12-12 15:08:36 +0100931 mwait_idle_with_hints(eax, ecx);
Len Brown26717172010-03-08 14:07:30 -0500932
Jason Baron0563bb72017-10-06 13:19:45 -0400933 if (!static_cpu_has(X86_FEATURE_ARAT) && tick)
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200934 tick_broadcast_exit();
Len Brown26717172010-03-08 14:07:30 -0500935
Deepthi Dharware978aa72011-10-28 16:20:09 +0530936 return index;
Len Brown26717172010-03-08 14:07:30 -0500937}
938
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100939/**
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200940 * intel_idle_s2idle - simplified "enter" callback routine for suspend-to-idle
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100941 * @dev: cpuidle_device
942 * @drv: cpuidle driver
943 * @index: state index
944 */
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200945static void intel_idle_s2idle(struct cpuidle_device *dev,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100946 struct cpuidle_driver *drv, int index)
947{
948 unsigned long ecx = 1; /* break on interrupt flag */
949 unsigned long eax = flg2MWAIT(drv->states[index].flags);
950
951 mwait_idle_with_hints(eax, ecx);
952}
953
Andi Kleenb66b8b92012-01-26 00:09:07 +0100954static const struct idle_cpu idle_cpu_nehalem = {
955 .state_table = nehalem_cstates,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100956 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
Len Brown32e95182013-02-02 01:31:56 -0500957 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100958};
959
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100960static const struct idle_cpu idle_cpu_nhx = {
961 .state_table = nehalem_cstates,
962 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
963 .disable_promotion_to_c1e = true,
964 .use_acpi = true,
965};
966
Andi Kleenb66b8b92012-01-26 00:09:07 +0100967static const struct idle_cpu idle_cpu_atom = {
968 .state_table = atom_cstates,
969};
970
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300971static const struct idle_cpu idle_cpu_tangier = {
972 .state_table = tangier_cstates,
973};
974
Andi Kleenb66b8b92012-01-26 00:09:07 +0100975static const struct idle_cpu idle_cpu_lincroft = {
976 .state_table = atom_cstates,
977 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
978};
979
980static const struct idle_cpu idle_cpu_snb = {
981 .state_table = snb_cstates,
Len Brown32e95182013-02-02 01:31:56 -0500982 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100983};
984
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100985static const struct idle_cpu idle_cpu_snx = {
986 .state_table = snb_cstates,
987 .disable_promotion_to_c1e = true,
988 .use_acpi = true,
989};
990
Len Brown718987d2014-02-14 02:30:00 -0500991static const struct idle_cpu idle_cpu_byt = {
992 .state_table = byt_cstates,
993 .disable_promotion_to_c1e = true,
Len Brown8c058d532014-07-31 15:21:24 -0400994 .byt_auto_demotion_disable_flag = true,
Len Brown718987d2014-02-14 02:30:00 -0500995};
996
Len Browncab07a52015-03-27 20:54:01 -0400997static const struct idle_cpu idle_cpu_cht = {
998 .state_table = cht_cstates,
999 .disable_promotion_to_c1e = true,
1000 .byt_auto_demotion_disable_flag = true,
1001};
1002
Len Brown6edab082012-06-01 19:45:32 -04001003static const struct idle_cpu idle_cpu_ivb = {
1004 .state_table = ivb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001005 .disable_promotion_to_c1e = true,
Len Brown6edab082012-06-01 19:45:32 -04001006};
1007
Len Brown0138d8f2014-04-04 01:21:07 -04001008static const struct idle_cpu idle_cpu_ivt = {
1009 .state_table = ivt_cstates,
1010 .disable_promotion_to_c1e = true,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001011 .use_acpi = true,
Len Brown0138d8f2014-04-04 01:21:07 -04001012};
1013
Len Brown85a4d2d2013-01-31 14:40:49 -05001014static const struct idle_cpu idle_cpu_hsw = {
1015 .state_table = hsw_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001016 .disable_promotion_to_c1e = true,
Len Brown85a4d2d2013-01-31 14:40:49 -05001017};
1018
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001019static const struct idle_cpu idle_cpu_hsx = {
1020 .state_table = hsw_cstates,
1021 .disable_promotion_to_c1e = true,
1022 .use_acpi = true,
1023};
1024
Len Browna138b562014-02-04 23:56:40 -05001025static const struct idle_cpu idle_cpu_bdw = {
1026 .state_table = bdw_cstates,
1027 .disable_promotion_to_c1e = true,
1028};
1029
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001030static const struct idle_cpu idle_cpu_bdx = {
1031 .state_table = bdw_cstates,
1032 .disable_promotion_to_c1e = true,
1033 .use_acpi = true,
1034};
1035
Len Brown493f1332015-03-25 23:20:37 -04001036static const struct idle_cpu idle_cpu_skl = {
1037 .state_table = skl_cstates,
1038 .disable_promotion_to_c1e = true,
1039};
1040
Len Brownf9e71652016-04-06 17:00:58 -04001041static const struct idle_cpu idle_cpu_skx = {
1042 .state_table = skx_cstates,
1043 .disable_promotion_to_c1e = true,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001044 .use_acpi = true,
Len Brownf9e71652016-04-06 17:00:58 -04001045};
Len Brown493f1332015-03-25 23:20:37 -04001046
Len Brownfab04b22013-11-09 00:30:17 -05001047static const struct idle_cpu idle_cpu_avn = {
1048 .state_table = avn_cstates,
1049 .disable_promotion_to_c1e = true,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001050 .use_acpi = true,
Len Brownfab04b22013-11-09 00:30:17 -05001051};
1052
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001053static const struct idle_cpu idle_cpu_knl = {
1054 .state_table = knl_cstates,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001055 .use_acpi = true,
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001056};
1057
Len Brown5dcef692016-04-06 17:00:47 -04001058static const struct idle_cpu idle_cpu_bxt = {
1059 .state_table = bxt_cstates,
1060 .disable_promotion_to_c1e = true,
1061};
1062
Jacob Pan0080d652016-06-17 01:28:34 -04001063static const struct idle_cpu idle_cpu_dnv = {
1064 .state_table = dnv_cstates,
1065 .disable_promotion_to_c1e = true,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001066 .use_acpi = true,
Jacob Pan0080d652016-06-17 01:28:34 -04001067};
1068
Mathias Kraused5cdc3c2015-03-25 22:15:14 +01001069static const struct x86_cpu_id intel_idle_ids[] __initconst = {
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001070 INTEL_CPU_FAM6(NEHALEM_EP, idle_cpu_nhx),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001071 INTEL_CPU_FAM6(NEHALEM, idle_cpu_nehalem),
1072 INTEL_CPU_FAM6(NEHALEM_G, idle_cpu_nehalem),
1073 INTEL_CPU_FAM6(WESTMERE, idle_cpu_nehalem),
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001074 INTEL_CPU_FAM6(WESTMERE_EP, idle_cpu_nhx),
1075 INTEL_CPU_FAM6(NEHALEM_EX, idle_cpu_nhx),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001076 INTEL_CPU_FAM6(ATOM_BONNELL, idle_cpu_atom),
1077 INTEL_CPU_FAM6(ATOM_BONNELL_MID, idle_cpu_lincroft),
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001078 INTEL_CPU_FAM6(WESTMERE_EX, idle_cpu_nhx),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001079 INTEL_CPU_FAM6(SANDYBRIDGE, idle_cpu_snb),
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001080 INTEL_CPU_FAM6(SANDYBRIDGE_X, idle_cpu_snx),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001081 INTEL_CPU_FAM6(ATOM_SALTWELL, idle_cpu_atom),
1082 INTEL_CPU_FAM6(ATOM_SILVERMONT, idle_cpu_byt),
1083 INTEL_CPU_FAM6(ATOM_SILVERMONT_MID, idle_cpu_tangier),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001084 INTEL_CPU_FAM6(ATOM_AIRMONT, idle_cpu_cht),
1085 INTEL_CPU_FAM6(IVYBRIDGE, idle_cpu_ivb),
1086 INTEL_CPU_FAM6(IVYBRIDGE_X, idle_cpu_ivt),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001087 INTEL_CPU_FAM6(HASWELL, idle_cpu_hsw),
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001088 INTEL_CPU_FAM6(HASWELL_X, idle_cpu_hsx),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001089 INTEL_CPU_FAM6(HASWELL_L, idle_cpu_hsw),
Peter Zijlstra5e741402019-08-27 21:48:23 +02001090 INTEL_CPU_FAM6(HASWELL_G, idle_cpu_hsw),
Peter Zijlstra5ebb34e2019-08-27 21:48:24 +02001091 INTEL_CPU_FAM6(ATOM_SILVERMONT_D, idle_cpu_avn),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001092 INTEL_CPU_FAM6(BROADWELL, idle_cpu_bdw),
Peter Zijlstra5e741402019-08-27 21:48:23 +02001093 INTEL_CPU_FAM6(BROADWELL_G, idle_cpu_bdw),
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001094 INTEL_CPU_FAM6(BROADWELL_X, idle_cpu_bdx),
1095 INTEL_CPU_FAM6(BROADWELL_D, idle_cpu_bdx),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001096 INTEL_CPU_FAM6(SKYLAKE_L, idle_cpu_skl),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001097 INTEL_CPU_FAM6(SKYLAKE, idle_cpu_skl),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001098 INTEL_CPU_FAM6(KABYLAKE_L, idle_cpu_skl),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001099 INTEL_CPU_FAM6(KABYLAKE, idle_cpu_skl),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001100 INTEL_CPU_FAM6(SKYLAKE_X, idle_cpu_skx),
1101 INTEL_CPU_FAM6(XEON_PHI_KNL, idle_cpu_knl),
1102 INTEL_CPU_FAM6(XEON_PHI_KNM, idle_cpu_knl),
1103 INTEL_CPU_FAM6(ATOM_GOLDMONT, idle_cpu_bxt),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001104 INTEL_CPU_FAM6(ATOM_GOLDMONT_PLUS, idle_cpu_bxt),
Peter Zijlstra5ebb34e2019-08-27 21:48:24 +02001105 INTEL_CPU_FAM6(ATOM_GOLDMONT_D, idle_cpu_dnv),
1106 INTEL_CPU_FAM6(ATOM_TREMONT_D, idle_cpu_dnv),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001107 {}
1108};
Andi Kleenb66b8b92012-01-26 00:09:07 +01001109
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001110#define INTEL_CPU_FAM6_MWAIT \
1111 { X86_VENDOR_INTEL, 6, X86_MODEL_ANY, X86_FEATURE_MWAIT, 0 }
1112
1113static const struct x86_cpu_id intel_mwait_ids[] __initconst = {
1114 INTEL_CPU_FAM6_MWAIT,
1115 {}
1116};
1117
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001118static bool __init intel_idle_max_cstate_reached(int cstate)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001119{
1120 if (cstate + 1 > max_cstate) {
1121 pr_info("max_cstate %d reached\n", max_cstate);
1122 return true;
1123 }
1124 return false;
1125}
1126
1127#ifdef CONFIG_ACPI_PROCESSOR_CSTATE
1128#include <acpi/processor.h>
1129
Rafael J. Wysocki4ec32d92019-12-13 09:56:29 +01001130static bool no_acpi __read_mostly;
1131module_param(no_acpi, bool, 0444);
1132MODULE_PARM_DESC(no_acpi, "Do not use ACPI _CST for building the idle states list");
1133
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001134static struct acpi_processor_power acpi_state_table __initdata;
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001135
1136/**
1137 * intel_idle_cst_usable - Check if the _CST information can be used.
1138 *
1139 * Check if all of the C-states listed by _CST in the max_cstate range are
1140 * ACPI_CSTATE_FFH, which means that they should be entered via MWAIT.
1141 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001142static bool __init intel_idle_cst_usable(void)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001143{
1144 int cstate, limit;
1145
1146 limit = min_t(int, min_t(int, CPUIDLE_STATE_MAX, max_cstate + 1),
1147 acpi_state_table.count);
1148
1149 for (cstate = 1; cstate < limit; cstate++) {
1150 struct acpi_processor_cx *cx = &acpi_state_table.states[cstate];
1151
1152 if (cx->entry_method != ACPI_CSTATE_FFH)
1153 return false;
1154 }
1155
1156 return true;
1157}
1158
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001159static bool __init intel_idle_acpi_cst_extract(void)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001160{
1161 unsigned int cpu;
1162
Rafael J. Wysocki4ec32d92019-12-13 09:56:29 +01001163 if (no_acpi) {
1164 pr_debug("Not allowed to use ACPI _CST\n");
1165 return false;
1166 }
1167
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001168 for_each_possible_cpu(cpu) {
1169 struct acpi_processor *pr = per_cpu(processors, cpu);
1170
1171 if (!pr)
1172 continue;
1173
1174 if (acpi_processor_evaluate_cst(pr->handle, cpu, &acpi_state_table))
1175 continue;
1176
1177 acpi_state_table.count++;
1178
1179 if (!intel_idle_cst_usable())
1180 continue;
1181
1182 if (!acpi_processor_claim_cst_control()) {
1183 acpi_state_table.count = 0;
1184 return false;
1185 }
1186
1187 return true;
1188 }
1189
1190 pr_debug("ACPI _CST not found or not usable\n");
1191 return false;
1192}
1193
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001194static void __init intel_idle_init_cstates_acpi(struct cpuidle_driver *drv)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001195{
1196 int cstate, limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
1197
1198 /*
1199 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1200 * the interesting states are ACPI_CSTATE_FFH.
1201 */
1202 for (cstate = 1; cstate < limit; cstate++) {
1203 struct acpi_processor_cx *cx;
1204 struct cpuidle_state *state;
1205
1206 if (intel_idle_max_cstate_reached(cstate))
1207 break;
1208
1209 cx = &acpi_state_table.states[cstate];
1210
1211 state = &drv->states[drv->state_count++];
1212
1213 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d_ACPI", cstate);
1214 strlcpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
1215 state->exit_latency = cx->latency;
1216 /*
1217 * For C1-type C-states use the same number for both the exit
1218 * latency and target residency, because that is the case for
1219 * C1 in the majority of the static C-states tables above.
1220 * For the other types of C-states, however, set the target
1221 * residency to 3 times the exit latency which should lead to
1222 * a reasonable balance between energy-efficiency and
1223 * performance in the majority of interesting cases.
1224 */
1225 state->target_residency = cx->latency;
1226 if (cx->type > ACPI_STATE_C1)
1227 state->target_residency *= 3;
1228
1229 state->flags = MWAIT2flg(cx->address);
1230 if (cx->type > ACPI_STATE_C2)
1231 state->flags |= CPUIDLE_FLAG_TLB_FLUSHED;
1232
1233 state->enter = intel_idle;
1234 state->enter_s2idle = intel_idle_s2idle;
1235 }
1236}
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001237
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001238static bool __init intel_idle_off_by_default(u32 mwait_hint)
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001239{
1240 int cstate, limit;
1241
1242 /*
1243 * If there are no _CST C-states, do not disable any C-states by
1244 * default.
1245 */
1246 if (!acpi_state_table.count)
1247 return false;
1248
1249 limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
1250 /*
1251 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1252 * the interesting states are ACPI_CSTATE_FFH.
1253 */
1254 for (cstate = 1; cstate < limit; cstate++) {
1255 if (acpi_state_table.states[cstate].address == mwait_hint)
1256 return false;
1257 }
1258 return true;
1259}
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001260#else /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1261static inline bool intel_idle_acpi_cst_extract(void) { return false; }
1262static inline void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) { }
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001263static inline bool intel_idle_off_by_default(u32 mwait_hint) { return false; }
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001264#endif /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1265
Len Brown26717172010-03-08 14:07:30 -05001266/*
Len Brownd70e28f2016-03-13 00:33:48 -05001267 * ivt_idle_state_table_update(void)
1268 *
1269 * Tune IVT multi-socket targets
1270 * Assumption: num_sockets == (max_package_num + 1)
1271 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001272static void __init ivt_idle_state_table_update(void)
Len Brownd70e28f2016-03-13 00:33:48 -05001273{
1274 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1275 int cpu, package_num, num_sockets = 1;
1276
1277 for_each_online_cpu(cpu) {
1278 package_num = topology_physical_package_id(cpu);
1279 if (package_num + 1 > num_sockets) {
1280 num_sockets = package_num + 1;
1281
1282 if (num_sockets > 4) {
1283 cpuidle_state_table = ivt_cstates_8s;
1284 return;
1285 }
1286 }
1287 }
1288
1289 if (num_sockets > 2)
1290 cpuidle_state_table = ivt_cstates_4s;
1291
1292 /* else, 1 and 2 socket systems use default ivt_cstates */
1293}
Len Brown5dcef692016-04-06 17:00:47 -04001294
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001295/**
1296 * irtl_2_usec - IRTL to microseconds conversion.
1297 * @irtl: IRTL MSR value.
1298 *
1299 * Translate the IRTL (Interrupt Response Time Limit) MSR value to microseconds.
Len Brown5dcef692016-04-06 17:00:47 -04001300 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001301static unsigned long long __init irtl_2_usec(unsigned long long irtl)
Len Brown5dcef692016-04-06 17:00:47 -04001302{
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001303 static const unsigned int irtl_ns_units[] __initconst = {
1304 1, 32, 1024, 32768, 1048576, 33554432, 0, 0
1305 };
Len Brown5dcef692016-04-06 17:00:47 -04001306 unsigned long long ns;
1307
Jan Beulich3451ab32016-06-27 00:35:12 -06001308 if (!irtl)
1309 return 0;
1310
Jan Beulichbef45092016-06-27 00:35:48 -06001311 ns = irtl_ns_units[(irtl >> 10) & 0x7];
Len Brown5dcef692016-04-06 17:00:47 -04001312
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001313 return div_u64((irtl & 0x3FF) * ns, NSEC_PER_USEC);
Len Brown5dcef692016-04-06 17:00:47 -04001314}
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001315
Len Brown5dcef692016-04-06 17:00:47 -04001316/*
1317 * bxt_idle_state_table_update(void)
1318 *
1319 * On BXT, we trust the IRTL to show the definitive maximum latency
1320 * We use the same value for target_residency.
1321 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001322static void __init bxt_idle_state_table_update(void)
Len Brown5dcef692016-04-06 17:00:47 -04001323{
1324 unsigned long long msr;
Jan Beulich3451ab32016-06-27 00:35:12 -06001325 unsigned int usec;
Len Brown5dcef692016-04-06 17:00:47 -04001326
1327 rdmsrl(MSR_PKGC6_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001328 usec = irtl_2_usec(msr);
1329 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001330 bxt_cstates[2].exit_latency = usec;
1331 bxt_cstates[2].target_residency = usec;
1332 }
1333
1334 rdmsrl(MSR_PKGC7_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001335 usec = irtl_2_usec(msr);
1336 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001337 bxt_cstates[3].exit_latency = usec;
1338 bxt_cstates[3].target_residency = usec;
1339 }
1340
1341 rdmsrl(MSR_PKGC8_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001342 usec = irtl_2_usec(msr);
1343 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001344 bxt_cstates[4].exit_latency = usec;
1345 bxt_cstates[4].target_residency = usec;
1346 }
1347
1348 rdmsrl(MSR_PKGC9_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001349 usec = irtl_2_usec(msr);
1350 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001351 bxt_cstates[5].exit_latency = usec;
1352 bxt_cstates[5].target_residency = usec;
1353 }
1354
1355 rdmsrl(MSR_PKGC10_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001356 usec = irtl_2_usec(msr);
1357 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001358 bxt_cstates[6].exit_latency = usec;
1359 bxt_cstates[6].target_residency = usec;
1360 }
1361
1362}
Len Brownd70e28f2016-03-13 00:33:48 -05001363/*
1364 * sklh_idle_state_table_update(void)
1365 *
1366 * On SKL-H (model 0x5e) disable C8 and C9 if:
1367 * C10 is enabled and SGX disabled
1368 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001369static void __init sklh_idle_state_table_update(void)
Len Brownd70e28f2016-03-13 00:33:48 -05001370{
1371 unsigned long long msr;
1372 unsigned int eax, ebx, ecx, edx;
1373
1374
1375 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1376 if (max_cstate <= 7)
1377 return;
1378
1379 /* if PC10 not present in CPUID.MWAIT.EDX */
1380 if ((mwait_substates & (0xF << 28)) == 0)
1381 return;
1382
Len Brown6cfb2372017-01-07 23:23:25 -05001383 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr);
Len Brownd70e28f2016-03-13 00:33:48 -05001384
1385 /* PC10 is not enabled in PKG C-state limit */
1386 if ((msr & 0xF) != 8)
1387 return;
1388
1389 ecx = 0;
1390 cpuid(7, &eax, &ebx, &ecx, &edx);
1391
1392 /* if SGX is present */
1393 if (ebx & (1 << 2)) {
1394
Sean Christopherson32ad73d2019-12-20 20:44:55 -08001395 rdmsrl(MSR_IA32_FEAT_CTL, msr);
Len Brownd70e28f2016-03-13 00:33:48 -05001396
1397 /* if SGX is enabled */
1398 if (msr & (1 << 18))
1399 return;
1400 }
1401
Rafael J. Wysockiba1e78a2019-11-21 19:41:51 +01001402 skl_cstates[5].flags |= CPUIDLE_FLAG_UNUSABLE; /* C8-SKL */
1403 skl_cstates[6].flags |= CPUIDLE_FLAG_UNUSABLE; /* C9-SKL */
Len Brownd70e28f2016-03-13 00:33:48 -05001404}
Len Brownd70e28f2016-03-13 00:33:48 -05001405
Rafael J. Wysocki1aefbd72020-01-10 11:52:32 +01001406static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
1407{
1408 unsigned int mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint) + 1;
1409 unsigned int num_substates = (mwait_substates >> mwait_cstate * 4) &
1410 MWAIT_SUBSTATE_MASK;
1411
1412 /* Ignore the C-state if there are NO sub-states in CPUID for it. */
1413 if (num_substates == 0)
1414 return false;
1415
1416 if (mwait_cstate > 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
1417 mark_tsc_unstable("TSC halts in idle states deeper than C2");
1418
1419 return true;
1420}
1421
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001422static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
Len Brown0138d8f2014-04-04 01:21:07 -04001423{
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001424 int cstate;
Len Brown0138d8f2014-04-04 01:21:07 -04001425
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001426 switch (boot_cpu_data.x86_model) {
Dave Hansendb73c5a2016-06-02 17:19:32 -07001427 case INTEL_FAM6_IVYBRIDGE_X:
Len Brownd70e28f2016-03-13 00:33:48 -05001428 ivt_idle_state_table_update();
1429 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001430 case INTEL_FAM6_ATOM_GOLDMONT:
Peter Zijlstraf2c4db12018-08-07 10:17:27 -07001431 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
Len Brown5dcef692016-04-06 17:00:47 -04001432 bxt_idle_state_table_update();
1433 break;
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001434 case INTEL_FAM6_SKYLAKE:
Len Brownd70e28f2016-03-13 00:33:48 -05001435 sklh_idle_state_table_update();
1436 break;
Len Brown0138d8f2014-04-04 01:21:07 -04001437 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301438
Len Browne022e7e2013-02-01 23:37:30 -05001439 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001440 unsigned int mwait_hint;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301441
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001442 if (intel_idle_max_cstate_reached(cstate))
1443 break;
1444
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001445 if (!cpuidle_state_table[cstate].enter &&
1446 !cpuidle_state_table[cstate].enter_s2idle)
Len Browne022e7e2013-02-01 23:37:30 -05001447 break;
1448
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001449 /* If marked as unusable, skip this state. */
Rafael J. Wysockiba1e78a2019-11-21 19:41:51 +01001450 if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_UNUSABLE) {
Joe Perches654d08a2017-06-09 12:29:20 -07001451 pr_debug("state %s is disabled\n",
1452 cpuidle_state_table[cstate].name);
Len Brownd70e28f2016-03-13 00:33:48 -05001453 continue;
1454 }
1455
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001456 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
1457 if (!intel_idle_verify_cstate(mwait_hint))
1458 continue;
Len Brownd70e28f2016-03-13 00:33:48 -05001459
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001460 /* Structure copy. */
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001461 drv->states[drv->state_count] = cpuidle_state_table[cstate];
1462
1463 if (icpu->use_acpi && intel_idle_off_by_default(mwait_hint) &&
1464 !(cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_ALWAYS_ENABLE))
1465 drv->states[drv->state_count].flags |= CPUIDLE_FLAG_OFF;
1466
1467 drv->state_count++;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301468 }
1469
Len Brown8c058d532014-07-31 15:21:24 -04001470 if (icpu->byt_auto_demotion_disable_flag) {
1471 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
1472 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
1473 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301474}
1475
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001476/*
1477 * intel_idle_cpuidle_driver_init()
1478 * allocate, initialize cpuidle_states
1479 */
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001480static void __init intel_idle_cpuidle_driver_init(struct cpuidle_driver *drv)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001481{
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001482 cpuidle_poll_state_init(drv);
1483 drv->state_count = 1;
1484
1485 if (icpu)
1486 intel_idle_init_cstates_icpu(drv);
1487 else
1488 intel_idle_init_cstates_acpi(drv);
1489}
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301490
Rafael J. Wysocki1aefbd72020-01-10 11:52:32 +01001491static void auto_demotion_disable(void)
1492{
1493 unsigned long long msr_bits;
1494
1495 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
1496 msr_bits &= ~(icpu->auto_demotion_disable_flags);
1497 wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
1498}
1499
1500static void c1e_promotion_disable(void)
1501{
1502 unsigned long long msr_bits;
1503
1504 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
1505 msr_bits &= ~0x2;
1506 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
1507}
1508
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301509/*
Thomas Renninger65b7f832012-01-17 22:40:08 +01001510 * intel_idle_cpu_init()
Len Brown26717172010-03-08 14:07:30 -05001511 * allocate, initialize, register cpuidle_devices
Thomas Renninger65b7f832012-01-17 22:40:08 +01001512 * @cpu: cpu/core to initialize
Len Brown26717172010-03-08 14:07:30 -05001513 */
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001514static int intel_idle_cpu_init(unsigned int cpu)
Len Brown26717172010-03-08 14:07:30 -05001515{
Len Brown26717172010-03-08 14:07:30 -05001516 struct cpuidle_device *dev;
1517
Thomas Renninger65b7f832012-01-17 22:40:08 +01001518 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001519 dev->cpu = cpu;
Len Brown26717172010-03-08 14:07:30 -05001520
Thomas Renninger65b7f832012-01-17 22:40:08 +01001521 if (cpuidle_register_device(dev)) {
Joe Perches654d08a2017-06-09 12:29:20 -07001522 pr_debug("cpuidle_register_device %d failed!\n", cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001523 return -EIO;
Len Brown26717172010-03-08 14:07:30 -05001524 }
1525
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001526 if (!icpu)
1527 return 0;
1528
Andi Kleenb66b8b92012-01-26 00:09:07 +01001529 if (icpu->auto_demotion_disable_flags)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001530 auto_demotion_disable();
Thomas Renninger65b7f832012-01-17 22:40:08 +01001531
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001532 if (icpu->disable_promotion_to_c1e)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001533 c1e_promotion_disable();
1534
1535 return 0;
1536}
1537
1538static int intel_idle_cpu_online(unsigned int cpu)
1539{
1540 struct cpuidle_device *dev;
1541
1542 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
Rafael J. Wysockicbd2c4c2020-01-10 11:43:23 +01001543 tick_broadcast_enable();
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001544
1545 /*
1546 * Some systems can hotplug a cpu at runtime after
1547 * the kernel has booted, we have to initialize the
1548 * driver in this case
1549 */
1550 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
1551 if (!dev->registered)
1552 return intel_idle_cpu_init(cpu);
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001553
Len Brown26717172010-03-08 14:07:30 -05001554 return 0;
1555}
Len Brown26717172010-03-08 14:07:30 -05001556
Rafael J. Wysocki0755a9b2020-01-10 11:49:58 +01001557/**
1558 * intel_idle_cpuidle_devices_uninit - Unregister all cpuidle devices.
1559 */
1560static void __init intel_idle_cpuidle_devices_uninit(void)
1561{
1562 int i;
1563
1564 for_each_online_cpu(i)
1565 cpuidle_unregister_device(per_cpu_ptr(intel_idle_cpuidle_devices, i));
1566}
1567
Len Brown26717172010-03-08 14:07:30 -05001568static int __init intel_idle_init(void)
1569{
Rafael J. Wysockia6c86e32020-01-10 11:44:58 +01001570 const struct x86_cpu_id *id;
1571 unsigned int eax, ebx, ecx;
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001572 int retval;
Len Brown26717172010-03-08 14:07:30 -05001573
Thomas Renningerd1896042010-11-03 17:06:14 +01001574 /* Do not load intel_idle at all for now if idle= is passed */
1575 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
1576 return -ENODEV;
1577
Rafael J. Wysockia6c86e32020-01-10 11:44:58 +01001578 if (max_cstate == 0) {
1579 pr_debug("disabled\n");
1580 return -EPERM;
1581 }
1582
1583 id = x86_match_cpu(intel_idle_ids);
1584 if (id) {
1585 if (!boot_cpu_has(X86_FEATURE_MWAIT)) {
1586 pr_debug("Please enable MWAIT in BIOS SETUP\n");
1587 return -ENODEV;
1588 }
1589 } else {
1590 id = x86_match_cpu(intel_mwait_ids);
1591 if (!id)
1592 return -ENODEV;
1593 }
1594
1595 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
1596 return -ENODEV;
1597
1598 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
1599
1600 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
1601 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
1602 !mwait_substates)
1603 return -ENODEV;
1604
1605 pr_debug("MWAIT substates: 0x%x\n", mwait_substates);
1606
1607 icpu = (const struct idle_cpu *)id->driver_data;
1608 if (icpu) {
1609 cpuidle_state_table = icpu->state_table;
1610 if (icpu->use_acpi)
1611 intel_idle_acpi_cst_extract();
1612 } else if (!intel_idle_acpi_cst_extract()) {
1613 return -ENODEV;
1614 }
1615
1616 pr_debug("v" INTEL_IDLE_VERSION " model 0x%X\n",
1617 boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001618
Richard Cochrane9df69c2016-04-06 17:00:52 -04001619 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
Rafael J. Wysocki533da742020-01-10 11:45:49 +01001620 if (!intel_idle_cpuidle_devices)
Richard Cochrane9df69c2016-04-06 17:00:52 -04001621 return -ENOMEM;
1622
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001623 intel_idle_cpuidle_driver_init(&intel_idle_driver);
1624
Len Brown26717172010-03-08 14:07:30 -05001625 retval = cpuidle_register_driver(&intel_idle_driver);
1626 if (retval) {
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001627 struct cpuidle_driver *drv = cpuidle_get_driver();
Joe Perches654d08a2017-06-09 12:29:20 -07001628 printk(KERN_DEBUG pr_fmt("intel_idle yielding to %s\n"),
1629 drv ? drv->name : "none");
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001630 goto init_driver_fail;
Len Brown26717172010-03-08 14:07:30 -05001631 }
1632
Richard Cochran2259a812016-04-06 17:00:54 -04001633 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
1634 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
Richard Cochran2259a812016-04-06 17:00:54 -04001635
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001636 retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online",
1637 intel_idle_cpu_online, NULL);
1638 if (retval < 0)
1639 goto hp_setup_fail;
Len Brown26717172010-03-08 14:07:30 -05001640
Joe Perches654d08a2017-06-09 12:29:20 -07001641 pr_debug("lapic_timer_reliable_states 0x%x\n",
1642 lapic_timer_reliable_states);
Richard Cochran2259a812016-04-06 17:00:54 -04001643
Len Brown26717172010-03-08 14:07:30 -05001644 return 0;
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001645
1646hp_setup_fail:
1647 intel_idle_cpuidle_devices_uninit();
1648 cpuidle_unregister_driver(&intel_idle_driver);
1649init_driver_fail:
1650 free_percpu(intel_idle_cpuidle_devices);
1651 return retval;
1652
Len Brown26717172010-03-08 14:07:30 -05001653}
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001654device_initcall(intel_idle_init);
Len Brown26717172010-03-08 14:07:30 -05001655
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001656/*
1657 * We are not really modular, but we used to support that. Meaning we also
1658 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
1659 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
1660 * is the easiest way (currently) to continue doing that.
1661 */
Len Brown26717172010-03-08 14:07:30 -05001662module_param(max_cstate, int, 0444);