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