2 * linux/arch/arm/mm/cache-fa.S
4 * Copyright (C) 2005 Faraday Corp.
5 * Copyright (C) 2008-2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
7 * Based on cache-v4wb.S:
8 * Copyright (C) 1997-2002 Russell king
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * Processors: FA520 FA526 FA626
16 #include <linux/linkage.h>
17 #include <linux/init.h>
18 #include <asm/memory.h>
21 #include "proc-macros.S"
24 * The size of one data cache line.
26 #define CACHE_DLINESIZE 16
29 * The total size of the data cache.
31 #ifdef CONFIG_ARCH_GEMINI
32 #define CACHE_DSIZE 8192
34 #define CACHE_DSIZE 16384
37 /* FIXME: put optimal value here. Current one is just estimation */
38 #define CACHE_DLIMIT (CACHE_DSIZE * 2)
43 * Unconditionally clean and invalidate the entire icache.
45 ENTRY(fa_flush_icache_all)
47 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
49 ENDPROC(fa_flush_icache_all)
52 * flush_user_cache_all()
54 * Clean and invalidate all cache entries in a particular address
57 ENTRY(fa_flush_user_cache_all)
60 * flush_kern_cache_all()
62 * Clean and invalidate the entire cache.
64 ENTRY(fa_flush_kern_cache_all)
68 mcr p15, 0, ip, c7, c14, 0 @ clean/invalidate D cache
70 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
71 mcrne p15, 0, ip, c7, c5, 6 @ invalidate BTB
72 mcrne p15, 0, ip, c7, c10, 4 @ drain write buffer
73 mcrne p15, 0, ip, c7, c5, 4 @ prefetch flush
77 * flush_user_cache_range(start, end, flags)
79 * Invalidate a range of cache entries in the specified
82 * - start - start address (inclusive, page aligned)
83 * - end - end address (exclusive, page aligned)
84 * - flags - vma_area_struct flags describing address space
86 ENTRY(fa_flush_user_cache_range)
88 sub r3, r1, r0 @ calculate total size
89 cmp r3, #CACHE_DLIMIT @ total size >= limit?
90 bhs __flush_whole_cache @ flush whole D cache
93 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I line
94 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
95 add r0, r0, #CACHE_DLINESIZE
99 mcrne p15, 0, ip, c7, c5, 6 @ invalidate BTB
100 mcrne p15, 0, ip, c7, c10, 4 @ data write barrier
101 mcrne p15, 0, ip, c7, c5, 4 @ prefetch flush
105 * coherent_kern_range(start, end)
107 * Ensure coherency between the Icache and the Dcache in the
108 * region described by start. If you have non-snooping
109 * Harvard caches, you need to implement this function.
111 * - start - virtual start address
112 * - end - virtual end address
114 ENTRY(fa_coherent_kern_range)
118 * coherent_user_range(start, end)
120 * Ensure coherency between the Icache and the Dcache in the
121 * region described by start. If you have non-snooping
122 * Harvard caches, you need to implement this function.
124 * - start - virtual start address
125 * - end - virtual end address
127 ENTRY(fa_coherent_user_range)
128 bic r0, r0, #CACHE_DLINESIZE - 1
129 1: mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
130 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
131 add r0, r0, #CACHE_DLINESIZE
135 mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB
136 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
137 mcr p15, 0, r0, c7, c5, 4 @ prefetch flush
141 * flush_kern_dcache_area(void *addr, size_t size)
143 * Ensure that the data held in the page kaddr is written back
144 * to the page in question.
146 * - addr - kernel address
147 * - size - size of region
149 ENTRY(fa_flush_kern_dcache_area)
151 1: mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
152 add r0, r0, #CACHE_DLINESIZE
156 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
157 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
161 * dma_inv_range(start, end)
163 * Invalidate (discard) the specified virtual address range.
164 * May not write back any entries. If 'start' or 'end'
165 * are not cache line aligned, those lines must be written
168 * - start - virtual start address
169 * - end - virtual end address
172 tst r0, #CACHE_DLINESIZE - 1
173 bic r0, r0, #CACHE_DLINESIZE - 1
174 mcrne p15, 0, r0, c7, c14, 1 @ clean & invalidate D entry
175 tst r1, #CACHE_DLINESIZE - 1
176 bic r1, r1, #CACHE_DLINESIZE - 1
177 mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D entry
178 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
179 add r0, r0, #CACHE_DLINESIZE
183 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
187 * dma_clean_range(start, end)
189 * Clean (write back) the specified virtual address range.
191 * - start - virtual start address
192 * - end - virtual end address
195 bic r0, r0, #CACHE_DLINESIZE - 1
196 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
197 add r0, r0, #CACHE_DLINESIZE
201 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
205 * dma_flush_range(start,end)
206 * - start - virtual start address of region
207 * - end - virtual end address of region
209 ENTRY(fa_dma_flush_range)
210 bic r0, r0, #CACHE_DLINESIZE - 1
211 1: mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D entry
212 add r0, r0, #CACHE_DLINESIZE
216 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
220 * dma_map_area(start, size, dir)
221 * - start - kernel virtual start address
222 * - size - size of region
223 * - dir - DMA direction
225 ENTRY(fa_dma_map_area)
227 cmp r2, #DMA_TO_DEVICE
228 beq fa_dma_clean_range
231 ENDPROC(fa_dma_map_area)
234 * dma_unmap_area(start, size, dir)
235 * - start - kernel virtual start address
236 * - size - size of region
237 * - dir - DMA direction
239 ENTRY(fa_dma_unmap_area)
241 ENDPROC(fa_dma_unmap_area)
245 .type fa_cache_fns, #object
247 .long fa_flush_icache_all
248 .long fa_flush_kern_cache_all
249 .long fa_flush_user_cache_all
250 .long fa_flush_user_cache_range
251 .long fa_coherent_kern_range
252 .long fa_coherent_user_range
253 .long fa_flush_kern_dcache_area
254 .long fa_dma_map_area
255 .long fa_dma_unmap_area
256 .long fa_dma_flush_range
257 .size fa_cache_fns, . - fa_cache_fns