Rev 775 | Rev 782 | 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 | |||
779 | giacomo | 88 | inline int CPU26_get_frequencies(int *buf) |
582 | mauro | 89 | { |
775 | mauro | 90 | return cpufreq_get_available_freqs (buf); |
91 | } |
||
92 | |||
779 | giacomo | 93 | inline int CPU26_show_frequencies(char *buf) |
775 | mauro | 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 | |||
779 | giacomo | 103 | inline int CPU26_DVS_status(void) |
582 | mauro | 104 | { |
779 | giacomo | 105 | return dvs_installed; |
106 | } |
||
107 | |||
108 | int CPU26_DVS_init(void) |
||
109 | { |
||
582 | mauro | 110 | int ret = 0; |
111 | |||
112 | if (cpu_installed == FALSE) |
||
113 | return -1; |
||
114 | |||
115 | if (dvs_installed != DVS_NONE) |
||
116 | return 0; |
||
117 | |||
118 | ret = powernow_k6_init(); |
||
119 | #ifdef __CPU26_DEBUG__ |
||
120 | printk(KERN_DEBUG "Check PowerNow! K6 - Returned: %d\n", ret); |
||
121 | #endif |
||
122 | if (!ret) { |
||
123 | dvs_installed = DVS_POWERNOW_K6; |
||
124 | return dvs_installed; |
||
125 | } |
||
126 | |||
127 | ret = powernow_init(); |
||
128 | #ifdef __CPU26_DEBUG__ |
||
129 | printk(KERN_DEBUG "Check PowerNow! K7 - Returned: %d\n", ret); |
||
130 | #endif |
||
131 | if (!ret) { |
||
132 | dvs_installed = DVS_POWERNOW_K7; |
||
133 | return dvs_installed; |
||
134 | } |
||
135 | |||
136 | ret = powernowk8_init(); |
||
137 | #ifdef __CPU26_DEBUG__ |
||
138 | printk(KERN_DEBUG "Check PowerNow! K8 - Returned: %d\n", ret); |
||
139 | #endif |
||
140 | if (!ret) { |
||
141 | dvs_installed = DVS_POWERNOW_K8; |
||
142 | return dvs_installed; |
||
143 | } |
||
144 | |||
145 | ret = cpufreq_gx_init(); |
||
146 | #ifdef __CPU26_DEBUG__ |
||
147 | printk(KERN_DEBUG "Check MediaGX/Geode (Returned: %d)\n", ret); |
||
148 | #endif |
||
149 | if (!ret) { |
||
150 | dvs_installed = DVS_MEDIAGX_GEODE; |
||
151 | return dvs_installed; |
||
152 | } |
||
153 | |||
154 | ret = cpufreq_p4_init(); |
||
155 | #ifdef __CPU26_DEBUG__ |
||
156 | printk(KERN_DEBUG "Check Pentium4 ClockModulation (Returned: %d)\n", ret); |
||
157 | #endif |
||
158 | if (!ret) { |
||
159 | dvs_installed = DVS_P4_CLOCK_MOD; |
||
160 | return dvs_installed; |
||
161 | } |
||
162 | |||
163 | ret = centrino_init(); |
||
164 | #ifdef __CPU26_DEBUG__ |
||
165 | printk(KERN_DEBUG "Check SpeedStep Centrino (Returned: %d)\n", ret); |
||
166 | #endif |
||
167 | if (!ret) { |
||
168 | dvs_installed = DVS_SS_CENTRINO; |
||
169 | return dvs_installed; |
||
170 | } |
||
171 | |||
172 | ret = speedstep_ich_init(); |
||
173 | #ifdef __CPU26_DEBUG__ |
||
174 | printk(KERN_DEBUG "Check SpeedStep ICH (Returned: %d)\n", ret); |
||
175 | #endif |
||
176 | if (!ret) { |
||
177 | dvs_installed = DVS_SS_ICH; |
||
178 | return dvs_installed; |
||
179 | } |
||
180 | |||
181 | /*ret = speedstep_smi_init(); |
||
182 | #ifdef __CPU26_DEBUG__ |
||
183 | printk(KERN_DEBUG "Check SpeedStep SMI (Returned: %d)\n", ret); |
||
184 | #endif |
||
185 | if (!ret) { |
||
186 | dvs_installed = DVS_SS_SMI; |
||
187 | return dvs_installed; |
||
188 | }*/ |
||
189 | |||
190 | return -1; |
||
191 | } |
||
192 | |||
779 | giacomo | 193 | int CPU26_DVS_close(void) |
582 | mauro | 194 | { |
195 | switch(dvs_installed) { |
||
196 | case DVS_NONE: |
||
197 | return -1; |
||
198 | case DVS_POWERNOW_K6: |
||
199 | powernow_k6_exit(); |
||
200 | return 0; |
||
201 | case DVS_POWERNOW_K7: |
||
202 | powernow_exit(); |
||
203 | return 0; |
||
204 | case DVS_POWERNOW_K8: |
||
205 | powernowk8_exit(); |
||
206 | return 0; |
||
207 | case DVS_MEDIAGX_GEODE: |
||
208 | cpufreq_gx_exit(); |
||
209 | return 0; |
||
210 | case DVS_P4_CLOCK_MOD: |
||
211 | cpufreq_p4_exit(); |
||
212 | return 0; |
||
213 | case DVS_SS_CENTRINO: |
||
214 | centrino_exit(); |
||
215 | return 0; |
||
216 | case DVS_SS_ICH: |
||
217 | speedstep_ich_exit(); |
||
218 | return 0; |
||
219 | /*case DVS_SS_SMI: |
||
220 | speedstep_smi_exit(); |
||
221 | return 0;*/ |
||
222 | } |
||
223 | |||
224 | dvs_installed = DVS_NONE; |
||
225 | return 0; |
||
226 | } |
||
597 | mauro | 227 | |
228 | /* Init the Linux CPU Layer */ |
||
770 | mauro | 229 | inline int CPU26_installed(void) |
597 | mauro | 230 | { |
231 | return cpu_installed; |
||
232 | } |
||
233 | |||
770 | mauro | 234 | inline void CPU26_showinfo(void) |
597 | mauro | 235 | { |
236 | print_cpu_info_0(); |
||
237 | } |
||
238 | |||
239 | int CPU26_init(void) |
||
240 | { |
||
241 | int ret = 0; |
||
242 | |||
243 | if (cpu_installed == TRUE) return 0; |
||
244 | |||
245 | early_cpu_init(); |
||
246 | |||
247 | identify_cpu_0(); |
||
248 | |||
249 | printk(KERN_INFO); |
||
250 | print_cpu_info_0(); |
||
251 | |||
252 | cpu_installed = TRUE; |
||
253 | |||
254 | return ret; |
||
255 | } |
||
256 | |||
770 | mauro | 257 | inline int CPU26_close(void) |
597 | mauro | 258 | { |
259 | if (cpu_installed == TRUE) { |
||
260 | return 0; |
||
261 | } else |
||
262 | return -1; |
||
263 | } |