processor_perflib.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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. int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
  134. {
  135. struct acpi_processor *pr;
  136. pr = per_cpu(processors, cpu);
  137. if (!pr || !pr->performance || !pr->performance->state_count)
  138. return -ENODEV;
  139. *limit = pr->performance->states[pr->performance_platform_limit].
  140. core_frequency * 1000;
  141. return 0;
  142. }
  143. EXPORT_SYMBOL(acpi_processor_get_bios_limit);
  144. void acpi_processor_ppc_init(void)
  145. {
  146. if (!cpufreq_register_notifier
  147. (&acpi_ppc_notifier_block, CPUFREQ_POLICY_NOTIFIER))
  148. acpi_processor_ppc_status |= PPC_REGISTERED;
  149. else
  150. printk(KERN_DEBUG
  151. "Warning: Processor Platform Limit not supported.\n");
  152. }
  153. void acpi_processor_ppc_exit(void)
  154. {
  155. if (acpi_processor_ppc_status & PPC_REGISTERED)
  156. cpufreq_unregister_notifier(&acpi_ppc_notifier_block,
  157. CPUFREQ_POLICY_NOTIFIER);
  158. acpi_processor_ppc_status &= ~PPC_REGISTERED;
  159. }
  160. static int acpi_processor_get_performance_control(struct acpi_processor *pr)
  161. {
  162. int result = 0;
  163. acpi_status status = 0;
  164. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  165. union acpi_object *pct = NULL;
  166. union acpi_object obj = { 0 };
  167. status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer);
  168. if (ACPI_FAILURE(status)) {
  169. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PCT"));
  170. return -ENODEV;
  171. }
  172. pct = (union acpi_object *)buffer.pointer;
  173. if (!pct || (pct->type != ACPI_TYPE_PACKAGE)
  174. || (pct->package.count != 2)) {
  175. printk(KERN_ERR PREFIX "Invalid _PCT data\n");
  176. result = -EFAULT;
  177. goto end;
  178. }
  179. /*
  180. * control_register
  181. */
  182. obj = pct->package.elements[0];
  183. if ((obj.type != ACPI_TYPE_BUFFER)
  184. || (obj.buffer.length < sizeof(struct acpi_pct_register))
  185. || (obj.buffer.pointer == NULL)) {
  186. printk(KERN_ERR PREFIX "Invalid _PCT data (control_register)\n");
  187. result = -EFAULT;
  188. goto end;
  189. }
  190. memcpy(&pr->performance->control_register, obj.buffer.pointer,
  191. sizeof(struct acpi_pct_register));
  192. /*
  193. * status_register
  194. */
  195. obj = pct->package.elements[1];
  196. if ((obj.type != ACPI_TYPE_BUFFER)
  197. || (obj.buffer.length < sizeof(struct acpi_pct_register))
  198. || (obj.buffer.pointer == NULL)) {
  199. printk(KERN_ERR PREFIX "Invalid _PCT data (status_register)\n");
  200. result = -EFAULT;
  201. goto end;
  202. }
  203. memcpy(&pr->performance->status_register, obj.buffer.pointer,
  204. sizeof(struct acpi_pct_register));
  205. end:
  206. kfree(buffer.pointer);
  207. return result;
  208. }
  209. static int acpi_processor_get_performance_states(struct acpi_processor *pr)
  210. {
  211. int result = 0;
  212. acpi_status status = AE_OK;
  213. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  214. struct acpi_buffer format = { sizeof("NNNNNN"), "NNNNNN" };
  215. struct acpi_buffer state = { 0, NULL };
  216. union acpi_object *pss = NULL;
  217. int i;
  218. status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer);
  219. if (ACPI_FAILURE(status)) {
  220. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PSS"));
  221. return -ENODEV;
  222. }
  223. pss = buffer.pointer;
  224. if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) {
  225. printk(KERN_ERR PREFIX "Invalid _PSS data\n");
  226. result = -EFAULT;
  227. goto end;
  228. }
  229. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d performance states\n",
  230. pss->package.count));
  231. pr->performance->state_count = pss->package.count;
  232. pr->performance->states =
  233. kmalloc(sizeof(struct acpi_processor_px) * pss->package.count,
  234. GFP_KERNEL);
  235. if (!pr->performance->states) {
  236. result = -ENOMEM;
  237. goto end;
  238. }
  239. for (i = 0; i < pr->performance->state_count; i++) {
  240. struct acpi_processor_px *px = &(pr->performance->states[i]);
  241. state.length = sizeof(struct acpi_processor_px);
  242. state.pointer = px;
  243. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i));
  244. status = acpi_extract_package(&(pss->package.elements[i]),
  245. &format, &state);
  246. if (ACPI_FAILURE(status)) {
  247. ACPI_EXCEPTION((AE_INFO, status, "Invalid _PSS data"));
  248. result = -EFAULT;
  249. kfree(pr->performance->states);
  250. goto end;
  251. }
  252. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  253. "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n",
  254. i,
  255. (u32) px->core_frequency,
  256. (u32) px->power,
  257. (u32) px->transition_latency,
  258. (u32) px->bus_master_latency,
  259. (u32) px->control, (u32) px->status));
  260. /*
  261. * Check that ACPI's u64 MHz will be valid as u32 KHz in cpufreq
  262. */
  263. if (!px->core_frequency ||
  264. ((u32)(px->core_frequency * 1000) !=
  265. (px->core_frequency * 1000))) {
  266. printk(KERN_ERR FW_BUG PREFIX
  267. "Invalid BIOS _PSS frequency: 0x%llx MHz\n",
  268. px->core_frequency);
  269. result = -EFAULT;
  270. kfree(pr->performance->states);
  271. goto end;
  272. }
  273. }
  274. end:
  275. kfree(buffer.pointer);
  276. return result;
  277. }
  278. static int acpi_processor_get_performance_info(struct acpi_processor *pr)
  279. {
  280. int result = 0;
  281. acpi_status status = AE_OK;
  282. acpi_handle handle = NULL;
  283. if (!pr || !pr->performance || !pr->handle)
  284. return -EINVAL;
  285. status = acpi_get_handle(pr->handle, "_PCT", &handle);
  286. if (ACPI_FAILURE(status)) {
  287. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  288. "ACPI-based processor performance control unavailable\n"));
  289. return -ENODEV;
  290. }
  291. result = acpi_processor_get_performance_control(pr);
  292. if (result)
  293. goto update_bios;
  294. result = acpi_processor_get_performance_states(pr);
  295. if (result)
  296. goto update_bios;
  297. return 0;
  298. /*
  299. * Having _PPC but missing frequencies (_PSS, _PCT) is a very good hint that
  300. * the BIOS is older than the CPU and does not know its frequencies
  301. */
  302. update_bios:
  303. #ifdef CONFIG_X86
  304. if (ACPI_SUCCESS(acpi_get_handle(pr->handle, "_PPC", &handle))){
  305. if(boot_cpu_has(X86_FEATURE_EST))
  306. printk(KERN_WARNING FW_BUG "BIOS needs update for CPU "
  307. "frequency support\n");
  308. }
  309. #endif
  310. return result;
  311. }
  312. int acpi_processor_notify_smm(struct module *calling_module)
  313. {
  314. acpi_status status;
  315. static int is_done = 0;
  316. if (!(acpi_processor_ppc_status & PPC_REGISTERED))
  317. return -EBUSY;
  318. if (!try_module_get(calling_module))
  319. return -EINVAL;
  320. /* is_done is set to negative if an error occured,
  321. * and to postitive if _no_ error occured, but SMM
  322. * was already notified. This avoids double notification
  323. * which might lead to unexpected results...
  324. */
  325. if (is_done > 0) {
  326. module_put(calling_module);
  327. return 0;
  328. } else if (is_done < 0) {
  329. module_put(calling_module);
  330. return is_done;
  331. }
  332. is_done = -EIO;
  333. /* Can't write pstate_control to smi_command if either value is zero */
  334. if ((!acpi_gbl_FADT.smi_command) || (!acpi_gbl_FADT.pstate_control)) {
  335. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_control\n"));
  336. module_put(calling_module);
  337. return 0;
  338. }
  339. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  340. "Writing pstate_control [0x%x] to smi_command [0x%x]\n",
  341. acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command));
  342. status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
  343. (u32) acpi_gbl_FADT.pstate_control, 8);
  344. if (ACPI_FAILURE(status)) {
  345. ACPI_EXCEPTION((AE_INFO, status,
  346. "Failed to write pstate_control [0x%x] to "
  347. "smi_command [0x%x]", acpi_gbl_FADT.pstate_control,
  348. acpi_gbl_FADT.smi_command));
  349. module_put(calling_module);
  350. return status;
  351. }
  352. /* Success. If there's no _PPC, we need to fear nothing, so
  353. * we can allow the cpufreq driver to be rmmod'ed. */
  354. is_done = 1;
  355. if (!(acpi_processor_ppc_status & PPC_IN_USE))
  356. module_put(calling_module);
  357. return 0;
  358. }
  359. EXPORT_SYMBOL(acpi_processor_notify_smm);
  360. static int acpi_processor_get_psd(struct acpi_processor *pr)
  361. {
  362. int result = 0;
  363. acpi_status status = AE_OK;
  364. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  365. struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"};
  366. struct acpi_buffer state = {0, NULL};
  367. union acpi_object *psd = NULL;
  368. struct acpi_psd_package *pdomain;
  369. status = acpi_evaluate_object(pr->handle, "_PSD", NULL, &buffer);
  370. if (ACPI_FAILURE(status)) {
  371. return -ENODEV;
  372. }
  373. psd = buffer.pointer;
  374. if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) {
  375. printk(KERN_ERR PREFIX "Invalid _PSD data\n");
  376. result = -EFAULT;
  377. goto end;
  378. }
  379. if (psd->package.count != 1) {
  380. printk(KERN_ERR PREFIX "Invalid _PSD data\n");
  381. result = -EFAULT;
  382. goto end;
  383. }
  384. pdomain = &(pr->performance->domain_info);
  385. state.length = sizeof(struct acpi_psd_package);
  386. state.pointer = pdomain;
  387. status = acpi_extract_package(&(psd->package.elements[0]),
  388. &format, &state);
  389. if (ACPI_FAILURE(status)) {
  390. printk(KERN_ERR PREFIX "Invalid _PSD data\n");
  391. result = -EFAULT;
  392. goto end;
  393. }
  394. if (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES) {
  395. printk(KERN_ERR PREFIX "Unknown _PSD:num_entries\n");
  396. result = -EFAULT;
  397. goto end;
  398. }
  399. if (pdomain->revision != ACPI_PSD_REV0_REVISION) {
  400. printk(KERN_ERR PREFIX "Unknown _PSD:revision\n");
  401. result = -EFAULT;
  402. goto end;
  403. }
  404. if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
  405. pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
  406. pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
  407. printk(KERN_ERR PREFIX "Invalid _PSD:coord_type\n");
  408. result = -EFAULT;
  409. goto end;
  410. }
  411. end:
  412. kfree(buffer.pointer);
  413. return result;
  414. }
  415. int acpi_processor_preregister_performance(
  416. struct acpi_processor_performance *performance)
  417. {
  418. int count, count_target;
  419. int retval = 0;
  420. unsigned int i, j;
  421. cpumask_var_t covered_cpus;
  422. struct acpi_processor *pr;
  423. struct acpi_psd_package *pdomain;
  424. struct acpi_processor *match_pr;
  425. struct acpi_psd_package *match_pdomain;
  426. if (!zalloc_cpumask_var(&covered_cpus, GFP_KERNEL))
  427. return -ENOMEM;
  428. mutex_lock(&performance_mutex);
  429. /*
  430. * Check if another driver has already registered, and abort before
  431. * changing pr->performance if it has. Check input data as well.
  432. */
  433. for_each_possible_cpu(i) {
  434. pr = per_cpu(processors, i);
  435. if (!pr) {
  436. /* Look only at processors in ACPI namespace */
  437. continue;
  438. }
  439. if (pr->performance) {
  440. retval = -EBUSY;
  441. goto err_out;
  442. }
  443. if (!performance || !per_cpu_ptr(performance, i)) {
  444. retval = -EINVAL;
  445. goto err_out;
  446. }
  447. }
  448. /* Call _PSD for all CPUs */
  449. for_each_possible_cpu(i) {
  450. pr = per_cpu(processors, i);
  451. if (!pr)
  452. continue;
  453. pr->performance = per_cpu_ptr(performance, i);
  454. cpumask_set_cpu(i, pr->performance->shared_cpu_map);
  455. if (acpi_processor_get_psd(pr)) {
  456. retval = -EINVAL;
  457. continue;
  458. }
  459. }
  460. if (retval)
  461. goto err_ret;
  462. /*
  463. * Now that we have _PSD data from all CPUs, lets setup P-state
  464. * domain info.
  465. */
  466. for_each_possible_cpu(i) {
  467. pr = per_cpu(processors, i);
  468. if (!pr)
  469. continue;
  470. if (cpumask_test_cpu(i, covered_cpus))
  471. continue;
  472. pdomain = &(pr->performance->domain_info);
  473. cpumask_set_cpu(i, pr->performance->shared_cpu_map);
  474. cpumask_set_cpu(i, covered_cpus);
  475. if (pdomain->num_processors <= 1)
  476. continue;
  477. /* Validate the Domain info */
  478. count_target = pdomain->num_processors;
  479. count = 1;
  480. if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL)
  481. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
  482. else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL)
  483. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_HW;
  484. else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY)
  485. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY;
  486. for_each_possible_cpu(j) {
  487. if (i == j)
  488. continue;
  489. match_pr = per_cpu(processors, j);
  490. if (!match_pr)
  491. continue;
  492. match_pdomain = &(match_pr->performance->domain_info);
  493. if (match_pdomain->domain != pdomain->domain)
  494. continue;
  495. /* Here i and j are in the same domain */
  496. if (match_pdomain->num_processors != count_target) {
  497. retval = -EINVAL;
  498. goto err_ret;
  499. }
  500. if (pdomain->coord_type != match_pdomain->coord_type) {
  501. retval = -EINVAL;
  502. goto err_ret;
  503. }
  504. cpumask_set_cpu(j, covered_cpus);
  505. cpumask_set_cpu(j, pr->performance->shared_cpu_map);
  506. count++;
  507. }
  508. for_each_possible_cpu(j) {
  509. if (i == j)
  510. continue;
  511. match_pr = per_cpu(processors, j);
  512. if (!match_pr)
  513. continue;
  514. match_pdomain = &(match_pr->performance->domain_info);
  515. if (match_pdomain->domain != pdomain->domain)
  516. continue;
  517. match_pr->performance->shared_type =
  518. pr->performance->shared_type;
  519. cpumask_copy(match_pr->performance->shared_cpu_map,
  520. pr->performance->shared_cpu_map);
  521. }
  522. }
  523. err_ret:
  524. for_each_possible_cpu(i) {
  525. pr = per_cpu(processors, i);
  526. if (!pr || !pr->performance)
  527. continue;
  528. /* Assume no coordination on any error parsing domain info */
  529. if (retval) {
  530. cpumask_clear(pr->performance->shared_cpu_map);
  531. cpumask_set_cpu(i, pr->performance->shared_cpu_map);
  532. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
  533. }
  534. pr->performance = NULL; /* Will be set for real in register */
  535. }
  536. err_out:
  537. mutex_unlock(&performance_mutex);
  538. free_cpumask_var(covered_cpus);
  539. return retval;
  540. }
  541. EXPORT_SYMBOL(acpi_processor_preregister_performance);
  542. int
  543. acpi_processor_register_performance(struct acpi_processor_performance
  544. *performance, unsigned int cpu)
  545. {
  546. struct acpi_processor *pr;
  547. if (!(acpi_processor_ppc_status & PPC_REGISTERED))
  548. return -EINVAL;
  549. mutex_lock(&performance_mutex);
  550. pr = per_cpu(processors, cpu);
  551. if (!pr) {
  552. mutex_unlock(&performance_mutex);
  553. return -ENODEV;
  554. }
  555. if (pr->performance) {
  556. mutex_unlock(&performance_mutex);
  557. return -EBUSY;
  558. }
  559. WARN_ON(!performance);
  560. pr->performance = performance;
  561. if (acpi_processor_get_performance_info(pr)) {
  562. pr->performance = NULL;
  563. mutex_unlock(&performance_mutex);
  564. return -EIO;
  565. }
  566. mutex_unlock(&performance_mutex);
  567. return 0;
  568. }
  569. EXPORT_SYMBOL(acpi_processor_register_performance);
  570. void
  571. acpi_processor_unregister_performance(struct acpi_processor_performance
  572. *performance, unsigned int cpu)
  573. {
  574. struct acpi_processor *pr;
  575. mutex_lock(&performance_mutex);
  576. pr = per_cpu(processors, cpu);
  577. if (!pr) {
  578. mutex_unlock(&performance_mutex);
  579. return;
  580. }
  581. if (pr->performance)
  582. kfree(pr->performance->states);
  583. pr->performance = NULL;
  584. mutex_unlock(&performance_mutex);
  585. return;
  586. }
  587. EXPORT_SYMBOL(acpi_processor_unregister_performance);