processor_perflib.c 18 KB

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