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