processor_perflib.c 20 KB

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