processor_perflib.c 19 KB

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