processor_perflib.c 21 KB

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