3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
24 #include <asm/system.h>
26 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
28 #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
29 #define CACHE_SETUP 0x1a
31 #define CACHE_SETUP 0x1e
34 DECLARE_GLOBAL_DATA_PTR;
36 void __arm_init_before_mmu(void)
39 void arm_init_before_mmu(void)
40 __attribute__((weak, alias("__arm_init_before_mmu")));
42 static void cp_delay (void)
46 /* copro seems to need some delay between reading and writing */
47 for (i = 0; i < 100; i++)
49 asm volatile("" : : : "memory");
52 static inline void dram_bank_mmu_setup(int bank)
54 u32 *page_table = (u32 *)gd->tlb_addr;
58 debug("%s: bank: %d\n", __func__, bank);
59 for (i = bd->bi_dram[bank].start >> 20;
60 i < (bd->bi_dram[bank].start + bd->bi_dram[bank].size) >> 20;
62 page_table[i] = i << 20 | (3 << 10) | CACHE_SETUP;
66 /* to activate the MMU we need to set up virtual memory: use 1M areas */
67 static inline void mmu_setup(void)
69 u32 *page_table = (u32 *)gd->tlb_addr;
73 arm_init_before_mmu();
74 /* Set up an identity-mapping for all 4GB, rw for everyone */
75 for (i = 0; i < 4096; i++)
76 page_table[i] = i << 20 | (3 << 10) | 0x12;
78 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
79 dram_bank_mmu_setup(i);
83 /* Copy the page table address to cp15 */
84 "mcr p15, 0, %0, c2, c0, 0\n"
85 /* Set the access control to all-supervisor */
86 "mcr p15, 0, %1, c3, c0, 0\n"
88 : "r"(page_table), "r"(~0)
90 /* and enable the mmu */
91 reg = get_cr(); /* get control reg. */
96 static int mmu_enabled(void)
98 return get_cr() & CR_M;
101 /* cache_bit must be either CR_I or CR_C */
102 static void cache_enable(uint32_t cache_bit)
106 /* The data cache is not active unless the mmu is enabled too */
107 if ((cache_bit == CR_C) && !mmu_enabled())
109 reg = get_cr(); /* get control reg. */
111 set_cr(reg | cache_bit);
114 /* cache_bit must be either CR_I or CR_C */
115 static void cache_disable(uint32_t cache_bit)
119 if (cache_bit == CR_C) {
120 /* if cache isn;t enabled no need to disable */
122 if ((reg & CR_C) != CR_C)
124 /* if disabling data cache, disable mmu too */
130 set_cr(reg & ~cache_bit);
134 #ifdef CONFIG_SYS_ICACHE_OFF
135 void icache_enable (void)
140 void icache_disable (void)
145 int icache_status (void)
147 return 0; /* always off */
150 void icache_enable(void)
155 void icache_disable(void)
160 int icache_status(void)
162 return (get_cr() & CR_I) != 0;
166 #ifdef CONFIG_SYS_DCACHE_OFF
167 void dcache_enable (void)
172 void dcache_disable (void)
177 int dcache_status (void)
179 return 0; /* always off */
182 void dcache_enable(void)
187 void dcache_disable(void)
192 int dcache_status(void)
194 return (get_cr() & CR_C) != 0;