ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / arm / mm / proc-arm925.S
1 /*
2  *  linux/arch/arm/mm/arm925.S: MMU functions for ARM925
3  *
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.
8  *
9  *  Update for Linux-2.6 and cache flush improvements
10  *  Copyright (C) 2004 Nokia Corporation by Tony Lindgren <tony@atomide.com>
11  *
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.
16  *
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.
21  *
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
25  *
26  *
27  * These are the low level assembler for performing cache and TLB
28  * functions on the arm925.
29  *
30  *  CONFIG_CPU_ARM925_CPU_IDLE -> nohlt
31  *
32  * Some additional notes based on deciphering the TI TRM on OMAP-5910:
33  *
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
37  *        more information.
38  *
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.
43  *
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).
48  */
49
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>
57 #include <asm/page.h>
58 #include <asm/ptrace.h>
59 #include "proc-macros.S"
60
61 /*
62  * The size of one data cache line.
63  */
64 #define CACHE_DLINESIZE 16
65
66 /*
67  * The number of data cache segments.
68  */
69 #define CACHE_DSEGMENTS 2
70
71 /*
72  * The number of lines in a cache segment.
73  */
74 #define CACHE_DENTRIES  256
75
76 /*
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.
80  */
81 #define CACHE_DLIMIT    8192
82
83         .text
84 /*
85  * cpu_arm925_proc_init()
86  */
87 ENTRY(cpu_arm925_proc_init)
88         mov     pc, lr
89
90 /*
91  * cpu_arm925_proc_fin()
92  */
93 ENTRY(cpu_arm925_proc_fin)
94         stmfd   sp!, {lr}
95         mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
96         msr     cpsr_c, ip
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
102         ldmfd   sp!, {pc}
103
104 /*
105  * cpu_arm925_reset(loc)
106  *
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.
110  *
111  * loc: location to jump to for soft reset
112  */
113         .align  5
114 ENTRY(cpu_arm925_reset)
115         /* Send software reset to MPU and DSP */
116         mov     ip, #0xff000000
117         orr     ip, ip, #0x00fe0000
118         orr     ip, ip, #0x0000ce00
119         mov     r4, #1
120         strh    r4, [ip, #0x10]
121
122         mov     ip, #0
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
130         mov     pc, r0
131
132 /*
133  * cpu_arm925_do_idle()
134  *
135  * Called with IRQs disabled
136  */
137         .align  10
138 ENTRY(cpu_arm925_do_idle)
139         mov     r0, #0
140         mrc     p15, 0, r1, c1, c0, 0           @ Read control register
141         mcr     p15, 0, r0, c7, c10, 4          @ Drain write buffer
142         bic     r2, r1, #1 << 12
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
146         mov     pc, lr
147
148 /*
149  *      flush_user_cache_all()
150  *
151  *      Clean and invalidate all cache entries in a particular
152  *      address space.
153  */
154 ENTRY(arm925_flush_user_cache_all)
155         /* FALLTHROUGH */
156
157 /*
158  *      flush_kern_cache_all()
159  *
160  *      Clean and invalidate the entire cache.
161  */
162 ENTRY(arm925_flush_kern_cache_all)
163         mov     r2, #VM_EXEC
164         mov     ip, #0
165 __flush_whole_cache:
166 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
167         mcr     p15, 0, ip, c7, c6, 0           @ invalidate D cache
168 #else
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
172         subs    r3, r3, #1 << 4
173         bcs     2b                              @ entries 255 to 0
174 #endif
175         tst     r2, #VM_EXEC
176         mcrne   p15, 0, ip, c7, c5, 0           @ invalidate I cache
177         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
178         mov     pc, lr
179
180 /*
181  *      flush_user_cache_range(start, end, flags)
182  *
183  *      Clean and invalidate a range of cache entries in the
184  *      specified address range.
185  *
186  *      - start - start address (inclusive)
187  *      - end   - end address (exclusive)
188  *      - flags - vm_flags describing address space
189  */
190 ENTRY(arm925_flush_user_cache_range)
191         mov     ip, #0
192         sub     r3, r1, r0                      @ calculate total size
193         cmp     r3, #CACHE_DLIMIT
194         bgt     __flush_whole_cache
195 1:      tst     r2, #VM_EXEC
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
203 #else
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
210 #endif
211         cmp     r0, r1
212         blo     1b
213         tst     r2, #VM_EXEC
214         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
215         mov     pc, lr
216
217 /*
218  *      coherent_kern_range(start, end)
219  *
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.
223  *
224  *      - start - virtual start address
225  *      - end   - virtual end address
226  */
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
232         cmp     r0, r1
233         blo     1b
234         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
235         mov     pc, lr
236
237 /*
238  *      flush_kern_dcache_page(void *page)
239  *
240  *      Ensure no D cache aliasing occurs, either with itself or
241  *      the I cache
242  *
243  *      - addr  - page aligned address
244  */
245 ENTRY(arm925_flush_kern_dcache_page)
246         add     r1, r0, #PAGE_SZ
247 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
248         add     r0, r0, #CACHE_DLINESIZE
249         cmp     r0, r1
250         blo     1b
251         mov     r0, #0
252         mcr     p15, 0, r0, c7, c5, 0           @ invalidate I cache
253         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
254         mov     pc, lr
255
256 /*
257  *      dma_inv_range(start, end)
258  *
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
262  *      back.
263  *
264  *      - start - virtual start address
265  *      - end   - virtual end address
266  *
267  * (same as v4wb)
268  */
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
275 #endif
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
279         cmp     r0, r1
280         blo     1b
281         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
282         mov     pc, lr
283
284 /*
285  *      dma_clean_range(start, end)
286  *
287  *      Clean the specified virtual address range.
288  *
289  *      - start - virtual start address
290  *      - end   - virtual end address
291  *
292  * (same as v4wb)
293  */
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
299         cmp     r0, r1
300         blo     1b
301 #endif
302         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
303         mov     pc, lr
304
305 /*
306  *      dma_flush_range(start, end)
307  *
308  *      Clean and invalidate the specified virtual address range.
309  *
310  *      - start - virtual start address
311  *      - end   - virtual end address
312  */
313 ENTRY(arm925_dma_flush_range)
314         bic     r0, r0, #CACHE_DLINESIZE - 1
315 1:
316 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
317         mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
318 #else
319         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
320 #endif
321         add     r0, r0, #CACHE_DLINESIZE
322         cmp     r0, r1
323         blo     1b
324         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
325         mov     pc, lr
326
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
336
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
342         bhi     1b
343 #endif
344         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
345         mov     pc, lr
346
347 /* =============================== PageTable ============================== */
348
349 /*
350  * cpu_arm925_switch_mm(pgd)
351  *
352  * Set the translation base pointer to be as described by pgd.
353  *
354  * pgd: new page tables
355  */
356         .align  5
357 ENTRY(cpu_arm925_switch_mm)
358         mov     ip, #0
359 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
360         mcr     p15, 0, ip, c7, c6, 0           @ invalidate D cache
361 #else
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
365         subs    r3, r3, #1 << 4
366         bcs     2b                              @ entries 255 to 0
367 #endif
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
372         mov     pc, lr
373
374 /*
375  * cpu_arm925_set_pte(ptep, pte)
376  *
377  * Set a PTE and flush it out
378  */
379         .align  5
380 ENTRY(cpu_arm925_set_pte)
381         str     r1, [r0], #-2048                @ linux version
382
383         eor     r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
384
385         bic     r2, r1, #PTE_SMALL_AP_MASK
386         bic     r2, r2, #PTE_TYPE_MASK
387         orr     r2, r2, #PTE_TYPE_SMALL
388
389         tst     r1, #L_PTE_USER                 @ User?
390         orrne   r2, r2, #PTE_SMALL_AP_URO_SRW
391
392         tst     r1, #L_PTE_WRITE | L_PTE_DIRTY  @ Write and Dirty?
393         orreq   r2, r2, #PTE_SMALL_AP_UNO_SRW
394
395         tst     r1, #L_PTE_PRESENT | L_PTE_YOUNG        @ Present and Young?
396         movne   r2, #0
397
398 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
399         eor     r3, r2, #0x0a                   @ C & small page?
400         tst     r3, #0x0b
401         biceq   r2, r2, #4
402 #endif
403         str     r2, [r0]                        @ hardware version
404         mov     r0, r0
405 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
406         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
407 #endif
408         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
409         mov     pc, lr
410
411         __INIT
412
413         .type   __arm925_setup, #function
414 __arm925_setup:
415         mov     r0, #0
416 #if defined(CONFIG_CPU_ICACHE_STREAMING_DISABLE)
417         orr     r0,r0,#1 << 7
418 #endif
419
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
423
424         mov     r0, #0
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
429
430 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
431         mov     r0, #4                          @ disable write-back on caches explicitly
432         mcr     p15, 7, r0, c15, c0, 0
433 #endif
434
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
438 /*
439  * Clear out 'unwanted' bits (then put them in if we need them)
440  */
441                                                 @   VI ZFRS BLDP WCAM
442         bic     r0, r0, #0x0e00
443         bic     r0, r0, #0x0002
444         bic     r0, r0, #0x000c
445         bic     r0, r0, #0x1000                 @ ...0 000. .... 000.
446 /*
447  * Turn on what we want
448  */
449         orr     r0, r0, #0x0031
450         orr     r0, r0, #0x2100                 @ ..1. ...1 ..11 ...1
451
452         /* Writebuffer on */
453         orr     r0, r0, #0x0008                 @ .... .... .... 1...
454
455 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
456         orr     r0, r0, #0x4000                 @ .1.. .... .... ....
457 #endif
458 #ifndef CONFIG_CPU_DCACHE_DISABLE
459         orr     r0, r0, #0x0004                 @ .... .... .... .1..
460 #endif
461 #ifndef CONFIG_CPU_ICACHE_DISABLE
462         orr     r0, r0, #0x1000                 @ ...1 .... .... ....
463 #endif
464         mov     pc, lr
465         .size   __arm925_setup, . - __arm925_setup
466
467         __INITDATA
468
469 /*
470  * Purpose : Function pointers used to access above functions - all calls
471  *           come through these
472  */
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
484
485         .section ".rodata"
486
487         .type   cpu_arch_name, #object
488 cpu_arch_name:
489         .asciz  "armv4t"
490         .size   cpu_arch_name, . - cpu_arch_name
491
492         .type   cpu_elf_name, #object
493 cpu_elf_name:
494         .asciz  "v4"
495         .size   cpu_elf_name, . - cpu_elf_name
496
497         .type   cpu_arm925_name, #object
498 cpu_arm925_name:
499         .ascii  "ARM925T"
500 #ifndef CONFIG_CPU_ICACHE_DISABLE
501         .ascii  "i"
502 #endif
503 #ifndef CONFIG_CPU_DCACHE_DISABLE
504         .ascii  "d"
505 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
506         .ascii  "(wt)"
507 #else
508         .ascii  "(wb)"
509 #endif
510 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
511         .ascii  "RR"
512 #endif
513 #endif
514         .ascii  "\0"
515         .size   cpu_arm925_name, . - cpu_arm925_name
516
517         .align
518
519         .section ".proc.info", #alloc, #execinstr
520
521         .type   __arm925_proc_info,#object
522 __arm925_proc_info:
523         .long   0x54029250
524         .long   0xfffffff0
525         .long   0x00000c12                      @ mmuflags
526         b       __arm925_setup
527         .long   cpu_arch_name
528         .long   cpu_elf_name
529         .long   HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
530         .long   cpu_arm925_name
531         .long   arm925_processor_functions
532         .long   v4wbi_tlb_fns
533         .long   v4wb_user_fns
534         .long   arm925_cache_fns
535         .size   __arm925_proc_info, . - __arm925_proc_info
536
537         .type   __arm915_proc_info,#object
538 __arm915_proc_info:
539         .long   0x54029150
540         .long   0xfffffff0
541         .long   0x00000c12                      @ mmuflags
542         b       __arm925_setup
543         .long   cpu_arch_name
544         .long   cpu_elf_name
545         .long   HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
546         .long   cpu_arm925_name
547         .long   arm925_processor_functions
548         .long   v4wbi_tlb_fns
549         .long   v4wb_user_fns
550         .long   arm925_cache_fns
551         .size   __arm925_proc_info, . - __arm925_proc_info