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/cache.h>
22 #include <asm/system.h>
24 static void cache_flush(void);
26 int cleanup_before_linux (void)
29 * this function is called just before we call linux
30 * it prepares the processor for linux
32 * we turn off caches etc ...
37 /* turn off I/D-cache */
46 static void cache_flush(void)
49 /* clean entire data cache */
50 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (i));
51 /* invalidate both caches and flush btb */
52 asm volatile("mcr p15, 0, %0, c7, c7, 0" : : "r" (i));
53 /* mem barrier to sync things */
54 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (i));
57 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
58 void invalidate_dcache_all(void)
60 asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
63 void flush_dcache_all(void)
65 asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
66 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
69 void invalidate_dcache_range(unsigned long start, unsigned long stop)
71 if (!check_cache_range(start, stop))
74 while (start < stop) {
75 asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
76 start += CONFIG_SYS_CACHELINE_SIZE;
80 void flush_dcache_range(unsigned long start, unsigned long stop)
82 if (!check_cache_range(start, stop))
85 while (start < stop) {
86 asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
87 start += CONFIG_SYS_CACHELINE_SIZE;
90 asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
93 #else /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
94 void invalidate_dcache_all(void)
98 void flush_dcache_all(void)
101 #endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
103 #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
104 void enable_caches(void)
106 #if !CONFIG_IS_ENABLED(SYS_ICACHE_OFF)
109 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)