2 * Copyright (C) 2005 Intel Corporation
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>
17 #include <asm/special_insns.h>
20 * Initialize bm_flags based on the CPU cache properties
21 * On SMP it depends on cache configuration
22 * - When cache is not shared among all CPUs, we flush cache
24 * - When cache is shared among all CPUs, we use bm_check
25 * mechanism as in UP case
27 * This routine is called only after all the CPUs are online
29 void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
32 struct cpuinfo_x86 *c = &cpu_data(cpu);
35 if (num_online_cpus() == 1)
37 else if (c->x86_vendor == X86_VENDOR_INTEL) {
39 * Today all MP CPUs that support C3 share cache.
40 * And caches should not be flushed by software while
41 * entering C3 type state.
47 * On all recent Intel platforms, ARB_DISABLE is a nop.
48 * So, set bm_control to zero to indicate that ARB_DISABLE
49 * is not required while entering C3 type state on
50 * P4, Core and beyond CPUs
52 if (c->x86_vendor == X86_VENDOR_INTEL &&
53 (c->x86 > 0xf || (c->x86 == 6 && c->x86_model >= 0x0f)))
54 flags->bm_control = 0;
56 EXPORT_SYMBOL(acpi_processor_power_init_bm_check);
58 /* The code below handles cstate entry with monitor-mwait pair on Intel*/
64 } states[ACPI_PROCESSOR_MAX_POWER];
66 static struct cstate_entry __percpu *cpu_cstate_entry; /* per CPU ptr */
68 static short mwait_supported[ACPI_PROCESSOR_MAX_POWER];
70 #define NATIVE_CSTATE_BEYOND_HALT (2)
72 static long acpi_processor_ffh_cstate_probe_cpu(void *_cx)
74 struct acpi_processor_cx *cx = _cx;
76 unsigned int eax, ebx, ecx, edx;
77 unsigned int edx_part;
78 unsigned int cstate_type; /* C-state type and not ACPI C-state type */
79 unsigned int num_cstate_subtype;
81 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx);
83 /* Check whether this particular cx_type (in CST) is supported or not */
84 cstate_type = ((cx->address >> MWAIT_SUBSTATE_SIZE) &
85 MWAIT_CSTATE_MASK) + 1;
86 edx_part = edx >> (cstate_type * MWAIT_SUBSTATE_SIZE);
87 num_cstate_subtype = edx_part & MWAIT_SUBSTATE_MASK;
90 if (num_cstate_subtype < (cx->address & MWAIT_SUBSTATE_MASK)) {
95 /* mwait ecx extensions INTERRUPT_BREAK should be supported for C2/C3 */
96 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
97 !(ecx & CPUID5_ECX_INTERRUPT_BREAK)) {
102 if (!mwait_supported[cstate_type]) {
103 mwait_supported[cstate_type] = 1;
105 "Monitor-Mwait will be used to enter C-%d "
106 "state\n", cx->type);
109 ACPI_CX_DESC_LEN, "ACPI FFH INTEL MWAIT 0x%x",
115 int acpi_processor_ffh_cstate_probe(unsigned int cpu,
116 struct acpi_processor_cx *cx, struct acpi_power_register *reg)
118 struct cstate_entry *percpu_entry;
119 struct cpuinfo_x86 *c = &cpu_data(cpu);
122 if (!cpu_cstate_entry || c->cpuid_level < CPUID_MWAIT_LEAF)
125 if (reg->bit_offset != NATIVE_CSTATE_BEYOND_HALT)
128 percpu_entry = per_cpu_ptr(cpu_cstate_entry, cpu);
129 percpu_entry->states[cx->index].eax = 0;
130 percpu_entry->states[cx->index].ecx = 0;
132 /* Make sure we are running on right CPU */
134 retval = work_on_cpu(cpu, acpi_processor_ffh_cstate_probe_cpu, cx);
136 /* Use the hint in CST */
137 percpu_entry->states[cx->index].eax = cx->address;
138 percpu_entry->states[cx->index].ecx = MWAIT_ECX_INTERRUPT_BREAK;
142 * For _CST FFH on Intel, if GAS.access_size bit 1 is cleared,
143 * then we should skip checking BM_STS for this C-state.
144 * ref: "Intel Processor Vendor-Specific ACPI Interface Specification"
146 if ((c->x86_vendor == X86_VENDOR_INTEL) && !(reg->access_size & 0x2))
151 EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_probe);
153 void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cx)
155 unsigned int cpu = smp_processor_id();
156 struct cstate_entry *percpu_entry;
158 percpu_entry = per_cpu_ptr(cpu_cstate_entry, cpu);
159 mwait_idle_with_hints(percpu_entry->states[cx->index].eax,
160 percpu_entry->states[cx->index].ecx);
162 EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_enter);
164 static int __init ffh_cstate_init(void)
166 struct cpuinfo_x86 *c = &boot_cpu_data;
167 if (c->x86_vendor != X86_VENDOR_INTEL)
170 cpu_cstate_entry = alloc_percpu(struct cstate_entry);
174 static void __exit ffh_cstate_exit(void)
176 free_percpu(cpu_cstate_entry);
177 cpu_cstate_entry = NULL;
180 arch_initcall(ffh_cstate_init);
181 __exitcall(ffh_cstate_exit);