| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * processor_thermal.c - Passive cooling 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> | 
|  | 32 | #include <linux/cpufreq.h> | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 33 | #include <linux/sysdev.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 |  | 
|  | 35 | #include <asm/uaccess.h> | 
|  | 36 |  | 
|  | 37 | #include <acpi/acpi_bus.h> | 
|  | 38 | #include <acpi/processor.h> | 
|  | 39 | #include <acpi/acpi_drivers.h> | 
|  | 40 |  | 
| Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 41 | #define PREFIX "ACPI: " | 
|  | 42 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #define ACPI_PROCESSOR_CLASS            "processor" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define _COMPONENT              ACPI_PROCESSOR_COMPONENT | 
| Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 45 | ACPI_MODULE_NAME("processor_thermal"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 |  | 
|  | 47 | /* -------------------------------------------------------------------------- | 
|  | 48 | Limit Interface | 
|  | 49 | -------------------------------------------------------------------------- */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | static int acpi_processor_apply_limit(struct acpi_processor *pr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | int result = 0; | 
|  | 53 | u16 px = 0; | 
|  | 54 | u16 tx = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 |  | 
|  | 57 | if (!pr) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 58 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 |  | 
|  | 60 | if (!pr->flags.limit) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 61 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 |  | 
|  | 63 | if (pr->flags.throttling) { | 
|  | 64 | if (pr->limit.user.tx > tx) | 
|  | 65 | tx = pr->limit.user.tx; | 
|  | 66 | if (pr->limit.thermal.tx > tx) | 
|  | 67 | tx = pr->limit.thermal.tx; | 
|  | 68 |  | 
| Frans Pop | 2a90800 | 2009-08-26 14:29:29 -0700 | [diff] [blame] | 69 | result = acpi_processor_set_throttling(pr, tx, false); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | if (result) | 
|  | 71 | goto end; | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | pr->limit.state.px = px; | 
|  | 75 | pr->limit.state.tx = tx; | 
|  | 76 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 77 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 78 | "Processor [%d] limit set to (P%d:T%d)\n", pr->id, | 
|  | 79 | pr->limit.state.px, pr->limit.state.tx)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | end: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | if (result) | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 83 | printk(KERN_ERR PREFIX "Unable to set limit\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 85 | return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } | 
|  | 87 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #ifdef CONFIG_CPU_FREQ | 
|  | 89 |  | 
|  | 90 | /* If a passive cooling situation is detected, primarily CPUfreq is used, as it | 
|  | 91 | * offers (in most cases) voltage scaling in addition to frequency scaling, and | 
|  | 92 | * thus a cubic (instead of linear) reduction of energy. Also, we allow for | 
|  | 93 | * _any_ cpufreq driver and not only the acpi-cpufreq driver. | 
|  | 94 | */ | 
|  | 95 |  | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 96 | #define CPUFREQ_THERMAL_MIN_STEP 0 | 
|  | 97 | #define CPUFREQ_THERMAL_MAX_STEP 3 | 
|  | 98 |  | 
| Mike Travis | c938ac2 | 2008-03-05 08:31:29 -0800 | [diff] [blame] | 99 | static DEFINE_PER_CPU(unsigned int, cpufreq_thermal_reduction_pctg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | static unsigned int acpi_thermal_cpufreq_is_init = 0; | 
|  | 101 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | static int cpu_has_cpufreq(unsigned int cpu) | 
|  | 103 | { | 
|  | 104 | struct cpufreq_policy policy; | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 105 | if (!acpi_thermal_cpufreq_is_init || cpufreq_get_policy(&policy, cpu)) | 
| Thomas Renninger | 75b245b3 | 2005-12-21 01:29:00 -0500 | [diff] [blame] | 106 | return 0; | 
|  | 107 | return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } | 
|  | 109 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | static int acpi_thermal_cpufreq_increase(unsigned int cpu) | 
|  | 111 | { | 
|  | 112 | if (!cpu_has_cpufreq(cpu)) | 
|  | 113 | return -ENODEV; | 
|  | 114 |  | 
| Mike Travis | c938ac2 | 2008-03-05 08:31:29 -0800 | [diff] [blame] | 115 | if (per_cpu(cpufreq_thermal_reduction_pctg, cpu) < | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 116 | CPUFREQ_THERMAL_MAX_STEP) { | 
| Mike Travis | c938ac2 | 2008-03-05 08:31:29 -0800 | [diff] [blame] | 117 | per_cpu(cpufreq_thermal_reduction_pctg, cpu)++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | cpufreq_update_policy(cpu); | 
|  | 119 | return 0; | 
|  | 120 | } | 
|  | 121 |  | 
|  | 122 | return -ERANGE; | 
|  | 123 | } | 
|  | 124 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | static int acpi_thermal_cpufreq_decrease(unsigned int cpu) | 
|  | 126 | { | 
|  | 127 | if (!cpu_has_cpufreq(cpu)) | 
|  | 128 | return -ENODEV; | 
|  | 129 |  | 
| Mike Travis | c938ac2 | 2008-03-05 08:31:29 -0800 | [diff] [blame] | 130 | if (per_cpu(cpufreq_thermal_reduction_pctg, cpu) > | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 131 | (CPUFREQ_THERMAL_MIN_STEP + 1)) | 
| Mike Travis | c938ac2 | 2008-03-05 08:31:29 -0800 | [diff] [blame] | 132 | per_cpu(cpufreq_thermal_reduction_pctg, cpu)--; | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 133 | else | 
| Mike Travis | c938ac2 | 2008-03-05 08:31:29 -0800 | [diff] [blame] | 134 | per_cpu(cpufreq_thermal_reduction_pctg, cpu) = 0; | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 135 | cpufreq_update_policy(cpu); | 
|  | 136 | /* We reached max freq again and can leave passive mode */ | 
| Mike Travis | c938ac2 | 2008-03-05 08:31:29 -0800 | [diff] [blame] | 137 | return !per_cpu(cpufreq_thermal_reduction_pctg, cpu); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } | 
|  | 139 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | static int acpi_thermal_cpufreq_notifier(struct notifier_block *nb, | 
|  | 141 | unsigned long event, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { | 
|  | 143 | struct cpufreq_policy *policy = data; | 
|  | 144 | unsigned long max_freq = 0; | 
|  | 145 |  | 
|  | 146 | if (event != CPUFREQ_ADJUST) | 
|  | 147 | goto out; | 
|  | 148 |  | 
| Mike Travis | c938ac2 | 2008-03-05 08:31:29 -0800 | [diff] [blame] | 149 | max_freq = ( | 
|  | 150 | policy->cpuinfo.max_freq * | 
|  | 151 | (100 - per_cpu(cpufreq_thermal_reduction_pctg, policy->cpu) * 20) | 
|  | 152 | ) / 100; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 |  | 
|  | 154 | cpufreq_verify_within_limits(policy, 0, max_freq); | 
|  | 155 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | out: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return 0; | 
|  | 158 | } | 
|  | 159 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | static struct notifier_block acpi_thermal_cpufreq_notifier_block = { | 
|  | 161 | .notifier_call = acpi_thermal_cpufreq_notifier, | 
|  | 162 | }; | 
|  | 163 |  | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 164 | static int cpufreq_get_max_state(unsigned int cpu) | 
|  | 165 | { | 
|  | 166 | if (!cpu_has_cpufreq(cpu)) | 
|  | 167 | return 0; | 
|  | 168 |  | 
|  | 169 | return CPUFREQ_THERMAL_MAX_STEP; | 
|  | 170 | } | 
|  | 171 |  | 
|  | 172 | static int cpufreq_get_cur_state(unsigned int cpu) | 
|  | 173 | { | 
|  | 174 | if (!cpu_has_cpufreq(cpu)) | 
|  | 175 | return 0; | 
|  | 176 |  | 
| Mike Travis | c938ac2 | 2008-03-05 08:31:29 -0800 | [diff] [blame] | 177 | return per_cpu(cpufreq_thermal_reduction_pctg, cpu); | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 178 | } | 
|  | 179 |  | 
|  | 180 | static int cpufreq_set_cur_state(unsigned int cpu, int state) | 
|  | 181 | { | 
|  | 182 | if (!cpu_has_cpufreq(cpu)) | 
|  | 183 | return 0; | 
|  | 184 |  | 
| Mike Travis | c938ac2 | 2008-03-05 08:31:29 -0800 | [diff] [blame] | 185 | per_cpu(cpufreq_thermal_reduction_pctg, cpu) = state; | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 186 | cpufreq_update_policy(cpu); | 
|  | 187 | return 0; | 
|  | 188 | } | 
|  | 189 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 190 | void acpi_thermal_cpufreq_init(void) | 
|  | 191 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | int i; | 
|  | 193 |  | 
| Mike Travis | c938ac2 | 2008-03-05 08:31:29 -0800 | [diff] [blame] | 194 | for (i = 0; i < nr_cpu_ids; i++) | 
|  | 195 | if (cpu_present(i)) | 
|  | 196 | per_cpu(cpufreq_thermal_reduction_pctg, i) = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 198 | i = cpufreq_register_notifier(&acpi_thermal_cpufreq_notifier_block, | 
|  | 199 | CPUFREQ_POLICY_NOTIFIER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | if (!i) | 
|  | 201 | acpi_thermal_cpufreq_is_init = 1; | 
|  | 202 | } | 
|  | 203 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | void acpi_thermal_cpufreq_exit(void) | 
|  | 205 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | if (acpi_thermal_cpufreq_is_init) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 207 | cpufreq_unregister_notifier | 
|  | 208 | (&acpi_thermal_cpufreq_notifier_block, | 
|  | 209 | CPUFREQ_POLICY_NOTIFIER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 |  | 
|  | 211 | acpi_thermal_cpufreq_is_init = 0; | 
|  | 212 | } | 
|  | 213 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | #else				/* ! CONFIG_CPU_FREQ */ | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 215 | static int cpufreq_get_max_state(unsigned int cpu) | 
|  | 216 | { | 
|  | 217 | return 0; | 
|  | 218 | } | 
|  | 219 |  | 
|  | 220 | static int cpufreq_get_cur_state(unsigned int cpu) | 
|  | 221 | { | 
|  | 222 | return 0; | 
|  | 223 | } | 
|  | 224 |  | 
|  | 225 | static int cpufreq_set_cur_state(unsigned int cpu, int state) | 
|  | 226 | { | 
|  | 227 | return 0; | 
|  | 228 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 230 | static int acpi_thermal_cpufreq_increase(unsigned int cpu) | 
|  | 231 | { | 
|  | 232 | return -ENODEV; | 
|  | 233 | } | 
|  | 234 | static int acpi_thermal_cpufreq_decrease(unsigned int cpu) | 
|  | 235 | { | 
|  | 236 | return -ENODEV; | 
|  | 237 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 |  | 
|  | 239 | #endif | 
|  | 240 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 241 | int acpi_processor_set_thermal_limit(acpi_handle handle, int type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | int result = 0; | 
|  | 244 | struct acpi_processor *pr = NULL; | 
|  | 245 | struct acpi_device *device = NULL; | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 246 | int tx = 0, max_tx_px = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 |  | 
|  | 249 | if ((type < ACPI_PROCESSOR_LIMIT_NONE) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | || (type > ACPI_PROCESSOR_LIMIT_DECREMENT)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 251 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 |  | 
|  | 253 | result = acpi_bus_get_device(handle, &device); | 
|  | 254 | if (result) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 255 | return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 |  | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 257 | pr = acpi_driver_data(device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | if (!pr) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 259 | return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 |  | 
|  | 261 | /* Thermal limits are always relative to the current Px/Tx state. */ | 
|  | 262 | if (pr->flags.throttling) | 
|  | 263 | pr->limit.thermal.tx = pr->throttling.state; | 
|  | 264 |  | 
|  | 265 | /* | 
|  | 266 | * Our default policy is to only use throttling at the lowest | 
|  | 267 | * performance state. | 
|  | 268 | */ | 
|  | 269 |  | 
|  | 270 | tx = pr->limit.thermal.tx; | 
|  | 271 |  | 
|  | 272 | switch (type) { | 
|  | 273 |  | 
|  | 274 | case ACPI_PROCESSOR_LIMIT_NONE: | 
|  | 275 | do { | 
|  | 276 | result = acpi_thermal_cpufreq_decrease(pr->id); | 
|  | 277 | } while (!result); | 
|  | 278 | tx = 0; | 
|  | 279 | break; | 
|  | 280 |  | 
|  | 281 | case ACPI_PROCESSOR_LIMIT_INCREMENT: | 
|  | 282 | /* if going up: P-states first, T-states later */ | 
|  | 283 |  | 
|  | 284 | result = acpi_thermal_cpufreq_increase(pr->id); | 
|  | 285 | if (!result) | 
|  | 286 | goto end; | 
|  | 287 | else if (result == -ERANGE) | 
|  | 288 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 289 | "At maximum performance state\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 |  | 
|  | 291 | if (pr->flags.throttling) { | 
|  | 292 | if (tx == (pr->throttling.state_count - 1)) | 
|  | 293 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | "At maximum throttling state\n")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | else | 
|  | 296 | tx++; | 
|  | 297 | } | 
|  | 298 | break; | 
|  | 299 |  | 
|  | 300 | case ACPI_PROCESSOR_LIMIT_DECREMENT: | 
|  | 301 | /* if going down: T-states first, P-states later */ | 
|  | 302 |  | 
|  | 303 | if (pr->flags.throttling) { | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 304 | if (tx == 0) { | 
|  | 305 | max_tx_px = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | "At minimum throttling state\n")); | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 308 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | tx--; | 
|  | 310 | goto end; | 
|  | 311 | } | 
|  | 312 | } | 
|  | 313 |  | 
|  | 314 | result = acpi_thermal_cpufreq_decrease(pr->id); | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 315 | if (result) { | 
|  | 316 | /* | 
|  | 317 | * We only could get -ERANGE, 1 or 0. | 
|  | 318 | * In the first two cases we reached max freq again. | 
|  | 319 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | "At minimum performance state\n")); | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 322 | max_tx_px = 1; | 
|  | 323 | } else | 
|  | 324 | max_tx_px = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 |  | 
|  | 326 | break; | 
|  | 327 | } | 
|  | 328 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | end: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | if (pr->flags.throttling) { | 
|  | 331 | pr->limit.thermal.px = 0; | 
|  | 332 | pr->limit.thermal.tx = tx; | 
|  | 333 |  | 
|  | 334 | result = acpi_processor_apply_limit(pr); | 
|  | 335 | if (result) | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 336 | printk(KERN_ERR PREFIX "Unable to set thermal limit\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 |  | 
|  | 338 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Thermal limit now (P%d:T%d)\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 339 | pr->limit.thermal.px, pr->limit.thermal.tx)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } else | 
|  | 341 | result = 0; | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 342 | if (max_tx_px) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 343 | return 1; | 
| Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 344 | else | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 345 | return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } | 
|  | 347 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | int acpi_processor_get_limit_info(struct acpi_processor *pr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 |  | 
|  | 351 | if (!pr) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 352 | return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 |  | 
|  | 354 | if (pr->flags.throttling) | 
|  | 355 | pr->flags.limit = 1; | 
|  | 356 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 357 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } | 
|  | 359 |  | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 360 | /* thermal coolign device callbacks */ | 
|  | 361 | static int acpi_processor_max_state(struct acpi_processor *pr) | 
|  | 362 | { | 
|  | 363 | int max_state = 0; | 
|  | 364 |  | 
|  | 365 | /* | 
|  | 366 | * There exists four states according to | 
|  | 367 | * cpufreq_thermal_reduction_ptg. 0, 1, 2, 3 | 
|  | 368 | */ | 
|  | 369 | max_state += cpufreq_get_max_state(pr->id); | 
|  | 370 | if (pr->flags.throttling) | 
|  | 371 | max_state += (pr->throttling.state_count -1); | 
|  | 372 |  | 
|  | 373 | return max_state; | 
|  | 374 | } | 
|  | 375 | static int | 
| Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 376 | processor_get_max_state(struct thermal_cooling_device *cdev, | 
|  | 377 | unsigned long *state) | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 378 | { | 
|  | 379 | struct acpi_device *device = cdev->devdata; | 
|  | 380 | struct acpi_processor *pr = acpi_driver_data(device); | 
|  | 381 |  | 
|  | 382 | if (!device || !pr) | 
|  | 383 | return -EINVAL; | 
|  | 384 |  | 
| Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 385 | *state = acpi_processor_max_state(pr); | 
|  | 386 | return 0; | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 387 | } | 
|  | 388 |  | 
|  | 389 | static int | 
| Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 390 | processor_get_cur_state(struct thermal_cooling_device *cdev, | 
|  | 391 | unsigned long *cur_state) | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 392 | { | 
|  | 393 | struct acpi_device *device = cdev->devdata; | 
|  | 394 | struct acpi_processor *pr = acpi_driver_data(device); | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 395 |  | 
|  | 396 | if (!device || !pr) | 
|  | 397 | return -EINVAL; | 
|  | 398 |  | 
| Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 399 | *cur_state = cpufreq_get_cur_state(pr->id); | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 400 | if (pr->flags.throttling) | 
| Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 401 | *cur_state += pr->throttling.state; | 
|  | 402 | return 0; | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 403 | } | 
|  | 404 |  | 
|  | 405 | static int | 
| Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 406 | processor_set_cur_state(struct thermal_cooling_device *cdev, | 
|  | 407 | unsigned long state) | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 408 | { | 
|  | 409 | struct acpi_device *device = cdev->devdata; | 
|  | 410 | struct acpi_processor *pr = acpi_driver_data(device); | 
|  | 411 | int result = 0; | 
|  | 412 | int max_pstate; | 
|  | 413 |  | 
|  | 414 | if (!device || !pr) | 
|  | 415 | return -EINVAL; | 
|  | 416 |  | 
|  | 417 | max_pstate = cpufreq_get_max_state(pr->id); | 
|  | 418 |  | 
|  | 419 | if (state > acpi_processor_max_state(pr)) | 
|  | 420 | return -EINVAL; | 
|  | 421 |  | 
|  | 422 | if (state <= max_pstate) { | 
|  | 423 | if (pr->flags.throttling && pr->throttling.state) | 
| Frans Pop | 2a90800 | 2009-08-26 14:29:29 -0700 | [diff] [blame] | 424 | result = acpi_processor_set_throttling(pr, 0, false); | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 425 | cpufreq_set_cur_state(pr->id, state); | 
|  | 426 | } else { | 
|  | 427 | cpufreq_set_cur_state(pr->id, max_pstate); | 
|  | 428 | result = acpi_processor_set_throttling(pr, | 
| Frans Pop | 2a90800 | 2009-08-26 14:29:29 -0700 | [diff] [blame] | 429 | state - max_pstate, false); | 
| Zhang Rui | d9460fd2 | 2008-01-17 15:51:23 +0800 | [diff] [blame] | 430 | } | 
|  | 431 | return result; | 
|  | 432 | } | 
|  | 433 |  | 
|  | 434 | struct thermal_cooling_device_ops processor_cooling_ops = { | 
|  | 435 | .get_max_state = processor_get_max_state, | 
|  | 436 | .get_cur_state = processor_get_cur_state, | 
|  | 437 | .set_cur_state = processor_set_cur_state, | 
|  | 438 | }; |