1 /* $NetBSD: cpufunc_asm_armv5.S,v 1.3 2007/01/06 00:50:54 christos Exp $ */
4 * Copyright (c) 2002, 2005 ARM Limited
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the company may not be used to endorse or promote
16 * products derived from this software without specific prior written
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * ARMv5 assembly functions for manipulating caches.
32 * These routines can be used by any core that supports the set/index
36 #include <machine/asm.h>
37 __FBSDID("$FreeBSD$");
40 * Functions to set the MMU Translation Table Base register
42 * We need to clean and flush the cache as it uses virtual
43 * addresses that are about to change.
47 bl _C_LABEL(armv5_idcache_wbinv_all)
50 mcr p15, 0, r0, c2, c0, 0 /* load new TTB */
52 mcr p15, 0, r0, c8, c7, 0 /* invalidate I+D TLBs */
57 * Cache operations. For the entire cache we use the set/index
65 ENTRY_NP(armv5_icache_sync_range)
66 ldr ip, .Larmv5_line_size
68 bcs .Larmv5_icache_sync_all
70 sub r1, r1, #1 /* Don't overrun */
76 mcr p15, 0, r0, c7, c5, 1 /* Invalidate I cache SE with VA */
77 mcr p15, 0, r0, c7, c10, 1 /* Clean D cache SE with VA */
81 mcr p15, 0, r0, c7, c10, 4 /* drain the write buffer */
83 END(armv5_icache_sync_range)
85 ENTRY_NP(armv5_icache_sync_all)
86 .Larmv5_icache_sync_all:
88 * We assume that the code here can never be out of sync with the
89 * dcache, so that we can safely flush the Icache and fall through
90 * into the Dcache cleaning code.
92 mcr p15, 0, r0, c7, c5, 0 /* Flush I cache */
93 /* Fall through to clean Dcache. */
96 ldr ip, .Larmv5_cache_data
97 ldmia ip, {s_max, i_max, s_inc, i_inc}
101 mcr p15, 0, ip, c7, c10, 2 /* Clean D cache SE with Set/Index */
103 tst ip, i_max /* Index 0 is last one */
104 bne 2b /* Next index */
105 mcr p15, 0, ip, c7, c10, 2 /* Clean D cache SE with Set/Index */
106 subs s_max, s_max, s_inc
107 bpl 1b /* Next set */
108 mcr p15, 0, r0, c7, c10, 4 /* drain the write buffer */
110 END(armv5_icache_sync_all)
113 .word _C_LABEL(arm_pdcache_line_size)
115 ENTRY(armv5_dcache_wb_range)
116 ldr ip, .Larmv5_line_size
118 bcs .Larmv5_dcache_wb
120 sub r1, r1, #1 /* Don't overrun */
126 mcr p15, 0, r0, c7, c10, 1 /* Clean D cache SE with VA */
130 mcr p15, 0, r0, c7, c10, 4 /* drain the write buffer */
132 END(armv5_dcache_wb_range)
134 ENTRY(armv5_dcache_wbinv_range)
135 ldr ip, .Larmv5_line_size
137 bcs .Larmv5_dcache_wbinv_all
139 sub r1, r1, #1 /* Don't overrun */
145 mcr p15, 0, r0, c7, c14, 1 /* Purge D cache SE with VA */
149 mcr p15, 0, r0, c7, c10, 4 /* drain the write buffer */
151 END(armv5_dcache_wbinv_range)
154 * Note, we must not invalidate everything. If the range is too big we
155 * must use wb-inv of the entire cache.
157 ENTRY(armv5_dcache_inv_range)
158 ldr ip, .Larmv5_line_size
160 bcs .Larmv5_dcache_wbinv_all
162 sub r1, r1, #1 /* Don't overrun */
168 mcr p15, 0, r0, c7, c6, 1 /* Invalidate D cache SE with VA */
172 mcr p15, 0, r0, c7, c10, 4 /* drain the write buffer */
174 END(armv5_dcache_inv_range)
176 ENTRY(armv5_idcache_wbinv_range)
177 ldr ip, .Larmv5_line_size
179 bcs .Larmv5_idcache_wbinv_all
181 sub r1, r1, #1 /* Don't overrun */
187 mcr p15, 0, r0, c7, c5, 1 /* Invalidate I cache SE with VA */
188 mcr p15, 0, r0, c7, c14, 1 /* Purge D cache SE with VA */
192 mcr p15, 0, r0, c7, c10, 4 /* drain the write buffer */
194 END(armv5_idcache_wbinv_range)
196 ENTRY_NP(armv5_idcache_wbinv_all)
197 armv5_idcache_wbinv_all:
198 .Larmv5_idcache_wbinv_all:
200 * We assume that the code here can never be out of sync with the
201 * dcache, so that we can safely flush the Icache and fall through
202 * into the Dcache purging code.
204 mcr p15, 0, r0, c7, c5, 0 /* Flush I cache */
205 /* Fall through to purge Dcache. */
207 EENTRY(armv5_dcache_wbinv_all)
208 .Larmv5_dcache_wbinv_all:
209 ldr ip, .Larmv5_cache_data
210 ldmia ip, {s_max, i_max, s_inc, i_inc}
214 mcr p15, 0, ip, c7, c14, 2 /* Purge D cache SE with Set/Index */
216 tst ip, i_max /* Index 0 is last one */
217 bne 2b /* Next index */
218 mcr p15, 0, ip, c7, c14, 2 /* Purge D cache SE with Set/Index */
219 subs s_max, s_max, s_inc
220 bpl 1b /* Next set */
221 mcr p15, 0, r0, c7, c10, 4 /* drain the write buffer */
223 EEND(armv5_dcache_wbinv_all)
224 END(armv5_idcache_wbinv_all)
227 .word _C_LABEL(armv5_dcache_sets_max)
231 /* XXX The following macros should probably be moved to asm.h */
232 #define _DATA_OBJECT(x) .globl x; .type x,_ASM_TYPE_OBJECT; x:
233 #define C_OBJECT(x) _DATA_OBJECT(_C_LABEL(x))
236 * Parameters for the cache cleaning code. Note that the order of these
237 * four variables is assumed in the code above. Hence the reason for
238 * declaring them in the assembler file.
241 C_OBJECT(armv5_dcache_sets_max)
243 C_OBJECT(armv5_dcache_index_max)
245 C_OBJECT(armv5_dcache_sets_inc)
247 C_OBJECT(armv5_dcache_index_inc)