]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * processor_perflib.c - ACPI Processor P-States Library ($Revision: 71 $) | |
3 | * | |
4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | |
5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | |
6 | * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de> | |
7 | * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> | |
8 | * - Added processor hotplug support | |
9 | * | |
10 | * | |
11 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
12 | * | |
13 | * This program is free software; you can redistribute it and/or modify | |
14 | * it under the terms of the GNU General Public License as published by | |
15 | * the Free Software Foundation; either version 2 of the License, or (at | |
16 | * your option) any later version. | |
17 | * | |
18 | * This program is distributed in the hope that it will be useful, but | |
19 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 | * General Public License for more details. | |
22 | * | |
23 | * You should have received a copy of the GNU General Public License along | |
24 | * with this program; if not, write to the Free Software Foundation, Inc., | |
25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
26 | * | |
27 | */ | |
28 | ||
1da177e4 LT |
29 | #include <linux/kernel.h> |
30 | #include <linux/module.h> | |
31 | #include <linux/init.h> | |
32 | #include <linux/cpufreq.h> | |
33 | ||
34 | #ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF | |
35 | #include <linux/proc_fs.h> | |
36 | #include <linux/seq_file.h> | |
65c19bbd | 37 | #include <linux/mutex.h> |
1da177e4 LT |
38 | |
39 | #include <asm/uaccess.h> | |
40 | #endif | |
910dfae2 | 41 | #include <asm/cpufeature.h> |
1da177e4 LT |
42 | |
43 | #include <acpi/acpi_bus.h> | |
44 | #include <acpi/processor.h> | |
45 | ||
1da177e4 LT |
46 | #define ACPI_PROCESSOR_COMPONENT 0x01000000 |
47 | #define ACPI_PROCESSOR_CLASS "processor" | |
1da177e4 LT |
48 | #define ACPI_PROCESSOR_FILE_PERFORMANCE "performance" |
49 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT | |
f52fd66d | 50 | ACPI_MODULE_NAME("processor_perflib"); |
1da177e4 | 51 | |
65c19bbd | 52 | static DEFINE_MUTEX(performance_mutex); |
1da177e4 | 53 | |
919158d1 TR |
54 | /* Use cpufreq debug layer for _PPC changes. */ |
55 | #define cpufreq_printk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, \ | |
56 | "cpufreq-core", msg) | |
57 | ||
1da177e4 LT |
58 | /* |
59 | * _PPC support is implemented as a CPUfreq policy notifier: | |
60 | * This means each time a CPUfreq driver registered also with | |
61 | * the ACPI core is asked to change the speed policy, the maximum | |
62 | * value is adjusted so that it is within the platform limit. | |
63 | * | |
64 | * Also, when a new platform limit value is detected, the CPUfreq | |
65 | * policy is adjusted accordingly. | |
66 | */ | |
67 | ||
a1531acd TR |
68 | /* ignore_ppc: |
69 | * -1 -> cpufreq low level drivers not initialized -> _PSS, etc. not called yet | |
70 | * ignore _PPC | |
71 | * 0 -> cpufreq low level drivers initialized -> consider _PPC values | |
72 | * 1 -> ignore _PPC totally -> forced by user through boot param | |
73 | */ | |
9f497bcc | 74 | static int ignore_ppc = -1; |
613e5f33 | 75 | module_param(ignore_ppc, int, 0644); |
623b78c3 TR |
76 | MODULE_PARM_DESC(ignore_ppc, "If the frequency of your machine gets wrongly" \ |
77 | "limited by BIOS, this should help"); | |
78 | ||
1da177e4 LT |
79 | #define PPC_REGISTERED 1 |
80 | #define PPC_IN_USE 2 | |
81 | ||
a1531acd | 82 | static int acpi_processor_ppc_status; |
1da177e4 LT |
83 | |
84 | static int acpi_processor_ppc_notifier(struct notifier_block *nb, | |
4be44fcd | 85 | unsigned long event, void *data) |
1da177e4 LT |
86 | { |
87 | struct cpufreq_policy *policy = data; | |
88 | struct acpi_processor *pr; | |
89 | unsigned int ppc = 0; | |
90 | ||
a1531acd TR |
91 | if (event == CPUFREQ_START && ignore_ppc <= 0) { |
92 | ignore_ppc = 0; | |
93 | return 0; | |
94 | } | |
95 | ||
623b78c3 TR |
96 | if (ignore_ppc) |
97 | return 0; | |
98 | ||
1da177e4 | 99 | if (event != CPUFREQ_INCOMPATIBLE) |
9b67c5d4 TR |
100 | return 0; |
101 | ||
102 | mutex_lock(&performance_mutex); | |
1da177e4 | 103 | |
706546d0 | 104 | pr = per_cpu(processors, policy->cpu); |
1da177e4 LT |
105 | if (!pr || !pr->performance) |
106 | goto out; | |
107 | ||
4be44fcd | 108 | ppc = (unsigned int)pr->performance_platform_limit; |
1da177e4 | 109 | |
0916bd3e | 110 | if (ppc >= pr->performance->state_count) |
1da177e4 LT |
111 | goto out; |
112 | ||
113 | cpufreq_verify_within_limits(policy, 0, | |
4be44fcd LB |
114 | pr->performance->states[ppc]. |
115 | core_frequency * 1000); | |
1da177e4 | 116 | |
4be44fcd | 117 | out: |
65c19bbd | 118 | mutex_unlock(&performance_mutex); |
1da177e4 LT |
119 | |
120 | return 0; | |
121 | } | |
122 | ||
1da177e4 LT |
123 | static struct notifier_block acpi_ppc_notifier_block = { |
124 | .notifier_call = acpi_processor_ppc_notifier, | |
125 | }; | |
126 | ||
4be44fcd | 127 | static int acpi_processor_get_platform_limit(struct acpi_processor *pr) |
1da177e4 | 128 | { |
4be44fcd | 129 | acpi_status status = 0; |
27663c58 | 130 | unsigned long long ppc = 0; |
1da177e4 | 131 | |
1da177e4 LT |
132 | |
133 | if (!pr) | |
d550d98d | 134 | return -EINVAL; |
1da177e4 LT |
135 | |
136 | /* | |
137 | * _PPC indicates the maximum state currently supported by the platform | |
138 | * (e.g. 0 = states 0..n; 1 = states 1..n; etc. | |
139 | */ | |
140 | status = acpi_evaluate_integer(pr->handle, "_PPC", NULL, &ppc); | |
141 | ||
142 | if (status != AE_NOT_FOUND) | |
143 | acpi_processor_ppc_status |= PPC_IN_USE; | |
144 | ||
4be44fcd | 145 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
a6fc6720 | 146 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PPC")); |
d550d98d | 147 | return -ENODEV; |
1da177e4 LT |
148 | } |
149 | ||
919158d1 TR |
150 | cpufreq_printk("CPU %d: _PPC is %d - frequency %s limited\n", pr->id, |
151 | (int)ppc, ppc ? "" : "not"); | |
152 | ||
4be44fcd | 153 | pr->performance_platform_limit = (int)ppc; |
1da177e4 | 154 | |
d550d98d | 155 | return 0; |
1da177e4 LT |
156 | } |
157 | ||
4be44fcd | 158 | int acpi_processor_ppc_has_changed(struct acpi_processor *pr) |
1da177e4 | 159 | { |
623b78c3 TR |
160 | int ret; |
161 | ||
162 | if (ignore_ppc) | |
163 | return 0; | |
164 | ||
165 | ret = acpi_processor_get_platform_limit(pr); | |
166 | ||
1da177e4 LT |
167 | if (ret < 0) |
168 | return (ret); | |
169 | else | |
170 | return cpufreq_update_policy(pr->id); | |
171 | } | |
172 | ||
4be44fcd LB |
173 | void acpi_processor_ppc_init(void) |
174 | { | |
175 | if (!cpufreq_register_notifier | |
176 | (&acpi_ppc_notifier_block, CPUFREQ_POLICY_NOTIFIER)) | |
1da177e4 LT |
177 | acpi_processor_ppc_status |= PPC_REGISTERED; |
178 | else | |
4be44fcd LB |
179 | printk(KERN_DEBUG |
180 | "Warning: Processor Platform Limit not supported.\n"); | |
1da177e4 LT |
181 | } |
182 | ||
4be44fcd LB |
183 | void acpi_processor_ppc_exit(void) |
184 | { | |
1da177e4 | 185 | if (acpi_processor_ppc_status & PPC_REGISTERED) |
4be44fcd LB |
186 | cpufreq_unregister_notifier(&acpi_ppc_notifier_block, |
187 | CPUFREQ_POLICY_NOTIFIER); | |
1da177e4 LT |
188 | |
189 | acpi_processor_ppc_status &= ~PPC_REGISTERED; | |
190 | } | |
191 | ||
4be44fcd | 192 | static int acpi_processor_get_performance_control(struct acpi_processor *pr) |
1da177e4 | 193 | { |
4be44fcd LB |
194 | int result = 0; |
195 | acpi_status status = 0; | |
196 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
197 | union acpi_object *pct = NULL; | |
198 | union acpi_object obj = { 0 }; | |
1da177e4 | 199 | |
1da177e4 LT |
200 | |
201 | status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer); | |
4be44fcd | 202 | if (ACPI_FAILURE(status)) { |
a6fc6720 | 203 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PCT")); |
d550d98d | 204 | return -ENODEV; |
1da177e4 LT |
205 | } |
206 | ||
4be44fcd | 207 | pct = (union acpi_object *)buffer.pointer; |
1da177e4 | 208 | if (!pct || (pct->type != ACPI_TYPE_PACKAGE) |
4be44fcd | 209 | || (pct->package.count != 2)) { |
6468463a | 210 | printk(KERN_ERR PREFIX "Invalid _PCT data\n"); |
1da177e4 LT |
211 | result = -EFAULT; |
212 | goto end; | |
213 | } | |
214 | ||
215 | /* | |
216 | * control_register | |
217 | */ | |
218 | ||
219 | obj = pct->package.elements[0]; | |
220 | ||
221 | if ((obj.type != ACPI_TYPE_BUFFER) | |
4be44fcd LB |
222 | || (obj.buffer.length < sizeof(struct acpi_pct_register)) |
223 | || (obj.buffer.pointer == NULL)) { | |
6468463a | 224 | printk(KERN_ERR PREFIX "Invalid _PCT data (control_register)\n"); |
1da177e4 LT |
225 | result = -EFAULT; |
226 | goto end; | |
227 | } | |
4be44fcd LB |
228 | memcpy(&pr->performance->control_register, obj.buffer.pointer, |
229 | sizeof(struct acpi_pct_register)); | |
1da177e4 LT |
230 | |
231 | /* | |
232 | * status_register | |
233 | */ | |
234 | ||
235 | obj = pct->package.elements[1]; | |
236 | ||
237 | if ((obj.type != ACPI_TYPE_BUFFER) | |
4be44fcd LB |
238 | || (obj.buffer.length < sizeof(struct acpi_pct_register)) |
239 | || (obj.buffer.pointer == NULL)) { | |
6468463a | 240 | printk(KERN_ERR PREFIX "Invalid _PCT data (status_register)\n"); |
1da177e4 LT |
241 | result = -EFAULT; |
242 | goto end; | |
243 | } | |
244 | ||
4be44fcd LB |
245 | memcpy(&pr->performance->status_register, obj.buffer.pointer, |
246 | sizeof(struct acpi_pct_register)); | |
1da177e4 | 247 | |
4be44fcd | 248 | end: |
02438d87 | 249 | kfree(buffer.pointer); |
1da177e4 | 250 | |
d550d98d | 251 | return result; |
1da177e4 LT |
252 | } |
253 | ||
4be44fcd | 254 | static int acpi_processor_get_performance_states(struct acpi_processor *pr) |
1da177e4 | 255 | { |
4be44fcd LB |
256 | int result = 0; |
257 | acpi_status status = AE_OK; | |
258 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
259 | struct acpi_buffer format = { sizeof("NNNNNN"), "NNNNNN" }; | |
260 | struct acpi_buffer state = { 0, NULL }; | |
261 | union acpi_object *pss = NULL; | |
262 | int i; | |
1da177e4 | 263 | |
1da177e4 LT |
264 | |
265 | status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer); | |
4be44fcd | 266 | if (ACPI_FAILURE(status)) { |
a6fc6720 | 267 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PSS")); |
d550d98d | 268 | return -ENODEV; |
1da177e4 LT |
269 | } |
270 | ||
50dd0969 | 271 | pss = buffer.pointer; |
1da177e4 | 272 | if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) { |
6468463a | 273 | printk(KERN_ERR PREFIX "Invalid _PSS data\n"); |
1da177e4 LT |
274 | result = -EFAULT; |
275 | goto end; | |
276 | } | |
277 | ||
278 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d performance states\n", | |
4be44fcd | 279 | pss->package.count)); |
1da177e4 LT |
280 | |
281 | pr->performance->state_count = pss->package.count; | |
4be44fcd LB |
282 | pr->performance->states = |
283 | kmalloc(sizeof(struct acpi_processor_px) * pss->package.count, | |
284 | GFP_KERNEL); | |
1da177e4 LT |
285 | if (!pr->performance->states) { |
286 | result = -ENOMEM; | |
287 | goto end; | |
288 | } | |
289 | ||
290 | for (i = 0; i < pr->performance->state_count; i++) { | |
291 | ||
292 | struct acpi_processor_px *px = &(pr->performance->states[i]); | |
293 | ||
294 | state.length = sizeof(struct acpi_processor_px); | |
295 | state.pointer = px; | |
296 | ||
297 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i)); | |
298 | ||
299 | status = acpi_extract_package(&(pss->package.elements[i]), | |
4be44fcd | 300 | &format, &state); |
1da177e4 | 301 | if (ACPI_FAILURE(status)) { |
a6fc6720 | 302 | ACPI_EXCEPTION((AE_INFO, status, "Invalid _PSS data")); |
1da177e4 LT |
303 | result = -EFAULT; |
304 | kfree(pr->performance->states); | |
305 | goto end; | |
306 | } | |
307 | ||
308 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd LB |
309 | "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n", |
310 | i, | |
311 | (u32) px->core_frequency, | |
312 | (u32) px->power, | |
313 | (u32) px->transition_latency, | |
314 | (u32) px->bus_master_latency, | |
315 | (u32) px->control, (u32) px->status)); | |
1da177e4 LT |
316 | |
317 | if (!px->core_frequency) { | |
6468463a LB |
318 | printk(KERN_ERR PREFIX |
319 | "Invalid _PSS data: freq is zero\n"); | |
1da177e4 LT |
320 | result = -EFAULT; |
321 | kfree(pr->performance->states); | |
322 | goto end; | |
323 | } | |
324 | } | |
325 | ||
4be44fcd | 326 | end: |
02438d87 | 327 | kfree(buffer.pointer); |
1da177e4 | 328 | |
d550d98d | 329 | return result; |
1da177e4 LT |
330 | } |
331 | ||
4be44fcd | 332 | static int acpi_processor_get_performance_info(struct acpi_processor *pr) |
1da177e4 | 333 | { |
4be44fcd LB |
334 | int result = 0; |
335 | acpi_status status = AE_OK; | |
336 | acpi_handle handle = NULL; | |
1da177e4 | 337 | |
1da177e4 | 338 | if (!pr || !pr->performance || !pr->handle) |
d550d98d | 339 | return -EINVAL; |
1da177e4 | 340 | |
1da177e4 LT |
341 | status = acpi_get_handle(pr->handle, "_PCT", &handle); |
342 | if (ACPI_FAILURE(status)) { | |
343 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 344 | "ACPI-based processor performance control unavailable\n")); |
d550d98d | 345 | return -ENODEV; |
1da177e4 LT |
346 | } |
347 | ||
348 | result = acpi_processor_get_performance_control(pr); | |
349 | if (result) | |
910dfae2 | 350 | goto update_bios; |
1da177e4 LT |
351 | |
352 | result = acpi_processor_get_performance_states(pr); | |
353 | if (result) | |
910dfae2 | 354 | goto update_bios; |
1da177e4 | 355 | |
d550d98d | 356 | return 0; |
910dfae2 TR |
357 | |
358 | /* | |
359 | * Having _PPC but missing frequencies (_PSS, _PCT) is a very good hint that | |
360 | * the BIOS is older than the CPU and does not know its frequencies | |
361 | */ | |
362 | update_bios: | |
363 | if (ACPI_SUCCESS(acpi_get_handle(pr->handle, "_PPC", &handle))){ | |
364 | if(boot_cpu_has(X86_FEATURE_EST)) | |
365 | printk(KERN_WARNING FW_BUG "BIOS needs update for CPU " | |
366 | "frequency support\n"); | |
367 | } | |
368 | return result; | |
1da177e4 LT |
369 | } |
370 | ||
4be44fcd LB |
371 | int acpi_processor_notify_smm(struct module *calling_module) |
372 | { | |
373 | acpi_status status; | |
374 | static int is_done = 0; | |
1da177e4 | 375 | |
1da177e4 LT |
376 | |
377 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) | |
d550d98d | 378 | return -EBUSY; |
1da177e4 LT |
379 | |
380 | if (!try_module_get(calling_module)) | |
d550d98d | 381 | return -EINVAL; |
1da177e4 LT |
382 | |
383 | /* is_done is set to negative if an error occured, | |
384 | * and to postitive if _no_ error occured, but SMM | |
385 | * was already notified. This avoids double notification | |
386 | * which might lead to unexpected results... | |
387 | */ | |
388 | if (is_done > 0) { | |
389 | module_put(calling_module); | |
d550d98d | 390 | return 0; |
4be44fcd | 391 | } else if (is_done < 0) { |
1da177e4 | 392 | module_put(calling_module); |
d550d98d | 393 | return is_done; |
1da177e4 LT |
394 | } |
395 | ||
396 | is_done = -EIO; | |
397 | ||
ad71860a | 398 | /* Can't write pstate_control to smi_command if either value is zero */ |
cee324b1 | 399 | if ((!acpi_gbl_FADT.smi_command) || (!acpi_gbl_FADT.pstate_control)) { |
ad71860a | 400 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_control\n")); |
1da177e4 | 401 | module_put(calling_module); |
d550d98d | 402 | return 0; |
1da177e4 LT |
403 | } |
404 | ||
4be44fcd | 405 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
ad71860a | 406 | "Writing pstate_control [0x%x] to smi_command [0x%x]\n", |
cee324b1 | 407 | acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command)); |
1da177e4 | 408 | |
cee324b1 AS |
409 | status = acpi_os_write_port(acpi_gbl_FADT.smi_command, |
410 | (u32) acpi_gbl_FADT.pstate_control, 8); | |
4be44fcd | 411 | if (ACPI_FAILURE(status)) { |
a6fc6720 | 412 | ACPI_EXCEPTION((AE_INFO, status, |
ad71860a | 413 | "Failed to write pstate_control [0x%x] to " |
cee324b1 AS |
414 | "smi_command [0x%x]", acpi_gbl_FADT.pstate_control, |
415 | acpi_gbl_FADT.smi_command)); | |
1da177e4 | 416 | module_put(calling_module); |
d550d98d | 417 | return status; |
1da177e4 LT |
418 | } |
419 | ||
420 | /* Success. If there's no _PPC, we need to fear nothing, so | |
421 | * we can allow the cpufreq driver to be rmmod'ed. */ | |
422 | is_done = 1; | |
423 | ||
424 | if (!(acpi_processor_ppc_status & PPC_IN_USE)) | |
425 | module_put(calling_module); | |
426 | ||
d550d98d | 427 | return 0; |
1da177e4 | 428 | } |
1da177e4 | 429 | |
4be44fcd | 430 | EXPORT_SYMBOL(acpi_processor_notify_smm); |
1da177e4 LT |
431 | |
432 | #ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF | |
433 | /* /proc/acpi/processor/../performance interface (DEPRECATED) */ | |
434 | ||
435 | static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file); | |
436 | static struct file_operations acpi_processor_perf_fops = { | |
cf7acfab | 437 | .owner = THIS_MODULE, |
4be44fcd LB |
438 | .open = acpi_processor_perf_open_fs, |
439 | .read = seq_read, | |
440 | .llseek = seq_lseek, | |
441 | .release = single_release, | |
1da177e4 LT |
442 | }; |
443 | ||
444 | static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset) | |
445 | { | |
50dd0969 | 446 | struct acpi_processor *pr = seq->private; |
4be44fcd | 447 | int i; |
1da177e4 | 448 | |
1da177e4 LT |
449 | |
450 | if (!pr) | |
451 | goto end; | |
452 | ||
453 | if (!pr->performance) { | |
454 | seq_puts(seq, "<not supported>\n"); | |
455 | goto end; | |
456 | } | |
457 | ||
458 | seq_printf(seq, "state count: %d\n" | |
4be44fcd LB |
459 | "active state: P%d\n", |
460 | pr->performance->state_count, pr->performance->state); | |
1da177e4 LT |
461 | |
462 | seq_puts(seq, "states:\n"); | |
463 | for (i = 0; i < pr->performance->state_count; i++) | |
4be44fcd LB |
464 | seq_printf(seq, |
465 | " %cP%d: %d MHz, %d mW, %d uS\n", | |
466 | (i == pr->performance->state ? '*' : ' '), i, | |
467 | (u32) pr->performance->states[i].core_frequency, | |
468 | (u32) pr->performance->states[i].power, | |
469 | (u32) pr->performance->states[i].transition_latency); | |
470 | ||
471 | end: | |
d550d98d | 472 | return 0; |
1da177e4 LT |
473 | } |
474 | ||
475 | static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file) | |
476 | { | |
477 | return single_open(file, acpi_processor_perf_seq_show, | |
4be44fcd | 478 | PDE(inode)->data); |
1da177e4 LT |
479 | } |
480 | ||
4be44fcd | 481 | static void acpi_cpufreq_add_file(struct acpi_processor *pr) |
1da177e4 | 482 | { |
4be44fcd | 483 | struct acpi_device *device = NULL; |
1da177e4 | 484 | |
1da177e4 LT |
485 | |
486 | if (acpi_bus_get_device(pr->handle, &device)) | |
d550d98d | 487 | return; |
1da177e4 LT |
488 | |
489 | /* add file 'performance' [R/W] */ | |
cf7acfab DL |
490 | proc_create_data(ACPI_PROCESSOR_FILE_PERFORMANCE, S_IFREG | S_IRUGO, |
491 | acpi_device_dir(device), | |
492 | &acpi_processor_perf_fops, acpi_driver_data(device)); | |
d550d98d | 493 | return; |
1da177e4 LT |
494 | } |
495 | ||
4be44fcd | 496 | static void acpi_cpufreq_remove_file(struct acpi_processor *pr) |
1da177e4 | 497 | { |
4be44fcd | 498 | struct acpi_device *device = NULL; |
1da177e4 | 499 | |
1da177e4 LT |
500 | |
501 | if (acpi_bus_get_device(pr->handle, &device)) | |
d550d98d | 502 | return; |
1da177e4 LT |
503 | |
504 | /* remove file 'performance' */ | |
505 | remove_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE, | |
4be44fcd | 506 | acpi_device_dir(device)); |
1da177e4 | 507 | |
d550d98d | 508 | return; |
1da177e4 LT |
509 | } |
510 | ||
511 | #else | |
4be44fcd LB |
512 | static void acpi_cpufreq_add_file(struct acpi_processor *pr) |
513 | { | |
514 | return; | |
515 | } | |
516 | static void acpi_cpufreq_remove_file(struct acpi_processor *pr) | |
517 | { | |
518 | return; | |
519 | } | |
520 | #endif /* CONFIG_X86_ACPI_CPUFREQ_PROC_INTF */ | |
1da177e4 | 521 | |
3b2d9942 VP |
522 | static int acpi_processor_get_psd(struct acpi_processor *pr) |
523 | { | |
524 | int result = 0; | |
525 | acpi_status status = AE_OK; | |
526 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; | |
527 | struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"}; | |
528 | struct acpi_buffer state = {0, NULL}; | |
529 | union acpi_object *psd = NULL; | |
530 | struct acpi_psd_package *pdomain; | |
531 | ||
3b2d9942 VP |
532 | status = acpi_evaluate_object(pr->handle, "_PSD", NULL, &buffer); |
533 | if (ACPI_FAILURE(status)) { | |
9011bff4 | 534 | return -ENODEV; |
3b2d9942 VP |
535 | } |
536 | ||
50dd0969 | 537 | psd = buffer.pointer; |
3b2d9942 | 538 | if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) { |
55ac9a01 | 539 | printk(KERN_ERR PREFIX "Invalid _PSD data\n"); |
3b2d9942 VP |
540 | result = -EFAULT; |
541 | goto end; | |
542 | } | |
543 | ||
544 | if (psd->package.count != 1) { | |
55ac9a01 | 545 | printk(KERN_ERR PREFIX "Invalid _PSD data\n"); |
3b2d9942 VP |
546 | result = -EFAULT; |
547 | goto end; | |
548 | } | |
549 | ||
550 | pdomain = &(pr->performance->domain_info); | |
551 | ||
552 | state.length = sizeof(struct acpi_psd_package); | |
553 | state.pointer = pdomain; | |
554 | ||
555 | status = acpi_extract_package(&(psd->package.elements[0]), | |
556 | &format, &state); | |
557 | if (ACPI_FAILURE(status)) { | |
55ac9a01 | 558 | printk(KERN_ERR PREFIX "Invalid _PSD data\n"); |
3b2d9942 VP |
559 | result = -EFAULT; |
560 | goto end; | |
561 | } | |
562 | ||
563 | if (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES) { | |
55ac9a01 | 564 | printk(KERN_ERR PREFIX "Unknown _PSD:num_entries\n"); |
3b2d9942 VP |
565 | result = -EFAULT; |
566 | goto end; | |
567 | } | |
568 | ||
569 | if (pdomain->revision != ACPI_PSD_REV0_REVISION) { | |
55ac9a01 | 570 | printk(KERN_ERR PREFIX "Unknown _PSD:revision\n"); |
3b2d9942 VP |
571 | result = -EFAULT; |
572 | goto end; | |
573 | } | |
574 | ||
575 | end: | |
02438d87 | 576 | kfree(buffer.pointer); |
9011bff4 | 577 | return result; |
3b2d9942 VP |
578 | } |
579 | ||
580 | int acpi_processor_preregister_performance( | |
50109292 | 581 | struct acpi_processor_performance *performance) |
3b2d9942 VP |
582 | { |
583 | int count, count_target; | |
584 | int retval = 0; | |
585 | unsigned int i, j; | |
586 | cpumask_t covered_cpus; | |
587 | struct acpi_processor *pr; | |
588 | struct acpi_psd_package *pdomain; | |
589 | struct acpi_processor *match_pr; | |
590 | struct acpi_psd_package *match_pdomain; | |
591 | ||
785fcccd | 592 | mutex_lock(&performance_mutex); |
3b2d9942 VP |
593 | |
594 | retval = 0; | |
595 | ||
596 | /* Call _PSD for all CPUs */ | |
193de0c7 | 597 | for_each_possible_cpu(i) { |
706546d0 | 598 | pr = per_cpu(processors, i); |
3b2d9942 VP |
599 | if (!pr) { |
600 | /* Look only at processors in ACPI namespace */ | |
601 | continue; | |
602 | } | |
603 | ||
604 | if (pr->performance) { | |
605 | retval = -EBUSY; | |
606 | continue; | |
607 | } | |
608 | ||
50109292 | 609 | if (!performance || !percpu_ptr(performance, i)) { |
3b2d9942 VP |
610 | retval = -EINVAL; |
611 | continue; | |
612 | } | |
613 | ||
50109292 | 614 | pr->performance = percpu_ptr(performance, i); |
3b2d9942 VP |
615 | cpu_set(i, pr->performance->shared_cpu_map); |
616 | if (acpi_processor_get_psd(pr)) { | |
617 | retval = -EINVAL; | |
618 | continue; | |
619 | } | |
620 | } | |
621 | if (retval) | |
622 | goto err_ret; | |
623 | ||
624 | /* | |
625 | * Now that we have _PSD data from all CPUs, lets setup P-state | |
626 | * domain info. | |
627 | */ | |
193de0c7 | 628 | for_each_possible_cpu(i) { |
706546d0 | 629 | pr = per_cpu(processors, i); |
3b2d9942 VP |
630 | if (!pr) |
631 | continue; | |
632 | ||
633 | /* Basic validity check for domain info */ | |
634 | pdomain = &(pr->performance->domain_info); | |
635 | if ((pdomain->revision != ACPI_PSD_REV0_REVISION) || | |
636 | (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES)) { | |
637 | retval = -EINVAL; | |
638 | goto err_ret; | |
639 | } | |
640 | if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL && | |
641 | pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY && | |
642 | pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) { | |
643 | retval = -EINVAL; | |
644 | goto err_ret; | |
645 | } | |
646 | } | |
647 | ||
648 | cpus_clear(covered_cpus); | |
193de0c7 | 649 | for_each_possible_cpu(i) { |
706546d0 | 650 | pr = per_cpu(processors, i); |
3b2d9942 VP |
651 | if (!pr) |
652 | continue; | |
653 | ||
654 | if (cpu_isset(i, covered_cpus)) | |
655 | continue; | |
656 | ||
657 | pdomain = &(pr->performance->domain_info); | |
658 | cpu_set(i, pr->performance->shared_cpu_map); | |
659 | cpu_set(i, covered_cpus); | |
660 | if (pdomain->num_processors <= 1) | |
661 | continue; | |
662 | ||
663 | /* Validate the Domain info */ | |
664 | count_target = pdomain->num_processors; | |
665 | count = 1; | |
46f18e3a | 666 | if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL) |
3b2d9942 | 667 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL; |
46f18e3a VP |
668 | else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL) |
669 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_HW; | |
670 | else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY) | |
3b2d9942 | 671 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY; |
3b2d9942 | 672 | |
193de0c7 | 673 | for_each_possible_cpu(j) { |
3b2d9942 VP |
674 | if (i == j) |
675 | continue; | |
676 | ||
706546d0 | 677 | match_pr = per_cpu(processors, j); |
3b2d9942 VP |
678 | if (!match_pr) |
679 | continue; | |
680 | ||
681 | match_pdomain = &(match_pr->performance->domain_info); | |
682 | if (match_pdomain->domain != pdomain->domain) | |
683 | continue; | |
684 | ||
685 | /* Here i and j are in the same domain */ | |
686 | ||
687 | if (match_pdomain->num_processors != count_target) { | |
688 | retval = -EINVAL; | |
689 | goto err_ret; | |
690 | } | |
691 | ||
692 | if (pdomain->coord_type != match_pdomain->coord_type) { | |
693 | retval = -EINVAL; | |
694 | goto err_ret; | |
695 | } | |
696 | ||
697 | cpu_set(j, covered_cpus); | |
698 | cpu_set(j, pr->performance->shared_cpu_map); | |
699 | count++; | |
700 | } | |
701 | ||
193de0c7 | 702 | for_each_possible_cpu(j) { |
3b2d9942 VP |
703 | if (i == j) |
704 | continue; | |
705 | ||
706546d0 | 706 | match_pr = per_cpu(processors, j); |
3b2d9942 VP |
707 | if (!match_pr) |
708 | continue; | |
709 | ||
710 | match_pdomain = &(match_pr->performance->domain_info); | |
711 | if (match_pdomain->domain != pdomain->domain) | |
712 | continue; | |
713 | ||
714 | match_pr->performance->shared_type = | |
715 | pr->performance->shared_type; | |
716 | match_pr->performance->shared_cpu_map = | |
717 | pr->performance->shared_cpu_map; | |
718 | } | |
719 | } | |
720 | ||
721 | err_ret: | |
193de0c7 | 722 | for_each_possible_cpu(i) { |
706546d0 | 723 | pr = per_cpu(processors, i); |
3b2d9942 VP |
724 | if (!pr || !pr->performance) |
725 | continue; | |
726 | ||
727 | /* Assume no coordination on any error parsing domain info */ | |
728 | if (retval) { | |
729 | cpus_clear(pr->performance->shared_cpu_map); | |
730 | cpu_set(i, pr->performance->shared_cpu_map); | |
731 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL; | |
732 | } | |
733 | pr->performance = NULL; /* Will be set for real in register */ | |
734 | } | |
735 | ||
785fcccd | 736 | mutex_unlock(&performance_mutex); |
9011bff4 | 737 | return retval; |
3b2d9942 VP |
738 | } |
739 | EXPORT_SYMBOL(acpi_processor_preregister_performance); | |
740 | ||
741 | ||
1da177e4 | 742 | int |
4be44fcd LB |
743 | acpi_processor_register_performance(struct acpi_processor_performance |
744 | *performance, unsigned int cpu) | |
1da177e4 LT |
745 | { |
746 | struct acpi_processor *pr; | |
747 | ||
1da177e4 LT |
748 | |
749 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) | |
d550d98d | 750 | return -EINVAL; |
1da177e4 | 751 | |
65c19bbd | 752 | mutex_lock(&performance_mutex); |
1da177e4 | 753 | |
706546d0 | 754 | pr = per_cpu(processors, cpu); |
1da177e4 | 755 | if (!pr) { |
65c19bbd | 756 | mutex_unlock(&performance_mutex); |
d550d98d | 757 | return -ENODEV; |
1da177e4 LT |
758 | } |
759 | ||
760 | if (pr->performance) { | |
65c19bbd | 761 | mutex_unlock(&performance_mutex); |
d550d98d | 762 | return -EBUSY; |
1da177e4 LT |
763 | } |
764 | ||
a913f507 AM |
765 | WARN_ON(!performance); |
766 | ||
1da177e4 LT |
767 | pr->performance = performance; |
768 | ||
769 | if (acpi_processor_get_performance_info(pr)) { | |
770 | pr->performance = NULL; | |
65c19bbd | 771 | mutex_unlock(&performance_mutex); |
d550d98d | 772 | return -EIO; |
1da177e4 LT |
773 | } |
774 | ||
775 | acpi_cpufreq_add_file(pr); | |
776 | ||
65c19bbd | 777 | mutex_unlock(&performance_mutex); |
d550d98d | 778 | return 0; |
1da177e4 | 779 | } |
1da177e4 | 780 | |
4be44fcd | 781 | EXPORT_SYMBOL(acpi_processor_register_performance); |
1da177e4 LT |
782 | |
783 | void | |
4be44fcd LB |
784 | acpi_processor_unregister_performance(struct acpi_processor_performance |
785 | *performance, unsigned int cpu) | |
1da177e4 LT |
786 | { |
787 | struct acpi_processor *pr; | |
788 | ||
1da177e4 | 789 | |
65c19bbd | 790 | mutex_lock(&performance_mutex); |
1da177e4 | 791 | |
706546d0 | 792 | pr = per_cpu(processors, cpu); |
1da177e4 | 793 | if (!pr) { |
65c19bbd | 794 | mutex_unlock(&performance_mutex); |
d550d98d | 795 | return; |
1da177e4 LT |
796 | } |
797 | ||
a913f507 AM |
798 | if (pr->performance) |
799 | kfree(pr->performance->states); | |
1da177e4 LT |
800 | pr->performance = NULL; |
801 | ||
802 | acpi_cpufreq_remove_file(pr); | |
803 | ||
65c19bbd | 804 | mutex_unlock(&performance_mutex); |
1da177e4 | 805 | |
d550d98d | 806 | return; |
1da177e4 | 807 | } |
4be44fcd | 808 | |
1da177e4 | 809 | EXPORT_SYMBOL(acpi_processor_unregister_performance); |