This source file includes following definitions.
- acpi_processor_power_init_bm_check
- acpi_processor_ffh_cstate_probe_cpu
- acpi_processor_ffh_cstate_probe
- acpi_processor_ffh_cstate_enter
- ffh_cstate_init
- ffh_cstate_exit
1
2
3
4
5
6
7
8 #include <linux/kernel.h>
9 #include <linux/export.h>
10 #include <linux/init.h>
11 #include <linux/acpi.h>
12 #include <linux/cpu.h>
13 #include <linux/sched.h>
14
15 #include <acpi/processor.h>
16 #include <asm/mwait.h>
17 #include <asm/special_insns.h>
18
19
20
21
22
23
24
25
26
27
28
29 void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
30 unsigned int cpu)
31 {
32 struct cpuinfo_x86 *c = &cpu_data(cpu);
33
34 flags->bm_check = 0;
35 if (num_online_cpus() == 1)
36 flags->bm_check = 1;
37 else if (c->x86_vendor == X86_VENDOR_INTEL) {
38
39
40
41
42
43 flags->bm_check = 1;
44 }
45
46
47
48
49
50
51
52 if (c->x86_vendor == X86_VENDOR_INTEL &&
53 (c->x86 > 0xf || (c->x86 == 6 && c->x86_model >= 0x0f)))
54 flags->bm_control = 0;
55
56
57
58
59
60
61
62 if (c->x86_vendor == X86_VENDOR_CENTAUR) {
63 if (c->x86 > 6 || (c->x86 == 6 && c->x86_model == 0x0f &&
64 c->x86_stepping >= 0x0e))
65 flags->bm_check = 1;
66 }
67
68 if (c->x86_vendor == X86_VENDOR_ZHAOXIN) {
69
70
71
72
73
74 flags->bm_check = 1;
75
76
77
78
79
80 flags->bm_control = 0;
81 }
82 }
83 EXPORT_SYMBOL(acpi_processor_power_init_bm_check);
84
85
86
87 struct cstate_entry {
88 struct {
89 unsigned int eax;
90 unsigned int ecx;
91 } states[ACPI_PROCESSOR_MAX_POWER];
92 };
93 static struct cstate_entry __percpu *cpu_cstate_entry;
94
95 static short mwait_supported[ACPI_PROCESSOR_MAX_POWER];
96
97 #define NATIVE_CSTATE_BEYOND_HALT (2)
98
99 static long acpi_processor_ffh_cstate_probe_cpu(void *_cx)
100 {
101 struct acpi_processor_cx *cx = _cx;
102 long retval;
103 unsigned int eax, ebx, ecx, edx;
104 unsigned int edx_part;
105 unsigned int cstate_type;
106 unsigned int num_cstate_subtype;
107
108 cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx);
109
110
111 cstate_type = ((cx->address >> MWAIT_SUBSTATE_SIZE) &
112 MWAIT_CSTATE_MASK) + 1;
113 edx_part = edx >> (cstate_type * MWAIT_SUBSTATE_SIZE);
114 num_cstate_subtype = edx_part & MWAIT_SUBSTATE_MASK;
115
116 retval = 0;
117
118 if (num_cstate_subtype == 0) {
119 pr_warn(FW_BUG "ACPI MWAIT C-state 0x%x not supported by HW (0x%x)\n",
120 cx->address, edx_part);
121 retval = -1;
122 goto out;
123 }
124
125
126 if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
127 !(ecx & CPUID5_ECX_INTERRUPT_BREAK)) {
128 retval = -1;
129 goto out;
130 }
131
132 if (!mwait_supported[cstate_type]) {
133 mwait_supported[cstate_type] = 1;
134 printk(KERN_DEBUG
135 "Monitor-Mwait will be used to enter C-%d state\n",
136 cx->type);
137 }
138 snprintf(cx->desc,
139 ACPI_CX_DESC_LEN, "ACPI FFH MWAIT 0x%x",
140 cx->address);
141 out:
142 return retval;
143 }
144
145 int acpi_processor_ffh_cstate_probe(unsigned int cpu,
146 struct acpi_processor_cx *cx, struct acpi_power_register *reg)
147 {
148 struct cstate_entry *percpu_entry;
149 struct cpuinfo_x86 *c = &cpu_data(cpu);
150 long retval;
151
152 if (!cpu_cstate_entry || c->cpuid_level < CPUID_MWAIT_LEAF)
153 return -1;
154
155 if (reg->bit_offset != NATIVE_CSTATE_BEYOND_HALT)
156 return -1;
157
158 percpu_entry = per_cpu_ptr(cpu_cstate_entry, cpu);
159 percpu_entry->states[cx->index].eax = 0;
160 percpu_entry->states[cx->index].ecx = 0;
161
162
163
164 retval = call_on_cpu(cpu, acpi_processor_ffh_cstate_probe_cpu, cx,
165 false);
166 if (retval == 0) {
167
168 percpu_entry->states[cx->index].eax = cx->address;
169 percpu_entry->states[cx->index].ecx = MWAIT_ECX_INTERRUPT_BREAK;
170 }
171
172
173
174
175
176
177 if ((c->x86_vendor == X86_VENDOR_INTEL) && !(reg->access_size & 0x2))
178 cx->bm_sts_skip = 1;
179
180 return retval;
181 }
182 EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_probe);
183
184 void __cpuidle acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cx)
185 {
186 unsigned int cpu = smp_processor_id();
187 struct cstate_entry *percpu_entry;
188
189 percpu_entry = per_cpu_ptr(cpu_cstate_entry, cpu);
190 mwait_idle_with_hints(percpu_entry->states[cx->index].eax,
191 percpu_entry->states[cx->index].ecx);
192 }
193 EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_enter);
194
195 static int __init ffh_cstate_init(void)
196 {
197 struct cpuinfo_x86 *c = &boot_cpu_data;
198
199 if (c->x86_vendor != X86_VENDOR_INTEL &&
200 c->x86_vendor != X86_VENDOR_AMD)
201 return -1;
202
203 cpu_cstate_entry = alloc_percpu(struct cstate_entry);
204 return 0;
205 }
206
207 static void __exit ffh_cstate_exit(void)
208 {
209 free_percpu(cpu_cstate_entry);
210 cpu_cstate_entry = NULL;
211 }
212
213 arch_initcall(ffh_cstate_init);
214 __exitcall(ffh_cstate_exit);