processor_perflib.c 20 KB

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