xref: /openbmc/u-boot/arch/arm/cpu/arm11/cpu.c (revision 2d2811c2)
1 /*
2  * (C) Copyright 2004 Texas Insturments
3  *
4  * (C) Copyright 2002
5  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
6  * Marius Groeger <mgroeger@sysgo.de>
7  *
8  * (C) Copyright 2002
9  * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
10  *
11  * SPDX-License-Identifier:	GPL-2.0+
12  */
13 
14 /*
15  * CPU specific code
16  */
17 
18 #include <common.h>
19 #include <command.h>
20 #include <asm/system.h>
21 
22 static void cache_flush(void);
23 
24 int cleanup_before_linux (void)
25 {
26 	/*
27 	 * this function is called just before we call linux
28 	 * it prepares the processor for linux
29 	 *
30 	 * we turn off caches etc ...
31 	 */
32 
33 	disable_interrupts ();
34 
35 	/* turn off I/D-cache */
36 	icache_disable();
37 	dcache_disable();
38 	/* flush I/D-cache */
39 	cache_flush();
40 
41 	return 0;
42 }
43 
44 static void cache_flush(void)
45 {
46 	unsigned long i = 0;
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));
53 }
54 
55 #ifndef CONFIG_SYS_DCACHE_OFF
56 
57 #ifndef CONFIG_SYS_CACHELINE_SIZE
58 #define CONFIG_SYS_CACHELINE_SIZE	32
59 #endif
60 
61 void invalidate_dcache_all(void)
62 {
63 	asm volatile("mcr p15, 0, %0, c7, c6, 0" : : "r" (0));
64 }
65 
66 void flush_dcache_all(void)
67 {
68 	asm volatile("mcr p15, 0, %0, c7, c10, 0" : : "r" (0));
69 	asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
70 }
71 
72 void invalidate_dcache_range(unsigned long start, unsigned long stop)
73 {
74 	if (!check_cache_range(start, stop))
75 		return;
76 
77 	while (start < stop) {
78 		asm volatile("mcr p15, 0, %0, c7, c6, 1" : : "r" (start));
79 		start += CONFIG_SYS_CACHELINE_SIZE;
80 	}
81 }
82 
83 void flush_dcache_range(unsigned long start, unsigned long stop)
84 {
85 	if (!check_cache_range(start, stop))
86 		return;
87 
88 	while (start < stop) {
89 		asm volatile("mcr p15, 0, %0, c7, c14, 1" : : "r" (start));
90 		start += CONFIG_SYS_CACHELINE_SIZE;
91 	}
92 
93 	asm volatile("mcr p15, 0, %0, c7, c10, 4" : : "r" (0));
94 }
95 
96 #else /* #ifndef CONFIG_SYS_DCACHE_OFF */
97 void invalidate_dcache_all(void)
98 {
99 }
100 
101 void flush_dcache_all(void)
102 {
103 }
104 #endif /* #ifndef CONFIG_SYS_DCACHE_OFF */
105 
106 #if !defined(CONFIG_SYS_ICACHE_OFF) || !defined(CONFIG_SYS_DCACHE_OFF)
107 void enable_caches(void)
108 {
109 #ifndef CONFIG_SYS_ICACHE_OFF
110 	icache_enable();
111 #endif
112 #ifndef CONFIG_SYS_DCACHE_OFF
113 	dcache_enable();
114 #endif
115 }
116 #endif
117