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 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 155 | int acpi_processor_ppc_has_changed(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Thomas Renninger | 623b78c | 2007-05-18 21:59:28 -0500 | [diff] [blame] | 157 | int ret; |
| 158 | |
| 159 | if (ignore_ppc) |
| 160 | return 0; |
| 161 | |
| 162 | ret = acpi_processor_get_platform_limit(pr); |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | if (ret < 0) |
| 165 | return (ret); |
| 166 | else |
| 167 | return cpufreq_update_policy(pr->id); |
| 168 | } |
| 169 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | void acpi_processor_ppc_init(void) |
| 171 | { |
| 172 | if (!cpufreq_register_notifier |
| 173 | (&acpi_ppc_notifier_block, CPUFREQ_POLICY_NOTIFIER)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | acpi_processor_ppc_status |= PPC_REGISTERED; |
| 175 | else |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | printk(KERN_DEBUG |
| 177 | "Warning: Processor Platform Limit not supported.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 180 | void acpi_processor_ppc_exit(void) |
| 181 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | if (acpi_processor_ppc_status & PPC_REGISTERED) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 183 | cpufreq_unregister_notifier(&acpi_ppc_notifier_block, |
| 184 | CPUFREQ_POLICY_NOTIFIER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | acpi_processor_ppc_status &= ~PPC_REGISTERED; |
| 187 | } |
| 188 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 189 | static int acpi_processor_get_performance_control(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 191 | int result = 0; |
| 192 | acpi_status status = 0; |
| 193 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 194 | union acpi_object *pct = NULL; |
| 195 | union acpi_object obj = { 0 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 199 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 200 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PCT")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 201 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | pct = (union acpi_object *)buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | if (!pct || (pct->type != ACPI_TYPE_PACKAGE) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | || (pct->package.count != 2)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 207 | printk(KERN_ERR PREFIX "Invalid _PCT data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | result = -EFAULT; |
| 209 | goto end; |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | * control_register |
| 214 | */ |
| 215 | |
| 216 | obj = pct->package.elements[0]; |
| 217 | |
| 218 | if ((obj.type != ACPI_TYPE_BUFFER) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | || (obj.buffer.length < sizeof(struct acpi_pct_register)) |
| 220 | || (obj.buffer.pointer == NULL)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 221 | printk(KERN_ERR PREFIX "Invalid _PCT data (control_register)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | result = -EFAULT; |
| 223 | goto end; |
| 224 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | memcpy(&pr->performance->control_register, obj.buffer.pointer, |
| 226 | sizeof(struct acpi_pct_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | /* |
| 229 | * status_register |
| 230 | */ |
| 231 | |
| 232 | obj = pct->package.elements[1]; |
| 233 | |
| 234 | if ((obj.type != ACPI_TYPE_BUFFER) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 235 | || (obj.buffer.length < sizeof(struct acpi_pct_register)) |
| 236 | || (obj.buffer.pointer == NULL)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 237 | printk(KERN_ERR PREFIX "Invalid _PCT data (status_register)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | result = -EFAULT; |
| 239 | goto end; |
| 240 | } |
| 241 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | memcpy(&pr->performance->status_register, obj.buffer.pointer, |
| 243 | sizeof(struct acpi_pct_register)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 245 | end: |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 246 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 248 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 251 | static int acpi_processor_get_performance_states(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | int result = 0; |
| 254 | acpi_status status = AE_OK; |
| 255 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 256 | struct acpi_buffer format = { sizeof("NNNNNN"), "NNNNNN" }; |
| 257 | struct acpi_buffer state = { 0, NULL }; |
| 258 | union acpi_object *pss = NULL; |
| 259 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 263 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 264 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PSS")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 265 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 268 | pss = buffer.pointer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 270 | printk(KERN_ERR PREFIX "Invalid _PSS data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | result = -EFAULT; |
| 272 | goto end; |
| 273 | } |
| 274 | |
| 275 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d performance states\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 276 | pss->package.count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | pr->performance->state_count = pss->package.count; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 279 | pr->performance->states = |
| 280 | kmalloc(sizeof(struct acpi_processor_px) * pss->package.count, |
| 281 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (!pr->performance->states) { |
| 283 | result = -ENOMEM; |
| 284 | goto end; |
| 285 | } |
| 286 | |
| 287 | for (i = 0; i < pr->performance->state_count; i++) { |
| 288 | |
| 289 | struct acpi_processor_px *px = &(pr->performance->states[i]); |
| 290 | |
| 291 | state.length = sizeof(struct acpi_processor_px); |
| 292 | state.pointer = px; |
| 293 | |
| 294 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i)); |
| 295 | |
| 296 | status = acpi_extract_package(&(pss->package.elements[i]), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | &format, &state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 299 | ACPI_EXCEPTION((AE_INFO, status, "Invalid _PSS data")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | result = -EFAULT; |
| 301 | kfree(pr->performance->states); |
| 302 | goto end; |
| 303 | } |
| 304 | |
| 305 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 306 | "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n", |
| 307 | i, |
| 308 | (u32) px->core_frequency, |
| 309 | (u32) px->power, |
| 310 | (u32) px->transition_latency, |
| 311 | (u32) px->bus_master_latency, |
| 312 | (u32) px->control, (u32) px->status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
Len Brown | 34d531e | 2009-05-26 15:11:06 -0400 | [diff] [blame] | 314 | /* |
| 315 | * Check that ACPI's u64 MHz will be valid as u32 KHz in cpufreq |
| 316 | */ |
| 317 | if (!px->core_frequency || |
| 318 | ((u32)(px->core_frequency * 1000) != |
| 319 | (px->core_frequency * 1000))) { |
| 320 | printk(KERN_ERR FW_BUG PREFIX |
| 321 | "Invalid BIOS _PSS frequency: 0x%llx MHz\n", |
| 322 | px->core_frequency); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | result = -EFAULT; |
| 324 | kfree(pr->performance->states); |
| 325 | goto end; |
| 326 | } |
| 327 | } |
| 328 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | end: |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 330 | kfree(buffer.pointer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 332 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 335 | static int acpi_processor_get_performance_info(struct acpi_processor *pr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | int result = 0; |
| 338 | acpi_status status = AE_OK; |
| 339 | acpi_handle handle = NULL; |
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 | if (!pr || !pr->performance || !pr->handle) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 342 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | status = acpi_get_handle(pr->handle, "_PCT", &handle); |
| 345 | if (ACPI_FAILURE(status)) { |
| 346 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 347 | "ACPI-based processor performance control unavailable\n")); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 348 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | result = acpi_processor_get_performance_control(pr); |
| 352 | if (result) |
Thomas Renninger | 910dfae | 2008-09-01 14:27:04 +0200 | [diff] [blame] | 353 | goto update_bios; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | result = acpi_processor_get_performance_states(pr); |
| 356 | if (result) |
Thomas Renninger | 910dfae | 2008-09-01 14:27:04 +0200 | [diff] [blame] | 357 | goto update_bios; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 359 | return 0; |
Thomas Renninger | 910dfae | 2008-09-01 14:27:04 +0200 | [diff] [blame] | 360 | |
| 361 | /* |
| 362 | * Having _PPC but missing frequencies (_PSS, _PCT) is a very good hint that |
| 363 | * the BIOS is older than the CPU and does not know its frequencies |
| 364 | */ |
| 365 | update_bios: |
Miao Xie | 16be87e | 2008-10-24 17:22:04 +0800 | [diff] [blame] | 366 | #ifdef CONFIG_X86 |
Thomas Renninger | 910dfae | 2008-09-01 14:27:04 +0200 | [diff] [blame] | 367 | if (ACPI_SUCCESS(acpi_get_handle(pr->handle, "_PPC", &handle))){ |
| 368 | if(boot_cpu_has(X86_FEATURE_EST)) |
| 369 | printk(KERN_WARNING FW_BUG "BIOS needs update for CPU " |
| 370 | "frequency support\n"); |
| 371 | } |
Miao Xie | 16be87e | 2008-10-24 17:22:04 +0800 | [diff] [blame] | 372 | #endif |
Thomas Renninger | 910dfae | 2008-09-01 14:27:04 +0200 | [diff] [blame] | 373 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 376 | int acpi_processor_notify_smm(struct module *calling_module) |
| 377 | { |
| 378 | acpi_status status; |
| 379 | static int is_done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
| 382 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 383 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
| 385 | if (!try_module_get(calling_module)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 386 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
| 388 | /* is_done is set to negative if an error occured, |
| 389 | * and to postitive if _no_ error occured, but SMM |
| 390 | * was already notified. This avoids double notification |
| 391 | * which might lead to unexpected results... |
| 392 | */ |
| 393 | if (is_done > 0) { |
| 394 | module_put(calling_module); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 395 | return 0; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 396 | } else if (is_done < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | module_put(calling_module); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 398 | return is_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | is_done = -EIO; |
| 402 | |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 403 | /* 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] | 404 | if ((!acpi_gbl_FADT.smi_command) || (!acpi_gbl_FADT.pstate_control)) { |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 405 | 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] | 406 | module_put(calling_module); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 407 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 410 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 411 | "Writing pstate_control [0x%x] to smi_command [0x%x]\n", |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 412 | acpi_gbl_FADT.pstate_control, acpi_gbl_FADT.smi_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 414 | status = acpi_os_write_port(acpi_gbl_FADT.smi_command, |
| 415 | (u32) acpi_gbl_FADT.pstate_control, 8); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | if (ACPI_FAILURE(status)) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 417 | ACPI_EXCEPTION((AE_INFO, status, |
Alexey Starikovskiy | ad71860a | 2007-02-02 19:48:19 +0300 | [diff] [blame] | 418 | "Failed to write pstate_control [0x%x] to " |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 419 | "smi_command [0x%x]", acpi_gbl_FADT.pstate_control, |
| 420 | acpi_gbl_FADT.smi_command)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | module_put(calling_module); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 422 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /* Success. If there's no _PPC, we need to fear nothing, so |
| 426 | * we can allow the cpufreq driver to be rmmod'ed. */ |
| 427 | is_done = 1; |
| 428 | |
| 429 | if (!(acpi_processor_ppc_status & PPC_IN_USE)) |
| 430 | module_put(calling_module); |
| 431 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 432 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 435 | EXPORT_SYMBOL(acpi_processor_notify_smm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 437 | static int acpi_processor_get_psd(struct acpi_processor *pr) |
| 438 | { |
| 439 | int result = 0; |
| 440 | acpi_status status = AE_OK; |
| 441 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 442 | struct acpi_buffer format = {sizeof("NNNNN"), "NNNNN"}; |
| 443 | struct acpi_buffer state = {0, NULL}; |
| 444 | union acpi_object *psd = NULL; |
| 445 | struct acpi_psd_package *pdomain; |
| 446 | |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 447 | status = acpi_evaluate_object(pr->handle, "_PSD", NULL, &buffer); |
| 448 | if (ACPI_FAILURE(status)) { |
Len Brown | 9011bff4 | 2006-05-11 00:28:12 -0400 | [diff] [blame] | 449 | return -ENODEV; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 450 | } |
| 451 | |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 452 | psd = buffer.pointer; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 453 | if (!psd || (psd->type != ACPI_TYPE_PACKAGE)) { |
Lin Ming | 55ac9a0 | 2008-09-28 14:51:56 +0800 | [diff] [blame] | 454 | printk(KERN_ERR PREFIX "Invalid _PSD data\n"); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 455 | result = -EFAULT; |
| 456 | goto end; |
| 457 | } |
| 458 | |
| 459 | if (psd->package.count != 1) { |
Lin Ming | 55ac9a0 | 2008-09-28 14:51:56 +0800 | [diff] [blame] | 460 | printk(KERN_ERR PREFIX "Invalid _PSD data\n"); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 461 | result = -EFAULT; |
| 462 | goto end; |
| 463 | } |
| 464 | |
| 465 | pdomain = &(pr->performance->domain_info); |
| 466 | |
| 467 | state.length = sizeof(struct acpi_psd_package); |
| 468 | state.pointer = pdomain; |
| 469 | |
| 470 | status = acpi_extract_package(&(psd->package.elements[0]), |
| 471 | &format, &state); |
| 472 | if (ACPI_FAILURE(status)) { |
Lin Ming | 55ac9a0 | 2008-09-28 14:51:56 +0800 | [diff] [blame] | 473 | printk(KERN_ERR PREFIX "Invalid _PSD data\n"); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 474 | result = -EFAULT; |
| 475 | goto end; |
| 476 | } |
| 477 | |
| 478 | if (pdomain->num_entries != ACPI_PSD_REV0_ENTRIES) { |
Lin Ming | 55ac9a0 | 2008-09-28 14:51:56 +0800 | [diff] [blame] | 479 | printk(KERN_ERR PREFIX "Unknown _PSD:num_entries\n"); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 480 | result = -EFAULT; |
| 481 | goto end; |
| 482 | } |
| 483 | |
| 484 | if (pdomain->revision != ACPI_PSD_REV0_REVISION) { |
Lin Ming | 55ac9a0 | 2008-09-28 14:51:56 +0800 | [diff] [blame] | 485 | printk(KERN_ERR PREFIX "Unknown _PSD:revision\n"); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 486 | result = -EFAULT; |
| 487 | goto end; |
| 488 | } |
| 489 | |
Stanislaw Gruszka | e1eb477 | 2009-03-24 13:41:59 +0100 | [diff] [blame] | 490 | if (pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ALL && |
| 491 | pdomain->coord_type != DOMAIN_COORD_TYPE_SW_ANY && |
| 492 | pdomain->coord_type != DOMAIN_COORD_TYPE_HW_ALL) { |
| 493 | printk(KERN_ERR PREFIX "Invalid _PSD:coord_type\n"); |
| 494 | result = -EFAULT; |
| 495 | goto end; |
| 496 | } |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 497 | end: |
Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 498 | kfree(buffer.pointer); |
Len Brown | 9011bff4 | 2006-05-11 00:28:12 -0400 | [diff] [blame] | 499 | return result; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | int acpi_processor_preregister_performance( |
Fenghua Yu | 5010929 | 2007-08-07 18:40:30 -0400 | [diff] [blame] | 503 | struct acpi_processor_performance *performance) |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 504 | { |
| 505 | int count, count_target; |
| 506 | int retval = 0; |
| 507 | unsigned int i, j; |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 508 | cpumask_var_t covered_cpus; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 509 | struct acpi_processor *pr; |
| 510 | struct acpi_psd_package *pdomain; |
| 511 | struct acpi_processor *match_pr; |
| 512 | struct acpi_psd_package *match_pdomain; |
| 513 | |
Li Zefan | 79f5599 | 2009-06-15 14:58:26 +0800 | [diff] [blame] | 514 | if (!zalloc_cpumask_var(&covered_cpus, GFP_KERNEL)) |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 515 | return -ENOMEM; |
| 516 | |
Len Brown | 785fccc | 2006-06-15 22:19:31 -0400 | [diff] [blame] | 517 | mutex_lock(&performance_mutex); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 518 | |
Stanislaw Gruszka | e1eb477 | 2009-03-24 13:41:59 +0100 | [diff] [blame] | 519 | /* |
| 520 | * Check if another driver has already registered, and abort before |
| 521 | * changing pr->performance if it has. Check input data as well. |
| 522 | */ |
KAMEZAWA Hiroyuki | 193de0c | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 523 | for_each_possible_cpu(i) { |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 524 | pr = per_cpu(processors, i); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 525 | if (!pr) { |
| 526 | /* Look only at processors in ACPI namespace */ |
| 527 | continue; |
| 528 | } |
| 529 | |
| 530 | if (pr->performance) { |
| 531 | retval = -EBUSY; |
Stanislaw Gruszka | e1eb477 | 2009-03-24 13:41:59 +0100 | [diff] [blame] | 532 | goto err_out; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 533 | } |
| 534 | |
Rusty Russell | b36128c | 2009-02-20 16:29:08 +0900 | [diff] [blame] | 535 | if (!performance || !per_cpu_ptr(performance, i)) { |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 536 | retval = -EINVAL; |
Stanislaw Gruszka | e1eb477 | 2009-03-24 13:41:59 +0100 | [diff] [blame] | 537 | goto err_out; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 538 | } |
Stanislaw Gruszka | e1eb477 | 2009-03-24 13:41:59 +0100 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /* Call _PSD for all CPUs */ |
| 542 | for_each_possible_cpu(i) { |
| 543 | pr = per_cpu(processors, i); |
| 544 | if (!pr) |
| 545 | continue; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 546 | |
Rusty Russell | b36128c | 2009-02-20 16:29:08 +0900 | [diff] [blame] | 547 | pr->performance = per_cpu_ptr(performance, i); |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 548 | cpumask_set_cpu(i, pr->performance->shared_cpu_map); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 549 | if (acpi_processor_get_psd(pr)) { |
| 550 | retval = -EINVAL; |
| 551 | continue; |
| 552 | } |
| 553 | } |
| 554 | if (retval) |
| 555 | goto err_ret; |
| 556 | |
| 557 | /* |
| 558 | * Now that we have _PSD data from all CPUs, lets setup P-state |
| 559 | * domain info. |
| 560 | */ |
KAMEZAWA Hiroyuki | 193de0c | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 561 | for_each_possible_cpu(i) { |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 562 | pr = per_cpu(processors, i); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 563 | if (!pr) |
| 564 | continue; |
| 565 | |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 566 | if (cpumask_test_cpu(i, covered_cpus)) |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 567 | continue; |
| 568 | |
| 569 | pdomain = &(pr->performance->domain_info); |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 570 | cpumask_set_cpu(i, pr->performance->shared_cpu_map); |
| 571 | cpumask_set_cpu(i, covered_cpus); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 572 | if (pdomain->num_processors <= 1) |
| 573 | continue; |
| 574 | |
| 575 | /* Validate the Domain info */ |
| 576 | count_target = pdomain->num_processors; |
| 577 | count = 1; |
Venkatesh Pallipadi | 46f18e3 | 2006-06-26 00:34:43 -0400 | [diff] [blame] | 578 | if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ALL) |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 579 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL; |
Venkatesh Pallipadi | 46f18e3 | 2006-06-26 00:34:43 -0400 | [diff] [blame] | 580 | else if (pdomain->coord_type == DOMAIN_COORD_TYPE_HW_ALL) |
| 581 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_HW; |
| 582 | else if (pdomain->coord_type == DOMAIN_COORD_TYPE_SW_ANY) |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 583 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ANY; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 584 | |
KAMEZAWA Hiroyuki | 193de0c | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 585 | for_each_possible_cpu(j) { |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 586 | if (i == j) |
| 587 | continue; |
| 588 | |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 589 | match_pr = per_cpu(processors, j); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 590 | if (!match_pr) |
| 591 | continue; |
| 592 | |
| 593 | match_pdomain = &(match_pr->performance->domain_info); |
| 594 | if (match_pdomain->domain != pdomain->domain) |
| 595 | continue; |
| 596 | |
| 597 | /* Here i and j are in the same domain */ |
| 598 | |
| 599 | if (match_pdomain->num_processors != count_target) { |
| 600 | retval = -EINVAL; |
| 601 | goto err_ret; |
| 602 | } |
| 603 | |
| 604 | if (pdomain->coord_type != match_pdomain->coord_type) { |
| 605 | retval = -EINVAL; |
| 606 | goto err_ret; |
| 607 | } |
| 608 | |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 609 | cpumask_set_cpu(j, covered_cpus); |
| 610 | cpumask_set_cpu(j, pr->performance->shared_cpu_map); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 611 | count++; |
| 612 | } |
| 613 | |
KAMEZAWA Hiroyuki | 193de0c | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 614 | for_each_possible_cpu(j) { |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 615 | if (i == j) |
| 616 | continue; |
| 617 | |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 618 | match_pr = per_cpu(processors, j); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 619 | if (!match_pr) |
| 620 | continue; |
| 621 | |
| 622 | match_pdomain = &(match_pr->performance->domain_info); |
| 623 | if (match_pdomain->domain != pdomain->domain) |
| 624 | continue; |
| 625 | |
| 626 | match_pr->performance->shared_type = |
| 627 | pr->performance->shared_type; |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 628 | cpumask_copy(match_pr->performance->shared_cpu_map, |
| 629 | pr->performance->shared_cpu_map); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | |
| 633 | err_ret: |
KAMEZAWA Hiroyuki | 193de0c | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 634 | for_each_possible_cpu(i) { |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 635 | pr = per_cpu(processors, i); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 636 | if (!pr || !pr->performance) |
| 637 | continue; |
| 638 | |
| 639 | /* Assume no coordination on any error parsing domain info */ |
| 640 | if (retval) { |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 641 | cpumask_clear(pr->performance->shared_cpu_map); |
| 642 | cpumask_set_cpu(i, pr->performance->shared_cpu_map); |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 643 | pr->performance->shared_type = CPUFREQ_SHARED_TYPE_ALL; |
| 644 | } |
| 645 | pr->performance = NULL; /* Will be set for real in register */ |
| 646 | } |
| 647 | |
Stanislaw Gruszka | e1eb477 | 2009-03-24 13:41:59 +0100 | [diff] [blame] | 648 | err_out: |
Len Brown | 785fccc | 2006-06-15 22:19:31 -0400 | [diff] [blame] | 649 | mutex_unlock(&performance_mutex); |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 650 | free_cpumask_var(covered_cpus); |
Len Brown | 9011bff4 | 2006-05-11 00:28:12 -0400 | [diff] [blame] | 651 | return retval; |
Venkatesh Pallipadi | 3b2d994 | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 652 | } |
| 653 | EXPORT_SYMBOL(acpi_processor_preregister_performance); |
| 654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | int |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 656 | acpi_processor_register_performance(struct acpi_processor_performance |
| 657 | *performance, unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | { |
| 659 | struct acpi_processor *pr; |
| 660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 662 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 664 | mutex_lock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 666 | pr = per_cpu(processors, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | if (!pr) { |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 668 | mutex_unlock(&performance_mutex); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 669 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | if (pr->performance) { |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 673 | mutex_unlock(&performance_mutex); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 674 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Andrew Morton | a913f50 | 2006-06-10 09:54:13 -0700 | [diff] [blame] | 677 | WARN_ON(!performance); |
| 678 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | pr->performance = performance; |
| 680 | |
| 681 | if (acpi_processor_get_performance_info(pr)) { |
| 682 | pr->performance = NULL; |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 683 | mutex_unlock(&performance_mutex); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 684 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 687 | mutex_unlock(&performance_mutex); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 688 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 690 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | EXPORT_SYMBOL(acpi_processor_register_performance); |
| 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 694 | acpi_processor_unregister_performance(struct acpi_processor_performance |
| 695 | *performance, unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { |
| 697 | struct acpi_processor *pr; |
| 698 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 699 | mutex_lock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Mike Travis | 706546d | 2008-06-09 16:22:23 -0700 | [diff] [blame] | 701 | pr = per_cpu(processors, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | if (!pr) { |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 703 | mutex_unlock(&performance_mutex); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 704 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Andrew Morton | a913f50 | 2006-06-10 09:54:13 -0700 | [diff] [blame] | 707 | if (pr->performance) |
| 708 | kfree(pr->performance->states); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | pr->performance = NULL; |
| 710 | |
Arjan van de Ven | 65c19bb | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 711 | mutex_unlock(&performance_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 713 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | EXPORT_SYMBOL(acpi_processor_unregister_performance); |