processor_perflib.c 21 KB

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