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