1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * processor_perflib.c - ACPI Processor P-States Library ($Revision: 71 $)
4 *
5 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de>
8 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
9 * - Added processor hotplug support
10 */
11
12 #define pr_fmt(fmt) "ACPI: " fmt
13
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/cpufreq.h>
18 #include <linux/slab.h>
19 #include <linux/acpi.h>
20 #include <acpi/processor.h>
21 #ifdef CONFIG_X86
22 #include <asm/cpufeature.h>
23 #include <asm/msr.h>
24 #endif
25
26 #define ACPI_PROCESSOR_FILE_PERFORMANCE "performance"
27
28 /*
29 * _PPC support is implemented as a CPUfreq policy notifier:
30 * This means each time a CPUfreq driver registered also with
31 * the ACPI core is asked to change the speed policy, the maximum
32 * value is adjusted so that it is within the platform limit.
33 *
34 * Also, when a new platform limit value is detected, the CPUfreq
35 * policy is adjusted accordingly.
36 */
37
38 /* ignore_ppc:
39 * -1 -> cpufreq low level drivers not initialized -> _PSS, etc. not called yet
40 * ignore _PPC
41 * 0 -> cpufreq low level drivers initialized -> consider _PPC values
42 * 1 -> ignore _PPC totally -> forced by user through boot param
43 */
44 static int ignore_ppc = -1;
45 module_param(ignore_ppc, int, 0644);
46 MODULE_PARM_DESC(ignore_ppc, "If the frequency of your machine gets wrongly" \
47 "limited by BIOS, this should help");
48
49 static bool acpi_processor_ppc_in_use;
50
acpi_processor_get_platform_limit(struct acpi_processor * pr)51 static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
52 {
53 acpi_status status = 0;
54 unsigned long long ppc = 0;
55 s32 qos_value;
56 int index;
57 int ret;
58
59 if (!pr)
60 return -EINVAL;
61
62 /*
63 * _PPC indicates the maximum state currently supported by the platform
64 * (e.g. 0 = states 0..n; 1 = states 1..n; etc.
65 */
66 status = acpi_evaluate_integer(pr->handle, "_PPC", NULL, &ppc);
67 if (status != AE_NOT_FOUND) {
68 acpi_processor_ppc_in_use = true;
69
70 if (ACPI_FAILURE(status)) {
71 acpi_evaluation_failure_warn(pr->handle, "_PPC", status);
72 return -ENODEV;
73 }
74 }
75
76 index = ppc;
77
78 if (pr->performance_platform_limit == index ||
79 ppc >= pr->performance->state_count)
80 return 0;
81
82 pr_debug("CPU %d: _PPC is %d - frequency %s limited\n", pr->id,
83 index, index ? "is" : "is not");
84
85 pr->performance_platform_limit = index;
86
87 if (unlikely(!freq_qos_request_active(&pr->perflib_req)))
88 return 0;
89
90 /*
91 * If _PPC returns 0, it means that all of the available states can be
92 * used ("no limit").
93 */
94 if (index == 0)
95 qos_value = FREQ_QOS_MAX_DEFAULT_VALUE;
96 else
97 qos_value = pr->performance->states[index].core_frequency * 1000;
98
99 ret = freq_qos_update_request(&pr->perflib_req, qos_value);
100 if (ret < 0) {
101 pr_warn("Failed to update perflib freq constraint: CPU%d (%d)\n",
102 pr->id, ret);
103 }
104
105 return 0;
106 }
107
108 #define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
109 /*
110 * acpi_processor_ppc_ost: Notify firmware the _PPC evaluation status
111 * @handle: ACPI processor handle
112 * @status: the status code of _PPC evaluation
113 * 0: success. OSPM is now using the performance state specified.
114 * 1: failure. OSPM has not changed the number of P-states in use
115 */
acpi_processor_ppc_ost(acpi_handle handle,int status)116 static void acpi_processor_ppc_ost(acpi_handle handle, int status)
117 {
118 if (acpi_has_method(handle, "_OST"))
119 acpi_evaluate_ost(handle, ACPI_PROCESSOR_NOTIFY_PERFORMANCE,
120 status, NULL);
121 }
122
acpi_processor_ppc_has_changed(struct acpi_processor * pr,int event_flag)123 void acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag)
124 {
125 int ret;
126
127 if (ignore_ppc || !pr->performance) {
128 /*
129 * Only when it is notification event, the _OST object
130 * will be evaluated. Otherwise it is skipped.
131 */
132 if (event_flag)
133 acpi_processor_ppc_ost(pr->handle, 1);
134 return;
135 }
136
137 ret = acpi_processor_get_platform_limit(pr);
138 /*
139 * Only when it is notification event, the _OST object
140 * will be evaluated. Otherwise it is skipped.
141 */
142 if (event_flag) {
143 if (ret < 0)
144 acpi_processor_ppc_ost(pr->handle, 1);
145 else
146 acpi_processor_ppc_ost(pr->handle, 0);
147 }
148 if (ret >= 0)
149 cpufreq_update_limits(pr->id);
150 }
151
acpi_processor_get_bios_limit(int cpu,unsigned int * limit)152 int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
153 {
154 struct acpi_processor *pr;
155
156 pr = per_cpu(processors, cpu);
157 if (!pr || !pr->performance || !pr->performance->state_count)
158 return -ENODEV;
159
160 *limit = pr->performance->states[pr->performance_platform_limit].
161 core_frequency * 1000;
162 return 0;
163 }
164 EXPORT_SYMBOL(acpi_processor_get_bios_limit);
165
acpi_processor_ignore_ppc_init(void)166 void acpi_processor_ignore_ppc_init(void)
167 {
168 if (ignore_ppc < 0)
169 ignore_ppc = 0;
170 }
171
acpi_processor_ppc_init(struct cpufreq_policy * policy)172 void acpi_processor_ppc_init(struct cpufreq_policy *policy)
173 {
174 unsigned int cpu;
175
176 if (ignore_ppc == 1)
177 return;
178
179 for_each_cpu(cpu, policy->related_cpus) {
180 struct acpi_processor *pr = per_cpu(processors, cpu);
181 int ret;
182
183 if (!pr || !pr->performance)
184 continue;
185
186 /*
187 * Reset performance_platform_limit in case there is a stale
188 * value in it, so as to make it match the "no limit" QoS value
189 * below.
190 */
191 pr->performance_platform_limit = 0;
192
193 ret = freq_qos_add_request(&policy->constraints,
194 &pr->perflib_req, FREQ_QOS_MAX,
195 FREQ_QOS_MAX_DEFAULT_VALUE);
196 if (ret < 0)
197 pr_err("Failed to add freq constraint for CPU%d (%d)\n",
198 cpu, ret);
199
200 ret = acpi_processor_get_platform_limit(pr);
201 if (ret)
202 pr_err("Failed to update freq constraint for CPU%d (%d)\n",
203 cpu, ret);
204 }
205 }
206
acpi_processor_ppc_exit(struct cpufreq_policy * policy)207 void acpi_processor_ppc_exit(struct cpufreq_policy *policy)
208 {
209 unsigned int cpu;
210
211 for_each_cpu(cpu, policy->related_cpus) {
212 struct acpi_processor *pr = per_cpu(processors, cpu);
213
214 if (pr)
215 freq_qos_remove_request(&pr->perflib_req);
216 }
217 }
218
219 #ifdef CONFIG_X86
220
221 static DEFINE_MUTEX(performance_mutex);
222
acpi_processor_get_performance_control(struct acpi_processor * pr)223 static int acpi_processor_get_performance_control(struct acpi_processor *pr)
224 {
225 int result = 0;
226 acpi_status status = 0;
227 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
228 union acpi_object *pct = NULL;
229 union acpi_object obj = { 0 };
230
231 status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer);
232 if (ACPI_FAILURE(status)) {
233 acpi_evaluation_failure_warn(pr->handle, "_PCT", status);
234 return -ENODEV;
235 }
236
237 pct = (union acpi_object *)buffer.pointer;
238 if (!pct || pct->type != ACPI_TYPE_PACKAGE || pct->package.count != 2) {
239 pr_err("Invalid _PCT data\n");
240 result = -EFAULT;
241 goto end;
242 }
243
244 /*
245 * control_register
246 */
247
248 obj = pct->package.elements[0];
249
250 if (!obj.buffer.pointer || obj.type != ACPI_TYPE_BUFFER ||
251 obj.buffer.length < sizeof(struct acpi_pct_register)) {
252 pr_err("Invalid _PCT data (control_register)\n");
253 result = -EFAULT;
254 goto end;
255 }
256 memcpy(&pr->performance->control_register, obj.buffer.pointer,
257 sizeof(struct acpi_pct_register));
258
259 /*
260 * status_register
261 */
262
263 obj = pct->package.elements[1];
264
265 if (!obj.buffer.pointer || obj.type != ACPI_TYPE_BUFFER ||
266 obj.buffer.length < sizeof(struct acpi_pct_register)) {
267 pr_err("Invalid _PCT data (status_register)\n");
268 result = -EFAULT;
269 goto end;
270 }
271
272 memcpy(&pr->performance->status_register, obj.buffer.pointer,
273 sizeof(struct acpi_pct_register));
274
275 end:
276 kfree(buffer.pointer);
277
278 return result;
279 }
280
281 /*
282 * Some AMDs have 50MHz frequency multiples, but only provide 100MHz rounding
283 * in their ACPI data. Calculate the real values and fix up the _PSS data.
284 */
amd_fixup_frequency(struct acpi_processor_px * px,int i)285 static void amd_fixup_frequency(struct acpi_processor_px *px, int i)
286 {
287 u32 hi, lo, fid, did;
288 int index = px->control & 0x00000007;
289
290 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
291 return;
292
293 if ((boot_cpu_data.x86 == 0x10 && boot_cpu_data.x86_model < 10) ||
294 boot_cpu_data.x86 == 0x11) {
295 rdmsr(MSR_AMD_PSTATE_DEF_BASE + index, lo, hi);
296 /*
297 * MSR C001_0064+:
298 * Bit 63: PstateEn. Read-write. If set, the P-state is valid.
299 */
300 if (!(hi & BIT(31)))
301 return;
302
303 fid = lo & 0x3f;
304 did = (lo >> 6) & 7;
305 if (boot_cpu_data.x86 == 0x10)
306 px->core_frequency = (100 * (fid + 0x10)) >> did;
307 else
308 px->core_frequency = (100 * (fid + 8)) >> did;
309 }
310 }
311
acpi_processor_get_performance_states(struct acpi_processor * pr)312 static int acpi_processor_get_performance_states(struct acpi_processor *pr)
313 {
314 int result = 0;
315 acpi_status status = AE_OK;
316 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
317 struct acpi_buffer format = { sizeof("NNNNNN"), "NNNNNN" };
318 struct acpi_buffer state = { 0, NULL };
319 union acpi_object *pss = NULL;
320 int i;
321 int last_invalid = -1;
322
323 status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer);
324 if (ACPI_FAILURE(status)) {
325 acpi_evaluation_failure_warn(pr->handle, "_PSS", status);
326 return -ENODEV;
327 }
328
329 pss = buffer.pointer;
330 if (!pss || pss->type != ACPI_TYPE_PACKAGE) {
331 pr_err("Invalid _PSS data\n");
332 result = -EFAULT;
333 goto end;
334 }
335
336 acpi_handle_debug(pr->handle, "Found %d performance states\n",
337 pss->package.count);
338
339 pr->performance->state_count = pss->package.count;
340 pr->performance->states =
341 kmalloc_array(pss->package.count,
342 sizeof(struct acpi_processor_px),
343 GFP_KERNEL);
344 if (!pr->performance->states) {
345 result = -ENOMEM;
346 goto end;
347 }
348
349 for (i = 0; i < pr->performance->state_count; i++) {
350
351 struct acpi_processor_px *px = &(pr->performance->states[i]);
352
353 state.length = sizeof(struct acpi_processor_px);
354 state.pointer = px;
355
356 acpi_handle_debug(pr->handle, "Extracting state %d\n", i);
357
358 status = acpi_extract_package(&(pss->package.elements[i]),
359 &format, &state);
360 if (ACPI_FAILURE(status)) {
361 acpi_handle_warn(pr->handle, "Invalid _PSS data: %s\n",
362 acpi_format_exception(status));
363 result = -EFAULT;
364 kfree(pr->performance->states);
365 goto end;
366 }
367
368 amd_fixup_frequency(px, i);
369
370 acpi_handle_debug(pr->handle,
371 "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n",
372 i,
373 (u32) px->core_frequency,
374 (u32) px->power,
375 (u32) px->transition_latency,
376 (u32) px->bus_master_latency,
377 (u32) px->control, (u32) px->status);
378
379 /*
380 * Check that ACPI's u64 MHz will be valid as u32 KHz in cpufreq
381 */
382 if (!px->core_frequency ||
383 (u32)(px->core_frequency * 1000) != px->core_frequency * 1000) {
384 pr_err(FW_BUG
385 "Invalid BIOS _PSS frequency found for processor %d: 0x%llx MHz\n",
386 pr->id, px->core_frequency);
387 if (last_invalid == -1)
388 last_invalid = i;
389 } else {
390 if (last_invalid != -1) {
391 /*
392 * Copy this valid entry over last_invalid entry
393 */
394 memcpy(&(pr->performance->states[last_invalid]),
395 px, sizeof(struct acpi_processor_px));
396 ++last_invalid;
397 }
398 }
399 }
400
401 if (last_invalid == 0) {
402 pr_err(FW_BUG
403 "No valid BIOS _PSS frequency found for processor %d\n", pr->id);
404 result = -EFAULT;
405 kfree(pr->performance->states);
406 pr->performance->states = NULL;
407 }
408
409 if (last_invalid > 0)
410 pr->performance->state_count = last_invalid;
411
412 end:
413 kfree(buffer.pointer);
414
415 return result;
416 }
417
acpi_processor_get_performance_info(struct acpi_processor * pr)418 int acpi_processor_get_performance_info(struct acpi_processor *pr)
419 {
420 int result = 0;
421
422 if (!pr || !pr->performance || !pr->handle)
423 return -EINVAL;
424
425 if (!acpi_has_method(pr->handle, "_PCT")) {
426 acpi_handle_debug(pr->handle,
427 "ACPI-based processor performance control unavailable\n");
428 return -ENODEV;
429 }
430
431 result = acpi_processor_get_performance_control(pr);
432 if (result)
433 goto update_bios;
434
435 result = acpi_processor_get_performance_states(pr);
436 if (result)
437 goto update_bios;
438
439 /* We need to call _PPC once when cpufreq starts */
440 if (ignore_ppc != 1)
441 result = acpi_processor_get_platform_limit(pr);
442
443 return result;
444
445 /*
446 * Having _PPC but missing frequencies (_PSS, _PCT) is a very good hint that
447 * the BIOS is older than the CPU and does not know its frequencies
448 */
449 update_bios:
450 if (acpi_has_method(pr->handle, "_PPC")) {
451 if(boot_cpu_has(X86_FEATURE_EST))
452 pr_warn(FW_BUG "BIOS needs update for CPU "
453 "frequency support\n");
454 }
455 return result;
456 }
457 EXPORT_SYMBOL_GPL(acpi_processor_get_performance_info);
458
acpi_processor_pstate_control(void)459 int acpi_processor_pstate_control(void)
460 {
461 acpi_status status;
462
463 if (!acpi_gbl_FADT.smi_command || !acpi_gbl_FADT.pstate_control)
464 return 0;
465
466 pr_debug("Writing pstate_control [0x%x] to smi_command [0x%x]\n",
467 acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command);
468
469 status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
470 (u32)acpi_gbl_FADT.pstate_control, 8);
471 if (ACPI_SUCCESS(status))
472 return 1;
473
474 pr_warn("Failed to write pstate_control [0x%x] to smi_command [0x%x]: %s\n",
475 acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command,
476 acpi_format_exception(status));
477 return -EIO;
478 }
479
acpi_processor_notify_smm(struct module * calling_module)480 int acpi_processor_notify_smm(struct module *calling_module)
481 {
482 static int is_done;
483 int result = 0;
484
485 if (!acpi_processor_cpufreq_init)
486 return -EBUSY;
487
488 if (!try_module_get(calling_module))
489 return -EINVAL;
490
491 /*
492 * is_done is set to negative if an error occurs and to 1 if no error
493 * occurrs, but SMM has been notified already. This avoids repeated
494 * notification which might lead to unexpected results.
495 */
496 if (is_done != 0) {
497 if (is_done < 0)
498 result = is_done;
499
500 goto out_put;
501 }
502
503 result = acpi_processor_pstate_control();
504 if (result <= 0) {
505 if (result) {
506 is_done = result;
507 } else {
508 pr_debug("No SMI port or pstate_control\n");
509 is_done = 1;
510 }
511 goto out_put;
512 }
513
514 is_done = 1;
515 /*
516 * Success. If there _PPC, unloading the cpufreq driver would be risky,
517 * so disallow it in that case.
518 */
519 if (acpi_processor_ppc_in_use)
520 return 0;
521
522 out_put:
523 module_put(calling_module);
524 return result;
525 }
526 EXPORT_SYMBOL(acpi_processor_notify_smm);
527
acpi_processor_get_psd(acpi_handle handle,struct acpi_psd_package * pdomain)528 int acpi_processor_get_psd(acpi_handle handle, struct acpi_psd_package *pdomain)
529 {
530 int result = 0;
531 acpi_status status = AE_OK;
532 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
533 struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"};
534 struct acpi_buffer state = {0, NULL};
535 union acpi_object *psd = NULL;
536
537 status = acpi_evaluate_object(handle, "_PSD", NULL, &buffer);
538 if (ACPI_FAILURE(status)) {
539 return -ENODEV;
540 }
541
542 psd = buffer.pointer;
543 if (!psd || psd->type != ACPI_TYPE_PACKAGE) {
544 pr_err("Invalid _PSD data\n");
545 result = -EFAULT;
546 goto end;
547 }
548
549 if (psd->package.count != 1) {
550 pr_err("Invalid _PSD data\n");
551 result = -EFAULT;
552 goto end;
553 }
554
555 state.length = sizeof(struct acpi_psd_package);
556 state.pointer = pdomain;
557
558 status = acpi_extract_package(&(psd->package.elements[0]), &format, &state);
559 if (ACPI_FAILURE(status)) {
560 pr_err("Invalid _PSD data\n");
561 result = -EFAULT;
562 goto end;
563 }
564
565 if (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES) {
566 pr_err("Unknown _PSD:num_entries\n");
567 result = -EFAULT;
568 goto end;
569 }
570
571 if (pdomain->revision != ACPI_PSD_REV0_REVISION) {
572 pr_err("Unknown _PSD:revision\n");
573 result = -EFAULT;
574 goto end;
575 }
576
577 if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
578 pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
579 pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
580 pr_err("Invalid _PSD:coord_type\n");
581 result = -EFAULT;
582 goto end;
583 }
584 end:
585 kfree(buffer.pointer);
586 return result;
587 }
588 EXPORT_SYMBOL(acpi_processor_get_psd);
589
acpi_processor_preregister_performance(struct acpi_processor_performance __percpu * performance)590 int acpi_processor_preregister_performance(
591 struct acpi_processor_performance __percpu *performance)
592 {
593 int count_target;
594 int retval = 0;
595 unsigned int i, j;
596 cpumask_var_t covered_cpus;
597 struct acpi_processor *pr;
598 struct acpi_psd_package *pdomain;
599 struct acpi_processor *match_pr;
600 struct acpi_psd_package *match_pdomain;
601
602 if (!zalloc_cpumask_var(&covered_cpus, GFP_KERNEL))
603 return -ENOMEM;
604
605 mutex_lock(&performance_mutex);
606
607 /*
608 * Check if another driver has already registered, and abort before
609 * changing pr->performance if it has. Check input data as well.
610 */
611 for_each_possible_cpu(i) {
612 pr = per_cpu(processors, i);
613 if (!pr) {
614 /* Look only at processors in ACPI namespace */
615 continue;
616 }
617
618 if (pr->performance) {
619 retval = -EBUSY;
620 goto err_out;
621 }
622
623 if (!performance || !per_cpu_ptr(performance, i)) {
624 retval = -EINVAL;
625 goto err_out;
626 }
627 }
628
629 /* Call _PSD for all CPUs */
630 for_each_possible_cpu(i) {
631 pr = per_cpu(processors, i);
632 if (!pr)
633 continue;
634
635 pr->performance = per_cpu_ptr(performance, i);
636 pdomain = &(pr->performance->domain_info);
637 if (acpi_processor_get_psd(pr->handle, pdomain)) {
638 retval = -EINVAL;
639 continue;
640 }
641 }
642 if (retval)
643 goto err_ret;
644
645 /*
646 * Now that we have _PSD data from all CPUs, lets setup P-state
647 * domain info.
648 */
649 for_each_possible_cpu(i) {
650 pr = per_cpu(processors, i);
651 if (!pr)
652 continue;
653
654 if (cpumask_test_cpu(i, covered_cpus))
655 continue;
656
657 pdomain = &(pr->performance->domain_info);
658 cpumask_set_cpu(i, pr->performance->shared_cpu_map);
659 cpumask_set_cpu(i, covered_cpus);
660 if (pdomain->num_processors <= 1)
661 continue;
662
663 /* Validate the Domain info */
664 count_target = pdomain->num_processors;
665 if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL)
666 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
667 else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL)
668 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_HW;
669 else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY)
670 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY;
671
672 for_each_possible_cpu(j) {
673 if (i == j)
674 continue;
675
676 match_pr = per_cpu(processors, j);
677 if (!match_pr)
678 continue;
679
680 match_pdomain = &(match_pr->performance->domain_info);
681 if (match_pdomain->domain != pdomain->domain)
682 continue;
683
684 /* Here i and j are in the same domain */
685
686 if (match_pdomain->num_processors != count_target) {
687 retval = -EINVAL;
688 goto err_ret;
689 }
690
691 if (pdomain->coord_type != match_pdomain->coord_type) {
692 retval = -EINVAL;
693 goto err_ret;
694 }
695
696 cpumask_set_cpu(j, covered_cpus);
697 cpumask_set_cpu(j, pr->performance->shared_cpu_map);
698 }
699
700 for_each_possible_cpu(j) {
701 if (i == j)
702 continue;
703
704 match_pr = per_cpu(processors, j);
705 if (!match_pr)
706 continue;
707
708 match_pdomain = &(match_pr->performance->domain_info);
709 if (match_pdomain->domain != pdomain->domain)
710 continue;
711
712 match_pr->performance->shared_type =
713 pr->performance->shared_type;
714 cpumask_copy(match_pr->performance->shared_cpu_map,
715 pr->performance->shared_cpu_map);
716 }
717 }
718
719 err_ret:
720 for_each_possible_cpu(i) {
721 pr = per_cpu(processors, i);
722 if (!pr || !pr->performance)
723 continue;
724
725 /* Assume no coordination on any error parsing domain info */
726 if (retval) {
727 cpumask_clear(pr->performance->shared_cpu_map);
728 cpumask_set_cpu(i, pr->performance->shared_cpu_map);
729 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_NONE;
730 }
731 pr->performance = NULL; /* Will be set for real in register */
732 }
733
734 err_out:
735 mutex_unlock(&performance_mutex);
736 free_cpumask_var(covered_cpus);
737 return retval;
738 }
739 EXPORT_SYMBOL(acpi_processor_preregister_performance);
740
acpi_processor_register_performance(struct acpi_processor_performance * performance,unsigned int cpu)741 int acpi_processor_register_performance(struct acpi_processor_performance
742 *performance, unsigned int cpu)
743 {
744 struct acpi_processor *pr;
745
746 if (!acpi_processor_cpufreq_init)
747 return -EINVAL;
748
749 mutex_lock(&performance_mutex);
750
751 pr = per_cpu(processors, cpu);
752 if (!pr) {
753 mutex_unlock(&performance_mutex);
754 return -ENODEV;
755 }
756
757 if (pr->performance) {
758 mutex_unlock(&performance_mutex);
759 return -EBUSY;
760 }
761
762 WARN_ON(!performance);
763
764 pr->performance = performance;
765
766 if (acpi_processor_get_performance_info(pr)) {
767 pr->performance = NULL;
768 mutex_unlock(&performance_mutex);
769 return -EIO;
770 }
771
772 mutex_unlock(&performance_mutex);
773 return 0;
774 }
775 EXPORT_SYMBOL(acpi_processor_register_performance);
776
acpi_processor_unregister_performance(unsigned int cpu)777 void acpi_processor_unregister_performance(unsigned int cpu)
778 {
779 struct acpi_processor *pr;
780
781 mutex_lock(&performance_mutex);
782
783 pr = per_cpu(processors, cpu);
784 if (!pr)
785 goto unlock;
786
787 if (pr->performance)
788 kfree(pr->performance->states);
789
790 pr->performance = NULL;
791
792 unlock:
793 mutex_unlock(&performance_mutex);
794 }
795 EXPORT_SYMBOL(acpi_processor_unregister_performance);
796 #endif
797