processor_throttling.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, int state)
  346. {
  347. u32 value = 0;
  348. u32 duty_mask = 0;
  349. u32 duty_value = 0;
  350. if (!pr)
  351. return -EINVAL;
  352. if ((state < 0) || (state > (pr->throttling.state_count - 1)))
  353. return -EINVAL;
  354. if (!pr->flags.throttling)
  355. return -ENODEV;
  356. if (state == pr->throttling.state)
  357. return 0;
  358. if (state < pr->throttling_platform_limit)
  359. return -EPERM;
  360. /*
  361. * Calculate the duty_value and duty_mask.
  362. */
  363. if (state) {
  364. duty_value = pr->throttling.state_count - state;
  365. duty_value <<= pr->throttling.duty_offset;
  366. /* Used to clear all duty_value bits */
  367. duty_mask = pr->throttling.state_count - 1;
  368. duty_mask <<= acpi_gbl_FADT.duty_offset;
  369. duty_mask = ~duty_mask;
  370. }
  371. local_irq_disable();
  372. /*
  373. * Disable throttling by writing a 0 to bit 4. Note that we must
  374. * turn it off before you can change the duty_value.
  375. */
  376. value = inl(pr->throttling.address);
  377. if (value & 0x10) {
  378. value &= 0xFFFFFFEF;
  379. outl(value, pr->throttling.address);
  380. }
  381. /*
  382. * Write the new duty_value and then enable throttling. Note
  383. * that a state value of 0 leaves throttling disabled.
  384. */
  385. if (state) {
  386. value &= duty_mask;
  387. value |= duty_value;
  388. outl(value, pr->throttling.address);
  389. value |= 0x00000010;
  390. outl(value, pr->throttling.address);
  391. }
  392. pr->throttling.state = state;
  393. local_irq_enable();
  394. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  395. "Throttling state set to T%d (%d%%)\n", state,
  396. (pr->throttling.states[state].performance ? pr->
  397. throttling.states[state].performance / 10 : 0)));
  398. return 0;
  399. }
  400. int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state)
  401. {
  402. u32 value = 0;
  403. if (!pr)
  404. return -EINVAL;
  405. if ((state < 0) || (state > (pr->throttling.state_count - 1)))
  406. return -EINVAL;
  407. if (!pr->flags.throttling)
  408. return -ENODEV;
  409. if (state == pr->throttling.state)
  410. return 0;
  411. if (state < pr->throttling_platform_limit)
  412. return -EPERM;
  413. local_irq_disable();
  414. value = acpi_get_throttling_value(pr, state);
  415. if (value >= 0) {
  416. acpi_write_throttling_state(&pr->throttling, value);
  417. pr->throttling.state = state;
  418. }
  419. local_irq_enable();
  420. return 0;
  421. }
  422. int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
  423. {
  424. return pr->throttling.acpi_processor_set_throttling(pr, state);
  425. }
  426. int acpi_processor_get_throttling_info(struct acpi_processor *pr)
  427. {
  428. int result = 0;
  429. int step = 0;
  430. int i = 0;
  431. int no_ptc = 0;
  432. int no_tss = 0;
  433. int no_tsd = 0;
  434. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  435. "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
  436. pr->throttling.address,
  437. pr->throttling.duty_offset,
  438. pr->throttling.duty_width));
  439. if (!pr)
  440. return -EINVAL;
  441. /* TBD: Support ACPI 2.0 objects */
  442. no_ptc = acpi_processor_get_throttling_control(pr);
  443. no_tss = acpi_processor_get_throttling_states(pr);
  444. no_tsd = acpi_processor_get_tsd(pr);
  445. if (no_ptc || no_tss) {
  446. pr->throttling.acpi_processor_get_throttling =
  447. &acpi_processor_get_throttling_fadt;
  448. pr->throttling.acpi_processor_set_throttling =
  449. &acpi_processor_set_throttling_fadt;
  450. } else {
  451. pr->throttling.acpi_processor_get_throttling =
  452. &acpi_processor_get_throttling_ptc;
  453. pr->throttling.acpi_processor_set_throttling =
  454. &acpi_processor_set_throttling_ptc;
  455. }
  456. if (!pr->throttling.address) {
  457. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
  458. return 0;
  459. } else if (!pr->throttling.duty_width) {
  460. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n"));
  461. return 0;
  462. }
  463. /* TBD: Support duty_cycle values that span bit 4. */
  464. else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) {
  465. printk(KERN_WARNING PREFIX "duty_cycle spans bit 4\n");
  466. return 0;
  467. }
  468. /*
  469. * PIIX4 Errata: We don't support throttling on the original PIIX4.
  470. * This shouldn't be an issue as few (if any) mobile systems ever
  471. * used this part.
  472. */
  473. if (errata.piix4.throttle) {
  474. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  475. "Throttling not supported on PIIX4 A- or B-step\n"));
  476. return 0;
  477. }
  478. pr->throttling.state_count = 1 << acpi_gbl_FADT.duty_width;
  479. /*
  480. * Compute state values. Note that throttling displays a linear power/
  481. * performance relationship (at 50% performance the CPU will consume
  482. * 50% power). Values are in 1/10th of a percent to preserve accuracy.
  483. */
  484. step = (1000 / pr->throttling.state_count);
  485. for (i = 0; i < pr->throttling.state_count; i++) {
  486. pr->throttling.states[i].performance = step * i;
  487. pr->throttling.states[i].power = step * i;
  488. }
  489. ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
  490. pr->throttling.state_count));
  491. pr->flags.throttling = 1;
  492. /*
  493. * Disable throttling (if enabled). We'll let subsequent policy (e.g.
  494. * thermal) decide to lower performance if it so chooses, but for now
  495. * we'll crank up the speed.
  496. */
  497. result = acpi_processor_get_throttling(pr);
  498. if (result)
  499. goto end;
  500. if (pr->throttling.state) {
  501. ACPI_DEBUG_PRINT((ACPI_DB_INFO,
  502. "Disabling throttling (was T%d)\n",
  503. pr->throttling.state));
  504. result = acpi_processor_set_throttling(pr, 0);
  505. if (result)
  506. goto end;
  507. }
  508. end:
  509. if (result)
  510. pr->flags.throttling = 0;
  511. return result;
  512. }
  513. /* proc interface */
  514. static int acpi_processor_throttling_seq_show(struct seq_file *seq,
  515. void *offset)
  516. {
  517. struct acpi_processor *pr = seq->private;
  518. int i = 0;
  519. int result = 0;
  520. if (!pr)
  521. goto end;
  522. if (!(pr->throttling.state_count > 0)) {
  523. seq_puts(seq, "<not supported>\n");
  524. goto end;
  525. }
  526. result = acpi_processor_get_throttling(pr);
  527. if (result) {
  528. seq_puts(seq,
  529. "Could not determine current throttling state.\n");
  530. goto end;
  531. }
  532. seq_printf(seq, "state count: %d\n"
  533. "active state: T%d\n"
  534. "state available: T%d to T%d\n",
  535. pr->throttling.state_count, pr->throttling.state,
  536. pr->throttling_platform_limit,
  537. pr->throttling.state_count - 1);
  538. seq_puts(seq, "states:\n");
  539. if (acpi_processor_get_throttling == acpi_processor_get_throttling_fadt)
  540. for (i = 0; i < pr->throttling.state_count; i++)
  541. seq_printf(seq, " %cT%d: %02d%%\n",
  542. (i == pr->throttling.state ? '*' : ' '), i,
  543. (pr->throttling.states[i].performance ? pr->
  544. throttling.states[i].performance / 10 : 0));
  545. else
  546. for (i = 0; i < pr->throttling.state_count; i++)
  547. seq_printf(seq, " %cT%d: %02d%%\n",
  548. (i == pr->throttling.state ? '*' : ' '), i,
  549. (int)pr->throttling.states_tss[i].
  550. freqpercentage);
  551. end:
  552. return 0;
  553. }
  554. static int acpi_processor_throttling_open_fs(struct inode *inode,
  555. struct file *file)
  556. {
  557. return single_open(file, acpi_processor_throttling_seq_show,
  558. PDE(inode)->data);
  559. }
  560. static ssize_t acpi_processor_write_throttling(struct file *file,
  561. const char __user * buffer,
  562. size_t count, loff_t * data)
  563. {
  564. int result = 0;
  565. struct seq_file *m = file->private_data;
  566. struct acpi_processor *pr = m->private;
  567. char state_string[12] = { '\0' };
  568. if (!pr || (count > sizeof(state_string) - 1))
  569. return -EINVAL;
  570. if (copy_from_user(state_string, buffer, count))
  571. return -EFAULT;
  572. state_string[count] = '\0';
  573. result = acpi_processor_set_throttling(pr,
  574. simple_strtoul(state_string,
  575. NULL, 0));
  576. if (result)
  577. return result;
  578. return count;
  579. }
  580. struct file_operations acpi_processor_throttling_fops = {
  581. .open = acpi_processor_throttling_open_fs,
  582. .read = seq_read,
  583. .write = acpi_processor_write_throttling,
  584. .llseek = seq_lseek,
  585. .release = single_release,
  586. };