# BRCM_VERSION=3
[bcm963xx.git] / kernel / linux / arch / arm / mm / proc-sa110.S
1 /*
2  *  linux/arch/arm/mm/proc-sa110.S
3  *
4  *  Copyright (C) 1997-2002 Russell King
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  *  MMU functions for SA110
11  *
12  *  These are the low level assembler for performing cache and TLB
13  *  functions on the StrongARM-110.
14  */
15 #include <linux/linkage.h>
16 #include <linux/init.h>
17 #include <asm/assembler.h>
18 #include <asm/constants.h>
19 #include <asm/procinfo.h>
20 #include <asm/hardware.h>
21 #include <asm/pgtable.h>
22 #include <asm/ptrace.h>
23
24 /*
25  * the cache line size of the I and D cache
26  */
27 #define DCACHELINESIZE  32
28 #define FLUSH_OFFSET    32768
29
30         .macro flush_110_dcache rd, ra, re
31         ldr     \rd, =flush_base
32         ldr     \ra, [\rd]
33         eor     \ra, \ra, #FLUSH_OFFSET
34         str     \ra, [\rd]
35         add     \re, \ra, #16384                @ only necessary for 16k
36 1001:   ldr     \rd, [\ra], #DCACHELINESIZE
37         teq     \re, \ra
38         bne     1001b
39         .endm
40
41         .data
42 flush_base:
43         .long   FLUSH_BASE
44         .text
45
46 /*
47  * cpu_sa110_proc_init()
48  */
49 ENTRY(cpu_sa110_proc_init)
50         mov     r0, #0
51         mcr     p15, 0, r0, c15, c1, 2          @ Enable clock switching
52         mov     pc, lr
53
54 /*
55  * cpu_sa110_proc_fin()
56  */
57 ENTRY(cpu_sa110_proc_fin)
58         stmfd   sp!, {lr}
59         mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
60         msr     cpsr_c, ip
61         bl      v4wb_flush_kern_cache_all       @ clean caches
62 1:      mov     r0, #0
63         mcr     p15, 0, r0, c15, c2, 2          @ Disable clock switching
64         mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
65         bic     r0, r0, #0x1000                 @ ...i............
66         bic     r0, r0, #0x000e                 @ ............wca.
67         mcr     p15, 0, r0, c1, c0, 0           @ disable caches
68         ldmfd   sp!, {pc}
69
70 /*
71  * cpu_sa110_reset(loc)
72  *
73  * Perform a soft reset of the system.  Put the CPU into the
74  * same state as it would be if it had been reset, and branch
75  * to what would be the reset vector.
76  *
77  * loc: location to jump to for soft reset
78  */
79         .align  5
80 ENTRY(cpu_sa110_reset)
81         mov     ip, #0
82         mcr     p15, 0, ip, c7, c7, 0           @ invalidate I,D caches
83         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
84         mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
85         mrc     p15, 0, ip, c1, c0, 0           @ ctrl register
86         bic     ip, ip, #0x000f                 @ ............wcam
87         bic     ip, ip, #0x1100                 @ ...i...s........
88         mcr     p15, 0, ip, c1, c0, 0           @ ctrl register
89         mov     pc, r0
90
91 /*
92  * cpu_sa110_do_idle(type)
93  *
94  * Cause the processor to idle
95  *
96  * type: call type:
97  *   0 = slow idle
98  *   1 = fast idle
99  *   2 = switch to slow processor clock
100  *   3 = switch to fast processor clock
101  */
102         .align  5
103
104 ENTRY(cpu_sa110_do_idle)
105         mcr     p15, 0, ip, c15, c2, 2          @ disable clock switching
106         ldr     r1, =UNCACHEABLE_ADDR           @ load from uncacheable loc
107         ldr     r1, [r1, #0]                    @ force switch to MCLK
108         mov     r0, r0                          @ safety
109         mov     r0, r0                          @ safety
110         mov     r0, r0                          @ safety
111         mcr     p15, 0, r0, c15, c8, 2          @ Wait for interrupt, cache aligned
112         mov     r0, r0                          @ safety
113         mov     r0, r0                          @ safety
114         mov     r0, r0                          @ safety
115         mcr     p15, 0, r0, c15, c1, 2          @ enable clock switching
116         mov     pc, lr
117
118 /* ================================= CACHE ================================ */
119
120 /*
121  * cpu_sa110_dcache_clean_area(addr,sz)
122  *
123  * Clean the specified entry of any caches such that the MMU
124  * translation fetches will obtain correct data.
125  *
126  * addr: cache-unaligned virtual address
127  */
128         .align  5
129 ENTRY(cpu_sa110_dcache_clean_area)
130 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
131         add     r0, r0, #DCACHELINESIZE
132         subs    r1, r1, #DCACHELINESIZE
133         bhi     1b
134         mov     pc, lr
135
136 /* =============================== PageTable ============================== */
137
138 /*
139  * cpu_sa110_switch_mm(pgd)
140  *
141  * Set the translation base pointer to be as described by pgd.
142  *
143  * pgd: new page tables
144  */
145         .align  5
146 ENTRY(cpu_sa110_switch_mm)
147         flush_110_dcache        r3, ip, r1
148         mov     r1, #0
149         mcr     p15, 0, r1, c7, c5, 0           @ invalidate I cache
150         mcr     p15, 0, r1, c7, c10, 4          @ drain WB
151         mcr     p15, 0, r0, c2, c0, 0           @ load page table pointer
152         mcr     p15, 0, r1, c8, c7, 0           @ invalidate I & D TLBs
153         mov     pc, lr
154
155 /*
156  * cpu_sa110_set_pte(ptep, pte)
157  *
158  * Set a PTE and flush it out
159  */
160         .align  5
161 ENTRY(cpu_sa110_set_pte)
162         str     r1, [r0], #-2048                @ linux version
163
164         eor     r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
165
166         bic     r2, r1, #PTE_SMALL_AP_MASK
167         bic     r2, r2, #PTE_TYPE_MASK
168         orr     r2, r2, #PTE_TYPE_SMALL
169
170         tst     r1, #L_PTE_USER                 @ User?
171         orrne   r2, r2, #PTE_SMALL_AP_URO_SRW
172
173         tst     r1, #L_PTE_WRITE | L_PTE_DIRTY  @ Write and Dirty?
174         orreq   r2, r2, #PTE_SMALL_AP_UNO_SRW
175
176         tst     r1, #L_PTE_PRESENT | L_PTE_YOUNG        @ Present and Young?
177         movne   r2, #0
178
179         str     r2, [r0]                        @ hardware version
180         mov     r0, r0
181         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
182         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
183         mov     pc, lr
184
185         __INIT
186
187         .type   __sa110_setup, #function
188 __sa110_setup:
189         mrc     p15, 0, r0, c1, c0              @ get control register v4
190         bic     r0, r0, #0x2e00                 @ ..VI ZFRS BLDP WCAM
191         bic     r0, r0, #0x0002                 @ ..0. 000. .... ..0.
192         orr     r0, r0, #0x003d
193         orr     r0, r0, #0x1100                 @ ...1 ...1 ..11 11.1
194         mov     r10, #0
195         mcr     p15, 0, r10, c7, c7             @ invalidate I,D caches on v4
196         mcr     p15, 0, r10, c7, c10, 4         @ drain write buffer on v4
197         mcr     p15, 0, r10, c8, c7             @ invalidate I,D TLBs on v4
198         mcr     p15, 0, r4, c2, c0              @ load page table pointer
199         mov     r10, #0x1f                      @ Domains 0, 1 = client
200         mcr     p15, 0, r10, c3, c0             @ load domain access register
201         mov     pc, lr
202         .size   __sa110_setup, . - __sa110_setup
203
204         __INITDATA
205
206 /*
207  * Purpose : Function pointers used to access above functions - all calls
208  *           come through these
209  */
210
211         .type   sa110_processor_functions, #object
212 ENTRY(sa110_processor_functions)
213         .word   v4_early_abort
214         .word   cpu_sa110_proc_init
215         .word   cpu_sa110_proc_fin
216         .word   cpu_sa110_reset
217         .word   cpu_sa110_do_idle
218         .word   cpu_sa110_dcache_clean_area
219         .word   cpu_sa110_switch_mm
220         .word   cpu_sa110_set_pte
221         .size   sa110_processor_functions, . - sa110_processor_functions
222
223         .section ".rodata"
224
225         .type   cpu_arch_name, #object
226 cpu_arch_name:
227         .asciz  "armv4"
228         .size   cpu_arch_name, . - cpu_arch_name
229
230         .type   cpu_elf_name, #object
231 cpu_elf_name:
232         .asciz  "v4"
233         .size   cpu_elf_name, . - cpu_elf_name
234
235         .type   cpu_sa110_name, #object
236 cpu_sa110_name:
237         .asciz  "StrongARM-110"
238         .size   cpu_sa110_name, . - cpu_sa110_name
239
240         .align
241
242         .section ".proc.info", #alloc, #execinstr
243
244         .type   __sa110_proc_info,#object
245 __sa110_proc_info:
246         .long   0x4401a100
247         .long   0xfffffff0
248         .long   0x00000c0e
249         b       __sa110_setup
250         .long   cpu_arch_name
251         .long   cpu_elf_name
252         .long   HWCAP_SWP | HWCAP_HALF | HWCAP_26BIT | HWCAP_FAST_MULT
253         .long   cpu_sa110_name
254         .long   sa110_processor_functions
255         .long   v4wb_tlb_fns
256         .long   v4wb_user_fns
257         .long   v4wb_cache_fns
258         .size   __sa110_proc_info, . - __sa110_proc_info