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> |
| 33 | #include <linux/proc_fs.h> |
| 34 | #include <linux/seq_file.h> |
| 35 | |
| 36 | #include <asm/uaccess.h> |
| 37 | |
| 38 | #include <acpi/acpi_bus.h> |
| 39 | #include <acpi/processor.h> |
| 40 | #include <acpi/acpi_drivers.h> |
| 41 | |
| 42 | #define ACPI_PROCESSOR_COMPONENT 0x01000000 |
| 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 | |
| 69 | result = acpi_processor_set_throttling(pr, tx); |
| 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 | |
| 96 | static unsigned int cpufreq_thermal_reduction_pctg[NR_CPUS]; |
| 97 | static unsigned int acpi_thermal_cpufreq_is_init = 0; |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | static int cpu_has_cpufreq(unsigned int cpu) |
| 100 | { |
| 101 | struct cpufreq_policy policy; |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 102 | if (!acpi_thermal_cpufreq_is_init || cpufreq_get_policy(&policy, cpu)) |
Thomas Renninger | 75b245b3 | 2005-12-21 01:29:00 -0500 | [diff] [blame] | 103 | return 0; |
| 104 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | static int acpi_thermal_cpufreq_increase(unsigned int cpu) |
| 108 | { |
| 109 | if (!cpu_has_cpufreq(cpu)) |
| 110 | return -ENODEV; |
| 111 | |
| 112 | if (cpufreq_thermal_reduction_pctg[cpu] < 60) { |
| 113 | cpufreq_thermal_reduction_pctg[cpu] += 20; |
| 114 | cpufreq_update_policy(cpu); |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | return -ERANGE; |
| 119 | } |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | static int acpi_thermal_cpufreq_decrease(unsigned int cpu) |
| 122 | { |
| 123 | if (!cpu_has_cpufreq(cpu)) |
| 124 | return -ENODEV; |
| 125 | |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 126 | if (cpufreq_thermal_reduction_pctg[cpu] > 20) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | cpufreq_thermal_reduction_pctg[cpu] -= 20; |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 128 | else |
| 129 | cpufreq_thermal_reduction_pctg[cpu] = 0; |
| 130 | cpufreq_update_policy(cpu); |
| 131 | /* We reached max freq again and can leave passive mode */ |
| 132 | return !cpufreq_thermal_reduction_pctg[cpu]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | static int acpi_thermal_cpufreq_notifier(struct notifier_block *nb, |
| 136 | unsigned long event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { |
| 138 | struct cpufreq_policy *policy = data; |
| 139 | unsigned long max_freq = 0; |
| 140 | |
| 141 | if (event != CPUFREQ_ADJUST) |
| 142 | goto out; |
| 143 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 144 | max_freq = |
| 145 | (policy->cpuinfo.max_freq * |
| 146 | (100 - cpufreq_thermal_reduction_pctg[policy->cpu])) / 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | cpufreq_verify_within_limits(policy, 0, max_freq); |
| 149 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | static struct notifier_block acpi_thermal_cpufreq_notifier_block = { |
| 155 | .notifier_call = acpi_thermal_cpufreq_notifier, |
| 156 | }; |
| 157 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 | void acpi_thermal_cpufreq_init(void) |
| 159 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | int i; |
| 161 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | for (i = 0; i < NR_CPUS; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | cpufreq_thermal_reduction_pctg[i] = 0; |
| 164 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | i = cpufreq_register_notifier(&acpi_thermal_cpufreq_notifier_block, |
| 166 | CPUFREQ_POLICY_NOTIFIER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | if (!i) |
| 168 | acpi_thermal_cpufreq_is_init = 1; |
| 169 | } |
| 170 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | void acpi_thermal_cpufreq_exit(void) |
| 172 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | if (acpi_thermal_cpufreq_is_init) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | cpufreq_unregister_notifier |
| 175 | (&acpi_thermal_cpufreq_notifier_block, |
| 176 | CPUFREQ_POLICY_NOTIFIER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | acpi_thermal_cpufreq_is_init = 0; |
| 179 | } |
| 180 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 181 | #else /* ! CONFIG_CPU_FREQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 183 | static int acpi_thermal_cpufreq_increase(unsigned int cpu) |
| 184 | { |
| 185 | return -ENODEV; |
| 186 | } |
| 187 | static int acpi_thermal_cpufreq_decrease(unsigned int cpu) |
| 188 | { |
| 189 | return -ENODEV; |
| 190 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | #endif |
| 193 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | int acpi_processor_set_thermal_limit(acpi_handle handle, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | int result = 0; |
| 197 | struct acpi_processor *pr = NULL; |
| 198 | struct acpi_device *device = NULL; |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 199 | int tx = 0, max_tx_px = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | if ((type < ACPI_PROCESSOR_LIMIT_NONE) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | || (type > ACPI_PROCESSOR_LIMIT_DECREMENT)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 204 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
| 206 | result = acpi_bus_get_device(handle, &device); |
| 207 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 208 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 210 | pr = acpi_driver_data(device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 212 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | /* Thermal limits are always relative to the current Px/Tx state. */ |
| 215 | if (pr->flags.throttling) |
| 216 | pr->limit.thermal.tx = pr->throttling.state; |
| 217 | |
| 218 | /* |
| 219 | * Our default policy is to only use throttling at the lowest |
| 220 | * performance state. |
| 221 | */ |
| 222 | |
| 223 | tx = pr->limit.thermal.tx; |
| 224 | |
| 225 | switch (type) { |
| 226 | |
| 227 | case ACPI_PROCESSOR_LIMIT_NONE: |
| 228 | do { |
| 229 | result = acpi_thermal_cpufreq_decrease(pr->id); |
| 230 | } while (!result); |
| 231 | tx = 0; |
| 232 | break; |
| 233 | |
| 234 | case ACPI_PROCESSOR_LIMIT_INCREMENT: |
| 235 | /* if going up: P-states first, T-states later */ |
| 236 | |
| 237 | result = acpi_thermal_cpufreq_increase(pr->id); |
| 238 | if (!result) |
| 239 | goto end; |
| 240 | else if (result == -ERANGE) |
| 241 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | "At maximum performance state\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | if (pr->flags.throttling) { |
| 245 | if (tx == (pr->throttling.state_count - 1)) |
| 246 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 247 | "At maximum throttling state\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | else |
| 249 | tx++; |
| 250 | } |
| 251 | break; |
| 252 | |
| 253 | case ACPI_PROCESSOR_LIMIT_DECREMENT: |
| 254 | /* if going down: T-states first, P-states later */ |
| 255 | |
| 256 | if (pr->flags.throttling) { |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 257 | if (tx == 0) { |
| 258 | max_tx_px = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 260 | "At minimum throttling state\n")); |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 261 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | tx--; |
| 263 | goto end; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | result = acpi_thermal_cpufreq_decrease(pr->id); |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 268 | if (result) { |
| 269 | /* |
| 270 | * We only could get -ERANGE, 1 or 0. |
| 271 | * In the first two cases we reached max freq again. |
| 272 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | "At minimum performance state\n")); |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 275 | max_tx_px = 1; |
| 276 | } else |
| 277 | max_tx_px = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | break; |
| 280 | } |
| 281 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 282 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | if (pr->flags.throttling) { |
| 284 | pr->limit.thermal.px = 0; |
| 285 | pr->limit.thermal.tx = tx; |
| 286 | |
| 287 | result = acpi_processor_apply_limit(pr); |
| 288 | if (result) |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 289 | printk(KERN_ERR PREFIX "Unable to set thermal limit\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | 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] | 292 | pr->limit.thermal.px, pr->limit.thermal.tx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } else |
| 294 | result = 0; |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 295 | if (max_tx_px) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 296 | return 1; |
Thomas Renninger | 1cbf4c5 | 2004-09-16 11:07:00 -0400 | [diff] [blame] | 297 | else |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 298 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 301 | int acpi_processor_get_limit_info(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
| 304 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 305 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
| 307 | if (pr->flags.throttling) |
| 308 | pr->flags.limit = 1; |
| 309 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 310 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | /* /proc interface */ |
| 314 | |
| 315 | static int acpi_processor_limit_seq_show(struct seq_file *seq, void *offset) |
| 316 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | struct acpi_processor *pr = (struct acpi_processor *)seq->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | if (!pr) |
| 321 | goto end; |
| 322 | |
| 323 | if (!pr->flags.limit) { |
| 324 | seq_puts(seq, "<not supported>\n"); |
| 325 | goto end; |
| 326 | } |
| 327 | |
| 328 | seq_printf(seq, "active limit: P%d:T%d\n" |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | "user limit: P%d:T%d\n" |
| 330 | "thermal limit: P%d:T%d\n", |
| 331 | pr->limit.state.px, pr->limit.state.tx, |
| 332 | pr->limit.user.px, pr->limit.user.tx, |
| 333 | pr->limit.thermal.px, pr->limit.thermal.tx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 335 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 336 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | static int acpi_processor_limit_open_fs(struct inode *inode, struct file *file) |
| 340 | { |
| 341 | return single_open(file, acpi_processor_limit_seq_show, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 342 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Adrian Bunk | 757b186 | 2006-01-07 13:19:00 -0500 | [diff] [blame] | 345 | static ssize_t acpi_processor_write_limit(struct file * file, |
| 346 | const char __user * buffer, |
| 347 | size_t count, loff_t * data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 349 | int result = 0; |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 350 | struct seq_file *m = file->private_data; |
| 351 | struct acpi_processor *pr = m->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 352 | char limit_string[25] = { '\0' }; |
| 353 | int px = 0; |
| 354 | int tx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | if (!pr || (count > sizeof(limit_string) - 1)) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 358 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | if (copy_from_user(limit_string, buffer, count)) { |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 362 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | limit_string[count] = '\0'; |
| 366 | |
| 367 | if (sscanf(limit_string, "%d:%d", &px, &tx) != 2) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 368 | printk(KERN_ERR PREFIX "Invalid data format\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 369 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | if (pr->flags.throttling) { |
| 373 | if ((tx < 0) || (tx > (pr->throttling.state_count - 1))) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 374 | printk(KERN_ERR PREFIX "Invalid tx\n"); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 375 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
| 377 | pr->limit.user.tx = tx; |
| 378 | } |
| 379 | |
| 380 | result = acpi_processor_apply_limit(pr); |
| 381 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 382 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | struct file_operations acpi_processor_limit_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | .open = acpi_processor_limit_open_fs, |
| 387 | .read = seq_read, |
Arjan van de Ven | d479e90 | 2006-01-06 16:47:00 -0500 | [diff] [blame] | 388 | .write = acpi_processor_write_limit, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 | .llseek = seq_lseek, |
| 390 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | }; |