blob: 47255d3cf51f717ff3562de78f43502503c4dc4d [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
Len Brown26717172010-03-08 14:07:30 -050044#include <linux/kernel.h>
45#include <linux/cpuidle.h>
Thomas Gleixner76962ca2015-04-03 02:02:34 +020046#include <linux/tick.h>
Len Brown26717172010-03-08 14:07:30 -050047#include <trace/events/power.h>
48#include <linux/sched.h>
Shaohua Li2a2d31c2011-01-10 09:38:12 +080049#include <linux/notifier.h>
50#include <linux/cpu.h>
Paul Gortmaker02c4fae2016-06-17 01:28:33 -040051#include <linux/moduleparam.h>
Andi Kleenb66b8b92012-01-26 00:09:07 +010052#include <asm/cpu_device_id.h>
Dave Hansendb73c5a2016-06-02 17:19:32 -070053#include <asm/intel-family.h>
H. Peter Anvinbc83ccc2010-09-17 15:36:40 -070054#include <asm/mwait.h>
Len Brown14796fc2011-01-18 20:48:27 -050055#include <asm/msr.h>
Len Brown26717172010-03-08 14:07:30 -050056
Len Brownd70e28f2016-03-13 00:33:48 -050057#define INTEL_IDLE_VERSION "0.4.1"
Len Brown26717172010-03-08 14:07:30 -050058
Len Brown26717172010-03-08 14:07:30 -050059static struct cpuidle_driver intel_idle_driver = {
60 .name = "intel_idle",
61 .owner = THIS_MODULE,
62};
63/* intel_idle.max_cstate=0 disables driver */
Len Brown137ecc72013-02-01 21:35:35 -050064static int max_cstate = CPUIDLE_STATE_MAX - 1;
Len Brown26717172010-03-08 14:07:30 -050065
Len Brownc4236282010-05-28 02:22:03 -040066static unsigned int mwait_substates;
Len Brown26717172010-03-08 14:07:30 -050067
Shaohua Li2a2d31c2011-01-10 09:38:12 +080068#define LAPIC_TIMER_ALWAYS_RELIABLE 0xFFFFFFFF
Len Brown26717172010-03-08 14:07:30 -050069/* Reliable LAPIC Timer States, bit 1 for C1 etc. */
Len Brownd13780d2010-07-07 00:12:03 -040070static unsigned int lapic_timer_reliable_states = (1 << 1); /* Default to only C1 */
Len Brown26717172010-03-08 14:07:30 -050071
Andi Kleenb66b8b92012-01-26 00:09:07 +010072struct idle_cpu {
73 struct cpuidle_state *state_table;
74
75 /*
76 * Hardware C-state auto-demotion may not always be optimal.
77 * Indicate which enable bits to clear here.
78 */
79 unsigned long auto_demotion_disable_flags;
Len Brown8c058d532014-07-31 15:21:24 -040080 bool byt_auto_demotion_disable_flag;
Len Brown32e95182013-02-02 01:31:56 -050081 bool disable_promotion_to_c1e;
Andi Kleenb66b8b92012-01-26 00:09:07 +010082};
83
84static const struct idle_cpu *icpu;
Namhyung Kim3265eba2010-08-08 03:10:03 +090085static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +053086static int intel_idle(struct cpuidle_device *dev,
87 struct cpuidle_driver *drv, int index);
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +020088static void intel_idle_s2idle(struct cpuidle_device *dev,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +010089 struct cpuidle_driver *drv, int index);
Len Brown26717172010-03-08 14:07:30 -050090static struct cpuidle_state *cpuidle_state_table;
91
92/*
Len Brown956d0332011-01-12 02:51:20 -050093 * Set this flag for states where the HW flushes the TLB for us
94 * and so we don't need cross-calls to keep it consistent.
95 * If this flag is set, SW flushes the TLB, so even if the
96 * HW doesn't do the flushing, this flag is safe to use.
97 */
98#define CPUIDLE_FLAG_TLB_FLUSHED 0x10000
99
100/*
Len Brownb1beab42013-01-31 19:55:37 -0500101 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
102 * the C-state (top nibble) and sub-state (bottom nibble)
103 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
104 *
105 * We store the hint at the top of our "flags" for each state.
106 */
107#define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
108#define MWAIT2flg(eax) ((eax & 0xFF) << 24)
109
110/*
Len Brown26717172010-03-08 14:07:30 -0500111 * States are indexed by the cstate number,
112 * which is also the index into the MWAIT hint array.
113 * Thus C0 is a dummy.
114 */
Jiang Liuba0dc812014-01-09 15:30:26 +0800115static struct cpuidle_state nehalem_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500116 {
Len Brownde09cdd2017-02-28 16:32:44 -0500117 .name = "C1",
Len Brown26717172010-03-08 14:07:30 -0500118 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100119 .flags = MWAIT2flg(0x00),
Len Brown26717172010-03-08 14:07:30 -0500120 .exit_latency = 3,
Len Brown26717172010-03-08 14:07:30 -0500121 .target_residency = 6,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100122 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200123 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500124 {
Len Brownde09cdd2017-02-28 16:32:44 -0500125 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500126 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100127 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500128 .exit_latency = 10,
129 .target_residency = 20,
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 Brown32e95182013-02-02 01:31:56 -0500132 {
Len Brownde09cdd2017-02-28 16:32:44 -0500133 .name = "C3",
Len Brown26717172010-03-08 14:07:30 -0500134 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100135 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500136 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500137 .target_residency = 80,
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 Browne022e7e2013-02-01 23:37:30 -0500140 {
Len Brownde09cdd2017-02-28 16:32:44 -0500141 .name = "C6",
Len Brown26717172010-03-08 14:07:30 -0500142 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100143 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500144 .exit_latency = 200,
Len Brown26717172010-03-08 14:07:30 -0500145 .target_residency = 800,
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 {
149 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500150};
151
Jiang Liuba0dc812014-01-09 15:30:26 +0800152static struct cpuidle_state snb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500153 {
Len Brownde09cdd2017-02-28 16:32:44 -0500154 .name = "C1",
Len Brownd13780d2010-07-07 00:12:03 -0400155 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100156 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500157 .exit_latency = 2,
158 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100159 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200160 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500161 {
Len Brownde09cdd2017-02-28 16:32:44 -0500162 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500163 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100164 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500165 .exit_latency = 10,
166 .target_residency = 20,
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 Browne022e7e2013-02-01 23:37:30 -0500169 {
Len Brownde09cdd2017-02-28 16:32:44 -0500170 .name = "C3",
Len Brownd13780d2010-07-07 00:12:03 -0400171 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100172 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400173 .exit_latency = 80,
Len Brownddbd5502010-12-13 18:28:22 -0500174 .target_residency = 211,
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 = "C6",
Len Brownd13780d2010-07-07 00:12:03 -0400179 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100180 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400181 .exit_latency = 104,
Len Brownddbd5502010-12-13 18:28:22 -0500182 .target_residency = 345,
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 = "C7",
Len Brownd13780d2010-07-07 00:12:03 -0400187 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100188 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400189 .exit_latency = 109,
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 {
194 .enter = NULL }
Len Brownd13780d2010-07-07 00:12:03 -0400195};
196
Len Brown718987d2014-02-14 02:30:00 -0500197static struct cpuidle_state byt_cstates[] = {
198 {
Len Brownde09cdd2017-02-28 16:32:44 -0500199 .name = "C1",
Len Brown718987d2014-02-14 02:30:00 -0500200 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100201 .flags = MWAIT2flg(0x00),
Len Brown718987d2014-02-14 02:30:00 -0500202 .exit_latency = 1,
203 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100204 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200205 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500206 {
Len Brownde09cdd2017-02-28 16:32:44 -0500207 .name = "C6N",
Len Brown718987d2014-02-14 02:30:00 -0500208 .desc = "MWAIT 0x58",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100209 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400210 .exit_latency = 300,
Len Brown718987d2014-02-14 02:30:00 -0500211 .target_residency = 275,
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 = "C6S",
Len Brown718987d2014-02-14 02:30:00 -0500216 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100217 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400218 .exit_latency = 500,
Len Brown718987d2014-02-14 02:30:00 -0500219 .target_residency = 560,
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 = "C7",
Len Brown718987d2014-02-14 02:30:00 -0500224 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100225 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500226 .exit_latency = 1200,
Len Brownd7ef7672015-03-24 23:23:20 -0400227 .target_residency = 4000,
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 = "C7S",
Len Brown718987d2014-02-14 02:30:00 -0500232 .desc = "MWAIT 0x64",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100233 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500234 .exit_latency = 10000,
235 .target_residency = 20000,
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 {
239 .enter = NULL }
240};
241
Len Browncab07a52015-03-27 20:54:01 -0400242static struct cpuidle_state cht_cstates[] = {
243 {
Len Brownde09cdd2017-02-28 16:32:44 -0500244 .name = "C1",
Len Browncab07a52015-03-27 20:54:01 -0400245 .desc = "MWAIT 0x00",
246 .flags = MWAIT2flg(0x00),
247 .exit_latency = 1,
248 .target_residency = 1,
249 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200250 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400251 {
Len Brownde09cdd2017-02-28 16:32:44 -0500252 .name = "C6N",
Len Browncab07a52015-03-27 20:54:01 -0400253 .desc = "MWAIT 0x58",
254 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
255 .exit_latency = 80,
256 .target_residency = 275,
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 = "C6S",
Len Browncab07a52015-03-27 20:54:01 -0400261 .desc = "MWAIT 0x52",
262 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
263 .exit_latency = 200,
264 .target_residency = 560,
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 = "C7",
Len Browncab07a52015-03-27 20:54:01 -0400269 .desc = "MWAIT 0x60",
270 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
271 .exit_latency = 1200,
272 .target_residency = 4000,
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 = "C7S",
Len Browncab07a52015-03-27 20:54:01 -0400277 .desc = "MWAIT 0x64",
278 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
279 .exit_latency = 10000,
280 .target_residency = 20000,
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 {
284 .enter = NULL }
285};
286
Jiang Liuba0dc812014-01-09 15:30:26 +0800287static struct cpuidle_state ivb_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500288 {
Len Brownde09cdd2017-02-28 16:32:44 -0500289 .name = "C1",
Len Brown6edab082012-06-01 19:45:32 -0400290 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100291 .flags = MWAIT2flg(0x00),
Len Brown6edab082012-06-01 19:45:32 -0400292 .exit_latency = 1,
293 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100294 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200295 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500296 {
Len Brownde09cdd2017-02-28 16:32:44 -0500297 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500298 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100299 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500300 .exit_latency = 10,
301 .target_residency = 20,
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 Brown32e95182013-02-02 01:31:56 -0500304 {
Len Brownde09cdd2017-02-28 16:32:44 -0500305 .name = "C3",
Len Brown6edab082012-06-01 19:45:32 -0400306 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100307 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400308 .exit_latency = 59,
309 .target_residency = 156,
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 Browne022e7e2013-02-01 23:37:30 -0500312 {
Len Brownde09cdd2017-02-28 16:32:44 -0500313 .name = "C6",
Len Brown6edab082012-06-01 19:45:32 -0400314 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100315 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400316 .exit_latency = 80,
317 .target_residency = 300,
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 = "C7",
Len Brown6edab082012-06-01 19:45:32 -0400322 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100323 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400324 .exit_latency = 87,
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 {
329 .enter = NULL }
Len Brown6edab082012-06-01 19:45:32 -0400330};
331
Len Brown0138d8f2014-04-04 01:21:07 -0400332static struct cpuidle_state ivt_cstates[] = {
333 {
Len Brownde09cdd2017-02-28 16:32:44 -0500334 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400335 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100336 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400337 .exit_latency = 1,
338 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100339 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200340 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400341 {
Len Brownde09cdd2017-02-28 16:32:44 -0500342 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400343 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100344 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400345 .exit_latency = 10,
346 .target_residency = 80,
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 = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400351 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100352 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400353 .exit_latency = 59,
354 .target_residency = 156,
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 = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400359 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100360 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400361 .exit_latency = 82,
362 .target_residency = 300,
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 {
366 .enter = NULL }
367};
368
369static struct cpuidle_state ivt_cstates_4s[] = {
370 {
Len Brownde09cdd2017-02-28 16:32:44 -0500371 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400372 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100373 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400374 .exit_latency = 1,
375 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100376 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200377 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400378 {
Len Brownde09cdd2017-02-28 16:32:44 -0500379 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400380 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100381 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400382 .exit_latency = 10,
383 .target_residency = 250,
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 = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400388 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100389 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400390 .exit_latency = 59,
391 .target_residency = 300,
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 = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400396 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100397 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400398 .exit_latency = 84,
399 .target_residency = 400,
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 {
403 .enter = NULL }
404};
405
406static struct cpuidle_state ivt_cstates_8s[] = {
407 {
Len Brownde09cdd2017-02-28 16:32:44 -0500408 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400409 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100410 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400411 .exit_latency = 1,
412 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100413 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200414 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400415 {
Len Brownde09cdd2017-02-28 16:32:44 -0500416 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400417 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100418 .flags = MWAIT2flg(0x01),
Len Brown0138d8f2014-04-04 01:21:07 -0400419 .exit_latency = 10,
420 .target_residency = 500,
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 = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400425 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100426 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400427 .exit_latency = 59,
428 .target_residency = 600,
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 = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400433 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100434 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400435 .exit_latency = 88,
436 .target_residency = 700,
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 {
440 .enter = NULL }
441};
442
Jiang Liuba0dc812014-01-09 15:30:26 +0800443static struct cpuidle_state hsw_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500444 {
Len Brownde09cdd2017-02-28 16:32:44 -0500445 .name = "C1",
Len Brown85a4d2d2013-01-31 14:40:49 -0500446 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100447 .flags = MWAIT2flg(0x00),
Len Brown85a4d2d2013-01-31 14:40:49 -0500448 .exit_latency = 2,
449 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100450 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200451 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500452 {
Len Brownde09cdd2017-02-28 16:32:44 -0500453 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500454 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100455 .flags = MWAIT2flg(0x01),
Len Brown32e95182013-02-02 01:31:56 -0500456 .exit_latency = 10,
457 .target_residency = 20,
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 Brown32e95182013-02-02 01:31:56 -0500460 {
Len Brownde09cdd2017-02-28 16:32:44 -0500461 .name = "C3",
Len Brown85a4d2d2013-01-31 14:40:49 -0500462 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100463 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500464 .exit_latency = 33,
465 .target_residency = 100,
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 Browne022e7e2013-02-01 23:37:30 -0500468 {
Len Brownde09cdd2017-02-28 16:32:44 -0500469 .name = "C6",
Len Brown85a4d2d2013-01-31 14:40:49 -0500470 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100471 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500472 .exit_latency = 133,
473 .target_residency = 400,
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 = "C7s",
Len Brown85a4d2d2013-01-31 14:40:49 -0500478 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100479 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500480 .exit_latency = 166,
481 .target_residency = 500,
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 = "C8",
Len Brown86239ce2013-02-27 13:18:50 -0500486 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100487 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500488 .exit_latency = 300,
489 .target_residency = 900,
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 Brown86239ce2013-02-27 13:18:50 -0500492 {
Len Brownde09cdd2017-02-28 16:32:44 -0500493 .name = "C9",
Len Brown86239ce2013-02-27 13:18:50 -0500494 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100495 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500496 .exit_latency = 600,
497 .target_residency = 1800,
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 = "C10",
Len Brown86239ce2013-02-27 13:18:50 -0500502 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100503 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500504 .exit_latency = 2600,
505 .target_residency = 7700,
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 Browne022e7e2013-02-01 23:37:30 -0500509 .enter = NULL }
Len Brown85a4d2d2013-01-31 14:40:49 -0500510};
Len Browna138b562014-02-04 23:56:40 -0500511static struct cpuidle_state bdw_cstates[] = {
512 {
Len Brownde09cdd2017-02-28 16:32:44 -0500513 .name = "C1",
Len Browna138b562014-02-04 23:56:40 -0500514 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100515 .flags = MWAIT2flg(0x00),
Len Browna138b562014-02-04 23:56:40 -0500516 .exit_latency = 2,
517 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100518 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200519 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500520 {
Len Brownde09cdd2017-02-28 16:32:44 -0500521 .name = "C1E",
Len Browna138b562014-02-04 23:56:40 -0500522 .desc = "MWAIT 0x01",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100523 .flags = MWAIT2flg(0x01),
Len Browna138b562014-02-04 23:56:40 -0500524 .exit_latency = 10,
525 .target_residency = 20,
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 = "C3",
Len Browna138b562014-02-04 23:56:40 -0500530 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100531 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500532 .exit_latency = 40,
533 .target_residency = 100,
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 = "C6",
Len Browna138b562014-02-04 23:56:40 -0500538 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100539 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500540 .exit_latency = 133,
541 .target_residency = 400,
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 = "C7s",
Len Browna138b562014-02-04 23:56:40 -0500546 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100547 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500548 .exit_latency = 166,
549 .target_residency = 500,
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 = "C8",
Len Browna138b562014-02-04 23:56:40 -0500554 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100555 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500556 .exit_latency = 300,
557 .target_residency = 900,
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 = "C9",
Len Browna138b562014-02-04 23:56:40 -0500562 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100563 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500564 .exit_latency = 600,
565 .target_residency = 1800,
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 = "C10",
Len Browna138b562014-02-04 23:56:40 -0500570 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100571 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500572 .exit_latency = 2600,
573 .target_residency = 7700,
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 {
577 .enter = NULL }
578};
Len Brown85a4d2d2013-01-31 14:40:49 -0500579
Len Brown493f1332015-03-25 23:20:37 -0400580static struct cpuidle_state skl_cstates[] = {
581 {
Len Brownde09cdd2017-02-28 16:32:44 -0500582 .name = "C1",
Len Brown493f1332015-03-25 23:20:37 -0400583 .desc = "MWAIT 0x00",
584 .flags = MWAIT2flg(0x00),
585 .exit_latency = 2,
586 .target_residency = 2,
587 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200588 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400589 {
Len Brownde09cdd2017-02-28 16:32:44 -0500590 .name = "C1E",
Len Brown493f1332015-03-25 23:20:37 -0400591 .desc = "MWAIT 0x01",
592 .flags = MWAIT2flg(0x01),
593 .exit_latency = 10,
594 .target_residency = 20,
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 = "C3",
Len Brown493f1332015-03-25 23:20:37 -0400599 .desc = "MWAIT 0x10",
600 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
601 .exit_latency = 70,
602 .target_residency = 100,
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 = "C6",
Len Brown493f1332015-03-25 23:20:37 -0400607 .desc = "MWAIT 0x20",
608 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400609 .exit_latency = 85,
Len Brown493f1332015-03-25 23:20:37 -0400610 .target_residency = 200,
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 = "C7s",
Len Brown493f1332015-03-25 23:20:37 -0400615 .desc = "MWAIT 0x33",
616 .flags = MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED,
617 .exit_latency = 124,
618 .target_residency = 800,
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 = "C8",
Len Brown493f1332015-03-25 23:20:37 -0400623 .desc = "MWAIT 0x40",
624 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400625 .exit_latency = 200,
Len Brown493f1332015-03-25 23:20:37 -0400626 .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 = "C9",
Len Brown135919a2015-09-09 13:35:05 -0400631 .desc = "MWAIT 0x50",
632 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
633 .exit_latency = 480,
634 .target_residency = 5000,
635 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200636 .enter_s2idle = intel_idle_s2idle, },
Len Brown135919a2015-09-09 13:35:05 -0400637 {
Len Brownde09cdd2017-02-28 16:32:44 -0500638 .name = "C10",
Len Brown493f1332015-03-25 23:20:37 -0400639 .desc = "MWAIT 0x60",
640 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
641 .exit_latency = 890,
642 .target_residency = 5000,
643 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200644 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400645 {
646 .enter = NULL }
647};
648
Len Brownf9e71652016-04-06 17:00:58 -0400649static struct cpuidle_state skx_cstates[] = {
650 {
Len Brownde09cdd2017-02-28 16:32:44 -0500651 .name = "C1",
Len Brownf9e71652016-04-06 17:00:58 -0400652 .desc = "MWAIT 0x00",
653 .flags = MWAIT2flg(0x00),
654 .exit_latency = 2,
655 .target_residency = 2,
656 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200657 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400658 {
Len Brownde09cdd2017-02-28 16:32:44 -0500659 .name = "C1E",
Len Brownf9e71652016-04-06 17:00:58 -0400660 .desc = "MWAIT 0x01",
661 .flags = MWAIT2flg(0x01),
662 .exit_latency = 10,
663 .target_residency = 20,
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 = "C6",
Len Brownf9e71652016-04-06 17:00:58 -0400668 .desc = "MWAIT 0x20",
669 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
670 .exit_latency = 133,
671 .target_residency = 600,
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 {
675 .enter = NULL }
676};
677
Jiang Liuba0dc812014-01-09 15:30:26 +0800678static struct cpuidle_state atom_cstates[] = {
Len Browne022e7e2013-02-01 23:37:30 -0500679 {
Len Brownde09cdd2017-02-28 16:32:44 -0500680 .name = "C1E",
Len Brown26717172010-03-08 14:07:30 -0500681 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100682 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500683 .exit_latency = 10,
684 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100685 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200686 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500687 {
Len Brownde09cdd2017-02-28 16:32:44 -0500688 .name = "C2",
Len Brown26717172010-03-08 14:07:30 -0500689 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100690 .flags = MWAIT2flg(0x10),
Len Brown26717172010-03-08 14:07:30 -0500691 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500692 .target_residency = 80,
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 = "C4",
Len Brown26717172010-03-08 14:07:30 -0500697 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100698 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500699 .exit_latency = 100,
Len Brown26717172010-03-08 14:07:30 -0500700 .target_residency = 400,
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 = "C6",
Len Brown7fcca7d2010-10-05 13:43:14 -0400705 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100706 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown7fcca7d2010-10-05 13:43:14 -0400707 .exit_latency = 140,
Len Brown7fcca7d2010-10-05 13:43:14 -0400708 .target_residency = 560,
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 {
712 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500713};
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300714static struct cpuidle_state tangier_cstates[] = {
715 {
Len Brownde09cdd2017-02-28 16:32:44 -0500716 .name = "C1",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300717 .desc = "MWAIT 0x00",
718 .flags = MWAIT2flg(0x00),
719 .exit_latency = 1,
720 .target_residency = 4,
721 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200722 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300723 {
Len Brownde09cdd2017-02-28 16:32:44 -0500724 .name = "C4",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300725 .desc = "MWAIT 0x30",
726 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
727 .exit_latency = 100,
728 .target_residency = 400,
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 = "C6",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300733 .desc = "MWAIT 0x52",
734 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
735 .exit_latency = 140,
736 .target_residency = 560,
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 = "C7",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300741 .desc = "MWAIT 0x60",
742 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
743 .exit_latency = 1200,
744 .target_residency = 4000,
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 = "C9",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300749 .desc = "MWAIT 0x64",
750 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
751 .exit_latency = 10000,
752 .target_residency = 20000,
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 {
756 .enter = NULL }
757};
Jiang Liu88390992014-01-09 15:30:27 +0800758static struct cpuidle_state avn_cstates[] = {
Len Brownfab04b22013-11-09 00:30:17 -0500759 {
Len Brownde09cdd2017-02-28 16:32:44 -0500760 .name = "C1",
Len Brownfab04b22013-11-09 00:30:17 -0500761 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100762 .flags = MWAIT2flg(0x00),
Len Brownfab04b22013-11-09 00:30:17 -0500763 .exit_latency = 2,
764 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100765 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200766 .enter_s2idle = intel_idle_s2idle, },
Len Brownfab04b22013-11-09 00:30:17 -0500767 {
Len Brownde09cdd2017-02-28 16:32:44 -0500768 .name = "C6",
Len Brownfab04b22013-11-09 00:30:17 -0500769 .desc = "MWAIT 0x51",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100770 .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownfab04b22013-11-09 00:30:17 -0500771 .exit_latency = 15,
772 .target_residency = 45,
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, },
Jiang Liu88390992014-01-09 15:30:27 +0800775 {
776 .enter = NULL }
Len Brownfab04b22013-11-09 00:30:17 -0500777};
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700778static struct cpuidle_state knl_cstates[] = {
779 {
Len Brownde09cdd2017-02-28 16:32:44 -0500780 .name = "C1",
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700781 .desc = "MWAIT 0x00",
782 .flags = MWAIT2flg(0x00),
783 .exit_latency = 1,
784 .target_residency = 2,
785 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200786 .enter_s2idle = intel_idle_s2idle },
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700787 {
Len Brownde09cdd2017-02-28 16:32:44 -0500788 .name = "C6",
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700789 .desc = "MWAIT 0x10",
790 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
791 .exit_latency = 120,
792 .target_residency = 500,
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 {
796 .enter = NULL }
797};
Len Brown26717172010-03-08 14:07:30 -0500798
Len Brown5dcef692016-04-06 17:00:47 -0400799static struct cpuidle_state bxt_cstates[] = {
800 {
Len Brownde09cdd2017-02-28 16:32:44 -0500801 .name = "C1",
Len Brown5dcef692016-04-06 17:00:47 -0400802 .desc = "MWAIT 0x00",
803 .flags = MWAIT2flg(0x00),
804 .exit_latency = 2,
805 .target_residency = 2,
806 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200807 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400808 {
Len Brownde09cdd2017-02-28 16:32:44 -0500809 .name = "C1E",
Len Brown5dcef692016-04-06 17:00:47 -0400810 .desc = "MWAIT 0x01",
811 .flags = MWAIT2flg(0x01),
812 .exit_latency = 10,
813 .target_residency = 20,
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 = "C6",
Len Brown5dcef692016-04-06 17:00:47 -0400818 .desc = "MWAIT 0x20",
819 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
820 .exit_latency = 133,
821 .target_residency = 133,
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 = "C7s",
Len Brown5dcef692016-04-06 17:00:47 -0400826 .desc = "MWAIT 0x31",
827 .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
828 .exit_latency = 155,
829 .target_residency = 155,
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 = "C8",
Len Brown5dcef692016-04-06 17:00:47 -0400834 .desc = "MWAIT 0x40",
835 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
836 .exit_latency = 1000,
837 .target_residency = 1000,
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 = "C9",
Len Brown5dcef692016-04-06 17:00:47 -0400842 .desc = "MWAIT 0x50",
843 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
844 .exit_latency = 2000,
845 .target_residency = 2000,
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 = "C10",
Len Brown5dcef692016-04-06 17:00:47 -0400850 .desc = "MWAIT 0x60",
851 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
852 .exit_latency = 10000,
853 .target_residency = 10000,
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 {
857 .enter = NULL }
858};
859
Jacob Pan0080d652016-06-17 01:28:34 -0400860static struct cpuidle_state dnv_cstates[] = {
861 {
Len Brownde09cdd2017-02-28 16:32:44 -0500862 .name = "C1",
Jacob Pan0080d652016-06-17 01:28:34 -0400863 .desc = "MWAIT 0x00",
864 .flags = MWAIT2flg(0x00),
865 .exit_latency = 2,
866 .target_residency = 2,
867 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200868 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400869 {
Len Brownde09cdd2017-02-28 16:32:44 -0500870 .name = "C1E",
Jacob Pan0080d652016-06-17 01:28:34 -0400871 .desc = "MWAIT 0x01",
872 .flags = MWAIT2flg(0x01),
873 .exit_latency = 10,
874 .target_residency = 20,
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 = "C6",
Jacob Pan0080d652016-06-17 01:28:34 -0400879 .desc = "MWAIT 0x20",
880 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
881 .exit_latency = 50,
882 .target_residency = 500,
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 {
886 .enter = NULL }
887};
888
Len Brown26717172010-03-08 14:07:30 -0500889/**
890 * intel_idle
891 * @dev: cpuidle_device
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530892 * @drv: cpuidle driver
Deepthi Dharware978aa72011-10-28 16:20:09 +0530893 * @index: index of cpuidle state
Len Brown26717172010-03-08 14:07:30 -0500894 *
Yanmin Zhang63ff07b2012-01-10 15:48:21 -0800895 * Must be called under local_irq_disable().
Len Brown26717172010-03-08 14:07:30 -0500896 */
Chris Metcalf6727ad92016-10-07 17:02:55 -0700897static __cpuidle int intel_idle(struct cpuidle_device *dev,
898 struct cpuidle_driver *drv, int index)
Len Brown26717172010-03-08 14:07:30 -0500899{
900 unsigned long ecx = 1; /* break on interrupt flag */
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +0530901 struct cpuidle_state *state = &drv->states[index];
Len Brownb1beab42013-01-31 19:55:37 -0500902 unsigned long eax = flg2MWAIT(state->flags);
Len Brown26717172010-03-08 14:07:30 -0500903 unsigned int cstate;
Jason Baron0563bb72017-10-06 13:19:45 -0400904 bool uninitialized_var(tick);
Andy Lutomirski67535732017-11-04 04:16:12 -0700905 int cpu = smp_processor_id();
Len Brown26717172010-03-08 14:07:30 -0500906
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400907 /*
Andy Lutomirski67535732017-11-04 04:16:12 -0700908 * leave_mm() to avoid costly and often unnecessary wakeups
909 * for flushing the user TLB's associated with the active mm.
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400910 */
Andy Lutomirski67535732017-11-04 04:16:12 -0700911 if (state->flags & CPUIDLE_FLAG_TLB_FLUSHED)
912 leave_mm(cpu);
Suresh Siddha6110a1f2010-09-30 21:19:07 -0400913
Jason Baron0563bb72017-10-06 13:19:45 -0400914 if (!static_cpu_has(X86_FEATURE_ARAT)) {
915 cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
916 MWAIT_CSTATE_MASK) + 1;
917 tick = false;
918 if (!(lapic_timer_reliable_states & (1 << (cstate)))) {
919 tick = true;
920 tick_broadcast_enter();
921 }
922 }
Len Brown26717172010-03-08 14:07:30 -0500923
Peter Zijlstra16824252013-12-12 15:08:36 +0100924 mwait_idle_with_hints(eax, ecx);
Len Brown26717172010-03-08 14:07:30 -0500925
Jason Baron0563bb72017-10-06 13:19:45 -0400926 if (!static_cpu_has(X86_FEATURE_ARAT) && tick)
Thomas Gleixnerf6cee192015-04-03 02:14:23 +0200927 tick_broadcast_exit();
Len Brown26717172010-03-08 14:07:30 -0500928
Deepthi Dharware978aa72011-10-28 16:20:09 +0530929 return index;
Len Brown26717172010-03-08 14:07:30 -0500930}
931
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100932/**
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200933 * intel_idle_s2idle - simplified "enter" callback routine for suspend-to-idle
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100934 * @dev: cpuidle_device
935 * @drv: cpuidle driver
936 * @index: state index
937 */
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200938static void intel_idle_s2idle(struct cpuidle_device *dev,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100939 struct cpuidle_driver *drv, int index)
940{
941 unsigned long ecx = 1; /* break on interrupt flag */
942 unsigned long eax = flg2MWAIT(drv->states[index].flags);
943
944 mwait_idle_with_hints(eax, ecx);
945}
946
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +0100947static bool intel_idle_verify_cstate(unsigned int mwait_hint)
948{
949 unsigned int mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint) + 1;
950 unsigned int num_substates = (mwait_substates >> mwait_cstate * 4) &
951 MWAIT_SUBSTATE_MASK;
952
953 /* Ignore the C-state if there are NO sub-states in CPUID for it. */
954 if (num_substates == 0)
955 return false;
956
957 if (mwait_cstate > 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
958 mark_tsc_unstable("TSC halts in idle states deeper than C2");
959
960 return true;
961}
962
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +0100963static void __setup_broadcast_timer(bool on)
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800964{
Thomas Gleixner76962ca2015-04-03 02:02:34 +0200965 if (on)
966 tick_broadcast_enable();
967 else
968 tick_broadcast_disable();
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800969}
970
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +0100971static void auto_demotion_disable(void)
Len Brown14796fc2011-01-18 20:48:27 -0500972{
973 unsigned long long msr_bits;
974
Len Brown6cfb2372017-01-07 23:23:25 -0500975 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
Andi Kleenb66b8b92012-01-26 00:09:07 +0100976 msr_bits &= ~(icpu->auto_demotion_disable_flags);
Len Brown6cfb2372017-01-07 23:23:25 -0500977 wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
Len Brown14796fc2011-01-18 20:48:27 -0500978}
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +0100979static void c1e_promotion_disable(void)
Len Brown32e95182013-02-02 01:31:56 -0500980{
981 unsigned long long msr_bits;
982
983 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
984 msr_bits &= ~0x2;
985 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
986}
Len Brown14796fc2011-01-18 20:48:27 -0500987
Andi Kleenb66b8b92012-01-26 00:09:07 +0100988static const struct idle_cpu idle_cpu_nehalem = {
989 .state_table = nehalem_cstates,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100990 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
Len Brown32e95182013-02-02 01:31:56 -0500991 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100992};
993
994static const struct idle_cpu idle_cpu_atom = {
995 .state_table = atom_cstates,
996};
997
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300998static const struct idle_cpu idle_cpu_tangier = {
999 .state_table = tangier_cstates,
1000};
1001
Andi Kleenb66b8b92012-01-26 00:09:07 +01001002static const struct idle_cpu idle_cpu_lincroft = {
1003 .state_table = atom_cstates,
1004 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
1005};
1006
1007static const struct idle_cpu idle_cpu_snb = {
1008 .state_table = snb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001009 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +01001010};
1011
Len Brown718987d2014-02-14 02:30:00 -05001012static const struct idle_cpu idle_cpu_byt = {
1013 .state_table = byt_cstates,
1014 .disable_promotion_to_c1e = true,
Len Brown8c058d532014-07-31 15:21:24 -04001015 .byt_auto_demotion_disable_flag = true,
Len Brown718987d2014-02-14 02:30:00 -05001016};
1017
Len Browncab07a52015-03-27 20:54:01 -04001018static const struct idle_cpu idle_cpu_cht = {
1019 .state_table = cht_cstates,
1020 .disable_promotion_to_c1e = true,
1021 .byt_auto_demotion_disable_flag = true,
1022};
1023
Len Brown6edab082012-06-01 19:45:32 -04001024static const struct idle_cpu idle_cpu_ivb = {
1025 .state_table = ivb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001026 .disable_promotion_to_c1e = true,
Len Brown6edab082012-06-01 19:45:32 -04001027};
1028
Len Brown0138d8f2014-04-04 01:21:07 -04001029static const struct idle_cpu idle_cpu_ivt = {
1030 .state_table = ivt_cstates,
1031 .disable_promotion_to_c1e = true,
1032};
1033
Len Brown85a4d2d2013-01-31 14:40:49 -05001034static const struct idle_cpu idle_cpu_hsw = {
1035 .state_table = hsw_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001036 .disable_promotion_to_c1e = true,
Len Brown85a4d2d2013-01-31 14:40:49 -05001037};
1038
Len Browna138b562014-02-04 23:56:40 -05001039static const struct idle_cpu idle_cpu_bdw = {
1040 .state_table = bdw_cstates,
1041 .disable_promotion_to_c1e = true,
1042};
1043
Len Brown493f1332015-03-25 23:20:37 -04001044static const struct idle_cpu idle_cpu_skl = {
1045 .state_table = skl_cstates,
1046 .disable_promotion_to_c1e = true,
1047};
1048
Len Brownf9e71652016-04-06 17:00:58 -04001049static const struct idle_cpu idle_cpu_skx = {
1050 .state_table = skx_cstates,
1051 .disable_promotion_to_c1e = true,
1052};
Len Brown493f1332015-03-25 23:20:37 -04001053
Len Brownfab04b22013-11-09 00:30:17 -05001054static const struct idle_cpu idle_cpu_avn = {
1055 .state_table = avn_cstates,
1056 .disable_promotion_to_c1e = true,
1057};
1058
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001059static const struct idle_cpu idle_cpu_knl = {
1060 .state_table = knl_cstates,
1061};
1062
Len Brown5dcef692016-04-06 17:00:47 -04001063static const struct idle_cpu idle_cpu_bxt = {
1064 .state_table = bxt_cstates,
1065 .disable_promotion_to_c1e = true,
1066};
1067
Jacob Pan0080d652016-06-17 01:28:34 -04001068static const struct idle_cpu idle_cpu_dnv = {
1069 .state_table = dnv_cstates,
1070 .disable_promotion_to_c1e = true,
1071};
1072
Mathias Kraused5cdc3c2015-03-25 22:15:14 +01001073static const struct x86_cpu_id intel_idle_ids[] __initconst = {
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001074 INTEL_CPU_FAM6(NEHALEM_EP, idle_cpu_nehalem),
1075 INTEL_CPU_FAM6(NEHALEM, idle_cpu_nehalem),
1076 INTEL_CPU_FAM6(NEHALEM_G, idle_cpu_nehalem),
1077 INTEL_CPU_FAM6(WESTMERE, idle_cpu_nehalem),
1078 INTEL_CPU_FAM6(WESTMERE_EP, idle_cpu_nehalem),
1079 INTEL_CPU_FAM6(NEHALEM_EX, idle_cpu_nehalem),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001080 INTEL_CPU_FAM6(ATOM_BONNELL, idle_cpu_atom),
1081 INTEL_CPU_FAM6(ATOM_BONNELL_MID, idle_cpu_lincroft),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001082 INTEL_CPU_FAM6(WESTMERE_EX, idle_cpu_nehalem),
1083 INTEL_CPU_FAM6(SANDYBRIDGE, idle_cpu_snb),
1084 INTEL_CPU_FAM6(SANDYBRIDGE_X, idle_cpu_snb),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001085 INTEL_CPU_FAM6(ATOM_SALTWELL, idle_cpu_atom),
1086 INTEL_CPU_FAM6(ATOM_SILVERMONT, idle_cpu_byt),
1087 INTEL_CPU_FAM6(ATOM_SILVERMONT_MID, idle_cpu_tangier),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001088 INTEL_CPU_FAM6(ATOM_AIRMONT, idle_cpu_cht),
1089 INTEL_CPU_FAM6(IVYBRIDGE, idle_cpu_ivb),
1090 INTEL_CPU_FAM6(IVYBRIDGE_X, idle_cpu_ivt),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001091 INTEL_CPU_FAM6(HASWELL, idle_cpu_hsw),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001092 INTEL_CPU_FAM6(HASWELL_X, idle_cpu_hsw),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001093 INTEL_CPU_FAM6(HASWELL_L, idle_cpu_hsw),
Peter Zijlstra5e741402019-08-27 21:48:23 +02001094 INTEL_CPU_FAM6(HASWELL_G, idle_cpu_hsw),
Peter Zijlstra5ebb34e2019-08-27 21:48:24 +02001095 INTEL_CPU_FAM6(ATOM_SILVERMONT_D, idle_cpu_avn),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001096 INTEL_CPU_FAM6(BROADWELL, idle_cpu_bdw),
Peter Zijlstra5e741402019-08-27 21:48:23 +02001097 INTEL_CPU_FAM6(BROADWELL_G, idle_cpu_bdw),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001098 INTEL_CPU_FAM6(BROADWELL_X, idle_cpu_bdw),
Peter Zijlstra5ebb34e2019-08-27 21:48:24 +02001099 INTEL_CPU_FAM6(BROADWELL_D, idle_cpu_bdw),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001100 INTEL_CPU_FAM6(SKYLAKE_L, idle_cpu_skl),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001101 INTEL_CPU_FAM6(SKYLAKE, idle_cpu_skl),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001102 INTEL_CPU_FAM6(KABYLAKE_L, idle_cpu_skl),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001103 INTEL_CPU_FAM6(KABYLAKE, idle_cpu_skl),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001104 INTEL_CPU_FAM6(SKYLAKE_X, idle_cpu_skx),
1105 INTEL_CPU_FAM6(XEON_PHI_KNL, idle_cpu_knl),
1106 INTEL_CPU_FAM6(XEON_PHI_KNM, idle_cpu_knl),
1107 INTEL_CPU_FAM6(ATOM_GOLDMONT, idle_cpu_bxt),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001108 INTEL_CPU_FAM6(ATOM_GOLDMONT_PLUS, idle_cpu_bxt),
Peter Zijlstra5ebb34e2019-08-27 21:48:24 +02001109 INTEL_CPU_FAM6(ATOM_GOLDMONT_D, idle_cpu_dnv),
1110 INTEL_CPU_FAM6(ATOM_TREMONT_D, idle_cpu_dnv),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001111 {}
1112};
Andi Kleenb66b8b92012-01-26 00:09:07 +01001113
Len Brown26717172010-03-08 14:07:30 -05001114/*
1115 * intel_idle_probe()
1116 */
Bartlomiej Zolnierkiewicz00f3e752013-08-30 12:27:45 +02001117static int __init intel_idle_probe(void)
Len Brown26717172010-03-08 14:07:30 -05001118{
Len Brownc4236282010-05-28 02:22:03 -04001119 unsigned int eax, ebx, ecx;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001120 const struct x86_cpu_id *id;
Len Brown26717172010-03-08 14:07:30 -05001121
1122 if (max_cstate == 0) {
Joe Perches654d08a2017-06-09 12:29:20 -07001123 pr_debug("disabled\n");
Len Brown26717172010-03-08 14:07:30 -05001124 return -EPERM;
1125 }
1126
Andi Kleenb66b8b92012-01-26 00:09:07 +01001127 id = x86_match_cpu(intel_idle_ids);
1128 if (!id) {
1129 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
1130 boot_cpu_data.x86 == 6)
Joe Perches654d08a2017-06-09 12:29:20 -07001131 pr_debug("does not run on family %d model %d\n",
1132 boot_cpu_data.x86, boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001133 return -ENODEV;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001134 }
Len Brown26717172010-03-08 14:07:30 -05001135
Len Browna4c44752017-11-09 02:19:39 -05001136 if (!boot_cpu_has(X86_FEATURE_MWAIT)) {
1137 pr_debug("Please enable MWAIT in BIOS SETUP\n");
1138 return -ENODEV;
1139 }
1140
Len Brown26717172010-03-08 14:07:30 -05001141 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
1142 return -ENODEV;
1143
Len Brownc4236282010-05-28 02:22:03 -04001144 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001145
1146 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
Thomas Renninger5c2a9f02011-12-04 22:17:29 +01001147 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
1148 !mwait_substates)
Len Brown26717172010-03-08 14:07:30 -05001149 return -ENODEV;
Len Brown26717172010-03-08 14:07:30 -05001150
Joe Perches654d08a2017-06-09 12:29:20 -07001151 pr_debug("MWAIT substates: 0x%x\n", mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001152
Andi Kleenb66b8b92012-01-26 00:09:07 +01001153 icpu = (const struct idle_cpu *)id->driver_data;
1154 cpuidle_state_table = icpu->state_table;
Len Brown26717172010-03-08 14:07:30 -05001155
Joe Perches654d08a2017-06-09 12:29:20 -07001156 pr_debug("v" INTEL_IDLE_VERSION " model 0x%X\n",
1157 boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001158
Len Brown26717172010-03-08 14:07:30 -05001159 return 0;
1160}
1161
1162/*
1163 * intel_idle_cpuidle_devices_uninit()
Richard Cochranca424892016-04-06 17:00:53 -04001164 * Unregisters the cpuidle devices.
Len Brown26717172010-03-08 14:07:30 -05001165 */
1166static void intel_idle_cpuidle_devices_uninit(void)
1167{
1168 int i;
1169 struct cpuidle_device *dev;
1170
1171 for_each_online_cpu(i) {
1172 dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
1173 cpuidle_unregister_device(dev);
1174 }
Len Brown26717172010-03-08 14:07:30 -05001175}
Len Brown0138d8f2014-04-04 01:21:07 -04001176
1177/*
Len Brownd70e28f2016-03-13 00:33:48 -05001178 * ivt_idle_state_table_update(void)
1179 *
1180 * Tune IVT multi-socket targets
1181 * Assumption: num_sockets == (max_package_num + 1)
1182 */
1183static void ivt_idle_state_table_update(void)
1184{
1185 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1186 int cpu, package_num, num_sockets = 1;
1187
1188 for_each_online_cpu(cpu) {
1189 package_num = topology_physical_package_id(cpu);
1190 if (package_num + 1 > num_sockets) {
1191 num_sockets = package_num + 1;
1192
1193 if (num_sockets > 4) {
1194 cpuidle_state_table = ivt_cstates_8s;
1195 return;
1196 }
1197 }
1198 }
1199
1200 if (num_sockets > 2)
1201 cpuidle_state_table = ivt_cstates_4s;
1202
1203 /* else, 1 and 2 socket systems use default ivt_cstates */
1204}
Len Brown5dcef692016-04-06 17:00:47 -04001205
1206/*
1207 * Translate IRTL (Interrupt Response Time Limit) MSR to usec
1208 */
1209
1210static unsigned int irtl_ns_units[] = {
1211 1, 32, 1024, 32768, 1048576, 33554432, 0, 0 };
1212
1213static unsigned long long irtl_2_usec(unsigned long long irtl)
1214{
1215 unsigned long long ns;
1216
Jan Beulich3451ab32016-06-27 00:35:12 -06001217 if (!irtl)
1218 return 0;
1219
Jan Beulichbef45092016-06-27 00:35:48 -06001220 ns = irtl_ns_units[(irtl >> 10) & 0x7];
Len Brown5dcef692016-04-06 17:00:47 -04001221
1222 return div64_u64((irtl & 0x3FF) * ns, 1000);
1223}
1224/*
1225 * bxt_idle_state_table_update(void)
1226 *
1227 * On BXT, we trust the IRTL to show the definitive maximum latency
1228 * We use the same value for target_residency.
1229 */
1230static void bxt_idle_state_table_update(void)
1231{
1232 unsigned long long msr;
Jan Beulich3451ab32016-06-27 00:35:12 -06001233 unsigned int usec;
Len Brown5dcef692016-04-06 17:00:47 -04001234
1235 rdmsrl(MSR_PKGC6_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001236 usec = irtl_2_usec(msr);
1237 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001238 bxt_cstates[2].exit_latency = usec;
1239 bxt_cstates[2].target_residency = usec;
1240 }
1241
1242 rdmsrl(MSR_PKGC7_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001243 usec = irtl_2_usec(msr);
1244 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001245 bxt_cstates[3].exit_latency = usec;
1246 bxt_cstates[3].target_residency = usec;
1247 }
1248
1249 rdmsrl(MSR_PKGC8_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001250 usec = irtl_2_usec(msr);
1251 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001252 bxt_cstates[4].exit_latency = usec;
1253 bxt_cstates[4].target_residency = usec;
1254 }
1255
1256 rdmsrl(MSR_PKGC9_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001257 usec = irtl_2_usec(msr);
1258 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001259 bxt_cstates[5].exit_latency = usec;
1260 bxt_cstates[5].target_residency = usec;
1261 }
1262
1263 rdmsrl(MSR_PKGC10_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001264 usec = irtl_2_usec(msr);
1265 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001266 bxt_cstates[6].exit_latency = usec;
1267 bxt_cstates[6].target_residency = usec;
1268 }
1269
1270}
Len Brownd70e28f2016-03-13 00:33:48 -05001271/*
1272 * sklh_idle_state_table_update(void)
1273 *
1274 * On SKL-H (model 0x5e) disable C8 and C9 if:
1275 * C10 is enabled and SGX disabled
1276 */
1277static void sklh_idle_state_table_update(void)
1278{
1279 unsigned long long msr;
1280 unsigned int eax, ebx, ecx, edx;
1281
1282
1283 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1284 if (max_cstate <= 7)
1285 return;
1286
1287 /* if PC10 not present in CPUID.MWAIT.EDX */
1288 if ((mwait_substates & (0xF << 28)) == 0)
1289 return;
1290
Len Brown6cfb2372017-01-07 23:23:25 -05001291 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr);
Len Brownd70e28f2016-03-13 00:33:48 -05001292
1293 /* PC10 is not enabled in PKG C-state limit */
1294 if ((msr & 0xF) != 8)
1295 return;
1296
1297 ecx = 0;
1298 cpuid(7, &eax, &ebx, &ecx, &edx);
1299
1300 /* if SGX is present */
1301 if (ebx & (1 << 2)) {
1302
1303 rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
1304
1305 /* if SGX is enabled */
1306 if (msr & (1 << 18))
1307 return;
1308 }
1309
Rafael J. Wysockiba1e78a2019-11-21 19:41:51 +01001310 skl_cstates[5].flags |= CPUIDLE_FLAG_UNUSABLE; /* C8-SKL */
1311 skl_cstates[6].flags |= CPUIDLE_FLAG_UNUSABLE; /* C9-SKL */
Len Brownd70e28f2016-03-13 00:33:48 -05001312}
1313/*
Len Brown0138d8f2014-04-04 01:21:07 -04001314 * intel_idle_state_table_update()
1315 *
1316 * Update the default state_table for this CPU-id
Len Brown0138d8f2014-04-04 01:21:07 -04001317 */
Len Brownd70e28f2016-03-13 00:33:48 -05001318
1319static void intel_idle_state_table_update(void)
Len Brown0138d8f2014-04-04 01:21:07 -04001320{
Len Brownd70e28f2016-03-13 00:33:48 -05001321 switch (boot_cpu_data.x86_model) {
Len Brown0138d8f2014-04-04 01:21:07 -04001322
Dave Hansendb73c5a2016-06-02 17:19:32 -07001323 case INTEL_FAM6_IVYBRIDGE_X:
Len Brownd70e28f2016-03-13 00:33:48 -05001324 ivt_idle_state_table_update();
1325 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001326 case INTEL_FAM6_ATOM_GOLDMONT:
Peter Zijlstraf2c4db12018-08-07 10:17:27 -07001327 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
Len Brown5dcef692016-04-06 17:00:47 -04001328 bxt_idle_state_table_update();
1329 break;
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001330 case INTEL_FAM6_SKYLAKE:
Len Brownd70e28f2016-03-13 00:33:48 -05001331 sklh_idle_state_table_update();
1332 break;
Len Brown0138d8f2014-04-04 01:21:07 -04001333 }
Len Brown0138d8f2014-04-04 01:21:07 -04001334}
1335
Len Brown26717172010-03-08 14:07:30 -05001336/*
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301337 * intel_idle_cpuidle_driver_init()
1338 * allocate, initialize cpuidle_states
1339 */
Richard Cochran5469c822016-04-06 17:00:49 -04001340static void __init intel_idle_cpuidle_driver_init(void)
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301341{
1342 int cstate;
1343 struct cpuidle_driver *drv = &intel_idle_driver;
1344
Len Brown0138d8f2014-04-04 01:21:07 -04001345 intel_idle_state_table_update();
1346
Rafael J. Wysocki1b39e3f2017-08-29 03:14:37 +02001347 cpuidle_poll_state_init(drv);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301348 drv->state_count = 1;
1349
Len Browne022e7e2013-02-01 23:37:30 -05001350 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001351 unsigned int mwait_hint;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301352
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001353 if (!cpuidle_state_table[cstate].enter &&
1354 !cpuidle_state_table[cstate].enter_s2idle)
Len Browne022e7e2013-02-01 23:37:30 -05001355 break;
1356
1357 if (cstate + 1 > max_cstate) {
Joe Perches654d08a2017-06-09 12:29:20 -07001358 pr_info("max_cstate %d reached\n", max_cstate);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301359 break;
1360 }
1361
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001362 /* If marked as unusable, skip this state. */
Rafael J. Wysockiba1e78a2019-11-21 19:41:51 +01001363 if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_UNUSABLE) {
Joe Perches654d08a2017-06-09 12:29:20 -07001364 pr_debug("state %s is disabled\n",
1365 cpuidle_state_table[cstate].name);
Len Brownd70e28f2016-03-13 00:33:48 -05001366 continue;
1367 }
1368
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001369 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
1370 if (!intel_idle_verify_cstate(mwait_hint))
1371 continue;
Len Brownd70e28f2016-03-13 00:33:48 -05001372
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001373 /* Structure copy. */
1374 drv->states[drv->state_count++] = cpuidle_state_table[cstate];
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301375 }
1376
Len Brown8c058d532014-07-31 15:21:24 -04001377 if (icpu->byt_auto_demotion_disable_flag) {
1378 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
1379 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
1380 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301381}
1382
1383
1384/*
Thomas Renninger65b7f832012-01-17 22:40:08 +01001385 * intel_idle_cpu_init()
Len Brown26717172010-03-08 14:07:30 -05001386 * allocate, initialize, register cpuidle_devices
Thomas Renninger65b7f832012-01-17 22:40:08 +01001387 * @cpu: cpu/core to initialize
Len Brown26717172010-03-08 14:07:30 -05001388 */
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001389static int intel_idle_cpu_init(unsigned int cpu)
Len Brown26717172010-03-08 14:07:30 -05001390{
Len Brown26717172010-03-08 14:07:30 -05001391 struct cpuidle_device *dev;
1392
Thomas Renninger65b7f832012-01-17 22:40:08 +01001393 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001394 dev->cpu = cpu;
Len Brown26717172010-03-08 14:07:30 -05001395
Thomas Renninger65b7f832012-01-17 22:40:08 +01001396 if (cpuidle_register_device(dev)) {
Joe Perches654d08a2017-06-09 12:29:20 -07001397 pr_debug("cpuidle_register_device %d failed!\n", cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001398 return -EIO;
Len Brown26717172010-03-08 14:07:30 -05001399 }
1400
Andi Kleenb66b8b92012-01-26 00:09:07 +01001401 if (icpu->auto_demotion_disable_flags)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001402 auto_demotion_disable();
Thomas Renninger65b7f832012-01-17 22:40:08 +01001403
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001404 if (icpu->disable_promotion_to_c1e)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001405 c1e_promotion_disable();
1406
1407 return 0;
1408}
1409
1410static int intel_idle_cpu_online(unsigned int cpu)
1411{
1412 struct cpuidle_device *dev;
1413
1414 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
1415 __setup_broadcast_timer(true);
1416
1417 /*
1418 * Some systems can hotplug a cpu at runtime after
1419 * the kernel has booted, we have to initialize the
1420 * driver in this case
1421 */
1422 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
1423 if (!dev->registered)
1424 return intel_idle_cpu_init(cpu);
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001425
Len Brown26717172010-03-08 14:07:30 -05001426 return 0;
1427}
Len Brown26717172010-03-08 14:07:30 -05001428
1429static int __init intel_idle_init(void)
1430{
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001431 int retval;
Len Brown26717172010-03-08 14:07:30 -05001432
Thomas Renningerd1896042010-11-03 17:06:14 +01001433 /* Do not load intel_idle at all for now if idle= is passed */
1434 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
1435 return -ENODEV;
1436
Len Brown26717172010-03-08 14:07:30 -05001437 retval = intel_idle_probe();
1438 if (retval)
1439 return retval;
1440
Richard Cochrane9df69c2016-04-06 17:00:52 -04001441 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
1442 if (intel_idle_cpuidle_devices == NULL)
1443 return -ENOMEM;
1444
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301445 intel_idle_cpuidle_driver_init();
Len Brown26717172010-03-08 14:07:30 -05001446 retval = cpuidle_register_driver(&intel_idle_driver);
1447 if (retval) {
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001448 struct cpuidle_driver *drv = cpuidle_get_driver();
Joe Perches654d08a2017-06-09 12:29:20 -07001449 printk(KERN_DEBUG pr_fmt("intel_idle yielding to %s\n"),
1450 drv ? drv->name : "none");
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001451 goto init_driver_fail;
Len Brown26717172010-03-08 14:07:30 -05001452 }
1453
Richard Cochran2259a812016-04-06 17:00:54 -04001454 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
1455 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
Richard Cochran2259a812016-04-06 17:00:54 -04001456
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001457 retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online",
1458 intel_idle_cpu_online, NULL);
1459 if (retval < 0)
1460 goto hp_setup_fail;
Len Brown26717172010-03-08 14:07:30 -05001461
Joe Perches654d08a2017-06-09 12:29:20 -07001462 pr_debug("lapic_timer_reliable_states 0x%x\n",
1463 lapic_timer_reliable_states);
Richard Cochran2259a812016-04-06 17:00:54 -04001464
Len Brown26717172010-03-08 14:07:30 -05001465 return 0;
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001466
1467hp_setup_fail:
1468 intel_idle_cpuidle_devices_uninit();
1469 cpuidle_unregister_driver(&intel_idle_driver);
1470init_driver_fail:
1471 free_percpu(intel_idle_cpuidle_devices);
1472 return retval;
1473
Len Brown26717172010-03-08 14:07:30 -05001474}
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001475device_initcall(intel_idle_init);
Len Brown26717172010-03-08 14:07:30 -05001476
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001477/*
1478 * We are not really modular, but we used to support that. Meaning we also
1479 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
1480 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
1481 * is the easiest way (currently) to continue doing that.
1482 */
Len Brown26717172010-03-08 14:07:30 -05001483module_param(max_cstate, int, 0444);