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