projects/linux·blob master · refs

798 lines · 19.3 KiB

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 <[email protected]>
6 * Copyright (C) 2001, 2002 Paul Diefenbaugh <[email protected]>
7 * Copyright (C) 2004 Dominik Brodowski <[email protected]>
8 * Copyright (C) 2004 Anil S Keshavamurthy <[email protected]>
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 */
44static int ignore_ppc = -1;
45module_param(ignore_ppc, int, 0644);
46MODULE_PARM_DESC(ignore_ppc, "If the frequency of your machine gets wrongly" \
47 "limited by BIOS, this should help");
48
49static bool acpi_processor_ppc_in_use;
50
51static 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 */
116static 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
123void 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
152int 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}
164EXPORT_SYMBOL(acpi_processor_get_bios_limit);
165
166void acpi_processor_ignore_ppc_init(void)
167{
168 if (ignore_ppc < 0)
169 ignore_ppc = 0;
170}
171
172void 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)
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 if (!pr->performance)
201 continue;
202
203 ret = acpi_processor_get_platform_limit(pr);
204 if (ret)
205 pr_err("Failed to update freq constraint for CPU%d (%d)\n",
206 cpu, ret);
207 }
208}
209
210void acpi_processor_ppc_exit(struct cpufreq_policy *policy)
211{
212 unsigned int cpu;
213
214 for_each_cpu(cpu, policy->related_cpus) {
215 struct acpi_processor *pr = per_cpu(processors, cpu);
216
217 if (pr)
218 freq_qos_remove_request(&pr->perflib_req);
219 }
220}
221
222#ifdef CONFIG_X86
223
224static DEFINE_MUTEX(performance_mutex);
225
226static int acpi_processor_get_performance_control(struct acpi_processor *pr)
227{
228 int result = 0;
229 acpi_status status = 0;
230 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
231 union acpi_object *pct = NULL;
232 union acpi_object obj = { 0 };
233
234 status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer);
235 if (ACPI_FAILURE(status)) {
236 acpi_evaluation_failure_warn(pr->handle, "_PCT", status);
237 return -ENODEV;
238 }
239
240 pct = (union acpi_object *)buffer.pointer;
241 if (!pct || pct->type != ACPI_TYPE_PACKAGE || pct->package.count != 2) {
242 pr_err("Invalid _PCT data\n");
243 result = -EFAULT;
244 goto end;
245 }
246
247 /*
248 * control_register
249 */
250
251 obj = pct->package.elements[0];
252
253 if (!obj.buffer.pointer || obj.type != ACPI_TYPE_BUFFER ||
254 obj.buffer.length < sizeof(struct acpi_pct_register)) {
255 pr_err("Invalid _PCT data (control_register)\n");
256 result = -EFAULT;
257 goto end;
258 }
259 memcpy(&pr->performance->control_register, obj.buffer.pointer,
260 sizeof(struct acpi_pct_register));
261
262 /*
263 * status_register
264 */
265
266 obj = pct->package.elements[1];
267
268 if (!obj.buffer.pointer || obj.type != ACPI_TYPE_BUFFER ||
269 obj.buffer.length < sizeof(struct acpi_pct_register)) {
270 pr_err("Invalid _PCT data (status_register)\n");
271 result = -EFAULT;
272 goto end;
273 }
274
275 memcpy(&pr->performance->status_register, obj.buffer.pointer,
276 sizeof(struct acpi_pct_register));
277
278end:
279 kfree(buffer.pointer);
280
281 return result;
282}
283
284/*
285 * Some AMDs have 50MHz frequency multiples, but only provide 100MHz rounding
286 * in their ACPI data. Calculate the real values and fix up the _PSS data.
287 */
288static void amd_fixup_frequency(struct acpi_processor_px *px, int i)
289{
290 struct msr val;
291 u32 fid, did;
292 int index = px->control & 0x00000007;
293
294 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
295 return;
296
297 if ((boot_cpu_data.x86 == 0x10 && boot_cpu_data.x86_model < 10) ||
298 boot_cpu_data.x86 == 0x11) {
299 rdmsrq(MSR_AMD_PSTATE_DEF_BASE + index, val.q);
300 /*
301 * MSR C001_0064+:
302 * Bit 63: PstateEn. Read-write. If set, the P-state is valid.
303 */
304 if (!(val.h & BIT(31)))
305 return;
306
307 fid = val.l & 0x3f;
308 did = (val.l >> 6) & 7;
309 if (boot_cpu_data.x86 == 0x10)
310 px->core_frequency = (100 * (fid + 0x10)) >> did;
311 else
312 px->core_frequency = (100 * (fid + 8)) >> did;
313 }
314}
315
316static int acpi_processor_get_performance_states(struct acpi_processor *pr)
317{
318 int result = 0;
319 acpi_status status = AE_OK;
320 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
321 struct acpi_buffer format = { sizeof("NNNNNN"), "NNNNNN" };
322 struct acpi_buffer state = { 0, NULL };
323 union acpi_object *pss = NULL;
324 int i;
325 int last_invalid = -1;
326
327 status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer);
328 if (ACPI_FAILURE(status)) {
329 acpi_evaluation_failure_warn(pr->handle, "_PSS", status);
330 return -ENODEV;
331 }
332
333 pss = buffer.pointer;
334 if (!pss || pss->type != ACPI_TYPE_PACKAGE) {
335 pr_err("Invalid _PSS data\n");
336 result = -EFAULT;
337 goto end;
338 }
339
340 acpi_handle_debug(pr->handle, "Found %d performance states\n",
341 pss->package.count);
342
343 pr->performance->state_count = pss->package.count;
344 pr->performance->states =
345 kmalloc_objs(struct acpi_processor_px, pss->package.count);
346 if (!pr->performance->states) {
347 result = -ENOMEM;
348 goto end;
349 }
350
351 for (i = 0; i < pr->performance->state_count; i++) {
352
353 struct acpi_processor_px *px = &(pr->performance->states[i]);
354
355 state.length = sizeof(struct acpi_processor_px);
356 state.pointer = px;
357
358 acpi_handle_debug(pr->handle, "Extracting state %d\n", i);
359
360 status = acpi_extract_package(&(pss->package.elements[i]),
361 &format, &state);
362 if (ACPI_FAILURE(status)) {
363 acpi_handle_warn(pr->handle, "Invalid _PSS data: %s\n",
364 acpi_format_exception(status));
365 result = -EFAULT;
366 kfree(pr->performance->states);
367 goto end;
368 }
369
370 amd_fixup_frequency(px, i);
371
372 acpi_handle_debug(pr->handle,
373 "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n",
374 i,
375 (u32) px->core_frequency,
376 (u32) px->power,
377 (u32) px->transition_latency,
378 (u32) px->bus_master_latency,
379 (u32) px->control, (u32) px->status);
380
381 /*
382 * Check that ACPI's u64 MHz will be valid as u32 KHz in cpufreq
383 */
384 if (!px->core_frequency ||
385 (u32)(px->core_frequency * 1000) != px->core_frequency * 1000) {
386 pr_err(FW_BUG
387 "Invalid BIOS _PSS frequency found for processor %d: 0x%llx MHz\n",
388 pr->id, px->core_frequency);
389 if (last_invalid == -1)
390 last_invalid = i;
391 } else {
392 if (last_invalid != -1) {
393 /*
394 * Copy this valid entry over last_invalid entry
395 */
396 memcpy(&(pr->performance->states[last_invalid]),
397 px, sizeof(struct acpi_processor_px));
398 ++last_invalid;
399 }
400 }
401 }
402
403 if (last_invalid == 0) {
404 pr_err(FW_BUG
405 "No valid BIOS _PSS frequency found for processor %d\n", pr->id);
406 result = -EFAULT;
407 kfree(pr->performance->states);
408 pr->performance->states = NULL;
409 }
410
411 if (last_invalid > 0)
412 pr->performance->state_count = last_invalid;
413
414end:
415 kfree(buffer.pointer);
416
417 return result;
418}
419
420int acpi_processor_get_performance_info(struct acpi_processor *pr)
421{
422 int result = 0;
423
424 if (!pr || !pr->performance || !pr->handle)
425 return -EINVAL;
426
427 if (!acpi_has_method(pr->handle, "_PCT")) {
428 acpi_handle_debug(pr->handle,
429 "ACPI-based processor performance control unavailable\n");
430 return -ENODEV;
431 }
432
433 result = acpi_processor_get_performance_control(pr);
434 if (result)
435 goto update_bios;
436
437 result = acpi_processor_get_performance_states(pr);
438 if (result)
439 goto update_bios;
440
441 /* We need to call _PPC once when cpufreq starts */
442 if (ignore_ppc != 1)
443 result = acpi_processor_get_platform_limit(pr);
444
445 return result;
446
447 /*
448 * Having _PPC but missing frequencies (_PSS, _PCT) is a very good hint that
449 * the BIOS is older than the CPU and does not know its frequencies
450 */
451 update_bios:
452 if (acpi_has_method(pr->handle, "_PPC")) {
453 if(boot_cpu_has(X86_FEATURE_EST))
454 pr_warn(FW_BUG "BIOS needs update for CPU "
455 "frequency support\n");
456 }
457 return result;
458}
459EXPORT_SYMBOL_GPL(acpi_processor_get_performance_info);
460
461int acpi_processor_pstate_control(void)
462{
463 acpi_status status;
464
465 if (!acpi_gbl_FADT.smi_command || !acpi_gbl_FADT.pstate_control)
466 return 0;
467
468 pr_debug("Writing pstate_control [0x%x] to smi_command [0x%x]\n",
469 acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command);
470
471 status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
472 (u32)acpi_gbl_FADT.pstate_control, 8);
473 if (ACPI_SUCCESS(status))
474 return 1;
475
476 pr_warn("Failed to write pstate_control [0x%x] to smi_command [0x%x]: %s\n",
477 acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command,
478 acpi_format_exception(status));
479 return -EIO;
480}
481
482int acpi_processor_notify_smm(struct module *calling_module)
483{
484 static int is_done;
485 int result = 0;
486
487 if (!acpi_processor_cpufreq_init)
488 return -EBUSY;
489
490 if (!try_module_get(calling_module))
491 return -EINVAL;
492
493 /*
494 * is_done is set to negative if an error occurs and to 1 if no error
495 * occurrs, but SMM has been notified already. This avoids repeated
496 * notification which might lead to unexpected results.
497 */
498 if (is_done != 0) {
499 if (is_done < 0)
500 result = is_done;
501
502 goto out_put;
503 }
504
505 result = acpi_processor_pstate_control();
506 if (result <= 0) {
507 if (result) {
508 is_done = result;
509 } else {
510 pr_debug("No SMI port or pstate_control\n");
511 is_done = 1;
512 }
513 goto out_put;
514 }
515
516 is_done = 1;
517 /*
518 * Success. If there _PPC, unloading the cpufreq driver would be risky,
519 * so disallow it in that case.
520 */
521 if (acpi_processor_ppc_in_use)
522 return 0;
523
524out_put:
525 module_put(calling_module);
526 return result;
527}
528EXPORT_SYMBOL(acpi_processor_notify_smm);
529
530int acpi_processor_get_psd(acpi_handle handle, struct acpi_psd_package *pdomain)
531{
532 int result = 0;
533 acpi_status status = AE_OK;
534 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
535 struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"};
536 struct acpi_buffer state = {0, NULL};
537 union acpi_object *psd = NULL;
538
539 status = acpi_evaluate_object(handle, "_PSD", NULL, &buffer);
540 if (ACPI_FAILURE(status)) {
541 return -ENODEV;
542 }
543
544 psd = buffer.pointer;
545 if (!psd || psd->type != ACPI_TYPE_PACKAGE) {
546 pr_err("Invalid _PSD data\n");
547 result = -EFAULT;
548 goto end;
549 }
550
551 if (psd->package.count != 1) {
552 pr_err("Invalid _PSD data\n");
553 result = -EFAULT;
554 goto end;
555 }
556
557 state.length = sizeof(struct acpi_psd_package);
558 state.pointer = pdomain;
559
560 status = acpi_extract_package(&(psd->package.elements[0]), &format, &state);
561 if (ACPI_FAILURE(status)) {
562 pr_err("Invalid _PSD data\n");
563 result = -EFAULT;
564 goto end;
565 }
566
567 if (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES) {
568 pr_err("Unknown _PSD:num_entries\n");
569 result = -EFAULT;
570 goto end;
571 }
572
573 if (pdomain->revision != ACPI_PSD_REV0_REVISION) {
574 pr_err("Unknown _PSD:revision\n");
575 result = -EFAULT;
576 goto end;
577 }
578
579 if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
580 pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
581 pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
582 pr_err("Invalid _PSD:coord_type\n");
583 result = -EFAULT;
584 goto end;
585 }
586end:
587 kfree(buffer.pointer);
588 return result;
589}
590EXPORT_SYMBOL(acpi_processor_get_psd);
591
592int acpi_processor_preregister_performance(
593 struct acpi_processor_performance __percpu *performance)
594{
595 int count_target;
596 int retval = 0;
597 unsigned int i, j;
598 cpumask_var_t covered_cpus;
599 struct acpi_processor *pr;
600 struct acpi_psd_package *pdomain;
601 struct acpi_processor *match_pr;
602 struct acpi_psd_package *match_pdomain;
603
604 if (!zalloc_cpumask_var(&covered_cpus, GFP_KERNEL))
605 return -ENOMEM;
606
607 mutex_lock(&performance_mutex);
608
609 /*
610 * Check if another driver has already registered, and abort before
611 * changing pr->performance if it has. Check input data as well.
612 */
613 for_each_possible_cpu(i) {
614 pr = per_cpu(processors, i);
615 if (!pr) {
616 /* Look only at processors in ACPI namespace */
617 continue;
618 }
619
620 if (pr->performance) {
621 retval = -EBUSY;
622 goto err_out;
623 }
624
625 if (!performance || !per_cpu_ptr(performance, i)) {
626 retval = -EINVAL;
627 goto err_out;
628 }
629 }
630
631 /* Call _PSD for all CPUs */
632 for_each_possible_cpu(i) {
633 pr = per_cpu(processors, i);
634 if (!pr)
635 continue;
636
637 pr->performance = per_cpu_ptr(performance, i);
638 pdomain = &(pr->performance->domain_info);
639 if (acpi_processor_get_psd(pr->handle, pdomain)) {
640 retval = -EINVAL;
641 continue;
642 }
643 }
644 if (retval)
645 goto err_ret;
646
647 /*
648 * Now that we have _PSD data from all CPUs, lets setup P-state
649 * domain info.
650 */
651 for_each_possible_cpu(i) {
652 pr = per_cpu(processors, i);
653 if (!pr)
654 continue;
655
656 if (cpumask_test_cpu(i, covered_cpus))
657 continue;
658
659 pdomain = &(pr->performance->domain_info);
660 cpumask_set_cpu(i, pr->performance->shared_cpu_map);
661 cpumask_set_cpu(i, covered_cpus);
662 if (pdomain->num_processors <= 1)
663 continue;
664
665 /* Validate the Domain info */
666 count_target = pdomain->num_processors;
667 if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL)
668 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
669 else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL)
670 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_HW;
671 else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY)
672 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY;
673
674 for_each_possible_cpu(j) {
675 if (i == j)
676 continue;
677
678 match_pr = per_cpu(processors, j);
679 if (!match_pr)
680 continue;
681
682 match_pdomain = &(match_pr->performance->domain_info);
683 if (match_pdomain->domain != pdomain->domain)
684 continue;
685
686 /* Here i and j are in the same domain */
687
688 if (match_pdomain->num_processors != count_target) {
689 retval = -EINVAL;
690 goto err_ret;
691 }
692
693 if (pdomain->coord_type != match_pdomain->coord_type) {
694 retval = -EINVAL;
695 goto err_ret;
696 }
697
698 cpumask_set_cpu(j, covered_cpus);
699 cpumask_set_cpu(j, pr->performance->shared_cpu_map);
700 }
701
702 for_each_possible_cpu(j) {
703 if (i == j)
704 continue;
705
706 match_pr = per_cpu(processors, j);
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 cpumask_copy(match_pr->performance->shared_cpu_map,
717 pr->performance->shared_cpu_map);
718 }
719 }
720
721err_ret:
722 for_each_possible_cpu(i) {
723 pr = per_cpu(processors, i);
724 if (!pr || !pr->performance)
725 continue;
726
727 /* Assume no coordination on any error parsing domain info */
728 if (retval) {
729 cpumask_clear(pr->performance->shared_cpu_map);
730 cpumask_set_cpu(i, pr->performance->shared_cpu_map);
731 pr->performance->shared_type = CPUFREQ_SHARED_TYPE_NONE;
732 }
733 pr->performance = NULL; /* Will be set for real in register */
734 }
735
736err_out:
737 mutex_unlock(&performance_mutex);
738 free_cpumask_var(covered_cpus);
739 return retval;
740}
741EXPORT_SYMBOL(acpi_processor_preregister_performance);
742
743int acpi_processor_register_performance(struct acpi_processor_performance
744 *performance, unsigned int cpu)
745{
746 struct acpi_processor *pr;
747
748 if (!acpi_processor_cpufreq_init)
749 return -EINVAL;
750
751 mutex_lock(&performance_mutex);
752
753 pr = per_cpu(processors, cpu);
754 if (!pr) {
755 mutex_unlock(&performance_mutex);
756 return -ENODEV;
757 }
758
759 if (pr->performance) {
760 mutex_unlock(&performance_mutex);
761 return -EBUSY;
762 }
763
764 WARN_ON(!performance);
765
766 pr->performance = performance;
767
768 if (acpi_processor_get_performance_info(pr)) {
769 pr->performance = NULL;
770 mutex_unlock(&performance_mutex);
771 return -EIO;
772 }
773
774 mutex_unlock(&performance_mutex);
775 return 0;
776}
777EXPORT_SYMBOL(acpi_processor_register_performance);
778
779void acpi_processor_unregister_performance(unsigned int cpu)
780{
781 struct acpi_processor *pr;
782
783 mutex_lock(&performance_mutex);
784
785 pr = per_cpu(processors, cpu);
786 if (!pr)
787 goto unlock;
788
789 if (pr->performance)
790 kfree(pr->performance->states);
791
792 pr->performance = NULL;
793
794unlock:
795 mutex_unlock(&performance_mutex);
796}
797EXPORT_SYMBOL(acpi_processor_unregister_performance);
798#endif