2 * (C) Copyright 2004 Texas Insturments
5 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
6 * Marius Groeger <mgroeger@sysgo.de>
9 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
11 * SPDX-License-Identifier: GPL-2.0+
20 #include <asm/system.h>
22 static void cache_flush(void);
24 int cleanup_before_linux (void)
27 * this function is called just before we call linux
28 * it prepares the processor for linux
30 * we turn off caches etc ...
33 disable_interrupts ();
35 /* turn off I/D-cache */
44 static void cache_flush(void)
47 /* clean entire data cache */
48 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
49 /* invalidate both caches and flush btb */
50 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
51 /* mem barrier to sync things */
52 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
55 #ifndef CONFIG_SYS_DCACHE_OFF
57 #ifndef CONFIG_SYS_CACHELINE_SIZE
58 #define CONFIG_SYS_CACHELINE_SIZE 32
61 void invalidate_dcache_all(void)
63 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
66 void flush_dcache_all(void)
68 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
69 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
72 void invalidate_dcache_range(unsigned long start, unsigned long stop)
74 if (!check_cache_range(start, stop))
77 while (start < stop) {
78 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
79 start += CONFIG_SYS_CACHELINE_SIZE;
83 void flush_dcache_range(unsigned long start, unsigned long stop)
85 if (!check_cache_range(start, stop))
88 while (start < stop) {
89 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
90 start += CONFIG_SYS_CACHELINE_SIZE;
93 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
96 #else /* #ifndef CONFIG_SYS_DCACHE_OFF */
97 void invalidate_dcache_all(void)
101 void flush_dcache_all(void)
104 #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
106 #if !defined(CONFIG_SYS_ICACHE_OFF) || !defined(CONFIG_SYS_DCACHE_OFF)
107 void enable_caches(void)
109 #ifndef CONFIG_SYS_ICACHE_OFF
112 #ifndef CONFIG_SYS_DCACHE_OFF