Subversion Repositories shark

Rev

Rev 782 | Rev 845 | 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
 
789 giacomo 77
        if (dvs_installed != DVS_NONE && dvs_installed != DVS_MEDIAGX_GEODE) {
78
                res = cpufreq_target(target_freq, relation);
79
                TRACER_LOGEVENT(FTrace_EVT_cycles_per_msec,0,clk_per_msec);
80
                return res;
81
        } else {
82
                return -1;
83
        }
782 giacomo 84
 
582 mauro 85
}
86
 
789 giacomo 87
extern void gx_force_values(unsigned char on_duration, unsigned char off_duration);
88
 
89
int CPU26_set_suspend_modulation(unsigned char on_duration, unsigned char off_duration) {
90
 
91
        if (dvs_installed == DVS_MEDIAGX_GEODE) {
92
                gx_force_values(on_duration, off_duration);
93
                return 0;
94
        }
95
 
96
        return -1;
97
 
98
}
99
 
770 mauro 100
inline int  CPU26_get_cur_frequency()
582 mauro 101
{
597 mauro 102
        return cpufreq_get_cur_freq();
582 mauro 103
}
104
 
770 mauro 105
inline int  CPU26_get_min_frequency()
582 mauro 106
{
597 mauro 107
        return cpufreq_get_min_freq();
108
}
582 mauro 109
 
770 mauro 110
inline int  CPU26_get_max_frequency()
597 mauro 111
{
112
        return cpufreq_get_max_freq();
582 mauro 113
}
114
 
779 giacomo 115
inline int CPU26_get_frequencies(int *buf)
582 mauro 116
{
775 mauro 117
        return cpufreq_get_available_freqs (buf);
118
}
119
 
779 giacomo 120
inline int CPU26_show_frequencies(char *buf)
775 mauro 121
{
770 mauro 122
        return cpufreq_show_available_freqs (buf);
123
}
124
 
125
inline int  CPU26_get_latency()
126
{
597 mauro 127
        return cpufreq_get_latency();
582 mauro 128
}
129
 
779 giacomo 130
inline int  CPU26_DVS_status(void)
582 mauro 131
{
779 giacomo 132
        return dvs_installed;
133
}      
134
 
135
int  CPU26_DVS_init(void)
136
{
582 mauro 137
        int ret = 0;
138
 
139
        if (cpu_installed == FALSE)
140
                return -1;
141
 
142
        if (dvs_installed != DVS_NONE)
143
                return 0;
144
 
145
        ret = powernow_k6_init();
146
#ifdef __CPU26_DEBUG__
147
        printk(KERN_DEBUG "Check PowerNow! K6 - Returned: %d\n", ret);
148
#endif
149
        if (!ret) {
150
                dvs_installed = DVS_POWERNOW_K6;
151
                return dvs_installed;
152
        }
153
 
154
        ret = powernow_init();
155
#ifdef __CPU26_DEBUG__
156
        printk(KERN_DEBUG "Check PowerNow! K7 - Returned: %d\n", ret);
157
#endif
158
        if (!ret) {
159
                dvs_installed = DVS_POWERNOW_K7;
160
                return dvs_installed;
161
        }
162
 
163
        ret = powernowk8_init();
164
#ifdef __CPU26_DEBUG__
165
        printk(KERN_DEBUG "Check PowerNow! K8 - Returned: %d\n", ret);
166
#endif
167
        if (!ret) {
168
                dvs_installed = DVS_POWERNOW_K8;
169
                return dvs_installed;
170
        }
171
 
172
        ret = cpufreq_gx_init();
173
#ifdef __CPU26_DEBUG__
174
        printk(KERN_DEBUG "Check MediaGX/Geode (Returned: %d)\n", ret);
175
#endif
176
        if (!ret) {
177
                dvs_installed = DVS_MEDIAGX_GEODE;
178
                return dvs_installed;
179
        }
180
 
181
        ret = cpufreq_p4_init();
182
#ifdef __CPU26_DEBUG__
183
        printk(KERN_DEBUG "Check Pentium4 ClockModulation (Returned: %d)\n", ret);
184
#endif
185
        if (!ret) {
186
                dvs_installed = DVS_P4_CLOCK_MOD;
187
                return dvs_installed;
188
        }
189
 
190
        ret = centrino_init();
191
#ifdef __CPU26_DEBUG__
192
        printk(KERN_DEBUG "Check SpeedStep Centrino (Returned: %d)\n", ret);
193
#endif
194
        if (!ret) {
195
                dvs_installed = DVS_SS_CENTRINO;
196
                return dvs_installed;
197
        }
198
 
199
        ret = speedstep_ich_init();
200
#ifdef __CPU26_DEBUG__
201
        printk(KERN_DEBUG "Check SpeedStep ICH (Returned: %d)\n", ret);
202
#endif
203
        if (!ret) {
204
                dvs_installed = DVS_SS_ICH;
205
                return dvs_installed;
206
        }
207
 
208
        /*ret = speedstep_smi_init();
209
#ifdef __CPU26_DEBUG__
210
        printk(KERN_DEBUG "Check SpeedStep SMI (Returned: %d)\n", ret);
211
#endif
212
        if (!ret) {
213
                dvs_installed = DVS_SS_SMI;
214
                return dvs_installed;
215
        }*/
216
 
217
        return -1;
218
}
219
 
779 giacomo 220
int  CPU26_DVS_close(void)
582 mauro 221
{
222
        switch(dvs_installed) {
223
                case DVS_NONE:
224
                        return -1;
225
                case DVS_POWERNOW_K6:
226
                        powernow_k6_exit();
227
                        return 0;
228
                case DVS_POWERNOW_K7:
229
                        powernow_exit();
230
                        return 0;
231
                case DVS_POWERNOW_K8:
232
                        powernowk8_exit();
233
                        return 0;
234
                case DVS_MEDIAGX_GEODE:
235
                        cpufreq_gx_exit();
236
                        return 0;
237
                case DVS_P4_CLOCK_MOD:
238
                        cpufreq_p4_exit();
239
                        return 0;
240
                case DVS_SS_CENTRINO:
241
                        centrino_exit();
242
                        return 0;
243
                case DVS_SS_ICH:
244
                        speedstep_ich_exit();
245
                        return 0;
246
                /*case DVS_SS_SMI:
247
                        speedstep_smi_exit();
248
                        return 0;*/
249
        }
250
 
251
        dvs_installed = DVS_NONE;
252
        return 0;
253
}
597 mauro 254
 
255
/* Init the Linux CPU Layer */
770 mauro 256
inline int  CPU26_installed(void)
597 mauro 257
{
258
        return cpu_installed;
259
}
260
 
770 mauro 261
inline void CPU26_showinfo(void)
597 mauro 262
{
263
        print_cpu_info_0();
264
}
265
 
266
int  CPU26_init(void)
267
{
268
        int ret = 0;
269
 
270
        if (cpu_installed == TRUE) return 0;
271
 
272
        early_cpu_init();
273
 
274
        identify_cpu_0();
275
 
276
        printk(KERN_INFO);
277
        print_cpu_info_0();
278
 
279
        cpu_installed = TRUE;
280
 
281
        return ret;
282
}
283
 
770 mauro 284
inline int  CPU26_close(void)
597 mauro 285
{
286
        if (cpu_installed == TRUE) {
287
                return 0;
288
        } else
289
                return -1;
290
}