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