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 static int check_cache_range(unsigned long start, unsigned long stop)
76 if (start & (CONFIG_SYS_CACHELINE_SIZE - 1))
79 if (stop & (CONFIG_SYS_CACHELINE_SIZE - 1))
83 debug("CACHE: Misaligned operation at range [%08lx, %08lx]\n",
89 void invalidate_dcache_range(unsigned long start, unsigned long stop)
91 if (!check_cache_range(start, stop))
94 while (start < stop) {
95 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
96 start += CONFIG_SYS_CACHELINE_SIZE;
100 void flush_dcache_range(unsigned long start, unsigned long stop)
102 if (!check_cache_range(start, stop))
105 while (start < stop) {
106 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
107 start += CONFIG_SYS_CACHELINE_SIZE;
110 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
113 #else /* #ifndef CONFIG_SYS_DCACHE_OFF */
114 void invalidate_dcache_all(void)
118 void flush_dcache_all(void)
121 #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
123 #if !defined(CONFIG_SYS_ICACHE_OFF) || !defined(CONFIG_SYS_DCACHE_OFF)
124 void enable_caches(void)
126 #ifndef CONFIG_SYS_ICACHE_OFF
129 #ifndef CONFIG_SYS_DCACHE_OFF