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/nospec-branch.h>
57 #include <asm/mwait.h>
59 #include <asm/fpu/api.h>
61 #define INTEL_IDLE_VERSION "0.5.1"
63 static struct cpuidle_driver intel_idle_driver = {
67 /* intel_idle.max_cstate=0 disables driver */
68 static int max_cstate = CPUIDLE_STATE_MAX - 1;
69 static unsigned int disabled_states_mask __read_mostly;
70 static unsigned int preferred_states_mask __read_mostly;
71 static bool force_irq_on __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 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
125 * the C-state (top nibble) and sub-state (bottom nibble)
126 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
128 * We store the hint at the top of our "flags" for each state.
130 #define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
131 #define MWAIT2flg(eax) ((eax & 0xFF) << 24)
133 static __always_inline int __intel_idle(struct cpuidle_device *dev,
134 struct cpuidle_driver *drv, int index)
136 struct cpuidle_state *state = &drv->states[index];
137 unsigned long eax = flg2MWAIT(state->flags);
138 unsigned long ecx = 1; /* break on interrupt flag */
140 mwait_idle_with_hints(eax, ecx);
146 * intel_idle - Ask the processor to enter the given idle state.
147 * @dev: cpuidle device of the target CPU.
148 * @drv: cpuidle driver (assumed to point to intel_idle_driver).
149 * @index: Target idle state index.
151 * Use the MWAIT instruction to notify the processor that the CPU represented by
152 * @dev is idle and it can try to enter the idle state corresponding to @index.
154 * If the local APIC timer is not known to be reliable in the target idle state,
155 * enable one-shot tick broadcasting for the target CPU before executing MWAIT.
157 * Must be called under local_irq_disable().
159 static __cpuidle int intel_idle(struct cpuidle_device *dev,
160 struct cpuidle_driver *drv, int index)
162 return __intel_idle(dev, drv, index);
165 static __cpuidle int intel_idle_irq(struct cpuidle_device *dev,
166 struct cpuidle_driver *drv, int index)
170 raw_local_irq_enable();
171 ret = __intel_idle(dev, drv, index);
172 raw_local_irq_disable();
177 static __cpuidle int intel_idle_ibrs(struct cpuidle_device *dev,
178 struct cpuidle_driver *drv, int index)
180 bool smt_active = sched_smt_active();
181 u64 spec_ctrl = spec_ctrl_current();
185 native_wrmsrl(MSR_IA32_SPEC_CTRL, 0);
187 ret = __intel_idle(dev, drv, index);
190 native_wrmsrl(MSR_IA32_SPEC_CTRL, spec_ctrl);
195 static __cpuidle int intel_idle_xstate(struct cpuidle_device *dev,
196 struct cpuidle_driver *drv, int index)
199 return __intel_idle(dev, drv, index);
202 static __always_inline int __intel_idle_hlt(struct cpuidle_device *dev,
203 struct cpuidle_driver *drv, int index)
206 raw_local_irq_disable();
211 * intel_idle_hlt - Ask the processor to enter the given idle state using hlt.
212 * @dev: cpuidle device of the target CPU.
213 * @drv: cpuidle driver (assumed to point to intel_idle_driver).
214 * @index: Target idle state index.
216 * Use the HLT instruction to notify the processor that the CPU represented by
217 * @dev is idle and it can try to enter the idle state corresponding to @index.
219 * Must be called under local_irq_disable().
221 static __cpuidle int intel_idle_hlt(struct cpuidle_device *dev,
222 struct cpuidle_driver *drv, int index)
224 return __intel_idle_hlt(dev, drv, index);
227 static __cpuidle int intel_idle_hlt_irq_on(struct cpuidle_device *dev,
228 struct cpuidle_driver *drv, int index)
232 raw_local_irq_enable();
233 ret = __intel_idle_hlt(dev, drv, index);
234 raw_local_irq_disable();
240 * intel_idle_s2idle - Ask the processor to enter the given idle state.
241 * @dev: cpuidle device of the target CPU.
242 * @drv: cpuidle driver (assumed to point to intel_idle_driver).
243 * @index: Target idle state index.
245 * Use the MWAIT instruction to notify the processor that the CPU represented by
246 * @dev is idle and it can try to enter the idle state corresponding to @index.
248 * Invoked as a suspend-to-idle callback routine with frozen user space, frozen
249 * scheduler tick and suspended scheduler clock on the target CPU.
251 static __cpuidle int intel_idle_s2idle(struct cpuidle_device *dev,
252 struct cpuidle_driver *drv, int index)
254 unsigned long ecx = 1; /* break on interrupt flag */
255 struct cpuidle_state *state = &drv->states[index];
256 unsigned long eax = flg2MWAIT(state->flags);
258 if (state->flags & CPUIDLE_FLAG_INIT_XSTATE)
261 mwait_idle_with_hints(eax, ecx);
267 * States are indexed by the cstate number,
268 * which is also the index into the MWAIT hint array.
269 * Thus C0 is a dummy.
271 static struct cpuidle_state nehalem_cstates[] __initdata = {
274 .desc = "MWAIT 0x00",
275 .flags = MWAIT2flg(0x00),
277 .target_residency = 6,
278 .enter = &intel_idle,
279 .enter_s2idle = intel_idle_s2idle, },
282 .desc = "MWAIT 0x01",
283 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
285 .target_residency = 20,
286 .enter = &intel_idle,
287 .enter_s2idle = intel_idle_s2idle, },
290 .desc = "MWAIT 0x10",
291 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
293 .target_residency = 80,
294 .enter = &intel_idle,
295 .enter_s2idle = intel_idle_s2idle, },
298 .desc = "MWAIT 0x20",
299 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
301 .target_residency = 800,
302 .enter = &intel_idle,
303 .enter_s2idle = intel_idle_s2idle, },
308 static struct cpuidle_state snb_cstates[] __initdata = {
311 .desc = "MWAIT 0x00",
312 .flags = MWAIT2flg(0x00),
314 .target_residency = 2,
315 .enter = &intel_idle,
316 .enter_s2idle = intel_idle_s2idle, },
319 .desc = "MWAIT 0x01",
320 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
322 .target_residency = 20,
323 .enter = &intel_idle,
324 .enter_s2idle = intel_idle_s2idle, },
327 .desc = "MWAIT 0x10",
328 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
330 .target_residency = 211,
331 .enter = &intel_idle,
332 .enter_s2idle = intel_idle_s2idle, },
335 .desc = "MWAIT 0x20",
336 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
338 .target_residency = 345,
339 .enter = &intel_idle,
340 .enter_s2idle = intel_idle_s2idle, },
343 .desc = "MWAIT 0x30",
344 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
346 .target_residency = 345,
347 .enter = &intel_idle,
348 .enter_s2idle = intel_idle_s2idle, },
353 static struct cpuidle_state byt_cstates[] __initdata = {
356 .desc = "MWAIT 0x00",
357 .flags = MWAIT2flg(0x00),
359 .target_residency = 1,
360 .enter = &intel_idle,
361 .enter_s2idle = intel_idle_s2idle, },
364 .desc = "MWAIT 0x58",
365 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
367 .target_residency = 275,
368 .enter = &intel_idle,
369 .enter_s2idle = intel_idle_s2idle, },
372 .desc = "MWAIT 0x52",
373 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
375 .target_residency = 560,
376 .enter = &intel_idle,
377 .enter_s2idle = intel_idle_s2idle, },
380 .desc = "MWAIT 0x60",
381 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
382 .exit_latency = 1200,
383 .target_residency = 4000,
384 .enter = &intel_idle,
385 .enter_s2idle = intel_idle_s2idle, },
388 .desc = "MWAIT 0x64",
389 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
390 .exit_latency = 10000,
391 .target_residency = 20000,
392 .enter = &intel_idle,
393 .enter_s2idle = intel_idle_s2idle, },
398 static struct cpuidle_state cht_cstates[] __initdata = {
401 .desc = "MWAIT 0x00",
402 .flags = MWAIT2flg(0x00),
404 .target_residency = 1,
405 .enter = &intel_idle,
406 .enter_s2idle = intel_idle_s2idle, },
409 .desc = "MWAIT 0x58",
410 .flags = MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED,
412 .target_residency = 275,
413 .enter = &intel_idle,
414 .enter_s2idle = intel_idle_s2idle, },
417 .desc = "MWAIT 0x52",
418 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
420 .target_residency = 560,
421 .enter = &intel_idle,
422 .enter_s2idle = intel_idle_s2idle, },
425 .desc = "MWAIT 0x60",
426 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
427 .exit_latency = 1200,
428 .target_residency = 4000,
429 .enter = &intel_idle,
430 .enter_s2idle = intel_idle_s2idle, },
433 .desc = "MWAIT 0x64",
434 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
435 .exit_latency = 10000,
436 .target_residency = 20000,
437 .enter = &intel_idle,
438 .enter_s2idle = intel_idle_s2idle, },
443 static struct cpuidle_state ivb_cstates[] __initdata = {
446 .desc = "MWAIT 0x00",
447 .flags = MWAIT2flg(0x00),
449 .target_residency = 1,
450 .enter = &intel_idle,
451 .enter_s2idle = intel_idle_s2idle, },
454 .desc = "MWAIT 0x01",
455 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
457 .target_residency = 20,
458 .enter = &intel_idle,
459 .enter_s2idle = intel_idle_s2idle, },
462 .desc = "MWAIT 0x10",
463 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
465 .target_residency = 156,
466 .enter = &intel_idle,
467 .enter_s2idle = intel_idle_s2idle, },
470 .desc = "MWAIT 0x20",
471 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
473 .target_residency = 300,
474 .enter = &intel_idle,
475 .enter_s2idle = intel_idle_s2idle, },
478 .desc = "MWAIT 0x30",
479 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
481 .target_residency = 300,
482 .enter = &intel_idle,
483 .enter_s2idle = intel_idle_s2idle, },
488 static struct cpuidle_state ivt_cstates[] __initdata = {
491 .desc = "MWAIT 0x00",
492 .flags = MWAIT2flg(0x00),
494 .target_residency = 1,
495 .enter = &intel_idle,
496 .enter_s2idle = intel_idle_s2idle, },
499 .desc = "MWAIT 0x01",
500 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
502 .target_residency = 80,
503 .enter = &intel_idle,
504 .enter_s2idle = intel_idle_s2idle, },
507 .desc = "MWAIT 0x10",
508 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
510 .target_residency = 156,
511 .enter = &intel_idle,
512 .enter_s2idle = intel_idle_s2idle, },
515 .desc = "MWAIT 0x20",
516 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
518 .target_residency = 300,
519 .enter = &intel_idle,
520 .enter_s2idle = intel_idle_s2idle, },
525 static struct cpuidle_state ivt_cstates_4s[] __initdata = {
528 .desc = "MWAIT 0x00",
529 .flags = MWAIT2flg(0x00),
531 .target_residency = 1,
532 .enter = &intel_idle,
533 .enter_s2idle = intel_idle_s2idle, },
536 .desc = "MWAIT 0x01",
537 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
539 .target_residency = 250,
540 .enter = &intel_idle,
541 .enter_s2idle = intel_idle_s2idle, },
544 .desc = "MWAIT 0x10",
545 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
547 .target_residency = 300,
548 .enter = &intel_idle,
549 .enter_s2idle = intel_idle_s2idle, },
552 .desc = "MWAIT 0x20",
553 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
555 .target_residency = 400,
556 .enter = &intel_idle,
557 .enter_s2idle = intel_idle_s2idle, },
562 static struct cpuidle_state ivt_cstates_8s[] __initdata = {
565 .desc = "MWAIT 0x00",
566 .flags = MWAIT2flg(0x00),
568 .target_residency = 1,
569 .enter = &intel_idle,
570 .enter_s2idle = intel_idle_s2idle, },
573 .desc = "MWAIT 0x01",
574 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
576 .target_residency = 500,
577 .enter = &intel_idle,
578 .enter_s2idle = intel_idle_s2idle, },
581 .desc = "MWAIT 0x10",
582 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
584 .target_residency = 600,
585 .enter = &intel_idle,
586 .enter_s2idle = intel_idle_s2idle, },
589 .desc = "MWAIT 0x20",
590 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
592 .target_residency = 700,
593 .enter = &intel_idle,
594 .enter_s2idle = intel_idle_s2idle, },
599 static struct cpuidle_state hsw_cstates[] __initdata = {
602 .desc = "MWAIT 0x00",
603 .flags = MWAIT2flg(0x00),
605 .target_residency = 2,
606 .enter = &intel_idle,
607 .enter_s2idle = intel_idle_s2idle, },
610 .desc = "MWAIT 0x01",
611 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
613 .target_residency = 20,
614 .enter = &intel_idle,
615 .enter_s2idle = intel_idle_s2idle, },
618 .desc = "MWAIT 0x10",
619 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
621 .target_residency = 100,
622 .enter = &intel_idle,
623 .enter_s2idle = intel_idle_s2idle, },
626 .desc = "MWAIT 0x20",
627 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
629 .target_residency = 400,
630 .enter = &intel_idle,
631 .enter_s2idle = intel_idle_s2idle, },
634 .desc = "MWAIT 0x32",
635 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
637 .target_residency = 500,
638 .enter = &intel_idle,
639 .enter_s2idle = intel_idle_s2idle, },
642 .desc = "MWAIT 0x40",
643 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
645 .target_residency = 900,
646 .enter = &intel_idle,
647 .enter_s2idle = intel_idle_s2idle, },
650 .desc = "MWAIT 0x50",
651 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
653 .target_residency = 1800,
654 .enter = &intel_idle,
655 .enter_s2idle = intel_idle_s2idle, },
658 .desc = "MWAIT 0x60",
659 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
660 .exit_latency = 2600,
661 .target_residency = 7700,
662 .enter = &intel_idle,
663 .enter_s2idle = intel_idle_s2idle, },
667 static struct cpuidle_state bdw_cstates[] __initdata = {
670 .desc = "MWAIT 0x00",
671 .flags = MWAIT2flg(0x00),
673 .target_residency = 2,
674 .enter = &intel_idle,
675 .enter_s2idle = intel_idle_s2idle, },
678 .desc = "MWAIT 0x01",
679 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
681 .target_residency = 20,
682 .enter = &intel_idle,
683 .enter_s2idle = intel_idle_s2idle, },
686 .desc = "MWAIT 0x10",
687 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
689 .target_residency = 100,
690 .enter = &intel_idle,
691 .enter_s2idle = intel_idle_s2idle, },
694 .desc = "MWAIT 0x20",
695 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
697 .target_residency = 400,
698 .enter = &intel_idle,
699 .enter_s2idle = intel_idle_s2idle, },
702 .desc = "MWAIT 0x32",
703 .flags = MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED,
705 .target_residency = 500,
706 .enter = &intel_idle,
707 .enter_s2idle = intel_idle_s2idle, },
710 .desc = "MWAIT 0x40",
711 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
713 .target_residency = 900,
714 .enter = &intel_idle,
715 .enter_s2idle = intel_idle_s2idle, },
718 .desc = "MWAIT 0x50",
719 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
721 .target_residency = 1800,
722 .enter = &intel_idle,
723 .enter_s2idle = intel_idle_s2idle, },
726 .desc = "MWAIT 0x60",
727 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
728 .exit_latency = 2600,
729 .target_residency = 7700,
730 .enter = &intel_idle,
731 .enter_s2idle = intel_idle_s2idle, },
736 static struct cpuidle_state skl_cstates[] __initdata = {
739 .desc = "MWAIT 0x00",
740 .flags = MWAIT2flg(0x00),
742 .target_residency = 2,
743 .enter = &intel_idle,
744 .enter_s2idle = intel_idle_s2idle, },
747 .desc = "MWAIT 0x01",
748 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
750 .target_residency = 20,
751 .enter = &intel_idle,
752 .enter_s2idle = intel_idle_s2idle, },
755 .desc = "MWAIT 0x10",
756 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
758 .target_residency = 100,
759 .enter = &intel_idle,
760 .enter_s2idle = intel_idle_s2idle, },
763 .desc = "MWAIT 0x20",
764 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
766 .target_residency = 200,
767 .enter = &intel_idle,
768 .enter_s2idle = intel_idle_s2idle, },
771 .desc = "MWAIT 0x33",
772 .flags = MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
774 .target_residency = 800,
775 .enter = &intel_idle,
776 .enter_s2idle = intel_idle_s2idle, },
779 .desc = "MWAIT 0x40",
780 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
782 .target_residency = 800,
783 .enter = &intel_idle,
784 .enter_s2idle = intel_idle_s2idle, },
787 .desc = "MWAIT 0x50",
788 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
790 .target_residency = 5000,
791 .enter = &intel_idle,
792 .enter_s2idle = intel_idle_s2idle, },
795 .desc = "MWAIT 0x60",
796 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
798 .target_residency = 5000,
799 .enter = &intel_idle,
800 .enter_s2idle = intel_idle_s2idle, },
805 static struct cpuidle_state skx_cstates[] __initdata = {
808 .desc = "MWAIT 0x00",
809 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_IRQ_ENABLE,
811 .target_residency = 2,
812 .enter = &intel_idle,
813 .enter_s2idle = intel_idle_s2idle, },
816 .desc = "MWAIT 0x01",
817 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
819 .target_residency = 20,
820 .enter = &intel_idle,
821 .enter_s2idle = intel_idle_s2idle, },
824 .desc = "MWAIT 0x20",
825 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED | CPUIDLE_FLAG_IBRS,
827 .target_residency = 600,
828 .enter = &intel_idle,
829 .enter_s2idle = intel_idle_s2idle, },
834 static struct cpuidle_state icx_cstates[] __initdata = {
837 .desc = "MWAIT 0x00",
838 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_IRQ_ENABLE,
840 .target_residency = 1,
841 .enter = &intel_idle,
842 .enter_s2idle = intel_idle_s2idle, },
845 .desc = "MWAIT 0x01",
846 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
848 .target_residency = 4,
849 .enter = &intel_idle,
850 .enter_s2idle = intel_idle_s2idle, },
853 .desc = "MWAIT 0x20",
854 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
856 .target_residency = 600,
857 .enter = &intel_idle,
858 .enter_s2idle = intel_idle_s2idle, },
864 * On AlderLake C1 has to be disabled if C1E is enabled, and vice versa.
865 * C1E is enabled only if "C1E promotion" bit is set in MSR_IA32_POWER_CTL.
866 * But in this case there is effectively no C1, because C1 requests are
867 * promoted to C1E. If the "C1E promotion" bit is cleared, then both C1
868 * and C1E requests end up with C1, so there is effectively no C1E.
870 * By default we enable C1E and disable C1 by marking it with
871 * 'CPUIDLE_FLAG_UNUSABLE'.
873 static struct cpuidle_state adl_cstates[] __initdata = {
876 .desc = "MWAIT 0x00",
877 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE,
879 .target_residency = 1,
880 .enter = &intel_idle,
881 .enter_s2idle = intel_idle_s2idle, },
884 .desc = "MWAIT 0x01",
885 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
887 .target_residency = 4,
888 .enter = &intel_idle,
889 .enter_s2idle = intel_idle_s2idle, },
892 .desc = "MWAIT 0x20",
893 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
895 .target_residency = 600,
896 .enter = &intel_idle,
897 .enter_s2idle = intel_idle_s2idle, },
900 .desc = "MWAIT 0x40",
901 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
903 .target_residency = 800,
904 .enter = &intel_idle,
905 .enter_s2idle = intel_idle_s2idle, },
908 .desc = "MWAIT 0x60",
909 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
911 .target_residency = 2000,
912 .enter = &intel_idle,
913 .enter_s2idle = intel_idle_s2idle, },
918 static struct cpuidle_state adl_l_cstates[] __initdata = {
921 .desc = "MWAIT 0x00",
922 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE,
924 .target_residency = 1,
925 .enter = &intel_idle,
926 .enter_s2idle = intel_idle_s2idle, },
929 .desc = "MWAIT 0x01",
930 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
932 .target_residency = 4,
933 .enter = &intel_idle,
934 .enter_s2idle = intel_idle_s2idle, },
937 .desc = "MWAIT 0x20",
938 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
940 .target_residency = 500,
941 .enter = &intel_idle,
942 .enter_s2idle = intel_idle_s2idle, },
945 .desc = "MWAIT 0x40",
946 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
948 .target_residency = 600,
949 .enter = &intel_idle,
950 .enter_s2idle = intel_idle_s2idle, },
953 .desc = "MWAIT 0x60",
954 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
956 .target_residency = 700,
957 .enter = &intel_idle,
958 .enter_s2idle = intel_idle_s2idle, },
963 static struct cpuidle_state adl_n_cstates[] __initdata = {
966 .desc = "MWAIT 0x00",
967 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE,
969 .target_residency = 1,
970 .enter = &intel_idle,
971 .enter_s2idle = intel_idle_s2idle, },
974 .desc = "MWAIT 0x01",
975 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
977 .target_residency = 4,
978 .enter = &intel_idle,
979 .enter_s2idle = intel_idle_s2idle, },
982 .desc = "MWAIT 0x20",
983 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
985 .target_residency = 585,
986 .enter = &intel_idle,
987 .enter_s2idle = intel_idle_s2idle, },
990 .desc = "MWAIT 0x40",
991 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
993 .target_residency = 1040,
994 .enter = &intel_idle,
995 .enter_s2idle = intel_idle_s2idle, },
998 .desc = "MWAIT 0x60",
999 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
1000 .exit_latency = 660,
1001 .target_residency = 1980,
1002 .enter = &intel_idle,
1003 .enter_s2idle = intel_idle_s2idle, },
1008 static struct cpuidle_state spr_cstates[] __initdata = {
1011 .desc = "MWAIT 0x00",
1012 .flags = MWAIT2flg(0x00),
1014 .target_residency = 1,
1015 .enter = &intel_idle,
1016 .enter_s2idle = intel_idle_s2idle, },
1019 .desc = "MWAIT 0x01",
1020 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1022 .target_residency = 4,
1023 .enter = &intel_idle,
1024 .enter_s2idle = intel_idle_s2idle, },
1027 .desc = "MWAIT 0x20",
1028 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED |
1029 CPUIDLE_FLAG_INIT_XSTATE,
1030 .exit_latency = 290,
1031 .target_residency = 800,
1032 .enter = &intel_idle,
1033 .enter_s2idle = intel_idle_s2idle, },
1038 static struct cpuidle_state atom_cstates[] __initdata = {
1041 .desc = "MWAIT 0x00",
1042 .flags = MWAIT2flg(0x00),
1044 .target_residency = 20,
1045 .enter = &intel_idle,
1046 .enter_s2idle = intel_idle_s2idle, },
1049 .desc = "MWAIT 0x10",
1050 .flags = MWAIT2flg(0x10),
1052 .target_residency = 80,
1053 .enter = &intel_idle,
1054 .enter_s2idle = intel_idle_s2idle, },
1057 .desc = "MWAIT 0x30",
1058 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
1059 .exit_latency = 100,
1060 .target_residency = 400,
1061 .enter = &intel_idle,
1062 .enter_s2idle = intel_idle_s2idle, },
1065 .desc = "MWAIT 0x52",
1066 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
1067 .exit_latency = 140,
1068 .target_residency = 560,
1069 .enter = &intel_idle,
1070 .enter_s2idle = intel_idle_s2idle, },
1074 static struct cpuidle_state tangier_cstates[] __initdata = {
1077 .desc = "MWAIT 0x00",
1078 .flags = MWAIT2flg(0x00),
1080 .target_residency = 4,
1081 .enter = &intel_idle,
1082 .enter_s2idle = intel_idle_s2idle, },
1085 .desc = "MWAIT 0x30",
1086 .flags = MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED,
1087 .exit_latency = 100,
1088 .target_residency = 400,
1089 .enter = &intel_idle,
1090 .enter_s2idle = intel_idle_s2idle, },
1093 .desc = "MWAIT 0x52",
1094 .flags = MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED,
1095 .exit_latency = 140,
1096 .target_residency = 560,
1097 .enter = &intel_idle,
1098 .enter_s2idle = intel_idle_s2idle, },
1101 .desc = "MWAIT 0x60",
1102 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
1103 .exit_latency = 1200,
1104 .target_residency = 4000,
1105 .enter = &intel_idle,
1106 .enter_s2idle = intel_idle_s2idle, },
1109 .desc = "MWAIT 0x64",
1110 .flags = MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED,
1111 .exit_latency = 10000,
1112 .target_residency = 20000,
1113 .enter = &intel_idle,
1114 .enter_s2idle = intel_idle_s2idle, },
1118 static struct cpuidle_state avn_cstates[] __initdata = {
1121 .desc = "MWAIT 0x00",
1122 .flags = MWAIT2flg(0x00),
1124 .target_residency = 2,
1125 .enter = &intel_idle,
1126 .enter_s2idle = intel_idle_s2idle, },
1129 .desc = "MWAIT 0x51",
1130 .flags = MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED,
1132 .target_residency = 45,
1133 .enter = &intel_idle,
1134 .enter_s2idle = intel_idle_s2idle, },
1138 static struct cpuidle_state knl_cstates[] __initdata = {
1141 .desc = "MWAIT 0x00",
1142 .flags = MWAIT2flg(0x00),
1144 .target_residency = 2,
1145 .enter = &intel_idle,
1146 .enter_s2idle = intel_idle_s2idle },
1149 .desc = "MWAIT 0x10",
1150 .flags = MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED,
1151 .exit_latency = 120,
1152 .target_residency = 500,
1153 .enter = &intel_idle,
1154 .enter_s2idle = intel_idle_s2idle },
1159 static struct cpuidle_state bxt_cstates[] __initdata = {
1162 .desc = "MWAIT 0x00",
1163 .flags = MWAIT2flg(0x00),
1165 .target_residency = 2,
1166 .enter = &intel_idle,
1167 .enter_s2idle = intel_idle_s2idle, },
1170 .desc = "MWAIT 0x01",
1171 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1173 .target_residency = 20,
1174 .enter = &intel_idle,
1175 .enter_s2idle = intel_idle_s2idle, },
1178 .desc = "MWAIT 0x20",
1179 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
1180 .exit_latency = 133,
1181 .target_residency = 133,
1182 .enter = &intel_idle,
1183 .enter_s2idle = intel_idle_s2idle, },
1186 .desc = "MWAIT 0x31",
1187 .flags = MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED,
1188 .exit_latency = 155,
1189 .target_residency = 155,
1190 .enter = &intel_idle,
1191 .enter_s2idle = intel_idle_s2idle, },
1194 .desc = "MWAIT 0x40",
1195 .flags = MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED,
1196 .exit_latency = 1000,
1197 .target_residency = 1000,
1198 .enter = &intel_idle,
1199 .enter_s2idle = intel_idle_s2idle, },
1202 .desc = "MWAIT 0x50",
1203 .flags = MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED,
1204 .exit_latency = 2000,
1205 .target_residency = 2000,
1206 .enter = &intel_idle,
1207 .enter_s2idle = intel_idle_s2idle, },
1210 .desc = "MWAIT 0x60",
1211 .flags = MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED,
1212 .exit_latency = 10000,
1213 .target_residency = 10000,
1214 .enter = &intel_idle,
1215 .enter_s2idle = intel_idle_s2idle, },
1220 static struct cpuidle_state dnv_cstates[] __initdata = {
1223 .desc = "MWAIT 0x00",
1224 .flags = MWAIT2flg(0x00),
1226 .target_residency = 2,
1227 .enter = &intel_idle,
1228 .enter_s2idle = intel_idle_s2idle, },
1231 .desc = "MWAIT 0x01",
1232 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1234 .target_residency = 20,
1235 .enter = &intel_idle,
1236 .enter_s2idle = intel_idle_s2idle, },
1239 .desc = "MWAIT 0x20",
1240 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
1242 .target_residency = 500,
1243 .enter = &intel_idle,
1244 .enter_s2idle = intel_idle_s2idle, },
1250 * Note, depending on HW and FW revision, SnowRidge SoC may or may not support
1251 * C6, and this is indicated in the CPUID mwait leaf.
1253 static struct cpuidle_state snr_cstates[] __initdata = {
1256 .desc = "MWAIT 0x00",
1257 .flags = MWAIT2flg(0x00),
1259 .target_residency = 2,
1260 .enter = &intel_idle,
1261 .enter_s2idle = intel_idle_s2idle, },
1264 .desc = "MWAIT 0x01",
1265 .flags = MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE,
1267 .target_residency = 25,
1268 .enter = &intel_idle,
1269 .enter_s2idle = intel_idle_s2idle, },
1272 .desc = "MWAIT 0x20",
1273 .flags = MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED,
1274 .exit_latency = 130,
1275 .target_residency = 500,
1276 .enter = &intel_idle,
1277 .enter_s2idle = intel_idle_s2idle, },
1282 static struct cpuidle_state vmguest_cstates[] __initdata = {
1286 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_IRQ_ENABLE,
1288 .target_residency = 10,
1289 .enter = &intel_idle_hlt, },
1293 .flags = MWAIT2flg(0x00) | CPUIDLE_FLAG_TLB_FLUSHED,
1295 .target_residency = 200,
1296 .enter = &intel_idle_hlt, },
1301 static const struct idle_cpu idle_cpu_nehalem __initconst = {
1302 .state_table = nehalem_cstates,
1303 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
1304 .disable_promotion_to_c1e = true,
1307 static const struct idle_cpu idle_cpu_nhx __initconst = {
1308 .state_table = nehalem_cstates,
1309 .auto_demotion_disable_flags = NHM_C1_AUTO_DEMOTE | NHM_C3_AUTO_DEMOTE,
1310 .disable_promotion_to_c1e = true,
1314 static const struct idle_cpu idle_cpu_atom __initconst = {
1315 .state_table = atom_cstates,
1318 static const struct idle_cpu idle_cpu_tangier __initconst = {
1319 .state_table = tangier_cstates,
1322 static const struct idle_cpu idle_cpu_lincroft __initconst = {
1323 .state_table = atom_cstates,
1324 .auto_demotion_disable_flags = ATM_LNC_C6_AUTO_DEMOTE,
1327 static const struct idle_cpu idle_cpu_snb __initconst = {
1328 .state_table = snb_cstates,
1329 .disable_promotion_to_c1e = true,
1332 static const struct idle_cpu idle_cpu_snx __initconst = {
1333 .state_table = snb_cstates,
1334 .disable_promotion_to_c1e = true,
1338 static const struct idle_cpu idle_cpu_byt __initconst = {
1339 .state_table = byt_cstates,
1340 .disable_promotion_to_c1e = true,
1341 .byt_auto_demotion_disable_flag = true,
1344 static const struct idle_cpu idle_cpu_cht __initconst = {
1345 .state_table = cht_cstates,
1346 .disable_promotion_to_c1e = true,
1347 .byt_auto_demotion_disable_flag = true,
1350 static const struct idle_cpu idle_cpu_ivb __initconst = {
1351 .state_table = ivb_cstates,
1352 .disable_promotion_to_c1e = true,
1355 static const struct idle_cpu idle_cpu_ivt __initconst = {
1356 .state_table = ivt_cstates,
1357 .disable_promotion_to_c1e = true,
1361 static const struct idle_cpu idle_cpu_hsw __initconst = {
1362 .state_table = hsw_cstates,
1363 .disable_promotion_to_c1e = true,
1366 static const struct idle_cpu idle_cpu_hsx __initconst = {
1367 .state_table = hsw_cstates,
1368 .disable_promotion_to_c1e = true,
1372 static const struct idle_cpu idle_cpu_bdw __initconst = {
1373 .state_table = bdw_cstates,
1374 .disable_promotion_to_c1e = true,
1377 static const struct idle_cpu idle_cpu_bdx __initconst = {
1378 .state_table = bdw_cstates,
1379 .disable_promotion_to_c1e = true,
1383 static const struct idle_cpu idle_cpu_skl __initconst = {
1384 .state_table = skl_cstates,
1385 .disable_promotion_to_c1e = true,
1388 static const struct idle_cpu idle_cpu_skx __initconst = {
1389 .state_table = skx_cstates,
1390 .disable_promotion_to_c1e = true,
1394 static const struct idle_cpu idle_cpu_icx __initconst = {
1395 .state_table = icx_cstates,
1396 .disable_promotion_to_c1e = true,
1400 static const struct idle_cpu idle_cpu_adl __initconst = {
1401 .state_table = adl_cstates,
1404 static const struct idle_cpu idle_cpu_adl_l __initconst = {
1405 .state_table = adl_l_cstates,
1408 static const struct idle_cpu idle_cpu_adl_n __initconst = {
1409 .state_table = adl_n_cstates,
1412 static const struct idle_cpu idle_cpu_spr __initconst = {
1413 .state_table = spr_cstates,
1414 .disable_promotion_to_c1e = true,
1418 static const struct idle_cpu idle_cpu_avn __initconst = {
1419 .state_table = avn_cstates,
1420 .disable_promotion_to_c1e = true,
1424 static const struct idle_cpu idle_cpu_knl __initconst = {
1425 .state_table = knl_cstates,
1429 static const struct idle_cpu idle_cpu_bxt __initconst = {
1430 .state_table = bxt_cstates,
1431 .disable_promotion_to_c1e = true,
1434 static const struct idle_cpu idle_cpu_dnv __initconst = {
1435 .state_table = dnv_cstates,
1436 .disable_promotion_to_c1e = true,
1440 static const struct idle_cpu idle_cpu_snr __initconst = {
1441 .state_table = snr_cstates,
1442 .disable_promotion_to_c1e = true,
1446 static const struct x86_cpu_id intel_idle_ids[] __initconst = {
1447 X86_MATCH_INTEL_FAM6_MODEL(NEHALEM_EP, &idle_cpu_nhx),
1448 X86_MATCH_INTEL_FAM6_MODEL(NEHALEM, &idle_cpu_nehalem),
1449 X86_MATCH_INTEL_FAM6_MODEL(NEHALEM_G, &idle_cpu_nehalem),
1450 X86_MATCH_INTEL_FAM6_MODEL(WESTMERE, &idle_cpu_nehalem),
1451 X86_MATCH_INTEL_FAM6_MODEL(WESTMERE_EP, &idle_cpu_nhx),
1452 X86_MATCH_INTEL_FAM6_MODEL(NEHALEM_EX, &idle_cpu_nhx),
1453 X86_MATCH_INTEL_FAM6_MODEL(ATOM_BONNELL, &idle_cpu_atom),
1454 X86_MATCH_INTEL_FAM6_MODEL(ATOM_BONNELL_MID, &idle_cpu_lincroft),
1455 X86_MATCH_INTEL_FAM6_MODEL(WESTMERE_EX, &idle_cpu_nhx),
1456 X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE, &idle_cpu_snb),
1457 X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE_X, &idle_cpu_snx),
1458 X86_MATCH_INTEL_FAM6_MODEL(ATOM_SALTWELL, &idle_cpu_atom),
1459 X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT, &idle_cpu_byt),
1460 X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT_MID, &idle_cpu_tangier),
1461 X86_MATCH_INTEL_FAM6_MODEL(ATOM_AIRMONT, &idle_cpu_cht),
1462 X86_MATCH_INTEL_FAM6_MODEL(IVYBRIDGE, &idle_cpu_ivb),
1463 X86_MATCH_INTEL_FAM6_MODEL(IVYBRIDGE_X, &idle_cpu_ivt),
1464 X86_MATCH_INTEL_FAM6_MODEL(HASWELL, &idle_cpu_hsw),
1465 X86_MATCH_INTEL_FAM6_MODEL(HASWELL_X, &idle_cpu_hsx),
1466 X86_MATCH_INTEL_FAM6_MODEL(HASWELL_L, &idle_cpu_hsw),
1467 X86_MATCH_INTEL_FAM6_MODEL(HASWELL_G, &idle_cpu_hsw),
1468 X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT_D, &idle_cpu_avn),
1469 X86_MATCH_INTEL_FAM6_MODEL(BROADWELL, &idle_cpu_bdw),
1470 X86_MATCH_INTEL_FAM6_MODEL(BROADWELL_G, &idle_cpu_bdw),
1471 X86_MATCH_INTEL_FAM6_MODEL(BROADWELL_X, &idle_cpu_bdx),
1472 X86_MATCH_INTEL_FAM6_MODEL(BROADWELL_D, &idle_cpu_bdx),
1473 X86_MATCH_INTEL_FAM6_MODEL(SKYLAKE_L, &idle_cpu_skl),
1474 X86_MATCH_INTEL_FAM6_MODEL(SKYLAKE, &idle_cpu_skl),
1475 X86_MATCH_INTEL_FAM6_MODEL(KABYLAKE_L, &idle_cpu_skl),
1476 X86_MATCH_INTEL_FAM6_MODEL(KABYLAKE, &idle_cpu_skl),
1477 X86_MATCH_INTEL_FAM6_MODEL(SKYLAKE_X, &idle_cpu_skx),
1478 X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, &idle_cpu_icx),
1479 X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, &idle_cpu_icx),
1480 X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE, &idle_cpu_adl),
1481 X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE_L, &idle_cpu_adl_l),
1482 X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE_N, &idle_cpu_adl_n),
1483 X86_MATCH_INTEL_FAM6_MODEL(SAPPHIRERAPIDS_X, &idle_cpu_spr),
1484 X86_MATCH_INTEL_FAM6_MODEL(EMERALDRAPIDS_X, &idle_cpu_spr),
1485 X86_MATCH_INTEL_FAM6_MODEL(XEON_PHI_KNL, &idle_cpu_knl),
1486 X86_MATCH_INTEL_FAM6_MODEL(XEON_PHI_KNM, &idle_cpu_knl),
1487 X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT, &idle_cpu_bxt),
1488 X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT_PLUS, &idle_cpu_bxt),
1489 X86_MATCH_INTEL_FAM6_MODEL(ATOM_GOLDMONT_D, &idle_cpu_dnv),
1490 X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_D, &idle_cpu_snr),
1494 static const struct x86_cpu_id intel_mwait_ids[] __initconst = {
1495 X86_MATCH_VENDOR_FAM_FEATURE(INTEL, 6, X86_FEATURE_MWAIT, NULL),
1499 static bool __init intel_idle_max_cstate_reached(int cstate)
1501 if (cstate + 1 > max_cstate) {
1502 pr_info("max_cstate %d reached\n", max_cstate);
1508 static bool __init intel_idle_state_needs_timer_stop(struct cpuidle_state *state)
1510 unsigned long eax = flg2MWAIT(state->flags);
1512 if (boot_cpu_has(X86_FEATURE_ARAT))
1516 * Switch over to one-shot tick broadcast if the target C-state
1517 * is deeper than C1.
1519 return !!((eax >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK);
1522 #ifdef CONFIG_ACPI_PROCESSOR_CSTATE
1523 #include <acpi/processor.h>
1525 static bool no_acpi __read_mostly;
1526 module_param(no_acpi, bool, 0444);
1527 MODULE_PARM_DESC(no_acpi, "Do not use ACPI _CST for building the idle states list");
1529 static bool force_use_acpi __read_mostly; /* No effect if no_acpi is set. */
1530 module_param_named(use_acpi, force_use_acpi, bool, 0444);
1531 MODULE_PARM_DESC(use_acpi, "Use ACPI _CST for building the idle states list");
1533 static struct acpi_processor_power acpi_state_table __initdata;
1536 * intel_idle_cst_usable - Check if the _CST information can be used.
1538 * Check if all of the C-states listed by _CST in the max_cstate range are
1539 * ACPI_CSTATE_FFH, which means that they should be entered via MWAIT.
1541 static bool __init intel_idle_cst_usable(void)
1545 limit = min_t(int, min_t(int, CPUIDLE_STATE_MAX, max_cstate + 1),
1546 acpi_state_table.count);
1548 for (cstate = 1; cstate < limit; cstate++) {
1549 struct acpi_processor_cx *cx = &acpi_state_table.states[cstate];
1551 if (cx->entry_method != ACPI_CSTATE_FFH)
1558 static bool __init intel_idle_acpi_cst_extract(void)
1563 pr_debug("Not allowed to use ACPI _CST\n");
1567 for_each_possible_cpu(cpu) {
1568 struct acpi_processor *pr = per_cpu(processors, cpu);
1573 if (acpi_processor_evaluate_cst(pr->handle, cpu, &acpi_state_table))
1576 acpi_state_table.count++;
1578 if (!intel_idle_cst_usable())
1581 if (!acpi_processor_claim_cst_control())
1587 acpi_state_table.count = 0;
1588 pr_debug("ACPI _CST not found or not usable\n");
1592 static void __init intel_idle_init_cstates_acpi(struct cpuidle_driver *drv)
1594 int cstate, limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
1597 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1598 * the interesting states are ACPI_CSTATE_FFH.
1600 for (cstate = 1; cstate < limit; cstate++) {
1601 struct acpi_processor_cx *cx;
1602 struct cpuidle_state *state;
1604 if (intel_idle_max_cstate_reached(cstate - 1))
1607 cx = &acpi_state_table.states[cstate];
1609 state = &drv->states[drv->state_count++];
1611 snprintf(state->name, CPUIDLE_NAME_LEN, "C%d_ACPI", cstate);
1612 strscpy(state->desc, cx->desc, CPUIDLE_DESC_LEN);
1613 state->exit_latency = cx->latency;
1615 * For C1-type C-states use the same number for both the exit
1616 * latency and target residency, because that is the case for
1617 * C1 in the majority of the static C-states tables above.
1618 * For the other types of C-states, however, set the target
1619 * residency to 3 times the exit latency which should lead to
1620 * a reasonable balance between energy-efficiency and
1621 * performance in the majority of interesting cases.
1623 state->target_residency = cx->latency;
1624 if (cx->type > ACPI_STATE_C1)
1625 state->target_residency *= 3;
1627 state->flags = MWAIT2flg(cx->address);
1628 if (cx->type > ACPI_STATE_C2)
1629 state->flags |= CPUIDLE_FLAG_TLB_FLUSHED;
1631 if (disabled_states_mask & BIT(cstate))
1632 state->flags |= CPUIDLE_FLAG_OFF;
1634 if (intel_idle_state_needs_timer_stop(state))
1635 state->flags |= CPUIDLE_FLAG_TIMER_STOP;
1637 state->enter = intel_idle;
1638 state->enter_s2idle = intel_idle_s2idle;
1642 static bool __init intel_idle_off_by_default(u32 mwait_hint)
1647 * If there are no _CST C-states, do not disable any C-states by
1650 if (!acpi_state_table.count)
1653 limit = min_t(int, CPUIDLE_STATE_MAX, acpi_state_table.count);
1655 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1656 * the interesting states are ACPI_CSTATE_FFH.
1658 for (cstate = 1; cstate < limit; cstate++) {
1659 if (acpi_state_table.states[cstate].address == mwait_hint)
1664 #else /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1665 #define force_use_acpi (false)
1667 static inline bool intel_idle_acpi_cst_extract(void) { return false; }
1668 static inline void intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) { }
1669 static inline bool intel_idle_off_by_default(u32 mwait_hint) { return false; }
1670 #endif /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1673 * ivt_idle_state_table_update - Tune the idle states table for Ivy Town.
1675 * Tune IVT multi-socket targets.
1676 * Assumption: num_sockets == (max_package_num + 1).
1678 static void __init ivt_idle_state_table_update(void)
1680 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1681 int cpu, package_num, num_sockets = 1;
1683 for_each_online_cpu(cpu) {
1684 package_num = topology_physical_package_id(cpu);
1685 if (package_num + 1 > num_sockets) {
1686 num_sockets = package_num + 1;
1688 if (num_sockets > 4) {
1689 cpuidle_state_table = ivt_cstates_8s;
1695 if (num_sockets > 2)
1696 cpuidle_state_table = ivt_cstates_4s;
1698 /* else, 1 and 2 socket systems use default ivt_cstates */
1702 * irtl_2_usec - IRTL to microseconds conversion.
1703 * @irtl: IRTL MSR value.
1705 * Translate the IRTL (Interrupt Response Time Limit) MSR value to microseconds.
1707 static unsigned long long __init irtl_2_usec(unsigned long long irtl)
1709 static const unsigned int irtl_ns_units[] __initconst = {
1710 1, 32, 1024, 32768, 1048576, 33554432, 0, 0
1712 unsigned long long ns;
1717 ns = irtl_ns_units[(irtl >> 10) & 0x7];
1719 return div_u64((irtl & 0x3FF) * ns, NSEC_PER_USEC);
1723 * bxt_idle_state_table_update - Fix up the Broxton idle states table.
1725 * On BXT, trust the IRTL (Interrupt Response Time Limit) MSR to show the
1726 * definitive maximum latency and use the same value for target_residency.
1728 static void __init bxt_idle_state_table_update(void)
1730 unsigned long long msr;
1733 rdmsrl(MSR_PKGC6_IRTL, msr);
1734 usec = irtl_2_usec(msr);
1736 bxt_cstates[2].exit_latency = usec;
1737 bxt_cstates[2].target_residency = usec;
1740 rdmsrl(MSR_PKGC7_IRTL, msr);
1741 usec = irtl_2_usec(msr);
1743 bxt_cstates[3].exit_latency = usec;
1744 bxt_cstates[3].target_residency = usec;
1747 rdmsrl(MSR_PKGC8_IRTL, msr);
1748 usec = irtl_2_usec(msr);
1750 bxt_cstates[4].exit_latency = usec;
1751 bxt_cstates[4].target_residency = usec;
1754 rdmsrl(MSR_PKGC9_IRTL, msr);
1755 usec = irtl_2_usec(msr);
1757 bxt_cstates[5].exit_latency = usec;
1758 bxt_cstates[5].target_residency = usec;
1761 rdmsrl(MSR_PKGC10_IRTL, msr);
1762 usec = irtl_2_usec(msr);
1764 bxt_cstates[6].exit_latency = usec;
1765 bxt_cstates[6].target_residency = usec;
1771 * sklh_idle_state_table_update - Fix up the Sky Lake idle states table.
1773 * On SKL-H (model 0x5e) skip C8 and C9 if C10 is enabled and SGX disabled.
1775 static void __init sklh_idle_state_table_update(void)
1777 unsigned long long msr;
1778 unsigned int eax, ebx, ecx, edx;
1781 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1782 if (max_cstate <= 7)
1785 /* if PC10 not present in CPUID.MWAIT.EDX */
1786 if ((mwait_substates & (0xF << 28)) == 0)
1789 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr);
1791 /* PC10 is not enabled in PKG C-state limit */
1792 if ((msr & 0xF) != 8)
1796 cpuid(7, &eax, &ebx, &ecx, &edx);
1798 /* if SGX is present */
1799 if (ebx & (1 << 2)) {
1801 rdmsrl(MSR_IA32_FEAT_CTL, msr);
1803 /* if SGX is enabled */
1804 if (msr & (1 << 18))
1808 skl_cstates[5].flags |= CPUIDLE_FLAG_UNUSABLE; /* C8-SKL */
1809 skl_cstates[6].flags |= CPUIDLE_FLAG_UNUSABLE; /* C9-SKL */
1813 * skx_idle_state_table_update - Adjust the Sky Lake/Cascade Lake
1814 * idle states table.
1816 static void __init skx_idle_state_table_update(void)
1818 unsigned long long msr;
1820 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr);
1823 * 000b: C0/C1 (no package C-state support)
1825 * 010b: C6 (non-retention)
1826 * 011b: C6 (retention)
1827 * 111b: No Package C state limits.
1829 if ((msr & 0x7) < 2) {
1831 * Uses the CC6 + PC0 latency and 3 times of
1832 * latency for target_residency if the PC6
1833 * is disabled in BIOS. This is consistent
1834 * with how intel_idle driver uses _CST
1835 * to set the target_residency.
1837 skx_cstates[2].exit_latency = 92;
1838 skx_cstates[2].target_residency = 276;
1843 * adl_idle_state_table_update - Adjust AlderLake idle states table.
1845 static void __init adl_idle_state_table_update(void)
1847 /* Check if user prefers C1 over C1E. */
1848 if (preferred_states_mask & BIT(1) && !(preferred_states_mask & BIT(2))) {
1849 cpuidle_state_table[0].flags &= ~CPUIDLE_FLAG_UNUSABLE;
1850 cpuidle_state_table[1].flags |= CPUIDLE_FLAG_UNUSABLE;
1852 /* Disable C1E by clearing the "C1E promotion" bit. */
1853 c1e_promotion = C1E_PROMOTION_DISABLE;
1857 /* Make sure C1E is enabled by default */
1858 c1e_promotion = C1E_PROMOTION_ENABLE;
1862 * spr_idle_state_table_update - Adjust Sapphire Rapids idle states table.
1864 static void __init spr_idle_state_table_update(void)
1866 unsigned long long msr;
1869 * By default, the C6 state assumes the worst-case scenario of package
1870 * C6. However, if PC6 is disabled, we update the numbers to match
1873 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr);
1875 /* Limit value 2 and above allow for PC6. */
1876 if ((msr & 0x7) < 2) {
1877 spr_cstates[2].exit_latency = 190;
1878 spr_cstates[2].target_residency = 600;
1882 static bool __init intel_idle_verify_cstate(unsigned int mwait_hint)
1884 unsigned int mwait_cstate = MWAIT_HINT2CSTATE(mwait_hint) + 1;
1885 unsigned int num_substates = (mwait_substates >> mwait_cstate * 4) &
1886 MWAIT_SUBSTATE_MASK;
1888 /* Ignore the C-state if there are NO sub-states in CPUID for it. */
1889 if (num_substates == 0)
1892 if (mwait_cstate > 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
1893 mark_tsc_unstable("TSC halts in idle states deeper than C2");
1898 static void state_update_enter_method(struct cpuidle_state *state, int cstate)
1900 if (state->enter == intel_idle_hlt) {
1902 pr_info("forced intel_idle_irq for state %d\n", cstate);
1903 state->enter = intel_idle_hlt_irq_on;
1907 if (state->enter == intel_idle_hlt_irq_on)
1908 return; /* no update scenarios */
1910 if (state->flags & CPUIDLE_FLAG_INIT_XSTATE) {
1912 * Combining with XSTATE with IBRS or IRQ_ENABLE flags
1913 * is not currently supported but this driver.
1915 WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IBRS);
1916 WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
1917 state->enter = intel_idle_xstate;
1921 if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
1922 state->flags & CPUIDLE_FLAG_IBRS) {
1924 * IBRS mitigation requires that C-states are entered
1925 * with interrupts disabled.
1927 WARN_ON_ONCE(state->flags & CPUIDLE_FLAG_IRQ_ENABLE);
1928 state->enter = intel_idle_ibrs;
1932 if (state->flags & CPUIDLE_FLAG_IRQ_ENABLE) {
1933 state->enter = intel_idle_irq;
1938 pr_info("forced intel_idle_irq for state %d\n", cstate);
1939 state->enter = intel_idle_irq;
1944 * For mwait based states, we want to verify the cpuid data to see if the state
1945 * is actually supported by this specific CPU.
1946 * For non-mwait based states, this check should be skipped.
1948 static bool should_verify_mwait(struct cpuidle_state *state)
1950 if (state->enter == intel_idle_hlt)
1952 if (state->enter == intel_idle_hlt_irq_on)
1958 static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)
1962 switch (boot_cpu_data.x86_model) {
1963 case INTEL_FAM6_IVYBRIDGE_X:
1964 ivt_idle_state_table_update();
1966 case INTEL_FAM6_ATOM_GOLDMONT:
1967 case INTEL_FAM6_ATOM_GOLDMONT_PLUS:
1968 bxt_idle_state_table_update();
1970 case INTEL_FAM6_SKYLAKE:
1971 sklh_idle_state_table_update();
1973 case INTEL_FAM6_SKYLAKE_X:
1974 skx_idle_state_table_update();
1976 case INTEL_FAM6_SAPPHIRERAPIDS_X:
1977 case INTEL_FAM6_EMERALDRAPIDS_X:
1978 spr_idle_state_table_update();
1980 case INTEL_FAM6_ALDERLAKE:
1981 case INTEL_FAM6_ALDERLAKE_L:
1982 case INTEL_FAM6_ALDERLAKE_N:
1983 adl_idle_state_table_update();
1987 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
1988 struct cpuidle_state *state;
1989 unsigned int mwait_hint;
1991 if (intel_idle_max_cstate_reached(cstate))
1994 if (!cpuidle_state_table[cstate].enter &&
1995 !cpuidle_state_table[cstate].enter_s2idle)
1998 /* If marked as unusable, skip this state. */
1999 if (cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_UNUSABLE) {
2000 pr_debug("state %s is disabled\n",
2001 cpuidle_state_table[cstate].name);
2005 mwait_hint = flg2MWAIT(cpuidle_state_table[cstate].flags);
2006 if (should_verify_mwait(&cpuidle_state_table[cstate]) && !intel_idle_verify_cstate(mwait_hint))
2009 /* Structure copy. */
2010 drv->states[drv->state_count] = cpuidle_state_table[cstate];
2011 state = &drv->states[drv->state_count];
2013 state_update_enter_method(state, cstate);
2016 if ((disabled_states_mask & BIT(drv->state_count)) ||
2017 ((icpu->use_acpi || force_use_acpi) &&
2018 intel_idle_off_by_default(mwait_hint) &&
2019 !(state->flags & CPUIDLE_FLAG_ALWAYS_ENABLE)))
2020 state->flags |= CPUIDLE_FLAG_OFF;
2022 if (intel_idle_state_needs_timer_stop(state))
2023 state->flags |= CPUIDLE_FLAG_TIMER_STOP;
2028 if (icpu->byt_auto_demotion_disable_flag) {
2029 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG, 0);
2030 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG, 0);
2035 * intel_idle_cpuidle_driver_init - Create the list of available idle states.
2036 * @drv: cpuidle driver structure to initialize.
2038 static void __init intel_idle_cpuidle_driver_init(struct cpuidle_driver *drv)
2040 cpuidle_poll_state_init(drv);
2042 if (disabled_states_mask & BIT(0))
2043 drv->states[0].flags |= CPUIDLE_FLAG_OFF;
2045 drv->state_count = 1;
2048 intel_idle_init_cstates_icpu(drv);
2050 intel_idle_init_cstates_acpi(drv);
2053 static void auto_demotion_disable(void)
2055 unsigned long long msr_bits;
2057 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
2058 msr_bits &= ~auto_demotion_disable_flags;
2059 wrmsrl(MSR_PKG_CST_CONFIG_CONTROL, msr_bits);
2062 static void c1e_promotion_enable(void)
2064 unsigned long long msr_bits;
2066 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
2068 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
2071 static void c1e_promotion_disable(void)
2073 unsigned long long msr_bits;
2075 rdmsrl(MSR_IA32_POWER_CTL, msr_bits);
2077 wrmsrl(MSR_IA32_POWER_CTL, msr_bits);
2081 * intel_idle_cpu_init - Register the target CPU with the cpuidle core.
2082 * @cpu: CPU to initialize.
2084 * Register a cpuidle device object for @cpu and update its MSRs in accordance
2085 * with the processor model flags.
2087 static int intel_idle_cpu_init(unsigned int cpu)
2089 struct cpuidle_device *dev;
2091 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
2094 if (cpuidle_register_device(dev)) {
2095 pr_debug("cpuidle_register_device %d failed!\n", cpu);
2099 if (auto_demotion_disable_flags)
2100 auto_demotion_disable();
2102 if (c1e_promotion == C1E_PROMOTION_ENABLE)
2103 c1e_promotion_enable();
2104 else if (c1e_promotion == C1E_PROMOTION_DISABLE)
2105 c1e_promotion_disable();
2110 static int intel_idle_cpu_online(unsigned int cpu)
2112 struct cpuidle_device *dev;
2114 if (!boot_cpu_has(X86_FEATURE_ARAT))
2115 tick_broadcast_enable();
2118 * Some systems can hotplug a cpu at runtime after
2119 * the kernel has booted, we have to initialize the
2120 * driver in this case
2122 dev = per_cpu_ptr(intel_idle_cpuidle_devices, cpu);
2123 if (!dev->registered)
2124 return intel_idle_cpu_init(cpu);
2130 * intel_idle_cpuidle_devices_uninit - Unregister all cpuidle devices.
2132 static void __init intel_idle_cpuidle_devices_uninit(void)
2136 for_each_online_cpu(i)
2137 cpuidle_unregister_device(per_cpu_ptr(intel_idle_cpuidle_devices, i));
2141 * Match up the latency and break even point of the bare metal (cpu based)
2142 * states with the deepest VM available state.
2144 * We only want to do this for the deepest state, the ones that has
2145 * the TLB_FLUSHED flag set on the .
2147 * All our short idle states are dominated by vmexit/vmenter latencies,
2148 * not the underlying hardware latencies so we keep our values for these.
2150 static void matchup_vm_state_with_baremetal(void)
2154 for (cstate = 0; cstate < CPUIDLE_STATE_MAX; ++cstate) {
2155 int matching_cstate;
2157 if (intel_idle_max_cstate_reached(cstate))
2160 if (!cpuidle_state_table[cstate].enter)
2163 if (!(cpuidle_state_table[cstate].flags & CPUIDLE_FLAG_TLB_FLUSHED))
2166 for (matching_cstate = 0; matching_cstate < CPUIDLE_STATE_MAX; ++matching_cstate) {
2167 if (!icpu->state_table[matching_cstate].enter)
2169 if (icpu->state_table[matching_cstate].exit_latency > cpuidle_state_table[cstate].exit_latency) {
2170 cpuidle_state_table[cstate].exit_latency = icpu->state_table[matching_cstate].exit_latency;
2171 cpuidle_state_table[cstate].target_residency = icpu->state_table[matching_cstate].target_residency;
2179 static int __init intel_idle_vminit(const struct x86_cpu_id *id)
2183 cpuidle_state_table = vmguest_cstates;
2185 icpu = (const struct idle_cpu *)id->driver_data;
2187 pr_debug("v" INTEL_IDLE_VERSION " model 0x%X\n",
2188 boot_cpu_data.x86_model);
2190 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
2191 if (!intel_idle_cpuidle_devices)
2195 * We don't know exactly what the host will do when we go idle, but as a worst estimate
2196 * we can assume that the exit latency of the deepest host state will be hit for our
2197 * deep (long duration) guest idle state.
2198 * The same logic applies to the break even point for the long duration guest idle state.
2199 * So lets copy these two properties from the table we found for the host CPU type.
2201 matchup_vm_state_with_baremetal();
2203 intel_idle_cpuidle_driver_init(&intel_idle_driver);
2205 retval = cpuidle_register_driver(&intel_idle_driver);
2207 struct cpuidle_driver *drv = cpuidle_get_driver();
2208 printk(KERN_DEBUG pr_fmt("intel_idle yielding to %s\n"),
2209 drv ? drv->name : "none");
2210 goto init_driver_fail;
2213 retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online",
2214 intel_idle_cpu_online, NULL);
2220 intel_idle_cpuidle_devices_uninit();
2221 cpuidle_unregister_driver(&intel_idle_driver);
2223 free_percpu(intel_idle_cpuidle_devices);
2227 static int __init intel_idle_init(void)
2229 const struct x86_cpu_id *id;
2230 unsigned int eax, ebx, ecx;
2233 /* Do not load intel_idle at all for now if idle= is passed */
2234 if (boot_option_idle_override != IDLE_NO_OVERRIDE)
2237 if (max_cstate == 0) {
2238 pr_debug("disabled\n");
2242 id = x86_match_cpu(intel_idle_ids);
2244 if (!boot_cpu_has(X86_FEATURE_MWAIT)) {
2245 if (boot_cpu_has(X86_FEATURE_HYPERVISOR))
2246 return intel_idle_vminit(id);
2247 pr_debug("Please enable MWAIT in BIOS SETUP\n");
2251 id = x86_match_cpu(intel_mwait_ids);
2256 if (boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF)
2259 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &mwait_substates);
2261 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
2262 !(ecx & CPUID5_ECX_INTERRUPT_BREAK) ||
2266 pr_debug("MWAIT substates: 0x%x\n", mwait_substates);
2268 icpu = (const struct idle_cpu *)id->driver_data;
2270 cpuidle_state_table = icpu->state_table;
2271 auto_demotion_disable_flags = icpu->auto_demotion_disable_flags;
2272 if (icpu->disable_promotion_to_c1e)
2273 c1e_promotion = C1E_PROMOTION_DISABLE;
2274 if (icpu->use_acpi || force_use_acpi)
2275 intel_idle_acpi_cst_extract();
2276 } else if (!intel_idle_acpi_cst_extract()) {
2280 pr_debug("v" INTEL_IDLE_VERSION " model 0x%X\n",
2281 boot_cpu_data.x86_model);
2283 intel_idle_cpuidle_devices = alloc_percpu(struct cpuidle_device);
2284 if (!intel_idle_cpuidle_devices)
2287 intel_idle_cpuidle_driver_init(&intel_idle_driver);
2289 retval = cpuidle_register_driver(&intel_idle_driver);
2291 struct cpuidle_driver *drv = cpuidle_get_driver();
2292 printk(KERN_DEBUG pr_fmt("intel_idle yielding to %s\n"),
2293 drv ? drv->name : "none");
2294 goto init_driver_fail;
2297 retval = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "idle/intel:online",
2298 intel_idle_cpu_online, NULL);
2302 pr_debug("Local APIC timer is reliable in %s\n",
2303 boot_cpu_has(X86_FEATURE_ARAT) ? "all C-states" : "C1");
2308 intel_idle_cpuidle_devices_uninit();
2309 cpuidle_unregister_driver(&intel_idle_driver);
2311 free_percpu(intel_idle_cpuidle_devices);
2315 device_initcall(intel_idle_init);
2318 * We are not really modular, but we used to support that. Meaning we also
2319 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
2320 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
2321 * is the easiest way (currently) to continue doing that.
2323 module_param(max_cstate, int, 0444);
2325 * The positions of the bits that are set in this number are the indices of the
2326 * idle states to be disabled by default (as reflected by the names of the
2327 * corresponding idle state directories in sysfs, "state0", "state1" ...
2328 * "state<i>" ..., where <i> is the index of the given state).
2330 module_param_named(states_off, disabled_states_mask, uint, 0444);
2331 MODULE_PARM_DESC(states_off, "Mask of disabled idle states");
2333 * Some platforms come with mutually exclusive C-states, so that if one is
2334 * enabled, the other C-states must not be used. Example: C1 and C1E on
2335 * Sapphire Rapids platform. This parameter allows for selecting the
2336 * preferred C-states among the groups of mutually exclusive C-states - the
2337 * selected C-states will be registered, the other C-states from the mutually
2338 * exclusive group won't be registered. If the platform has no mutually
2339 * exclusive C-states, this parameter has no effect.
2341 module_param_named(preferred_cstates, preferred_states_mask, uint, 0444);
2342 MODULE_PARM_DESC(preferred_cstates, "Mask of preferred idle states");
2344 * Debugging option that forces the driver to enter all C-states with
2345 * interrupts enabled. Does not apply to C-states with
2346 * 'CPUIDLE_FLAG_INIT_XSTATE' and 'CPUIDLE_FLAG_IBRS' flags.
2348 module_param(force_irq_on, bool, 0444);