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