1 // SPDX-License-Identifier: GPL-2.0-only
3 * intel_idle.c - native hardware idle loop for modern Intel processors
5 * Copyright (c) 2013 - 2020, Intel Corporation.
6 * Len Brown <len.brown@intel.com>
7 * Rafael J. Wysocki <rafael.j.wysocki@intel.com>
11 * intel_idle is a cpuidle driver that loads on all Intel CPUs with MWAIT
12 * in lieu of the legacy ACPI processor_idle driver. The intent is to
13 * make Linux more efficient on these processors, as intel_idle knows
14 * more than ACPI, as well as make Linux more immune to ACPI BIOS bugs.
20 * All CPUs have same idle states as boot CPU
22 * Chipset BM_STS (bus master status) bit is a NOP
23 * for preventing entry into deep C-states
25 * CPU will flush caches as needed when entering a C-state via MWAIT
26 * (in contrast to entering ACPI C3, in which case the WBINVD
27 * instruction needs to be executed to flush the caches)
33 * ACPI has a .suspend hack to turn off deep c-statees during suspend
34 * to avoid complications with the lapic timer workaround.
35 * Have not seen issues with suspend, but may need same workaround here.
39 /* un-comment DEBUG to enable pr_debug() statements */
42 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
44 #include <linux/acpi.h>
45 #include <linux/kernel.h>
46 #include <linux/cpuidle.h>
47 #include <linux/tick.h>
48 #include <trace/events/power.h>
49 #include <linux/sched.h>
50 #include <linux/sched/smt.h>
51 #include <linux/notifier.h>
52 #include <linux/cpu.h>
53 #include <linux/moduleparam.h>
54 #include <asm/cpu_device_id.h>
55 #include <asm/intel-family.h>
56 #include <asm/mwait.h>
57 #include <asm/spec-ctrl.h>
58 #include <asm/fpu/api.h>
60 #define INTEL_IDLE_VERSION "0.5.1"
62 static struct cpuidle_driver intel_idle_driver
= {
66 /* intel_idle.max_cstate=0 disables driver */
67 static int max_cstate
= CPUIDLE_STATE_MAX
- 1;
68 static unsigned int disabled_states_mask __read_mostly
;
69 static unsigned int preferred_states_mask __read_mostly
;
70 static bool force_irq_on __read_mostly
;
71 static bool ibrs_off __read_mostly
;
73 static struct cpuidle_device __percpu
*intel_idle_cpuidle_devices
;
75 static unsigned long auto_demotion_disable_flags
;
78 C1E_PROMOTION_PRESERVE
,
81 } c1e_promotion
= C1E_PROMOTION_PRESERVE
;
84 struct cpuidle_state
*state_table
;
87 * Hardware C-state auto-demotion may not always be optimal.
88 * Indicate which enable bits to clear here.
90 unsigned long auto_demotion_disable_flags
;
91 bool byt_auto_demotion_disable_flag
;
92 bool disable_promotion_to_c1e
;
96 static const struct idle_cpu
*icpu __initdata
;
97 static struct cpuidle_state
*cpuidle_state_table __initdata
;
99 static unsigned int mwait_substates __initdata
;
102 * Enable interrupts before entering the C-state. On some platforms and for
103 * some C-states, this may measurably decrease interrupt latency.
105 #define CPUIDLE_FLAG_IRQ_ENABLE BIT(14)
108 * Enable this state by default even if the ACPI _CST does not list it.
110 #define CPUIDLE_FLAG_ALWAYS_ENABLE BIT(15)
113 * Disable IBRS across idle (when KERNEL_IBRS), is exclusive vs IRQ_ENABLE
116 #define CPUIDLE_FLAG_IBRS BIT(16)
119 * Initialize large xstate for the C6-state entrance.
121 #define CPUIDLE_FLAG_INIT_XSTATE BIT(17)
124 * Ignore the sub-state when matching mwait hints between the ACPI _CST and
127 #define CPUIDLE_FLAG_PARTIAL_HINT_MATCH BIT(18)
130 * MWAIT takes an 8-bit "hint" in EAX "suggesting"
131 * the C-state (top nibble) and sub-state (bottom nibble)
132 * 0x00 means "MWAIT(C1)", 0x10 means "MWAIT(C2)" etc.
134 * We store the hint at the top of our "flags" for each state.
136 #define flg2MWAIT(flags) (((flags) >> 24) & 0xFF)
137 #define MWAIT2flg(eax) ((eax & 0xFF) << 24)
139 static __always_inline
int __intel_idle(struct cpuidle_device
*dev
,
140 struct cpuidle_driver
*drv
,
141 int index
, bool irqoff
)
143 struct cpuidle_state
*state
= &drv
->states
[index
];
144 unsigned long eax
= flg2MWAIT(state
->flags
);
145 unsigned long ecx
= 1*irqoff
; /* break on interrupt flag */
147 mwait_idle_with_hints(eax
, ecx
);
153 * intel_idle - Ask the processor to enter the given idle state.
154 * @dev: cpuidle device of the target CPU.
155 * @drv: cpuidle driver (assumed to point to intel_idle_driver).
156 * @index: Target idle state index.
158 * Use the MWAIT instruction to notify the processor that the CPU represented by
159 * @dev is idle and it can try to enter the idle state corresponding to @index.
161 * If the local APIC timer is not known to be reliable in the target idle state,
162 * enable one-shot tick broadcasting for the target CPU before executing MWAIT.
164 * Must be called under local_irq_disable().
166 static __cpuidle
int intel_idle(struct cpuidle_device
*dev
,
167 struct cpuidle_driver
*drv
, int index
)
169 return __intel_idle(dev
, drv
, index
, true);
172 static __cpuidle
int intel_idle_irq(struct cpuidle_device
*dev
,
173 struct cpuidle_driver
*drv
, int index
)
175 return __intel_idle(dev
, drv
, index
, false);
178 static __cpuidle
int intel_idle_ibrs(struct cpuidle_device
*dev
,
179 struct cpuidle_driver
*drv
, int index
)
181 bool smt_active
= sched_smt_active();
182 u64 spec_ctrl
= spec_ctrl_current();
186 __update_spec_ctrl(0);
188 ret
= __intel_idle(dev
, drv
, index
, true);
191 __update_spec_ctrl(spec_ctrl
);
196 static __cpuidle
int intel_idle_xstate(struct cpuidle_device
*dev
,
197 struct cpuidle_driver
*drv
, int index
)
200 return __intel_idle(dev
, drv
, index
, true);
204 * intel_idle_s2idle - Ask the processor to enter the given idle state.
205 * @dev: cpuidle device of the target CPU.
206 * @drv: cpuidle driver (assumed to point to intel_idle_driver).
207 * @index: Target idle state index.
209 * Use the MWAIT instruction to notify the processor that the CPU represented by
210 * @dev is idle and it can try to enter the idle state corresponding to @index.
212 * Invoked as a suspend-to-idle callback routine with frozen user space, frozen
213 * scheduler tick and suspended scheduler clock on the target CPU.
215 static __cpuidle
int intel_idle_s2idle(struct cpuidle_device
*dev
,
216 struct cpuidle_driver
*drv
, int index
)
218 unsigned long ecx
= 1; /* break on interrupt flag */
219 struct cpuidle_state
*state
= &drv
->states
[index
];
220 unsigned long eax
= flg2MWAIT(state
->flags
);
222 if (state
->flags
& CPUIDLE_FLAG_INIT_XSTATE
)
225 mwait_idle_with_hints(eax
, ecx
);
231 * States are indexed by the cstate number,
232 * which is also the index into the MWAIT hint array.
233 * Thus C0 is a dummy.
235 static struct cpuidle_state nehalem_cstates
[] __initdata
= {
238 .desc
= "MWAIT 0x00",
239 .flags
= MWAIT2flg(0x00),
241 .target_residency
= 6,
242 .enter
= &intel_idle
,
243 .enter_s2idle
= intel_idle_s2idle
, },
246 .desc
= "MWAIT 0x01",
247 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
249 .target_residency
= 20,
250 .enter
= &intel_idle
,
251 .enter_s2idle
= intel_idle_s2idle
, },
254 .desc
= "MWAIT 0x10",
255 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
257 .target_residency
= 80,
258 .enter
= &intel_idle
,
259 .enter_s2idle
= intel_idle_s2idle
, },
262 .desc
= "MWAIT 0x20",
263 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
265 .target_residency
= 800,
266 .enter
= &intel_idle
,
267 .enter_s2idle
= intel_idle_s2idle
, },
272 static struct cpuidle_state snb_cstates
[] __initdata
= {
275 .desc
= "MWAIT 0x00",
276 .flags
= MWAIT2flg(0x00),
278 .target_residency
= 2,
279 .enter
= &intel_idle
,
280 .enter_s2idle
= intel_idle_s2idle
, },
283 .desc
= "MWAIT 0x01",
284 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
286 .target_residency
= 20,
287 .enter
= &intel_idle
,
288 .enter_s2idle
= intel_idle_s2idle
, },
291 .desc
= "MWAIT 0x10",
292 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
294 .target_residency
= 211,
295 .enter
= &intel_idle
,
296 .enter_s2idle
= intel_idle_s2idle
, },
299 .desc
= "MWAIT 0x20",
300 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
302 .target_residency
= 345,
303 .enter
= &intel_idle
,
304 .enter_s2idle
= intel_idle_s2idle
, },
307 .desc
= "MWAIT 0x30",
308 .flags
= MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED
,
310 .target_residency
= 345,
311 .enter
= &intel_idle
,
312 .enter_s2idle
= intel_idle_s2idle
, },
317 static struct cpuidle_state byt_cstates
[] __initdata
= {
320 .desc
= "MWAIT 0x00",
321 .flags
= MWAIT2flg(0x00),
323 .target_residency
= 1,
324 .enter
= &intel_idle
,
325 .enter_s2idle
= intel_idle_s2idle
, },
328 .desc
= "MWAIT 0x58",
329 .flags
= MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED
,
331 .target_residency
= 275,
332 .enter
= &intel_idle
,
333 .enter_s2idle
= intel_idle_s2idle
, },
336 .desc
= "MWAIT 0x52",
337 .flags
= MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED
,
339 .target_residency
= 560,
340 .enter
= &intel_idle
,
341 .enter_s2idle
= intel_idle_s2idle
, },
344 .desc
= "MWAIT 0x60",
345 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
346 .exit_latency
= 1200,
347 .target_residency
= 4000,
348 .enter
= &intel_idle
,
349 .enter_s2idle
= intel_idle_s2idle
, },
352 .desc
= "MWAIT 0x64",
353 .flags
= MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED
,
354 .exit_latency
= 10000,
355 .target_residency
= 20000,
356 .enter
= &intel_idle
,
357 .enter_s2idle
= intel_idle_s2idle
, },
362 static struct cpuidle_state cht_cstates
[] __initdata
= {
365 .desc
= "MWAIT 0x00",
366 .flags
= MWAIT2flg(0x00),
368 .target_residency
= 1,
369 .enter
= &intel_idle
,
370 .enter_s2idle
= intel_idle_s2idle
, },
373 .desc
= "MWAIT 0x58",
374 .flags
= MWAIT2flg(0x58) | CPUIDLE_FLAG_TLB_FLUSHED
,
376 .target_residency
= 275,
377 .enter
= &intel_idle
,
378 .enter_s2idle
= intel_idle_s2idle
, },
381 .desc
= "MWAIT 0x52",
382 .flags
= MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED
,
384 .target_residency
= 560,
385 .enter
= &intel_idle
,
386 .enter_s2idle
= intel_idle_s2idle
, },
389 .desc
= "MWAIT 0x60",
390 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
391 .exit_latency
= 1200,
392 .target_residency
= 4000,
393 .enter
= &intel_idle
,
394 .enter_s2idle
= intel_idle_s2idle
, },
397 .desc
= "MWAIT 0x64",
398 .flags
= MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED
,
399 .exit_latency
= 10000,
400 .target_residency
= 20000,
401 .enter
= &intel_idle
,
402 .enter_s2idle
= intel_idle_s2idle
, },
407 static struct cpuidle_state ivb_cstates
[] __initdata
= {
410 .desc
= "MWAIT 0x00",
411 .flags
= MWAIT2flg(0x00),
413 .target_residency
= 1,
414 .enter
= &intel_idle
,
415 .enter_s2idle
= intel_idle_s2idle
, },
418 .desc
= "MWAIT 0x01",
419 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
421 .target_residency
= 20,
422 .enter
= &intel_idle
,
423 .enter_s2idle
= intel_idle_s2idle
, },
426 .desc
= "MWAIT 0x10",
427 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
429 .target_residency
= 156,
430 .enter
= &intel_idle
,
431 .enter_s2idle
= intel_idle_s2idle
, },
434 .desc
= "MWAIT 0x20",
435 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
437 .target_residency
= 300,
438 .enter
= &intel_idle
,
439 .enter_s2idle
= intel_idle_s2idle
, },
442 .desc
= "MWAIT 0x30",
443 .flags
= MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED
,
445 .target_residency
= 300,
446 .enter
= &intel_idle
,
447 .enter_s2idle
= intel_idle_s2idle
, },
452 static struct cpuidle_state ivt_cstates
[] __initdata
= {
455 .desc
= "MWAIT 0x00",
456 .flags
= MWAIT2flg(0x00),
458 .target_residency
= 1,
459 .enter
= &intel_idle
,
460 .enter_s2idle
= intel_idle_s2idle
, },
463 .desc
= "MWAIT 0x01",
464 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
466 .target_residency
= 80,
467 .enter
= &intel_idle
,
468 .enter_s2idle
= intel_idle_s2idle
, },
471 .desc
= "MWAIT 0x10",
472 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
474 .target_residency
= 156,
475 .enter
= &intel_idle
,
476 .enter_s2idle
= intel_idle_s2idle
, },
479 .desc
= "MWAIT 0x20",
480 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
482 .target_residency
= 300,
483 .enter
= &intel_idle
,
484 .enter_s2idle
= intel_idle_s2idle
, },
489 static struct cpuidle_state ivt_cstates_4s
[] __initdata
= {
492 .desc
= "MWAIT 0x00",
493 .flags
= MWAIT2flg(0x00),
495 .target_residency
= 1,
496 .enter
= &intel_idle
,
497 .enter_s2idle
= intel_idle_s2idle
, },
500 .desc
= "MWAIT 0x01",
501 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
503 .target_residency
= 250,
504 .enter
= &intel_idle
,
505 .enter_s2idle
= intel_idle_s2idle
, },
508 .desc
= "MWAIT 0x10",
509 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
511 .target_residency
= 300,
512 .enter
= &intel_idle
,
513 .enter_s2idle
= intel_idle_s2idle
, },
516 .desc
= "MWAIT 0x20",
517 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
519 .target_residency
= 400,
520 .enter
= &intel_idle
,
521 .enter_s2idle
= intel_idle_s2idle
, },
526 static struct cpuidle_state ivt_cstates_8s
[] __initdata
= {
529 .desc
= "MWAIT 0x00",
530 .flags
= MWAIT2flg(0x00),
532 .target_residency
= 1,
533 .enter
= &intel_idle
,
534 .enter_s2idle
= intel_idle_s2idle
, },
537 .desc
= "MWAIT 0x01",
538 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
540 .target_residency
= 500,
541 .enter
= &intel_idle
,
542 .enter_s2idle
= intel_idle_s2idle
, },
545 .desc
= "MWAIT 0x10",
546 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
548 .target_residency
= 600,
549 .enter
= &intel_idle
,
550 .enter_s2idle
= intel_idle_s2idle
, },
553 .desc
= "MWAIT 0x20",
554 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
556 .target_residency
= 700,
557 .enter
= &intel_idle
,
558 .enter_s2idle
= intel_idle_s2idle
, },
563 static struct cpuidle_state hsw_cstates
[] __initdata
= {
566 .desc
= "MWAIT 0x00",
567 .flags
= MWAIT2flg(0x00),
569 .target_residency
= 2,
570 .enter
= &intel_idle
,
571 .enter_s2idle
= intel_idle_s2idle
, },
574 .desc
= "MWAIT 0x01",
575 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
577 .target_residency
= 20,
578 .enter
= &intel_idle
,
579 .enter_s2idle
= intel_idle_s2idle
, },
582 .desc
= "MWAIT 0x10",
583 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
585 .target_residency
= 100,
586 .enter
= &intel_idle
,
587 .enter_s2idle
= intel_idle_s2idle
, },
590 .desc
= "MWAIT 0x20",
591 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
593 .target_residency
= 400,
594 .enter
= &intel_idle
,
595 .enter_s2idle
= intel_idle_s2idle
, },
598 .desc
= "MWAIT 0x32",
599 .flags
= MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED
,
601 .target_residency
= 500,
602 .enter
= &intel_idle
,
603 .enter_s2idle
= intel_idle_s2idle
, },
606 .desc
= "MWAIT 0x40",
607 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
609 .target_residency
= 900,
610 .enter
= &intel_idle
,
611 .enter_s2idle
= intel_idle_s2idle
, },
614 .desc
= "MWAIT 0x50",
615 .flags
= MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED
,
617 .target_residency
= 1800,
618 .enter
= &intel_idle
,
619 .enter_s2idle
= intel_idle_s2idle
, },
622 .desc
= "MWAIT 0x60",
623 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
624 .exit_latency
= 2600,
625 .target_residency
= 7700,
626 .enter
= &intel_idle
,
627 .enter_s2idle
= intel_idle_s2idle
, },
631 static struct cpuidle_state bdw_cstates
[] __initdata
= {
634 .desc
= "MWAIT 0x00",
635 .flags
= MWAIT2flg(0x00),
637 .target_residency
= 2,
638 .enter
= &intel_idle
,
639 .enter_s2idle
= intel_idle_s2idle
, },
642 .desc
= "MWAIT 0x01",
643 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
645 .target_residency
= 20,
646 .enter
= &intel_idle
,
647 .enter_s2idle
= intel_idle_s2idle
, },
650 .desc
= "MWAIT 0x10",
651 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
653 .target_residency
= 100,
654 .enter
= &intel_idle
,
655 .enter_s2idle
= intel_idle_s2idle
, },
658 .desc
= "MWAIT 0x20",
659 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
661 .target_residency
= 400,
662 .enter
= &intel_idle
,
663 .enter_s2idle
= intel_idle_s2idle
, },
666 .desc
= "MWAIT 0x32",
667 .flags
= MWAIT2flg(0x32) | CPUIDLE_FLAG_TLB_FLUSHED
,
669 .target_residency
= 500,
670 .enter
= &intel_idle
,
671 .enter_s2idle
= intel_idle_s2idle
, },
674 .desc
= "MWAIT 0x40",
675 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
677 .target_residency
= 900,
678 .enter
= &intel_idle
,
679 .enter_s2idle
= intel_idle_s2idle
, },
682 .desc
= "MWAIT 0x50",
683 .flags
= MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED
,
685 .target_residency
= 1800,
686 .enter
= &intel_idle
,
687 .enter_s2idle
= intel_idle_s2idle
, },
690 .desc
= "MWAIT 0x60",
691 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
692 .exit_latency
= 2600,
693 .target_residency
= 7700,
694 .enter
= &intel_idle
,
695 .enter_s2idle
= intel_idle_s2idle
, },
700 static struct cpuidle_state skl_cstates
[] __initdata
= {
703 .desc
= "MWAIT 0x00",
704 .flags
= MWAIT2flg(0x00),
706 .target_residency
= 2,
707 .enter
= &intel_idle
,
708 .enter_s2idle
= intel_idle_s2idle
, },
711 .desc
= "MWAIT 0x01",
712 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
714 .target_residency
= 20,
715 .enter
= &intel_idle
,
716 .enter_s2idle
= intel_idle_s2idle
, },
719 .desc
= "MWAIT 0x10",
720 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
722 .target_residency
= 100,
723 .enter
= &intel_idle
,
724 .enter_s2idle
= intel_idle_s2idle
, },
727 .desc
= "MWAIT 0x20",
728 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
730 .target_residency
= 200,
731 .enter
= &intel_idle
,
732 .enter_s2idle
= intel_idle_s2idle
, },
735 .desc
= "MWAIT 0x33",
736 .flags
= MWAIT2flg(0x33) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
738 .target_residency
= 800,
739 .enter
= &intel_idle
,
740 .enter_s2idle
= intel_idle_s2idle
, },
743 .desc
= "MWAIT 0x40",
744 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
746 .target_residency
= 800,
747 .enter
= &intel_idle
,
748 .enter_s2idle
= intel_idle_s2idle
, },
751 .desc
= "MWAIT 0x50",
752 .flags
= MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
754 .target_residency
= 5000,
755 .enter
= &intel_idle
,
756 .enter_s2idle
= intel_idle_s2idle
, },
759 .desc
= "MWAIT 0x60",
760 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
762 .target_residency
= 5000,
763 .enter
= &intel_idle
,
764 .enter_s2idle
= intel_idle_s2idle
, },
769 static struct cpuidle_state skx_cstates
[] __initdata
= {
772 .desc
= "MWAIT 0x00",
773 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_IRQ_ENABLE
,
775 .target_residency
= 2,
776 .enter
= &intel_idle
,
777 .enter_s2idle
= intel_idle_s2idle
, },
780 .desc
= "MWAIT 0x01",
781 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
783 .target_residency
= 20,
784 .enter
= &intel_idle
,
785 .enter_s2idle
= intel_idle_s2idle
, },
788 .desc
= "MWAIT 0x20",
789 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
| CPUIDLE_FLAG_IBRS
,
791 .target_residency
= 600,
792 .enter
= &intel_idle
,
793 .enter_s2idle
= intel_idle_s2idle
, },
798 static struct cpuidle_state icx_cstates
[] __initdata
= {
801 .desc
= "MWAIT 0x00",
802 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_IRQ_ENABLE
,
804 .target_residency
= 1,
805 .enter
= &intel_idle
,
806 .enter_s2idle
= intel_idle_s2idle
, },
809 .desc
= "MWAIT 0x01",
810 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
812 .target_residency
= 4,
813 .enter
= &intel_idle
,
814 .enter_s2idle
= intel_idle_s2idle
, },
817 .desc
= "MWAIT 0x20",
818 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
820 .target_residency
= 600,
821 .enter
= &intel_idle
,
822 .enter_s2idle
= intel_idle_s2idle
, },
828 * On AlderLake C1 has to be disabled if C1E is enabled, and vice versa.
829 * C1E is enabled only if "C1E promotion" bit is set in MSR_IA32_POWER_CTL.
830 * But in this case there is effectively no C1, because C1 requests are
831 * promoted to C1E. If the "C1E promotion" bit is cleared, then both C1
832 * and C1E requests end up with C1, so there is effectively no C1E.
834 * By default we enable C1E and disable C1 by marking it with
835 * 'CPUIDLE_FLAG_UNUSABLE'.
837 static struct cpuidle_state adl_cstates
[] __initdata
= {
840 .desc
= "MWAIT 0x00",
841 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE
,
843 .target_residency
= 1,
844 .enter
= &intel_idle
,
845 .enter_s2idle
= intel_idle_s2idle
, },
848 .desc
= "MWAIT 0x01",
849 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
851 .target_residency
= 4,
852 .enter
= &intel_idle
,
853 .enter_s2idle
= intel_idle_s2idle
, },
856 .desc
= "MWAIT 0x20",
857 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
859 .target_residency
= 600,
860 .enter
= &intel_idle
,
861 .enter_s2idle
= intel_idle_s2idle
, },
864 .desc
= "MWAIT 0x40",
865 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
867 .target_residency
= 800,
868 .enter
= &intel_idle
,
869 .enter_s2idle
= intel_idle_s2idle
, },
872 .desc
= "MWAIT 0x60",
873 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
875 .target_residency
= 2000,
876 .enter
= &intel_idle
,
877 .enter_s2idle
= intel_idle_s2idle
, },
882 static struct cpuidle_state adl_l_cstates
[] __initdata
= {
885 .desc
= "MWAIT 0x00",
886 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE
,
888 .target_residency
= 1,
889 .enter
= &intel_idle
,
890 .enter_s2idle
= intel_idle_s2idle
, },
893 .desc
= "MWAIT 0x01",
894 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
896 .target_residency
= 4,
897 .enter
= &intel_idle
,
898 .enter_s2idle
= intel_idle_s2idle
, },
901 .desc
= "MWAIT 0x20",
902 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
904 .target_residency
= 500,
905 .enter
= &intel_idle
,
906 .enter_s2idle
= intel_idle_s2idle
, },
909 .desc
= "MWAIT 0x40",
910 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
912 .target_residency
= 600,
913 .enter
= &intel_idle
,
914 .enter_s2idle
= intel_idle_s2idle
, },
917 .desc
= "MWAIT 0x60",
918 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
920 .target_residency
= 700,
921 .enter
= &intel_idle
,
922 .enter_s2idle
= intel_idle_s2idle
, },
927 static struct cpuidle_state mtl_l_cstates
[] __initdata
= {
930 .desc
= "MWAIT 0x01",
931 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
933 .target_residency
= 1,
934 .enter
= &intel_idle
,
935 .enter_s2idle
= intel_idle_s2idle
, },
938 .desc
= "MWAIT 0x20",
939 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
941 .target_residency
= 420,
942 .enter
= &intel_idle
,
943 .enter_s2idle
= intel_idle_s2idle
, },
946 .desc
= "MWAIT 0x60",
947 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
949 .target_residency
= 930,
950 .enter
= &intel_idle
,
951 .enter_s2idle
= intel_idle_s2idle
, },
956 static struct cpuidle_state gmt_cstates
[] __initdata
= {
959 .desc
= "MWAIT 0x00",
960 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_UNUSABLE
,
962 .target_residency
= 1,
963 .enter
= &intel_idle
,
964 .enter_s2idle
= intel_idle_s2idle
, },
967 .desc
= "MWAIT 0x01",
968 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
970 .target_residency
= 4,
971 .enter
= &intel_idle
,
972 .enter_s2idle
= intel_idle_s2idle
, },
975 .desc
= "MWAIT 0x20",
976 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
978 .target_residency
= 585,
979 .enter
= &intel_idle
,
980 .enter_s2idle
= intel_idle_s2idle
, },
983 .desc
= "MWAIT 0x40",
984 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
986 .target_residency
= 1040,
987 .enter
= &intel_idle
,
988 .enter_s2idle
= intel_idle_s2idle
, },
991 .desc
= "MWAIT 0x60",
992 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
994 .target_residency
= 1980,
995 .enter
= &intel_idle
,
996 .enter_s2idle
= intel_idle_s2idle
, },
1001 static struct cpuidle_state spr_cstates
[] __initdata
= {
1004 .desc
= "MWAIT 0x00",
1005 .flags
= MWAIT2flg(0x00),
1007 .target_residency
= 1,
1008 .enter
= &intel_idle
,
1009 .enter_s2idle
= intel_idle_s2idle
, },
1012 .desc
= "MWAIT 0x01",
1013 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1015 .target_residency
= 4,
1016 .enter
= &intel_idle
,
1017 .enter_s2idle
= intel_idle_s2idle
, },
1020 .desc
= "MWAIT 0x20",
1021 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
|
1022 CPUIDLE_FLAG_INIT_XSTATE
,
1023 .exit_latency
= 290,
1024 .target_residency
= 800,
1025 .enter
= &intel_idle
,
1026 .enter_s2idle
= intel_idle_s2idle
, },
1031 static struct cpuidle_state gnr_cstates
[] __initdata
= {
1034 .desc
= "MWAIT 0x00",
1035 .flags
= MWAIT2flg(0x00),
1037 .target_residency
= 1,
1038 .enter
= &intel_idle
,
1039 .enter_s2idle
= intel_idle_s2idle
, },
1042 .desc
= "MWAIT 0x01",
1043 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1045 .target_residency
= 4,
1046 .enter
= &intel_idle
,
1047 .enter_s2idle
= intel_idle_s2idle
, },
1050 .desc
= "MWAIT 0x20",
1051 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
|
1052 CPUIDLE_FLAG_INIT_XSTATE
|
1053 CPUIDLE_FLAG_PARTIAL_HINT_MATCH
,
1054 .exit_latency
= 170,
1055 .target_residency
= 650,
1056 .enter
= &intel_idle
,
1057 .enter_s2idle
= intel_idle_s2idle
, },
1060 .desc
= "MWAIT 0x21",
1061 .flags
= MWAIT2flg(0x21) | CPUIDLE_FLAG_TLB_FLUSHED
|
1062 CPUIDLE_FLAG_INIT_XSTATE
|
1063 CPUIDLE_FLAG_PARTIAL_HINT_MATCH
,
1064 .exit_latency
= 210,
1065 .target_residency
= 1000,
1066 .enter
= &intel_idle
,
1067 .enter_s2idle
= intel_idle_s2idle
, },
1072 static struct cpuidle_state atom_cstates
[] __initdata
= {
1075 .desc
= "MWAIT 0x00",
1076 .flags
= MWAIT2flg(0x00),
1078 .target_residency
= 20,
1079 .enter
= &intel_idle
,
1080 .enter_s2idle
= intel_idle_s2idle
, },
1083 .desc
= "MWAIT 0x10",
1084 .flags
= MWAIT2flg(0x10),
1086 .target_residency
= 80,
1087 .enter
= &intel_idle
,
1088 .enter_s2idle
= intel_idle_s2idle
, },
1091 .desc
= "MWAIT 0x30",
1092 .flags
= MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED
,
1093 .exit_latency
= 100,
1094 .target_residency
= 400,
1095 .enter
= &intel_idle
,
1096 .enter_s2idle
= intel_idle_s2idle
, },
1099 .desc
= "MWAIT 0x52",
1100 .flags
= MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED
,
1101 .exit_latency
= 140,
1102 .target_residency
= 560,
1103 .enter
= &intel_idle
,
1104 .enter_s2idle
= intel_idle_s2idle
, },
1108 static struct cpuidle_state tangier_cstates
[] __initdata
= {
1111 .desc
= "MWAIT 0x00",
1112 .flags
= MWAIT2flg(0x00),
1114 .target_residency
= 4,
1115 .enter
= &intel_idle
,
1116 .enter_s2idle
= intel_idle_s2idle
, },
1119 .desc
= "MWAIT 0x30",
1120 .flags
= MWAIT2flg(0x30) | CPUIDLE_FLAG_TLB_FLUSHED
,
1121 .exit_latency
= 100,
1122 .target_residency
= 400,
1123 .enter
= &intel_idle
,
1124 .enter_s2idle
= intel_idle_s2idle
, },
1127 .desc
= "MWAIT 0x52",
1128 .flags
= MWAIT2flg(0x52) | CPUIDLE_FLAG_TLB_FLUSHED
,
1129 .exit_latency
= 140,
1130 .target_residency
= 560,
1131 .enter
= &intel_idle
,
1132 .enter_s2idle
= intel_idle_s2idle
, },
1135 .desc
= "MWAIT 0x60",
1136 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
1137 .exit_latency
= 1200,
1138 .target_residency
= 4000,
1139 .enter
= &intel_idle
,
1140 .enter_s2idle
= intel_idle_s2idle
, },
1143 .desc
= "MWAIT 0x64",
1144 .flags
= MWAIT2flg(0x64) | CPUIDLE_FLAG_TLB_FLUSHED
,
1145 .exit_latency
= 10000,
1146 .target_residency
= 20000,
1147 .enter
= &intel_idle
,
1148 .enter_s2idle
= intel_idle_s2idle
, },
1152 static struct cpuidle_state avn_cstates
[] __initdata
= {
1155 .desc
= "MWAIT 0x00",
1156 .flags
= MWAIT2flg(0x00),
1158 .target_residency
= 2,
1159 .enter
= &intel_idle
,
1160 .enter_s2idle
= intel_idle_s2idle
, },
1163 .desc
= "MWAIT 0x51",
1164 .flags
= MWAIT2flg(0x51) | CPUIDLE_FLAG_TLB_FLUSHED
,
1166 .target_residency
= 45,
1167 .enter
= &intel_idle
,
1168 .enter_s2idle
= intel_idle_s2idle
, },
1172 static struct cpuidle_state knl_cstates
[] __initdata
= {
1175 .desc
= "MWAIT 0x00",
1176 .flags
= MWAIT2flg(0x00),
1178 .target_residency
= 2,
1179 .enter
= &intel_idle
,
1180 .enter_s2idle
= intel_idle_s2idle
},
1183 .desc
= "MWAIT 0x10",
1184 .flags
= MWAIT2flg(0x10) | CPUIDLE_FLAG_TLB_FLUSHED
,
1185 .exit_latency
= 120,
1186 .target_residency
= 500,
1187 .enter
= &intel_idle
,
1188 .enter_s2idle
= intel_idle_s2idle
},
1193 static struct cpuidle_state bxt_cstates
[] __initdata
= {
1196 .desc
= "MWAIT 0x00",
1197 .flags
= MWAIT2flg(0x00),
1199 .target_residency
= 2,
1200 .enter
= &intel_idle
,
1201 .enter_s2idle
= intel_idle_s2idle
, },
1204 .desc
= "MWAIT 0x01",
1205 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1207 .target_residency
= 20,
1208 .enter
= &intel_idle
,
1209 .enter_s2idle
= intel_idle_s2idle
, },
1212 .desc
= "MWAIT 0x20",
1213 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
1214 .exit_latency
= 133,
1215 .target_residency
= 133,
1216 .enter
= &intel_idle
,
1217 .enter_s2idle
= intel_idle_s2idle
, },
1220 .desc
= "MWAIT 0x31",
1221 .flags
= MWAIT2flg(0x31) | CPUIDLE_FLAG_TLB_FLUSHED
,
1222 .exit_latency
= 155,
1223 .target_residency
= 155,
1224 .enter
= &intel_idle
,
1225 .enter_s2idle
= intel_idle_s2idle
, },
1228 .desc
= "MWAIT 0x40",
1229 .flags
= MWAIT2flg(0x40) | CPUIDLE_FLAG_TLB_FLUSHED
,
1230 .exit_latency
= 1000,
1231 .target_residency
= 1000,
1232 .enter
= &intel_idle
,
1233 .enter_s2idle
= intel_idle_s2idle
, },
1236 .desc
= "MWAIT 0x50",
1237 .flags
= MWAIT2flg(0x50) | CPUIDLE_FLAG_TLB_FLUSHED
,
1238 .exit_latency
= 2000,
1239 .target_residency
= 2000,
1240 .enter
= &intel_idle
,
1241 .enter_s2idle
= intel_idle_s2idle
, },
1244 .desc
= "MWAIT 0x60",
1245 .flags
= MWAIT2flg(0x60) | CPUIDLE_FLAG_TLB_FLUSHED
,
1246 .exit_latency
= 10000,
1247 .target_residency
= 10000,
1248 .enter
= &intel_idle
,
1249 .enter_s2idle
= intel_idle_s2idle
, },
1254 static struct cpuidle_state dnv_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
,
1276 .target_residency
= 500,
1277 .enter
= &intel_idle
,
1278 .enter_s2idle
= intel_idle_s2idle
, },
1284 * Note, depending on HW and FW revision, SnowRidge SoC may or may not support
1285 * C6, and this is indicated in the CPUID mwait leaf.
1287 static struct cpuidle_state snr_cstates
[] __initdata
= {
1290 .desc
= "MWAIT 0x00",
1291 .flags
= MWAIT2flg(0x00),
1293 .target_residency
= 2,
1294 .enter
= &intel_idle
,
1295 .enter_s2idle
= intel_idle_s2idle
, },
1298 .desc
= "MWAIT 0x01",
1299 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1301 .target_residency
= 25,
1302 .enter
= &intel_idle
,
1303 .enter_s2idle
= intel_idle_s2idle
, },
1306 .desc
= "MWAIT 0x20",
1307 .flags
= MWAIT2flg(0x20) | CPUIDLE_FLAG_TLB_FLUSHED
,
1308 .exit_latency
= 130,
1309 .target_residency
= 500,
1310 .enter
= &intel_idle
,
1311 .enter_s2idle
= intel_idle_s2idle
, },
1316 static struct cpuidle_state grr_cstates
[] __initdata
= {
1319 .desc
= "MWAIT 0x00",
1320 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1322 .target_residency
= 1,
1323 .enter
= &intel_idle
,
1324 .enter_s2idle
= intel_idle_s2idle
, },
1327 .desc
= "MWAIT 0x01",
1328 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1330 .target_residency
= 10,
1331 .enter
= &intel_idle
,
1332 .enter_s2idle
= intel_idle_s2idle
, },
1335 .desc
= "MWAIT 0x22",
1336 .flags
= MWAIT2flg(0x22) | CPUIDLE_FLAG_TLB_FLUSHED
,
1337 .exit_latency
= 140,
1338 .target_residency
= 500,
1339 .enter
= &intel_idle
,
1340 .enter_s2idle
= intel_idle_s2idle
, },
1345 static struct cpuidle_state srf_cstates
[] __initdata
= {
1348 .desc
= "MWAIT 0x00",
1349 .flags
= MWAIT2flg(0x00) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1351 .target_residency
= 1,
1352 .enter
= &intel_idle
,
1353 .enter_s2idle
= intel_idle_s2idle
, },
1356 .desc
= "MWAIT 0x01",
1357 .flags
= MWAIT2flg(0x01) | CPUIDLE_FLAG_ALWAYS_ENABLE
,
1359 .target_residency
= 10,
1360 .enter
= &intel_idle
,
1361 .enter_s2idle
= intel_idle_s2idle
, },
1364 .desc
= "MWAIT 0x22",
1365 .flags
= MWAIT2flg(0x22) | CPUIDLE_FLAG_TLB_FLUSHED
|
1366 CPUIDLE_FLAG_PARTIAL_HINT_MATCH
,
1367 .exit_latency
= 270,
1368 .target_residency
= 700,
1369 .enter
= &intel_idle
,
1370 .enter_s2idle
= intel_idle_s2idle
, },
1373 .desc
= "MWAIT 0x23",
1374 .flags
= MWAIT2flg(0x23) | CPUIDLE_FLAG_TLB_FLUSHED
|
1375 CPUIDLE_FLAG_PARTIAL_HINT_MATCH
,
1376 .exit_latency
= 310,
1377 .target_residency
= 900,
1378 .enter
= &intel_idle
,
1379 .enter_s2idle
= intel_idle_s2idle
, },
1384 static const struct idle_cpu idle_cpu_nehalem __initconst
= {
1385 .state_table
= nehalem_cstates
,
1386 .auto_demotion_disable_flags
= NHM_C1_AUTO_DEMOTE
| NHM_C3_AUTO_DEMOTE
,
1387 .disable_promotion_to_c1e
= true,
1390 static const struct idle_cpu idle_cpu_nhx __initconst
= {
1391 .state_table
= nehalem_cstates
,
1392 .auto_demotion_disable_flags
= NHM_C1_AUTO_DEMOTE
| NHM_C3_AUTO_DEMOTE
,
1393 .disable_promotion_to_c1e
= true,
1397 static const struct idle_cpu idle_cpu_atom __initconst
= {
1398 .state_table
= atom_cstates
,
1401 static const struct idle_cpu idle_cpu_tangier __initconst
= {
1402 .state_table
= tangier_cstates
,
1405 static const struct idle_cpu idle_cpu_lincroft __initconst
= {
1406 .state_table
= atom_cstates
,
1407 .auto_demotion_disable_flags
= ATM_LNC_C6_AUTO_DEMOTE
,
1410 static const struct idle_cpu idle_cpu_snb __initconst
= {
1411 .state_table
= snb_cstates
,
1412 .disable_promotion_to_c1e
= true,
1415 static const struct idle_cpu idle_cpu_snx __initconst
= {
1416 .state_table
= snb_cstates
,
1417 .disable_promotion_to_c1e
= true,
1421 static const struct idle_cpu idle_cpu_byt __initconst
= {
1422 .state_table
= byt_cstates
,
1423 .disable_promotion_to_c1e
= true,
1424 .byt_auto_demotion_disable_flag
= true,
1427 static const struct idle_cpu idle_cpu_cht __initconst
= {
1428 .state_table
= cht_cstates
,
1429 .disable_promotion_to_c1e
= true,
1430 .byt_auto_demotion_disable_flag
= true,
1433 static const struct idle_cpu idle_cpu_ivb __initconst
= {
1434 .state_table
= ivb_cstates
,
1435 .disable_promotion_to_c1e
= true,
1438 static const struct idle_cpu idle_cpu_ivt __initconst
= {
1439 .state_table
= ivt_cstates
,
1440 .disable_promotion_to_c1e
= true,
1444 static const struct idle_cpu idle_cpu_hsw __initconst
= {
1445 .state_table
= hsw_cstates
,
1446 .disable_promotion_to_c1e
= true,
1449 static const struct idle_cpu idle_cpu_hsx __initconst
= {
1450 .state_table
= hsw_cstates
,
1451 .disable_promotion_to_c1e
= true,
1455 static const struct idle_cpu idle_cpu_bdw __initconst
= {
1456 .state_table
= bdw_cstates
,
1457 .disable_promotion_to_c1e
= true,
1460 static const struct idle_cpu idle_cpu_bdx __initconst
= {
1461 .state_table
= bdw_cstates
,
1462 .disable_promotion_to_c1e
= true,
1466 static const struct idle_cpu idle_cpu_skl __initconst
= {
1467 .state_table
= skl_cstates
,
1468 .disable_promotion_to_c1e
= true,
1471 static const struct idle_cpu idle_cpu_skx __initconst
= {
1472 .state_table
= skx_cstates
,
1473 .disable_promotion_to_c1e
= true,
1477 static const struct idle_cpu idle_cpu_icx __initconst
= {
1478 .state_table
= icx_cstates
,
1479 .disable_promotion_to_c1e
= true,
1483 static const struct idle_cpu idle_cpu_adl __initconst
= {
1484 .state_table
= adl_cstates
,
1487 static const struct idle_cpu idle_cpu_adl_l __initconst
= {
1488 .state_table
= adl_l_cstates
,
1491 static const struct idle_cpu idle_cpu_mtl_l __initconst
= {
1492 .state_table
= mtl_l_cstates
,
1495 static const struct idle_cpu idle_cpu_gmt __initconst
= {
1496 .state_table
= gmt_cstates
,
1499 static const struct idle_cpu idle_cpu_spr __initconst
= {
1500 .state_table
= spr_cstates
,
1501 .disable_promotion_to_c1e
= true,
1505 static const struct idle_cpu idle_cpu_gnr __initconst
= {
1506 .state_table
= gnr_cstates
,
1507 .disable_promotion_to_c1e
= true,
1511 static const struct idle_cpu idle_cpu_avn __initconst
= {
1512 .state_table
= avn_cstates
,
1513 .disable_promotion_to_c1e
= true,
1517 static const struct idle_cpu idle_cpu_knl __initconst
= {
1518 .state_table
= knl_cstates
,
1522 static const struct idle_cpu idle_cpu_bxt __initconst
= {
1523 .state_table
= bxt_cstates
,
1524 .disable_promotion_to_c1e
= true,
1527 static const struct idle_cpu idle_cpu_dnv __initconst
= {
1528 .state_table
= dnv_cstates
,
1529 .disable_promotion_to_c1e
= true,
1533 static const struct idle_cpu idle_cpu_tmt __initconst
= {
1534 .disable_promotion_to_c1e
= true,
1537 static const struct idle_cpu idle_cpu_snr __initconst
= {
1538 .state_table
= snr_cstates
,
1539 .disable_promotion_to_c1e
= true,
1543 static const struct idle_cpu idle_cpu_grr __initconst
= {
1544 .state_table
= grr_cstates
,
1545 .disable_promotion_to_c1e
= true,
1549 static const struct idle_cpu idle_cpu_srf __initconst
= {
1550 .state_table
= srf_cstates
,
1551 .disable_promotion_to_c1e
= true,
1555 static const struct x86_cpu_id intel_idle_ids
[] __initconst
= {
1556 X86_MATCH_VFM(INTEL_NEHALEM_EP
, &idle_cpu_nhx
),
1557 X86_MATCH_VFM(INTEL_NEHALEM
, &idle_cpu_nehalem
),
1558 X86_MATCH_VFM(INTEL_NEHALEM_G
, &idle_cpu_nehalem
),
1559 X86_MATCH_VFM(INTEL_WESTMERE
, &idle_cpu_nehalem
),
1560 X86_MATCH_VFM(INTEL_WESTMERE_EP
, &idle_cpu_nhx
),
1561 X86_MATCH_VFM(INTEL_NEHALEM_EX
, &idle_cpu_nhx
),
1562 X86_MATCH_VFM(INTEL_ATOM_BONNELL
, &idle_cpu_atom
),
1563 X86_MATCH_VFM(INTEL_ATOM_BONNELL_MID
, &idle_cpu_lincroft
),
1564 X86_MATCH_VFM(INTEL_WESTMERE_EX
, &idle_cpu_nhx
),
1565 X86_MATCH_VFM(INTEL_SANDYBRIDGE
, &idle_cpu_snb
),
1566 X86_MATCH_VFM(INTEL_SANDYBRIDGE_X
, &idle_cpu_snx
),
1567 X86_MATCH_VFM(INTEL_ATOM_SALTWELL
, &idle_cpu_atom
),
1568 X86_MATCH_VFM(INTEL_ATOM_SILVERMONT
, &idle_cpu_byt
),
1569 X86_MATCH_VFM(INTEL_ATOM_SILVERMONT_MID
, &idle_cpu_tangier
),
1570 X86_MATCH_VFM(INTEL_ATOM_AIRMONT
, &idle_cpu_cht
),
1571 X86_MATCH_VFM(INTEL_IVYBRIDGE
, &idle_cpu_ivb
),
1572 X86_MATCH_VFM(INTEL_IVYBRIDGE_X
, &idle_cpu_ivt
),
1573 X86_MATCH_VFM(INTEL_HASWELL
, &idle_cpu_hsw
),
1574 X86_MATCH_VFM(INTEL_HASWELL_X
, &idle_cpu_hsx
),
1575 X86_MATCH_VFM(INTEL_HASWELL_L
, &idle_cpu_hsw
),
1576 X86_MATCH_VFM(INTEL_HASWELL_G
, &idle_cpu_hsw
),
1577 X86_MATCH_VFM(INTEL_ATOM_SILVERMONT_D
, &idle_cpu_avn
),
1578 X86_MATCH_VFM(INTEL_BROADWELL
, &idle_cpu_bdw
),
1579 X86_MATCH_VFM(INTEL_BROADWELL_G
, &idle_cpu_bdw
),
1580 X86_MATCH_VFM(INTEL_BROADWELL_X
, &idle_cpu_bdx
),
1581 X86_MATCH_VFM(INTEL_BROADWELL_D
, &idle_cpu_bdx
),
1582 X86_MATCH_VFM(INTEL_SKYLAKE_L
, &idle_cpu_skl
),
1583 X86_MATCH_VFM(INTEL_SKYLAKE
, &idle_cpu_skl
),
1584 X86_MATCH_VFM(INTEL_KABYLAKE_L
, &idle_cpu_skl
),
1585 X86_MATCH_VFM(INTEL_KABYLAKE
, &idle_cpu_skl
),
1586 X86_MATCH_VFM(INTEL_SKYLAKE_X
, &idle_cpu_skx
),
1587 X86_MATCH_VFM(INTEL_ICELAKE_X
, &idle_cpu_icx
),
1588 X86_MATCH_VFM(INTEL_ICELAKE_D
, &idle_cpu_icx
),
1589 X86_MATCH_VFM(INTEL_ALDERLAKE
, &idle_cpu_adl
),
1590 X86_MATCH_VFM(INTEL_ALDERLAKE_L
, &idle_cpu_adl_l
),
1591 X86_MATCH_VFM(INTEL_METEORLAKE_L
, &idle_cpu_mtl_l
),
1592 X86_MATCH_VFM(INTEL_ATOM_GRACEMONT
, &idle_cpu_gmt
),
1593 X86_MATCH_VFM(INTEL_SAPPHIRERAPIDS_X
, &idle_cpu_spr
),
1594 X86_MATCH_VFM(INTEL_EMERALDRAPIDS_X
, &idle_cpu_spr
),
1595 X86_MATCH_VFM(INTEL_GRANITERAPIDS_X
, &idle_cpu_gnr
),
1596 X86_MATCH_VFM(INTEL_XEON_PHI_KNL
, &idle_cpu_knl
),
1597 X86_MATCH_VFM(INTEL_XEON_PHI_KNM
, &idle_cpu_knl
),
1598 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT
, &idle_cpu_bxt
),
1599 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_PLUS
, &idle_cpu_bxt
),
1600 X86_MATCH_VFM(INTEL_ATOM_GOLDMONT_D
, &idle_cpu_dnv
),
1601 X86_MATCH_VFM(INTEL_ATOM_TREMONT
, &idle_cpu_tmt
),
1602 X86_MATCH_VFM(INTEL_ATOM_TREMONT_L
, &idle_cpu_tmt
),
1603 X86_MATCH_VFM(INTEL_ATOM_TREMONT_D
, &idle_cpu_snr
),
1604 X86_MATCH_VFM(INTEL_ATOM_CRESTMONT
, &idle_cpu_grr
),
1605 X86_MATCH_VFM(INTEL_ATOM_CRESTMONT_X
, &idle_cpu_srf
),
1609 static const struct x86_cpu_id intel_mwait_ids
[] __initconst
= {
1610 X86_MATCH_VENDOR_FAM_FEATURE(INTEL
, 6, X86_FEATURE_MWAIT
, NULL
),
1614 static bool __init
intel_idle_max_cstate_reached(int cstate
)
1616 if (cstate
+ 1 > max_cstate
) {
1617 pr_info("max_cstate %d reached\n", max_cstate
);
1623 static bool __init
intel_idle_state_needs_timer_stop(struct cpuidle_state
*state
)
1625 unsigned long eax
= flg2MWAIT(state
->flags
);
1627 if (boot_cpu_has(X86_FEATURE_ARAT
))
1631 * Switch over to one-shot tick broadcast if the target C-state
1632 * is deeper than C1.
1634 return !!((eax
>> MWAIT_SUBSTATE_SIZE
) & MWAIT_CSTATE_MASK
);
1637 #ifdef CONFIG_ACPI_PROCESSOR_CSTATE
1638 #include <acpi/processor.h>
1640 static bool no_acpi __read_mostly
;
1641 module_param(no_acpi
, bool, 0444);
1642 MODULE_PARM_DESC(no_acpi
, "Do not use ACPI _CST for building the idle states list");
1644 static bool force_use_acpi __read_mostly
; /* No effect if no_acpi is set. */
1645 module_param_named(use_acpi
, force_use_acpi
, bool, 0444);
1646 MODULE_PARM_DESC(use_acpi
, "Use ACPI _CST for building the idle states list");
1648 static struct acpi_processor_power acpi_state_table __initdata
;
1651 * intel_idle_cst_usable - Check if the _CST information can be used.
1653 * Check if all of the C-states listed by _CST in the max_cstate range are
1654 * ACPI_CSTATE_FFH, which means that they should be entered via MWAIT.
1656 static bool __init
intel_idle_cst_usable(void)
1660 limit
= min_t(int, min_t(int, CPUIDLE_STATE_MAX
, max_cstate
+ 1),
1661 acpi_state_table
.count
);
1663 for (cstate
= 1; cstate
< limit
; cstate
++) {
1664 struct acpi_processor_cx
*cx
= &acpi_state_table
.states
[cstate
];
1666 if (cx
->entry_method
!= ACPI_CSTATE_FFH
)
1673 static bool __init
intel_idle_acpi_cst_extract(void)
1678 pr_debug("Not allowed to use ACPI _CST\n");
1682 for_each_possible_cpu(cpu
) {
1683 struct acpi_processor
*pr
= per_cpu(processors
, cpu
);
1688 if (acpi_processor_evaluate_cst(pr
->handle
, cpu
, &acpi_state_table
))
1691 acpi_state_table
.count
++;
1693 if (!intel_idle_cst_usable())
1696 if (!acpi_processor_claim_cst_control())
1702 acpi_state_table
.count
= 0;
1703 pr_debug("ACPI _CST not found or not usable\n");
1707 static void __init
intel_idle_init_cstates_acpi(struct cpuidle_driver
*drv
)
1709 int cstate
, limit
= min_t(int, CPUIDLE_STATE_MAX
, acpi_state_table
.count
);
1712 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1713 * the interesting states are ACPI_CSTATE_FFH.
1715 for (cstate
= 1; cstate
< limit
; cstate
++) {
1716 struct acpi_processor_cx
*cx
;
1717 struct cpuidle_state
*state
;
1719 if (intel_idle_max_cstate_reached(cstate
- 1))
1722 cx
= &acpi_state_table
.states
[cstate
];
1724 state
= &drv
->states
[drv
->state_count
++];
1726 snprintf(state
->name
, CPUIDLE_NAME_LEN
, "C%d_ACPI", cstate
);
1727 strscpy(state
->desc
, cx
->desc
, CPUIDLE_DESC_LEN
);
1728 state
->exit_latency
= cx
->latency
;
1730 * For C1-type C-states use the same number for both the exit
1731 * latency and target residency, because that is the case for
1732 * C1 in the majority of the static C-states tables above.
1733 * For the other types of C-states, however, set the target
1734 * residency to 3 times the exit latency which should lead to
1735 * a reasonable balance between energy-efficiency and
1736 * performance in the majority of interesting cases.
1738 state
->target_residency
= cx
->latency
;
1739 if (cx
->type
> ACPI_STATE_C1
)
1740 state
->target_residency
*= 3;
1742 state
->flags
= MWAIT2flg(cx
->address
);
1743 if (cx
->type
> ACPI_STATE_C2
)
1744 state
->flags
|= CPUIDLE_FLAG_TLB_FLUSHED
;
1746 if (disabled_states_mask
& BIT(cstate
))
1747 state
->flags
|= CPUIDLE_FLAG_OFF
;
1749 if (intel_idle_state_needs_timer_stop(state
))
1750 state
->flags
|= CPUIDLE_FLAG_TIMER_STOP
;
1752 state
->enter
= intel_idle
;
1753 state
->enter_s2idle
= intel_idle_s2idle
;
1757 static bool __init
intel_idle_off_by_default(unsigned int flags
, u32 mwait_hint
)
1762 * If there are no _CST C-states, do not disable any C-states by
1765 if (!acpi_state_table
.count
)
1768 limit
= min_t(int, CPUIDLE_STATE_MAX
, acpi_state_table
.count
);
1770 * If limit > 0, intel_idle_cst_usable() has returned 'true', so all of
1771 * the interesting states are ACPI_CSTATE_FFH.
1773 for (cstate
= 1; cstate
< limit
; cstate
++) {
1774 u32 acpi_hint
= acpi_state_table
.states
[cstate
].address
;
1775 u32 table_hint
= mwait_hint
;
1777 if (flags
& CPUIDLE_FLAG_PARTIAL_HINT_MATCH
) {
1778 acpi_hint
&= ~MWAIT_SUBSTATE_MASK
;
1779 table_hint
&= ~MWAIT_SUBSTATE_MASK
;
1782 if (acpi_hint
== table_hint
)
1787 #else /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1788 #define force_use_acpi (false)
1790 static inline bool intel_idle_acpi_cst_extract(void) { return false; }
1791 static inline void intel_idle_init_cstates_acpi(struct cpuidle_driver
*drv
) { }
1792 static inline bool intel_idle_off_by_default(unsigned int flags
, u32 mwait_hint
)
1796 #endif /* !CONFIG_ACPI_PROCESSOR_CSTATE */
1799 * ivt_idle_state_table_update - Tune the idle states table for Ivy Town.
1801 * Tune IVT multi-socket targets.
1802 * Assumption: num_sockets == (max_package_num + 1).
1804 static void __init
ivt_idle_state_table_update(void)
1806 /* IVT uses a different table for 1-2, 3-4, and > 4 sockets */
1807 int cpu
, package_num
, num_sockets
= 1;
1809 for_each_online_cpu(cpu
) {
1810 package_num
= topology_physical_package_id(cpu
);
1811 if (package_num
+ 1 > num_sockets
) {
1812 num_sockets
= package_num
+ 1;
1814 if (num_sockets
> 4) {
1815 cpuidle_state_table
= ivt_cstates_8s
;
1821 if (num_sockets
> 2)
1822 cpuidle_state_table
= ivt_cstates_4s
;
1824 /* else, 1 and 2 socket systems use default ivt_cstates */
1828 * irtl_2_usec - IRTL to microseconds conversion.
1829 * @irtl: IRTL MSR value.
1831 * Translate the IRTL (Interrupt Response Time Limit) MSR value to microseconds.
1833 static unsigned long long __init
irtl_2_usec(unsigned long long irtl
)
1835 static const unsigned int irtl_ns_units
[] __initconst
= {
1836 1, 32, 1024, 32768, 1048576, 33554432, 0, 0
1838 unsigned long long ns
;
1843 ns
= irtl_ns_units
[(irtl
>> 10) & 0x7];
1845 return div_u64((irtl
& 0x3FF) * ns
, NSEC_PER_USEC
);
1849 * bxt_idle_state_table_update - Fix up the Broxton idle states table.
1851 * On BXT, trust the IRTL (Interrupt Response Time Limit) MSR to show the
1852 * definitive maximum latency and use the same value for target_residency.
1854 static void __init
bxt_idle_state_table_update(void)
1856 unsigned long long msr
;
1859 rdmsrl(MSR_PKGC6_IRTL
, msr
);
1860 usec
= irtl_2_usec(msr
);
1862 bxt_cstates
[2].exit_latency
= usec
;
1863 bxt_cstates
[2].target_residency
= usec
;
1866 rdmsrl(MSR_PKGC7_IRTL
, msr
);
1867 usec
= irtl_2_usec(msr
);
1869 bxt_cstates
[3].exit_latency
= usec
;
1870 bxt_cstates
[3].target_residency
= usec
;
1873 rdmsrl(MSR_PKGC8_IRTL
, msr
);
1874 usec
= irtl_2_usec(msr
);
1876 bxt_cstates
[4].exit_latency
= usec
;
1877 bxt_cstates
[4].target_residency
= usec
;
1880 rdmsrl(MSR_PKGC9_IRTL
, msr
);
1881 usec
= irtl_2_usec(msr
);
1883 bxt_cstates
[5].exit_latency
= usec
;
1884 bxt_cstates
[5].target_residency
= usec
;
1887 rdmsrl(MSR_PKGC10_IRTL
, msr
);
1888 usec
= irtl_2_usec(msr
);
1890 bxt_cstates
[6].exit_latency
= usec
;
1891 bxt_cstates
[6].target_residency
= usec
;
1897 * sklh_idle_state_table_update - Fix up the Sky Lake idle states table.
1899 * On SKL-H (model 0x5e) skip C8 and C9 if C10 is enabled and SGX disabled.
1901 static void __init
sklh_idle_state_table_update(void)
1903 unsigned long long msr
;
1904 unsigned int eax
, ebx
, ecx
, edx
;
1907 /* if PC10 disabled via cmdline intel_idle.max_cstate=7 or shallower */
1908 if (max_cstate
<= 7)
1911 /* if PC10 not present in CPUID.MWAIT.EDX */
1912 if ((mwait_substates
& (0xF << 28)) == 0)
1915 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL
, msr
);
1917 /* PC10 is not enabled in PKG C-state limit */
1918 if ((msr
& 0xF) != 8)
1922 cpuid(7, &eax
, &ebx
, &ecx
, &edx
);
1924 /* if SGX is present */
1925 if (ebx
& (1 << 2)) {
1927 rdmsrl(MSR_IA32_FEAT_CTL
, msr
);
1929 /* if SGX is enabled */
1930 if (msr
& (1 << 18))
1934 skl_cstates
[5].flags
|= CPUIDLE_FLAG_UNUSABLE
; /* C8-SKL */
1935 skl_cstates
[6].flags
|= CPUIDLE_FLAG_UNUSABLE
; /* C9-SKL */
1939 * skx_idle_state_table_update - Adjust the Sky Lake/Cascade Lake
1940 * idle states table.
1942 static void __init
skx_idle_state_table_update(void)
1944 unsigned long long msr
;
1946 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL
, msr
);
1949 * 000b: C0/C1 (no package C-state support)
1951 * 010b: C6 (non-retention)
1952 * 011b: C6 (retention)
1953 * 111b: No Package C state limits.
1955 if ((msr
& 0x7) < 2) {
1957 * Uses the CC6 + PC0 latency and 3 times of
1958 * latency for target_residency if the PC6
1959 * is disabled in BIOS. This is consistent
1960 * with how intel_idle driver uses _CST
1961 * to set the target_residency.
1963 skx_cstates
[2].exit_latency
= 92;
1964 skx_cstates
[2].target_residency
= 276;
1969 * adl_idle_state_table_update - Adjust AlderLake idle states table.
1971 static void __init
adl_idle_state_table_update(void)
1973 /* Check if user prefers C1 over C1E. */
1974 if (preferred_states_mask
& BIT(1) && !(preferred_states_mask
& BIT(2))) {
1975 cpuidle_state_table
[0].flags
&= ~CPUIDLE_FLAG_UNUSABLE
;
1976 cpuidle_state_table
[1].flags
|= CPUIDLE_FLAG_UNUSABLE
;
1978 /* Disable C1E by clearing the "C1E promotion" bit. */
1979 c1e_promotion
= C1E_PROMOTION_DISABLE
;
1983 /* Make sure C1E is enabled by default */
1984 c1e_promotion
= C1E_PROMOTION_ENABLE
;
1988 * spr_idle_state_table_update - Adjust Sapphire Rapids idle states table.
1990 static void __init
spr_idle_state_table_update(void)
1992 unsigned long long msr
;
1995 * By default, the C6 state assumes the worst-case scenario of package
1996 * C6. However, if PC6 is disabled, we update the numbers to match
1999 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL
, msr
);
2001 /* Limit value 2 and above allow for PC6. */
2002 if ((msr
& 0x7) < 2) {
2003 spr_cstates
[2].exit_latency
= 190;
2004 spr_cstates
[2].target_residency
= 600;
2008 static bool __init
intel_idle_verify_cstate(unsigned int mwait_hint
)
2010 unsigned int mwait_cstate
= (MWAIT_HINT2CSTATE(mwait_hint
) + 1) &
2012 unsigned int num_substates
= (mwait_substates
>> mwait_cstate
* 4) &
2013 MWAIT_SUBSTATE_MASK
;
2015 /* Ignore the C-state if there are NO sub-states in CPUID for it. */
2016 if (num_substates
== 0)
2019 if (mwait_cstate
> 2 && !boot_cpu_has(X86_FEATURE_NONSTOP_TSC
))
2020 mark_tsc_unstable("TSC halts in idle states deeper than C2");
2025 static void state_update_enter_method(struct cpuidle_state
*state
, int cstate
)
2027 if (state
->flags
& CPUIDLE_FLAG_INIT_XSTATE
) {
2029 * Combining with XSTATE with IBRS or IRQ_ENABLE flags
2030 * is not currently supported but this driver.
2032 WARN_ON_ONCE(state
->flags
& CPUIDLE_FLAG_IBRS
);
2033 WARN_ON_ONCE(state
->flags
& CPUIDLE_FLAG_IRQ_ENABLE
);
2034 state
->enter
= intel_idle_xstate
;
2038 if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS
) &&
2039 ((state
->flags
& CPUIDLE_FLAG_IBRS
) || ibrs_off
)) {
2041 * IBRS mitigation requires that C-states are entered
2042 * with interrupts disabled.
2044 if (ibrs_off
&& (state
->flags
& CPUIDLE_FLAG_IRQ_ENABLE
))
2045 state
->flags
&= ~CPUIDLE_FLAG_IRQ_ENABLE
;
2046 WARN_ON_ONCE(state
->flags
& CPUIDLE_FLAG_IRQ_ENABLE
);
2047 state
->enter
= intel_idle_ibrs
;
2051 if (state
->flags
& CPUIDLE_FLAG_IRQ_ENABLE
) {
2052 state
->enter
= intel_idle_irq
;
2057 pr_info("forced intel_idle_irq for state %d\n", cstate
);
2058 state
->enter
= intel_idle_irq
;
2062 static void __init
intel_idle_init_cstates_icpu(struct cpuidle_driver
*drv
)
2066 switch (boot_cpu_data
.x86_vfm
) {
2067 case INTEL_IVYBRIDGE_X
:
2068 ivt_idle_state_table_update();
2070 case INTEL_ATOM_GOLDMONT
:
2071 case INTEL_ATOM_GOLDMONT_PLUS
:
2072 bxt_idle_state_table_update();
2075 sklh_idle_state_table_update();
2077 case INTEL_SKYLAKE_X
:
2078 skx_idle_state_table_update();
2080 case INTEL_SAPPHIRERAPIDS_X
:
2081 case INTEL_EMERALDRAPIDS_X
:
2082 spr_idle_state_table_update();
2084 case INTEL_ALDERLAKE
:
2085 case INTEL_ALDERLAKE_L
:
2086 case INTEL_ATOM_GRACEMONT
:
2087 adl_idle_state_table_update();
2091 for (cstate
= 0; cstate
< CPUIDLE_STATE_MAX
; ++cstate
) {
2092 struct cpuidle_state
*state
;
2093 unsigned int mwait_hint
;
2095 if (intel_idle_max_cstate_reached(cstate
))
2098 if (!cpuidle_state_table
[cstate
].enter
&&
2099 !cpuidle_state_table
[cstate
].enter_s2idle
)
2102 /* If marked as unusable, skip this state. */
2103 if (cpuidle_state_table
[cstate
].flags
& CPUIDLE_FLAG_UNUSABLE
) {
2104 pr_debug("state %s is disabled\n",
2105 cpuidle_state_table
[cstate
].name
);
2109 mwait_hint
= flg2MWAIT(cpuidle_state_table
[cstate
].flags
);
2110 if (!intel_idle_verify_cstate(mwait_hint
))
2113 /* Structure copy. */
2114 drv
->states
[drv
->state_count
] = cpuidle_state_table
[cstate
];
2115 state
= &drv
->states
[drv
->state_count
];
2117 state_update_enter_method(state
, cstate
);
2120 if ((disabled_states_mask
& BIT(drv
->state_count
)) ||
2121 ((icpu
->use_acpi
|| force_use_acpi
) &&
2122 intel_idle_off_by_default(state
->flags
, mwait_hint
) &&
2123 !(state
->flags
& CPUIDLE_FLAG_ALWAYS_ENABLE
)))
2124 state
->flags
|= CPUIDLE_FLAG_OFF
;
2126 if (intel_idle_state_needs_timer_stop(state
))
2127 state
->flags
|= CPUIDLE_FLAG_TIMER_STOP
;
2132 if (icpu
->byt_auto_demotion_disable_flag
) {
2133 wrmsrl(MSR_CC6_DEMOTION_POLICY_CONFIG
, 0);
2134 wrmsrl(MSR_MC6_DEMOTION_POLICY_CONFIG
, 0);
2139 * intel_idle_cpuidle_driver_init - Create the list of available idle states.
2140 * @drv: cpuidle driver structure to initialize.
2142 static void __init
intel_idle_cpuidle_driver_init(struct cpuidle_driver
*drv
)
2144 cpuidle_poll_state_init(drv
);
2146 if (disabled_states_mask
& BIT(0))
2147 drv
->states
[0].flags
|= CPUIDLE_FLAG_OFF
;
2149 drv
->state_count
= 1;
2151 if (icpu
&& icpu
->state_table
)
2152 intel_idle_init_cstates_icpu(drv
);
2154 intel_idle_init_cstates_acpi(drv
);
2157 static void auto_demotion_disable(void)
2159 unsigned long long msr_bits
;
2161 rdmsrl(MSR_PKG_CST_CONFIG_CONTROL
, msr_bits
);
2162 msr_bits
&= ~auto_demotion_disable_flags
;
2163 wrmsrl(MSR_PKG_CST_CONFIG_CONTROL
, msr_bits
);
2166 static void c1e_promotion_enable(void)
2168 unsigned long long msr_bits
;
2170 rdmsrl(MSR_IA32_POWER_CTL
, msr_bits
);
2172 wrmsrl(MSR_IA32_POWER_CTL
, msr_bits
);
2175 static void c1e_promotion_disable(void)
2177 unsigned long long msr_bits
;
2179 rdmsrl(MSR_IA32_POWER_CTL
, msr_bits
);
2181 wrmsrl(MSR_IA32_POWER_CTL
, msr_bits
);
2185 * intel_idle_cpu_init - Register the target CPU with the cpuidle core.
2186 * @cpu: CPU to initialize.
2188 * Register a cpuidle device object for @cpu and update its MSRs in accordance
2189 * with the processor model flags.
2191 static int intel_idle_cpu_init(unsigned int cpu
)
2193 struct cpuidle_device
*dev
;
2195 dev
= per_cpu_ptr(intel_idle_cpuidle_devices
, cpu
);
2198 if (cpuidle_register_device(dev
)) {
2199 pr_debug("cpuidle_register_device %d failed!\n", cpu
);
2203 if (auto_demotion_disable_flags
)
2204 auto_demotion_disable();
2206 if (c1e_promotion
== C1E_PROMOTION_ENABLE
)
2207 c1e_promotion_enable();
2208 else if (c1e_promotion
== C1E_PROMOTION_DISABLE
)
2209 c1e_promotion_disable();
2214 static int intel_idle_cpu_online(unsigned int cpu
)
2216 struct cpuidle_device
*dev
;
2218 if (!boot_cpu_has(X86_FEATURE_ARAT
))
2219 tick_broadcast_enable();
2222 * Some systems can hotplug a cpu at runtime after
2223 * the kernel has booted, we have to initialize the
2224 * driver in this case
2226 dev
= per_cpu_ptr(intel_idle_cpuidle_devices
, cpu
);
2227 if (!dev
->registered
)
2228 return intel_idle_cpu_init(cpu
);
2234 * intel_idle_cpuidle_devices_uninit - Unregister all cpuidle devices.
2236 static void __init
intel_idle_cpuidle_devices_uninit(void)
2240 for_each_online_cpu(i
)
2241 cpuidle_unregister_device(per_cpu_ptr(intel_idle_cpuidle_devices
, i
));
2244 static int __init
intel_idle_init(void)
2246 const struct x86_cpu_id
*id
;
2247 unsigned int eax
, ebx
, ecx
;
2250 /* Do not load intel_idle at all for now if idle= is passed */
2251 if (boot_option_idle_override
!= IDLE_NO_OVERRIDE
)
2254 if (max_cstate
== 0) {
2255 pr_debug("disabled\n");
2259 id
= x86_match_cpu(intel_idle_ids
);
2261 if (!boot_cpu_has(X86_FEATURE_MWAIT
)) {
2262 pr_debug("Please enable MWAIT in BIOS SETUP\n");
2266 id
= x86_match_cpu(intel_mwait_ids
);
2271 if (boot_cpu_data
.cpuid_level
< CPUID_MWAIT_LEAF
)
2274 cpuid(CPUID_MWAIT_LEAF
, &eax
, &ebx
, &ecx
, &mwait_substates
);
2276 if (!(ecx
& CPUID5_ECX_EXTENSIONS_SUPPORTED
) ||
2277 !(ecx
& CPUID5_ECX_INTERRUPT_BREAK
) ||
2281 pr_debug("MWAIT substates: 0x%x\n", mwait_substates
);
2283 icpu
= (const struct idle_cpu
*)id
->driver_data
;
2285 if (icpu
->state_table
)
2286 cpuidle_state_table
= icpu
->state_table
;
2287 else if (!intel_idle_acpi_cst_extract())
2290 auto_demotion_disable_flags
= icpu
->auto_demotion_disable_flags
;
2291 if (icpu
->disable_promotion_to_c1e
)
2292 c1e_promotion
= C1E_PROMOTION_DISABLE
;
2293 if (icpu
->use_acpi
|| force_use_acpi
)
2294 intel_idle_acpi_cst_extract();
2295 } else if (!intel_idle_acpi_cst_extract()) {
2299 pr_debug("v" INTEL_IDLE_VERSION
" model 0x%X\n",
2300 boot_cpu_data
.x86_model
);
2302 intel_idle_cpuidle_devices
= alloc_percpu(struct cpuidle_device
);
2303 if (!intel_idle_cpuidle_devices
)
2306 intel_idle_cpuidle_driver_init(&intel_idle_driver
);
2308 retval
= cpuidle_register_driver(&intel_idle_driver
);
2310 struct cpuidle_driver
*drv
= cpuidle_get_driver();
2311 printk(KERN_DEBUG
pr_fmt("intel_idle yielding to %s\n"),
2312 drv
? drv
->name
: "none");
2313 goto init_driver_fail
;
2316 retval
= cpuhp_setup_state(CPUHP_AP_ONLINE_DYN
, "idle/intel:online",
2317 intel_idle_cpu_online
, NULL
);
2321 pr_debug("Local APIC timer is reliable in %s\n",
2322 boot_cpu_has(X86_FEATURE_ARAT
) ? "all C-states" : "C1");
2327 intel_idle_cpuidle_devices_uninit();
2328 cpuidle_unregister_driver(&intel_idle_driver
);
2330 free_percpu(intel_idle_cpuidle_devices
);
2334 device_initcall(intel_idle_init
);
2337 * We are not really modular, but we used to support that. Meaning we also
2338 * support "intel_idle.max_cstate=..." at boot and also a read-only export of
2339 * it at /sys/module/intel_idle/parameters/max_cstate -- so using module_param
2340 * is the easiest way (currently) to continue doing that.
2342 module_param(max_cstate
, int, 0444);
2344 * The positions of the bits that are set in this number are the indices of the
2345 * idle states to be disabled by default (as reflected by the names of the
2346 * corresponding idle state directories in sysfs, "state0", "state1" ...
2347 * "state<i>" ..., where <i> is the index of the given state).
2349 module_param_named(states_off
, disabled_states_mask
, uint
, 0444);
2350 MODULE_PARM_DESC(states_off
, "Mask of disabled idle states");
2352 * Some platforms come with mutually exclusive C-states, so that if one is
2353 * enabled, the other C-states must not be used. Example: C1 and C1E on
2354 * Sapphire Rapids platform. This parameter allows for selecting the
2355 * preferred C-states among the groups of mutually exclusive C-states - the
2356 * selected C-states will be registered, the other C-states from the mutually
2357 * exclusive group won't be registered. If the platform has no mutually
2358 * exclusive C-states, this parameter has no effect.
2360 module_param_named(preferred_cstates
, preferred_states_mask
, uint
, 0444);
2361 MODULE_PARM_DESC(preferred_cstates
, "Mask of preferred idle states");
2363 * Debugging option that forces the driver to enter all C-states with
2364 * interrupts enabled. Does not apply to C-states with
2365 * 'CPUIDLE_FLAG_INIT_XSTATE' and 'CPUIDLE_FLAG_IBRS' flags.
2367 module_param(force_irq_on
, bool, 0444);
2369 * Force the disabling of IBRS when X86_FEATURE_KERNEL_IBRS is on and
2370 * CPUIDLE_FLAG_IRQ_ENABLE isn't set.
2372 module_param(ibrs_off
, bool, 0444);
2373 MODULE_PARM_DESC(ibrs_off
, "Disable IBRS when idle");