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 | |
Thomas Renninger | 919158d | 2007-10-31 15:41:42 +0100 | [diff] [blame] | 53 | /* Use cpufreq debug layer for _PPC changes. */ |
| 54 | #define cpufreq_printk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, \ |
| 55 | "cpufreq-core", msg) |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /* |
| 58 | * _PPC support is implemented as a CPUfreq policy notifier: |
| 59 | * This means each time a CPUfreq driver registered also with |
| 60 | * the ACPI core is asked to change the speed policy, the maximum |
| 61 | * value is adjusted so that it is within the platform limit. |
| 62 | * |
| 63 | * Also, when a new platform limit value is detected, the CPUfreq |
| 64 | * policy is adjusted accordingly. |
| 65 | */ |
| 66 | |
Thomas Renninger | 623b78c | 2007-05-18 21:59:28 -0500 | [diff] [blame] | 67 | static unsigned int ignore_ppc = 0; |
| 68 | module_param(ignore_ppc, uint, 0644); |
| 69 | MODULE_PARM_DESC(ignore_ppc, "If the frequency of your machine gets wrongly" \ |
| 70 | "limited by BIOS, this should help"); |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #define PPC_REGISTERED 1 |
| 73 | #define PPC_IN_USE 2 |
| 74 | |
| 75 | static int acpi_processor_ppc_status = 0; |
| 76 | |
| 77 | static int acpi_processor_ppc_notifier(struct notifier_block *nb, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | unsigned long event, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
| 80 | struct cpufreq_policy *policy = data; |
| 81 | struct acpi_processor *pr; |
| 82 | unsigned int ppc = 0; |
| 83 | |
Thomas Renninger | 623b78c | 2007-05-18 21:59:28 -0500 | [diff] [blame] | 84 | if (ignore_ppc) |
| 85 | return 0; |
| 86 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 87 | mutex_lock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | if (event != CPUFREQ_INCOMPATIBLE) |
| 90 | goto out; |
| 91 | |
| 92 | pr = processors[policy->cpu]; |
| 93 | if (!pr || !pr->performance) |
| 94 | goto out; |
| 95 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 96 | ppc = (unsigned int)pr->performance_platform_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Dave Jones | 0916bd3 | 2006-11-22 20:42:01 -0500 | [diff] [blame] | 98 | if (ppc >= pr->performance->state_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | goto out; |
| 100 | |
| 101 | cpufreq_verify_within_limits(policy, 0, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 102 | pr->performance->states[ppc]. |
| 103 | core_frequency * 1000); |
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 | out: |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 106 | mutex_unlock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | static struct notifier_block acpi_ppc_notifier_block = { |
| 112 | .notifier_call = acpi_processor_ppc_notifier, |
| 113 | }; |
| 114 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 115 | static int acpi_processor_get_platform_limit(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 117 | acpi_status status = 0; |
| 118 | unsigned long ppc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | if (!pr) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 122 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | /* |
| 125 | * _PPC indicates the maximum state currently supported by the platform |
| 126 | * (e.g. 0 = states 0..n; 1 = states 1..n; etc. |
| 127 | */ |
| 128 | status = acpi_evaluate_integer(pr->handle, "_PPC", NULL, &ppc); |
| 129 | |
| 130 | if (status != AE_NOT_FOUND) |
| 131 | acpi_processor_ppc_status |= PPC_IN_USE; |
| 132 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 134 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PPC")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 135 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Thomas Renninger | 919158d | 2007-10-31 15:41:42 +0100 | [diff] [blame] | 138 | cpufreq_printk("CPU %d: _PPC is %d - frequency %s limited\n", pr->id, |
| 139 | (int)ppc, ppc ? "" : "not"); |
| 140 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | pr->performance_platform_limit = (int)ppc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 143 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 146 | int acpi_processor_ppc_has_changed(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
Thomas Renninger | 623b78c | 2007-05-18 21:59:28 -0500 | [diff] [blame] | 148 | int ret; |
| 149 | |
| 150 | if (ignore_ppc) |
| 151 | return 0; |
| 152 | |
| 153 | ret = acpi_processor_get_platform_limit(pr); |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | if (ret < 0) |
| 156 | return (ret); |
| 157 | else |
| 158 | return cpufreq_update_policy(pr->id); |
| 159 | } |
| 160 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | void acpi_processor_ppc_init(void) |
| 162 | { |
| 163 | if (!cpufreq_register_notifier |
| 164 | (&acpi_ppc_notifier_block, CPUFREQ_POLICY_NOTIFIER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | acpi_processor_ppc_status |= PPC_REGISTERED; |
| 166 | else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 167 | printk(KERN_DEBUG |
| 168 | "Warning: Processor Platform Limit not supported.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 171 | void acpi_processor_ppc_exit(void) |
| 172 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | if (acpi_processor_ppc_status & PPC_REGISTERED) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | cpufreq_unregister_notifier(&acpi_ppc_notifier_block, |
| 175 | CPUFREQ_POLICY_NOTIFIER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | acpi_processor_ppc_status &= ~PPC_REGISTERED; |
| 178 | } |
| 179 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 180 | static int acpi_processor_get_performance_control(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | int result = 0; |
| 183 | acpi_status status = 0; |
| 184 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 185 | union acpi_object *pct = NULL; |
| 186 | union acpi_object obj = { 0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 190 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 191 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PCT")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 192 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | pct = (union acpi_object *)buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | if (!pct || (pct->type != ACPI_TYPE_PACKAGE) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 197 | || (pct->package.count != 2)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 198 | printk(KERN_ERR PREFIX "Invalid _PCT data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | result = -EFAULT; |
| 200 | goto end; |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * control_register |
| 205 | */ |
| 206 | |
| 207 | obj = pct->package.elements[0]; |
| 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)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 212 | printk(KERN_ERR PREFIX "Invalid _PCT data (control_register)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | result = -EFAULT; |
| 214 | goto end; |
| 215 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 216 | memcpy(&pr->performance->control_register, obj.buffer.pointer, |
| 217 | sizeof(struct acpi_pct_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | /* |
| 220 | * status_register |
| 221 | */ |
| 222 | |
| 223 | obj = pct->package.elements[1]; |
| 224 | |
| 225 | if ((obj.type != ACPI_TYPE_BUFFER) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 226 | || (obj.buffer.length < sizeof(struct acpi_pct_register)) |
| 227 | || (obj.buffer.pointer == NULL)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 228 | printk(KERN_ERR PREFIX "Invalid _PCT data (status_register)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | result = -EFAULT; |
| 230 | goto end; |
| 231 | } |
| 232 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 233 | memcpy(&pr->performance->status_register, obj.buffer.pointer, |
| 234 | sizeof(struct acpi_pct_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 236 | end: |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 237 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 239 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | static int acpi_processor_get_performance_states(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | int result = 0; |
| 245 | acpi_status status = AE_OK; |
| 246 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 247 | struct acpi_buffer format = { sizeof("NNNNNN"), "NNNNNN" }; |
| 248 | struct acpi_buffer state = { 0, NULL }; |
| 249 | union acpi_object *pss = NULL; |
| 250 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 255 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PSS")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 256 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 259 | pss = buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 261 | printk(KERN_ERR PREFIX "Invalid _PSS data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | result = -EFAULT; |
| 263 | goto end; |
| 264 | } |
| 265 | |
| 266 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d performance states\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 267 | pss->package.count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | pr->performance->state_count = pss->package.count; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 270 | pr->performance->states = |
| 271 | kmalloc(sizeof(struct acpi_processor_px) * pss->package.count, |
| 272 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (!pr->performance->states) { |
| 274 | result = -ENOMEM; |
| 275 | goto end; |
| 276 | } |
| 277 | |
| 278 | for (i = 0; i < pr->performance->state_count; i++) { |
| 279 | |
| 280 | struct acpi_processor_px *px = &(pr->performance->states[i]); |
| 281 | |
| 282 | state.length = sizeof(struct acpi_processor_px); |
| 283 | state.pointer = px; |
| 284 | |
| 285 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i)); |
| 286 | |
| 287 | status = acpi_extract_package(&(pss->package.elements[i]), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | &format, &state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 290 | ACPI_EXCEPTION((AE_INFO, status, "Invalid _PSS data")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | result = -EFAULT; |
| 292 | kfree(pr->performance->states); |
| 293 | goto end; |
| 294 | } |
| 295 | |
| 296 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n", |
| 298 | i, |
| 299 | (u32) px->core_frequency, |
| 300 | (u32) px->power, |
| 301 | (u32) px->transition_latency, |
| 302 | (u32) px->bus_master_latency, |
| 303 | (u32) px->control, (u32) px->status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | if (!px->core_frequency) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 306 | printk(KERN_ERR PREFIX |
| 307 | "Invalid _PSS data: freq is zero\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | result = -EFAULT; |
| 309 | kfree(pr->performance->states); |
| 310 | goto end; |
| 311 | } |
| 312 | } |
| 313 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 314 | end: |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 315 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 317 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | static int acpi_processor_get_performance_info(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 322 | int result = 0; |
| 323 | acpi_status status = AE_OK; |
| 324 | acpi_handle handle = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | if (!pr || !pr->performance || !pr->handle) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 328 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | status = acpi_get_handle(pr->handle, "_PCT", &handle); |
| 331 | if (ACPI_FAILURE(status)) { |
| 332 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | "ACPI-based processor performance control unavailable\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 334 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | result = acpi_processor_get_performance_control(pr); |
| 338 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 339 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | result = acpi_processor_get_performance_states(pr); |
| 342 | if (result) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 343 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 345 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | int acpi_processor_notify_smm(struct module *calling_module) |
| 349 | { |
| 350 | acpi_status status; |
| 351 | static int is_done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
| 354 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 355 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | if (!try_module_get(calling_module)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 358 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
| 360 | /* is_done is set to negative if an error occured, |
| 361 | * and to postitive if _no_ error occured, but SMM |
| 362 | * was already notified. This avoids double notification |
| 363 | * which might lead to unexpected results... |
| 364 | */ |
| 365 | if (is_done > 0) { |
| 366 | module_put(calling_module); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 367 | return 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | } else if (is_done < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | module_put(calling_module); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 370 | return is_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | is_done = -EIO; |
| 374 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 375 | /* 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] | 376 | if ((!acpi_gbl_FADT.smi_command) || (!acpi_gbl_FADT.pstate_control)) { |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 377 | 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] | 378 | module_put(calling_module); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 379 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 382 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 383 | "Writing pstate_control [0x%x] to smi_command [0x%x]\n", |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 384 | acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 386 | status = acpi_os_write_port(acpi_gbl_FADT.smi_command, |
| 387 | (u32) acpi_gbl_FADT.pstate_control, 8); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 388 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 389 | ACPI_EXCEPTION((AE_INFO, status, |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 390 | "Failed to write pstate_control [0x%x] to " |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 391 | "smi_command [0x%x]", acpi_gbl_FADT.pstate_control, |
| 392 | acpi_gbl_FADT.smi_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | module_put(calling_module); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 394 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 404 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 414 | .owner = THIS_MODULE, |
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 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 423 | struct acpi_processor *pr = seq->private; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 424 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 449 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 458 | static void acpi_cpufreq_add_file(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 460 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | if (acpi_bus_get_device(pr->handle, &device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 464 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | /* add file 'performance' [R/W] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 467 | proc_create_data(ACPI_PROCESSOR_FILE_PERFORMANCE, S_IFREG | S_IRUGO, |
| 468 | acpi_device_dir(device), |
| 469 | &acpi_processor_perf_fops, acpi_driver_data(device)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 470 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 473 | static void acpi_cpufreq_remove_file(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 475 | struct acpi_device *device = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
| 478 | if (acpi_bus_get_device(pr->handle, &device)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 479 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
| 481 | /* remove file 'performance' */ |
| 482 | remove_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 483 | acpi_device_dir(device)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 485 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | #else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 489 | static void acpi_cpufreq_add_file(struct acpi_processor *pr) |
| 490 | { |
| 491 | return; |
| 492 | } |
| 493 | static void acpi_cpufreq_remove_file(struct acpi_processor *pr) |
| 494 | { |
| 495 | return; |
| 496 | } |
| 497 | #endif /* CONFIG_X86_ACPI_CPUFREQ_PROC_INTF */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 499 | static int acpi_processor_get_psd(struct acpi_processor *pr) |
| 500 | { |
| 501 | int result = 0; |
| 502 | acpi_status status = AE_OK; |
| 503 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 504 | struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"}; |
| 505 | struct acpi_buffer state = {0, NULL}; |
| 506 | union acpi_object *psd = NULL; |
| 507 | struct acpi_psd_package *pdomain; |
| 508 | |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 509 | status = acpi_evaluate_object(pr->handle, "_PSD", NULL, &buffer); |
| 510 | if (ACPI_FAILURE(status)) { |
Len Brown | 9011bff4 | 2006-05-11 00:28:12 -0400 | [diff] [blame] | 511 | return -ENODEV; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 512 | } |
| 513 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 514 | psd = buffer.pointer; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 515 | if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) { |
| 516 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n")); |
| 517 | result = -EFAULT; |
| 518 | goto end; |
| 519 | } |
| 520 | |
| 521 | if (psd->package.count != 1) { |
| 522 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n")); |
| 523 | result = -EFAULT; |
| 524 | goto end; |
| 525 | } |
| 526 | |
| 527 | pdomain = &(pr->performance->domain_info); |
| 528 | |
| 529 | state.length = sizeof(struct acpi_psd_package); |
| 530 | state.pointer = pdomain; |
| 531 | |
| 532 | status = acpi_extract_package(&(psd->package.elements[0]), |
| 533 | &format, &state); |
| 534 | if (ACPI_FAILURE(status)) { |
| 535 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSD data\n")); |
| 536 | result = -EFAULT; |
| 537 | goto end; |
| 538 | } |
| 539 | |
| 540 | if (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES) { |
| 541 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _PSD:num_entries\n")); |
| 542 | result = -EFAULT; |
| 543 | goto end; |
| 544 | } |
| 545 | |
| 546 | if (pdomain->revision != ACPI_PSD_REV0_REVISION) { |
| 547 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unknown _PSD:revision\n")); |
| 548 | result = -EFAULT; |
| 549 | goto end; |
| 550 | } |
| 551 | |
| 552 | end: |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 553 | kfree(buffer.pointer); |
Len Brown | 9011bff4 | 2006-05-11 00:28:12 -0400 | [diff] [blame] | 554 | return result; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | int acpi_processor_preregister_performance( |
Fenghua Yu | 5010929 | 2007-08-07 18:40:30 -0400 | [diff] [blame] | 558 | struct acpi_processor_performance *performance) |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 559 | { |
| 560 | int count, count_target; |
| 561 | int retval = 0; |
| 562 | unsigned int i, j; |
| 563 | cpumask_t covered_cpus; |
| 564 | struct acpi_processor *pr; |
| 565 | struct acpi_psd_package *pdomain; |
| 566 | struct acpi_processor *match_pr; |
| 567 | struct acpi_psd_package *match_pdomain; |
| 568 | |
Len Brown | 785fccc | 2006-06-15 22:19:31 -0400 | [diff] [blame] | 569 | mutex_lock(&performance_mutex); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 570 | |
| 571 | retval = 0; |
| 572 | |
| 573 | /* Call _PSD for all CPUs */ |
KAMEZAWA Hiroyuki | 193de0c | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 574 | for_each_possible_cpu(i) { |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 575 | pr = processors[i]; |
| 576 | if (!pr) { |
| 577 | /* Look only at processors in ACPI namespace */ |
| 578 | continue; |
| 579 | } |
| 580 | |
| 581 | if (pr->performance) { |
| 582 | retval = -EBUSY; |
| 583 | continue; |
| 584 | } |
| 585 | |
Fenghua Yu | 5010929 | 2007-08-07 18:40:30 -0400 | [diff] [blame] | 586 | if (!performance || !percpu_ptr(performance, i)) { |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 587 | retval = -EINVAL; |
| 588 | continue; |
| 589 | } |
| 590 | |
Fenghua Yu | 5010929 | 2007-08-07 18:40:30 -0400 | [diff] [blame] | 591 | pr->performance = percpu_ptr(performance, i); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 592 | cpu_set(i, pr->performance->shared_cpu_map); |
| 593 | if (acpi_processor_get_psd(pr)) { |
| 594 | retval = -EINVAL; |
| 595 | continue; |
| 596 | } |
| 597 | } |
| 598 | if (retval) |
| 599 | goto err_ret; |
| 600 | |
| 601 | /* |
| 602 | * Now that we have _PSD data from all CPUs, lets setup P-state |
| 603 | * domain info. |
| 604 | */ |
KAMEZAWA Hiroyuki | 193de0c | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 605 | for_each_possible_cpu(i) { |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 606 | pr = processors[i]; |
| 607 | if (!pr) |
| 608 | continue; |
| 609 | |
| 610 | /* Basic validity check for domain info */ |
| 611 | pdomain = &(pr->performance->domain_info); |
| 612 | if ((pdomain->revision != ACPI_PSD_REV0_REVISION) || |
| 613 | (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES)) { |
| 614 | retval = -EINVAL; |
| 615 | goto err_ret; |
| 616 | } |
| 617 | if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL && |
| 618 | pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY && |
| 619 | pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) { |
| 620 | retval = -EINVAL; |
| 621 | goto err_ret; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | cpus_clear(covered_cpus); |
KAMEZAWA Hiroyuki | 193de0c | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 626 | for_each_possible_cpu(i) { |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 627 | pr = processors[i]; |
| 628 | if (!pr) |
| 629 | continue; |
| 630 | |
| 631 | if (cpu_isset(i, covered_cpus)) |
| 632 | continue; |
| 633 | |
| 634 | pdomain = &(pr->performance->domain_info); |
| 635 | cpu_set(i, pr->performance->shared_cpu_map); |
| 636 | cpu_set(i, covered_cpus); |
| 637 | if (pdomain->num_processors <= 1) |
| 638 | continue; |
| 639 | |
| 640 | /* Validate the Domain info */ |
| 641 | count_target = pdomain->num_processors; |
| 642 | count = 1; |
Venkatesh Pallipadi | 46f18e3 | 2006-06-26 00:34:43 -0400 | [diff] [blame] | 643 | if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL) |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 644 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL; |
Venkatesh Pallipadi | 46f18e3 | 2006-06-26 00:34:43 -0400 | [diff] [blame] | 645 | else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL) |
| 646 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_HW; |
| 647 | else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY) |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 648 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 649 | |
KAMEZAWA Hiroyuki | 193de0c | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 650 | for_each_possible_cpu(j) { |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 651 | if (i == j) |
| 652 | continue; |
| 653 | |
| 654 | match_pr = processors[j]; |
| 655 | if (!match_pr) |
| 656 | continue; |
| 657 | |
| 658 | match_pdomain = &(match_pr->performance->domain_info); |
| 659 | if (match_pdomain->domain != pdomain->domain) |
| 660 | continue; |
| 661 | |
| 662 | /* Here i and j are in the same domain */ |
| 663 | |
| 664 | if (match_pdomain->num_processors != count_target) { |
| 665 | retval = -EINVAL; |
| 666 | goto err_ret; |
| 667 | } |
| 668 | |
| 669 | if (pdomain->coord_type != match_pdomain->coord_type) { |
| 670 | retval = -EINVAL; |
| 671 | goto err_ret; |
| 672 | } |
| 673 | |
| 674 | cpu_set(j, covered_cpus); |
| 675 | cpu_set(j, pr->performance->shared_cpu_map); |
| 676 | count++; |
| 677 | } |
| 678 | |
KAMEZAWA Hiroyuki | 193de0c | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 679 | for_each_possible_cpu(j) { |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 680 | if (i == j) |
| 681 | continue; |
| 682 | |
| 683 | match_pr = processors[j]; |
| 684 | if (!match_pr) |
| 685 | continue; |
| 686 | |
| 687 | match_pdomain = &(match_pr->performance->domain_info); |
| 688 | if (match_pdomain->domain != pdomain->domain) |
| 689 | continue; |
| 690 | |
| 691 | match_pr->performance->shared_type = |
| 692 | pr->performance->shared_type; |
| 693 | match_pr->performance->shared_cpu_map = |
| 694 | pr->performance->shared_cpu_map; |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | err_ret: |
KAMEZAWA Hiroyuki | 193de0c | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 699 | for_each_possible_cpu(i) { |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 700 | pr = processors[i]; |
| 701 | if (!pr || !pr->performance) |
| 702 | continue; |
| 703 | |
| 704 | /* Assume no coordination on any error parsing domain info */ |
| 705 | if (retval) { |
| 706 | cpus_clear(pr->performance->shared_cpu_map); |
| 707 | cpu_set(i, pr->performance->shared_cpu_map); |
| 708 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL; |
| 709 | } |
| 710 | pr->performance = NULL; /* Will be set for real in register */ |
| 711 | } |
| 712 | |
Len Brown | 785fccc | 2006-06-15 22:19:31 -0400 | [diff] [blame] | 713 | mutex_unlock(&performance_mutex); |
Len Brown | 9011bff4 | 2006-05-11 00:28:12 -0400 | [diff] [blame] | 714 | return retval; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 715 | } |
| 716 | EXPORT_SYMBOL(acpi_processor_preregister_performance); |
| 717 | |
| 718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 720 | acpi_processor_register_performance(struct acpi_processor_performance |
| 721 | *performance, unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
| 723 | struct acpi_processor *pr; |
| 724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
| 726 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 727 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 729 | mutex_lock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
| 731 | pr = processors[cpu]; |
| 732 | if (!pr) { |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 733 | mutex_unlock(&performance_mutex); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 734 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | if (pr->performance) { |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 738 | mutex_unlock(&performance_mutex); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 739 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Andrew Morton | a913f50 | 2006-06-10 09:54:13 -0700 | [diff] [blame] | 742 | WARN_ON(!performance); |
| 743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | pr->performance = performance; |
| 745 | |
| 746 | if (acpi_processor_get_performance_info(pr)) { |
| 747 | pr->performance = NULL; |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 748 | mutex_unlock(&performance_mutex); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 749 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | acpi_cpufreq_add_file(pr); |
| 753 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 754 | mutex_unlock(&performance_mutex); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 755 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | EXPORT_SYMBOL(acpi_processor_register_performance); |
| 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 761 | acpi_processor_unregister_performance(struct acpi_processor_performance |
| 762 | *performance, unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | { |
| 764 | struct acpi_processor *pr; |
| 765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 767 | mutex_lock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
| 769 | pr = processors[cpu]; |
| 770 | if (!pr) { |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 771 | mutex_unlock(&performance_mutex); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 772 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Andrew Morton | a913f50 | 2006-06-10 09:54:13 -0700 | [diff] [blame] | 775 | if (pr->performance) |
| 776 | kfree(pr->performance->states); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | pr->performance = NULL; |
| 778 | |
| 779 | acpi_cpufreq_remove_file(pr); |
| 780 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 781 | mutex_unlock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 783 | return; |
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_unregister_performance); |