]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/lib/cache-cp15.c
arm: remove bogus cp_delay() function
[karo-tx-uboot.git] / arch / arm / lib / cache-cp15.c
1 /*
2  * (C) Copyright 2002
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <asm/system.h>
26
27 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
28
29 #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
30 #define CACHE_SETUP     0x1a
31 #else
32 #define CACHE_SETUP     0x1e
33 #endif
34
35 DECLARE_GLOBAL_DATA_PTR;
36
37 void __arm_init_before_mmu(void)
38 {
39 }
40 void arm_init_before_mmu(void)
41         __attribute__((weak, alias("__arm_init_before_mmu")));
42
43 static inline void dram_bank_mmu_setup(int bank)
44 {
45         u32 *page_table = (u32 *)gd->tlb_addr;
46         bd_t *bd = gd->bd;
47         int     i;
48
49         debug("%s: bank: %d\n", __func__, bank);
50         for (i = bd->bi_dram[bank].start >> 20;
51              i < (bd->bi_dram[bank].start + bd->bi_dram[bank].size) >> 20;
52              i++) {
53                 page_table[i] = i << 20 | (3 << 10) | CACHE_SETUP;
54         }
55 }
56
57 /* to activate the MMU we need to set up virtual memory: use 1M areas */
58 static inline void mmu_setup(void)
59 {
60         u32 *page_table = (u32 *)gd->tlb_addr;
61         int i;
62         u32 reg;
63
64         arm_init_before_mmu();
65         /* Set up an identity-mapping for all 4GB, rw for everyone */
66         for (i = 0; i < 4096; i++)
67                 page_table[i] = i << 20 | (3 << 10) | 0x12;
68
69         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
70                 dram_bank_mmu_setup(i);
71         }
72
73         /* Copy the page table address to cp15 */
74         asm volatile("mcr p15, 0, %0, c2, c0, 0"
75                      : : "r" (page_table) : "memory");
76         /* Set the access control to all-supervisor */
77         asm volatile("mcr p15, 0, %0, c3, c0, 0"
78                      : : "r" (~0));
79         /* and enable the mmu */
80         reg = get_cr(); /* get control reg. */
81         set_cr(reg | CR_M);
82 }
83
84 static int mmu_enabled(void)
85 {
86         return get_cr() & CR_M;
87 }
88
89 /* cache_bit must be either CR_I or CR_C */
90 static void cache_enable(uint32_t cache_bit)
91 {
92         uint32_t reg;
93
94         /* The data cache is not active unless the mmu is enabled too */
95         if ((cache_bit == CR_C) && !mmu_enabled())
96                 mmu_setup();
97         reg = get_cr(); /* get control reg. */
98         set_cr(reg | cache_bit);
99 }
100
101 /* cache_bit must be either CR_I or CR_C */
102 static void cache_disable(uint32_t cache_bit)
103 {
104         uint32_t reg;
105
106         if (cache_bit == CR_C) {
107                 /* if cache isn;t enabled no need to disable */
108                 reg = get_cr();
109                 if ((reg & CR_C) != CR_C)
110                         return;
111                 /* if disabling data cache, disable mmu too */
112                 cache_bit |= CR_M;
113                 flush_dcache_all();
114         }
115         reg = get_cr();
116         set_cr(reg & ~cache_bit);
117 }
118 #endif
119
120 #ifdef CONFIG_SYS_ICACHE_OFF
121 void icache_enable (void)
122 {
123         return;
124 }
125
126 void icache_disable (void)
127 {
128         return;
129 }
130
131 int icache_status (void)
132 {
133         return 0;                                       /* always off */
134 }
135 #else
136 void icache_enable(void)
137 {
138         cache_enable(CR_I);
139 }
140
141 void icache_disable(void)
142 {
143         cache_disable(CR_I);
144 }
145
146 int icache_status(void)
147 {
148         return (get_cr() & CR_I) != 0;
149 }
150 #endif
151
152 #ifdef CONFIG_SYS_DCACHE_OFF
153 void dcache_enable (void)
154 {
155         return;
156 }
157
158 void dcache_disable (void)
159 {
160         return;
161 }
162
163 int dcache_status (void)
164 {
165         return 0;                                       /* always off */
166 }
167 #else
168 void dcache_enable(void)
169 {
170         cache_enable(CR_C);
171 }
172
173 void dcache_disable(void)
174 {
175         cache_disable(CR_C);
176 }
177
178 int dcache_status(void)
179 {
180         return (get_cr() & CR_C) != 0;
181 }
182 #endif