cache-v6.S 7.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 *  linux/arch/arm/mm/cache-v6.S
 *
 *  Copyright (C) 2001 Deep Blue Solutions Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 *  This is the "shell" of the ARMv6 processor support.
 */
#include <linux/linkage.h>
#include <linux/init.h>
#include <asm/assembler.h>
15
#include <asm/errno.h>
16
#include <asm/unwind.h>
L
Linus Torvalds 已提交
17 18 19 20 21 22

#include "proc-macros.S"

#define HARVARD_CACHE
#define CACHE_LINE_SIZE		32
#define D_CACHE_LINE_SIZE	32
23
#define BTB_FLUSH_SIZE		8
L
Linus Torvalds 已提交
24

25
/*
26 27 28
 *	v6_flush_icache_all()
 *
 *	Flush the whole I-cache.
29
 *
30 31 32 33 34 35 36
 *	ARM1136 erratum 411920 - Invalidate Instruction Cache operation can fail.
 *	This erratum is present in 1136, 1156 and 1176. It does not affect the
 *	MPCore.
 *
 *	Registers:
 *	r0 - set to 0
 *	r1 - corrupted
37
 */
38
ENTRY(v6_flush_icache_all)
39
	mov	r0, #0
40
#ifdef CONFIG_ARM_ERRATA_411920
41 42 43 44 45 46 47 48 49 50
	mrs	r1, cpsr
	cpsid	ifa				@ disable interrupts
	mcr	p15, 0, r0, c7, c5, 0		@ invalidate entire I-cache
	mcr	p15, 0, r0, c7, c5, 0		@ invalidate entire I-cache
	mcr	p15, 0, r0, c7, c5, 0		@ invalidate entire I-cache
	mcr	p15, 0, r0, c7, c5, 0		@ invalidate entire I-cache
	msr	cpsr_cx, r1			@ restore interrupts
	.rept	11				@ ARM Ltd recommends at least
	nop					@ 11 NOPs
	.endr
51 52
#else
	mcr	p15, 0, r0, c7, c5, 0		@ invalidate I-cache
53
#endif
54 55
	mov	pc, lr
ENDPROC(v6_flush_icache_all)
56

L
Linus Torvalds 已提交
57 58 59 60 61 62 63 64 65 66 67
/*
 *	v6_flush_cache_all()
 *
 *	Flush the entire cache.
 *
 *	It is assumed that:
 */
ENTRY(v6_flush_kern_cache_all)
	mov	r0, #0
#ifdef HARVARD_CACHE
	mcr	p15, 0, r0, c7, c14, 0		@ D cache clean+invalidate
68
#ifndef CONFIG_ARM_ERRATA_411920
L
Linus Torvalds 已提交
69
	mcr	p15, 0, r0, c7, c5, 0		@ I+BTB cache invalidate
70
#else
71
	b	v6_flush_icache_all
72
#endif
L
Linus Torvalds 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
#else
	mcr	p15, 0, r0, c7, c15, 0		@ Cache clean+invalidate
#endif
	mov	pc, lr

/*
 *	v6_flush_cache_all()
 *
 *	Flush all TLB entries in a particular address space
 *
 *	- mm    - mm_struct describing address space
 */
ENTRY(v6_flush_user_cache_all)
	/*FALLTHROUGH*/

/*
 *	v6_flush_cache_range(start, end, flags)
 *
 *	Flush a range of TLB entries in the specified address space.
 *
 *	- start - start address (may not be aligned)
 *	- end   - end address (exclusive, may not be aligned)
 *	- flags	- vm_area_struct flags describing address space
 *
 *	It is assumed that:
 *	- we have a VIPT cache.
 */
ENTRY(v6_flush_user_cache_range)
	mov	pc, lr

/*
 *	v6_coherent_kern_range(start,end)
 *
 *	Ensure that the I and D caches are coherent within specified
 *	region.  This is typically used when code has been written to
 *	a memory region, and will be executed.
 *
 *	- start   - virtual start address of region
 *	- end     - virtual end address of region
 *
 *	It is assumed that:
 *	- the Icache does not read data from the write buffer
 */
ENTRY(v6_coherent_kern_range)
	/* FALLTHROUGH */

/*
 *	v6_coherent_user_range(start,end)
 *
 *	Ensure that the I and D caches are coherent within specified
 *	region.  This is typically used when code has been written to
 *	a memory region, and will be executed.
 *
 *	- start   - virtual start address of region
 *	- end     - virtual end address of region
 *
 *	It is assumed that:
 *	- the Icache does not read data from the write buffer
 */
ENTRY(v6_coherent_user_range)
133
 UNWIND(.fnstart		)
L
Linus Torvalds 已提交
134
#ifdef HARVARD_CACHE
135
	bic	r0, r0, #CACHE_LINE_SIZE - 1
136 137
1:
 USER(	mcr	p15, 0, r0, c7, c10, 1	)	@ clean D line
138
	add	r0, r0, #CACHE_LINE_SIZE
L
Linus Torvalds 已提交
139 140
	cmp	r0, r1
	blo	1b
141
#endif
L
Linus Torvalds 已提交
142
	mov	r0, #0
143
#ifdef HARVARD_CACHE
L
Linus Torvalds 已提交
144
	mcr	p15, 0, r0, c7, c10, 4		@ drain write buffer
145
#ifndef CONFIG_ARM_ERRATA_411920
146
	mcr	p15, 0, r0, c7, c5, 0		@ I+BTB cache invalidate
147
#else
148
	b	v6_flush_icache_all
149
#endif
150 151
#else
	mcr	p15, 0, r0, c7, c5, 6		@ invalidate BTB
L
Linus Torvalds 已提交
152 153 154
#endif
	mov	pc, lr

155 156
/*
 * Fault handling for the cache operation above. If the virtual address in r0
157
 * isn't mapped, fail with -EFAULT.
158 159
 */
9001:
160 161
	mov	r0, #-EFAULT
	mov	pc, lr
162 163 164 165
 UNWIND(.fnend		)
ENDPROC(v6_coherent_user_range)
ENDPROC(v6_coherent_kern_range)

L
Linus Torvalds 已提交
166
/*
167
 *	v6_flush_kern_dcache_area(void *addr, size_t size)
L
Linus Torvalds 已提交
168 169 170 171
 *
 *	Ensure that the data held in the page kaddr is written back
 *	to the page in question.
 *
172 173
 *	- addr	- kernel address
 *	- size	- region size
L
Linus Torvalds 已提交
174
 */
175 176
ENTRY(v6_flush_kern_dcache_area)
	add	r1, r0, r1
177
	bic	r0, r0, #D_CACHE_LINE_SIZE - 1
L
Linus Torvalds 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
1:
#ifdef HARVARD_CACHE
	mcr	p15, 0, r0, c7, c14, 1		@ clean & invalidate D line
#else
	mcr	p15, 0, r0, c7, c15, 1		@ clean & invalidate unified line
#endif	
	add	r0, r0, #D_CACHE_LINE_SIZE
	cmp	r0, r1
	blo	1b
#ifdef HARVARD_CACHE
	mov	r0, #0
	mcr	p15, 0, r0, c7, c10, 4
#endif
	mov	pc, lr


/*
 *	v6_dma_inv_range(start,end)
 *
 *	Invalidate the data cache within the specified region; we will
 *	be performing a DMA operation in this region and we want to
 *	purge old data in the cache.
 *
 *	- start   - virtual start address of region
 *	- end     - virtual end address of region
 */
204
v6_dma_inv_range:
205 206 207 208
#ifdef CONFIG_DMA_CACHE_RWFO
	ldrb	r2, [r0]			@ read for ownership
	strb	r2, [r0]			@ write for ownership
#endif
L
Linus Torvalds 已提交
209 210 211 212 213 214 215 216
	tst	r0, #D_CACHE_LINE_SIZE - 1
	bic	r0, r0, #D_CACHE_LINE_SIZE - 1
#ifdef HARVARD_CACHE
	mcrne	p15, 0, r0, c7, c10, 1		@ clean D line
#else
	mcrne	p15, 0, r0, c7, c11, 1		@ clean unified line
#endif
	tst	r1, #D_CACHE_LINE_SIZE - 1
217 218 219 220
#ifdef CONFIG_DMA_CACHE_RWFO
	ldrneb	r2, [r1, #-1]			@ read for ownership
	strneb	r2, [r1, #-1]			@ write for ownership
#endif
L
Linus Torvalds 已提交
221 222 223 224 225 226 227 228 229 230 231 232 233 234
	bic	r1, r1, #D_CACHE_LINE_SIZE - 1
#ifdef HARVARD_CACHE
	mcrne	p15, 0, r1, c7, c14, 1		@ clean & invalidate D line
#else
	mcrne	p15, 0, r1, c7, c15, 1		@ clean & invalidate unified line
#endif
1:
#ifdef HARVARD_CACHE
	mcr	p15, 0, r0, c7, c6, 1		@ invalidate D line
#else
	mcr	p15, 0, r0, c7, c7, 1		@ invalidate unified line
#endif
	add	r0, r0, #D_CACHE_LINE_SIZE
	cmp	r0, r1
235 236 237 238
#ifdef CONFIG_DMA_CACHE_RWFO
	ldrlo	r2, [r0]			@ read for ownership
	strlo	r2, [r0]			@ write for ownership
#endif
L
Linus Torvalds 已提交
239 240 241 242 243 244 245 246 247 248
	blo	1b
	mov	r0, #0
	mcr	p15, 0, r0, c7, c10, 4		@ drain write buffer
	mov	pc, lr

/*
 *	v6_dma_clean_range(start,end)
 *	- start   - virtual start address of region
 *	- end     - virtual end address of region
 */
249
v6_dma_clean_range:
L
Linus Torvalds 已提交
250 251
	bic	r0, r0, #D_CACHE_LINE_SIZE - 1
1:
252
#ifdef CONFIG_DMA_CACHE_RWFO
253 254
	ldr	r2, [r0]			@ read for ownership
#endif
L
Linus Torvalds 已提交
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
#ifdef HARVARD_CACHE
	mcr	p15, 0, r0, c7, c10, 1		@ clean D line
#else
	mcr	p15, 0, r0, c7, c11, 1		@ clean unified line
#endif
	add	r0, r0, #D_CACHE_LINE_SIZE
	cmp	r0, r1
	blo	1b
	mov	r0, #0
	mcr	p15, 0, r0, c7, c10, 4		@ drain write buffer
	mov	pc, lr

/*
 *	v6_dma_flush_range(start,end)
 *	- start   - virtual start address of region
 *	- end     - virtual end address of region
 */
ENTRY(v6_dma_flush_range)
273
#ifdef CONFIG_DMA_CACHE_RWFO
274 275
	ldrb	r2, [r0]		@ read for ownership
	strb	r2, [r0]		@ write for ownership
276
#endif
277 278
	bic	r0, r0, #D_CACHE_LINE_SIZE - 1
1:
L
Linus Torvalds 已提交
279 280 281 282 283 284 285
#ifdef HARVARD_CACHE
	mcr	p15, 0, r0, c7, c14, 1		@ clean & invalidate D line
#else
	mcr	p15, 0, r0, c7, c15, 1		@ clean & invalidate line
#endif
	add	r0, r0, #D_CACHE_LINE_SIZE
	cmp	r0, r1
286 287 288 289
#ifdef CONFIG_DMA_CACHE_RWFO
	ldrlob	r2, [r0]			@ read for ownership
	strlob	r2, [r0]			@ write for ownership
#endif
L
Linus Torvalds 已提交
290 291 292 293 294
	blo	1b
	mov	r0, #0
	mcr	p15, 0, r0, c7, c10, 4		@ drain write buffer
	mov	pc, lr

295 296 297 298 299 300 301 302
/*
 *	dma_map_area(start, size, dir)
 *	- start	- kernel virtual start address
 *	- size	- size of region
 *	- dir	- DMA direction
 */
ENTRY(v6_dma_map_area)
	add	r1, r1, r0
303 304
	teq	r2, #DMA_FROM_DEVICE
	beq	v6_dma_inv_range
305 306 307
#ifndef CONFIG_DMA_CACHE_RWFO
	b	v6_dma_clean_range
#else
308 309 310
	teq	r2, #DMA_TO_DEVICE
	beq	v6_dma_clean_range
	b	v6_dma_flush_range
311
#endif
312 313 314 315 316 317 318 319 320
ENDPROC(v6_dma_map_area)

/*
 *	dma_unmap_area(start, size, dir)
 *	- start	- kernel virtual start address
 *	- size	- size of region
 *	- dir	- DMA direction
 */
ENTRY(v6_dma_unmap_area)
321 322 323 324 325
#ifndef CONFIG_DMA_CACHE_RWFO
	add	r1, r1, r0
	teq	r2, #DMA_TO_DEVICE
	bne	v6_dma_inv_range
#endif
326 327 328
	mov	pc, lr
ENDPROC(v6_dma_unmap_area)

329 330 331
	.globl	v6_flush_kern_cache_louis
	.equ	v6_flush_kern_cache_louis, v6_flush_kern_cache_all

L
Linus Torvalds 已提交
332 333
	__INITDATA

334 335
	@ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
	define_cache_functions v6