2 * processor_throttling.c - Throttling submodule of the ACPI processor driver
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 * Copyright (C) 2004 Dominik Brodowski <linux@brodo.de>
7 * Copyright (C) 2004 Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 * - Added processor hotplug support
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/cpufreq.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
37 #include <asm/uaccess.h>
39 #include <acpi/acpi_bus.h>
40 #include <acpi/processor.h>
42 #define ACPI_PROCESSOR_COMPONENT 0x01000000
43 #define ACPI_PROCESSOR_CLASS "processor"
44 #define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver"
45 #define _COMPONENT ACPI_PROCESSOR_COMPONENT
46 ACPI_MODULE_NAME("acpi_processor")
48 /* --------------------------------------------------------------------------
50 -------------------------------------------------------------------------- */
51 static int acpi_processor_get_throttling(struct acpi_processor
*pr
)
58 ACPI_FUNCTION_TRACE("acpi_processor_get_throttling");
61 return_VALUE(-EINVAL
);
63 if (!pr
->flags
.throttling
)
64 return_VALUE(-ENODEV
);
66 pr
->throttling
.state
= 0;
68 duty_mask
= pr
->throttling
.state_count
- 1;
70 duty_mask
<<= pr
->throttling
.duty_offset
;
74 value
= inl(pr
->throttling
.address
);
77 * Compute the current throttling state when throttling is enabled
81 duty_value
= value
& duty_mask
;
82 duty_value
>>= pr
->throttling
.duty_offset
;
85 state
= pr
->throttling
.state_count
- duty_value
;
88 pr
->throttling
.state
= state
;
92 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
93 "Throttling state is T%d (%d%% throttling applied)\n",
94 state
, pr
->throttling
.states
[state
].performance
));
99 int acpi_processor_set_throttling(struct acpi_processor
*pr
, int state
)
105 ACPI_FUNCTION_TRACE("acpi_processor_set_throttling");
108 return_VALUE(-EINVAL
);
110 if ((state
< 0) || (state
> (pr
->throttling
.state_count
- 1)))
111 return_VALUE(-EINVAL
);
113 if (!pr
->flags
.throttling
)
114 return_VALUE(-ENODEV
);
116 if (state
== pr
->throttling
.state
)
120 * Calculate the duty_value and duty_mask.
123 duty_value
= pr
->throttling
.state_count
- state
;
125 duty_value
<<= pr
->throttling
.duty_offset
;
127 /* Used to clear all duty_value bits */
128 duty_mask
= pr
->throttling
.state_count
- 1;
130 duty_mask
<<= acpi_fadt
.duty_offset
;
131 duty_mask
= ~duty_mask
;
137 * Disable throttling by writing a 0 to bit 4. Note that we must
138 * turn it off before you can change the duty_value.
140 value
= inl(pr
->throttling
.address
);
143 outl(value
, pr
->throttling
.address
);
147 * Write the new duty_value and then enable throttling. Note
148 * that a state value of 0 leaves throttling disabled.
153 outl(value
, pr
->throttling
.address
);
156 outl(value
, pr
->throttling
.address
);
159 pr
->throttling
.state
= state
;
163 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
164 "Throttling state set to T%d (%d%%)\n", state
,
165 (pr
->throttling
.states
[state
].performance
? pr
->
166 throttling
.states
[state
].performance
/ 10 : 0)));
171 int acpi_processor_get_throttling_info(struct acpi_processor
*pr
)
177 ACPI_FUNCTION_TRACE("acpi_processor_get_throttling_info");
179 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
180 "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n",
181 pr
->throttling
.address
,
182 pr
->throttling
.duty_offset
,
183 pr
->throttling
.duty_width
));
186 return_VALUE(-EINVAL
);
188 /* TBD: Support ACPI 2.0 objects */
190 if (!pr
->throttling
.address
) {
191 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "No throttling register\n"));
193 } else if (!pr
->throttling
.duty_width
) {
194 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "No throttling states\n"));
197 /* TBD: Support duty_cycle values that span bit 4. */
198 else if ((pr
->throttling
.duty_offset
+ pr
->throttling
.duty_width
) > 4) {
199 printk(KERN_WARNING PREFIX
"duty_cycle spans bit 4\n");
204 * PIIX4 Errata: We don't support throttling on the original PIIX4.
205 * This shouldn't be an issue as few (if any) mobile systems ever
208 if (errata
.piix4
.throttle
) {
209 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
210 "Throttling not supported on PIIX4 A- or B-step\n"));
214 pr
->throttling
.state_count
= 1 << acpi_fadt
.duty_width
;
217 * Compute state values. Note that throttling displays a linear power/
218 * performance relationship (at 50% performance the CPU will consume
219 * 50% power). Values are in 1/10th of a percent to preserve accuracy.
222 step
= (1000 / pr
->throttling
.state_count
);
224 for (i
= 0; i
< pr
->throttling
.state_count
; i
++) {
225 pr
->throttling
.states
[i
].performance
= step
* i
;
226 pr
->throttling
.states
[i
].power
= step
* i
;
229 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Found %d throttling states\n",
230 pr
->throttling
.state_count
));
232 pr
->flags
.throttling
= 1;
235 * Disable throttling (if enabled). We'll let subsequent policy (e.g.
236 * thermal) decide to lower performance if it so chooses, but for now
237 * we'll crank up the speed.
240 result
= acpi_processor_get_throttling(pr
);
244 if (pr
->throttling
.state
) {
245 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
246 "Disabling throttling (was T%d)\n",
247 pr
->throttling
.state
));
248 result
= acpi_processor_set_throttling(pr
, 0);
255 pr
->flags
.throttling
= 0;
257 return_VALUE(result
);
262 static int acpi_processor_throttling_seq_show(struct seq_file
*seq
,
265 struct acpi_processor
*pr
= (struct acpi_processor
*)seq
->private;
269 ACPI_FUNCTION_TRACE("acpi_processor_throttling_seq_show");
274 if (!(pr
->throttling
.state_count
> 0)) {
275 seq_puts(seq
, "<not supported>\n");
279 result
= acpi_processor_get_throttling(pr
);
283 "Could not determine current throttling state.\n");
287 seq_printf(seq
, "state count: %d\n"
288 "active state: T%d\n",
289 pr
->throttling
.state_count
, pr
->throttling
.state
);
291 seq_puts(seq
, "states:\n");
292 for (i
= 0; i
< pr
->throttling
.state_count
; i
++)
293 seq_printf(seq
, " %cT%d: %02d%%\n",
294 (i
== pr
->throttling
.state
? '*' : ' '), i
,
295 (pr
->throttling
.states
[i
].performance
? pr
->
296 throttling
.states
[i
].performance
/ 10 : 0));
302 static int acpi_processor_throttling_open_fs(struct inode
*inode
,
305 return single_open(file
, acpi_processor_throttling_seq_show
,
309 static ssize_t
acpi_processor_write_throttling(struct file
* file
,
310 const char __user
* buffer
,
311 size_t count
, loff_t
* data
)
314 struct seq_file
*m
= (struct seq_file
*)file
->private_data
;
315 struct acpi_processor
*pr
= (struct acpi_processor
*)m
->private;
316 char state_string
[12] = { '\0' };
318 ACPI_FUNCTION_TRACE("acpi_processor_write_throttling");
320 if (!pr
|| (count
> sizeof(state_string
) - 1))
321 return_VALUE(-EINVAL
);
323 if (copy_from_user(state_string
, buffer
, count
))
324 return_VALUE(-EFAULT
);
326 state_string
[count
] = '\0';
328 result
= acpi_processor_set_throttling(pr
,
329 simple_strtoul(state_string
,
332 return_VALUE(result
);
337 struct file_operations acpi_processor_throttling_fops
= {
338 .open
= acpi_processor_throttling_open_fs
,
340 .write
= acpi_processor_write_throttling
,
342 .release
= single_release
,