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