1 // SPDX-License-Identifier: GPL-2.0-only
3 * intel_idle.c - native hardware idle loop for modern Intel processors
5 * Copyright (c) 2013 - 2020, Intel Corporation.
6 * Len Brown <len.brown@intel.com>
7 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
11 * intel_idle is a cpuidle driver that loads on all Intel CPUs with MWAIT
12 * 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.
20 * All CPUs have same idle states as boot CPU
22 * Chipset BM_STS (bus master status) bit is a NOP
23 * for preventing entry into deep C-states
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)
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.
39 /* un-comment DEBUG to enable pr_debug() statements */
42 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
44 #include <linux/acpi.h>
45 #include <linux/kernel.h>
46 #include <linux/cpuidle.h>
47 #include <linux/tick.h>
48 #include <trace/events/power.h>
49 #include <linux/sched.h>
50 #include <linux/sched/smt.h>
51 #include <linux/notifier.h>
52 #include <linux/cpu.h>
53 #include <linux/moduleparam.h>
54 #include <asm/cpu_device_id.h>
55 #include <asm/intel-family.h>
56 #include <asm/mwait.h>
57 #include <asm/spec-ctrl.h>
58 #include <asm/fpu/api.h>
60 #define INTEL_IDLE_VERSION "0.5.1"
62 static struct cpuidle_driver intel_idle_driver
= {
66 /* intel_idle.max_cstate=0 disables driver */
67 static int max_cstate
= CPUIDLE_STATE_MAX
- 1;
68 static unsigned int disabled_states_mask __read_mostly
;
69 static unsigned int preferred_states_mask __read_mostly
;
70 static bool force_irq_on __read_mostly
;
71 static bool ibrs_off __read_mostly
;
73 static struct cpuidle_device __percpu
*intel_idle_cpuidle_devices
;
75 static unsigned long auto_demotion_disable_flags
;
78 C1E_PROMOTION_PRESERVE
,
81 } c1e_promotion
= C1E_PROMOTION_PRESERVE
;
84 struct cpuidle_state
*state_table
;
87 * Hardware C-state auto-demotion may not always be optimal.
88 * Indicate which enable bits to clear here.
90 unsigned long auto_demotion_disable_flags
;
91 bool byt_auto_demotion_disable_flag
;
92 bool disable_promotion_to_c1e
;
96 static const struct idle_cpu
*icpu __initdata
;
97 static struct cpuidle_state
*cpuidle_state_table __initdata
;
99 static unsigned int mwait_substates __initdata
;
102 * Enable interrupts before entering the C-state. On some platforms and for
103 * some C-states, this may measurably decrease interrupt latency.
105 #define CPUIDLE_FLAG_IRQ_ENABLE BIT(14)
108 * Enable this state by default even if the ACPI _CST does not list it.
110 #define CPUIDLE_FLAG_ALWAYS_ENABLE BIT(15)
113 * Disable IBRS across idle (when KERNEL_IBRS), is exclusive vs IRQ_ENABLE
116 #define CPUIDLE_FLAG_IBRS BIT(16)
119 * Initialize large xstate for the C6-state entrance.
121 #define CPUIDLE_FLAG_INIT_XSTATE BIT(17)
124 * Ignore the sub-state when matching mwait hints between the ACPI _CST and
127 #define CPUIDLE_FLAG_PARTIAL_HINT_MATCH BIT(18)
130 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
131 * the C-state (top nibble) and sub-state (bottom nibble)
132 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
134 * We store the hint at the top of our "flags" for each state.
136 #define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
137 #define MWAIT2flg(eax) ((eax & 0xFF) << 24)
139 static __always_inline
int __intel_idle(struct cpuidle_device
*dev
,
140 struct cpuidle_driver
*drv
,
141 int index
, bool irqoff
)
143 struct cpuidle_state
*state
= &drv
->states
[index
];
144 unsigned long eax
= flg2MWAIT(state
->flags
);
145 unsigned long ecx
= 1*irqoff
; /* break on interrupt flag */
147 mwait_idle_with_hints(eax
, ecx
);
153 * intel_idle - 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.
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.
161 * If the local APIC timer is not known to be reliable in the target idle state,
162 * enable one-shot tick broadcasting for the target CPU before executing MWAIT.
164 * Must be called under local_irq_disable().
166 static __cpuidle
int intel_idle(struct cpuidle_device
*dev
,
167 struct cpuidle_driver
*drv
, int index
)
169 return __intel_idle(dev
, drv
, index
, true);
172 static __cpuidle
int intel_idle_irq(struct cpuidle_device
*dev
,
173 struct cpuidle_driver
*drv
, int index
)
175 return __intel_idle(dev
, drv
, index
, false);
178 static __cpuidle
int intel_idle_ibrs(struct cpuidle_device
*dev
,
179 struct cpuidle_driver
*drv
, int index
)
181 bool smt_active
= sched_smt_active();
182 u64 spec_ctrl
= spec_ctrl_current();
186 __update_spec_ctrl(0);
188 ret
= __intel_idle(dev
, drv
, index
, true);
191 __update_spec_ctrl(spec_ctrl
);
196 static __cpuidle
int intel_idle_xstate(struct cpuidle_device
*dev
,
197 struct cpuidle_driver
*drv
, int index
)
200 return __intel_idle(dev
, drv
, index
, true);
204 * intel_idle_s2idle - Ask the processor to enter the given idle state.
205 * @dev: cpuidle device of the target CPU.
206 * @drv: cpuidle driver (assumed to point to intel_idle_driver).
207 * @index: Target idle state index.
209 * Use the MWAIT instruction to notify the processor that the CPU represented by
210 * @dev is idle and it can try to enter the idle state corresponding to @index.
212 * Invoked as a suspend-to-idle callback routine with frozen user space, frozen
213 * scheduler tick and suspended scheduler clock on the target CPU.
215 static __cpuidle
int intel_idle_s2idle(struct cpuidle_device
*dev
,
216 struct cpuidle_driver
*drv
, int index
)
218 unsigned long ecx
= 1; /* break on interrupt flag */
219 struct cpuidle_state
*state
= &drv
->states
[index
];
220 unsigned long eax
= flg2MWAIT(state
->flags
);
222 if (state
->flags
& CPUIDLE_FLAG_INIT_XSTATE
)
225 mwait_idle_with_hints(eax
, ecx
);
231 * States are indexed by the cstate number,
232 * which is also the index into the MWAIT hint array.
233 * Thus C0 is a dummy.
235 static struct cpuidle_state nehalem_cstates
[] __initdata
= {
238 .desc
= "MWAIT 0x00",
239 .flags
= MWAIT2flg(0x00),
241 .target_residency
= 6,
242 .enter
= &intel_idle
,
243 .enter_s2idle
= intel_idle_s2idle
, },
246 .desc
= "MWAIT 0x01",
247 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
249 .target_residency
= 20,
250 .enter
= &intel_idle
,
251 .enter_s2idle
= intel_idle_s2idle
, },
254 .desc
= "MWAIT 0x10",
255 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
257 .target_residency
= 80,
258 .enter
= &intel_idle
,
259 .enter_s2idle
= intel_idle_s2idle
, },
262 .desc
= "MWAIT 0x20",
263 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
265 .target_residency
= 800,
266 .enter
= &intel_idle
,
267 .enter_s2idle
= intel_idle_s2idle
, },
272 static struct cpuidle_state snb_cstates
[] __initdata
= {
275 .desc
= "MWAIT 0x00",
276 .flags
= MWAIT2flg(0x00),
278 .target_residency
= 2,
279 .enter
= &intel_idle
,
280 .enter_s2idle
= intel_idle_s2idle
, },
283 .desc
= "MWAIT 0x01",
284 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
286 .target_residency
= 20,
287 .enter
= &intel_idle
,
288 .enter_s2idle
= intel_idle_s2idle
, },
291 .desc
= "MWAIT 0x10",
292 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
294 .target_residency
= 211,
295 .enter
= &intel_idle
,
296 .enter_s2idle
= intel_idle_s2idle
, },
299 .desc
= "MWAIT 0x20",
300 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
302 .target_residency
= 345,
303 .enter
= &intel_idle
,
304 .enter_s2idle
= intel_idle_s2idle
, },
307 .desc
= "MWAIT 0x30",
308 .flags
= MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED
,
310 .target_residency
= 345,
311 .enter
= &intel_idle
,
312 .enter_s2idle
= intel_idle_s2idle
, },
317 static struct cpuidle_state byt_cstates
[] __initdata
= {
320 .desc
= "MWAIT 0x00",
321 .flags
= MWAIT2flg(0x00),
323 .target_residency
= 1,
324 .enter
= &intel_idle
,
325 .enter_s2idle
= intel_idle_s2idle
, },
328 .desc
= "MWAIT 0x58",
329 .flags
= MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED
,
331 .target_residency
= 275,
332 .enter
= &intel_idle
,
333 .enter_s2idle
= intel_idle_s2idle
, },
336 .desc
= "MWAIT 0x52",
337 .flags
= MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED
,
339 .target_residency
= 560,
340 .enter
= &intel_idle
,
341 .enter_s2idle
= intel_idle_s2idle
, },
344 .desc
= "MWAIT 0x60",
345 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
346 .exit_latency
= 1200,
347 .target_residency
= 4000,
348 .enter
= &intel_idle
,
349 .enter_s2idle
= intel_idle_s2idle
, },
352 .desc
= "MWAIT 0x64",
353 .flags
= MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED
,
354 .exit_latency
= 10000,
355 .target_residency
= 20000,
356 .enter
= &intel_idle
,
357 .enter_s2idle
= intel_idle_s2idle
, },
362 static struct cpuidle_state cht_cstates
[] __initdata
= {
365 .desc
= "MWAIT 0x00",
366 .flags
= MWAIT2flg(0x00),
368 .target_residency
= 1,
369 .enter
= &intel_idle
,
370 .enter_s2idle
= intel_idle_s2idle
, },
373 .desc
= "MWAIT 0x58",
374 .flags
= MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED
,
376 .target_residency
= 275,
377 .enter
= &intel_idle
,
378 .enter_s2idle
= intel_idle_s2idle
, },
381 .desc
= "MWAIT 0x52",
382 .flags
= MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED
,
384 .target_residency
= 560,
385 .enter
= &intel_idle
,
386 .enter_s2idle
= intel_idle_s2idle
, },
389 .desc
= "MWAIT 0x60",
390 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
391 .exit_latency
= 1200,
392 .target_residency
= 4000,
393 .enter
= &intel_idle
,
394 .enter_s2idle
= intel_idle_s2idle
, },
397 .desc
= "MWAIT 0x64",
398 .flags
= MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED
,
399 .exit_latency
= 10000,
400 .target_residency
= 20000,
401 .enter
= &intel_idle
,
402 .enter_s2idle
= intel_idle_s2idle
, },
407 static struct cpuidle_state ivb_cstates
[] __initdata
= {
410 .desc
= "MWAIT 0x00",
411 .flags
= MWAIT2flg(0x00),
413 .target_residency
= 1,
414 .enter
= &intel_idle
,
415 .enter_s2idle
= intel_idle_s2idle
, },
418 .desc
= "MWAIT 0x01",
419 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
421 .target_residency
= 20,
422 .enter
= &intel_idle
,
423 .enter_s2idle
= intel_idle_s2idle
, },
426 .desc
= "MWAIT 0x10",
427 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
429 .target_residency
= 156,
430 .enter
= &intel_idle
,
431 .enter_s2idle
= intel_idle_s2idle
, },
434 .desc
= "MWAIT 0x20",
435 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
437 .target_residency
= 300,
438 .enter
= &intel_idle
,
439 .enter_s2idle
= intel_idle_s2idle
, },
442 .desc
= "MWAIT 0x30",
443 .flags
= MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED
,
445 .target_residency
= 300,
446 .enter
= &intel_idle
,
447 .enter_s2idle
= intel_idle_s2idle
, },
452 static struct cpuidle_state ivt_cstates
[] __initdata
= {
455 .desc
= "MWAIT 0x00",
456 .flags
= MWAIT2flg(0x00),
458 .target_residency
= 1,
459 .enter
= &intel_idle
,
460 .enter_s2idle
= intel_idle_s2idle
, },
463 .desc
= "MWAIT 0x01",
464 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
466 .target_residency
= 80,
467 .enter
= &intel_idle
,
468 .enter_s2idle
= intel_idle_s2idle
, },
471 .desc
= "MWAIT 0x10",
472 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
474 .target_residency
= 156,
475 .enter
= &intel_idle
,
476 .enter_s2idle
= intel_idle_s2idle
, },
479 .desc
= "MWAIT 0x20",
480 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
482 .target_residency
= 300,
483 .enter
= &intel_idle
,
484 .enter_s2idle
= intel_idle_s2idle
, },
489 static struct cpuidle_state ivt_cstates_4s
[] __initdata
= {
492 .desc
= "MWAIT 0x00",
493 .flags
= MWAIT2flg(0x00),
495 .target_residency
= 1,
496 .enter
= &intel_idle
,
497 .enter_s2idle
= intel_idle_s2idle
, },
500 .desc
= "MWAIT 0x01",
501 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
503 .target_residency
= 250,
504 .enter
= &intel_idle
,
505 .enter_s2idle
= intel_idle_s2idle
, },
508 .desc
= "MWAIT 0x10",
509 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
511 .target_residency
= 300,
512 .enter
= &intel_idle
,
513 .enter_s2idle
= intel_idle_s2idle
, },
516 .desc
= "MWAIT 0x20",
517 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
519 .target_residency
= 400,
520 .enter
= &intel_idle
,
521 .enter_s2idle
= intel_idle_s2idle
, },
526 static struct cpuidle_state ivt_cstates_8s
[] __initdata
= {
529 .desc
= "MWAIT 0x00",
530 .flags
= MWAIT2flg(0x00),
532 .target_residency
= 1,
533 .enter
= &intel_idle
,
534 .enter_s2idle
= intel_idle_s2idle
, },
537 .desc
= "MWAIT 0x01",
538 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
540 .target_residency
= 500,
541 .enter
= &intel_idle
,
542 .enter_s2idle
= intel_idle_s2idle
, },
545 .desc
= "MWAIT 0x10",
546 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
548 .target_residency
= 600,
549 .enter
= &intel_idle
,
550 .enter_s2idle
= intel_idle_s2idle
, },
553 .desc
= "MWAIT 0x20",
554 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
556 .target_residency
= 700,
557 .enter
= &intel_idle
,
558 .enter_s2idle
= intel_idle_s2idle
, },
563 static struct cpuidle_state hsw_cstates
[] __initdata
= {
566 .desc
= "MWAIT 0x00",
567 .flags
= MWAIT2flg(0x00),
569 .target_residency
= 2,
570 .enter
= &intel_idle
,
571 .enter_s2idle
= intel_idle_s2idle
, },
574 .desc
= "MWAIT 0x01",
575 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
577 .target_residency
= 20,
578 .enter
= &intel_idle
,
579 .enter_s2idle
= intel_idle_s2idle
, },
582 .desc
= "MWAIT 0x10",
583 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
585 .target_residency
= 100,
586 .enter
= &intel_idle
,
587 .enter_s2idle
= intel_idle_s2idle
, },
590 .desc
= "MWAIT 0x20",
591 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
593 .target_residency
= 400,
594 .enter
= &intel_idle
,
595 .enter_s2idle
= intel_idle_s2idle
, },
598 .desc
= "MWAIT 0x32",
599 .flags
= MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED
,
601 .target_residency
= 500,
602 .enter
= &intel_idle
,
603 .enter_s2idle
= intel_idle_s2idle
, },
606 .desc
= "MWAIT 0x40",
607 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
609 .target_residency
= 900,
610 .enter
= &intel_idle
,
611 .enter_s2idle
= intel_idle_s2idle
, },
614 .desc
= "MWAIT 0x50",
615 .flags
= MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED
,
617 .target_residency
= 1800,
618 .enter
= &intel_idle
,
619 .enter_s2idle
= intel_idle_s2idle
, },
622 .desc
= "MWAIT 0x60",
623 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
624 .exit_latency
= 2600,
625 .target_residency
= 7700,
626 .enter
= &intel_idle
,
627 .enter_s2idle
= intel_idle_s2idle
, },
631 static struct cpuidle_state bdw_cstates
[] __initdata
= {
634 .desc
= "MWAIT 0x00",
635 .flags
= MWAIT2flg(0x00),
637 .target_residency
= 2,
638 .enter
= &intel_idle
,
639 .enter_s2idle
= intel_idle_s2idle
, },
642 .desc
= "MWAIT 0x01",
643 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
645 .target_residency
= 20,
646 .enter
= &intel_idle
,
647 .enter_s2idle
= intel_idle_s2idle
, },
650 .desc
= "MWAIT 0x10",
651 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
653 .target_residency
= 100,
654 .enter
= &intel_idle
,
655 .enter_s2idle
= intel_idle_s2idle
, },
658 .desc
= "MWAIT 0x20",
659 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
661 .target_residency
= 400,
662 .enter
= &intel_idle
,
663 .enter_s2idle
= intel_idle_s2idle
, },
666 .desc
= "MWAIT 0x32",
667 .flags
= MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED
,
669 .target_residency
= 500,
670 .enter
= &intel_idle
,
671 .enter_s2idle
= intel_idle_s2idle
, },
674 .desc
= "MWAIT 0x40",
675 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
677 .target_residency
= 900,
678 .enter
= &intel_idle
,
679 .enter_s2idle
= intel_idle_s2idle
, },
682 .desc
= "MWAIT 0x50",
683 .flags
= MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED
,
685 .target_residency
= 1800,
686 .enter
= &intel_idle
,
687 .enter_s2idle
= intel_idle_s2idle
, },
690 .desc
= "MWAIT 0x60",
691 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
692 .exit_latency
= 2600,
693 .target_residency
= 7700,
694 .enter
= &intel_idle
,
695 .enter_s2idle
= intel_idle_s2idle
, },
700 static struct cpuidle_state skl_cstates
[] __initdata
= {
703 .desc
= "MWAIT 0x00",
704 .flags
= MWAIT2flg(0x00),
706 .target_residency
= 2,
707 .enter
= &intel_idle
,
708 .enter_s2idle
= intel_idle_s2idle
, },
711 .desc
= "MWAIT 0x01",
712 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
714 .target_residency
= 20,
715 .enter
= &intel_idle
,
716 .enter_s2idle
= intel_idle_s2idle
, },
719 .desc
= "MWAIT 0x10",
720 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
722 .target_residency
= 100,
723 .enter
= &intel_idle
,
724 .enter_s2idle
= intel_idle_s2idle
, },
727 .desc
= "MWAIT 0x20",
728 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
730 .target_residency
= 200,
731 .enter
= &intel_idle
,
732 .enter_s2idle
= intel_idle_s2idle
, },
735 .desc
= "MWAIT 0x33",
736 .flags
= MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
738 .target_residency
= 800,
739 .enter
= &intel_idle
,
740 .enter_s2idle
= intel_idle_s2idle
, },
743 .desc
= "MWAIT 0x40",
744 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
746 .target_residency
= 800,
747 .enter
= &intel_idle
,
748 .enter_s2idle
= intel_idle_s2idle
, },
751 .desc
= "MWAIT 0x50",
752 .flags
= MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
754 .target_residency
= 5000,
755 .enter
= &intel_idle
,
756 .enter_s2idle
= intel_idle_s2idle
, },
759 .desc
= "MWAIT 0x60",
760 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
762 .target_residency
= 5000,
763 .enter
= &intel_idle
,
764 .enter_s2idle
= intel_idle_s2idle
, },
769 static struct cpuidle_state skx_cstates
[] __initdata
= {
772 .desc
= "MWAIT 0x00",
773 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_IRQ_ENABLE
,
775 .target_residency
= 2,
776 .enter
= &intel_idle
,
777 .enter_s2idle
= intel_idle_s2idle
, },
780 .desc
= "MWAIT 0x01",
781 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
783 .target_residency
= 20,
784 .enter
= &intel_idle
,
785 .enter_s2idle
= intel_idle_s2idle
, },
788 .desc
= "MWAIT 0x20",
789 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
791 .target_residency
= 600,
792 .enter
= &intel_idle
,
793 .enter_s2idle
= intel_idle_s2idle
, },
798 static struct cpuidle_state icx_cstates
[] __initdata
= {
801 .desc
= "MWAIT 0x00",
802 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_IRQ_ENABLE
,
804 .target_residency
= 1,
805 .enter
= &intel_idle
,
806 .enter_s2idle
= intel_idle_s2idle
, },
809 .desc
= "MWAIT 0x01",
810 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
812 .target_residency
= 4,
813 .enter
= &intel_idle
,
814 .enter_s2idle
= intel_idle_s2idle
, },
817 .desc
= "MWAIT 0x20",
818 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
820 .target_residency
= 600,
821 .enter
= &intel_idle
,
822 .enter_s2idle
= intel_idle_s2idle
, },
828 * On AlderLake C1 has to be disabled if C1E is enabled, and vice versa.
829 * C1E is enabled only if "C1E promotion" bit is set in MSR_IA32_POWER_CTL.
830 * But in this case there is effectively no C1, because C1 requests are
831 * promoted to C1E. If the "C1E promotion" bit is cleared, then both C1
832 * and C1E requests end up with C1, so there is effectively no C1E.
834 * By default we enable C1E and disable C1 by marking it with
835 * 'CPUIDLE_FLAG_UNUSABLE'.
837 static struct cpuidle_state adl_cstates
[] __initdata
= {
840 .desc
= "MWAIT 0x00",
841 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE
,
843 .target_residency
= 1,
844 .enter
= &intel_idle
,
845 .enter_s2idle
= intel_idle_s2idle
, },
848 .desc
= "MWAIT 0x01",
849 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
851 .target_residency
= 4,
852 .enter
= &intel_idle
,
853 .enter_s2idle
= intel_idle_s2idle
, },
856 .desc
= "MWAIT 0x20",
857 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
859 .target_residency
= 600,
860 .enter
= &intel_idle
,
861 .enter_s2idle
= intel_idle_s2idle
, },
864 .desc
= "MWAIT 0x40",
865 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
867 .target_residency
= 800,
868 .enter
= &intel_idle
,
869 .enter_s2idle
= intel_idle_s2idle
, },
872 .desc
= "MWAIT 0x60",
873 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
875 .target_residency
= 2000,
876 .enter
= &intel_idle
,
877 .enter_s2idle
= intel_idle_s2idle
, },
882 static struct cpuidle_state adl_l_cstates
[] __initdata
= {
885 .desc
= "MWAIT 0x00",
886 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE
,
888 .target_residency
= 1,
889 .enter
= &intel_idle
,
890 .enter_s2idle
= intel_idle_s2idle
, },
893 .desc
= "MWAIT 0x01",
894 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
896 .target_residency
= 4,
897 .enter
= &intel_idle
,
898 .enter_s2idle
= intel_idle_s2idle
, },
901 .desc
= "MWAIT 0x20",
902 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
904 .target_residency
= 500,
905 .enter
= &intel_idle
,
906 .enter_s2idle
= intel_idle_s2idle
, },
909 .desc
= "MWAIT 0x40",
910 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
912 .target_residency
= 600,
913 .enter
= &intel_idle
,
914 .enter_s2idle
= intel_idle_s2idle
, },
917 .desc
= "MWAIT 0x60",
918 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
920 .target_residency
= 700,
921 .enter
= &intel_idle
,
922 .enter_s2idle
= intel_idle_s2idle
, },
927 static struct cpuidle_state mtl_l_cstates
[] __initdata
= {
930 .desc
= "MWAIT 0x01",
931 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
933 .target_residency
= 1,
934 .enter
= &intel_idle
,
935 .enter_s2idle
= intel_idle_s2idle
, },
938 .desc
= "MWAIT 0x20",
939 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
941 .target_residency
= 420,
942 .enter
= &intel_idle
,
943 .enter_s2idle
= intel_idle_s2idle
, },
946 .desc
= "MWAIT 0x60",
947 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
949 .target_residency
= 930,
950 .enter
= &intel_idle
,
951 .enter_s2idle
= intel_idle_s2idle
, },
956 static struct cpuidle_state gmt_cstates
[] __initdata
= {
959 .desc
= "MWAIT 0x00",
960 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE
,
962 .target_residency
= 1,
963 .enter
= &intel_idle
,
964 .enter_s2idle
= intel_idle_s2idle
, },
967 .desc
= "MWAIT 0x01",
968 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
970 .target_residency
= 4,
971 .enter
= &intel_idle
,
972 .enter_s2idle
= intel_idle_s2idle
, },
975 .desc
= "MWAIT 0x20",
976 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
978 .target_residency
= 585,
979 .enter
= &intel_idle
,
980 .enter_s2idle
= intel_idle_s2idle
, },
983 .desc
= "MWAIT 0x40",
984 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
986 .target_residency
= 1040,
987 .enter
= &intel_idle
,
988 .enter_s2idle
= intel_idle_s2idle
, },
991 .desc
= "MWAIT 0x60",
992 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
994 .target_residency
= 1980,
995 .enter
= &intel_idle
,
996 .enter_s2idle
= intel_idle_s2idle
, },
1001 static struct cpuidle_state spr_cstates
[] __initdata
= {
1004 .desc
= "MWAIT 0x00",
1005 .flags
= MWAIT2flg(0x00),
1007 .target_residency
= 1,
1008 .enter
= &intel_idle
,
1009 .enter_s2idle
= intel_idle_s2idle
, },
1012 .desc
= "MWAIT 0x01",
1013 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1015 .target_residency
= 4,
1016 .enter
= &intel_idle
,
1017 .enter_s2idle
= intel_idle_s2idle
, },
1020 .desc
= "MWAIT 0x20",
1021 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
|
1022 CPUIDLE_FLAG_INIT_XSTATE
,
1023 .exit_latency
= 290,
1024 .target_residency
= 800,
1025 .enter
= &intel_idle
,
1026 .enter_s2idle
= intel_idle_s2idle
, },
1031 static struct cpuidle_state gnr_cstates
[] __initdata
= {
1034 .desc
= "MWAIT 0x00",
1035 .flags
= MWAIT2flg(0x00),
1037 .target_residency
= 1,
1038 .enter
= &intel_idle
,
1039 .enter_s2idle
= intel_idle_s2idle
, },
1042 .desc
= "MWAIT 0x01",
1043 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1045 .target_residency
= 4,
1046 .enter
= &intel_idle
,
1047 .enter_s2idle
= intel_idle_s2idle
, },
1050 .desc
= "MWAIT 0x20",
1051 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
|
1052 CPUIDLE_FLAG_INIT_XSTATE
|
1053 CPUIDLE_FLAG_PARTIAL_HINT_MATCH
,
1054 .exit_latency
= 170,
1055 .target_residency
= 650,
1056 .enter
= &intel_idle
,
1057 .enter_s2idle
= intel_idle_s2idle
, },
1060 .desc
= "MWAIT 0x21",
1061 .flags
= MWAIT2flg(0x21) | CPUIDLE_FLAG_TLB_FLUSHED
|
1062 CPUIDLE_FLAG_INIT_XSTATE
|
1063 CPUIDLE_FLAG_PARTIAL_HINT_MATCH
,
1064 .exit_latency
= 210,
1065 .target_residency
= 1000,
1066 .enter
= &intel_idle
,
1067 .enter_s2idle
= intel_idle_s2idle
, },
1072 static struct cpuidle_state gnrd_cstates
[] __initdata
= {
1075 .desc
= "MWAIT 0x00",
1076 .flags
= MWAIT2flg(0x00),
1078 .target_residency
= 1,
1079 .enter
= &intel_idle
,
1080 .enter_s2idle
= intel_idle_s2idle
, },
1083 .desc
= "MWAIT 0x01",
1084 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1086 .target_residency
= 4,
1087 .enter
= &intel_idle
,
1088 .enter_s2idle
= intel_idle_s2idle
, },
1091 .desc
= "MWAIT 0x20",
1092 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
|
1093 CPUIDLE_FLAG_INIT_XSTATE
|
1094 CPUIDLE_FLAG_PARTIAL_HINT_MATCH
,
1095 .exit_latency
= 220,
1096 .target_residency
= 650,
1097 .enter
= &intel_idle
,
1098 .enter_s2idle
= intel_idle_s2idle
, },
1101 .desc
= "MWAIT 0x21",
1102 .flags
= MWAIT2flg(0x21) | CPUIDLE_FLAG_TLB_FLUSHED
|
1103 CPUIDLE_FLAG_INIT_XSTATE
|
1104 CPUIDLE_FLAG_PARTIAL_HINT_MATCH
,
1105 .exit_latency
= 240,
1106 .target_residency
= 750,
1107 .enter
= &intel_idle
,
1108 .enter_s2idle
= intel_idle_s2idle
, },
1113 static struct cpuidle_state atom_cstates
[] __initdata
= {
1116 .desc
= "MWAIT 0x00",
1117 .flags
= MWAIT2flg(0x00),
1119 .target_residency
= 20,
1120 .enter
= &intel_idle
,
1121 .enter_s2idle
= intel_idle_s2idle
, },
1124 .desc
= "MWAIT 0x10",
1125 .flags
= MWAIT2flg(0x10),
1127 .target_residency
= 80,
1128 .enter
= &intel_idle
,
1129 .enter_s2idle
= intel_idle_s2idle
, },
1132 .desc
= "MWAIT 0x30",
1133 .flags
= MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED
,
1134 .exit_latency
= 100,
1135 .target_residency
= 400,
1136 .enter
= &intel_idle
,
1137 .enter_s2idle
= intel_idle_s2idle
, },
1140 .desc
= "MWAIT 0x52",
1141 .flags
= MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED
,
1142 .exit_latency
= 140,
1143 .target_residency
= 560,
1144 .enter
= &intel_idle
,
1145 .enter_s2idle
= intel_idle_s2idle
, },
1149 static struct cpuidle_state tangier_cstates
[] __initdata
= {
1152 .desc
= "MWAIT 0x00",
1153 .flags
= MWAIT2flg(0x00),
1155 .target_residency
= 4,
1156 .enter
= &intel_idle
,
1157 .enter_s2idle
= intel_idle_s2idle
, },
1160 .desc
= "MWAIT 0x30",
1161 .flags
= MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED
,
1162 .exit_latency
= 100,
1163 .target_residency
= 400,
1164 .enter
= &intel_idle
,
1165 .enter_s2idle
= intel_idle_s2idle
, },
1168 .desc
= "MWAIT 0x52",
1169 .flags
= MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED
,
1170 .exit_latency
= 140,
1171 .target_residency
= 560,
1172 .enter
= &intel_idle
,
1173 .enter_s2idle
= intel_idle_s2idle
, },
1176 .desc
= "MWAIT 0x60",
1177 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
1178 .exit_latency
= 1200,
1179 .target_residency
= 4000,
1180 .enter
= &intel_idle
,
1181 .enter_s2idle
= intel_idle_s2idle
, },
1184 .desc
= "MWAIT 0x64",
1185 .flags
= MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED
,
1186 .exit_latency
= 10000,
1187 .target_residency
= 20000,
1188 .enter
= &intel_idle
,
1189 .enter_s2idle
= intel_idle_s2idle
, },
1193 static struct cpuidle_state avn_cstates
[] __initdata
= {
1196 .desc
= "MWAIT 0x00",
1197 .flags
= MWAIT2flg(0x00),
1199 .target_residency
= 2,
1200 .enter
= &intel_idle
,
1201 .enter_s2idle
= intel_idle_s2idle
, },
1204 .desc
= "MWAIT 0x51",
1205 .flags
= MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED
,
1207 .target_residency
= 45,
1208 .enter
= &intel_idle
,
1209 .enter_s2idle
= intel_idle_s2idle
, },
1213 static struct cpuidle_state knl_cstates
[] __initdata
= {
1216 .desc
= "MWAIT 0x00",
1217 .flags
= MWAIT2flg(0x00),
1219 .target_residency
= 2,
1220 .enter
= &intel_idle
,
1221 .enter_s2idle
= intel_idle_s2idle
},
1224 .desc
= "MWAIT 0x10",
1225 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
1226 .exit_latency
= 120,
1227 .target_residency
= 500,
1228 .enter
= &intel_idle
,
1229 .enter_s2idle
= intel_idle_s2idle
},
1234 static struct cpuidle_state bxt_cstates
[] __initdata
= {
1237 .desc
= "MWAIT 0x00",
1238 .flags
= MWAIT2flg(0x00),
1240 .target_residency
= 2,
1241 .enter
= &intel_idle
,
1242 .enter_s2idle
= intel_idle_s2idle
, },
1245 .desc
= "MWAIT 0x01",
1246 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1248 .target_residency
= 20,
1249 .enter
= &intel_idle
,
1250 .enter_s2idle
= intel_idle_s2idle
, },
1253 .desc
= "MWAIT 0x20",
1254 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
1255 .exit_latency
= 133,
1256 .target_residency
= 133,
1257 .enter
= &intel_idle
,
1258 .enter_s2idle
= intel_idle_s2idle
, },
1261 .desc
= "MWAIT 0x31",
1262 .flags
= MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED
,
1263 .exit_latency
= 155,
1264 .target_residency
= 155,
1265 .enter
= &intel_idle
,
1266 .enter_s2idle
= intel_idle_s2idle
, },
1269 .desc
= "MWAIT 0x40",
1270 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
1271 .exit_latency
= 1000,
1272 .target_residency
= 1000,
1273 .enter
= &intel_idle
,
1274 .enter_s2idle
= intel_idle_s2idle
, },
1277 .desc
= "MWAIT 0x50",
1278 .flags
= MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED
,
1279 .exit_latency
= 2000,
1280 .target_residency
= 2000,
1281 .enter
= &intel_idle
,
1282 .enter_s2idle
= intel_idle_s2idle
, },
1285 .desc
= "MWAIT 0x60",
1286 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
1287 .exit_latency
= 10000,
1288 .target_residency
= 10000,
1289 .enter
= &intel_idle
,
1290 .enter_s2idle
= intel_idle_s2idle
, },
1295 static struct cpuidle_state dnv_cstates
[] __initdata
= {
1298 .desc
= "MWAIT 0x00",
1299 .flags
= MWAIT2flg(0x00),
1301 .target_residency
= 2,
1302 .enter
= &intel_idle
,
1303 .enter_s2idle
= intel_idle_s2idle
, },
1306 .desc
= "MWAIT 0x01",
1307 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1309 .target_residency
= 20,
1310 .enter
= &intel_idle
,
1311 .enter_s2idle
= intel_idle_s2idle
, },
1314 .desc
= "MWAIT 0x20",
1315 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
1317 .target_residency
= 500,
1318 .enter
= &intel_idle
,
1319 .enter_s2idle
= intel_idle_s2idle
, },
1325 * Note, depending on HW and FW revision, SnowRidge SoC may or may not support
1326 * C6, and this is indicated in the CPUID mwait leaf.
1328 static struct cpuidle_state snr_cstates
[] __initdata
= {
1331 .desc
= "MWAIT 0x00",
1332 .flags
= MWAIT2flg(0x00),
1334 .target_residency
= 2,
1335 .enter
= &intel_idle
,
1336 .enter_s2idle
= intel_idle_s2idle
, },
1339 .desc
= "MWAIT 0x01",
1340 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1342 .target_residency
= 25,
1343 .enter
= &intel_idle
,
1344 .enter_s2idle
= intel_idle_s2idle
, },
1347 .desc
= "MWAIT 0x20",
1348 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
1349 .exit_latency
= 130,
1350 .target_residency
= 500,
1351 .enter
= &intel_idle
,
1352 .enter_s2idle
= intel_idle_s2idle
, },
1357 static struct cpuidle_state grr_cstates
[] __initdata
= {
1360 .desc
= "MWAIT 0x00",
1361 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1363 .target_residency
= 1,
1364 .enter
= &intel_idle
,
1365 .enter_s2idle
= intel_idle_s2idle
, },
1368 .desc
= "MWAIT 0x01",
1369 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1371 .target_residency
= 10,
1372 .enter
= &intel_idle
,
1373 .enter_s2idle
= intel_idle_s2idle
, },
1376 .desc
= "MWAIT 0x22",
1377 .flags
= MWAIT2flg(0x22) | CPUIDLE_FLAG_TLB_FLUSHED
,
1378 .exit_latency
= 140,
1379 .target_residency
= 500,
1380 .enter
= &intel_idle
,
1381 .enter_s2idle
= intel_idle_s2idle
, },
1386 static struct cpuidle_state srf_cstates
[] __initdata
= {
1389 .desc
= "MWAIT 0x00",
1390 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1392 .target_residency
= 1,
1393 .enter
= &intel_idle
,
1394 .enter_s2idle
= intel_idle_s2idle
, },
1397 .desc
= "MWAIT 0x01",
1398 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1400 .target_residency
= 10,
1401 .enter
= &intel_idle
,
1402 .enter_s2idle
= intel_idle_s2idle
, },
1405 .desc
= "MWAIT 0x22",
1406 .flags
= MWAIT2flg(0x22) | CPUIDLE_FLAG_TLB_FLUSHED
|
1407 CPUIDLE_FLAG_PARTIAL_HINT_MATCH
,
1408 .exit_latency
= 270,
1409 .target_residency
= 700,
1410 .enter
= &intel_idle
,
1411 .enter_s2idle
= intel_idle_s2idle
, },
1414 .desc
= "MWAIT 0x23",
1415 .flags
= MWAIT2flg(0x23) | CPUIDLE_FLAG_TLB_FLUSHED
|
1416 CPUIDLE_FLAG_PARTIAL_HINT_MATCH
,
1417 .exit_latency
= 310,
1418 .target_residency
= 900,
1419 .enter
= &intel_idle
,
1420 .enter_s2idle
= intel_idle_s2idle
, },
1425 static const struct idle_cpu idle_cpu_nehalem __initconst
= {
1426 .state_table
= nehalem_cstates
,
1427 .auto_demotion_disable_flags
= NHM_C1_AUTO_DEMOTE
| NHM_C3_AUTO_DEMOTE
,
1428 .disable_promotion_to_c1e
= true,
1431 static const struct idle_cpu idle_cpu_nhx __initconst
= {
1432 .state_table
= nehalem_cstates
,
1433 .auto_demotion_disable_flags
= NHM_C1_AUTO_DEMOTE
| NHM_C3_AUTO_DEMOTE
,
1434 .disable_promotion_to_c1e
= true,
1438 static const struct idle_cpu idle_cpu_atom __initconst
= {
1439 .state_table
= atom_cstates
,
1442 static const struct idle_cpu idle_cpu_tangier __initconst
= {
1443 .state_table
= tangier_cstates
,
1446 static const struct idle_cpu idle_cpu_lincroft __initconst
= {
1447 .state_table
= atom_cstates
,
1448 .auto_demotion_disable_flags
= ATM_LNC_C6_AUTO_DEMOTE
,
1451 static const struct idle_cpu idle_cpu_snb __initconst
= {
1452 .state_table
= snb_cstates
,
1453 .disable_promotion_to_c1e
= true,
1456 static const struct idle_cpu idle_cpu_snx __initconst
= {
1457 .state_table
= snb_cstates
,
1458 .disable_promotion_to_c1e
= true,
1462 static const struct idle_cpu idle_cpu_byt __initconst
= {
1463 .state_table
= byt_cstates
,
1464 .disable_promotion_to_c1e
= true,
1465 .byt_auto_demotion_disable_flag
= true,
1468 static const struct idle_cpu idle_cpu_cht __initconst
= {
1469 .state_table
= cht_cstates
,
1470 .disable_promotion_to_c1e
= true,
1471 .byt_auto_demotion_disable_flag
= true,
1474 static const struct idle_cpu idle_cpu_ivb __initconst
= {
1475 .state_table
= ivb_cstates
,
1476 .disable_promotion_to_c1e
= true,
1479 static const struct idle_cpu idle_cpu_ivt __initconst
= {
1480 .state_table
= ivt_cstates
,
1481 .disable_promotion_to_c1e
= true,
1485 static const struct idle_cpu idle_cpu_hsw __initconst
= {
1486 .state_table
= hsw_cstates
,
1487 .disable_promotion_to_c1e
= true,
1490 static const struct idle_cpu idle_cpu_hsx __initconst
= {
1491 .state_table
= hsw_cstates
,
1492 .disable_promotion_to_c1e
= true,
1496 static const struct idle_cpu idle_cpu_bdw __initconst
= {
1497 .state_table
= bdw_cstates
,
1498 .disable_promotion_to_c1e
= true,
1501 static const struct idle_cpu idle_cpu_bdx __initconst
= {
1502 .state_table
= bdw_cstates
,
1503 .disable_promotion_to_c1e
= true,
1507 static const struct idle_cpu idle_cpu_skl __initconst
= {
1508 .state_table
= skl_cstates
,
1509 .disable_promotion_to_c1e
= true,
1512 static const struct idle_cpu idle_cpu_skx __initconst
= {
1513 .state_table
= skx_cstates
,
1514 .disable_promotion_to_c1e
= true,
1518 static const struct idle_cpu idle_cpu_icx __initconst
= {
1519 .state_table
= icx_cstates
,
1520 .disable_promotion_to_c1e
= true,
1524 static const struct idle_cpu idle_cpu_adl __initconst
= {
1525 .state_table
= adl_cstates
,
1528 static const struct idle_cpu idle_cpu_adl_l __initconst
= {
1529 .state_table
= adl_l_cstates
,
1532 static const struct idle_cpu idle_cpu_mtl_l __initconst
= {
1533 .state_table
= mtl_l_cstates
,
1536 static const struct idle_cpu idle_cpu_gmt __initconst
= {
1537 .state_table
= gmt_cstates
,
1540 static const struct idle_cpu idle_cpu_spr __initconst
= {
1541 .state_table
= spr_cstates
,
1542 .disable_promotion_to_c1e
= true,
1546 static const struct idle_cpu idle_cpu_gnr __initconst
= {
1547 .state_table
= gnr_cstates
,
1548 .disable_promotion_to_c1e
= true,
1552 static const struct idle_cpu idle_cpu_gnrd __initconst
= {
1553 .state_table
= gnrd_cstates
,
1554 .disable_promotion_to_c1e
= true,
1558 static const struct idle_cpu idle_cpu_avn __initconst
= {
1559 .state_table
= avn_cstates
,
1560 .disable_promotion_to_c1e
= true,
1564 static const struct idle_cpu idle_cpu_knl __initconst
= {
1565 .state_table
= knl_cstates
,
1569 static const struct idle_cpu idle_cpu_bxt __initconst
= {
1570 .state_table
= bxt_cstates
,
1571 .disable_promotion_to_c1e
= true,
1574 static const struct idle_cpu idle_cpu_dnv __initconst
= {
1575 .state_table
= dnv_cstates
,
1576 .disable_promotion_to_c1e
= true,
1580 static const struct idle_cpu idle_cpu_tmt __initconst
= {
1581 .disable_promotion_to_c1e
= true,
1584 static const struct idle_cpu idle_cpu_snr __initconst
= {
1585 .state_table
= snr_cstates
,
1586 .disable_promotion_to_c1e
= true,
1590 static const struct idle_cpu idle_cpu_grr __initconst
= {
1591 .state_table
= grr_cstates
,
1592 .disable_promotion_to_c1e
= true,
1596 static const struct idle_cpu idle_cpu_srf __initconst
= {
1597 .state_table
= srf_cstates
,
1598 .disable_promotion_to_c1e
= true,
1602 static const struct x86_cpu_id intel_idle_ids
[] __initconst
= {
1603 X86_MATCH_VFM(INTEL_NEHALEM_EP
, &idle_cpu_nhx
),
1604 X86_MATCH_VFM(INTEL_NEHALEM
, &idle_cpu_nehalem
),
1605 X86_MATCH_VFM(INTEL_NEHALEM_G
, &idle_cpu_nehalem
),
1606 X86_MATCH_VFM(INTEL_WESTMERE
, &idle_cpu_nehalem
),
1607 X86_MATCH_VFM(INTEL_WESTMERE_EP
, &idle_cpu_nhx
),
1608 X86_MATCH_VFM(INTEL_NEHALEM_EX
, &idle_cpu_nhx
),
1609 X86_MATCH_VFM(INTEL_ATOM_BONNELL
, &idle_cpu_atom
),
1610 X86_MATCH_VFM(INTEL_ATOM_BONNELL_MID
, &idle_cpu_lincroft
),
1611 X86_MATCH_VFM(INTEL_WESTMERE_EX
, &idle_cpu_nhx
),
1612 X86_MATCH_VFM(INTEL_SANDYBRIDGE
, &idle_cpu_snb
),
1613 X86_MATCH_VFM(INTEL_SANDYBRIDGE_X
, &idle_cpu_snx
),
1614 X86_MATCH_VFM(INTEL_ATOM_SALTWELL
, &idle_cpu_atom
),
1615 X86_MATCH_VFM(INTEL_ATOM_SILVERMONT
, &idle_cpu_byt
),
1616 X86_MATCH_VFM(INTEL_ATOM_SILVERMONT_MID
, &idle_cpu_tangier
),
1617 X86_MATCH_VFM(INTEL_ATOM_AIRMONT
, &idle_cpu_cht
),
1618 X86_MATCH_VFM(INTEL_IVYBRIDGE
, &idle_cpu_ivb
),
1619 X86_MATCH_VFM(INTEL_IVYBRIDGE_X
, &idle_cpu_ivt
),
1620 X86_MATCH_VFM(INTEL_HASWELL
, &idle_cpu_hsw
),
1621 X86_MATCH_VFM(INTEL_HASWELL_X
, &idle_cpu_hsx
),
1622 X86_MATCH_VFM(INTEL_HASWELL_L
, &idle_cpu_hsw
),
1623 X86_MATCH_VFM(INTEL_HASWELL_G
, &idle_cpu_hsw
),
1624 X86_MATCH_VFM(INTEL_ATOM_SILVERMONT_D
, &idle_cpu_avn
),
1625 X86_MATCH_VFM(INTEL_BROADWELL
, &idle_cpu_bdw
),
1626 X86_MATCH_VFM(INTEL_BROADWELL_G
, &idle_cpu_bdw
),
1627 X86_MATCH_VFM(INTEL_BROADWELL_X
, &idle_cpu_bdx
),
1628 X86_MATCH_VFM(INTEL_BROADWELL_D
, &idle_cpu_bdx
),
1629 X86_MATCH_VFM(INTEL_SKYLAKE_L
, &idle_cpu_skl
),
1630 X86_MATCH_VFM(INTEL_SKYLAKE
, &idle_cpu_skl
),
1631 X86_MATCH_VFM(INTEL_KABYLAKE_L
, &idle_cpu_skl
),
1632 X86_MATCH_VFM(INTEL_KABYLAKE
, &idle_cpu_skl
),
1633 X86_MATCH_VFM(INTEL_SKYLAKE_X
, &idle_cpu_skx
),
1634 X86_MATCH_VFM(INTEL_ICELAKE_X
, &idle_cpu_icx
),
1635 X86_MATCH_VFM(INTEL_ICELAKE_D
, &idle_cpu_icx
),
1636 X86_MATCH_VFM(INTEL_ALDERLAKE
, &idle_cpu_adl
),
1637 X86_MATCH_VFM(INTEL_ALDERLAKE_L
, &idle_cpu_adl_l
),
1638 X86_MATCH_VFM(INTEL_METEORLAKE_L
, &idle_cpu_mtl_l
),
1639 X86_MATCH_VFM(INTEL_ATOM_GRACEMONT
, &idle_cpu_gmt
),
1640 X86_MATCH_VFM(INTEL_SAPPHIRERAPIDS_X
, &idle_cpu_spr
),
1641 X86_MATCH_VFM(INTEL_EMERALDRAPIDS_X
, &idle_cpu_spr
),
1642 X86_MATCH_VFM(INTEL_GRANITERAPIDS_X
, &idle_cpu_gnr
),
1643 X86_MATCH_VFM(INTEL_GRANITERAPIDS_D
, &idle_cpu_gnrd
),
1644 X86_MATCH_VFM(INTEL_XEON_PHI_KNL
, &idle_cpu_knl
),
1645 X86_MATCH_VFM(INTEL_XEON_PHI_KNM
, &idle_cpu_knl
),
1646 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT
, &idle_cpu_bxt
),
1647 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_PLUS
, &idle_cpu_bxt
),
1648 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_D
, &idle_cpu_dnv
),
1649 X86_MATCH_VFM(INTEL_ATOM_TREMONT
, &idle_cpu_tmt
),
1650 X86_MATCH_VFM(INTEL_ATOM_TREMONT_L
, &idle_cpu_tmt
),
1651 X86_MATCH_VFM(INTEL_ATOM_TREMONT_D
, &idle_cpu_snr
),
1652 X86_MATCH_VFM(INTEL_ATOM_CRESTMONT
, &idle_cpu_grr
),
1653 X86_MATCH_VFM(INTEL_ATOM_CRESTMONT_X
, &idle_cpu_srf
),
1657 static const struct x86_cpu_id intel_mwait_ids
[] __initconst
= {
1658 X86_MATCH_VENDOR_FAM_FEATURE(INTEL
, 6, X86_FEATURE_MWAIT
, NULL
),
1662 static bool __init
intel_idle_max_cstate_reached(int cstate
)
1664 if (cstate
+ 1 > max_cstate
) {
1665 pr_info("max_cstate %d reached\n", max_cstate
);
1671 static bool __init
intel_idle_state_needs_timer_stop(struct cpuidle_state
*state
)
1673 unsigned long eax
= flg2MWAIT(state
->flags
);
1675 if (boot_cpu_has(X86_FEATURE_ARAT
))
1679 * Switch over to one-shot tick broadcast if the target C-state
1680 * is deeper than C1.
1682 return !!((eax
>> MWAIT_SUBSTATE_SIZE
) & MWAIT_CSTATE_MASK
);
1685 #ifdef CONFIG_ACPI_PROCESSOR_CSTATE
1686 #include <acpi/processor.h>
1688 static bool no_acpi __read_mostly
;
1689 module_param(no_acpi
, bool, 0444);
1690 MODULE_PARM_DESC(no_acpi
, "Do not use ACPI _CST for building the idle states list");
1692 static bool force_use_acpi __read_mostly
; /* No effect if no_acpi is set. */
1693 module_param_named(use_acpi
, force_use_acpi
, bool, 0444);
1694 MODULE_PARM_DESC(use_acpi
, "Use ACPI _CST for building the idle states list");
1696 static struct acpi_processor_power acpi_state_table __initdata
;
1699 * intel_idle_cst_usable - Check if the _CST information can be used.
1701 * Check if all of the C-states listed by _CST in the max_cstate range are
1702 * ACPI_CSTATE_FFH, which means that they should be entered via MWAIT.
1704 static bool __init
intel_idle_cst_usable(void)
1708 limit
= min_t(int, min_t(int, CPUIDLE_STATE_MAX
, max_cstate
+ 1),
1709 acpi_state_table
.count
);
1711 for (cstate
= 1; cstate
< limit
; cstate
++) {
1712 struct acpi_processor_cx
*cx
= &acpi_state_table
.states
[cstate
];
1714 if (cx
->entry_method
!= ACPI_CSTATE_FFH
)
1721 static bool __init
intel_idle_acpi_cst_extract(void)
1726 pr_debug("Not allowed to use ACPI _CST\n");
1730 for_each_possible_cpu(cpu
) {
1731 struct acpi_processor
*pr
= per_cpu(processors
, cpu
);
1736 if (acpi_processor_evaluate_cst(pr
->handle
, cpu
, &acpi_state_table
))
1739 acpi_state_table
.count
++;
1741 if (!intel_idle_cst_usable())
1744 if (!acpi_processor_claim_cst_control())
1750 acpi_state_table
.count
= 0;
1751 pr_debug("ACPI _CST not found or not usable\n");
1755 static void __init
intel_idle_init_cstates_acpi(struct cpuidle_driver
*drv
)
1757 int cstate
, limit
= min_t(int, CPUIDLE_STATE_MAX
, acpi_state_table
.count
);
1760 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1761 * the interesting states are ACPI_CSTATE_FFH.
1763 for (cstate
= 1; cstate
< limit
; cstate
++) {
1764 struct acpi_processor_cx
*cx
;
1765 struct cpuidle_state
*state
;
1767 if (intel_idle_max_cstate_reached(cstate
- 1))
1770 cx
= &acpi_state_table
.states
[cstate
];
1772 state
= &drv
->states
[drv
->state_count
++];
1774 snprintf(state
->name
, CPUIDLE_NAME_LEN
, "C%d_ACPI", cstate
);
1775 strscpy(state
->desc
, cx
->desc
, CPUIDLE_DESC_LEN
);
1776 state
->exit_latency
= cx
->latency
;
1778 * For C1-type C-states use the same number for both the exit
1779 * latency and target residency, because that is the case for
1780 * C1 in the majority of the static C-states tables above.
1781 * For the other types of C-states, however, set the target
1782 * residency to 3 times the exit latency which should lead to
1783 * a reasonable balance between energy-efficiency and
1784 * performance in the majority of interesting cases.
1786 state
->target_residency
= cx
->latency
;
1787 if (cx
->type
> ACPI_STATE_C1
)
1788 state
->target_residency
*= 3;
1790 state
->flags
= MWAIT2flg(cx
->address
);
1791 if (cx
->type
> ACPI_STATE_C2
)
1792 state
->flags
|= CPUIDLE_FLAG_TLB_FLUSHED
;
1794 if (disabled_states_mask
& BIT(cstate
))
1795 state
->flags
|= CPUIDLE_FLAG_OFF
;
1797 if (intel_idle_state_needs_timer_stop(state
))
1798 state
->flags
|= CPUIDLE_FLAG_TIMER_STOP
;
1800 state
->enter
= intel_idle
;
1801 state
->enter_s2idle
= intel_idle_s2idle
;
1805 static bool __init
intel_idle_off_by_default(unsigned int flags
, u32 mwait_hint
)
1810 * If there are no _CST C-states, do not disable any C-states by
1813 if (!acpi_state_table
.count
)
1816 limit
= min_t(int, CPUIDLE_STATE_MAX
, acpi_state_table
.count
);
1818 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1819 * the interesting states are ACPI_CSTATE_FFH.
1821 for (cstate
= 1; cstate
< limit
; cstate
++) {
1822 u32 acpi_hint
= acpi_state_table
.states
[cstate
].address
;
1823 u32 table_hint
= mwait_hint
;
1825 if (flags
& CPUIDLE_FLAG_PARTIAL_HINT_MATCH
) {
1826 acpi_hint
&= ~MWAIT_SUBSTATE_MASK
;
1827 table_hint
&= ~MWAIT_SUBSTATE_MASK
;
1830 if (acpi_hint
== table_hint
)
1835 #else /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1836 #define force_use_acpi (false)
1838 static inline bool intel_idle_acpi_cst_extract(void) { return false; }
1839 static inline void intel_idle_init_cstates_acpi(struct cpuidle_driver
*drv
) { }
1840 static inline bool intel_idle_off_by_default(unsigned int flags
, u32 mwait_hint
)
1844 #endif /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1847 * ivt_idle_state_table_update - Tune the idle states table for Ivy Town.
1849 * Tune IVT multi-socket targets.
1850 * Assumption: num_sockets == (max_package_num + 1).
1852 static void __init
ivt_idle_state_table_update(void)
1854 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1855 int cpu
, package_num
, num_sockets
= 1;
1857 for_each_online_cpu(cpu
) {
1858 package_num
= topology_physical_package_id(cpu
);
1859 if (package_num
+ 1 > num_sockets
) {
1860 num_sockets
= package_num
+ 1;
1862 if (num_sockets
> 4) {
1863 cpuidle_state_table
= ivt_cstates_8s
;
1869 if (num_sockets
> 2)
1870 cpuidle_state_table
= ivt_cstates_4s
;
1872 /* else, 1 and 2 socket systems use default ivt_cstates */
1876 * irtl_2_usec - IRTL to microseconds conversion.
1877 * @irtl: IRTL MSR value.
1879 * Translate the IRTL (Interrupt Response Time Limit) MSR value to microseconds.
1881 static unsigned long long __init
irtl_2_usec(unsigned long long irtl
)
1883 static const unsigned int irtl_ns_units
[] __initconst
= {
1884 1, 32, 1024, 32768, 1048576, 33554432, 0, 0
1886 unsigned long long ns
;
1891 ns
= irtl_ns_units
[(irtl
>> 10) & 0x7];
1893 return div_u64((irtl
& 0x3FF) * ns
, NSEC_PER_USEC
);
1897 * bxt_idle_state_table_update - Fix up the Broxton idle states table.
1899 * On BXT, trust the IRTL (Interrupt Response Time Limit) MSR to show the
1900 * definitive maximum latency and use the same value for target_residency.
1902 static void __init
bxt_idle_state_table_update(void)
1904 unsigned long long msr
;
1907 rdmsrl(MSR_PKGC6_IRTL
, msr
);
1908 usec
= irtl_2_usec(msr
);
1910 bxt_cstates
[2].exit_latency
= usec
;
1911 bxt_cstates
[2].target_residency
= usec
;
1914 rdmsrl(MSR_PKGC7_IRTL
, msr
);
1915 usec
= irtl_2_usec(msr
);
1917 bxt_cstates
[3].exit_latency
= usec
;
1918 bxt_cstates
[3].target_residency
= usec
;
1921 rdmsrl(MSR_PKGC8_IRTL
, msr
);
1922 usec
= irtl_2_usec(msr
);
1924 bxt_cstates
[4].exit_latency
= usec
;
1925 bxt_cstates
[4].target_residency
= usec
;
1928 rdmsrl(MSR_PKGC9_IRTL
, msr
);
1929 usec
= irtl_2_usec(msr
);
1931 bxt_cstates
[5].exit_latency
= usec
;
1932 bxt_cstates
[5].target_residency
= usec
;
1935 rdmsrl(MSR_PKGC10_IRTL
, msr
);
1936 usec
= irtl_2_usec(msr
);
1938 bxt_cstates
[6].exit_latency
= usec
;
1939 bxt_cstates
[6].target_residency
= usec
;
1945 * sklh_idle_state_table_update - Fix up the Sky Lake idle states table.
1947 * On SKL-H (model 0x5e) skip C8 and C9 if C10 is enabled and SGX disabled.
1949 static void __init
sklh_idle_state_table_update(void)
1951 unsigned long long msr
;
1952 unsigned int eax
, ebx
, ecx
, edx
;
1955 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1956 if (max_cstate
<= 7)
1959 /* if PC10 not present in CPUID.MWAIT.EDX */
1960 if ((mwait_substates
& (0xF << 28)) == 0)
1963 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL
, msr
);
1965 /* PC10 is not enabled in PKG C-state limit */
1966 if ((msr
& 0xF) != 8)
1970 cpuid(7, &eax
, &ebx
, &ecx
, &edx
);
1972 /* if SGX is present */
1973 if (ebx
& (1 << 2)) {
1975 rdmsrl(MSR_IA32_FEAT_CTL
, msr
);
1977 /* if SGX is enabled */
1978 if (msr
& (1 << 18))
1982 skl_cstates
[5].flags
|= CPUIDLE_FLAG_UNUSABLE
; /* C8-SKL */
1983 skl_cstates
[6].flags
|= CPUIDLE_FLAG_UNUSABLE
; /* C9-SKL */
1987 * skx_idle_state_table_update - Adjust the Sky Lake/Cascade Lake
1988 * idle states table.
1990 static void __init
skx_idle_state_table_update(void)
1992 unsigned long long msr
;
1994 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL
, msr
);
1997 * 000b: C0/C1 (no package C-state support)
1999 * 010b: C6 (non-retention)
2000 * 011b: C6 (retention)
2001 * 111b: No Package C state limits.
2003 if ((msr
& 0x7) < 2) {
2005 * Uses the CC6 + PC0 latency and 3 times of
2006 * latency for target_residency if the PC6
2007 * is disabled in BIOS. This is consistent
2008 * with how intel_idle driver uses _CST
2009 * to set the target_residency.
2011 skx_cstates
[2].exit_latency
= 92;
2012 skx_cstates
[2].target_residency
= 276;
2017 * adl_idle_state_table_update - Adjust AlderLake idle states table.
2019 static void __init
adl_idle_state_table_update(void)
2021 /* Check if user prefers C1 over C1E. */
2022 if (preferred_states_mask
& BIT(1) && !(preferred_states_mask
& BIT(2))) {
2023 cpuidle_state_table
[0].flags
&= ~CPUIDLE_FLAG_UNUSABLE
;
2024 cpuidle_state_table
[1].flags
|= CPUIDLE_FLAG_UNUSABLE
;
2026 /* Disable C1E by clearing the "C1E promotion" bit. */
2027 c1e_promotion
= C1E_PROMOTION_DISABLE
;
2031 /* Make sure C1E is enabled by default */
2032 c1e_promotion
= C1E_PROMOTION_ENABLE
;
2036 * spr_idle_state_table_update - Adjust Sapphire Rapids idle states table.
2038 static void __init
spr_idle_state_table_update(void)
2040 unsigned long long msr
;
2043 * By default, the C6 state assumes the worst-case scenario of package
2044 * C6. However, if PC6 is disabled, we update the numbers to match
2047 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL
, msr
);
2049 /* Limit value 2 and above allow for PC6. */
2050 if ((msr
& 0x7) < 2) {
2051 spr_cstates
[2].exit_latency
= 190;
2052 spr_cstates
[2].target_residency
= 600;
2056 static bool __init
intel_idle_verify_cstate(unsigned int mwait_hint
)
2058 unsigned int mwait_cstate
= (MWAIT_HINT2CSTATE(mwait_hint
) + 1) &
2060 unsigned int num_substates
= (mwait_substates
>> mwait_cstate
* 4) &
2061 MWAIT_SUBSTATE_MASK
;
2063 /* Ignore the C-state if there are NO sub-states in CPUID for it. */
2064 if (num_substates
== 0)
2067 if (mwait_cstate
> 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC
))
2068 mark_tsc_unstable("TSC halts in idle states deeper than C2");
2073 static void state_update_enter_method(struct cpuidle_state
*state
, int cstate
)
2075 if (state
->flags
& CPUIDLE_FLAG_INIT_XSTATE
) {
2077 * Combining with XSTATE with IBRS or IRQ_ENABLE flags
2078 * is not currently supported but this driver.
2080 WARN_ON_ONCE(state
->flags
& CPUIDLE_FLAG_IBRS
);
2081 WARN_ON_ONCE(state
->flags
& CPUIDLE_FLAG_IRQ_ENABLE
);
2082 state
->enter
= intel_idle_xstate
;
2086 if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS
) &&
2087 ((state
->flags
& CPUIDLE_FLAG_IBRS
) || ibrs_off
)) {
2089 * IBRS mitigation requires that C-states are entered
2090 * with interrupts disabled.
2092 if (ibrs_off
&& (state
->flags
& CPUIDLE_FLAG_IRQ_ENABLE
))
2093 state
->flags
&= ~CPUIDLE_FLAG_IRQ_ENABLE
;
2094 WARN_ON_ONCE(state
->flags
& CPUIDLE_FLAG_IRQ_ENABLE
);
2095 state
->enter
= intel_idle_ibrs
;
2099 if (state
->flags
& CPUIDLE_FLAG_IRQ_ENABLE
) {
2100 state
->enter
= intel_idle_irq
;
2105 pr_info("forced intel_idle_irq for state %d\n", cstate
);
2106 state
->enter
= intel_idle_irq
;
2110 static void __init
intel_idle_init_cstates_icpu(struct cpuidle_driver
*drv
)
2114 switch (boot_cpu_data
.x86_vfm
) {
2115 case INTEL_IVYBRIDGE_X
:
2116 ivt_idle_state_table_update();
2118 case INTEL_ATOM_GOLDMONT
:
2119 case INTEL_ATOM_GOLDMONT_PLUS
:
2120 bxt_idle_state_table_update();
2123 sklh_idle_state_table_update();
2125 case INTEL_SKYLAKE_X
:
2126 skx_idle_state_table_update();
2128 case INTEL_SAPPHIRERAPIDS_X
:
2129 case INTEL_EMERALDRAPIDS_X
:
2130 spr_idle_state_table_update();
2132 case INTEL_ALDERLAKE
:
2133 case INTEL_ALDERLAKE_L
:
2134 case INTEL_ATOM_GRACEMONT
:
2135 adl_idle_state_table_update();
2139 for (cstate
= 0; cstate
< CPUIDLE_STATE_MAX
; ++cstate
) {
2140 struct cpuidle_state
*state
;
2141 unsigned int mwait_hint
;
2143 if (intel_idle_max_cstate_reached(cstate
))
2146 if (!cpuidle_state_table
[cstate
].enter
&&
2147 !cpuidle_state_table
[cstate
].enter_s2idle
)
2150 /* If marked as unusable, skip this state. */
2151 if (cpuidle_state_table
[cstate
].flags
& CPUIDLE_FLAG_UNUSABLE
) {
2152 pr_debug("state %s is disabled\n",
2153 cpuidle_state_table
[cstate
].name
);
2157 mwait_hint
= flg2MWAIT(cpuidle_state_table
[cstate
].flags
);
2158 if (!intel_idle_verify_cstate(mwait_hint
))
2161 /* Structure copy. */
2162 drv
->states
[drv
->state_count
] = cpuidle_state_table
[cstate
];
2163 state
= &drv
->states
[drv
->state_count
];
2165 state_update_enter_method(state
, cstate
);
2168 if ((disabled_states_mask
& BIT(drv
->state_count
)) ||
2169 ((icpu
->use_acpi
|| force_use_acpi
) &&
2170 intel_idle_off_by_default(state
->flags
, mwait_hint
) &&
2171 !(state
->flags
& CPUIDLE_FLAG_ALWAYS_ENABLE
)))
2172 state
->flags
|= CPUIDLE_FLAG_OFF
;
2174 if (intel_idle_state_needs_timer_stop(state
))
2175 state
->flags
|= CPUIDLE_FLAG_TIMER_STOP
;
2180 if (icpu
->byt_auto_demotion_disable_flag
) {
2181 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG
, 0);
2182 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG
, 0);
2187 * intel_idle_cpuidle_driver_init - Create the list of available idle states.
2188 * @drv: cpuidle driver structure to initialize.
2190 static void __init
intel_idle_cpuidle_driver_init(struct cpuidle_driver
*drv
)
2192 cpuidle_poll_state_init(drv
);
2194 if (disabled_states_mask
& BIT(0))
2195 drv
->states
[0].flags
|= CPUIDLE_FLAG_OFF
;
2197 drv
->state_count
= 1;
2199 if (icpu
&& icpu
->state_table
)
2200 intel_idle_init_cstates_icpu(drv
);
2202 intel_idle_init_cstates_acpi(drv
);
2205 static void auto_demotion_disable(void)
2207 unsigned long long msr_bits
;
2209 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL
, msr_bits
);
2210 msr_bits
&= ~auto_demotion_disable_flags
;
2211 wrmsrl(MSR_PKG_CST_CONFIG_CONTROL
, msr_bits
);
2214 static void c1e_promotion_enable(void)
2216 unsigned long long msr_bits
;
2218 rdmsrl(MSR_IA32_POWER_CTL
, msr_bits
);
2220 wrmsrl(MSR_IA32_POWER_CTL
, msr_bits
);
2223 static void c1e_promotion_disable(void)
2225 unsigned long long msr_bits
;
2227 rdmsrl(MSR_IA32_POWER_CTL
, msr_bits
);
2229 wrmsrl(MSR_IA32_POWER_CTL
, msr_bits
);
2233 * intel_idle_cpu_init - Register the target CPU with the cpuidle core.
2234 * @cpu: CPU to initialize.
2236 * Register a cpuidle device object for @cpu and update its MSRs in accordance
2237 * with the processor model flags.
2239 static int intel_idle_cpu_init(unsigned int cpu
)
2241 struct cpuidle_device
*dev
;
2243 dev
= per_cpu_ptr(intel_idle_cpuidle_devices
, cpu
);
2246 if (cpuidle_register_device(dev
)) {
2247 pr_debug("cpuidle_register_device %d failed!\n", cpu
);
2251 if (auto_demotion_disable_flags
)
2252 auto_demotion_disable();
2254 if (c1e_promotion
== C1E_PROMOTION_ENABLE
)
2255 c1e_promotion_enable();
2256 else if (c1e_promotion
== C1E_PROMOTION_DISABLE
)
2257 c1e_promotion_disable();
2262 static int intel_idle_cpu_online(unsigned int cpu
)
2264 struct cpuidle_device
*dev
;
2266 if (!boot_cpu_has(X86_FEATURE_ARAT
))
2267 tick_broadcast_enable();
2270 * Some systems can hotplug a cpu at runtime after
2271 * the kernel has booted, we have to initialize the
2272 * driver in this case
2274 dev
= per_cpu_ptr(intel_idle_cpuidle_devices
, cpu
);
2275 if (!dev
->registered
)
2276 return intel_idle_cpu_init(cpu
);
2282 * intel_idle_cpuidle_devices_uninit - Unregister all cpuidle devices.
2284 static void __init
intel_idle_cpuidle_devices_uninit(void)
2288 for_each_online_cpu(i
)
2289 cpuidle_unregister_device(per_cpu_ptr(intel_idle_cpuidle_devices
, i
));
2292 static int __init
intel_idle_init(void)
2294 const struct x86_cpu_id
*id
;
2295 unsigned int eax
, ebx
, ecx
;
2298 /* Do not load intel_idle at all for now if idle= is passed */
2299 if (boot_option_idle_override
!= IDLE_NO_OVERRIDE
)
2302 if (max_cstate
== 0) {
2303 pr_debug("disabled\n");
2307 id
= x86_match_cpu(intel_idle_ids
);
2309 if (!boot_cpu_has(X86_FEATURE_MWAIT
)) {
2310 pr_debug("Please enable MWAIT in BIOS SETUP\n");
2314 id
= x86_match_cpu(intel_mwait_ids
);
2319 if (boot_cpu_data
.cpuid_level
< CPUID_MWAIT_LEAF
)
2322 cpuid(CPUID_MWAIT_LEAF
, &eax
, &ebx
, &ecx
, &mwait_substates
);
2324 if (!(ecx
& CPUID5_ECX_EXTENSIONS_SUPPORTED
) ||
2325 !(ecx
& CPUID5_ECX_INTERRUPT_BREAK
) ||
2329 pr_debug("MWAIT substates: 0x%x\n", mwait_substates
);
2331 icpu
= (const struct idle_cpu
*)id
->driver_data
;
2333 if (icpu
->state_table
)
2334 cpuidle_state_table
= icpu
->state_table
;
2335 else if (!intel_idle_acpi_cst_extract())
2338 auto_demotion_disable_flags
= icpu
->auto_demotion_disable_flags
;
2339 if (icpu
->disable_promotion_to_c1e
)
2340 c1e_promotion
= C1E_PROMOTION_DISABLE
;
2341 if (icpu
->use_acpi
|| force_use_acpi
)
2342 intel_idle_acpi_cst_extract();
2343 } else if (!intel_idle_acpi_cst_extract()) {
2347 pr_debug("v" INTEL_IDLE_VERSION
" model 0x%X\n",
2348 boot_cpu_data
.x86_model
);
2350 intel_idle_cpuidle_devices
= alloc_percpu(struct cpuidle_device
);
2351 if (!intel_idle_cpuidle_devices
)
2354 intel_idle_cpuidle_driver_init(&intel_idle_driver
);
2356 retval
= cpuidle_register_driver(&intel_idle_driver
);
2358 struct cpuidle_driver
*drv
= cpuidle_get_driver();
2359 printk(KERN_DEBUG
pr_fmt("intel_idle yielding to %s\n"),
2360 drv
? drv
->name
: "none");
2361 goto init_driver_fail
;
2364 retval
= cpuhp_setup_state(CPUHP_AP_ONLINE_DYN
, "idle/intel:online",
2365 intel_idle_cpu_online
, NULL
);
2369 pr_debug("Local APIC timer is reliable in %s\n",
2370 boot_cpu_has(X86_FEATURE_ARAT
) ? "all C-states" : "C1");
2375 intel_idle_cpuidle_devices_uninit();
2376 cpuidle_unregister_driver(&intel_idle_driver
);
2378 free_percpu(intel_idle_cpuidle_devices
);
2382 device_initcall(intel_idle_init
);
2385 * We are not really modular, but we used to support that. Meaning we also
2386 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
2387 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
2388 * is the easiest way (currently) to continue doing that.
2390 module_param(max_cstate
, int, 0444);
2392 * The positions of the bits that are set in this number are the indices of the
2393 * idle states to be disabled by default (as reflected by the names of the
2394 * corresponding idle state directories in sysfs, "state0", "state1" ...
2395 * "state<i>" ..., where <i> is the index of the given state).
2397 module_param_named(states_off
, disabled_states_mask
, uint
, 0444);
2398 MODULE_PARM_DESC(states_off
, "Mask of disabled idle states");
2400 * Some platforms come with mutually exclusive C-states, so that if one is
2401 * enabled, the other C-states must not be used. Example: C1 and C1E on
2402 * Sapphire Rapids platform. This parameter allows for selecting the
2403 * preferred C-states among the groups of mutually exclusive C-states - the
2404 * selected C-states will be registered, the other C-states from the mutually
2405 * exclusive group won't be registered. If the platform has no mutually
2406 * exclusive C-states, this parameter has no effect.
2408 module_param_named(preferred_cstates
, preferred_states_mask
, uint
, 0444);
2409 MODULE_PARM_DESC(preferred_cstates
, "Mask of preferred idle states");
2411 * Debugging option that forces the driver to enter all C-states with
2412 * interrupts enabled. Does not apply to C-states with
2413 * 'CPUIDLE_FLAG_INIT_XSTATE' and 'CPUIDLE_FLAG_IBRS' flags.
2415 module_param(force_irq_on
, bool, 0444);
2417 * Force the disabling of IBRS when X86_FEATURE_KERNEL_IBRS is on and
2418 * CPUIDLE_FLAG_IRQ_ENABLE isn't set.
2420 module_param(ibrs_off
, bool, 0444);
2421 MODULE_PARM_DESC(ibrs_off
, "Disable IBRS when idle");