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> |
| 37 | |
| 38 | #include <asm/uaccess.h> |
| 39 | #endif |
| 40 | |
| 41 | #include <acpi/acpi_bus.h> |
| 42 | #include <acpi/processor.h> |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #define ACPI_PROCESSOR_COMPONENT 0x01000000 |
| 45 | #define ACPI_PROCESSOR_CLASS "processor" |
| 46 | #define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver" |
| 47 | #define ACPI_PROCESSOR_FILE_PERFORMANCE "performance" |
| 48 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 49 | ACPI_MODULE_NAME("acpi_processor") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | static DECLARE_MUTEX(performance_sem); |
| 52 | |
| 53 | /* |
| 54 | * _PPC support is implemented as a CPUfreq policy notifier: |
| 55 | * This means each time a CPUfreq driver registered also with |
| 56 | * the ACPI core is asked to change the speed policy, the maximum |
| 57 | * value is adjusted so that it is within the platform limit. |
| 58 | * |
| 59 | * Also, when a new platform limit value is detected, the CPUfreq |
| 60 | * policy is adjusted accordingly. |
| 61 | */ |
| 62 | |
| 63 | #define PPC_REGISTERED 1 |
| 64 | #define PPC_IN_USE 2 |
| 65 | |
| 66 | static int acpi_processor_ppc_status = 0; |
| 67 | |
| 68 | static int acpi_processor_ppc_notifier(struct notifier_block *nb, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | unsigned long event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
| 71 | struct cpufreq_policy *policy = data; |
| 72 | struct acpi_processor *pr; |
| 73 | unsigned int ppc = 0; |
| 74 | |
| 75 | down(&performance_sem); |
| 76 | |
| 77 | if (event != CPUFREQ_INCOMPATIBLE) |
| 78 | goto out; |
| 79 | |
| 80 | pr = processors[policy->cpu]; |
| 81 | if (!pr || !pr->performance) |
| 82 | goto out; |
| 83 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | ppc = (unsigned int)pr->performance_platform_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | if (!ppc) |
| 86 | goto out; |
| 87 | |
| 88 | if (ppc > pr->performance->state_count) |
| 89 | goto out; |
| 90 | |
| 91 | cpufreq_verify_within_limits(policy, 0, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 92 | pr->performance->states[ppc]. |
| 93 | core_frequency * 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 95 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | up(&performance_sem); |
| 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | static struct notifier_block acpi_ppc_notifier_block = { |
| 102 | .notifier_call = acpi_processor_ppc_notifier, |
| 103 | }; |
| 104 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | static int acpi_processor_get_platform_limit(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | acpi_status status = 0; |
| 108 | unsigned long ppc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | ACPI_FUNCTION_TRACE("acpi_processor_get_platform_limit"); |
| 111 | |
| 112 | if (!pr) |
| 113 | return_VALUE(-EINVAL); |
| 114 | |
| 115 | /* |
| 116 | * _PPC indicates the maximum state currently supported by the platform |
| 117 | * (e.g. 0 = states 0..n; 1 = states 1..n; etc. |
| 118 | */ |
| 119 | status = acpi_evaluate_integer(pr->handle, "_PPC", NULL, &ppc); |
| 120 | |
| 121 | if (status != AE_NOT_FOUND) |
| 122 | acpi_processor_ppc_status |= PPC_IN_USE; |
| 123 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 124 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PPC\n")); |
| 126 | return_VALUE(-ENODEV); |
| 127 | } |
| 128 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 129 | pr->performance_platform_limit = (int)ppc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | return_VALUE(0); |
| 132 | } |
| 133 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 134 | int acpi_processor_ppc_has_changed(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { |
| 136 | int ret = acpi_processor_get_platform_limit(pr); |
| 137 | if (ret < 0) |
| 138 | return (ret); |
| 139 | else |
| 140 | return cpufreq_update_policy(pr->id); |
| 141 | } |
| 142 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | void acpi_processor_ppc_init(void) |
| 144 | { |
| 145 | if (!cpufreq_register_notifier |
| 146 | (&acpi_ppc_notifier_block, CPUFREQ_POLICY_NOTIFIER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | acpi_processor_ppc_status |= PPC_REGISTERED; |
| 148 | else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | printk(KERN_DEBUG |
| 150 | "Warning: Processor Platform Limit not supported.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | void acpi_processor_ppc_exit(void) |
| 154 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | if (acpi_processor_ppc_status & PPC_REGISTERED) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | cpufreq_unregister_notifier(&acpi_ppc_notifier_block, |
| 157 | CPUFREQ_POLICY_NOTIFIER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | acpi_processor_ppc_status &= ~PPC_REGISTERED; |
| 160 | } |
| 161 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 162 | static int acpi_processor_get_performance_control(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | int result = 0; |
| 165 | acpi_status status = 0; |
| 166 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 167 | union acpi_object *pct = NULL; |
| 168 | union acpi_object obj = { 0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | ACPI_FUNCTION_TRACE("acpi_processor_get_performance_control"); |
| 171 | |
| 172 | status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 173 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PCT\n")); |
| 175 | return_VALUE(-ENODEV); |
| 176 | } |
| 177 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 178 | pct = (union acpi_object *)buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | if (!pct || (pct->type != ACPI_TYPE_PACKAGE) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 180 | || (pct->package.count != 2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PCT data\n")); |
| 182 | result = -EFAULT; |
| 183 | goto end; |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * control_register |
| 188 | */ |
| 189 | |
| 190 | obj = pct->package.elements[0]; |
| 191 | |
| 192 | if ((obj.type != ACPI_TYPE_BUFFER) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 193 | || (obj.buffer.length < sizeof(struct acpi_pct_register)) |
| 194 | || (obj.buffer.pointer == NULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | "Invalid _PCT data (control_register)\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | result = -EFAULT; |
| 198 | goto end; |
| 199 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | memcpy(&pr->performance->control_register, obj.buffer.pointer, |
| 201 | sizeof(struct acpi_pct_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | /* |
| 204 | * status_register |
| 205 | */ |
| 206 | |
| 207 | obj = pct->package.elements[1]; |
| 208 | |
| 209 | if ((obj.type != ACPI_TYPE_BUFFER) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 210 | || (obj.buffer.length < sizeof(struct acpi_pct_register)) |
| 211 | || (obj.buffer.pointer == NULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | "Invalid _PCT data (status_register)\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | result = -EFAULT; |
| 215 | goto end; |
| 216 | } |
| 217 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | memcpy(&pr->performance->status_register, obj.buffer.pointer, |
| 219 | sizeof(struct acpi_pct_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 221 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | acpi_os_free(buffer.pointer); |
| 223 | |
| 224 | return_VALUE(result); |
| 225 | } |
| 226 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 227 | static int acpi_processor_get_performance_states(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 229 | int result = 0; |
| 230 | acpi_status status = AE_OK; |
| 231 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 232 | struct acpi_buffer format = { sizeof("NNNNNN"), "NNNNNN" }; |
| 233 | struct acpi_buffer state = { 0, NULL }; |
| 234 | union acpi_object *pss = NULL; |
| 235 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | ACPI_FUNCTION_TRACE("acpi_processor_get_performance_states"); |
| 238 | |
| 239 | status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PSS\n")); |
| 242 | return_VALUE(-ENODEV); |
| 243 | } |
| 244 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | pss = (union acpi_object *)buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) { |
| 247 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSS data\n")); |
| 248 | result = -EFAULT; |
| 249 | goto end; |
| 250 | } |
| 251 | |
| 252 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d performance states\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | pss->package.count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | pr->performance->state_count = pss->package.count; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 256 | pr->performance->states = |
| 257 | kmalloc(sizeof(struct acpi_processor_px) * pss->package.count, |
| 258 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | if (!pr->performance->states) { |
| 260 | result = -ENOMEM; |
| 261 | goto end; |
| 262 | } |
| 263 | |
| 264 | for (i = 0; i < pr->performance->state_count; i++) { |
| 265 | |
| 266 | struct acpi_processor_px *px = &(pr->performance->states[i]); |
| 267 | |
| 268 | state.length = sizeof(struct acpi_processor_px); |
| 269 | state.pointer = px; |
| 270 | |
| 271 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i)); |
| 272 | |
| 273 | status = acpi_extract_package(&(pss->package.elements[i]), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | &format, &state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | if (ACPI_FAILURE(status)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 276 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 277 | "Invalid _PSS data\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | result = -EFAULT; |
| 279 | kfree(pr->performance->states); |
| 280 | goto end; |
| 281 | } |
| 282 | |
| 283 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n", |
| 285 | i, |
| 286 | (u32) px->core_frequency, |
| 287 | (u32) px->power, |
| 288 | (u32) px->transition_latency, |
| 289 | (u32) px->bus_master_latency, |
| 290 | (u32) px->control, (u32) px->status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | if (!px->core_frequency) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 294 | "Invalid _PSS data: freq is zero\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | result = -EFAULT; |
| 296 | kfree(pr->performance->states); |
| 297 | goto end; |
| 298 | } |
| 299 | } |
| 300 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 301 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | acpi_os_free(buffer.pointer); |
| 303 | |
| 304 | return_VALUE(result); |
| 305 | } |
| 306 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | static int acpi_processor_get_performance_info(struct acpi_processor *pr) |
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 | acpi_status status = AE_OK; |
| 311 | acpi_handle handle = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | ACPI_FUNCTION_TRACE("acpi_processor_get_performance_info"); |
| 314 | |
| 315 | if (!pr || !pr->performance || !pr->handle) |
| 316 | return_VALUE(-EINVAL); |
| 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | status = acpi_get_handle(pr->handle, "_PCT", &handle); |
| 319 | if (ACPI_FAILURE(status)) { |
| 320 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | "ACPI-based processor performance control unavailable\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | return_VALUE(-ENODEV); |
| 323 | } |
| 324 | |
| 325 | result = acpi_processor_get_performance_control(pr); |
| 326 | if (result) |
| 327 | return_VALUE(result); |
| 328 | |
| 329 | result = acpi_processor_get_performance_states(pr); |
| 330 | if (result) |
| 331 | return_VALUE(result); |
| 332 | |
| 333 | result = acpi_processor_get_platform_limit(pr); |
| 334 | if (result) |
| 335 | return_VALUE(result); |
| 336 | |
| 337 | return_VALUE(0); |
| 338 | } |
| 339 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | int acpi_processor_notify_smm(struct module *calling_module) |
| 341 | { |
| 342 | acpi_status status; |
| 343 | static int is_done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
| 345 | ACPI_FUNCTION_TRACE("acpi_processor_notify_smm"); |
| 346 | |
| 347 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) |
| 348 | return_VALUE(-EBUSY); |
| 349 | |
| 350 | if (!try_module_get(calling_module)) |
| 351 | return_VALUE(-EINVAL); |
| 352 | |
| 353 | /* is_done is set to negative if an error occured, |
| 354 | * and to postitive if _no_ error occured, but SMM |
| 355 | * was already notified. This avoids double notification |
| 356 | * which might lead to unexpected results... |
| 357 | */ |
| 358 | if (is_done > 0) { |
| 359 | module_put(calling_module); |
| 360 | return_VALUE(0); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 361 | } else if (is_done < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | module_put(calling_module); |
| 363 | return_VALUE(is_done); |
| 364 | } |
| 365 | |
| 366 | is_done = -EIO; |
| 367 | |
| 368 | /* 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] | 369 | if ((!acpi_fadt.smi_cmd) || (!acpi_fadt.pstate_cnt)) { |
| 370 | 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] | 371 | module_put(calling_module); |
| 372 | return_VALUE(0); |
| 373 | } |
| 374 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 375 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 376 | "Writing pstate_cnt [0x%x] to smi_cmd [0x%x]\n", |
| 377 | acpi_fadt.pstate_cnt, acpi_fadt.smi_cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
| 379 | /* FADT v1 doesn't support pstate_cnt, many BIOS vendors use |
| 380 | * it anyway, so we need to support it... */ |
| 381 | if (acpi_fadt_is_v1) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 382 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 383 | "Using v1.0 FADT reserved value for pstate_cnt\n")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | } |
| 385 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | status = acpi_os_write_port(acpi_fadt.smi_cmd, |
| 387 | (u32) acpi_fadt.pstate_cnt, 8); |
| 388 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
| 390 | "Failed to write pstate_cnt [0x%x] to " |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 391 | "smi_cmd [0x%x]\n", acpi_fadt.pstate_cnt, |
| 392 | acpi_fadt.smi_cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | module_put(calling_module); |
| 394 | return_VALUE(status); |
| 395 | } |
| 396 | |
| 397 | /* Success. If there's no _PPC, we need to fear nothing, so |
| 398 | * we can allow the cpufreq driver to be rmmod'ed. */ |
| 399 | is_done = 1; |
| 400 | |
| 401 | if (!(acpi_processor_ppc_status & PPC_IN_USE)) |
| 402 | module_put(calling_module); |
| 403 | |
| 404 | return_VALUE(0); |
| 405 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 407 | EXPORT_SYMBOL(acpi_processor_notify_smm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | #ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF |
| 410 | /* /proc/acpi/processor/../performance interface (DEPRECATED) */ |
| 411 | |
| 412 | static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file); |
| 413 | static struct file_operations acpi_processor_perf_fops = { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 414 | .open = acpi_processor_perf_open_fs, |
| 415 | .read = seq_read, |
| 416 | .llseek = seq_lseek, |
| 417 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | }; |
| 419 | |
| 420 | static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset) |
| 421 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 422 | struct acpi_processor *pr = (struct acpi_processor *)seq->private; |
| 423 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
| 425 | ACPI_FUNCTION_TRACE("acpi_processor_perf_seq_show"); |
| 426 | |
| 427 | if (!pr) |
| 428 | goto end; |
| 429 | |
| 430 | if (!pr->performance) { |
| 431 | seq_puts(seq, "<not supported>\n"); |
| 432 | goto end; |
| 433 | } |
| 434 | |
| 435 | seq_printf(seq, "state count: %d\n" |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 436 | "active state: P%d\n", |
| 437 | pr->performance->state_count, pr->performance->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
| 439 | seq_puts(seq, "states:\n"); |
| 440 | for (i = 0; i < pr->performance->state_count; i++) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 441 | seq_printf(seq, |
| 442 | " %cP%d: %d MHz, %d mW, %d uS\n", |
| 443 | (i == pr->performance->state ? '*' : ' '), i, |
| 444 | (u32) pr->performance->states[i].core_frequency, |
| 445 | (u32) pr->performance->states[i].power, |
| 446 | (u32) pr->performance->states[i].transition_latency); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 448 | end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | return_VALUE(0); |
| 450 | } |
| 451 | |
| 452 | static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file) |
| 453 | { |
| 454 | return single_open(file, acpi_processor_perf_seq_show, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 455 | PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 459 | acpi_processor_write_performance(struct file *file, |
| 460 | const char __user * buffer, |
| 461 | size_t count, loff_t * data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 463 | int result = 0; |
| 464 | struct seq_file *m = (struct seq_file *)file->private_data; |
| 465 | struct acpi_processor *pr = (struct acpi_processor *)m->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | struct acpi_processor_performance *perf; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 467 | char state_string[12] = { '\0' }; |
| 468 | unsigned int new_state = 0; |
| 469 | struct cpufreq_policy policy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | ACPI_FUNCTION_TRACE("acpi_processor_write_performance"); |
| 472 | |
| 473 | if (!pr || (count > sizeof(state_string) - 1)) |
| 474 | return_VALUE(-EINVAL); |
| 475 | |
| 476 | perf = pr->performance; |
| 477 | if (!perf) |
| 478 | return_VALUE(-EINVAL); |
| 479 | |
| 480 | if (copy_from_user(state_string, buffer, count)) |
| 481 | return_VALUE(-EFAULT); |
| 482 | |
| 483 | state_string[count] = '\0'; |
| 484 | new_state = simple_strtoul(state_string, NULL, 0); |
| 485 | |
| 486 | if (new_state >= perf->state_count) |
| 487 | return_VALUE(-EINVAL); |
| 488 | |
| 489 | cpufreq_get_policy(&policy, pr->id); |
| 490 | |
| 491 | policy.cpu = pr->id; |
| 492 | policy.min = perf->states[new_state].core_frequency * 1000; |
| 493 | policy.max = perf->states[new_state].core_frequency * 1000; |
| 494 | |
| 495 | result = cpufreq_set_policy(&policy); |
| 496 | if (result) |
| 497 | return_VALUE(result); |
| 498 | |
| 499 | return_VALUE(count); |
| 500 | } |
| 501 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 502 | static void acpi_cpufreq_add_file(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 504 | struct proc_dir_entry *entry = NULL; |
| 505 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
| 507 | ACPI_FUNCTION_TRACE("acpi_cpufreq_addfile"); |
| 508 | |
| 509 | if (acpi_bus_get_device(pr->handle, &device)) |
| 510 | return_VOID; |
| 511 | |
| 512 | /* add file 'performance' [R/W] */ |
| 513 | entry = create_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | S_IFREG | S_IRUGO | S_IWUSR, |
| 515 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | if (!entry) |
| 517 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 518 | "Unable to create '%s' fs entry\n", |
| 519 | ACPI_PROCESSOR_FILE_PERFORMANCE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | else { |
Arjan van de Ven | d479e90 | 2006-01-06 16:47:00 -0500 | [diff] [blame] | 521 | acpi_processor_perf_fops.write = acpi_processor_write_performance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | entry->proc_fops = &acpi_processor_perf_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | entry->data = acpi_driver_data(device); |
| 524 | entry->owner = THIS_MODULE; |
| 525 | } |
| 526 | return_VOID; |
| 527 | } |
| 528 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 529 | static void acpi_cpufreq_remove_file(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 531 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
| 533 | ACPI_FUNCTION_TRACE("acpi_cpufreq_addfile"); |
| 534 | |
| 535 | if (acpi_bus_get_device(pr->handle, &device)) |
| 536 | return_VOID; |
| 537 | |
| 538 | /* remove file 'performance' */ |
| 539 | remove_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 540 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
| 542 | return_VOID; |
| 543 | } |
| 544 | |
| 545 | #else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 546 | static void acpi_cpufreq_add_file(struct acpi_processor *pr) |
| 547 | { |
| 548 | return; |
| 549 | } |
| 550 | static void acpi_cpufreq_remove_file(struct acpi_processor *pr) |
| 551 | { |
| 552 | return; |
| 553 | } |
| 554 | #endif /* CONFIG_X86_ACPI_CPUFREQ_PROC_INTF */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 556 | static int acpi_processor_get_psd(struct acpi_processor *pr) |
| 557 | { |
| 558 | int result = 0; |
| 559 | acpi_status status = AE_OK; |
| 560 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 561 | struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"}; |
| 562 | struct acpi_buffer state = {0, NULL}; |
| 563 | union acpi_object *psd = NULL; |
| 564 | struct acpi_psd_package *pdomain; |
| 565 | |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 566 | status = acpi_evaluate_object(pr->handle, "_PSD", NULL, &buffer); |
| 567 | if (ACPI_FAILURE(status)) { |
Len Brown | 9011bff | 2006-05-11 00:28:12 -0400 | [diff] [blame^] | 568 | return -ENODEV; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | psd = (union acpi_object *) buffer.pointer; |
| 572 | if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) { |
| 573 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n")); |
| 574 | result = -EFAULT; |
| 575 | goto end; |
| 576 | } |
| 577 | |
| 578 | if (psd->package.count != 1) { |
| 579 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n")); |
| 580 | result = -EFAULT; |
| 581 | goto end; |
| 582 | } |
| 583 | |
| 584 | pdomain = &(pr->performance->domain_info); |
| 585 | |
| 586 | state.length = sizeof(struct acpi_psd_package); |
| 587 | state.pointer = pdomain; |
| 588 | |
| 589 | status = acpi_extract_package(&(psd->package.elements[0]), |
| 590 | &format, &state); |
| 591 | if (ACPI_FAILURE(status)) { |
| 592 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n")); |
| 593 | result = -EFAULT; |
| 594 | goto end; |
| 595 | } |
| 596 | |
| 597 | if (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES) { |
| 598 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _PSD:num_entries\n")); |
| 599 | result = -EFAULT; |
| 600 | goto end; |
| 601 | } |
| 602 | |
| 603 | if (pdomain->revision != ACPI_PSD_REV0_REVISION) { |
| 604 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _PSD:revision\n")); |
| 605 | result = -EFAULT; |
| 606 | goto end; |
| 607 | } |
| 608 | |
| 609 | end: |
| 610 | acpi_os_free(buffer.pointer); |
Len Brown | 9011bff | 2006-05-11 00:28:12 -0400 | [diff] [blame^] | 611 | return result; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | int acpi_processor_preregister_performance( |
| 615 | struct acpi_processor_performance **performance) |
| 616 | { |
| 617 | int count, count_target; |
| 618 | int retval = 0; |
| 619 | unsigned int i, j; |
| 620 | cpumask_t covered_cpus; |
| 621 | struct acpi_processor *pr; |
| 622 | struct acpi_psd_package *pdomain; |
| 623 | struct acpi_processor *match_pr; |
| 624 | struct acpi_psd_package *match_pdomain; |
| 625 | |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 626 | down(&performance_sem); |
| 627 | |
| 628 | retval = 0; |
| 629 | |
| 630 | /* Call _PSD for all CPUs */ |
| 631 | for_each_cpu(i) { |
| 632 | pr = processors[i]; |
| 633 | if (!pr) { |
| 634 | /* Look only at processors in ACPI namespace */ |
| 635 | continue; |
| 636 | } |
| 637 | |
| 638 | if (pr->performance) { |
| 639 | retval = -EBUSY; |
| 640 | continue; |
| 641 | } |
| 642 | |
| 643 | if (!performance || !performance[i]) { |
| 644 | retval = -EINVAL; |
| 645 | continue; |
| 646 | } |
| 647 | |
| 648 | pr->performance = performance[i]; |
| 649 | cpu_set(i, pr->performance->shared_cpu_map); |
| 650 | if (acpi_processor_get_psd(pr)) { |
| 651 | retval = -EINVAL; |
| 652 | continue; |
| 653 | } |
| 654 | } |
| 655 | if (retval) |
| 656 | goto err_ret; |
| 657 | |
| 658 | /* |
| 659 | * Now that we have _PSD data from all CPUs, lets setup P-state |
| 660 | * domain info. |
| 661 | */ |
| 662 | for_each_cpu(i) { |
| 663 | pr = processors[i]; |
| 664 | if (!pr) |
| 665 | continue; |
| 666 | |
| 667 | /* Basic validity check for domain info */ |
| 668 | pdomain = &(pr->performance->domain_info); |
| 669 | if ((pdomain->revision != ACPI_PSD_REV0_REVISION) || |
| 670 | (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES)) { |
| 671 | retval = -EINVAL; |
| 672 | goto err_ret; |
| 673 | } |
| 674 | if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL && |
| 675 | pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY && |
| 676 | pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) { |
| 677 | retval = -EINVAL; |
| 678 | goto err_ret; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | cpus_clear(covered_cpus); |
| 683 | for_each_cpu(i) { |
| 684 | pr = processors[i]; |
| 685 | if (!pr) |
| 686 | continue; |
| 687 | |
| 688 | if (cpu_isset(i, covered_cpus)) |
| 689 | continue; |
| 690 | |
| 691 | pdomain = &(pr->performance->domain_info); |
| 692 | cpu_set(i, pr->performance->shared_cpu_map); |
| 693 | cpu_set(i, covered_cpus); |
| 694 | if (pdomain->num_processors <= 1) |
| 695 | continue; |
| 696 | |
| 697 | /* Validate the Domain info */ |
| 698 | count_target = pdomain->num_processors; |
| 699 | count = 1; |
| 700 | if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL || |
| 701 | pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL) { |
| 702 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL; |
| 703 | } else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY) { |
| 704 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY; |
| 705 | } |
| 706 | |
| 707 | for_each_cpu(j) { |
| 708 | if (i == j) |
| 709 | continue; |
| 710 | |
| 711 | match_pr = processors[j]; |
| 712 | if (!match_pr) |
| 713 | continue; |
| 714 | |
| 715 | match_pdomain = &(match_pr->performance->domain_info); |
| 716 | if (match_pdomain->domain != pdomain->domain) |
| 717 | continue; |
| 718 | |
| 719 | /* Here i and j are in the same domain */ |
| 720 | |
| 721 | if (match_pdomain->num_processors != count_target) { |
| 722 | retval = -EINVAL; |
| 723 | goto err_ret; |
| 724 | } |
| 725 | |
| 726 | if (pdomain->coord_type != match_pdomain->coord_type) { |
| 727 | retval = -EINVAL; |
| 728 | goto err_ret; |
| 729 | } |
| 730 | |
| 731 | cpu_set(j, covered_cpus); |
| 732 | cpu_set(j, pr->performance->shared_cpu_map); |
| 733 | count++; |
| 734 | } |
| 735 | |
| 736 | for_each_cpu(j) { |
| 737 | if (i == j) |
| 738 | continue; |
| 739 | |
| 740 | match_pr = processors[j]; |
| 741 | if (!match_pr) |
| 742 | continue; |
| 743 | |
| 744 | match_pdomain = &(match_pr->performance->domain_info); |
| 745 | if (match_pdomain->domain != pdomain->domain) |
| 746 | continue; |
| 747 | |
| 748 | match_pr->performance->shared_type = |
| 749 | pr->performance->shared_type; |
| 750 | match_pr->performance->shared_cpu_map = |
| 751 | pr->performance->shared_cpu_map; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | err_ret: |
| 756 | if (retval) { |
| 757 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error while parsing _PSD domain information. Assuming no coordination\n")); |
| 758 | } |
| 759 | |
| 760 | for_each_cpu(i) { |
| 761 | pr = processors[i]; |
| 762 | if (!pr || !pr->performance) |
| 763 | continue; |
| 764 | |
| 765 | /* Assume no coordination on any error parsing domain info */ |
| 766 | if (retval) { |
| 767 | cpus_clear(pr->performance->shared_cpu_map); |
| 768 | cpu_set(i, pr->performance->shared_cpu_map); |
| 769 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL; |
| 770 | } |
| 771 | pr->performance = NULL; /* Will be set for real in register */ |
| 772 | } |
| 773 | |
| 774 | up(&performance_sem); |
Len Brown | 9011bff | 2006-05-11 00:28:12 -0400 | [diff] [blame^] | 775 | return retval; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 776 | } |
| 777 | EXPORT_SYMBOL(acpi_processor_preregister_performance); |
| 778 | |
| 779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 781 | acpi_processor_register_performance(struct acpi_processor_performance |
| 782 | *performance, unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | { |
| 784 | struct acpi_processor *pr; |
| 785 | |
| 786 | ACPI_FUNCTION_TRACE("acpi_processor_register_performance"); |
| 787 | |
| 788 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) |
| 789 | return_VALUE(-EINVAL); |
| 790 | |
| 791 | down(&performance_sem); |
| 792 | |
| 793 | pr = processors[cpu]; |
| 794 | if (!pr) { |
| 795 | up(&performance_sem); |
| 796 | return_VALUE(-ENODEV); |
| 797 | } |
| 798 | |
| 799 | if (pr->performance) { |
| 800 | up(&performance_sem); |
| 801 | return_VALUE(-EBUSY); |
| 802 | } |
| 803 | |
| 804 | pr->performance = performance; |
| 805 | |
| 806 | if (acpi_processor_get_performance_info(pr)) { |
| 807 | pr->performance = NULL; |
| 808 | up(&performance_sem); |
| 809 | return_VALUE(-EIO); |
| 810 | } |
| 811 | |
| 812 | acpi_cpufreq_add_file(pr); |
| 813 | |
| 814 | up(&performance_sem); |
| 815 | return_VALUE(0); |
| 816 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | EXPORT_SYMBOL(acpi_processor_register_performance); |
| 819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 821 | acpi_processor_unregister_performance(struct acpi_processor_performance |
| 822 | *performance, unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | { |
| 824 | struct acpi_processor *pr; |
| 825 | |
| 826 | ACPI_FUNCTION_TRACE("acpi_processor_unregister_performance"); |
| 827 | |
| 828 | down(&performance_sem); |
| 829 | |
| 830 | pr = processors[cpu]; |
| 831 | if (!pr) { |
| 832 | up(&performance_sem); |
| 833 | return_VOID; |
| 834 | } |
| 835 | |
| 836 | kfree(pr->performance->states); |
| 837 | pr->performance = NULL; |
| 838 | |
| 839 | acpi_cpufreq_remove_file(pr); |
| 840 | |
| 841 | up(&performance_sem); |
| 842 | |
| 843 | return_VOID; |
| 844 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | EXPORT_SYMBOL(acpi_processor_unregister_performance); |