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 | |
Zhao Yakui | e4aa5cb | 2008-01-28 13:54:46 +0800 | [diff] [blame] | 48 | struct throttling_tstate { |
| 49 | unsigned int cpu; /* cpu nr */ |
| 50 | int target_state; /* target T-state */ |
| 51 | }; |
| 52 | |
| 53 | #define THROTTLING_PRECHANGE (1) |
| 54 | #define THROTTLING_POSTCHANGE (2) |
| 55 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 56 | static int acpi_processor_get_throttling(struct acpi_processor *pr); |
| 57 | int acpi_processor_set_throttling(struct acpi_processor *pr, int state); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 58 | |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 59 | static int acpi_processor_update_tsd_coord(void) |
| 60 | { |
| 61 | int count, count_target; |
| 62 | int retval = 0; |
| 63 | unsigned int i, j; |
| 64 | cpumask_t covered_cpus; |
| 65 | struct acpi_processor *pr, *match_pr; |
| 66 | struct acpi_tsd_package *pdomain, *match_pdomain; |
| 67 | struct acpi_processor_throttling *pthrottling, *match_pthrottling; |
| 68 | |
| 69 | /* |
| 70 | * Now that we have _TSD data from all CPUs, lets setup T-state |
Zhao Yakui | 33a2a52 | 2008-01-28 13:55:56 +0800 | [diff] [blame] | 71 | * coordination between all CPUs. |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 72 | */ |
| 73 | for_each_possible_cpu(i) { |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 74 | pr = per_cpu(processors, i); |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 75 | if (!pr) |
| 76 | continue; |
| 77 | |
| 78 | /* Basic validity check for domain info */ |
| 79 | pthrottling = &(pr->throttling); |
| 80 | |
| 81 | /* |
| 82 | * If tsd package for one cpu is invalid, the coordination |
| 83 | * among all CPUs is thought as invalid. |
| 84 | * Maybe it is ugly. |
| 85 | */ |
| 86 | if (!pthrottling->tsd_valid_flag) { |
| 87 | retval = -EINVAL; |
| 88 | break; |
| 89 | } |
| 90 | } |
| 91 | if (retval) |
| 92 | goto err_ret; |
| 93 | |
| 94 | cpus_clear(covered_cpus); |
| 95 | for_each_possible_cpu(i) { |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 96 | pr = per_cpu(processors, i); |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 97 | if (!pr) |
| 98 | continue; |
| 99 | |
| 100 | if (cpu_isset(i, covered_cpus)) |
| 101 | continue; |
| 102 | pthrottling = &pr->throttling; |
| 103 | |
| 104 | pdomain = &(pthrottling->domain_info); |
| 105 | cpu_set(i, pthrottling->shared_cpu_map); |
| 106 | cpu_set(i, covered_cpus); |
| 107 | /* |
| 108 | * If the number of processor in the TSD domain is 1, it is |
| 109 | * unnecessary to parse the coordination for this CPU. |
| 110 | */ |
| 111 | if (pdomain->num_processors <= 1) |
| 112 | continue; |
| 113 | |
| 114 | /* Validate the Domain info */ |
| 115 | count_target = pdomain->num_processors; |
| 116 | count = 1; |
| 117 | |
| 118 | for_each_possible_cpu(j) { |
| 119 | if (i == j) |
| 120 | continue; |
| 121 | |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 122 | match_pr = per_cpu(processors, j); |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 123 | if (!match_pr) |
| 124 | continue; |
| 125 | |
| 126 | match_pthrottling = &(match_pr->throttling); |
| 127 | match_pdomain = &(match_pthrottling->domain_info); |
| 128 | if (match_pdomain->domain != pdomain->domain) |
| 129 | continue; |
| 130 | |
| 131 | /* Here i and j are in the same domain. |
| 132 | * If two TSD packages have the same domain, they |
| 133 | * should have the same num_porcessors and |
| 134 | * coordination type. Otherwise it will be regarded |
| 135 | * as illegal. |
| 136 | */ |
| 137 | if (match_pdomain->num_processors != count_target) { |
| 138 | retval = -EINVAL; |
| 139 | goto err_ret; |
| 140 | } |
| 141 | |
| 142 | if (pdomain->coord_type != match_pdomain->coord_type) { |
| 143 | retval = -EINVAL; |
| 144 | goto err_ret; |
| 145 | } |
| 146 | |
| 147 | cpu_set(j, covered_cpus); |
| 148 | cpu_set(j, pthrottling->shared_cpu_map); |
| 149 | count++; |
| 150 | } |
| 151 | for_each_possible_cpu(j) { |
| 152 | if (i == j) |
| 153 | continue; |
| 154 | |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 155 | match_pr = per_cpu(processors, j); |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 156 | if (!match_pr) |
| 157 | continue; |
| 158 | |
| 159 | match_pthrottling = &(match_pr->throttling); |
| 160 | match_pdomain = &(match_pthrottling->domain_info); |
| 161 | if (match_pdomain->domain != pdomain->domain) |
| 162 | continue; |
| 163 | |
| 164 | /* |
| 165 | * If some CPUS have the same domain, they |
| 166 | * will have the same shared_cpu_map. |
| 167 | */ |
| 168 | match_pthrottling->shared_cpu_map = |
| 169 | pthrottling->shared_cpu_map; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | err_ret: |
| 174 | for_each_possible_cpu(i) { |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 175 | pr = per_cpu(processors, i); |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 176 | if (!pr) |
| 177 | continue; |
| 178 | |
| 179 | /* |
| 180 | * Assume no coordination on any error parsing domain info. |
| 181 | * The coordination type will be forced as SW_ALL. |
| 182 | */ |
| 183 | if (retval) { |
| 184 | pthrottling = &(pr->throttling); |
| 185 | cpus_clear(pthrottling->shared_cpu_map); |
| 186 | cpu_set(i, pthrottling->shared_cpu_map); |
| 187 | pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | return retval; |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | * Update the T-state coordination after the _TSD |
| 196 | * data for all cpus is obtained. |
| 197 | */ |
| 198 | void acpi_processor_throttling_init(void) |
| 199 | { |
| 200 | if (acpi_processor_update_tsd_coord()) |
| 201 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 202 | "Assume no T-state coordination\n")); |
| 203 | |
| 204 | return; |
| 205 | } |
| 206 | |
Zhao Yakui | e4aa5cb | 2008-01-28 13:54:46 +0800 | [diff] [blame] | 207 | static int acpi_processor_throttling_notifier(unsigned long event, void *data) |
| 208 | { |
| 209 | struct throttling_tstate *p_tstate = data; |
| 210 | struct acpi_processor *pr; |
| 211 | unsigned int cpu ; |
| 212 | int target_state; |
| 213 | struct acpi_processor_limit *p_limit; |
| 214 | struct acpi_processor_throttling *p_throttling; |
| 215 | |
| 216 | cpu = p_tstate->cpu; |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 217 | pr = per_cpu(processors, cpu); |
Zhao Yakui | e4aa5cb | 2008-01-28 13:54:46 +0800 | [diff] [blame] | 218 | if (!pr) { |
| 219 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Invalid pr pointer\n")); |
| 220 | return 0; |
| 221 | } |
| 222 | if (!pr->flags.throttling) { |
| 223 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Throttling control is " |
| 224 | "unsupported on CPU %d\n", cpu)); |
| 225 | return 0; |
| 226 | } |
| 227 | target_state = p_tstate->target_state; |
| 228 | p_throttling = &(pr->throttling); |
| 229 | switch (event) { |
| 230 | case THROTTLING_PRECHANGE: |
| 231 | /* |
| 232 | * Prechange event is used to choose one proper t-state, |
| 233 | * which meets the limits of thermal, user and _TPC. |
| 234 | */ |
| 235 | p_limit = &pr->limit; |
| 236 | if (p_limit->thermal.tx > target_state) |
| 237 | target_state = p_limit->thermal.tx; |
| 238 | if (p_limit->user.tx > target_state) |
| 239 | target_state = p_limit->user.tx; |
| 240 | if (pr->throttling_platform_limit > target_state) |
| 241 | target_state = pr->throttling_platform_limit; |
| 242 | if (target_state >= p_throttling->state_count) { |
| 243 | printk(KERN_WARNING |
| 244 | "Exceed the limit of T-state \n"); |
| 245 | target_state = p_throttling->state_count - 1; |
| 246 | } |
| 247 | p_tstate->target_state = target_state; |
| 248 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PreChange Event:" |
| 249 | "target T-state of CPU %d is T%d\n", |
| 250 | cpu, target_state)); |
| 251 | break; |
| 252 | case THROTTLING_POSTCHANGE: |
| 253 | /* |
| 254 | * Postchange event is only used to update the |
| 255 | * T-state flag of acpi_processor_throttling. |
| 256 | */ |
| 257 | p_throttling->state = target_state; |
| 258 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "PostChange Event:" |
| 259 | "CPU %d is switched to T%d\n", |
| 260 | cpu, target_state)); |
| 261 | break; |
| 262 | default: |
| 263 | printk(KERN_WARNING |
| 264 | "Unsupported Throttling notifier event\n"); |
| 265 | break; |
| 266 | } |
| 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 271 | /* |
| 272 | * _TPC - Throttling Present Capabilities |
| 273 | */ |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 274 | static int acpi_processor_get_platform_limit(struct acpi_processor *pr) |
| 275 | { |
| 276 | acpi_status status = 0; |
| 277 | unsigned long tpc = 0; |
| 278 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 279 | if (!pr) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 280 | return -EINVAL; |
| 281 | status = acpi_evaluate_integer(pr->handle, "_TPC", NULL, &tpc); |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 282 | if (ACPI_FAILURE(status)) { |
| 283 | if (status != AE_NOT_FOUND) { |
| 284 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TPC")); |
| 285 | } |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 286 | return -ENODEV; |
| 287 | } |
| 288 | pr->throttling_platform_limit = (int)tpc; |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | int acpi_processor_tstate_has_changed(struct acpi_processor *pr) |
| 293 | { |
Zhao Yakui | ef54d5a | 2007-11-15 16:59:30 +0800 | [diff] [blame] | 294 | int result = 0; |
| 295 | int throttling_limit; |
| 296 | int current_state; |
| 297 | struct acpi_processor_limit *limit; |
| 298 | int target_state; |
| 299 | |
| 300 | result = acpi_processor_get_platform_limit(pr); |
| 301 | if (result) { |
| 302 | /* Throttling Limit is unsupported */ |
| 303 | return result; |
| 304 | } |
| 305 | |
| 306 | throttling_limit = pr->throttling_platform_limit; |
| 307 | if (throttling_limit >= pr->throttling.state_count) { |
| 308 | /* Uncorrect Throttling Limit */ |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | |
| 312 | current_state = pr->throttling.state; |
| 313 | if (current_state > throttling_limit) { |
| 314 | /* |
| 315 | * The current state can meet the requirement of |
| 316 | * _TPC limit. But it is reasonable that OSPM changes |
| 317 | * t-states from high to low for better performance. |
| 318 | * Of course the limit condition of thermal |
| 319 | * and user should be considered. |
| 320 | */ |
| 321 | limit = &pr->limit; |
| 322 | target_state = throttling_limit; |
| 323 | if (limit->thermal.tx > target_state) |
| 324 | target_state = limit->thermal.tx; |
| 325 | if (limit->user.tx > target_state) |
| 326 | target_state = limit->user.tx; |
| 327 | } else if (current_state == throttling_limit) { |
| 328 | /* |
| 329 | * Unnecessary to change the throttling state |
| 330 | */ |
| 331 | return 0; |
| 332 | } else { |
| 333 | /* |
| 334 | * If the current state is lower than the limit of _TPC, it |
| 335 | * will be forced to switch to the throttling state defined |
| 336 | * by throttling_platfor_limit. |
| 337 | * Because the previous state meets with the limit condition |
| 338 | * of thermal and user, it is unnecessary to check it again. |
| 339 | */ |
| 340 | target_state = throttling_limit; |
| 341 | } |
| 342 | return acpi_processor_set_throttling(pr, target_state); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 343 | } |
| 344 | |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 345 | /* |
| 346 | * _PTC - Processor Throttling Control (and status) register location |
| 347 | */ |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 348 | static int acpi_processor_get_throttling_control(struct acpi_processor *pr) |
| 349 | { |
| 350 | int result = 0; |
| 351 | acpi_status status = 0; |
| 352 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 353 | union acpi_object *ptc = NULL; |
| 354 | union acpi_object obj = { 0 }; |
Zhao Yakui | 9bcb272 | 2007-11-15 17:05:05 +0800 | [diff] [blame] | 355 | struct acpi_processor_throttling *throttling; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 356 | |
| 357 | status = acpi_evaluate_object(pr->handle, "_PTC", NULL, &buffer); |
| 358 | if (ACPI_FAILURE(status)) { |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 359 | if (status != AE_NOT_FOUND) { |
| 360 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PTC")); |
| 361 | } |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 362 | return -ENODEV; |
| 363 | } |
| 364 | |
| 365 | ptc = (union acpi_object *)buffer.pointer; |
| 366 | if (!ptc || (ptc->type != ACPI_TYPE_PACKAGE) |
| 367 | || (ptc->package.count != 2)) { |
| 368 | printk(KERN_ERR PREFIX "Invalid _PTC data\n"); |
| 369 | result = -EFAULT; |
| 370 | goto end; |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * control_register |
| 375 | */ |
| 376 | |
| 377 | obj = ptc->package.elements[0]; |
| 378 | |
| 379 | if ((obj.type != ACPI_TYPE_BUFFER) |
| 380 | || (obj.buffer.length < sizeof(struct acpi_ptc_register)) |
| 381 | || (obj.buffer.pointer == NULL)) { |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 382 | printk(KERN_ERR PREFIX |
| 383 | "Invalid _PTC data (control_register)\n"); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 384 | result = -EFAULT; |
| 385 | goto end; |
| 386 | } |
| 387 | memcpy(&pr->throttling.control_register, obj.buffer.pointer, |
| 388 | sizeof(struct acpi_ptc_register)); |
| 389 | |
| 390 | /* |
| 391 | * status_register |
| 392 | */ |
| 393 | |
| 394 | obj = ptc->package.elements[1]; |
| 395 | |
| 396 | if ((obj.type != ACPI_TYPE_BUFFER) |
| 397 | || (obj.buffer.length < sizeof(struct acpi_ptc_register)) |
| 398 | || (obj.buffer.pointer == NULL)) { |
| 399 | printk(KERN_ERR PREFIX "Invalid _PTC data (status_register)\n"); |
| 400 | result = -EFAULT; |
| 401 | goto end; |
| 402 | } |
| 403 | |
| 404 | memcpy(&pr->throttling.status_register, obj.buffer.pointer, |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 405 | sizeof(struct acpi_ptc_register)); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 406 | |
Zhao Yakui | 9bcb272 | 2007-11-15 17:05:05 +0800 | [diff] [blame] | 407 | throttling = &pr->throttling; |
| 408 | |
| 409 | if ((throttling->control_register.bit_width + |
| 410 | throttling->control_register.bit_offset) > 32) { |
| 411 | printk(KERN_ERR PREFIX "Invalid _PTC control register\n"); |
| 412 | result = -EFAULT; |
| 413 | goto end; |
| 414 | } |
| 415 | |
| 416 | if ((throttling->status_register.bit_width + |
| 417 | throttling->status_register.bit_offset) > 32) { |
| 418 | printk(KERN_ERR PREFIX "Invalid _PTC status register\n"); |
| 419 | result = -EFAULT; |
| 420 | goto end; |
| 421 | } |
| 422 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 423 | end: |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 424 | kfree(buffer.pointer); |
| 425 | |
| 426 | return result; |
| 427 | } |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 428 | |
| 429 | /* |
| 430 | * _TSS - Throttling Supported States |
| 431 | */ |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 432 | static int acpi_processor_get_throttling_states(struct acpi_processor *pr) |
| 433 | { |
| 434 | int result = 0; |
| 435 | acpi_status status = AE_OK; |
| 436 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 437 | struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" }; |
| 438 | struct acpi_buffer state = { 0, NULL }; |
| 439 | union acpi_object *tss = NULL; |
| 440 | int i; |
| 441 | |
| 442 | status = acpi_evaluate_object(pr->handle, "_TSS", NULL, &buffer); |
| 443 | if (ACPI_FAILURE(status)) { |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 444 | if (status != AE_NOT_FOUND) { |
| 445 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSS")); |
| 446 | } |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 447 | return -ENODEV; |
| 448 | } |
| 449 | |
| 450 | tss = buffer.pointer; |
| 451 | if (!tss || (tss->type != ACPI_TYPE_PACKAGE)) { |
| 452 | printk(KERN_ERR PREFIX "Invalid _TSS data\n"); |
| 453 | result = -EFAULT; |
| 454 | goto end; |
| 455 | } |
| 456 | |
| 457 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n", |
| 458 | tss->package.count)); |
| 459 | |
| 460 | pr->throttling.state_count = tss->package.count; |
| 461 | pr->throttling.states_tss = |
| 462 | kmalloc(sizeof(struct acpi_processor_tx_tss) * tss->package.count, |
| 463 | GFP_KERNEL); |
| 464 | if (!pr->throttling.states_tss) { |
| 465 | result = -ENOMEM; |
| 466 | goto end; |
| 467 | } |
| 468 | |
| 469 | for (i = 0; i < pr->throttling.state_count; i++) { |
| 470 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 471 | struct acpi_processor_tx_tss *tx = |
| 472 | (struct acpi_processor_tx_tss *)&(pr->throttling. |
| 473 | states_tss[i]); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 474 | |
| 475 | state.length = sizeof(struct acpi_processor_tx_tss); |
| 476 | state.pointer = tx; |
| 477 | |
| 478 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i)); |
| 479 | |
| 480 | status = acpi_extract_package(&(tss->package.elements[i]), |
| 481 | &format, &state); |
| 482 | if (ACPI_FAILURE(status)) { |
| 483 | ACPI_EXCEPTION((AE_INFO, status, "Invalid _TSS data")); |
| 484 | result = -EFAULT; |
| 485 | kfree(pr->throttling.states_tss); |
| 486 | goto end; |
| 487 | } |
| 488 | |
| 489 | if (!tx->freqpercentage) { |
| 490 | printk(KERN_ERR PREFIX |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 491 | "Invalid _TSS data: freq is zero\n"); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 492 | result = -EFAULT; |
| 493 | kfree(pr->throttling.states_tss); |
| 494 | goto end; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | end: |
| 499 | kfree(buffer.pointer); |
| 500 | |
| 501 | return result; |
| 502 | } |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 503 | |
| 504 | /* |
| 505 | * _TSD - T-State Dependencies |
| 506 | */ |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 507 | static int acpi_processor_get_tsd(struct acpi_processor *pr) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 508 | { |
| 509 | int result = 0; |
| 510 | acpi_status status = AE_OK; |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 511 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 512 | struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" }; |
| 513 | struct acpi_buffer state = { 0, NULL }; |
| 514 | union acpi_object *tsd = NULL; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 515 | struct acpi_tsd_package *pdomain; |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 516 | struct acpi_processor_throttling *pthrottling; |
| 517 | |
| 518 | pthrottling = &pr->throttling; |
| 519 | pthrottling->tsd_valid_flag = 0; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 520 | |
| 521 | status = acpi_evaluate_object(pr->handle, "_TSD", NULL, &buffer); |
| 522 | if (ACPI_FAILURE(status)) { |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 523 | if (status != AE_NOT_FOUND) { |
| 524 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _TSD")); |
| 525 | } |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 526 | return -ENODEV; |
| 527 | } |
| 528 | |
| 529 | tsd = buffer.pointer; |
| 530 | if (!tsd || (tsd->type != ACPI_TYPE_PACKAGE)) { |
| 531 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); |
| 532 | result = -EFAULT; |
| 533 | goto end; |
| 534 | } |
| 535 | |
| 536 | if (tsd->package.count != 1) { |
| 537 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); |
| 538 | result = -EFAULT; |
| 539 | goto end; |
| 540 | } |
| 541 | |
| 542 | pdomain = &(pr->throttling.domain_info); |
| 543 | |
| 544 | state.length = sizeof(struct acpi_tsd_package); |
| 545 | state.pointer = pdomain; |
| 546 | |
| 547 | status = acpi_extract_package(&(tsd->package.elements[0]), |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 548 | &format, &state); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 549 | if (ACPI_FAILURE(status)) { |
| 550 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _TSD data\n")); |
| 551 | result = -EFAULT; |
| 552 | goto end; |
| 553 | } |
| 554 | |
| 555 | if (pdomain->num_entries != ACPI_TSD_REV0_ENTRIES) { |
| 556 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:num_entries\n")); |
| 557 | result = -EFAULT; |
| 558 | goto end; |
| 559 | } |
| 560 | |
| 561 | if (pdomain->revision != ACPI_TSD_REV0_REVISION) { |
| 562 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _TSD:revision\n")); |
| 563 | result = -EFAULT; |
| 564 | goto end; |
| 565 | } |
| 566 | |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 567 | pthrottling = &pr->throttling; |
| 568 | pthrottling->tsd_valid_flag = 1; |
| 569 | pthrottling->shared_type = pdomain->coord_type; |
| 570 | cpu_set(pr->id, pthrottling->shared_cpu_map); |
| 571 | /* |
| 572 | * If the coordination type is not defined in ACPI spec, |
| 573 | * the tsd_valid_flag will be clear and coordination type |
| 574 | * will be forecd as DOMAIN_COORD_TYPE_SW_ALL. |
| 575 | */ |
| 576 | if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL && |
| 577 | pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY && |
| 578 | pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) { |
| 579 | pthrottling->tsd_valid_flag = 0; |
| 580 | pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL; |
| 581 | } |
| 582 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 583 | end: |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 584 | kfree(buffer.pointer); |
| 585 | return result; |
| 586 | } |
| 587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | /* -------------------------------------------------------------------------- |
| 589 | Throttling Control |
| 590 | -------------------------------------------------------------------------- */ |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 591 | static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 593 | int state = 0; |
| 594 | u32 value = 0; |
| 595 | u32 duty_mask = 0; |
| 596 | u32 duty_value = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 599 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
| 601 | if (!pr->flags.throttling) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 602 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
| 604 | pr->throttling.state = 0; |
| 605 | |
| 606 | duty_mask = pr->throttling.state_count - 1; |
| 607 | |
| 608 | duty_mask <<= pr->throttling.duty_offset; |
| 609 | |
| 610 | local_irq_disable(); |
| 611 | |
| 612 | value = inl(pr->throttling.address); |
| 613 | |
| 614 | /* |
| 615 | * Compute the current throttling state when throttling is enabled |
| 616 | * (bit 4 is on). |
| 617 | */ |
| 618 | if (value & 0x10) { |
| 619 | duty_value = value & duty_mask; |
| 620 | duty_value >>= pr->throttling.duty_offset; |
| 621 | |
| 622 | if (duty_value) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 623 | state = pr->throttling.state_count - duty_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | pr->throttling.state = state; |
| 627 | |
| 628 | local_irq_enable(); |
| 629 | |
| 630 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 631 | "Throttling state is T%d (%d%% throttling applied)\n", |
| 632 | state, pr->throttling.states[state].performance)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 634 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | } |
| 636 | |
Zhao Yakui | f79f06a | 2007-11-15 17:06:36 +0800 | [diff] [blame] | 637 | #ifdef CONFIG_X86 |
| 638 | static int acpi_throttling_rdmsr(struct acpi_processor *pr, |
| 639 | acpi_integer * value) |
| 640 | { |
| 641 | struct cpuinfo_x86 *c; |
| 642 | u64 msr_high, msr_low; |
| 643 | unsigned int cpu; |
| 644 | u64 msr = 0; |
| 645 | int ret = -1; |
| 646 | |
| 647 | cpu = pr->id; |
| 648 | c = &cpu_data(cpu); |
| 649 | |
| 650 | if ((c->x86_vendor != X86_VENDOR_INTEL) || |
| 651 | !cpu_has(c, X86_FEATURE_ACPI)) { |
| 652 | printk(KERN_ERR PREFIX |
| 653 | "HARDWARE addr space,NOT supported yet\n"); |
| 654 | } else { |
| 655 | msr_low = 0; |
| 656 | msr_high = 0; |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 657 | rdmsr_safe(MSR_IA32_THERM_CONTROL, |
Zhao Yakui | f79f06a | 2007-11-15 17:06:36 +0800 | [diff] [blame] | 658 | (u32 *)&msr_low , (u32 *) &msr_high); |
| 659 | msr = (msr_high << 32) | msr_low; |
| 660 | *value = (acpi_integer) msr; |
| 661 | ret = 0; |
| 662 | } |
| 663 | return ret; |
| 664 | } |
| 665 | |
| 666 | static int acpi_throttling_wrmsr(struct acpi_processor *pr, acpi_integer value) |
| 667 | { |
| 668 | struct cpuinfo_x86 *c; |
| 669 | unsigned int cpu; |
| 670 | int ret = -1; |
| 671 | u64 msr; |
| 672 | |
| 673 | cpu = pr->id; |
| 674 | c = &cpu_data(cpu); |
| 675 | |
| 676 | if ((c->x86_vendor != X86_VENDOR_INTEL) || |
| 677 | !cpu_has(c, X86_FEATURE_ACPI)) { |
| 678 | printk(KERN_ERR PREFIX |
| 679 | "HARDWARE addr space,NOT supported yet\n"); |
| 680 | } else { |
| 681 | msr = value; |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 682 | wrmsr_safe(MSR_IA32_THERM_CONTROL, |
Zhao Yakui | f79f06a | 2007-11-15 17:06:36 +0800 | [diff] [blame] | 683 | msr & 0xffffffff, msr >> 32); |
| 684 | ret = 0; |
| 685 | } |
| 686 | return ret; |
| 687 | } |
| 688 | #else |
| 689 | static int acpi_throttling_rdmsr(struct acpi_processor *pr, |
| 690 | acpi_integer * value) |
| 691 | { |
| 692 | printk(KERN_ERR PREFIX |
| 693 | "HARDWARE addr space,NOT supported yet\n"); |
| 694 | return -1; |
| 695 | } |
| 696 | |
| 697 | static int acpi_throttling_wrmsr(struct acpi_processor *pr, acpi_integer value) |
| 698 | { |
| 699 | printk(KERN_ERR PREFIX |
| 700 | "HARDWARE addr space,NOT supported yet\n"); |
| 701 | return -1; |
| 702 | } |
| 703 | #endif |
| 704 | |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 705 | static int acpi_read_throttling_status(struct acpi_processor *pr, |
| 706 | acpi_integer *value) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 707 | { |
Zhao Yakui | 9bcb272 | 2007-11-15 17:05:05 +0800 | [diff] [blame] | 708 | u32 bit_width, bit_offset; |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 709 | u64 ptc_value; |
Zhao Yakui | 9bcb272 | 2007-11-15 17:05:05 +0800 | [diff] [blame] | 710 | u64 ptc_mask; |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 711 | struct acpi_processor_throttling *throttling; |
| 712 | int ret = -1; |
| 713 | |
| 714 | throttling = &pr->throttling; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 715 | switch (throttling->status_register.space_id) { |
| 716 | case ACPI_ADR_SPACE_SYSTEM_IO: |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 717 | ptc_value = 0; |
Zhao Yakui | 9bcb272 | 2007-11-15 17:05:05 +0800 | [diff] [blame] | 718 | bit_width = throttling->status_register.bit_width; |
| 719 | bit_offset = throttling->status_register.bit_offset; |
| 720 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 721 | acpi_os_read_port((acpi_io_address) throttling->status_register. |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 722 | address, (u32 *) &ptc_value, |
Zhao Yakui | 9bcb272 | 2007-11-15 17:05:05 +0800 | [diff] [blame] | 723 | (u32) (bit_width + bit_offset)); |
| 724 | ptc_mask = (1 << bit_width) - 1; |
| 725 | *value = (acpi_integer) ((ptc_value >> bit_offset) & ptc_mask); |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 726 | ret = 0; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 727 | break; |
| 728 | case ACPI_ADR_SPACE_FIXED_HARDWARE: |
Zhao Yakui | f79f06a | 2007-11-15 17:06:36 +0800 | [diff] [blame] | 729 | ret = acpi_throttling_rdmsr(pr, value); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 730 | break; |
| 731 | default: |
| 732 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 733 | (u32) (throttling->status_register.space_id)); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 734 | } |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 735 | return ret; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 736 | } |
| 737 | |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 738 | static int acpi_write_throttling_state(struct acpi_processor *pr, |
| 739 | acpi_integer value) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 740 | { |
Zhao Yakui | 9bcb272 | 2007-11-15 17:05:05 +0800 | [diff] [blame] | 741 | u32 bit_width, bit_offset; |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 742 | u64 ptc_value; |
Zhao Yakui | 9bcb272 | 2007-11-15 17:05:05 +0800 | [diff] [blame] | 743 | u64 ptc_mask; |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 744 | struct acpi_processor_throttling *throttling; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 745 | int ret = -1; |
| 746 | |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 747 | throttling = &pr->throttling; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 748 | switch (throttling->control_register.space_id) { |
| 749 | case ACPI_ADR_SPACE_SYSTEM_IO: |
Zhao Yakui | 9bcb272 | 2007-11-15 17:05:05 +0800 | [diff] [blame] | 750 | bit_width = throttling->control_register.bit_width; |
| 751 | bit_offset = throttling->control_register.bit_offset; |
| 752 | ptc_mask = (1 << bit_width) - 1; |
| 753 | ptc_value = value & ptc_mask; |
| 754 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 755 | acpi_os_write_port((acpi_io_address) throttling-> |
Zhao Yakui | 9bcb272 | 2007-11-15 17:05:05 +0800 | [diff] [blame] | 756 | control_register.address, |
| 757 | (u32) (ptc_value << bit_offset), |
| 758 | (u32) (bit_width + bit_offset)); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 759 | ret = 0; |
| 760 | break; |
| 761 | case ACPI_ADR_SPACE_FIXED_HARDWARE: |
Zhao Yakui | f79f06a | 2007-11-15 17:06:36 +0800 | [diff] [blame] | 762 | ret = acpi_throttling_wrmsr(pr, value); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 763 | break; |
| 764 | default: |
| 765 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 766 | (u32) (throttling->control_register.space_id)); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 767 | } |
| 768 | return ret; |
| 769 | } |
| 770 | |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 771 | static int acpi_get_throttling_state(struct acpi_processor *pr, |
| 772 | acpi_integer value) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 773 | { |
| 774 | int i; |
| 775 | |
| 776 | for (i = 0; i < pr->throttling.state_count; i++) { |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 777 | struct acpi_processor_tx_tss *tx = |
| 778 | (struct acpi_processor_tx_tss *)&(pr->throttling. |
| 779 | states_tss[i]); |
| 780 | if (tx->control == value) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 781 | break; |
| 782 | } |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 783 | if (i > pr->throttling.state_count) |
| 784 | i = -1; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 785 | return i; |
| 786 | } |
| 787 | |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 788 | static int acpi_get_throttling_value(struct acpi_processor *pr, |
| 789 | int state, acpi_integer *value) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 790 | { |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 791 | int ret = -1; |
| 792 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 793 | if (state >= 0 && state <= pr->throttling.state_count) { |
| 794 | struct acpi_processor_tx_tss *tx = |
| 795 | (struct acpi_processor_tx_tss *)&(pr->throttling. |
| 796 | states_tss[state]); |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 797 | *value = tx->control; |
| 798 | ret = 0; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 799 | } |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 800 | return ret; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | static int acpi_processor_get_throttling_ptc(struct acpi_processor *pr) |
| 804 | { |
| 805 | int state = 0; |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 806 | int ret; |
| 807 | acpi_integer value; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 808 | |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 809 | if (!pr) |
| 810 | return -EINVAL; |
| 811 | |
| 812 | if (!pr->flags.throttling) |
| 813 | return -ENODEV; |
| 814 | |
| 815 | pr->throttling.state = 0; |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 816 | |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 817 | value = 0; |
| 818 | ret = acpi_read_throttling_status(pr, &value); |
| 819 | if (ret >= 0) { |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 820 | state = acpi_get_throttling_state(pr, value); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 821 | pr->throttling.state = state; |
| 822 | } |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 823 | |
| 824 | return 0; |
| 825 | } |
| 826 | |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 827 | static int acpi_processor_get_throttling(struct acpi_processor *pr) |
| 828 | { |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 829 | cpumask_t saved_mask; |
Mike Travis | 65c0118 | 2008-07-15 14:14:30 -0700 | [diff] [blame] | 830 | cpumask_of_cpu_ptr_declare(new_mask); |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 831 | int ret; |
| 832 | |
Zhao Yakui | 8765427 | 2008-01-28 13:53:30 +0800 | [diff] [blame] | 833 | if (!pr) |
| 834 | return -EINVAL; |
| 835 | |
| 836 | if (!pr->flags.throttling) |
| 837 | return -ENODEV; |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 838 | /* |
| 839 | * Migrate task to the cpu pointed by pr. |
| 840 | */ |
| 841 | saved_mask = current->cpus_allowed; |
Mike Travis | 65c0118 | 2008-07-15 14:14:30 -0700 | [diff] [blame] | 842 | cpumask_of_cpu_ptr_next(new_mask, pr->id); |
| 843 | set_cpus_allowed_ptr(current, new_mask); |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 844 | ret = pr->throttling.acpi_processor_get_throttling(pr); |
| 845 | /* restore the previous state */ |
Mike Travis | f70316d | 2008-04-04 18:11:06 -0700 | [diff] [blame] | 846 | set_cpus_allowed_ptr(current, &saved_mask); |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 847 | |
| 848 | return ret; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 849 | } |
| 850 | |
Zhao Yakui | 22cc501 | 2007-11-15 17:02:03 +0800 | [diff] [blame] | 851 | static int acpi_processor_get_fadt_info(struct acpi_processor *pr) |
| 852 | { |
| 853 | int i, step; |
| 854 | |
| 855 | if (!pr->throttling.address) { |
| 856 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n")); |
| 857 | return -EINVAL; |
| 858 | } else if (!pr->throttling.duty_width) { |
| 859 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n")); |
| 860 | return -EINVAL; |
| 861 | } |
| 862 | /* TBD: Support duty_cycle values that span bit 4. */ |
| 863 | else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) { |
| 864 | printk(KERN_WARNING PREFIX "duty_cycle spans bit 4\n"); |
| 865 | return -EINVAL; |
| 866 | } |
| 867 | |
| 868 | pr->throttling.state_count = 1 << acpi_gbl_FADT.duty_width; |
| 869 | |
| 870 | /* |
| 871 | * Compute state values. Note that throttling displays a linear power |
| 872 | * performance relationship (at 50% performance the CPU will consume |
| 873 | * 50% power). Values are in 1/10th of a percent to preserve accuracy. |
| 874 | */ |
| 875 | |
| 876 | step = (1000 / pr->throttling.state_count); |
| 877 | |
| 878 | for (i = 0; i < pr->throttling.state_count; i++) { |
| 879 | pr->throttling.states[i].performance = 1000 - step * i; |
| 880 | pr->throttling.states[i].power = 1000 - step * i; |
| 881 | } |
| 882 | return 0; |
| 883 | } |
| 884 | |
Adrian Bunk | 6c5cf8a | 2007-07-03 00:53:12 -0400 | [diff] [blame] | 885 | static int acpi_processor_set_throttling_fadt(struct acpi_processor *pr, |
| 886 | int state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 888 | u32 value = 0; |
| 889 | u32 duty_mask = 0; |
| 890 | u32 duty_value = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 893 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
| 895 | if ((state < 0) || (state > (pr->throttling.state_count - 1))) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 896 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
| 898 | if (!pr->flags.throttling) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 899 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
| 901 | if (state == pr->throttling.state) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 902 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 904 | if (state < pr->throttling_platform_limit) |
| 905 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | /* |
| 907 | * Calculate the duty_value and duty_mask. |
| 908 | */ |
| 909 | if (state) { |
| 910 | duty_value = pr->throttling.state_count - state; |
| 911 | |
| 912 | duty_value <<= pr->throttling.duty_offset; |
| 913 | |
| 914 | /* Used to clear all duty_value bits */ |
| 915 | duty_mask = pr->throttling.state_count - 1; |
| 916 | |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 917 | duty_mask <<= acpi_gbl_FADT.duty_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | duty_mask = ~duty_mask; |
| 919 | } |
| 920 | |
| 921 | local_irq_disable(); |
| 922 | |
| 923 | /* |
| 924 | * Disable throttling by writing a 0 to bit 4. Note that we must |
| 925 | * turn it off before you can change the duty_value. |
| 926 | */ |
| 927 | value = inl(pr->throttling.address); |
| 928 | if (value & 0x10) { |
| 929 | value &= 0xFFFFFFEF; |
| 930 | outl(value, pr->throttling.address); |
| 931 | } |
| 932 | |
| 933 | /* |
| 934 | * Write the new duty_value and then enable throttling. Note |
| 935 | * that a state value of 0 leaves throttling disabled. |
| 936 | */ |
| 937 | if (state) { |
| 938 | value &= duty_mask; |
| 939 | value |= duty_value; |
| 940 | outl(value, pr->throttling.address); |
| 941 | |
| 942 | value |= 0x00000010; |
| 943 | outl(value, pr->throttling.address); |
| 944 | } |
| 945 | |
| 946 | pr->throttling.state = state; |
| 947 | |
| 948 | local_irq_enable(); |
| 949 | |
| 950 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 951 | "Throttling state set to T%d (%d%%)\n", state, |
| 952 | (pr->throttling.states[state].performance ? pr-> |
| 953 | throttling.states[state].performance / 10 : 0))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 955 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | } |
| 957 | |
Adrian Bunk | 6c5cf8a | 2007-07-03 00:53:12 -0400 | [diff] [blame] | 958 | static int acpi_processor_set_throttling_ptc(struct acpi_processor *pr, |
| 959 | int state) |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 960 | { |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 961 | int ret; |
| 962 | acpi_integer value; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 963 | |
| 964 | if (!pr) |
| 965 | return -EINVAL; |
| 966 | |
| 967 | if ((state < 0) || (state > (pr->throttling.state_count - 1))) |
| 968 | return -EINVAL; |
| 969 | |
| 970 | if (!pr->flags.throttling) |
| 971 | return -ENODEV; |
| 972 | |
| 973 | if (state == pr->throttling.state) |
| 974 | return 0; |
| 975 | |
| 976 | if (state < pr->throttling_platform_limit) |
| 977 | return -EPERM; |
| 978 | |
Zhao Yakui | 0753f6e | 2007-11-15 17:03:46 +0800 | [diff] [blame] | 979 | value = 0; |
| 980 | ret = acpi_get_throttling_value(pr, state, &value); |
| 981 | if (ret >= 0) { |
| 982 | acpi_write_throttling_state(pr, value); |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 983 | pr->throttling.state = state; |
| 984 | } |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 985 | |
| 986 | return 0; |
| 987 | } |
| 988 | |
| 989 | int acpi_processor_set_throttling(struct acpi_processor *pr, int state) |
| 990 | { |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 991 | cpumask_t saved_mask; |
Mike Travis | 65c0118 | 2008-07-15 14:14:30 -0700 | [diff] [blame] | 992 | cpumask_of_cpu_ptr_declare(new_mask); |
Len Brown | 3391a76 | 2008-02-02 03:56:18 -0500 | [diff] [blame] | 993 | int ret = 0; |
Zhao Yakui | 33a2a52 | 2008-01-28 13:55:56 +0800 | [diff] [blame] | 994 | unsigned int i; |
| 995 | struct acpi_processor *match_pr; |
| 996 | struct acpi_processor_throttling *p_throttling; |
| 997 | struct throttling_tstate t_state; |
| 998 | cpumask_t online_throttling_cpus; |
Zhao Yakui | 8765427 | 2008-01-28 13:53:30 +0800 | [diff] [blame] | 999 | |
| 1000 | if (!pr) |
| 1001 | return -EINVAL; |
| 1002 | |
| 1003 | if (!pr->flags.throttling) |
| 1004 | return -ENODEV; |
| 1005 | |
| 1006 | if ((state < 0) || (state > (pr->throttling.state_count - 1))) |
| 1007 | return -EINVAL; |
| 1008 | |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 1009 | saved_mask = current->cpus_allowed; |
Zhao Yakui | 33a2a52 | 2008-01-28 13:55:56 +0800 | [diff] [blame] | 1010 | t_state.target_state = state; |
| 1011 | p_throttling = &(pr->throttling); |
| 1012 | cpus_and(online_throttling_cpus, cpu_online_map, |
| 1013 | p_throttling->shared_cpu_map); |
| 1014 | /* |
| 1015 | * The throttling notifier will be called for every |
| 1016 | * affected cpu in order to get one proper T-state. |
| 1017 | * The notifier event is THROTTLING_PRECHANGE. |
| 1018 | */ |
Mike Travis | 141ad06 | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 1019 | for_each_cpu_mask_nr(i, online_throttling_cpus) { |
Zhao Yakui | 33a2a52 | 2008-01-28 13:55:56 +0800 | [diff] [blame] | 1020 | t_state.cpu = i; |
| 1021 | acpi_processor_throttling_notifier(THROTTLING_PRECHANGE, |
| 1022 | &t_state); |
| 1023 | } |
| 1024 | /* |
| 1025 | * The function of acpi_processor_set_throttling will be called |
| 1026 | * to switch T-state. If the coordination type is SW_ALL or HW_ALL, |
| 1027 | * it is necessary to call it for every affected cpu. Otherwise |
| 1028 | * it can be called only for the cpu pointed by pr. |
| 1029 | */ |
| 1030 | if (p_throttling->shared_type == DOMAIN_COORD_TYPE_SW_ANY) { |
Mike Travis | 65c0118 | 2008-07-15 14:14:30 -0700 | [diff] [blame] | 1031 | cpumask_of_cpu_ptr_next(new_mask, pr->id); |
| 1032 | set_cpus_allowed_ptr(current, new_mask); |
Zhao Yakui | 33a2a52 | 2008-01-28 13:55:56 +0800 | [diff] [blame] | 1033 | ret = p_throttling->acpi_processor_set_throttling(pr, |
| 1034 | t_state.target_state); |
| 1035 | } else { |
| 1036 | /* |
| 1037 | * When the T-state coordination is SW_ALL or HW_ALL, |
| 1038 | * it is necessary to set T-state for every affected |
| 1039 | * cpus. |
| 1040 | */ |
Mike Travis | 141ad06 | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 1041 | for_each_cpu_mask_nr(i, online_throttling_cpus) { |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 1042 | match_pr = per_cpu(processors, i); |
Zhao Yakui | 33a2a52 | 2008-01-28 13:55:56 +0800 | [diff] [blame] | 1043 | /* |
| 1044 | * If the pointer is invalid, we will report the |
| 1045 | * error message and continue. |
| 1046 | */ |
| 1047 | if (!match_pr) { |
| 1048 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 1049 | "Invalid Pointer for CPU %d\n", i)); |
| 1050 | continue; |
| 1051 | } |
| 1052 | /* |
| 1053 | * If the throttling control is unsupported on CPU i, |
| 1054 | * we will report the error message and continue. |
| 1055 | */ |
| 1056 | if (!match_pr->flags.throttling) { |
| 1057 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 1058 | "Throttling Controll is unsupported " |
| 1059 | "on CPU %d\n", i)); |
| 1060 | continue; |
| 1061 | } |
| 1062 | t_state.cpu = i; |
Mike Travis | 65c0118 | 2008-07-15 14:14:30 -0700 | [diff] [blame] | 1063 | cpumask_of_cpu_ptr_next(new_mask, i); |
| 1064 | set_cpus_allowed_ptr(current, new_mask); |
Zhao Yakui | 33a2a52 | 2008-01-28 13:55:56 +0800 | [diff] [blame] | 1065 | ret = match_pr->throttling. |
| 1066 | acpi_processor_set_throttling( |
| 1067 | match_pr, t_state.target_state); |
| 1068 | } |
| 1069 | } |
| 1070 | /* |
| 1071 | * After the set_throttling is called, the |
| 1072 | * throttling notifier is called for every |
| 1073 | * affected cpu to update the T-states. |
| 1074 | * The notifier event is THROTTLING_POSTCHANGE |
| 1075 | */ |
Mike Travis | 141ad06 | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 1076 | for_each_cpu_mask_nr(i, online_throttling_cpus) { |
Zhao Yakui | 33a2a52 | 2008-01-28 13:55:56 +0800 | [diff] [blame] | 1077 | t_state.cpu = i; |
| 1078 | acpi_processor_throttling_notifier(THROTTLING_POSTCHANGE, |
| 1079 | &t_state); |
| 1080 | } |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 1081 | /* restore the previous state */ |
Mike Travis | f70316d | 2008-04-04 18:11:06 -0700 | [diff] [blame] | 1082 | set_cpus_allowed_ptr(current, &saved_mask); |
Zhao Yakui | 357dc4c | 2007-11-29 16:22:43 +0800 | [diff] [blame] | 1083 | return ret; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 1084 | } |
| 1085 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1086 | int acpi_processor_get_throttling_info(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1088 | int result = 0; |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 1089 | struct acpi_processor_throttling *pthrottling; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1092 | "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n", |
| 1093 | pr->throttling.address, |
| 1094 | pr->throttling.duty_offset, |
| 1095 | pr->throttling.duty_width)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
| 1097 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1098 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 1100 | /* |
| 1101 | * Evaluate _PTC, _TSS and _TPC |
| 1102 | * They must all be present or none of them can be used. |
| 1103 | */ |
| 1104 | if (acpi_processor_get_throttling_control(pr) || |
| 1105 | acpi_processor_get_throttling_states(pr) || |
| 1106 | acpi_processor_get_platform_limit(pr)) |
| 1107 | { |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 1108 | pr->throttling.acpi_processor_get_throttling = |
| 1109 | &acpi_processor_get_throttling_fadt; |
| 1110 | pr->throttling.acpi_processor_set_throttling = |
| 1111 | &acpi_processor_set_throttling_fadt; |
Alexey Starikovskiy | d1154be | 2008-01-15 00:47:47 -0500 | [diff] [blame] | 1112 | if (acpi_processor_get_fadt_info(pr)) |
| 1113 | return 0; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 1114 | } else { |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 1115 | pr->throttling.acpi_processor_get_throttling = |
| 1116 | &acpi_processor_get_throttling_ptc; |
| 1117 | pr->throttling.acpi_processor_set_throttling = |
| 1118 | &acpi_processor_set_throttling_ptc; |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 1119 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | |
Zhao Yakui | 1180509 | 2008-01-28 13:53:42 +0800 | [diff] [blame] | 1121 | /* |
| 1122 | * If TSD package for one CPU can't be parsed successfully, it means |
| 1123 | * that this CPU will have no coordination with other CPUs. |
| 1124 | */ |
| 1125 | if (acpi_processor_get_tsd(pr)) { |
| 1126 | pthrottling = &pr->throttling; |
| 1127 | pthrottling->tsd_valid_flag = 0; |
| 1128 | cpu_set(pr->id, pthrottling->shared_cpu_map); |
| 1129 | pthrottling->shared_type = DOMAIN_COORD_TYPE_SW_ALL; |
| 1130 | } |
Len Brown | c30c620 | 2007-07-25 00:57:46 -0400 | [diff] [blame] | 1131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | /* |
| 1133 | * PIIX4 Errata: We don't support throttling on the original PIIX4. |
| 1134 | * This shouldn't be an issue as few (if any) mobile systems ever |
| 1135 | * used this part. |
| 1136 | */ |
| 1137 | if (errata.piix4.throttle) { |
| 1138 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1139 | "Throttling not supported on PIIX4 A- or B-step\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1140 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1144 | pr->throttling.state_count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | |
| 1146 | pr->flags.throttling = 1; |
| 1147 | |
| 1148 | /* |
| 1149 | * Disable throttling (if enabled). We'll let subsequent policy (e.g. |
| 1150 | * thermal) decide to lower performance if it so chooses, but for now |
| 1151 | * we'll crank up the speed. |
| 1152 | */ |
| 1153 | |
| 1154 | result = acpi_processor_get_throttling(pr); |
| 1155 | if (result) |
| 1156 | goto end; |
| 1157 | |
| 1158 | if (pr->throttling.state) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1159 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 1160 | "Disabling throttling (was T%d)\n", |
| 1161 | pr->throttling.state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | result = acpi_processor_set_throttling(pr, 0); |
| 1163 | if (result) |
| 1164 | goto end; |
| 1165 | } |
| 1166 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1167 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | if (result) |
| 1169 | pr->flags.throttling = 0; |
| 1170 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1171 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | /* proc interface */ |
| 1175 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1176 | static int acpi_processor_throttling_seq_show(struct seq_file *seq, |
| 1177 | void *offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1179 | struct acpi_processor *pr = seq->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1180 | int i = 0; |
| 1181 | int result = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | if (!pr) |
| 1184 | goto end; |
| 1185 | |
| 1186 | if (!(pr->throttling.state_count > 0)) { |
| 1187 | seq_puts(seq, "<not supported>\n"); |
| 1188 | goto end; |
| 1189 | } |
| 1190 | |
| 1191 | result = acpi_processor_get_throttling(pr); |
| 1192 | |
| 1193 | if (result) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1194 | seq_puts(seq, |
| 1195 | "Could not determine current throttling state.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | goto end; |
| 1197 | } |
| 1198 | |
| 1199 | seq_printf(seq, "state count: %d\n" |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 1200 | "active state: T%d\n" |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 1201 | "state available: T%d to T%d\n", |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 1202 | pr->throttling.state_count, pr->throttling.state, |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 1203 | pr->throttling_platform_limit, |
| 1204 | pr->throttling.state_count - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | |
| 1206 | seq_puts(seq, "states:\n"); |
Luming Yu | 3cc2649 | 2007-07-23 12:39:28 -0400 | [diff] [blame] | 1207 | if (pr->throttling.acpi_processor_get_throttling == |
| 1208 | acpi_processor_get_throttling_fadt) { |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 1209 | for (i = 0; i < pr->throttling.state_count; i++) |
| 1210 | seq_printf(seq, " %cT%d: %02d%%\n", |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 1211 | (i == pr->throttling.state ? '*' : ' '), i, |
| 1212 | (pr->throttling.states[i].performance ? pr-> |
| 1213 | throttling.states[i].performance / 10 : 0)); |
Luming Yu | 3cc2649 | 2007-07-23 12:39:28 -0400 | [diff] [blame] | 1214 | } else { |
Luming Yu | 01854e6 | 2007-05-26 22:49:58 +0800 | [diff] [blame] | 1215 | for (i = 0; i < pr->throttling.state_count; i++) |
| 1216 | seq_printf(seq, " %cT%d: %02d%%\n", |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 1217 | (i == pr->throttling.state ? '*' : ' '), i, |
| 1218 | (int)pr->throttling.states_tss[i]. |
| 1219 | freqpercentage); |
Luming Yu | 3cc2649 | 2007-07-23 12:39:28 -0400 | [diff] [blame] | 1220 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1222 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1223 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1226 | static int acpi_processor_throttling_open_fs(struct inode *inode, |
| 1227 | struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | { |
| 1229 | return single_open(file, acpi_processor_throttling_seq_show, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1230 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
Len Brown | ff55a9c | 2007-06-02 00:15:25 -0400 | [diff] [blame] | 1233 | static ssize_t acpi_processor_write_throttling(struct file *file, |
Adrian Bunk | 757b186 | 2006-01-07 13:19:00 -0500 | [diff] [blame] | 1234 | const char __user * buffer, |
| 1235 | size_t count, loff_t * data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1237 | int result = 0; |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 1238 | struct seq_file *m = file->private_data; |
| 1239 | struct acpi_processor *pr = m->private; |
Yi Yang | 3d532d5 | 2008-06-14 00:54:37 -0400 | [diff] [blame] | 1240 | char state_string[5] = ""; |
| 1241 | char *charp = NULL; |
| 1242 | size_t state_val = 0; |
| 1243 | char tmpbuf[5] = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | if (!pr || (count > sizeof(state_string) - 1)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1246 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | |
| 1248 | if (copy_from_user(state_string, buffer, count)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1249 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | |
| 1251 | state_string[count] = '\0'; |
Yi Yang | 3d532d5 | 2008-06-14 00:54:37 -0400 | [diff] [blame] | 1252 | if ((count > 0) && (state_string[count-1] == '\n')) |
| 1253 | state_string[count-1] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
Yi Yang | 3d532d5 | 2008-06-14 00:54:37 -0400 | [diff] [blame] | 1255 | charp = state_string; |
| 1256 | if ((state_string[0] == 't') || (state_string[0] == 'T')) |
| 1257 | charp++; |
| 1258 | |
| 1259 | state_val = simple_strtoul(charp, NULL, 0); |
| 1260 | if (state_val >= pr->throttling.state_count) |
| 1261 | return -EINVAL; |
| 1262 | |
Randy Dunlap | 12b2b34 | 2008-06-17 09:43:41 -0700 | [diff] [blame] | 1263 | snprintf(tmpbuf, 5, "%zu", state_val); |
Yi Yang | 3d532d5 | 2008-06-14 00:54:37 -0400 | [diff] [blame] | 1264 | |
| 1265 | if (strcmp(tmpbuf, charp) != 0) |
| 1266 | return -EINVAL; |
| 1267 | |
| 1268 | result = acpi_processor_set_throttling(pr, state_val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1270 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 1272 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | struct file_operations acpi_processor_throttling_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 1276 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1277 | .open = acpi_processor_throttling_open_fs, |
| 1278 | .read = seq_read, |
Arjan van de Ven | d479e90 | 2006-01-06 16:47:00 -0500 | [diff] [blame] | 1279 | .write = acpi_processor_write_throttling, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1280 | .llseek = seq_lseek, |
| 1281 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | }; |