Rev 845 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
582 | mauro | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Mauro Marinoni <mauro.marinoni@unipv.it> |
||
10 | * |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
1063 | tullio | 19 | /* |
20 | * This program is free software; you can redistribute it and/or modify |
||
21 | * it under the terms of the GNU General Public License as published by |
||
22 | * the Free Software Foundation; either version 2 of the License, or |
||
23 | * (at your option) any later version. |
||
24 | * |
||
25 | * This program is distributed in the hope that it will be useful, |
||
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
28 | * GNU General Public License for more details. |
||
29 | * |
||
30 | * You should have received a copy of the GNU General Public License |
||
31 | * along with this program; if not, write to the Free Software |
||
32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
33 | * |
||
34 | */ |
||
35 | |||
582 | mauro | 36 | #include <kernel/func.h> |
37 | #include "../include/drivers/shark_cpu26.h" |
||
782 | giacomo | 38 | #include <tracer.h> |
582 | mauro | 39 | |
775 | mauro | 40 | //#define __CPU26_DEBUG__ |
582 | mauro | 41 | |
42 | /* CPU Initialization */ |
||
43 | extern void early_cpu_init(void); |
||
44 | extern void identify_cpu_0(void); |
||
45 | extern void print_cpu_info_0(void); |
||
46 | |||
47 | /* AMD K6 PowerNow */ |
||
48 | extern int powernow_k6_init(void); |
||
49 | extern void powernow_k6_exit(void); |
||
50 | /* AMD K7 PowerNow */ |
||
51 | extern int powernow_init(void); |
||
52 | extern void powernow_exit(void); |
||
53 | /* AMD K8 PowerNow */ |
||
54 | extern int powernowk8_init(void); |
||
55 | extern void powernowk8_exit(void); |
||
56 | /* Cyrix MediaGX - NatSemi Geode */ |
||
57 | extern int cpufreq_gx_init(void); |
||
58 | extern void cpufreq_gx_exit(void); |
||
59 | /* Pentium4 clock modulation/speed scaling */ |
||
60 | extern int cpufreq_p4_init(void); |
||
61 | extern void cpufreq_p4_exit(void); |
||
62 | /* PentiumM/Centrino SpeedStep */ |
||
63 | extern int centrino_init(void); |
||
64 | extern void centrino_exit(void); |
||
65 | /* Pentium ICH SpeedStep */ |
||
66 | extern int speedstep_ich_init(void); |
||
67 | extern void speedstep_ich_exit(void); |
||
68 | /* Pentium SMI SpeedStep */ |
||
69 | /*extern int speedstep_smi_init(void); |
||
70 | extern void speedstep_smi_exit(void);*/ |
||
71 | |||
597 | mauro | 72 | /* DVS function */ |
73 | extern int cpufreq_target(unsigned int target_freq, unsigned int relation); |
||
74 | extern int cpufreq_get_cur_freq(void); |
||
75 | extern int cpufreq_get_min_freq(void); |
||
76 | extern int cpufreq_get_max_freq(void); |
||
77 | extern int cpufreq_get_latency(void); |
||
775 | mauro | 78 | extern int cpufreq_get_available_freqs(int *buf); |
770 | mauro | 79 | extern int cpufreq_show_available_freqs(char *buf); |
597 | mauro | 80 | |
582 | mauro | 81 | static int cpu_installed = FALSE; |
82 | static int dvs_installed = DVS_NONE; |
||
775 | mauro | 83 | int cpu26_freqs[DVS_MAX_NUM_FREQS]; |
582 | mauro | 84 | |
597 | mauro | 85 | /* DVS user function */ |
782 | giacomo | 86 | |
87 | extern unsigned int clk_per_msec; |
||
88 | |||
89 | int CPU26_set_frequency(unsigned int target_freq, unsigned int relation) |
||
582 | mauro | 90 | { |
782 | giacomo | 91 | |
92 | int res; |
||
93 | |||
789 | giacomo | 94 | if (dvs_installed != DVS_NONE && dvs_installed != DVS_MEDIAGX_GEODE) { |
95 | res = cpufreq_target(target_freq, relation); |
||
96 | TRACER_LOGEVENT(FTrace_EVT_cycles_per_msec,0,clk_per_msec); |
||
97 | return res; |
||
98 | } else { |
||
99 | return -1; |
||
100 | } |
||
782 | giacomo | 101 | |
582 | mauro | 102 | } |
103 | |||
789 | giacomo | 104 | extern void gx_force_values(unsigned char on_duration, unsigned char off_duration); |
105 | |||
106 | int CPU26_set_suspend_modulation(unsigned char on_duration, unsigned char off_duration) { |
||
107 | |||
108 | if (dvs_installed == DVS_MEDIAGX_GEODE) { |
||
109 | gx_force_values(on_duration, off_duration); |
||
110 | return 0; |
||
111 | } |
||
112 | |||
113 | return -1; |
||
114 | |||
115 | } |
||
116 | |||
770 | mauro | 117 | inline int CPU26_get_cur_frequency() |
582 | mauro | 118 | { |
597 | mauro | 119 | return cpufreq_get_cur_freq(); |
582 | mauro | 120 | } |
121 | |||
770 | mauro | 122 | inline int CPU26_get_min_frequency() |
582 | mauro | 123 | { |
597 | mauro | 124 | return cpufreq_get_min_freq(); |
125 | } |
||
582 | mauro | 126 | |
770 | mauro | 127 | inline int CPU26_get_max_frequency() |
597 | mauro | 128 | { |
129 | return cpufreq_get_max_freq(); |
||
582 | mauro | 130 | } |
131 | |||
779 | giacomo | 132 | inline int CPU26_get_frequencies(int *buf) |
582 | mauro | 133 | { |
775 | mauro | 134 | return cpufreq_get_available_freqs (buf); |
135 | } |
||
136 | |||
779 | giacomo | 137 | inline int CPU26_show_frequencies(char *buf) |
775 | mauro | 138 | { |
770 | mauro | 139 | return cpufreq_show_available_freqs (buf); |
140 | } |
||
141 | |||
142 | inline int CPU26_get_latency() |
||
143 | { |
||
597 | mauro | 144 | return cpufreq_get_latency(); |
582 | mauro | 145 | } |
146 | |||
845 | mauro | 147 | inline int CPU26_DVS_installed(void) |
582 | mauro | 148 | { |
779 | giacomo | 149 | return dvs_installed; |
150 | } |
||
151 | |||
152 | int CPU26_DVS_init(void) |
||
153 | { |
||
582 | mauro | 154 | int ret = 0; |
155 | |||
156 | if (cpu_installed == FALSE) |
||
157 | return -1; |
||
158 | |||
159 | if (dvs_installed != DVS_NONE) |
||
160 | return 0; |
||
161 | |||
162 | ret = powernow_k6_init(); |
||
163 | #ifdef __CPU26_DEBUG__ |
||
164 | printk(KERN_DEBUG "Check PowerNow! K6 - Returned: %d\n", ret); |
||
165 | #endif |
||
166 | if (!ret) { |
||
167 | dvs_installed = DVS_POWERNOW_K6; |
||
168 | return dvs_installed; |
||
169 | } |
||
170 | |||
171 | ret = powernow_init(); |
||
172 | #ifdef __CPU26_DEBUG__ |
||
173 | printk(KERN_DEBUG "Check PowerNow! K7 - Returned: %d\n", ret); |
||
174 | #endif |
||
175 | if (!ret) { |
||
176 | dvs_installed = DVS_POWERNOW_K7; |
||
177 | return dvs_installed; |
||
178 | } |
||
179 | |||
180 | ret = powernowk8_init(); |
||
181 | #ifdef __CPU26_DEBUG__ |
||
182 | printk(KERN_DEBUG "Check PowerNow! K8 - Returned: %d\n", ret); |
||
183 | #endif |
||
184 | if (!ret) { |
||
185 | dvs_installed = DVS_POWERNOW_K8; |
||
186 | return dvs_installed; |
||
187 | } |
||
188 | |||
189 | ret = cpufreq_gx_init(); |
||
190 | #ifdef __CPU26_DEBUG__ |
||
191 | printk(KERN_DEBUG "Check MediaGX/Geode (Returned: %d)\n", ret); |
||
192 | #endif |
||
193 | if (!ret) { |
||
194 | dvs_installed = DVS_MEDIAGX_GEODE; |
||
195 | return dvs_installed; |
||
196 | } |
||
197 | |||
198 | ret = cpufreq_p4_init(); |
||
199 | #ifdef __CPU26_DEBUG__ |
||
200 | printk(KERN_DEBUG "Check Pentium4 ClockModulation (Returned: %d)\n", ret); |
||
201 | #endif |
||
202 | if (!ret) { |
||
203 | dvs_installed = DVS_P4_CLOCK_MOD; |
||
204 | return dvs_installed; |
||
205 | } |
||
206 | |||
207 | ret = centrino_init(); |
||
208 | #ifdef __CPU26_DEBUG__ |
||
209 | printk(KERN_DEBUG "Check SpeedStep Centrino (Returned: %d)\n", ret); |
||
210 | #endif |
||
211 | if (!ret) { |
||
212 | dvs_installed = DVS_SS_CENTRINO; |
||
213 | return dvs_installed; |
||
214 | } |
||
215 | |||
216 | ret = speedstep_ich_init(); |
||
217 | #ifdef __CPU26_DEBUG__ |
||
218 | printk(KERN_DEBUG "Check SpeedStep ICH (Returned: %d)\n", ret); |
||
219 | #endif |
||
220 | if (!ret) { |
||
221 | dvs_installed = DVS_SS_ICH; |
||
222 | return dvs_installed; |
||
223 | } |
||
224 | |||
225 | /*ret = speedstep_smi_init(); |
||
226 | #ifdef __CPU26_DEBUG__ |
||
227 | printk(KERN_DEBUG "Check SpeedStep SMI (Returned: %d)\n", ret); |
||
228 | #endif |
||
229 | if (!ret) { |
||
230 | dvs_installed = DVS_SS_SMI; |
||
231 | return dvs_installed; |
||
232 | }*/ |
||
233 | |||
234 | return -1; |
||
235 | } |
||
236 | |||
779 | giacomo | 237 | int CPU26_DVS_close(void) |
582 | mauro | 238 | { |
239 | switch(dvs_installed) { |
||
240 | case DVS_NONE: |
||
241 | return -1; |
||
242 | case DVS_POWERNOW_K6: |
||
243 | powernow_k6_exit(); |
||
244 | return 0; |
||
245 | case DVS_POWERNOW_K7: |
||
246 | powernow_exit(); |
||
247 | return 0; |
||
248 | case DVS_POWERNOW_K8: |
||
249 | powernowk8_exit(); |
||
250 | return 0; |
||
251 | case DVS_MEDIAGX_GEODE: |
||
252 | cpufreq_gx_exit(); |
||
253 | return 0; |
||
254 | case DVS_P4_CLOCK_MOD: |
||
255 | cpufreq_p4_exit(); |
||
256 | return 0; |
||
257 | case DVS_SS_CENTRINO: |
||
258 | centrino_exit(); |
||
259 | return 0; |
||
260 | case DVS_SS_ICH: |
||
261 | speedstep_ich_exit(); |
||
262 | return 0; |
||
263 | /*case DVS_SS_SMI: |
||
264 | speedstep_smi_exit(); |
||
265 | return 0;*/ |
||
266 | } |
||
267 | |||
268 | dvs_installed = DVS_NONE; |
||
269 | return 0; |
||
270 | } |
||
597 | mauro | 271 | |
272 | /* Init the Linux CPU Layer */ |
||
770 | mauro | 273 | inline int CPU26_installed(void) |
597 | mauro | 274 | { |
275 | return cpu_installed; |
||
276 | } |
||
277 | |||
770 | mauro | 278 | inline void CPU26_showinfo(void) |
597 | mauro | 279 | { |
280 | print_cpu_info_0(); |
||
281 | } |
||
282 | |||
283 | int CPU26_init(void) |
||
284 | { |
||
285 | int ret = 0; |
||
286 | |||
287 | if (cpu_installed == TRUE) return 0; |
||
288 | |||
289 | early_cpu_init(); |
||
290 | |||
291 | identify_cpu_0(); |
||
292 | |||
293 | printk(KERN_INFO); |
||
294 | print_cpu_info_0(); |
||
295 | |||
296 | cpu_installed = TRUE; |
||
297 | |||
298 | return ret; |
||
299 | } |
||
300 | |||
770 | mauro | 301 | inline int CPU26_close(void) |
597 | mauro | 302 | { |
303 | if (cpu_installed == TRUE) { |
||
304 | return 0; |
||
305 | } else |
||
306 | return -1; |
||
307 | } |