blob: d55606608ac8c30fb3b19eb6cd3c9f634fa20301 [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;
Rafael J. Wysocki4dcb78e2020-02-03 11:57:18 +010066static unsigned int disabled_states_mask;
Len Brown26717172010-03-08 14:07:30 -050067
Len Brownc4236282010-05-28 02:22:03 -040068static unsigned int mwait_substates;
Len Brown26717172010-03-08 14:07:30 -050069
Shaohua Li2a2d31c2011-01-10 09:38:12 +080070#define LAPIC_TIMER_ALWAYS_RELIABLE 0xFFFFFFFF
Len Brown26717172010-03-08 14:07:30 -050071/* Reliable LAPIC Timer States, bit 1 for C1 etc. */
Len Brownd13780d2010-07-07 00:12:03 -040072static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
Len Brown26717172010-03-08 14:07:30 -050073
Andi Kleenb66b8b92012-01-26 00:09:07 +010074struct idle_cpu {
75 struct cpuidle_state *state_table;
76
77 /*
78 * Hardware C-state auto-demotion may not always be optimal.
79 * Indicate which enable bits to clear here.
80 */
81 unsigned long auto_demotion_disable_flags;
Len Brown8c058d532014-07-31 15:21:24 -040082 bool byt_auto_demotion_disable_flag;
Len Brown32e95182013-02-02 01:31:56 -050083 bool disable_promotion_to_c1e;
Rafael J. Wysockibff8e602019-12-13 09:56:21 +010084 bool use_acpi;
Andi Kleenb66b8b92012-01-26 00:09:07 +010085};
86
87static const struct idle_cpu *icpu;
Namhyung Kim3265eba2010-08-08 03:10:03 +090088static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053089static int intel_idle(struct cpuidle_device *dev,
90 struct cpuidle_driver *drv, int index);
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +020091static void intel_idle_s2idle(struct cpuidle_device *dev,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +010092 struct cpuidle_driver *drv, int index);
Len Brown26717172010-03-08 14:07:30 -050093static struct cpuidle_state *cpuidle_state_table;
94
95/*
Rafael J. Wysockibff8e602019-12-13 09:56:21 +010096 * Enable this state by default even if the ACPI _CST does not list it.
97 */
98#define CPUIDLE_FLAG_ALWAYS_ENABLE BIT(15)
99
100/*
Len Brown956d0332011-01-12 02:51:20 -0500101 * Set this flag for states where the HW flushes the TLB for us
102 * and so we don't need cross-calls to keep it consistent.
103 * If this flag is set, SW flushes the TLB, so even if the
104 * HW doesn't do the flushing, this flag is safe to use.
105 */
106#define CPUIDLE_FLAG_TLB_FLUSHED 0x10000
107
108/*
Len Brownb1beab42013-01-31 19:55:37 -0500109 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
110 * the C-state (top nibble) and sub-state (bottom nibble)
111 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
112 *
113 * We store the hint at the top of our "flags" for each state.
114 */
115#define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
116#define MWAIT2flg(eax) ((eax & 0xFF) << 24)
117
118/*
Len Brown26717172010-03-08 14:07:30 -0500119 * States are indexed by the cstate number,
120 * which is also the index into the MWAIT hint array.
121 * Thus C0 is a dummy.
122 */
Jiang Liuba0dc812014-01-09 15:30:26 +0800123static struct cpuidle_state nehalem_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500124 {
Len Brownde09cdd2017-02-28 16:32:44 -0500125 .name = "C1",
Len Brown26717172010-03-08 14:07:30 -0500126 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100127 .flags = MWAIT2flg(0x00),
Len Brown26717172010-03-08 14:07:30 -0500128 .exit_latency = 3,
Len Brown26717172010-03-08 14:07:30 -0500129 .target_residency = 6,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100130 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200131 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500132 {
Len Brownde09cdd2017-02-28 16:32:44 -0500133 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500134 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100135 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500136 .exit_latency = 10,
137 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100138 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200139 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500140 {
Len Brownde09cdd2017-02-28 16:32:44 -0500141 .name = "C3",
Len Brown26717172010-03-08 14:07:30 -0500142 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100143 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500144 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500145 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100146 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200147 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500148 {
Len Brownde09cdd2017-02-28 16:32:44 -0500149 .name = "C6",
Len Brown26717172010-03-08 14:07:30 -0500150 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100151 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500152 .exit_latency = 200,
Len Brown26717172010-03-08 14:07:30 -0500153 .target_residency = 800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100154 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200155 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500156 {
157 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500158};
159
Jiang Liuba0dc812014-01-09 15:30:26 +0800160static struct cpuidle_state snb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500161 {
Len Brownde09cdd2017-02-28 16:32:44 -0500162 .name = "C1",
Len Brownd13780d2010-07-07 00:12:03 -0400163 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100164 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500165 .exit_latency = 2,
166 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100167 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200168 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500169 {
Len Brownde09cdd2017-02-28 16:32:44 -0500170 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500171 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100172 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500173 .exit_latency = 10,
174 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100175 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200176 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500177 {
Len Brownde09cdd2017-02-28 16:32:44 -0500178 .name = "C3",
Len Brownd13780d2010-07-07 00:12:03 -0400179 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100180 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400181 .exit_latency = 80,
Len Brownddbd5502010-12-13 18:28:22 -0500182 .target_residency = 211,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100183 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200184 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500185 {
Len Brownde09cdd2017-02-28 16:32:44 -0500186 .name = "C6",
Len Brownd13780d2010-07-07 00:12:03 -0400187 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100188 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400189 .exit_latency = 104,
Len Brownddbd5502010-12-13 18:28:22 -0500190 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100191 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200192 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500193 {
Len Brownde09cdd2017-02-28 16:32:44 -0500194 .name = "C7",
Len Brownd13780d2010-07-07 00:12:03 -0400195 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100196 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400197 .exit_latency = 109,
Len Brownddbd5502010-12-13 18:28:22 -0500198 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100199 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200200 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500201 {
202 .enter = NULL }
Len Brownd13780d2010-07-07 00:12:03 -0400203};
204
Len Brown718987d2014-02-14 02:30:00 -0500205static struct cpuidle_state byt_cstates[] = {
206 {
Len Brownde09cdd2017-02-28 16:32:44 -0500207 .name = "C1",
Len Brown718987d2014-02-14 02:30:00 -0500208 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100209 .flags = MWAIT2flg(0x00),
Len Brown718987d2014-02-14 02:30:00 -0500210 .exit_latency = 1,
211 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100212 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200213 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500214 {
Len Brownde09cdd2017-02-28 16:32:44 -0500215 .name = "C6N",
Len Brown718987d2014-02-14 02:30:00 -0500216 .desc = "MWAIT 0x58",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100217 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400218 .exit_latency = 300,
Len Brown718987d2014-02-14 02:30:00 -0500219 .target_residency = 275,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100220 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200221 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500222 {
Len Brownde09cdd2017-02-28 16:32:44 -0500223 .name = "C6S",
Len Brown718987d2014-02-14 02:30:00 -0500224 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100225 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400226 .exit_latency = 500,
Len Brown718987d2014-02-14 02:30:00 -0500227 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100228 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200229 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500230 {
Len Brownde09cdd2017-02-28 16:32:44 -0500231 .name = "C7",
Len Brown718987d2014-02-14 02:30:00 -0500232 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100233 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500234 .exit_latency = 1200,
Len Brownd7ef7672015-03-24 23:23:20 -0400235 .target_residency = 4000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100236 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200237 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500238 {
Len Brownde09cdd2017-02-28 16:32:44 -0500239 .name = "C7S",
Len Brown718987d2014-02-14 02:30:00 -0500240 .desc = "MWAIT 0x64",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100241 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500242 .exit_latency = 10000,
243 .target_residency = 20000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100244 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200245 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500246 {
247 .enter = NULL }
248};
249
Len Browncab07a52015-03-27 20:54:01 -0400250static struct cpuidle_state cht_cstates[] = {
251 {
Len Brownde09cdd2017-02-28 16:32:44 -0500252 .name = "C1",
Len Browncab07a52015-03-27 20:54:01 -0400253 .desc = "MWAIT 0x00",
254 .flags = MWAIT2flg(0x00),
255 .exit_latency = 1,
256 .target_residency = 1,
257 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200258 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400259 {
Len Brownde09cdd2017-02-28 16:32:44 -0500260 .name = "C6N",
Len Browncab07a52015-03-27 20:54:01 -0400261 .desc = "MWAIT 0x58",
262 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
263 .exit_latency = 80,
264 .target_residency = 275,
265 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200266 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400267 {
Len Brownde09cdd2017-02-28 16:32:44 -0500268 .name = "C6S",
Len Browncab07a52015-03-27 20:54:01 -0400269 .desc = "MWAIT 0x52",
270 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
271 .exit_latency = 200,
272 .target_residency = 560,
273 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200274 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400275 {
Len Brownde09cdd2017-02-28 16:32:44 -0500276 .name = "C7",
Len Browncab07a52015-03-27 20:54:01 -0400277 .desc = "MWAIT 0x60",
278 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
279 .exit_latency = 1200,
280 .target_residency = 4000,
281 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200282 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400283 {
Len Brownde09cdd2017-02-28 16:32:44 -0500284 .name = "C7S",
Len Browncab07a52015-03-27 20:54:01 -0400285 .desc = "MWAIT 0x64",
286 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
287 .exit_latency = 10000,
288 .target_residency = 20000,
289 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200290 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400291 {
292 .enter = NULL }
293};
294
Jiang Liuba0dc812014-01-09 15:30:26 +0800295static struct cpuidle_state ivb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500296 {
Len Brownde09cdd2017-02-28 16:32:44 -0500297 .name = "C1",
Len Brown6edab082012-06-01 19:45:32 -0400298 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100299 .flags = MWAIT2flg(0x00),
Len Brown6edab082012-06-01 19:45:32 -0400300 .exit_latency = 1,
301 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100302 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200303 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500304 {
Len Brownde09cdd2017-02-28 16:32:44 -0500305 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500306 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100307 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500308 .exit_latency = 10,
309 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100310 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200311 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500312 {
Len Brownde09cdd2017-02-28 16:32:44 -0500313 .name = "C3",
Len Brown6edab082012-06-01 19:45:32 -0400314 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100315 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400316 .exit_latency = 59,
317 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100318 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200319 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500320 {
Len Brownde09cdd2017-02-28 16:32:44 -0500321 .name = "C6",
Len Brown6edab082012-06-01 19:45:32 -0400322 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100323 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400324 .exit_latency = 80,
325 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100326 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200327 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500328 {
Len Brownde09cdd2017-02-28 16:32:44 -0500329 .name = "C7",
Len Brown6edab082012-06-01 19:45:32 -0400330 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100331 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400332 .exit_latency = 87,
333 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100334 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200335 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500336 {
337 .enter = NULL }
Len Brown6edab082012-06-01 19:45:32 -0400338};
339
Len Brown0138d8f2014-04-04 01:21:07 -0400340static struct cpuidle_state ivt_cstates[] = {
341 {
Len Brownde09cdd2017-02-28 16:32:44 -0500342 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400343 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100344 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400345 .exit_latency = 1,
346 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100347 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200348 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400349 {
Len Brownde09cdd2017-02-28 16:32:44 -0500350 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400351 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100352 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown0138d8f2014-04-04 01:21:07 -0400353 .exit_latency = 10,
354 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100355 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200356 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400357 {
Len Brownde09cdd2017-02-28 16:32:44 -0500358 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400359 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100360 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400361 .exit_latency = 59,
362 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100363 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200364 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400365 {
Len Brownde09cdd2017-02-28 16:32:44 -0500366 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400367 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100368 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400369 .exit_latency = 82,
370 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100371 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200372 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400373 {
374 .enter = NULL }
375};
376
377static struct cpuidle_state ivt_cstates_4s[] = {
378 {
Len Brownde09cdd2017-02-28 16:32:44 -0500379 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400380 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100381 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400382 .exit_latency = 1,
383 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100384 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200385 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400386 {
Len Brownde09cdd2017-02-28 16:32:44 -0500387 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400388 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100389 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown0138d8f2014-04-04 01:21:07 -0400390 .exit_latency = 10,
391 .target_residency = 250,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100392 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200393 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400394 {
Len Brownde09cdd2017-02-28 16:32:44 -0500395 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400396 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100397 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400398 .exit_latency = 59,
399 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100400 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200401 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400402 {
Len Brownde09cdd2017-02-28 16:32:44 -0500403 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400404 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100405 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400406 .exit_latency = 84,
407 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100408 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200409 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400410 {
411 .enter = NULL }
412};
413
414static struct cpuidle_state ivt_cstates_8s[] = {
415 {
Len Brownde09cdd2017-02-28 16:32:44 -0500416 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400417 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100418 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400419 .exit_latency = 1,
420 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100421 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200422 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400423 {
Len Brownde09cdd2017-02-28 16:32:44 -0500424 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400425 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100426 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown0138d8f2014-04-04 01:21:07 -0400427 .exit_latency = 10,
428 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100429 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200430 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400431 {
Len Brownde09cdd2017-02-28 16:32:44 -0500432 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400433 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100434 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400435 .exit_latency = 59,
436 .target_residency = 600,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100437 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200438 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400439 {
Len Brownde09cdd2017-02-28 16:32:44 -0500440 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400441 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100442 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400443 .exit_latency = 88,
444 .target_residency = 700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100445 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200446 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400447 {
448 .enter = NULL }
449};
450
Jiang Liuba0dc812014-01-09 15:30:26 +0800451static struct cpuidle_state hsw_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500452 {
Len Brownde09cdd2017-02-28 16:32:44 -0500453 .name = "C1",
Len Brown85a4d2d2013-01-31 14:40:49 -0500454 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100455 .flags = MWAIT2flg(0x00),
Len Brown85a4d2d2013-01-31 14:40:49 -0500456 .exit_latency = 2,
457 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100458 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200459 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500460 {
Len Brownde09cdd2017-02-28 16:32:44 -0500461 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500462 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100463 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500464 .exit_latency = 10,
465 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100466 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200467 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500468 {
Len Brownde09cdd2017-02-28 16:32:44 -0500469 .name = "C3",
Len Brown85a4d2d2013-01-31 14:40:49 -0500470 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100471 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500472 .exit_latency = 33,
473 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100474 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200475 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500476 {
Len Brownde09cdd2017-02-28 16:32:44 -0500477 .name = "C6",
Len Brown85a4d2d2013-01-31 14:40:49 -0500478 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100479 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500480 .exit_latency = 133,
481 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100482 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200483 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500484 {
Len Brownde09cdd2017-02-28 16:32:44 -0500485 .name = "C7s",
Len Brown85a4d2d2013-01-31 14:40:49 -0500486 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100487 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500488 .exit_latency = 166,
489 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100490 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200491 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500492 {
Len Brownde09cdd2017-02-28 16:32:44 -0500493 .name = "C8",
Len Brown86239ce2013-02-27 13:18:50 -0500494 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100495 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500496 .exit_latency = 300,
497 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100498 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200499 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500500 {
Len Brownde09cdd2017-02-28 16:32:44 -0500501 .name = "C9",
Len Brown86239ce2013-02-27 13:18:50 -0500502 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100503 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500504 .exit_latency = 600,
505 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100506 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200507 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500508 {
Len Brownde09cdd2017-02-28 16:32:44 -0500509 .name = "C10",
Len Brown86239ce2013-02-27 13:18:50 -0500510 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100511 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500512 .exit_latency = 2600,
513 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100514 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200515 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500516 {
Len Browne022e7e2013-02-01 23:37:30 -0500517 .enter = NULL }
Len Brown85a4d2d2013-01-31 14:40:49 -0500518};
Len Browna138b562014-02-04 23:56:40 -0500519static struct cpuidle_state bdw_cstates[] = {
520 {
Len Brownde09cdd2017-02-28 16:32:44 -0500521 .name = "C1",
Len Browna138b562014-02-04 23:56:40 -0500522 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100523 .flags = MWAIT2flg(0x00),
Len Browna138b562014-02-04 23:56:40 -0500524 .exit_latency = 2,
525 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100526 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200527 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500528 {
Len Brownde09cdd2017-02-28 16:32:44 -0500529 .name = "C1E",
Len Browna138b562014-02-04 23:56:40 -0500530 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100531 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Browna138b562014-02-04 23:56:40 -0500532 .exit_latency = 10,
533 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100534 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200535 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500536 {
Len Brownde09cdd2017-02-28 16:32:44 -0500537 .name = "C3",
Len Browna138b562014-02-04 23:56:40 -0500538 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100539 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500540 .exit_latency = 40,
541 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100542 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200543 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500544 {
Len Brownde09cdd2017-02-28 16:32:44 -0500545 .name = "C6",
Len Browna138b562014-02-04 23:56:40 -0500546 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100547 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500548 .exit_latency = 133,
549 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100550 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200551 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500552 {
Len Brownde09cdd2017-02-28 16:32:44 -0500553 .name = "C7s",
Len Browna138b562014-02-04 23:56:40 -0500554 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100555 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500556 .exit_latency = 166,
557 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100558 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200559 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500560 {
Len Brownde09cdd2017-02-28 16:32:44 -0500561 .name = "C8",
Len Browna138b562014-02-04 23:56:40 -0500562 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100563 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500564 .exit_latency = 300,
565 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100566 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200567 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500568 {
Len Brownde09cdd2017-02-28 16:32:44 -0500569 .name = "C9",
Len Browna138b562014-02-04 23:56:40 -0500570 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100571 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500572 .exit_latency = 600,
573 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100574 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200575 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500576 {
Len Brownde09cdd2017-02-28 16:32:44 -0500577 .name = "C10",
Len Browna138b562014-02-04 23:56:40 -0500578 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100579 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500580 .exit_latency = 2600,
581 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100582 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200583 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500584 {
585 .enter = NULL }
586};
Len Brown85a4d2d2013-01-31 14:40:49 -0500587
Len Brown493f1332015-03-25 23:20:37 -0400588static struct cpuidle_state skl_cstates[] = {
589 {
Len Brownde09cdd2017-02-28 16:32:44 -0500590 .name = "C1",
Len Brown493f1332015-03-25 23:20:37 -0400591 .desc = "MWAIT 0x00",
592 .flags = MWAIT2flg(0x00),
593 .exit_latency = 2,
594 .target_residency = 2,
595 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200596 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400597 {
Len Brownde09cdd2017-02-28 16:32:44 -0500598 .name = "C1E",
Len Brown493f1332015-03-25 23:20:37 -0400599 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100600 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown493f1332015-03-25 23:20:37 -0400601 .exit_latency = 10,
602 .target_residency = 20,
603 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200604 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400605 {
Len Brownde09cdd2017-02-28 16:32:44 -0500606 .name = "C3",
Len Brown493f1332015-03-25 23:20:37 -0400607 .desc = "MWAIT 0x10",
608 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
609 .exit_latency = 70,
610 .target_residency = 100,
611 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200612 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400613 {
Len Brownde09cdd2017-02-28 16:32:44 -0500614 .name = "C6",
Len Brown493f1332015-03-25 23:20:37 -0400615 .desc = "MWAIT 0x20",
616 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400617 .exit_latency = 85,
Len Brown493f1332015-03-25 23:20:37 -0400618 .target_residency = 200,
619 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200620 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400621 {
Len Brownde09cdd2017-02-28 16:32:44 -0500622 .name = "C7s",
Len Brown493f1332015-03-25 23:20:37 -0400623 .desc = "MWAIT 0x33",
624 .flags = MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED,
625 .exit_latency = 124,
626 .target_residency = 800,
627 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200628 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400629 {
Len Brownde09cdd2017-02-28 16:32:44 -0500630 .name = "C8",
Len Brown493f1332015-03-25 23:20:37 -0400631 .desc = "MWAIT 0x40",
632 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400633 .exit_latency = 200,
Len Brown493f1332015-03-25 23:20:37 -0400634 .target_residency = 800,
635 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200636 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400637 {
Len Brownde09cdd2017-02-28 16:32:44 -0500638 .name = "C9",
Len Brown135919a2015-09-09 13:35:05 -0400639 .desc = "MWAIT 0x50",
640 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
641 .exit_latency = 480,
642 .target_residency = 5000,
643 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200644 .enter_s2idle = intel_idle_s2idle, },
Len Brown135919a2015-09-09 13:35:05 -0400645 {
Len Brownde09cdd2017-02-28 16:32:44 -0500646 .name = "C10",
Len Brown493f1332015-03-25 23:20:37 -0400647 .desc = "MWAIT 0x60",
648 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
649 .exit_latency = 890,
650 .target_residency = 5000,
651 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200652 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400653 {
654 .enter = NULL }
655};
656
Len Brownf9e71652016-04-06 17:00:58 -0400657static struct cpuidle_state skx_cstates[] = {
658 {
Len Brownde09cdd2017-02-28 16:32:44 -0500659 .name = "C1",
Len Brownf9e71652016-04-06 17:00:58 -0400660 .desc = "MWAIT 0x00",
661 .flags = MWAIT2flg(0x00),
662 .exit_latency = 2,
663 .target_residency = 2,
664 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200665 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400666 {
Len Brownde09cdd2017-02-28 16:32:44 -0500667 .name = "C1E",
Len Brownf9e71652016-04-06 17:00:58 -0400668 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100669 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brownf9e71652016-04-06 17:00:58 -0400670 .exit_latency = 10,
671 .target_residency = 20,
672 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200673 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400674 {
Len Brownde09cdd2017-02-28 16:32:44 -0500675 .name = "C6",
Len Brownf9e71652016-04-06 17:00:58 -0400676 .desc = "MWAIT 0x20",
677 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
678 .exit_latency = 133,
679 .target_residency = 600,
680 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200681 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400682 {
683 .enter = NULL }
684};
685
Jiang Liuba0dc812014-01-09 15:30:26 +0800686static struct cpuidle_state atom_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500687 {
Len Brownde09cdd2017-02-28 16:32:44 -0500688 .name = "C1E",
Len Brown26717172010-03-08 14:07:30 -0500689 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100690 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500691 .exit_latency = 10,
692 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100693 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200694 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500695 {
Len Brownde09cdd2017-02-28 16:32:44 -0500696 .name = "C2",
Len Brown26717172010-03-08 14:07:30 -0500697 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100698 .flags = MWAIT2flg(0x10),
Len Brown26717172010-03-08 14:07:30 -0500699 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500700 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100701 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200702 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500703 {
Len Brownde09cdd2017-02-28 16:32:44 -0500704 .name = "C4",
Len Brown26717172010-03-08 14:07:30 -0500705 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100706 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500707 .exit_latency = 100,
Len Brown26717172010-03-08 14:07:30 -0500708 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100709 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200710 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500711 {
Len Brownde09cdd2017-02-28 16:32:44 -0500712 .name = "C6",
Len Brown7fcca7d2010-10-05 13:43:14 -0400713 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100714 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown7fcca7d2010-10-05 13:43:14 -0400715 .exit_latency = 140,
Len Brown7fcca7d2010-10-05 13:43:14 -0400716 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100717 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200718 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500719 {
720 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500721};
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300722static struct cpuidle_state tangier_cstates[] = {
723 {
Len Brownde09cdd2017-02-28 16:32:44 -0500724 .name = "C1",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300725 .desc = "MWAIT 0x00",
726 .flags = MWAIT2flg(0x00),
727 .exit_latency = 1,
728 .target_residency = 4,
729 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200730 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300731 {
Len Brownde09cdd2017-02-28 16:32:44 -0500732 .name = "C4",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300733 .desc = "MWAIT 0x30",
734 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
735 .exit_latency = 100,
736 .target_residency = 400,
737 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200738 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300739 {
Len Brownde09cdd2017-02-28 16:32:44 -0500740 .name = "C6",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300741 .desc = "MWAIT 0x52",
742 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
743 .exit_latency = 140,
744 .target_residency = 560,
745 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200746 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300747 {
Len Brownde09cdd2017-02-28 16:32:44 -0500748 .name = "C7",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300749 .desc = "MWAIT 0x60",
750 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
751 .exit_latency = 1200,
752 .target_residency = 4000,
753 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200754 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300755 {
Len Brownde09cdd2017-02-28 16:32:44 -0500756 .name = "C9",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300757 .desc = "MWAIT 0x64",
758 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
759 .exit_latency = 10000,
760 .target_residency = 20000,
761 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200762 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300763 {
764 .enter = NULL }
765};
Jiang Liu88390992014-01-09 15:30:27 +0800766static struct cpuidle_state avn_cstates[] = {
Len Brownfab04b22013-11-09 00:30:17 -0500767 {
Len Brownde09cdd2017-02-28 16:32:44 -0500768 .name = "C1",
Len Brownfab04b22013-11-09 00:30:17 -0500769 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100770 .flags = MWAIT2flg(0x00),
Len Brownfab04b22013-11-09 00:30:17 -0500771 .exit_latency = 2,
772 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100773 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200774 .enter_s2idle = intel_idle_s2idle, },
Len Brownfab04b22013-11-09 00:30:17 -0500775 {
Len Brownde09cdd2017-02-28 16:32:44 -0500776 .name = "C6",
Len Brownfab04b22013-11-09 00:30:17 -0500777 .desc = "MWAIT 0x51",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100778 .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownfab04b22013-11-09 00:30:17 -0500779 .exit_latency = 15,
780 .target_residency = 45,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100781 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200782 .enter_s2idle = intel_idle_s2idle, },
Jiang Liu88390992014-01-09 15:30:27 +0800783 {
784 .enter = NULL }
Len Brownfab04b22013-11-09 00:30:17 -0500785};
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700786static struct cpuidle_state knl_cstates[] = {
787 {
Len Brownde09cdd2017-02-28 16:32:44 -0500788 .name = "C1",
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700789 .desc = "MWAIT 0x00",
790 .flags = MWAIT2flg(0x00),
791 .exit_latency = 1,
792 .target_residency = 2,
793 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200794 .enter_s2idle = intel_idle_s2idle },
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700795 {
Len Brownde09cdd2017-02-28 16:32:44 -0500796 .name = "C6",
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700797 .desc = "MWAIT 0x10",
798 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
799 .exit_latency = 120,
800 .target_residency = 500,
801 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200802 .enter_s2idle = intel_idle_s2idle },
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700803 {
804 .enter = NULL }
805};
Len Brown26717172010-03-08 14:07:30 -0500806
Len Brown5dcef692016-04-06 17:00:47 -0400807static struct cpuidle_state bxt_cstates[] = {
808 {
Len Brownde09cdd2017-02-28 16:32:44 -0500809 .name = "C1",
Len Brown5dcef692016-04-06 17:00:47 -0400810 .desc = "MWAIT 0x00",
811 .flags = MWAIT2flg(0x00),
812 .exit_latency = 2,
813 .target_residency = 2,
814 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200815 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400816 {
Len Brownde09cdd2017-02-28 16:32:44 -0500817 .name = "C1E",
Len Brown5dcef692016-04-06 17:00:47 -0400818 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100819 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown5dcef692016-04-06 17:00:47 -0400820 .exit_latency = 10,
821 .target_residency = 20,
822 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200823 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400824 {
Len Brownde09cdd2017-02-28 16:32:44 -0500825 .name = "C6",
Len Brown5dcef692016-04-06 17:00:47 -0400826 .desc = "MWAIT 0x20",
827 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
828 .exit_latency = 133,
829 .target_residency = 133,
830 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200831 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400832 {
Len Brownde09cdd2017-02-28 16:32:44 -0500833 .name = "C7s",
Len Brown5dcef692016-04-06 17:00:47 -0400834 .desc = "MWAIT 0x31",
835 .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
836 .exit_latency = 155,
837 .target_residency = 155,
838 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200839 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400840 {
Len Brownde09cdd2017-02-28 16:32:44 -0500841 .name = "C8",
Len Brown5dcef692016-04-06 17:00:47 -0400842 .desc = "MWAIT 0x40",
843 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
844 .exit_latency = 1000,
845 .target_residency = 1000,
846 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200847 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400848 {
Len Brownde09cdd2017-02-28 16:32:44 -0500849 .name = "C9",
Len Brown5dcef692016-04-06 17:00:47 -0400850 .desc = "MWAIT 0x50",
851 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
852 .exit_latency = 2000,
853 .target_residency = 2000,
854 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200855 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400856 {
Len Brownde09cdd2017-02-28 16:32:44 -0500857 .name = "C10",
Len Brown5dcef692016-04-06 17:00:47 -0400858 .desc = "MWAIT 0x60",
859 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
860 .exit_latency = 10000,
861 .target_residency = 10000,
862 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200863 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400864 {
865 .enter = NULL }
866};
867
Jacob Pan0080d652016-06-17 01:28:34 -0400868static struct cpuidle_state dnv_cstates[] = {
869 {
Len Brownde09cdd2017-02-28 16:32:44 -0500870 .name = "C1",
Jacob Pan0080d652016-06-17 01:28:34 -0400871 .desc = "MWAIT 0x00",
872 .flags = MWAIT2flg(0x00),
873 .exit_latency = 2,
874 .target_residency = 2,
875 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200876 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400877 {
Len Brownde09cdd2017-02-28 16:32:44 -0500878 .name = "C1E",
Jacob Pan0080d652016-06-17 01:28:34 -0400879 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100880 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Jacob Pan0080d652016-06-17 01:28:34 -0400881 .exit_latency = 10,
882 .target_residency = 20,
883 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200884 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400885 {
Len Brownde09cdd2017-02-28 16:32:44 -0500886 .name = "C6",
Jacob Pan0080d652016-06-17 01:28:34 -0400887 .desc = "MWAIT 0x20",
888 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
889 .exit_latency = 50,
890 .target_residency = 500,
891 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200892 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400893 {
894 .enter = NULL }
895};
896
Len Brown26717172010-03-08 14:07:30 -0500897/**
898 * intel_idle
899 * @dev: cpuidle_device
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530900 * @drv: cpuidle driver
Deepthi Dharware978aa72011-10-28 16:20:09 +0530901 * @index: index of cpuidle state
Len Brown26717172010-03-08 14:07:30 -0500902 *
Yanmin Zhang63ff07b2012-01-10 15:48:21 -0800903 * Must be called under local_irq_disable().
Len Brown26717172010-03-08 14:07:30 -0500904 */
Chris Metcalf6727ad92016-10-07 17:02:55 -0700905static __cpuidle int intel_idle(struct cpuidle_device *dev,
906 struct cpuidle_driver *drv, int index)
Len Brown26717172010-03-08 14:07:30 -0500907{
908 unsigned long ecx = 1; /* break on interrupt flag */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530909 struct cpuidle_state *state = &drv->states[index];
Len Brownb1beab42013-01-31 19:55:37 -0500910 unsigned long eax = flg2MWAIT(state->flags);
Len Brown26717172010-03-08 14:07:30 -0500911 unsigned int cstate;
Jason Baron0563bb72017-10-06 13:19:45 -0400912 bool uninitialized_var(tick);
Andy Lutomirski67535732017-11-04 04:16:12 -0700913 int cpu = smp_processor_id();
Len Brown26717172010-03-08 14:07:30 -0500914
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400915 /*
Andy Lutomirski67535732017-11-04 04:16:12 -0700916 * leave_mm() to avoid costly and often unnecessary wakeups
917 * for flushing the user TLB's associated with the active mm.
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400918 */
Andy Lutomirski67535732017-11-04 04:16:12 -0700919 if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
920 leave_mm(cpu);
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400921
Jason Baron0563bb72017-10-06 13:19:45 -0400922 if (!static_cpu_has(X86_FEATURE_ARAT)) {
923 cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
924 MWAIT_CSTATE_MASK) + 1;
925 tick = false;
926 if (!(lapic_timer_reliable_states & (1 << (cstate)))) {
927 tick = true;
928 tick_broadcast_enter();
929 }
930 }
Len Brown26717172010-03-08 14:07:30 -0500931
Peter Zijlstra16824252013-12-12 15:08:36 +0100932 mwait_idle_with_hints(eax, ecx);
Len Brown26717172010-03-08 14:07:30 -0500933
Jason Baron0563bb72017-10-06 13:19:45 -0400934 if (!static_cpu_has(X86_FEATURE_ARAT) && tick)
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200935 tick_broadcast_exit();
Len Brown26717172010-03-08 14:07:30 -0500936
Deepthi Dharware978aa72011-10-28 16:20:09 +0530937 return index;
Len Brown26717172010-03-08 14:07:30 -0500938}
939
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100940/**
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200941 * intel_idle_s2idle - simplified "enter" callback routine for suspend-to-idle
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100942 * @dev: cpuidle_device
943 * @drv: cpuidle driver
944 * @index: state index
945 */
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200946static void intel_idle_s2idle(struct cpuidle_device *dev,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100947 struct cpuidle_driver *drv, int index)
948{
949 unsigned long ecx = 1; /* break on interrupt flag */
950 unsigned long eax = flg2MWAIT(drv->states[index].flags);
951
952 mwait_idle_with_hints(eax, ecx);
953}
954
Andi Kleenb66b8b92012-01-26 00:09:07 +0100955static const struct idle_cpu idle_cpu_nehalem = {
956 .state_table = nehalem_cstates,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100957 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
Len Brown32e95182013-02-02 01:31:56 -0500958 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100959};
960
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100961static const struct idle_cpu idle_cpu_nhx = {
962 .state_table = nehalem_cstates,
963 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
964 .disable_promotion_to_c1e = true,
965 .use_acpi = true,
966};
967
Andi Kleenb66b8b92012-01-26 00:09:07 +0100968static const struct idle_cpu idle_cpu_atom = {
969 .state_table = atom_cstates,
970};
971
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300972static const struct idle_cpu idle_cpu_tangier = {
973 .state_table = tangier_cstates,
974};
975
Andi Kleenb66b8b92012-01-26 00:09:07 +0100976static const struct idle_cpu idle_cpu_lincroft = {
977 .state_table = atom_cstates,
978 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
979};
980
981static const struct idle_cpu idle_cpu_snb = {
982 .state_table = snb_cstates,
Len Brown32e95182013-02-02 01:31:56 -0500983 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100984};
985
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100986static const struct idle_cpu idle_cpu_snx = {
987 .state_table = snb_cstates,
988 .disable_promotion_to_c1e = true,
989 .use_acpi = true,
990};
991
Len Brown718987d2014-02-14 02:30:00 -0500992static const struct idle_cpu idle_cpu_byt = {
993 .state_table = byt_cstates,
994 .disable_promotion_to_c1e = true,
Len Brown8c058d532014-07-31 15:21:24 -0400995 .byt_auto_demotion_disable_flag = true,
Len Brown718987d2014-02-14 02:30:00 -0500996};
997
Len Browncab07a52015-03-27 20:54:01 -0400998static const struct idle_cpu idle_cpu_cht = {
999 .state_table = cht_cstates,
1000 .disable_promotion_to_c1e = true,
1001 .byt_auto_demotion_disable_flag = true,
1002};
1003
Len Brown6edab082012-06-01 19:45:32 -04001004static const struct idle_cpu idle_cpu_ivb = {
1005 .state_table = ivb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001006 .disable_promotion_to_c1e = true,
Len Brown6edab082012-06-01 19:45:32 -04001007};
1008
Len Brown0138d8f2014-04-04 01:21:07 -04001009static const struct idle_cpu idle_cpu_ivt = {
1010 .state_table = ivt_cstates,
1011 .disable_promotion_to_c1e = true,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001012 .use_acpi = true,
Len Brown0138d8f2014-04-04 01:21:07 -04001013};
1014
Len Brown85a4d2d2013-01-31 14:40:49 -05001015static const struct idle_cpu idle_cpu_hsw = {
1016 .state_table = hsw_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001017 .disable_promotion_to_c1e = true,
Len Brown85a4d2d2013-01-31 14:40:49 -05001018};
1019
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001020static const struct idle_cpu idle_cpu_hsx = {
1021 .state_table = hsw_cstates,
1022 .disable_promotion_to_c1e = true,
1023 .use_acpi = true,
1024};
1025
Len Browna138b562014-02-04 23:56:40 -05001026static const struct idle_cpu idle_cpu_bdw = {
1027 .state_table = bdw_cstates,
1028 .disable_promotion_to_c1e = true,
1029};
1030
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001031static const struct idle_cpu idle_cpu_bdx = {
1032 .state_table = bdw_cstates,
1033 .disable_promotion_to_c1e = true,
1034 .use_acpi = true,
1035};
1036
Len Brown493f1332015-03-25 23:20:37 -04001037static const struct idle_cpu idle_cpu_skl = {
1038 .state_table = skl_cstates,
1039 .disable_promotion_to_c1e = true,
1040};
1041
Len Brownf9e71652016-04-06 17:00:58 -04001042static const struct idle_cpu idle_cpu_skx = {
1043 .state_table = skx_cstates,
1044 .disable_promotion_to_c1e = true,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001045 .use_acpi = true,
Len Brownf9e71652016-04-06 17:00:58 -04001046};
Len Brown493f1332015-03-25 23:20:37 -04001047
Len Brownfab04b22013-11-09 00:30:17 -05001048static const struct idle_cpu idle_cpu_avn = {
1049 .state_table = avn_cstates,
1050 .disable_promotion_to_c1e = true,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001051 .use_acpi = true,
Len Brownfab04b22013-11-09 00:30:17 -05001052};
1053
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001054static const struct idle_cpu idle_cpu_knl = {
1055 .state_table = knl_cstates,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001056 .use_acpi = true,
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001057};
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,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001067 .use_acpi = true,
Jacob Pan0080d652016-06-17 01:28:34 -04001068};
1069
Mathias Kraused5cdc3c2015-03-25 22:15:14 +01001070static const struct x86_cpu_id intel_idle_ids[] __initconst = {
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001071 INTEL_CPU_FAM6(NEHALEM_EP, idle_cpu_nhx),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001072 INTEL_CPU_FAM6(NEHALEM, idle_cpu_nehalem),
1073 INTEL_CPU_FAM6(NEHALEM_G, idle_cpu_nehalem),
1074 INTEL_CPU_FAM6(WESTMERE, idle_cpu_nehalem),
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001075 INTEL_CPU_FAM6(WESTMERE_EP, idle_cpu_nhx),
1076 INTEL_CPU_FAM6(NEHALEM_EX, idle_cpu_nhx),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001077 INTEL_CPU_FAM6(ATOM_BONNELL, idle_cpu_atom),
1078 INTEL_CPU_FAM6(ATOM_BONNELL_MID, idle_cpu_lincroft),
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001079 INTEL_CPU_FAM6(WESTMERE_EX, idle_cpu_nhx),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001080 INTEL_CPU_FAM6(SANDYBRIDGE, idle_cpu_snb),
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001081 INTEL_CPU_FAM6(SANDYBRIDGE_X, idle_cpu_snx),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001082 INTEL_CPU_FAM6(ATOM_SALTWELL, idle_cpu_atom),
1083 INTEL_CPU_FAM6(ATOM_SILVERMONT, idle_cpu_byt),
1084 INTEL_CPU_FAM6(ATOM_SILVERMONT_MID, idle_cpu_tangier),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001085 INTEL_CPU_FAM6(ATOM_AIRMONT, idle_cpu_cht),
1086 INTEL_CPU_FAM6(IVYBRIDGE, idle_cpu_ivb),
1087 INTEL_CPU_FAM6(IVYBRIDGE_X, idle_cpu_ivt),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001088 INTEL_CPU_FAM6(HASWELL, idle_cpu_hsw),
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001089 INTEL_CPU_FAM6(HASWELL_X, idle_cpu_hsx),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001090 INTEL_CPU_FAM6(HASWELL_L, idle_cpu_hsw),
Peter Zijlstra5e741402019-08-27 21:48:23 +02001091 INTEL_CPU_FAM6(HASWELL_G, idle_cpu_hsw),
Peter Zijlstra5ebb34e2019-08-27 21:48:24 +02001092 INTEL_CPU_FAM6(ATOM_SILVERMONT_D, idle_cpu_avn),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001093 INTEL_CPU_FAM6(BROADWELL, idle_cpu_bdw),
Peter Zijlstra5e741402019-08-27 21:48:23 +02001094 INTEL_CPU_FAM6(BROADWELL_G, idle_cpu_bdw),
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001095 INTEL_CPU_FAM6(BROADWELL_X, idle_cpu_bdx),
1096 INTEL_CPU_FAM6(BROADWELL_D, idle_cpu_bdx),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001097 INTEL_CPU_FAM6(SKYLAKE_L, idle_cpu_skl),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001098 INTEL_CPU_FAM6(SKYLAKE, idle_cpu_skl),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001099 INTEL_CPU_FAM6(KABYLAKE_L, idle_cpu_skl),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001100 INTEL_CPU_FAM6(KABYLAKE, idle_cpu_skl),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001101 INTEL_CPU_FAM6(SKYLAKE_X, idle_cpu_skx),
1102 INTEL_CPU_FAM6(XEON_PHI_KNL, idle_cpu_knl),
1103 INTEL_CPU_FAM6(XEON_PHI_KNM, idle_cpu_knl),
1104 INTEL_CPU_FAM6(ATOM_GOLDMONT, idle_cpu_bxt),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001105 INTEL_CPU_FAM6(ATOM_GOLDMONT_PLUS, idle_cpu_bxt),
Peter Zijlstra5ebb34e2019-08-27 21:48:24 +02001106 INTEL_CPU_FAM6(ATOM_GOLDMONT_D, idle_cpu_dnv),
1107 INTEL_CPU_FAM6(ATOM_TREMONT_D, idle_cpu_dnv),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001108 {}
1109};
Andi Kleenb66b8b92012-01-26 00:09:07 +01001110
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001111#define INTEL_CPU_FAM6_MWAIT \
1112 { X86_VENDOR_INTEL, 6, X86_MODEL_ANY, X86_FEATURE_MWAIT, 0 }
1113
1114static const struct x86_cpu_id intel_mwait_ids[] __initconst = {
1115 INTEL_CPU_FAM6_MWAIT,
1116 {}
1117};
1118
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001119static bool __init intel_idle_max_cstate_reached(int cstate)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001120{
1121 if (cstate + 1 > max_cstate) {
1122 pr_info("max_cstate %d reached\n", max_cstate);
1123 return true;
1124 }
1125 return false;
1126}
1127
1128#ifdef CONFIG_ACPI_PROCESSOR_CSTATE
1129#include <acpi/processor.h>
1130
Rafael J. Wysocki4ec32d92019-12-13 09:56:29 +01001131static bool no_acpi __read_mostly;
1132module_param(no_acpi, bool, 0444);
1133MODULE_PARM_DESC(no_acpi, "Do not use ACPI _CST for building the idle states list");
1134
Rafael J. Wysocki3a5be9b2020-02-03 11:57:08 +01001135static bool force_use_acpi __read_mostly; /* No effect if no_acpi is set. */
1136module_param_named(use_acpi, force_use_acpi, bool, 0444);
1137MODULE_PARM_DESC(use_acpi, "Use ACPI _CST for building the idle states list");
1138
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001139static struct acpi_processor_power acpi_state_table __initdata;
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001140
1141/**
1142 * intel_idle_cst_usable - Check if the _CST information can be used.
1143 *
1144 * Check if all of the C-states listed by _CST in the max_cstate range are
1145 * ACPI_CSTATE_FFH, which means that they should be entered via MWAIT.
1146 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001147static bool __init intel_idle_cst_usable(void)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001148{
1149 int cstate, limit;
1150
1151 limit = min_t(int, min_t(int, CPUIDLE_STATE_MAX, max_cstate + 1),
1152 acpi_state_table.count);
1153
1154 for (cstate = 1; cstate < limit; cstate++) {
1155 struct acpi_processor_cx *cx = &acpi_state_table.states[cstate];
1156
1157 if (cx->entry_method != ACPI_CSTATE_FFH)
1158 return false;
1159 }
1160
1161 return true;
1162}
1163
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001164static bool __init intel_idle_acpi_cst_extract(void)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001165{
1166 unsigned int cpu;
1167
Rafael J. Wysocki4ec32d92019-12-13 09:56:29 +01001168 if (no_acpi) {
1169 pr_debug("Not allowed to use ACPI _CST\n");
1170 return false;
1171 }
1172
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001173 for_each_possible_cpu(cpu) {
1174 struct acpi_processor *pr = per_cpu(processors, cpu);
1175
1176 if (!pr)
1177 continue;
1178
1179 if (acpi_processor_evaluate_cst(pr->handle, cpu, &acpi_state_table))
1180 continue;
1181
1182 acpi_state_table.count++;
1183
1184 if (!intel_idle_cst_usable())
1185 continue;
1186
1187 if (!acpi_processor_claim_cst_control()) {
1188 acpi_state_table.count = 0;
1189 return false;
1190 }
1191
1192 return true;
1193 }
1194
1195 pr_debug("ACPI _CST not found or not usable\n");
1196 return false;
1197}
1198
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001199static void __init intel_idle_init_cstates_acpi(struct cpuidle_driver *drv)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001200{
1201 int cstate, limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
1202
1203 /*
1204 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1205 * the interesting states are ACPI_CSTATE_FFH.
1206 */
1207 for (cstate = 1; cstate < limit; cstate++) {
1208 struct acpi_processor_cx *cx;
1209 struct cpuidle_state *state;
1210
1211 if (intel_idle_max_cstate_reached(cstate))
1212 break;
1213
1214 cx = &acpi_state_table.states[cstate];
1215
1216 state = &drv->states[drv->state_count++];
1217
1218 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d_ACPI", cstate);
1219 strlcpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
1220 state->exit_latency = cx->latency;
1221 /*
1222 * For C1-type C-states use the same number for both the exit
1223 * latency and target residency, because that is the case for
1224 * C1 in the majority of the static C-states tables above.
1225 * For the other types of C-states, however, set the target
1226 * residency to 3 times the exit latency which should lead to
1227 * a reasonable balance between energy-efficiency and
1228 * performance in the majority of interesting cases.
1229 */
1230 state->target_residency = cx->latency;
1231 if (cx->type > ACPI_STATE_C1)
1232 state->target_residency *= 3;
1233
1234 state->flags = MWAIT2flg(cx->address);
1235 if (cx->type > ACPI_STATE_C2)
1236 state->flags |= CPUIDLE_FLAG_TLB_FLUSHED;
1237
Rafael J. Wysocki4dcb78e2020-02-03 11:57:18 +01001238 if (disabled_states_mask & BIT(cstate))
1239 state->flags |= CPUIDLE_FLAG_OFF;
1240
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001241 state->enter = intel_idle;
1242 state->enter_s2idle = intel_idle_s2idle;
1243 }
1244}
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001245
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001246static bool __init intel_idle_off_by_default(u32 mwait_hint)
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001247{
1248 int cstate, limit;
1249
1250 /*
1251 * If there are no _CST C-states, do not disable any C-states by
1252 * default.
1253 */
1254 if (!acpi_state_table.count)
1255 return false;
1256
1257 limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
1258 /*
1259 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1260 * the interesting states are ACPI_CSTATE_FFH.
1261 */
1262 for (cstate = 1; cstate < limit; cstate++) {
1263 if (acpi_state_table.states[cstate].address == mwait_hint)
1264 return false;
1265 }
1266 return true;
1267}
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001268#else /* !CONFIG_ACPI_PROCESSOR_CSTATE */
Rafael J. Wysocki3a5be9b2020-02-03 11:57:08 +01001269#define force_use_acpi (false)
1270
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001271static inline bool intel_idle_acpi_cst_extract(void) { return false; }
1272static inline void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) { }
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001273static inline bool intel_idle_off_by_default(u32 mwait_hint) { return false; }
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001274#endif /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1275
Len Brown26717172010-03-08 14:07:30 -05001276/*
Len Brownd70e28f2016-03-13 00:33:48 -05001277 * ivt_idle_state_table_update(void)
1278 *
1279 * Tune IVT multi-socket targets
1280 * Assumption: num_sockets == (max_package_num + 1)
1281 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001282static void __init ivt_idle_state_table_update(void)
Len Brownd70e28f2016-03-13 00:33:48 -05001283{
1284 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1285 int cpu, package_num, num_sockets = 1;
1286
1287 for_each_online_cpu(cpu) {
1288 package_num = topology_physical_package_id(cpu);
1289 if (package_num + 1 > num_sockets) {
1290 num_sockets = package_num + 1;
1291
1292 if (num_sockets > 4) {
1293 cpuidle_state_table = ivt_cstates_8s;
1294 return;
1295 }
1296 }
1297 }
1298
1299 if (num_sockets > 2)
1300 cpuidle_state_table = ivt_cstates_4s;
1301
1302 /* else, 1 and 2 socket systems use default ivt_cstates */
1303}
Len Brown5dcef692016-04-06 17:00:47 -04001304
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001305/**
1306 * irtl_2_usec - IRTL to microseconds conversion.
1307 * @irtl: IRTL MSR value.
1308 *
1309 * Translate the IRTL (Interrupt Response Time Limit) MSR value to microseconds.
Len Brown5dcef692016-04-06 17:00:47 -04001310 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001311static unsigned long long __init irtl_2_usec(unsigned long long irtl)
Len Brown5dcef692016-04-06 17:00:47 -04001312{
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001313 static const unsigned int irtl_ns_units[] __initconst = {
1314 1, 32, 1024, 32768, 1048576, 33554432, 0, 0
1315 };
Len Brown5dcef692016-04-06 17:00:47 -04001316 unsigned long long ns;
1317
Jan Beulich3451ab32016-06-27 00:35:12 -06001318 if (!irtl)
1319 return 0;
1320
Jan Beulichbef45092016-06-27 00:35:48 -06001321 ns = irtl_ns_units[(irtl >> 10) & 0x7];
Len Brown5dcef692016-04-06 17:00:47 -04001322
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001323 return div_u64((irtl & 0x3FF) * ns, NSEC_PER_USEC);
Len Brown5dcef692016-04-06 17:00:47 -04001324}
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001325
Len Brown5dcef692016-04-06 17:00:47 -04001326/*
1327 * bxt_idle_state_table_update(void)
1328 *
1329 * On BXT, we trust the IRTL to show the definitive maximum latency
1330 * We use the same value for target_residency.
1331 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001332static void __init bxt_idle_state_table_update(void)
Len Brown5dcef692016-04-06 17:00:47 -04001333{
1334 unsigned long long msr;
Jan Beulich3451ab32016-06-27 00:35:12 -06001335 unsigned int usec;
Len Brown5dcef692016-04-06 17:00:47 -04001336
1337 rdmsrl(MSR_PKGC6_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001338 usec = irtl_2_usec(msr);
1339 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001340 bxt_cstates[2].exit_latency = usec;
1341 bxt_cstates[2].target_residency = usec;
1342 }
1343
1344 rdmsrl(MSR_PKGC7_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001345 usec = irtl_2_usec(msr);
1346 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001347 bxt_cstates[3].exit_latency = usec;
1348 bxt_cstates[3].target_residency = usec;
1349 }
1350
1351 rdmsrl(MSR_PKGC8_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001352 usec = irtl_2_usec(msr);
1353 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001354 bxt_cstates[4].exit_latency = usec;
1355 bxt_cstates[4].target_residency = usec;
1356 }
1357
1358 rdmsrl(MSR_PKGC9_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001359 usec = irtl_2_usec(msr);
1360 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001361 bxt_cstates[5].exit_latency = usec;
1362 bxt_cstates[5].target_residency = usec;
1363 }
1364
1365 rdmsrl(MSR_PKGC10_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001366 usec = irtl_2_usec(msr);
1367 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001368 bxt_cstates[6].exit_latency = usec;
1369 bxt_cstates[6].target_residency = usec;
1370 }
1371
1372}
Len Brownd70e28f2016-03-13 00:33:48 -05001373/*
1374 * sklh_idle_state_table_update(void)
1375 *
1376 * On SKL-H (model 0x5e) disable C8 and C9 if:
1377 * C10 is enabled and SGX disabled
1378 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001379static void __init sklh_idle_state_table_update(void)
Len Brownd70e28f2016-03-13 00:33:48 -05001380{
1381 unsigned long long msr;
1382 unsigned int eax, ebx, ecx, edx;
1383
1384
1385 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1386 if (max_cstate <= 7)
1387 return;
1388
1389 /* if PC10 not present in CPUID.MWAIT.EDX */
1390 if ((mwait_substates & (0xF << 28)) == 0)
1391 return;
1392
Len Brown6cfb2372017-01-07 23:23:25 -05001393 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr);
Len Brownd70e28f2016-03-13 00:33:48 -05001394
1395 /* PC10 is not enabled in PKG C-state limit */
1396 if ((msr & 0xF) != 8)
1397 return;
1398
1399 ecx = 0;
1400 cpuid(7, &eax, &ebx, &ecx, &edx);
1401
1402 /* if SGX is present */
1403 if (ebx & (1 << 2)) {
1404
Sean Christopherson32ad73d2019-12-20 20:44:55 -08001405 rdmsrl(MSR_IA32_FEAT_CTL, msr);
Len Brownd70e28f2016-03-13 00:33:48 -05001406
1407 /* if SGX is enabled */
1408 if (msr & (1 << 18))
1409 return;
1410 }
1411
Rafael J. Wysockiba1e78a2019-11-21 19:41:51 +01001412 skl_cstates[5].flags |= CPUIDLE_FLAG_UNUSABLE; /* C8-SKL */
1413 skl_cstates[6].flags |= CPUIDLE_FLAG_UNUSABLE; /* C9-SKL */
Len Brownd70e28f2016-03-13 00:33:48 -05001414}
Len Brownd70e28f2016-03-13 00:33:48 -05001415
Rafael J. Wysocki1aefbd72020-01-10 11:52:32 +01001416static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
1417{
1418 unsigned int mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint) + 1;
1419 unsigned int num_substates = (mwait_substates >> mwait_cstate * 4) &
1420 MWAIT_SUBSTATE_MASK;
1421
1422 /* Ignore the C-state if there are NO sub-states in CPUID for it. */
1423 if (num_substates == 0)
1424 return false;
1425
1426 if (mwait_cstate > 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
1427 mark_tsc_unstable("TSC halts in idle states deeper than C2");
1428
1429 return true;
1430}
1431
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001432static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
Len Brown0138d8f2014-04-04 01:21:07 -04001433{
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001434 int cstate;
Len Brown0138d8f2014-04-04 01:21:07 -04001435
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001436 switch (boot_cpu_data.x86_model) {
Dave Hansendb73c5a2016-06-02 17:19:32 -07001437 case INTEL_FAM6_IVYBRIDGE_X:
Len Brownd70e28f2016-03-13 00:33:48 -05001438 ivt_idle_state_table_update();
1439 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001440 case INTEL_FAM6_ATOM_GOLDMONT:
Peter Zijlstraf2c4db12018-08-07 10:17:27 -07001441 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
Len Brown5dcef692016-04-06 17:00:47 -04001442 bxt_idle_state_table_update();
1443 break;
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001444 case INTEL_FAM6_SKYLAKE:
Len Brownd70e28f2016-03-13 00:33:48 -05001445 sklh_idle_state_table_update();
1446 break;
Len Brown0138d8f2014-04-04 01:21:07 -04001447 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301448
Len Browne022e7e2013-02-01 23:37:30 -05001449 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001450 unsigned int mwait_hint;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301451
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001452 if (intel_idle_max_cstate_reached(cstate))
1453 break;
1454
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001455 if (!cpuidle_state_table[cstate].enter &&
1456 !cpuidle_state_table[cstate].enter_s2idle)
Len Browne022e7e2013-02-01 23:37:30 -05001457 break;
1458
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001459 /* If marked as unusable, skip this state. */
Rafael J. Wysockiba1e78a2019-11-21 19:41:51 +01001460 if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_UNUSABLE) {
Joe Perches654d08a2017-06-09 12:29:20 -07001461 pr_debug("state %s is disabled\n",
1462 cpuidle_state_table[cstate].name);
Len Brownd70e28f2016-03-13 00:33:48 -05001463 continue;
1464 }
1465
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001466 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
1467 if (!intel_idle_verify_cstate(mwait_hint))
1468 continue;
Len Brownd70e28f2016-03-13 00:33:48 -05001469
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001470 /* Structure copy. */
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001471 drv->states[drv->state_count] = cpuidle_state_table[cstate];
1472
Rafael J. Wysocki4dcb78e2020-02-03 11:57:18 +01001473 if ((disabled_states_mask & BIT(drv->state_count)) ||
1474 ((icpu->use_acpi || force_use_acpi) &&
1475 intel_idle_off_by_default(mwait_hint) &&
1476 !(cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001477 drv->states[drv->state_count].flags |= CPUIDLE_FLAG_OFF;
1478
1479 drv->state_count++;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301480 }
1481
Len Brown8c058d532014-07-31 15:21:24 -04001482 if (icpu->byt_auto_demotion_disable_flag) {
1483 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
1484 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
1485 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301486}
1487
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001488/*
1489 * intel_idle_cpuidle_driver_init()
1490 * allocate, initialize cpuidle_states
1491 */
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001492static void __init intel_idle_cpuidle_driver_init(struct cpuidle_driver *drv)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001493{
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001494 cpuidle_poll_state_init(drv);
Rafael J. Wysocki4dcb78e2020-02-03 11:57:18 +01001495
1496 if (disabled_states_mask & BIT(0))
1497 drv->states[0].flags |= CPUIDLE_FLAG_OFF;
1498
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001499 drv->state_count = 1;
1500
1501 if (icpu)
1502 intel_idle_init_cstates_icpu(drv);
1503 else
1504 intel_idle_init_cstates_acpi(drv);
1505}
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301506
Rafael J. Wysocki1aefbd72020-01-10 11:52:32 +01001507static void auto_demotion_disable(void)
1508{
1509 unsigned long long msr_bits;
1510
1511 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
1512 msr_bits &= ~(icpu->auto_demotion_disable_flags);
1513 wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
1514}
1515
1516static void c1e_promotion_disable(void)
1517{
1518 unsigned long long msr_bits;
1519
1520 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
1521 msr_bits &= ~0x2;
1522 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
1523}
1524
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301525/*
Thomas Renninger65b7f832012-01-17 22:40:08 +01001526 * intel_idle_cpu_init()
Len Brown26717172010-03-08 14:07:30 -05001527 * allocate, initialize, register cpuidle_devices
Thomas Renninger65b7f832012-01-17 22:40:08 +01001528 * @cpu: cpu/core to initialize
Len Brown26717172010-03-08 14:07:30 -05001529 */
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001530static int intel_idle_cpu_init(unsigned int cpu)
Len Brown26717172010-03-08 14:07:30 -05001531{
Len Brown26717172010-03-08 14:07:30 -05001532 struct cpuidle_device *dev;
1533
Thomas Renninger65b7f832012-01-17 22:40:08 +01001534 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001535 dev->cpu = cpu;
Len Brown26717172010-03-08 14:07:30 -05001536
Thomas Renninger65b7f832012-01-17 22:40:08 +01001537 if (cpuidle_register_device(dev)) {
Joe Perches654d08a2017-06-09 12:29:20 -07001538 pr_debug("cpuidle_register_device %d failed!\n", cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001539 return -EIO;
Len Brown26717172010-03-08 14:07:30 -05001540 }
1541
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001542 if (!icpu)
1543 return 0;
1544
Andi Kleenb66b8b92012-01-26 00:09:07 +01001545 if (icpu->auto_demotion_disable_flags)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001546 auto_demotion_disable();
Thomas Renninger65b7f832012-01-17 22:40:08 +01001547
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001548 if (icpu->disable_promotion_to_c1e)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001549 c1e_promotion_disable();
1550
1551 return 0;
1552}
1553
1554static int intel_idle_cpu_online(unsigned int cpu)
1555{
1556 struct cpuidle_device *dev;
1557
1558 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
Rafael J. Wysockicbd2c4c2020-01-10 11:43:23 +01001559 tick_broadcast_enable();
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001560
1561 /*
1562 * Some systems can hotplug a cpu at runtime after
1563 * the kernel has booted, we have to initialize the
1564 * driver in this case
1565 */
1566 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
1567 if (!dev->registered)
1568 return intel_idle_cpu_init(cpu);
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001569
Len Brown26717172010-03-08 14:07:30 -05001570 return 0;
1571}
Len Brown26717172010-03-08 14:07:30 -05001572
Rafael J. Wysocki0755a9b2020-01-10 11:49:58 +01001573/**
1574 * intel_idle_cpuidle_devices_uninit - Unregister all cpuidle devices.
1575 */
1576static void __init intel_idle_cpuidle_devices_uninit(void)
1577{
1578 int i;
1579
1580 for_each_online_cpu(i)
1581 cpuidle_unregister_device(per_cpu_ptr(intel_idle_cpuidle_devices, i));
1582}
1583
Len Brown26717172010-03-08 14:07:30 -05001584static int __init intel_idle_init(void)
1585{
Rafael J. Wysockia6c86e32020-01-10 11:44:58 +01001586 const struct x86_cpu_id *id;
1587 unsigned int eax, ebx, ecx;
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001588 int retval;
Len Brown26717172010-03-08 14:07:30 -05001589
Thomas Renningerd1896042010-11-03 17:06:14 +01001590 /* Do not load intel_idle at all for now if idle= is passed */
1591 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
1592 return -ENODEV;
1593
Rafael J. Wysockia6c86e32020-01-10 11:44:58 +01001594 if (max_cstate == 0) {
1595 pr_debug("disabled\n");
1596 return -EPERM;
1597 }
1598
1599 id = x86_match_cpu(intel_idle_ids);
1600 if (id) {
1601 if (!boot_cpu_has(X86_FEATURE_MWAIT)) {
1602 pr_debug("Please enable MWAIT in BIOS SETUP\n");
1603 return -ENODEV;
1604 }
1605 } else {
1606 id = x86_match_cpu(intel_mwait_ids);
1607 if (!id)
1608 return -ENODEV;
1609 }
1610
1611 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
1612 return -ENODEV;
1613
1614 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
1615
1616 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
1617 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
1618 !mwait_substates)
1619 return -ENODEV;
1620
1621 pr_debug("MWAIT substates: 0x%x\n", mwait_substates);
1622
1623 icpu = (const struct idle_cpu *)id->driver_data;
1624 if (icpu) {
1625 cpuidle_state_table = icpu->state_table;
Rafael J. Wysocki3a5be9b2020-02-03 11:57:08 +01001626 if (icpu->use_acpi || force_use_acpi)
Rafael J. Wysockia6c86e32020-01-10 11:44:58 +01001627 intel_idle_acpi_cst_extract();
1628 } else if (!intel_idle_acpi_cst_extract()) {
1629 return -ENODEV;
1630 }
1631
1632 pr_debug("v" INTEL_IDLE_VERSION " model 0x%X\n",
1633 boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001634
Richard Cochrane9df69c2016-04-06 17:00:52 -04001635 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
Rafael J. Wysocki533da742020-01-10 11:45:49 +01001636 if (!intel_idle_cpuidle_devices)
Richard Cochrane9df69c2016-04-06 17:00:52 -04001637 return -ENOMEM;
1638
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001639 intel_idle_cpuidle_driver_init(&intel_idle_driver);
1640
Len Brown26717172010-03-08 14:07:30 -05001641 retval = cpuidle_register_driver(&intel_idle_driver);
1642 if (retval) {
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001643 struct cpuidle_driver *drv = cpuidle_get_driver();
Joe Perches654d08a2017-06-09 12:29:20 -07001644 printk(KERN_DEBUG pr_fmt("intel_idle yielding to %s\n"),
1645 drv ? drv->name : "none");
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001646 goto init_driver_fail;
Len Brown26717172010-03-08 14:07:30 -05001647 }
1648
Richard Cochran2259a812016-04-06 17:00:54 -04001649 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
1650 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
Richard Cochran2259a812016-04-06 17:00:54 -04001651
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001652 retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online",
1653 intel_idle_cpu_online, NULL);
1654 if (retval < 0)
1655 goto hp_setup_fail;
Len Brown26717172010-03-08 14:07:30 -05001656
Joe Perches654d08a2017-06-09 12:29:20 -07001657 pr_debug("lapic_timer_reliable_states 0x%x\n",
1658 lapic_timer_reliable_states);
Richard Cochran2259a812016-04-06 17:00:54 -04001659
Len Brown26717172010-03-08 14:07:30 -05001660 return 0;
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001661
1662hp_setup_fail:
1663 intel_idle_cpuidle_devices_uninit();
1664 cpuidle_unregister_driver(&intel_idle_driver);
1665init_driver_fail:
1666 free_percpu(intel_idle_cpuidle_devices);
1667 return retval;
1668
Len Brown26717172010-03-08 14:07:30 -05001669}
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001670device_initcall(intel_idle_init);
Len Brown26717172010-03-08 14:07:30 -05001671
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001672/*
1673 * We are not really modular, but we used to support that. Meaning we also
1674 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
1675 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
1676 * is the easiest way (currently) to continue doing that.
1677 */
Len Brown26717172010-03-08 14:07:30 -05001678module_param(max_cstate, int, 0444);
Rafael J. Wysocki4dcb78e2020-02-03 11:57:18 +01001679/*
1680 * The positions of the bits that are set in this number are the indices of the
1681 * idle states to be disabled by default (as reflected by the names of the
1682 * corresponding idle state directories in sysfs, "state0", "state1" ...
1683 * "state<i>" ..., where <i> is the index of the given state).
1684 */
1685module_param_named(states_off, disabled_states_mask, uint, 0444);
1686MODULE_PARM_DESC(states_off, "Mask of disabled idle states");