[ARM] nommu: rename compressed/head.S symbols to a new style
[sfrench/cifs-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-hwdef.h>
33 #include <asm/pgtable.h>
34 #include <asm/procinfo.h>
35 #include <asm/hardware.h>
36 #include <asm/page.h>
37 #include <asm/ptrace.h>
38 #include "proc-macros.S"
39
40 /*
41  * The size of one data cache line.
42  */
43 #define CACHE_DLINESIZE 32
44
45 /*
46  * The number of data cache segments.
47  */
48 #define CACHE_DSEGMENTS 4
49
50 /*
51  * The number of lines in a cache segment.
52  */
53 #define CACHE_DENTRIES  64
54
55 /*
56  * This is the size at which it becomes more efficient to
57  * clean the whole cache, rather than using the individual
58  * cache line maintainence instructions.  (I think this should
59  * be 32768).
60  */
61 #define CACHE_DLIMIT    8192
62
63
64         .text
65 /*
66  * cpu_arm922_proc_init()
67  */
68 ENTRY(cpu_arm922_proc_init)
69         mov     pc, lr
70
71 /*
72  * cpu_arm922_proc_fin()
73  */
74 ENTRY(cpu_arm922_proc_fin)
75         stmfd   sp!, {lr}
76         mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
77         msr     cpsr_c, ip
78 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
79         bl      arm922_flush_kern_cache_all
80 #else
81         bl      v4wt_flush_kern_cache_all
82 #endif
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_arm922_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_arm922_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_arm922_do_idle()
112  */
113         .align  5
114 ENTRY(cpu_arm922_do_idle)
115         mcr     p15, 0, r0, c7, c0, 4           @ Wait for interrupt
116         mov     pc, lr
117
118
119 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
120
121 /*
122  *      flush_user_cache_all()
123  *
124  *      Clean and invalidate all cache entries in a particular
125  *      address space.
126  */
127 ENTRY(arm922_flush_user_cache_all)
128         /* FALLTHROUGH */
129
130 /*
131  *      flush_kern_cache_all()
132  *
133  *      Clean and invalidate the entire cache.
134  */
135 ENTRY(arm922_flush_kern_cache_all)
136         mov     r2, #VM_EXEC
137         mov     ip, #0
138 __flush_whole_cache:
139         mov     r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
140 1:      orr     r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
141 2:      mcr     p15, 0, r3, c7, c14, 2          @ clean+invalidate D index
142         subs    r3, r3, #1 << 26
143         bcs     2b                              @ entries 63 to 0
144         subs    r1, r1, #1 << 5
145         bcs     1b                              @ segments 7 to 0
146         tst     r2, #VM_EXEC
147         mcrne   p15, 0, ip, c7, c5, 0           @ invalidate I cache
148         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
149         mov     pc, lr
150
151 /*
152  *      flush_user_cache_range(start, end, flags)
153  *
154  *      Clean and invalidate a range of cache entries in the
155  *      specified address range.
156  *
157  *      - start - start address (inclusive)
158  *      - end   - end address (exclusive)
159  *      - flags - vm_flags describing address space
160  */
161 ENTRY(arm922_flush_user_cache_range)
162         mov     ip, #0
163         sub     r3, r1, r0                      @ calculate total size
164         cmp     r3, #CACHE_DLIMIT
165         bhs     __flush_whole_cache
166
167 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
168         tst     r2, #VM_EXEC
169         mcrne   p15, 0, r0, c7, c5, 1           @ invalidate I entry
170         add     r0, r0, #CACHE_DLINESIZE
171         cmp     r0, r1
172         blo     1b
173         tst     r2, #VM_EXEC
174         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
175         mov     pc, lr
176
177 /*
178  *      coherent_kern_range(start, end)
179  *
180  *      Ensure coherency between the Icache and the Dcache in the
181  *      region described by start, end.  If you have non-snooping
182  *      Harvard caches, you need to implement this function.
183  *
184  *      - start - virtual start address
185  *      - end   - virtual end address
186  */
187 ENTRY(arm922_coherent_kern_range)
188         /* FALLTHROUGH */
189
190 /*
191  *      coherent_user_range(start, end)
192  *
193  *      Ensure coherency between the Icache and the Dcache in the
194  *      region described by start, end.  If you have non-snooping
195  *      Harvard caches, you need to implement this function.
196  *
197  *      - start - virtual start address
198  *      - end   - virtual end address
199  */
200 ENTRY(arm922_coherent_user_range)
201         bic     r0, r0, #CACHE_DLINESIZE - 1
202 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
203         mcr     p15, 0, r0, c7, c5, 1           @ invalidate I entry
204         add     r0, r0, #CACHE_DLINESIZE
205         cmp     r0, r1
206         blo     1b
207         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
208         mov     pc, lr
209
210 /*
211  *      flush_kern_dcache_page(void *page)
212  *
213  *      Ensure no D cache aliasing occurs, either with itself or
214  *      the I cache
215  *
216  *      - addr  - page aligned address
217  */
218 ENTRY(arm922_flush_kern_dcache_page)
219         add     r1, r0, #PAGE_SZ
220 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
221         add     r0, r0, #CACHE_DLINESIZE
222         cmp     r0, r1
223         blo     1b
224         mov     r0, #0
225         mcr     p15, 0, r0, c7, c5, 0           @ invalidate I cache
226         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
227         mov     pc, lr
228
229 /*
230  *      dma_inv_range(start, end)
231  *
232  *      Invalidate (discard) the specified virtual address range.
233  *      May not write back any entries.  If 'start' or 'end'
234  *      are not cache line aligned, those lines must be written
235  *      back.
236  *
237  *      - start - virtual start address
238  *      - end   - virtual end address
239  *
240  * (same as v4wb)
241  */
242 ENTRY(arm922_dma_inv_range)
243         tst     r0, #CACHE_DLINESIZE - 1
244         bic     r0, r0, #CACHE_DLINESIZE - 1
245         mcrne   p15, 0, r0, c7, c10, 1          @ clean D entry
246         tst     r1, #CACHE_DLINESIZE - 1
247         mcrne   p15, 0, r1, c7, c10, 1          @ clean D entry
248 1:      mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
249         add     r0, r0, #CACHE_DLINESIZE
250         cmp     r0, r1
251         blo     1b
252         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
253         mov     pc, lr
254
255 /*
256  *      dma_clean_range(start, end)
257  *
258  *      Clean the specified virtual address range.
259  *
260  *      - start - virtual start address
261  *      - end   - virtual end address
262  *
263  * (same as v4wb)
264  */
265 ENTRY(arm922_dma_clean_range)
266         bic     r0, r0, #CACHE_DLINESIZE - 1
267 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
268         add     r0, r0, #CACHE_DLINESIZE
269         cmp     r0, r1
270         blo     1b
271         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
272         mov     pc, lr
273
274 /*
275  *      dma_flush_range(start, end)
276  *
277  *      Clean and invalidate the specified virtual address range.
278  *
279  *      - start - virtual start address
280  *      - end   - virtual end address
281  */
282 ENTRY(arm922_dma_flush_range)
283         bic     r0, r0, #CACHE_DLINESIZE - 1
284 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
285         add     r0, r0, #CACHE_DLINESIZE
286         cmp     r0, r1
287         blo     1b
288         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
289         mov     pc, lr
290
291 ENTRY(arm922_cache_fns)
292         .long   arm922_flush_kern_cache_all
293         .long   arm922_flush_user_cache_all
294         .long   arm922_flush_user_cache_range
295         .long   arm922_coherent_kern_range
296         .long   arm922_coherent_user_range
297         .long   arm922_flush_kern_dcache_page
298         .long   arm922_dma_inv_range
299         .long   arm922_dma_clean_range
300         .long   arm922_dma_flush_range
301
302 #endif
303
304
305 ENTRY(cpu_arm922_dcache_clean_area)
306 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
307 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
308         add     r0, r0, #CACHE_DLINESIZE
309         subs    r1, r1, #CACHE_DLINESIZE
310         bhi     1b
311 #endif
312         mov     pc, lr
313
314 /* =============================== PageTable ============================== */
315
316 /*
317  * cpu_arm922_switch_mm(pgd)
318  *
319  * Set the translation base pointer to be as described by pgd.
320  *
321  * pgd: new page tables
322  */
323         .align  5
324 ENTRY(cpu_arm922_switch_mm)
325         mov     ip, #0
326 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
327         mcr     p15, 0, ip, c7, c6, 0           @ invalidate D cache
328 #else
329 @ && 'Clean & Invalidate whole DCache'
330 @ && Re-written to use Index Ops.
331 @ && Uses registers r1, r3 and ip
332
333         mov     r1, #(CACHE_DSEGMENTS - 1) << 5 @ 4 segments
334 1:      orr     r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
335 2:      mcr     p15, 0, r3, c7, c14, 2          @ clean & invalidate D index
336         subs    r3, r3, #1 << 26
337         bcs     2b                              @ entries 63 to 0
338         subs    r1, r1, #1 << 5
339         bcs     1b                              @ segments 7 to 0
340 #endif
341         mcr     p15, 0, ip, c7, c5, 0           @ invalidate I cache
342         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
343         mcr     p15, 0, r0, c2, c0, 0           @ load page table pointer
344         mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
345         mov     pc, lr
346
347 /*
348  * cpu_arm922_set_pte(ptep, pte)
349  *
350  * Set a PTE and flush it out
351  */
352         .align  5
353 ENTRY(cpu_arm922_set_pte)
354         str     r1, [r0], #-2048                @ linux version
355
356         eor     r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
357
358         bic     r2, r1, #PTE_SMALL_AP_MASK
359         bic     r2, r2, #PTE_TYPE_MASK
360         orr     r2, r2, #PTE_TYPE_SMALL
361
362         tst     r1, #L_PTE_USER                 @ User?
363         orrne   r2, r2, #PTE_SMALL_AP_URO_SRW
364
365         tst     r1, #L_PTE_WRITE | L_PTE_DIRTY  @ Write and Dirty?
366         orreq   r2, r2, #PTE_SMALL_AP_UNO_SRW
367
368         tst     r1, #L_PTE_PRESENT | L_PTE_YOUNG        @ Present and Young?
369         movne   r2, #0
370
371 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
372         eor     r3, r2, #0x0a                   @ C & small page?
373         tst     r3, #0x0b
374         biceq   r2, r2, #4
375 #endif
376         str     r2, [r0]                        @ hardware version
377         mov     r0, r0
378         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
379         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
380         mov     pc, lr
381
382         __INIT
383
384         .type   __arm922_setup, #function
385 __arm922_setup:
386         mov     r0, #0
387         mcr     p15, 0, r0, c7, c7              @ invalidate I,D caches on v4
388         mcr     p15, 0, r0, c7, c10, 4          @ drain write buffer on v4
389         mcr     p15, 0, r0, c8, c7              @ invalidate I,D TLBs on v4
390         mrc     p15, 0, r0, c1, c0              @ get control register v4
391         ldr     r5, arm922_cr1_clear
392         bic     r0, r0, r5
393         ldr     r5, arm922_cr1_set
394         orr     r0, r0, r5
395         mov     pc, lr
396         .size   __arm922_setup, . - __arm922_setup
397
398         /*
399          *  R
400          * .RVI ZFRS BLDP WCAM
401          * ..11 0001 ..11 0101
402          * 
403          */
404         .type   arm922_cr1_clear, #object
405         .type   arm922_cr1_set, #object
406 arm922_cr1_clear:
407         .word   0x3f3f
408 arm922_cr1_set:
409         .word   0x3135
410
411         __INITDATA
412
413 /*
414  * Purpose : Function pointers used to access above functions - all calls
415  *           come through these
416  */
417         .type   arm922_processor_functions, #object
418 arm922_processor_functions:
419         .word   v4t_early_abort
420         .word   cpu_arm922_proc_init
421         .word   cpu_arm922_proc_fin
422         .word   cpu_arm922_reset
423         .word   cpu_arm922_do_idle
424         .word   cpu_arm922_dcache_clean_area
425         .word   cpu_arm922_switch_mm
426         .word   cpu_arm922_set_pte
427         .size   arm922_processor_functions, . - arm922_processor_functions
428
429         .section ".rodata"
430
431         .type   cpu_arch_name, #object
432 cpu_arch_name:
433         .asciz  "armv4t"
434         .size   cpu_arch_name, . - cpu_arch_name
435
436         .type   cpu_elf_name, #object
437 cpu_elf_name:
438         .asciz  "v4"
439         .size   cpu_elf_name, . - cpu_elf_name
440
441         .type   cpu_arm922_name, #object
442 cpu_arm922_name:
443         .ascii  "ARM922T"
444 #ifndef CONFIG_CPU_ICACHE_DISABLE
445         .ascii  "i"
446 #endif
447 #ifndef CONFIG_CPU_DCACHE_DISABLE
448         .ascii  "d"
449 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
450         .ascii  "(wt)"
451 #else
452         .ascii  "(wb)"
453 #endif
454 #endif
455         .ascii  "\0"
456         .size   cpu_arm922_name, . - cpu_arm922_name
457
458         .align
459
460         .section ".proc.info.init", #alloc, #execinstr
461
462         .type   __arm922_proc_info,#object
463 __arm922_proc_info:
464         .long   0x41009220
465         .long   0xff00fff0
466         .long   PMD_TYPE_SECT | \
467                 PMD_SECT_BUFFERABLE | \
468                 PMD_SECT_CACHEABLE | \
469                 PMD_BIT4 | \
470                 PMD_SECT_AP_WRITE | \
471                 PMD_SECT_AP_READ
472         b       __arm922_setup
473         .long   cpu_arch_name
474         .long   cpu_elf_name
475         .long   HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
476         .long   cpu_arm922_name
477         .long   arm922_processor_functions
478         .long   v4wbi_tlb_fns
479         .long   v4wb_user_fns
480 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
481         .long   arm922_cache_fns
482 #else
483         .long   v4wt_cache_fns
484 #endif
485         .size   __arm922_proc_info, . - __arm922_proc_info