processor_perflib.c 19 KB

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