processor_perflib.c 18 KB

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