processor_perflib.c 18 KB

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