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