processor_throttling.c 20 KB

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