processor_throttling.c 18 KB

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