ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / arm / mm / proc-arm1020e.S
1 /*
2  *  linux/arch/arm/mm/proc-arm1020e.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 arm1020e.
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_arm1020e_proc_init()
72  */
73 ENTRY(cpu_arm1020e_proc_init)
74         mov     pc, lr
75
76 /*
77  * cpu_arm1020e_proc_fin()
78  */
79 ENTRY(cpu_arm1020e_proc_fin)
80         stmfd   sp!, {lr}
81         mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
82         msr     cpsr_c, ip
83         bl      arm1020e_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_arm1020e_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_arm1020e_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_arm1020e_do_idle()
113  */
114         .align  5
115 ENTRY(cpu_arm1020e_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(arm1020e_flush_user_cache_all)
129         /* FALLTHROUGH */
130 /*
131  *      flush_kern_cache_all()
132  *
133  *      Clean and invalidate the entire cache.
134  */
135 ENTRY(arm1020e_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         subs    r3, r3, #1 << 26
145         bcs     2b                              @ entries 63 to 0
146         subs    r1, r1, #1 << 5
147         bcs     1b                              @ segments 15 to 0
148 #endif
149         tst     r2, #VM_EXEC
150 #ifndef CONFIG_CPU_ICACHE_DISABLE
151         mcrne   p15, 0, ip, c7, c5, 0           @ invalidate I cache
152 #endif
153         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
154         mov     pc, lr
155
156 /*
157  *      flush_user_cache_range(start, end, flags)
158  *
159  *      Invalidate a range of cache entries in the specified
160  *      address space.
161  *
162  *      - start - start address (inclusive)
163  *      - end   - end address (exclusive)
164  *      - flags - vm_flags for this space
165  */
166 ENTRY(arm1020e_flush_user_cache_range)
167         mov     ip, #0
168         sub     r3, r1, r0                      @ calculate total size
169         cmp     r3, #CACHE_DLIMIT
170         bhs     __flush_whole_cache
171
172 #ifndef CONFIG_CPU_DCACHE_DISABLE
173 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
174         add     r0, r0, #CACHE_DLINESIZE
175         cmp     r0, r1
176         blo     1b
177 #endif
178         tst     r2, #VM_EXEC
179 #ifndef CONFIG_CPU_ICACHE_DISABLE
180         mcrne   p15, 0, ip, c7, c5, 0           @ invalidate I cache
181 #endif
182         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
183         mov     pc, lr
184
185 /*
186  *      coherent_kern_range(start, end)
187  *
188  *      Ensure coherency between the Icache and the Dcache in the
189  *      region described by start.  If you have non-snooping
190  *      Harvard caches, you need to implement this function.
191  *
192  *      - start - virtual start address
193  *      - end   - virtual end address
194  */
195 ENTRY(arm1020e_coherent_kern_range)
196         mov     ip, #0
197         bic     r0, r0, #CACHE_DLINESIZE - 1
198 1:
199 #ifndef CONFIG_CPU_DCACHE_DISABLE
200         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
201 #endif
202 #ifndef CONFIG_CPU_ICACHE_DISABLE
203         mcr     p15, 0, r0, c7, c5, 1           @ invalidate I entry
204 #endif
205         add     r0, r0, #CACHE_DLINESIZE
206         cmp     r0, r1
207         blo     1b
208         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
209         mov     pc, lr
210
211 /*
212  *      flush_kern_dcache_page(void *page)
213  *
214  *      Ensure no D cache aliasing occurs, either with itself or
215  *      the I cache
216  *
217  *      - page  - page aligned address
218  */
219 ENTRY(arm1020e_flush_kern_dcache_page)
220         mov     ip, #0
221 #ifndef CONFIG_CPU_DCACHE_DISABLE
222         add     r1, r0, #PAGE_SZ
223 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
224         add     r0, r0, #CACHE_DLINESIZE
225         cmp     r0, r1
226         blo     1b
227 #endif
228         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
229         mov     pc, lr
230
231 /*
232  *      dma_inv_range(start, end)
233  *
234  *      Invalidate (discard) the specified virtual address range.
235  *      May not write back any entries.  If 'start' or 'end'
236  *      are not cache line aligned, those lines must be written
237  *      back.
238  *
239  *      - start - virtual start address
240  *      - end   - virtual end address
241  *
242  * (same as v4wb)
243  */
244 ENTRY(arm1020e_dma_inv_range)
245         mov     ip, #0
246 #ifndef CONFIG_CPU_DCACHE_DISABLE
247         tst     r0, #CACHE_DLINESIZE - 1
248         bic     r0, r0, #CACHE_DLINESIZE - 1
249         mcrne   p15, 0, r0, c7, c10, 1          @ clean D entry
250         tst     r1, #CACHE_DLINESIZE - 1
251         mcrne   p15, 0, r1, c7, c10, 1          @ clean D entry
252 1:      mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
253         add     r0, r0, #CACHE_DLINESIZE
254         cmp     r0, r1
255         blo     1b
256 #endif
257         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
258         mov     pc, lr
259
260 /*
261  *      dma_clean_range(start, end)
262  *
263  *      Clean the specified virtual address range.
264  *
265  *      - start - virtual start address
266  *      - end   - virtual end address
267  *
268  * (same as v4wb)
269  */
270 ENTRY(arm1020e_dma_clean_range)
271         mov     ip, #0
272 #ifndef CONFIG_CPU_DCACHE_DISABLE
273         bic     r0, r0, #CACHE_DLINESIZE - 1
274 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
275         add     r0, r0, #CACHE_DLINESIZE
276         cmp     r0, r1
277         blo     1b
278 #endif
279         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
280         mov     pc, lr
281
282 /*
283  *      dma_flush_range(start, end)
284  *
285  *      Clean and invalidate the specified virtual address range.
286  *
287  *      - start - virtual start address
288  *      - end   - virtual end address
289  */
290 ENTRY(arm1020e_dma_flush_range)
291         mov     ip, #0
292 #ifndef CONFIG_CPU_DCACHE_DISABLE
293         bic     r0, r0, #CACHE_DLINESIZE - 1
294 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
295         add     r0, r0, #CACHE_DLINESIZE
296         cmp     r0, r1
297         blo     1b
298 #endif
299         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
300         mov     pc, lr
301
302 ENTRY(arm1020e_cache_fns)
303         .long   arm1020e_flush_kern_cache_all
304         .long   arm1020e_flush_user_cache_all
305         .long   arm1020e_flush_user_cache_range
306         .long   arm1020e_coherent_kern_range
307         .long   arm1020e_flush_kern_dcache_page
308         .long   arm1020e_dma_inv_range
309         .long   arm1020e_dma_clean_range
310         .long   arm1020e_dma_flush_range
311
312         .align  5
313 ENTRY(cpu_arm1020e_dcache_clean_area)
314 #ifndef CONFIG_CPU_DCACHE_DISABLE
315         mov     ip, #0
316 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
317         add     r0, r0, #CACHE_DLINESIZE
318         subs    r1, r1, #CACHE_DLINESIZE
319         bhi     1b
320 #endif
321         mov     pc, lr
322
323 /* =============================== PageTable ============================== */
324
325 /*
326  * cpu_arm1020e_switch_mm(pgd)
327  *
328  * Set the translation base pointer to be as described by pgd.
329  *
330  * pgd: new page tables
331  */
332         .align  5
333 ENTRY(cpu_arm1020e_switch_mm)
334 #ifndef CONFIG_CPU_DCACHE_DISABLE
335         mcr     p15, 0, r3, c7, c10, 4
336         mov     r1, #0xF                        @ 16 segments
337 1:      mov     r3, #0x3F                       @ 64 entries
338 2:      mov     ip, r3, LSL #26                 @ shift up entry
339         orr     ip, ip, r1, LSL #5              @ shift in/up index
340         mcr     p15, 0, ip, c7, c14, 2          @ Clean & Inval DCache entry
341         mov     ip, #0
342         subs    r3, r3, #1
343         cmp     r3, #0
344         bge     2b                              @ entries 3F to 0
345         subs    r1, r1, #1
346         cmp     r1, #0
347         bge     1b                              @ segments 15 to 0
348
349 #endif
350         mov     r1, #0
351 #ifndef CONFIG_CPU_ICACHE_DISABLE
352         mcr     p15, 0, r1, c7, c5, 0           @ invalidate I cache
353 #endif
354         mcr     p15, 0, r1, c7, c10, 4          @ drain WB
355         mcr     p15, 0, r0, c2, c0, 0           @ load page table pointer
356         mcr     p15, 0, r1, c8, c7, 0           @ invalidate I & D TLBs
357         mov     pc, lr
358         
359 /*
360  * cpu_arm1020e_set_pte(ptep, pte)
361  *
362  * Set a PTE and flush it out
363  */
364         .align  5
365 ENTRY(cpu_arm1020e_set_pte)
366         str     r1, [r0], #-2048                @ linux version
367
368         eor     r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
369
370         bic     r2, r1, #PTE_SMALL_AP_MASK
371         bic     r2, r2, #PTE_TYPE_MASK
372         orr     r2, r2, #PTE_TYPE_SMALL
373
374         tst     r1, #L_PTE_USER                 @ User?
375         orrne   r2, r2, #PTE_SMALL_AP_URO_SRW
376
377         tst     r1, #L_PTE_WRITE | L_PTE_DIRTY  @ Write and Dirty?
378         orreq   r2, r2, #PTE_SMALL_AP_UNO_SRW
379
380         tst     r1, #L_PTE_PRESENT | L_PTE_YOUNG        @ Present and Young?
381         movne   r2, #0
382
383 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
384         eor     r3, r1, #0x0a                   @ C & small page?
385         tst     r3, #0x0b
386         biceq   r2, r2, #4
387 #endif
388         str     r2, [r0]                        @ hardware version
389         mov     r0, r0
390 #ifndef CONFIG_CPU_DCACHE_DISABLE
391         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
392 #endif
393         mov     pc, lr
394
395         __INIT
396
397         .type   __arm1020e_setup, #function
398 __arm1020e_setup:
399         mov     r0, #0
400         mcr     p15, 0, r0, c7, c7              @ invalidate I,D caches on v4
401         mcr     p15, 0, r0, c7, c10, 4          @ drain write buffer on v4
402         mcr     p15, 0, r0, c8, c7              @ invalidate I,D TLBs on v4
403         mcr     p15, 0, r4, c2, c0              @ load page table pointer
404         mov     r0, #0x1f                       @ Domains 0, 1 = client
405         mcr     p15, 0, r0, c3, c0              @ load domain access register
406         mrc     p15, 0, r0, c1, c0              @ get control register v4
407 /*
408  * Clear out 'unwanted' bits (then put them in if we need them)
409  */
410         bic     r0, r0, #0x1e00                 @ i...??r.........
411         bic     r0, r0, #0x000e                 @ ............wca.
412 /*
413  * Turn on what we want
414  */
415         orr     r0, r0, #0x0031                 @ ..........DP...M
416         orr     r0, r0, #0x0100                 @ .......S........
417
418 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
419         orr     r0, r0, #0x4000                 @ .R..............
420 #endif
421 #ifndef CONFIG_CPU_BPREDICT_DISABLE
422         orr     r0, r0, #0x0800                 @ ....Z...........
423 #endif
424 #ifndef CONFIG_CPU_DCACHE_DISABLE
425         orr     r0, r0, #0x0004                 @ Enable D cache
426 #endif
427 #ifndef CONFIG_CPU_ICACHE_DISABLE
428         orr     r0, r0, #0x1000                 @ I Cache on
429 #endif
430         mov     pc, lr
431         .size   __arm1020e_setup, . - __arm1020e_setup
432
433         __INITDATA
434
435 /*
436  * Purpose : Function pointers used to access above functions - all calls
437  *           come through these
438  */
439         .type   arm1020e_processor_functions, #object
440 arm1020e_processor_functions:
441         .word   v4t_early_abort
442         .word   cpu_arm1020e_proc_init
443         .word   cpu_arm1020e_proc_fin
444         .word   cpu_arm1020e_reset
445         .word   cpu_arm1020e_do_idle
446         .word   cpu_arm1020e_dcache_clean_area
447         .word   cpu_arm1020e_switch_mm
448         .word   cpu_arm1020e_set_pte
449         .size   arm1020e_processor_functions, . - arm1020e_processor_functions
450
451         .section ".rodata"
452
453         .type   cpu_arch_name, #object
454 cpu_arch_name:
455         .asciz  "armv5te"
456         .size   cpu_arch_name, . - cpu_arch_name
457
458         .type   cpu_elf_name, #object
459 cpu_elf_name:
460         .asciz  "v5"
461         .size   cpu_elf_name, . - cpu_elf_name
462
463         .type   cpu_arm1020e_name, #object
464 cpu_arm1020e_name:
465         .ascii  "ARM1020E"
466 #ifndef CONFIG_CPU_ICACHE_DISABLE
467         .ascii  "i"
468 #endif
469 #ifndef CONFIG_CPU_DCACHE_DISABLE
470         .ascii  "d"
471 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
472         .ascii  "(wt)"
473 #else
474         .ascii  "(wb)"
475 #endif
476 #endif
477 #ifndef CONFIG_CPU_BPREDICT_DISABLE
478         .ascii  "B"
479 #endif
480 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
481         .ascii  "RR"
482 #endif
483         .ascii  "\0"
484         .size   cpu_arm1020e_name, . - cpu_arm1020e_name
485
486         .align
487
488         .section ".proc.info", #alloc, #execinstr
489
490         .type   __arm1020e_proc_info,#object
491 __arm1020e_proc_info:
492         .long   0x4105a200                      @ ARM 1020TE (Architecture v5TE)
493         .long   0xff0ffff0
494         .long   0x00000c12                      @ mmuflags
495         b       __arm1020e_setup
496         .long   cpu_arch_name
497         .long   cpu_elf_name
498         .long   HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
499         .long   cpu_arm1020e_name
500         .long   arm1020e_processor_functions
501         .long   v4wbi_tlb_fns
502         .long   v4wb_user_fns
503         .long   arm1020e_cache_fns
504         .size   __arm1020e_proc_info, . - __arm1020e_proc_info