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>
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 ...
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 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
56 void invalidate_dcache_all(void)
58 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
61 void flush_dcache_all(void)
63 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
64 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
67 void invalidate_dcache_range(unsigned long start, unsigned long stop)
69 if (!check_cache_range(start, stop))
72 while (start < stop) {
73 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
74 start += CONFIG_SYS_CACHELINE_SIZE;
78 void flush_dcache_range(unsigned long start, unsigned long stop)
80 if (!check_cache_range(start, stop))
83 while (start < stop) {
84 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
85 start += CONFIG_SYS_CACHELINE_SIZE;
88 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
91 #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
92 void invalidate_dcache_all(void)
96 void flush_dcache_all(void)
99 #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
101 #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
102 void enable_caches(void)
104 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
107 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)