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