Rev 779 | Rev 789 | Go to most recent revision | 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 | |||
19 | #include <kernel/func.h> |
||
20 | #include "../include/drivers/shark_cpu26.h" |
||
782 | giacomo | 21 | #include <tracer.h> |
582 | mauro | 22 | |
775 | mauro | 23 | //#define __CPU26_DEBUG__ |
582 | mauro | 24 | |
25 | /* CPU Initialization */ |
||
26 | extern void early_cpu_init(void); |
||
27 | extern void identify_cpu_0(void); |
||
28 | extern void print_cpu_info_0(void); |
||
29 | |||
30 | /* AMD K6 PowerNow */ |
||
31 | extern int powernow_k6_init(void); |
||
32 | extern void powernow_k6_exit(void); |
||
33 | /* AMD K7 PowerNow */ |
||
34 | extern int powernow_init(void); |
||
35 | extern void powernow_exit(void); |
||
36 | /* AMD K8 PowerNow */ |
||
37 | extern int powernowk8_init(void); |
||
38 | extern void powernowk8_exit(void); |
||
39 | /* Cyrix MediaGX - NatSemi Geode */ |
||
40 | extern int cpufreq_gx_init(void); |
||
41 | extern void cpufreq_gx_exit(void); |
||
42 | /* Pentium4 clock modulation/speed scaling */ |
||
43 | extern int cpufreq_p4_init(void); |
||
44 | extern void cpufreq_p4_exit(void); |
||
45 | /* PentiumM/Centrino SpeedStep */ |
||
46 | extern int centrino_init(void); |
||
47 | extern void centrino_exit(void); |
||
48 | /* Pentium ICH SpeedStep */ |
||
49 | extern int speedstep_ich_init(void); |
||
50 | extern void speedstep_ich_exit(void); |
||
51 | /* Pentium SMI SpeedStep */ |
||
52 | /*extern int speedstep_smi_init(void); |
||
53 | extern void speedstep_smi_exit(void);*/ |
||
54 | |||
597 | mauro | 55 | /* DVS function */ |
56 | extern int cpufreq_target(unsigned int target_freq, unsigned int relation); |
||
57 | extern int cpufreq_get_cur_freq(void); |
||
58 | extern int cpufreq_get_min_freq(void); |
||
59 | extern int cpufreq_get_max_freq(void); |
||
60 | extern int cpufreq_get_latency(void); |
||
775 | mauro | 61 | extern int cpufreq_get_available_freqs(int *buf); |
770 | mauro | 62 | extern int cpufreq_show_available_freqs(char *buf); |
597 | mauro | 63 | |
582 | mauro | 64 | static int cpu_installed = FALSE; |
65 | static int dvs_installed = DVS_NONE; |
||
775 | mauro | 66 | int cpu26_freqs[DVS_MAX_NUM_FREQS]; |
582 | mauro | 67 | |
597 | mauro | 68 | /* DVS user function */ |
782 | giacomo | 69 | |
70 | extern unsigned int clk_per_msec; |
||
71 | |||
72 | int CPU26_set_frequency(unsigned int target_freq, unsigned int relation) |
||
582 | mauro | 73 | { |
782 | giacomo | 74 | |
75 | int res; |
||
76 | |||
77 | res = cpufreq_target(target_freq, relation); |
||
78 | TRACER_LOGEVENT(FTrace_EVT_cycles_per_msec,0,clk_per_msec); |
||
79 | return res; |
||
80 | |||
582 | mauro | 81 | } |
82 | |||
770 | mauro | 83 | inline int CPU26_get_cur_frequency() |
582 | mauro | 84 | { |
597 | mauro | 85 | return cpufreq_get_cur_freq(); |
582 | mauro | 86 | } |
87 | |||
770 | mauro | 88 | inline int CPU26_get_min_frequency() |
582 | mauro | 89 | { |
597 | mauro | 90 | return cpufreq_get_min_freq(); |
91 | } |
||
582 | mauro | 92 | |
770 | mauro | 93 | inline int CPU26_get_max_frequency() |
597 | mauro | 94 | { |
95 | return cpufreq_get_max_freq(); |
||
582 | mauro | 96 | } |
97 | |||
779 | giacomo | 98 | inline int CPU26_get_frequencies(int *buf) |
582 | mauro | 99 | { |
775 | mauro | 100 | return cpufreq_get_available_freqs (buf); |
101 | } |
||
102 | |||
779 | giacomo | 103 | inline int CPU26_show_frequencies(char *buf) |
775 | mauro | 104 | { |
770 | mauro | 105 | return cpufreq_show_available_freqs (buf); |
106 | } |
||
107 | |||
108 | inline int CPU26_get_latency() |
||
109 | { |
||
597 | mauro | 110 | return cpufreq_get_latency(); |
582 | mauro | 111 | } |
112 | |||
779 | giacomo | 113 | inline int CPU26_DVS_status(void) |
582 | mauro | 114 | { |
779 | giacomo | 115 | return dvs_installed; |
116 | } |
||
117 | |||
118 | int CPU26_DVS_init(void) |
||
119 | { |
||
582 | mauro | 120 | int ret = 0; |
121 | |||
122 | if (cpu_installed == FALSE) |
||
123 | return -1; |
||
124 | |||
125 | if (dvs_installed != DVS_NONE) |
||
126 | return 0; |
||
127 | |||
128 | ret = powernow_k6_init(); |
||
129 | #ifdef __CPU26_DEBUG__ |
||
130 | printk(KERN_DEBUG "Check PowerNow! K6 - Returned: %d\n", ret); |
||
131 | #endif |
||
132 | if (!ret) { |
||
133 | dvs_installed = DVS_POWERNOW_K6; |
||
134 | return dvs_installed; |
||
135 | } |
||
136 | |||
137 | ret = powernow_init(); |
||
138 | #ifdef __CPU26_DEBUG__ |
||
139 | printk(KERN_DEBUG "Check PowerNow! K7 - Returned: %d\n", ret); |
||
140 | #endif |
||
141 | if (!ret) { |
||
142 | dvs_installed = DVS_POWERNOW_K7; |
||
143 | return dvs_installed; |
||
144 | } |
||
145 | |||
146 | ret = powernowk8_init(); |
||
147 | #ifdef __CPU26_DEBUG__ |
||
148 | printk(KERN_DEBUG "Check PowerNow! K8 - Returned: %d\n", ret); |
||
149 | #endif |
||
150 | if (!ret) { |
||
151 | dvs_installed = DVS_POWERNOW_K8; |
||
152 | return dvs_installed; |
||
153 | } |
||
154 | |||
155 | ret = cpufreq_gx_init(); |
||
156 | #ifdef __CPU26_DEBUG__ |
||
157 | printk(KERN_DEBUG "Check MediaGX/Geode (Returned: %d)\n", ret); |
||
158 | #endif |
||
159 | if (!ret) { |
||
160 | dvs_installed = DVS_MEDIAGX_GEODE; |
||
161 | return dvs_installed; |
||
162 | } |
||
163 | |||
164 | ret = cpufreq_p4_init(); |
||
165 | #ifdef __CPU26_DEBUG__ |
||
166 | printk(KERN_DEBUG "Check Pentium4 ClockModulation (Returned: %d)\n", ret); |
||
167 | #endif |
||
168 | if (!ret) { |
||
169 | dvs_installed = DVS_P4_CLOCK_MOD; |
||
170 | return dvs_installed; |
||
171 | } |
||
172 | |||
173 | ret = centrino_init(); |
||
174 | #ifdef __CPU26_DEBUG__ |
||
175 | printk(KERN_DEBUG "Check SpeedStep Centrino (Returned: %d)\n", ret); |
||
176 | #endif |
||
177 | if (!ret) { |
||
178 | dvs_installed = DVS_SS_CENTRINO; |
||
179 | return dvs_installed; |
||
180 | } |
||
181 | |||
182 | ret = speedstep_ich_init(); |
||
183 | #ifdef __CPU26_DEBUG__ |
||
184 | printk(KERN_DEBUG "Check SpeedStep ICH (Returned: %d)\n", ret); |
||
185 | #endif |
||
186 | if (!ret) { |
||
187 | dvs_installed = DVS_SS_ICH; |
||
188 | return dvs_installed; |
||
189 | } |
||
190 | |||
191 | /*ret = speedstep_smi_init(); |
||
192 | #ifdef __CPU26_DEBUG__ |
||
193 | printk(KERN_DEBUG "Check SpeedStep SMI (Returned: %d)\n", ret); |
||
194 | #endif |
||
195 | if (!ret) { |
||
196 | dvs_installed = DVS_SS_SMI; |
||
197 | return dvs_installed; |
||
198 | }*/ |
||
199 | |||
200 | return -1; |
||
201 | } |
||
202 | |||
779 | giacomo | 203 | int CPU26_DVS_close(void) |
582 | mauro | 204 | { |
205 | switch(dvs_installed) { |
||
206 | case DVS_NONE: |
||
207 | return -1; |
||
208 | case DVS_POWERNOW_K6: |
||
209 | powernow_k6_exit(); |
||
210 | return 0; |
||
211 | case DVS_POWERNOW_K7: |
||
212 | powernow_exit(); |
||
213 | return 0; |
||
214 | case DVS_POWERNOW_K8: |
||
215 | powernowk8_exit(); |
||
216 | return 0; |
||
217 | case DVS_MEDIAGX_GEODE: |
||
218 | cpufreq_gx_exit(); |
||
219 | return 0; |
||
220 | case DVS_P4_CLOCK_MOD: |
||
221 | cpufreq_p4_exit(); |
||
222 | return 0; |
||
223 | case DVS_SS_CENTRINO: |
||
224 | centrino_exit(); |
||
225 | return 0; |
||
226 | case DVS_SS_ICH: |
||
227 | speedstep_ich_exit(); |
||
228 | return 0; |
||
229 | /*case DVS_SS_SMI: |
||
230 | speedstep_smi_exit(); |
||
231 | return 0;*/ |
||
232 | } |
||
233 | |||
234 | dvs_installed = DVS_NONE; |
||
235 | return 0; |
||
236 | } |
||
597 | mauro | 237 | |
238 | /* Init the Linux CPU Layer */ |
||
770 | mauro | 239 | inline int CPU26_installed(void) |
597 | mauro | 240 | { |
241 | return cpu_installed; |
||
242 | } |
||
243 | |||
770 | mauro | 244 | inline void CPU26_showinfo(void) |
597 | mauro | 245 | { |
246 | print_cpu_info_0(); |
||
247 | } |
||
248 | |||
249 | int CPU26_init(void) |
||
250 | { |
||
251 | int ret = 0; |
||
252 | |||
253 | if (cpu_installed == TRUE) return 0; |
||
254 | |||
255 | early_cpu_init(); |
||
256 | |||
257 | identify_cpu_0(); |
||
258 | |||
259 | printk(KERN_INFO); |
||
260 | print_cpu_info_0(); |
||
261 | |||
262 | cpu_installed = TRUE; |
||
263 | |||
264 | return ret; |
||
265 | } |
||
266 | |||
770 | mauro | 267 | inline int CPU26_close(void) |
597 | mauro | 268 | { |
269 | if (cpu_installed == TRUE) { |
||
270 | return 0; |
||
271 | } else |
||
272 | return -1; |
||
273 | } |