| 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> | 
 | 32 | #include <linux/cpufreq.h> | 
 | 33 | #include <linux/proc_fs.h> | 
 | 34 | #include <linux/seq_file.h> | 
 | 35 |  | 
 | 36 | #include <asm/io.h> | 
 | 37 | #include <asm/uaccess.h> | 
 | 38 |  | 
 | 39 | #include <acpi/acpi_bus.h> | 
 | 40 | #include <acpi/processor.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 | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 46 | ACPI_MODULE_NAME("acpi_processor") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 |  | 
 | 48 | /* -------------------------------------------------------------------------- | 
 | 49 |                               Throttling Control | 
 | 50 |    -------------------------------------------------------------------------- */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | static int acpi_processor_get_throttling(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 state = 0; | 
 | 54 | 	u32 value = 0; | 
 | 55 | 	u32 duty_mask = 0; | 
 | 56 | 	u32 duty_value = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 |  | 
 | 59 | 	if (!pr) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 60 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 |  | 
 | 62 | 	if (!pr->flags.throttling) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 63 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 |  | 
 | 65 | 	pr->throttling.state = 0; | 
 | 66 |  | 
 | 67 | 	duty_mask = pr->throttling.state_count - 1; | 
 | 68 |  | 
 | 69 | 	duty_mask <<= pr->throttling.duty_offset; | 
 | 70 |  | 
 | 71 | 	local_irq_disable(); | 
 | 72 |  | 
 | 73 | 	value = inl(pr->throttling.address); | 
 | 74 |  | 
 | 75 | 	/* | 
 | 76 | 	 * Compute the current throttling state when throttling is enabled | 
 | 77 | 	 * (bit 4 is on). | 
 | 78 | 	 */ | 
 | 79 | 	if (value & 0x10) { | 
 | 80 | 		duty_value = value & duty_mask; | 
 | 81 | 		duty_value >>= pr->throttling.duty_offset; | 
 | 82 |  | 
 | 83 | 		if (duty_value) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | 			state = pr->throttling.state_count - duty_value; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | 	} | 
 | 86 |  | 
 | 87 | 	pr->throttling.state = state; | 
 | 88 |  | 
 | 89 | 	local_irq_enable(); | 
 | 90 |  | 
 | 91 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | 			  "Throttling state is T%d (%d%% throttling applied)\n", | 
 | 93 | 			  state, pr->throttling.states[state].performance)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 95 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } | 
 | 97 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | int acpi_processor_set_throttling(struct acpi_processor *pr, int state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 100 | 	u32 value = 0; | 
 | 101 | 	u32 duty_mask = 0; | 
 | 102 | 	u32 duty_value = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 |  | 
 | 105 | 	if (!pr) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 106 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 |  | 
 | 108 | 	if ((state < 0) || (state > (pr->throttling.state_count - 1))) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 109 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 |  | 
 | 111 | 	if (!pr->flags.throttling) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 112 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 |  | 
 | 114 | 	if (state == pr->throttling.state) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 115 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 |  | 
 | 117 | 	/* | 
 | 118 | 	 * Calculate the duty_value and duty_mask. | 
 | 119 | 	 */ | 
 | 120 | 	if (state) { | 
 | 121 | 		duty_value = pr->throttling.state_count - state; | 
 | 122 |  | 
 | 123 | 		duty_value <<= pr->throttling.duty_offset; | 
 | 124 |  | 
 | 125 | 		/* Used to clear all duty_value bits */ | 
 | 126 | 		duty_mask = pr->throttling.state_count - 1; | 
 | 127 |  | 
 | 128 | 		duty_mask <<= acpi_fadt.duty_offset; | 
 | 129 | 		duty_mask = ~duty_mask; | 
 | 130 | 	} | 
 | 131 |  | 
 | 132 | 	local_irq_disable(); | 
 | 133 |  | 
 | 134 | 	/* | 
 | 135 | 	 * Disable throttling by writing a 0 to bit 4.  Note that we must | 
 | 136 | 	 * turn it off before you can change the duty_value. | 
 | 137 | 	 */ | 
 | 138 | 	value = inl(pr->throttling.address); | 
 | 139 | 	if (value & 0x10) { | 
 | 140 | 		value &= 0xFFFFFFEF; | 
 | 141 | 		outl(value, pr->throttling.address); | 
 | 142 | 	} | 
 | 143 |  | 
 | 144 | 	/* | 
 | 145 | 	 * Write the new duty_value and then enable throttling.  Note | 
 | 146 | 	 * that a state value of 0 leaves throttling disabled. | 
 | 147 | 	 */ | 
 | 148 | 	if (state) { | 
 | 149 | 		value &= duty_mask; | 
 | 150 | 		value |= duty_value; | 
 | 151 | 		outl(value, pr->throttling.address); | 
 | 152 |  | 
 | 153 | 		value |= 0x00000010; | 
 | 154 | 		outl(value, pr->throttling.address); | 
 | 155 | 	} | 
 | 156 |  | 
 | 157 | 	pr->throttling.state = state; | 
 | 158 |  | 
 | 159 | 	local_irq_enable(); | 
 | 160 |  | 
 | 161 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | 			  "Throttling state set to T%d (%d%%)\n", state, | 
 | 163 | 			  (pr->throttling.states[state].performance ? pr-> | 
 | 164 | 			   throttling.states[state].performance / 10 : 0))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 166 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } | 
 | 168 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 169 | int acpi_processor_get_throttling_info(struct acpi_processor *pr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | 	int result = 0; | 
 | 172 | 	int step = 0; | 
 | 173 | 	int i = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 |  | 
 | 176 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | 			  "pblk_address[0x%08x] duty_offset[%d] duty_width[%d]\n", | 
 | 178 | 			  pr->throttling.address, | 
 | 179 | 			  pr->throttling.duty_offset, | 
 | 180 | 			  pr->throttling.duty_width)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 |  | 
 | 182 | 	if (!pr) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 183 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 |  | 
 | 185 | 	/* TBD: Support ACPI 2.0 objects */ | 
 | 186 |  | 
 | 187 | 	if (!pr->throttling.address) { | 
 | 188 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling register\n")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 189 | 		return 0; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 190 | 	} else if (!pr->throttling.duty_width) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No throttling states\n")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 192 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | 	} | 
 | 194 | 	/* TBD: Support duty_cycle values that span bit 4. */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | 	else if ((pr->throttling.duty_offset + pr->throttling.duty_width) > 4) { | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 196 | 		printk(KERN_WARNING PREFIX "duty_cycle spans bit 4\n"); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 197 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | 	} | 
 | 199 |  | 
 | 200 | 	/* | 
 | 201 | 	 * PIIX4 Errata: We don't support throttling on the original PIIX4. | 
 | 202 | 	 * This shouldn't be an issue as few (if any) mobile systems ever | 
 | 203 | 	 * used this part. | 
 | 204 | 	 */ | 
 | 205 | 	if (errata.piix4.throttle) { | 
 | 206 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 207 | 				  "Throttling not supported on PIIX4 A- or B-step\n")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 208 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | 	} | 
 | 210 |  | 
 | 211 | 	pr->throttling.state_count = 1 << acpi_fadt.duty_width; | 
 | 212 |  | 
 | 213 | 	/* | 
 | 214 | 	 * Compute state values. Note that throttling displays a linear power/ | 
 | 215 | 	 * performance relationship (at 50% performance the CPU will consume | 
 | 216 | 	 * 50% power).  Values are in 1/10th of a percent to preserve accuracy. | 
 | 217 | 	 */ | 
 | 218 |  | 
 | 219 | 	step = (1000 / pr->throttling.state_count); | 
 | 220 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 221 | 	for (i = 0; i < pr->throttling.state_count; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | 		pr->throttling.states[i].performance = step * i; | 
 | 223 | 		pr->throttling.states[i].power = step * i; | 
 | 224 | 	} | 
 | 225 |  | 
 | 226 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d throttling states\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 227 | 			  pr->throttling.state_count)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 |  | 
 | 229 | 	pr->flags.throttling = 1; | 
 | 230 |  | 
 | 231 | 	/* | 
 | 232 | 	 * Disable throttling (if enabled).  We'll let subsequent policy (e.g. | 
 | 233 | 	 * thermal) decide to lower performance if it so chooses, but for now | 
 | 234 | 	 * we'll crank up the speed. | 
 | 235 | 	 */ | 
 | 236 |  | 
 | 237 | 	result = acpi_processor_get_throttling(pr); | 
 | 238 | 	if (result) | 
 | 239 | 		goto end; | 
 | 240 |  | 
 | 241 | 	if (pr->throttling.state) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | 		ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 243 | 				  "Disabling throttling (was T%d)\n", | 
 | 244 | 				  pr->throttling.state)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | 		result = acpi_processor_set_throttling(pr, 0); | 
 | 246 | 		if (result) | 
 | 247 | 			goto end; | 
 | 248 | 	} | 
 | 249 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 |       end: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | 	if (result) | 
 | 252 | 		pr->flags.throttling = 0; | 
 | 253 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 254 | 	return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } | 
 | 256 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | /* proc interface */ | 
 | 258 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | static int acpi_processor_throttling_seq_show(struct seq_file *seq, | 
 | 260 | 					      void *offset) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 262 | 	struct acpi_processor *pr = (struct acpi_processor *)seq->private; | 
 | 263 | 	int i = 0; | 
 | 264 | 	int result = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 |  | 
 | 267 | 	if (!pr) | 
 | 268 | 		goto end; | 
 | 269 |  | 
 | 270 | 	if (!(pr->throttling.state_count > 0)) { | 
 | 271 | 		seq_puts(seq, "<not supported>\n"); | 
 | 272 | 		goto end; | 
 | 273 | 	} | 
 | 274 |  | 
 | 275 | 	result = acpi_processor_get_throttling(pr); | 
 | 276 |  | 
 | 277 | 	if (result) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 278 | 		seq_puts(seq, | 
 | 279 | 			 "Could not determine current throttling state.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | 		goto end; | 
 | 281 | 	} | 
 | 282 |  | 
 | 283 | 	seq_printf(seq, "state count:             %d\n" | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | 		   "active state:            T%d\n", | 
 | 285 | 		   pr->throttling.state_count, pr->throttling.state); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 |  | 
 | 287 | 	seq_puts(seq, "states:\n"); | 
 | 288 | 	for (i = 0; i < pr->throttling.state_count; i++) | 
 | 289 | 		seq_printf(seq, "   %cT%d:                  %02d%%\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 290 | 			   (i == pr->throttling.state ? '*' : ' '), i, | 
 | 291 | 			   (pr->throttling.states[i].performance ? pr-> | 
 | 292 | 			    throttling.states[i].performance / 10 : 0)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 |       end: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 295 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | } | 
 | 297 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | static int acpi_processor_throttling_open_fs(struct inode *inode, | 
 | 299 | 					     struct file *file) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | { | 
 | 301 | 	return single_open(file, acpi_processor_throttling_seq_show, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 302 | 			   PDE(inode)->data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } | 
 | 304 |  | 
| Adrian Bunk | 757b186 | 2006-01-07 13:19:00 -0500 | [diff] [blame] | 305 | static ssize_t acpi_processor_write_throttling(struct file * file, | 
 | 306 | 					       const char __user * buffer, | 
 | 307 | 					       size_t count, loff_t * data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 309 | 	int result = 0; | 
 | 310 | 	struct seq_file *m = (struct seq_file *)file->private_data; | 
 | 311 | 	struct acpi_processor *pr = (struct acpi_processor *)m->private; | 
 | 312 | 	char state_string[12] = { '\0' }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 |  | 
 | 315 | 	if (!pr || (count > sizeof(state_string) - 1)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 316 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 |  | 
 | 318 | 	if (copy_from_user(state_string, buffer, count)) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 319 | 		return -EFAULT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 |  | 
 | 321 | 	state_string[count] = '\0'; | 
 | 322 |  | 
 | 323 | 	result = acpi_processor_set_throttling(pr, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 324 | 					       simple_strtoul(state_string, | 
 | 325 | 							      NULL, 0)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | 	if (result) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 327 | 		return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 329 | 	return count; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } | 
 | 331 |  | 
 | 332 | struct file_operations acpi_processor_throttling_fops = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | 	.open = acpi_processor_throttling_open_fs, | 
 | 334 | 	.read = seq_read, | 
| Arjan van de Ven | d479e90 | 2006-01-06 16:47:00 -0500 | [diff] [blame] | 335 | 	.write = acpi_processor_write_throttling, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 336 | 	.llseek = seq_lseek, | 
 | 337 | 	.release = single_release, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | }; |