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