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