ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / arm / mm / proc-arm1020.S
1 /*
2  *  linux/arch/arm/mm/proc-arm1020.S: MMU functions for ARM1020
3  *
4  *  Copyright (C) 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 arm1020.
24  *
25  *  CONFIG_CPU_ARM1020_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/constants.h>
32 #include <asm/pgtable.h>
33 #include <asm/procinfo.h>
34 #include <asm/ptrace.h>
35 #include <asm/hardware.h>
36
37 /*
38  * This is the maximum size of an area which will be invalidated
39  * using the single invalidate entry instructions.  Anything larger
40  * than this, and we go for the whole cache.
41  *
42  * This value should be chosen such that we choose the cheapest
43  * alternative.
44  */
45 #define MAX_AREA_SIZE   32768
46
47 /*
48  * The size of one data cache line.
49  */
50 #define CACHE_DLINESIZE 32
51
52 /*
53  * The number of data cache segments.
54  */
55 #define CACHE_DSEGMENTS 16
56
57 /*
58  * The number of lines in a cache segment.
59  */
60 #define CACHE_DENTRIES  64
61
62 /*
63  * This is the size at which it becomes more efficient to
64  * clean the whole cache, rather than using the individual
65  * cache line maintainence instructions.
66  */
67 #define CACHE_DLIMIT    32768
68
69         .text
70 /*
71  * cpu_arm1020_proc_init()
72  */
73 ENTRY(cpu_arm1020_proc_init)
74         mov     pc, lr
75
76 /*
77  * cpu_arm1020_proc_fin()
78  */
79 ENTRY(cpu_arm1020_proc_fin)
80         stmfd   sp!, {lr}
81         mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
82         msr     cpsr_c, ip
83         bl      arm1020_flush_kern_cache_all
84         mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
85         bic     r0, r0, #0x1000                 @ ...i............
86         bic     r0, r0, #0x000e                 @ ............wca.
87         mcr     p15, 0, r0, c1, c0, 0           @ disable caches
88         ldmfd   sp!, {pc}
89
90 /*
91  * cpu_arm1020_reset(loc)
92  *
93  * Perform a soft reset of the system.  Put the CPU into the
94  * same state as it would be if it had been reset, and branch
95  * to what would be the reset vector.
96  *
97  * loc: location to jump to for soft reset
98  */
99         .align  5
100 ENTRY(cpu_arm1020_reset)
101         mov     ip, #0
102         mcr     p15, 0, ip, c7, c7, 0           @ invalidate I,D caches
103         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
104         mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
105         mrc     p15, 0, ip, c1, c0, 0           @ ctrl register
106         bic     ip, ip, #0x000f                 @ ............wcam
107         bic     ip, ip, #0x1100                 @ ...i...s........
108         mcr     p15, 0, ip, c1, c0, 0           @ ctrl register
109         mov     pc, r0
110
111 /*
112  * cpu_arm1020_do_idle()
113  */
114         .align  5
115 ENTRY(cpu_arm1020_do_idle)
116         mcr     p15, 0, r0, c7, c0, 4           @ Wait for interrupt
117         mov     pc, lr
118
119 /* ================================= CACHE ================================ */
120
121         .align  5
122 /*
123  *      flush_user_cache_all()
124  *
125  *      Invalidate all cache entries in a particular address
126  *      space.
127  */
128 ENTRY(arm1020_flush_user_cache_all)
129         /* FALLTHROUGH */
130 /*
131  *      flush_kern_cache_all()
132  *
133  *      Clean and invalidate the entire cache.
134  */
135 ENTRY(arm1020_flush_kern_cache_all)
136         mov     r2, #VM_EXEC
137         mov     ip, #0
138 __flush_whole_cache:
139 #ifndef CONFIG_CPU_DCACHE_DISABLE
140         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
141         mov     r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
142 1:      orr     r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
143 2:      mcr     p15, 0, r3, c7, c14, 2          @ clean+invalidate D index
144         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
145         subs    r3, r3, #1 << 26
146         bcs     2b                              @ entries 63 to 0
147         subs    r1, r1, #1 << 5
148         bcs     1b                              @ segments 15 to 0
149 #endif
150         tst     r2, #VM_EXEC
151 #ifndef CONFIG_CPU_ICACHE_DISABLE
152         mcrne   p15, 0, ip, c7, c5, 0           @ invalidate I cache
153 #endif
154         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
155         mov     pc, lr
156
157 /*
158  *      flush_user_cache_range(start, end, flags)
159  *
160  *      Invalidate a range of cache entries in the specified
161  *      address space.
162  *
163  *      - start - start address (inclusive)
164  *      - end   - end address (exclusive)
165  *      - flags - vm_flags for this space
166  */
167 ENTRY(arm1020_flush_user_cache_range)
168         mov     ip, #0
169         sub     r3, r1, r0                      @ calculate total size
170         cmp     r3, #CACHE_DLIMIT
171         bhs     __flush_whole_cache
172
173 #ifndef CONFIG_CPU_DCACHE_DISABLE
174         mcr     p15, 0, ip, c7, c10, 4
175 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
176         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
177         add     r0, r0, #CACHE_DLINESIZE
178         cmp     r0, r1
179         blo     1b
180 #endif
181         tst     r2, #VM_EXEC
182 #ifndef CONFIG_CPU_ICACHE_DISABLE
183         mcrne   p15, 0, ip, c7, c5, 0           @ invalidate I cache
184 #endif
185         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
186         mov     pc, lr
187
188 /*
189  *      coherent_kern_range(start, end)
190  *
191  *      Ensure coherency between the Icache and the Dcache in the
192  *      region described by start.  If you have non-snooping
193  *      Harvard caches, you need to implement this function.
194  *
195  *      - start - virtual start address
196  *      - end   - virtual end address
197  */
198 ENTRY(arm1020_coherent_kern_range)
199         mov     ip, #0
200         bic     r0, r0, #CACHE_DLINESIZE - 1
201         mcr     p15, 0, ip, c7, c10, 4
202 1:
203 #ifndef CONFIG_CPU_DCACHE_DISABLE
204         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
205         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
206 #endif
207 #ifndef CONFIG_CPU_ICACHE_DISABLE
208         mcr     p15, 0, r0, c7, c5, 1           @ invalidate I entry
209 #endif
210         add     r0, r0, #CACHE_DLINESIZE
211         cmp     r0, r1
212         blo     1b
213         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
214         mov     pc, lr
215
216 /*
217  *      flush_kern_dcache_page(void *page)
218  *
219  *      Ensure no D cache aliasing occurs, either with itself or
220  *      the I cache
221  *
222  *      - page  - page aligned address
223  */
224 ENTRY(arm1020_flush_kern_dcache_page)
225         mov     ip, #0
226 #ifndef CONFIG_CPU_DCACHE_DISABLE
227         add     r1, r0, #PAGE_SZ
228 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
229         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
230         add     r0, r0, #CACHE_DLINESIZE
231         cmp     r0, r1
232         blo     1b
233 #endif
234         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
235         mov     pc, lr
236
237 /*
238  *      dma_inv_range(start, end)
239  *
240  *      Invalidate (discard) the specified virtual address range.
241  *      May not write back any entries.  If 'start' or 'end'
242  *      are not cache line aligned, those lines must be written
243  *      back.
244  *
245  *      - start - virtual start address
246  *      - end   - virtual end address
247  *
248  * (same as v4wb)
249  */
250 ENTRY(arm1020_dma_inv_range)
251         mov     ip, #0
252 #ifndef CONFIG_CPU_DCACHE_DISABLE
253         tst     r0, #CACHE_DLINESIZE - 1
254         bic     r0, r0, #CACHE_DLINESIZE - 1
255         mcrne   p15, 0, ip, c7, c10, 4
256         mcrne   p15, 0, r0, c7, c10, 1          @ clean D entry
257         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
258         tst     r1, #CACHE_DLINESIZE - 1
259         mcrne   p15, 0, ip, c7, c10, 4
260         mcrne   p15, 0, r1, c7, c10, 1          @ clean D entry
261         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
262 1:      mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
263         add     r0, r0, #CACHE_DLINESIZE
264         cmp     r0, r1
265         blo     1b
266 #endif
267         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
268         mov     pc, lr
269
270 /*
271  *      dma_clean_range(start, end)
272  *
273  *      Clean the specified virtual address range.
274  *
275  *      - start - virtual start address
276  *      - end   - virtual end address
277  *
278  * (same as v4wb)
279  */
280 ENTRY(arm1020_dma_clean_range)
281         mov     ip, #0
282 #ifndef CONFIG_CPU_DCACHE_DISABLE
283         bic     r0, r0, #CACHE_DLINESIZE - 1
284 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
285         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
286         add     r0, r0, #CACHE_DLINESIZE
287         cmp     r0, r1
288         blo     1b
289 #endif
290         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
291         mov     pc, lr
292
293 /*
294  *      dma_flush_range(start, end)
295  *
296  *      Clean and invalidate the specified virtual address range.
297  *
298  *      - start - virtual start address
299  *      - end   - virtual end address
300  */
301 ENTRY(arm1020_dma_flush_range)
302         mov     ip, #0
303 #ifndef CONFIG_CPU_DCACHE_DISABLE
304         bic     r0, r0, #CACHE_DLINESIZE - 1
305         mcr     p15, 0, ip, c7, c10, 4
306 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
307         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
308         add     r0, r0, #CACHE_DLINESIZE
309         cmp     r0, r1
310         blo     1b
311 #endif
312         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
313         mov     pc, lr
314
315 ENTRY(arm1020_cache_fns)
316         .long   arm1020_flush_kern_cache_all
317         .long   arm1020_flush_user_cache_all
318         .long   arm1020_flush_user_cache_range
319         .long   arm1020_coherent_kern_range
320         .long   arm1020_flush_kern_dcache_page
321         .long   arm1020_dma_inv_range
322         .long   arm1020_dma_clean_range
323         .long   arm1020_dma_flush_range
324
325         .align  5
326 ENTRY(cpu_arm1020_dcache_clean_area)
327 #ifndef CONFIG_CPU_DCACHE_DISABLE
328         mov     ip, #0
329 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
330         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
331         add     r0, r0, #CACHE_DLINESIZE
332         subs    r1, r1, #CACHE_DLINESIZE
333         bhi     1b
334 #endif
335         mov     pc, lr
336
337 /* =============================== PageTable ============================== */
338
339 /*
340  * cpu_arm1020_switch_mm(pgd)
341  *
342  * Set the translation base pointer to be as described by pgd.
343  *
344  * pgd: new page tables
345  */
346         .align  5
347 ENTRY(cpu_arm1020_switch_mm)
348 #ifndef CONFIG_CPU_DCACHE_DISABLE
349         mcr     p15, 0, r3, c7, c10, 4
350         mov     r1, #0xF                        @ 16 segments
351 1:      mov     r3, #0x3F                       @ 64 entries
352 2:      mov     ip, r3, LSL #26                 @ shift up entry
353         orr     ip, ip, r1, LSL #5              @ shift in/up index
354         mcr     p15, 0, ip, c7, c14, 2          @ Clean & Inval DCache entry
355         mov     ip, #0
356         mcr     p15, 0, ip, c7, c10, 4
357         subs    r3, r3, #1
358         cmp     r3, #0
359         bge     2b                              @ entries 3F to 0
360         subs    r1, r1, #1
361         cmp     r1, #0
362         bge     1b                              @ segments 15 to 0
363
364 #endif
365         mov     r1, #0
366 #ifndef CONFIG_CPU_ICACHE_DISABLE
367         mcr     p15, 0, r1, c7, c5, 0           @ invalidate I cache
368 #endif
369         mcr     p15, 0, r1, c7, c10, 4          @ drain WB
370         mcr     p15, 0, r0, c2, c0, 0           @ load page table pointer
371         mcr     p15, 0, r1, c8, c7, 0           @ invalidate I & D TLBs
372         mov     pc, lr
373         
374 /*
375  * cpu_arm1020_set_pte(ptep, pte)
376  *
377  * Set a PTE and flush it out
378  */
379         .align  5
380 ENTRY(cpu_arm1020_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, r1, #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_DISABLE
406         mcr     p15, 0, r0, c7, c10, 4
407         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
408 #endif
409         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
410         mov     pc, lr
411
412         __INIT
413
414         .type   __arm1020_setup, #function
415 __arm1020_setup:
416         mov     r0, #0
417         mcr     p15, 0, r0, c7, c7              @ invalidate I,D caches on v4
418         mcr     p15, 0, r0, c7, c10, 4          @ drain write buffer on v4
419         mcr     p15, 0, r0, c8, c7              @ invalidate I,D TLBs on v4
420         mcr     p15, 0, r4, c2, c0              @ load page table pointer
421         mov     r0, #0x1f                       @ Domains 0, 1 = client
422         mcr     p15, 0, r0, c3, c0              @ load domain access register
423         mrc     p15, 0, r0, c1, c0              @ get control register v4
424 /*
425  * Clear out 'unwanted' bits (then put them in if we need them)
426  */
427         bic     r0, r0, #0x1e00                 @ i...??r.........
428         bic     r0, r0, #0x000e                 @ ............wca.
429 /*
430  * Turn on what we want
431  */
432         orr     r0, r0, #0x0031                 @ ..........DP...M
433         orr     r0, r0, #0x0100                 @ .......S........
434
435 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
436         orr     r0, r0, #0x4000                 @ .R..............
437 #endif
438 #ifndef CONFIG_CPU_BPREDICT_DISABLE
439         orr     r0, r0, #0x0800                 @ ....Z...........
440 #endif
441 #ifndef CONFIG_CPU_DCACHE_DISABLE
442         orr     r0, r0, #0x0004                 @ Enable D cache
443 #endif
444 #ifndef CONFIG_CPU_ICACHE_DISABLE
445         orr     r0, r0, #0x1000                 @ I Cache on
446 #endif
447         mov     pc, lr
448         .size   __arm1020_setup, . - __arm1020_setup
449
450         __INITDATA
451
452 /*
453  * Purpose : Function pointers used to access above functions - all calls
454  *           come through these
455  */
456         .type   arm1020_processor_functions, #object
457 arm1020_processor_functions:
458         .word   v4t_early_abort
459         .word   cpu_arm1020_proc_init
460         .word   cpu_arm1020_proc_fin
461         .word   cpu_arm1020_reset
462         .word   cpu_arm1020_do_idle
463         .word   cpu_arm1020_dcache_clean_area
464         .word   cpu_arm1020_switch_mm
465         .word   cpu_arm1020_set_pte
466         .size   arm1020_processor_functions, . - arm1020_processor_functions
467
468         .section ".rodata"
469
470         .type   cpu_arch_name, #object
471 cpu_arch_name:
472         .asciz  "armv5t"
473         .size   cpu_arch_name, . - cpu_arch_name
474
475         .type   cpu_elf_name, #object
476 cpu_elf_name:
477         .asciz  "v5"
478         .size   cpu_elf_name, . - cpu_elf_name
479
480         .type   cpu_arm1020_name, #object
481 cpu_arm1020_name:
482         .ascii  "ARM1020"
483 #ifndef CONFIG_CPU_ICACHE_DISABLE
484         .ascii  "i"
485 #endif
486 #ifndef CONFIG_CPU_DCACHE_DISABLE
487         .ascii  "d"
488 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
489         .ascii  "(wt)"
490 #else
491         .ascii  "(wb)"
492 #endif
493 #endif
494 #ifndef CONFIG_CPU_BPREDICT_DISABLE
495         .ascii  "B"
496 #endif
497 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
498         .ascii  "RR"
499 #endif
500         .ascii  "\0"
501         .size   cpu_arm1020_name, . - cpu_arm1020_name
502
503         .align
504
505         .section ".proc.info", #alloc, #execinstr
506
507         .type   __arm1020_proc_info,#object
508 __arm1020_proc_info:
509         .long   0x4104a200                      @ ARM 1020T (Architecture v5T)
510         .long   0xff0ffff0
511         .long   0x00000c02                      @ mmuflags
512         b       __arm1020_setup
513         .long   cpu_arch_name
514         .long   cpu_elf_name
515         .long   HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
516         .long   cpu_arm1020_name
517         .long   arm1020_processor_functions
518         .long   v4wbi_tlb_fns
519         .long   v4wb_user_fns
520         .long   arm1020_cache_fns
521         .size   __arm1020_proc_info, . - __arm1020_proc_info