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