ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / arm / mm / proc-arm920.S
1 /*
2  *  linux/arch/arm/mm/proc-arm920.S: MMU functions for ARM920
3  *
4  *  Copyright (C) 1999,2000 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 arm920.
24  *
25  *  CONFIG_CPU_ARM920_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  * The size of one data cache line.
40  */
41 #define CACHE_DLINESIZE 32
42
43 /*
44  * The number of data cache segments.
45  */
46 #define CACHE_DSEGMENTS 8
47
48 /*
49  * The number of lines in a cache segment.
50  */
51 #define CACHE_DENTRIES  64
52
53 /*
54  * This is the size at which it becomes more efficient to
55  * clean the whole cache, rather than using the individual
56  * cache line maintainence instructions.
57  */
58 #define CACHE_DLIMIT    65536
59
60
61         .text
62 /*
63  * cpu_arm920_proc_init()
64  */
65 ENTRY(cpu_arm920_proc_init)
66         mov     pc, lr
67
68 /*
69  * cpu_arm920_proc_fin()
70  */
71 ENTRY(cpu_arm920_proc_fin)
72         stmfd   sp!, {lr}
73         mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
74         msr     cpsr_c, ip
75 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
76         bl      arm920_flush_kern_cache_all
77 #else
78         bl      v4wt_flush_kern_cache_all
79 #endif
80         mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
81         bic     r0, r0, #0x1000                 @ ...i............
82         bic     r0, r0, #0x000e                 @ ............wca.
83         mcr     p15, 0, r0, c1, c0, 0           @ disable caches
84         ldmfd   sp!, {pc}
85
86 /*
87  * cpu_arm920_reset(loc)
88  *
89  * Perform a soft reset of the system.  Put the CPU into the
90  * same state as it would be if it had been reset, and branch
91  * to what would be the reset vector.
92  *
93  * loc: location to jump to for soft reset
94  */
95         .align  5
96 ENTRY(cpu_arm920_reset)
97         mov     ip, #0
98         mcr     p15, 0, ip, c7, c7, 0           @ invalidate I,D caches
99         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
100         mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
101         mrc     p15, 0, ip, c1, c0, 0           @ ctrl register
102         bic     ip, ip, #0x000f                 @ ............wcam
103         bic     ip, ip, #0x1100                 @ ...i...s........
104         mcr     p15, 0, ip, c1, c0, 0           @ ctrl register
105         mov     pc, r0
106
107 /*
108  * cpu_arm920_do_idle()
109  */
110         .align  5
111 ENTRY(cpu_arm920_do_idle)
112         mcr     p15, 0, r0, c7, c0, 4           @ Wait for interrupt
113         mov     pc, lr
114
115
116 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
117
118 /*
119  *      flush_user_cache_all()
120  *
121  *      Invalidate all cache entries in a particular address
122  *      space.
123  */
124 ENTRY(arm920_flush_user_cache_all)
125         /* FALLTHROUGH */
126
127 /*
128  *      flush_kern_cache_all()
129  *
130  *      Clean and invalidate the entire cache.
131  */
132 ENTRY(arm920_flush_kern_cache_all)
133         mov     r2, #VM_EXEC
134         mov     ip, #0
135 __flush_whole_cache:
136         mov     r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
137 1:      orr     r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
138 2:      mcr     p15, 0, r3, c7, c14, 2          @ clean+invalidate D index
139         subs    r3, r3, #1 << 26
140         bcs     2b                              @ entries 63 to 0
141         subs    r1, r1, #1 << 5
142         bcs     1b                              @ segments 7 to 0
143         tst     r2, #VM_EXEC
144         mcrne   p15, 0, ip, c7, c5, 0           @ invalidate I cache
145         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
146         mov     pc, lr
147
148 /*
149  *      flush_user_cache_range(start, end, flags)
150  *
151  *      Invalidate a range of cache entries in the specified
152  *      address space.
153  *
154  *      - start - start address (inclusive)
155  *      - end   - end address (exclusive)
156  *      - flags - vm_flags for address space
157  */
158 ENTRY(arm920_flush_user_cache_range)
159         mov     ip, #0
160         sub     r3, r1, r0                      @ calculate total size
161         cmp     r3, #CACHE_DLIMIT
162         bhs     __flush_whole_cache
163
164 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
165         tst     r2, #VM_EXEC
166         mcrne   p15, 0, r0, c7, c5, 1           @ invalidate I entry
167         add     r0, r0, #CACHE_DLINESIZE
168         cmp     r0, r1
169         blo     1b
170         tst     r2, #VM_EXEC
171         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
172         mov     pc, lr
173
174 /*
175  *      coherent_kern_range(start, end)
176  *
177  *      Ensure coherency between the Icache and the Dcache in the
178  *      region described by start, end.  If you have non-snooping
179  *      Harvard caches, you need to implement this function.
180  *
181  *      - start - virtual start address
182  *      - end   - virtual end address
183  */
184 ENTRY(arm920_coherent_kern_range)
185         bic     r0, r0, #CACHE_DLINESIZE - 1
186 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
187         mcr     p15, 0, r0, c7, c5, 1           @ invalidate I entry
188         add     r0, r0, #CACHE_DLINESIZE
189         cmp     r0, r1
190         blo     1b
191         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
192         mov     pc, lr
193
194 /*
195  *      flush_kern_dcache_page(void *page)
196  *
197  *      Ensure no D cache aliasing occurs, either with itself or
198  *      the I cache
199  *
200  *      - addr  - page aligned address
201  */
202 ENTRY(arm920_flush_kern_dcache_page)
203         add     r1, r0, #PAGE_SZ
204 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
205         add     r0, r0, #CACHE_DLINESIZE
206         cmp     r0, r1
207         blo     1b
208         mov     r0, #0
209         mcr     p15, 0, r0, c7, c5, 0           @ invalidate I cache
210         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
211         mov     pc, lr
212
213 /*
214  *      dma_inv_range(start, end)
215  *
216  *      Invalidate (discard) the specified virtual address range.
217  *      May not write back any entries.  If 'start' or 'end'
218  *      are not cache line aligned, those lines must be written
219  *      back.
220  *
221  *      - start - virtual start address
222  *      - end   - virtual end address
223  *
224  * (same as v4wb)
225  */
226 ENTRY(arm920_dma_inv_range)
227         tst     r0, #CACHE_DLINESIZE - 1
228         bic     r0, r0, #CACHE_DLINESIZE - 1
229         mcrne   p15, 0, r0, c7, c10, 1          @ clean D entry
230         tst     r1, #CACHE_DLINESIZE - 1
231         mcrne   p15, 0, r1, c7, c10, 1          @ clean D entry
232 1:      mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
233         add     r0, r0, #CACHE_DLINESIZE
234         cmp     r0, r1
235         blo     1b
236         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
237         mov     pc, lr
238
239 /*
240  *      dma_clean_range(start, end)
241  *
242  *      Clean the specified virtual address range.
243  *
244  *      - start - virtual start address
245  *      - end   - virtual end address
246  *
247  * (same as v4wb)
248  */
249 ENTRY(arm920_dma_clean_range)
250         bic     r0, r0, #CACHE_DLINESIZE - 1
251 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
252         add     r0, r0, #CACHE_DLINESIZE
253         cmp     r0, r1
254         blo     1b
255         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
256         mov     pc, lr
257
258 /*
259  *      dma_flush_range(start, end)
260  *
261  *      Clean and invalidate the specified virtual address range.
262  *
263  *      - start - virtual start address
264  *      - end   - virtual end address
265  */
266 ENTRY(arm920_dma_flush_range)
267         bic     r0, r0, #CACHE_DLINESIZE - 1
268 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
269         add     r0, r0, #CACHE_DLINESIZE
270         cmp     r0, r1
271         blo     1b
272         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
273         mov     pc, lr
274
275 ENTRY(arm920_cache_fns)
276         .long   arm920_flush_kern_cache_all
277         .long   arm920_flush_user_cache_all
278         .long   arm920_flush_user_cache_range
279         .long   arm920_coherent_kern_range
280         .long   arm920_flush_kern_dcache_page
281         .long   arm920_dma_inv_range
282         .long   arm920_dma_clean_range
283         .long   arm920_dma_flush_range
284
285 #endif
286
287
288 ENTRY(cpu_arm920_dcache_clean_area)
289 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
290         add     r0, r0, #CACHE_DLINESIZE
291         subs    r1, r1, #CACHE_DLINESIZE
292         bhi     1b
293         mov     pc, lr
294
295 /* =============================== PageTable ============================== */
296
297 /*
298  * cpu_arm920_switch_mm(pgd)
299  *
300  * Set the translation base pointer to be as described by pgd.
301  *
302  * pgd: new page tables
303  */
304         .align  5
305 ENTRY(cpu_arm920_switch_mm)
306         mov     ip, #0
307 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
308         mcr     p15, 0, ip, c7, c6, 0           @ invalidate D cache
309 #else
310 @ && 'Clean & Invalidate whole DCache'
311 @ && Re-written to use Index Ops.
312 @ && Uses registers r1, r3 and ip
313
314         mov     r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
315 1:      orr     r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
316 2:      mcr     p15, 0, r3, c7, c14, 2          @ clean & invalidate D index
317         subs    r3, r3, #1 << 26
318         bcs     2b                              @ entries 63 to 0
319         subs    r1, r1, #1 << 5
320         bcs     1b                              @ segments 7 to 0
321 #endif
322         mcr     p15, 0, ip, c7, c5, 0           @ invalidate I cache
323         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
324         mcr     p15, 0, r0, c2, c0, 0           @ load page table pointer
325         mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
326         mov     pc, lr
327
328 /*
329  * cpu_arm920_set_pte(ptep, pte)
330  *
331  * Set a PTE and flush it out
332  */
333         .align  5
334 ENTRY(cpu_arm920_set_pte)
335         str     r1, [r0], #-2048                @ linux version
336
337         eor     r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
338
339         bic     r2, r1, #PTE_SMALL_AP_MASK
340         bic     r2, r2, #PTE_TYPE_MASK
341         orr     r2, r2, #PTE_TYPE_SMALL
342
343         tst     r1, #L_PTE_USER                 @ User?
344         orrne   r2, r2, #PTE_SMALL_AP_URO_SRW
345
346         tst     r1, #L_PTE_WRITE | L_PTE_DIRTY  @ Write and Dirty?
347         orreq   r2, r2, #PTE_SMALL_AP_UNO_SRW
348
349         tst     r1, #L_PTE_PRESENT | L_PTE_YOUNG        @ Present and Young?
350         movne   r2, #0
351
352 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
353         eor     r3, r2, #0x0a                   @ C & small page?
354         tst     r3, #0x0b
355         biceq   r2, r2, #4
356 #endif
357         str     r2, [r0]                        @ hardware version
358         mov     r0, r0
359         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
360         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
361         mov     pc, lr
362
363         __INIT
364
365         .type   __arm920_setup, #function
366 __arm920_setup:
367         mov     r0, #0
368         mcr     p15, 0, r0, c7, c7              @ invalidate I,D caches on v4
369         mcr     p15, 0, r0, c7, c10, 4          @ drain write buffer on v4
370         mcr     p15, 0, r0, c8, c7              @ invalidate I,D TLBs on v4
371         mcr     p15, 0, r4, c2, c0              @ load page table pointer
372         mov     r0, #0x1f                       @ Domains 0, 1 = client
373         mcr     p15, 0, r0, c3, c0              @ load domain access register
374         mrc     p15, 0, r0, c1, c0              @ get control register v4
375 /*
376  * Clear out 'unwanted' bits (then put them in if we need them)
377  */
378                                                 @   VI ZFRS BLDP WCAM
379         bic     r0, r0, #0x0e00
380         bic     r0, r0, #0x0002
381         bic     r0, r0, #0x000c
382         bic     r0, r0, #0x1000                 @ ...0 000. .... 000.
383 /*
384  * Turn on what we want
385  */
386         orr     r0, r0, #0x0031
387         orr     r0, r0, #0x2100                 @ ..1. ...1 ..11 ...1
388
389 #ifndef CONFIG_CPU_DCACHE_DISABLE
390         orr     r0, r0, #0x0004                 @ .... .... .... .1..
391 #endif
392 #ifndef CONFIG_CPU_ICACHE_DISABLE
393         orr     r0, r0, #0x1000                 @ ...1 .... .... ....
394 #endif
395         mov     pc, lr
396         .size   __arm920_setup, . - __arm920_setup
397
398         __INITDATA
399
400 /*
401  * Purpose : Function pointers used to access above functions - all calls
402  *           come through these
403  */
404         .type   arm920_processor_functions, #object
405 arm920_processor_functions:
406         .word   v4t_early_abort
407         .word   cpu_arm920_proc_init
408         .word   cpu_arm920_proc_fin
409         .word   cpu_arm920_reset
410         .word   cpu_arm920_do_idle
411         .word   cpu_arm920_dcache_clean_area
412         .word   cpu_arm920_switch_mm
413         .word   cpu_arm920_set_pte
414         .size   arm920_processor_functions, . - arm920_processor_functions
415
416         .section ".rodata"
417
418         .type   cpu_arch_name, #object
419 cpu_arch_name:
420         .asciz  "armv4t"
421         .size   cpu_arch_name, . - cpu_arch_name
422
423         .type   cpu_elf_name, #object
424 cpu_elf_name:
425         .asciz  "v4"
426         .size   cpu_elf_name, . - cpu_elf_name
427
428         .type   cpu_arm920_name, #object
429 cpu_arm920_name:
430         .ascii  "ARM920T"
431 #ifndef CONFIG_CPU_ICACHE_DISABLE
432         .ascii  "i"
433 #endif
434 #ifndef CONFIG_CPU_DCACHE_DISABLE
435         .ascii  "d"
436 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
437         .ascii  "(wt)"
438 #else
439         .ascii  "(wb)"
440 #endif
441 #endif
442         .ascii  "\0"
443         .size   cpu_arm920_name, . - cpu_arm920_name
444
445         .align
446
447         .section ".proc.info", #alloc, #execinstr
448
449         .type   __arm920_proc_info,#object
450 __arm920_proc_info:
451         .long   0x41009200
452         .long   0xff00fff0
453         .long   0x00000c1e                      @ mmuflags
454         b       __arm920_setup
455         .long   cpu_arch_name
456         .long   cpu_elf_name
457         .long   HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
458         .long   cpu_arm920_name
459         .long   arm920_processor_functions
460         .long   v4wbi_tlb_fns
461         .long   v4wb_user_fns
462 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
463         .long   arm920_cache_fns
464 #else
465         .long   v4wt_cache_fns
466 #endif
467         .size   __arm920_proc_info, . - __arm920_proc_info