processor_perflib.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. /*
  249. * Check that ACPI's u64 MHz will be valid as u32 KHz in cpufreq
  250. */
  251. if (!px->core_frequency ||
  252. ((u32)(px->core_frequency * 1000) !=
  253. (px->core_frequency * 1000))) {
  254. printk(KERN_ERR FW_BUG PREFIX
  255. "Invalid BIOS _PSS frequency: 0x%llx MHz\n",
  256. px->core_frequency);
  257. result = -EFAULT;
  258. kfree(pr->performance->states);
  259. goto end;
  260. }
  261. }
  262. end:
  263. kfree(buffer.pointer);
  264. return result;
  265. }
  266. static int acpi_processor_get_performance_info(struct acpi_processor *pr)
  267. {
  268. int result = 0;
  269. acpi_status status = AE_OK;
  270. acpi_handle handle = NULL;
  271. if (!pr || !pr->performance || !pr->handle)
  272. return -EINVAL;
  273. status = acpi_get_handle(pr->handle, "_PCT", &handle);
  274. if (ACPI_FAILURE(status)) {
  275. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  276. "ACPI-based processor performance control unavailable\n"));
  277. return -ENODEV;
  278. }
  279. result = acpi_processor_get_performance_control(pr);
  280. if (result)
  281. goto update_bios;
  282. result = acpi_processor_get_performance_states(pr);
  283. if (result)
  284. goto update_bios;
  285. return 0;
  286. /*
  287. * Having _PPC but missing frequencies (_PSS, _PCT) is a very good hint that
  288. * the BIOS is older than the CPU and does not know its frequencies
  289. */
  290. update_bios:
  291. #ifdef CONFIG_X86
  292. if (ACPI_SUCCESS(acpi_get_handle(pr->handle, "_PPC", &handle))){
  293. if(boot_cpu_has(X86_FEATURE_EST))
  294. printk(KERN_WARNING FW_BUG "BIOS needs update for CPU "
  295. "frequency support\n");
  296. }
  297. #endif
  298. return result;
  299. }
  300. int acpi_processor_notify_smm(struct module *calling_module)
  301. {
  302. acpi_status status;
  303. static int is_done = 0;
  304. if (!(acpi_processor_ppc_status & PPC_REGISTERED))
  305. return -EBUSY;
  306. if (!try_module_get(calling_module))
  307. return -EINVAL;
  308. /* is_done is set to negative if an error occured,
  309. * and to postitive if _no_ error occured, but SMM
  310. * was already notified. This avoids double notification
  311. * which might lead to unexpected results...
  312. */
  313. if (is_done > 0) {
  314. module_put(calling_module);
  315. return 0;
  316. } else if (is_done < 0) {
  317. module_put(calling_module);
  318. return is_done;
  319. }
  320. is_done = -EIO;
  321. /* Can't write pstate_control to smi_command if either value is zero */
  322. if ((!acpi_gbl_FADT.smi_command) || (!acpi_gbl_FADT.pstate_control)) {
  323. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_control\n"));
  324. module_put(calling_module);
  325. return 0;
  326. }
  327. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  328. "Writing pstate_control [0x%x] to smi_command [0x%x]\n",
  329. acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command));
  330. status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
  331. (u32) acpi_gbl_FADT.pstate_control, 8);
  332. if (ACPI_FAILURE(status)) {
  333. ACPI_EXCEPTION((AE_INFO, status,
  334. "Failed to write pstate_control [0x%x] to "
  335. "smi_command [0x%x]", acpi_gbl_FADT.pstate_control,
  336. acpi_gbl_FADT.smi_command));
  337. module_put(calling_module);
  338. return status;
  339. }
  340. /* Success. If there's no _PPC, we need to fear nothing, so
  341. * we can allow the cpufreq driver to be rmmod'ed. */
  342. is_done = 1;
  343. if (!(acpi_processor_ppc_status & PPC_IN_USE))
  344. module_put(calling_module);
  345. return 0;
  346. }
  347. EXPORT_SYMBOL(acpi_processor_notify_smm);
  348. static int acpi_processor_get_psd(struct acpi_processor *pr)
  349. {
  350. int result = 0;
  351. acpi_status status = AE_OK;
  352. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  353. struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"};
  354. struct acpi_buffer state = {0, NULL};
  355. union acpi_object *psd = NULL;
  356. struct acpi_psd_package *pdomain;
  357. status = acpi_evaluate_object(pr->handle, "_PSD", NULL, &buffer);
  358. if (ACPI_FAILURE(status)) {
  359. return -ENODEV;
  360. }
  361. psd = buffer.pointer;
  362. if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) {
  363. printk(KERN_ERR PREFIX "Invalid _PSD data\n");
  364. result = -EFAULT;
  365. goto end;
  366. }
  367. if (psd->package.count != 1) {
  368. printk(KERN_ERR PREFIX "Invalid _PSD data\n");
  369. result = -EFAULT;
  370. goto end;
  371. }
  372. pdomain = &(pr->performance->domain_info);
  373. state.length = sizeof(struct acpi_psd_package);
  374. state.pointer = pdomain;
  375. status = acpi_extract_package(&(psd->package.elements[0]),
  376. &format, &state);
  377. if (ACPI_FAILURE(status)) {
  378. printk(KERN_ERR PREFIX "Invalid _PSD data\n");
  379. result = -EFAULT;
  380. goto end;
  381. }
  382. if (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES) {
  383. printk(KERN_ERR PREFIX "Unknown _PSD:num_entries\n");
  384. result = -EFAULT;
  385. goto end;
  386. }
  387. if (pdomain->revision != ACPI_PSD_REV0_REVISION) {
  388. printk(KERN_ERR PREFIX "Unknown _PSD:revision\n");
  389. result = -EFAULT;
  390. goto end;
  391. }
  392. if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
  393. pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
  394. pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
  395. printk(KERN_ERR PREFIX "Invalid _PSD:coord_type\n");
  396. result = -EFAULT;
  397. goto end;
  398. }
  399. end:
  400. kfree(buffer.pointer);
  401. return result;
  402. }
  403. int acpi_processor_preregister_performance(
  404. struct acpi_processor_performance *performance)
  405. {
  406. int count, count_target;
  407. int retval = 0;
  408. unsigned int i, j;
  409. cpumask_var_t covered_cpus;
  410. struct acpi_processor *pr;
  411. struct acpi_psd_package *pdomain;
  412. struct acpi_processor *match_pr;
  413. struct acpi_psd_package *match_pdomain;
  414. if (!alloc_cpumask_var(&covered_cpus, GFP_KERNEL))
  415. return -ENOMEM;
  416. mutex_lock(&performance_mutex);
  417. /*
  418. * Check if another driver has already registered, and abort before
  419. * changing pr->performance if it has. Check input data as well.
  420. */
  421. for_each_possible_cpu(i) {
  422. pr = per_cpu(processors, i);
  423. if (!pr) {
  424. /* Look only at processors in ACPI namespace */
  425. continue;
  426. }
  427. if (pr->performance) {
  428. retval = -EBUSY;
  429. goto err_out;
  430. }
  431. if (!performance || !per_cpu_ptr(performance, i)) {
  432. retval = -EINVAL;
  433. goto err_out;
  434. }
  435. }
  436. /* Call _PSD for all CPUs */
  437. for_each_possible_cpu(i) {
  438. pr = per_cpu(processors, i);
  439. if (!pr)
  440. continue;
  441. pr->performance = per_cpu_ptr(performance, i);
  442. cpumask_set_cpu(i, pr->performance->shared_cpu_map);
  443. if (acpi_processor_get_psd(pr)) {
  444. retval = -EINVAL;
  445. continue;
  446. }
  447. }
  448. if (retval)
  449. goto err_ret;
  450. /*
  451. * Now that we have _PSD data from all CPUs, lets setup P-state
  452. * domain info.
  453. */
  454. cpumask_clear(covered_cpus);
  455. for_each_possible_cpu(i) {
  456. pr = per_cpu(processors, i);
  457. if (!pr)
  458. continue;
  459. if (cpumask_test_cpu(i, covered_cpus))
  460. continue;
  461. pdomain = &(pr->performance->domain_info);
  462. cpumask_set_cpu(i, pr->performance->shared_cpu_map);
  463. cpumask_set_cpu(i, covered_cpus);
  464. if (pdomain->num_processors <= 1)
  465. continue;
  466. /* Validate the Domain info */
  467. count_target = pdomain->num_processors;
  468. count = 1;
  469. if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL)
  470. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
  471. else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL)
  472. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_HW;
  473. else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY)
  474. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY;
  475. for_each_possible_cpu(j) {
  476. if (i == j)
  477. continue;
  478. match_pr = per_cpu(processors, j);
  479. if (!match_pr)
  480. continue;
  481. match_pdomain = &(match_pr->performance->domain_info);
  482. if (match_pdomain->domain != pdomain->domain)
  483. continue;
  484. /* Here i and j are in the same domain */
  485. if (match_pdomain->num_processors != count_target) {
  486. retval = -EINVAL;
  487. goto err_ret;
  488. }
  489. if (pdomain->coord_type != match_pdomain->coord_type) {
  490. retval = -EINVAL;
  491. goto err_ret;
  492. }
  493. cpumask_set_cpu(j, covered_cpus);
  494. cpumask_set_cpu(j, pr->performance->shared_cpu_map);
  495. count++;
  496. }
  497. for_each_possible_cpu(j) {
  498. if (i == j)
  499. continue;
  500. match_pr = per_cpu(processors, j);
  501. if (!match_pr)
  502. continue;
  503. match_pdomain = &(match_pr->performance->domain_info);
  504. if (match_pdomain->domain != pdomain->domain)
  505. continue;
  506. match_pr->performance->shared_type =
  507. pr->performance->shared_type;
  508. cpumask_copy(match_pr->performance->shared_cpu_map,
  509. pr->performance->shared_cpu_map);
  510. }
  511. }
  512. err_ret:
  513. for_each_possible_cpu(i) {
  514. pr = per_cpu(processors, i);
  515. if (!pr || !pr->performance)
  516. continue;
  517. /* Assume no coordination on any error parsing domain info */
  518. if (retval) {
  519. cpumask_clear(pr->performance->shared_cpu_map);
  520. cpumask_set_cpu(i, pr->performance->shared_cpu_map);
  521. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
  522. }
  523. pr->performance = NULL; /* Will be set for real in register */
  524. }
  525. err_out:
  526. mutex_unlock(&performance_mutex);
  527. free_cpumask_var(covered_cpus);
  528. return retval;
  529. }
  530. EXPORT_SYMBOL(acpi_processor_preregister_performance);
  531. int
  532. acpi_processor_register_performance(struct acpi_processor_performance
  533. *performance, unsigned int cpu)
  534. {
  535. struct acpi_processor *pr;
  536. if (!(acpi_processor_ppc_status & PPC_REGISTERED))
  537. return -EINVAL;
  538. mutex_lock(&performance_mutex);
  539. pr = per_cpu(processors, cpu);
  540. if (!pr) {
  541. mutex_unlock(&performance_mutex);
  542. return -ENODEV;
  543. }
  544. if (pr->performance) {
  545. mutex_unlock(&performance_mutex);
  546. return -EBUSY;
  547. }
  548. WARN_ON(!performance);
  549. pr->performance = performance;
  550. if (acpi_processor_get_performance_info(pr)) {
  551. pr->performance = NULL;
  552. mutex_unlock(&performance_mutex);
  553. return -EIO;
  554. }
  555. mutex_unlock(&performance_mutex);
  556. return 0;
  557. }
  558. EXPORT_SYMBOL(acpi_processor_register_performance);
  559. void
  560. acpi_processor_unregister_performance(struct acpi_processor_performance
  561. *performance, unsigned int cpu)
  562. {
  563. struct acpi_processor *pr;
  564. mutex_lock(&performance_mutex);
  565. pr = per_cpu(processors, cpu);
  566. if (!pr) {
  567. mutex_unlock(&performance_mutex);
  568. return;
  569. }
  570. if (pr->performance)
  571. kfree(pr->performance->states);
  572. pr->performance = NULL;
  573. mutex_unlock(&performance_mutex);
  574. return;
  575. }
  576. EXPORT_SYMBOL(acpi_processor_unregister_performance);