ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / arm / mm / proc-arm926.S
1 /*
2  *  linux/arch/arm/mm/proc-arm926.S: MMU functions for ARM926EJ-S
3  *
4  *  Copyright (C) 1999-2001 ARM Limited
5  *  Copyright (C) 2000 Deep Blue Solutions Ltd.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  *
22  * These are the low level assembler for performing cache and TLB
23  * functions on the arm926.
24  *
25  *  CONFIG_CPU_ARM926_CPU_IDLE -> nohlt
26  */
27 #include <linux/linkage.h>
28 #include <linux/config.h>
29 #include <linux/init.h>
30 #include <asm/assembler.h>
31 #include <asm/pgtable.h>
32 #include <asm/procinfo.h>
33 #include <asm/hardware.h>
34 #include <asm/page.h>
35 #include <asm/ptrace.h>
36 #include "proc-macros.S"
37
38 /*
39  * This is the maximum size of an area which will be invalidated
40  * using the single invalidate entry instructions.  Anything larger
41  * than this, and we go for the whole cache.
42  *
43  * This value should be chosen such that we choose the cheapest
44  * alternative.
45  */
46 #define CACHE_DLIMIT    16384
47
48 /*
49  * the cache line size of the I and D cache
50  */
51 #define CACHE_DLINESIZE 32
52
53         .text
54 /*
55  * cpu_arm926_proc_init()
56  */
57 ENTRY(cpu_arm926_proc_init)
58         mov     pc, lr
59
60 /*
61  * cpu_arm926_proc_fin()
62  */
63 ENTRY(cpu_arm926_proc_fin)
64         stmfd   sp!, {lr}
65         mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
66         msr     cpsr_c, ip
67         bl      arm926_flush_kern_cache_all
68         mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
69         bic     r0, r0, #0x1000                 @ ...i............
70         bic     r0, r0, #0x000e                 @ ............wca.
71         mcr     p15, 0, r0, c1, c0, 0           @ disable caches
72         ldmfd   sp!, {pc}
73
74 /*
75  * cpu_arm926_reset(loc)
76  *
77  * Perform a soft reset of the system.  Put the CPU into the
78  * same state as it would be if it had been reset, and branch
79  * to what would be the reset vector.
80  *
81  * loc: location to jump to for soft reset
82  */
83         .align  5
84 ENTRY(cpu_arm926_reset)
85         mov     ip, #0
86         mcr     p15, 0, ip, c7, c7, 0           @ invalidate I,D caches
87         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
88         mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
89         mrc     p15, 0, ip, c1, c0, 0           @ ctrl register
90         bic     ip, ip, #0x000f                 @ ............wcam
91         bic     ip, ip, #0x1100                 @ ...i...s........
92         mcr     p15, 0, ip, c1, c0, 0           @ ctrl register
93         mov     pc, r0
94
95 /*
96  * cpu_arm926_do_idle()
97  *
98  * Called with IRQs disabled
99  */
100         .align  10
101 ENTRY(cpu_arm926_do_idle)
102         mov     r0, #0
103         mrc     p15, 0, r1, c1, c0, 0           @ Read control register
104         mcr     p15, 0, r0, c7, c10, 4          @ Drain write buffer
105         bic     r2, r1, #1 << 12
106         mcr     p15, 0, r2, c1, c0, 0           @ Disable I cache
107         mcr     p15, 0, r0, c7, c0, 4           @ Wait for interrupt
108         mcr     p15, 0, r1, c1, c0, 0           @ Restore ICache enable
109         mov     pc, lr
110
111 /*
112  *      flush_user_cache_all()
113  *
114  *      Clean and invalidate all cache entries in a particular
115  *      address space.
116  */
117 ENTRY(arm926_flush_user_cache_all)
118         /* FALLTHROUGH */
119
120 /*
121  *      flush_kern_cache_all()
122  *
123  *      Clean and invalidate the entire cache.
124  */
125 ENTRY(arm926_flush_kern_cache_all)
126         mov     r2, #VM_EXEC
127         mov     ip, #0
128 __flush_whole_cache:
129 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
130         mcr     p15, 0, ip, c7, c6, 0           @ invalidate D cache
131 #else
132 1:      mrc     p15, 0, r15, c7, c14, 3         @ test,clean,invalidate
133         bne     1b
134 #endif
135         tst     r2, #VM_EXEC
136         mcrne   p15, 0, ip, c7, c5, 0           @ invalidate I cache
137         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
138         mov     pc, lr
139
140 /*
141  *      flush_user_cache_range(start, end, flags)
142  *
143  *      Clean and invalidate a range of cache entries in the
144  *      specified address range.
145  *
146  *      - start - start address (inclusive)
147  *      - end   - end address (exclusive)
148  *      - flags - vm_flags describing address space
149  */
150 ENTRY(arm926_flush_user_cache_range)
151         mov     ip, #0
152         sub     r3, r1, r0                      @ calculate total size
153         cmp     r3, #CACHE_DLIMIT
154         bgt     __flush_whole_cache
155 1:      tst     r2, #VM_EXEC
156 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
157         mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
158         mcrne   p15, 0, r0, c7, c5, 1           @ invalidate I entry
159         add     r0, r0, #CACHE_DLINESIZE
160         mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
161         mcrne   p15, 0, r0, c7, c5, 1           @ invalidate I entry
162         add     r0, r0, #CACHE_DLINESIZE
163 #else
164         mcr     p15, 0, r0, c7, c14, 1          @ clean and invalidate D entry
165         mcrne   p15, 0, r0, c7, c5, 1           @ invalidate I entry
166         add     r0, r0, #CACHE_DLINESIZE
167         mcr     p15, 0, r0, c7, c14, 1          @ clean and invalidate D entry
168         mcrne   p15, 0, r0, c7, c5, 1           @ invalidate I entry
169         add     r0, r0, #CACHE_DLINESIZE
170 #endif
171         cmp     r0, r1
172         blo     1b
173         tst     r2, #VM_EXEC
174         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
175         mov     pc, lr
176
177 /*
178  *      coherent_kern_range(start, end)
179  *
180  *      Ensure coherency between the Icache and the Dcache in the
181  *      region described by start, end.  If you have non-snooping
182  *      Harvard caches, you need to implement this function.
183  *
184  *      - start - virtual start address
185  *      - end   - virtual end address
186  */
187 ENTRY(arm926_coherent_kern_range)
188         bic     r0, r0, #CACHE_DLINESIZE - 1
189 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
190         mcr     p15, 0, r0, c7, c5, 1           @ invalidate I entry
191         add     r0, r0, #CACHE_DLINESIZE
192         cmp     r0, r1
193         blo     1b
194         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
195         mov     pc, lr
196
197 /*
198  *      flush_kern_dcache_page(void *page)
199  *
200  *      Ensure no D cache aliasing occurs, either with itself or
201  *      the I cache
202  *
203  *      - addr  - page aligned address
204  */
205 ENTRY(arm926_flush_kern_dcache_page)
206         add     r1, r0, #PAGE_SZ
207 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
208         add     r0, r0, #CACHE_DLINESIZE
209         cmp     r0, r1
210         blo     1b
211         mov     r0, #0
212         mcr     p15, 0, r0, c7, c5, 0           @ invalidate I cache
213         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
214         mov     pc, lr
215
216 /*
217  *      dma_inv_range(start, end)
218  *
219  *      Invalidate (discard) the specified virtual address range.
220  *      May not write back any entries.  If 'start' or 'end'
221  *      are not cache line aligned, those lines must be written
222  *      back.
223  *
224  *      - start - virtual start address
225  *      - end   - virtual end address
226  *
227  * (same as v4wb)
228  */
229 ENTRY(arm926_dma_inv_range)
230 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
231         tst     r0, #CACHE_DLINESIZE - 1
232         mcrne   p15, 0, r0, c7, c10, 1          @ clean D entry
233         tst     r1, #CACHE_DLINESIZE - 1
234         mcrne   p15, 0, r1, c7, c10, 1          @ clean D entry
235 #endif
236         bic     r0, r0, #CACHE_DLINESIZE - 1
237 1:      mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
238         add     r0, r0, #CACHE_DLINESIZE
239         cmp     r0, r1
240         blo     1b
241         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
242         mov     pc, lr
243
244 /*
245  *      dma_clean_range(start, end)
246  *
247  *      Clean the specified virtual address range.
248  *
249  *      - start - virtual start address
250  *      - end   - virtual end address
251  *
252  * (same as v4wb)
253  */
254 ENTRY(arm926_dma_clean_range)
255 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
256         bic     r0, r0, #CACHE_DLINESIZE - 1
257 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
258         add     r0, r0, #CACHE_DLINESIZE
259         cmp     r0, r1
260         blo     1b
261 #endif
262         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
263         mov     pc, lr
264
265 /*
266  *      dma_flush_range(start, end)
267  *
268  *      Clean and invalidate the specified virtual address range.
269  *
270  *      - start - virtual start address
271  *      - end   - virtual end address
272  */
273 ENTRY(arm926_dma_flush_range)
274         bic     r0, r0, #CACHE_DLINESIZE - 1
275 1:
276 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
277         mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
278 #else
279         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
280 #endif
281         add     r0, r0, #CACHE_DLINESIZE
282         cmp     r0, r1
283         blo     1b
284         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
285         mov     pc, lr
286
287 ENTRY(arm926_cache_fns)
288         .long   arm926_flush_kern_cache_all
289         .long   arm926_flush_user_cache_all
290         .long   arm926_flush_user_cache_range
291         .long   arm926_coherent_kern_range
292         .long   arm926_flush_kern_dcache_page
293         .long   arm926_dma_inv_range
294         .long   arm926_dma_clean_range
295         .long   arm926_dma_flush_range
296
297 ENTRY(cpu_arm926_dcache_clean_area)
298 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
299 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
300         add     r0, r0, #CACHE_DLINESIZE
301         subs    r1, r1, #CACHE_DLINESIZE
302         bhi     1b
303 #endif
304         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
305         mov     pc, lr
306
307 /* =============================== PageTable ============================== */
308
309 /*
310  * cpu_arm926_switch_mm(pgd)
311  *
312  * Set the translation base pointer to be as described by pgd.
313  *
314  * pgd: new page tables
315  */
316         .align  5
317 ENTRY(cpu_arm926_switch_mm)
318         mov     ip, #0
319 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
320         mcr     p15, 0, ip, c7, c6, 0           @ invalidate D cache
321 #else
322 @ && 'Clean & Invalidate whole DCache'
323 1:      mrc     p15, 0, r15, c7, c14, 3         @ test,clean,invalidate
324         bne     1b
325 #endif
326         mcr     p15, 0, ip, c7, c5, 0           @ invalidate I cache
327         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
328         mcr     p15, 0, r0, c2, c0, 0           @ load page table pointer
329         mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
330         mov     pc, lr
331
332 /*
333  * cpu_arm926_set_pte(ptep, pte)
334  *
335  * Set a PTE and flush it out
336  */
337         .align  5
338 ENTRY(cpu_arm926_set_pte)
339         str     r1, [r0], #-2048                @ linux version
340
341         eor     r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
342
343         bic     r2, r1, #PTE_SMALL_AP_MASK
344         bic     r2, r2, #PTE_TYPE_MASK
345         orr     r2, r2, #PTE_TYPE_SMALL
346
347         tst     r1, #L_PTE_USER                 @ User?
348         orrne   r2, r2, #PTE_SMALL_AP_URO_SRW
349
350         tst     r1, #L_PTE_WRITE | L_PTE_DIRTY  @ Write and Dirty?
351         orreq   r2, r2, #PTE_SMALL_AP_UNO_SRW
352
353         tst     r1, #L_PTE_PRESENT | L_PTE_YOUNG        @ Present and Young?
354         movne   r2, #0
355
356 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
357         eor     r3, r2, #0x0a                   @ C & small page?
358         tst     r3, #0x0b
359         biceq   r2, r2, #4
360 #endif
361         str     r2, [r0]                        @ hardware version
362         mov     r0, r0
363 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
364         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
365 #endif
366         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
367         mov     pc, lr
368
369         __INIT
370
371         .type   __arm926_setup, #function
372 __arm926_setup:
373         mov     r0, #0
374         mcr     p15, 0, r0, c7, c7              @ invalidate I,D caches on v4
375         mcr     p15, 0, r0, c7, c10, 4          @ drain write buffer on v4
376         mcr     p15, 0, r0, c8, c7              @ invalidate I,D TLBs on v4
377         mcr     p15, 0, r4, c2, c0              @ load page table pointer
378
379
380 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
381         mov     r0, #4                          @ disable write-back on caches explicitly
382         mcr     p15, 7, r0, c15, c0, 0
383 #endif 
384
385         mov     r0, #0x1f                       @ Domains 0, 1 = client
386         mcr     p15, 0, r0, c3, c0              @ load domain access register
387         mrc     p15, 0, r0, c1, c0              @ get control register v4
388 /*
389  * Clear out 'unwanted' bits (then put them in if we need them)
390  */
391                                                 @   VI ZFRS BLDP WCAM
392         bic     r0, r0, #0x0e00
393         bic     r0, r0, #0x0002
394         bic     r0, r0, #0x000c
395         bic     r0, r0, #0x1000                 @ ...0 000. .... 000.
396 /*
397  * Turn on what we want
398  */
399         orr     r0, r0, #0x0031
400         orr     r0, r0, #0x2100                 @ ..1. ...1 ..11 ...1
401
402 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
403         orr     r0, r0, #0x4000                 @ .1.. .... .... ....
404 #endif
405 #ifndef CONFIG_CPU_DCACHE_DISABLE
406         orr     r0, r0, #0x0004                 @ .... .... .... .1..
407 #endif
408 #ifndef CONFIG_CPU_ICACHE_DISABLE
409         orr     r0, r0, #0x1000                 @ ...1 .... .... ....
410 #endif
411         mov     pc, lr
412         .size   __arm926_setup, . - __arm926_setup
413
414         __INITDATA
415
416 /*
417  * Purpose : Function pointers used to access above functions - all calls
418  *           come through these
419  */
420         .type   arm926_processor_functions, #object
421 arm926_processor_functions:
422         .word   v5tj_early_abort
423         .word   cpu_arm926_proc_init
424         .word   cpu_arm926_proc_fin
425         .word   cpu_arm926_reset
426         .word   cpu_arm926_do_idle
427         .word   cpu_arm926_dcache_clean_area
428         .word   cpu_arm926_switch_mm
429         .word   cpu_arm926_set_pte
430         .size   arm926_processor_functions, . - arm926_processor_functions
431
432         .section ".rodata"
433
434         .type   cpu_arch_name, #object
435 cpu_arch_name:
436         .asciz  "armv5tej"
437         .size   cpu_arch_name, . - cpu_arch_name
438
439         .type   cpu_elf_name, #object
440 cpu_elf_name:
441         .asciz  "v5"
442         .size   cpu_elf_name, . - cpu_elf_name
443
444         .type   cpu_arm926_name, #object
445 cpu_arm926_name:
446         .ascii  "ARM926EJ-S"
447 #ifndef CONFIG_CPU_ICACHE_DISABLE
448         .ascii  "i"
449 #endif
450 #ifndef CONFIG_CPU_DCACHE_DISABLE
451         .ascii  "d"
452 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
453         .ascii  "(wt)"
454 #else
455         .ascii  "(wb)"
456 #endif
457 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
458         .ascii  "RR"
459 #endif
460 #endif
461         .ascii  "\0"
462         .size   cpu_arm926_name, . - cpu_arm926_name
463
464         .align
465
466         .section ".proc.info", #alloc, #execinstr
467
468         .type   __arm926_proc_info,#object
469 __arm926_proc_info:
470         .long   0x41069260                      @ ARM926EJ-S (v5TEJ)
471         .long   0xff0ffff0
472         .long   0x00000c1e                      @ mmuflags
473         b       __arm926_setup
474         .long   cpu_arch_name
475         .long   cpu_elf_name
476         .long   HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_FAST_MULT | HWCAP_JAVA
477         .long   cpu_arm926_name
478         .long   arm926_processor_functions
479         .long   v4wbi_tlb_fns
480         .long   v4wb_user_fns
481         .long   arm926_cache_fns
482         .size   __arm926_proc_info, . - __arm926_proc_info