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