blob: 01bace49a9626cf79fe2d0d3fd758fe455a6e745 [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 *
Rafael J. Wysocki317e5ec2020-02-06 18:45:49 +01005 * Copyright (c) 2013 - 2020, Intel Corporation.
Len Brown26717172010-03-08 14:07:30 -05006 * Len Brown <len.brown@intel.com>
Rafael J. Wysocki317e5ec2020-02-06 18:45:49 +01007 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Len Brown26717172010-03-08 14:07:30 -05008 */
9
10/*
Alexander Monakov8bb2e2a2020-10-12 15:50:33 +030011 * intel_idle is a cpuidle driver that loads on all Intel CPUs with MWAIT
Len Brown26717172010-03-08 14:07:30 -050012 * in lieu of the legacy ACPI processor_idle driver. The intent is to
13 * make Linux more efficient on these processors, as intel_idle knows
14 * more than ACPI, as well as make Linux more immune to ACPI BIOS bugs.
15 */
16
17/*
18 * Design Assumptions
19 *
20 * All CPUs have same idle states as boot CPU
21 *
22 * Chipset BM_STS (bus master status) bit is a NOP
Alexander Monakov8bb2e2a2020-10-12 15:50:33 +030023 * for preventing entry into deep C-states
24 *
25 * CPU will flush caches as needed when entering a C-state via MWAIT
26 * (in contrast to entering ACPI C3, in which case the WBINVD
27 * instruction needs to be executed to flush the caches)
Len Brown26717172010-03-08 14:07:30 -050028 */
29
30/*
31 * Known limitations
32 *
Len Brown26717172010-03-08 14:07:30 -050033 * ACPI has a .suspend hack to turn off deep c-statees during suspend
34 * to avoid complications with the lapic timer workaround.
35 * Have not seen issues with suspend, but may need same workaround here.
36 *
Len Brown26717172010-03-08 14:07:30 -050037 */
38
39/* un-comment DEBUG to enable pr_debug() statements */
40#define DEBUG
41
Joe Perches654d08a2017-06-09 12:29:20 -070042#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
43
Rafael J. Wysocki18734952019-12-13 09:56:01 +010044#include <linux/acpi.h>
Len Brown26717172010-03-08 14:07:30 -050045#include <linux/kernel.h>
46#include <linux/cpuidle.h>
Thomas Gleixner76962ca2015-04-03 02:02:34 +020047#include <linux/tick.h>
Len Brown26717172010-03-08 14:07:30 -050048#include <trace/events/power.h>
49#include <linux/sched.h>
Shaohua Li2a2d31c2011-01-10 09:38:12 +080050#include <linux/notifier.h>
51#include <linux/cpu.h>
Paul Gortmaker02c4fae2016-06-17 01:28:33 -040052#include <linux/moduleparam.h>
Andi Kleenb66b8b92012-01-26 00:09:07 +010053#include <asm/cpu_device_id.h>
Dave Hansendb73c5a2016-06-02 17:19:32 -070054#include <asm/intel-family.h>
H. Peter Anvinbc83ccc2010-09-17 15:36:40 -070055#include <asm/mwait.h>
Len Brown14796fc2011-01-18 20:48:27 -050056#include <asm/msr.h>
Len Brown26717172010-03-08 14:07:30 -050057
Rafael J. Wysocki317e5ec2020-02-06 18:45:49 +010058#define INTEL_IDLE_VERSION "0.5.1"
Len Brown26717172010-03-08 14:07:30 -050059
Len Brown26717172010-03-08 14:07:30 -050060static struct cpuidle_driver intel_idle_driver = {
61 .name = "intel_idle",
62 .owner = THIS_MODULE,
63};
64/* intel_idle.max_cstate=0 disables driver */
Len Brown137ecc72013-02-01 21:35:35 -050065static int max_cstate = CPUIDLE_STATE_MAX - 1;
Rafael J. Wysocki4dcb78e2020-02-03 11:57:18 +010066static unsigned int disabled_states_mask;
Len Brown26717172010-03-08 14:07:30 -050067
Rafael J. Wysocki6eb04432020-02-06 18:45:18 +010068static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
Rafael J. Wysocki7f843dd2020-02-06 18:41:24 +010069
70static unsigned long auto_demotion_disable_flags;
71static bool disable_promotion_to_c1e;
72
Andi Kleenb66b8b92012-01-26 00:09:07 +010073struct idle_cpu {
74 struct cpuidle_state *state_table;
75
76 /*
77 * Hardware C-state auto-demotion may not always be optimal.
78 * Indicate which enable bits to clear here.
79 */
80 unsigned long auto_demotion_disable_flags;
Len Brown8c058d532014-07-31 15:21:24 -040081 bool byt_auto_demotion_disable_flag;
Len Brown32e95182013-02-02 01:31:56 -050082 bool disable_promotion_to_c1e;
Rafael J. Wysockibff8e602019-12-13 09:56:21 +010083 bool use_acpi;
Andi Kleenb66b8b92012-01-26 00:09:07 +010084};
85
Rafael J. Wysocki7f843dd2020-02-06 18:41:24 +010086static const struct idle_cpu *icpu __initdata;
Rafael J. Wysocki7f843dd2020-02-06 18:41:24 +010087static struct cpuidle_state *cpuidle_state_table __initdata;
Len Brown26717172010-03-08 14:07:30 -050088
Rafael J. Wysocki6eb04432020-02-06 18:45:18 +010089static unsigned int mwait_substates __initdata;
90
Len Brown26717172010-03-08 14:07:30 -050091/*
Rafael J. Wysockibff8e602019-12-13 09:56:21 +010092 * Enable this state by default even if the ACPI _CST does not list it.
93 */
94#define CPUIDLE_FLAG_ALWAYS_ENABLE BIT(15)
95
96/*
Len Brownb1beab42013-01-31 19:55:37 -050097 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
98 * the C-state (top nibble) and sub-state (bottom nibble)
99 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
100 *
101 * We store the hint at the top of our "flags" for each state.
102 */
103#define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
104#define MWAIT2flg(eax) ((eax & 0xFF) << 24)
105
Rafael J. Wysocki30a996f2020-02-06 18:41:15 +0100106/**
107 * intel_idle - Ask the processor to enter the given idle state.
108 * @dev: cpuidle device of the target CPU.
109 * @drv: cpuidle driver (assumed to point to intel_idle_driver).
110 * @index: Target idle state index.
111 *
112 * Use the MWAIT instruction to notify the processor that the CPU represented by
113 * @dev is idle and it can try to enter the idle state corresponding to @index.
114 *
115 * If the local APIC timer is not known to be reliable in the target idle state,
116 * enable one-shot tick broadcasting for the target CPU before executing MWAIT.
117 *
118 * Optionally call leave_mm() for the target CPU upfront to avoid wakeups due to
119 * flushing user TLBs.
120 *
121 * Must be called under local_irq_disable().
122 */
123static __cpuidle int intel_idle(struct cpuidle_device *dev,
124 struct cpuidle_driver *drv, int index)
125{
126 struct cpuidle_state *state = &drv->states[index];
127 unsigned long eax = flg2MWAIT(state->flags);
128 unsigned long ecx = 1; /* break on interrupt flag */
Kees Cook3f649ab2020-06-03 13:09:38 -0700129 bool tick;
Rafael J. Wysocki30a996f2020-02-06 18:41:15 +0100130
Rafael J. Wysockidab20172020-06-29 13:58:28 +0200131 if (!static_cpu_has(X86_FEATURE_ARAT)) {
Rafael J. Wysocki30a996f2020-02-06 18:41:15 +0100132 /*
133 * Switch over to one-shot tick broadcast if the target C-state
134 * is deeper than C1.
135 */
136 if ((eax >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) {
137 tick = true;
138 tick_broadcast_enter();
139 } else {
140 tick = false;
141 }
142 }
143
144 mwait_idle_with_hints(eax, ecx);
145
146 if (!static_cpu_has(X86_FEATURE_ARAT) && tick)
147 tick_broadcast_exit();
148
149 return index;
150}
151
152/**
153 * intel_idle_s2idle - Ask the processor to enter the given idle state.
154 * @dev: cpuidle device of the target CPU.
155 * @drv: cpuidle driver (assumed to point to intel_idle_driver).
156 * @index: Target idle state index.
157 *
158 * Use the MWAIT instruction to notify the processor that the CPU represented by
159 * @dev is idle and it can try to enter the idle state corresponding to @index.
160 *
161 * Invoked as a suspend-to-idle callback routine with frozen user space, frozen
162 * scheduler tick and suspended scheduler clock on the target CPU.
163 */
Neal Liuefe97112020-07-27 11:25:46 +0800164static __cpuidle int intel_idle_s2idle(struct cpuidle_device *dev,
165 struct cpuidle_driver *drv, int index)
Rafael J. Wysocki30a996f2020-02-06 18:41:15 +0100166{
167 unsigned long eax = flg2MWAIT(drv->states[index].flags);
168 unsigned long ecx = 1; /* break on interrupt flag */
169
170 mwait_idle_with_hints(eax, ecx);
Neal Liuefe97112020-07-27 11:25:46 +0800171
172 return 0;
Rafael J. Wysocki30a996f2020-02-06 18:41:15 +0100173}
174
Len Brownb1beab42013-01-31 19:55:37 -0500175/*
Len Brown26717172010-03-08 14:07:30 -0500176 * States are indexed by the cstate number,
177 * which is also the index into the MWAIT hint array.
178 * Thus C0 is a dummy.
179 */
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100180static struct cpuidle_state nehalem_cstates[] __initdata = {
Len Browne022e7e2013-02-01 23:37:30 -0500181 {
Len Brownde09cdd2017-02-28 16:32:44 -0500182 .name = "C1",
Len Brown26717172010-03-08 14:07:30 -0500183 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100184 .flags = MWAIT2flg(0x00),
Len Brown26717172010-03-08 14:07:30 -0500185 .exit_latency = 3,
Len Brown26717172010-03-08 14:07:30 -0500186 .target_residency = 6,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100187 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200188 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500189 {
Len Brownde09cdd2017-02-28 16:32:44 -0500190 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500191 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100192 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500193 .exit_latency = 10,
194 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100195 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200196 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500197 {
Len Brownde09cdd2017-02-28 16:32:44 -0500198 .name = "C3",
Len Brown26717172010-03-08 14:07:30 -0500199 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100200 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500201 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500202 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100203 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200204 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500205 {
Len Brownde09cdd2017-02-28 16:32:44 -0500206 .name = "C6",
Len Brown26717172010-03-08 14:07:30 -0500207 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100208 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500209 .exit_latency = 200,
Len Brown26717172010-03-08 14:07:30 -0500210 .target_residency = 800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100211 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200212 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500213 {
214 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500215};
216
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100217static struct cpuidle_state snb_cstates[] __initdata = {
Len Browne022e7e2013-02-01 23:37:30 -0500218 {
Len Brownde09cdd2017-02-28 16:32:44 -0500219 .name = "C1",
Len Brownd13780d2010-07-07 00:12:03 -0400220 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100221 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500222 .exit_latency = 2,
223 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100224 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200225 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500226 {
Len Brownde09cdd2017-02-28 16:32:44 -0500227 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500228 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100229 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500230 .exit_latency = 10,
231 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100232 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200233 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500234 {
Len Brownde09cdd2017-02-28 16:32:44 -0500235 .name = "C3",
Len Brownd13780d2010-07-07 00:12:03 -0400236 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100237 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400238 .exit_latency = 80,
Len Brownddbd5502010-12-13 18:28:22 -0500239 .target_residency = 211,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100240 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200241 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500242 {
Len Brownde09cdd2017-02-28 16:32:44 -0500243 .name = "C6",
Len Brownd13780d2010-07-07 00:12:03 -0400244 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100245 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400246 .exit_latency = 104,
Len Brownddbd5502010-12-13 18:28:22 -0500247 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100248 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200249 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500250 {
Len Brownde09cdd2017-02-28 16:32:44 -0500251 .name = "C7",
Len Brownd13780d2010-07-07 00:12:03 -0400252 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100253 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd13780d2010-07-07 00:12:03 -0400254 .exit_latency = 109,
Len Brownddbd5502010-12-13 18:28:22 -0500255 .target_residency = 345,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100256 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200257 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500258 {
259 .enter = NULL }
Len Brownd13780d2010-07-07 00:12:03 -0400260};
261
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100262static struct cpuidle_state byt_cstates[] __initdata = {
Len Brown718987d2014-02-14 02:30:00 -0500263 {
Len Brownde09cdd2017-02-28 16:32:44 -0500264 .name = "C1",
Len Brown718987d2014-02-14 02:30:00 -0500265 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100266 .flags = MWAIT2flg(0x00),
Len Brown718987d2014-02-14 02:30:00 -0500267 .exit_latency = 1,
268 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100269 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200270 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500271 {
Len Brownde09cdd2017-02-28 16:32:44 -0500272 .name = "C6N",
Len Brown718987d2014-02-14 02:30:00 -0500273 .desc = "MWAIT 0x58",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100274 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400275 .exit_latency = 300,
Len Brown718987d2014-02-14 02:30:00 -0500276 .target_residency = 275,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100277 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200278 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500279 {
Len Brownde09cdd2017-02-28 16:32:44 -0500280 .name = "C6S",
Len Brown718987d2014-02-14 02:30:00 -0500281 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100282 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownd7ef7672015-03-24 23:23:20 -0400283 .exit_latency = 500,
Len Brown718987d2014-02-14 02:30:00 -0500284 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100285 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200286 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500287 {
Len Brownde09cdd2017-02-28 16:32:44 -0500288 .name = "C7",
Len Brown718987d2014-02-14 02:30:00 -0500289 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100290 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500291 .exit_latency = 1200,
Len Brownd7ef7672015-03-24 23:23:20 -0400292 .target_residency = 4000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100293 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200294 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500295 {
Len Brownde09cdd2017-02-28 16:32:44 -0500296 .name = "C7S",
Len Brown718987d2014-02-14 02:30:00 -0500297 .desc = "MWAIT 0x64",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100298 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown718987d2014-02-14 02:30:00 -0500299 .exit_latency = 10000,
300 .target_residency = 20000,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100301 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200302 .enter_s2idle = intel_idle_s2idle, },
Len Brown718987d2014-02-14 02:30:00 -0500303 {
304 .enter = NULL }
305};
306
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100307static struct cpuidle_state cht_cstates[] __initdata = {
Len Browncab07a52015-03-27 20:54:01 -0400308 {
Len Brownde09cdd2017-02-28 16:32:44 -0500309 .name = "C1",
Len Browncab07a52015-03-27 20:54:01 -0400310 .desc = "MWAIT 0x00",
311 .flags = MWAIT2flg(0x00),
312 .exit_latency = 1,
313 .target_residency = 1,
314 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200315 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400316 {
Len Brownde09cdd2017-02-28 16:32:44 -0500317 .name = "C6N",
Len Browncab07a52015-03-27 20:54:01 -0400318 .desc = "MWAIT 0x58",
319 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
320 .exit_latency = 80,
321 .target_residency = 275,
322 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200323 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400324 {
Len Brownde09cdd2017-02-28 16:32:44 -0500325 .name = "C6S",
Len Browncab07a52015-03-27 20:54:01 -0400326 .desc = "MWAIT 0x52",
327 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
328 .exit_latency = 200,
329 .target_residency = 560,
330 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200331 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400332 {
Len Brownde09cdd2017-02-28 16:32:44 -0500333 .name = "C7",
Len Browncab07a52015-03-27 20:54:01 -0400334 .desc = "MWAIT 0x60",
335 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
336 .exit_latency = 1200,
337 .target_residency = 4000,
338 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200339 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400340 {
Len Brownde09cdd2017-02-28 16:32:44 -0500341 .name = "C7S",
Len Browncab07a52015-03-27 20:54:01 -0400342 .desc = "MWAIT 0x64",
343 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
344 .exit_latency = 10000,
345 .target_residency = 20000,
346 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200347 .enter_s2idle = intel_idle_s2idle, },
Len Browncab07a52015-03-27 20:54:01 -0400348 {
349 .enter = NULL }
350};
351
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100352static struct cpuidle_state ivb_cstates[] __initdata = {
Len Browne022e7e2013-02-01 23:37:30 -0500353 {
Len Brownde09cdd2017-02-28 16:32:44 -0500354 .name = "C1",
Len Brown6edab082012-06-01 19:45:32 -0400355 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100356 .flags = MWAIT2flg(0x00),
Len Brown6edab082012-06-01 19:45:32 -0400357 .exit_latency = 1,
358 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100359 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200360 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500361 {
Len Brownde09cdd2017-02-28 16:32:44 -0500362 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500363 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100364 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500365 .exit_latency = 10,
366 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100367 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200368 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500369 {
Len Brownde09cdd2017-02-28 16:32:44 -0500370 .name = "C3",
Len Brown6edab082012-06-01 19:45:32 -0400371 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100372 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400373 .exit_latency = 59,
374 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100375 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200376 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500377 {
Len Brownde09cdd2017-02-28 16:32:44 -0500378 .name = "C6",
Len Brown6edab082012-06-01 19:45:32 -0400379 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100380 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400381 .exit_latency = 80,
382 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100383 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200384 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500385 {
Len Brownde09cdd2017-02-28 16:32:44 -0500386 .name = "C7",
Len Brown6edab082012-06-01 19:45:32 -0400387 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100388 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown6edab082012-06-01 19:45:32 -0400389 .exit_latency = 87,
390 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100391 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200392 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500393 {
394 .enter = NULL }
Len Brown6edab082012-06-01 19:45:32 -0400395};
396
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100397static struct cpuidle_state ivt_cstates[] __initdata = {
Len Brown0138d8f2014-04-04 01:21:07 -0400398 {
Len Brownde09cdd2017-02-28 16:32:44 -0500399 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400400 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100401 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400402 .exit_latency = 1,
403 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100404 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200405 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400406 {
Len Brownde09cdd2017-02-28 16:32:44 -0500407 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400408 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100409 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown0138d8f2014-04-04 01:21:07 -0400410 .exit_latency = 10,
411 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100412 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200413 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400414 {
Len Brownde09cdd2017-02-28 16:32:44 -0500415 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400416 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100417 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400418 .exit_latency = 59,
419 .target_residency = 156,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100420 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200421 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400422 {
Len Brownde09cdd2017-02-28 16:32:44 -0500423 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400424 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100425 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400426 .exit_latency = 82,
427 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100428 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200429 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400430 {
431 .enter = NULL }
432};
433
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100434static struct cpuidle_state ivt_cstates_4s[] __initdata = {
Len Brown0138d8f2014-04-04 01:21:07 -0400435 {
Len Brownde09cdd2017-02-28 16:32:44 -0500436 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400437 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100438 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400439 .exit_latency = 1,
440 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100441 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200442 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400443 {
Len Brownde09cdd2017-02-28 16:32:44 -0500444 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400445 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100446 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown0138d8f2014-04-04 01:21:07 -0400447 .exit_latency = 10,
448 .target_residency = 250,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100449 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200450 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400451 {
Len Brownde09cdd2017-02-28 16:32:44 -0500452 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400453 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100454 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400455 .exit_latency = 59,
456 .target_residency = 300,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100457 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200458 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400459 {
Len Brownde09cdd2017-02-28 16:32:44 -0500460 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400461 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100462 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400463 .exit_latency = 84,
464 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100465 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200466 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400467 {
468 .enter = NULL }
469};
470
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100471static struct cpuidle_state ivt_cstates_8s[] __initdata = {
Len Brown0138d8f2014-04-04 01:21:07 -0400472 {
Len Brownde09cdd2017-02-28 16:32:44 -0500473 .name = "C1",
Len Brown0138d8f2014-04-04 01:21:07 -0400474 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100475 .flags = MWAIT2flg(0x00),
Len Brown0138d8f2014-04-04 01:21:07 -0400476 .exit_latency = 1,
477 .target_residency = 1,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100478 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200479 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400480 {
Len Brownde09cdd2017-02-28 16:32:44 -0500481 .name = "C1E",
Len Brown0138d8f2014-04-04 01:21:07 -0400482 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100483 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown0138d8f2014-04-04 01:21:07 -0400484 .exit_latency = 10,
485 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100486 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200487 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400488 {
Len Brownde09cdd2017-02-28 16:32:44 -0500489 .name = "C3",
Len Brown0138d8f2014-04-04 01:21:07 -0400490 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100491 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400492 .exit_latency = 59,
493 .target_residency = 600,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100494 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200495 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400496 {
Len Brownde09cdd2017-02-28 16:32:44 -0500497 .name = "C6",
Len Brown0138d8f2014-04-04 01:21:07 -0400498 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100499 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown0138d8f2014-04-04 01:21:07 -0400500 .exit_latency = 88,
501 .target_residency = 700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100502 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200503 .enter_s2idle = intel_idle_s2idle, },
Len Brown0138d8f2014-04-04 01:21:07 -0400504 {
505 .enter = NULL }
506};
507
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100508static struct cpuidle_state hsw_cstates[] __initdata = {
Len Browne022e7e2013-02-01 23:37:30 -0500509 {
Len Brownde09cdd2017-02-28 16:32:44 -0500510 .name = "C1",
Len Brown85a4d2d2013-01-31 14:40:49 -0500511 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100512 .flags = MWAIT2flg(0x00),
Len Brown85a4d2d2013-01-31 14:40:49 -0500513 .exit_latency = 2,
514 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100515 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200516 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500517 {
Len Brownde09cdd2017-02-28 16:32:44 -0500518 .name = "C1E",
Len Brown32e95182013-02-02 01:31:56 -0500519 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100520 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown32e95182013-02-02 01:31:56 -0500521 .exit_latency = 10,
522 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100523 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200524 .enter_s2idle = intel_idle_s2idle, },
Len Brown32e95182013-02-02 01:31:56 -0500525 {
Len Brownde09cdd2017-02-28 16:32:44 -0500526 .name = "C3",
Len Brown85a4d2d2013-01-31 14:40:49 -0500527 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100528 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500529 .exit_latency = 33,
530 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100531 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200532 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500533 {
Len Brownde09cdd2017-02-28 16:32:44 -0500534 .name = "C6",
Len Brown85a4d2d2013-01-31 14:40:49 -0500535 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100536 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500537 .exit_latency = 133,
538 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100539 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200540 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500541 {
Len Brownde09cdd2017-02-28 16:32:44 -0500542 .name = "C7s",
Len Brown85a4d2d2013-01-31 14:40:49 -0500543 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100544 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown85a4d2d2013-01-31 14:40:49 -0500545 .exit_latency = 166,
546 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100547 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200548 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500549 {
Len Brownde09cdd2017-02-28 16:32:44 -0500550 .name = "C8",
Len Brown86239ce2013-02-27 13:18:50 -0500551 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100552 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500553 .exit_latency = 300,
554 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100555 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200556 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500557 {
Len Brownde09cdd2017-02-28 16:32:44 -0500558 .name = "C9",
Len Brown86239ce2013-02-27 13:18:50 -0500559 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100560 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500561 .exit_latency = 600,
562 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100563 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200564 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500565 {
Len Brownde09cdd2017-02-28 16:32:44 -0500566 .name = "C10",
Len Brown86239ce2013-02-27 13:18:50 -0500567 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100568 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown86239ce2013-02-27 13:18:50 -0500569 .exit_latency = 2600,
570 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100571 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200572 .enter_s2idle = intel_idle_s2idle, },
Len Brown86239ce2013-02-27 13:18:50 -0500573 {
Len Browne022e7e2013-02-01 23:37:30 -0500574 .enter = NULL }
Len Brown85a4d2d2013-01-31 14:40:49 -0500575};
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100576static struct cpuidle_state bdw_cstates[] __initdata = {
Len Browna138b562014-02-04 23:56:40 -0500577 {
Len Brownde09cdd2017-02-28 16:32:44 -0500578 .name = "C1",
Len Browna138b562014-02-04 23:56:40 -0500579 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100580 .flags = MWAIT2flg(0x00),
Len Browna138b562014-02-04 23:56:40 -0500581 .exit_latency = 2,
582 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100583 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200584 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500585 {
Len Brownde09cdd2017-02-28 16:32:44 -0500586 .name = "C1E",
Len Browna138b562014-02-04 23:56:40 -0500587 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100588 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Browna138b562014-02-04 23:56:40 -0500589 .exit_latency = 10,
590 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100591 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200592 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500593 {
Len Brownde09cdd2017-02-28 16:32:44 -0500594 .name = "C3",
Len Browna138b562014-02-04 23:56:40 -0500595 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100596 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500597 .exit_latency = 40,
598 .target_residency = 100,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100599 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200600 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500601 {
Len Brownde09cdd2017-02-28 16:32:44 -0500602 .name = "C6",
Len Browna138b562014-02-04 23:56:40 -0500603 .desc = "MWAIT 0x20",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100604 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500605 .exit_latency = 133,
606 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100607 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200608 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500609 {
Len Brownde09cdd2017-02-28 16:32:44 -0500610 .name = "C7s",
Len Browna138b562014-02-04 23:56:40 -0500611 .desc = "MWAIT 0x32",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100612 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500613 .exit_latency = 166,
614 .target_residency = 500,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100615 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200616 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500617 {
Len Brownde09cdd2017-02-28 16:32:44 -0500618 .name = "C8",
Len Browna138b562014-02-04 23:56:40 -0500619 .desc = "MWAIT 0x40",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100620 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500621 .exit_latency = 300,
622 .target_residency = 900,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100623 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200624 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500625 {
Len Brownde09cdd2017-02-28 16:32:44 -0500626 .name = "C9",
Len Browna138b562014-02-04 23:56:40 -0500627 .desc = "MWAIT 0x50",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100628 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500629 .exit_latency = 600,
630 .target_residency = 1800,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100631 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200632 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500633 {
Len Brownde09cdd2017-02-28 16:32:44 -0500634 .name = "C10",
Len Browna138b562014-02-04 23:56:40 -0500635 .desc = "MWAIT 0x60",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100636 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Browna138b562014-02-04 23:56:40 -0500637 .exit_latency = 2600,
638 .target_residency = 7700,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100639 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200640 .enter_s2idle = intel_idle_s2idle, },
Len Browna138b562014-02-04 23:56:40 -0500641 {
642 .enter = NULL }
643};
Len Brown85a4d2d2013-01-31 14:40:49 -0500644
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100645static struct cpuidle_state skl_cstates[] __initdata = {
Len Brown493f1332015-03-25 23:20:37 -0400646 {
Len Brownde09cdd2017-02-28 16:32:44 -0500647 .name = "C1",
Len Brown493f1332015-03-25 23:20:37 -0400648 .desc = "MWAIT 0x00",
649 .flags = MWAIT2flg(0x00),
650 .exit_latency = 2,
651 .target_residency = 2,
652 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200653 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400654 {
Len Brownde09cdd2017-02-28 16:32:44 -0500655 .name = "C1E",
Len Brown493f1332015-03-25 23:20:37 -0400656 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100657 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown493f1332015-03-25 23:20:37 -0400658 .exit_latency = 10,
659 .target_residency = 20,
660 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200661 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400662 {
Len Brownde09cdd2017-02-28 16:32:44 -0500663 .name = "C3",
Len Brown493f1332015-03-25 23:20:37 -0400664 .desc = "MWAIT 0x10",
665 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
666 .exit_latency = 70,
667 .target_residency = 100,
668 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200669 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400670 {
Len Brownde09cdd2017-02-28 16:32:44 -0500671 .name = "C6",
Len Brown493f1332015-03-25 23:20:37 -0400672 .desc = "MWAIT 0x20",
673 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400674 .exit_latency = 85,
Len Brown493f1332015-03-25 23:20:37 -0400675 .target_residency = 200,
676 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200677 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400678 {
Len Brownde09cdd2017-02-28 16:32:44 -0500679 .name = "C7s",
Len Brown493f1332015-03-25 23:20:37 -0400680 .desc = "MWAIT 0x33",
681 .flags = MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED,
682 .exit_latency = 124,
683 .target_residency = 800,
684 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200685 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400686 {
Len Brownde09cdd2017-02-28 16:32:44 -0500687 .name = "C8",
Len Brown493f1332015-03-25 23:20:37 -0400688 .desc = "MWAIT 0x40",
689 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown135919a2015-09-09 13:35:05 -0400690 .exit_latency = 200,
Len Brown493f1332015-03-25 23:20:37 -0400691 .target_residency = 800,
692 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200693 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400694 {
Len Brownde09cdd2017-02-28 16:32:44 -0500695 .name = "C9",
Len Brown135919a2015-09-09 13:35:05 -0400696 .desc = "MWAIT 0x50",
697 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
698 .exit_latency = 480,
699 .target_residency = 5000,
700 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200701 .enter_s2idle = intel_idle_s2idle, },
Len Brown135919a2015-09-09 13:35:05 -0400702 {
Len Brownde09cdd2017-02-28 16:32:44 -0500703 .name = "C10",
Len Brown493f1332015-03-25 23:20:37 -0400704 .desc = "MWAIT 0x60",
705 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
706 .exit_latency = 890,
707 .target_residency = 5000,
708 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200709 .enter_s2idle = intel_idle_s2idle, },
Len Brown493f1332015-03-25 23:20:37 -0400710 {
711 .enter = NULL }
712};
713
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100714static struct cpuidle_state skx_cstates[] __initdata = {
Len Brownf9e71652016-04-06 17:00:58 -0400715 {
Len Brownde09cdd2017-02-28 16:32:44 -0500716 .name = "C1",
Len Brownf9e71652016-04-06 17:00:58 -0400717 .desc = "MWAIT 0x00",
718 .flags = MWAIT2flg(0x00),
719 .exit_latency = 2,
720 .target_residency = 2,
721 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200722 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400723 {
Len Brownde09cdd2017-02-28 16:32:44 -0500724 .name = "C1E",
Len Brownf9e71652016-04-06 17:00:58 -0400725 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100726 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brownf9e71652016-04-06 17:00:58 -0400727 .exit_latency = 10,
728 .target_residency = 20,
729 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200730 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400731 {
Len Brownde09cdd2017-02-28 16:32:44 -0500732 .name = "C6",
Len Brownf9e71652016-04-06 17:00:58 -0400733 .desc = "MWAIT 0x20",
734 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
735 .exit_latency = 133,
736 .target_residency = 600,
737 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200738 .enter_s2idle = intel_idle_s2idle, },
Len Brownf9e71652016-04-06 17:00:58 -0400739 {
740 .enter = NULL }
741};
742
Chen Yua472ad22020-07-10 12:12:01 +0800743static struct cpuidle_state icx_cstates[] __initdata = {
744 {
745 .name = "C1",
746 .desc = "MWAIT 0x00",
747 .flags = MWAIT2flg(0x00),
748 .exit_latency = 1,
749 .target_residency = 1,
750 .enter = &intel_idle,
751 .enter_s2idle = intel_idle_s2idle, },
752 {
753 .name = "C1E",
754 .desc = "MWAIT 0x01",
755 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
756 .exit_latency = 4,
757 .target_residency = 4,
758 .enter = &intel_idle,
759 .enter_s2idle = intel_idle_s2idle, },
760 {
761 .name = "C6",
762 .desc = "MWAIT 0x20",
763 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
764 .exit_latency = 128,
765 .target_residency = 384,
766 .enter = &intel_idle,
767 .enter_s2idle = intel_idle_s2idle, },
768 {
769 .enter = NULL }
770};
771
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100772static struct cpuidle_state atom_cstates[] __initdata = {
Len Browne022e7e2013-02-01 23:37:30 -0500773 {
Len Brownde09cdd2017-02-28 16:32:44 -0500774 .name = "C1E",
Len Brown26717172010-03-08 14:07:30 -0500775 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100776 .flags = MWAIT2flg(0x00),
Len Brown32e95182013-02-02 01:31:56 -0500777 .exit_latency = 10,
778 .target_residency = 20,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100779 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200780 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500781 {
Len Brownde09cdd2017-02-28 16:32:44 -0500782 .name = "C2",
Len Brown26717172010-03-08 14:07:30 -0500783 .desc = "MWAIT 0x10",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100784 .flags = MWAIT2flg(0x10),
Len Brown26717172010-03-08 14:07:30 -0500785 .exit_latency = 20,
Len Brown26717172010-03-08 14:07:30 -0500786 .target_residency = 80,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100787 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200788 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500789 {
Len Brownde09cdd2017-02-28 16:32:44 -0500790 .name = "C4",
Len Brown26717172010-03-08 14:07:30 -0500791 .desc = "MWAIT 0x30",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100792 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown26717172010-03-08 14:07:30 -0500793 .exit_latency = 100,
Len Brown26717172010-03-08 14:07:30 -0500794 .target_residency = 400,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100795 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200796 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500797 {
Len Brownde09cdd2017-02-28 16:32:44 -0500798 .name = "C6",
Len Brown7fcca7d2010-10-05 13:43:14 -0400799 .desc = "MWAIT 0x52",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100800 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brown7fcca7d2010-10-05 13:43:14 -0400801 .exit_latency = 140,
Len Brown7fcca7d2010-10-05 13:43:14 -0400802 .target_residency = 560,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100803 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200804 .enter_s2idle = intel_idle_s2idle, },
Len Browne022e7e2013-02-01 23:37:30 -0500805 {
806 .enter = NULL }
Len Brown26717172010-03-08 14:07:30 -0500807};
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100808static struct cpuidle_state tangier_cstates[] __initdata = {
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300809 {
Len Brownde09cdd2017-02-28 16:32:44 -0500810 .name = "C1",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300811 .desc = "MWAIT 0x00",
812 .flags = MWAIT2flg(0x00),
813 .exit_latency = 1,
814 .target_residency = 4,
815 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200816 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300817 {
Len Brownde09cdd2017-02-28 16:32:44 -0500818 .name = "C4",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300819 .desc = "MWAIT 0x30",
820 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
821 .exit_latency = 100,
822 .target_residency = 400,
823 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200824 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300825 {
Len Brownde09cdd2017-02-28 16:32:44 -0500826 .name = "C6",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300827 .desc = "MWAIT 0x52",
828 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
829 .exit_latency = 140,
830 .target_residency = 560,
831 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200832 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300833 {
Len Brownde09cdd2017-02-28 16:32:44 -0500834 .name = "C7",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300835 .desc = "MWAIT 0x60",
836 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
837 .exit_latency = 1200,
838 .target_residency = 4000,
839 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200840 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300841 {
Len Brownde09cdd2017-02-28 16:32:44 -0500842 .name = "C9",
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300843 .desc = "MWAIT 0x64",
844 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
845 .exit_latency = 10000,
846 .target_residency = 20000,
847 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200848 .enter_s2idle = intel_idle_s2idle, },
Andy Shevchenko5e7ec262016-10-25 17:11:39 +0300849 {
850 .enter = NULL }
851};
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100852static struct cpuidle_state avn_cstates[] __initdata = {
Len Brownfab04b22013-11-09 00:30:17 -0500853 {
Len Brownde09cdd2017-02-28 16:32:44 -0500854 .name = "C1",
Len Brownfab04b22013-11-09 00:30:17 -0500855 .desc = "MWAIT 0x00",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100856 .flags = MWAIT2flg(0x00),
Len Brownfab04b22013-11-09 00:30:17 -0500857 .exit_latency = 2,
858 .target_residency = 2,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100859 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200860 .enter_s2idle = intel_idle_s2idle, },
Len Brownfab04b22013-11-09 00:30:17 -0500861 {
Len Brownde09cdd2017-02-28 16:32:44 -0500862 .name = "C6",
Len Brownfab04b22013-11-09 00:30:17 -0500863 .desc = "MWAIT 0x51",
Daniel Lezcanob82b6cc2014-11-12 16:03:50 +0100864 .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
Len Brownfab04b22013-11-09 00:30:17 -0500865 .exit_latency = 15,
866 .target_residency = 45,
Rafael J. Wysocki5fe2e522015-02-11 05:04:17 +0100867 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200868 .enter_s2idle = intel_idle_s2idle, },
Jiang Liu88390992014-01-09 15:30:27 +0800869 {
870 .enter = NULL }
Len Brownfab04b22013-11-09 00:30:17 -0500871};
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100872static struct cpuidle_state knl_cstates[] __initdata = {
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700873 {
Len Brownde09cdd2017-02-28 16:32:44 -0500874 .name = "C1",
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700875 .desc = "MWAIT 0x00",
876 .flags = MWAIT2flg(0x00),
877 .exit_latency = 1,
878 .target_residency = 2,
879 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200880 .enter_s2idle = intel_idle_s2idle },
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700881 {
Len Brownde09cdd2017-02-28 16:32:44 -0500882 .name = "C6",
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700883 .desc = "MWAIT 0x10",
884 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
885 .exit_latency = 120,
886 .target_residency = 500,
887 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200888 .enter_s2idle = intel_idle_s2idle },
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -0700889 {
890 .enter = NULL }
891};
Len Brown26717172010-03-08 14:07:30 -0500892
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100893static struct cpuidle_state bxt_cstates[] __initdata = {
Len Brown5dcef692016-04-06 17:00:47 -0400894 {
Len Brownde09cdd2017-02-28 16:32:44 -0500895 .name = "C1",
Len Brown5dcef692016-04-06 17:00:47 -0400896 .desc = "MWAIT 0x00",
897 .flags = MWAIT2flg(0x00),
898 .exit_latency = 2,
899 .target_residency = 2,
900 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200901 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400902 {
Len Brownde09cdd2017-02-28 16:32:44 -0500903 .name = "C1E",
Len Brown5dcef692016-04-06 17:00:47 -0400904 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100905 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Len Brown5dcef692016-04-06 17:00:47 -0400906 .exit_latency = 10,
907 .target_residency = 20,
908 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200909 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400910 {
Len Brownde09cdd2017-02-28 16:32:44 -0500911 .name = "C6",
Len Brown5dcef692016-04-06 17:00:47 -0400912 .desc = "MWAIT 0x20",
913 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
914 .exit_latency = 133,
915 .target_residency = 133,
916 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200917 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400918 {
Len Brownde09cdd2017-02-28 16:32:44 -0500919 .name = "C7s",
Len Brown5dcef692016-04-06 17:00:47 -0400920 .desc = "MWAIT 0x31",
921 .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
922 .exit_latency = 155,
923 .target_residency = 155,
924 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200925 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400926 {
Len Brownde09cdd2017-02-28 16:32:44 -0500927 .name = "C8",
Len Brown5dcef692016-04-06 17:00:47 -0400928 .desc = "MWAIT 0x40",
929 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
930 .exit_latency = 1000,
931 .target_residency = 1000,
932 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200933 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400934 {
Len Brownde09cdd2017-02-28 16:32:44 -0500935 .name = "C9",
Len Brown5dcef692016-04-06 17:00:47 -0400936 .desc = "MWAIT 0x50",
937 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
938 .exit_latency = 2000,
939 .target_residency = 2000,
940 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200941 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400942 {
Len Brownde09cdd2017-02-28 16:32:44 -0500943 .name = "C10",
Len Brown5dcef692016-04-06 17:00:47 -0400944 .desc = "MWAIT 0x60",
945 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
946 .exit_latency = 10000,
947 .target_residency = 10000,
948 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200949 .enter_s2idle = intel_idle_s2idle, },
Len Brown5dcef692016-04-06 17:00:47 -0400950 {
951 .enter = NULL }
952};
953
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100954static struct cpuidle_state dnv_cstates[] __initdata = {
Jacob Pan0080d652016-06-17 01:28:34 -0400955 {
Len Brownde09cdd2017-02-28 16:32:44 -0500956 .name = "C1",
Jacob Pan0080d652016-06-17 01:28:34 -0400957 .desc = "MWAIT 0x00",
958 .flags = MWAIT2flg(0x00),
959 .exit_latency = 2,
960 .target_residency = 2,
961 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200962 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400963 {
Len Brownde09cdd2017-02-28 16:32:44 -0500964 .name = "C1E",
Jacob Pan0080d652016-06-17 01:28:34 -0400965 .desc = "MWAIT 0x01",
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100966 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
Jacob Pan0080d652016-06-17 01:28:34 -0400967 .exit_latency = 10,
968 .target_residency = 20,
969 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200970 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400971 {
Len Brownde09cdd2017-02-28 16:32:44 -0500972 .name = "C6",
Jacob Pan0080d652016-06-17 01:28:34 -0400973 .desc = "MWAIT 0x20",
974 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
975 .exit_latency = 50,
976 .target_residency = 500,
977 .enter = &intel_idle,
Rafael J. Wysocki28ba0862017-08-10 00:14:45 +0200978 .enter_s2idle = intel_idle_s2idle, },
Jacob Pan0080d652016-06-17 01:28:34 -0400979 {
980 .enter = NULL }
981};
982
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100983static const struct idle_cpu idle_cpu_nehalem __initconst = {
Andi Kleenb66b8b92012-01-26 00:09:07 +0100984 .state_table = nehalem_cstates,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100985 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
Len Brown32e95182013-02-02 01:31:56 -0500986 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +0100987};
988
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100989static const struct idle_cpu idle_cpu_nhx __initconst = {
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +0100990 .state_table = nehalem_cstates,
991 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
992 .disable_promotion_to_c1e = true,
993 .use_acpi = true,
994};
995
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +0100996static const struct idle_cpu idle_cpu_atom __initconst = {
Andi Kleenb66b8b92012-01-26 00:09:07 +0100997 .state_table = atom_cstates,
998};
999
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001000static const struct idle_cpu idle_cpu_tangier __initconst = {
Andy Shevchenko5e7ec262016-10-25 17:11:39 +03001001 .state_table = tangier_cstates,
1002};
1003
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001004static const struct idle_cpu idle_cpu_lincroft __initconst = {
Andi Kleenb66b8b92012-01-26 00:09:07 +01001005 .state_table = atom_cstates,
1006 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
1007};
1008
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001009static const struct idle_cpu idle_cpu_snb __initconst = {
Andi Kleenb66b8b92012-01-26 00:09:07 +01001010 .state_table = snb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001011 .disable_promotion_to_c1e = true,
Andi Kleenb66b8b92012-01-26 00:09:07 +01001012};
1013
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001014static const struct idle_cpu idle_cpu_snx __initconst = {
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001015 .state_table = snb_cstates,
1016 .disable_promotion_to_c1e = true,
1017 .use_acpi = true,
1018};
1019
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001020static const struct idle_cpu idle_cpu_byt __initconst = {
Len Brown718987d2014-02-14 02:30:00 -05001021 .state_table = byt_cstates,
1022 .disable_promotion_to_c1e = true,
Len Brown8c058d532014-07-31 15:21:24 -04001023 .byt_auto_demotion_disable_flag = true,
Len Brown718987d2014-02-14 02:30:00 -05001024};
1025
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001026static const struct idle_cpu idle_cpu_cht __initconst = {
Len Browncab07a52015-03-27 20:54:01 -04001027 .state_table = cht_cstates,
1028 .disable_promotion_to_c1e = true,
1029 .byt_auto_demotion_disable_flag = true,
1030};
1031
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001032static const struct idle_cpu idle_cpu_ivb __initconst = {
Len Brown6edab082012-06-01 19:45:32 -04001033 .state_table = ivb_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001034 .disable_promotion_to_c1e = true,
Len Brown6edab082012-06-01 19:45:32 -04001035};
1036
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001037static const struct idle_cpu idle_cpu_ivt __initconst = {
Len Brown0138d8f2014-04-04 01:21:07 -04001038 .state_table = ivt_cstates,
1039 .disable_promotion_to_c1e = true,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001040 .use_acpi = true,
Len Brown0138d8f2014-04-04 01:21:07 -04001041};
1042
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001043static const struct idle_cpu idle_cpu_hsw __initconst = {
Len Brown85a4d2d2013-01-31 14:40:49 -05001044 .state_table = hsw_cstates,
Len Brown32e95182013-02-02 01:31:56 -05001045 .disable_promotion_to_c1e = true,
Len Brown85a4d2d2013-01-31 14:40:49 -05001046};
1047
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001048static const struct idle_cpu idle_cpu_hsx __initconst = {
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001049 .state_table = hsw_cstates,
1050 .disable_promotion_to_c1e = true,
1051 .use_acpi = true,
1052};
1053
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001054static const struct idle_cpu idle_cpu_bdw __initconst = {
Len Browna138b562014-02-04 23:56:40 -05001055 .state_table = bdw_cstates,
1056 .disable_promotion_to_c1e = true,
1057};
1058
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001059static const struct idle_cpu idle_cpu_bdx __initconst = {
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001060 .state_table = bdw_cstates,
1061 .disable_promotion_to_c1e = true,
1062 .use_acpi = true,
1063};
1064
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001065static const struct idle_cpu idle_cpu_skl __initconst = {
Len Brown493f1332015-03-25 23:20:37 -04001066 .state_table = skl_cstates,
1067 .disable_promotion_to_c1e = true,
1068};
1069
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001070static const struct idle_cpu idle_cpu_skx __initconst = {
Len Brownf9e71652016-04-06 17:00:58 -04001071 .state_table = skx_cstates,
1072 .disable_promotion_to_c1e = true,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001073 .use_acpi = true,
Len Brownf9e71652016-04-06 17:00:58 -04001074};
Len Brown493f1332015-03-25 23:20:37 -04001075
Chen Yua472ad22020-07-10 12:12:01 +08001076static const struct idle_cpu idle_cpu_icx __initconst = {
1077 .state_table = icx_cstates,
1078 .disable_promotion_to_c1e = true,
1079 .use_acpi = true,
1080};
1081
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001082static const struct idle_cpu idle_cpu_avn __initconst = {
Len Brownfab04b22013-11-09 00:30:17 -05001083 .state_table = avn_cstates,
1084 .disable_promotion_to_c1e = true,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001085 .use_acpi = true,
Len Brownfab04b22013-11-09 00:30:17 -05001086};
1087
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001088static const struct idle_cpu idle_cpu_knl __initconst = {
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001089 .state_table = knl_cstates,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001090 .use_acpi = true,
Dasaratharaman Chandramouli281baf72014-09-04 17:22:54 -07001091};
1092
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001093static const struct idle_cpu idle_cpu_bxt __initconst = {
Len Brown5dcef692016-04-06 17:00:47 -04001094 .state_table = bxt_cstates,
1095 .disable_promotion_to_c1e = true,
1096};
1097
Rafael J. Wysockiab1a85222020-02-06 18:45:06 +01001098static const struct idle_cpu idle_cpu_dnv __initconst = {
Jacob Pan0080d652016-06-17 01:28:34 -04001099 .state_table = dnv_cstates,
1100 .disable_promotion_to_c1e = true,
Rafael J. Wysockie6d4f082019-12-13 09:56:38 +01001101 .use_acpi = true,
Jacob Pan0080d652016-06-17 01:28:34 -04001102};
1103
Mathias Kraused5cdc3c2015-03-25 22:15:14 +01001104static const struct x86_cpu_id intel_idle_ids[] __initconst = {
Thomas Gleixner4a9f45a2020-03-20 14:14:00 +01001105 X86_MATCH_INTEL_FAM6_MODEL(NEHALEM_EP, &idle_cpu_nhx),
1106 X86_MATCH_INTEL_FAM6_MODEL(NEHALEM, &idle_cpu_nehalem),
1107 X86_MATCH_INTEL_FAM6_MODEL(NEHALEM_G, &idle_cpu_nehalem),
1108 X86_MATCH_INTEL_FAM6_MODEL(WESTMERE, &idle_cpu_nehalem),
1109 X86_MATCH_INTEL_FAM6_MODEL(WESTMERE_EP, &idle_cpu_nhx),
1110 X86_MATCH_INTEL_FAM6_MODEL(NEHALEM_EX, &idle_cpu_nhx),
1111 X86_MATCH_INTEL_FAM6_MODEL(ATOM_BONNELL, &idle_cpu_atom),
1112 X86_MATCH_INTEL_FAM6_MODEL(ATOM_BONNELL_MID, &idle_cpu_lincroft),
1113 X86_MATCH_INTEL_FAM6_MODEL(WESTMERE_EX, &idle_cpu_nhx),
1114 X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE, &idle_cpu_snb),
1115 X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE_X, &idle_cpu_snx),
1116 X86_MATCH_INTEL_FAM6_MODEL(ATOM_SALTWELL, &idle_cpu_atom),
1117 X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT, &idle_cpu_byt),
1118 X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT_MID, &idle_cpu_tangier),
1119 X86_MATCH_INTEL_FAM6_MODEL(ATOM_AIRMONT, &idle_cpu_cht),
1120 X86_MATCH_INTEL_FAM6_MODEL(IVYBRIDGE, &idle_cpu_ivb),
1121 X86_MATCH_INTEL_FAM6_MODEL(IVYBRIDGE_X, &idle_cpu_ivt),
1122 X86_MATCH_INTEL_FAM6_MODEL(HASWELL, &idle_cpu_hsw),
1123 X86_MATCH_INTEL_FAM6_MODEL(HASWELL_X, &idle_cpu_hsx),
1124 X86_MATCH_INTEL_FAM6_MODEL(HASWELL_L, &idle_cpu_hsw),
1125 X86_MATCH_INTEL_FAM6_MODEL(HASWELL_G, &idle_cpu_hsw),
1126 X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT_D, &idle_cpu_avn),
1127 X86_MATCH_INTEL_FAM6_MODEL(BROADWELL, &idle_cpu_bdw),
1128 X86_MATCH_INTEL_FAM6_MODEL(BROADWELL_G, &idle_cpu_bdw),
1129 X86_MATCH_INTEL_FAM6_MODEL(BROADWELL_X, &idle_cpu_bdx),
1130 X86_MATCH_INTEL_FAM6_MODEL(BROADWELL_D, &idle_cpu_bdx),
1131 X86_MATCH_INTEL_FAM6_MODEL(SKYLAKE_L, &idle_cpu_skl),
1132 X86_MATCH_INTEL_FAM6_MODEL(SKYLAKE, &idle_cpu_skl),
1133 X86_MATCH_INTEL_FAM6_MODEL(KABYLAKE_L, &idle_cpu_skl),
1134 X86_MATCH_INTEL_FAM6_MODEL(KABYLAKE, &idle_cpu_skl),
1135 X86_MATCH_INTEL_FAM6_MODEL(SKYLAKE_X, &idle_cpu_skx),
Chen Yua472ad22020-07-10 12:12:01 +08001136 X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, &idle_cpu_icx),
Thomas Gleixner4a9f45a2020-03-20 14:14:00 +01001137 X86_MATCH_INTEL_FAM6_MODEL(XEON_PHI_KNL, &idle_cpu_knl),
1138 X86_MATCH_INTEL_FAM6_MODEL(XEON_PHI_KNM, &idle_cpu_knl),
1139 X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT, &idle_cpu_bxt),
1140 X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT_PLUS, &idle_cpu_bxt),
1141 X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT_D, &idle_cpu_dnv),
1142 X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_D, &idle_cpu_dnv),
Andi Kleenb66b8b92012-01-26 00:09:07 +01001143 {}
1144};
Andi Kleenb66b8b92012-01-26 00:09:07 +01001145
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001146static const struct x86_cpu_id intel_mwait_ids[] __initconst = {
Thomas Gleixner4a9f45a2020-03-20 14:14:00 +01001147 X86_MATCH_VENDOR_FAM_FEATURE(INTEL, 6, X86_FEATURE_MWAIT, NULL),
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001148 {}
1149};
1150
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001151static bool __init intel_idle_max_cstate_reached(int cstate)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001152{
1153 if (cstate + 1 > max_cstate) {
1154 pr_info("max_cstate %d reached\n", max_cstate);
1155 return true;
1156 }
1157 return false;
1158}
1159
1160#ifdef CONFIG_ACPI_PROCESSOR_CSTATE
1161#include <acpi/processor.h>
1162
Rafael J. Wysocki4ec32d92019-12-13 09:56:29 +01001163static bool no_acpi __read_mostly;
1164module_param(no_acpi, bool, 0444);
1165MODULE_PARM_DESC(no_acpi, "Do not use ACPI _CST for building the idle states list");
1166
Rafael J. Wysocki3a5be9b2020-02-03 11:57:08 +01001167static bool force_use_acpi __read_mostly; /* No effect if no_acpi is set. */
1168module_param_named(use_acpi, force_use_acpi, bool, 0444);
1169MODULE_PARM_DESC(use_acpi, "Use ACPI _CST for building the idle states list");
1170
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001171static struct acpi_processor_power acpi_state_table __initdata;
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001172
1173/**
1174 * intel_idle_cst_usable - Check if the _CST information can be used.
1175 *
1176 * Check if all of the C-states listed by _CST in the max_cstate range are
1177 * ACPI_CSTATE_FFH, which means that they should be entered via MWAIT.
1178 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001179static bool __init intel_idle_cst_usable(void)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001180{
1181 int cstate, limit;
1182
1183 limit = min_t(int, min_t(int, CPUIDLE_STATE_MAX, max_cstate + 1),
1184 acpi_state_table.count);
1185
1186 for (cstate = 1; cstate < limit; cstate++) {
1187 struct acpi_processor_cx *cx = &acpi_state_table.states[cstate];
1188
1189 if (cx->entry_method != ACPI_CSTATE_FFH)
1190 return false;
1191 }
1192
1193 return true;
1194}
1195
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001196static bool __init intel_idle_acpi_cst_extract(void)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001197{
1198 unsigned int cpu;
1199
Rafael J. Wysocki4ec32d92019-12-13 09:56:29 +01001200 if (no_acpi) {
1201 pr_debug("Not allowed to use ACPI _CST\n");
1202 return false;
1203 }
1204
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001205 for_each_possible_cpu(cpu) {
1206 struct acpi_processor *pr = per_cpu(processors, cpu);
1207
1208 if (!pr)
1209 continue;
1210
1211 if (acpi_processor_evaluate_cst(pr->handle, cpu, &acpi_state_table))
1212 continue;
1213
1214 acpi_state_table.count++;
1215
1216 if (!intel_idle_cst_usable())
1217 continue;
1218
Mel Gorman75af76d2020-10-16 17:28:32 +02001219 if (!acpi_processor_claim_cst_control())
1220 break;
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001221
1222 return true;
1223 }
1224
Mel Gorman75af76d2020-10-16 17:28:32 +02001225 acpi_state_table.count = 0;
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001226 pr_debug("ACPI _CST not found or not usable\n");
1227 return false;
1228}
1229
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001230static void __init intel_idle_init_cstates_acpi(struct cpuidle_driver *drv)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001231{
1232 int cstate, limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
1233
1234 /*
1235 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1236 * the interesting states are ACPI_CSTATE_FFH.
1237 */
1238 for (cstate = 1; cstate < limit; cstate++) {
1239 struct acpi_processor_cx *cx;
1240 struct cpuidle_state *state;
1241
Chen Yu4e0ba552020-10-25 00:29:53 +08001242 if (intel_idle_max_cstate_reached(cstate - 1))
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001243 break;
1244
1245 cx = &acpi_state_table.states[cstate];
1246
1247 state = &drv->states[drv->state_count++];
1248
1249 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d_ACPI", cstate);
1250 strlcpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
1251 state->exit_latency = cx->latency;
1252 /*
1253 * For C1-type C-states use the same number for both the exit
1254 * latency and target residency, because that is the case for
1255 * C1 in the majority of the static C-states tables above.
1256 * For the other types of C-states, however, set the target
1257 * residency to 3 times the exit latency which should lead to
1258 * a reasonable balance between energy-efficiency and
1259 * performance in the majority of interesting cases.
1260 */
1261 state->target_residency = cx->latency;
1262 if (cx->type > ACPI_STATE_C1)
1263 state->target_residency *= 3;
1264
1265 state->flags = MWAIT2flg(cx->address);
1266 if (cx->type > ACPI_STATE_C2)
1267 state->flags |= CPUIDLE_FLAG_TLB_FLUSHED;
1268
Rafael J. Wysocki4dcb78e2020-02-03 11:57:18 +01001269 if (disabled_states_mask & BIT(cstate))
1270 state->flags |= CPUIDLE_FLAG_OFF;
1271
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001272 state->enter = intel_idle;
1273 state->enter_s2idle = intel_idle_s2idle;
1274 }
1275}
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001276
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001277static bool __init intel_idle_off_by_default(u32 mwait_hint)
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001278{
1279 int cstate, limit;
1280
1281 /*
1282 * If there are no _CST C-states, do not disable any C-states by
1283 * default.
1284 */
1285 if (!acpi_state_table.count)
1286 return false;
1287
1288 limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
1289 /*
1290 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1291 * the interesting states are ACPI_CSTATE_FFH.
1292 */
1293 for (cstate = 1; cstate < limit; cstate++) {
1294 if (acpi_state_table.states[cstate].address == mwait_hint)
1295 return false;
1296 }
1297 return true;
1298}
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001299#else /* !CONFIG_ACPI_PROCESSOR_CSTATE */
Rafael J. Wysocki3a5be9b2020-02-03 11:57:08 +01001300#define force_use_acpi (false)
1301
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001302static inline bool intel_idle_acpi_cst_extract(void) { return false; }
1303static inline void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) { }
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001304static inline bool intel_idle_off_by_default(u32 mwait_hint) { return false; }
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001305#endif /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1306
Rafael J. Wysocki6eacb152020-02-06 18:45:29 +01001307/**
1308 * ivt_idle_state_table_update - Tune the idle states table for Ivy Town.
Len Brownd70e28f2016-03-13 00:33:48 -05001309 *
Rafael J. Wysocki6eacb152020-02-06 18:45:29 +01001310 * Tune IVT multi-socket targets.
1311 * Assumption: num_sockets == (max_package_num + 1).
Len Brownd70e28f2016-03-13 00:33:48 -05001312 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001313static void __init ivt_idle_state_table_update(void)
Len Brownd70e28f2016-03-13 00:33:48 -05001314{
1315 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1316 int cpu, package_num, num_sockets = 1;
1317
1318 for_each_online_cpu(cpu) {
1319 package_num = topology_physical_package_id(cpu);
1320 if (package_num + 1 > num_sockets) {
1321 num_sockets = package_num + 1;
1322
1323 if (num_sockets > 4) {
1324 cpuidle_state_table = ivt_cstates_8s;
1325 return;
1326 }
1327 }
1328 }
1329
1330 if (num_sockets > 2)
1331 cpuidle_state_table = ivt_cstates_4s;
1332
1333 /* else, 1 and 2 socket systems use default ivt_cstates */
1334}
Len Brown5dcef692016-04-06 17:00:47 -04001335
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001336/**
1337 * irtl_2_usec - IRTL to microseconds conversion.
1338 * @irtl: IRTL MSR value.
1339 *
1340 * Translate the IRTL (Interrupt Response Time Limit) MSR value to microseconds.
Len Brown5dcef692016-04-06 17:00:47 -04001341 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001342static unsigned long long __init irtl_2_usec(unsigned long long irtl)
Len Brown5dcef692016-04-06 17:00:47 -04001343{
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001344 static const unsigned int irtl_ns_units[] __initconst = {
1345 1, 32, 1024, 32768, 1048576, 33554432, 0, 0
1346 };
Len Brown5dcef692016-04-06 17:00:47 -04001347 unsigned long long ns;
1348
Jan Beulich3451ab32016-06-27 00:35:12 -06001349 if (!irtl)
1350 return 0;
1351
Jan Beulichbef45092016-06-27 00:35:48 -06001352 ns = irtl_ns_units[(irtl >> 10) & 0x7];
Len Brown5dcef692016-04-06 17:00:47 -04001353
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001354 return div_u64((irtl & 0x3FF) * ns, NSEC_PER_USEC);
Len Brown5dcef692016-04-06 17:00:47 -04001355}
Rafael J. Wysocki86e94662020-01-17 11:46:24 +01001356
Rafael J. Wysocki6eacb152020-02-06 18:45:29 +01001357/**
1358 * bxt_idle_state_table_update - Fix up the Broxton idle states table.
Len Brown5dcef692016-04-06 17:00:47 -04001359 *
Rafael J. Wysocki6eacb152020-02-06 18:45:29 +01001360 * On BXT, trust the IRTL (Interrupt Response Time Limit) MSR to show the
1361 * definitive maximum latency and use the same value for target_residency.
Len Brown5dcef692016-04-06 17:00:47 -04001362 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001363static void __init bxt_idle_state_table_update(void)
Len Brown5dcef692016-04-06 17:00:47 -04001364{
1365 unsigned long long msr;
Jan Beulich3451ab32016-06-27 00:35:12 -06001366 unsigned int usec;
Len Brown5dcef692016-04-06 17:00:47 -04001367
1368 rdmsrl(MSR_PKGC6_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001369 usec = irtl_2_usec(msr);
1370 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001371 bxt_cstates[2].exit_latency = usec;
1372 bxt_cstates[2].target_residency = usec;
1373 }
1374
1375 rdmsrl(MSR_PKGC7_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001376 usec = irtl_2_usec(msr);
1377 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001378 bxt_cstates[3].exit_latency = usec;
1379 bxt_cstates[3].target_residency = usec;
1380 }
1381
1382 rdmsrl(MSR_PKGC8_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001383 usec = irtl_2_usec(msr);
1384 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001385 bxt_cstates[4].exit_latency = usec;
1386 bxt_cstates[4].target_residency = usec;
1387 }
1388
1389 rdmsrl(MSR_PKGC9_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001390 usec = irtl_2_usec(msr);
1391 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001392 bxt_cstates[5].exit_latency = usec;
1393 bxt_cstates[5].target_residency = usec;
1394 }
1395
1396 rdmsrl(MSR_PKGC10_IRTL, msr);
Jan Beulich3451ab32016-06-27 00:35:12 -06001397 usec = irtl_2_usec(msr);
1398 if (usec) {
Len Brown5dcef692016-04-06 17:00:47 -04001399 bxt_cstates[6].exit_latency = usec;
1400 bxt_cstates[6].target_residency = usec;
1401 }
1402
1403}
Rafael J. Wysocki6eacb152020-02-06 18:45:29 +01001404
1405/**
1406 * sklh_idle_state_table_update - Fix up the Sky Lake idle states table.
Len Brownd70e28f2016-03-13 00:33:48 -05001407 *
Rafael J. Wysocki6eacb152020-02-06 18:45:29 +01001408 * On SKL-H (model 0x5e) skip C8 and C9 if C10 is enabled and SGX disabled.
Len Brownd70e28f2016-03-13 00:33:48 -05001409 */
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001410static void __init sklh_idle_state_table_update(void)
Len Brownd70e28f2016-03-13 00:33:48 -05001411{
1412 unsigned long long msr;
1413 unsigned int eax, ebx, ecx, edx;
1414
1415
1416 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1417 if (max_cstate <= 7)
1418 return;
1419
1420 /* if PC10 not present in CPUID.MWAIT.EDX */
1421 if ((mwait_substates & (0xF << 28)) == 0)
1422 return;
1423
Len Brown6cfb2372017-01-07 23:23:25 -05001424 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr);
Len Brownd70e28f2016-03-13 00:33:48 -05001425
1426 /* PC10 is not enabled in PKG C-state limit */
1427 if ((msr & 0xF) != 8)
1428 return;
1429
1430 ecx = 0;
1431 cpuid(7, &eax, &ebx, &ecx, &edx);
1432
1433 /* if SGX is present */
1434 if (ebx & (1 << 2)) {
1435
Sean Christopherson32ad73d2019-12-20 20:44:55 -08001436 rdmsrl(MSR_IA32_FEAT_CTL, msr);
Len Brownd70e28f2016-03-13 00:33:48 -05001437
1438 /* if SGX is enabled */
1439 if (msr & (1 << 18))
1440 return;
1441 }
1442
Rafael J. Wysockiba1e78a2019-11-21 19:41:51 +01001443 skl_cstates[5].flags |= CPUIDLE_FLAG_UNUSABLE; /* C8-SKL */
1444 skl_cstates[6].flags |= CPUIDLE_FLAG_UNUSABLE; /* C9-SKL */
Len Brownd70e28f2016-03-13 00:33:48 -05001445}
Len Brownd70e28f2016-03-13 00:33:48 -05001446
Rafael J. Wysocki1aefbd72020-01-10 11:52:32 +01001447static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
1448{
1449 unsigned int mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint) + 1;
1450 unsigned int num_substates = (mwait_substates >> mwait_cstate * 4) &
1451 MWAIT_SUBSTATE_MASK;
1452
1453 /* Ignore the C-state if there are NO sub-states in CPUID for it. */
1454 if (num_substates == 0)
1455 return false;
1456
1457 if (mwait_cstate > 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
1458 mark_tsc_unstable("TSC halts in idle states deeper than C2");
1459
1460 return true;
1461}
1462
Rafael J. Wysocki095928a2020-01-10 11:51:22 +01001463static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
Len Brown0138d8f2014-04-04 01:21:07 -04001464{
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001465 int cstate;
Len Brown0138d8f2014-04-04 01:21:07 -04001466
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001467 switch (boot_cpu_data.x86_model) {
Dave Hansendb73c5a2016-06-02 17:19:32 -07001468 case INTEL_FAM6_IVYBRIDGE_X:
Len Brownd70e28f2016-03-13 00:33:48 -05001469 ivt_idle_state_table_update();
1470 break;
Dave Hansendb73c5a2016-06-02 17:19:32 -07001471 case INTEL_FAM6_ATOM_GOLDMONT:
Peter Zijlstraf2c4db12018-08-07 10:17:27 -07001472 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
Len Brown5dcef692016-04-06 17:00:47 -04001473 bxt_idle_state_table_update();
1474 break;
Peter Zijlstrac66f78a2019-08-27 21:48:21 +02001475 case INTEL_FAM6_SKYLAKE:
Len Brownd70e28f2016-03-13 00:33:48 -05001476 sklh_idle_state_table_update();
1477 break;
Len Brown0138d8f2014-04-04 01:21:07 -04001478 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301479
Len Browne022e7e2013-02-01 23:37:30 -05001480 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001481 unsigned int mwait_hint;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301482
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001483 if (intel_idle_max_cstate_reached(cstate))
1484 break;
1485
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001486 if (!cpuidle_state_table[cstate].enter &&
1487 !cpuidle_state_table[cstate].enter_s2idle)
Len Browne022e7e2013-02-01 23:37:30 -05001488 break;
1489
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001490 /* If marked as unusable, skip this state. */
Rafael J. Wysockiba1e78a2019-11-21 19:41:51 +01001491 if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_UNUSABLE) {
Joe Perches654d08a2017-06-09 12:29:20 -07001492 pr_debug("state %s is disabled\n",
1493 cpuidle_state_table[cstate].name);
Len Brownd70e28f2016-03-13 00:33:48 -05001494 continue;
1495 }
1496
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001497 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
1498 if (!intel_idle_verify_cstate(mwait_hint))
1499 continue;
Len Brownd70e28f2016-03-13 00:33:48 -05001500
Rafael J. Wysocki9f3d6da2019-12-13 09:55:52 +01001501 /* Structure copy. */
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001502 drv->states[drv->state_count] = cpuidle_state_table[cstate];
1503
Rafael J. Wysocki4dcb78e2020-02-03 11:57:18 +01001504 if ((disabled_states_mask & BIT(drv->state_count)) ||
1505 ((icpu->use_acpi || force_use_acpi) &&
1506 intel_idle_off_by_default(mwait_hint) &&
1507 !(cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
Rafael J. Wysockibff8e602019-12-13 09:56:21 +01001508 drv->states[drv->state_count].flags |= CPUIDLE_FLAG_OFF;
1509
1510 drv->state_count++;
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301511 }
1512
Len Brown8c058d532014-07-31 15:21:24 -04001513 if (icpu->byt_auto_demotion_disable_flag) {
1514 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
1515 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
1516 }
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301517}
1518
Rafael J. Wysocki6eacb152020-02-06 18:45:29 +01001519/**
1520 * intel_idle_cpuidle_driver_init - Create the list of available idle states.
1521 * @drv: cpuidle driver structure to initialize.
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001522 */
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001523static void __init intel_idle_cpuidle_driver_init(struct cpuidle_driver *drv)
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001524{
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001525 cpuidle_poll_state_init(drv);
Rafael J. Wysocki4dcb78e2020-02-03 11:57:18 +01001526
1527 if (disabled_states_mask & BIT(0))
1528 drv->states[0].flags |= CPUIDLE_FLAG_OFF;
1529
Rafael J. Wysocki18734952019-12-13 09:56:01 +01001530 drv->state_count = 1;
1531
1532 if (icpu)
1533 intel_idle_init_cstates_icpu(drv);
1534 else
1535 intel_idle_init_cstates_acpi(drv);
1536}
Deepthi Dharwar46bcfad2011-10-28 16:20:42 +05301537
Rafael J. Wysocki1aefbd72020-01-10 11:52:32 +01001538static void auto_demotion_disable(void)
1539{
1540 unsigned long long msr_bits;
1541
1542 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
Rafael J. Wysocki7f843dd2020-02-06 18:41:24 +01001543 msr_bits &= ~auto_demotion_disable_flags;
Rafael J. Wysocki1aefbd72020-01-10 11:52:32 +01001544 wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
1545}
1546
1547static void c1e_promotion_disable(void)
1548{
1549 unsigned long long msr_bits;
1550
1551 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
1552 msr_bits &= ~0x2;
1553 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
1554}
1555
Rafael J. Wysocki6eacb152020-02-06 18:45:29 +01001556/**
1557 * intel_idle_cpu_init - Register the target CPU with the cpuidle core.
1558 * @cpu: CPU to initialize.
1559 *
1560 * Register a cpuidle device object for @cpu and update its MSRs in accordance
1561 * with the processor model flags.
Len Brown26717172010-03-08 14:07:30 -05001562 */
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001563static int intel_idle_cpu_init(unsigned int cpu)
Len Brown26717172010-03-08 14:07:30 -05001564{
Len Brown26717172010-03-08 14:07:30 -05001565 struct cpuidle_device *dev;
1566
Thomas Renninger65b7f832012-01-17 22:40:08 +01001567 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001568 dev->cpu = cpu;
Len Brown26717172010-03-08 14:07:30 -05001569
Thomas Renninger65b7f832012-01-17 22:40:08 +01001570 if (cpuidle_register_device(dev)) {
Joe Perches654d08a2017-06-09 12:29:20 -07001571 pr_debug("cpuidle_register_device %d failed!\n", cpu);
Thomas Renninger65b7f832012-01-17 22:40:08 +01001572 return -EIO;
Len Brown26717172010-03-08 14:07:30 -05001573 }
1574
Rafael J. Wysocki7f843dd2020-02-06 18:41:24 +01001575 if (auto_demotion_disable_flags)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001576 auto_demotion_disable();
Thomas Renninger65b7f832012-01-17 22:40:08 +01001577
Rafael J. Wysocki7f843dd2020-02-06 18:41:24 +01001578 if (disable_promotion_to_c1e)
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001579 c1e_promotion_disable();
1580
1581 return 0;
1582}
1583
1584static int intel_idle_cpu_online(unsigned int cpu)
1585{
1586 struct cpuidle_device *dev;
1587
Rafael J. Wysockidab20172020-06-29 13:58:28 +02001588 if (!boot_cpu_has(X86_FEATURE_ARAT))
Rafael J. Wysockicbd2c4c2020-01-10 11:43:23 +01001589 tick_broadcast_enable();
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001590
1591 /*
1592 * Some systems can hotplug a cpu at runtime after
1593 * the kernel has booted, we have to initialize the
1594 * driver in this case
1595 */
1596 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
1597 if (!dev->registered)
1598 return intel_idle_cpu_init(cpu);
Bartlomiej Zolnierkiewiczdbf87ab82013-12-20 19:47:28 +01001599
Len Brown26717172010-03-08 14:07:30 -05001600 return 0;
1601}
Len Brown26717172010-03-08 14:07:30 -05001602
Rafael J. Wysocki0755a9b2020-01-10 11:49:58 +01001603/**
1604 * intel_idle_cpuidle_devices_uninit - Unregister all cpuidle devices.
1605 */
1606static void __init intel_idle_cpuidle_devices_uninit(void)
1607{
1608 int i;
1609
1610 for_each_online_cpu(i)
1611 cpuidle_unregister_device(per_cpu_ptr(intel_idle_cpuidle_devices, i));
1612}
1613
Len Brown26717172010-03-08 14:07:30 -05001614static int __init intel_idle_init(void)
1615{
Rafael J. Wysockia6c86e32020-01-10 11:44:58 +01001616 const struct x86_cpu_id *id;
1617 unsigned int eax, ebx, ecx;
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001618 int retval;
Len Brown26717172010-03-08 14:07:30 -05001619
Thomas Renningerd1896042010-11-03 17:06:14 +01001620 /* Do not load intel_idle at all for now if idle= is passed */
1621 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
1622 return -ENODEV;
1623
Rafael J. Wysockia6c86e32020-01-10 11:44:58 +01001624 if (max_cstate == 0) {
1625 pr_debug("disabled\n");
1626 return -EPERM;
1627 }
1628
1629 id = x86_match_cpu(intel_idle_ids);
1630 if (id) {
1631 if (!boot_cpu_has(X86_FEATURE_MWAIT)) {
1632 pr_debug("Please enable MWAIT in BIOS SETUP\n");
1633 return -ENODEV;
1634 }
1635 } else {
1636 id = x86_match_cpu(intel_mwait_ids);
1637 if (!id)
1638 return -ENODEV;
1639 }
1640
1641 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
1642 return -ENODEV;
1643
1644 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
1645
1646 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
1647 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
1648 !mwait_substates)
1649 return -ENODEV;
1650
1651 pr_debug("MWAIT substates: 0x%x\n", mwait_substates);
1652
1653 icpu = (const struct idle_cpu *)id->driver_data;
1654 if (icpu) {
1655 cpuidle_state_table = icpu->state_table;
Rafael J. Wysocki7f843dd2020-02-06 18:41:24 +01001656 auto_demotion_disable_flags = icpu->auto_demotion_disable_flags;
1657 disable_promotion_to_c1e = icpu->disable_promotion_to_c1e;
Rafael J. Wysocki3a5be9b2020-02-03 11:57:08 +01001658 if (icpu->use_acpi || force_use_acpi)
Rafael J. Wysockia6c86e32020-01-10 11:44:58 +01001659 intel_idle_acpi_cst_extract();
1660 } else if (!intel_idle_acpi_cst_extract()) {
1661 return -ENODEV;
1662 }
1663
1664 pr_debug("v" INTEL_IDLE_VERSION " model 0x%X\n",
1665 boot_cpu_data.x86_model);
Len Brown26717172010-03-08 14:07:30 -05001666
Richard Cochrane9df69c2016-04-06 17:00:52 -04001667 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
Rafael J. Wysocki533da742020-01-10 11:45:49 +01001668 if (!intel_idle_cpuidle_devices)
Richard Cochrane9df69c2016-04-06 17:00:52 -04001669 return -ENOMEM;
1670
Rafael J. Wysocki3d3a1ae2020-01-10 11:48:25 +01001671 intel_idle_cpuidle_driver_init(&intel_idle_driver);
1672
Len Brown26717172010-03-08 14:07:30 -05001673 retval = cpuidle_register_driver(&intel_idle_driver);
1674 if (retval) {
Konrad Rzeszutek Wilk3735d522012-08-16 22:06:55 +02001675 struct cpuidle_driver *drv = cpuidle_get_driver();
Joe Perches654d08a2017-06-09 12:29:20 -07001676 printk(KERN_DEBUG pr_fmt("intel_idle yielding to %s\n"),
1677 drv ? drv->name : "none");
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001678 goto init_driver_fail;
Len Brown26717172010-03-08 14:07:30 -05001679 }
1680
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001681 retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online",
1682 intel_idle_cpu_online, NULL);
1683 if (retval < 0)
1684 goto hp_setup_fail;
Len Brown26717172010-03-08 14:07:30 -05001685
Rafael J. Wysocki40ab82e2020-02-06 18:40:54 +01001686 pr_debug("Local APIC timer is reliable in %s\n",
Rafael J. Wysockidab20172020-06-29 13:58:28 +02001687 boot_cpu_has(X86_FEATURE_ARAT) ? "all C-states" : "C1");
Richard Cochran2259a812016-04-06 17:00:54 -04001688
Len Brown26717172010-03-08 14:07:30 -05001689 return 0;
Sebastian Andrzej Siewiorfb1013a2016-11-29 10:51:43 +01001690
1691hp_setup_fail:
1692 intel_idle_cpuidle_devices_uninit();
1693 cpuidle_unregister_driver(&intel_idle_driver);
1694init_driver_fail:
1695 free_percpu(intel_idle_cpuidle_devices);
1696 return retval;
1697
Len Brown26717172010-03-08 14:07:30 -05001698}
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001699device_initcall(intel_idle_init);
Len Brown26717172010-03-08 14:07:30 -05001700
Paul Gortmaker02c4fae2016-06-17 01:28:33 -04001701/*
1702 * We are not really modular, but we used to support that. Meaning we also
1703 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
1704 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
1705 * is the easiest way (currently) to continue doing that.
1706 */
Len Brown26717172010-03-08 14:07:30 -05001707module_param(max_cstate, int, 0444);
Rafael J. Wysocki4dcb78e2020-02-03 11:57:18 +01001708/*
1709 * The positions of the bits that are set in this number are the indices of the
1710 * idle states to be disabled by default (as reflected by the names of the
1711 * corresponding idle state directories in sysfs, "state0", "state1" ...
1712 * "state<i>" ..., where <i> is the index of the given state).
1713 */
1714module_param_named(states_off, disabled_states_mask, uint, 0444);
1715MODULE_PARM_DESC(states_off, "Mask of disabled idle states");