blob: 347b08b56042f707203fd625e6e757b7b186ae6a [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
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +0100947static void __setup_broadcast_timer(bool on)
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800948{
Thomas Gleixner76962ca2015-04-03 02:02:34 +0200949 if (on)
950 tick_broadcast_enable();
951 else
952 tick_broadcast_disable();
Shaohua Li2a2d31c2011-01-10 09:38:12 +0800953}
954
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +0100955static void auto_demotion_disable(void)
Len Brown14796fc2011-01-18 20:48:27 -0500956{
957 unsigned long long msr_bits;
958
Len Brown6cfb2372017-01-07 23:23:25 -0500959 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
Andi Kleenb66b8b92012-01-26 00:09:07 +0100960 msr_bits &= ~(icpu->auto_demotion_disable_flags);
Len Brown6cfb2372017-01-07 23:23:25 -0500961 wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
Len Brown14796fc2011-01-18 20:48:27 -0500962}
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +0100963static void c1e_promotion_disable(void)
Len Brown32e95182013-02-02 01:31:56 -0500964{
965 unsigned long long msr_bits;
966
967 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
968 msr_bits &= ~0x2;
969 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
970}
Len Brown14796fc2011-01-18 20:48:27 -0500971
Andi Kleenb66b8b92012-01-26 00:09:07 +0100972static const struct idle_cpu idle_cpu_nehalem = {
973 .state_table = nehalem_cstates,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100974 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
Len Brown32e95182013-02-02 01:31:56 -0500975 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100976};
977
978static const struct idle_cpu idle_cpu_atom = {
979 .state_table = atom_cstates,
980};
981
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300982static const struct idle_cpu idle_cpu_tangier = {
983 .state_table = tangier_cstates,
984};
985
Andi Kleenb66b8b92012-01-26 00:09:07 +0100986static const struct idle_cpu idle_cpu_lincroft = {
987 .state_table = atom_cstates,
988 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
989};
990
991static const struct idle_cpu idle_cpu_snb = {
992 .state_table = snb_cstates,
Len Brown32e95182013-02-02 01:31:56 -0500993 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100994};
995
Len Brown718987d2014-02-14 02:30:00 -0500996static const struct idle_cpu idle_cpu_byt = {
997 .state_table = byt_cstates,
998 .disable_promotion_to_c1e = true,
Len Brown8c058d532014-07-31 15:21:24 -0400999 .byt_auto_demotion_disable_flag = true,
Len Brown718987d2014-02-14 02:30:00 -05001000};
1001
Len Browncab07a52015-03-27 20:54:01 -04001002static const struct idle_cpu idle_cpu_cht = {
1003 .state_table = cht_cstates,
1004 .disable_promotion_to_c1e = true,
1005 .byt_auto_demotion_disable_flag = true,
1006};
1007
Len Brown6edab082012-06-01 19:45:32 -04001008static const struct idle_cpu idle_cpu_ivb = {
1009 .state_table = ivb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001010 .disable_promotion_to_c1e = true,
Len Brown6edab082012-06-01 19:45:32 -04001011};
1012
Len Brown0138d8f2014-04-04 01:21:07 -04001013static const struct idle_cpu idle_cpu_ivt = {
1014 .state_table = ivt_cstates,
1015 .disable_promotion_to_c1e = true,
1016};
1017
Len Brown85a4d2d2013-01-31 14:40:49 -05001018static const struct idle_cpu idle_cpu_hsw = {
1019 .state_table = hsw_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001020 .disable_promotion_to_c1e = true,
Len Brown85a4d2d2013-01-31 14:40:49 -05001021};
1022
Len Browna138b562014-02-04 23:56:40 -05001023static const struct idle_cpu idle_cpu_bdw = {
1024 .state_table = bdw_cstates,
1025 .disable_promotion_to_c1e = true,
1026};
1027
Len Brown493f1332015-03-25 23:20:37 -04001028static const struct idle_cpu idle_cpu_skl = {
1029 .state_table = skl_cstates,
1030 .disable_promotion_to_c1e = true,
1031};
1032
Len Brownf9e71652016-04-06 17:00:58 -04001033static const struct idle_cpu idle_cpu_skx = {
1034 .state_table = skx_cstates,
1035 .disable_promotion_to_c1e = true,
1036};
Len Brown493f1332015-03-25 23:20:37 -04001037
Len Brownfab04b22013-11-09 00:30:17 -05001038static const struct idle_cpu idle_cpu_avn = {
1039 .state_table = avn_cstates,
1040 .disable_promotion_to_c1e = true,
1041};
1042
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001043static const struct idle_cpu idle_cpu_knl = {
1044 .state_table = knl_cstates,
1045};
1046
Len Brown5dcef692016-04-06 17:00:47 -04001047static const struct idle_cpu idle_cpu_bxt = {
1048 .state_table = bxt_cstates,
1049 .disable_promotion_to_c1e = true,
1050};
1051
Jacob Pan0080d652016-06-17 01:28:34 -04001052static const struct idle_cpu idle_cpu_dnv = {
1053 .state_table = dnv_cstates,
1054 .disable_promotion_to_c1e = true,
1055};
1056
Mathias Kraused5cdc3c2015-03-25 22:15:14 +01001057static const struct x86_cpu_id intel_idle_ids[] __initconst = {
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001058 INTEL_CPU_FAM6(NEHALEM_EP, idle_cpu_nehalem),
1059 INTEL_CPU_FAM6(NEHALEM, idle_cpu_nehalem),
1060 INTEL_CPU_FAM6(NEHALEM_G, idle_cpu_nehalem),
1061 INTEL_CPU_FAM6(WESTMERE, idle_cpu_nehalem),
1062 INTEL_CPU_FAM6(WESTMERE_EP, idle_cpu_nehalem),
1063 INTEL_CPU_FAM6(NEHALEM_EX, idle_cpu_nehalem),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001064 INTEL_CPU_FAM6(ATOM_BONNELL, idle_cpu_atom),
1065 INTEL_CPU_FAM6(ATOM_BONNELL_MID, idle_cpu_lincroft),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001066 INTEL_CPU_FAM6(WESTMERE_EX, idle_cpu_nehalem),
1067 INTEL_CPU_FAM6(SANDYBRIDGE, idle_cpu_snb),
1068 INTEL_CPU_FAM6(SANDYBRIDGE_X, idle_cpu_snb),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001069 INTEL_CPU_FAM6(ATOM_SALTWELL, idle_cpu_atom),
1070 INTEL_CPU_FAM6(ATOM_SILVERMONT, idle_cpu_byt),
1071 INTEL_CPU_FAM6(ATOM_SILVERMONT_MID, idle_cpu_tangier),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001072 INTEL_CPU_FAM6(ATOM_AIRMONT, idle_cpu_cht),
1073 INTEL_CPU_FAM6(IVYBRIDGE, idle_cpu_ivb),
1074 INTEL_CPU_FAM6(IVYBRIDGE_X, idle_cpu_ivt),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001075 INTEL_CPU_FAM6(HASWELL, idle_cpu_hsw),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001076 INTEL_CPU_FAM6(HASWELL_X, idle_cpu_hsw),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001077 INTEL_CPU_FAM6(HASWELL_L, idle_cpu_hsw),
Peter Zijlstra5e741402019-08-27 21:48:23 +02001078 INTEL_CPU_FAM6(HASWELL_G, idle_cpu_hsw),
Peter Zijlstra5ebb34e2019-08-27 21:48:24 +02001079 INTEL_CPU_FAM6(ATOM_SILVERMONT_D, idle_cpu_avn),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001080 INTEL_CPU_FAM6(BROADWELL, idle_cpu_bdw),
Peter Zijlstra5e741402019-08-27 21:48:23 +02001081 INTEL_CPU_FAM6(BROADWELL_G, idle_cpu_bdw),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001082 INTEL_CPU_FAM6(BROADWELL_X, idle_cpu_bdw),
Peter Zijlstra5ebb34e2019-08-27 21:48:24 +02001083 INTEL_CPU_FAM6(BROADWELL_D, idle_cpu_bdw),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001084 INTEL_CPU_FAM6(SKYLAKE_L, idle_cpu_skl),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001085 INTEL_CPU_FAM6(SKYLAKE, idle_cpu_skl),
Peter Zijlstraaf239c42019-08-27 21:48:22 +02001086 INTEL_CPU_FAM6(KABYLAKE_L, idle_cpu_skl),
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001087 INTEL_CPU_FAM6(KABYLAKE, idle_cpu_skl),
Andy Shevchenkoa4a008e2018-08-31 11:22:29 +03001088 INTEL_CPU_FAM6(SKYLAKE_X, idle_cpu_skx),
1089 INTEL_CPU_FAM6(XEON_PHI_KNL, idle_cpu_knl),
1090 INTEL_CPU_FAM6(XEON_PHI_KNM, idle_cpu_knl),
1091 INTEL_CPU_FAM6(ATOM_GOLDMONT, idle_cpu_bxt),
Linus Torvaldsc05f3642018-10-23 13:32:18 +01001092 INTEL_CPU_FAM6(ATOM_GOLDMONT_PLUS, idle_cpu_bxt),
Peter Zijlstra5ebb34e2019-08-27 21:48:24 +02001093 INTEL_CPU_FAM6(ATOM_GOLDMONT_D, idle_cpu_dnv),
1094 INTEL_CPU_FAM6(ATOM_TREMONT_D, idle_cpu_dnv),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001095 {}
1096};
Andi Kleenb66b8b92012-01-26 00:09:07 +01001097
Len Brown26717172010-03-08 14:07:30 -05001098/*
1099 * intel_idle_probe()
1100 */
Bartlomiej Zolnierkiewicz00f3e752013-08-30 12:27:45 +02001101static int __init intel_idle_probe(void)
Len Brown26717172010-03-08 14:07:30 -05001102{
Len Brownc4236282010-05-28 02:22:03 -04001103 unsigned int eax, ebx, ecx;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001104 const struct x86_cpu_id *id;
Len Brown26717172010-03-08 14:07:30 -05001105
1106 if (max_cstate == 0) {
Joe Perches654d08a2017-06-09 12:29:20 -07001107 pr_debug("disabled\n");
Len Brown26717172010-03-08 14:07:30 -05001108 return -EPERM;
1109 }
1110
Andi Kleenb66b8b92012-01-26 00:09:07 +01001111 id = x86_match_cpu(intel_idle_ids);
1112 if (!id) {
1113 if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
1114 boot_cpu_data.x86 == 6)
Joe Perches654d08a2017-06-09 12:29:20 -07001115 pr_debug("does not run on family %d model %d\n",
1116 boot_cpu_data.x86, boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001117 return -ENODEV;
Andi Kleenb66b8b92012-01-26 00:09:07 +01001118 }
Len Brown26717172010-03-08 14:07:30 -05001119
Len Browna4c44752017-11-09 02:19:39 -05001120 if (!boot_cpu_has(X86_FEATURE_MWAIT)) {
1121 pr_debug("Please enable MWAIT in BIOS SETUP\n");
1122 return -ENODEV;
1123 }
1124
Len Brown26717172010-03-08 14:07:30 -05001125 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
1126 return -ENODEV;
1127
Len Brownc4236282010-05-28 02:22:03 -04001128 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001129
1130 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
Thomas Renninger5c2a9f02011-12-04 22:17:29 +01001131 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
1132 !mwait_substates)
Len Brown26717172010-03-08 14:07:30 -05001133 return -ENODEV;
Len Brown26717172010-03-08 14:07:30 -05001134
Joe Perches654d08a2017-06-09 12:29:20 -07001135 pr_debug("MWAIT substates: 0x%x\n", mwait_substates);
Len Brown26717172010-03-08 14:07:30 -05001136
Andi Kleenb66b8b92012-01-26 00:09:07 +01001137 icpu = (const struct idle_cpu *)id->driver_data;
1138 cpuidle_state_table = icpu->state_table;
Len Brown26717172010-03-08 14:07:30 -05001139
Joe Perches654d08a2017-06-09 12:29:20 -07001140 pr_debug("v" INTEL_IDLE_VERSION " model 0x%X\n",
1141 boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001142
Len Brown26717172010-03-08 14:07:30 -05001143 return 0;
1144}
1145
1146/*
1147 * intel_idle_cpuidle_devices_uninit()
Richard Cochranca424892016-04-06 17:00:53 -04001148 * Unregisters the cpuidle devices.
Len Brown26717172010-03-08 14:07:30 -05001149 */
1150static void intel_idle_cpuidle_devices_uninit(void)
1151{
1152 int i;
1153 struct cpuidle_device *dev;
1154
1155 for_each_online_cpu(i) {
1156 dev = per_cpu_ptr(intel_idle_cpuidle_devices, i);
1157 cpuidle_unregister_device(dev);
1158 }
Len Brown26717172010-03-08 14:07:30 -05001159}
Len Brown0138d8f2014-04-04 01:21:07 -04001160
1161/*
Len Brownd70e28f2016-03-13 00:33:48 -05001162 * ivt_idle_state_table_update(void)
1163 *
1164 * Tune IVT multi-socket targets
1165 * Assumption: num_sockets == (max_package_num + 1)
1166 */
1167static void ivt_idle_state_table_update(void)
1168{
1169 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1170 int cpu, package_num, num_sockets = 1;
1171
1172 for_each_online_cpu(cpu) {
1173 package_num = topology_physical_package_id(cpu);
1174 if (package_num + 1 > num_sockets) {
1175 num_sockets = package_num + 1;
1176
1177 if (num_sockets > 4) {
1178 cpuidle_state_table = ivt_cstates_8s;
1179 return;
1180 }
1181 }
1182 }
1183
1184 if (num_sockets > 2)
1185 cpuidle_state_table = ivt_cstates_4s;
1186
1187 /* else, 1 and 2 socket systems use default ivt_cstates */
1188}
Len Brown5dcef692016-04-06 17:00:47 -04001189
1190/*
1191 * Translate IRTL (Interrupt Response Time Limit) MSR to usec
1192 */
1193
1194static unsigned int irtl_ns_units[] = {
1195 1, 32, 1024, 32768, 1048576, 33554432, 0, 0 };
1196
1197static unsigned long long irtl_2_usec(unsigned long long irtl)
1198{
1199 unsigned long long ns;
1200
Jan Beulich3451ab32016-06-27 00:35:12 -06001201 if (!irtl)
1202 return 0;
1203
Jan Beulichbef45092016-06-27 00:35:48 -06001204 ns = irtl_ns_units[(irtl >> 10) & 0x7];
Len Brown5dcef692016-04-06 17:00:47 -04001205
1206 return div64_u64((irtl & 0x3FF) * ns, 1000);
1207}
1208/*
1209 * bxt_idle_state_table_update(void)
1210 *
1211 * On BXT, we trust the IRTL to show the definitive maximum latency
1212 * We use the same value for target_residency.
1213 */
1214static void bxt_idle_state_table_update(void)
1215{
1216 unsigned long long msr;
Jan Beulich3451ab32016-06-27 00:35:12 -06001217 unsigned int usec;
Len Brown5dcef692016-04-06 17:00:47 -04001218
1219 rdmsrl(MSR_PKGC6_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001220 usec = irtl_2_usec(msr);
1221 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001222 bxt_cstates[2].exit_latency = usec;
1223 bxt_cstates[2].target_residency = usec;
1224 }
1225
1226 rdmsrl(MSR_PKGC7_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001227 usec = irtl_2_usec(msr);
1228 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001229 bxt_cstates[3].exit_latency = usec;
1230 bxt_cstates[3].target_residency = usec;
1231 }
1232
1233 rdmsrl(MSR_PKGC8_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001234 usec = irtl_2_usec(msr);
1235 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001236 bxt_cstates[4].exit_latency = usec;
1237 bxt_cstates[4].target_residency = usec;
1238 }
1239
1240 rdmsrl(MSR_PKGC9_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001241 usec = irtl_2_usec(msr);
1242 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001243 bxt_cstates[5].exit_latency = usec;
1244 bxt_cstates[5].target_residency = usec;
1245 }
1246
1247 rdmsrl(MSR_PKGC10_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001248 usec = irtl_2_usec(msr);
1249 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001250 bxt_cstates[6].exit_latency = usec;
1251 bxt_cstates[6].target_residency = usec;
1252 }
1253
1254}
Len Brownd70e28f2016-03-13 00:33:48 -05001255/*
1256 * sklh_idle_state_table_update(void)
1257 *
1258 * On SKL-H (model 0x5e) disable C8 and C9 if:
1259 * C10 is enabled and SGX disabled
1260 */
1261static void sklh_idle_state_table_update(void)
1262{
1263 unsigned long long msr;
1264 unsigned int eax, ebx, ecx, edx;
1265
1266
1267 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1268 if (max_cstate <= 7)
1269 return;
1270
1271 /* if PC10 not present in CPUID.MWAIT.EDX */
1272 if ((mwait_substates & (0xF << 28)) == 0)
1273 return;
1274
Len Brown6cfb2372017-01-07 23:23:25 -05001275 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr);
Len Brownd70e28f2016-03-13 00:33:48 -05001276
1277 /* PC10 is not enabled in PKG C-state limit */
1278 if ((msr & 0xF) != 8)
1279 return;
1280
1281 ecx = 0;
1282 cpuid(7, &eax, &ebx, &ecx, &edx);
1283
1284 /* if SGX is present */
1285 if (ebx & (1 << 2)) {
1286
1287 rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
1288
1289 /* if SGX is enabled */
1290 if (msr & (1 << 18))
1291 return;
1292 }
1293
1294 skl_cstates[5].disabled = 1; /* C8-SKL */
1295 skl_cstates[6].disabled = 1; /* C9-SKL */
1296}
1297/*
Len Brown0138d8f2014-04-04 01:21:07 -04001298 * intel_idle_state_table_update()
1299 *
1300 * Update the default state_table for this CPU-id
Len Brown0138d8f2014-04-04 01:21:07 -04001301 */
Len Brownd70e28f2016-03-13 00:33:48 -05001302
1303static void intel_idle_state_table_update(void)
Len Brown0138d8f2014-04-04 01:21:07 -04001304{
Len Brownd70e28f2016-03-13 00:33:48 -05001305 switch (boot_cpu_data.x86_model) {
Len Brown0138d8f2014-04-04 01:21:07 -04001306
Dave Hansendb73c5a2016-06-02 17:19:32 -07001307 case INTEL_FAM6_IVYBRIDGE_X:
Len Brownd70e28f2016-03-13 00:33:48 -05001308 ivt_idle_state_table_update();
1309 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001310 case INTEL_FAM6_ATOM_GOLDMONT:
Peter Zijlstraf2c4db12018-08-07 10:17:27 -07001311 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
Len Brown5dcef692016-04-06 17:00:47 -04001312 bxt_idle_state_table_update();
1313 break;
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001314 case INTEL_FAM6_SKYLAKE:
Len Brownd70e28f2016-03-13 00:33:48 -05001315 sklh_idle_state_table_update();
1316 break;
Len Brown0138d8f2014-04-04 01:21:07 -04001317 }
Len Brown0138d8f2014-04-04 01:21:07 -04001318}
1319
Len Brown26717172010-03-08 14:07:30 -05001320/*
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301321 * intel_idle_cpuidle_driver_init()
1322 * allocate, initialize cpuidle_states
1323 */
Richard Cochran5469c822016-04-06 17:00:49 -04001324static void __init intel_idle_cpuidle_driver_init(void)
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301325{
1326 int cstate;
1327 struct cpuidle_driver *drv = &intel_idle_driver;
1328
Len Brown0138d8f2014-04-04 01:21:07 -04001329 intel_idle_state_table_update();
1330
Rafael J. Wysocki1b39e3f2017-08-29 03:14:37 +02001331 cpuidle_poll_state_init(drv);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301332 drv->state_count = 1;
1333
Len Browne022e7e2013-02-01 23:37:30 -05001334 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
Len Brown24bfa952014-02-14 00:50:34 -05001335 int num_substates, mwait_hint, mwait_cstate;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301336
Len Brown7dd0e0a2015-05-27 17:11:37 -04001337 if ((cpuidle_state_table[cstate].enter == NULL) &&
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +02001338 (cpuidle_state_table[cstate].enter_s2idle == NULL))
Len Browne022e7e2013-02-01 23:37:30 -05001339 break;
1340
1341 if (cstate + 1 > max_cstate) {
Joe Perches654d08a2017-06-09 12:29:20 -07001342 pr_info("max_cstate %d reached\n", max_cstate);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301343 break;
1344 }
1345
Len Browne022e7e2013-02-01 23:37:30 -05001346 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
1347 mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint);
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301348
Len Brown24bfa952014-02-14 00:50:34 -05001349 /* number of sub-states for this state in CPUID.MWAIT */
Len Browne022e7e2013-02-01 23:37:30 -05001350 num_substates = (mwait_substates >> ((mwait_cstate + 1) * 4))
1351 & MWAIT_SUBSTATE_MASK;
1352
Len Brown24bfa952014-02-14 00:50:34 -05001353 /* if NO sub-states for this state in CPUID, skip it */
1354 if (num_substates == 0)
Len Browne022e7e2013-02-01 23:37:30 -05001355 continue;
1356
Len Brownd70e28f2016-03-13 00:33:48 -05001357 /* if state marked as disabled, skip it */
1358 if (cpuidle_state_table[cstate].disabled != 0) {
Joe Perches654d08a2017-06-09 12:29:20 -07001359 pr_debug("state %s is disabled\n",
1360 cpuidle_state_table[cstate].name);
Len Brownd70e28f2016-03-13 00:33:48 -05001361 continue;
1362 }
1363
1364
Len Browne022e7e2013-02-01 23:37:30 -05001365 if (((mwait_cstate + 1) > 2) &&
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301366 !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
1367 mark_tsc_unstable("TSC halts in idle"
1368 " states deeper than C2");
1369
1370 drv->states[drv->state_count] = /* structure copy */
1371 cpuidle_state_table[cstate];
1372
1373 drv->state_count += 1;
1374 }
1375
Len Brown8c058d532014-07-31 15:21:24 -04001376 if (icpu->byt_auto_demotion_disable_flag) {
1377 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
1378 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
1379 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301380}
1381
1382
1383/*
Thomas Renninger65b7f832012-01-17 22:40:08 +01001384 * intel_idle_cpu_init()
Len Brown26717172010-03-08 14:07:30 -05001385 * allocate, initialize, register cpuidle_devices
Thomas Renninger65b7f832012-01-17 22:40:08 +01001386 * @cpu: cpu/core to initialize
Len Brown26717172010-03-08 14:07:30 -05001387 */
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001388static int intel_idle_cpu_init(unsigned int cpu)
Len Brown26717172010-03-08 14:07:30 -05001389{
Len Brown26717172010-03-08 14:07:30 -05001390 struct cpuidle_device *dev;
1391
Thomas Renninger65b7f832012-01-17 22:40:08 +01001392 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001393 dev->cpu = cpu;
Len Brown26717172010-03-08 14:07:30 -05001394
Thomas Renninger65b7f832012-01-17 22:40:08 +01001395 if (cpuidle_register_device(dev)) {
Joe Perches654d08a2017-06-09 12:29:20 -07001396 pr_debug("cpuidle_register_device %d failed!\n", cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001397 return -EIO;
Len Brown26717172010-03-08 14:07:30 -05001398 }
1399
Andi Kleenb66b8b92012-01-26 00:09:07 +01001400 if (icpu->auto_demotion_disable_flags)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001401 auto_demotion_disable();
Thomas Renninger65b7f832012-01-17 22:40:08 +01001402
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001403 if (icpu->disable_promotion_to_c1e)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001404 c1e_promotion_disable();
1405
1406 return 0;
1407}
1408
1409static int intel_idle_cpu_online(unsigned int cpu)
1410{
1411 struct cpuidle_device *dev;
1412
1413 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
1414 __setup_broadcast_timer(true);
1415
1416 /*
1417 * Some systems can hotplug a cpu at runtime after
1418 * the kernel has booted, we have to initialize the
1419 * driver in this case
1420 */
1421 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
1422 if (!dev->registered)
1423 return intel_idle_cpu_init(cpu);
Bartlomiej Zolnierkiewiczdbf87ab2013-12-20 19:47:28 +01001424
Len Brown26717172010-03-08 14:07:30 -05001425 return 0;
1426}
Len Brown26717172010-03-08 14:07:30 -05001427
1428static int __init intel_idle_init(void)
1429{
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001430 int retval;
Len Brown26717172010-03-08 14:07:30 -05001431
Thomas Renningerd1896042010-11-03 17:06:14 +01001432 /* Do not load intel_idle at all for now if idle= is passed */
1433 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
1434 return -ENODEV;
1435
Len Brown26717172010-03-08 14:07:30 -05001436 retval = intel_idle_probe();
1437 if (retval)
1438 return retval;
1439
Richard Cochrane9df69c2016-04-06 17:00:52 -04001440 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
1441 if (intel_idle_cpuidle_devices == NULL)
1442 return -ENOMEM;
1443
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301444 intel_idle_cpuidle_driver_init();
Len Brown26717172010-03-08 14:07:30 -05001445 retval = cpuidle_register_driver(&intel_idle_driver);
1446 if (retval) {
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001447 struct cpuidle_driver *drv = cpuidle_get_driver();
Joe Perches654d08a2017-06-09 12:29:20 -07001448 printk(KERN_DEBUG pr_fmt("intel_idle yielding to %s\n"),
1449 drv ? drv->name : "none");
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001450 goto init_driver_fail;
Len Brown26717172010-03-08 14:07:30 -05001451 }
1452
Richard Cochran2259a812016-04-06 17:00:54 -04001453 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
1454 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
Richard Cochran2259a812016-04-06 17:00:54 -04001455
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001456 retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online",
1457 intel_idle_cpu_online, NULL);
1458 if (retval < 0)
1459 goto hp_setup_fail;
Len Brown26717172010-03-08 14:07:30 -05001460
Joe Perches654d08a2017-06-09 12:29:20 -07001461 pr_debug("lapic_timer_reliable_states 0x%x\n",
1462 lapic_timer_reliable_states);
Richard Cochran2259a812016-04-06 17:00:54 -04001463
Len Brown26717172010-03-08 14:07:30 -05001464 return 0;
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001465
1466hp_setup_fail:
1467 intel_idle_cpuidle_devices_uninit();
1468 cpuidle_unregister_driver(&intel_idle_driver);
1469init_driver_fail:
1470 free_percpu(intel_idle_cpuidle_devices);
1471 return retval;
1472
Len Brown26717172010-03-08 14:07:30 -05001473}
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001474device_initcall(intel_idle_init);
Len Brown26717172010-03-08 14:07:30 -05001475
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001476/*
1477 * We are not really modular, but we used to support that. Meaning we also
1478 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
1479 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
1480 * is the easiest way (currently) to continue doing that.
1481 */
Len Brown26717172010-03-08 14:07:30 -05001482module_param(max_cstate, int, 0444);