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