processor_perflib.c 19 KB

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