1 /* MN10300 CPU core caching routines
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
11 #include <linux/sys.h>
12 #include <linux/linkage.h>
15 #include <asm/cache.h>
17 #define mn10300_dcache_inv_range_intr_interval \
18 +((1 << MN10300_DCACHE_INV_RANGE_INTR_LOG2_INTERVAL) - 1)
20 #if mn10300_dcache_inv_range_intr_interval > 0xff
21 #error MN10300_DCACHE_INV_RANGE_INTR_LOG2_INTERVAL must be 8 or less
26 .globl mn10300_icache_inv
27 .globl mn10300_dcache_inv
28 .globl mn10300_dcache_inv_range
29 .globl mn10300_dcache_inv_range2
30 .globl mn10300_dcache_inv_page
32 ###############################################################################
34 # void mn10300_icache_inv(void)
35 # Invalidate the entire icache
37 ###############################################################################
44 beq mn10300_icache_inv_end
55 # and wait for it to calm down
65 # wait for the cache to finish
80 mn10300_icache_inv_end:
83 ###############################################################################
85 # void mn10300_dcache_inv(void)
86 # Invalidate the entire dcache
88 ###############################################################################
95 beq mn10300_dcache_inv_end
106 # and wait for it to calm down
116 # wait for the cache to finish
131 mn10300_dcache_inv_end:
134 ###############################################################################
136 # void mn10300_dcache_inv_range(unsigned start, unsigned end)
137 # void mn10300_dcache_inv_range2(unsigned start, unsigned size)
138 # void mn10300_dcache_inv_page(unsigned start)
139 # Invalidate a range of addresses on a page in the dcache
141 ###############################################################################
143 mn10300_dcache_inv_page:
145 mn10300_dcache_inv_range2:
147 mn10300_dcache_inv_range:
153 beq mn10300_dcache_inv_range_end
155 and L1_CACHE_TAG_ADDRESS|L1_CACHE_TAG_ENTRY,d0 # round start
159 add L1_CACHE_BYTES,d1 # round end addr up
160 and L1_CACHE_TAG_ADDRESS|L1_CACHE_TAG_ENTRY,d1
162 clr d2 # we're going to clear tag ram
165 # read the tags from the tag RAM, and if they indicate a valid dirty
166 # cache line then invalidate that line
167 mov DCACHE_TAG(0,0),a0
169 and L1_CACHE_TAG_ENTRY,d0
170 add d0,a0 # starting dcache tag RAM
174 lsr L1_CACHE_SHIFT,d1 # total number of entries to
177 and ~(L1_CACHE_DISPARITY-1),a1 # determine comparator base
179 mn10300_dcache_inv_range_outer_loop:
183 nop # note that reading CHCTR and
184 # AND'ing D0 occupy two delay
185 # slots after disabling
193 # and wait for it to calm down
199 mn10300_dcache_inv_range_loop:
201 # process the way 0 slot
202 mov (L1_CACHE_WAYDISP*0,a0),d0 # read the tag in the way 0 slot
203 btst L1_CACHE_TAG_VALID,d0
204 beq mn10300_dcache_inv_range_skip_0 # jump if this cacheline is not
209 bne mn10300_dcache_inv_range_skip_0 # jump if not this cacheline
211 mov d2,(a0) # kill the tag
213 mn10300_dcache_inv_range_skip_0:
215 # process the way 1 slot
216 mov (L1_CACHE_WAYDISP*1,a0),d0 # read the tag in the way 1 slot
217 btst L1_CACHE_TAG_VALID,d0
218 beq mn10300_dcache_inv_range_skip_1 # jump if this cacheline is not
223 bne mn10300_dcache_inv_range_skip_1 # jump if not this cacheline
225 mov d2,(a0) # kill the tag
227 mn10300_dcache_inv_range_skip_1:
229 # process the way 2 slot
230 mov (L1_CACHE_WAYDISP*2,a0),d0 # read the tag in the way 2 slot
231 btst L1_CACHE_TAG_VALID,d0
232 beq mn10300_dcache_inv_range_skip_2 # jump if this cacheline is not
237 bne mn10300_dcache_inv_range_skip_2 # jump if not this cacheline
239 mov d2,(a0) # kill the tag
241 mn10300_dcache_inv_range_skip_2:
243 # process the way 3 slot
244 mov (L1_CACHE_WAYDISP*3,a0),d0 # read the tag in the way 3 slot
245 btst L1_CACHE_TAG_VALID,d0
246 beq mn10300_dcache_inv_range_skip_3 # jump if this cacheline is not
251 bne mn10300_dcache_inv_range_skip_3 # jump if not this cacheline
253 mov d2,(a0) # kill the tag
255 mn10300_dcache_inv_range_skip_3:
257 # approx every N steps we re-enable the cache and see if there are any
258 # interrupts to be processed
259 # we also break out if we've reached the end of the loop
260 # (the bottom nibble of the count is zero in both cases)
261 add L1_CACHE_BYTES,a0
262 add L1_CACHE_BYTES,a1
264 btst mn10300_dcache_inv_range_intr_interval,d1
265 bne mn10300_dcache_inv_range_loop
267 # wait for the cache to finish what it's doing
278 # re-enable interrupts
279 # - we don't bother with delay NOPs as we'll have enough instructions
280 # before we disable interrupts again to give the interrupts a chance
284 # go around again if the counter hasn't yet reached zero
286 bne mn10300_dcache_inv_range_outer_loop
288 mn10300_dcache_inv_range_end: