summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2009-02-11 12:55:51 +0000
committerMichael Sevakis <jethead71@rockbox.org>2009-02-11 12:55:51 +0000
commit21f0c9a2829415f52b64cbdf965b01525e78f17a (patch)
treeb5cb8021097722969f75784011c9f64f991c0c3d
parent4cd7597172d916db9fc99bde4c03b669366f852a (diff)
downloadrockbox-21f0c9a2829415f52b64cbdf965b01525e78f17a.tar.gz
rockbox-21f0c9a2829415f52b64cbdf965b01525e78f17a.zip
Make basic cache functions into calls, and get rid of CACHE_FUNCTION_WRAPPERS and CACHE_FUNCTIONS_AS_CALL macros. Rename flush/invalidate_icache to cpucache_flush/invalidate. They're inlined only if an implementation isn't provided by defining HAVE_CPUCACHE_FLUSH/INVALIDATE.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19971 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs.c8
-rw-r--r--apps/codecs.h24
-rw-r--r--apps/codecs/codec_crt0.c4
-rw-r--r--apps/codecs/mpa.c2
-rw-r--r--apps/codecs/spc.c6
-rw-r--r--apps/playback.c4
-rw-r--r--apps/plugin.c12
-rw-r--r--apps/plugin.h21
-rw-r--r--apps/plugins/mpegplayer/alloc.c2
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c2
-rw-r--r--apps/plugins/mpegplayer/video_thread.c8
-rw-r--r--apps/plugins/rockboy/dynarec.c2
-rw-r--r--apps/plugins/test_codec.c6
-rw-r--r--bootloader/gigabeat-s.c4
-rw-r--r--bootloader/gigabeat.c4
-rw-r--r--firmware/export/system.h16
-rw-r--r--firmware/rolo.c6
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/system-target.h32
-rw-r--r--firmware/target/arm/mmu-arm.c30
-rw-r--r--firmware/target/arm/s3c2440/gigabeat-fx/system-target.h14
-rw-r--r--firmware/target/arm/system-pp5002.c6
-rw-r--r--firmware/target/arm/system-pp502x.c6
-rw-r--r--firmware/target/arm/system-target.h9
-rw-r--r--firmware/target/coldfire/system-coldfire.c8
-rw-r--r--firmware/target/coldfire/system-target.h9
-rw-r--r--firmware/target/sh/system-target.h2
-rw-r--r--firmware/thread.c60
-rw-r--r--firmware/usbstack/usb_storage.c2
28 files changed, 136 insertions, 173 deletions
diff --git a/apps/codecs.c b/apps/codecs.c
index 231b612358..4fcf9ce02f 100644
--- a/apps/codecs.c
+++ b/apps/codecs.c
@@ -113,9 +113,9 @@ struct codec_api ci = {
113 semaphore_release, 113 semaphore_release,
114#endif 114#endif
115 115
116#ifdef CACHE_FUNCTIONS_AS_CALL 116#if NUM_CORES > 1
117 flush_icache, 117 cpucache_flush,
118 invalidate_icache, 118 cpucache_invalidate,
119#endif 119#endif
120 120
121 /* strings and memory */ 121 /* strings and memory */
@@ -232,7 +232,7 @@ static int codec_load_ram(int size, struct codec_api *api)
232 } 232 }
233 233
234 *(hdr->api) = api; 234 *(hdr->api) = api;
235 invalidate_icache(); 235 cpucache_invalidate();
236 status = hdr->entry_point(); 236 status = hdr->entry_point();
237 237
238 sim_codec_close(pd); 238 sim_codec_close(pd);
diff --git a/apps/codecs.h b/apps/codecs.h
index 3eab1d35c2..c2358e1750 100644
--- a/apps/codecs.h
+++ b/apps/codecs.h
@@ -170,9 +170,9 @@ struct codec_api {
170 void (*semaphore_release)(struct semaphore *s); 170 void (*semaphore_release)(struct semaphore *s);
171#endif /* NUM_CORES */ 171#endif /* NUM_CORES */
172 172
173#ifdef CACHE_FUNCTIONS_AS_CALL 173#if NUM_CORES > 1
174 void (*flush_icache)(void); 174 void (*cpucache_flush)(void);
175 void (*invalidate_icache)(void); 175 void (*cpucache_invalidate)(void);
176#endif 176#endif
177 177
178 /* strings and memory */ 178 /* strings and memory */
@@ -297,22 +297,4 @@ int codec_load_file(const char* codec, struct codec_api *api);
297enum codec_status codec_start(void); 297enum codec_status codec_start(void);
298enum codec_status codec_main(void); 298enum codec_status codec_main(void);
299 299
300#ifndef CACHE_FUNCTION_WRAPPERS
301
302#ifdef CACHE_FUNCTIONS_AS_CALL
303#define CACHE_FUNCTION_WRAPPERS(api) \
304 void flush_icache(void) \
305 { \
306 (api)->flush_icache(); \
307 } \
308 void invalidate_icache(void) \
309 { \
310 (api)->invalidate_icache(); \
311 }
312#else
313#define CACHE_FUNCTION_WRAPPERS(api)
314#endif /* CACHE_FUNCTIONS_AS_CALL */
315
316#endif /* CACHE_FUNCTION_WRAPPERS */
317
318#endif 300#endif
diff --git a/apps/codecs/codec_crt0.c b/apps/codecs/codec_crt0.c
index 467e115de9..09b6982246 100644
--- a/apps/codecs/codec_crt0.c
+++ b/apps/codecs/codec_crt0.c
@@ -34,8 +34,6 @@ extern unsigned char plugin_end_addr[];
34 34
35extern enum codec_status codec_main(void); 35extern enum codec_status codec_main(void);
36 36
37CACHE_FUNCTION_WRAPPERS(ci);
38
39enum codec_status codec_start(void) 37enum codec_status codec_start(void)
40{ 38{
41#ifndef SIMULATOR 39#ifndef SIMULATOR
@@ -47,7 +45,7 @@ enum codec_status codec_start(void)
47#endif 45#endif
48#if NUM_CORES > 1 46#if NUM_CORES > 1
49 /* writeback cleared iedata and bss areas */ 47 /* writeback cleared iedata and bss areas */
50 flush_icache(); 48 ci->cpucache_flush();
51#endif 49#endif
52 return codec_main(); 50 return codec_main();
53} 51}
diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c
index 1a0b03c272..1b71bde79e 100644
--- a/apps/codecs/mpa.c
+++ b/apps/codecs/mpa.c
@@ -268,7 +268,7 @@ static void mad_synth_thread_quit(void)
268 die=1; 268 die=1;
269 ci->semaphore_release(&synth_pending_sem); 269 ci->semaphore_release(&synth_pending_sem);
270 ci->thread_wait(mad_synth_thread_id); 270 ci->thread_wait(mad_synth_thread_id);
271 invalidate_icache(); 271 ci->cpucache_invalidate();
272} 272}
273#else 273#else
274static inline void mad_synth_thread_ready(void) 274static inline void mad_synth_thread_ready(void)
diff --git a/apps/codecs/spc.c b/apps/codecs/spc.c
index 5ac594431a..6ceb704c7c 100644
--- a/apps/codecs/spc.c
+++ b/apps/codecs/spc.c
@@ -302,7 +302,7 @@ static bool emu_thread_process_msg(struct sample_queue_chunk *chunk)
302 if (id == SPC_EMU_LOAD) 302 if (id == SPC_EMU_LOAD)
303 { 303 {
304 struct spc_load *ld = (struct spc_load *)chunk->data; 304 struct spc_load *ld = (struct spc_load *)chunk->data;
305 invalidate_icache(); 305 ci->cpucache_invalidate();
306 SPC_Init(&spc_emu); 306 SPC_Init(&spc_emu);
307 sample_queue.retval = SPC_load_spc(&spc_emu, ld->buf, ld->size); 307 sample_queue.retval = SPC_load_spc(&spc_emu, ld->buf, ld->size);
308 308
@@ -376,7 +376,7 @@ static bool spc_emu_start(void)
376static inline int load_spc_buffer(uint8_t *buf, size_t size) 376static inline int load_spc_buffer(uint8_t *buf, size_t size)
377{ 377{
378 struct spc_load ld = { buf, size }; 378 struct spc_load ld = { buf, size };
379 flush_icache(); 379 ci->cpucache_flush();
380 return emu_thread_send_msg(SPC_EMU_LOAD, (intptr_t)&ld); 380 return emu_thread_send_msg(SPC_EMU_LOAD, (intptr_t)&ld);
381} 381}
382 382
@@ -386,7 +386,7 @@ static inline void spc_emu_quit(void)
386 emu_thread_send_msg(SPC_EMU_QUIT, 0); 386 emu_thread_send_msg(SPC_EMU_QUIT, 0);
387 /* Wait for emu thread to be killed */ 387 /* Wait for emu thread to be killed */
388 ci->thread_wait(emu_thread_id); 388 ci->thread_wait(emu_thread_id);
389 invalidate_icache(); 389 ci->cpucache_invalidate();
390 } 390 }
391} 391}
392 392
diff --git a/apps/playback.c b/apps/playback.c
index 55c1878d4e..deaebfbdf0 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -1317,9 +1317,9 @@ static void codec_thread(void)
1317 queue_reply(&codec_queue, 1); 1317 queue_reply(&codec_queue, 1);
1318 if ((void*)ev.data != NULL) 1318 if ((void*)ev.data != NULL)
1319 { 1319 {
1320 invalidate_icache(); 1320 cpucache_invalidate();
1321 ((void (*)(void))ev.data)(); 1321 ((void (*)(void))ev.data)();
1322 flush_icache(); 1322 cpucache_flush();
1323 } 1323 }
1324 break; 1324 break;
1325 1325
diff --git a/apps/plugin.c b/apps/plugin.c
index 3b14b0032f..f9f1c53617 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -327,9 +327,9 @@ static const struct plugin_api rockbox_api = {
327 trigger_cpu_boost, 327 trigger_cpu_boost,
328 cancel_cpu_boost, 328 cancel_cpu_boost,
329#endif 329#endif
330#ifdef CACHE_FUNCTIONS_AS_CALL 330#if NUM_CORES > 1
331 flush_icache, 331 cpucache_flush,
332 invalidate_icache, 332 cpucache_invalidate,
333#endif 333#endif
334 timer_register, 334 timer_register,
335 timer_unregister, 335 timer_unregister,
@@ -694,7 +694,7 @@ int plugin_load(const char* plugin, const void* parameter)
694#if NUM_CORES > 1 694#if NUM_CORES > 1
695 /* Make sure COP cache is flushed and invalidated before loading */ 695 /* Make sure COP cache is flushed and invalidated before loading */
696 my_core = switch_core(CURRENT_CORE ^ 1); 696 my_core = switch_core(CURRENT_CORE ^ 1);
697 invalidate_icache(); 697 cpucache_invalidate();
698 switch_core(my_core); 698 switch_core(my_core);
699#endif 699#endif
700 700
@@ -742,7 +742,7 @@ int plugin_load(const char* plugin, const void* parameter)
742 lcd_remote_update(); 742 lcd_remote_update();
743#endif 743#endif
744 744
745 invalidate_icache(); 745 cpucache_invalidate();
746 oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL); 746 oldbars = viewportmanager_set_statusbar(VP_SB_HIDE_ALL);
747 747
748 rc = hdr->entry_point(parameter); 748 rc = hdr->entry_point(parameter);
@@ -854,7 +854,7 @@ void plugin_iram_init(char *iramstart, char *iramcopy, size_t iram_size,
854 memset(iramcopy, 0, iram_size); 854 memset(iramcopy, 0, iram_size);
855#if NUM_CORES > 1 855#if NUM_CORES > 1
856 /* writeback cleared iedata and iramcopy areas */ 856 /* writeback cleared iedata and iramcopy areas */
857 flush_icache(); 857 cpucache_flush();
858#endif 858#endif
859} 859}
860#endif /* PLUGIN_USE_IRAM */ 860#endif /* PLUGIN_USE_IRAM */
diff --git a/apps/plugin.h b/apps/plugin.h
index 9ebf793d3f..715f2ec512 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -438,9 +438,9 @@ struct plugin_api {
438 void (*trigger_cpu_boost)(void); 438 void (*trigger_cpu_boost)(void);
439 void (*cancel_cpu_boost)(void); 439 void (*cancel_cpu_boost)(void);
440#endif 440#endif
441#ifdef CACHE_FUNCTIONS_AS_CALL 441#if NUM_CORES > 1
442 void (*flush_icache)(void); 442 void (*cpucache_flush)(void);
443 void (*invalidate_icache)(void); 443 void (*cpucache_invalidate)(void);
444#endif 444#endif
445 bool (*timer_register)(int reg_prio, void (*unregister_callback)(void), 445 bool (*timer_register)(int reg_prio, void (*unregister_callback)(void),
446 long cycles, int int_prio, 446 long cycles, int int_prio,
@@ -854,20 +854,5 @@ extern const struct plugin_api *rb;
854enum plugin_status plugin_start(const void* parameter) 854enum plugin_status plugin_start(const void* parameter)
855 NO_PROF_ATTR; 855 NO_PROF_ATTR;
856 856
857#undef CACHE_FUNCTION_WRAPPERS
858#ifdef CACHE_FUNCTIONS_AS_CALL
859#define CACHE_FUNCTION_WRAPPERS \
860 void flush_icache(void) \
861 { \
862 rb->flush_icache(); \
863 } \
864 void invalidate_icache(void) \
865 { \
866 rb->invalidate_icache(); \
867 }
868#else
869#define CACHE_FUNCTION_WRAPPERS
870#endif /* CACHE_FUNCTIONS_AS_CALL */
871
872#endif /* __PCTOOL__ */ 857#endif /* __PCTOOL__ */
873#endif 858#endif
diff --git a/apps/plugins/mpegplayer/alloc.c b/apps/plugins/mpegplayer/alloc.c
index a69b6accf8..da92f8754a 100644
--- a/apps/plugins/mpegplayer/alloc.c
+++ b/apps/plugins/mpegplayer/alloc.c
@@ -149,7 +149,7 @@ bool mpeg_alloc_init(unsigned char *buf, size_t mallocsize)
149 return false; 149 return false;
150 } 150 }
151 151
152 IF_COP(invalidate_icache()); 152 IF_COP(rb->cpucache_invalidate());
153 return true; 153 return true;
154} 154}
155 155
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index 6e8f9350f8..eaf8f246c6 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -296,8 +296,6 @@ CONFIG_KEYPAD == SANSA_M200_PAD
296#endif 296#endif
297#endif 297#endif
298 298
299CACHE_FUNCTION_WRAPPERS;
300
301/* One thing we can do here for targets with remotes is having a display 299/* One thing we can do here for targets with remotes is having a display
302 * always on the remote instead of always forcing a popup on the main display */ 300 * always on the remote instead of always forcing a popup on the main display */
303 301
diff --git a/apps/plugins/mpegplayer/video_thread.c b/apps/plugins/mpegplayer/video_thread.c
index 8b84686a3b..6d60e64131 100644
--- a/apps/plugins/mpegplayer/video_thread.c
+++ b/apps/plugins/mpegplayer/video_thread.c
@@ -524,7 +524,7 @@ static void video_thread_msg(struct video_thread_data *td)
524 } 524 }
525 else 525 else
526 { 526 {
527 IF_COP(invalidate_icache()); 527 IF_COP(rb->cpucache_invalidate());
528 vo_lock(); 528 vo_lock();
529 rb->lcd_update(); 529 rb->lcd_update();
530 vo_unlock(); 530 vo_unlock();
@@ -996,7 +996,7 @@ bool video_thread_init(void)
996{ 996{
997 intptr_t rep; 997 intptr_t rep;
998 998
999 IF_COP(flush_icache()); 999 IF_COP(rb->cpucache_flush());
1000 1000
1001 video_str.hdr.q = &video_str_queue; 1001 video_str.hdr.q = &video_str_queue;
1002 rb->queue_init(video_str.hdr.q, false); 1002 rb->queue_init(video_str.hdr.q, false);
@@ -1014,7 +1014,7 @@ bool video_thread_init(void)
1014 1014
1015 /* Wait for thread to initialize */ 1015 /* Wait for thread to initialize */
1016 rep = str_send_msg(&video_str, STREAM_NULL, 0); 1016 rep = str_send_msg(&video_str, STREAM_NULL, 0);
1017 IF_COP(invalidate_icache()); 1017 IF_COP(rb->cpucache_invalidate());
1018 1018
1019 return rep == 0; /* Normally STREAM_NULL should be ignored */ 1019 return rep == 0; /* Normally STREAM_NULL should be ignored */
1020} 1020}
@@ -1026,7 +1026,7 @@ void video_thread_exit(void)
1026 { 1026 {
1027 str_post_msg(&video_str, STREAM_QUIT, 0); 1027 str_post_msg(&video_str, STREAM_QUIT, 0);
1028 rb->thread_wait(video_str.thread); 1028 rb->thread_wait(video_str.thread);
1029 IF_COP(invalidate_icache()); 1029 IF_COP(rb->cpucache_invalidate());
1030 video_str.thread = 0; 1030 video_str.thread = 0;
1031 } 1031 }
1032} 1032}
diff --git a/apps/plugins/rockboy/dynarec.c b/apps/plugins/rockboy/dynarec.c
index 7c466de986..afe6caaf1a 100644
--- a/apps/plugins/rockboy/dynarec.c
+++ b/apps/plugins/rockboy/dynarec.c
@@ -1905,7 +1905,7 @@ void dynamic_recompile (struct dynarec_block *newblock)
1905 PC=oldpc; 1905 PC=oldpc;
1906 setmallocpos(dynapointer); 1906 setmallocpos(dynapointer);
1907 newblock->length=dynapointer-newblock->block; 1907 newblock->length=dynapointer-newblock->block;
1908 invalidate_icache(); 1908 IF_COP(rb->cpucache_invalidate());
1909 snprintf(meow,499,"/dyna_0x%x_code.rb",PC); 1909 snprintf(meow,499,"/dyna_0x%x_code.rb",PC);
1910 fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC); 1910 fd=open(meow,O_WRONLY|O_CREAT|O_TRUNC);
1911 if(fd>=0) 1911 if(fd>=0)
diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c
index ec5c8e9800..3260360882 100644
--- a/apps/plugins/test_codec.c
+++ b/apps/plugins/test_codec.c
@@ -480,9 +480,9 @@ static void init_ci(void)
480 ci.profile_func_exit = rb->profile_func_exit; 480 ci.profile_func_exit = rb->profile_func_exit;
481#endif 481#endif
482 482
483#ifdef CACHE_FUNCTIONS_AS_CALL 483#if NUM_CORES > 1
484 ci.invalidate_icache = invalidate_icache; 484 ci.cpucache_invalidate = rb->cpucache_invalidate;
485 ci.flush_icache = flush_icache; 485 ci.cpucache_flush = rb->cpucache_flush;
486#endif 486#endif
487 487
488#if NUM_CORES > 1 488#if NUM_CORES > 1
diff --git a/bootloader/gigabeat-s.c b/bootloader/gigabeat-s.c
index cd3b1df545..2e95d4cf64 100644
--- a/bootloader/gigabeat-s.c
+++ b/bootloader/gigabeat-s.c
@@ -311,7 +311,7 @@ static void __attribute__((noreturn)) handle_firmware_load(void)
311 311
312 if (rc == EOK) 312 if (rc == EOK)
313 { 313 {
314 invalidate_icache(); 314 cpucache_invalidate();
315 asm volatile ("bx %0": : "r"(start_addr)); 315 asm volatile ("bx %0": : "r"(start_addr));
316 } 316 }
317 317
@@ -332,7 +332,7 @@ void main(void)
332 int rc; 332 int rc;
333 333
334 /* Flush and invalidate all caches (because vectors were written) */ 334 /* Flush and invalidate all caches (because vectors were written) */
335 invalidate_icache(); 335 cpucache_invalidate();
336 336
337 system_init(); 337 system_init();
338 kernel_init(); 338 kernel_init();
diff --git a/bootloader/gigabeat.c b/bootloader/gigabeat.c
index a3732b0e06..23fedcc463 100644
--- a/bootloader/gigabeat.c
+++ b/bootloader/gigabeat.c
@@ -196,7 +196,7 @@ void main(void)
196 printf("Loading firmware"); 196 printf("Loading firmware");
197 197
198 /* Flush out anything pending first */ 198 /* Flush out anything pending first */
199 invalidate_icache(); 199 cpucache_invalidate();
200 200
201 loadbuffer = (unsigned char*) 0x31000000; 201 loadbuffer = (unsigned char*) 0x31000000;
202 buffer_size = (unsigned char*)0x31400000 - loadbuffer; 202 buffer_size = (unsigned char*)0x31400000 - loadbuffer;
@@ -210,7 +210,7 @@ void main(void)
210 210
211 if (rc == EOK) 211 if (rc == EOK)
212 { 212 {
213 invalidate_icache(); 213 cpucache_invalidate();
214 kernel_entry = (void*) loadbuffer; 214 kernel_entry = (void*) loadbuffer;
215 rc = kernel_entry(); 215 rc = kernel_entry();
216 } 216 }
diff --git a/firmware/export/system.h b/firmware/export/system.h
index fb9dfa3003..b44600d2c2 100644
--- a/firmware/export/system.h
+++ b/firmware/export/system.h
@@ -272,12 +272,20 @@ static inline uint32_t swap_odd_even32(uint32_t value)
272#endif 272#endif
273 273
274/* Just define these as empty if not declared */ 274/* Just define these as empty if not declared */
275#ifndef HAVE_INVALIDATE_ICACHE 275#ifdef HAVE_CPUCACHE_INVALIDATE
276#define invalidate_icache() 276void cpucache_invalidate(void);
277#else
278static inline void cpucache_invalidate(void)
279{
280}
277#endif 281#endif
278 282
279#ifndef HAVE_FLUSH_ICACHE 283#ifdef HAVE_CPUCACHE_FLUSH
280#define flush_icache() 284void cpucache_flush(void);
285#else
286static inline void cpucache_flush(void)
287{
288}
281#endif 289#endif
282 290
283#ifdef PROC_NEEDS_CACHEALIGN 291#ifdef PROC_NEEDS_CACHEALIGN
diff --git a/firmware/rolo.c b/firmware/rolo.c
index 6a3fcd2bbb..014f00e2c7 100644
--- a/firmware/rolo.c
+++ b/firmware/rolo.c
@@ -75,7 +75,7 @@ void rolo_restart_cop(void)
75 COP_INT_DIS = -1; 75 COP_INT_DIS = -1;
76 76
77 /* Invalidate cache */ 77 /* Invalidate cache */
78 invalidate_icache(); 78 cpucache_invalidate();
79 79
80 /* Disable cache */ 80 /* Disable cache */
81 CACHE_CTL = CACHE_CTL_DISABLE; 81 CACHE_CTL = CACHE_CTL_DISABLE;
@@ -147,7 +147,7 @@ void rolo_restart(const unsigned char* source, unsigned char* dest,
147 CPU_INT_DIS = -1; 147 CPU_INT_DIS = -1;
148 148
149 /* Flush cache */ 149 /* Flush cache */
150 flush_icache(); 150 cpucache_flush();
151 151
152 /* Disable cache */ 152 /* Disable cache */
153 CACHE_CTL = CACHE_CTL_DISABLE; 153 CACHE_CTL = CACHE_CTL_DISABLE;
@@ -174,7 +174,7 @@ void rolo_restart(const unsigned char* source, unsigned char* dest,
174 174
175#elif defined(CPU_TCC780X) || (CONFIG_CPU == S3C2440) 175#elif defined(CPU_TCC780X) || (CONFIG_CPU == S3C2440)
176 /* Flush and invalidate caches */ 176 /* Flush and invalidate caches */
177 invalidate_icache(); 177 cpucache_invalidate();
178 178
179 asm volatile( 179 asm volatile(
180 "mov pc, %0 \n" 180 "mov pc, %0 \n"
diff --git a/firmware/target/arm/imx31/gigabeat-s/system-target.h b/firmware/target/arm/imx31/gigabeat-s/system-target.h
index ae50ec4c78..921af0ec8b 100644
--- a/firmware/target/arm/imx31/gigabeat-s/system-target.h
+++ b/firmware/target/arm/imx31/gigabeat-s/system-target.h
@@ -57,34 +57,12 @@ void imx31_regclr32(volatile uint32_t *reg_p, uint32_t mask);
57 57
58#define KDEV_INIT 58#define KDEV_INIT
59 59
60#define HAVE_INVALIDATE_ICACHE 60#define HAVE_CPUCACHE_INVALIDATE
61static inline void invalidate_icache(void) 61#define HAVE_CPUCACHE_FLUSH
62{
63 asm volatile(
64 /* Clean and invalidate entire data cache */
65 "mcr p15, 0, %0, c7, c14, 0 \n"
66 /* Invalidate entire instruction cache
67 * Also flushes the branch target cache */
68 "mcr p15, 0, %0, c7, c5, 0 \n"
69 /* Data synchronization barrier */
70 "mcr p15, 0, %0, c7, c10, 4 \n"
71 /* Flush prefetch buffer */
72 "mcr p15, 0, %0, c7, c5, 4 \n"
73 : : "r"(0)
74 );
75}
76 62
77#define HAVE_FLUSH_ICACHE 63/* Different internal names */
78static inline void flush_icache(void) 64#define cpucache_flush clean_dcache
79{ 65#define cpucache_invalidate invalidate_idcache
80 asm volatile (
81 /* Clean entire data cache */
82 "mcr p15, 0, %0, c7, c10, 0 \n"
83 /* Data synchronization barrier */
84 "mcr p15, 0, %0, c7, c10, 4 \n"
85 : : "r"(0)
86 );
87}
88 66
89struct ARM_REGS { 67struct ARM_REGS {
90 int r0; 68 int r0;
diff --git a/firmware/target/arm/mmu-arm.c b/firmware/target/arm/mmu-arm.c
index d86cd430b5..fae7fd0b8f 100644
--- a/firmware/target/arm/mmu-arm.c
+++ b/firmware/target/arm/mmu-arm.c
@@ -265,6 +265,8 @@ void __attribute__((naked)) clean_dcache(void)
265 /* Clean entire data cache */ 265 /* Clean entire data cache */
266 "mov r0, #0 \n" 266 "mov r0, #0 \n"
267 "mcr p15, 0, r0, c7, c10, 0 \n" 267 "mcr p15, 0, r0, c7, c10, 0 \n"
268 /* Data synchronization barrier */
269 "mcr p15, 0, r0, c7, c10, 4 \n"
268 "bx lr \n" 270 "bx lr \n"
269 ); 271 );
270} 272}
@@ -290,3 +292,31 @@ void clean_dcache(void)
290} 292}
291#endif 293#endif
292 294
295#if CONFIG_CPU == IMX31L
296void invalidate_idcache(void)
297{
298 asm volatile(
299 /* Clean and invalidate entire data cache */
300 "mcr p15, 0, %0, c7, c14, 0 \n"
301 /* Invalidate entire instruction cache
302 * Also flushes the branch target cache */
303 "mcr p15, 0, %0, c7, c5, 0 \n"
304 /* Data synchronization barrier */
305 "mcr p15, 0, %0, c7, c10, 4 \n"
306 /* Flush prefetch buffer */
307 "mcr p15, 0, %0, c7, c5, 4 \n"
308 : : "r"(0)
309 );
310}
311#else
312void invalidate_idcache(void)
313{
314 clean_dcache();
315 asm volatile(
316 "mov r0, #0 \n"
317 "mcr p15, 0, r0, c7, c5, 0 \n"
318 : : : "r0"
319 );
320}
321#endif
322
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/system-target.h b/firmware/target/arm/s3c2440/gigabeat-fx/system-target.h
index 320c595b99..aa7c0aa50c 100644
--- a/firmware/target/arm/s3c2440/gigabeat-fx/system-target.h
+++ b/firmware/target/arm/s3c2440/gigabeat-fx/system-target.h
@@ -41,15 +41,9 @@ void s3c_regset32(volatile unsigned long *reg, unsigned long bits);
41/* Clear register bits */ 41/* Clear register bits */
42void s3c_regclr32(volatile unsigned long *reg, unsigned long bits); 42void s3c_regclr32(volatile unsigned long *reg, unsigned long bits);
43 43
44#define HAVE_INVALIDATE_ICACHE 44#define HAVE_CPUCACHE_FLUSH
45static inline void invalidate_icache(void) 45#define HAVE_CPUCACHE_INVALIDATE
46{ 46#define cpucache_flush clean_dcache
47 clean_dcache(); 47#define cpucache_invalidate invalidate_idcache
48 asm volatile(
49 "mov r0, #0 \n"
50 "mcr p15, 0, r0, c7, c5, 0 \n"
51 : : : "r0"
52 );
53}
54 48
55#endif /* SYSTEM_TARGET_H */ 49#endif /* SYSTEM_TARGET_H */
diff --git a/firmware/target/arm/system-pp5002.c b/firmware/target/arm/system-pp5002.c
index a995a5464b..98bf5f21f1 100644
--- a/firmware/target/arm/system-pp5002.c
+++ b/firmware/target/arm/system-pp5002.c
@@ -62,8 +62,7 @@ void __attribute__((interrupt("IRQ"))) irq_handler(void)
62 some other CPU frequency scaling. */ 62 some other CPU frequency scaling. */
63 63
64#ifndef BOOTLOADER 64#ifndef BOOTLOADER
65void flush_icache(void) ICODE_ATTR; 65void ICODE_ATTR cpucache_flush(void)
66void flush_icache(void)
67{ 66{
68 intptr_t b, e; 67 intptr_t b, e;
69 68
@@ -73,8 +72,7 @@ void flush_icache(void)
73 } 72 }
74} 73}
75 74
76void invalidate_icache(void) ICODE_ATTR; 75void ICODE_ATTR cpucache_invalidate(void)
77void invalidate_icache(void)
78{ 76{
79 intptr_t b, e; 77 intptr_t b, e;
80 78
diff --git a/firmware/target/arm/system-pp502x.c b/firmware/target/arm/system-pp502x.c
index b1cef7152a..10a7651f7b 100644
--- a/firmware/target/arm/system-pp502x.c
+++ b/firmware/target/arm/system-pp502x.c
@@ -163,8 +163,7 @@ void __attribute__((interrupt("IRQ"))) irq_handler(void)
163 to extend the funtions to do alternate cache configurations. */ 163 to extend the funtions to do alternate cache configurations. */
164 164
165#ifndef BOOTLOADER 165#ifndef BOOTLOADER
166void flush_icache(void) ICODE_ATTR; 166void ICODE_ATTR cpucache_flush(void)
167void flush_icache(void)
168{ 167{
169 if (CACHE_CTL & CACHE_CTL_ENABLE) 168 if (CACHE_CTL & CACHE_CTL_ENABLE)
170 { 169 {
@@ -173,8 +172,7 @@ void flush_icache(void)
173 } 172 }
174} 173}
175 174
176void invalidate_icache(void) ICODE_ATTR; 175void ICODE_ATTR cpucache_invalidate(void)
177void invalidate_icache(void)
178{ 176{
179 if (CACHE_CTL & CACHE_CTL_ENABLE) 177 if (CACHE_CTL & CACHE_CTL_ENABLE)
180 { 178 {
diff --git a/firmware/target/arm/system-target.h b/firmware/target/arm/system-target.h
index 4719b8c971..60844e0b5f 100644
--- a/firmware/target/arm/system-target.h
+++ b/firmware/target/arm/system-target.h
@@ -168,13 +168,8 @@ static inline void wake_core(int core)
168 168
169/** cache functions **/ 169/** cache functions **/
170#ifndef BOOTLOADER 170#ifndef BOOTLOADER
171#define CACHE_FUNCTIONS_AS_CALL 171#define HAVE_CPUCACHE_INVALIDATE
172 172#define HAVE_CPUCACHE_FLUSH
173#define HAVE_INVALIDATE_ICACHE
174void invalidate_icache(void);
175
176#define HAVE_FLUSH_ICACHE
177void flush_icache(void);
178#endif 173#endif
179 174
180#endif /* CPU_PP */ 175#endif /* CPU_PP */
diff --git a/firmware/target/coldfire/system-coldfire.c b/firmware/target/coldfire/system-coldfire.c
index c4651a3c80..a96cd34441 100644
--- a/firmware/target/coldfire/system-coldfire.c
+++ b/firmware/target/coldfire/system-coldfire.c
@@ -358,3 +358,11 @@ void coldfire_set_dataincontrol(unsigned long value)
358 DATAINCONTROL = (DATAINCONTROL & (1 << 9)) | value; 358 DATAINCONTROL = (DATAINCONTROL & (1 << 9)) | value;
359 restore_irq(level); 359 restore_irq(level);
360} 360}
361
362void cpucache_invalidate(void)
363{
364 asm volatile ("move.l #0x01000000,%d0\n"
365 "movec.l %d0,%cacr\n"
366 "move.l #0x80000000,%d0\n"
367 "movec.l %d0,%cacr");
368}
diff --git a/firmware/target/coldfire/system-target.h b/firmware/target/coldfire/system-target.h
index 9c349b1436..347d8e13dc 100644
--- a/firmware/target/coldfire/system-target.h
+++ b/firmware/target/coldfire/system-target.h
@@ -194,14 +194,7 @@ static inline uint32_t swap_odd_even32(uint32_t value)
194 return value; 194 return value;
195} 195}
196 196
197#define HAVE_INVALIDATE_ICACHE 197#define HAVE_CPUCACHE_INVALIDATE
198static inline void invalidate_icache(void)
199{
200 asm volatile ("move.l #0x01000000,%d0\n"
201 "movec.l %d0,%cacr\n"
202 "move.l #0x80000000,%d0\n"
203 "movec.l %d0,%cacr");
204}
205 198
206#define DEFAULT_PLLCR_AUDIO_BITS 0x10400000 199#define DEFAULT_PLLCR_AUDIO_BITS 0x10400000
207void coldfire_set_pllcr_audio_bits(long bits); 200void coldfire_set_pllcr_audio_bits(long bits);
diff --git a/firmware/target/sh/system-target.h b/firmware/target/sh/system-target.h
index aaf6c6bb2d..3c225fbb69 100644
--- a/firmware/target/sh/system-target.h
+++ b/firmware/target/sh/system-target.h
@@ -126,6 +126,4 @@ static inline uint32_t swap_odd_even32(uint32_t value)
126 return value; 126 return value;
127} 127}
128 128
129#define invalidate_icache()
130
131#endif /* SYSTEM_TARGET_H */ 129#endif /* SYSTEM_TARGET_H */
diff --git a/firmware/thread.c b/firmware/thread.c
index f779ca3ae0..ce78769d11 100644
--- a/firmware/thread.c
+++ b/firmware/thread.c
@@ -179,17 +179,17 @@ static void __attribute__((naked,used)) start_thread(void)
179{ 179{
180 /* r0 = context */ 180 /* r0 = context */
181 asm volatile ( 181 asm volatile (
182 "ldr sp, [r0, #32] \n" /* Load initial sp */ 182 "ldr sp, [r0, #32] \n" /* Load initial sp */
183 "ldr r4, [r0, #40] \n" /* start in r4 since it's non-volatile */ 183 "ldr r4, [r0, #40] \n" /* start in r4 since it's non-volatile */
184 "mov r1, #0 \n" /* Mark thread as running */ 184 "mov r1, #0 \n" /* Mark thread as running */
185 "str r1, [r0, #40] \n" 185 "str r1, [r0, #40] \n"
186#if NUM_CORES > 1 186#if NUM_CORES > 1
187 "ldr r0, =invalidate_icache \n" /* Invalidate this core's cache. */ 187 "ldr r0, =cpucache_invalidate \n" /* Invalidate this core's cache. */
188 "mov lr, pc \n" /* This could be the first entry into */ 188 "mov lr, pc \n" /* This could be the first entry into */
189 "bx r0 \n" /* plugin or codec code for this core. */ 189 "bx r0 \n" /* plugin or codec code for this core. */
190#endif 190#endif
191 "mov lr, pc \n" /* Call thread function */ 191 "mov lr, pc \n" /* Call thread function */
192 "bx r4 \n" 192 "bx r4 \n"
193 ); /* No clobber list - new thread doesn't care */ 193 ); /* No clobber list - new thread doesn't care */
194 thread_exit(); 194 thread_exit();
195 //asm volatile (".ltorg"); /* Dump constant pool */ 195 //asm volatile (".ltorg"); /* Dump constant pool */
@@ -668,7 +668,7 @@ static inline void switch_to_idle_stack(const unsigned int core)
668static void core_switch_blk_op(unsigned int core, struct thread_entry *thread) 668static void core_switch_blk_op(unsigned int core, struct thread_entry *thread)
669{ 669{
670 /* Flush our data to ram */ 670 /* Flush our data to ram */
671 flush_icache(); 671 cpucache_flush();
672 /* Stash thread in r4 slot */ 672 /* Stash thread in r4 slot */
673 thread->context.r[0] = (uint32_t)thread; 673 thread->context.r[0] = (uint32_t)thread;
674 /* Stash restart address in r5 slot */ 674 /* Stash restart address in r5 slot */
@@ -696,24 +696,24 @@ static void __attribute__((naked))
696 * Stack access also isn't permitted until restoring the original stack and 696 * Stack access also isn't permitted until restoring the original stack and
697 * context. */ 697 * context. */
698 asm volatile ( 698 asm volatile (
699 "stmfd sp!, { r4-r12, lr } \n" /* Stack all non-volatile context on current core */ 699 "stmfd sp!, { r4-r12, lr } \n" /* Stack all non-volatile context on current core */
700 "ldr r2, =idle_stacks \n" /* r2 = &idle_stacks[core][IDLE_STACK_WORDS] */ 700 "ldr r2, =idle_stacks \n" /* r2 = &idle_stacks[core][IDLE_STACK_WORDS] */
701 "ldr r2, [r2, r0, lsl #2] \n" 701 "ldr r2, [r2, r0, lsl #2] \n"
702 "add r2, r2, %0*4 \n" 702 "add r2, r2, %0*4 \n"
703 "stmfd r2!, { sp } \n" /* save original stack pointer on idle stack */ 703 "stmfd r2!, { sp } \n" /* save original stack pointer on idle stack */
704 "mov sp, r2 \n" /* switch stacks */ 704 "mov sp, r2 \n" /* switch stacks */
705 "adr r2, 1f \n" /* r2 = new core restart address */ 705 "adr r2, 1f \n" /* r2 = new core restart address */
706 "str r2, [r1, #40] \n" /* thread->context.start = r2 */ 706 "str r2, [r1, #40] \n" /* thread->context.start = r2 */
707 "ldr pc, =switch_thread \n" /* r0 = thread after call - see load_context */ 707 "ldr pc, =switch_thread \n" /* r0 = thread after call - see load_context */
708 "1: \n" 708 "1: \n"
709 "ldr sp, [r0, #32] \n" /* Reload original sp from context structure */ 709 "ldr sp, [r0, #32] \n" /* Reload original sp from context structure */
710 "mov r1, #0 \n" /* Clear start address */ 710 "mov r1, #0 \n" /* Clear start address */
711 "str r1, [r0, #40] \n" 711 "str r1, [r0, #40] \n"
712 "ldr r0, =invalidate_icache \n" /* Invalidate new core's cache */ 712 "ldr r0, =cpucache_invalidate \n" /* Invalidate new core's cache */
713 "mov lr, pc \n" 713 "mov lr, pc \n"
714 "bx r0 \n" 714 "bx r0 \n"
715 "ldmfd sp!, { r4-r12, pc } \n" /* Restore non-volatile context to new core and return */ 715 "ldmfd sp!, { r4-r12, pc } \n" /* Restore non-volatile context to new core and return */
716 ".ltorg \n" /* Dump constant pool */ 716 ".ltorg \n" /* Dump constant pool */
717 : : "i"(IDLE_STACK_WORDS) 717 : : "i"(IDLE_STACK_WORDS)
718 ); 718 );
719 (void)core; (void)thread; 719 (void)core; (void)thread;
@@ -2457,7 +2457,7 @@ unsigned int create_thread(void (*function)(void),
2457 /* Writeback stack munging or anything else before starting */ 2457 /* Writeback stack munging or anything else before starting */
2458 if (core != CURRENT_CORE) 2458 if (core != CURRENT_CORE)
2459 { 2459 {
2460 flush_icache(); 2460 cpucache_flush();
2461 } 2461 }
2462#endif 2462#endif
2463 2463
@@ -2597,7 +2597,7 @@ void thread_exit(void)
2597 switch_to_idle_stack(core); 2597 switch_to_idle_stack(core);
2598 } 2598 }
2599 2599
2600 flush_icache(); 2600 cpucache_flush();
2601 2601
2602 /* At this point, this thread isn't using resources allocated for 2602 /* At this point, this thread isn't using resources allocated for
2603 * execution except the slot itself. */ 2603 * execution except the slot itself. */
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c
index 85499c1bbd..86b47cf653 100644
--- a/firmware/usbstack/usb_storage.c
+++ b/firmware/usbstack/usb_storage.c
@@ -415,7 +415,7 @@ void usb_storage_init_connection(void)
415 audio_buffer = audio_get_buffer(false,&bufsize); 415 audio_buffer = audio_get_buffer(false,&bufsize);
416 tb.transfer_buffer = 416 tb.transfer_buffer =
417 (void *)UNCACHED_ADDR((unsigned int)(audio_buffer + 31) & 0xffffffe0); 417 (void *)UNCACHED_ADDR((unsigned int)(audio_buffer + 31) & 0xffffffe0);
418 invalidate_icache(); 418 cpucache_invalidate();
419#ifdef USB_USE_RAMDISK 419#ifdef USB_USE_RAMDISK
420 ramdisk_buffer = tb.transfer_buffer + BUFFER_SIZE*2; 420 ramdisk_buffer = tb.transfer_buffer + BUFFER_SIZE*2;
421#endif 421#endif