1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2004 Texas Insturments
6 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
10 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
19 #include <asm/system.h>
21 static void cache_flush(void);
23 int cleanup_before_linux (void)
26 * this function is called just before we call linux
27 * it prepares the processor for linux
29 * we turn off caches etc ...
32 disable_interrupts ();
34 /* turn off I/D-cache */
43 static void cache_flush(void)
46 /* clean entire data cache */
47 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i
));
48 /* invalidate both caches and flush btb */
49 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i
));
50 /* mem barrier to sync things */
51 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i
));
54 #ifndef CONFIG_SYS_DCACHE_OFF
55 void invalidate_dcache_all(void)
57 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
60 void flush_dcache_all(void)
62 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
63 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
66 void invalidate_dcache_range(unsigned long start
, unsigned long stop
)
68 if (!check_cache_range(start
, stop
))
71 while (start
< stop
) {
72 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start
));
73 start
+= CONFIG_SYS_CACHELINE_SIZE
;
77 void flush_dcache_range(unsigned long start
, unsigned long stop
)
79 if (!check_cache_range(start
, stop
))
82 while (start
< stop
) {
83 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start
));
84 start
+= CONFIG_SYS_CACHELINE_SIZE
;
87 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
90 #else /* #ifndef CONFIG_SYS_DCACHE_OFF */
91 void invalidate_dcache_all(void)
95 void flush_dcache_all(void)
98 #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
100 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
101 void enable_caches(void)
103 #ifndef CONFIG_SYS_ICACHE_OFF
106 #ifndef CONFIG_SYS_DCACHE_OFF