Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * processor_throttling.c - Throttling submodule of the ACPI processor driver |
| 3 | * |
| 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 |
| 9 | * |
| 10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11 | * |
| 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. |
| 16 | * |
| 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. |
| 21 | * |
| 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. |
| 25 | * |
| 26 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 27 | */ |
| 28 | |
| 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> |
| 35 | |
| 36 | #include <asm/io.h> |
| 37 | #include <asm/uaccess.h> |
| 38 | |
| 39 | #include <acpi/acpi_bus.h> |
| 40 | #include <acpi/processor.h> |
| 41 | |
| 42 | #define ACPI_PROCESSOR_COMPONENT 0x01000000 |
| 43 | #define ACPI_PROCESSOR_CLASS "processor" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 45 | ACPI_MODULE_NAME("processor_throttling"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 47 | static int acpi_processor_get_throttling(struct acpi_processor *pr); |
| 48 | int acpi_processor_set_throttling(struct acpi_processor *pr, int state); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 49 | |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 50 | /* |
| 51 | * _TPC - Throttling Present Capabilities |
| 52 | */ |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 53 | static int acpi_processor_get_platform_limit(struct acpi_processor *pr) |
| 54 | { |
| 55 | acpi_status status = 0; |
| 56 | unsigned long tpc = 0; |
| 57 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 58 | if (!pr) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 59 | return -EINVAL; |
| 60 | status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc); |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 61 | if (ACPI_FAILURE(status)) { |
| 62 | if (status != AE_NOT_FOUND) { |
| 63 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC")); |
| 64 | } |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 65 | return -ENODEV; |
| 66 | } |
| 67 | pr->throttling_platform_limit = (int)tpc; |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | int acpi_processor_tstate_has_changed(struct acpi_processor *pr) |
| 72 | { |
| 73 | return acpi_processor_get_platform_limit(pr); |
| 74 | } |
| 75 | |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 76 | /* |
| 77 | * _PTC - Processor Throttling Control (and status) register location |
| 78 | */ |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 79 | static int acpi_processor_get_throttling_control(struct acpi_processor *pr) |
| 80 | { |
| 81 | int result = 0; |
| 82 | acpi_status status = 0; |
| 83 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 84 | union acpi_object *ptc = NULL; |
| 85 | union acpi_object obj = { 0 }; |
| 86 | |
| 87 | status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer); |
| 88 | if (ACPI_FAILURE(status)) { |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 89 | if (status != AE_NOT_FOUND) { |
| 90 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PTC")); |
| 91 | } |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 92 | return -ENODEV; |
| 93 | } |
| 94 | |
| 95 | ptc = (union acpi_object *)buffer.pointer; |
| 96 | if (!ptc || (ptc->type != ACPI_TYPE_PACKAGE) |
| 97 | || (ptc->package.count != 2)) { |
| 98 | printk(KERN_ERR PREFIX "Invalid _PTC data\n"); |
| 99 | result = -EFAULT; |
| 100 | goto end; |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * control_register |
| 105 | */ |
| 106 | |
| 107 | obj = ptc->package.elements[0]; |
| 108 | |
| 109 | if ((obj.type != ACPI_TYPE_BUFFER) |
| 110 | || (obj.buffer.length < sizeof(struct acpi_ptc_register)) |
| 111 | || (obj.buffer.pointer == NULL)) { |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 112 | printk(KERN_ERR PREFIX |
| 113 | "Invalid _PTC data (control_register)\n"); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 114 | result = -EFAULT; |
| 115 | goto end; |
| 116 | } |
| 117 | memcpy(&pr->throttling.control_register, obj.buffer.pointer, |
| 118 | sizeof(struct acpi_ptc_register)); |
| 119 | |
| 120 | /* |
| 121 | * status_register |
| 122 | */ |
| 123 | |
| 124 | obj = ptc->package.elements[1]; |
| 125 | |
| 126 | if ((obj.type != ACPI_TYPE_BUFFER) |
| 127 | || (obj.buffer.length < sizeof(struct acpi_ptc_register)) |
| 128 | || (obj.buffer.pointer == NULL)) { |
| 129 | printk(KERN_ERR PREFIX "Invalid _PTC data (status_register)\n"); |
| 130 | result = -EFAULT; |
| 131 | goto end; |
| 132 | } |
| 133 | |
| 134 | memcpy(&pr->throttling.status_register, obj.buffer.pointer, |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 135 | sizeof(struct acpi_ptc_register)); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 136 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 137 | end: |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 138 | kfree(buffer.pointer); |
| 139 | |
| 140 | return result; |
| 141 | } |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | * _TSS - Throttling Supported States |
| 145 | */ |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 146 | static int acpi_processor_get_throttling_states(struct acpi_processor *pr) |
| 147 | { |
| 148 | int result = 0; |
| 149 | acpi_status status = AE_OK; |
| 150 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 151 | struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" }; |
| 152 | struct acpi_buffer state = { 0, NULL }; |
| 153 | union acpi_object *tss = NULL; |
| 154 | int i; |
| 155 | |
| 156 | status = acpi_evaluate_object(pr->handle, "_TSS", NULL, &buffer); |
| 157 | if (ACPI_FAILURE(status)) { |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 158 | if (status != AE_NOT_FOUND) { |
| 159 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSS")); |
| 160 | } |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 161 | return -ENODEV; |
| 162 | } |
| 163 | |
| 164 | tss = buffer.pointer; |
| 165 | if (!tss || (tss->type != ACPI_TYPE_PACKAGE)) { |
| 166 | printk(KERN_ERR PREFIX "Invalid _TSS data\n"); |
| 167 | result = -EFAULT; |
| 168 | goto end; |
| 169 | } |
| 170 | |
| 171 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n", |
| 172 | tss->package.count)); |
| 173 | |
| 174 | pr->throttling.state_count = tss->package.count; |
| 175 | pr->throttling.states_tss = |
| 176 | kmalloc(sizeof(struct acpi_processor_tx_tss) * tss->package.count, |
| 177 | GFP_KERNEL); |
| 178 | if (!pr->throttling.states_tss) { |
| 179 | result = -ENOMEM; |
| 180 | goto end; |
| 181 | } |
| 182 | |
| 183 | for (i = 0; i < pr->throttling.state_count; i++) { |
| 184 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 185 | struct acpi_processor_tx_tss *tx = |
| 186 | (struct acpi_processor_tx_tss *)&(pr->throttling. |
| 187 | states_tss[i]); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 188 | |
| 189 | state.length = sizeof(struct acpi_processor_tx_tss); |
| 190 | state.pointer = tx; |
| 191 | |
| 192 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i)); |
| 193 | |
| 194 | status = acpi_extract_package(&(tss->package.elements[i]), |
| 195 | &format, &state); |
| 196 | if (ACPI_FAILURE(status)) { |
| 197 | ACPI_EXCEPTION((AE_INFO, status, "Invalid _TSS data")); |
| 198 | result = -EFAULT; |
| 199 | kfree(pr->throttling.states_tss); |
| 200 | goto end; |
| 201 | } |
| 202 | |
| 203 | if (!tx->freqpercentage) { |
| 204 | printk(KERN_ERR PREFIX |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 205 | "Invalid _TSS data: freq is zero\n"); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 206 | result = -EFAULT; |
| 207 | kfree(pr->throttling.states_tss); |
| 208 | goto end; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | end: |
| 213 | kfree(buffer.pointer); |
| 214 | |
| 215 | return result; |
| 216 | } |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 217 | |
| 218 | /* |
| 219 | * _TSD - T-State Dependencies |
| 220 | */ |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 221 | static int acpi_processor_get_tsd(struct acpi_processor *pr) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 222 | { |
| 223 | int result = 0; |
| 224 | acpi_status status = AE_OK; |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 225 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 226 | struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" }; |
| 227 | struct acpi_buffer state = { 0, NULL }; |
| 228 | union acpi_object *tsd = NULL; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 229 | struct acpi_tsd_package *pdomain; |
| 230 | |
| 231 | status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer); |
| 232 | if (ACPI_FAILURE(status)) { |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 233 | if (status != AE_NOT_FOUND) { |
| 234 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSD")); |
| 235 | } |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 236 | return -ENODEV; |
| 237 | } |
| 238 | |
| 239 | tsd = buffer.pointer; |
| 240 | if (!tsd || (tsd->type != ACPI_TYPE_PACKAGE)) { |
| 241 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); |
| 242 | result = -EFAULT; |
| 243 | goto end; |
| 244 | } |
| 245 | |
| 246 | if (tsd->package.count != 1) { |
| 247 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); |
| 248 | result = -EFAULT; |
| 249 | goto end; |
| 250 | } |
| 251 | |
| 252 | pdomain = &(pr->throttling.domain_info); |
| 253 | |
| 254 | state.length = sizeof(struct acpi_tsd_package); |
| 255 | state.pointer = pdomain; |
| 256 | |
| 257 | status = acpi_extract_package(&(tsd->package.elements[0]), |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 258 | &format, &state); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 259 | if (ACPI_FAILURE(status)) { |
| 260 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); |
| 261 | result = -EFAULT; |
| 262 | goto end; |
| 263 | } |
| 264 | |
| 265 | if (pdomain->num_entries != ACPI_TSD_REV0_ENTRIES) { |
| 266 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:num_entries\n")); |
| 267 | result = -EFAULT; |
| 268 | goto end; |
| 269 | } |
| 270 | |
| 271 | if (pdomain->revision != ACPI_TSD_REV0_REVISION) { |
| 272 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:revision\n")); |
| 273 | result = -EFAULT; |
| 274 | goto end; |
| 275 | } |
| 276 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 277 | end: |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 278 | kfree(buffer.pointer); |
| 279 | return result; |
| 280 | } |
| 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | /* -------------------------------------------------------------------------- |
| 283 | Throttling Control |
| 284 | -------------------------------------------------------------------------- */ |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 285 | static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 287 | int state = 0; |
| 288 | u32 value = 0; |
| 289 | u32 duty_mask = 0; |
| 290 | u32 duty_value = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 293 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | if (!pr->flags.throttling) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 296 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
| 298 | pr->throttling.state = 0; |
| 299 | |
| 300 | duty_mask = pr->throttling.state_count - 1; |
| 301 | |
| 302 | duty_mask <<= pr->throttling.duty_offset; |
| 303 | |
| 304 | local_irq_disable(); |
| 305 | |
| 306 | value = inl(pr->throttling.address); |
| 307 | |
| 308 | /* |
| 309 | * Compute the current throttling state when throttling is enabled |
| 310 | * (bit 4 is on). |
| 311 | */ |
| 312 | if (value & 0x10) { |
| 313 | duty_value = value & duty_mask; |
| 314 | duty_value >>= pr->throttling.duty_offset; |
| 315 | |
| 316 | if (duty_value) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | state = pr->throttling.state_count - duty_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | pr->throttling.state = state; |
| 321 | |
| 322 | local_irq_enable(); |
| 323 | |
| 324 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 325 | "Throttling state is T%d (%d%% throttling applied)\n", |
| 326 | state, pr->throttling.states[state].performance)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 328 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 331 | static int acpi_read_throttling_status(struct acpi_processor_throttling |
| 332 | *throttling) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 333 | { |
| 334 | int value = -1; |
| 335 | switch (throttling->status_register.space_id) { |
| 336 | case ACPI_ADR_SPACE_SYSTEM_IO: |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 337 | acpi_os_read_port((acpi_io_address) throttling->status_register. |
| 338 | address, &value, |
| 339 | (u32) throttling->status_register.bit_width * |
| 340 | 8); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 341 | break; |
| 342 | case ACPI_ADR_SPACE_FIXED_HARDWARE: |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 343 | printk(KERN_ERR PREFIX |
| 344 | "HARDWARE addr space,NOT supported yet\n"); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 345 | break; |
| 346 | default: |
| 347 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 348 | (u32) (throttling->status_register.space_id)); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 349 | } |
| 350 | return value; |
| 351 | } |
| 352 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 353 | static int acpi_write_throttling_state(struct acpi_processor_throttling |
| 354 | *throttling, int value) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 355 | { |
| 356 | int ret = -1; |
| 357 | |
| 358 | switch (throttling->control_register.space_id) { |
| 359 | case ACPI_ADR_SPACE_SYSTEM_IO: |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 360 | acpi_os_write_port((acpi_io_address) throttling-> |
| 361 | control_register.address, value, |
| 362 | (u32) throttling->control_register. |
| 363 | bit_width * 8); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 364 | ret = 0; |
| 365 | break; |
| 366 | case ACPI_ADR_SPACE_FIXED_HARDWARE: |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 367 | printk(KERN_ERR PREFIX |
| 368 | "HARDWARE addr space,NOT supported yet\n"); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 369 | break; |
| 370 | default: |
| 371 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 372 | (u32) (throttling->control_register.space_id)); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 373 | } |
| 374 | return ret; |
| 375 | } |
| 376 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 377 | static int acpi_get_throttling_state(struct acpi_processor *pr, int value) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 378 | { |
| 379 | int i; |
| 380 | |
| 381 | for (i = 0; i < pr->throttling.state_count; i++) { |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 382 | struct acpi_processor_tx_tss *tx = |
| 383 | (struct acpi_processor_tx_tss *)&(pr->throttling. |
| 384 | states_tss[i]); |
| 385 | if (tx->control == value) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 386 | break; |
| 387 | } |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 388 | if (i > pr->throttling.state_count) |
| 389 | i = -1; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 390 | return i; |
| 391 | } |
| 392 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 393 | static int acpi_get_throttling_value(struct acpi_processor *pr, int state) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 394 | { |
| 395 | int value = -1; |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 396 | if (state >= 0 && state <= pr->throttling.state_count) { |
| 397 | struct acpi_processor_tx_tss *tx = |
| 398 | (struct acpi_processor_tx_tss *)&(pr->throttling. |
| 399 | states_tss[state]); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 400 | value = tx->control; |
| 401 | } |
| 402 | return value; |
| 403 | } |
| 404 | |
| 405 | static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) |
| 406 | { |
| 407 | int state = 0; |
| 408 | u32 value = 0; |
| 409 | |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 410 | if (!pr) |
| 411 | return -EINVAL; |
| 412 | |
| 413 | if (!pr->flags.throttling) |
| 414 | return -ENODEV; |
| 415 | |
| 416 | pr->throttling.state = 0; |
| 417 | local_irq_disable(); |
| 418 | value = acpi_read_throttling_status(&pr->throttling); |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 419 | if (value >= 0) { |
| 420 | state = acpi_get_throttling_state(pr, value); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 421 | pr->throttling.state = state; |
| 422 | } |
| 423 | local_irq_enable(); |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 428 | static int acpi_processor_get_throttling(struct acpi_processor *pr) |
| 429 | { |
| 430 | return pr->throttling.acpi_processor_get_throttling(pr); |
| 431 | } |
| 432 | |
Adrian Bunk | 6c5cf8a | 2007-07-03 00:53:12 -0400 | [diff] [blame] | 433 | static int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, |
| 434 | int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 436 | u32 value = 0; |
| 437 | u32 duty_mask = 0; |
| 438 | u32 duty_value = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 441 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | if ((state < 0) || (state > (pr->throttling.state_count - 1))) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 444 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
| 446 | if (!pr->flags.throttling) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 447 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | if (state == pr->throttling.state) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 450 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 452 | if (state < pr->throttling_platform_limit) |
| 453 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | /* |
| 455 | * Calculate the duty_value and duty_mask. |
| 456 | */ |
| 457 | if (state) { |
| 458 | duty_value = pr->throttling.state_count - state; |
| 459 | |
| 460 | duty_value <<= pr->throttling.duty_offset; |
| 461 | |
| 462 | /* Used to clear all duty_value bits */ |
| 463 | duty_mask = pr->throttling.state_count - 1; |
| 464 | |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 465 | duty_mask <<= acpi_gbl_FADT.duty_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | duty_mask = ~duty_mask; |
| 467 | } |
| 468 | |
| 469 | local_irq_disable(); |
| 470 | |
| 471 | /* |
| 472 | * Disable throttling by writing a 0 to bit 4. Note that we must |
| 473 | * turn it off before you can change the duty_value. |
| 474 | */ |
| 475 | value = inl(pr->throttling.address); |
| 476 | if (value & 0x10) { |
| 477 | value &= 0xFFFFFFEF; |
| 478 | outl(value, pr->throttling.address); |
| 479 | } |
| 480 | |
| 481 | /* |
| 482 | * Write the new duty_value and then enable throttling. Note |
| 483 | * that a state value of 0 leaves throttling disabled. |
| 484 | */ |
| 485 | if (state) { |
| 486 | value &= duty_mask; |
| 487 | value |= duty_value; |
| 488 | outl(value, pr->throttling.address); |
| 489 | |
| 490 | value |= 0x00000010; |
| 491 | outl(value, pr->throttling.address); |
| 492 | } |
| 493 | |
| 494 | pr->throttling.state = state; |
| 495 | |
| 496 | local_irq_enable(); |
| 497 | |
| 498 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 499 | "Throttling state set to T%d (%d%%)\n", state, |
| 500 | (pr->throttling.states[state].performance ? pr-> |
| 501 | throttling.states[state].performance / 10 : 0))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 503 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Adrian Bunk | 6c5cf8a | 2007-07-03 00:53:12 -0400 | [diff] [blame] | 506 | static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, |
| 507 | int state) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 508 | { |
| 509 | u32 value = 0; |
| 510 | |
| 511 | if (!pr) |
| 512 | return -EINVAL; |
| 513 | |
| 514 | if ((state < 0) || (state > (pr->throttling.state_count - 1))) |
| 515 | return -EINVAL; |
| 516 | |
| 517 | if (!pr->flags.throttling) |
| 518 | return -ENODEV; |
| 519 | |
| 520 | if (state == pr->throttling.state) |
| 521 | return 0; |
| 522 | |
| 523 | if (state < pr->throttling_platform_limit) |
| 524 | return -EPERM; |
| 525 | |
| 526 | local_irq_disable(); |
| 527 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 528 | value = acpi_get_throttling_value(pr, state); |
| 529 | if (value >= 0) { |
| 530 | acpi_write_throttling_state(&pr->throttling, value); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 531 | pr->throttling.state = state; |
| 532 | } |
| 533 | local_irq_enable(); |
| 534 | |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | int acpi_processor_set_throttling(struct acpi_processor *pr, int state) |
| 539 | { |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 540 | return pr->throttling.acpi_processor_set_throttling(pr, state); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 541 | } |
| 542 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 543 | int acpi_processor_get_throttling_info(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 545 | int result = 0; |
| 546 | int step = 0; |
| 547 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 550 | "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n", |
| 551 | pr->throttling.address, |
| 552 | pr->throttling.duty_offset, |
| 553 | pr->throttling.duty_width)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 556 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 558 | /* |
| 559 | * Evaluate _PTC, _TSS and _TPC |
| 560 | * They must all be present or none of them can be used. |
| 561 | */ |
| 562 | if (acpi_processor_get_throttling_control(pr) || |
| 563 | acpi_processor_get_throttling_states(pr) || |
| 564 | acpi_processor_get_platform_limit(pr)) |
| 565 | { |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 566 | pr->throttling.acpi_processor_get_throttling = |
| 567 | &acpi_processor_get_throttling_fadt; |
| 568 | pr->throttling.acpi_processor_set_throttling = |
| 569 | &acpi_processor_set_throttling_fadt; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 570 | } else { |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 571 | pr->throttling.acpi_processor_get_throttling = |
| 572 | &acpi_processor_get_throttling_ptc; |
| 573 | pr->throttling.acpi_processor_set_throttling = |
| 574 | &acpi_processor_set_throttling_ptc; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 577 | acpi_processor_get_tsd(pr); |
| 578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | if (!pr->throttling.address) { |
| 580 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 581 | return 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 582 | } else if (!pr->throttling.duty_width) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 584 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | } |
| 586 | /* TBD: Support duty_cycle values that span bit 4. */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 587 | else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) { |
Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 588 | printk(KERN_WARNING PREFIX "duty_cycle spans bit 4\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 589 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /* |
| 593 | * PIIX4 Errata: We don't support throttling on the original PIIX4. |
| 594 | * This shouldn't be an issue as few (if any) mobile systems ever |
| 595 | * used this part. |
| 596 | */ |
| 597 | if (errata.piix4.throttle) { |
| 598 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 599 | "Throttling not supported on PIIX4 A- or B-step\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 600 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 603 | pr->throttling.state_count = 1 << acpi_gbl_FADT.duty_width; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
| 605 | /* |
| 606 | * Compute state values. Note that throttling displays a linear power/ |
| 607 | * performance relationship (at 50% performance the CPU will consume |
| 608 | * 50% power). Values are in 1/10th of a percent to preserve accuracy. |
| 609 | */ |
| 610 | |
| 611 | step = (1000 / pr->throttling.state_count); |
| 612 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 613 | for (i = 0; i < pr->throttling.state_count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | pr->throttling.states[i].performance = step * i; |
| 615 | pr->throttling.states[i].power = step * i; |
| 616 | } |
| 617 | |
| 618 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 619 | pr->throttling.state_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
| 621 | pr->flags.throttling = 1; |
| 622 | |
| 623 | /* |
| 624 | * Disable throttling (if enabled). We'll let subsequent policy (e.g. |
| 625 | * thermal) decide to lower performance if it so chooses, but for now |
| 626 | * we'll crank up the speed. |
| 627 | */ |
| 628 | |
| 629 | result = acpi_processor_get_throttling(pr); |
| 630 | if (result) |
| 631 | goto end; |
| 632 | |
| 633 | if (pr->throttling.state) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 634 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 635 | "Disabling throttling (was T%d)\n", |
| 636 | pr->throttling.state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | result = acpi_processor_set_throttling(pr, 0); |
| 638 | if (result) |
| 639 | goto end; |
| 640 | } |
| 641 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 642 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | if (result) |
| 644 | pr->flags.throttling = 0; |
| 645 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 646 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | /* proc interface */ |
| 650 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 651 | static int acpi_processor_throttling_seq_show(struct seq_file *seq, |
| 652 | void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 654 | struct acpi_processor *pr = seq->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 655 | int i = 0; |
| 656 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | if (!pr) |
| 659 | goto end; |
| 660 | |
| 661 | if (!(pr->throttling.state_count > 0)) { |
| 662 | seq_puts(seq, "<not supported>\n"); |
| 663 | goto end; |
| 664 | } |
| 665 | |
| 666 | result = acpi_processor_get_throttling(pr); |
| 667 | |
| 668 | if (result) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 669 | seq_puts(seq, |
| 670 | "Could not determine current throttling state.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | goto end; |
| 672 | } |
| 673 | |
| 674 | seq_printf(seq, "state count: %d\n" |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 675 | "active state: T%d\n" |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 676 | "state available: T%d to T%d\n", |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 677 | pr->throttling.state_count, pr->throttling.state, |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 678 | pr->throttling_platform_limit, |
| 679 | pr->throttling.state_count - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
| 681 | seq_puts(seq, "states:\n"); |
Luming Yu | 3cc2649 | 2007-07-23 12:39:28 -0400 | [diff] [blame] | 682 | if (pr->throttling.acpi_processor_get_throttling == |
| 683 | acpi_processor_get_throttling_fadt) { |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 684 | for (i = 0; i < pr->throttling.state_count; i++) |
| 685 | seq_printf(seq, " %cT%d: %02d%%\n", |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 686 | (i == pr->throttling.state ? '*' : ' '), i, |
| 687 | (pr->throttling.states[i].performance ? pr-> |
| 688 | throttling.states[i].performance / 10 : 0)); |
Luming Yu | 3cc2649 | 2007-07-23 12:39:28 -0400 | [diff] [blame] | 689 | } else { |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 690 | for (i = 0; i < pr->throttling.state_count; i++) |
| 691 | seq_printf(seq, " %cT%d: %02d%%\n", |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 692 | (i == pr->throttling.state ? '*' : ' '), i, |
| 693 | (int)pr->throttling.states_tss[i]. |
| 694 | freqpercentage); |
Luming Yu | 3cc2649 | 2007-07-23 12:39:28 -0400 | [diff] [blame] | 695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 697 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 698 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | } |
| 700 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 701 | static int acpi_processor_throttling_open_fs(struct inode *inode, |
| 702 | struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { |
| 704 | return single_open(file, acpi_processor_throttling_seq_show, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 705 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 708 | static ssize_t acpi_processor_write_throttling(struct file *file, |
Adrian Bunk | 757b186 | 2006-01-07 13:19:00 -0500 | [diff] [blame] | 709 | const char __user * buffer, |
| 710 | size_t count, loff_t * data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 712 | int result = 0; |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 713 | struct seq_file *m = file->private_data; |
| 714 | struct acpi_processor *pr = m->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 715 | char state_string[12] = { '\0' }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | if (!pr || (count > sizeof(state_string) - 1)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 718 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | |
| 720 | if (copy_from_user(state_string, buffer, count)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 721 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
| 723 | state_string[count] = '\0'; |
| 724 | |
| 725 | result = acpi_processor_set_throttling(pr, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 726 | simple_strtoul(state_string, |
| 727 | NULL, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 729 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 731 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | struct file_operations acpi_processor_throttling_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 735 | .open = acpi_processor_throttling_open_fs, |
| 736 | .read = seq_read, |
Arjan van de Ven | d479e90 | 2006-01-06 16:47:00 -0500 | [diff] [blame] | 737 | .write = acpi_processor_write_throttling, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 738 | .llseek = seq_lseek, |
| 739 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | }; |