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