aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/acpi/processor_core.c6
-rw-r--r--drivers/acpi/processor_throttling.c380
-rw-r--r--include/acpi/processor.h46
3 files changed, 423 insertions, 9 deletions
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index f7de02a6f497..7aefb7c0e4d3 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -66,6 +66,7 @@
66#define ACPI_PROCESSOR_FILE_LIMIT "limit" 66#define ACPI_PROCESSOR_FILE_LIMIT "limit"
67#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80 67#define ACPI_PROCESSOR_NOTIFY_PERFORMANCE 0x80
68#define ACPI_PROCESSOR_NOTIFY_POWER 0x81 68#define ACPI_PROCESSOR_NOTIFY_POWER 0x81
69#define ACPI_PROCESSOR_NOTIFY_THROTTLING 0x82
69 70
70#define ACPI_PROCESSOR_LIMIT_USER 0 71#define ACPI_PROCESSOR_LIMIT_USER 0
71#define ACPI_PROCESSOR_LIMIT_THERMAL 1 72#define ACPI_PROCESSOR_LIMIT_THERMAL 1
@@ -84,6 +85,8 @@ static int acpi_processor_info_open_fs(struct inode *inode, struct file *file);
84static void acpi_processor_notify(acpi_handle handle, u32 event, void *data); 85static void acpi_processor_notify(acpi_handle handle, u32 event, void *data);
85static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu); 86static acpi_status acpi_processor_hotadd_init(acpi_handle handle, int *p_cpu);
86static int acpi_processor_handle_eject(struct acpi_processor *pr); 87static int acpi_processor_handle_eject(struct acpi_processor *pr);
88extern int acpi_processor_tstate_has_changed(struct acpi_processor *pr);
89
87 90
88static struct acpi_driver acpi_processor_driver = { 91static struct acpi_driver acpi_processor_driver = {
89 .name = "processor", 92 .name = "processor",
@@ -699,6 +702,9 @@ static void acpi_processor_notify(acpi_handle handle, u32 event, void *data)
699 acpi_processor_cst_has_changed(pr); 702 acpi_processor_cst_has_changed(pr);
700 acpi_bus_generate_event(device, event, 0); 703 acpi_bus_generate_event(device, event, 0);
701 break; 704 break;
705 case ACPI_PROCESSOR_NOTIFY_THROTTLING:
706 acpi_processor_tstate_has_changed(pr);
707 acpi_bus_generate_event(device, event, 0);
702 default: 708 default:
703 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 709 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
704 "Unsupported event [0x%x]\n", event)); 710 "Unsupported event [0x%x]\n", event));
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index b33486009f41..1bae2e42a7c7 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -44,10 +44,222 @@
44#define _COMPONENT ACPI_PROCESSOR_COMPONENT 44#define _COMPONENT ACPI_PROCESSOR_COMPONENT
45ACPI_MODULE_NAME("processor_throttling"); 45ACPI_MODULE_NAME("processor_throttling");
46 46
47static int acpi_processor_get_throttling (struct acpi_processor *pr);
48int acpi_processor_set_throttling (struct acpi_processor *pr, int state);
49
50static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
51{
52 acpi_status status = 0;
53 unsigned long tpc = 0;
54
55 if(!pr)
56 return -EINVAL;
57 status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc);
58 if(ACPI_FAILURE(status) && status != AE_NOT_FOUND){
59 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC"));
60 return -ENODEV;
61 }
62 pr->throttling_platform_limit = (int)tpc;
63 return 0;
64}
65
66int 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 -------------------------------------------------------------------------- */
74static 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)) {
105 printk(KERN_ERR PREFIX "Invalid _PTC data (control_register)\n");
106 result = -EFAULT;
107 goto end;
108 }
109 memcpy(&pr->throttling.control_register, obj.buffer.pointer,
110 sizeof(struct acpi_ptc_register));
111
112 /*
113 * status_register
114 */
115
116 obj = ptc->package.elements[1];
117
118 if ((obj.type != ACPI_TYPE_BUFFER)
119 || (obj.buffer.length < sizeof(struct acpi_ptc_register))
120 || (obj.buffer.pointer == NULL)) {
121 printk(KERN_ERR PREFIX "Invalid _PTC data (status_register)\n");
122 result = -EFAULT;
123 goto end;
124 }
125
126 memcpy(&pr->throttling.status_register, obj.buffer.pointer,
127 sizeof(struct acpi_ptc_register));
128
129 end:
130 kfree(buffer.pointer);
131
132 return result;
133}
134static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
135{
136 int result = 0;
137 acpi_status status = AE_OK;
138 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
139 struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
140 struct acpi_buffer state = { 0, NULL };
141 union acpi_object *tss = NULL;
142 int i;
143
144 status = acpi_evaluate_object(pr->handle, "_TSS", NULL, &buffer);
145 if (ACPI_FAILURE(status)) {
146 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSS"));
147 return -ENODEV;
148 }
149
150 tss = buffer.pointer;
151 if (!tss || (tss->type != ACPI_TYPE_PACKAGE)) {
152 printk(KERN_ERR PREFIX "Invalid _TSS data\n");
153 result = -EFAULT;
154 goto end;
155 }
156
157 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n",
158 tss->package.count));
159
160 pr->throttling.state_count = tss->package.count;
161 pr->throttling.states_tss =
162 kmalloc(sizeof(struct acpi_processor_tx_tss) * tss->package.count,
163 GFP_KERNEL);
164 if (!pr->throttling.states_tss) {
165 result = -ENOMEM;
166 goto end;
167 }
168
169 for (i = 0; i < pr->throttling.state_count; i++) {
170
171 struct acpi_processor_tx_tss *tx = (struct acpi_processor_tx_tss *) &(pr->throttling.states_tss[i]);
172
173 state.length = sizeof(struct acpi_processor_tx_tss);
174 state.pointer = tx;
175
176 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i));
177
178 status = acpi_extract_package(&(tss->package.elements[i]),
179 &format, &state);
180 if (ACPI_FAILURE(status)) {
181 ACPI_EXCEPTION((AE_INFO, status, "Invalid _TSS data"));
182 result = -EFAULT;
183 kfree(pr->throttling.states_tss);
184 goto end;
185 }
186
187 if (!tx->freqpercentage) {
188 printk(KERN_ERR PREFIX
189 "Invalid _TSS data: freq is zero\n");
190 result = -EFAULT;
191 kfree(pr->throttling.states_tss);
192 goto end;
193 }
194 }
195
196 end:
197 kfree(buffer.pointer);
198
199 return result;
200}
201static int acpi_processor_get_tsd(struct acpi_processor *pr)
202{
203 int result = 0;
204 acpi_status status = AE_OK;
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;
209 struct acpi_tsd_package *pdomain;
210
211 status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer);
212 if (ACPI_FAILURE(status)) {
213 return -ENODEV;
214 }
215
216 tsd = buffer.pointer;
217 if (!tsd || (tsd->type != ACPI_TYPE_PACKAGE)) {
218 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
219 result = -EFAULT;
220 goto end;
221 }
222
223 if (tsd->package.count != 1) {
224 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
225 result = -EFAULT;
226 goto end;
227 }
228
229 pdomain = &(pr->throttling.domain_info);
230
231 state.length = sizeof(struct acpi_tsd_package);
232 state.pointer = pdomain;
233
234 status = acpi_extract_package(&(tsd->package.elements[0]),
235 &format, &state);
236 if (ACPI_FAILURE(status)) {
237 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n"));
238 result = -EFAULT;
239 goto end;
240 }
241
242 if (pdomain->num_entries != ACPI_TSD_REV0_ENTRIES) {
243 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:num_entries\n"));
244 result = -EFAULT;
245 goto end;
246 }
247
248 if (pdomain->revision != ACPI_TSD_REV0_REVISION) {
249 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:revision\n"));
250 result = -EFAULT;
251 goto end;
252 }
253
254end:
255 kfree(buffer.pointer);
256 return result;
257}
258
47/* -------------------------------------------------------------------------- 259/* --------------------------------------------------------------------------
48 Throttling Control 260 Throttling Control
49 -------------------------------------------------------------------------- */ 261 -------------------------------------------------------------------------- */
50static int acpi_processor_get_throttling(struct acpi_processor *pr) 262static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr)
51{ 263{
52 int state = 0; 264 int state = 0;
53 u32 value = 0; 265 u32 value = 0;
@@ -94,7 +306,101 @@ static int acpi_processor_get_throttling(struct acpi_processor *pr)
94 return 0; 306 return 0;
95} 307}
96 308
97int acpi_processor_set_throttling(struct acpi_processor *pr, int state) 309static int acpi_read_throttling_status(struct acpi_processor_throttling *throttling)
310{
311 int value = -1;
312 switch (throttling->status_register.space_id) {
313 case ACPI_ADR_SPACE_SYSTEM_IO:
314 acpi_os_read_port((acpi_io_address)throttling->status_register.address,
315 &value,
316 (u32)throttling->status_register.bit_width*8);
317 break;
318 case ACPI_ADR_SPACE_FIXED_HARDWARE:
319 printk(KERN_ERR PREFIX "HARDWARE addr space,NOT supported yet\n");
320 break;
321 default:
322 printk(KERN_ERR PREFIX "Unknown addr space %d\n",
323 (u32) (throttling->status_register.space_id));
324 }
325 return value;
326}
327
328static int acpi_write_throttling_state(struct acpi_processor_throttling *throttling,int value)
329{
330 int ret = -1;
331
332 switch (throttling->control_register.space_id) {
333 case ACPI_ADR_SPACE_SYSTEM_IO:
334 acpi_os_write_port((acpi_io_address)throttling->control_register.address,
335 value,
336 (u32)throttling->control_register.bit_width*8);
337 ret = 0;
338 break;
339 case ACPI_ADR_SPACE_FIXED_HARDWARE:
340 printk(KERN_ERR PREFIX "HARDWARE addr space,NOT supported yet\n");
341 break;
342 default:
343 printk(KERN_ERR PREFIX "Unknown addr space %d\n",
344 (u32) (throttling->control_register.space_id));
345 }
346 return ret;
347}
348
349static int acpi_get_throttling_state(struct acpi_processor *pr,int value)
350{
351 int i;
352
353 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]);
355 if(tx->control == value)
356 break;
357 }
358 if(i > pr->throttling.state_count)
359 i=-1;
360 return i;
361}
362
363static int acpi_get_throttling_value(struct acpi_processor *pr,int state)
364{
365 int value = -1;
366 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]);
368 value = tx->control;
369 }
370 return value;
371}
372
373static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr)
374{
375 int state = 0;
376 u32 value = 0;
377
378
379 if (!pr)
380 return -EINVAL;
381
382 if (!pr->flags.throttling)
383 return -ENODEV;
384
385 pr->throttling.state = 0;
386 local_irq_disable();
387 value = acpi_read_throttling_status(&pr->throttling);
388 if(value >= 0){
389 state = acpi_get_throttling_state(pr,value);
390 pr->throttling.state = state;
391 }
392 local_irq_enable();
393
394 return 0;
395}
396
397
398static int acpi_processor_get_throttling(struct acpi_processor *pr)
399{
400 return pr->throttling.acpi_processor_get_throttling(pr);
401}
402
403int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, int state)
98{ 404{
99 u32 value = 0; 405 u32 value = 0;
100 u32 duty_mask = 0; 406 u32 duty_mask = 0;
@@ -113,6 +419,8 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
113 if (state == pr->throttling.state) 419 if (state == pr->throttling.state)
114 return 0; 420 return 0;
115 421
422 if (state < pr->throttling_platform_limit)
423 return -EPERM;
116 /* 424 /*
117 * Calculate the duty_value and duty_mask. 425 * Calculate the duty_value and duty_mask.
118 */ 426 */
@@ -165,11 +473,50 @@ int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
165 return 0; 473 return 0;
166} 474}
167 475
476int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, int state)
477{
478 u32 value = 0;
479
480 if (!pr)
481 return -EINVAL;
482
483 if ((state < 0) || (state > (pr->throttling.state_count - 1)))
484 return -EINVAL;
485
486 if (!pr->flags.throttling)
487 return -ENODEV;
488
489 if (state == pr->throttling.state)
490 return 0;
491
492 if (state < pr->throttling_platform_limit)
493 return -EPERM;
494
495 local_irq_disable();
496
497 value = acpi_get_throttling_value(pr,state);
498 if(value >=0){
499 acpi_write_throttling_state(&pr->throttling,value);
500 pr->throttling.state = state;
501 }
502 local_irq_enable();
503
504 return 0;
505}
506
507int acpi_processor_set_throttling(struct acpi_processor *pr, int state)
508{
509 return pr->throttling.acpi_processor_set_throttling(pr,state);
510}
511
168int acpi_processor_get_throttling_info(struct acpi_processor *pr) 512int acpi_processor_get_throttling_info(struct acpi_processor *pr)
169{ 513{
170 int result = 0; 514 int result = 0;
171 int step = 0; 515 int step = 0;
172 int i = 0; 516 int i = 0;
517 int no_ptc = 0;
518 int no_tss = 0;
519 int no_tsd = 0;
173 520
174 521
175 ACPI_DEBUG_PRINT((ACPI_DB_INFO, 522 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
@@ -182,6 +529,17 @@ int acpi_processor_get_throttling_info(struct acpi_processor *pr)
182 return -EINVAL; 529 return -EINVAL;
183 530
184 /* TBD: Support ACPI 2.0 objects */ 531 /* TBD: Support ACPI 2.0 objects */
532 no_ptc = acpi_processor_get_throttling_control(pr);
533 no_tss = acpi_processor_get_throttling_states(pr);
534 no_tsd = acpi_processor_get_tsd(pr);
535
536 if(no_ptc || no_tss) {
537 pr->throttling.acpi_processor_get_throttling = &acpi_processor_get_throttling_fadt;
538 pr->throttling.acpi_processor_set_throttling = &acpi_processor_set_throttling_fadt;
539 } else {
540 pr->throttling.acpi_processor_get_throttling = &acpi_processor_get_throttling_ptc;
541 pr->throttling.acpi_processor_set_throttling = &acpi_processor_set_throttling_ptc;
542 }
185 543
186 if (!pr->throttling.address) { 544 if (!pr->throttling.address) {
187 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n")); 545 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n"));
@@ -280,15 +638,25 @@ static int acpi_processor_throttling_seq_show(struct seq_file *seq,
280 } 638 }
281 639
282 seq_printf(seq, "state count: %d\n" 640 seq_printf(seq, "state count: %d\n"
283 "active state: T%d\n", 641 "active state: T%d\n"
284 pr->throttling.state_count, pr->throttling.state); 642 "state available: T%d to T%d\n",
643 pr->throttling.state_count, pr->throttling.state,
644 pr->throttling_platform_limit,
645 pr->throttling.state_count-1);
285 646
286 seq_puts(seq, "states:\n"); 647 seq_puts(seq, "states:\n");
287 for (i = 0; i < pr->throttling.state_count; i++) 648 if(acpi_processor_get_throttling == acpi_processor_get_throttling_fadt)
288 seq_printf(seq, " %cT%d: %02d%%\n", 649 for (i = 0; i < pr->throttling.state_count; i++)
650 seq_printf(seq, " %cT%d: %02d%%\n",
289 (i == pr->throttling.state ? '*' : ' '), i, 651 (i == pr->throttling.state ? '*' : ' '), i,
290 (pr->throttling.states[i].performance ? pr-> 652 (pr->throttling.states[i].performance ? pr->
291 throttling.states[i].performance / 10 : 0)); 653 throttling.states[i].performance / 10 : 0));
654 else
655 for (i = 0; i < pr->throttling.state_count; i++)
656 seq_printf(seq, " %cT%d: %02d%%\n",
657 (i == pr->throttling.state ? '*' : ' '), i,
658 (int)pr->throttling.states_tss[i].freqpercentage);
659
292 660
293 end: 661 end:
294 return 0; 662 return 0;
diff --git a/include/acpi/processor.h b/include/acpi/processor.h
index b4b0ffdab098..01d2f24c224f 100644
--- a/include/acpi/processor.h
+++ b/include/acpi/processor.h
@@ -21,6 +21,8 @@
21#define ACPI_PSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */ 21#define ACPI_PSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */
22#define ACPI_PSD_REV0_ENTRIES 5 22#define ACPI_PSD_REV0_ENTRIES 5
23 23
24#define ACPI_TSD_REV0_REVISION 0 /* Support for _PSD as in ACPI 3.0 */
25#define ACPI_TSD_REV0_ENTRIES 5
24/* 26/*
25 * Types of coordination defined in ACPI 3.0. Same macros can be used across 27 * Types of coordination defined in ACPI 3.0. Same macros can be used across
26 * P, C and T states 28 * P, C and T states
@@ -125,17 +127,52 @@ struct acpi_processor_performance {
125 127
126/* Throttling Control */ 128/* Throttling Control */
127 129
130struct acpi_tsd_package {
131 acpi_integer num_entries;
132 acpi_integer revision;
133 acpi_integer domain;
134 acpi_integer coord_type;
135 acpi_integer num_processors;
136} __attribute__ ((packed));
137
138struct acpi_ptc_register {
139 u8 descriptor;
140 u16 length;
141 u8 space_id;
142 u8 bit_width;
143 u8 bit_offset;
144 u8 reserved;
145 u64 address;
146} __attribute__ ((packed));
147
148struct acpi_processor_tx_tss {
149 acpi_integer freqpercentage; /* */
150 acpi_integer power; /* milliWatts */
151 acpi_integer transition_latency; /* microseconds */
152 acpi_integer control; /* control value */
153 acpi_integer status; /* success indicator */
154};
128struct acpi_processor_tx { 155struct acpi_processor_tx {
129 u16 power; 156 u16 power;
130 u16 performance; 157 u16 performance;
131}; 158};
132 159
160struct acpi_processor;
133struct acpi_processor_throttling { 161struct acpi_processor_throttling {
134 int state; 162 unsigned int state;
163 unsigned int platform_limit;
164 struct acpi_pct_register control_register;
165 struct acpi_pct_register status_register;
166 unsigned int state_count;
167 struct acpi_processor_tx_tss *states_tss;
168 struct acpi_tsd_package domain_info;
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);
172
135 u32 address; 173 u32 address;
136 u8 duty_offset; 174 u8 duty_offset;
137 u8 duty_width; 175 u8 duty_width;
138 int state_count;
139 struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING]; 176 struct acpi_processor_tx states[ACPI_PROCESSOR_MAX_THROTTLING];
140}; 177};
141 178
@@ -169,6 +206,9 @@ struct acpi_processor {
169 u32 id; 206 u32 id;
170 u32 pblk; 207 u32 pblk;
171 int performance_platform_limit; 208 int performance_platform_limit;
209 int throttling_platform_limit;
210 /*0 - states 0..n-th satte available*/
211
172 struct acpi_processor_flags flags; 212 struct acpi_processor_flags flags;
173 struct acpi_processor_power power; 213 struct acpi_processor_power power;
174 struct acpi_processor_performance *performance; 214 struct acpi_processor_performance *performance;
@@ -270,7 +310,7 @@ static inline int acpi_processor_ppc_has_changed(struct acpi_processor *pr)
270 310
271/* in processor_throttling.c */ 311/* in processor_throttling.c */
272int acpi_processor_get_throttling_info(struct acpi_processor *pr); 312int acpi_processor_get_throttling_info(struct acpi_processor *pr);
273int acpi_processor_set_throttling(struct acpi_processor *pr, int state); 313extern int acpi_processor_set_throttling(struct acpi_processor *pr, int state);
274extern struct file_operations acpi_processor_throttling_fops; 314extern struct file_operations acpi_processor_throttling_fops;
275 315
276/* in processor_idle.c */ 316/* in processor_idle.c */