blob: d6780f41d28c5f4cdb703a198b2e3d4b28528296 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Zhao Yakui357dc4c2007-11-29 16:22:43 +080032#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/cpufreq.h>
34#include <linux/proc_fs.h>
35#include <linux/seq_file.h>
36
37#include <asm/io.h>
38#include <asm/uaccess.h>
39
40#include <acpi/acpi_bus.h>
41#include <acpi/processor.h>
42
43#define ACPI_PROCESSOR_COMPONENT 0x01000000
44#define ACPI_PROCESSOR_CLASS "processor"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define _COMPONENT ACPI_PROCESSOR_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050046ACPI_MODULE_NAME("processor_throttling");
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Len Brownff55a9c2007-06-02 00:15:25 -040048static int acpi_processor_get_throttling(struct acpi_processor *pr);
49int acpi_processor_set_throttling(struct acpi_processor *pr, int state);
Luming Yu01854e62007-05-26 22:49:58 +080050
Zhao Yakui11805092008-01-28 13:53:42 +080051static int acpi_processor_update_tsd_coord(void)
52{
53 int count, count_target;
54 int retval = 0;
55 unsigned int i, j;
56 cpumask_t covered_cpus;
57 struct acpi_processor *pr, *match_pr;
58 struct acpi_tsd_package *pdomain, *match_pdomain;
59 struct acpi_processor_throttling *pthrottling, *match_pthrottling;
60
61 /*
62 * Now that we have _TSD data from all CPUs, lets setup T-state
63 * coordination among all CPUs.
64 */
65 for_each_possible_cpu(i) {
66 pr = processors[i];
67 if (!pr)
68 continue;
69
70 /* Basic validity check for domain info */
71 pthrottling = &(pr->throttling);
72
73 /*
74 * If tsd package for one cpu is invalid, the coordination
75 * among all CPUs is thought as invalid.
76 * Maybe it is ugly.
77 */
78 if (!pthrottling->tsd_valid_flag) {
79 retval = -EINVAL;
80 break;
81 }
82 }
83 if (retval)
84 goto err_ret;
85
86 cpus_clear(covered_cpus);
87 for_each_possible_cpu(i) {
88 pr = processors[i];
89 if (!pr)
90 continue;
91
92 if (cpu_isset(i, covered_cpus))
93 continue;
94 pthrottling = &pr->throttling;
95
96 pdomain = &(pthrottling->domain_info);
97 cpu_set(i, pthrottling->shared_cpu_map);
98 cpu_set(i, covered_cpus);
99 /*
100 * If the number of processor in the TSD domain is 1, it is
101 * unnecessary to parse the coordination for this CPU.
102 */
103 if (pdomain->num_processors <= 1)
104 continue;
105
106 /* Validate the Domain info */
107 count_target = pdomain->num_processors;
108 count = 1;
109
110 for_each_possible_cpu(j) {
111 if (i == j)
112 continue;
113
114 match_pr = processors[j];
115 if (!match_pr)
116 continue;
117
118 match_pthrottling = &(match_pr->throttling);
119 match_pdomain = &(match_pthrottling->domain_info);
120 if (match_pdomain->domain != pdomain->domain)
121 continue;
122
123 /* Here i and j are in the same domain.
124 * If two TSD packages have the same domain, they
125 * should have the same num_porcessors and
126 * coordination type. Otherwise it will be regarded
127 * as illegal.
128 */
129 if (match_pdomain->num_processors != count_target) {
130 retval = -EINVAL;
131 goto err_ret;
132 }
133
134 if (pdomain->coord_type != match_pdomain->coord_type) {
135 retval = -EINVAL;
136 goto err_ret;
137 }
138
139 cpu_set(j, covered_cpus);
140 cpu_set(j, pthrottling->shared_cpu_map);
141 count++;
142 }
143 for_each_possible_cpu(j) {
144 if (i == j)
145 continue;
146
147 match_pr = processors[j];
148 if (!match_pr)
149 continue;
150
151 match_pthrottling = &(match_pr->throttling);
152 match_pdomain = &(match_pthrottling->domain_info);
153 if (match_pdomain->domain != pdomain->domain)
154 continue;
155
156 /*
157 * If some CPUS have the same domain, they
158 * will have the same shared_cpu_map.
159 */
160 match_pthrottling->shared_cpu_map =
161 pthrottling->shared_cpu_map;
162 }
163 }
164
165err_ret:
166 for_each_possible_cpu(i) {
167 pr = processors[i];
168 if (!pr)
169 continue;
170
171 /*
172 * Assume no coordination on any error parsing domain info.
173 * The coordination type will be forced as SW_ALL.
174 */
175 if (retval) {
176 pthrottling = &(pr->throttling);
177 cpus_clear(pthrottling->shared_cpu_map);
178 cpu_set(i, pthrottling->shared_cpu_map);
179 pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL;
180 }
181 }
182
183 return retval;
184}
185
186/*
187 * Update the T-state coordination after the _TSD
188 * data for all cpus is obtained.
189 */
190void acpi_processor_throttling_init(void)
191{
192 if (acpi_processor_update_tsd_coord())
193 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
194 "Assume no T-state coordination\n"));
195
196 return;
197}
198
Len Brownc30c6202007-07-25 00:57:46 -0400199/*
200 * _TPC - Throttling Present Capabilities
201 */
Luming Yu01854e62007-05-26 22:49:58 +0800202static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
203{
204 acpi_status status = 0;
205 unsigned long tpc = 0;
206
Len Brownff55a9c2007-06-02 00:15:25 -0400207 if (!pr)
Luming Yu01854e62007-05-26 22:49:58 +0800208 return -EINVAL;
209 status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc);
Len Brownc30c6202007-07-25 00:57:46 -0400210 if (ACPI_FAILURE(status)) {
211 if (status != AE_NOT_FOUND) {
212 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC"));
213 }
Luming Yu01854e62007-05-26 22:49:58 +0800214 return -ENODEV;
215 }
216 pr->throttling_platform_limit = (int)tpc;
217 return 0;
218}
219
220int acpi_processor_tstate_has_changed(struct acpi_processor *pr)
221{
Zhao Yakuief54d5a2007-11-15 16:59:30 +0800222 int result = 0;
223 int throttling_limit;
224 int current_state;
225 struct acpi_processor_limit *limit;
226 int target_state;
227
228 result = acpi_processor_get_platform_limit(pr);
229 if (result) {
230 /* Throttling Limit is unsupported */
231 return result;
232 }
233
234 throttling_limit = pr->throttling_platform_limit;
235 if (throttling_limit >= pr->throttling.state_count) {
236 /* Uncorrect Throttling Limit */
237 return -EINVAL;
238 }
239
240 current_state = pr->throttling.state;
241 if (current_state > throttling_limit) {
242 /*
243 * The current state can meet the requirement of
244 * _TPC limit. But it is reasonable that OSPM changes
245 * t-states from high to low for better performance.
246 * Of course the limit condition of thermal
247 * and user should be considered.
248 */
249 limit = &pr->limit;
250 target_state = throttling_limit;
251 if (limit->thermal.tx > target_state)
252 target_state = limit->thermal.tx;
253 if (limit->user.tx > target_state)
254 target_state = limit->user.tx;
255 } else if (current_state == throttling_limit) {
256 /*
257 * Unnecessary to change the throttling state
258 */
259 return 0;
260 } else {
261 /*
262 * If the current state is lower than the limit of _TPC, it
263 * will be forced to switch to the throttling state defined
264 * by throttling_platfor_limit.
265 * Because the previous state meets with the limit condition
266 * of thermal and user, it is unnecessary to check it again.
267 */
268 target_state = throttling_limit;
269 }
270 return acpi_processor_set_throttling(pr, target_state);
Luming Yu01854e62007-05-26 22:49:58 +0800271}
272
Len Brownc30c6202007-07-25 00:57:46 -0400273/*
274 * _PTC - Processor Throttling Control (and status) register location
275 */
Luming Yu01854e62007-05-26 22:49:58 +0800276static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
277{
278 int result = 0;
279 acpi_status status = 0;
280 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
281 union acpi_object *ptc = NULL;
282 union acpi_object obj = { 0 };
Zhao Yakui9bcb2722007-11-15 17:05:05 +0800283 struct acpi_processor_throttling *throttling;
Luming Yu01854e62007-05-26 22:49:58 +0800284
285 status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer);
286 if (ACPI_FAILURE(status)) {
Len Brownc30c6202007-07-25 00:57:46 -0400287 if (status != AE_NOT_FOUND) {
288 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PTC"));
289 }
Luming Yu01854e62007-05-26 22:49:58 +0800290 return -ENODEV;
291 }
292
293 ptc = (union acpi_object *)buffer.pointer;
294 if (!ptc || (ptc->type != ACPI_TYPE_PACKAGE)
295 || (ptc->package.count != 2)) {
296 printk(KERN_ERR PREFIX "Invalid _PTC data\n");
297 result = -EFAULT;
298 goto end;
299 }
300
301 /*
302 * control_register
303 */
304
305 obj = ptc->package.elements[0];
306
307 if ((obj.type != ACPI_TYPE_BUFFER)
308 || (obj.buffer.length < sizeof(struct acpi_ptc_register))
309 || (obj.buffer.pointer == NULL)) {
Len Brownff55a9c2007-06-02 00:15:25 -0400310 printk(KERN_ERR PREFIX
311 "Invalid _PTC data (control_register)\n");
Luming Yu01854e62007-05-26 22:49:58 +0800312 result = -EFAULT;
313 goto end;
314 }
315 memcpy(&pr->throttling.control_register, obj.buffer.pointer,
316 sizeof(struct acpi_ptc_register));
317
318 /*
319 * status_register
320 */
321
322 obj = ptc->package.elements[1];
323
324 if ((obj.type != ACPI_TYPE_BUFFER)
325 || (obj.buffer.length < sizeof(struct acpi_ptc_register))
326 || (obj.buffer.pointer == NULL)) {
327 printk(KERN_ERR PREFIX "Invalid _PTC data (status_register)\n");
328 result = -EFAULT;
329 goto end;
330 }
331
332 memcpy(&pr->throttling.status_register, obj.buffer.pointer,
Len Brownff55a9c2007-06-02 00:15:25 -0400333 sizeof(struct acpi_ptc_register));
Luming Yu01854e62007-05-26 22:49:58 +0800334
Zhao Yakui9bcb2722007-11-15 17:05:05 +0800335 throttling = &pr->throttling;
336
337 if ((throttling->control_register.bit_width +
338 throttling->control_register.bit_offset) > 32) {
339 printk(KERN_ERR PREFIX "Invalid _PTC control register\n");
340 result = -EFAULT;
341 goto end;
342 }
343
344 if ((throttling->status_register.bit_width +
345 throttling->status_register.bit_offset) > 32) {
346 printk(KERN_ERR PREFIX "Invalid _PTC status register\n");
347 result = -EFAULT;
348 goto end;
349 }
350
Len Brownff55a9c2007-06-02 00:15:25 -0400351 end:
Luming Yu01854e62007-05-26 22:49:58 +0800352 kfree(buffer.pointer);
353
354 return result;
355}
Len Brownc30c6202007-07-25 00:57:46 -0400356
357/*
358 * _TSS - Throttling Supported States
359 */
Luming Yu01854e62007-05-26 22:49:58 +0800360static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
361{
362 int result = 0;
363 acpi_status status = AE_OK;
364 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
365 struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
366 struct acpi_buffer state = { 0, NULL };
367 union acpi_object *tss = NULL;
368 int i;
369
370 status = acpi_evaluate_object(pr->handle, "_TSS", NULL, &buffer);
371 if (ACPI_FAILURE(status)) {
Len Brownc30c6202007-07-25 00:57:46 -0400372 if (status != AE_NOT_FOUND) {
373 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSS"));
374 }
Luming Yu01854e62007-05-26 22:49:58 +0800375 return -ENODEV;
376 }
377
378 tss = buffer.pointer;
379 if (!tss || (tss->type != ACPI_TYPE_PACKAGE)) {
380 printk(KERN_ERR PREFIX "Invalid _TSS data\n");
381 result = -EFAULT;
382 goto end;
383 }
384
385 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
386 tss->package.count));
387
388 pr->throttling.state_count = tss->package.count;
389 pr->throttling.states_tss =
390 kmalloc(sizeof(struct acpi_processor_tx_tss) * tss->package.count,
391 GFP_KERNEL);
392 if (!pr->throttling.states_tss) {
393 result = -ENOMEM;
394 goto end;
395 }
396
397 for (i = 0; i < pr->throttling.state_count; i++) {
398
Len Brownff55a9c2007-06-02 00:15:25 -0400399 struct acpi_processor_tx_tss *tx =
400 (struct acpi_processor_tx_tss *)&(pr->throttling.
401 states_tss[i]);
Luming Yu01854e62007-05-26 22:49:58 +0800402
403 state.length = sizeof(struct acpi_processor_tx_tss);
404 state.pointer = tx;
405
406 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i));
407
408 status = acpi_extract_package(&(tss->package.elements[i]),
409 &format, &state);
410 if (ACPI_FAILURE(status)) {
411 ACPI_EXCEPTION((AE_INFO, status, "Invalid _TSS data"));
412 result = -EFAULT;
413 kfree(pr->throttling.states_tss);
414 goto end;
415 }
416
417 if (!tx->freqpercentage) {
418 printk(KERN_ERR PREFIX
Len Brownff55a9c2007-06-02 00:15:25 -0400419 "Invalid _TSS data: freq is zero\n");
Luming Yu01854e62007-05-26 22:49:58 +0800420 result = -EFAULT;
421 kfree(pr->throttling.states_tss);
422 goto end;
423 }
424 }
425
426 end:
427 kfree(buffer.pointer);
428
429 return result;
430}
Len Brownc30c6202007-07-25 00:57:46 -0400431
432/*
433 * _TSD - T-State Dependencies
434 */
Len Brownff55a9c2007-06-02 00:15:25 -0400435static int acpi_processor_get_tsd(struct acpi_processor *pr)
Luming Yu01854e62007-05-26 22:49:58 +0800436{
437 int result = 0;
438 acpi_status status = AE_OK;
Len Brownff55a9c2007-06-02 00:15:25 -0400439 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
440 struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
441 struct acpi_buffer state = { 0, NULL };
442 union acpi_object *tsd = NULL;
Luming Yu01854e62007-05-26 22:49:58 +0800443 struct acpi_tsd_package *pdomain;
Zhao Yakui11805092008-01-28 13:53:42 +0800444 struct acpi_processor_throttling *pthrottling;
445
446 pthrottling = &pr->throttling;
447 pthrottling->tsd_valid_flag = 0;
Luming Yu01854e62007-05-26 22:49:58 +0800448
449 status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer);
450 if (ACPI_FAILURE(status)) {
Len Brownc30c6202007-07-25 00:57:46 -0400451 if (status != AE_NOT_FOUND) {
452 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSD"));
453 }
Luming Yu01854e62007-05-26 22:49:58 +0800454 return -ENODEV;
455 }
456
457 tsd = buffer.pointer;
458 if (!tsd || (tsd->type != ACPI_TYPE_PACKAGE)) {
459 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
460 result = -EFAULT;
461 goto end;
462 }
463
464 if (tsd->package.count != 1) {
465 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
466 result = -EFAULT;
467 goto end;
468 }
469
470 pdomain = &(pr->throttling.domain_info);
471
472 state.length = sizeof(struct acpi_tsd_package);
473 state.pointer = pdomain;
474
475 status = acpi_extract_package(&(tsd->package.elements[0]),
Len Brownff55a9c2007-06-02 00:15:25 -0400476 &format, &state);
Luming Yu01854e62007-05-26 22:49:58 +0800477 if (ACPI_FAILURE(status)) {
478 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
479 result = -EFAULT;
480 goto end;
481 }
482
483 if (pdomain->num_entries != ACPI_TSD_REV0_ENTRIES) {
484 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:num_entries\n"));
485 result = -EFAULT;
486 goto end;
487 }
488
489 if (pdomain->revision != ACPI_TSD_REV0_REVISION) {
490 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:revision\n"));
491 result = -EFAULT;
492 goto end;
493 }
494
Zhao Yakui11805092008-01-28 13:53:42 +0800495 pthrottling = &pr->throttling;
496 pthrottling->tsd_valid_flag = 1;
497 pthrottling->shared_type = pdomain->coord_type;
498 cpu_set(pr->id, pthrottling->shared_cpu_map);
499 /*
500 * If the coordination type is not defined in ACPI spec,
501 * the tsd_valid_flag will be clear and coordination type
502 * will be forecd as DOMAIN_COORD_TYPE_SW_ALL.
503 */
504 if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL &&
505 pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY &&
506 pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) {
507 pthrottling->tsd_valid_flag = 0;
508 pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL;
509 }
510
Len Brownff55a9c2007-06-02 00:15:25 -0400511 end:
Luming Yu01854e62007-05-26 22:49:58 +0800512 kfree(buffer.pointer);
513 return result;
514}
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516/* --------------------------------------------------------------------------
517 Throttling Control
518 -------------------------------------------------------------------------- */
Luming Yu01854e62007-05-26 22:49:58 +0800519static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520{
Len Brown4be44fc2005-08-05 00:44:28 -0400521 int state = 0;
522 u32 value = 0;
523 u32 duty_mask = 0;
524 u32 duty_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400527 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 if (!pr->flags.throttling)
Patrick Mocheld550d982006-06-27 00:41:40 -0400530 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532 pr->throttling.state = 0;
533
534 duty_mask = pr->throttling.state_count - 1;
535
536 duty_mask <<= pr->throttling.duty_offset;
537
538 local_irq_disable();
539
540 value = inl(pr->throttling.address);
541
542 /*
543 * Compute the current throttling state when throttling is enabled
544 * (bit 4 is on).
545 */
546 if (value & 0x10) {
547 duty_value = value & duty_mask;
548 duty_value >>= pr->throttling.duty_offset;
549
550 if (duty_value)
Len Brown4be44fc2005-08-05 00:44:28 -0400551 state = pr->throttling.state_count - duty_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 }
553
554 pr->throttling.state = state;
555
556 local_irq_enable();
557
558 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400559 "Throttling state is T%d (%d%% throttling applied)\n",
560 state, pr->throttling.states[state].performance));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
Patrick Mocheld550d982006-06-27 00:41:40 -0400562 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563}
564
Zhao Yakuif79f06a2007-11-15 17:06:36 +0800565#ifdef CONFIG_X86
566static int acpi_throttling_rdmsr(struct acpi_processor *pr,
567 acpi_integer * value)
568{
569 struct cpuinfo_x86 *c;
570 u64 msr_high, msr_low;
571 unsigned int cpu;
572 u64 msr = 0;
573 int ret = -1;
574
575 cpu = pr->id;
576 c = &cpu_data(cpu);
577
578 if ((c->x86_vendor != X86_VENDOR_INTEL) ||
579 !cpu_has(c, X86_FEATURE_ACPI)) {
580 printk(KERN_ERR PREFIX
581 "HARDWARE addr space,NOT supported yet\n");
582 } else {
583 msr_low = 0;
584 msr_high = 0;
Zhao Yakui357dc4c2007-11-29 16:22:43 +0800585 rdmsr_safe(MSR_IA32_THERM_CONTROL,
Zhao Yakuif79f06a2007-11-15 17:06:36 +0800586 (u32 *)&msr_low , (u32 *) &msr_high);
587 msr = (msr_high << 32) | msr_low;
588 *value = (acpi_integer) msr;
589 ret = 0;
590 }
591 return ret;
592}
593
594static int acpi_throttling_wrmsr(struct acpi_processor *pr, acpi_integer value)
595{
596 struct cpuinfo_x86 *c;
597 unsigned int cpu;
598 int ret = -1;
599 u64 msr;
600
601 cpu = pr->id;
602 c = &cpu_data(cpu);
603
604 if ((c->x86_vendor != X86_VENDOR_INTEL) ||
605 !cpu_has(c, X86_FEATURE_ACPI)) {
606 printk(KERN_ERR PREFIX
607 "HARDWARE addr space,NOT supported yet\n");
608 } else {
609 msr = value;
Zhao Yakui357dc4c2007-11-29 16:22:43 +0800610 wrmsr_safe(MSR_IA32_THERM_CONTROL,
Zhao Yakuif79f06a2007-11-15 17:06:36 +0800611 msr & 0xffffffff, msr >> 32);
612 ret = 0;
613 }
614 return ret;
615}
616#else
617static int acpi_throttling_rdmsr(struct acpi_processor *pr,
618 acpi_integer * value)
619{
620 printk(KERN_ERR PREFIX
621 "HARDWARE addr space,NOT supported yet\n");
622 return -1;
623}
624
625static int acpi_throttling_wrmsr(struct acpi_processor *pr, acpi_integer value)
626{
627 printk(KERN_ERR PREFIX
628 "HARDWARE addr space,NOT supported yet\n");
629 return -1;
630}
631#endif
632
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800633static int acpi_read_throttling_status(struct acpi_processor *pr,
634 acpi_integer *value)
Luming Yu01854e62007-05-26 22:49:58 +0800635{
Zhao Yakui9bcb2722007-11-15 17:05:05 +0800636 u32 bit_width, bit_offset;
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800637 u64 ptc_value;
Zhao Yakui9bcb2722007-11-15 17:05:05 +0800638 u64 ptc_mask;
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800639 struct acpi_processor_throttling *throttling;
640 int ret = -1;
641
642 throttling = &pr->throttling;
Luming Yu01854e62007-05-26 22:49:58 +0800643 switch (throttling->status_register.space_id) {
644 case ACPI_ADR_SPACE_SYSTEM_IO:
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800645 ptc_value = 0;
Zhao Yakui9bcb2722007-11-15 17:05:05 +0800646 bit_width = throttling->status_register.bit_width;
647 bit_offset = throttling->status_register.bit_offset;
648
Len Brownff55a9c2007-06-02 00:15:25 -0400649 acpi_os_read_port((acpi_io_address) throttling->status_register.
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800650 address, (u32 *) &ptc_value,
Zhao Yakui9bcb2722007-11-15 17:05:05 +0800651 (u32) (bit_width + bit_offset));
652 ptc_mask = (1 << bit_width) - 1;
653 *value = (acpi_integer) ((ptc_value >> bit_offset) & ptc_mask);
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800654 ret = 0;
Luming Yu01854e62007-05-26 22:49:58 +0800655 break;
656 case ACPI_ADR_SPACE_FIXED_HARDWARE:
Zhao Yakuif79f06a2007-11-15 17:06:36 +0800657 ret = acpi_throttling_rdmsr(pr, value);
Luming Yu01854e62007-05-26 22:49:58 +0800658 break;
659 default:
660 printk(KERN_ERR PREFIX "Unknown addr space %d\n",
Len Brownff55a9c2007-06-02 00:15:25 -0400661 (u32) (throttling->status_register.space_id));
Luming Yu01854e62007-05-26 22:49:58 +0800662 }
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800663 return ret;
Luming Yu01854e62007-05-26 22:49:58 +0800664}
665
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800666static int acpi_write_throttling_state(struct acpi_processor *pr,
667 acpi_integer value)
Luming Yu01854e62007-05-26 22:49:58 +0800668{
Zhao Yakui9bcb2722007-11-15 17:05:05 +0800669 u32 bit_width, bit_offset;
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800670 u64 ptc_value;
Zhao Yakui9bcb2722007-11-15 17:05:05 +0800671 u64 ptc_mask;
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800672 struct acpi_processor_throttling *throttling;
Luming Yu01854e62007-05-26 22:49:58 +0800673 int ret = -1;
674
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800675 throttling = &pr->throttling;
Luming Yu01854e62007-05-26 22:49:58 +0800676 switch (throttling->control_register.space_id) {
677 case ACPI_ADR_SPACE_SYSTEM_IO:
Zhao Yakui9bcb2722007-11-15 17:05:05 +0800678 bit_width = throttling->control_register.bit_width;
679 bit_offset = throttling->control_register.bit_offset;
680 ptc_mask = (1 << bit_width) - 1;
681 ptc_value = value & ptc_mask;
682
Len Brownff55a9c2007-06-02 00:15:25 -0400683 acpi_os_write_port((acpi_io_address) throttling->
Zhao Yakui9bcb2722007-11-15 17:05:05 +0800684 control_register.address,
685 (u32) (ptc_value << bit_offset),
686 (u32) (bit_width + bit_offset));
Luming Yu01854e62007-05-26 22:49:58 +0800687 ret = 0;
688 break;
689 case ACPI_ADR_SPACE_FIXED_HARDWARE:
Zhao Yakuif79f06a2007-11-15 17:06:36 +0800690 ret = acpi_throttling_wrmsr(pr, value);
Luming Yu01854e62007-05-26 22:49:58 +0800691 break;
692 default:
693 printk(KERN_ERR PREFIX "Unknown addr space %d\n",
Len Brownff55a9c2007-06-02 00:15:25 -0400694 (u32) (throttling->control_register.space_id));
Luming Yu01854e62007-05-26 22:49:58 +0800695 }
696 return ret;
697}
698
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800699static int acpi_get_throttling_state(struct acpi_processor *pr,
700 acpi_integer value)
Luming Yu01854e62007-05-26 22:49:58 +0800701{
702 int i;
703
704 for (i = 0; i < pr->throttling.state_count; i++) {
Len Brownff55a9c2007-06-02 00:15:25 -0400705 struct acpi_processor_tx_tss *tx =
706 (struct acpi_processor_tx_tss *)&(pr->throttling.
707 states_tss[i]);
708 if (tx->control == value)
Luming Yu01854e62007-05-26 22:49:58 +0800709 break;
710 }
Len Brownff55a9c2007-06-02 00:15:25 -0400711 if (i > pr->throttling.state_count)
712 i = -1;
Luming Yu01854e62007-05-26 22:49:58 +0800713 return i;
714}
715
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800716static int acpi_get_throttling_value(struct acpi_processor *pr,
717 int state, acpi_integer *value)
Luming Yu01854e62007-05-26 22:49:58 +0800718{
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800719 int ret = -1;
720
Len Brownff55a9c2007-06-02 00:15:25 -0400721 if (state >= 0 && state <= pr->throttling.state_count) {
722 struct acpi_processor_tx_tss *tx =
723 (struct acpi_processor_tx_tss *)&(pr->throttling.
724 states_tss[state]);
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800725 *value = tx->control;
726 ret = 0;
Luming Yu01854e62007-05-26 22:49:58 +0800727 }
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800728 return ret;
Luming Yu01854e62007-05-26 22:49:58 +0800729}
730
731static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
732{
733 int state = 0;
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800734 int ret;
735 acpi_integer value;
Luming Yu01854e62007-05-26 22:49:58 +0800736
Luming Yu01854e62007-05-26 22:49:58 +0800737 if (!pr)
738 return -EINVAL;
739
740 if (!pr->flags.throttling)
741 return -ENODEV;
742
743 pr->throttling.state = 0;
Zhao Yakui357dc4c2007-11-29 16:22:43 +0800744
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800745 value = 0;
746 ret = acpi_read_throttling_status(pr, &value);
747 if (ret >= 0) {
Len Brownff55a9c2007-06-02 00:15:25 -0400748 state = acpi_get_throttling_state(pr, value);
Luming Yu01854e62007-05-26 22:49:58 +0800749 pr->throttling.state = state;
750 }
Luming Yu01854e62007-05-26 22:49:58 +0800751
752 return 0;
753}
754
Luming Yu01854e62007-05-26 22:49:58 +0800755static int acpi_processor_get_throttling(struct acpi_processor *pr)
756{
Zhao Yakui357dc4c2007-11-29 16:22:43 +0800757 cpumask_t saved_mask;
758 int ret;
759
Zhao Yakui87654272008-01-28 13:53:30 +0800760 if (!pr)
761 return -EINVAL;
762
763 if (!pr->flags.throttling)
764 return -ENODEV;
Zhao Yakui357dc4c2007-11-29 16:22:43 +0800765 /*
766 * Migrate task to the cpu pointed by pr.
767 */
768 saved_mask = current->cpus_allowed;
769 set_cpus_allowed(current, cpumask_of_cpu(pr->id));
770 ret = pr->throttling.acpi_processor_get_throttling(pr);
771 /* restore the previous state */
772 set_cpus_allowed(current, saved_mask);
773
774 return ret;
Luming Yu01854e62007-05-26 22:49:58 +0800775}
776
Zhao Yakui22cc5012007-11-15 17:02:03 +0800777static int acpi_processor_get_fadt_info(struct acpi_processor *pr)
778{
779 int i, step;
780
781 if (!pr->throttling.address) {
782 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
783 return -EINVAL;
784 } else if (!pr->throttling.duty_width) {
785 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n"));
786 return -EINVAL;
787 }
788 /* TBD: Support duty_cycle values that span bit 4. */
789 else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) {
790 printk(KERN_WARNING PREFIX "duty_cycle spans bit 4\n");
791 return -EINVAL;
792 }
793
794 pr->throttling.state_count = 1 << acpi_gbl_FADT.duty_width;
795
796 /*
797 * Compute state values. Note that throttling displays a linear power
798 * performance relationship (at 50% performance the CPU will consume
799 * 50% power). Values are in 1/10th of a percent to preserve accuracy.
800 */
801
802 step = (1000 / pr->throttling.state_count);
803
804 for (i = 0; i < pr->throttling.state_count; i++) {
805 pr->throttling.states[i].performance = 1000 - step * i;
806 pr->throttling.states[i].power = 1000 - step * i;
807 }
808 return 0;
809}
810
Adrian Bunk6c5cf8a2007-07-03 00:53:12 -0400811static int acpi_processor_set_throttling_fadt(struct acpi_processor *pr,
812 int state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Len Brown4be44fc2005-08-05 00:44:28 -0400814 u32 value = 0;
815 u32 duty_mask = 0;
816 u32 duty_value = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400819 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
Patrick Mocheld550d982006-06-27 00:41:40 -0400822 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 if (!pr->flags.throttling)
Patrick Mocheld550d982006-06-27 00:41:40 -0400825 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 if (state == pr->throttling.state)
Patrick Mocheld550d982006-06-27 00:41:40 -0400828 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
Luming Yu01854e62007-05-26 22:49:58 +0800830 if (state < pr->throttling_platform_limit)
831 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 /*
833 * Calculate the duty_value and duty_mask.
834 */
835 if (state) {
836 duty_value = pr->throttling.state_count - state;
837
838 duty_value <<= pr->throttling.duty_offset;
839
840 /* Used to clear all duty_value bits */
841 duty_mask = pr->throttling.state_count - 1;
842
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300843 duty_mask <<= acpi_gbl_FADT.duty_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 duty_mask = ~duty_mask;
845 }
846
847 local_irq_disable();
848
849 /*
850 * Disable throttling by writing a 0 to bit 4. Note that we must
851 * turn it off before you can change the duty_value.
852 */
853 value = inl(pr->throttling.address);
854 if (value & 0x10) {
855 value &= 0xFFFFFFEF;
856 outl(value, pr->throttling.address);
857 }
858
859 /*
860 * Write the new duty_value and then enable throttling. Note
861 * that a state value of 0 leaves throttling disabled.
862 */
863 if (state) {
864 value &= duty_mask;
865 value |= duty_value;
866 outl(value, pr->throttling.address);
867
868 value |= 0x00000010;
869 outl(value, pr->throttling.address);
870 }
871
872 pr->throttling.state = state;
873
874 local_irq_enable();
875
876 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400877 "Throttling state set to T%d (%d%%)\n", state,
878 (pr->throttling.states[state].performance ? pr->
879 throttling.states[state].performance / 10 : 0)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
Patrick Mocheld550d982006-06-27 00:41:40 -0400881 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882}
883
Adrian Bunk6c5cf8a2007-07-03 00:53:12 -0400884static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr,
885 int state)
Luming Yu01854e62007-05-26 22:49:58 +0800886{
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800887 int ret;
888 acpi_integer value;
Luming Yu01854e62007-05-26 22:49:58 +0800889
890 if (!pr)
891 return -EINVAL;
892
893 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
894 return -EINVAL;
895
896 if (!pr->flags.throttling)
897 return -ENODEV;
898
899 if (state == pr->throttling.state)
900 return 0;
901
902 if (state < pr->throttling_platform_limit)
903 return -EPERM;
904
Zhao Yakui0753f6e2007-11-15 17:03:46 +0800905 value = 0;
906 ret = acpi_get_throttling_value(pr, state, &value);
907 if (ret >= 0) {
908 acpi_write_throttling_state(pr, value);
Luming Yu01854e62007-05-26 22:49:58 +0800909 pr->throttling.state = state;
910 }
Luming Yu01854e62007-05-26 22:49:58 +0800911
912 return 0;
913}
914
915int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
916{
Zhao Yakui357dc4c2007-11-29 16:22:43 +0800917 cpumask_t saved_mask;
918 int ret;
Zhao Yakui87654272008-01-28 13:53:30 +0800919
920 if (!pr)
921 return -EINVAL;
922
923 if (!pr->flags.throttling)
924 return -ENODEV;
925
926 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
927 return -EINVAL;
928
Zhao Yakui357dc4c2007-11-29 16:22:43 +0800929 /*
930 * Migrate task to the cpu pointed by pr.
931 */
932 saved_mask = current->cpus_allowed;
933 set_cpus_allowed(current, cpumask_of_cpu(pr->id));
934 ret = pr->throttling.acpi_processor_set_throttling(pr, state);
935 /* restore the previous state */
936 set_cpus_allowed(current, saved_mask);
937 return ret;
Luming Yu01854e62007-05-26 22:49:58 +0800938}
939
Len Brown4be44fc2005-08-05 00:44:28 -0400940int acpi_processor_get_throttling_info(struct acpi_processor *pr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
Len Brown4be44fc2005-08-05 00:44:28 -0400942 int result = 0;
Zhao Yakui11805092008-01-28 13:53:42 +0800943 struct acpi_processor_throttling *pthrottling;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400946 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
947 pr->throttling.address,
948 pr->throttling.duty_offset,
949 pr->throttling.duty_width));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951 if (!pr)
Patrick Mocheld550d982006-06-27 00:41:40 -0400952 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953
Len Brownc30c6202007-07-25 00:57:46 -0400954 /*
955 * Evaluate _PTC, _TSS and _TPC
956 * They must all be present or none of them can be used.
957 */
958 if (acpi_processor_get_throttling_control(pr) ||
959 acpi_processor_get_throttling_states(pr) ||
960 acpi_processor_get_platform_limit(pr))
961 {
Len Brownff55a9c2007-06-02 00:15:25 -0400962 pr->throttling.acpi_processor_get_throttling =
963 &acpi_processor_get_throttling_fadt;
964 pr->throttling.acpi_processor_set_throttling =
965 &acpi_processor_set_throttling_fadt;
Alexey Starikovskiyd1154be2008-01-15 00:47:47 -0500966 if (acpi_processor_get_fadt_info(pr))
967 return 0;
Luming Yu01854e62007-05-26 22:49:58 +0800968 } else {
Len Brownff55a9c2007-06-02 00:15:25 -0400969 pr->throttling.acpi_processor_get_throttling =
970 &acpi_processor_get_throttling_ptc;
971 pr->throttling.acpi_processor_set_throttling =
972 &acpi_processor_set_throttling_ptc;
Luming Yu01854e62007-05-26 22:49:58 +0800973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Zhao Yakui11805092008-01-28 13:53:42 +0800975 /*
976 * If TSD package for one CPU can't be parsed successfully, it means
977 * that this CPU will have no coordination with other CPUs.
978 */
979 if (acpi_processor_get_tsd(pr)) {
980 pthrottling = &pr->throttling;
981 pthrottling->tsd_valid_flag = 0;
982 cpu_set(pr->id, pthrottling->shared_cpu_map);
983 pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL;
984 }
Len Brownc30c6202007-07-25 00:57:46 -0400985
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 /*
987 * PIIX4 Errata: We don't support throttling on the original PIIX4.
988 * This shouldn't be an issue as few (if any) mobile systems ever
989 * used this part.
990 */
991 if (errata.piix4.throttle) {
992 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Len Brown4be44fc2005-08-05 00:44:28 -0400993 "Throttling not supported on PIIX4 A- or B-step\n"));
Patrick Mocheld550d982006-06-27 00:41:40 -0400994 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 }
996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400998 pr->throttling.state_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
1000 pr->flags.throttling = 1;
1001
1002 /*
1003 * Disable throttling (if enabled). We'll let subsequent policy (e.g.
1004 * thermal) decide to lower performance if it so chooses, but for now
1005 * we'll crank up the speed.
1006 */
1007
1008 result = acpi_processor_get_throttling(pr);
1009 if (result)
1010 goto end;
1011
1012 if (pr->throttling.state) {
Len Brown4be44fc2005-08-05 00:44:28 -04001013 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
1014 "Disabling throttling (was T%d)\n",
1015 pr->throttling.state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 result = acpi_processor_set_throttling(pr, 0);
1017 if (result)
1018 goto end;
1019 }
1020
Len Brown4be44fc2005-08-05 00:44:28 -04001021 end:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (result)
1023 pr->flags.throttling = 0;
1024
Patrick Mocheld550d982006-06-27 00:41:40 -04001025 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026}
1027
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028/* proc interface */
1029
Len Brown4be44fc2005-08-05 00:44:28 -04001030static int acpi_processor_throttling_seq_show(struct seq_file *seq,
1031 void *offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001033 struct acpi_processor *pr = seq->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001034 int i = 0;
1035 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 if (!pr)
1038 goto end;
1039
1040 if (!(pr->throttling.state_count > 0)) {
1041 seq_puts(seq, "<not supported>\n");
1042 goto end;
1043 }
1044
1045 result = acpi_processor_get_throttling(pr);
1046
1047 if (result) {
Len Brown4be44fc2005-08-05 00:44:28 -04001048 seq_puts(seq,
1049 "Could not determine current throttling state.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 goto end;
1051 }
1052
1053 seq_printf(seq, "state count: %d\n"
Luming Yu01854e62007-05-26 22:49:58 +08001054 "active state: T%d\n"
Len Brownff55a9c2007-06-02 00:15:25 -04001055 "state available: T%d to T%d\n",
Luming Yu01854e62007-05-26 22:49:58 +08001056 pr->throttling.state_count, pr->throttling.state,
Len Brownff55a9c2007-06-02 00:15:25 -04001057 pr->throttling_platform_limit,
1058 pr->throttling.state_count - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
1060 seq_puts(seq, "states:\n");
Luming Yu3cc26492007-07-23 12:39:28 -04001061 if (pr->throttling.acpi_processor_get_throttling ==
1062 acpi_processor_get_throttling_fadt) {
Luming Yu01854e62007-05-26 22:49:58 +08001063 for (i = 0; i < pr->throttling.state_count; i++)
1064 seq_printf(seq, " %cT%d: %02d%%\n",
Len Brownff55a9c2007-06-02 00:15:25 -04001065 (i == pr->throttling.state ? '*' : ' '), i,
1066 (pr->throttling.states[i].performance ? pr->
1067 throttling.states[i].performance / 10 : 0));
Luming Yu3cc26492007-07-23 12:39:28 -04001068 } else {
Luming Yu01854e62007-05-26 22:49:58 +08001069 for (i = 0; i < pr->throttling.state_count; i++)
1070 seq_printf(seq, " %cT%d: %02d%%\n",
Len Brownff55a9c2007-06-02 00:15:25 -04001071 (i == pr->throttling.state ? '*' : ' '), i,
1072 (int)pr->throttling.states_tss[i].
1073 freqpercentage);
Luming Yu3cc26492007-07-23 12:39:28 -04001074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Len Brown4be44fc2005-08-05 00:44:28 -04001076 end:
Patrick Mocheld550d982006-06-27 00:41:40 -04001077 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078}
1079
Len Brown4be44fc2005-08-05 00:44:28 -04001080static int acpi_processor_throttling_open_fs(struct inode *inode,
1081 struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082{
1083 return single_open(file, acpi_processor_throttling_seq_show,
Len Brown4be44fc2005-08-05 00:44:28 -04001084 PDE(inode)->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085}
1086
Len Brownff55a9c2007-06-02 00:15:25 -04001087static ssize_t acpi_processor_write_throttling(struct file *file,
Adrian Bunk757b1862006-01-07 13:19:00 -05001088 const char __user * buffer,
1089 size_t count, loff_t * data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090{
Len Brown4be44fc2005-08-05 00:44:28 -04001091 int result = 0;
Jan Engelhardt50dd0962006-10-01 00:28:50 +02001092 struct seq_file *m = file->private_data;
1093 struct acpi_processor *pr = m->private;
Len Brown4be44fc2005-08-05 00:44:28 -04001094 char state_string[12] = { '\0' };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 if (!pr || (count > sizeof(state_string) - 1))
Patrick Mocheld550d982006-06-27 00:41:40 -04001097 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 if (copy_from_user(state_string, buffer, count))
Patrick Mocheld550d982006-06-27 00:41:40 -04001100 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 state_string[count] = '\0';
1103
1104 result = acpi_processor_set_throttling(pr,
Len Brown4be44fc2005-08-05 00:44:28 -04001105 simple_strtoul(state_string,
1106 NULL, 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 if (result)
Patrick Mocheld550d982006-06-27 00:41:40 -04001108 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Patrick Mocheld550d982006-06-27 00:41:40 -04001110 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111}
1112
1113struct file_operations acpi_processor_throttling_fops = {
Len Brown4be44fc2005-08-05 00:44:28 -04001114 .open = acpi_processor_throttling_open_fs,
1115 .read = seq_read,
Arjan van de Vend479e902006-01-06 16:47:00 -05001116 .write = acpi_processor_write_throttling,
Len Brown4be44fc2005-08-05 00:44:28 -04001117 .llseek = seq_lseek,
1118 .release = single_release,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119};