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