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/mutex.h>
52 #include <linux/notifier.h>
53 #include <linux/cpu.h>
54 #include <linux/moduleparam.h>
55 #include <linux/sysfs.h>
56 #include <asm/cpuid/api.h>
57 #include <asm/cpu_device_id.h>
58 #include <asm/intel-family.h>
59 #include <asm/mwait.h>
60 #include <asm/spec-ctrl.h>
63 #include <asm/fpu/api.h>
66 #define INTEL_IDLE_VERSION "0.5.1"
68 static struct cpuidle_driver intel_idle_driver = {
72 /* intel_idle.max_cstate=0 disables driver */
73 static int max_cstate = CPUIDLE_STATE_MAX - 1;
74 static unsigned int disabled_states_mask __read_mostly;
75 static unsigned int preferred_states_mask __read_mostly;
76 static bool force_irq_on __read_mostly;
77 static bool ibrs_off __read_mostly;
79 static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
81 static unsigned long auto_demotion_disable_flags;
84 C1E_PROMOTION_PRESERVE,
87 } c1e_promotion = C1E_PROMOTION_PRESERVE;
90 struct cpuidle_state *state_table;
93 * Hardware C-state auto-demotion may not always be optimal.
94 * Indicate which enable bits to clear here.
96 unsigned long auto_demotion_disable_flags;
97 bool disable_promotion_to_c1e;
98 bool c1_demotion_supported;
102 static bool c1_demotion_supported;
103 static DEFINE_MUTEX(c1_demotion_mutex);
105 static struct device *sysfs_root __initdata;
107 static const struct idle_cpu *icpu __initdata;
108 static struct cpuidle_state *cpuidle_state_table __initdata;
110 static unsigned int mwait_substates __initdata;
113 * Enable interrupts before entering the C-state. On some platforms and for
114 * some C-states, this may measurably decrease interrupt latency.
116 #define CPUIDLE_FLAG_IRQ_ENABLE BIT(14)
119 * Enable this state by default even if the ACPI _CST does not list it.
121 #define CPUIDLE_FLAG_ALWAYS_ENABLE BIT(15)
124 * Disable IBRS across idle (when KERNEL_IBRS), is exclusive vs IRQ_ENABLE
127 #define CPUIDLE_FLAG_IBRS BIT(16)
130 * Initialize large xstate for the C6-state entrance.
132 #define CPUIDLE_FLAG_INIT_XSTATE BIT(17)
135 * Ignore the sub-state when matching mwait hints between the ACPI _CST and
138 #define CPUIDLE_FLAG_PARTIAL_HINT_MATCH BIT(18)
141 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
142 * the C-state (top nibble) and sub-state (bottom nibble)
143 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
145 * We store the hint at the top of our "flags" for each state.
147 #define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
148 #define MWAIT2flg(eax) ((eax & 0xFF) << 24)
150 static __always_inline int __intel_idle(struct cpuidle_device *dev,
151 struct cpuidle_driver *drv,
152 int index, bool irqoff)
154 struct cpuidle_state *state = &drv->states[index];
155 unsigned int eax = flg2MWAIT(state->flags);
156 unsigned int ecx = 1*irqoff; /* break on interrupt flag */
158 mwait_idle_with_hints(eax, ecx);
164 * intel_idle - Ask the processor to enter the given idle state.
165 * @dev: cpuidle device of the target CPU.
166 * @drv: cpuidle driver (assumed to point to intel_idle_driver).
167 * @index: Target idle state index.
169 * Use the MWAIT instruction to notify the processor that the CPU represented by
170 * @dev is idle and it can try to enter the idle state corresponding to @index.
172 * If the local APIC timer is not known to be reliable in the target idle state,
173 * enable one-shot tick broadcasting for the target CPU before executing MWAIT.
175 * Must be called under local_irq_disable().
177 static __cpuidle int intel_idle(struct cpuidle_device *dev,
178 struct cpuidle_driver *drv, int index)
180 return __intel_idle(dev, drv, index, true);
183 static __cpuidle int intel_idle_irq(struct cpuidle_device *dev,
184 struct cpuidle_driver *drv, int index)
186 return __intel_idle(dev, drv, index, false);
189 static __cpuidle int intel_idle_ibrs(struct cpuidle_device *dev,
190 struct cpuidle_driver *drv, int index)
192 bool smt_active = sched_smt_active();
193 u64 spec_ctrl = spec_ctrl_current();
197 __update_spec_ctrl(0);
199 ret = __intel_idle(dev, drv, index, true);
202 __update_spec_ctrl(spec_ctrl);
207 static __cpuidle int intel_idle_xstate(struct cpuidle_device *dev,
208 struct cpuidle_driver *drv, int index)
211 return __intel_idle(dev, drv, index, true);
215 * intel_idle_s2idle - Ask the processor to enter the given idle state.
216 * @dev: cpuidle device of the target CPU.
217 * @drv: cpuidle driver (assumed to point to intel_idle_driver).
218 * @index: Target idle state index.
220 * Use the MWAIT instruction to notify the processor that the CPU represented by
221 * @dev is idle and it can try to enter the idle state corresponding to @index.
223 * Invoked as a suspend-to-idle callback routine with frozen user space, frozen
224 * scheduler tick and suspended scheduler clock on the target CPU.
226 static __cpuidle int intel_idle_s2idle(struct cpuidle_device *dev,
227 struct cpuidle_driver *drv, int index)
229 struct cpuidle_state *state = &drv->states[index];
230 unsigned int eax = flg2MWAIT(state->flags);
231 unsigned int ecx = 1; /* break on interrupt flag */
233 if (state->flags & CPUIDLE_FLAG_INIT_XSTATE)
236 mwait_idle_with_hints(eax, ecx);
241 static void intel_idle_enter_dead(struct cpuidle_device *dev, int index)
243 struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
244 struct cpuidle_state *state = &drv->states[index];
245 unsigned long eax = flg2MWAIT(state->flags);
247 mwait_play_dead(eax);
251 * States are indexed by the cstate number,
252 * which is also the index into the MWAIT hint array.
253 * Thus C0 is a dummy.
255 static struct cpuidle_state nehalem_cstates[] __initdata = {
258 .desc = "MWAIT 0x00",
259 .flags = MWAIT2flg(0x00),
261 .target_residency = 6,
262 .enter = &intel_idle,
263 .enter_s2idle = intel_idle_s2idle, },
266 .desc = "MWAIT 0x01",
267 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
269 .target_residency = 20,
270 .enter = &intel_idle,
271 .enter_s2idle = intel_idle_s2idle, },
274 .desc = "MWAIT 0x10",
275 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
277 .target_residency = 80,
278 .enter = &intel_idle,
279 .enter_s2idle = intel_idle_s2idle, },
282 .desc = "MWAIT 0x20",
283 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
285 .target_residency = 800,
286 .enter = &intel_idle,
287 .enter_s2idle = intel_idle_s2idle, },
292 static struct cpuidle_state snb_cstates[] __initdata = {
295 .desc = "MWAIT 0x00",
296 .flags = MWAIT2flg(0x00),
298 .target_residency = 2,
299 .enter = &intel_idle,
300 .enter_s2idle = intel_idle_s2idle, },
303 .desc = "MWAIT 0x01",
304 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
306 .target_residency = 20,
307 .enter = &intel_idle,
308 .enter_s2idle = intel_idle_s2idle, },
311 .desc = "MWAIT 0x10",
312 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
314 .target_residency = 211,
315 .enter = &intel_idle,
316 .enter_s2idle = intel_idle_s2idle, },
319 .desc = "MWAIT 0x20",
320 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
322 .target_residency = 345,
323 .enter = &intel_idle,
324 .enter_s2idle = intel_idle_s2idle, },
327 .desc = "MWAIT 0x30",
328 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
330 .target_residency = 345,
331 .enter = &intel_idle,
332 .enter_s2idle = intel_idle_s2idle, },
337 static struct cpuidle_state byt_cstates[] __initdata = {
340 .desc = "MWAIT 0x00",
341 .flags = MWAIT2flg(0x00),
343 .target_residency = 1,
344 .enter = &intel_idle,
345 .enter_s2idle = intel_idle_s2idle, },
348 .desc = "MWAIT 0x58",
349 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
351 .target_residency = 275,
352 .enter = &intel_idle,
353 .enter_s2idle = intel_idle_s2idle, },
356 .desc = "MWAIT 0x52",
357 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
359 .target_residency = 560,
360 .enter = &intel_idle,
361 .enter_s2idle = intel_idle_s2idle, },
364 .desc = "MWAIT 0x60",
365 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
366 .exit_latency = 1200,
367 .target_residency = 4000,
368 .enter = &intel_idle,
369 .enter_s2idle = intel_idle_s2idle, },
372 .desc = "MWAIT 0x64",
373 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
374 .exit_latency = 10000,
375 .target_residency = 20000,
376 .enter = &intel_idle,
377 .enter_s2idle = intel_idle_s2idle, },
382 static struct cpuidle_state cht_cstates[] __initdata = {
385 .desc = "MWAIT 0x00",
386 .flags = MWAIT2flg(0x00),
388 .target_residency = 1,
389 .enter = &intel_idle,
390 .enter_s2idle = intel_idle_s2idle, },
393 .desc = "MWAIT 0x58",
394 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
396 .target_residency = 275,
397 .enter = &intel_idle,
398 .enter_s2idle = intel_idle_s2idle, },
401 .desc = "MWAIT 0x52",
402 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
404 .target_residency = 560,
405 .enter = &intel_idle,
406 .enter_s2idle = intel_idle_s2idle, },
409 .desc = "MWAIT 0x60",
410 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
411 .exit_latency = 1200,
412 .target_residency = 4000,
413 .enter = &intel_idle,
414 .enter_s2idle = intel_idle_s2idle, },
417 .desc = "MWAIT 0x64",
418 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
419 .exit_latency = 10000,
420 .target_residency = 20000,
421 .enter = &intel_idle,
422 .enter_s2idle = intel_idle_s2idle, },
427 static struct cpuidle_state ivb_cstates[] __initdata = {
430 .desc = "MWAIT 0x00",
431 .flags = MWAIT2flg(0x00),
433 .target_residency = 1,
434 .enter = &intel_idle,
435 .enter_s2idle = intel_idle_s2idle, },
438 .desc = "MWAIT 0x01",
439 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
441 .target_residency = 20,
442 .enter = &intel_idle,
443 .enter_s2idle = intel_idle_s2idle, },
446 .desc = "MWAIT 0x10",
447 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
449 .target_residency = 156,
450 .enter = &intel_idle,
451 .enter_s2idle = intel_idle_s2idle, },
454 .desc = "MWAIT 0x20",
455 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
457 .target_residency = 300,
458 .enter = &intel_idle,
459 .enter_s2idle = intel_idle_s2idle, },
462 .desc = "MWAIT 0x30",
463 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
465 .target_residency = 300,
466 .enter = &intel_idle,
467 .enter_s2idle = intel_idle_s2idle, },
472 static struct cpuidle_state ivt_cstates[] __initdata = {
475 .desc = "MWAIT 0x00",
476 .flags = MWAIT2flg(0x00),
478 .target_residency = 1,
479 .enter = &intel_idle,
480 .enter_s2idle = intel_idle_s2idle, },
483 .desc = "MWAIT 0x01",
484 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
486 .target_residency = 80,
487 .enter = &intel_idle,
488 .enter_s2idle = intel_idle_s2idle, },
491 .desc = "MWAIT 0x10",
492 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
494 .target_residency = 156,
495 .enter = &intel_idle,
496 .enter_s2idle = intel_idle_s2idle, },
499 .desc = "MWAIT 0x20",
500 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
502 .target_residency = 300,
503 .enter = &intel_idle,
504 .enter_s2idle = intel_idle_s2idle, },
509 static struct cpuidle_state ivt_cstates_4s[] __initdata = {
512 .desc = "MWAIT 0x00",
513 .flags = MWAIT2flg(0x00),
515 .target_residency = 1,
516 .enter = &intel_idle,
517 .enter_s2idle = intel_idle_s2idle, },
520 .desc = "MWAIT 0x01",
521 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
523 .target_residency = 250,
524 .enter = &intel_idle,
525 .enter_s2idle = intel_idle_s2idle, },
528 .desc = "MWAIT 0x10",
529 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
531 .target_residency = 300,
532 .enter = &intel_idle,
533 .enter_s2idle = intel_idle_s2idle, },
536 .desc = "MWAIT 0x20",
537 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
539 .target_residency = 400,
540 .enter = &intel_idle,
541 .enter_s2idle = intel_idle_s2idle, },
546 static struct cpuidle_state ivt_cstates_8s[] __initdata = {
549 .desc = "MWAIT 0x00",
550 .flags = MWAIT2flg(0x00),
552 .target_residency = 1,
553 .enter = &intel_idle,
554 .enter_s2idle = intel_idle_s2idle, },
557 .desc = "MWAIT 0x01",
558 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
560 .target_residency = 500,
561 .enter = &intel_idle,
562 .enter_s2idle = intel_idle_s2idle, },
565 .desc = "MWAIT 0x10",
566 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
568 .target_residency = 600,
569 .enter = &intel_idle,
570 .enter_s2idle = intel_idle_s2idle, },
573 .desc = "MWAIT 0x20",
574 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
576 .target_residency = 700,
577 .enter = &intel_idle,
578 .enter_s2idle = intel_idle_s2idle, },
583 static struct cpuidle_state hsw_cstates[] __initdata = {
586 .desc = "MWAIT 0x00",
587 .flags = MWAIT2flg(0x00),
589 .target_residency = 2,
590 .enter = &intel_idle,
591 .enter_s2idle = intel_idle_s2idle, },
594 .desc = "MWAIT 0x01",
595 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
597 .target_residency = 20,
598 .enter = &intel_idle,
599 .enter_s2idle = intel_idle_s2idle, },
602 .desc = "MWAIT 0x10",
603 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
605 .target_residency = 100,
606 .enter = &intel_idle,
607 .enter_s2idle = intel_idle_s2idle, },
610 .desc = "MWAIT 0x20",
611 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
613 .target_residency = 400,
614 .enter = &intel_idle,
615 .enter_s2idle = intel_idle_s2idle, },
618 .desc = "MWAIT 0x32",
619 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
621 .target_residency = 500,
622 .enter = &intel_idle,
623 .enter_s2idle = intel_idle_s2idle, },
626 .desc = "MWAIT 0x40",
627 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
629 .target_residency = 900,
630 .enter = &intel_idle,
631 .enter_s2idle = intel_idle_s2idle, },
634 .desc = "MWAIT 0x50",
635 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
637 .target_residency = 1800,
638 .enter = &intel_idle,
639 .enter_s2idle = intel_idle_s2idle, },
642 .desc = "MWAIT 0x60",
643 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
644 .exit_latency = 2600,
645 .target_residency = 7700,
646 .enter = &intel_idle,
647 .enter_s2idle = intel_idle_s2idle, },
651 static struct cpuidle_state bdw_cstates[] __initdata = {
654 .desc = "MWAIT 0x00",
655 .flags = MWAIT2flg(0x00),
657 .target_residency = 2,
658 .enter = &intel_idle,
659 .enter_s2idle = intel_idle_s2idle, },
662 .desc = "MWAIT 0x01",
663 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
665 .target_residency = 20,
666 .enter = &intel_idle,
667 .enter_s2idle = intel_idle_s2idle, },
670 .desc = "MWAIT 0x10",
671 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
673 .target_residency = 100,
674 .enter = &intel_idle,
675 .enter_s2idle = intel_idle_s2idle, },
678 .desc = "MWAIT 0x20",
679 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
681 .target_residency = 400,
682 .enter = &intel_idle,
683 .enter_s2idle = intel_idle_s2idle, },
686 .desc = "MWAIT 0x32",
687 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
689 .target_residency = 500,
690 .enter = &intel_idle,
691 .enter_s2idle = intel_idle_s2idle, },
694 .desc = "MWAIT 0x40",
695 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
697 .target_residency = 900,
698 .enter = &intel_idle,
699 .enter_s2idle = intel_idle_s2idle, },
702 .desc = "MWAIT 0x50",
703 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
705 .target_residency = 1800,
706 .enter = &intel_idle,
707 .enter_s2idle = intel_idle_s2idle, },
710 .desc = "MWAIT 0x60",
711 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
712 .exit_latency = 2600,
713 .target_residency = 7700,
714 .enter = &intel_idle,
715 .enter_s2idle = intel_idle_s2idle, },
720 static struct cpuidle_state skl_cstates[] __initdata = {
723 .desc = "MWAIT 0x00",
724 .flags = MWAIT2flg(0x00),
726 .target_residency = 2,
727 .enter = &intel_idle,
728 .enter_s2idle = intel_idle_s2idle, },
731 .desc = "MWAIT 0x01",
732 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
734 .target_residency = 20,
735 .enter = &intel_idle,
736 .enter_s2idle = intel_idle_s2idle, },
739 .desc = "MWAIT 0x10",
740 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
742 .target_residency = 100,
743 .enter = &intel_idle,
744 .enter_s2idle = intel_idle_s2idle, },
747 .desc = "MWAIT 0x20",
748 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
750 .target_residency = 200,
751 .enter = &intel_idle,
752 .enter_s2idle = intel_idle_s2idle, },
755 .desc = "MWAIT 0x33",
756 .flags = MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
758 .target_residency = 800,
759 .enter = &intel_idle,
760 .enter_s2idle = intel_idle_s2idle, },
763 .desc = "MWAIT 0x40",
764 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
766 .target_residency = 800,
767 .enter = &intel_idle,
768 .enter_s2idle = intel_idle_s2idle, },
771 .desc = "MWAIT 0x50",
772 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
774 .target_residency = 5000,
775 .enter = &intel_idle,
776 .enter_s2idle = intel_idle_s2idle, },
779 .desc = "MWAIT 0x60",
780 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
782 .target_residency = 5000,
783 .enter = &intel_idle,
784 .enter_s2idle = intel_idle_s2idle, },
789 static struct cpuidle_state skx_cstates[] __initdata = {
792 .desc = "MWAIT 0x00",
793 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_IRQ_ENABLE,
795 .target_residency = 2,
796 .enter = &intel_idle,
797 .enter_s2idle = intel_idle_s2idle, },
800 .desc = "MWAIT 0x01",
801 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
803 .target_residency = 20,
804 .enter = &intel_idle,
805 .enter_s2idle = intel_idle_s2idle, },
808 .desc = "MWAIT 0x20",
809 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
811 .target_residency = 600,
812 .enter = &intel_idle,
813 .enter_s2idle = intel_idle_s2idle, },
818 static struct cpuidle_state icx_cstates[] __initdata = {
821 .desc = "MWAIT 0x00",
822 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_IRQ_ENABLE,
824 .target_residency = 1,
825 .enter = &intel_idle,
826 .enter_s2idle = intel_idle_s2idle, },
829 .desc = "MWAIT 0x01",
830 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
832 .target_residency = 4,
833 .enter = &intel_idle,
834 .enter_s2idle = intel_idle_s2idle, },
837 .desc = "MWAIT 0x20",
838 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
840 .target_residency = 600,
841 .enter = &intel_idle,
842 .enter_s2idle = intel_idle_s2idle, },
848 * On AlderLake C1 has to be disabled if C1E is enabled, and vice versa.
849 * C1E is enabled only if "C1E promotion" bit is set in MSR_IA32_POWER_CTL.
850 * But in this case there is effectively no C1, because C1 requests are
851 * promoted to C1E. If the "C1E promotion" bit is cleared, then both C1
852 * and C1E requests end up with C1, so there is effectively no C1E.
854 * By default we enable C1E and disable C1 by marking it with
855 * 'CPUIDLE_FLAG_UNUSABLE'.
857 static struct cpuidle_state adl_cstates[] __initdata = {
860 .desc = "MWAIT 0x00",
861 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE,
863 .target_residency = 1,
864 .enter = &intel_idle,
865 .enter_s2idle = intel_idle_s2idle, },
868 .desc = "MWAIT 0x01",
869 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
871 .target_residency = 4,
872 .enter = &intel_idle,
873 .enter_s2idle = intel_idle_s2idle, },
876 .desc = "MWAIT 0x20",
877 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
879 .target_residency = 600,
880 .enter = &intel_idle,
881 .enter_s2idle = intel_idle_s2idle, },
884 .desc = "MWAIT 0x40",
885 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
887 .target_residency = 800,
888 .enter = &intel_idle,
889 .enter_s2idle = intel_idle_s2idle, },
892 .desc = "MWAIT 0x60",
893 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
895 .target_residency = 2000,
896 .enter = &intel_idle,
897 .enter_s2idle = intel_idle_s2idle, },
902 static struct cpuidle_state adl_l_cstates[] __initdata = {
905 .desc = "MWAIT 0x00",
906 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE,
908 .target_residency = 1,
909 .enter = &intel_idle,
910 .enter_s2idle = intel_idle_s2idle, },
913 .desc = "MWAIT 0x01",
914 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
916 .target_residency = 4,
917 .enter = &intel_idle,
918 .enter_s2idle = intel_idle_s2idle, },
921 .desc = "MWAIT 0x20",
922 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
924 .target_residency = 500,
925 .enter = &intel_idle,
926 .enter_s2idle = intel_idle_s2idle, },
929 .desc = "MWAIT 0x40",
930 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
932 .target_residency = 600,
933 .enter = &intel_idle,
934 .enter_s2idle = intel_idle_s2idle, },
937 .desc = "MWAIT 0x60",
938 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
940 .target_residency = 700,
941 .enter = &intel_idle,
942 .enter_s2idle = intel_idle_s2idle, },
947 static struct cpuidle_state mtl_l_cstates[] __initdata = {
950 .desc = "MWAIT 0x01",
951 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
953 .target_residency = 1,
954 .enter = &intel_idle,
955 .enter_s2idle = intel_idle_s2idle, },
958 .desc = "MWAIT 0x20",
959 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
961 .target_residency = 420,
962 .enter = &intel_idle,
963 .enter_s2idle = intel_idle_s2idle, },
966 .desc = "MWAIT 0x60",
967 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
969 .target_residency = 930,
970 .enter = &intel_idle,
971 .enter_s2idle = intel_idle_s2idle, },
976 static struct cpuidle_state gmt_cstates[] __initdata = {
979 .desc = "MWAIT 0x00",
980 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE,
982 .target_residency = 1,
983 .enter = &intel_idle,
984 .enter_s2idle = intel_idle_s2idle, },
987 .desc = "MWAIT 0x01",
988 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
990 .target_residency = 4,
991 .enter = &intel_idle,
992 .enter_s2idle = intel_idle_s2idle, },
995 .desc = "MWAIT 0x20",
996 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
998 .target_residency = 585,
999 .enter = &intel_idle,
1000 .enter_s2idle = intel_idle_s2idle, },
1003 .desc = "MWAIT 0x40",
1004 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
1005 .exit_latency = 260,
1006 .target_residency = 1040,
1007 .enter = &intel_idle,
1008 .enter_s2idle = intel_idle_s2idle, },
1011 .desc = "MWAIT 0x60",
1012 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
1013 .exit_latency = 660,
1014 .target_residency = 1980,
1015 .enter = &intel_idle,
1016 .enter_s2idle = intel_idle_s2idle, },
1021 static struct cpuidle_state spr_cstates[] __initdata = {
1024 .desc = "MWAIT 0x00",
1025 .flags = MWAIT2flg(0x00),
1027 .target_residency = 1,
1028 .enter = &intel_idle,
1029 .enter_s2idle = intel_idle_s2idle, },
1032 .desc = "MWAIT 0x01",
1033 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1035 .target_residency = 4,
1036 .enter = &intel_idle,
1037 .enter_s2idle = intel_idle_s2idle, },
1040 .desc = "MWAIT 0x20",
1041 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED |
1042 CPUIDLE_FLAG_INIT_XSTATE,
1043 .exit_latency = 290,
1044 .target_residency = 800,
1045 .enter = &intel_idle,
1046 .enter_s2idle = intel_idle_s2idle, },
1051 static struct cpuidle_state gnr_cstates[] __initdata = {
1054 .desc = "MWAIT 0x00",
1055 .flags = MWAIT2flg(0x00),
1057 .target_residency = 1,
1058 .enter = &intel_idle,
1059 .enter_s2idle = intel_idle_s2idle, },
1062 .desc = "MWAIT 0x01",
1063 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1065 .target_residency = 4,
1066 .enter = &intel_idle,
1067 .enter_s2idle = intel_idle_s2idle, },
1070 .desc = "MWAIT 0x20",
1071 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED |
1072 CPUIDLE_FLAG_INIT_XSTATE |
1073 CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
1074 .exit_latency = 170,
1075 .target_residency = 650,
1076 .enter = &intel_idle,
1077 .enter_s2idle = intel_idle_s2idle, },
1080 .desc = "MWAIT 0x21",
1081 .flags = MWAIT2flg(0x21) | CPUIDLE_FLAG_TLB_FLUSHED |
1082 CPUIDLE_FLAG_INIT_XSTATE |
1083 CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
1084 .exit_latency = 210,
1085 .target_residency = 1000,
1086 .enter = &intel_idle,
1087 .enter_s2idle = intel_idle_s2idle, },
1092 static struct cpuidle_state gnrd_cstates[] __initdata = {
1095 .desc = "MWAIT 0x00",
1096 .flags = MWAIT2flg(0x00),
1098 .target_residency = 1,
1099 .enter = &intel_idle,
1100 .enter_s2idle = intel_idle_s2idle, },
1103 .desc = "MWAIT 0x01",
1104 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1106 .target_residency = 4,
1107 .enter = &intel_idle,
1108 .enter_s2idle = intel_idle_s2idle, },
1111 .desc = "MWAIT 0x20",
1112 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED |
1113 CPUIDLE_FLAG_INIT_XSTATE |
1114 CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
1115 .exit_latency = 220,
1116 .target_residency = 650,
1117 .enter = &intel_idle,
1118 .enter_s2idle = intel_idle_s2idle, },
1121 .desc = "MWAIT 0x21",
1122 .flags = MWAIT2flg(0x21) | CPUIDLE_FLAG_TLB_FLUSHED |
1123 CPUIDLE_FLAG_INIT_XSTATE |
1124 CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
1125 .exit_latency = 240,
1126 .target_residency = 750,
1127 .enter = &intel_idle,
1128 .enter_s2idle = intel_idle_s2idle, },
1133 static struct cpuidle_state atom_cstates[] __initdata = {
1136 .desc = "MWAIT 0x00",
1137 .flags = MWAIT2flg(0x00),
1139 .target_residency = 20,
1140 .enter = &intel_idle,
1141 .enter_s2idle = intel_idle_s2idle, },
1144 .desc = "MWAIT 0x10",
1145 .flags = MWAIT2flg(0x10),
1147 .target_residency = 80,
1148 .enter = &intel_idle,
1149 .enter_s2idle = intel_idle_s2idle, },
1152 .desc = "MWAIT 0x30",
1153 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
1154 .exit_latency = 100,
1155 .target_residency = 400,
1156 .enter = &intel_idle,
1157 .enter_s2idle = intel_idle_s2idle, },
1160 .desc = "MWAIT 0x52",
1161 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
1162 .exit_latency = 140,
1163 .target_residency = 560,
1164 .enter = &intel_idle,
1165 .enter_s2idle = intel_idle_s2idle, },
1169 static struct cpuidle_state tangier_cstates[] __initdata = {
1172 .desc = "MWAIT 0x00",
1173 .flags = MWAIT2flg(0x00),
1175 .target_residency = 4,
1176 .enter = &intel_idle,
1177 .enter_s2idle = intel_idle_s2idle, },
1180 .desc = "MWAIT 0x30",
1181 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
1182 .exit_latency = 100,
1183 .target_residency = 400,
1184 .enter = &intel_idle,
1185 .enter_s2idle = intel_idle_s2idle, },
1188 .desc = "MWAIT 0x52",
1189 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
1190 .exit_latency = 140,
1191 .target_residency = 560,
1192 .enter = &intel_idle,
1193 .enter_s2idle = intel_idle_s2idle, },
1196 .desc = "MWAIT 0x60",
1197 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
1198 .exit_latency = 1200,
1199 .target_residency = 4000,
1200 .enter = &intel_idle,
1201 .enter_s2idle = intel_idle_s2idle, },
1204 .desc = "MWAIT 0x64",
1205 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
1206 .exit_latency = 10000,
1207 .target_residency = 20000,
1208 .enter = &intel_idle,
1209 .enter_s2idle = intel_idle_s2idle, },
1213 static struct cpuidle_state avn_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 0x51",
1225 .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
1227 .target_residency = 45,
1228 .enter = &intel_idle,
1229 .enter_s2idle = intel_idle_s2idle, },
1233 static struct cpuidle_state knl_cstates[] __initdata = {
1236 .desc = "MWAIT 0x00",
1237 .flags = MWAIT2flg(0x00),
1239 .target_residency = 2,
1240 .enter = &intel_idle,
1241 .enter_s2idle = intel_idle_s2idle },
1244 .desc = "MWAIT 0x10",
1245 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
1246 .exit_latency = 120,
1247 .target_residency = 500,
1248 .enter = &intel_idle,
1249 .enter_s2idle = intel_idle_s2idle },
1254 static struct cpuidle_state bxt_cstates[] __initdata = {
1257 .desc = "MWAIT 0x00",
1258 .flags = MWAIT2flg(0x00),
1260 .target_residency = 2,
1261 .enter = &intel_idle,
1262 .enter_s2idle = intel_idle_s2idle, },
1265 .desc = "MWAIT 0x01",
1266 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1268 .target_residency = 20,
1269 .enter = &intel_idle,
1270 .enter_s2idle = intel_idle_s2idle, },
1273 .desc = "MWAIT 0x20",
1274 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
1275 .exit_latency = 133,
1276 .target_residency = 133,
1277 .enter = &intel_idle,
1278 .enter_s2idle = intel_idle_s2idle, },
1281 .desc = "MWAIT 0x31",
1282 .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
1283 .exit_latency = 155,
1284 .target_residency = 155,
1285 .enter = &intel_idle,
1286 .enter_s2idle = intel_idle_s2idle, },
1289 .desc = "MWAIT 0x40",
1290 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
1291 .exit_latency = 1000,
1292 .target_residency = 1000,
1293 .enter = &intel_idle,
1294 .enter_s2idle = intel_idle_s2idle, },
1297 .desc = "MWAIT 0x50",
1298 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
1299 .exit_latency = 2000,
1300 .target_residency = 2000,
1301 .enter = &intel_idle,
1302 .enter_s2idle = intel_idle_s2idle, },
1305 .desc = "MWAIT 0x60",
1306 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
1307 .exit_latency = 10000,
1308 .target_residency = 10000,
1309 .enter = &intel_idle,
1310 .enter_s2idle = intel_idle_s2idle, },
1315 static struct cpuidle_state dnv_cstates[] __initdata = {
1318 .desc = "MWAIT 0x00",
1319 .flags = MWAIT2flg(0x00),
1321 .target_residency = 2,
1322 .enter = &intel_idle,
1323 .enter_s2idle = intel_idle_s2idle, },
1326 .desc = "MWAIT 0x01",
1327 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1329 .target_residency = 20,
1330 .enter = &intel_idle,
1331 .enter_s2idle = intel_idle_s2idle, },
1334 .desc = "MWAIT 0x20",
1335 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
1337 .target_residency = 500,
1338 .enter = &intel_idle,
1339 .enter_s2idle = intel_idle_s2idle, },
1345 * Note, depending on HW and FW revision, SnowRidge SoC may or may not support
1346 * C6, and this is indicated in the CPUID mwait leaf.
1348 static struct cpuidle_state snr_cstates[] __initdata = {
1351 .desc = "MWAIT 0x00",
1352 .flags = MWAIT2flg(0x00),
1354 .target_residency = 2,
1355 .enter = &intel_idle,
1356 .enter_s2idle = intel_idle_s2idle, },
1359 .desc = "MWAIT 0x01",
1360 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1362 .target_residency = 25,
1363 .enter = &intel_idle,
1364 .enter_s2idle = intel_idle_s2idle, },
1367 .desc = "MWAIT 0x20",
1368 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
1369 .exit_latency = 130,
1370 .target_residency = 500,
1371 .enter = &intel_idle,
1372 .enter_s2idle = intel_idle_s2idle, },
1377 static struct cpuidle_state grr_cstates[] __initdata = {
1380 .desc = "MWAIT 0x00",
1381 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1383 .target_residency = 1,
1384 .enter = &intel_idle,
1385 .enter_s2idle = intel_idle_s2idle, },
1388 .desc = "MWAIT 0x01",
1389 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1391 .target_residency = 10,
1392 .enter = &intel_idle,
1393 .enter_s2idle = intel_idle_s2idle, },
1396 .desc = "MWAIT 0x22",
1397 .flags = MWAIT2flg(0x22) | CPUIDLE_FLAG_TLB_FLUSHED,
1398 .exit_latency = 140,
1399 .target_residency = 500,
1400 .enter = &intel_idle,
1401 .enter_s2idle = intel_idle_s2idle, },
1406 static struct cpuidle_state srf_cstates[] __initdata = {
1409 .desc = "MWAIT 0x00",
1410 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1412 .target_residency = 1,
1413 .enter = &intel_idle,
1414 .enter_s2idle = intel_idle_s2idle, },
1417 .desc = "MWAIT 0x01",
1418 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1420 .target_residency = 10,
1421 .enter = &intel_idle,
1422 .enter_s2idle = intel_idle_s2idle, },
1425 .desc = "MWAIT 0x22",
1426 .flags = MWAIT2flg(0x22) | CPUIDLE_FLAG_TLB_FLUSHED |
1427 CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
1428 .exit_latency = 270,
1429 .target_residency = 700,
1430 .enter = &intel_idle,
1431 .enter_s2idle = intel_idle_s2idle, },
1434 .desc = "MWAIT 0x23",
1435 .flags = MWAIT2flg(0x23) | CPUIDLE_FLAG_TLB_FLUSHED |
1436 CPUIDLE_FLAG_PARTIAL_HINT_MATCH,
1437 .exit_latency = 310,
1438 .target_residency = 900,
1439 .enter = &intel_idle,
1440 .enter_s2idle = intel_idle_s2idle, },
1445 static const struct idle_cpu idle_cpu_nehalem __initconst = {
1446 .state_table = nehalem_cstates,
1447 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
1448 .disable_promotion_to_c1e = true,
1451 static const struct idle_cpu idle_cpu_nhx __initconst = {
1452 .state_table = nehalem_cstates,
1453 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
1454 .disable_promotion_to_c1e = true,
1458 static const struct idle_cpu idle_cpu_atom __initconst = {
1459 .state_table = atom_cstates,
1462 static const struct idle_cpu idle_cpu_tangier __initconst = {
1463 .state_table = tangier_cstates,
1466 static const struct idle_cpu idle_cpu_lincroft __initconst = {
1467 .state_table = atom_cstates,
1468 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
1471 static const struct idle_cpu idle_cpu_snb __initconst = {
1472 .state_table = snb_cstates,
1473 .disable_promotion_to_c1e = true,
1476 static const struct idle_cpu idle_cpu_snx __initconst = {
1477 .state_table = snb_cstates,
1478 .disable_promotion_to_c1e = true,
1482 static const struct idle_cpu idle_cpu_byt __initconst = {
1483 .state_table = byt_cstates,
1484 .disable_promotion_to_c1e = true,
1487 static const struct idle_cpu idle_cpu_cht __initconst = {
1488 .state_table = cht_cstates,
1489 .disable_promotion_to_c1e = true,
1492 static const struct idle_cpu idle_cpu_ivb __initconst = {
1493 .state_table = ivb_cstates,
1494 .disable_promotion_to_c1e = true,
1497 static const struct idle_cpu idle_cpu_ivt __initconst = {
1498 .state_table = ivt_cstates,
1499 .disable_promotion_to_c1e = true,
1503 static const struct idle_cpu idle_cpu_hsw __initconst = {
1504 .state_table = hsw_cstates,
1505 .disable_promotion_to_c1e = true,
1508 static const struct idle_cpu idle_cpu_hsx __initconst = {
1509 .state_table = hsw_cstates,
1510 .disable_promotion_to_c1e = true,
1514 static const struct idle_cpu idle_cpu_bdw __initconst = {
1515 .state_table = bdw_cstates,
1516 .disable_promotion_to_c1e = true,
1519 static const struct idle_cpu idle_cpu_bdx __initconst = {
1520 .state_table = bdw_cstates,
1521 .disable_promotion_to_c1e = true,
1525 static const struct idle_cpu idle_cpu_skl __initconst = {
1526 .state_table = skl_cstates,
1527 .disable_promotion_to_c1e = true,
1530 static const struct idle_cpu idle_cpu_skx __initconst = {
1531 .state_table = skx_cstates,
1532 .disable_promotion_to_c1e = true,
1536 static const struct idle_cpu idle_cpu_icx __initconst = {
1537 .state_table = icx_cstates,
1538 .disable_promotion_to_c1e = true,
1542 static const struct idle_cpu idle_cpu_adl __initconst = {
1543 .state_table = adl_cstates,
1546 static const struct idle_cpu idle_cpu_adl_l __initconst = {
1547 .state_table = adl_l_cstates,
1550 static const struct idle_cpu idle_cpu_mtl_l __initconst = {
1551 .state_table = mtl_l_cstates,
1554 static const struct idle_cpu idle_cpu_gmt __initconst = {
1555 .state_table = gmt_cstates,
1558 static const struct idle_cpu idle_cpu_spr __initconst = {
1559 .state_table = spr_cstates,
1560 .disable_promotion_to_c1e = true,
1561 .c1_demotion_supported = true,
1565 static const struct idle_cpu idle_cpu_gnr __initconst = {
1566 .state_table = gnr_cstates,
1567 .disable_promotion_to_c1e = true,
1568 .c1_demotion_supported = true,
1572 static const struct idle_cpu idle_cpu_gnrd __initconst = {
1573 .state_table = gnrd_cstates,
1574 .disable_promotion_to_c1e = true,
1575 .c1_demotion_supported = true,
1579 static const struct idle_cpu idle_cpu_avn __initconst = {
1580 .state_table = avn_cstates,
1581 .disable_promotion_to_c1e = true,
1585 static const struct idle_cpu idle_cpu_knl __initconst = {
1586 .state_table = knl_cstates,
1590 static const struct idle_cpu idle_cpu_bxt __initconst = {
1591 .state_table = bxt_cstates,
1592 .disable_promotion_to_c1e = true,
1595 static const struct idle_cpu idle_cpu_dnv __initconst = {
1596 .state_table = dnv_cstates,
1597 .disable_promotion_to_c1e = true,
1601 static const struct idle_cpu idle_cpu_tmt __initconst = {
1602 .disable_promotion_to_c1e = true,
1605 static const struct idle_cpu idle_cpu_snr __initconst = {
1606 .state_table = snr_cstates,
1607 .disable_promotion_to_c1e = true,
1611 static const struct idle_cpu idle_cpu_grr __initconst = {
1612 .state_table = grr_cstates,
1613 .disable_promotion_to_c1e = true,
1614 .c1_demotion_supported = true,
1618 static const struct idle_cpu idle_cpu_srf __initconst = {
1619 .state_table = srf_cstates,
1620 .disable_promotion_to_c1e = true,
1621 .c1_demotion_supported = true,
1625 static const struct x86_cpu_id intel_idle_ids[] __initconst = {
1626 X86_MATCH_VFM(INTEL_NEHALEM_EP, &idle_cpu_nhx),
1627 X86_MATCH_VFM(INTEL_NEHALEM, &idle_cpu_nehalem),
1628 X86_MATCH_VFM(INTEL_NEHALEM_G, &idle_cpu_nehalem),
1629 X86_MATCH_VFM(INTEL_WESTMERE, &idle_cpu_nehalem),
1630 X86_MATCH_VFM(INTEL_WESTMERE_EP, &idle_cpu_nhx),
1631 X86_MATCH_VFM(INTEL_NEHALEM_EX, &idle_cpu_nhx),
1632 X86_MATCH_VFM(INTEL_ATOM_BONNELL, &idle_cpu_atom),
1633 X86_MATCH_VFM(INTEL_ATOM_BONNELL_MID, &idle_cpu_lincroft),
1634 X86_MATCH_VFM(INTEL_WESTMERE_EX, &idle_cpu_nhx),
1635 X86_MATCH_VFM(INTEL_SANDYBRIDGE, &idle_cpu_snb),
1636 X86_MATCH_VFM(INTEL_SANDYBRIDGE_X, &idle_cpu_snx),
1637 X86_MATCH_VFM(INTEL_ATOM_SALTWELL, &idle_cpu_atom),
1638 X86_MATCH_VFM(INTEL_ATOM_SILVERMONT, &idle_cpu_byt),
1639 X86_MATCH_VFM(INTEL_ATOM_SILVERMONT_MID, &idle_cpu_tangier),
1640 X86_MATCH_VFM(INTEL_ATOM_AIRMONT, &idle_cpu_cht),
1641 X86_MATCH_VFM(INTEL_IVYBRIDGE, &idle_cpu_ivb),
1642 X86_MATCH_VFM(INTEL_IVYBRIDGE_X, &idle_cpu_ivt),
1643 X86_MATCH_VFM(INTEL_HASWELL, &idle_cpu_hsw),
1644 X86_MATCH_VFM(INTEL_HASWELL_X, &idle_cpu_hsx),
1645 X86_MATCH_VFM(INTEL_HASWELL_L, &idle_cpu_hsw),
1646 X86_MATCH_VFM(INTEL_HASWELL_G, &idle_cpu_hsw),
1647 X86_MATCH_VFM(INTEL_ATOM_SILVERMONT_D, &idle_cpu_avn),
1648 X86_MATCH_VFM(INTEL_BROADWELL, &idle_cpu_bdw),
1649 X86_MATCH_VFM(INTEL_BROADWELL_G, &idle_cpu_bdw),
1650 X86_MATCH_VFM(INTEL_BROADWELL_X, &idle_cpu_bdx),
1651 X86_MATCH_VFM(INTEL_BROADWELL_D, &idle_cpu_bdx),
1652 X86_MATCH_VFM(INTEL_SKYLAKE_L, &idle_cpu_skl),
1653 X86_MATCH_VFM(INTEL_SKYLAKE, &idle_cpu_skl),
1654 X86_MATCH_VFM(INTEL_KABYLAKE_L, &idle_cpu_skl),
1655 X86_MATCH_VFM(INTEL_KABYLAKE, &idle_cpu_skl),
1656 X86_MATCH_VFM(INTEL_SKYLAKE_X, &idle_cpu_skx),
1657 X86_MATCH_VFM(INTEL_ICELAKE_X, &idle_cpu_icx),
1658 X86_MATCH_VFM(INTEL_ICELAKE_D, &idle_cpu_icx),
1659 X86_MATCH_VFM(INTEL_ALDERLAKE, &idle_cpu_adl),
1660 X86_MATCH_VFM(INTEL_ALDERLAKE_L, &idle_cpu_adl_l),
1661 X86_MATCH_VFM(INTEL_METEORLAKE_L, &idle_cpu_mtl_l),
1662 X86_MATCH_VFM(INTEL_ATOM_GRACEMONT, &idle_cpu_gmt),
1663 X86_MATCH_VFM(INTEL_SAPPHIRERAPIDS_X, &idle_cpu_spr),
1664 X86_MATCH_VFM(INTEL_EMERALDRAPIDS_X, &idle_cpu_spr),
1665 X86_MATCH_VFM(INTEL_GRANITERAPIDS_X, &idle_cpu_gnr),
1666 X86_MATCH_VFM(INTEL_GRANITERAPIDS_D, &idle_cpu_gnrd),
1667 X86_MATCH_VFM(INTEL_XEON_PHI_KNL, &idle_cpu_knl),
1668 X86_MATCH_VFM(INTEL_XEON_PHI_KNM, &idle_cpu_knl),
1669 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT, &idle_cpu_bxt),
1670 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_PLUS, &idle_cpu_bxt),
1671 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_D, &idle_cpu_dnv),
1672 X86_MATCH_VFM(INTEL_ATOM_TREMONT, &idle_cpu_tmt),
1673 X86_MATCH_VFM(INTEL_ATOM_TREMONT_L, &idle_cpu_tmt),
1674 X86_MATCH_VFM(INTEL_ATOM_TREMONT_D, &idle_cpu_snr),
1675 X86_MATCH_VFM(INTEL_ATOM_CRESTMONT, &idle_cpu_grr),
1676 X86_MATCH_VFM(INTEL_ATOM_CRESTMONT_X, &idle_cpu_srf),
1677 X86_MATCH_VFM(INTEL_ATOM_DARKMONT_X, &idle_cpu_srf),
1681 static const struct x86_cpu_id intel_mwait_ids[] __initconst = {
1682 X86_MATCH_VENDOR_FAM_FEATURE(INTEL, 6, X86_FEATURE_MWAIT, NULL),
1686 static bool __init intel_idle_max_cstate_reached(int cstate)
1688 if (cstate + 1 > max_cstate) {
1689 pr_info("max_cstate %d reached\n", max_cstate);
1695 static bool __init intel_idle_state_needs_timer_stop(struct cpuidle_state *state)
1697 unsigned long eax = flg2MWAIT(state->flags);
1699 if (boot_cpu_has(X86_FEATURE_ARAT))
1703 * Switch over to one-shot tick broadcast if the target C-state
1704 * is deeper than C1.
1706 return !!((eax >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK);
1709 #ifdef CONFIG_ACPI_PROCESSOR_CSTATE
1710 #include <acpi/processor.h>
1712 static bool no_acpi __read_mostly;
1713 module_param(no_acpi, bool, 0444);
1714 MODULE_PARM_DESC(no_acpi, "Do not use ACPI _CST for building the idle states list");
1716 static bool force_use_acpi __read_mostly; /* No effect if no_acpi is set. */
1717 module_param_named(use_acpi, force_use_acpi, bool, 0444);
1718 MODULE_PARM_DESC(use_acpi, "Use ACPI _CST for building the idle states list");
1720 static bool no_native __read_mostly; /* No effect if no_acpi is set. */
1721 module_param_named(no_native, no_native, bool, 0444);
1722 MODULE_PARM_DESC(no_native, "Ignore cpu specific (native) idle states in lieu of ACPI idle states");
1724 static struct acpi_processor_power acpi_state_table __initdata;
1727 * intel_idle_cst_usable - Check if the _CST information can be used.
1729 * Check if all of the C-states listed by _CST in the max_cstate range are
1730 * ACPI_CSTATE_FFH, which means that they should be entered via MWAIT.
1732 static bool __init intel_idle_cst_usable(void)
1736 limit = min_t(int, min_t(int, CPUIDLE_STATE_MAX, max_cstate + 1),
1737 acpi_state_table.count);
1739 for (cstate = 1; cstate < limit; cstate++) {
1740 struct acpi_processor_cx *cx = &acpi_state_table.states[cstate];
1742 if (cx->entry_method != ACPI_CSTATE_FFH)
1749 static bool __init intel_idle_acpi_cst_extract(void)
1754 pr_debug("Not allowed to use ACPI _CST\n");
1758 for_each_possible_cpu(cpu) {
1759 struct acpi_processor *pr = per_cpu(processors, cpu);
1764 if (acpi_processor_evaluate_cst(pr->handle, cpu, &acpi_state_table))
1767 acpi_state_table.count++;
1769 if (!intel_idle_cst_usable())
1772 if (!acpi_processor_claim_cst_control())
1778 acpi_state_table.count = 0;
1779 pr_debug("ACPI _CST not found or not usable\n");
1783 static void __init intel_idle_init_cstates_acpi(struct cpuidle_driver *drv)
1785 int cstate, limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
1788 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1789 * the interesting states are ACPI_CSTATE_FFH.
1791 for (cstate = 1; cstate < limit; cstate++) {
1792 struct acpi_processor_cx *cx;
1793 struct cpuidle_state *state;
1795 if (intel_idle_max_cstate_reached(cstate - 1))
1798 cx = &acpi_state_table.states[cstate];
1800 state = &drv->states[drv->state_count++];
1802 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d_ACPI", cstate);
1803 strscpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
1804 state->exit_latency = cx->latency;
1806 * For C1-type C-states use the same number for both the exit
1807 * latency and target residency, because that is the case for
1808 * C1 in the majority of the static C-states tables above.
1809 * For the other types of C-states, however, set the target
1810 * residency to 3 times the exit latency which should lead to
1811 * a reasonable balance between energy-efficiency and
1812 * performance in the majority of interesting cases.
1814 state->target_residency = cx->latency;
1815 if (cx->type > ACPI_STATE_C1)
1816 state->target_residency *= 3;
1818 state->flags = MWAIT2flg(cx->address);
1819 if (cx->type > ACPI_STATE_C2)
1820 state->flags |= CPUIDLE_FLAG_TLB_FLUSHED;
1822 if (disabled_states_mask & BIT(cstate))
1823 state->flags |= CPUIDLE_FLAG_OFF;
1825 if (intel_idle_state_needs_timer_stop(state))
1826 state->flags |= CPUIDLE_FLAG_TIMER_STOP;
1828 if (cx->type > ACPI_STATE_C1 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
1829 mark_tsc_unstable("TSC halts in idle");
1831 state->enter = intel_idle;
1832 state->enter_dead = intel_idle_enter_dead;
1833 state->enter_s2idle = intel_idle_s2idle;
1837 static bool __init intel_idle_off_by_default(unsigned int flags, u32 mwait_hint)
1842 * If there are no _CST C-states, do not disable any C-states by
1845 if (!acpi_state_table.count)
1848 limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
1850 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1851 * the interesting states are ACPI_CSTATE_FFH.
1853 for (cstate = 1; cstate < limit; cstate++) {
1854 u32 acpi_hint = acpi_state_table.states[cstate].address;
1855 u32 table_hint = mwait_hint;
1857 if (flags & CPUIDLE_FLAG_PARTIAL_HINT_MATCH) {
1858 acpi_hint &= ~MWAIT_SUBSTATE_MASK;
1859 table_hint &= ~MWAIT_SUBSTATE_MASK;
1862 if (acpi_hint == table_hint)
1868 static inline bool ignore_native(void)
1870 return no_native && !no_acpi;
1872 #else /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1873 #define force_use_acpi (false)
1875 static inline bool intel_idle_acpi_cst_extract(void) { return false; }
1876 static inline void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) { }
1877 static inline bool intel_idle_off_by_default(unsigned int flags, u32 mwait_hint)
1881 static inline bool ignore_native(void) { return false; }
1882 #endif /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1885 * ivt_idle_state_table_update - Tune the idle states table for Ivy Town.
1887 * Tune IVT multi-socket targets.
1888 * Assumption: num_sockets == (max_package_num + 1).
1890 static void __init ivt_idle_state_table_update(void)
1892 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1893 int cpu, package_num, num_sockets = 1;
1895 for_each_online_cpu(cpu) {
1896 package_num = topology_physical_package_id(cpu);
1897 if (package_num + 1 > num_sockets) {
1898 num_sockets = package_num + 1;
1900 if (num_sockets > 4) {
1901 cpuidle_state_table = ivt_cstates_8s;
1907 if (num_sockets > 2)
1908 cpuidle_state_table = ivt_cstates_4s;
1910 /* else, 1 and 2 socket systems use default ivt_cstates */
1914 * irtl_2_usec - IRTL to microseconds conversion.
1915 * @irtl: IRTL MSR value.
1917 * Translate the IRTL (Interrupt Response Time Limit) MSR value to microseconds.
1919 static unsigned long long __init irtl_2_usec(unsigned long long irtl)
1921 static const unsigned int irtl_ns_units[] __initconst = {
1922 1, 32, 1024, 32768, 1048576, 33554432, 0, 0
1924 unsigned long long ns;
1929 ns = irtl_ns_units[(irtl >> 10) & 0x7];
1931 return div_u64((irtl & 0x3FF) * ns, NSEC_PER_USEC);
1935 * bxt_idle_state_table_update - Fix up the Broxton idle states table.
1937 * On BXT, trust the IRTL (Interrupt Response Time Limit) MSR to show the
1938 * definitive maximum latency and use the same value for target_residency.
1940 static void __init bxt_idle_state_table_update(void)
1942 unsigned long long msr;
1945 rdmsrq(MSR_PKGC6_IRTL, msr);
1946 usec = irtl_2_usec(msr);
1948 bxt_cstates[2].exit_latency = usec;
1949 bxt_cstates[2].target_residency = usec;
1952 rdmsrq(MSR_PKGC7_IRTL, msr);
1953 usec = irtl_2_usec(msr);
1955 bxt_cstates[3].exit_latency = usec;
1956 bxt_cstates[3].target_residency = usec;
1959 rdmsrq(MSR_PKGC8_IRTL, msr);
1960 usec = irtl_2_usec(msr);
1962 bxt_cstates[4].exit_latency = usec;
1963 bxt_cstates[4].target_residency = usec;
1966 rdmsrq(MSR_PKGC9_IRTL, msr);
1967 usec = irtl_2_usec(msr);
1969 bxt_cstates[5].exit_latency = usec;
1970 bxt_cstates[5].target_residency = usec;
1973 rdmsrq(MSR_PKGC10_IRTL, msr);
1974 usec = irtl_2_usec(msr);
1976 bxt_cstates[6].exit_latency = usec;
1977 bxt_cstates[6].target_residency = usec;
1983 * sklh_idle_state_table_update - Fix up the Sky Lake idle states table.
1985 * On SKL-H (model 0x5e) skip C8 and C9 if C10 is enabled and SGX disabled.
1987 static void __init sklh_idle_state_table_update(void)
1989 unsigned long long msr;
1990 unsigned int eax, ebx, ecx, edx;
1993 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1994 if (max_cstate <= 7)
1997 /* if PC10 not present in CPUID.MWAIT.EDX */
1998 if ((mwait_substates & (0xF << 28)) == 0)
2001 rdmsrq(MSR_PKG_CST_CONFIG_CONTROL, msr);
2003 /* PC10 is not enabled in PKG C-state limit */
2004 if ((msr & 0xF) != 8)
2008 cpuid(7, &eax, &ebx, &ecx, &edx);
2010 /* if SGX is present */
2011 if (ebx & (1 << 2)) {
2013 rdmsrq(MSR_IA32_FEAT_CTL, msr);
2015 /* if SGX is enabled */
2016 if (msr & (1 << 18))
2020 skl_cstates[5].flags |= CPUIDLE_FLAG_UNUSABLE; /* C8-SKL */
2021 skl_cstates[6].flags |= CPUIDLE_FLAG_UNUSABLE; /* C9-SKL */
2025 * skx_idle_state_table_update - Adjust the Sky Lake/Cascade Lake
2026 * idle states table.
2028 static void __init skx_idle_state_table_update(void)
2030 unsigned long long msr;
2032 rdmsrq(MSR_PKG_CST_CONFIG_CONTROL, msr);
2035 * 000b: C0/C1 (no package C-state support)
2037 * 010b: C6 (non-retention)
2038 * 011b: C6 (retention)
2039 * 111b: No Package C state limits.
2041 if ((msr & 0x7) < 2) {
2043 * Uses the CC6 + PC0 latency and 3 times of
2044 * latency for target_residency if the PC6
2045 * is disabled in BIOS. This is consistent
2046 * with how intel_idle driver uses _CST
2047 * to set the target_residency.
2049 skx_cstates[2].exit_latency = 92;
2050 skx_cstates[2].target_residency = 276;
2055 * adl_idle_state_table_update - Adjust AlderLake idle states table.
2057 static void __init adl_idle_state_table_update(void)
2059 /* Check if user prefers C1 over C1E. */
2060 if (preferred_states_mask & BIT(1) && !(preferred_states_mask & BIT(2))) {
2061 cpuidle_state_table[0].flags &= ~CPUIDLE_FLAG_UNUSABLE;
2062 cpuidle_state_table[1].flags |= CPUIDLE_FLAG_UNUSABLE;
2064 /* Disable C1E by clearing the "C1E promotion" bit. */
2065 c1e_promotion = C1E_PROMOTION_DISABLE;
2069 /* Make sure C1E is enabled by default */
2070 c1e_promotion = C1E_PROMOTION_ENABLE;
2074 * spr_idle_state_table_update - Adjust Sapphire Rapids idle states table.
2076 static void __init spr_idle_state_table_update(void)
2078 unsigned long long msr;
2081 * By default, the C6 state assumes the worst-case scenario of package
2082 * C6. However, if PC6 is disabled, we update the numbers to match
2085 rdmsrq(MSR_PKG_CST_CONFIG_CONTROL, msr);
2087 /* Limit value 2 and above allow for PC6. */
2088 if ((msr & 0x7) < 2) {
2089 spr_cstates[2].exit_latency = 190;
2090 spr_cstates[2].target_residency = 600;
2095 * byt_cht_auto_demotion_disable - Disable Bay/Cherry Trail auto-demotion.
2097 static void __init byt_cht_auto_demotion_disable(void)
2099 wrmsrq(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
2100 wrmsrq(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
2103 static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
2105 unsigned int mwait_cstate = (MWAIT_HINT2CSTATE(mwait_hint) + 1) &
2107 unsigned int num_substates = (mwait_substates >> mwait_cstate * 4) &
2108 MWAIT_SUBSTATE_MASK;
2110 /* Ignore the C-state if there are NO sub-states in CPUID for it. */
2111 if (num_substates == 0)
2114 if (mwait_cstate > 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
2115 mark_tsc_unstable("TSC halts in idle states deeper than C2");
2120 static void state_update_enter_method(struct cpuidle_state *state, int cstate)
2122 if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) {
2124 * Combining with XSTATE with IBRS or IRQ_ENABLE flags
2125 * is not currently supported but this driver.
2127 WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IBRS);
2128 WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
2129 state->enter = intel_idle_xstate;
2133 if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
2134 ((state->flags & CPUIDLE_FLAG_IBRS) || ibrs_off)) {
2136 * IBRS mitigation requires that C-states are entered
2137 * with interrupts disabled.
2139 if (ibrs_off && (state->flags & CPUIDLE_FLAG_IRQ_ENABLE))
2140 state->flags &= ~CPUIDLE_FLAG_IRQ_ENABLE;
2141 WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
2142 state->enter = intel_idle_ibrs;
2146 if (state->flags & CPUIDLE_FLAG_IRQ_ENABLE) {
2147 state->enter = intel_idle_irq;
2152 pr_info("forced intel_idle_irq for state %d\n", cstate);
2153 state->enter = intel_idle_irq;
2157 static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
2161 switch (boot_cpu_data.x86_vfm) {
2162 case INTEL_IVYBRIDGE_X:
2163 ivt_idle_state_table_update();
2165 case INTEL_ATOM_GOLDMONT:
2166 case INTEL_ATOM_GOLDMONT_PLUS:
2167 bxt_idle_state_table_update();
2170 sklh_idle_state_table_update();
2172 case INTEL_SKYLAKE_X:
2173 skx_idle_state_table_update();
2175 case INTEL_SAPPHIRERAPIDS_X:
2176 case INTEL_EMERALDRAPIDS_X:
2177 spr_idle_state_table_update();
2179 case INTEL_ALDERLAKE:
2180 case INTEL_ALDERLAKE_L:
2181 case INTEL_ATOM_GRACEMONT:
2182 adl_idle_state_table_update();
2184 case INTEL_ATOM_SILVERMONT:
2185 case INTEL_ATOM_AIRMONT:
2186 byt_cht_auto_demotion_disable();
2190 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
2191 struct cpuidle_state *state;
2192 unsigned int mwait_hint;
2194 if (intel_idle_max_cstate_reached(cstate))
2197 if (!cpuidle_state_table[cstate].enter &&
2198 !cpuidle_state_table[cstate].enter_s2idle)
2201 if (!cpuidle_state_table[cstate].enter_dead)
2202 cpuidle_state_table[cstate].enter_dead = intel_idle_enter_dead;
2204 /* If marked as unusable, skip this state. */
2205 if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_UNUSABLE) {
2206 pr_debug("state %s is disabled\n",
2207 cpuidle_state_table[cstate].name);
2211 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
2212 if (!intel_idle_verify_cstate(mwait_hint))
2215 /* Structure copy. */
2216 drv->states[drv->state_count] = cpuidle_state_table[cstate];
2217 state = &drv->states[drv->state_count];
2219 state_update_enter_method(state, cstate);
2222 if ((disabled_states_mask & BIT(drv->state_count)) ||
2223 ((icpu->use_acpi || force_use_acpi) &&
2224 intel_idle_off_by_default(state->flags, mwait_hint) &&
2225 !(state->flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
2226 state->flags |= CPUIDLE_FLAG_OFF;
2228 if (intel_idle_state_needs_timer_stop(state))
2229 state->flags |= CPUIDLE_FLAG_TIMER_STOP;
2236 * intel_idle_cpuidle_driver_init - Create the list of available idle states.
2237 * @drv: cpuidle driver structure to initialize.
2239 static void __init intel_idle_cpuidle_driver_init(struct cpuidle_driver *drv)
2241 cpuidle_poll_state_init(drv);
2243 if (disabled_states_mask & BIT(0))
2244 drv->states[0].flags |= CPUIDLE_FLAG_OFF;
2246 drv->state_count = 1;
2248 if (icpu && icpu->state_table)
2249 intel_idle_init_cstates_icpu(drv);
2251 intel_idle_init_cstates_acpi(drv);
2254 static void auto_demotion_disable(void)
2256 unsigned long long msr_bits;
2258 rdmsrq(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
2259 msr_bits &= ~auto_demotion_disable_flags;
2260 wrmsrq(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
2263 static void c1e_promotion_enable(void)
2265 unsigned long long msr_bits;
2267 rdmsrq(MSR_IA32_POWER_CTL, msr_bits);
2269 wrmsrq(MSR_IA32_POWER_CTL, msr_bits);
2272 static void c1e_promotion_disable(void)
2274 unsigned long long msr_bits;
2276 rdmsrq(MSR_IA32_POWER_CTL, msr_bits);
2278 wrmsrq(MSR_IA32_POWER_CTL, msr_bits);
2282 * intel_idle_cpu_init - Register the target CPU with the cpuidle core.
2283 * @cpu: CPU to initialize.
2285 * Register a cpuidle device object for @cpu and update its MSRs in accordance
2286 * with the processor model flags.
2288 static int intel_idle_cpu_init(unsigned int cpu)
2290 struct cpuidle_device *dev;
2292 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
2295 if (cpuidle_register_device(dev)) {
2296 pr_debug("cpuidle_register_device %d failed!\n", cpu);
2300 if (auto_demotion_disable_flags)
2301 auto_demotion_disable();
2303 if (c1e_promotion == C1E_PROMOTION_ENABLE)
2304 c1e_promotion_enable();
2305 else if (c1e_promotion == C1E_PROMOTION_DISABLE)
2306 c1e_promotion_disable();
2311 static int intel_idle_cpu_online(unsigned int cpu)
2313 struct cpuidle_device *dev;
2315 if (!boot_cpu_has(X86_FEATURE_ARAT))
2316 tick_broadcast_enable();
2319 * Some systems can hotplug a cpu at runtime after
2320 * the kernel has booted, we have to initialize the
2321 * driver in this case
2323 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
2324 if (!dev->registered)
2325 return intel_idle_cpu_init(cpu);
2331 * intel_idle_cpuidle_devices_uninit - Unregister all cpuidle devices.
2333 static void __init intel_idle_cpuidle_devices_uninit(void)
2337 for_each_online_cpu(i)
2338 cpuidle_unregister_device(per_cpu_ptr(intel_idle_cpuidle_devices, i));
2341 static void intel_c1_demotion_toggle(void *enable)
2343 unsigned long long msr_val;
2345 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_val);
2347 * Enable/disable C1 undemotion along with C1 demotion, as this is the
2348 * most sensible configuration in general.
2351 msr_val |= NHM_C1_AUTO_DEMOTE | SNB_C1_AUTO_UNDEMOTE;
2353 msr_val &= ~(NHM_C1_AUTO_DEMOTE | SNB_C1_AUTO_UNDEMOTE);
2354 wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_val);
2357 static ssize_t intel_c1_demotion_store(struct device *dev,
2358 struct device_attribute *attr,
2359 const char *buf, size_t count)
2364 err = kstrtobool(buf, &enable);
2368 mutex_lock(&c1_demotion_mutex);
2369 /* Enable/disable C1 demotion on all CPUs */
2370 on_each_cpu(intel_c1_demotion_toggle, (void *)enable, 1);
2371 mutex_unlock(&c1_demotion_mutex);
2376 static ssize_t intel_c1_demotion_show(struct device *dev,
2377 struct device_attribute *attr, char *buf)
2379 unsigned long long msr_val;
2382 * Read the MSR value for a CPU and assume it is the same for all CPUs. Any other
2383 * configuration would be a BIOS bug.
2385 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_val);
2386 return sysfs_emit(buf, "%d\n", !!(msr_val & NHM_C1_AUTO_DEMOTE));
2388 static DEVICE_ATTR_RW(intel_c1_demotion);
2390 static int __init intel_idle_sysfs_init(void)
2394 if (!c1_demotion_supported)
2397 sysfs_root = bus_get_dev_root(&cpu_subsys);
2401 err = sysfs_add_file_to_group(&sysfs_root->kobj,
2402 &dev_attr_intel_c1_demotion.attr,
2405 put_device(sysfs_root);
2412 static void __init intel_idle_sysfs_uninit(void)
2417 sysfs_remove_file_from_group(&sysfs_root->kobj,
2418 &dev_attr_intel_c1_demotion.attr,
2420 put_device(sysfs_root);
2423 static int __init intel_idle_init(void)
2425 const struct x86_cpu_id *id;
2426 unsigned int eax, ebx, ecx;
2429 /* Do not load intel_idle at all for now if idle= is passed */
2430 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
2433 if (max_cstate == 0) {
2434 pr_debug("disabled\n");
2438 id = x86_match_cpu(intel_idle_ids);
2440 if (!boot_cpu_has(X86_FEATURE_MWAIT)) {
2441 pr_debug("Please enable MWAIT in BIOS SETUP\n");
2445 id = x86_match_cpu(intel_mwait_ids);
2450 cpuid(CPUID_LEAF_MWAIT, &eax, &ebx, &ecx, &mwait_substates);
2452 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
2453 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
2457 pr_debug("MWAIT substates: 0x%x\n", mwait_substates);
2459 icpu = (const struct idle_cpu *)id->driver_data;
2460 if (icpu && ignore_native()) {
2461 pr_debug("ignoring native CPU idle states\n");
2465 if (icpu->state_table)
2466 cpuidle_state_table = icpu->state_table;
2467 else if (!intel_idle_acpi_cst_extract())
2470 auto_demotion_disable_flags = icpu->auto_demotion_disable_flags;
2471 if (icpu->disable_promotion_to_c1e)
2472 c1e_promotion = C1E_PROMOTION_DISABLE;
2473 if (icpu->c1_demotion_supported)
2474 c1_demotion_supported = true;
2475 if (icpu->use_acpi || force_use_acpi)
2476 intel_idle_acpi_cst_extract();
2477 } else if (!intel_idle_acpi_cst_extract()) {
2481 pr_debug("v" INTEL_IDLE_VERSION " model 0x%X\n",
2482 boot_cpu_data.x86_model);
2484 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
2485 if (!intel_idle_cpuidle_devices)
2488 retval = intel_idle_sysfs_init();
2490 pr_warn("failed to initialized sysfs");
2492 intel_idle_cpuidle_driver_init(&intel_idle_driver);
2494 retval = cpuidle_register_driver(&intel_idle_driver);
2496 struct cpuidle_driver *drv = cpuidle_get_driver();
2497 printk(KERN_DEBUG pr_fmt("intel_idle yielding to %s\n"),
2498 drv ? drv->name : "none");
2499 goto init_driver_fail;
2502 retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online",
2503 intel_idle_cpu_online, NULL);
2507 pr_debug("Local APIC timer is reliable in %s\n",
2508 boot_cpu_has(X86_FEATURE_ARAT) ? "all C-states" : "C1");
2510 arch_cpu_rescan_dead_smt_siblings();
2515 intel_idle_cpuidle_devices_uninit();
2516 cpuidle_unregister_driver(&intel_idle_driver);
2518 intel_idle_sysfs_uninit();
2519 free_percpu(intel_idle_cpuidle_devices);
2523 subsys_initcall_sync(intel_idle_init);
2526 * We are not really modular, but we used to support that. Meaning we also
2527 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
2528 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
2529 * is the easiest way (currently) to continue doing that.
2531 module_param(max_cstate, int, 0444);
2533 * The positions of the bits that are set in this number are the indices of the
2534 * idle states to be disabled by default (as reflected by the names of the
2535 * corresponding idle state directories in sysfs, "state0", "state1" ...
2536 * "state<i>" ..., where <i> is the index of the given state).
2538 module_param_named(states_off, disabled_states_mask, uint, 0444);
2539 MODULE_PARM_DESC(states_off, "Mask of disabled idle states");
2541 * Some platforms come with mutually exclusive C-states, so that if one is
2542 * enabled, the other C-states must not be used. Example: C1 and C1E on
2543 * Sapphire Rapids platform. This parameter allows for selecting the
2544 * preferred C-states among the groups of mutually exclusive C-states - the
2545 * selected C-states will be registered, the other C-states from the mutually
2546 * exclusive group won't be registered. If the platform has no mutually
2547 * exclusive C-states, this parameter has no effect.
2549 module_param_named(preferred_cstates, preferred_states_mask, uint, 0444);
2550 MODULE_PARM_DESC(preferred_cstates, "Mask of preferred idle states");
2552 * Debugging option that forces the driver to enter all C-states with
2553 * interrupts enabled. Does not apply to C-states with
2554 * 'CPUIDLE_FLAG_INIT_XSTATE' and 'CPUIDLE_FLAG_IBRS' flags.
2556 module_param(force_irq_on, bool, 0444);
2558 * Force the disabling of IBRS when X86_FEATURE_KERNEL_IBRS is on and
2559 * CPUIDLE_FLAG_IRQ_ENABLE isn't set.
2561 module_param(ibrs_off, bool, 0444);
2562 MODULE_PARM_DESC(ibrs_off, "Disable IBRS when idle");