2 * linux/arch/arm/mm/arm925.S: MMU functions for ARM925
4 * Copyright (C) 1999,2000 ARM Limited
5 * Copyright (C) 2000 Deep Blue Solutions Ltd.
6 * Copyright (C) 2002 RidgeRun, Inc.
7 * Copyright (C) 2002-2003 MontaVista Software, Inc.
9 * Update for Linux-2.6 and cache flush improvements
10 * Copyright (C) 2004 Nokia Corporation by Tony Lindgren <tony@atomide.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * These are the low level assembler for performing cache and TLB
28 * functions on the arm925.
30 * CONFIG_CPU_ARM925_CPU_IDLE -> nohlt
32 * Some additional notes based on deciphering the TI TRM on OMAP-5910:
34 * NOTE1: The TI925T Configuration Register bit "D-cache clean and flush
35 * entry mode" must be 0 to flush the entries in both segments
36 * at once. This is the default value. See TRM 2-20 and 2-24 for
39 * NOTE2: Default is the "D-cache clean and flush entry mode". It looks
40 * like the "Transparent mode" must be on for partial cache flushes
41 * to work in this mode. This mode only works with 16-bit external
42 * memory. See TRM 2-24 for more information.
44 * NOTE3: Write-back cache flushing seems to be flakey with devices using
45 * direct memory access, such as USB OHCI. The workaround is to use
46 * write-through cache with CONFIG_CPU_DCACHE_WRITETHROUGH (this is
47 * the default for OMAP-1510).
50 #include <linux/linkage.h>
51 #include <linux/config.h>
52 #include <linux/init.h>
53 #include <asm/assembler.h>
54 #include <asm/pgtable.h>
55 #include <asm/procinfo.h>
56 #include <asm/hardware.h>
58 #include <asm/ptrace.h>
59 #include "proc-macros.S"
62 * The size of one data cache line.
64 #define CACHE_DLINESIZE 16
67 * The number of data cache segments.
69 #define CACHE_DSEGMENTS 2
72 * The number of lines in a cache segment.
74 #define CACHE_DENTRIES 256
77 * This is the size at which it becomes more efficient to
78 * clean the whole cache, rather than using the individual
79 * cache line maintainence instructions.
81 #define CACHE_DLIMIT 8192
85 * cpu_arm925_proc_init()
87 ENTRY(cpu_arm925_proc_init)
91 * cpu_arm925_proc_fin()
93 ENTRY(cpu_arm925_proc_fin)
95 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
97 bl arm925_flush_kern_cache_all
98 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
99 bic r0, r0, #0x1000 @ ...i............
100 bic r0, r0, #0x000e @ ............wca.
101 mcr p15, 0, r0, c1, c0, 0 @ disable caches
105 * cpu_arm925_reset(loc)
107 * Perform a soft reset of the system. Put the CPU into the
108 * same state as it would be if it had been reset, and branch
109 * to what would be the reset vector.
111 * loc: location to jump to for soft reset
114 ENTRY(cpu_arm925_reset)
115 /* Send software reset to MPU and DSP */
117 orr ip, ip, #0x00fe0000
118 orr ip, ip, #0x0000ce00
123 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
124 mcr p15, 0, ip, c7, c10, 4 @ drain WB
125 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
126 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
127 bic ip, ip, #0x000f @ ............wcam
128 bic ip, ip, #0x1100 @ ...i...s........
129 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
133 * cpu_arm925_do_idle()
135 * Called with IRQs disabled
138 ENTRY(cpu_arm925_do_idle)
140 mrc p15, 0, r1, c1, c0, 0 @ Read control register
141 mcr p15, 0, r0, c7, c10, 4 @ Drain write buffer
143 mcr p15, 0, r2, c1, c0, 0 @ Disable I cache
144 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
145 mcr p15, 0, r1, c1, c0, 0 @ Restore ICache enable
149 * flush_user_cache_all()
151 * Clean and invalidate all cache entries in a particular
154 ENTRY(arm925_flush_user_cache_all)
158 * flush_kern_cache_all()
160 * Clean and invalidate the entire cache.
162 ENTRY(arm925_flush_kern_cache_all)
166 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
167 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
169 /* Flush entries in both segments at once, see NOTE1 above */
170 mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
171 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
173 bcs 2b @ entries 255 to 0
176 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
177 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
181 * flush_user_cache_range(start, end, flags)
183 * Clean and invalidate a range of cache entries in the
184 * specified address range.
186 * - start - start address (inclusive)
187 * - end - end address (exclusive)
188 * - flags - vm_flags describing address space
190 ENTRY(arm925_flush_user_cache_range)
192 sub r3, r1, r0 @ calculate total size
193 cmp r3, #CACHE_DLIMIT
194 bgt __flush_whole_cache
196 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
197 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
198 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
199 add r0, r0, #CACHE_DLINESIZE
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
204 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
205 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
206 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
214 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
218 * coherent_kern_range(start, end)
220 * Ensure coherency between the Icache and the Dcache in the
221 * region described by start, end. If you have non-snooping
222 * Harvard caches, you need to implement this function.
224 * - start - virtual start address
225 * - end - virtual end address
227 ENTRY(arm925_coherent_kern_range)
228 bic r0, r0, #CACHE_DLINESIZE - 1
229 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
230 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
231 add r0, r0, #CACHE_DLINESIZE
234 mcr p15, 0, r0, c7, c10, 4 @ drain WB
238 * flush_kern_dcache_page(void *page)
240 * Ensure no D cache aliasing occurs, either with itself or
243 * - addr - page aligned address
245 ENTRY(arm925_flush_kern_dcache_page)
247 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
248 add r0, r0, #CACHE_DLINESIZE
252 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
253 mcr p15, 0, r0, c7, c10, 4 @ drain WB
257 * dma_inv_range(start, end)
259 * Invalidate (discard) the specified virtual address range.
260 * May not write back any entries. If 'start' or 'end'
261 * are not cache line aligned, those lines must be written
264 * - start - virtual start address
265 * - end - virtual end address
269 ENTRY(arm925_dma_inv_range)
270 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
271 tst r0, #CACHE_DLINESIZE - 1
272 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
273 tst r1, #CACHE_DLINESIZE - 1
274 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
276 bic r0, r0, #CACHE_DLINESIZE - 1
277 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
278 add r0, r0, #CACHE_DLINESIZE
281 mcr p15, 0, r0, c7, c10, 4 @ drain WB
285 * dma_clean_range(start, end)
287 * Clean the specified virtual address range.
289 * - start - virtual start address
290 * - end - virtual end address
294 ENTRY(arm925_dma_clean_range)
295 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
296 bic r0, r0, #CACHE_DLINESIZE - 1
297 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
298 add r0, r0, #CACHE_DLINESIZE
302 mcr p15, 0, r0, c7, c10, 4 @ drain WB
306 * dma_flush_range(start, end)
308 * Clean and invalidate the specified virtual address range.
310 * - start - virtual start address
311 * - end - virtual end address
313 ENTRY(arm925_dma_flush_range)
314 bic r0, r0, #CACHE_DLINESIZE - 1
316 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
317 mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
319 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
321 add r0, r0, #CACHE_DLINESIZE
324 mcr p15, 0, r0, c7, c10, 4 @ drain WB
327 ENTRY(arm925_cache_fns)
328 .long arm925_flush_kern_cache_all
329 .long arm925_flush_user_cache_all
330 .long arm925_flush_user_cache_range
331 .long arm925_coherent_kern_range
332 .long arm925_flush_kern_dcache_page
333 .long arm925_dma_inv_range
334 .long arm925_dma_clean_range
335 .long arm925_dma_flush_range
337 ENTRY(cpu_arm925_dcache_clean_area)
338 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
339 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
340 add r0, r0, #CACHE_DLINESIZE
341 subs r1, r1, #CACHE_DLINESIZE
344 mcr p15, 0, r0, c7, c10, 4 @ drain WB
347 /* =============================== PageTable ============================== */
350 * cpu_arm925_switch_mm(pgd)
352 * Set the translation base pointer to be as described by pgd.
354 * pgd: new page tables
357 ENTRY(cpu_arm925_switch_mm)
359 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
360 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
362 /* Flush entries in bothe segments at once, see NOTE1 above */
363 mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
364 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
366 bcs 2b @ entries 255 to 0
368 mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
369 mcr p15, 0, ip, c7, c10, 4 @ drain WB
370 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
371 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
375 * cpu_arm925_set_pte(ptep, pte)
377 * Set a PTE and flush it out
380 ENTRY(cpu_arm925_set_pte)
381 str r1, [r0], #-2048 @ linux version
383 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
385 bic r2, r1, #PTE_SMALL_AP_MASK
386 bic r2, r2, #PTE_TYPE_MASK
387 orr r2, r2, #PTE_TYPE_SMALL
389 tst r1, #L_PTE_USER @ User?
390 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
392 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
393 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
395 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
398 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
399 eor r3, r2, #0x0a @ C & small page?
403 str r2, [r0] @ hardware version
405 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
406 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
408 mcr p15, 0, r0, c7, c10, 4 @ drain WB
413 .type __arm925_setup, #function
416 #if defined(CONFIG_CPU_ICACHE_STREAMING_DISABLE)
420 /* Transparent on, D-cache clean & flush mode. See NOTE2 above */
421 orr r0,r0,#1 << 1 @ transparent mode on
422 mcr p15, 0, r0, c15, c1, 0 @ write TI config register
425 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
426 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
427 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
428 mcr p15, 0, r4, c2, c0 @ load page table pointer
430 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
431 mov r0, #4 @ disable write-back on caches explicitly
432 mcr p15, 7, r0, c15, c0, 0
435 mov r0, #0x1f @ Domains 0, 1 = client
436 mcr p15, 0, r0, c3, c0 @ load domain access register
437 mrc p15, 0, r0, c1, c0 @ get control register v4
439 * Clear out 'unwanted' bits (then put them in if we need them)
445 bic r0, r0, #0x1000 @ ...0 000. .... 000.
447 * Turn on what we want
450 orr r0, r0, #0x2100 @ ..1. ...1 ..11 ...1
453 orr r0, r0, #0x0008 @ .... .... .... 1...
455 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
456 orr r0, r0, #0x4000 @ .1.. .... .... ....
458 #ifndef CONFIG_CPU_DCACHE_DISABLE
459 orr r0, r0, #0x0004 @ .... .... .... .1..
461 #ifndef CONFIG_CPU_ICACHE_DISABLE
462 orr r0, r0, #0x1000 @ ...1 .... .... ....
465 .size __arm925_setup, . - __arm925_setup
470 * Purpose : Function pointers used to access above functions - all calls
473 .type arm925_processor_functions, #object
474 arm925_processor_functions:
475 .word v4t_early_abort
476 .word cpu_arm925_proc_init
477 .word cpu_arm925_proc_fin
478 .word cpu_arm925_reset
479 .word cpu_arm925_do_idle
480 .word cpu_arm925_dcache_clean_area
481 .word cpu_arm925_switch_mm
482 .word cpu_arm925_set_pte
483 .size arm925_processor_functions, . - arm925_processor_functions
487 .type cpu_arch_name, #object
490 .size cpu_arch_name, . - cpu_arch_name
492 .type cpu_elf_name, #object
495 .size cpu_elf_name, . - cpu_elf_name
497 .type cpu_arm925_name, #object
500 #ifndef CONFIG_CPU_ICACHE_DISABLE
503 #ifndef CONFIG_CPU_DCACHE_DISABLE
505 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
510 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
515 .size cpu_arm925_name, . - cpu_arm925_name
519 .section ".proc.info", #alloc, #execinstr
521 .type __arm925_proc_info,#object
525 .long 0x00000c12 @ mmuflags
529 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
530 .long cpu_arm925_name
531 .long arm925_processor_functions
534 .long arm925_cache_fns
535 .size __arm925_proc_info, . - __arm925_proc_info
537 .type __arm915_proc_info,#object
541 .long 0x00000c12 @ mmuflags
545 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
546 .long cpu_arm925_name
547 .long arm925_processor_functions
550 .long arm925_cache_fns
551 .size __arm925_proc_info, . - __arm925_proc_info