processor_perflib.c 19 KB

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