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