2019-06-04 16:11:33 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/arch/arm/mm/cache-v6.S
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 Deep Blue Solutions Ltd.
|
|
|
|
*
|
|
|
|
* This is the "shell" of the ARMv6 processor support.
|
|
|
|
*/
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <asm/assembler.h>
|
2012-04-27 20:08:53 +08:00
|
|
|
#include <asm/errno.h>
|
2009-10-07 00:57:09 +08:00
|
|
|
#include <asm/unwind.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include "proc-macros.S"
|
|
|
|
|
|
|
|
#define HARVARD_CACHE
|
|
|
|
#define CACHE_LINE_SIZE 32
|
|
|
|
#define D_CACHE_LINE_SIZE 32
|
2005-09-30 23:09:17 +08:00
|
|
|
#define BTB_FLUSH_SIZE 8
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-05-01 00:06:03 +08:00
|
|
|
/*
|
2010-09-22 00:16:40 +08:00
|
|
|
* v6_flush_icache_all()
|
|
|
|
*
|
|
|
|
* Flush the whole I-cache.
|
2009-05-01 00:06:03 +08:00
|
|
|
*
|
2010-09-22 00:16:40 +08:00
|
|
|
* 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
|
2009-05-01 00:06:03 +08:00
|
|
|
*/
|
2010-09-22 00:16:40 +08:00
|
|
|
ENTRY(v6_flush_icache_all)
|
2009-05-01 00:06:03 +08:00
|
|
|
mov r0, #0
|
2010-09-22 00:16:40 +08:00
|
|
|
#ifdef CONFIG_ARM_ERRATA_411920
|
2009-05-01 00:06:03 +08:00
|
|
|
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
|
2010-09-22 00:16:40 +08:00
|
|
|
#else
|
|
|
|
mcr p15, 0, r0, c7, c5, 0 @ invalidate I-cache
|
2009-05-01 00:06:03 +08:00
|
|
|
#endif
|
2014-06-30 23:29:12 +08:00
|
|
|
ret lr
|
2010-09-22 00:16:40 +08:00
|
|
|
ENDPROC(v6_flush_icache_all)
|
2009-05-01 00:06:03 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* 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
|
2009-05-01 00:06:03 +08:00
|
|
|
#ifndef CONFIG_ARM_ERRATA_411920
|
2005-04-17 06:20:36 +08:00
|
|
|
mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
|
2009-05-01 00:06:03 +08:00
|
|
|
#else
|
2010-09-22 00:16:40 +08:00
|
|
|
b v6_flush_icache_all
|
2009-05-01 00:06:03 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
|
|
|
mcr p15, 0, r0, c7, c15, 0 @ Cache clean+invalidate
|
|
|
|
#endif
|
2014-06-30 23:29:12 +08:00
|
|
|
ret lr
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
2014-06-30 23:29:12 +08:00
|
|
|
ret lr
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
2009-10-07 00:57:09 +08:00
|
|
|
UNWIND(.fnstart )
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef HARVARD_CACHE
|
2006-02-02 03:26:01 +08:00
|
|
|
bic r0, r0, #CACHE_LINE_SIZE - 1
|
2009-10-07 00:57:09 +08:00
|
|
|
1:
|
|
|
|
USER( mcr p15, 0, r0, c7, c10, 1 ) @ clean D line
|
2006-02-02 03:26:01 +08:00
|
|
|
add r0, r0, #CACHE_LINE_SIZE
|
2005-04-17 06:20:36 +08:00
|
|
|
cmp r0, r1
|
|
|
|
blo 1b
|
2006-02-02 03:26:01 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
mov r0, #0
|
2006-03-11 06:26:47 +08:00
|
|
|
#ifdef HARVARD_CACHE
|
2005-04-17 06:20:36 +08:00
|
|
|
mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
|
2009-05-01 00:06:03 +08:00
|
|
|
#ifndef CONFIG_ARM_ERRATA_411920
|
2006-03-11 06:26:47 +08:00
|
|
|
mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
|
2009-05-01 00:06:03 +08:00
|
|
|
#else
|
2010-09-22 00:16:40 +08:00
|
|
|
b v6_flush_icache_all
|
2009-05-01 00:06:03 +08:00
|
|
|
#endif
|
2006-03-11 06:26:47 +08:00
|
|
|
#else
|
|
|
|
mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2014-06-30 23:29:12 +08:00
|
|
|
ret lr
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-10-07 00:57:09 +08:00
|
|
|
/*
|
|
|
|
* Fault handling for the cache operation above. If the virtual address in r0
|
2012-04-27 20:08:53 +08:00
|
|
|
* isn't mapped, fail with -EFAULT.
|
2009-10-07 00:57:09 +08:00
|
|
|
*/
|
|
|
|
9001:
|
2012-04-27 20:08:53 +08:00
|
|
|
mov r0, #-EFAULT
|
2014-06-30 23:29:12 +08:00
|
|
|
ret lr
|
2009-10-07 00:57:09 +08:00
|
|
|
UNWIND(.fnend )
|
|
|
|
ENDPROC(v6_coherent_user_range)
|
|
|
|
ENDPROC(v6_coherent_kern_range)
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2009-11-26 20:56:21 +08:00
|
|
|
* v6_flush_kern_dcache_area(void *addr, size_t size)
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Ensure that the data held in the page kaddr is written back
|
|
|
|
* to the page in question.
|
|
|
|
*
|
2009-11-26 20:56:21 +08:00
|
|
|
* - addr - kernel address
|
|
|
|
* - size - region size
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-11-26 20:56:21 +08:00
|
|
|
ENTRY(v6_flush_kern_dcache_area)
|
|
|
|
add r1, r0, r1
|
2011-05-26 18:20:19 +08:00
|
|
|
bic r0, r0, #D_CACHE_LINE_SIZE - 1
|
2005-04-17 06:20:36 +08:00
|
|
|
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
|
2014-06-30 23:29:12 +08:00
|
|
|
ret lr
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2009-11-27 00:24:19 +08:00
|
|
|
v6_dma_inv_range:
|
2010-12-14 07:03:16 +08:00
|
|
|
#ifdef CONFIG_DMA_CACHE_RWFO
|
|
|
|
ldrb r2, [r0] @ read for ownership
|
|
|
|
strb r2, [r0] @ write for ownership
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
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
|
2010-12-14 07:03:16 +08:00
|
|
|
#ifdef CONFIG_DMA_CACHE_RWFO
|
2019-02-18 07:57:38 +08:00
|
|
|
ldrbne r2, [r1, #-1] @ read for ownership
|
|
|
|
strbne r2, [r1, #-1] @ write for ownership
|
2010-12-14 07:03:16 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
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
|
2010-12-14 07:03:16 +08:00
|
|
|
#ifdef CONFIG_DMA_CACHE_RWFO
|
|
|
|
ldrlo r2, [r0] @ read for ownership
|
|
|
|
strlo r2, [r0] @ write for ownership
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
blo 1b
|
|
|
|
mov r0, #0
|
|
|
|
mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
|
2014-06-30 23:29:12 +08:00
|
|
|
ret lr
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* v6_dma_clean_range(start,end)
|
|
|
|
* - start - virtual start address of region
|
|
|
|
* - end - virtual end address of region
|
|
|
|
*/
|
2009-11-27 00:24:19 +08:00
|
|
|
v6_dma_clean_range:
|
2005-04-17 06:20:36 +08:00
|
|
|
bic r0, r0, #D_CACHE_LINE_SIZE - 1
|
|
|
|
1:
|
2010-06-21 22:10:07 +08:00
|
|
|
#ifdef CONFIG_DMA_CACHE_RWFO
|
2010-05-07 23:26:24 +08:00
|
|
|
ldr r2, [r0] @ read for ownership
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
#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
|
2014-06-30 23:29:12 +08:00
|
|
|
ret lr
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* v6_dma_flush_range(start,end)
|
|
|
|
* - start - virtual start address of region
|
|
|
|
* - end - virtual end address of region
|
|
|
|
*/
|
|
|
|
ENTRY(v6_dma_flush_range)
|
2010-06-21 22:10:07 +08:00
|
|
|
#ifdef CONFIG_DMA_CACHE_RWFO
|
2010-12-14 07:03:16 +08:00
|
|
|
ldrb r2, [r0] @ read for ownership
|
|
|
|
strb r2, [r0] @ write for ownership
|
2010-05-07 23:26:24 +08:00
|
|
|
#endif
|
2010-12-14 07:03:16 +08:00
|
|
|
bic r0, r0, #D_CACHE_LINE_SIZE - 1
|
|
|
|
1:
|
2005-04-17 06:20:36 +08:00
|
|
|
#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
|
2010-12-14 07:03:16 +08:00
|
|
|
#ifdef CONFIG_DMA_CACHE_RWFO
|
2019-02-18 07:57:38 +08:00
|
|
|
ldrblo r2, [r0] @ read for ownership
|
|
|
|
strblo r2, [r0] @ write for ownership
|
2010-12-14 07:03:16 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
blo 1b
|
|
|
|
mov r0, #0
|
|
|
|
mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
|
2014-06-30 23:29:12 +08:00
|
|
|
ret lr
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-11-27 00:19:58 +08:00
|
|
|
/*
|
|
|
|
* 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
|
2009-11-01 00:52:16 +08:00
|
|
|
teq r2, #DMA_FROM_DEVICE
|
|
|
|
beq v6_dma_inv_range
|
2010-06-21 22:10:07 +08:00
|
|
|
#ifndef CONFIG_DMA_CACHE_RWFO
|
|
|
|
b v6_dma_clean_range
|
|
|
|
#else
|
2010-05-07 23:26:24 +08:00
|
|
|
teq r2, #DMA_TO_DEVICE
|
|
|
|
beq v6_dma_clean_range
|
|
|
|
b v6_dma_flush_range
|
2010-06-21 22:10:07 +08:00
|
|
|
#endif
|
2009-11-27 00:19:58 +08:00
|
|
|
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)
|
2010-06-21 22:10:07 +08:00
|
|
|
#ifndef CONFIG_DMA_CACHE_RWFO
|
|
|
|
add r1, r1, r0
|
|
|
|
teq r2, #DMA_TO_DEVICE
|
|
|
|
bne v6_dma_inv_range
|
|
|
|
#endif
|
2014-06-30 23:29:12 +08:00
|
|
|
ret lr
|
2009-11-27 00:19:58 +08:00
|
|
|
ENDPROC(v6_dma_unmap_area)
|
|
|
|
|
2012-09-06 21:05:13 +08:00
|
|
|
.globl v6_flush_kern_cache_louis
|
|
|
|
.equ v6_flush_kern_cache_louis, v6_flush_kern_cache_all
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
__INITDATA
|
|
|
|
|
2011-06-24 00:16:04 +08:00
|
|
|
@ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
|
|
|
|
define_cache_functions v6
|