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