change source file mode to 0644 instead of 0755
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / cpu / armv7 / sc9630 / mmu_asm.S
1 /* ============================================================================
2 @
3 @ MMU function for armV7
4 @ steve.zhan
5 @ Spreadtrum Communications Inc.
6 @
7 @ ============================================================================
8 */
9
10 @AREA mmu_functions, CODE, READONLY
11 @    CODE32
12
13 #include <config.h>
14 @   Initialize the MMU
15 @
16 .globl g_mmu_page_table
17 .globl MMU_EnableIDCM
18 .globl MMU_InvalideDCACHEALL
19 .globl MMU_InvalideICACHEALL
20 .globl Dcache_InvalRegion
21 .globl Dcache_CleanRegion
22
23
24 @============================================================================
25 @ Dcache_InvalRegion
26 @
27 @ PROTOTYPE
28 @ void Dcache_InvalRegion(void *addr, unsigned int length)
29 @
30 @ steve.zhan
31 @ DESCRIPTION
32 @ Invalid a memory region in the cache.
33 @============================================================================
34 Dcache_InvalRegion:
35     stmfd sp!, {r0-r3, lr}
36     add r1,r1,r0
37
38     mrc p15, 1, r3, c0, c0, 0
39     and r3, r3, #7
40     mov r2, #16
41     mov r2, r2, lsl r3
42
43     sub r3, r2, #1
44     tst r0, r3
45     bic r0, r0, r3
46     mcrne p15, 0, r0, c7, c14, 1
47
48     tst r1, r3
49     bic r1, r1, r3
50     mcrne p15, 0, r1, c7, c14, 1
51
52 1:
53     mcr p15, 0, r0, c7, c6, 1
54     add r0, r0, r2
55     cmp r0, r1
56     blo 1b
57     .word 0xf57ff04f
58
59     ldmfd sp!, {r0-r3, lr}
60
61 @============================================================================
62 @ Dcache_CleanRegion
63 @
64 @ PROTOTYPE
65 @ void Dcache_CleanRegion(void *addr, unsigned int length)
66 @
67 @ steve.zhan
68 @ DESCRIPTION
69 @ clean a memory region in the cache.
70 @============================================================================
71 Dcache_CleanRegion:
72         stmfd sp!, {r0-r3, lr}
73
74         add r1,r1,r0
75         mrc p15, 1, r3, c0, c0, 0
76         and r3, r3, #7
77         mov r2, #16
78         mov r2, r2, lsl r3
79
80         sub r3, r2, #1
81         bic r0, r0, r3
82
83 1:
84         mcr p15, 0, r0, c7, c10, 1 
85         add r0, r0, r2
86         cmp r0, r1
87         blo 1b
88
89         .word 0xf57ff04f
90         .word 0xf57ff05f
91         ldmfd sp!, {r0-r3,pc}
92
93
94 MMU_InvalideICACHEALL:
95     stmfd   sp!, {r0, lr}            @ save lr_USR and non-callee
96
97     MOV     r0, #0
98     MCR     p15, 0, r0, c7, c5, 0       @Invalidate(flush)the ICache
99     MCR     p15, 0, r0, c8, c5, 0       @flush ITLB only
100     NOP
101     NOP
102     NOP
103     NOP
104     NOP
105
106     ldmfd   sp!, {r0, PC}
107
108
109 MMU_EnableIDCM:
110 @ save lr_USR and non-callee
111     stmfd   sp!, {r0-r3, lr}
112
113 @   Set the MMU page table address
114     LDR     r2, =g_mmu_page_table
115     LDR     r2, [r2]
116     MCR     p15, 0, r2, c2, c0, 0
117
118 @   Domain Access Control: set all domains to manager
119     LDR     r0, =0xFFFFFFFF
120     MCR     p15, 0, r0, c3, c0, 0
121
122 @   Enable the ICache, DCache, write buffer, MMU
123     MRC     p15, 0, r0, c1, c0, 0
124     LDR     r1, =0x107D
125     ORR     r0, r0, r1
126     MCR     p15, 0, r0, c1, c0, 0
127
128 @   Delay for the operations to finish
129     NOP
130     NOP
131     NOP
132     NOP
133     NOP
134     ldmfd   sp!, {r0-r3, PC}
135
136 v7_flush_dcache_all:
137         stmfd   sp!,    {r0-r3,lr}
138         mov r1, #0x1f0
139         add r1,r1,#0xf
140
141         .word 0xf57ff05f
142
143         mrc p15, 1, r3, c0, c0, 0
144
145         and r3, r1, r3, lsr #13
146         mov r0, #0
147
148 way_loop2:
149         mov r1, #0
150
151 set_loop2:
152         mov r2, r0, lsr #30
153         orr r2, r1, lsr #5
154         mcr p15, 0, r2, c7 ,c14, 2
155         and r1, r1, #1
156         cmp r1, r3
157         ble set_loop2
158
159         add r0, r0, #1
160         cmp r0, #4
161         blt way_loop2
162
163         .word 0xf57ff04f
164         .word 0xf57ff06f
165         ldmfd sp!, {r0-r3,pc}
166
167
168 v7_flush_dcache_all1:
169         .word 0xf57ff05f
170         mrc     p15, 1, r0, c0, c0, 1                    @ read clidr
171         ands    r3, r0, #0x7000000              @ extract loc from clidr
172         mov     r3, r3, lsr #23                          @ left align loc bit field
173         beq     finished                                          @ if loc is 0, then no need to clean
174         mov     r10, #0                                 @ start clean at cache level 0
175 loop1:
176         add     r2, r10, r10, lsr #1            @ work out 3x current cache level
177         mov     r1, r0, lsr r2                  @ extract cache type bits from clidr
178         and     r1, r1, #7                      @ mask of the bits for current cache only
179         cmp     r1, #2                          @ see what cache we have at this level
180         blt     skip                            @ skip if no cache, or just i-cache
181         mcr     p15, 2, r10, c0, c0, 0          @ select current cache level in cssr
182         .word 0xf57ff06f
183         mrc     p15, 1, r1, c0, c0, 0           @ read the new csidr
184         and     r2, r1, #7                      @ extract the length of the cache lines
185         add     r2, r2, #4                      @ add 4 (line length offset)
186         ldr     r4, =0x3ff
187         ands    r4, r4, r1, lsr #3              @ find maximum number on the way size
188         clz     r5, r4                          @ find bit position of way size increment
189         ldr     r7, =0x7fff
190         ands    r7, r7, r1, lsr #13             @ extract max number of the index size
191 loop2:
192         mov     r9, r4                          @ create working copy of max way size
193 loop3:
194         orr     r11, r10, r9, lsl r5            @ factor way and cache number into r11
195         orr     r11, r11, r7, lsl r2            @ factor index number into r11
196         mcr     p15, 0, r11, c7, c14, 2         @ clean & invalidate by set/way
197         subs    r9, r9, #1                      @ decrement the way
198         bge     loop3
199         subs    r7, r7, #1                      @ decrement the index
200         bge     loop2
201 skip:
202         add     r10, r10, #2                    @ increment cache number
203         cmp     r3, r10
204         bgt     loop1
205 finished:
206         mov     r10, #0                         @ swith back to cache level 0
207         mcr     p15, 2, r10, c0, c0, 0          @ select current cache level in cssr
208         .word 0xf57ff04f
209         .word 0xf57ff06f
210         mov pc, lr
211
212
213 .globl  MMU_DisableIDCM
214 MMU_DisableIDCM:
215         stmfd   sp!, {r0-r12, lr}
216
217 @   Disable the ICache, DCache, write buffer, MMU
218         MRC     p15, 0, r0, c1, c0, 0
219         LDR     r1, =0x1005
220         BIC     r0, r0, r1
221         ORR     r0, r0, #0x8     @Bit_7 must be one when write c1@
222         MCR     p15, 0, r0, c1, c0, 0
223
224         bl v7_flush_dcache_all1
225
226         mov r0, #0
227         mcr p15, 0, r0, c7, c5, 0
228         mcr p15, 0, r0, c8, c7, 0
229         NOP
230         NOP
231         NOP
232         NOP
233 @   Return
234         ldmfd   sp!, {r0-r12, PC}             @ restore registers
235