Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * processor_perflib.c - ACPI Processor P-States Library ($Revision: 71 $) |
| 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 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or (at |
| 16 | * your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, but |
| 19 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | * General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License along |
| 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 25 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 26 | * |
| 27 | */ |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/cpufreq.h> |
| 33 | |
| 34 | #ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF |
| 35 | #include <linux/proc_fs.h> |
| 36 | #include <linux/seq_file.h> |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 37 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #include <asm/uaccess.h> |
| 40 | #endif |
| 41 | |
| 42 | #include <acpi/acpi_bus.h> |
| 43 | #include <acpi/processor.h> |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define ACPI_PROCESSOR_COMPONENT 0x01000000 |
| 46 | #define ACPI_PROCESSOR_CLASS "processor" |
| 47 | #define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver" |
| 48 | #define ACPI_PROCESSOR_FILE_PERFORMANCE "performance" |
| 49 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("acpi_processor") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 52 | static DEFINE_MUTEX(performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * _PPC support is implemented as a CPUfreq policy notifier: |
| 56 | * This means each time a CPUfreq driver registered also with |
| 57 | * the ACPI core is asked to change the speed policy, the maximum |
| 58 | * value is adjusted so that it is within the platform limit. |
| 59 | * |
| 60 | * Also, when a new platform limit value is detected, the CPUfreq |
| 61 | * policy is adjusted accordingly. |
| 62 | */ |
| 63 | |
| 64 | #define PPC_REGISTERED 1 |
| 65 | #define PPC_IN_USE 2 |
| 66 | |
| 67 | static int acpi_processor_ppc_status = 0; |
| 68 | |
| 69 | static int acpi_processor_ppc_notifier(struct notifier_block *nb, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 70 | unsigned long event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
| 72 | struct cpufreq_policy *policy = data; |
| 73 | struct acpi_processor *pr; |
| 74 | unsigned int ppc = 0; |
| 75 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 76 | mutex_lock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | if (event != CPUFREQ_INCOMPATIBLE) |
| 79 | goto out; |
| 80 | |
| 81 | pr = processors[policy->cpu]; |
| 82 | if (!pr || !pr->performance) |
| 83 | goto out; |
| 84 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | ppc = (unsigned int)pr->performance_platform_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | if (!ppc) |
| 87 | goto out; |
| 88 | |
| 89 | if (ppc > pr->performance->state_count) |
| 90 | goto out; |
| 91 | |
| 92 | cpufreq_verify_within_limits(policy, 0, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 93 | pr->performance->states[ppc]. |
| 94 | core_frequency * 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 96 | out: |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 97 | mutex_unlock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | static struct notifier_block acpi_ppc_notifier_block = { |
| 103 | .notifier_call = acpi_processor_ppc_notifier, |
| 104 | }; |
| 105 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | static int acpi_processor_get_platform_limit(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 108 | acpi_status status = 0; |
| 109 | unsigned long ppc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | ACPI_FUNCTION_TRACE("acpi_processor_get_platform_limit"); |
| 112 | |
| 113 | if (!pr) |
| 114 | return_VALUE(-EINVAL); |
| 115 | |
| 116 | /* |
| 117 | * _PPC indicates the maximum state currently supported by the platform |
| 118 | * (e.g. 0 = states 0..n; 1 = states 1..n; etc. |
| 119 | */ |
| 120 | status = acpi_evaluate_integer(pr->handle, "_PPC", NULL, &ppc); |
| 121 | |
| 122 | if (status != AE_NOT_FOUND) |
| 123 | acpi_processor_ppc_status |= PPC_IN_USE; |
| 124 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PPC\n")); |
| 127 | return_VALUE(-ENODEV); |
| 128 | } |
| 129 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 130 | pr->performance_platform_limit = (int)ppc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | return_VALUE(0); |
| 133 | } |
| 134 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | int acpi_processor_ppc_has_changed(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
| 137 | int ret = acpi_processor_get_platform_limit(pr); |
| 138 | if (ret < 0) |
| 139 | return (ret); |
| 140 | else |
| 141 | return cpufreq_update_policy(pr->id); |
| 142 | } |
| 143 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 144 | void acpi_processor_ppc_init(void) |
| 145 | { |
| 146 | if (!cpufreq_register_notifier |
| 147 | (&acpi_ppc_notifier_block, CPUFREQ_POLICY_NOTIFIER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | acpi_processor_ppc_status |= PPC_REGISTERED; |
| 149 | else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | printk(KERN_DEBUG |
| 151 | "Warning: Processor Platform Limit not supported.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 154 | void acpi_processor_ppc_exit(void) |
| 155 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | if (acpi_processor_ppc_status & PPC_REGISTERED) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 157 | cpufreq_unregister_notifier(&acpi_ppc_notifier_block, |
| 158 | CPUFREQ_POLICY_NOTIFIER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
| 160 | acpi_processor_ppc_status &= ~PPC_REGISTERED; |
| 161 | } |
| 162 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | static int acpi_processor_get_performance_control(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 165 | int result = 0; |
| 166 | acpi_status status = 0; |
| 167 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 168 | union acpi_object *pct = NULL; |
| 169 | union acpi_object obj = { 0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
| 171 | ACPI_FUNCTION_TRACE("acpi_processor_get_performance_control"); |
| 172 | |
| 173 | status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PCT\n")); |
| 176 | return_VALUE(-ENODEV); |
| 177 | } |
| 178 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | pct = (union acpi_object *)buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | if (!pct || (pct->type != ACPI_TYPE_PACKAGE) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 181 | || (pct->package.count != 2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PCT data\n")); |
| 183 | result = -EFAULT; |
| 184 | goto end; |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * control_register |
| 189 | */ |
| 190 | |
| 191 | obj = pct->package.elements[0]; |
| 192 | |
| 193 | if ((obj.type != ACPI_TYPE_BUFFER) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | || (obj.buffer.length < sizeof(struct acpi_pct_register)) |
| 195 | || (obj.buffer.pointer == NULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | "Invalid _PCT data (control_register)\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | result = -EFAULT; |
| 199 | goto end; |
| 200 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 201 | memcpy(&pr->performance->control_register, obj.buffer.pointer, |
| 202 | sizeof(struct acpi_pct_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * status_register |
| 206 | */ |
| 207 | |
| 208 | obj = pct->package.elements[1]; |
| 209 | |
| 210 | if ((obj.type != ACPI_TYPE_BUFFER) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | || (obj.buffer.length < sizeof(struct acpi_pct_register)) |
| 212 | || (obj.buffer.pointer == NULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | "Invalid _PCT data (status_register)\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | result = -EFAULT; |
| 216 | goto end; |
| 217 | } |
| 218 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | memcpy(&pr->performance->status_register, obj.buffer.pointer, |
| 220 | sizeof(struct acpi_pct_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 222 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | acpi_os_free(buffer.pointer); |
| 224 | |
| 225 | return_VALUE(result); |
| 226 | } |
| 227 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 228 | static int acpi_processor_get_performance_states(struct acpi_processor *pr) |
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 | int result = 0; |
| 231 | acpi_status status = AE_OK; |
| 232 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 233 | struct acpi_buffer format = { sizeof("NNNNNN"), "NNNNNN" }; |
| 234 | struct acpi_buffer state = { 0, NULL }; |
| 235 | union acpi_object *pss = NULL; |
| 236 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | ACPI_FUNCTION_TRACE("acpi_processor_get_performance_states"); |
| 239 | |
| 240 | status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 241 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PSS\n")); |
| 243 | return_VALUE(-ENODEV); |
| 244 | } |
| 245 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 246 | pss = (union acpi_object *)buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) { |
| 248 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSS data\n")); |
| 249 | result = -EFAULT; |
| 250 | goto end; |
| 251 | } |
| 252 | |
| 253 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d performance states\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | pss->package.count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | pr->performance->state_count = pss->package.count; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 257 | pr->performance->states = |
| 258 | kmalloc(sizeof(struct acpi_processor_px) * pss->package.count, |
| 259 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (!pr->performance->states) { |
| 261 | result = -ENOMEM; |
| 262 | goto end; |
| 263 | } |
| 264 | |
| 265 | for (i = 0; i < pr->performance->state_count; i++) { |
| 266 | |
| 267 | struct acpi_processor_px *px = &(pr->performance->states[i]); |
| 268 | |
| 269 | state.length = sizeof(struct acpi_processor_px); |
| 270 | state.pointer = px; |
| 271 | |
| 272 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i)); |
| 273 | |
| 274 | status = acpi_extract_package(&(pss->package.elements[i]), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 275 | &format, &state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 277 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 278 | "Invalid _PSS data\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | result = -EFAULT; |
| 280 | kfree(pr->performance->states); |
| 281 | goto end; |
| 282 | } |
| 283 | |
| 284 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n", |
| 286 | i, |
| 287 | (u32) px->core_frequency, |
| 288 | (u32) px->power, |
| 289 | (u32) px->transition_latency, |
| 290 | (u32) px->bus_master_latency, |
| 291 | (u32) px->control, (u32) px->status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
| 293 | if (!px->core_frequency) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 295 | "Invalid _PSS data: freq is zero\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | result = -EFAULT; |
| 297 | kfree(pr->performance->states); |
| 298 | goto end; |
| 299 | } |
| 300 | } |
| 301 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 302 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | acpi_os_free(buffer.pointer); |
| 304 | |
| 305 | return_VALUE(result); |
| 306 | } |
| 307 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | static int acpi_processor_get_performance_info(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 310 | int result = 0; |
| 311 | acpi_status status = AE_OK; |
| 312 | acpi_handle handle = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | ACPI_FUNCTION_TRACE("acpi_processor_get_performance_info"); |
| 315 | |
| 316 | if (!pr || !pr->performance || !pr->handle) |
| 317 | return_VALUE(-EINVAL); |
| 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | status = acpi_get_handle(pr->handle, "_PCT", &handle); |
| 320 | if (ACPI_FAILURE(status)) { |
| 321 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | "ACPI-based processor performance control unavailable\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | return_VALUE(-ENODEV); |
| 324 | } |
| 325 | |
| 326 | result = acpi_processor_get_performance_control(pr); |
| 327 | if (result) |
| 328 | return_VALUE(result); |
| 329 | |
| 330 | result = acpi_processor_get_performance_states(pr); |
| 331 | if (result) |
| 332 | return_VALUE(result); |
| 333 | |
| 334 | result = acpi_processor_get_platform_limit(pr); |
| 335 | if (result) |
| 336 | return_VALUE(result); |
| 337 | |
| 338 | return_VALUE(0); |
| 339 | } |
| 340 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 341 | int acpi_processor_notify_smm(struct module *calling_module) |
| 342 | { |
| 343 | acpi_status status; |
| 344 | static int is_done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | ACPI_FUNCTION_TRACE("acpi_processor_notify_smm"); |
| 347 | |
| 348 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) |
| 349 | return_VALUE(-EBUSY); |
| 350 | |
| 351 | if (!try_module_get(calling_module)) |
| 352 | return_VALUE(-EINVAL); |
| 353 | |
| 354 | /* is_done is set to negative if an error occured, |
| 355 | * and to postitive if _no_ error occured, but SMM |
| 356 | * was already notified. This avoids double notification |
| 357 | * which might lead to unexpected results... |
| 358 | */ |
| 359 | if (is_done > 0) { |
| 360 | module_put(calling_module); |
| 361 | return_VALUE(0); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 362 | } else if (is_done < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | module_put(calling_module); |
| 364 | return_VALUE(is_done); |
| 365 | } |
| 366 | |
| 367 | is_done = -EIO; |
| 368 | |
| 369 | /* Can't write pstate_cnt to smi_cmd if either value is zero */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 370 | if ((!acpi_fadt.smi_cmd) || (!acpi_fadt.pstate_cnt)) { |
| 371 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_cnt\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | module_put(calling_module); |
| 373 | return_VALUE(0); |
| 374 | } |
| 375 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 376 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 377 | "Writing pstate_cnt [0x%x] to smi_cmd [0x%x]\n", |
| 378 | acpi_fadt.pstate_cnt, acpi_fadt.smi_cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
| 380 | /* FADT v1 doesn't support pstate_cnt, many BIOS vendors use |
| 381 | * it anyway, so we need to support it... */ |
| 382 | if (acpi_fadt_is_v1) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 383 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 384 | "Using v1.0 FADT reserved value for pstate_cnt\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 387 | status = acpi_os_write_port(acpi_fadt.smi_cmd, |
| 388 | (u32) acpi_fadt.pstate_cnt, 8); |
| 389 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 391 | "Failed to write pstate_cnt [0x%x] to " |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | "smi_cmd [0x%x]\n", acpi_fadt.pstate_cnt, |
| 393 | acpi_fadt.smi_cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | module_put(calling_module); |
| 395 | return_VALUE(status); |
| 396 | } |
| 397 | |
| 398 | /* Success. If there's no _PPC, we need to fear nothing, so |
| 399 | * we can allow the cpufreq driver to be rmmod'ed. */ |
| 400 | is_done = 1; |
| 401 | |
| 402 | if (!(acpi_processor_ppc_status & PPC_IN_USE)) |
| 403 | module_put(calling_module); |
| 404 | |
| 405 | return_VALUE(0); |
| 406 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 408 | EXPORT_SYMBOL(acpi_processor_notify_smm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
| 410 | #ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF |
| 411 | /* /proc/acpi/processor/../performance interface (DEPRECATED) */ |
| 412 | |
| 413 | static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file); |
| 414 | static struct file_operations acpi_processor_perf_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 415 | .open = acpi_processor_perf_open_fs, |
| 416 | .read = seq_read, |
| 417 | .llseek = seq_lseek, |
| 418 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | }; |
| 420 | |
| 421 | static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset) |
| 422 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 423 | struct acpi_processor *pr = (struct acpi_processor *)seq->private; |
| 424 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | ACPI_FUNCTION_TRACE("acpi_processor_perf_seq_show"); |
| 427 | |
| 428 | if (!pr) |
| 429 | goto end; |
| 430 | |
| 431 | if (!pr->performance) { |
| 432 | seq_puts(seq, "<not supported>\n"); |
| 433 | goto end; |
| 434 | } |
| 435 | |
| 436 | seq_printf(seq, "state count: %d\n" |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 437 | "active state: P%d\n", |
| 438 | pr->performance->state_count, pr->performance->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
| 440 | seq_puts(seq, "states:\n"); |
| 441 | for (i = 0; i < pr->performance->state_count; i++) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 442 | seq_printf(seq, |
| 443 | " %cP%d: %d MHz, %d mW, %d uS\n", |
| 444 | (i == pr->performance->state ? '*' : ' '), i, |
| 445 | (u32) pr->performance->states[i].core_frequency, |
| 446 | (u32) pr->performance->states[i].power, |
| 447 | (u32) pr->performance->states[i].transition_latency); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 449 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | return_VALUE(0); |
| 451 | } |
| 452 | |
| 453 | static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file) |
| 454 | { |
| 455 | return single_open(file, acpi_processor_perf_seq_show, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 456 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 460 | acpi_processor_write_performance(struct file *file, |
| 461 | const char __user * buffer, |
| 462 | size_t count, loff_t * data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 464 | int result = 0; |
| 465 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 466 | struct acpi_processor *pr = (struct acpi_processor *)m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | struct acpi_processor_performance *perf; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | char state_string[12] = { '\0' }; |
| 469 | unsigned int new_state = 0; |
| 470 | struct cpufreq_policy policy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
| 472 | ACPI_FUNCTION_TRACE("acpi_processor_write_performance"); |
| 473 | |
| 474 | if (!pr || (count > sizeof(state_string) - 1)) |
| 475 | return_VALUE(-EINVAL); |
| 476 | |
| 477 | perf = pr->performance; |
| 478 | if (!perf) |
| 479 | return_VALUE(-EINVAL); |
| 480 | |
| 481 | if (copy_from_user(state_string, buffer, count)) |
| 482 | return_VALUE(-EFAULT); |
| 483 | |
| 484 | state_string[count] = '\0'; |
| 485 | new_state = simple_strtoul(state_string, NULL, 0); |
| 486 | |
| 487 | if (new_state >= perf->state_count) |
| 488 | return_VALUE(-EINVAL); |
| 489 | |
| 490 | cpufreq_get_policy(&policy, pr->id); |
| 491 | |
| 492 | policy.cpu = pr->id; |
| 493 | policy.min = perf->states[new_state].core_frequency * 1000; |
| 494 | policy.max = perf->states[new_state].core_frequency * 1000; |
| 495 | |
| 496 | result = cpufreq_set_policy(&policy); |
| 497 | if (result) |
| 498 | return_VALUE(result); |
| 499 | |
| 500 | return_VALUE(count); |
| 501 | } |
| 502 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 503 | static void acpi_cpufreq_add_file(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 505 | struct proc_dir_entry *entry = NULL; |
| 506 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
| 508 | ACPI_FUNCTION_TRACE("acpi_cpufreq_addfile"); |
| 509 | |
| 510 | if (acpi_bus_get_device(pr->handle, &device)) |
| 511 | return_VOID; |
| 512 | |
| 513 | /* add file 'performance' [R/W] */ |
| 514 | entry = create_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 515 | S_IFREG | S_IRUGO | S_IWUSR, |
| 516 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | if (!entry) |
| 518 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 519 | "Unable to create '%s' fs entry\n", |
| 520 | ACPI_PROCESSOR_FILE_PERFORMANCE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | else { |
Arjan van de Ven | d479e90 | 2006-01-06 16:47:00 -0500 | [diff] [blame] | 522 | acpi_processor_perf_fops.write = acpi_processor_write_performance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | entry->proc_fops = &acpi_processor_perf_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | entry->data = acpi_driver_data(device); |
| 525 | entry->owner = THIS_MODULE; |
| 526 | } |
| 527 | return_VOID; |
| 528 | } |
| 529 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 530 | static void acpi_cpufreq_remove_file(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 532 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
| 534 | ACPI_FUNCTION_TRACE("acpi_cpufreq_addfile"); |
| 535 | |
| 536 | if (acpi_bus_get_device(pr->handle, &device)) |
| 537 | return_VOID; |
| 538 | |
| 539 | /* remove file 'performance' */ |
| 540 | remove_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 541 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
| 543 | return_VOID; |
| 544 | } |
| 545 | |
| 546 | #else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 547 | static void acpi_cpufreq_add_file(struct acpi_processor *pr) |
| 548 | { |
| 549 | return; |
| 550 | } |
| 551 | static void acpi_cpufreq_remove_file(struct acpi_processor *pr) |
| 552 | { |
| 553 | return; |
| 554 | } |
| 555 | #endif /* CONFIG_X86_ACPI_CPUFREQ_PROC_INTF */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 558 | acpi_processor_register_performance(struct acpi_processor_performance |
| 559 | *performance, unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | { |
| 561 | struct acpi_processor *pr; |
| 562 | |
| 563 | ACPI_FUNCTION_TRACE("acpi_processor_register_performance"); |
| 564 | |
| 565 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) |
| 566 | return_VALUE(-EINVAL); |
| 567 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 568 | mutex_lock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
| 570 | pr = processors[cpu]; |
| 571 | if (!pr) { |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 572 | mutex_unlock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | return_VALUE(-ENODEV); |
| 574 | } |
| 575 | |
| 576 | if (pr->performance) { |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 577 | mutex_unlock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | return_VALUE(-EBUSY); |
| 579 | } |
| 580 | |
| 581 | pr->performance = performance; |
| 582 | |
| 583 | if (acpi_processor_get_performance_info(pr)) { |
| 584 | pr->performance = NULL; |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 585 | mutex_unlock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | return_VALUE(-EIO); |
| 587 | } |
| 588 | |
| 589 | acpi_cpufreq_add_file(pr); |
| 590 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 591 | mutex_unlock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | return_VALUE(0); |
| 593 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | EXPORT_SYMBOL(acpi_processor_register_performance); |
| 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 598 | acpi_processor_unregister_performance(struct acpi_processor_performance |
| 599 | *performance, unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | { |
| 601 | struct acpi_processor *pr; |
| 602 | |
| 603 | ACPI_FUNCTION_TRACE("acpi_processor_unregister_performance"); |
| 604 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 605 | mutex_lock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
| 607 | pr = processors[cpu]; |
| 608 | if (!pr) { |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 609 | mutex_unlock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | return_VOID; |
| 611 | } |
| 612 | |
| 613 | kfree(pr->performance->states); |
| 614 | pr->performance = NULL; |
| 615 | |
| 616 | acpi_cpufreq_remove_file(pr); |
| 617 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame^] | 618 | mutex_unlock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
| 620 | return_VOID; |
| 621 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | EXPORT_SYMBOL(acpi_processor_unregister_performance); |