Commit ff55a9ce authored by Len Brown's avatar Len Brown

ACPI: Lindent processor throttling code

Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 01854e69
...@@ -44,18 +44,18 @@ ...@@ -44,18 +44,18 @@
#define _COMPONENT ACPI_PROCESSOR_COMPONENT #define _COMPONENT ACPI_PROCESSOR_COMPONENT
ACPI_MODULE_NAME("processor_throttling"); ACPI_MODULE_NAME("processor_throttling");
static int acpi_processor_get_throttling (struct acpi_processor *pr); static int acpi_processor_get_throttling(struct acpi_processor *pr);
int acpi_processor_set_throttling (struct acpi_processor *pr, int state); int acpi_processor_set_throttling(struct acpi_processor *pr, int state);
static int acpi_processor_get_platform_limit(struct acpi_processor *pr) static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
{ {
acpi_status status = 0; acpi_status status = 0;
unsigned long tpc = 0; unsigned long tpc = 0;
if(!pr) if (!pr)
return -EINVAL; return -EINVAL;
status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc); status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc);
if(ACPI_FAILURE(status) && status != AE_NOT_FOUND){ if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC")); ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC"));
return -ENODEV; return -ENODEV;
} }
...@@ -102,7 +102,8 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr) ...@@ -102,7 +102,8 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
if ((obj.type != ACPI_TYPE_BUFFER) if ((obj.type != ACPI_TYPE_BUFFER)
|| (obj.buffer.length < sizeof(struct acpi_ptc_register)) || (obj.buffer.length < sizeof(struct acpi_ptc_register))
|| (obj.buffer.pointer == NULL)) { || (obj.buffer.pointer == NULL)) {
printk(KERN_ERR PREFIX "Invalid _PTC data (control_register)\n"); printk(KERN_ERR PREFIX
"Invalid _PTC data (control_register)\n");
result = -EFAULT; result = -EFAULT;
goto end; goto end;
} }
...@@ -124,9 +125,9 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr) ...@@ -124,9 +125,9 @@ static int acpi_processor_get_throttling_control(struct acpi_processor *pr)
} }
memcpy(&pr->throttling.status_register, obj.buffer.pointer, memcpy(&pr->throttling.status_register, obj.buffer.pointer,
sizeof(struct acpi_ptc_register)); sizeof(struct acpi_ptc_register));
end: end:
kfree(buffer.pointer); kfree(buffer.pointer);
return result; return result;
...@@ -168,7 +169,9 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) ...@@ -168,7 +169,9 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
for (i = 0; i < pr->throttling.state_count; i++) { for (i = 0; i < pr->throttling.state_count; i++) {
struct acpi_processor_tx_tss *tx = (struct acpi_processor_tx_tss *) &(pr->throttling.states_tss[i]); struct acpi_processor_tx_tss *tx =
(struct acpi_processor_tx_tss *)&(pr->throttling.
states_tss[i]);
state.length = sizeof(struct acpi_processor_tx_tss); state.length = sizeof(struct acpi_processor_tx_tss);
state.pointer = tx; state.pointer = tx;
...@@ -186,7 +189,7 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) ...@@ -186,7 +189,7 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
if (!tx->freqpercentage) { if (!tx->freqpercentage) {
printk(KERN_ERR PREFIX printk(KERN_ERR PREFIX
"Invalid _TSS data: freq is zero\n"); "Invalid _TSS data: freq is zero\n");
result = -EFAULT; result = -EFAULT;
kfree(pr->throttling.states_tss); kfree(pr->throttling.states_tss);
goto end; goto end;
...@@ -198,14 +201,14 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr) ...@@ -198,14 +201,14 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
return result; return result;
} }
static int acpi_processor_get_tsd(struct acpi_processor *pr) static int acpi_processor_get_tsd(struct acpi_processor *pr)
{ {
int result = 0; int result = 0;
acpi_status status = AE_OK; acpi_status status = AE_OK;
struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"}; struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
struct acpi_buffer state = {0, NULL}; struct acpi_buffer state = { 0, NULL };
union acpi_object *tsd = NULL; union acpi_object *tsd = NULL;
struct acpi_tsd_package *pdomain; struct acpi_tsd_package *pdomain;
status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer); status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer);
...@@ -232,7 +235,7 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr) ...@@ -232,7 +235,7 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr)
state.pointer = pdomain; state.pointer = pdomain;
status = acpi_extract_package(&(tsd->package.elements[0]), status = acpi_extract_package(&(tsd->package.elements[0]),
&format, &state); &format, &state);
if (ACPI_FAILURE(status)) { if (ACPI_FAILURE(status)) {
ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
result = -EFAULT; result = -EFAULT;
...@@ -251,7 +254,7 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr) ...@@ -251,7 +254,7 @@ static int acpi_processor_get_tsd(struct acpi_processor *pr)
goto end; goto end;
} }
end: end:
kfree(buffer.pointer); kfree(buffer.pointer);
return result; return result;
} }
...@@ -266,7 +269,6 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr) ...@@ -266,7 +269,6 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
u32 duty_mask = 0; u32 duty_mask = 0;
u32 duty_value = 0; u32 duty_value = 0;
if (!pr) if (!pr)
return -EINVAL; return -EINVAL;
...@@ -306,65 +308,75 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr) ...@@ -306,65 +308,75 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
return 0; return 0;
} }
static int acpi_read_throttling_status(struct acpi_processor_throttling *throttling) static int acpi_read_throttling_status(struct acpi_processor_throttling
*throttling)
{ {
int value = -1; int value = -1;
switch (throttling->status_register.space_id) { switch (throttling->status_register.space_id) {
case ACPI_ADR_SPACE_SYSTEM_IO: case ACPI_ADR_SPACE_SYSTEM_IO:
acpi_os_read_port((acpi_io_address)throttling->status_register.address, acpi_os_read_port((acpi_io_address) throttling->status_register.
&value, address, &value,
(u32)throttling->status_register.bit_width*8); (u32) throttling->status_register.bit_width *
8);
break; break;
case ACPI_ADR_SPACE_FIXED_HARDWARE: case ACPI_ADR_SPACE_FIXED_HARDWARE:
printk(KERN_ERR PREFIX "HARDWARE addr space,NOT supported yet\n"); printk(KERN_ERR PREFIX
"HARDWARE addr space,NOT supported yet\n");
break; break;
default: default:
printk(KERN_ERR PREFIX "Unknown addr space %d\n", printk(KERN_ERR PREFIX "Unknown addr space %d\n",
(u32) (throttling->status_register.space_id)); (u32) (throttling->status_register.space_id));
} }
return value; return value;
} }
static int acpi_write_throttling_state(struct acpi_processor_throttling *throttling,int value) static int acpi_write_throttling_state(struct acpi_processor_throttling
*throttling, int value)
{ {
int ret = -1; int ret = -1;
switch (throttling->control_register.space_id) { switch (throttling->control_register.space_id) {
case ACPI_ADR_SPACE_SYSTEM_IO: case ACPI_ADR_SPACE_SYSTEM_IO:
acpi_os_write_port((acpi_io_address)throttling->control_register.address, acpi_os_write_port((acpi_io_address) throttling->
value, control_register.address, value,
(u32)throttling->control_register.bit_width*8); (u32) throttling->control_register.
bit_width * 8);
ret = 0; ret = 0;
break; break;
case ACPI_ADR_SPACE_FIXED_HARDWARE: case ACPI_ADR_SPACE_FIXED_HARDWARE:
printk(KERN_ERR PREFIX "HARDWARE addr space,NOT supported yet\n"); printk(KERN_ERR PREFIX
"HARDWARE addr space,NOT supported yet\n");
break; break;
default: default:
printk(KERN_ERR PREFIX "Unknown addr space %d\n", printk(KERN_ERR PREFIX "Unknown addr space %d\n",
(u32) (throttling->control_register.space_id)); (u32) (throttling->control_register.space_id));
} }
return ret; return ret;
} }
static int acpi_get_throttling_state(struct acpi_processor *pr,int value) static int acpi_get_throttling_state(struct acpi_processor *pr, int value)
{ {
int i; int i;
for (i = 0; i < pr->throttling.state_count; i++) { for (i = 0; i < pr->throttling.state_count; i++) {
struct acpi_processor_tx_tss *tx = (struct acpi_processor_tx_tss *) &(pr->throttling.states_tss[i]); struct acpi_processor_tx_tss *tx =
if(tx->control == value) (struct acpi_processor_tx_tss *)&(pr->throttling.
states_tss[i]);
if (tx->control == value)
break; break;
} }
if(i > pr->throttling.state_count) if (i > pr->throttling.state_count)
i=-1; i = -1;
return i; return i;
} }
static int acpi_get_throttling_value(struct acpi_processor *pr,int state) static int acpi_get_throttling_value(struct acpi_processor *pr, int state)
{ {
int value = -1; int value = -1;
if(state >=0 && state <= pr->throttling.state_count){ if (state >= 0 && state <= pr->throttling.state_count) {
struct acpi_processor_tx_tss *tx = (struct acpi_processor_tx_tss *) &(pr->throttling.states_tss[state]); struct acpi_processor_tx_tss *tx =
(struct acpi_processor_tx_tss *)&(pr->throttling.
states_tss[state]);
value = tx->control; value = tx->control;
} }
return value; return value;
...@@ -375,7 +387,6 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) ...@@ -375,7 +387,6 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
int state = 0; int state = 0;
u32 value = 0; u32 value = 0;
if (!pr) if (!pr)
return -EINVAL; return -EINVAL;
...@@ -385,8 +396,8 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) ...@@ -385,8 +396,8 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
pr->throttling.state = 0; pr->throttling.state = 0;
local_irq_disable(); local_irq_disable();
value = acpi_read_throttling_status(&pr->throttling); value = acpi_read_throttling_status(&pr->throttling);
if(value >= 0){ if (value >= 0) {
state = acpi_get_throttling_state(pr,value); state = acpi_get_throttling_state(pr, value);
pr->throttling.state = state; pr->throttling.state = state;
} }
local_irq_enable(); local_irq_enable();
...@@ -394,7 +405,6 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) ...@@ -394,7 +405,6 @@ static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
return 0; return 0;
} }
static int acpi_processor_get_throttling(struct acpi_processor *pr) static int acpi_processor_get_throttling(struct acpi_processor *pr)
{ {
return pr->throttling.acpi_processor_get_throttling(pr); 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,7 +416,6 @@ int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, int state)
u32 duty_mask = 0; u32 duty_mask = 0;
u32 duty_value = 0; u32 duty_value = 0;
if (!pr) if (!pr)
return -EINVAL; return -EINVAL;
...@@ -494,9 +503,9 @@ int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state) ...@@ -494,9 +503,9 @@ int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state)
local_irq_disable(); local_irq_disable();
value = acpi_get_throttling_value(pr,state); value = acpi_get_throttling_value(pr, state);
if(value >=0){ if (value >= 0) {
acpi_write_throttling_state(&pr->throttling,value); acpi_write_throttling_state(&pr->throttling, value);
pr->throttling.state = state; pr->throttling.state = state;
} }
local_irq_enable(); local_irq_enable();
...@@ -506,7 +515,7 @@ int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state) ...@@ -506,7 +515,7 @@ int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state)
int acpi_processor_set_throttling(struct acpi_processor *pr, int state) int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
{ {
return pr->throttling.acpi_processor_set_throttling(pr,state); return pr->throttling.acpi_processor_set_throttling(pr, state);
} }
int acpi_processor_get_throttling_info(struct acpi_processor *pr) 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,7 +527,6 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
int no_tss = 0; int no_tss = 0;
int no_tsd = 0; int no_tsd = 0;
ACPI_DEBUG_PRINT((ACPI_DB_INFO, ACPI_DEBUG_PRINT((ACPI_DB_INFO,
"pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n", "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
pr->throttling.address, pr->throttling.address,
...@@ -533,12 +541,16 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr) ...@@ -533,12 +541,16 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
no_tss = acpi_processor_get_throttling_states(pr); no_tss = acpi_processor_get_throttling_states(pr);
no_tsd = acpi_processor_get_tsd(pr); no_tsd = acpi_processor_get_tsd(pr);
if(no_ptc || no_tss) { if (no_ptc || no_tss) {
pr->throttling.acpi_processor_get_throttling = &acpi_processor_get_throttling_fadt; pr->throttling.acpi_processor_get_throttling =
pr->throttling.acpi_processor_set_throttling = &acpi_processor_set_throttling_fadt; &acpi_processor_get_throttling_fadt;
pr->throttling.acpi_processor_set_throttling =
&acpi_processor_set_throttling_fadt;
} else { } else {
pr->throttling.acpi_processor_get_throttling = &acpi_processor_get_throttling_ptc; pr->throttling.acpi_processor_get_throttling =
pr->throttling.acpi_processor_set_throttling = &acpi_processor_set_throttling_ptc; &acpi_processor_get_throttling_ptc;
pr->throttling.acpi_processor_set_throttling =
&acpi_processor_set_throttling_ptc;
} }
if (!pr->throttling.address) { if (!pr->throttling.address) {
...@@ -620,7 +632,6 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq, ...@@ -620,7 +632,6 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq,
int i = 0; int i = 0;
int result = 0; int result = 0;
if (!pr) if (!pr)
goto end; goto end;
...@@ -639,24 +650,24 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq, ...@@ -639,24 +650,24 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq,
seq_printf(seq, "state count: %d\n" seq_printf(seq, "state count: %d\n"
"active state: T%d\n" "active state: T%d\n"
"state available: T%d to T%d\n", "state available: T%d to T%d\n",
pr->throttling.state_count, pr->throttling.state, pr->throttling.state_count, pr->throttling.state,
pr->throttling_platform_limit, pr->throttling_platform_limit,
pr->throttling.state_count-1); pr->throttling.state_count - 1);
seq_puts(seq, "states:\n"); seq_puts(seq, "states:\n");
if(acpi_processor_get_throttling == acpi_processor_get_throttling_fadt) if (acpi_processor_get_throttling == acpi_processor_get_throttling_fadt)
for (i = 0; i < pr->throttling.state_count; i++) for (i = 0; i < pr->throttling.state_count; i++)
seq_printf(seq, " %cT%d: %02d%%\n", seq_printf(seq, " %cT%d: %02d%%\n",
(i == pr->throttling.state ? '*' : ' '), i, (i == pr->throttling.state ? '*' : ' '), i,
(pr->throttling.states[i].performance ? pr-> (pr->throttling.states[i].performance ? pr->
throttling.states[i].performance / 10 : 0)); throttling.states[i].performance / 10 : 0));
else else
for (i = 0; i < pr->throttling.state_count; i++) for (i = 0; i < pr->throttling.state_count; i++)
seq_printf(seq, " %cT%d: %02d%%\n", seq_printf(seq, " %cT%d: %02d%%\n",
(i == pr->throttling.state ? '*' : ' '), i, (i == pr->throttling.state ? '*' : ' '), i,
(int)pr->throttling.states_tss[i].freqpercentage); (int)pr->throttling.states_tss[i].
freqpercentage);
end: end:
return 0; return 0;
...@@ -669,7 +680,7 @@ static int acpi_processor_throttling_open_fs(struct inode *inode, ...@@ -669,7 +680,7 @@ static int acpi_processor_throttling_open_fs(struct inode *inode,
PDE(inode)->data); PDE(inode)->data);
} }
static ssize_t acpi_processor_write_throttling(struct file * file, static ssize_t acpi_processor_write_throttling(struct file *file,
const char __user * buffer, const char __user * buffer,
size_t count, loff_t * data) size_t count, loff_t * data)
{ {
...@@ -678,7 +689,6 @@ static ssize_t acpi_processor_write_throttling(struct file * file, ...@@ -678,7 +689,6 @@ static ssize_t acpi_processor_write_throttling(struct file * file,
struct acpi_processor *pr = m->private; struct acpi_processor *pr = m->private;
char state_string[12] = { '\0' }; char state_string[12] = { '\0' };
if (!pr || (count > sizeof(state_string) - 1)) if (!pr || (count > sizeof(state_string) - 1))
return -EINVAL; return -EINVAL;
......
...@@ -167,8 +167,9 @@ struct acpi_processor_throttling { ...@@ -167,8 +167,9 @@ struct acpi_processor_throttling {
struct acpi_processor_tx_tss *states_tss; struct acpi_processor_tx_tss *states_tss;
struct acpi_tsd_package domain_info; struct acpi_tsd_package domain_info;
cpumask_t shared_cpu_map; cpumask_t shared_cpu_map;
int (*acpi_processor_get_throttling) (struct acpi_processor *pr); int (*acpi_processor_get_throttling) (struct acpi_processor * pr);
int (*acpi_processor_set_throttling) (struct acpi_processor *pr, int state); int (*acpi_processor_set_throttling) (struct acpi_processor * pr,
int state);
u32 address; u32 address;
u8 duty_offset; u8 duty_offset;
...@@ -207,7 +208,7 @@ struct acpi_processor { ...@@ -207,7 +208,7 @@ struct acpi_processor {
u32 pblk; u32 pblk;
int performance_platform_limit; int performance_platform_limit;
int throttling_platform_limit; int throttling_platform_limit;
/*0 - states 0..n-th satte available*/ /* 0 - states 0..n-th state available */
struct acpi_processor_flags flags; struct acpi_processor_flags flags;
struct acpi_processor_power power; struct acpi_processor_power power;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment