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