2 * Copyright (C) 2005 Intel Corporation
3 * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
4 * - Added _PDC for SMP C-states on Intel CPUs
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/init.h>
10 #include <linux/acpi.h>
11 #include <linux/cpu.h>
12 #include <linux/sched.h>
14 #include <acpi/processor.h>
16 #include <asm/mwait.h>
19 * Initialize bm_flags based on the CPU cache properties
20 * On SMP it depends on cache configuration
21 * - When cache is not shared among all CPUs, we flush cache
23 * - When cache is shared among all CPUs, we use bm_check
24 * mechanism as in UP case
26 * This routine is called only after all the CPUs are online
28 void acpi_processor_power_init_bm_check(struct acpi_processor_flags
*flags
,
31 struct cpuinfo_x86
*c
= &cpu_data(cpu
);
34 if (num_online_cpus() == 1)
36 else if (c
->x86_vendor
== X86_VENDOR_INTEL
) {
38 * Today all MP CPUs that support C3 share cache.
39 * And caches should not be flushed by software while
40 * entering C3 type state.
46 * On all recent Intel platforms, ARB_DISABLE is a nop.
47 * So, set bm_control to zero to indicate that ARB_DISABLE
48 * is not required while entering C3 type state on
49 * P4, Core and beyond CPUs
51 if (c
->x86_vendor
== X86_VENDOR_INTEL
&&
52 (c
->x86
> 0xf || (c
->x86
== 6 && c
->x86_model
>= 0x0f)))
53 flags
->bm_control
= 0;
55 EXPORT_SYMBOL(acpi_processor_power_init_bm_check
);
57 /* The code below handles cstate entry with monitor-mwait pair on Intel*/
63 } states
[ACPI_PROCESSOR_MAX_POWER
];
65 static struct cstate_entry __percpu
*cpu_cstate_entry
; /* per CPU ptr */
67 static short mwait_supported
[ACPI_PROCESSOR_MAX_POWER
];
69 #define NATIVE_CSTATE_BEYOND_HALT (2)
71 static long acpi_processor_ffh_cstate_probe_cpu(void *_cx
)
73 struct acpi_processor_cx
*cx
= _cx
;
75 unsigned int eax
, ebx
, ecx
, edx
;
76 unsigned int edx_part
;
77 unsigned int cstate_type
; /* C-state type and not ACPI C-state type */
78 unsigned int num_cstate_subtype
;
80 cpuid(CPUID_MWAIT_LEAF
, &eax
, &ebx
, &ecx
, &edx
);
82 /* Check whether this particular cx_type (in CST) is supported or not */
83 cstate_type
= ((cx
->address
>> MWAIT_SUBSTATE_SIZE
) &
84 MWAIT_CSTATE_MASK
) + 1;
85 edx_part
= edx
>> (cstate_type
* MWAIT_SUBSTATE_SIZE
);
86 num_cstate_subtype
= edx_part
& MWAIT_SUBSTATE_MASK
;
89 if (num_cstate_subtype
< (cx
->address
& MWAIT_SUBSTATE_MASK
)) {
94 /* mwait ecx extensions INTERRUPT_BREAK should be supported for C2/C3 */
95 if (!(ecx
& CPUID5_ECX_EXTENSIONS_SUPPORTED
) ||
96 !(ecx
& CPUID5_ECX_INTERRUPT_BREAK
)) {
101 if (!mwait_supported
[cstate_type
]) {
102 mwait_supported
[cstate_type
] = 1;
104 "Monitor-Mwait will be used to enter C-%d "
105 "state\n", cx
->type
);
108 ACPI_CX_DESC_LEN
, "ACPI FFH INTEL MWAIT 0x%x",
114 int acpi_processor_ffh_cstate_probe(unsigned int cpu
,
115 struct acpi_processor_cx
*cx
, struct acpi_power_register
*reg
)
117 struct cstate_entry
*percpu_entry
;
118 struct cpuinfo_x86
*c
= &cpu_data(cpu
);
121 if (!cpu_cstate_entry
|| c
->cpuid_level
< CPUID_MWAIT_LEAF
)
124 if (reg
->bit_offset
!= NATIVE_CSTATE_BEYOND_HALT
)
127 percpu_entry
= per_cpu_ptr(cpu_cstate_entry
, cpu
);
128 percpu_entry
->states
[cx
->index
].eax
= 0;
129 percpu_entry
->states
[cx
->index
].ecx
= 0;
131 /* Make sure we are running on right CPU */
133 retval
= work_on_cpu(cpu
, acpi_processor_ffh_cstate_probe_cpu
, cx
);
135 /* Use the hint in CST */
136 percpu_entry
->states
[cx
->index
].eax
= cx
->address
;
137 percpu_entry
->states
[cx
->index
].ecx
= MWAIT_ECX_INTERRUPT_BREAK
;
141 * For _CST FFH on Intel, if GAS.access_size bit 1 is cleared,
142 * then we should skip checking BM_STS for this C-state.
143 * ref: "Intel Processor Vendor-Specific ACPI Interface Specification"
145 if ((c
->x86_vendor
== X86_VENDOR_INTEL
) && !(reg
->access_size
& 0x2))
150 EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_probe
);
153 * This uses new MONITOR/MWAIT instructions on P4 processors with PNI,
154 * which can obviate IPI to trigger checking of need_resched.
155 * We execute MONITOR against need_resched and enter optimized wait state
156 * through MWAIT. Whenever someone changes need_resched, we would be woken
157 * up from MWAIT (without an IPI).
159 * New with Core Duo processors, MWAIT can take some hints based on CPU
162 void mwait_idle_with_hints(unsigned long ax
, unsigned long cx
)
164 if (!need_resched()) {
165 if (this_cpu_has(X86_FEATURE_CLFLUSH_MONITOR
))
166 clflush((void *)¤t_thread_info()->flags
);
168 __monitor((void *)¤t_thread_info()->flags
, 0, 0);
175 void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx
*cx
)
177 unsigned int cpu
= smp_processor_id();
178 struct cstate_entry
*percpu_entry
;
180 percpu_entry
= per_cpu_ptr(cpu_cstate_entry
, cpu
);
181 mwait_idle_with_hints(percpu_entry
->states
[cx
->index
].eax
,
182 percpu_entry
->states
[cx
->index
].ecx
);
184 EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_enter
);
186 static int __init
ffh_cstate_init(void)
188 struct cpuinfo_x86
*c
= &boot_cpu_data
;
189 if (c
->x86_vendor
!= X86_VENDOR_INTEL
)
192 cpu_cstate_entry
= alloc_percpu(struct cstate_entry
);
196 static void __exit
ffh_cstate_exit(void)
198 free_percpu(cpu_cstate_entry
);
199 cpu_cstate_entry
= NULL
;
202 arch_initcall(ffh_cstate_init
);
203 __exitcall(ffh_cstate_exit
);