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