aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/processor_throttling.c
diff options
context:
space:
mode:
authorLuming Yu <luming.yu@gmail.com>2007-05-26 10:49:58 -0400
committerLen Brown <len.brown@intel.com>2007-06-02 00:07:47 -0400
commit01854e697a77a434104b2f7e6d7fd463a978af32 (patch)
tree5882fceb379dacfc9e9f784d8c265a3be46b513e /drivers/acpi/processor_throttling.c
parentf285e3d329ce68cc355fadf4ab2c8f34d7f264cb (diff)
ACPI: add ACPI 3.0 _TPC _TSS _PTC throttling support
adds _TPC _TSS _PTC -- Throttling Present Capabilities Signed-off-by: Luming Yu <luming.yu@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi/processor_throttling.c')
-rw-r--r--drivers/acpi/processor_throttling.c380
1 files changed, 374 insertions, 6 deletions
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;