processor_perflib.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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 = 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. .open = acpi_processor_perf_open_fs,
  327. .read = seq_read,
  328. .llseek = seq_lseek,
  329. .release = single_release,
  330. };
  331. static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset)
  332. {
  333. struct acpi_processor *pr = seq->private;
  334. int i;
  335. if (!pr)
  336. goto end;
  337. if (!pr->performance) {
  338. seq_puts(seq, "<not supported>\n");
  339. goto end;
  340. }
  341. seq_printf(seq, "state count: %d\n"
  342. "active state: P%d\n",
  343. pr->performance->state_count, pr->performance->state);
  344. seq_puts(seq, "states:\n");
  345. for (i = 0; i < pr->performance->state_count; i++)
  346. seq_printf(seq,
  347. " %cP%d: %d MHz, %d mW, %d uS\n",
  348. (i == pr->performance->state ? '*' : ' '), i,
  349. (u32) pr->performance->states[i].core_frequency,
  350. (u32) pr->performance->states[i].power,
  351. (u32) pr->performance->states[i].transition_latency);
  352. end:
  353. return 0;
  354. }
  355. static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file)
  356. {
  357. return single_open(file, acpi_processor_perf_seq_show,
  358. PDE(inode)->data);
  359. }
  360. static void acpi_cpufreq_add_file(struct acpi_processor *pr)
  361. {
  362. struct proc_dir_entry *entry = NULL;
  363. struct acpi_device *device = NULL;
  364. if (acpi_bus_get_device(pr->handle, &device))
  365. return;
  366. /* add file 'performance' [R/W] */
  367. entry = create_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE,
  368. S_IFREG | S_IRUGO,
  369. acpi_device_dir(device));
  370. if (entry){
  371. entry->proc_fops = &acpi_processor_perf_fops;
  372. entry->data = acpi_driver_data(device);
  373. entry->owner = THIS_MODULE;
  374. }
  375. return;
  376. }
  377. static void acpi_cpufreq_remove_file(struct acpi_processor *pr)
  378. {
  379. struct acpi_device *device = NULL;
  380. if (acpi_bus_get_device(pr->handle, &device))
  381. return;
  382. /* remove file 'performance' */
  383. remove_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE,
  384. acpi_device_dir(device));
  385. return;
  386. }
  387. #else
  388. static void acpi_cpufreq_add_file(struct acpi_processor *pr)
  389. {
  390. return;
  391. }
  392. static void acpi_cpufreq_remove_file(struct acpi_processor *pr)
  393. {
  394. return;
  395. }
  396. #endif /* CONFIG_X86_ACPI_CPUFREQ_PROC_INTF */
  397. static int acpi_processor_get_psd(struct acpi_processor *pr)
  398. {
  399. int result = 0;
  400. acpi_status status = AE_OK;
  401. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  402. struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"};
  403. struct acpi_buffer state = {0, NULL};
  404. union acpi_object *psd = NULL;
  405. struct acpi_psd_package *pdomain;
  406. status = acpi_evaluate_object(pr->handle, "_PSD", NULL, &buffer);
  407. if (ACPI_FAILURE(status)) {
  408. return -ENODEV;
  409. }
  410. psd = buffer.pointer;
  411. if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) {
  412. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n"));
  413. result = -EFAULT;
  414. goto end;
  415. }
  416. if (psd->package.count != 1) {
  417. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n"));
  418. result = -EFAULT;
  419. goto end;
  420. }
  421. pdomain = &(pr->performance->domain_info);
  422. state.length = sizeof(struct acpi_psd_package);
  423. state.pointer = pdomain;
  424. status = acpi_extract_package(&(psd->package.elements[0]),
  425. &format, &state);
  426. if (ACPI_FAILURE(status)) {
  427. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n"));
  428. result = -EFAULT;
  429. goto end;
  430. }
  431. if (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES) {
  432. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _PSD:num_entries\n"));
  433. result = -EFAULT;
  434. goto end;
  435. }
  436. if (pdomain->revision != ACPI_PSD_REV0_REVISION) {
  437. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _PSD:revision\n"));
  438. result = -EFAULT;
  439. goto end;
  440. }
  441. end:
  442. kfree(buffer.pointer);
  443. return result;
  444. }
  445. int acpi_processor_preregister_performance(
  446. struct acpi_processor_performance *performance)
  447. {
  448. int count, count_target;
  449. int retval = 0;
  450. unsigned int i, j;
  451. cpumask_t covered_cpus;
  452. struct acpi_processor *pr;
  453. struct acpi_psd_package *pdomain;
  454. struct acpi_processor *match_pr;
  455. struct acpi_psd_package *match_pdomain;
  456. mutex_lock(&performance_mutex);
  457. retval = 0;
  458. /* Call _PSD for all CPUs */
  459. for_each_possible_cpu(i) {
  460. pr = processors[i];
  461. if (!pr) {
  462. /* Look only at processors in ACPI namespace */
  463. continue;
  464. }
  465. if (pr->performance) {
  466. retval = -EBUSY;
  467. continue;
  468. }
  469. if (!performance || !percpu_ptr(performance, i)) {
  470. retval = -EINVAL;
  471. continue;
  472. }
  473. pr->performance = percpu_ptr(performance, i);
  474. cpu_set(i, pr->performance->shared_cpu_map);
  475. if (acpi_processor_get_psd(pr)) {
  476. retval = -EINVAL;
  477. continue;
  478. }
  479. }
  480. if (retval)
  481. goto err_ret;
  482. /*
  483. * Now that we have _PSD data from all CPUs, lets setup P-state
  484. * domain info.
  485. */
  486. for_each_possible_cpu(i) {
  487. pr = processors[i];
  488. if (!pr)
  489. continue;
  490. /* Basic validity check for domain info */
  491. pdomain = &(pr->performance->domain_info);
  492. if ((pdomain->revision != ACPI_PSD_REV0_REVISION) ||
  493. (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES)) {
  494. retval = -EINVAL;
  495. goto err_ret;
  496. }
  497. if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
  498. pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
  499. pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
  500. retval = -EINVAL;
  501. goto err_ret;
  502. }
  503. }
  504. cpus_clear(covered_cpus);
  505. for_each_possible_cpu(i) {
  506. pr = processors[i];
  507. if (!pr)
  508. continue;
  509. if (cpu_isset(i, covered_cpus))
  510. continue;
  511. pdomain = &(pr->performance->domain_info);
  512. cpu_set(i, pr->performance->shared_cpu_map);
  513. cpu_set(i, covered_cpus);
  514. if (pdomain->num_processors <= 1)
  515. continue;
  516. /* Validate the Domain info */
  517. count_target = pdomain->num_processors;
  518. count = 1;
  519. if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL)
  520. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
  521. else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL)
  522. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_HW;
  523. else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY)
  524. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY;
  525. for_each_possible_cpu(j) {
  526. if (i == j)
  527. continue;
  528. match_pr = processors[j];
  529. if (!match_pr)
  530. continue;
  531. match_pdomain = &(match_pr->performance->domain_info);
  532. if (match_pdomain->domain != pdomain->domain)
  533. continue;
  534. /* Here i and j are in the same domain */
  535. if (match_pdomain->num_processors != count_target) {
  536. retval = -EINVAL;
  537. goto err_ret;
  538. }
  539. if (pdomain->coord_type != match_pdomain->coord_type) {
  540. retval = -EINVAL;
  541. goto err_ret;
  542. }
  543. cpu_set(j, covered_cpus);
  544. cpu_set(j, pr->performance->shared_cpu_map);
  545. count++;
  546. }
  547. for_each_possible_cpu(j) {
  548. if (i == j)
  549. continue;
  550. match_pr = processors[j];
  551. if (!match_pr)
  552. continue;
  553. match_pdomain = &(match_pr->performance->domain_info);
  554. if (match_pdomain->domain != pdomain->domain)
  555. continue;
  556. match_pr->performance->shared_type =
  557. pr->performance->shared_type;
  558. match_pr->performance->shared_cpu_map =
  559. pr->performance->shared_cpu_map;
  560. }
  561. }
  562. err_ret:
  563. for_each_possible_cpu(i) {
  564. pr = processors[i];
  565. if (!pr || !pr->performance)
  566. continue;
  567. /* Assume no coordination on any error parsing domain info */
  568. if (retval) {
  569. cpus_clear(pr->performance->shared_cpu_map);
  570. cpu_set(i, pr->performance->shared_cpu_map);
  571. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
  572. }
  573. pr->performance = NULL; /* Will be set for real in register */
  574. }
  575. mutex_unlock(&performance_mutex);
  576. return retval;
  577. }
  578. EXPORT_SYMBOL(acpi_processor_preregister_performance);
  579. int
  580. acpi_processor_register_performance(struct acpi_processor_performance
  581. *performance, unsigned int cpu)
  582. {
  583. struct acpi_processor *pr;
  584. if (!(acpi_processor_ppc_status & PPC_REGISTERED))
  585. return -EINVAL;
  586. mutex_lock(&performance_mutex);
  587. pr = processors[cpu];
  588. if (!pr) {
  589. mutex_unlock(&performance_mutex);
  590. return -ENODEV;
  591. }
  592. if (pr->performance) {
  593. mutex_unlock(&performance_mutex);
  594. return -EBUSY;
  595. }
  596. WARN_ON(!performance);
  597. pr->performance = performance;
  598. if (acpi_processor_get_performance_info(pr)) {
  599. pr->performance = NULL;
  600. mutex_unlock(&performance_mutex);
  601. return -EIO;
  602. }
  603. acpi_cpufreq_add_file(pr);
  604. mutex_unlock(&performance_mutex);
  605. return 0;
  606. }
  607. EXPORT_SYMBOL(acpi_processor_register_performance);
  608. void
  609. acpi_processor_unregister_performance(struct acpi_processor_performance
  610. *performance, unsigned int cpu)
  611. {
  612. struct acpi_processor *pr;
  613. mutex_lock(&performance_mutex);
  614. pr = processors[cpu];
  615. if (!pr) {
  616. mutex_unlock(&performance_mutex);
  617. return;
  618. }
  619. if (pr->performance)
  620. kfree(pr->performance->states);
  621. pr->performance = NULL;
  622. acpi_cpufreq_remove_file(pr);
  623. mutex_unlock(&performance_mutex);
  624. return;
  625. }
  626. EXPORT_SYMBOL(acpi_processor_unregister_performance);