[ARM] 3399/1: Fix link problem when CONFIG_PRINTK is disabled
[pandora-kernel.git] / arch / arm / mm / proc-arm925.S
1 /*
2  *  linux/arch/arm/mm/arm925.S: MMU functions for ARM925
3  *
4  *  Copyright (C) 1999,2000 ARM Limited
5  *  Copyright (C) 2000 Deep Blue Solutions Ltd.
6  *  Copyright (C) 2002 RidgeRun, Inc.
7  *  Copyright (C) 2002-2003 MontaVista Software, Inc.
8  *
9  *  Update for Linux-2.6 and cache flush improvements
10  *  Copyright (C) 2004 Nokia Corporation by Tony Lindgren <tony@atomide.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25  *
26  *
27  * These are the low level assembler for performing cache and TLB
28  * functions on the arm925.
29  *
30  *  CONFIG_CPU_ARM925_CPU_IDLE -> nohlt
31  *
32  * Some additional notes based on deciphering the TI TRM on OMAP-5910:
33  *
34  * NOTE1: The TI925T Configuration Register bit "D-cache clean and flush
35  *        entry mode" must be 0 to flush the entries in both segments
36  *        at once. This is the default value. See TRM 2-20 and 2-24 for
37  *        more information.
38  *
39  * NOTE2: Default is the "D-cache clean and flush entry mode". It looks
40  *        like the "Transparent mode" must be on for partial cache flushes
41  *        to work in this mode. This mode only works with 16-bit external
42  *        memory. See TRM 2-24 for more information.
43  *
44  * NOTE3: Write-back cache flushing seems to be flakey with devices using
45  *        direct memory access, such as USB OHCI. The workaround is to use
46  *        write-through cache with CONFIG_CPU_DCACHE_WRITETHROUGH (this is
47  *        the default for OMAP-1510).
48  */
49
50 #include <linux/linkage.h>
51 #include <linux/config.h>
52 #include <linux/init.h>
53 #include <asm/assembler.h>
54 #include <asm/pgtable.h>
55 #include <asm/procinfo.h>
56 #include <asm/page.h>
57 #include <asm/ptrace.h>
58 #include "proc-macros.S"
59
60 /*
61  * The size of one data cache line.
62  */
63 #define CACHE_DLINESIZE 16
64
65 /*
66  * The number of data cache segments.
67  */
68 #define CACHE_DSEGMENTS 2
69
70 /*
71  * The number of lines in a cache segment.
72  */
73 #define CACHE_DENTRIES  256
74
75 /*
76  * This is the size at which it becomes more efficient to
77  * clean the whole cache, rather than using the individual
78  * cache line maintainence instructions.
79  */
80 #define CACHE_DLIMIT    8192
81
82         .text
83 /*
84  * cpu_arm925_proc_init()
85  */
86 ENTRY(cpu_arm925_proc_init)
87         mov     pc, lr
88
89 /*
90  * cpu_arm925_proc_fin()
91  */
92 ENTRY(cpu_arm925_proc_fin)
93         stmfd   sp!, {lr}
94         mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
95         msr     cpsr_c, ip
96         bl      arm925_flush_kern_cache_all
97         mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
98         bic     r0, r0, #0x1000                 @ ...i............
99         bic     r0, r0, #0x000e                 @ ............wca.
100         mcr     p15, 0, r0, c1, c0, 0           @ disable caches
101         ldmfd   sp!, {pc}
102
103 /*
104  * cpu_arm925_reset(loc)
105  *
106  * Perform a soft reset of the system.  Put the CPU into the
107  * same state as it would be if it had been reset, and branch
108  * to what would be the reset vector.
109  *
110  * loc: location to jump to for soft reset
111  */
112         .align  5
113 ENTRY(cpu_arm925_reset)
114         /* Send software reset to MPU and DSP */
115         mov     ip, #0xff000000
116         orr     ip, ip, #0x00fe0000
117         orr     ip, ip, #0x0000ce00
118         mov     r4, #1
119         strh    r4, [ip, #0x10]
120
121         mov     ip, #0
122         mcr     p15, 0, ip, c7, c7, 0           @ invalidate I,D caches
123         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
124         mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
125         mrc     p15, 0, ip, c1, c0, 0           @ ctrl register
126         bic     ip, ip, #0x000f                 @ ............wcam
127         bic     ip, ip, #0x1100                 @ ...i...s........
128         mcr     p15, 0, ip, c1, c0, 0           @ ctrl register
129         mov     pc, r0
130
131 /*
132  * cpu_arm925_do_idle()
133  *
134  * Called with IRQs disabled
135  */
136         .align  10
137 ENTRY(cpu_arm925_do_idle)
138         mov     r0, #0
139         mrc     p15, 0, r1, c1, c0, 0           @ Read control register
140         mcr     p15, 0, r0, c7, c10, 4          @ Drain write buffer
141         bic     r2, r1, #1 << 12
142         mcr     p15, 0, r2, c1, c0, 0           @ Disable I cache
143         mcr     p15, 0, r0, c7, c0, 4           @ Wait for interrupt
144         mcr     p15, 0, r1, c1, c0, 0           @ Restore ICache enable
145         mov     pc, lr
146
147 /*
148  *      flush_user_cache_all()
149  *
150  *      Clean and invalidate all cache entries in a particular
151  *      address space.
152  */
153 ENTRY(arm925_flush_user_cache_all)
154         /* FALLTHROUGH */
155
156 /*
157  *      flush_kern_cache_all()
158  *
159  *      Clean and invalidate the entire cache.
160  */
161 ENTRY(arm925_flush_kern_cache_all)
162         mov     r2, #VM_EXEC
163         mov     ip, #0
164 __flush_whole_cache:
165 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
166         mcr     p15, 0, ip, c7, c6, 0           @ invalidate D cache
167 #else
168         /* Flush entries in both segments at once, see NOTE1 above */
169         mov     r3, #(CACHE_DENTRIES - 1) << 4  @ 256 entries in segment
170 2:      mcr     p15, 0, r3, c7, c14, 2          @ clean+invalidate D index
171         subs    r3, r3, #1 << 4
172         bcs     2b                              @ entries 255 to 0
173 #endif
174         tst     r2, #VM_EXEC
175         mcrne   p15, 0, ip, c7, c5, 0           @ invalidate I cache
176         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
177         mov     pc, lr
178
179 /*
180  *      flush_user_cache_range(start, end, flags)
181  *
182  *      Clean and invalidate a range of cache entries in the
183  *      specified address range.
184  *
185  *      - start - start address (inclusive)
186  *      - end   - end address (exclusive)
187  *      - flags - vm_flags describing address space
188  */
189 ENTRY(arm925_flush_user_cache_range)
190         mov     ip, #0
191         sub     r3, r1, r0                      @ calculate total size
192         cmp     r3, #CACHE_DLIMIT
193         bgt     __flush_whole_cache
194 1:      tst     r2, #VM_EXEC
195 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
196         mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
197         mcrne   p15, 0, r0, c7, c5, 1           @ invalidate I entry
198         add     r0, r0, #CACHE_DLINESIZE
199         mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
200         mcrne   p15, 0, r0, c7, c5, 1           @ invalidate I entry
201         add     r0, r0, #CACHE_DLINESIZE
202 #else
203         mcr     p15, 0, r0, c7, c14, 1          @ clean and invalidate D entry
204         mcrne   p15, 0, r0, c7, c5, 1           @ invalidate I entry
205         add     r0, r0, #CACHE_DLINESIZE
206         mcr     p15, 0, r0, c7, c14, 1          @ clean and invalidate D entry
207         mcrne   p15, 0, r0, c7, c5, 1           @ invalidate I entry
208         add     r0, r0, #CACHE_DLINESIZE
209 #endif
210         cmp     r0, r1
211         blo     1b
212         tst     r2, #VM_EXEC
213         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
214         mov     pc, lr
215
216 /*
217  *      coherent_kern_range(start, end)
218  *
219  *      Ensure coherency between the Icache and the Dcache in the
220  *      region described by start, end.  If you have non-snooping
221  *      Harvard caches, you need to implement this function.
222  *
223  *      - start - virtual start address
224  *      - end   - virtual end address
225  */
226 ENTRY(arm925_coherent_kern_range)
227         /* FALLTHROUGH */
228
229 /*
230  *      coherent_user_range(start, end)
231  *
232  *      Ensure coherency between the Icache and the Dcache in the
233  *      region described by start, end.  If you have non-snooping
234  *      Harvard caches, you need to implement this function.
235  *
236  *      - start - virtual start address
237  *      - end   - virtual end address
238  */
239 ENTRY(arm925_coherent_user_range)
240         bic     r0, r0, #CACHE_DLINESIZE - 1
241 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
242         mcr     p15, 0, r0, c7, c5, 1           @ invalidate I entry
243         add     r0, r0, #CACHE_DLINESIZE
244         cmp     r0, r1
245         blo     1b
246         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
247         mov     pc, lr
248
249 /*
250  *      flush_kern_dcache_page(void *page)
251  *
252  *      Ensure no D cache aliasing occurs, either with itself or
253  *      the I cache
254  *
255  *      - addr  - page aligned address
256  */
257 ENTRY(arm925_flush_kern_dcache_page)
258         add     r1, r0, #PAGE_SZ
259 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
260         add     r0, r0, #CACHE_DLINESIZE
261         cmp     r0, r1
262         blo     1b
263         mov     r0, #0
264         mcr     p15, 0, r0, c7, c5, 0           @ invalidate I cache
265         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
266         mov     pc, lr
267
268 /*
269  *      dma_inv_range(start, end)
270  *
271  *      Invalidate (discard) the specified virtual address range.
272  *      May not write back any entries.  If 'start' or 'end'
273  *      are not cache line aligned, those lines must be written
274  *      back.
275  *
276  *      - start - virtual start address
277  *      - end   - virtual end address
278  *
279  * (same as v4wb)
280  */
281 ENTRY(arm925_dma_inv_range)
282 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
283         tst     r0, #CACHE_DLINESIZE - 1
284         mcrne   p15, 0, r0, c7, c10, 1          @ clean D entry
285         tst     r1, #CACHE_DLINESIZE - 1
286         mcrne   p15, 0, r1, c7, c10, 1          @ clean D entry
287 #endif
288         bic     r0, r0, #CACHE_DLINESIZE - 1
289 1:      mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
290         add     r0, r0, #CACHE_DLINESIZE
291         cmp     r0, r1
292         blo     1b
293         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
294         mov     pc, lr
295
296 /*
297  *      dma_clean_range(start, end)
298  *
299  *      Clean the specified virtual address range.
300  *
301  *      - start - virtual start address
302  *      - end   - virtual end address
303  *
304  * (same as v4wb)
305  */
306 ENTRY(arm925_dma_clean_range)
307 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
308         bic     r0, r0, #CACHE_DLINESIZE - 1
309 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
310         add     r0, r0, #CACHE_DLINESIZE
311         cmp     r0, r1
312         blo     1b
313 #endif
314         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
315         mov     pc, lr
316
317 /*
318  *      dma_flush_range(start, end)
319  *
320  *      Clean and invalidate the specified virtual address range.
321  *
322  *      - start - virtual start address
323  *      - end   - virtual end address
324  */
325 ENTRY(arm925_dma_flush_range)
326         bic     r0, r0, #CACHE_DLINESIZE - 1
327 1:
328 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
329         mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
330 #else
331         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
332 #endif
333         add     r0, r0, #CACHE_DLINESIZE
334         cmp     r0, r1
335         blo     1b
336         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
337         mov     pc, lr
338
339 ENTRY(arm925_cache_fns)
340         .long   arm925_flush_kern_cache_all
341         .long   arm925_flush_user_cache_all
342         .long   arm925_flush_user_cache_range
343         .long   arm925_coherent_kern_range
344         .long   arm925_coherent_user_range
345         .long   arm925_flush_kern_dcache_page
346         .long   arm925_dma_inv_range
347         .long   arm925_dma_clean_range
348         .long   arm925_dma_flush_range
349
350 ENTRY(cpu_arm925_dcache_clean_area)
351 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
352 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
353         add     r0, r0, #CACHE_DLINESIZE
354         subs    r1, r1, #CACHE_DLINESIZE
355         bhi     1b
356 #endif
357         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
358         mov     pc, lr
359
360 /* =============================== PageTable ============================== */
361
362 /*
363  * cpu_arm925_switch_mm(pgd)
364  *
365  * Set the translation base pointer to be as described by pgd.
366  *
367  * pgd: new page tables
368  */
369         .align  5
370 ENTRY(cpu_arm925_switch_mm)
371         mov     ip, #0
372 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
373         mcr     p15, 0, ip, c7, c6, 0           @ invalidate D cache
374 #else
375         /* Flush entries in bothe segments at once, see NOTE1 above */
376         mov     r3, #(CACHE_DENTRIES - 1) << 4  @ 256 entries in segment
377 2:      mcr     p15, 0, r3, c7, c14, 2          @ clean & invalidate D index
378         subs    r3, r3, #1 << 4
379         bcs     2b                              @ entries 255 to 0
380 #endif
381         mcr     p15, 0, ip, c7, c5, 0           @ invalidate I cache
382         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
383         mcr     p15, 0, r0, c2, c0, 0           @ load page table pointer
384         mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
385         mov     pc, lr
386
387 /*
388  * cpu_arm925_set_pte(ptep, pte)
389  *
390  * Set a PTE and flush it out
391  */
392         .align  5
393 ENTRY(cpu_arm925_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, r2, #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_WRITETHROUGH
419         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
420 #endif
421         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
422         mov     pc, lr
423
424         __INIT
425
426         .type   __arm925_setup, #function
427 __arm925_setup:
428         mov     r0, #0
429 #if defined(CONFIG_CPU_ICACHE_STREAMING_DISABLE)
430         orr     r0,r0,#1 << 7
431 #endif
432
433         /* Transparent on, D-cache clean & flush mode. See  NOTE2 above */
434         orr     r0,r0,#1 << 1                   @ transparent mode on
435         mcr     p15, 0, r0, c15, c1, 0          @ write TI config register
436
437         mov     r0, #0
438         mcr     p15, 0, r0, c7, c7              @ invalidate I,D caches on v4
439         mcr     p15, 0, r0, c7, c10, 4          @ drain write buffer on v4
440         mcr     p15, 0, r0, c8, c7              @ invalidate I,D TLBs on v4
441
442 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
443         mov     r0, #4                          @ disable write-back on caches explicitly
444         mcr     p15, 7, r0, c15, c0, 0
445 #endif
446
447         mrc     p15, 0, r0, c1, c0              @ get control register v4
448         ldr     r5, arm925_cr1_clear
449         bic     r0, r0, r5
450         ldr     r5, arm925_cr1_set
451         orr     r0, r0, r5
452 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
453         orr     r0, r0, #0x4000                 @ .1.. .... .... ....
454 #endif
455         mov     pc, lr
456         .size   __arm925_setup, . - __arm925_setup
457
458         /*
459          *  R
460          * .RVI ZFRS BLDP WCAM
461          * .011 0001 ..11 1101
462          * 
463          */
464         .type   arm925_cr1_clear, #object
465         .type   arm925_cr1_set, #object
466 arm925_cr1_clear:
467         .word   0x7f3f
468 arm925_cr1_set:
469         .word   0x313d
470
471         __INITDATA
472
473 /*
474  * Purpose : Function pointers used to access above functions - all calls
475  *           come through these
476  */
477         .type   arm925_processor_functions, #object
478 arm925_processor_functions:
479         .word   v4t_early_abort
480         .word   cpu_arm925_proc_init
481         .word   cpu_arm925_proc_fin
482         .word   cpu_arm925_reset
483         .word   cpu_arm925_do_idle
484         .word   cpu_arm925_dcache_clean_area
485         .word   cpu_arm925_switch_mm
486         .word   cpu_arm925_set_pte
487         .size   arm925_processor_functions, . - arm925_processor_functions
488
489         .section ".rodata"
490
491         .type   cpu_arch_name, #object
492 cpu_arch_name:
493         .asciz  "armv4t"
494         .size   cpu_arch_name, . - cpu_arch_name
495
496         .type   cpu_elf_name, #object
497 cpu_elf_name:
498         .asciz  "v4"
499         .size   cpu_elf_name, . - cpu_elf_name
500
501         .type   cpu_arm925_name, #object
502 cpu_arm925_name:
503         .ascii  "ARM925T"
504 #ifndef CONFIG_CPU_ICACHE_DISABLE
505         .ascii  "i"
506 #endif
507 #ifndef CONFIG_CPU_DCACHE_DISABLE
508         .ascii  "d"
509 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
510         .ascii  "(wt)"
511 #else
512         .ascii  "(wb)"
513 #endif
514 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
515         .ascii  "RR"
516 #endif
517 #endif
518         .ascii  "\0"
519         .size   cpu_arm925_name, . - cpu_arm925_name
520
521         .align
522
523         .section ".proc.info.init", #alloc, #execinstr
524
525         .type   __arm925_proc_info,#object
526 __arm925_proc_info:
527         .long   0x54029250
528         .long   0xfffffff0
529         .long   PMD_TYPE_SECT | \
530                 PMD_BIT4 | \
531                 PMD_SECT_AP_WRITE | \
532                 PMD_SECT_AP_READ
533         b       __arm925_setup
534         .long   cpu_arch_name
535         .long   cpu_elf_name
536         .long   HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
537         .long   cpu_arm925_name
538         .long   arm925_processor_functions
539         .long   v4wbi_tlb_fns
540         .long   v4wb_user_fns
541         .long   arm925_cache_fns
542         .size   __arm925_proc_info, . - __arm925_proc_info
543
544         .type   __arm915_proc_info,#object
545 __arm915_proc_info:
546         .long   0x54029150
547         .long   0xfffffff0
548         .long   PMD_TYPE_SECT | \
549                 PMD_BIT4 | \
550                 PMD_SECT_AP_WRITE | \
551                 PMD_SECT_AP_READ
552         b       __arm925_setup
553         .long   cpu_arch_name
554         .long   cpu_elf_name
555         .long   HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
556         .long   cpu_arm925_name
557         .long   arm925_processor_functions
558         .long   v4wbi_tlb_fns
559         .long   v4wb_user_fns
560         .long   arm925_cache_fns
561         .size   __arm925_proc_info, . - __arm925_proc_info