diff options
Diffstat (limited to 'tools/power/cpupower/lib/cpufreq.c')
-rw-r--r-- | tools/power/cpupower/lib/cpufreq.c | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/tools/power/cpupower/lib/cpufreq.c b/tools/power/cpupower/lib/cpufreq.c new file mode 100644 index 00000000000..ae7d8c57b44 --- /dev/null +++ b/tools/power/cpupower/lib/cpufreq.c | |||
@@ -0,0 +1,190 @@ | |||
1 | /* | ||
2 | * (C) 2004-2009 Dominik Brodowski <linux@dominikbrodowski.de> | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | */ | ||
6 | |||
7 | |||
8 | #include <stdio.h> | ||
9 | #include <errno.h> | ||
10 | #include <stdlib.h> | ||
11 | #include <string.h> | ||
12 | |||
13 | #include "cpufreq.h" | ||
14 | #include "sysfs.h" | ||
15 | |||
16 | int cpufreq_cpu_exists(unsigned int cpu) | ||
17 | { | ||
18 | return sysfs_cpu_exists(cpu); | ||
19 | } | ||
20 | |||
21 | unsigned long cpufreq_get_freq_kernel(unsigned int cpu) | ||
22 | { | ||
23 | return sysfs_get_freq_kernel(cpu); | ||
24 | } | ||
25 | |||
26 | unsigned long cpufreq_get_freq_hardware(unsigned int cpu) | ||
27 | { | ||
28 | return sysfs_get_freq_hardware(cpu); | ||
29 | } | ||
30 | |||
31 | unsigned long cpufreq_get_transition_latency(unsigned int cpu) | ||
32 | { | ||
33 | return sysfs_get_freq_transition_latency(cpu); | ||
34 | } | ||
35 | |||
36 | int cpufreq_get_hardware_limits(unsigned int cpu, | ||
37 | unsigned long *min, | ||
38 | unsigned long *max) | ||
39 | { | ||
40 | if ((!min) || (!max)) | ||
41 | return -EINVAL; | ||
42 | return sysfs_get_freq_hardware_limits(cpu, min, max); | ||
43 | } | ||
44 | |||
45 | char * cpufreq_get_driver(unsigned int cpu) { | ||
46 | return sysfs_get_freq_driver(cpu); | ||
47 | } | ||
48 | |||
49 | void cpufreq_put_driver(char * ptr) { | ||
50 | if (!ptr) | ||
51 | return; | ||
52 | free(ptr); | ||
53 | } | ||
54 | |||
55 | struct cpufreq_policy * cpufreq_get_policy(unsigned int cpu) { | ||
56 | return sysfs_get_freq_policy(cpu); | ||
57 | } | ||
58 | |||
59 | void cpufreq_put_policy(struct cpufreq_policy *policy) { | ||
60 | if ((!policy) || (!policy->governor)) | ||
61 | return; | ||
62 | |||
63 | free(policy->governor); | ||
64 | policy->governor = NULL; | ||
65 | free(policy); | ||
66 | } | ||
67 | |||
68 | struct cpufreq_available_governors * cpufreq_get_available_governors(unsigned int cpu) { | ||
69 | return sysfs_get_freq_available_governors(cpu); | ||
70 | } | ||
71 | |||
72 | void cpufreq_put_available_governors(struct cpufreq_available_governors *any) { | ||
73 | struct cpufreq_available_governors *tmp, *next; | ||
74 | |||
75 | if (!any) | ||
76 | return; | ||
77 | |||
78 | tmp = any->first; | ||
79 | while (tmp) { | ||
80 | next = tmp->next; | ||
81 | if (tmp->governor) | ||
82 | free(tmp->governor); | ||
83 | free(tmp); | ||
84 | tmp = next; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | |||
89 | struct cpufreq_available_frequencies * cpufreq_get_available_frequencies(unsigned int cpu) { | ||
90 | return sysfs_get_available_frequencies(cpu); | ||
91 | } | ||
92 | |||
93 | void cpufreq_put_available_frequencies(struct cpufreq_available_frequencies *any) { | ||
94 | struct cpufreq_available_frequencies *tmp, *next; | ||
95 | |||
96 | if (!any) | ||
97 | return; | ||
98 | |||
99 | tmp = any->first; | ||
100 | while (tmp) { | ||
101 | next = tmp->next; | ||
102 | free(tmp); | ||
103 | tmp = next; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | |||
108 | struct cpufreq_affected_cpus * cpufreq_get_affected_cpus(unsigned int cpu) { | ||
109 | return sysfs_get_freq_affected_cpus(cpu); | ||
110 | } | ||
111 | |||
112 | void cpufreq_put_affected_cpus(struct cpufreq_affected_cpus *any) { | ||
113 | struct cpufreq_affected_cpus *tmp, *next; | ||
114 | |||
115 | if (!any) | ||
116 | return; | ||
117 | |||
118 | tmp = any->first; | ||
119 | while (tmp) { | ||
120 | next = tmp->next; | ||
121 | free(tmp); | ||
122 | tmp = next; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | |||
127 | struct cpufreq_affected_cpus * cpufreq_get_related_cpus(unsigned int cpu) { | ||
128 | return sysfs_get_freq_related_cpus(cpu); | ||
129 | } | ||
130 | |||
131 | void cpufreq_put_related_cpus(struct cpufreq_affected_cpus *any) { | ||
132 | cpufreq_put_affected_cpus(any); | ||
133 | } | ||
134 | |||
135 | |||
136 | int cpufreq_set_policy(unsigned int cpu, struct cpufreq_policy *policy) { | ||
137 | if (!policy || !(policy->governor)) | ||
138 | return -EINVAL; | ||
139 | |||
140 | return sysfs_set_freq_policy(cpu, policy); | ||
141 | } | ||
142 | |||
143 | |||
144 | int cpufreq_modify_policy_min(unsigned int cpu, unsigned long min_freq) { | ||
145 | return sysfs_modify_freq_policy_min(cpu, min_freq); | ||
146 | } | ||
147 | |||
148 | |||
149 | int cpufreq_modify_policy_max(unsigned int cpu, unsigned long max_freq) { | ||
150 | return sysfs_modify_freq_policy_max(cpu, max_freq); | ||
151 | } | ||
152 | |||
153 | |||
154 | int cpufreq_modify_policy_governor(unsigned int cpu, char *governor) { | ||
155 | if ((!governor) || (strlen(governor) > 19)) | ||
156 | return -EINVAL; | ||
157 | |||
158 | return sysfs_modify_freq_policy_governor(cpu, governor); | ||
159 | } | ||
160 | |||
161 | int cpufreq_set_frequency(unsigned int cpu, unsigned long target_frequency) { | ||
162 | return sysfs_set_frequency(cpu, target_frequency); | ||
163 | } | ||
164 | |||
165 | struct cpufreq_stats * cpufreq_get_stats(unsigned int cpu, unsigned long long *total_time) { | ||
166 | struct cpufreq_stats *ret; | ||
167 | |||
168 | ret = sysfs_get_freq_stats(cpu, total_time); | ||
169 | return (ret); | ||
170 | } | ||
171 | |||
172 | void cpufreq_put_stats(struct cpufreq_stats *any) { | ||
173 | struct cpufreq_stats *tmp, *next; | ||
174 | |||
175 | if (!any) | ||
176 | return; | ||
177 | |||
178 | tmp = any->first; | ||
179 | while (tmp) { | ||
180 | next = tmp->next; | ||
181 | free(tmp); | ||
182 | tmp = next; | ||
183 | } | ||
184 | } | ||
185 | |||
186 | unsigned long cpufreq_get_transitions(unsigned int cpu) { | ||
187 | unsigned long ret = sysfs_get_freq_transitions(cpu); | ||
188 | |||
189 | return (ret); | ||
190 | } | ||