processor_perflib.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * processor_perflib.c - ACPI Processor P-States Library ($Revision: 71 $)
  4. *
  5. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  6. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  7. * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de>
  8. * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
  9. * - Added processor hotplug support
  10. */
  11. #define pr_fmt(fmt) "ACPI: " fmt
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/cpufreq.h>
  16. #include <linux/slab.h>
  17. #include <linux/acpi.h>
  18. #include <acpi/processor.h>
  19. #ifdef CONFIG_X86
  20. #include <asm/cpufeature.h>
  21. #endif
  22. #define ACPI_PROCESSOR_FILE_PERFORMANCE "performance"
  23. static DEFINE_MUTEX(performance_mutex);
  24. /*
  25. * _PPC support is implemented as a CPUfreq policy notifier:
  26. * This means each time a CPUfreq driver registered also with
  27. * the ACPI core is asked to change the speed policy, the maximum
  28. * value is adjusted so that it is within the platform limit.
  29. *
  30. * Also, when a new platform limit value is detected, the CPUfreq
  31. * policy is adjusted accordingly.
  32. */
  33. /* ignore_ppc:
  34. * -1 -> cpufreq low level drivers not initialized -> _PSS, etc. not called yet
  35. * ignore _PPC
  36. * 0 -> cpufreq low level drivers initialized -> consider _PPC values
  37. * 1 -> ignore _PPC totally -> forced by user through boot param
  38. */
  39. static int ignore_ppc = -1;
  40. module_param(ignore_ppc, int, 0644);
  41. MODULE_PARM_DESC(ignore_ppc, "If the frequency of your machine gets wrongly" \
  42. "limited by BIOS, this should help");
  43. static bool acpi_processor_ppc_in_use;
  44. static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
  45. {
  46. acpi_status status = 0;
  47. unsigned long long ppc = 0;
  48. s32 qos_value;
  49. int index;
  50. int ret;
  51. if (!pr)
  52. return -EINVAL;
  53. /*
  54. * _PPC indicates the maximum state currently supported by the platform
  55. * (e.g. 0 = states 0..n; 1 = states 1..n; etc.
  56. */
  57. status = acpi_evaluate_integer(pr->handle, "_PPC", NULL, &ppc);
  58. if (status != AE_NOT_FOUND) {
  59. acpi_processor_ppc_in_use = true;
  60. if (ACPI_FAILURE(status)) {
  61. acpi_evaluation_failure_warn(pr->handle, "_PPC", status);
  62. return -ENODEV;
  63. }
  64. }
  65. index = ppc;
  66. if (pr->performance_platform_limit == index ||
  67. ppc >= pr->performance->state_count)
  68. return 0;
  69. pr_debug("CPU %d: _PPC is %d - frequency %s limited\n", pr->id,
  70. index, index ? "is" : "is not");
  71. pr->performance_platform_limit = index;
  72. if (unlikely(!freq_qos_request_active(&pr->perflib_req)))
  73. return 0;
  74. /*
  75. * If _PPC returns 0, it means that all of the available states can be
  76. * used ("no limit").
  77. */
  78. if (index == 0)
  79. qos_value = FREQ_QOS_MAX_DEFAULT_VALUE;
  80. else
  81. qos_value = pr->performance->states[index].core_frequency * 1000;
  82. ret = freq_qos_update_request(&pr->perflib_req, qos_value);
  83. if (ret < 0) {
  84. pr_warn("Failed to update perflib freq constraint: CPU%d (%d)\n",
  85. pr->id, ret);
  86. }
  87. return 0;
  88. }
  89. #define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
  90. /*
  91. * acpi_processor_ppc_ost: Notify firmware the _PPC evaluation status
  92. * @handle: ACPI processor handle
  93. * @status: the status code of _PPC evaluation
  94. * 0: success. OSPM is now using the performance state specified.
  95. * 1: failure. OSPM has not changed the number of P-states in use
  96. */
  97. static void acpi_processor_ppc_ost(acpi_handle handle, int status)
  98. {
  99. if (acpi_has_method(handle, "_OST"))
  100. acpi_evaluate_ost(handle, ACPI_PROCESSOR_NOTIFY_PERFORMANCE,
  101. status, NULL);
  102. }
  103. void acpi_processor_ppc_has_changed(struct acpi_processor *pr, int event_flag)
  104. {
  105. int ret;
  106. if (ignore_ppc || !pr->performance) {
  107. /*
  108. * Only when it is notification event, the _OST object
  109. * will be evaluated. Otherwise it is skipped.
  110. */
  111. if (event_flag)
  112. acpi_processor_ppc_ost(pr->handle, 1);
  113. return;
  114. }
  115. ret = acpi_processor_get_platform_limit(pr);
  116. /*
  117. * Only when it is notification event, the _OST object
  118. * will be evaluated. Otherwise it is skipped.
  119. */
  120. if (event_flag) {
  121. if (ret < 0)
  122. acpi_processor_ppc_ost(pr->handle, 1);
  123. else
  124. acpi_processor_ppc_ost(pr->handle, 0);
  125. }
  126. if (ret >= 0)
  127. cpufreq_update_limits(pr->id);
  128. }
  129. int acpi_processor_get_bios_limit(int cpu, unsigned int *limit)
  130. {
  131. struct acpi_processor *pr;
  132. pr = per_cpu(processors, cpu);
  133. if (!pr || !pr->performance || !pr->performance->state_count)
  134. return -ENODEV;
  135. *limit = pr->performance->states[pr->performance_platform_limit].
  136. core_frequency * 1000;
  137. return 0;
  138. }
  139. EXPORT_SYMBOL(acpi_processor_get_bios_limit);
  140. void acpi_processor_ignore_ppc_init(void)
  141. {
  142. if (ignore_ppc < 0)
  143. ignore_ppc = 0;
  144. }
  145. void acpi_processor_ppc_init(struct cpufreq_policy *policy)
  146. {
  147. unsigned int cpu;
  148. if (ignore_ppc == 1)
  149. return;
  150. for_each_cpu(cpu, policy->related_cpus) {
  151. struct acpi_processor *pr = per_cpu(processors, cpu);
  152. int ret;
  153. if (!pr)
  154. continue;
  155. /*
  156. * Reset performance_platform_limit in case there is a stale
  157. * value in it, so as to make it match the "no limit" QoS value
  158. * below.
  159. */
  160. pr->performance_platform_limit = 0;
  161. ret = freq_qos_add_request(&policy->constraints,
  162. &pr->perflib_req, FREQ_QOS_MAX,
  163. FREQ_QOS_MAX_DEFAULT_VALUE);
  164. if (ret < 0)
  165. pr_err("Failed to add freq constraint for CPU%d (%d)\n",
  166. cpu, ret);
  167. if (!pr->performance)
  168. continue;
  169. ret = acpi_processor_get_platform_limit(pr);
  170. if (ret)
  171. pr_err("Failed to update freq constraint for CPU%d (%d)\n",
  172. cpu, ret);
  173. }
  174. }
  175. void acpi_processor_ppc_exit(struct cpufreq_policy *policy)
  176. {
  177. unsigned int cpu;
  178. for_each_cpu(cpu, policy->related_cpus) {
  179. struct acpi_processor *pr = per_cpu(processors, cpu);
  180. if (pr)
  181. freq_qos_remove_request(&pr->perflib_req);
  182. }
  183. }
  184. static int acpi_processor_get_performance_control(struct acpi_processor *pr)
  185. {
  186. int result = 0;
  187. acpi_status status = 0;
  188. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  189. union acpi_object *pct = NULL;
  190. union acpi_object obj = { 0 };
  191. status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer);
  192. if (ACPI_FAILURE(status)) {
  193. acpi_evaluation_failure_warn(pr->handle, "_PCT", status);
  194. return -ENODEV;
  195. }
  196. pct = (union acpi_object *)buffer.pointer;
  197. if (!pct || pct->type != ACPI_TYPE_PACKAGE || pct->package.count != 2) {
  198. pr_err("Invalid _PCT data\n");
  199. result = -EFAULT;
  200. goto end;
  201. }
  202. /*
  203. * control_register
  204. */
  205. obj = pct->package.elements[0];
  206. if (!obj.buffer.pointer || obj.type != ACPI_TYPE_BUFFER ||
  207. obj.buffer.length < sizeof(struct acpi_pct_register)) {
  208. pr_err("Invalid _PCT data (control_register)\n");
  209. result = -EFAULT;
  210. goto end;
  211. }
  212. memcpy(&pr->performance->control_register, obj.buffer.pointer,
  213. sizeof(struct acpi_pct_register));
  214. /*
  215. * status_register
  216. */
  217. obj = pct->package.elements[1];
  218. if (!obj.buffer.pointer || obj.type != ACPI_TYPE_BUFFER ||
  219. obj.buffer.length < sizeof(struct acpi_pct_register)) {
  220. pr_err("Invalid _PCT data (status_register)\n");
  221. result = -EFAULT;
  222. goto end;
  223. }
  224. memcpy(&pr->performance->status_register, obj.buffer.pointer,
  225. sizeof(struct acpi_pct_register));
  226. end:
  227. kfree(buffer.pointer);
  228. return result;
  229. }
  230. #ifdef CONFIG_X86
  231. /*
  232. * Some AMDs have 50MHz frequency multiples, but only provide 100MHz rounding
  233. * in their ACPI data. Calculate the real values and fix up the _PSS data.
  234. */
  235. static void amd_fixup_frequency(struct acpi_processor_px *px, int i)
  236. {
  237. u32 hi, lo, fid, did;
  238. int index = px->control & 0x00000007;
  239. if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
  240. return;
  241. if ((boot_cpu_data.x86 == 0x10 && boot_cpu_data.x86_model < 10) ||
  242. boot_cpu_data.x86 == 0x11) {
  243. rdmsr(MSR_AMD_PSTATE_DEF_BASE + index, lo, hi);
  244. /*
  245. * MSR C001_0064+:
  246. * Bit 63: PstateEn. Read-write. If set, the P-state is valid.
  247. */
  248. if (!(hi & BIT(31)))
  249. return;
  250. fid = lo & 0x3f;
  251. did = (lo >> 6) & 7;
  252. if (boot_cpu_data.x86 == 0x10)
  253. px->core_frequency = (100 * (fid + 0x10)) >> did;
  254. else
  255. px->core_frequency = (100 * (fid + 8)) >> did;
  256. }
  257. }
  258. #else
  259. static void amd_fixup_frequency(struct acpi_processor_px *px, int i) {};
  260. #endif
  261. static int acpi_processor_get_performance_states(struct acpi_processor *pr)
  262. {
  263. int result = 0;
  264. acpi_status status = AE_OK;
  265. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  266. struct acpi_buffer format = { sizeof("NNNNNN"), "NNNNNN" };
  267. struct acpi_buffer state = { 0, NULL };
  268. union acpi_object *pss = NULL;
  269. int i;
  270. int last_invalid = -1;
  271. status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer);
  272. if (ACPI_FAILURE(status)) {
  273. acpi_evaluation_failure_warn(pr->handle, "_PSS", status);
  274. return -ENODEV;
  275. }
  276. pss = buffer.pointer;
  277. if (!pss || pss->type != ACPI_TYPE_PACKAGE) {
  278. pr_err("Invalid _PSS data\n");
  279. result = -EFAULT;
  280. goto end;
  281. }
  282. acpi_handle_debug(pr->handle, "Found %d performance states\n",
  283. pss->package.count);
  284. pr->performance->state_count = pss->package.count;
  285. pr->performance->states =
  286. kmalloc_array(pss->package.count,
  287. sizeof(struct acpi_processor_px),
  288. GFP_KERNEL);
  289. if (!pr->performance->states) {
  290. result = -ENOMEM;
  291. goto end;
  292. }
  293. for (i = 0; i < pr->performance->state_count; i++) {
  294. struct acpi_processor_px *px = &(pr->performance->states[i]);
  295. state.length = sizeof(struct acpi_processor_px);
  296. state.pointer = px;
  297. acpi_handle_debug(pr->handle, "Extracting state %d\n", i);
  298. status = acpi_extract_package(&(pss->package.elements[i]),
  299. &format, &state);
  300. if (ACPI_FAILURE(status)) {
  301. acpi_handle_warn(pr->handle, "Invalid _PSS data: %s\n",
  302. acpi_format_exception(status));
  303. result = -EFAULT;
  304. kfree(pr->performance->states);
  305. goto end;
  306. }
  307. amd_fixup_frequency(px, i);
  308. acpi_handle_debug(pr->handle,
  309. "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n",
  310. i,
  311. (u32) px->core_frequency,
  312. (u32) px->power,
  313. (u32) px->transition_latency,
  314. (u32) px->bus_master_latency,
  315. (u32) px->control, (u32) px->status);
  316. /*
  317. * Check that ACPI's u64 MHz will be valid as u32 KHz in cpufreq
  318. */
  319. if (!px->core_frequency ||
  320. (u32)(px->core_frequency * 1000) != px->core_frequency * 1000) {
  321. pr_err(FW_BUG
  322. "Invalid BIOS _PSS frequency found for processor %d: 0x%llx MHz\n",
  323. pr->id, px->core_frequency);
  324. if (last_invalid == -1)
  325. last_invalid = i;
  326. } else {
  327. if (last_invalid != -1) {
  328. /*
  329. * Copy this valid entry over last_invalid entry
  330. */
  331. memcpy(&(pr->performance->states[last_invalid]),
  332. px, sizeof(struct acpi_processor_px));
  333. ++last_invalid;
  334. }
  335. }
  336. }
  337. if (last_invalid == 0) {
  338. pr_err(FW_BUG
  339. "No valid BIOS _PSS frequency found for processor %d\n", pr->id);
  340. result = -EFAULT;
  341. kfree(pr->performance->states);
  342. pr->performance->states = NULL;
  343. }
  344. if (last_invalid > 0)
  345. pr->performance->state_count = last_invalid;
  346. end:
  347. kfree(buffer.pointer);
  348. return result;
  349. }
  350. int acpi_processor_get_performance_info(struct acpi_processor *pr)
  351. {
  352. int result = 0;
  353. if (!pr || !pr->performance || !pr->handle)
  354. return -EINVAL;
  355. if (!acpi_has_method(pr->handle, "_PCT")) {
  356. acpi_handle_debug(pr->handle,
  357. "ACPI-based processor performance control unavailable\n");
  358. return -ENODEV;
  359. }
  360. result = acpi_processor_get_performance_control(pr);
  361. if (result)
  362. goto update_bios;
  363. result = acpi_processor_get_performance_states(pr);
  364. if (result)
  365. goto update_bios;
  366. /* We need to call _PPC once when cpufreq starts */
  367. if (ignore_ppc != 1)
  368. result = acpi_processor_get_platform_limit(pr);
  369. return result;
  370. /*
  371. * Having _PPC but missing frequencies (_PSS, _PCT) is a very good hint that
  372. * the BIOS is older than the CPU and does not know its frequencies
  373. */
  374. update_bios:
  375. #ifdef CONFIG_X86
  376. if (acpi_has_method(pr->handle, "_PPC")) {
  377. if(boot_cpu_has(X86_FEATURE_EST))
  378. pr_warn(FW_BUG "BIOS needs update for CPU "
  379. "frequency support\n");
  380. }
  381. #endif
  382. return result;
  383. }
  384. EXPORT_SYMBOL_GPL(acpi_processor_get_performance_info);
  385. int acpi_processor_pstate_control(void)
  386. {
  387. acpi_status status;
  388. if (!acpi_gbl_FADT.smi_command || !acpi_gbl_FADT.pstate_control)
  389. return 0;
  390. pr_debug("Writing pstate_control [0x%x] to smi_command [0x%x]\n",
  391. acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command);
  392. status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
  393. (u32)acpi_gbl_FADT.pstate_control, 8);
  394. if (ACPI_SUCCESS(status))
  395. return 1;
  396. pr_warn("Failed to write pstate_control [0x%x] to smi_command [0x%x]: %s\n",
  397. acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command,
  398. acpi_format_exception(status));
  399. return -EIO;
  400. }
  401. int acpi_processor_notify_smm(struct module *calling_module)
  402. {
  403. static int is_done;
  404. int result = 0;
  405. if (!acpi_processor_cpufreq_init)
  406. return -EBUSY;
  407. if (!try_module_get(calling_module))
  408. return -EINVAL;
  409. /*
  410. * is_done is set to negative if an error occurs and to 1 if no error
  411. * occurrs, but SMM has been notified already. This avoids repeated
  412. * notification which might lead to unexpected results.
  413. */
  414. if (is_done != 0) {
  415. if (is_done < 0)
  416. result = is_done;
  417. goto out_put;
  418. }
  419. result = acpi_processor_pstate_control();
  420. if (result <= 0) {
  421. if (result) {
  422. is_done = result;
  423. } else {
  424. pr_debug("No SMI port or pstate_control\n");
  425. is_done = 1;
  426. }
  427. goto out_put;
  428. }
  429. is_done = 1;
  430. /*
  431. * Success. If there _PPC, unloading the cpufreq driver would be risky,
  432. * so disallow it in that case.
  433. */
  434. if (acpi_processor_ppc_in_use)
  435. return 0;
  436. out_put:
  437. module_put(calling_module);
  438. return result;
  439. }
  440. EXPORT_SYMBOL(acpi_processor_notify_smm);
  441. int acpi_processor_get_psd(acpi_handle handle, struct acpi_psd_package *pdomain)
  442. {
  443. int result = 0;
  444. acpi_status status = AE_OK;
  445. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  446. struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"};
  447. struct acpi_buffer state = {0, NULL};
  448. union acpi_object *psd = NULL;
  449. status = acpi_evaluate_object(handle, "_PSD", NULL, &buffer);
  450. if (ACPI_FAILURE(status)) {
  451. return -ENODEV;
  452. }
  453. psd = buffer.pointer;
  454. if (!psd || psd->type != ACPI_TYPE_PACKAGE) {
  455. pr_err("Invalid _PSD data\n");
  456. result = -EFAULT;
  457. goto end;
  458. }
  459. if (psd->package.count != 1) {
  460. pr_err("Invalid _PSD data\n");
  461. result = -EFAULT;
  462. goto end;
  463. }
  464. state.length = sizeof(struct acpi_psd_package);
  465. state.pointer = pdomain;
  466. status = acpi_extract_package(&(psd->package.elements[0]), &format, &state);
  467. if (ACPI_FAILURE(status)) {
  468. pr_err("Invalid _PSD data\n");
  469. result = -EFAULT;
  470. goto end;
  471. }
  472. if (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES) {
  473. pr_err("Unknown _PSD:num_entries\n");
  474. result = -EFAULT;
  475. goto end;
  476. }
  477. if (pdomain->revision != ACPI_PSD_REV0_REVISION) {
  478. pr_err("Unknown _PSD:revision\n");
  479. result = -EFAULT;
  480. goto end;
  481. }
  482. if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
  483. pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
  484. pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
  485. pr_err("Invalid _PSD:coord_type\n");
  486. result = -EFAULT;
  487. goto end;
  488. }
  489. end:
  490. kfree(buffer.pointer);
  491. return result;
  492. }
  493. EXPORT_SYMBOL(acpi_processor_get_psd);
  494. int acpi_processor_preregister_performance(
  495. struct acpi_processor_performance __percpu *performance)
  496. {
  497. int count_target;
  498. int retval = 0;
  499. unsigned int i, j;
  500. cpumask_var_t covered_cpus;
  501. struct acpi_processor *pr;
  502. struct acpi_psd_package *pdomain;
  503. struct acpi_processor *match_pr;
  504. struct acpi_psd_package *match_pdomain;
  505. if (!zalloc_cpumask_var(&covered_cpus, GFP_KERNEL))
  506. return -ENOMEM;
  507. mutex_lock(&performance_mutex);
  508. /*
  509. * Check if another driver has already registered, and abort before
  510. * changing pr->performance if it has. Check input data as well.
  511. */
  512. for_each_possible_cpu(i) {
  513. pr = per_cpu(processors, i);
  514. if (!pr) {
  515. /* Look only at processors in ACPI namespace */
  516. continue;
  517. }
  518. if (pr->performance) {
  519. retval = -EBUSY;
  520. goto err_out;
  521. }
  522. if (!performance || !per_cpu_ptr(performance, i)) {
  523. retval = -EINVAL;
  524. goto err_out;
  525. }
  526. }
  527. /* Call _PSD for all CPUs */
  528. for_each_possible_cpu(i) {
  529. pr = per_cpu(processors, i);
  530. if (!pr)
  531. continue;
  532. pr->performance = per_cpu_ptr(performance, i);
  533. pdomain = &(pr->performance->domain_info);
  534. if (acpi_processor_get_psd(pr->handle, pdomain)) {
  535. retval = -EINVAL;
  536. continue;
  537. }
  538. }
  539. if (retval)
  540. goto err_ret;
  541. /*
  542. * Now that we have _PSD data from all CPUs, lets setup P-state
  543. * domain info.
  544. */
  545. for_each_possible_cpu(i) {
  546. pr = per_cpu(processors, i);
  547. if (!pr)
  548. continue;
  549. if (cpumask_test_cpu(i, covered_cpus))
  550. continue;
  551. pdomain = &(pr->performance->domain_info);
  552. cpumask_set_cpu(i, pr->performance->shared_cpu_map);
  553. cpumask_set_cpu(i, covered_cpus);
  554. if (pdomain->num_processors <= 1)
  555. continue;
  556. /* Validate the Domain info */
  557. count_target = pdomain->num_processors;
  558. if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL)
  559. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL;
  560. else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL)
  561. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_HW;
  562. else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY)
  563. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY;
  564. for_each_possible_cpu(j) {
  565. if (i == j)
  566. continue;
  567. match_pr = per_cpu(processors, j);
  568. if (!match_pr)
  569. continue;
  570. match_pdomain = &(match_pr->performance->domain_info);
  571. if (match_pdomain->domain != pdomain->domain)
  572. continue;
  573. /* Here i and j are in the same domain */
  574. if (match_pdomain->num_processors != count_target) {
  575. retval = -EINVAL;
  576. goto err_ret;
  577. }
  578. if (pdomain->coord_type != match_pdomain->coord_type) {
  579. retval = -EINVAL;
  580. goto err_ret;
  581. }
  582. cpumask_set_cpu(j, covered_cpus);
  583. cpumask_set_cpu(j, pr->performance->shared_cpu_map);
  584. }
  585. for_each_possible_cpu(j) {
  586. if (i == j)
  587. continue;
  588. match_pr = per_cpu(processors, j);
  589. if (!match_pr)
  590. continue;
  591. match_pdomain = &(match_pr->performance->domain_info);
  592. if (match_pdomain->domain != pdomain->domain)
  593. continue;
  594. match_pr->performance->shared_type =
  595. pr->performance->shared_type;
  596. cpumask_copy(match_pr->performance->shared_cpu_map,
  597. pr->performance->shared_cpu_map);
  598. }
  599. }
  600. err_ret:
  601. for_each_possible_cpu(i) {
  602. pr = per_cpu(processors, i);
  603. if (!pr || !pr->performance)
  604. continue;
  605. /* Assume no coordination on any error parsing domain info */
  606. if (retval) {
  607. cpumask_clear(pr->performance->shared_cpu_map);
  608. cpumask_set_cpu(i, pr->performance->shared_cpu_map);
  609. pr->performance->shared_type = CPUFREQ_SHARED_TYPE_NONE;
  610. }
  611. pr->performance = NULL; /* Will be set for real in register */
  612. }
  613. err_out:
  614. mutex_unlock(&performance_mutex);
  615. free_cpumask_var(covered_cpus);
  616. return retval;
  617. }
  618. EXPORT_SYMBOL(acpi_processor_preregister_performance);
  619. int acpi_processor_register_performance(struct acpi_processor_performance
  620. *performance, unsigned int cpu)
  621. {
  622. struct acpi_processor *pr;
  623. if (!acpi_processor_cpufreq_init)
  624. return -EINVAL;
  625. mutex_lock(&performance_mutex);
  626. pr = per_cpu(processors, cpu);
  627. if (!pr) {
  628. mutex_unlock(&performance_mutex);
  629. return -ENODEV;
  630. }
  631. if (pr->performance) {
  632. mutex_unlock(&performance_mutex);
  633. return -EBUSY;
  634. }
  635. WARN_ON(!performance);
  636. pr->performance = performance;
  637. if (acpi_processor_get_performance_info(pr)) {
  638. pr->performance = NULL;
  639. mutex_unlock(&performance_mutex);
  640. return -EIO;
  641. }
  642. mutex_unlock(&performance_mutex);
  643. return 0;
  644. }
  645. EXPORT_SYMBOL(acpi_processor_register_performance);
  646. void acpi_processor_unregister_performance(unsigned int cpu)
  647. {
  648. struct acpi_processor *pr;
  649. mutex_lock(&performance_mutex);
  650. pr = per_cpu(processors, cpu);
  651. if (!pr)
  652. goto unlock;
  653. if (pr->performance)
  654. kfree(pr->performance->states);
  655. pr->performance = NULL;
  656. unlock:
  657. mutex_unlock(&performance_mutex);
  658. }
  659. EXPORT_SYMBOL(acpi_processor_unregister_performance);