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