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-hwdef.h>
55 #include <asm/pgtable.h>
56 #include <asm/procinfo.h>
57 #include <asm/hardware.h>
59 #include <asm/ptrace.h>
60 #include "proc-macros.S"
63 * The size of one data cache line.
65 #define CACHE_DLINESIZE 16
68 * The number of data cache segments.
70 #define CACHE_DSEGMENTS 2
73 * The number of lines in a cache segment.
75 #define CACHE_DENTRIES 256
78 * This is the size at which it becomes more efficient to
79 * clean the whole cache, rather than using the individual
80 * cache line maintainence instructions.
82 #define CACHE_DLIMIT 8192
86 * cpu_arm925_proc_init()
88 ENTRY(cpu_arm925_proc_init)
92 * cpu_arm925_proc_fin()
94 ENTRY(cpu_arm925_proc_fin)
96 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
98 bl arm925_flush_kern_cache_all
99 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
100 bic r0, r0, #0x1000 @ ...i............
101 bic r0, r0, #0x000e @ ............wca.
102 mcr p15, 0, r0, c1, c0, 0 @ disable caches
106 * cpu_arm925_reset(loc)
108 * Perform a soft reset of the system. Put the CPU into the
109 * same state as it would be if it had been reset, and branch
110 * to what would be the reset vector.
112 * loc: location to jump to for soft reset
115 ENTRY(cpu_arm925_reset)
116 /* Send software reset to MPU and DSP */
118 orr ip, ip, #0x00fe0000
119 orr ip, ip, #0x0000ce00
124 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
125 mcr p15, 0, ip, c7, c10, 4 @ drain WB
126 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
127 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
128 bic ip, ip, #0x000f @ ............wcam
129 bic ip, ip, #0x1100 @ ...i...s........
130 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
134 * cpu_arm925_do_idle()
136 * Called with IRQs disabled
139 ENTRY(cpu_arm925_do_idle)
141 mrc p15, 0, r1, c1, c0, 0 @ Read control register
142 mcr p15, 0, r0, c7, c10, 4 @ Drain write buffer
144 mcr p15, 0, r2, c1, c0, 0 @ Disable I cache
145 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
146 mcr p15, 0, r1, c1, c0, 0 @ Restore ICache enable
150 * flush_user_cache_all()
152 * Clean and invalidate all cache entries in a particular
155 ENTRY(arm925_flush_user_cache_all)
159 * flush_kern_cache_all()
161 * Clean and invalidate the entire cache.
163 ENTRY(arm925_flush_kern_cache_all)
167 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
168 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
170 /* Flush entries in both segments at once, see NOTE1 above */
171 mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
172 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
174 bcs 2b @ entries 255 to 0
177 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
178 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
182 * flush_user_cache_range(start, end, flags)
184 * Clean and invalidate a range of cache entries in the
185 * specified address range.
187 * - start - start address (inclusive)
188 * - end - end address (exclusive)
189 * - flags - vm_flags describing address space
191 ENTRY(arm925_flush_user_cache_range)
193 sub r3, r1, r0 @ calculate total size
194 cmp r3, #CACHE_DLIMIT
195 bgt __flush_whole_cache
197 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
198 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
199 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
200 add r0, r0, #CACHE_DLINESIZE
201 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
202 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
203 add r0, r0, #CACHE_DLINESIZE
205 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
206 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
207 add r0, r0, #CACHE_DLINESIZE
208 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
209 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
210 add r0, r0, #CACHE_DLINESIZE
215 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
219 * coherent_kern_range(start, end)
221 * Ensure coherency between the Icache and the Dcache in the
222 * region described by start, end. If you have non-snooping
223 * Harvard caches, you need to implement this function.
225 * - start - virtual start address
226 * - end - virtual end address
228 ENTRY(arm925_coherent_kern_range)
232 * coherent_user_range(start, end)
234 * Ensure coherency between the Icache and the Dcache in the
235 * region described by start, end. If you have non-snooping
236 * Harvard caches, you need to implement this function.
238 * - start - virtual start address
239 * - end - virtual end address
241 ENTRY(arm925_coherent_user_range)
242 bic r0, r0, #CACHE_DLINESIZE - 1
243 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
244 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
245 add r0, r0, #CACHE_DLINESIZE
248 mcr p15, 0, r0, c7, c10, 4 @ drain WB
252 * flush_kern_dcache_page(void *page)
254 * Ensure no D cache aliasing occurs, either with itself or
257 * - addr - page aligned address
259 ENTRY(arm925_flush_kern_dcache_page)
261 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
262 add r0, r0, #CACHE_DLINESIZE
266 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
267 mcr p15, 0, r0, c7, c10, 4 @ drain WB
271 * dma_inv_range(start, end)
273 * Invalidate (discard) the specified virtual address range.
274 * May not write back any entries. If 'start' or 'end'
275 * are not cache line aligned, those lines must be written
278 * - start - virtual start address
279 * - end - virtual end address
283 ENTRY(arm925_dma_inv_range)
284 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
285 tst r0, #CACHE_DLINESIZE - 1
286 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
287 tst r1, #CACHE_DLINESIZE - 1
288 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
290 bic r0, r0, #CACHE_DLINESIZE - 1
291 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
292 add r0, r0, #CACHE_DLINESIZE
295 mcr p15, 0, r0, c7, c10, 4 @ drain WB
299 * dma_clean_range(start, end)
301 * Clean the specified virtual address range.
303 * - start - virtual start address
304 * - end - virtual end address
308 ENTRY(arm925_dma_clean_range)
309 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
310 bic r0, r0, #CACHE_DLINESIZE - 1
311 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
312 add r0, r0, #CACHE_DLINESIZE
316 mcr p15, 0, r0, c7, c10, 4 @ drain WB
320 * dma_flush_range(start, end)
322 * Clean and invalidate the specified virtual address range.
324 * - start - virtual start address
325 * - end - virtual end address
327 ENTRY(arm925_dma_flush_range)
328 bic r0, r0, #CACHE_DLINESIZE - 1
330 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
331 mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
333 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
335 add r0, r0, #CACHE_DLINESIZE
338 mcr p15, 0, r0, c7, c10, 4 @ drain WB
341 ENTRY(arm925_cache_fns)
342 .long arm925_flush_kern_cache_all
343 .long arm925_flush_user_cache_all
344 .long arm925_flush_user_cache_range
345 .long arm925_coherent_kern_range
346 .long arm925_coherent_user_range
347 .long arm925_flush_kern_dcache_page
348 .long arm925_dma_inv_range
349 .long arm925_dma_clean_range
350 .long arm925_dma_flush_range
352 ENTRY(cpu_arm925_dcache_clean_area)
353 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
354 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
355 add r0, r0, #CACHE_DLINESIZE
356 subs r1, r1, #CACHE_DLINESIZE
359 mcr p15, 0, r0, c7, c10, 4 @ drain WB
362 /* =============================== PageTable ============================== */
365 * cpu_arm925_switch_mm(pgd)
367 * Set the translation base pointer to be as described by pgd.
369 * pgd: new page tables
372 ENTRY(cpu_arm925_switch_mm)
374 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
375 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
377 /* Flush entries in bothe segments at once, see NOTE1 above */
378 mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
379 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
381 bcs 2b @ entries 255 to 0
383 mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
384 mcr p15, 0, ip, c7, c10, 4 @ drain WB
385 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
386 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
390 * cpu_arm925_set_pte(ptep, pte)
392 * Set a PTE and flush it out
395 ENTRY(cpu_arm925_set_pte)
396 str r1, [r0], #-2048 @ linux version
398 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
400 bic r2, r1, #PTE_SMALL_AP_MASK
401 bic r2, r2, #PTE_TYPE_MASK
402 orr r2, r2, #PTE_TYPE_SMALL
404 tst r1, #L_PTE_USER @ User?
405 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
407 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
408 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
410 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
413 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
414 eor r3, r2, #0x0a @ C & small page?
418 str r2, [r0] @ hardware version
420 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
421 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
423 mcr p15, 0, r0, c7, c10, 4 @ drain WB
428 .type __arm925_setup, #function
431 #if defined(CONFIG_CPU_ICACHE_STREAMING_DISABLE)
435 /* Transparent on, D-cache clean & flush mode. See NOTE2 above */
436 orr r0,r0,#1 << 1 @ transparent mode on
437 mcr p15, 0, r0, c15, c1, 0 @ write TI config register
440 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
441 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
442 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
444 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
445 mov r0, #4 @ disable write-back on caches explicitly
446 mcr p15, 7, r0, c15, c0, 0
449 mrc p15, 0, r0, c1, c0 @ get control register v4
450 ldr r5, arm925_cr1_clear
452 ldr r5, arm925_cr1_set
454 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
455 orr r0, r0, #0x4000 @ .1.. .... .... ....
458 .size __arm925_setup, . - __arm925_setup
462 * .RVI ZFRS BLDP WCAM
463 * .011 0001 ..11 1101
466 .type arm925_cr1_clear, #object
467 .type arm925_cr1_set, #object
476 * Purpose : Function pointers used to access above functions - all calls
479 .type arm925_processor_functions, #object
480 arm925_processor_functions:
481 .word v4t_early_abort
482 .word cpu_arm925_proc_init
483 .word cpu_arm925_proc_fin
484 .word cpu_arm925_reset
485 .word cpu_arm925_do_idle
486 .word cpu_arm925_dcache_clean_area
487 .word cpu_arm925_switch_mm
488 .word cpu_arm925_set_pte
489 .size arm925_processor_functions, . - arm925_processor_functions
493 .type cpu_arch_name, #object
496 .size cpu_arch_name, . - cpu_arch_name
498 .type cpu_elf_name, #object
501 .size cpu_elf_name, . - cpu_elf_name
503 .type cpu_arm925_name, #object
506 #ifndef CONFIG_CPU_ICACHE_DISABLE
509 #ifndef CONFIG_CPU_DCACHE_DISABLE
511 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
516 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
521 .size cpu_arm925_name, . - cpu_arm925_name
525 .section ".proc.info.init", #alloc, #execinstr
527 .type __arm925_proc_info,#object
531 .long PMD_TYPE_SECT | \
533 PMD_SECT_AP_WRITE | \
538 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
539 .long cpu_arm925_name
540 .long arm925_processor_functions
543 .long arm925_cache_fns
544 .size __arm925_proc_info, . - __arm925_proc_info
546 .type __arm915_proc_info,#object
550 .long PMD_TYPE_SECT | \
552 PMD_SECT_AP_WRITE | \
557 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
558 .long cpu_arm925_name
559 .long arm925_processor_functions
562 .long arm925_cache_fns
563 .size __arm925_proc_info, . - __arm925_proc_info