processor_throttling.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /*
  2. * processor_throttling.c - Throttling submodule of the ACPI processor driver
  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. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or (at
  15. * your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful, but
  18. * WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. * General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License along
  23. * with this program; if not, write to the Free Software Foundation, Inc.,
  24. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  25. *
  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/proc_fs.h>
  33. #include <linux/seq_file.h>
  34. #include <asm/io.h>
  35. #include <asm/uaccess.h>
  36. #include <acpi/acpi_bus.h>
  37. #include <acpi/processor.h>
  38. #define ACPI_PROCESSOR_COMPONENT 0x01000000
  39. #define ACPI_PROCESSOR_CLASS "processor"
  40. #define _COMPONENT ACPI_PROCESSOR_COMPONENT
  41. ACPI_MODULE_NAME("processor_throttling");
  42. static int acpi_processor_get_throttling(struct acpi_processor *pr);
  43. int acpi_processor_set_throttling(struct acpi_processor *pr, int state);
  44. /*
  45. * _TPC - Throttling Present Capabilities
  46. */
  47. static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
  48. {
  49. acpi_status status = 0;
  50. unsigned long tpc = 0;
  51. if (!pr)
  52. return -EINVAL;
  53. status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc);
  54. if (ACPI_FAILURE(status)) {
  55. if (status != AE_NOT_FOUND) {
  56. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC"));
  57. }
  58. return -ENODEV;
  59. }
  60. pr->throttling_platform_limit = (int)tpc;
  61. return 0;
  62. }
  63. int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
  64. {
  65. return acpi_processor_get_platform_limit(pr);
  66. }
  67. /*
  68. * _PTC - Processor Throttling Control (and status) register location
  69. */
  70. static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
  71. {
  72. int result = 0;
  73. acpi_status status = 0;
  74. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  75. union acpi_object *ptc = NULL;
  76. union acpi_object obj = { 0 };
  77. status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer);
  78. if (ACPI_FAILURE(status)) {
  79. if (status != AE_NOT_FOUND) {
  80. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PTC"));
  81. }
  82. return -ENODEV;
  83. }
  84. ptc = (union acpi_object *)buffer.pointer;
  85. if (!ptc || (ptc->type != ACPI_TYPE_PACKAGE)
  86. || (ptc->package.count != 2)) {
  87. printk(KERN_ERR PREFIX "Invalid _PTC data\n");
  88. result = -EFAULT;
  89. goto end;
  90. }
  91. /*
  92. * control_register
  93. */
  94. obj = ptc->package.elements[0];
  95. if ((obj.type != ACPI_TYPE_BUFFER)
  96. || (obj.buffer.length < sizeof(struct acpi_ptc_register))
  97. || (obj.buffer.pointer == NULL)) {
  98. printk(KERN_ERR PREFIX
  99. "Invalid _PTC data (control_register)\n");
  100. result = -EFAULT;
  101. goto end;
  102. }
  103. memcpy(&pr->throttling.control_register, obj.buffer.pointer,
  104. sizeof(struct acpi_ptc_register));
  105. /*
  106. * status_register
  107. */
  108. obj = ptc->package.elements[1];
  109. if ((obj.type != ACPI_TYPE_BUFFER)
  110. || (obj.buffer.length < sizeof(struct acpi_ptc_register))
  111. || (obj.buffer.pointer == NULL)) {
  112. printk(KERN_ERR PREFIX "Invalid _PTC data (status_register)\n");
  113. result = -EFAULT;
  114. goto end;
  115. }
  116. memcpy(&pr->throttling.status_register, obj.buffer.pointer,
  117. sizeof(struct acpi_ptc_register));
  118. end:
  119. kfree(buffer.pointer);
  120. return result;
  121. }
  122. /*
  123. * _TSS - Throttling Supported States
  124. */
  125. static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
  126. {
  127. int result = 0;
  128. acpi_status status = AE_OK;
  129. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  130. struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
  131. struct acpi_buffer state = { 0, NULL };
  132. union acpi_object *tss = NULL;
  133. int i;
  134. status = acpi_evaluate_object(pr->handle, "_TSS", NULL, &buffer);
  135. if (ACPI_FAILURE(status)) {
  136. if (status != AE_NOT_FOUND) {
  137. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSS"));
  138. }
  139. return -ENODEV;
  140. }
  141. tss = buffer.pointer;
  142. if (!tss || (tss->type != ACPI_TYPE_PACKAGE)) {
  143. printk(KERN_ERR PREFIX "Invalid _TSS data\n");
  144. result = -EFAULT;
  145. goto end;
  146. }
  147. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
  148. tss->package.count));
  149. pr->throttling.state_count = tss->package.count;
  150. pr->throttling.states_tss =
  151. kmalloc(sizeof(struct acpi_processor_tx_tss) * tss->package.count,
  152. GFP_KERNEL);
  153. if (!pr->throttling.states_tss) {
  154. result = -ENOMEM;
  155. goto end;
  156. }
  157. for (i = 0; i < pr->throttling.state_count; i++) {
  158. struct acpi_processor_tx_tss *tx =
  159. (struct acpi_processor_tx_tss *)&(pr->throttling.
  160. states_tss[i]);
  161. state.length = sizeof(struct acpi_processor_tx_tss);
  162. state.pointer = tx;
  163. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i));
  164. status = acpi_extract_package(&(tss->package.elements[i]),
  165. &format, &state);
  166. if (ACPI_FAILURE(status)) {
  167. ACPI_EXCEPTION((AE_INFO, status, "Invalid _TSS data"));
  168. result = -EFAULT;
  169. kfree(pr->throttling.states_tss);
  170. goto end;
  171. }
  172. if (!tx->freqpercentage) {
  173. printk(KERN_ERR PREFIX
  174. "Invalid _TSS data: freq is zero\n");
  175. result = -EFAULT;
  176. kfree(pr->throttling.states_tss);
  177. goto end;
  178. }
  179. }
  180. end:
  181. kfree(buffer.pointer);
  182. return result;
  183. }
  184. /*
  185. * _TSD - T-State Dependencies
  186. */
  187. static int acpi_processor_get_tsd(struct acpi_processor *pr)
  188. {
  189. int result = 0;
  190. acpi_status status = AE_OK;
  191. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  192. struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
  193. struct acpi_buffer state = { 0, NULL };
  194. union acpi_object *tsd = NULL;
  195. struct acpi_tsd_package *pdomain;
  196. status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer);
  197. if (ACPI_FAILURE(status)) {
  198. if (status != AE_NOT_FOUND) {
  199. ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSD"));
  200. }
  201. return -ENODEV;
  202. }
  203. tsd = buffer.pointer;
  204. if (!tsd || (tsd->type != ACPI_TYPE_PACKAGE)) {
  205. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
  206. result = -EFAULT;
  207. goto end;
  208. }
  209. if (tsd->package.count != 1) {
  210. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
  211. result = -EFAULT;
  212. goto end;
  213. }
  214. pdomain = &(pr->throttling.domain_info);
  215. state.length = sizeof(struct acpi_tsd_package);
  216. state.pointer = pdomain;
  217. status = acpi_extract_package(&(tsd->package.elements[0]),
  218. &format, &state);
  219. if (ACPI_FAILURE(status)) {
  220. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
  221. result = -EFAULT;
  222. goto end;
  223. }
  224. if (pdomain->num_entries != ACPI_TSD_REV0_ENTRIES) {
  225. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:num_entries\n"));
  226. result = -EFAULT;
  227. goto end;
  228. }
  229. if (pdomain->revision != ACPI_TSD_REV0_REVISION) {
  230. ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:revision\n"));
  231. result = -EFAULT;
  232. goto end;
  233. }
  234. end:
  235. kfree(buffer.pointer);
  236. return result;
  237. }
  238. /* --------------------------------------------------------------------------
  239. Throttling Control
  240. -------------------------------------------------------------------------- */
  241. static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
  242. {
  243. int state = 0;
  244. u32 value = 0;
  245. u32 duty_mask = 0;
  246. u32 duty_value = 0;
  247. if (!pr)
  248. return -EINVAL;
  249. if (!pr->flags.throttling)
  250. return -ENODEV;
  251. pr->throttling.state = 0;
  252. duty_mask = pr->throttling.state_count - 1;
  253. duty_mask <<= pr->throttling.duty_offset;
  254. local_irq_disable();
  255. value = inl(pr->throttling.address);
  256. /*
  257. * Compute the current throttling state when throttling is enabled
  258. * (bit 4 is on).
  259. */
  260. if (value & 0x10) {
  261. duty_value = value & duty_mask;
  262. duty_value >>= pr->throttling.duty_offset;
  263. if (duty_value)
  264. state = pr->throttling.state_count - duty_value;
  265. }
  266. pr->throttling.state = state;
  267. local_irq_enable();
  268. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  269. "Throttling state is T%d (%d%% throttling applied)\n",
  270. state, pr->throttling.states[state].performance));
  271. return 0;
  272. }
  273. static int acpi_read_throttling_status(struct acpi_processor_throttling
  274. *throttling)
  275. {
  276. int value = -1;
  277. switch (throttling->status_register.space_id) {
  278. case ACPI_ADR_SPACE_SYSTEM_IO:
  279. acpi_os_read_port((acpi_io_address) throttling->status_register.
  280. address, &value,
  281. (u32) throttling->status_register.bit_width *
  282. 8);
  283. break;
  284. case ACPI_ADR_SPACE_FIXED_HARDWARE:
  285. printk(KERN_ERR PREFIX
  286. "HARDWARE addr space,NOT supported yet\n");
  287. break;
  288. default:
  289. printk(KERN_ERR PREFIX "Unknown addr space %d\n",
  290. (u32) (throttling->status_register.space_id));
  291. }
  292. return value;
  293. }
  294. static int acpi_write_throttling_state(struct acpi_processor_throttling
  295. *throttling, int value)
  296. {
  297. int ret = -1;
  298. switch (throttling->control_register.space_id) {
  299. case ACPI_ADR_SPACE_SYSTEM_IO:
  300. acpi_os_write_port((acpi_io_address) throttling->
  301. control_register.address, value,
  302. (u32) throttling->control_register.
  303. bit_width * 8);
  304. ret = 0;
  305. break;
  306. case ACPI_ADR_SPACE_FIXED_HARDWARE:
  307. printk(KERN_ERR PREFIX
  308. "HARDWARE addr space,NOT supported yet\n");
  309. break;
  310. default:
  311. printk(KERN_ERR PREFIX "Unknown addr space %d\n",
  312. (u32) (throttling->control_register.space_id));
  313. }
  314. return ret;
  315. }
  316. static int acpi_get_throttling_state(struct acpi_processor *pr, int value)
  317. {
  318. int i;
  319. for (i = 0; i < pr->throttling.state_count; i++) {
  320. struct acpi_processor_tx_tss *tx =
  321. (struct acpi_processor_tx_tss *)&(pr->throttling.
  322. states_tss[i]);
  323. if (tx->control == value)
  324. break;
  325. }
  326. if (i > pr->throttling.state_count)
  327. i = -1;
  328. return i;
  329. }
  330. static int acpi_get_throttling_value(struct acpi_processor *pr, int state)
  331. {
  332. int value = -1;
  333. if (state >= 0 && state <= pr->throttling.state_count) {
  334. struct acpi_processor_tx_tss *tx =
  335. (struct acpi_processor_tx_tss *)&(pr->throttling.
  336. states_tss[state]);
  337. value = tx->control;
  338. }
  339. return value;
  340. }
  341. static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
  342. {
  343. int state = 0;
  344. u32 value = 0;
  345. if (!pr)
  346. return -EINVAL;
  347. if (!pr->flags.throttling)
  348. return -ENODEV;
  349. pr->throttling.state = 0;
  350. local_irq_disable();
  351. value = acpi_read_throttling_status(&pr->throttling);
  352. if (value >= 0) {
  353. state = acpi_get_throttling_state(pr, value);
  354. pr->throttling.state = state;
  355. }
  356. local_irq_enable();
  357. return 0;
  358. }
  359. static int acpi_processor_get_throttling(struct acpi_processor *pr)
  360. {
  361. return pr->throttling.acpi_processor_get_throttling(pr);
  362. }
  363. static int acpi_processor_set_throttling_fadt(struct acpi_processor *pr,
  364. int state)
  365. {
  366. u32 value = 0;
  367. u32 duty_mask = 0;
  368. u32 duty_value = 0;
  369. if (!pr)
  370. return -EINVAL;
  371. if ((state < 0) || (state > (pr->throttling.state_count - 1)))
  372. return -EINVAL;
  373. if (!pr->flags.throttling)
  374. return -ENODEV;
  375. if (state == pr->throttling.state)
  376. return 0;
  377. if (state < pr->throttling_platform_limit)
  378. return -EPERM;
  379. /*
  380. * Calculate the duty_value and duty_mask.
  381. */
  382. if (state) {
  383. duty_value = pr->throttling.state_count - state;
  384. duty_value <<= pr->throttling.duty_offset;
  385. /* Used to clear all duty_value bits */
  386. duty_mask = pr->throttling.state_count - 1;
  387. duty_mask <<= acpi_gbl_FADT.duty_offset;
  388. duty_mask = ~duty_mask;
  389. }
  390. local_irq_disable();
  391. /*
  392. * Disable throttling by writing a 0 to bit 4. Note that we must
  393. * turn it off before you can change the duty_value.
  394. */
  395. value = inl(pr->throttling.address);
  396. if (value & 0x10) {
  397. value &= 0xFFFFFFEF;
  398. outl(value, pr->throttling.address);
  399. }
  400. /*
  401. * Write the new duty_value and then enable throttling. Note
  402. * that a state value of 0 leaves throttling disabled.
  403. */
  404. if (state) {
  405. value &= duty_mask;
  406. value |= duty_value;
  407. outl(value, pr->throttling.address);
  408. value |= 0x00000010;
  409. outl(value, pr->throttling.address);
  410. }
  411. pr->throttling.state = state;
  412. local_irq_enable();
  413. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  414. "Throttling state set to T%d (%d%%)\n", state,
  415. (pr->throttling.states[state].performance ? pr->
  416. throttling.states[state].performance / 10 : 0)));
  417. return 0;
  418. }
  419. static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
  420. int state)
  421. {
  422. u32 value = 0;
  423. if (!pr)
  424. return -EINVAL;
  425. if ((state < 0) || (state > (pr->throttling.state_count - 1)))
  426. return -EINVAL;
  427. if (!pr->flags.throttling)
  428. return -ENODEV;
  429. if (state == pr->throttling.state)
  430. return 0;
  431. if (state < pr->throttling_platform_limit)
  432. return -EPERM;
  433. local_irq_disable();
  434. value = acpi_get_throttling_value(pr, state);
  435. if (value >= 0) {
  436. acpi_write_throttling_state(&pr->throttling, value);
  437. pr->throttling.state = state;
  438. }
  439. local_irq_enable();
  440. return 0;
  441. }
  442. int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
  443. {
  444. return pr->throttling.acpi_processor_set_throttling(pr, state);
  445. }
  446. int acpi_processor_get_throttling_info(struct acpi_processor *pr)
  447. {
  448. int result = 0;
  449. int step = 0;
  450. int i = 0;
  451. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  452. "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
  453. pr->throttling.address,
  454. pr->throttling.duty_offset,
  455. pr->throttling.duty_width));
  456. if (!pr)
  457. return -EINVAL;
  458. /*
  459. * Evaluate _PTC, _TSS and _TPC
  460. * They must all be present or none of them can be used.
  461. */
  462. if (acpi_processor_get_throttling_control(pr) ||
  463. acpi_processor_get_throttling_states(pr) ||
  464. acpi_processor_get_platform_limit(pr))
  465. {
  466. pr->throttling.acpi_processor_get_throttling =
  467. &acpi_processor_get_throttling_fadt;
  468. pr->throttling.acpi_processor_set_throttling =
  469. &acpi_processor_set_throttling_fadt;
  470. } else {
  471. pr->throttling.acpi_processor_get_throttling =
  472. &acpi_processor_get_throttling_ptc;
  473. pr->throttling.acpi_processor_set_throttling =
  474. &acpi_processor_set_throttling_ptc;
  475. }
  476. acpi_processor_get_tsd(pr);
  477. if (!pr->throttling.address) {
  478. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
  479. return 0;
  480. } else if (!pr->throttling.duty_width) {
  481. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n"));
  482. return 0;
  483. }
  484. /* TBD: Support duty_cycle values that span bit 4. */
  485. else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) {
  486. printk(KERN_WARNING PREFIX "duty_cycle spans bit 4\n");
  487. return 0;
  488. }
  489. /*
  490. * PIIX4 Errata: We don't support throttling on the original PIIX4.
  491. * This shouldn't be an issue as few (if any) mobile systems ever
  492. * used this part.
  493. */
  494. if (errata.piix4.throttle) {
  495. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  496. "Throttling not supported on PIIX4 A- or B-step\n"));
  497. return 0;
  498. }
  499. pr->throttling.state_count = 1 << acpi_gbl_FADT.duty_width;
  500. /*
  501. * Compute state values. Note that throttling displays a linear power/
  502. * performance relationship (at 50% performance the CPU will consume
  503. * 50% power). Values are in 1/10th of a percent to preserve accuracy.
  504. */
  505. step = (1000 / pr->throttling.state_count);
  506. for (i = 0; i < pr->throttling.state_count; i++) {
  507. pr->throttling.states[i].performance = step * i;
  508. pr->throttling.states[i].power = step * i;
  509. }
  510. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
  511. pr->throttling.state_count));
  512. pr->flags.throttling = 1;
  513. /*
  514. * Disable throttling (if enabled). We'll let subsequent policy (e.g.
  515. * thermal) decide to lower performance if it so chooses, but for now
  516. * we'll crank up the speed.
  517. */
  518. result = acpi_processor_get_throttling(pr);
  519. if (result)
  520. goto end;
  521. if (pr->throttling.state) {
  522. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  523. "Disabling throttling (was T%d)\n",
  524. pr->throttling.state));
  525. result = acpi_processor_set_throttling(pr, 0);
  526. if (result)
  527. goto end;
  528. }
  529. end:
  530. if (result)
  531. pr->flags.throttling = 0;
  532. return result;
  533. }
  534. /* proc interface */
  535. static int acpi_processor_throttling_seq_show(struct seq_file *seq,
  536. void *offset)
  537. {
  538. struct acpi_processor *pr = seq->private;
  539. int i = 0;
  540. int result = 0;
  541. if (!pr)
  542. goto end;
  543. if (!(pr->throttling.state_count > 0)) {
  544. seq_puts(seq, "<not supported>\n");
  545. goto end;
  546. }
  547. result = acpi_processor_get_throttling(pr);
  548. if (result) {
  549. seq_puts(seq,
  550. "Could not determine current throttling state.\n");
  551. goto end;
  552. }
  553. seq_printf(seq, "state count: %d\n"
  554. "active state: T%d\n"
  555. "state available: T%d to T%d\n",
  556. pr->throttling.state_count, pr->throttling.state,
  557. pr->throttling_platform_limit,
  558. pr->throttling.state_count - 1);
  559. seq_puts(seq, "states:\n");
  560. if (pr->throttling.acpi_processor_get_throttling ==
  561. acpi_processor_get_throttling_fadt) {
  562. for (i = 0; i < pr->throttling.state_count; i++)
  563. seq_printf(seq, " %cT%d: %02d%%\n",
  564. (i == pr->throttling.state ? '*' : ' '), i,
  565. (pr->throttling.states[i].performance ? pr->
  566. throttling.states[i].performance / 10 : 0));
  567. } else {
  568. for (i = 0; i < pr->throttling.state_count; i++)
  569. seq_printf(seq, " %cT%d: %02d%%\n",
  570. (i == pr->throttling.state ? '*' : ' '), i,
  571. (int)pr->throttling.states_tss[i].
  572. freqpercentage);
  573. }
  574. end:
  575. return 0;
  576. }
  577. static int acpi_processor_throttling_open_fs(struct inode *inode,
  578. struct file *file)
  579. {
  580. return single_open(file, acpi_processor_throttling_seq_show,
  581. PDE(inode)->data);
  582. }
  583. static ssize_t acpi_processor_write_throttling(struct file *file,
  584. const char __user * buffer,
  585. size_t count, loff_t * data)
  586. {
  587. int result = 0;
  588. struct seq_file *m = file->private_data;
  589. struct acpi_processor *pr = m->private;
  590. char state_string[12] = { '\0' };
  591. if (!pr || (count > sizeof(state_string) - 1))
  592. return -EINVAL;
  593. if (copy_from_user(state_string, buffer, count))
  594. return -EFAULT;
  595. state_string[count] = '\0';
  596. result = acpi_processor_set_throttling(pr,
  597. simple_strtoul(state_string,
  598. NULL, 0));
  599. if (result)
  600. return result;
  601. return count;
  602. }
  603. struct file_operations acpi_processor_throttling_fops = {
  604. .open = acpi_processor_throttling_open_fs,
  605. .read = seq_read,
  606. .write = acpi_processor_write_throttling,
  607. .llseek = seq_lseek,
  608. .release = single_release,
  609. };