2 * linux/drivers/cpufreq/proc_intf.c
4 * Copyright (C) 2002 - 2003 Dominik Brodowski
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/init.h>
10 #include <linux/cpufreq.h>
11 #include <linux/ctype.h>
12 #include <linux/proc_fs.h>
13 #include <asm/uaccess.h>
15 #warning This module will be removed from the 2.6. kernel series soon after 2005-01-01
17 #define CPUFREQ_ALL_CPUS ((NR_CPUS))
19 static unsigned int warning_print
= 0;
22 * cpufreq_parse_policy - parse a policy string
23 * @input_string: the string to parse.
24 * @policy: the policy written inside input_string
26 * This function parses a "policy string" - something the user echo'es into
27 * /proc/cpufreq or gives as boot parameter - into a struct cpufreq_policy.
28 * If there are invalid/missing entries, they are replaced with current
31 static int cpufreq_parse_policy(char input_string
[42], struct cpufreq_policy
*policy
)
36 char str_governor
[16];
37 struct cpufreq_policy current_policy
;
38 unsigned int result
= -EFAULT
;
46 policy
->cpu
= CPUFREQ_ALL_CPUS
;
48 if (sscanf(input_string
, "%d:%d:%d:%15s", &cpu
, &min
, &max
, str_governor
) == 4)
56 if (sscanf(input_string
, "%d%%%d%%%d%%%15s", &cpu
, &min
, &max
, str_governor
) == 4)
58 if (!cpufreq_get_policy(¤t_policy
, cpu
)) {
59 policy
->min
= (min
* current_policy
.cpuinfo
.max_freq
) / 100;
60 policy
->max
= (max
* current_policy
.cpuinfo
.max_freq
) / 100;
67 if (sscanf(input_string
, "%d:%d:%15s", &min
, &max
, str_governor
) == 3)
75 if (sscanf(input_string
, "%d%%%d%%%15s", &min
, &max
, str_governor
) == 3)
77 if (!cpufreq_get_policy(¤t_policy
, cpu
)) {
78 policy
->min
= (min
* current_policy
.cpuinfo
.max_freq
) / 100;
79 policy
->max
= (max
* current_policy
.cpuinfo
.max_freq
) / 100;
88 result
= cpufreq_parse_governor(str_governor
, &policy
->policy
, &policy
->governor
);
94 * cpufreq_proc_read - read /proc/cpufreq
96 * This function prints out the current cpufreq policy.
98 static int cpufreq_proc_read (
108 struct cpufreq_policy policy
;
109 unsigned int min_pctg
= 0;
110 unsigned int max_pctg
= 0;
116 if (!warning_print
) {
118 printk(KERN_INFO
"Access to /proc/cpufreq is deprecated and "
119 "will be removed from (new) 2.6. kernels soon "
120 "after 2005-01-01\n");
123 p
+= sprintf(p
, " minimum CPU frequency - maximum CPU frequency - policy\n");
124 for (i
=0;i
<NR_CPUS
;i
++) {
128 if (cpufreq_get_policy(&policy
, i
))
131 if (!policy
.cpuinfo
.max_freq
)
134 min_pctg
= (policy
.min
* 100) / policy
.cpuinfo
.max_freq
;
135 max_pctg
= (policy
.max
* 100) / policy
.cpuinfo
.max_freq
;
137 p
+= sprintf(p
, "CPU%3d %9d kHz (%3d %%) - %9d kHz (%3d %%) - ",
138 i
, policy
.min
, min_pctg
, policy
.max
, max_pctg
);
140 switch (policy
.policy
) {
141 case CPUFREQ_POLICY_POWERSAVE
:
142 p
+= sprintf(p
, "powersave\n");
144 case CPUFREQ_POLICY_PERFORMANCE
:
145 p
+= sprintf(p
, "performance\n");
148 p
+= sprintf(p
, "INVALID\n");
152 p
+= scnprintf(p
, CPUFREQ_NAME_LEN
, "%s\n", policy
.governor
->name
);
156 if (len
<= off
+count
)
170 * cpufreq_proc_write - handles writing into /proc/cpufreq
172 * This function calls the parsing script and then sets the policy
175 static int cpufreq_proc_write (
177 const char __user
*buffer
,
182 char proc_string
[42] = {'\0'};
183 struct cpufreq_policy policy
;
187 if ((count
> sizeof(proc_string
) - 1))
190 if (copy_from_user(proc_string
, buffer
, count
))
193 if (!warning_print
) {
195 printk(KERN_INFO
"Access to /proc/cpufreq is deprecated and "
196 "will be removed from (new) 2.6. kernels soon "
197 "after 2005-01-01\n");
200 proc_string
[count
] = '\0';
202 result
= cpufreq_parse_policy(proc_string
, &policy
);
206 if (policy
.cpu
== CPUFREQ_ALL_CPUS
)
208 for (i
=0; i
<NR_CPUS
; i
++)
212 cpufreq_set_policy(&policy
);
216 cpufreq_set_policy(&policy
);
223 * cpufreq_proc_init - add "cpufreq" to the /proc root directory
225 * This function adds "cpufreq" to the /proc root directory.
227 static int __init
cpufreq_proc_init (void)
229 struct proc_dir_entry
*entry
= NULL
;
231 /* are these acceptable values? */
232 entry
= create_proc_entry("cpufreq", S_IFREG
|S_IRUGO
|S_IWUSR
,
236 printk(KERN_ERR
"unable to create /proc/cpufreq entry\n");
239 entry
->read_proc
= cpufreq_proc_read
;
240 entry
->write_proc
= cpufreq_proc_write
;
248 * cpufreq_proc_exit - removes "cpufreq" from the /proc root directory.
250 * This function removes "cpufreq" from the /proc root directory.
252 static void __exit
cpufreq_proc_exit (void)
254 remove_proc_entry("cpufreq", &proc_root
);
258 MODULE_AUTHOR ("Dominik Brodowski <linux@brodo.de>");
259 MODULE_DESCRIPTION ("CPUfreq /proc/cpufreq interface");
260 MODULE_LICENSE ("GPL");
262 module_init(cpufreq_proc_init
);
263 module_exit(cpufreq_proc_exit
);