blob: 23ad5027d90cdf777adf1b479387980afe2b845e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mm/proc-arm926.S: MMU functions for ARM926EJ-S
3 *
4 * Copyright (C) 1999-2001 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 arm926.
24 *
25 * CONFIG_CPU_ARM926_CPU_IDLE -> nohlt
26 */
27#include <linux/linkage.h>
28#include <linux/config.h>
29#include <linux/init.h>
30#include <asm/assembler.h>
Russell King74945c82006-03-16 14:44:36 +000031#include <asm/pgtable-hwdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#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 * This is the maximum size of an area which will be invalidated
41 * using the single invalidate entry instructions. Anything larger
42 * than this, and we go for the whole cache.
43 *
44 * This value should be chosen such that we choose the cheapest
45 * alternative.
46 */
47#define CACHE_DLIMIT 16384
48
49/*
50 * the cache line size of the I and D cache
51 */
52#define CACHE_DLINESIZE 32
53
54 .text
55/*
56 * cpu_arm926_proc_init()
57 */
58ENTRY(cpu_arm926_proc_init)
59 mov pc, lr
60
61/*
62 * cpu_arm926_proc_fin()
63 */
64ENTRY(cpu_arm926_proc_fin)
65 stmfd sp!, {lr}
66 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
67 msr cpsr_c, ip
68 bl arm926_flush_kern_cache_all
69 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
70 bic r0, r0, #0x1000 @ ...i............
71 bic r0, r0, #0x000e @ ............wca.
72 mcr p15, 0, r0, c1, c0, 0 @ disable caches
73 ldmfd sp!, {pc}
74
75/*
76 * cpu_arm926_reset(loc)
77 *
78 * Perform a soft reset of the system. Put the CPU into the
79 * same state as it would be if it had been reset, and branch
80 * to what would be the reset vector.
81 *
82 * loc: location to jump to for soft reset
83 */
84 .align 5
85ENTRY(cpu_arm926_reset)
86 mov ip, #0
87 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
88 mcr p15, 0, ip, c7, c10, 4 @ drain WB
89 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
90 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
91 bic ip, ip, #0x000f @ ............wcam
92 bic ip, ip, #0x1100 @ ...i...s........
93 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
94 mov pc, r0
95
96/*
97 * cpu_arm926_do_idle()
98 *
99 * Called with IRQs disabled
100 */
101 .align 10
102ENTRY(cpu_arm926_do_idle)
103 mov r0, #0
104 mrc p15, 0, r1, c1, c0, 0 @ Read control register
105 mcr p15, 0, r0, c7, c10, 4 @ Drain write buffer
106 bic r2, r1, #1 << 12
107 mcr p15, 0, r2, c1, c0, 0 @ Disable I cache
108 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
109 mcr p15, 0, r1, c1, c0, 0 @ Restore ICache enable
110 mov pc, lr
111
112/*
113 * flush_user_cache_all()
114 *
115 * Clean and invalidate all cache entries in a particular
116 * address space.
117 */
118ENTRY(arm926_flush_user_cache_all)
119 /* FALLTHROUGH */
120
121/*
122 * flush_kern_cache_all()
123 *
124 * Clean and invalidate the entire cache.
125 */
126ENTRY(arm926_flush_kern_cache_all)
127 mov r2, #VM_EXEC
128 mov ip, #0
129__flush_whole_cache:
130#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
131 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
132#else
1331: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate
134 bne 1b
135#endif
136 tst r2, #VM_EXEC
137 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
138 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
139 mov pc, lr
140
141/*
142 * flush_user_cache_range(start, end, flags)
143 *
144 * Clean and invalidate a range of cache entries in the
145 * specified address range.
146 *
147 * - start - start address (inclusive)
148 * - end - end address (exclusive)
149 * - flags - vm_flags describing address space
150 */
151ENTRY(arm926_flush_user_cache_range)
152 mov ip, #0
153 sub r3, r1, r0 @ calculate total size
154 cmp r3, #CACHE_DLIMIT
155 bgt __flush_whole_cache
1561: tst r2, #VM_EXEC
157#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
158 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
159 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
160 add r0, r0, #CACHE_DLINESIZE
161 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
162 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
163 add r0, r0, #CACHE_DLINESIZE
164#else
165 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
166 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
167 add r0, r0, #CACHE_DLINESIZE
168 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
169 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
170 add r0, r0, #CACHE_DLINESIZE
171#endif
172 cmp r0, r1
173 blo 1b
174 tst r2, #VM_EXEC
175 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
176 mov pc, lr
177
178/*
179 * coherent_kern_range(start, end)
180 *
181 * Ensure coherency between the Icache and the Dcache in the
182 * region described by start, end. If you have non-snooping
183 * Harvard caches, you need to implement this function.
184 *
185 * - start - virtual start address
186 * - end - virtual end address
187 */
188ENTRY(arm926_coherent_kern_range)
189 /* FALLTHROUGH */
190
191/*
192 * coherent_user_range(start, end)
193 *
194 * Ensure coherency between the Icache and the Dcache in the
195 * region described by start, end. If you have non-snooping
196 * Harvard caches, you need to implement this function.
197 *
198 * - start - virtual start address
199 * - end - virtual end address
200 */
201ENTRY(arm926_coherent_user_range)
202 bic r0, r0, #CACHE_DLINESIZE - 1
2031: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
204 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
205 add r0, r0, #CACHE_DLINESIZE
206 cmp r0, r1
207 blo 1b
208 mcr p15, 0, r0, c7, c10, 4 @ drain WB
209 mov pc, lr
210
211/*
212 * flush_kern_dcache_page(void *page)
213 *
214 * Ensure no D cache aliasing occurs, either with itself or
215 * the I cache
216 *
217 * - addr - page aligned address
218 */
219ENTRY(arm926_flush_kern_dcache_page)
220 add r1, r0, #PAGE_SZ
2211: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
222 add r0, r0, #CACHE_DLINESIZE
223 cmp r0, r1
224 blo 1b
225 mov r0, #0
226 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
227 mcr p15, 0, r0, c7, c10, 4 @ drain WB
228 mov pc, lr
229
230/*
231 * dma_inv_range(start, end)
232 *
233 * Invalidate (discard) the specified virtual address range.
234 * May not write back any entries. If 'start' or 'end'
235 * are not cache line aligned, those lines must be written
236 * back.
237 *
238 * - start - virtual start address
239 * - end - virtual end address
240 *
241 * (same as v4wb)
242 */
243ENTRY(arm926_dma_inv_range)
244#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
245 tst r0, #CACHE_DLINESIZE - 1
246 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
247 tst r1, #CACHE_DLINESIZE - 1
248 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
249#endif
250 bic r0, r0, #CACHE_DLINESIZE - 1
2511: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
252 add r0, r0, #CACHE_DLINESIZE
253 cmp r0, r1
254 blo 1b
255 mcr p15, 0, r0, c7, c10, 4 @ drain WB
256 mov pc, lr
257
258/*
259 * dma_clean_range(start, end)
260 *
261 * Clean the specified virtual address range.
262 *
263 * - start - virtual start address
264 * - end - virtual end address
265 *
266 * (same as v4wb)
267 */
268ENTRY(arm926_dma_clean_range)
269#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
270 bic r0, r0, #CACHE_DLINESIZE - 1
2711: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
272 add r0, r0, #CACHE_DLINESIZE
273 cmp r0, r1
274 blo 1b
275#endif
276 mcr p15, 0, r0, c7, c10, 4 @ drain WB
277 mov pc, lr
278
279/*
280 * dma_flush_range(start, end)
281 *
282 * Clean and invalidate the specified virtual address range.
283 *
284 * - start - virtual start address
285 * - end - virtual end address
286 */
287ENTRY(arm926_dma_flush_range)
288 bic r0, r0, #CACHE_DLINESIZE - 1
2891:
290#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
291 mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
292#else
293 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
294#endif
295 add r0, r0, #CACHE_DLINESIZE
296 cmp r0, r1
297 blo 1b
298 mcr p15, 0, r0, c7, c10, 4 @ drain WB
299 mov pc, lr
300
301ENTRY(arm926_cache_fns)
302 .long arm926_flush_kern_cache_all
303 .long arm926_flush_user_cache_all
304 .long arm926_flush_user_cache_range
305 .long arm926_coherent_kern_range
306 .long arm926_coherent_user_range
307 .long arm926_flush_kern_dcache_page
308 .long arm926_dma_inv_range
309 .long arm926_dma_clean_range
310 .long arm926_dma_flush_range
311
312ENTRY(cpu_arm926_dcache_clean_area)
313#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
3141: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
315 add r0, r0, #CACHE_DLINESIZE
316 subs r1, r1, #CACHE_DLINESIZE
317 bhi 1b
318#endif
319 mcr p15, 0, r0, c7, c10, 4 @ drain WB
320 mov pc, lr
321
322/* =============================== PageTable ============================== */
323
324/*
325 * cpu_arm926_switch_mm(pgd)
326 *
327 * Set the translation base pointer to be as described by pgd.
328 *
329 * pgd: new page tables
330 */
331 .align 5
332ENTRY(cpu_arm926_switch_mm)
333 mov ip, #0
334#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
335 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
336#else
337@ && 'Clean & Invalidate whole DCache'
3381: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate
339 bne 1b
340#endif
341 mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
342 mcr p15, 0, ip, c7, c10, 4 @ drain WB
343 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
344 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
345 mov pc, lr
346
347/*
348 * cpu_arm926_set_pte(ptep, pte)
349 *
350 * Set a PTE and flush it out
351 */
352 .align 5
353ENTRY(cpu_arm926_set_pte)
354 str r1, [r0], #-2048 @ linux version
355
356 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
357
358 bic r2, r1, #PTE_SMALL_AP_MASK
359 bic r2, r2, #PTE_TYPE_MASK
360 orr r2, r2, #PTE_TYPE_SMALL
361
362 tst r1, #L_PTE_USER @ User?
363 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
364
365 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
366 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
367
368 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
369 movne r2, #0
370
371#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
372 eor r3, r2, #0x0a @ C & small page?
373 tst r3, #0x0b
374 biceq r2, r2, #4
375#endif
376 str r2, [r0] @ hardware version
377 mov r0, r0
378#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
379 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
380#endif
381 mcr p15, 0, r0, c7, c10, 4 @ drain WB
382 mov pc, lr
383
384 __INIT
385
386 .type __arm926_setup, #function
387__arm926_setup:
388 mov r0, #0
389 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
390 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
391 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
392
393
394#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
395 mov r0, #4 @ disable write-back on caches explicitly
396 mcr p15, 7, r0, c15, c0, 0
397#endif
398
399 mrc p15, 0, r0, c1, c0 @ get control register v4
400 ldr r5, arm926_cr1_clear
401 bic r0, r0, r5
402 ldr r5, arm926_cr1_set
403 orr r0, r0, r5
404#ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
405 orr r0, r0, #0x4000 @ .1.. .... .... ....
406#endif
407 mov pc, lr
408 .size __arm926_setup, . - __arm926_setup
409
410 /*
411 * R
412 * .RVI ZFRS BLDP WCAM
413 * .011 0001 ..11 0101
414 *
415 */
416 .type arm926_cr1_clear, #object
417 .type arm926_cr1_set, #object
418arm926_cr1_clear:
419 .word 0x7f3f
420arm926_cr1_set:
421 .word 0x3135
422
423 __INITDATA
424
425/*
426 * Purpose : Function pointers used to access above functions - all calls
427 * come through these
428 */
429 .type arm926_processor_functions, #object
430arm926_processor_functions:
431 .word v5tj_early_abort
432 .word cpu_arm926_proc_init
433 .word cpu_arm926_proc_fin
434 .word cpu_arm926_reset
435 .word cpu_arm926_do_idle
436 .word cpu_arm926_dcache_clean_area
437 .word cpu_arm926_switch_mm
438 .word cpu_arm926_set_pte
439 .size arm926_processor_functions, . - arm926_processor_functions
440
441 .section ".rodata"
442
443 .type cpu_arch_name, #object
444cpu_arch_name:
445 .asciz "armv5tej"
446 .size cpu_arch_name, . - cpu_arch_name
447
448 .type cpu_elf_name, #object
449cpu_elf_name:
450 .asciz "v5"
451 .size cpu_elf_name, . - cpu_elf_name
452
453 .type cpu_arm926_name, #object
454cpu_arm926_name:
455 .ascii "ARM926EJ-S"
456#ifndef CONFIG_CPU_ICACHE_DISABLE
457 .ascii "i"
458#endif
459#ifndef CONFIG_CPU_DCACHE_DISABLE
460 .ascii "d"
461#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
462 .ascii "(wt)"
463#else
464 .ascii "(wb)"
465#endif
466#ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
467 .ascii "RR"
468#endif
469#endif
470 .ascii "\0"
471 .size cpu_arm926_name, . - cpu_arm926_name
472
473 .align
474
Ben Dooks02b7dd12005-09-20 16:35:03 +0100475 .section ".proc.info.init", #alloc, #execinstr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477 .type __arm926_proc_info,#object
478__arm926_proc_info:
479 .long 0x41069260 @ ARM926EJ-S (v5TEJ)
480 .long 0xff0ffff0
481 .long PMD_TYPE_SECT | \
482 PMD_SECT_BUFFERABLE | \
483 PMD_SECT_CACHEABLE | \
484 PMD_BIT4 | \
485 PMD_SECT_AP_WRITE | \
486 PMD_SECT_AP_READ
487 b __arm926_setup
488 .long cpu_arch_name
489 .long cpu_elf_name
490 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_JAVA
491 .long cpu_arm926_name
492 .long arm926_processor_functions
493 .long v4wbi_tlb_fns
494 .long v4wb_user_fns
495 .long arm926_cache_fns
496 .size __arm926_proc_info, . - __arm926_proc_info