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