Merge commit 'takashi/topic/asoc' into for-2.6.31
[linux-2.6] / arch / arm / mm / proc-v7.S
1 /*
2  *  linux/arch/arm/mm/proc-v7.S
3  *
4  *  Copyright (C) 2001 Deep Blue Solutions Ltd.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  *  This is the "shell" of the ARMv7 processor support.
11  */
12 #include <linux/init.h>
13 #include <linux/linkage.h>
14 #include <asm/assembler.h>
15 #include <asm/asm-offsets.h>
16 #include <asm/hwcap.h>
17 #include <asm/pgtable-hwdef.h>
18 #include <asm/pgtable.h>
19
20 #include "proc-macros.S"
21
22 #define TTB_C           (1 << 0)
23 #define TTB_S           (1 << 1)
24 #define TTB_RGN_NC      (0 << 3)
25 #define TTB_RGN_OC_WBWA (1 << 3)
26 #define TTB_RGN_OC_WT   (2 << 3)
27 #define TTB_RGN_OC_WB   (3 << 3)
28
29 #ifndef CONFIG_SMP
30 #define TTB_FLAGS       TTB_C|TTB_RGN_OC_WB             @ mark PTWs cacheable, outer WB
31 #else
32 #define TTB_FLAGS       TTB_C|TTB_S|TTB_RGN_OC_WBWA     @ mark PTWs cacheable and shared, outer WBWA
33 #endif
34
35 ENTRY(cpu_v7_proc_init)
36         mov     pc, lr
37 ENDPROC(cpu_v7_proc_init)
38
39 ENTRY(cpu_v7_proc_fin)
40         mov     pc, lr
41 ENDPROC(cpu_v7_proc_fin)
42
43 /*
44  *      cpu_v7_reset(loc)
45  *
46  *      Perform a soft reset of the system.  Put the CPU into the
47  *      same state as it would be if it had been reset, and branch
48  *      to what would be the reset vector.
49  *
50  *      - loc   - location to jump to for soft reset
51  *
52  *      It is assumed that:
53  */
54         .align  5
55 ENTRY(cpu_v7_reset)
56         mov     pc, r0
57 ENDPROC(cpu_v7_reset)
58
59 /*
60  *      cpu_v7_do_idle()
61  *
62  *      Idle the processor (eg, wait for interrupt).
63  *
64  *      IRQs are already disabled.
65  */
66 ENTRY(cpu_v7_do_idle)
67         dsb                                     @ WFI may enter a low-power mode
68         wfi
69         mov     pc, lr
70 ENDPROC(cpu_v7_do_idle)
71
72 ENTRY(cpu_v7_dcache_clean_area)
73 #ifndef TLB_CAN_READ_FROM_L1_CACHE
74         dcache_line_size r2, r3
75 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
76         add     r0, r0, r2
77         subs    r1, r1, r2
78         bhi     1b
79         dsb
80 #endif
81         mov     pc, lr
82 ENDPROC(cpu_v7_dcache_clean_area)
83
84 /*
85  *      cpu_v7_switch_mm(pgd_phys, tsk)
86  *
87  *      Set the translation table base pointer to be pgd_phys
88  *
89  *      - pgd_phys - physical address of new TTB
90  *
91  *      It is assumed that:
92  *      - we are not using split page tables
93  */
94 ENTRY(cpu_v7_switch_mm)
95 #ifdef CONFIG_MMU
96         mov     r2, #0
97         ldr     r1, [r1, #MM_CONTEXT_ID]        @ get mm->context.id
98         orr     r0, r0, #TTB_FLAGS
99         mcr     p15, 0, r2, c13, c0, 1          @ set reserved context ID
100         isb
101 1:      mcr     p15, 0, r0, c2, c0, 0           @ set TTB 0
102         isb
103         mcr     p15, 0, r1, c13, c0, 1          @ set context ID
104         isb
105 #endif
106         mov     pc, lr
107 ENDPROC(cpu_v7_switch_mm)
108
109 /*
110  *      cpu_v7_set_pte_ext(ptep, pte)
111  *
112  *      Set a level 2 translation table entry.
113  *
114  *      - ptep  - pointer to level 2 translation table entry
115  *                (hardware version is stored at -1024 bytes)
116  *      - pte   - PTE value to store
117  *      - ext   - value for extended PTE bits
118  */
119 ENTRY(cpu_v7_set_pte_ext)
120 #ifdef CONFIG_MMU
121         str     r1, [r0], #-2048                @ linux version
122
123         bic     r3, r1, #0x000003f0
124         bic     r3, r3, #PTE_TYPE_MASK
125         orr     r3, r3, r2
126         orr     r3, r3, #PTE_EXT_AP0 | 2
127
128         tst     r1, #1 << 4
129         orrne   r3, r3, #PTE_EXT_TEX(1)
130
131         tst     r1, #L_PTE_WRITE
132         tstne   r1, #L_PTE_DIRTY
133         orreq   r3, r3, #PTE_EXT_APX
134
135         tst     r1, #L_PTE_USER
136         orrne   r3, r3, #PTE_EXT_AP1
137         tstne   r3, #PTE_EXT_APX
138         bicne   r3, r3, #PTE_EXT_APX | PTE_EXT_AP0
139
140         tst     r1, #L_PTE_EXEC
141         orreq   r3, r3, #PTE_EXT_XN
142
143         tst     r1, #L_PTE_YOUNG
144         tstne   r1, #L_PTE_PRESENT
145         moveq   r3, #0
146
147         str     r3, [r0]
148         mcr     p15, 0, r0, c7, c10, 1          @ flush_pte
149 #endif
150         mov     pc, lr
151 ENDPROC(cpu_v7_set_pte_ext)
152
153 cpu_v7_name:
154         .ascii  "ARMv7 Processor"
155         .align
156
157         __INIT
158
159 /*
160  *      __v7_setup
161  *
162  *      Initialise TLB, Caches, and MMU state ready to switch the MMU
163  *      on.  Return in r0 the new CP15 C1 control register setting.
164  *
165  *      We automatically detect if we have a Harvard cache, and use the
166  *      Harvard cache control instructions insead of the unified cache
167  *      control instructions.
168  *
169  *      This should be able to cover all ARMv7 cores.
170  *
171  *      It is assumed that:
172  *      - cache type register is implemented
173  */
174 __v7_setup:
175 #ifdef CONFIG_SMP
176         mrc     p15, 0, r0, c1, c0, 1           @ Enable SMP/nAMP mode
177         orr     r0, r0, #(0x1 << 6)
178         mcr     p15, 0, r0, c1, c0, 1
179 #endif
180         adr     r12, __v7_setup_stack           @ the local stack
181         stmia   r12, {r0-r5, r7, r9, r11, lr}
182         bl      v7_flush_dcache_all
183         ldmia   r12, {r0-r5, r7, r9, r11, lr}
184         mov     r10, #0
185 #ifdef HARVARD_CACHE
186         mcr     p15, 0, r10, c7, c5, 0          @ I+BTB cache invalidate
187 #endif
188         dsb
189 #ifdef CONFIG_MMU
190         mcr     p15, 0, r10, c8, c7, 0          @ invalidate I + D TLBs
191         mcr     p15, 0, r10, c2, c0, 2          @ TTB control register
192         orr     r4, r4, #TTB_FLAGS
193         mcr     p15, 0, r4, c2, c0, 1           @ load TTB1
194         mov     r10, #0x1f                      @ domains 0, 1 = manager
195         mcr     p15, 0, r10, c3, c0, 0          @ load domain access register
196 #endif
197         ldr     r5, =0xff0aa1a8
198         ldr     r6, =0x40e040e0
199         mcr     p15, 0, r5, c10, c2, 0          @ write PRRR
200         mcr     p15, 0, r6, c10, c2, 1          @ write NMRR
201         adr     r5, v7_crval
202         ldmia   r5, {r5, r6}
203         mrc     p15, 0, r0, c1, c0, 0           @ read control register
204         bic     r0, r0, r5                      @ clear bits them
205         orr     r0, r0, r6                      @ set them
206         mov     pc, lr                          @ return to head.S:__ret
207 ENDPROC(__v7_setup)
208
209         /*   AT
210          *  TFR   EV X F   I D LR
211          * .EEE ..EE PUI. .T.T 4RVI ZFRS BLDP WCAM
212          * rxxx rrxx xxx0 0101 xxxx xxxx x111 xxxx < forced
213          *    1    0 110       0011 1.00 .111 1101 < we want
214          */
215         .type   v7_crval, #object
216 v7_crval:
217         crval   clear=0x0120c302, mmuset=0x10c0387d, ucset=0x00c0187c
218
219 __v7_setup_stack:
220         .space  4 * 11                          @ 11 registers
221
222         .type   v7_processor_functions, #object
223 ENTRY(v7_processor_functions)
224         .word   v7_early_abort
225         .word   pabort_ifar
226         .word   cpu_v7_proc_init
227         .word   cpu_v7_proc_fin
228         .word   cpu_v7_reset
229         .word   cpu_v7_do_idle
230         .word   cpu_v7_dcache_clean_area
231         .word   cpu_v7_switch_mm
232         .word   cpu_v7_set_pte_ext
233         .size   v7_processor_functions, . - v7_processor_functions
234
235         .type   cpu_arch_name, #object
236 cpu_arch_name:
237         .asciz  "armv7"
238         .size   cpu_arch_name, . - cpu_arch_name
239
240         .type   cpu_elf_name, #object
241 cpu_elf_name:
242         .asciz  "v7"
243         .size   cpu_elf_name, . - cpu_elf_name
244         .align
245
246         .section ".proc.info.init", #alloc, #execinstr
247
248         /*
249          * Match any ARMv7 processor core.
250          */
251         .type   __v7_proc_info, #object
252 __v7_proc_info:
253         .long   0x000f0000              @ Required ID value
254         .long   0x000f0000              @ Mask for ID
255         .long   PMD_TYPE_SECT | \
256                 PMD_SECT_BUFFERABLE | \
257                 PMD_SECT_CACHEABLE | \
258                 PMD_SECT_AP_WRITE | \
259                 PMD_SECT_AP_READ
260         .long   PMD_TYPE_SECT | \
261                 PMD_SECT_XN | \
262                 PMD_SECT_AP_WRITE | \
263                 PMD_SECT_AP_READ
264         b       __v7_setup
265         .long   cpu_arch_name
266         .long   cpu_elf_name
267         .long   HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
268         .long   cpu_v7_name
269         .long   v7_processor_functions
270         .long   v7wbi_tlb_fns
271         .long   v6_user_fns
272         .long   v7_cache_fns
273         .size   __v7_proc_info, . - __v7_proc_info