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