2 * Cache-handling routined for MIPS 4K CPUs
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/regdef.h>
28 #include <asm/mipsregs.h>
29 #include <asm/addrspace.h>
30 #include <asm/cacheops.h>
32 /* 16KB is the maximum size of instruction and data caches on
35 #define MIPS_MAX_CACHE_SIZE 0x4000
38 * cacheop macro to automate cache operations
39 * first some helpers...
41 #define _mincache(size, maxsize) \
42 bltu size,maxsize,9f ; \
46 #define _align(minaddr, maxaddr, linesize) \
48 subu AT,linesize,1 ; \
55 /* general operations */
58 #define doop2(op1, op2) \
63 /* specials for cache initialisation */
64 #define doop1lw(op1) \
66 #define doop1lw1(op1) \
70 #define doop121(op1,op2) \
77 #define _oploopn(minaddr, maxaddr, linesize, tag, ops) \
79 10: doop##tag##ops ; \
80 bne minaddr,maxaddr,10b ; \
81 add minaddr,linesize ; \
84 /* finally the cache operation macros */
85 #define vcacheopn(kva, n, cacheSize, cacheLineSize, tag, ops) \
88 _align(kva, n, cacheLineSize) ; \
89 _oploopn(kva, n, cacheLineSize, tag, ops) ; \
92 #define icacheopn(kva, n, cacheSize, cacheLineSize, tag, ops) \
93 _mincache(n, cacheSize); \
96 _align(kva, n, cacheLineSize) ; \
97 _oploopn(kva, n, cacheLineSize, tag, ops) ; \
100 #define vcacheop(kva, n, cacheSize, cacheLineSize, op) \
101 vcacheopn(kva, n, cacheSize, cacheLineSize, 1, (op))
103 #define icacheop(kva, n, cacheSize, cacheLineSize, op) \
104 icacheopn(kva, n, cacheSize, cacheLineSize, 1, (op))
106 /*******************************************************************************
108 * mips_cache_reset - low level initialisation of the primary caches
110 * This routine initialises the primary caches to ensure that they
111 * have good parity. It must be called by the ROM before any cached locations
112 * are used to prevent the possibility of data with bad parity being written to
114 * To initialise the instruction cache it is essential that a source of data
115 * with good parity is available. This routine
116 * will initialise an area of memory starting at location zero to be used as
117 * a source of parity.
122 .globl mips_cache_reset
123 .ent mips_cache_reset
126 li t2, CFG_ICACHE_SIZE
127 li t3, CFG_DCACHE_SIZE
128 li t4, CFG_CACHELINE_SIZE
131 li v0, MIPS_MAX_CACHE_SIZE
133 /* Now clear that much memory starting from zero.
156 * The caches are probably in an indeterminate state,
157 * so we force good parity into them by doing an
158 * invalidate, load/fill, invalidate for each line.
161 /* Assume bottom of RAM will generate good parity for the cache.
165 move a2, t2 # icacheSize
166 move a3, t4 # icacheLineSize
168 icacheopn(a0,a1,a2,a3,121,(Index_Store_Tag_I,Fill))
170 /* To support Orion/R4600, we initialise the data cache in 3 passes.
173 /* 1: initialise dcache tags.
177 move a2, t3 # dcacheSize
178 move a3, t5 # dcacheLineSize
180 icacheop(a0,a1,a2,a3,Index_Store_Tag_D)
186 move a2, t3 # dcacheSize
187 move a3, t5 # dcacheLineSize
189 icacheopn(a0,a1,a2,a3,1lw,(dummy))
191 /* 3: clear dcache tags.
195 move a2, t3 # dcacheSize
196 move a3, t5 # dcacheLineSize
198 icacheop(a0,a1,a2,a3,Index_Store_Tag_D)
202 .end mips_cache_reset
204 /*******************************************************************************
206 * dcache_status - get cache status
208 * RETURNS: 0 - cache disabled; 1 - cache enabled
221 /*******************************************************************************
223 * dcache_disable - disable cache
228 .globl dcache_disable
235 ori t0, t0, CONF_CM_UNCACHED
241 /*******************************************************************************
243 * mips_cache_lock - lock RAM area pointed to by a0 in cache.
248 #if defined(CONFIG_PURPLE)
249 # define CACHE_LOCK_SIZE (CFG_DCACHE_SIZE/2)
251 # define CACHE_LOCK_SIZE (CFG_DCACHE_SIZE)
253 .globl mips_cache_lock
256 li a1, K0BASE - CACHE_LOCK_SIZE
258 li a2, CACHE_LOCK_SIZE
259 li a3, CFG_CACHELINE_SIZE
261 icacheop(a0,a1,a2,a3,0x1d)