]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/arm/lib/cache-cp15.c
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,
25 #include <asm/system.h>
27 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
29 #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
30 #define CACHE_SETUP 0x1a
32 #define CACHE_SETUP 0x1e
35 DECLARE_GLOBAL_DATA_PTR
;
37 void __arm_init_before_mmu(void)
40 void arm_init_before_mmu(void)
41 __attribute__((weak
, alias("__arm_init_before_mmu")));
43 static void cp_delay (void)
47 /* copro seems to need some delay between reading and writing */
48 for (i
= 0; i
< 100; i
++)
50 asm volatile("" : : : "memory");
53 static inline void dram_bank_mmu_setup(int bank
)
55 u32
*page_table
= (u32
*)gd
->tlb_addr
;
59 debug("%s: bank: %d\n", __func__
, bank
);
60 for (i
= bd
->bi_dram
[bank
].start
>> 20;
61 i
< (bd
->bi_dram
[bank
].start
+ bd
->bi_dram
[bank
].size
) >> 20;
63 page_table
[i
] = i
<< 20 | (3 << 10) | CACHE_SETUP
;
67 /* to activate the MMU we need to set up virtual memory: use 1M areas */
68 static inline void mmu_setup(void)
70 u32
*page_table
= (u32
*)gd
->tlb_addr
;
74 arm_init_before_mmu();
75 /* Set up an identity-mapping for all 4GB, rw for everyone */
76 for (i
= 0; i
< 4096; i
++)
77 page_table
[i
] = i
<< 20 | (3 << 10) | 0x12;
79 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
80 dram_bank_mmu_setup(i
);
83 /* Copy the page table address to cp15 */
84 asm volatile("mcr p15, 0, %0, c2, c0, 0"
85 : : "r" (page_table
) : "memory");
86 /* Set the access control to all-supervisor */
87 asm volatile("mcr p15, 0, %0, c3, c0, 0"
89 /* and enable the mmu */
90 reg
= get_cr(); /* get control reg. */
95 static int mmu_enabled(void)
97 return get_cr() & CR_M
;
100 /* cache_bit must be either CR_I or CR_C */
101 static void cache_enable(uint32_t cache_bit
)
105 /* The data cache is not active unless the mmu is enabled too */
106 if ((cache_bit
== CR_C
) && !mmu_enabled())
108 reg
= get_cr(); /* get control reg. */
110 set_cr(reg
| cache_bit
);
113 /* cache_bit must be either CR_I or CR_C */
114 static void cache_disable(uint32_t cache_bit
)
118 if (cache_bit
== CR_C
) {
119 /* if cache isn;t enabled no need to disable */
121 if ((reg
& CR_C
) != CR_C
)
123 /* if disabling data cache, disable mmu too */
129 set_cr(reg
& ~cache_bit
);
133 #ifdef CONFIG_SYS_ICACHE_OFF
134 void icache_enable (void)
139 void icache_disable (void)
144 int icache_status (void)
146 return 0; /* always off */
149 void icache_enable(void)
154 void icache_disable(void)
159 int icache_status(void)
161 return (get_cr() & CR_I
) != 0;
165 #ifdef CONFIG_SYS_DCACHE_OFF
166 void dcache_enable (void)
171 void dcache_disable (void)
176 int dcache_status (void)
178 return 0; /* always off */
181 void dcache_enable(void)
186 void dcache_disable(void)
191 int dcache_status(void)
193 return (get_cr() & CR_C
) != 0;