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