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