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 | ||
34 | #ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF | |
35 | #include <linux/proc_fs.h> | |
36 | #include <linux/seq_file.h> | |
37 | ||
38 | #include <asm/uaccess.h> | |
39 | #endif | |
40 | ||
41 | #include <acpi/acpi_bus.h> | |
42 | #include <acpi/processor.h> | |
43 | ||
1da177e4 LT |
44 | #define ACPI_PROCESSOR_COMPONENT 0x01000000 |
45 | #define ACPI_PROCESSOR_CLASS "processor" | |
46 | #define ACPI_PROCESSOR_DRIVER_NAME "ACPI Processor Driver" | |
47 | #define ACPI_PROCESSOR_FILE_PERFORMANCE "performance" | |
48 | #define _COMPONENT ACPI_PROCESSOR_COMPONENT | |
4be44fcd | 49 | ACPI_MODULE_NAME("acpi_processor") |
1da177e4 LT |
50 | |
51 | static DECLARE_MUTEX(performance_sem); | |
52 | ||
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 | ||
63 | #define PPC_REGISTERED 1 | |
64 | #define PPC_IN_USE 2 | |
65 | ||
66 | static int acpi_processor_ppc_status = 0; | |
67 | ||
68 | static int acpi_processor_ppc_notifier(struct notifier_block *nb, | |
4be44fcd | 69 | unsigned long event, void *data) |
1da177e4 LT |
70 | { |
71 | struct cpufreq_policy *policy = data; | |
72 | struct acpi_processor *pr; | |
73 | unsigned int ppc = 0; | |
74 | ||
75 | down(&performance_sem); | |
76 | ||
77 | if (event != CPUFREQ_INCOMPATIBLE) | |
78 | goto out; | |
79 | ||
80 | pr = processors[policy->cpu]; | |
81 | if (!pr || !pr->performance) | |
82 | goto out; | |
83 | ||
4be44fcd | 84 | ppc = (unsigned int)pr->performance_platform_limit; |
1da177e4 LT |
85 | if (!ppc) |
86 | goto out; | |
87 | ||
88 | if (ppc > pr->performance->state_count) | |
89 | goto out; | |
90 | ||
91 | cpufreq_verify_within_limits(policy, 0, | |
4be44fcd LB |
92 | pr->performance->states[ppc]. |
93 | core_frequency * 1000); | |
1da177e4 | 94 | |
4be44fcd | 95 | out: |
1da177e4 LT |
96 | up(&performance_sem); |
97 | ||
98 | return 0; | |
99 | } | |
100 | ||
1da177e4 LT |
101 | static struct notifier_block acpi_ppc_notifier_block = { |
102 | .notifier_call = acpi_processor_ppc_notifier, | |
103 | }; | |
104 | ||
4be44fcd | 105 | static int acpi_processor_get_platform_limit(struct acpi_processor *pr) |
1da177e4 | 106 | { |
4be44fcd LB |
107 | acpi_status status = 0; |
108 | unsigned long ppc = 0; | |
1da177e4 LT |
109 | |
110 | ACPI_FUNCTION_TRACE("acpi_processor_get_platform_limit"); | |
111 | ||
112 | if (!pr) | |
113 | return_VALUE(-EINVAL); | |
114 | ||
115 | /* | |
116 | * _PPC indicates the maximum state currently supported by the platform | |
117 | * (e.g. 0 = states 0..n; 1 = states 1..n; etc. | |
118 | */ | |
119 | status = acpi_evaluate_integer(pr->handle, "_PPC", NULL, &ppc); | |
120 | ||
121 | if (status != AE_NOT_FOUND) | |
122 | acpi_processor_ppc_status |= PPC_IN_USE; | |
123 | ||
4be44fcd | 124 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
1da177e4 LT |
125 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PPC\n")); |
126 | return_VALUE(-ENODEV); | |
127 | } | |
128 | ||
4be44fcd | 129 | pr->performance_platform_limit = (int)ppc; |
1da177e4 LT |
130 | |
131 | return_VALUE(0); | |
132 | } | |
133 | ||
4be44fcd | 134 | int acpi_processor_ppc_has_changed(struct acpi_processor *pr) |
1da177e4 LT |
135 | { |
136 | int ret = acpi_processor_get_platform_limit(pr); | |
137 | if (ret < 0) | |
138 | return (ret); | |
139 | else | |
140 | return cpufreq_update_policy(pr->id); | |
141 | } | |
142 | ||
4be44fcd LB |
143 | void acpi_processor_ppc_init(void) |
144 | { | |
145 | if (!cpufreq_register_notifier | |
146 | (&acpi_ppc_notifier_block, CPUFREQ_POLICY_NOTIFIER)) | |
1da177e4 LT |
147 | acpi_processor_ppc_status |= PPC_REGISTERED; |
148 | else | |
4be44fcd LB |
149 | printk(KERN_DEBUG |
150 | "Warning: Processor Platform Limit not supported.\n"); | |
1da177e4 LT |
151 | } |
152 | ||
4be44fcd LB |
153 | void acpi_processor_ppc_exit(void) |
154 | { | |
1da177e4 | 155 | if (acpi_processor_ppc_status & PPC_REGISTERED) |
4be44fcd LB |
156 | cpufreq_unregister_notifier(&acpi_ppc_notifier_block, |
157 | CPUFREQ_POLICY_NOTIFIER); | |
1da177e4 LT |
158 | |
159 | acpi_processor_ppc_status &= ~PPC_REGISTERED; | |
160 | } | |
161 | ||
4be44fcd | 162 | static int acpi_processor_get_performance_control(struct acpi_processor *pr) |
1da177e4 | 163 | { |
4be44fcd LB |
164 | int result = 0; |
165 | acpi_status status = 0; | |
166 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
167 | union acpi_object *pct = NULL; | |
168 | union acpi_object obj = { 0 }; | |
1da177e4 LT |
169 | |
170 | ACPI_FUNCTION_TRACE("acpi_processor_get_performance_control"); | |
171 | ||
172 | status = acpi_evaluate_object(pr->handle, "_PCT", NULL, &buffer); | |
4be44fcd | 173 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
174 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PCT\n")); |
175 | return_VALUE(-ENODEV); | |
176 | } | |
177 | ||
4be44fcd | 178 | pct = (union acpi_object *)buffer.pointer; |
1da177e4 | 179 | if (!pct || (pct->type != ACPI_TYPE_PACKAGE) |
4be44fcd | 180 | || (pct->package.count != 2)) { |
1da177e4 LT |
181 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PCT data\n")); |
182 | result = -EFAULT; | |
183 | goto end; | |
184 | } | |
185 | ||
186 | /* | |
187 | * control_register | |
188 | */ | |
189 | ||
190 | obj = pct->package.elements[0]; | |
191 | ||
192 | if ((obj.type != ACPI_TYPE_BUFFER) | |
4be44fcd LB |
193 | || (obj.buffer.length < sizeof(struct acpi_pct_register)) |
194 | || (obj.buffer.pointer == NULL)) { | |
1da177e4 | 195 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
4be44fcd | 196 | "Invalid _PCT data (control_register)\n")); |
1da177e4 LT |
197 | result = -EFAULT; |
198 | goto end; | |
199 | } | |
4be44fcd LB |
200 | memcpy(&pr->performance->control_register, obj.buffer.pointer, |
201 | sizeof(struct acpi_pct_register)); | |
1da177e4 LT |
202 | |
203 | /* | |
204 | * status_register | |
205 | */ | |
206 | ||
207 | obj = pct->package.elements[1]; | |
208 | ||
209 | if ((obj.type != ACPI_TYPE_BUFFER) | |
4be44fcd LB |
210 | || (obj.buffer.length < sizeof(struct acpi_pct_register)) |
211 | || (obj.buffer.pointer == NULL)) { | |
1da177e4 | 212 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
4be44fcd | 213 | "Invalid _PCT data (status_register)\n")); |
1da177e4 LT |
214 | result = -EFAULT; |
215 | goto end; | |
216 | } | |
217 | ||
4be44fcd LB |
218 | memcpy(&pr->performance->status_register, obj.buffer.pointer, |
219 | sizeof(struct acpi_pct_register)); | |
1da177e4 | 220 | |
4be44fcd | 221 | end: |
1da177e4 LT |
222 | acpi_os_free(buffer.pointer); |
223 | ||
224 | return_VALUE(result); | |
225 | } | |
226 | ||
4be44fcd | 227 | static int acpi_processor_get_performance_states(struct acpi_processor *pr) |
1da177e4 | 228 | { |
4be44fcd LB |
229 | int result = 0; |
230 | acpi_status status = AE_OK; | |
231 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
232 | struct acpi_buffer format = { sizeof("NNNNNN"), "NNNNNN" }; | |
233 | struct acpi_buffer state = { 0, NULL }; | |
234 | union acpi_object *pss = NULL; | |
235 | int i; | |
1da177e4 LT |
236 | |
237 | ACPI_FUNCTION_TRACE("acpi_processor_get_performance_states"); | |
238 | ||
239 | status = acpi_evaluate_object(pr->handle, "_PSS", NULL, &buffer); | |
4be44fcd | 240 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
241 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error evaluating _PSS\n")); |
242 | return_VALUE(-ENODEV); | |
243 | } | |
244 | ||
4be44fcd | 245 | pss = (union acpi_object *)buffer.pointer; |
1da177e4 LT |
246 | if (!pss || (pss->type != ACPI_TYPE_PACKAGE)) { |
247 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid _PSS data\n")); | |
248 | result = -EFAULT; | |
249 | goto end; | |
250 | } | |
251 | ||
252 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Found %d performance states\n", | |
4be44fcd | 253 | pss->package.count)); |
1da177e4 LT |
254 | |
255 | pr->performance->state_count = pss->package.count; | |
4be44fcd LB |
256 | pr->performance->states = |
257 | kmalloc(sizeof(struct acpi_processor_px) * pss->package.count, | |
258 | GFP_KERNEL); | |
1da177e4 LT |
259 | if (!pr->performance->states) { |
260 | result = -ENOMEM; | |
261 | goto end; | |
262 | } | |
263 | ||
264 | for (i = 0; i < pr->performance->state_count; i++) { | |
265 | ||
266 | struct acpi_processor_px *px = &(pr->performance->states[i]); | |
267 | ||
268 | state.length = sizeof(struct acpi_processor_px); | |
269 | state.pointer = px; | |
270 | ||
271 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Extracting state %d\n", i)); | |
272 | ||
273 | status = acpi_extract_package(&(pss->package.elements[i]), | |
4be44fcd | 274 | &format, &state); |
1da177e4 | 275 | if (ACPI_FAILURE(status)) { |
4be44fcd LB |
276 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
277 | "Invalid _PSS data\n")); | |
1da177e4 LT |
278 | result = -EFAULT; |
279 | kfree(pr->performance->states); | |
280 | goto end; | |
281 | } | |
282 | ||
283 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd LB |
284 | "State [%d]: core_frequency[%d] power[%d] transition_latency[%d] bus_master_latency[%d] control[0x%x] status[0x%x]\n", |
285 | i, | |
286 | (u32) px->core_frequency, | |
287 | (u32) px->power, | |
288 | (u32) px->transition_latency, | |
289 | (u32) px->bus_master_latency, | |
290 | (u32) px->control, (u32) px->status)); | |
1da177e4 LT |
291 | |
292 | if (!px->core_frequency) { | |
4be44fcd LB |
293 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
294 | "Invalid _PSS data: freq is zero\n")); | |
1da177e4 LT |
295 | result = -EFAULT; |
296 | kfree(pr->performance->states); | |
297 | goto end; | |
298 | } | |
299 | } | |
300 | ||
4be44fcd | 301 | end: |
1da177e4 LT |
302 | acpi_os_free(buffer.pointer); |
303 | ||
304 | return_VALUE(result); | |
305 | } | |
306 | ||
4be44fcd | 307 | static int acpi_processor_get_performance_info(struct acpi_processor *pr) |
1da177e4 | 308 | { |
4be44fcd LB |
309 | int result = 0; |
310 | acpi_status status = AE_OK; | |
311 | acpi_handle handle = NULL; | |
1da177e4 LT |
312 | |
313 | ACPI_FUNCTION_TRACE("acpi_processor_get_performance_info"); | |
314 | ||
315 | if (!pr || !pr->performance || !pr->handle) | |
316 | return_VALUE(-EINVAL); | |
317 | ||
02df8b93 | 318 | acpi_processor_set_pdc(pr, pr->performance->pdc); |
1da177e4 LT |
319 | |
320 | status = acpi_get_handle(pr->handle, "_PCT", &handle); | |
321 | if (ACPI_FAILURE(status)) { | |
322 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 323 | "ACPI-based processor performance control unavailable\n")); |
1da177e4 LT |
324 | return_VALUE(-ENODEV); |
325 | } | |
326 | ||
327 | result = acpi_processor_get_performance_control(pr); | |
328 | if (result) | |
329 | return_VALUE(result); | |
330 | ||
331 | result = acpi_processor_get_performance_states(pr); | |
332 | if (result) | |
333 | return_VALUE(result); | |
334 | ||
335 | result = acpi_processor_get_platform_limit(pr); | |
336 | if (result) | |
337 | return_VALUE(result); | |
338 | ||
339 | return_VALUE(0); | |
340 | } | |
341 | ||
4be44fcd LB |
342 | int acpi_processor_notify_smm(struct module *calling_module) |
343 | { | |
344 | acpi_status status; | |
345 | static int is_done = 0; | |
1da177e4 LT |
346 | |
347 | ACPI_FUNCTION_TRACE("acpi_processor_notify_smm"); | |
348 | ||
349 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) | |
350 | return_VALUE(-EBUSY); | |
351 | ||
352 | if (!try_module_get(calling_module)) | |
353 | return_VALUE(-EINVAL); | |
354 | ||
355 | /* is_done is set to negative if an error occured, | |
356 | * and to postitive if _no_ error occured, but SMM | |
357 | * was already notified. This avoids double notification | |
358 | * which might lead to unexpected results... | |
359 | */ | |
360 | if (is_done > 0) { | |
361 | module_put(calling_module); | |
362 | return_VALUE(0); | |
4be44fcd | 363 | } else if (is_done < 0) { |
1da177e4 LT |
364 | module_put(calling_module); |
365 | return_VALUE(is_done); | |
366 | } | |
367 | ||
368 | is_done = -EIO; | |
369 | ||
370 | /* Can't write pstate_cnt to smi_cmd if either value is zero */ | |
4be44fcd LB |
371 | if ((!acpi_fadt.smi_cmd) || (!acpi_fadt.pstate_cnt)) { |
372 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No SMI port or pstate_cnt\n")); | |
1da177e4 LT |
373 | module_put(calling_module); |
374 | return_VALUE(0); | |
375 | } | |
376 | ||
4be44fcd LB |
377 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
378 | "Writing pstate_cnt [0x%x] to smi_cmd [0x%x]\n", | |
379 | acpi_fadt.pstate_cnt, acpi_fadt.smi_cmd)); | |
1da177e4 LT |
380 | |
381 | /* FADT v1 doesn't support pstate_cnt, many BIOS vendors use | |
382 | * it anyway, so we need to support it... */ | |
383 | if (acpi_fadt_is_v1) { | |
4be44fcd LB |
384 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
385 | "Using v1.0 FADT reserved value for pstate_cnt\n")); | |
1da177e4 LT |
386 | } |
387 | ||
4be44fcd LB |
388 | status = acpi_os_write_port(acpi_fadt.smi_cmd, |
389 | (u32) acpi_fadt.pstate_cnt, 8); | |
390 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
391 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
392 | "Failed to write pstate_cnt [0x%x] to " | |
4be44fcd LB |
393 | "smi_cmd [0x%x]\n", acpi_fadt.pstate_cnt, |
394 | acpi_fadt.smi_cmd)); | |
1da177e4 LT |
395 | module_put(calling_module); |
396 | return_VALUE(status); | |
397 | } | |
398 | ||
399 | /* Success. If there's no _PPC, we need to fear nothing, so | |
400 | * we can allow the cpufreq driver to be rmmod'ed. */ | |
401 | is_done = 1; | |
402 | ||
403 | if (!(acpi_processor_ppc_status & PPC_IN_USE)) | |
404 | module_put(calling_module); | |
405 | ||
406 | return_VALUE(0); | |
407 | } | |
1da177e4 | 408 | |
4be44fcd | 409 | EXPORT_SYMBOL(acpi_processor_notify_smm); |
1da177e4 LT |
410 | |
411 | #ifdef CONFIG_X86_ACPI_CPUFREQ_PROC_INTF | |
412 | /* /proc/acpi/processor/../performance interface (DEPRECATED) */ | |
413 | ||
414 | static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file); | |
415 | static struct file_operations acpi_processor_perf_fops = { | |
4be44fcd LB |
416 | .open = acpi_processor_perf_open_fs, |
417 | .read = seq_read, | |
418 | .llseek = seq_lseek, | |
419 | .release = single_release, | |
1da177e4 LT |
420 | }; |
421 | ||
422 | static int acpi_processor_perf_seq_show(struct seq_file *seq, void *offset) | |
423 | { | |
4be44fcd LB |
424 | struct acpi_processor *pr = (struct acpi_processor *)seq->private; |
425 | int i; | |
1da177e4 LT |
426 | |
427 | ACPI_FUNCTION_TRACE("acpi_processor_perf_seq_show"); | |
428 | ||
429 | if (!pr) | |
430 | goto end; | |
431 | ||
432 | if (!pr->performance) { | |
433 | seq_puts(seq, "<not supported>\n"); | |
434 | goto end; | |
435 | } | |
436 | ||
437 | seq_printf(seq, "state count: %d\n" | |
4be44fcd LB |
438 | "active state: P%d\n", |
439 | pr->performance->state_count, pr->performance->state); | |
1da177e4 LT |
440 | |
441 | seq_puts(seq, "states:\n"); | |
442 | for (i = 0; i < pr->performance->state_count; i++) | |
4be44fcd LB |
443 | seq_printf(seq, |
444 | " %cP%d: %d MHz, %d mW, %d uS\n", | |
445 | (i == pr->performance->state ? '*' : ' '), i, | |
446 | (u32) pr->performance->states[i].core_frequency, | |
447 | (u32) pr->performance->states[i].power, | |
448 | (u32) pr->performance->states[i].transition_latency); | |
449 | ||
450 | end: | |
1da177e4 LT |
451 | return_VALUE(0); |
452 | } | |
453 | ||
454 | static int acpi_processor_perf_open_fs(struct inode *inode, struct file *file) | |
455 | { | |
456 | return single_open(file, acpi_processor_perf_seq_show, | |
4be44fcd | 457 | PDE(inode)->data); |
1da177e4 LT |
458 | } |
459 | ||
460 | static ssize_t | |
4be44fcd LB |
461 | acpi_processor_write_performance(struct file *file, |
462 | const char __user * buffer, | |
463 | size_t count, loff_t * data) | |
1da177e4 | 464 | { |
4be44fcd LB |
465 | int result = 0; |
466 | struct seq_file *m = (struct seq_file *)file->private_data; | |
467 | struct acpi_processor *pr = (struct acpi_processor *)m->private; | |
1da177e4 | 468 | struct acpi_processor_performance *perf; |
4be44fcd LB |
469 | char state_string[12] = { '\0' }; |
470 | unsigned int new_state = 0; | |
471 | struct cpufreq_policy policy; | |
1da177e4 LT |
472 | |
473 | ACPI_FUNCTION_TRACE("acpi_processor_write_performance"); | |
474 | ||
475 | if (!pr || (count > sizeof(state_string) - 1)) | |
476 | return_VALUE(-EINVAL); | |
477 | ||
478 | perf = pr->performance; | |
479 | if (!perf) | |
480 | return_VALUE(-EINVAL); | |
481 | ||
482 | if (copy_from_user(state_string, buffer, count)) | |
483 | return_VALUE(-EFAULT); | |
484 | ||
485 | state_string[count] = '\0'; | |
486 | new_state = simple_strtoul(state_string, NULL, 0); | |
487 | ||
488 | if (new_state >= perf->state_count) | |
489 | return_VALUE(-EINVAL); | |
490 | ||
491 | cpufreq_get_policy(&policy, pr->id); | |
492 | ||
493 | policy.cpu = pr->id; | |
494 | policy.min = perf->states[new_state].core_frequency * 1000; | |
495 | policy.max = perf->states[new_state].core_frequency * 1000; | |
496 | ||
497 | result = cpufreq_set_policy(&policy); | |
498 | if (result) | |
499 | return_VALUE(result); | |
500 | ||
501 | return_VALUE(count); | |
502 | } | |
503 | ||
4be44fcd | 504 | static void acpi_cpufreq_add_file(struct acpi_processor *pr) |
1da177e4 | 505 | { |
4be44fcd LB |
506 | struct proc_dir_entry *entry = NULL; |
507 | struct acpi_device *device = NULL; | |
1da177e4 LT |
508 | |
509 | ACPI_FUNCTION_TRACE("acpi_cpufreq_addfile"); | |
510 | ||
511 | if (acpi_bus_get_device(pr->handle, &device)) | |
512 | return_VOID; | |
513 | ||
514 | /* add file 'performance' [R/W] */ | |
515 | entry = create_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE, | |
4be44fcd LB |
516 | S_IFREG | S_IRUGO | S_IWUSR, |
517 | acpi_device_dir(device)); | |
1da177e4 LT |
518 | if (!entry) |
519 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | |
4be44fcd LB |
520 | "Unable to create '%s' fs entry\n", |
521 | ACPI_PROCESSOR_FILE_PERFORMANCE)); | |
1da177e4 LT |
522 | else { |
523 | entry->proc_fops = &acpi_processor_perf_fops; | |
524 | entry->proc_fops->write = acpi_processor_write_performance; | |
525 | entry->data = acpi_driver_data(device); | |
526 | entry->owner = THIS_MODULE; | |
527 | } | |
528 | return_VOID; | |
529 | } | |
530 | ||
4be44fcd | 531 | static void acpi_cpufreq_remove_file(struct acpi_processor *pr) |
1da177e4 | 532 | { |
4be44fcd | 533 | struct acpi_device *device = NULL; |
1da177e4 LT |
534 | |
535 | ACPI_FUNCTION_TRACE("acpi_cpufreq_addfile"); | |
536 | ||
537 | if (acpi_bus_get_device(pr->handle, &device)) | |
538 | return_VOID; | |
539 | ||
540 | /* remove file 'performance' */ | |
541 | remove_proc_entry(ACPI_PROCESSOR_FILE_PERFORMANCE, | |
4be44fcd | 542 | acpi_device_dir(device)); |
1da177e4 LT |
543 | |
544 | return_VOID; | |
545 | } | |
546 | ||
547 | #else | |
4be44fcd LB |
548 | static void acpi_cpufreq_add_file(struct acpi_processor *pr) |
549 | { | |
550 | return; | |
551 | } | |
552 | static void acpi_cpufreq_remove_file(struct acpi_processor *pr) | |
553 | { | |
554 | return; | |
555 | } | |
556 | #endif /* CONFIG_X86_ACPI_CPUFREQ_PROC_INTF */ | |
1da177e4 LT |
557 | |
558 | int | |
4be44fcd LB |
559 | acpi_processor_register_performance(struct acpi_processor_performance |
560 | *performance, unsigned int cpu) | |
1da177e4 LT |
561 | { |
562 | struct acpi_processor *pr; | |
563 | ||
564 | ACPI_FUNCTION_TRACE("acpi_processor_register_performance"); | |
565 | ||
566 | if (!(acpi_processor_ppc_status & PPC_REGISTERED)) | |
567 | return_VALUE(-EINVAL); | |
568 | ||
569 | down(&performance_sem); | |
570 | ||
571 | pr = processors[cpu]; | |
572 | if (!pr) { | |
573 | up(&performance_sem); | |
574 | return_VALUE(-ENODEV); | |
575 | } | |
576 | ||
577 | if (pr->performance) { | |
578 | up(&performance_sem); | |
579 | return_VALUE(-EBUSY); | |
580 | } | |
581 | ||
582 | pr->performance = performance; | |
583 | ||
584 | if (acpi_processor_get_performance_info(pr)) { | |
585 | pr->performance = NULL; | |
586 | up(&performance_sem); | |
587 | return_VALUE(-EIO); | |
588 | } | |
589 | ||
590 | acpi_cpufreq_add_file(pr); | |
591 | ||
592 | up(&performance_sem); | |
593 | return_VALUE(0); | |
594 | } | |
1da177e4 | 595 | |
4be44fcd | 596 | EXPORT_SYMBOL(acpi_processor_register_performance); |
1da177e4 LT |
597 | |
598 | void | |
4be44fcd LB |
599 | acpi_processor_unregister_performance(struct acpi_processor_performance |
600 | *performance, unsigned int cpu) | |
1da177e4 LT |
601 | { |
602 | struct acpi_processor *pr; | |
603 | ||
604 | ACPI_FUNCTION_TRACE("acpi_processor_unregister_performance"); | |
605 | ||
606 | down(&performance_sem); | |
607 | ||
608 | pr = processors[cpu]; | |
609 | if (!pr) { | |
610 | up(&performance_sem); | |
611 | return_VOID; | |
612 | } | |
613 | ||
614 | kfree(pr->performance->states); | |
615 | pr->performance = NULL; | |
616 | ||
617 | acpi_cpufreq_remove_file(pr); | |
618 | ||
619 | up(&performance_sem); | |
620 | ||
621 | return_VOID; | |
622 | } | |
4be44fcd | 623 | |
1da177e4 | 624 | EXPORT_SYMBOL(acpi_processor_unregister_performance); |