1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * linux/arch/arm/mm/arm925.S: MMU functions for ARM925
5 * Copyright (C) 1999,2000 ARM Limited
6 * Copyright (C) 2000 Deep Blue Solutions Ltd.
7 * Copyright (C) 2002 RidgeRun, Inc.
8 * Copyright (C) 2002-2003 MontaVista Software, Inc.
10 * Update for Linux-2.6 and cache flush improvements
11 * Copyright (C) 2004 Nokia Corporation by Tony Lindgren <tony@atomide.com>
13 * hacked for non-paged-MM by Hyok S. Choi, 2004.
15 * These are the low level assembler for performing cache and TLB
16 * functions on the arm925.
18 * CONFIG_CPU_ARM925_CPU_IDLE -> nohlt
20 * Some additional notes based on deciphering the TI TRM on OMAP-5910:
22 * NOTE1: The TI925T Configuration Register bit "D-cache clean and flush
23 * entry mode" must be 0 to flush the entries in both segments
24 * at once. This is the default value. See TRM 2-20 and 2-24 for
27 * NOTE2: Default is the "D-cache clean and flush entry mode". It looks
28 * like the "Transparent mode" must be on for partial cache flushes
29 * to work in this mode. This mode only works with 16-bit external
30 * memory. See TRM 2-24 for more information.
32 * NOTE3: Write-back cache flushing seems to be flakey with devices using
33 * direct memory access, such as USB OHCI. The workaround is to use
34 * write-through cache with CONFIG_CPU_DCACHE_WRITETHROUGH (this is
35 * the default for OMAP-1510).
38 #include <linux/linkage.h>
39 #include <linux/init.h>
40 #include <linux/cfi_types.h>
41 #include <linux/pgtable.h>
42 #include <asm/assembler.h>
43 #include <asm/hwcap.h>
44 #include <asm/pgtable-hwdef.h>
46 #include <asm/ptrace.h>
47 #include "proc-macros.S"
50 * The size of one data cache line.
52 #define CACHE_DLINESIZE 16
55 * The number of data cache segments.
57 #define CACHE_DSEGMENTS 2
60 * The number of lines in a cache segment.
62 #define CACHE_DENTRIES 256
65 * This is the size at which it becomes more efficient to
66 * clean the whole cache, rather than using the individual
67 * cache line maintenance instructions.
69 #define CACHE_DLIMIT 8192
73 * cpu_arm925_proc_init()
75 SYM_TYPED_FUNC_START(cpu_arm925_proc_init)
77 SYM_FUNC_END(cpu_arm925_proc_init)
80 * cpu_arm925_proc_fin()
82 SYM_TYPED_FUNC_START(cpu_arm925_proc_fin)
83 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
84 bic r0, r0, #0x1000 @ ...i............
85 bic r0, r0, #0x000e @ ............wca.
86 mcr p15, 0, r0, c1, c0, 0 @ disable caches
88 SYM_FUNC_END(cpu_arm925_proc_fin)
91 * cpu_arm925_reset(loc)
93 * Perform a soft reset of the system. Put the CPU into the
94 * same state as it would be if it had been reset, and branch
95 * to what would be the reset vector.
97 * loc: location to jump to for soft reset
100 .pushsection .idmap.text, "ax"
101 SYM_TYPED_FUNC_START(cpu_arm925_reset)
102 /* Send software reset to MPU and DSP */
104 orr ip, ip, #0x00fe0000
105 orr ip, ip, #0x0000ce00
108 SYM_FUNC_END(cpu_arm925_reset)
112 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
113 mcr p15, 0, ip, c7, c10, 4 @ drain WB
115 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
117 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
118 bic ip, ip, #0x000f @ ............wcam
119 bic ip, ip, #0x1100 @ ...i...s........
120 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
124 * cpu_arm925_do_idle()
126 * Called with IRQs disabled
129 SYM_TYPED_FUNC_START(cpu_arm925_do_idle)
131 mrc p15, 0, r1, c1, c0, 0 @ Read control register
132 mcr p15, 0, r0, c7, c10, 4 @ Drain write buffer
134 mcr p15, 0, r2, c1, c0, 0 @ Disable I cache
135 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
136 mcr p15, 0, r1, c1, c0, 0 @ Restore ICache enable
138 SYM_FUNC_END(cpu_arm925_do_idle)
143 * Unconditionally clean and invalidate the entire icache.
145 SYM_TYPED_FUNC_START(arm925_flush_icache_all)
147 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
149 SYM_FUNC_END(arm925_flush_icache_all)
152 * flush_user_cache_all()
154 * Clean and invalidate all cache entries in a particular
157 SYM_FUNC_ALIAS(arm925_flush_user_cache_all, arm925_flush_kern_cache_all)
160 * flush_kern_cache_all()
162 * Clean and invalidate the entire cache.
164 SYM_TYPED_FUNC_START(arm925_flush_kern_cache_all)
168 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
169 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
171 /* Flush entries in both segments at once, see NOTE1 above */
172 mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
173 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
175 bcs 2b @ entries 255 to 0
178 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
179 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
181 SYM_FUNC_END(arm925_flush_kern_cache_all)
184 * flush_user_cache_range(start, end, flags)
186 * Clean and invalidate a range of cache entries in the
187 * specified address range.
189 * - start - start address (inclusive)
190 * - end - end address (exclusive)
191 * - flags - vm_flags describing address space
193 SYM_TYPED_FUNC_START(arm925_flush_user_cache_range)
195 sub r3, r1, r0 @ calculate total size
196 cmp r3, #CACHE_DLIMIT
197 bgt __flush_whole_cache
199 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
200 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
201 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
202 add r0, r0, #CACHE_DLINESIZE
203 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
204 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
205 add r0, r0, #CACHE_DLINESIZE
207 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
208 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
209 add r0, r0, #CACHE_DLINESIZE
210 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
211 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
212 add r0, r0, #CACHE_DLINESIZE
217 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
219 SYM_FUNC_END(arm925_flush_user_cache_range)
222 * coherent_kern_range(start, end)
224 * Ensure coherency between the Icache and the Dcache in the
225 * region described by start, end. If you have non-snooping
226 * Harvard caches, you need to implement this function.
228 * - start - virtual start address
229 * - end - virtual end address
231 SYM_TYPED_FUNC_START(arm925_coherent_kern_range)
232 #ifdef CONFIG_CFI_CLANG /* Fallthrough if !CFI */
233 b arm925_coherent_user_range
235 SYM_FUNC_END(arm925_coherent_kern_range)
238 * coherent_user_range(start, end)
240 * Ensure coherency between the Icache and the Dcache in the
241 * region described by start, end. If you have non-snooping
242 * Harvard caches, you need to implement this function.
244 * - start - virtual start address
245 * - end - virtual end address
247 SYM_TYPED_FUNC_START(arm925_coherent_user_range)
248 bic r0, r0, #CACHE_DLINESIZE - 1
249 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
250 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
251 add r0, r0, #CACHE_DLINESIZE
254 mcr p15, 0, r0, c7, c10, 4 @ drain WB
257 SYM_FUNC_END(arm925_coherent_user_range)
260 * flush_kern_dcache_area(void *addr, size_t size)
262 * Ensure no D cache aliasing occurs, either with itself or
265 * - addr - kernel address
266 * - size - region size
268 SYM_TYPED_FUNC_START(arm925_flush_kern_dcache_area)
270 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
271 add r0, r0, #CACHE_DLINESIZE
275 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
276 mcr p15, 0, r0, c7, c10, 4 @ drain WB
278 SYM_FUNC_END(arm925_flush_kern_dcache_area)
281 * dma_inv_range(start, end)
283 * Invalidate (discard) the specified virtual address range.
284 * May not write back any entries. If 'start' or 'end'
285 * are not cache line aligned, those lines must be written
288 * - start - virtual start address
289 * - end - virtual end address
293 arm925_dma_inv_range:
294 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
295 tst r0, #CACHE_DLINESIZE - 1
296 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
297 tst r1, #CACHE_DLINESIZE - 1
298 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
300 bic r0, r0, #CACHE_DLINESIZE - 1
301 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
302 add r0, r0, #CACHE_DLINESIZE
305 mcr p15, 0, r0, c7, c10, 4 @ drain WB
309 * dma_clean_range(start, end)
311 * Clean the specified virtual address range.
313 * - start - virtual start address
314 * - end - virtual end address
318 arm925_dma_clean_range:
319 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
320 bic r0, r0, #CACHE_DLINESIZE - 1
321 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
322 add r0, r0, #CACHE_DLINESIZE
326 mcr p15, 0, r0, c7, c10, 4 @ drain WB
330 * dma_flush_range(start, end)
332 * Clean and invalidate the specified virtual address range.
334 * - start - virtual start address
335 * - end - virtual end address
337 SYM_TYPED_FUNC_START(arm925_dma_flush_range)
338 bic r0, r0, #CACHE_DLINESIZE - 1
340 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
341 mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
343 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
345 add r0, r0, #CACHE_DLINESIZE
348 mcr p15, 0, r0, c7, c10, 4 @ drain WB
350 SYM_FUNC_END(arm925_dma_flush_range)
353 * dma_map_area(start, size, dir)
354 * - start - kernel virtual start address
355 * - size - size of region
356 * - dir - DMA direction
358 SYM_TYPED_FUNC_START(arm925_dma_map_area)
360 cmp r2, #DMA_TO_DEVICE
361 beq arm925_dma_clean_range
362 bcs arm925_dma_inv_range
363 b arm925_dma_flush_range
364 SYM_FUNC_END(arm925_dma_map_area)
367 * dma_unmap_area(start, size, dir)
368 * - start - kernel virtual start address
369 * - size - size of region
370 * - dir - DMA direction
372 SYM_TYPED_FUNC_START(arm925_dma_unmap_area)
374 SYM_FUNC_END(arm925_dma_unmap_area)
376 SYM_TYPED_FUNC_START(cpu_arm925_dcache_clean_area)
377 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
378 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
379 add r0, r0, #CACHE_DLINESIZE
380 subs r1, r1, #CACHE_DLINESIZE
383 mcr p15, 0, r0, c7, c10, 4 @ drain WB
385 SYM_FUNC_END(cpu_arm925_dcache_clean_area)
387 /* =============================== PageTable ============================== */
390 * cpu_arm925_switch_mm(pgd)
392 * Set the translation base pointer to be as described by pgd.
394 * pgd: new page tables
397 SYM_TYPED_FUNC_START(cpu_arm925_switch_mm)
400 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
401 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
403 /* Flush entries in bothe segments at once, see NOTE1 above */
404 mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
405 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
407 bcs 2b @ entries 255 to 0
409 mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
410 mcr p15, 0, ip, c7, c10, 4 @ drain WB
411 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
412 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
415 SYM_FUNC_END(cpu_arm925_switch_mm)
418 * cpu_arm925_set_pte_ext(ptep, pte, ext)
420 * Set a PTE and flush it out
423 SYM_TYPED_FUNC_START(cpu_arm925_set_pte_ext)
427 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
428 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
430 mcr p15, 0, r0, c7, c10, 4 @ drain WB
431 #endif /* CONFIG_MMU */
433 SYM_FUNC_END(cpu_arm925_set_pte_ext)
435 .type __arm925_setup, #function
439 /* Transparent on, D-cache clean & flush mode. See NOTE2 above */
440 orr r0,r0,#1 << 1 @ transparent mode on
441 mcr p15, 0, r0, c15, c1, 0 @ write TI config register
444 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
445 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
447 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
450 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
451 mov r0, #4 @ disable write-back on caches explicitly
452 mcr p15, 7, r0, c15, c0, 0
457 mrc p15, 0, r0, c1, c0 @ get control register v4
460 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
461 orr r0, r0, #0x4000 @ .1.. .... .... ....
464 .size __arm925_setup, . - __arm925_setup
468 * .RVI ZFRS BLDP WCAM
469 * .011 0001 ..11 1101
472 .type arm925_crval, #object
474 crval clear=0x00007f3f, mmuset=0x0000313d, ucset=0x00001130
477 @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
478 define_processor_functions arm925, dabort=v4t_early_abort, pabort=legacy_pabort
482 string cpu_arch_name, "armv4t"
483 string cpu_elf_name, "v4"
484 string cpu_arm925_name, "ARM925T"
488 .section ".proc.info.init", "a"
490 .macro arm925_proc_info name:req, cpu_val:req, cpu_mask:req, cpu_name:req, cache
491 .type __\name\()_proc_info,#object
492 __\name\()_proc_info:
495 .long PMD_TYPE_SECT | \
496 PMD_SECT_CACHEABLE | \
498 PMD_SECT_AP_WRITE | \
500 .long PMD_TYPE_SECT | \
502 PMD_SECT_AP_WRITE | \
504 initfn __arm925_setup, __\name\()_proc_info
507 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
508 .long cpu_arm925_name
509 .long arm925_processor_functions
512 .long arm925_cache_fns
513 .size __\name\()_proc_info, . - __\name\()_proc_info
516 arm925_proc_info arm925, 0x54029250, 0xfffffff0, cpu_arm925_name
517 arm925_proc_info arm915, 0x54029150, 0xfffffff0, cpu_arm925_name