diff options
author | Len Brown <len.brown@intel.com> | 2007-06-02 00:15:25 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2007-06-02 00:15:25 -0400 |
commit | ff55a9cebab02403f942121e2f898bb06ecfffbb (patch) | |
tree | cb99a74f44ae83d2e937b02365210c59fc593740 /drivers/acpi | |
parent | 01854e697a77a434104b2f7e6d7fd463a978af32 (diff) |
ACPI: Lindent processor throttling code
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/processor_throttling.c | 140 |
1 files changed, 75 insertions, 65 deletions
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c index 1bae2e42a7c7..3a2e9a601874 100644 --- a/drivers/acpi/processor_throttling.c +++ b/drivers/acpi/processor_throttling.c | |||
@@ -44,18 +44,18 @@ | |||
44 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT | 44 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT |
45 | ACPI_MODULE_NAME("processor_throttling"); | 45 | ACPI_MODULE_NAME("processor_throttling"); |
46 | 46 | ||
47 | static int acpi_processor_get_throttling (struct acpi_processor *pr); | 47 | static int acpi_processor_get_throttling(struct acpi_processor *pr); |
48 | int acpi_processor_set_throttling (struct acpi_processor *pr, int state); | 48 | int acpi_processor_set_throttling(struct acpi_processor *pr, int state); |
49 | 49 | ||
50 | static int acpi_processor_get_platform_limit(struct acpi_processor *pr) | 50 | static int acpi_processor_get_platform_limit(struct acpi_processor *pr) |
51 | { | 51 | { |
52 | acpi_status status = 0; | 52 | acpi_status status = 0; |
53 | unsigned long tpc = 0; | 53 | unsigned long tpc = 0; |
54 | 54 | ||
55 | if(!pr) | 55 | if (!pr) |
56 | return -EINVAL; | 56 | return -EINVAL; |
57 | status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc); | 57 | status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc); |
58 | if(ACPI_FAILURE(status) && status != AE_NOT_FOUND){ | 58 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
59 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC")); | 59 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC")); |
60 | return -ENODEV; | 60 | return -ENODEV; |
61 | } | 61 | } |
@@ -102,7 +102,8 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr) | |||
102 | if ((obj.type != ACPI_TYPE_BUFFER) | 102 | if ((obj.type != ACPI_TYPE_BUFFER) |
103 | || (obj.buffer.length < sizeof(struct acpi_ptc_register)) | 103 | || (obj.buffer.length < sizeof(struct acpi_ptc_register)) |
104 | || (obj.buffer.pointer == NULL)) { | 104 | || (obj.buffer.pointer == NULL)) { |
105 | printk(KERN_ERR PREFIX "Invalid _PTC data (control_register)\n"); | 105 | printk(KERN_ERR PREFIX |
106 | "Invalid _PTC data (control_register)\n"); | ||
106 | result = -EFAULT; | 107 | result = -EFAULT; |
107 | goto end; | 108 | goto end; |
108 | } | 109 | } |
@@ -124,9 +125,9 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr) | |||
124 | } | 125 | } |
125 | 126 | ||
126 | memcpy(&pr->throttling.status_register, obj.buffer.pointer, | 127 | memcpy(&pr->throttling.status_register, obj.buffer.pointer, |
127 | sizeof(struct acpi_ptc_register)); | 128 | sizeof(struct acpi_ptc_register)); |
128 | 129 | ||
129 | end: | 130 | end: |
130 | kfree(buffer.pointer); | 131 | kfree(buffer.pointer); |
131 | 132 | ||
132 | return result; | 133 | return result; |
@@ -168,7 +169,9 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) | |||
168 | 169 | ||
169 | for (i = 0; i < pr->throttling.state_count; i++) { | 170 | for (i = 0; i < pr->throttling.state_count; i++) { |
170 | 171 | ||
171 | struct acpi_processor_tx_tss *tx = (struct acpi_processor_tx_tss *) &(pr->throttling.states_tss[i]); | 172 | struct acpi_processor_tx_tss *tx = |
173 | (struct acpi_processor_tx_tss *)&(pr->throttling. | ||
174 | states_tss[i]); | ||
172 | 175 | ||
173 | state.length = sizeof(struct acpi_processor_tx_tss); | 176 | state.length = sizeof(struct acpi_processor_tx_tss); |
174 | state.pointer = tx; | 177 | state.pointer = tx; |
@@ -186,7 +189,7 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) | |||
186 | 189 | ||
187 | if (!tx->freqpercentage) { | 190 | if (!tx->freqpercentage) { |
188 | printk(KERN_ERR PREFIX | 191 | printk(KERN_ERR PREFIX |
189 | "Invalid _TSS data: freq is zero\n"); | 192 | "Invalid _TSS data: freq is zero\n"); |
190 | result = -EFAULT; | 193 | result = -EFAULT; |
191 | kfree(pr->throttling.states_tss); | 194 | kfree(pr->throttling.states_tss); |
192 | goto end; | 195 | goto end; |
@@ -198,14 +201,14 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) | |||
198 | 201 | ||
199 | return result; | 202 | return result; |
200 | } | 203 | } |
201 | static int acpi_processor_get_tsd(struct acpi_processor *pr) | 204 | static int acpi_processor_get_tsd(struct acpi_processor *pr) |
202 | { | 205 | { |
203 | int result = 0; | 206 | int result = 0; |
204 | acpi_status status = AE_OK; | 207 | acpi_status status = AE_OK; |
205 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; | 208 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
206 | struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"}; | 209 | struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" }; |
207 | struct acpi_buffer state = {0, NULL}; | 210 | struct acpi_buffer state = { 0, NULL }; |
208 | union acpi_object *tsd = NULL; | 211 | union acpi_object *tsd = NULL; |
209 | struct acpi_tsd_package *pdomain; | 212 | struct acpi_tsd_package *pdomain; |
210 | 213 | ||
211 | status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer); | 214 | status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer); |
@@ -232,7 +235,7 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr) | |||
232 | state.pointer = pdomain; | 235 | state.pointer = pdomain; |
233 | 236 | ||
234 | status = acpi_extract_package(&(tsd->package.elements[0]), | 237 | status = acpi_extract_package(&(tsd->package.elements[0]), |
235 | &format, &state); | 238 | &format, &state); |
236 | if (ACPI_FAILURE(status)) { | 239 | if (ACPI_FAILURE(status)) { |
237 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); | 240 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); |
238 | result = -EFAULT; | 241 | result = -EFAULT; |
@@ -251,7 +254,7 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr) | |||
251 | goto end; | 254 | goto end; |
252 | } | 255 | } |
253 | 256 | ||
254 | end: | 257 | end: |
255 | kfree(buffer.pointer); | 258 | kfree(buffer.pointer); |
256 | return result; | 259 | return result; |
257 | } | 260 | } |
@@ -266,7 +269,6 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr) | |||
266 | u32 duty_mask = 0; | 269 | u32 duty_mask = 0; |
267 | u32 duty_value = 0; | 270 | u32 duty_value = 0; |
268 | 271 | ||
269 | |||
270 | if (!pr) | 272 | if (!pr) |
271 | return -EINVAL; | 273 | return -EINVAL; |
272 | 274 | ||
@@ -306,65 +308,75 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr) | |||
306 | return 0; | 308 | return 0; |
307 | } | 309 | } |
308 | 310 | ||
309 | static int acpi_read_throttling_status(struct acpi_processor_throttling *throttling) | 311 | static int acpi_read_throttling_status(struct acpi_processor_throttling |
312 | *throttling) | ||
310 | { | 313 | { |
311 | int value = -1; | 314 | int value = -1; |
312 | switch (throttling->status_register.space_id) { | 315 | switch (throttling->status_register.space_id) { |
313 | case ACPI_ADR_SPACE_SYSTEM_IO: | 316 | case ACPI_ADR_SPACE_SYSTEM_IO: |
314 | acpi_os_read_port((acpi_io_address)throttling->status_register.address, | 317 | acpi_os_read_port((acpi_io_address) throttling->status_register. |
315 | &value, | 318 | address, &value, |
316 | (u32)throttling->status_register.bit_width*8); | 319 | (u32) throttling->status_register.bit_width * |
320 | 8); | ||
317 | break; | 321 | break; |
318 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | 322 | case ACPI_ADR_SPACE_FIXED_HARDWARE: |
319 | printk(KERN_ERR PREFIX "HARDWARE addr space,NOT supported yet\n"); | 323 | printk(KERN_ERR PREFIX |
324 | "HARDWARE addr space,NOT supported yet\n"); | ||
320 | break; | 325 | break; |
321 | default: | 326 | default: |
322 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", | 327 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", |
323 | (u32) (throttling->status_register.space_id)); | 328 | (u32) (throttling->status_register.space_id)); |
324 | } | 329 | } |
325 | return value; | 330 | return value; |
326 | } | 331 | } |
327 | 332 | ||
328 | static int acpi_write_throttling_state(struct acpi_processor_throttling *throttling,int value) | 333 | static int acpi_write_throttling_state(struct acpi_processor_throttling |
334 | *throttling, int value) | ||
329 | { | 335 | { |
330 | int ret = -1; | 336 | int ret = -1; |
331 | 337 | ||
332 | switch (throttling->control_register.space_id) { | 338 | switch (throttling->control_register.space_id) { |
333 | case ACPI_ADR_SPACE_SYSTEM_IO: | 339 | case ACPI_ADR_SPACE_SYSTEM_IO: |
334 | acpi_os_write_port((acpi_io_address)throttling->control_register.address, | 340 | acpi_os_write_port((acpi_io_address) throttling-> |
335 | value, | 341 | control_register.address, value, |
336 | (u32)throttling->control_register.bit_width*8); | 342 | (u32) throttling->control_register. |
343 | bit_width * 8); | ||
337 | ret = 0; | 344 | ret = 0; |
338 | break; | 345 | break; |
339 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | 346 | case ACPI_ADR_SPACE_FIXED_HARDWARE: |
340 | printk(KERN_ERR PREFIX "HARDWARE addr space,NOT supported yet\n"); | 347 | printk(KERN_ERR PREFIX |
348 | "HARDWARE addr space,NOT supported yet\n"); | ||
341 | break; | 349 | break; |
342 | default: | 350 | default: |
343 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", | 351 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", |
344 | (u32) (throttling->control_register.space_id)); | 352 | (u32) (throttling->control_register.space_id)); |
345 | } | 353 | } |
346 | return ret; | 354 | return ret; |
347 | } | 355 | } |
348 | 356 | ||
349 | static int acpi_get_throttling_state(struct acpi_processor *pr,int value) | 357 | static int acpi_get_throttling_state(struct acpi_processor *pr, int value) |
350 | { | 358 | { |
351 | int i; | 359 | int i; |
352 | 360 | ||
353 | for (i = 0; i < pr->throttling.state_count; i++) { | 361 | 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]); | 362 | struct acpi_processor_tx_tss *tx = |
355 | if(tx->control == value) | 363 | (struct acpi_processor_tx_tss *)&(pr->throttling. |
364 | states_tss[i]); | ||
365 | if (tx->control == value) | ||
356 | break; | 366 | break; |
357 | } | 367 | } |
358 | if(i > pr->throttling.state_count) | 368 | if (i > pr->throttling.state_count) |
359 | i=-1; | 369 | i = -1; |
360 | return i; | 370 | return i; |
361 | } | 371 | } |
362 | 372 | ||
363 | static int acpi_get_throttling_value(struct acpi_processor *pr,int state) | 373 | static int acpi_get_throttling_value(struct acpi_processor *pr, int state) |
364 | { | 374 | { |
365 | int value = -1; | 375 | int value = -1; |
366 | if(state >=0 && state <= pr->throttling.state_count){ | 376 | 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]); | 377 | struct acpi_processor_tx_tss *tx = |
378 | (struct acpi_processor_tx_tss *)&(pr->throttling. | ||
379 | states_tss[state]); | ||
368 | value = tx->control; | 380 | value = tx->control; |
369 | } | 381 | } |
370 | return value; | 382 | return value; |
@@ -375,7 +387,6 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) | |||
375 | int state = 0; | 387 | int state = 0; |
376 | u32 value = 0; | 388 | u32 value = 0; |
377 | 389 | ||
378 | |||
379 | if (!pr) | 390 | if (!pr) |
380 | return -EINVAL; | 391 | return -EINVAL; |
381 | 392 | ||
@@ -385,8 +396,8 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) | |||
385 | pr->throttling.state = 0; | 396 | pr->throttling.state = 0; |
386 | local_irq_disable(); | 397 | local_irq_disable(); |
387 | value = acpi_read_throttling_status(&pr->throttling); | 398 | value = acpi_read_throttling_status(&pr->throttling); |
388 | if(value >= 0){ | 399 | if (value >= 0) { |
389 | state = acpi_get_throttling_state(pr,value); | 400 | state = acpi_get_throttling_state(pr, value); |
390 | pr->throttling.state = state; | 401 | pr->throttling.state = state; |
391 | } | 402 | } |
392 | local_irq_enable(); | 403 | local_irq_enable(); |
@@ -394,7 +405,6 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) | |||
394 | return 0; | 405 | return 0; |
395 | } | 406 | } |
396 | 407 | ||
397 | |||
398 | static int acpi_processor_get_throttling(struct acpi_processor *pr) | 408 | static int acpi_processor_get_throttling(struct acpi_processor *pr) |
399 | { | 409 | { |
400 | return pr->throttling.acpi_processor_get_throttling(pr); | 410 | return pr->throttling.acpi_processor_get_throttling(pr); |
@@ -406,7 +416,6 @@ int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, int state) | |||
406 | u32 duty_mask = 0; | 416 | u32 duty_mask = 0; |
407 | u32 duty_value = 0; | 417 | u32 duty_value = 0; |
408 | 418 | ||
409 | |||
410 | if (!pr) | 419 | if (!pr) |
411 | return -EINVAL; | 420 | return -EINVAL; |
412 | 421 | ||
@@ -494,9 +503,9 @@ int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state) | |||
494 | 503 | ||
495 | local_irq_disable(); | 504 | local_irq_disable(); |
496 | 505 | ||
497 | value = acpi_get_throttling_value(pr,state); | 506 | value = acpi_get_throttling_value(pr, state); |
498 | if(value >=0){ | 507 | if (value >= 0) { |
499 | acpi_write_throttling_state(&pr->throttling,value); | 508 | acpi_write_throttling_state(&pr->throttling, value); |
500 | pr->throttling.state = state; | 509 | pr->throttling.state = state; |
501 | } | 510 | } |
502 | local_irq_enable(); | 511 | local_irq_enable(); |
@@ -506,7 +515,7 @@ int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state) | |||
506 | 515 | ||
507 | int acpi_processor_set_throttling(struct acpi_processor *pr, int state) | 516 | int acpi_processor_set_throttling(struct acpi_processor *pr, int state) |
508 | { | 517 | { |
509 | return pr->throttling.acpi_processor_set_throttling(pr,state); | 518 | return pr->throttling.acpi_processor_set_throttling(pr, state); |
510 | } | 519 | } |
511 | 520 | ||
512 | int acpi_processor_get_throttling_info(struct acpi_processor *pr) | 521 | int acpi_processor_get_throttling_info(struct acpi_processor *pr) |
@@ -518,7 +527,6 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr) | |||
518 | int no_tss = 0; | 527 | int no_tss = 0; |
519 | int no_tsd = 0; | 528 | int no_tsd = 0; |
520 | 529 | ||
521 | |||
522 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 530 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
523 | "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n", | 531 | "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n", |
524 | pr->throttling.address, | 532 | pr->throttling.address, |
@@ -533,12 +541,16 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr) | |||
533 | no_tss = acpi_processor_get_throttling_states(pr); | 541 | no_tss = acpi_processor_get_throttling_states(pr); |
534 | no_tsd = acpi_processor_get_tsd(pr); | 542 | no_tsd = acpi_processor_get_tsd(pr); |
535 | 543 | ||
536 | if(no_ptc || no_tss) { | 544 | if (no_ptc || no_tss) { |
537 | pr->throttling.acpi_processor_get_throttling = &acpi_processor_get_throttling_fadt; | 545 | pr->throttling.acpi_processor_get_throttling = |
538 | pr->throttling.acpi_processor_set_throttling = &acpi_processor_set_throttling_fadt; | 546 | &acpi_processor_get_throttling_fadt; |
547 | pr->throttling.acpi_processor_set_throttling = | ||
548 | &acpi_processor_set_throttling_fadt; | ||
539 | } else { | 549 | } else { |
540 | pr->throttling.acpi_processor_get_throttling = &acpi_processor_get_throttling_ptc; | 550 | pr->throttling.acpi_processor_get_throttling = |
541 | pr->throttling.acpi_processor_set_throttling = &acpi_processor_set_throttling_ptc; | 551 | &acpi_processor_get_throttling_ptc; |
552 | pr->throttling.acpi_processor_set_throttling = | ||
553 | &acpi_processor_set_throttling_ptc; | ||
542 | } | 554 | } |
543 | 555 | ||
544 | if (!pr->throttling.address) { | 556 | if (!pr->throttling.address) { |
@@ -620,7 +632,6 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq, | |||
620 | int i = 0; | 632 | int i = 0; |
621 | int result = 0; | 633 | int result = 0; |
622 | 634 | ||
623 | |||
624 | if (!pr) | 635 | if (!pr) |
625 | goto end; | 636 | goto end; |
626 | 637 | ||
@@ -639,24 +650,24 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq, | |||
639 | 650 | ||
640 | seq_printf(seq, "state count: %d\n" | 651 | seq_printf(seq, "state count: %d\n" |
641 | "active state: T%d\n" | 652 | "active state: T%d\n" |
642 | "state available: T%d to T%d\n", | 653 | "state available: T%d to T%d\n", |
643 | pr->throttling.state_count, pr->throttling.state, | 654 | pr->throttling.state_count, pr->throttling.state, |
644 | pr->throttling_platform_limit, | 655 | pr->throttling_platform_limit, |
645 | pr->throttling.state_count-1); | 656 | pr->throttling.state_count - 1); |
646 | 657 | ||
647 | seq_puts(seq, "states:\n"); | 658 | seq_puts(seq, "states:\n"); |
648 | if(acpi_processor_get_throttling == acpi_processor_get_throttling_fadt) | 659 | if (acpi_processor_get_throttling == acpi_processor_get_throttling_fadt) |
649 | for (i = 0; i < pr->throttling.state_count; i++) | 660 | for (i = 0; i < pr->throttling.state_count; i++) |
650 | seq_printf(seq, " %cT%d: %02d%%\n", | 661 | seq_printf(seq, " %cT%d: %02d%%\n", |
651 | (i == pr->throttling.state ? '*' : ' '), i, | 662 | (i == pr->throttling.state ? '*' : ' '), i, |
652 | (pr->throttling.states[i].performance ? pr-> | 663 | (pr->throttling.states[i].performance ? pr-> |
653 | throttling.states[i].performance / 10 : 0)); | 664 | throttling.states[i].performance / 10 : 0)); |
654 | else | 665 | else |
655 | for (i = 0; i < pr->throttling.state_count; i++) | 666 | for (i = 0; i < pr->throttling.state_count; i++) |
656 | seq_printf(seq, " %cT%d: %02d%%\n", | 667 | seq_printf(seq, " %cT%d: %02d%%\n", |
657 | (i == pr->throttling.state ? '*' : ' '), i, | 668 | (i == pr->throttling.state ? '*' : ' '), i, |
658 | (int)pr->throttling.states_tss[i].freqpercentage); | 669 | (int)pr->throttling.states_tss[i]. |
659 | 670 | freqpercentage); | |
660 | 671 | ||
661 | end: | 672 | end: |
662 | return 0; | 673 | return 0; |
@@ -669,7 +680,7 @@ static int acpi_processor_throttling_open_fs(struct inode *inode, | |||
669 | PDE(inode)->data); | 680 | PDE(inode)->data); |
670 | } | 681 | } |
671 | 682 | ||
672 | static ssize_t acpi_processor_write_throttling(struct file * file, | 683 | static ssize_t acpi_processor_write_throttling(struct file *file, |
673 | const char __user * buffer, | 684 | const char __user * buffer, |
674 | size_t count, loff_t * data) | 685 | size_t count, loff_t * data) |
675 | { | 686 | { |
@@ -678,7 +689,6 @@ static ssize_t acpi_processor_write_throttling(struct file * file, | |||
678 | struct acpi_processor *pr = m->private; | 689 | struct acpi_processor *pr = m->private; |
679 | char state_string[12] = { '\0' }; | 690 | char state_string[12] = { '\0' }; |
680 | 691 | ||
681 | |||
682 | if (!pr || (count > sizeof(state_string) - 1)) | 692 | if (!pr || (count > sizeof(state_string) - 1)) |
683 | return -EINVAL; | 693 | return -EINVAL; |
684 | 694 | ||