1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alan Korr
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
30 long cpu_frequency SHAREDBSS_ATTR
= CPU_FREQ
;
33 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
34 static int boost_counter SHAREDBSS_ATTR
= 0;
35 static bool cpu_idle SHAREDBSS_ATTR
= false;
37 static struct corelock boostctrl_cl SHAREDBSS_ATTR
;
38 void cpu_boost_init(void)
40 corelock_init(&boostctrl_cl
);
44 int get_cpu_boost_counter(void)
48 #ifdef CPU_BOOST_LOGGING
49 #define MAX_BOOST_LOG 64
50 static char cpu_boost_calls
[MAX_BOOST_LOG
][MAX_PATH
];
51 static int cpu_boost_first
= 0;
52 static int cpu_boost_calls_count
= 0;
53 static int cpu_boost_track_message
= 0;
54 int cpu_boost_log_getcount(void)
56 return cpu_boost_calls_count
;
58 char * cpu_boost_log_getlog_first(void)
61 corelock_lock(&boostctrl_cl
);
65 if (cpu_boost_calls_count
)
67 cpu_boost_track_message
= 1;
68 first
= cpu_boost_calls
[cpu_boost_first
];
71 corelock_unlock(&boostctrl_cl
);
75 char * cpu_boost_log_getlog_next(void)
80 corelock_lock(&boostctrl_cl
);
82 message
= (cpu_boost_track_message
+cpu_boost_first
)%MAX_BOOST_LOG
;
85 if (cpu_boost_track_message
< cpu_boost_calls_count
)
87 cpu_boost_track_message
++;
88 next
= cpu_boost_calls
[message
];
91 corelock_unlock(&boostctrl_cl
);
95 void cpu_boost_(bool on_off
, char* location
, int line
)
97 corelock_lock(&boostctrl_cl
);
99 if (cpu_boost_calls_count
== MAX_BOOST_LOG
)
101 cpu_boost_first
= (cpu_boost_first
+1)%MAX_BOOST_LOG
;
102 cpu_boost_calls_count
--;
103 if (cpu_boost_calls_count
< 0)
104 cpu_boost_calls_count
= 0;
106 if (cpu_boost_calls_count
< MAX_BOOST_LOG
)
108 int message
= (cpu_boost_first
+cpu_boost_calls_count
)%MAX_BOOST_LOG
;
109 snprintf(cpu_boost_calls
[message
], MAX_PATH
,
110 "%c %s:%d",on_off
?'B':'U',location
,line
);
111 cpu_boost_calls_count
++;
114 void cpu_boost(bool on_off
)
116 corelock_lock(&boostctrl_cl
);
117 #endif /* CPU_BOOST_LOGGING */
120 /* Boost the frequency if not already boosted */
121 if(++boost_counter
== 1)
122 set_cpu_frequency(CPUFREQ_MAX
);
126 /* Lower the frequency if the counter reaches 0 */
127 if(--boost_counter
<= 0)
130 set_cpu_frequency(CPUFREQ_DEFAULT
);
132 set_cpu_frequency(CPUFREQ_NORMAL
);
135 if (boost_counter
< 0)
142 corelock_unlock(&boostctrl_cl
);
145 void cpu_idle_mode(bool on_off
)
147 corelock_lock(&boostctrl_cl
);
151 /* We need to adjust the frequency immediately if the CPU
153 if(boost_counter
== 0)
156 set_cpu_frequency(CPUFREQ_DEFAULT
);
158 set_cpu_frequency(CPUFREQ_NORMAL
);
161 corelock_unlock(&boostctrl_cl
);
163 #endif /* HAVE_ADJUSTABLE_CPU_FREQ */
166 #ifdef HAVE_FLASHED_ROCKBOX
167 static bool detect_flash_header(uint8_t *addr
)
170 int oldmode
= system_memory_guard(MEMGUARD_NONE
);
172 struct flash_header hdr
;
173 memcpy(&hdr
, addr
, sizeof(struct flash_header
));
175 system_memory_guard(oldmode
);
177 return hdr
.magic
== FLASH_MAGIC
;
181 bool detect_flashed_romimage(void)
183 #ifdef HAVE_FLASHED_ROCKBOX
184 return detect_flash_header((uint8_t *)FLASH_ROMIMAGE_ENTRY
);
187 #endif /* HAVE_FLASHED_ROCKBOX */
190 bool detect_flashed_ramimage(void)
192 #ifdef HAVE_FLASHED_ROCKBOX
193 return detect_flash_header((uint8_t *)FLASH_RAMIMAGE_ENTRY
);
196 #endif /* HAVE_FLASHED_ROCKBOX */
199 bool detect_original_firmware(void)
201 return !(detect_flashed_ramimage() || detect_flashed_romimage());