processor_perflib.c 19 KB

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