[ARM] nommu: Move hardware page table definitions to pgtable-hwdef.h
[firefly-linux-kernel-4.4.55.git] / arch / arm / mm / proc-arm920.S
1 /*
2  *  linux/arch/arm/mm/proc-arm920.S: MMU functions for ARM920
3  *
4  *  Copyright (C) 1999,2000 ARM Limited
5  *  Copyright (C) 2000 Deep Blue Solutions Ltd.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  *
22  * These are the low level assembler for performing cache and TLB
23  * functions on the arm920.
24  *
25  *  CONFIG_CPU_ARM920_CPU_IDLE -> nohlt
26  */
27 #include <linux/linkage.h>
28 #include <linux/config.h>
29 #include <linux/init.h>
30 #include <asm/assembler.h>
31 #include <asm/pgtable-hwdef.h>
32 #include <asm/pgtable.h>
33 #include <asm/procinfo.h>
34 #include <asm/hardware.h>
35 #include <asm/page.h>
36 #include <asm/ptrace.h>
37 #include "proc-macros.S"
38
39 /*
40  * The size of one data cache line.
41  */
42 #define CACHE_DLINESIZE 32
43
44 /*
45  * The number of data cache segments.
46  */
47 #define CACHE_DSEGMENTS 8
48
49 /*
50  * The number of lines in a cache segment.
51  */
52 #define CACHE_DENTRIES  64
53
54 /*
55  * This is the size at which it becomes more efficient to
56  * clean the whole cache, rather than using the individual
57  * cache line maintainence instructions.
58  */
59 #define CACHE_DLIMIT    65536
60
61
62         .text
63 /*
64  * cpu_arm920_proc_init()
65  */
66 ENTRY(cpu_arm920_proc_init)
67         mov     pc, lr
68
69 /*
70  * cpu_arm920_proc_fin()
71  */
72 ENTRY(cpu_arm920_proc_fin)
73         stmfd   sp!, {lr}
74         mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
75         msr     cpsr_c, ip
76 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
77         bl      arm920_flush_kern_cache_all
78 #else
79         bl      v4wt_flush_kern_cache_all
80 #endif
81         mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
82         bic     r0, r0, #0x1000                 @ ...i............
83         bic     r0, r0, #0x000e                 @ ............wca.
84         mcr     p15, 0, r0, c1, c0, 0           @ disable caches
85         ldmfd   sp!, {pc}
86
87 /*
88  * cpu_arm920_reset(loc)
89  *
90  * Perform a soft reset of the system.  Put the CPU into the
91  * same state as it would be if it had been reset, and branch
92  * to what would be the reset vector.
93  *
94  * loc: location to jump to for soft reset
95  */
96         .align  5
97 ENTRY(cpu_arm920_reset)
98         mov     ip, #0
99         mcr     p15, 0, ip, c7, c7, 0           @ invalidate I,D caches
100         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
101         mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
102         mrc     p15, 0, ip, c1, c0, 0           @ ctrl register
103         bic     ip, ip, #0x000f                 @ ............wcam
104         bic     ip, ip, #0x1100                 @ ...i...s........
105         mcr     p15, 0, ip, c1, c0, 0           @ ctrl register
106         mov     pc, r0
107
108 /*
109  * cpu_arm920_do_idle()
110  */
111         .align  5
112 ENTRY(cpu_arm920_do_idle)
113         mcr     p15, 0, r0, c7, c0, 4           @ Wait for interrupt
114         mov     pc, lr
115
116
117 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
118
119 /*
120  *      flush_user_cache_all()
121  *
122  *      Invalidate all cache entries in a particular address
123  *      space.
124  */
125 ENTRY(arm920_flush_user_cache_all)
126         /* FALLTHROUGH */
127
128 /*
129  *      flush_kern_cache_all()
130  *
131  *      Clean and invalidate the entire cache.
132  */
133 ENTRY(arm920_flush_kern_cache_all)
134         mov     r2, #VM_EXEC
135         mov     ip, #0
136 __flush_whole_cache:
137         mov     r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
138 1:      orr     r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
139 2:      mcr     p15, 0, r3, c7, c14, 2          @ clean+invalidate D index
140         subs    r3, r3, #1 << 26
141         bcs     2b                              @ entries 63 to 0
142         subs    r1, r1, #1 << 5
143         bcs     1b                              @ segments 7 to 0
144         tst     r2, #VM_EXEC
145         mcrne   p15, 0, ip, c7, c5, 0           @ invalidate I cache
146         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
147         mov     pc, lr
148
149 /*
150  *      flush_user_cache_range(start, end, flags)
151  *
152  *      Invalidate a range of cache entries in the specified
153  *      address space.
154  *
155  *      - start - start address (inclusive)
156  *      - end   - end address (exclusive)
157  *      - flags - vm_flags for address space
158  */
159 ENTRY(arm920_flush_user_cache_range)
160         mov     ip, #0
161         sub     r3, r1, r0                      @ calculate total size
162         cmp     r3, #CACHE_DLIMIT
163         bhs     __flush_whole_cache
164
165 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
166         tst     r2, #VM_EXEC
167         mcrne   p15, 0, r0, c7, c5, 1           @ invalidate I entry
168         add     r0, r0, #CACHE_DLINESIZE
169         cmp     r0, r1
170         blo     1b
171         tst     r2, #VM_EXEC
172         mcrne   p15, 0, ip, c7, c10, 4          @ drain WB
173         mov     pc, lr
174
175 /*
176  *      coherent_kern_range(start, end)
177  *
178  *      Ensure coherency between the Icache and the Dcache in the
179  *      region described by start, end.  If you have non-snooping
180  *      Harvard caches, you need to implement this function.
181  *
182  *      - start - virtual start address
183  *      - end   - virtual end address
184  */
185 ENTRY(arm920_coherent_kern_range)
186         /* FALLTHROUGH */
187
188 /*
189  *      coherent_user_range(start, end)
190  *
191  *      Ensure coherency between the Icache and the Dcache in the
192  *      region described by start, end.  If you have non-snooping
193  *      Harvard caches, you need to implement this function.
194  *
195  *      - start - virtual start address
196  *      - end   - virtual end address
197  */
198 ENTRY(arm920_coherent_user_range)
199         bic     r0, r0, #CACHE_DLINESIZE - 1
200 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
201         mcr     p15, 0, r0, c7, c5, 1           @ invalidate I entry
202         add     r0, r0, #CACHE_DLINESIZE
203         cmp     r0, r1
204         blo     1b
205         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
206         mov     pc, lr
207
208 /*
209  *      flush_kern_dcache_page(void *page)
210  *
211  *      Ensure no D cache aliasing occurs, either with itself or
212  *      the I cache
213  *
214  *      - addr  - page aligned address
215  */
216 ENTRY(arm920_flush_kern_dcache_page)
217         add     r1, r0, #PAGE_SZ
218 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
219         add     r0, r0, #CACHE_DLINESIZE
220         cmp     r0, r1
221         blo     1b
222         mov     r0, #0
223         mcr     p15, 0, r0, c7, c5, 0           @ invalidate I cache
224         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
225         mov     pc, lr
226
227 /*
228  *      dma_inv_range(start, end)
229  *
230  *      Invalidate (discard) the specified virtual address range.
231  *      May not write back any entries.  If 'start' or 'end'
232  *      are not cache line aligned, those lines must be written
233  *      back.
234  *
235  *      - start - virtual start address
236  *      - end   - virtual end address
237  *
238  * (same as v4wb)
239  */
240 ENTRY(arm920_dma_inv_range)
241         tst     r0, #CACHE_DLINESIZE - 1
242         bic     r0, r0, #CACHE_DLINESIZE - 1
243         mcrne   p15, 0, r0, c7, c10, 1          @ clean D entry
244         tst     r1, #CACHE_DLINESIZE - 1
245         mcrne   p15, 0, r1, c7, c10, 1          @ clean D entry
246 1:      mcr     p15, 0, r0, c7, c6, 1           @ invalidate D entry
247         add     r0, r0, #CACHE_DLINESIZE
248         cmp     r0, r1
249         blo     1b
250         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
251         mov     pc, lr
252
253 /*
254  *      dma_clean_range(start, end)
255  *
256  *      Clean the specified virtual address range.
257  *
258  *      - start - virtual start address
259  *      - end   - virtual end address
260  *
261  * (same as v4wb)
262  */
263 ENTRY(arm920_dma_clean_range)
264         bic     r0, r0, #CACHE_DLINESIZE - 1
265 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
266         add     r0, r0, #CACHE_DLINESIZE
267         cmp     r0, r1
268         blo     1b
269         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
270         mov     pc, lr
271
272 /*
273  *      dma_flush_range(start, end)
274  *
275  *      Clean and invalidate the specified virtual address range.
276  *
277  *      - start - virtual start address
278  *      - end   - virtual end address
279  */
280 ENTRY(arm920_dma_flush_range)
281         bic     r0, r0, #CACHE_DLINESIZE - 1
282 1:      mcr     p15, 0, r0, c7, c14, 1          @ clean+invalidate D entry
283         add     r0, r0, #CACHE_DLINESIZE
284         cmp     r0, r1
285         blo     1b
286         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
287         mov     pc, lr
288
289 ENTRY(arm920_cache_fns)
290         .long   arm920_flush_kern_cache_all
291         .long   arm920_flush_user_cache_all
292         .long   arm920_flush_user_cache_range
293         .long   arm920_coherent_kern_range
294         .long   arm920_coherent_user_range
295         .long   arm920_flush_kern_dcache_page
296         .long   arm920_dma_inv_range
297         .long   arm920_dma_clean_range
298         .long   arm920_dma_flush_range
299
300 #endif
301
302
303 ENTRY(cpu_arm920_dcache_clean_area)
304 1:      mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
305         add     r0, r0, #CACHE_DLINESIZE
306         subs    r1, r1, #CACHE_DLINESIZE
307         bhi     1b
308         mov     pc, lr
309
310 /* =============================== PageTable ============================== */
311
312 /*
313  * cpu_arm920_switch_mm(pgd)
314  *
315  * Set the translation base pointer to be as described by pgd.
316  *
317  * pgd: new page tables
318  */
319         .align  5
320 ENTRY(cpu_arm920_switch_mm)
321         mov     ip, #0
322 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
323         mcr     p15, 0, ip, c7, c6, 0           @ invalidate D cache
324 #else
325 @ && 'Clean & Invalidate whole DCache'
326 @ && Re-written to use Index Ops.
327 @ && Uses registers r1, r3 and ip
328
329         mov     r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
330 1:      orr     r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
331 2:      mcr     p15, 0, r3, c7, c14, 2          @ clean & invalidate D index
332         subs    r3, r3, #1 << 26
333         bcs     2b                              @ entries 63 to 0
334         subs    r1, r1, #1 << 5
335         bcs     1b                              @ segments 7 to 0
336 #endif
337         mcr     p15, 0, ip, c7, c5, 0           @ invalidate I cache
338         mcr     p15, 0, ip, c7, c10, 4          @ drain WB
339         mcr     p15, 0, r0, c2, c0, 0           @ load page table pointer
340         mcr     p15, 0, ip, c8, c7, 0           @ invalidate I & D TLBs
341         mov     pc, lr
342
343 /*
344  * cpu_arm920_set_pte(ptep, pte)
345  *
346  * Set a PTE and flush it out
347  */
348         .align  5
349 ENTRY(cpu_arm920_set_pte)
350         str     r1, [r0], #-2048                @ linux version
351
352         eor     r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
353
354         bic     r2, r1, #PTE_SMALL_AP_MASK
355         bic     r2, r2, #PTE_TYPE_MASK
356         orr     r2, r2, #PTE_TYPE_SMALL
357
358         tst     r1, #L_PTE_USER                 @ User?
359         orrne   r2, r2, #PTE_SMALL_AP_URO_SRW
360
361         tst     r1, #L_PTE_WRITE | L_PTE_DIRTY  @ Write and Dirty?
362         orreq   r2, r2, #PTE_SMALL_AP_UNO_SRW
363
364         tst     r1, #L_PTE_PRESENT | L_PTE_YOUNG        @ Present and Young?
365         movne   r2, #0
366
367 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
368         eor     r3, r2, #0x0a                   @ C & small page?
369         tst     r3, #0x0b
370         biceq   r2, r2, #4
371 #endif
372         str     r2, [r0]                        @ hardware version
373         mov     r0, r0
374         mcr     p15, 0, r0, c7, c10, 1          @ clean D entry
375         mcr     p15, 0, r0, c7, c10, 4          @ drain WB
376         mov     pc, lr
377
378         __INIT
379
380         .type   __arm920_setup, #function
381 __arm920_setup:
382         mov     r0, #0
383         mcr     p15, 0, r0, c7, c7              @ invalidate I,D caches on v4
384         mcr     p15, 0, r0, c7, c10, 4          @ drain write buffer on v4
385         mcr     p15, 0, r0, c8, c7              @ invalidate I,D TLBs on v4
386         mrc     p15, 0, r0, c1, c0              @ get control register v4
387         ldr     r5, arm920_cr1_clear
388         bic     r0, r0, r5
389         ldr     r5, arm920_cr1_set
390         orr     r0, r0, r5
391         mov     pc, lr
392         .size   __arm920_setup, . - __arm920_setup
393
394         /*
395          *  R
396          * .RVI ZFRS BLDP WCAM
397          * ..11 0001 ..11 0101
398          * 
399          */
400         .type   arm920_cr1_clear, #object
401         .type   arm920_cr1_set, #object
402 arm920_cr1_clear:
403         .word   0x3f3f
404 arm920_cr1_set:
405         .word   0x3135
406
407         __INITDATA
408
409 /*
410  * Purpose : Function pointers used to access above functions - all calls
411  *           come through these
412  */
413         .type   arm920_processor_functions, #object
414 arm920_processor_functions:
415         .word   v4t_early_abort
416         .word   cpu_arm920_proc_init
417         .word   cpu_arm920_proc_fin
418         .word   cpu_arm920_reset
419         .word   cpu_arm920_do_idle
420         .word   cpu_arm920_dcache_clean_area
421         .word   cpu_arm920_switch_mm
422         .word   cpu_arm920_set_pte
423         .size   arm920_processor_functions, . - arm920_processor_functions
424
425         .section ".rodata"
426
427         .type   cpu_arch_name, #object
428 cpu_arch_name:
429         .asciz  "armv4t"
430         .size   cpu_arch_name, . - cpu_arch_name
431
432         .type   cpu_elf_name, #object
433 cpu_elf_name:
434         .asciz  "v4"
435         .size   cpu_elf_name, . - cpu_elf_name
436
437         .type   cpu_arm920_name, #object
438 cpu_arm920_name:
439         .ascii  "ARM920T"
440 #ifndef CONFIG_CPU_ICACHE_DISABLE
441         .ascii  "i"
442 #endif
443 #ifndef CONFIG_CPU_DCACHE_DISABLE
444         .ascii  "d"
445 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
446         .ascii  "(wt)"
447 #else
448         .ascii  "(wb)"
449 #endif
450 #endif
451         .ascii  "\0"
452         .size   cpu_arm920_name, . - cpu_arm920_name
453
454         .align
455
456         .section ".proc.info.init", #alloc, #execinstr
457
458         .type   __arm920_proc_info,#object
459 __arm920_proc_info:
460         .long   0x41009200
461         .long   0xff00fff0
462         .long   PMD_TYPE_SECT | \
463                 PMD_SECT_BUFFERABLE | \
464                 PMD_SECT_CACHEABLE | \
465                 PMD_BIT4 | \
466                 PMD_SECT_AP_WRITE | \
467                 PMD_SECT_AP_READ
468         b       __arm920_setup
469         .long   cpu_arch_name
470         .long   cpu_elf_name
471         .long   HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
472         .long   cpu_arm920_name
473         .long   arm920_processor_functions
474         .long   v4wbi_tlb_fns
475         .long   v4wb_user_fns
476 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
477         .long   arm920_cache_fns
478 #else
479         .long   v4wt_cache_fns
480 #endif
481         .size   __arm920_proc_info, . - __arm920_proc_info