Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ACPI: Lindent processor throttling code

Signed-off-by: Len Brown <len.brown@intel.com>

Len Brown ff55a9ce 01854e69

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