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>
21 #include <asm/system.h>
23 static void cache_flush(void);
25 int cleanup_before_linux (void)
28 * this function is called just before we call linux
29 * it prepares the processor for linux
31 * we turn off caches etc ...
36 /* turn off I/D-cache */
45 static void cache_flush(void)
48 /* clean entire data cache */
49 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
50 /* invalidate both caches and flush btb */
51 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
52 /* mem barrier to sync things */
53 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
56 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
57 void invalidate_dcache_all(void)
59 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
62 void flush_dcache_all(void)
64 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
65 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
68 void invalidate_dcache_range(unsigned long start, unsigned long stop)
70 if (!check_cache_range(start, stop))
73 while (start < stop) {
74 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
75 start += CONFIG_SYS_CACHELINE_SIZE;
79 void flush_dcache_range(unsigned long start, unsigned long stop)
81 if (!check_cache_range(start, stop))
84 while (start < stop) {
85 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
86 start += CONFIG_SYS_CACHELINE_SIZE;
89 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
92 #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
93 void invalidate_dcache_all(void)
97 void flush_dcache_all(void)
100 #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
102 #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
103 void enable_caches(void)
105 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
108 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)