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