processor_perflib.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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. /* Use cpufreq debug layer for _PPC changes. */
  47. #define cpufreq_printk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, \
  48. "cpufreq-core", msg)
  49. /*
  50. * _PPC support is implemented as a CPUfreq policy notifier:
  51. * This means each time a CPUfreq driver registered also with
  52. * the ACPI core is asked to change the speed policy, the maximum
  53. * value is adjusted so that it is within the platform limit.
  54. *
  55. * Also, when a new platform limit value is detected, the CPUfreq
  56. * policy is adjusted accordingly.
  57. */
  58. static unsigned int ignore_ppc = 0;
  59. module_param(ignore_ppc, uint, 0644);
  60. MODULE_PARM_DESC(ignore_ppc, "If the frequency of your machine gets wrongly" \
  61. "limited by BIOS, this should help");
  62. #define PPC_REGISTERED 1
  63. #define PPC_IN_USE 2
  64. static int acpi_processor_ppc_status = 0;
  65. static int acpi_processor_ppc_notifier(struct notifier_block *nb,
  66. unsigned long event, void *data)
  67. {
  68. struct cpufreq_policy *policy = data;
  69. struct acpi_processor *pr;
  70. unsigned int ppc = 0;
  71. if (ignore_ppc)
  72. return 0;
  73. mutex_lock(&performance_mutex);
  74. if (event != CPUFREQ_INCOMPATIBLE)
  75. goto out;
  76. pr = per_cpu(processors, policy->cpu);
  77. if (!pr || !pr->performance)
  78. goto out;
  79. ppc = (unsigned int)pr->performance_platform_limit;
  80. if (ppc >= pr->performance->state_count)
  81. goto out;
  82. cpufreq_verify_within_limits(policy, 0,
  83. pr->performance->states[ppc].
  84. core_frequency * 1000);
  85. out:
  86. mutex_unlock(&performance_mutex);
  87. return 0;
  88. }
  89. static struct notifier_block acpi_ppc_notifier_block = {
  90. .notifier_call = acpi_processor_ppc_notifier,
  91. };
  92. static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
  93. {
  94. acpi_status status = 0;
  95. unsigned long ppc = 0;
  96. if (!pr)
  97. return -EINVAL;
  98. /*
  99. * _PPC indicates the maximum state currently supported by the platform
  100. * (e.g. 0 = states 0..n; 1 = states 1..n; etc.
  101. */
  102. status = acpi_evaluate_integer(pr->handle, "_PPC", NULL, &ppc);
  103. if (status != AE_NOT_FOUND)
  104. acpi_processor_ppc_status |= PPC_IN_USE;
  105. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  106. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PPC"));
  107. return -ENODEV;
  108. }
  109. cpufreq_printk("CPU %d: _PPC is %d - frequency %s limited\n", pr->id,
  110. (int)ppc, ppc ? "" : "not");
  111. pr->performance_platform_limit = (int)ppc;
  112. return 0;
  113. }
  114. int acpi_processor_ppc_has_changed(struct acpi_processor *pr)
  115. {
  116. int ret;
  117. if (ignore_ppc)
  118. return 0;
  119. ret = acpi_processor_get_platform_limit(pr);
  120. if (ret < 0)
  121. return (ret);
  122. else
  123. return cpufreq_update_policy(pr->id);
  124. }
  125. void acpi_processor_ppc_init(void)
  126. {
  127. if (!cpufreq_register_notifier
  128. (&acpi_ppc_notifier_block, CPUFREQ_POLICY_NOTIFIER))
  129. acpi_processor_ppc_status |= PPC_REGISTERED;
  130. else
  131. printk(KERN_DEBUG
  132. "Warning: Processor Platform Limit not supported.\n");
  133. }
  134. void acpi_processor_ppc_exit(void)
  135. {
  136. if (acpi_processor_ppc_status & PPC_REGISTERED)
  137. cpufreq_unregister_notifier(&acpi_ppc_notifier_block,
  138. CPUFREQ_POLICY_NOTIFIER);
  139. acpi_processor_ppc_status &= ~PPC_REGISTERED;
  140. }
  141. static int acpi_processor_get_performance_control(struct acpi_processor *pr)
  142. {
  143. int result = 0;
  144. acpi_status status = 0;
  145. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  146. union acpi_object *pct = NULL;
  147. union acpi_object obj = { 0 };
  148. status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer);
  149. if (ACPI_FAILURE(status)) {
  150. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PCT"));
  151. return -ENODEV;
  152. }
  153. pct = (union acpi_object *)buffer.pointer;
  154. if (!pct || (pct->type != ACPI_TYPE_PACKAGE)
  155. || (pct->package.count != 2)) {
  156. printk(KERN_ERR PREFIX "Invalid _PCT data\n");
  157. result = -EFAULT;
  158. goto end;
  159. }
  160. /*
  161. * control_register
  162. */
  163. obj = pct->package.elements[0];
  164. if ((obj.type != ACPI_TYPE_BUFFER)
  165. || (obj.buffer.length < sizeof(struct acpi_pct_register))
  166. || (obj.buffer.pointer == NULL)) {
  167. printk(KERN_ERR PREFIX "Invalid _PCT data (control_register)\n");
  168. result = -EFAULT;
  169. goto end;
  170. }
  171. memcpy(&pr->performance->control_register, obj.buffer.pointer,
  172. sizeof(struct acpi_pct_register));
  173. /*
  174. * status_register
  175. */
  176. obj = pct->package.elements[1];
  177. if ((obj.type != ACPI_TYPE_BUFFER)
  178. || (obj.buffer.length < sizeof(struct acpi_pct_register))
  179. || (obj.buffer.pointer == NULL)) {
  180. printk(KERN_ERR PREFIX "Invalid _PCT data (status_register)\n");
  181. result = -EFAULT;
  182. goto end;
  183. }
  184. memcpy(&pr->performance->status_register, obj.buffer.pointer,
  185. sizeof(struct acpi_pct_register));
  186. end:
  187. kfree(buffer.pointer);
  188. return result;
  189. }
  190. static int acpi_processor_get_performance_states(struct acpi_processor *pr)
  191. {
  192. int result = 0;
  193. acpi_status status = AE_OK;
  194. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  195. struct acpi_buffer format = { sizeof("NNNNNN"), "NNNNNN" };
  196. struct acpi_buffer state = { 0, NULL };
  197. union acpi_object *pss = NULL;
  198. int i;
  199. status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer);
  200. if (ACPI_FAILURE(status)) {
  201. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PSS"));
  202. return -ENODEV;
  203. }
  204. pss = buffer.pointer;
  205. if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) {
  206. printk(KERN_ERR PREFIX "Invalid _PSS data\n");
  207. result = -EFAULT;
  208. goto end;
  209. }
  210. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d performance states\n",
  211. pss->package.count));
  212. pr->performance->state_count = pss->package.count;
  213. pr->performance->states =
  214. kmalloc(sizeof(struct acpi_processor_px) * pss->package.count,
  215. GFP_KERNEL);
  216. if (!pr->performance->states) {
  217. result = -ENOMEM;
  218. goto end;
  219. }
  220. for (i = 0; i < pr->performance->state_count; i++) {
  221. struct acpi_processor_px *px = &(pr->performance->states[i]);
  222. state.length = sizeof(struct acpi_processor_px);
  223. state.pointer = px;
  224. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i));
  225. status = acpi_extract_package(&(pss->package.elements[i]),
  226. &format, &state);
  227. if (ACPI_FAILURE(status)) {
  228. ACPI_EXCEPTION((AE_INFO, status, "Invalid _PSS data"));
  229. result = -EFAULT;
  230. kfree(pr->performance->states);
  231. goto end;
  232. }
  233. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  234. "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n",
  235. i,
  236. (u32) px->core_frequency,
  237. (u32) px->power,
  238. (u32) px->transition_latency,
  239. (u32) px->bus_master_latency,
  240. (u32) px->control, (u32) px->status));
  241. if (!px->core_frequency) {
  242. printk(KERN_ERR PREFIX
  243. "Invalid _PSS data: freq is zero\n");
  244. result = -EFAULT;
  245. kfree(pr->performance->states);
  246. goto end;
  247. }
  248. }
  249. end:
  250. kfree(buffer.pointer);
  251. return result;
  252. }
  253. static int acpi_processor_get_performance_info(struct acpi_processor *pr)
  254. {
  255. int result = 0;
  256. acpi_status status = AE_OK;
  257. acpi_handle handle = NULL;
  258. if (!pr || !pr->performance || !pr->handle)
  259. return -EINVAL;
  260. status = acpi_get_handle(pr->handle, "_PCT", &handle);
  261. if (ACPI_FAILURE(status)) {
  262. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  263. "ACPI-based processor performance control unavailable\n"));
  264. return -ENODEV;
  265. }
  266. result = acpi_processor_get_performance_control(pr);
  267. if (result)
  268. return result;
  269. result = acpi_processor_get_performance_states(pr);
  270. if (result)
  271. return result;
  272. return 0;
  273. }
  274. int acpi_processor_notify_smm(struct module *calling_module)
  275. {
  276. acpi_status status;
  277. static int is_done = 0;
  278. if (!(acpi_processor_ppc_status & PPC_REGISTERED))
  279. return -EBUSY;
  280. if (!try_module_get(calling_module))
  281. return -EINVAL;
  282. /* is_done is set to negative if an error occured,
  283. * and to postitive if _no_ error occured, but SMM
  284. * was already notified. This avoids double notification
  285. * which might lead to unexpected results...
  286. */
  287. if (is_done > 0) {
  288. module_put(calling_module);
  289. return 0;
  290. } else if (is_done < 0) {
  291. module_put(calling_module);
  292. return is_done;
  293. }
  294. is_done = -EIO;
  295. /* Can't write pstate_control to smi_command if either value is zero */
  296. if ((!acpi_gbl_FADT.smi_command) || (!acpi_gbl_FADT.pstate_control)) {
  297. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_control\n"));
  298. module_put(calling_module);
  299. return 0;
  300. }
  301. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  302. "Writing pstate_control [0x%x] to smi_command [0x%x]\n",
  303. acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command));
  304. status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
  305. (u32) acpi_gbl_FADT.pstate_control, 8);
  306. if (ACPI_FAILURE(status)) {
  307. ACPI_EXCEPTION((AE_INFO, status,
  308. "Failed to write pstate_control [0x%x] to "
  309. "smi_command [0x%x]", acpi_gbl_FADT.pstate_control,
  310. acpi_gbl_FADT.smi_command));
  311. module_put(calling_module);
  312. return status;
  313. }
  314. /* Success. If there's no _PPC, we need to fear nothing, so
  315. * we can allow the cpufreq driver to be rmmod'ed. */
  316. is_done = 1;
  317. if (!(acpi_processor_ppc_status & PPC_IN_USE))
  318. module_put(calling_module);
  319. return 0;
  320. }
  321. EXPORT_SYMBOL(acpi_processor_notify_smm);
  322. #ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF
  323. /* /proc/acpi/processor/../performance interface (DEPRECATED) */
  324. static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file);
  325. static struct file_operations acpi_processor_perf_fops = {
  326. .owner = THIS_MODULE,
  327. .open = acpi_processor_perf_open_fs,
  328. .read = seq_read,
  329. .llseek = seq_lseek,
  330. .release = single_release,
  331. };
  332. static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset)
  333. {
  334. struct acpi_processor *pr = seq->private;
  335. int i;
  336. if (!pr)
  337. goto end;
  338. if (!pr->performance) {
  339. seq_puts(seq, "<not supported>\n");
  340. goto end;
  341. }
  342. seq_printf(seq, "state count: %d\n"
  343. "active state: P%d\n",
  344. pr->performance->state_count, pr->performance->state);
  345. seq_puts(seq, "states:\n");
  346. for (i = 0; i < pr->performance->state_count; i++)
  347. seq_printf(seq,
  348. " %cP%d: %d MHz, %d mW, %d uS\n",
  349. (i == pr->performance->state ? '*' : ' '), i,
  350. (u32) pr->performance->states[i].core_frequency,
  351. (u32) pr->performance->states[i].power,
  352. (u32) pr->performance->states[i].transition_latency);
  353. end:
  354. return 0;
  355. }
  356. static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file)
  357. {
  358. return single_open(file, acpi_processor_perf_seq_show,
  359. PDE(inode)->data);
  360. }
  361. static void acpi_cpufreq_add_file(struct acpi_processor *pr)
  362. {
  363. struct acpi_device *device = NULL;
  364. if (acpi_bus_get_device(pr->handle, &device))
  365. return;
  366. /* add file 'performance' [R/W] */
  367. proc_create_data(ACPI_PROCESSOR_FILE_PERFORMANCE, S_IFREG | S_IRUGO,
  368. acpi_device_dir(device),
  369. &acpi_processor_perf_fops, acpi_driver_data(device));
  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 = per_cpu(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 = per_cpu(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 = per_cpu(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 = per_cpu(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 = per_cpu(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 = per_cpu(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 = per_cpu(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 = per_cpu(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);