blob: eb78850addaade5b09566818340e22d55a4bb606 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mm/arm925.S: MMU functions for ARM925
3 *
4 * Copyright (C) 1999,2000 ARM Limited
5 * Copyright (C) 2000 Deep Blue Solutions Ltd.
6 * Copyright (C) 2002 RidgeRun, Inc.
7 * Copyright (C) 2002-2003 MontaVista Software, Inc.
8 *
9 * Update for Linux-2.6 and cache flush improvements
10 * Copyright (C) 2004 Nokia Corporation by Tony Lindgren <tony@atomide.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 *
27 * These are the low level assembler for performing cache and TLB
28 * functions on the arm925.
29 *
30 * CONFIG_CPU_ARM925_CPU_IDLE -> nohlt
31 *
32 * Some additional notes based on deciphering the TI TRM on OMAP-5910:
33 *
34 * NOTE1: The TI925T Configuration Register bit "D-cache clean and flush
35 * entry mode" must be 0 to flush the entries in both segments
36 * at once. This is the default value. See TRM 2-20 and 2-24 for
37 * more information.
38 *
39 * NOTE2: Default is the "D-cache clean and flush entry mode". It looks
40 * like the "Transparent mode" must be on for partial cache flushes
41 * to work in this mode. This mode only works with 16-bit external
42 * memory. See TRM 2-24 for more information.
43 *
44 * NOTE3: Write-back cache flushing seems to be flakey with devices using
45 * direct memory access, such as USB OHCI. The workaround is to use
46 * write-through cache with CONFIG_CPU_DCACHE_WRITETHROUGH (this is
47 * the default for OMAP-1510).
48 */
49
50#include <linux/linkage.h>
51#include <linux/config.h>
52#include <linux/init.h>
53#include <asm/assembler.h>
Russell King74945c82006-03-16 14:44:36 +000054#include <asm/pgtable-hwdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <asm/pgtable.h>
56#include <asm/procinfo.h>
57#include <asm/hardware.h>
58#include <asm/page.h>
59#include <asm/ptrace.h>
60#include "proc-macros.S"
61
62/*
63 * The size of one data cache line.
64 */
65#define CACHE_DLINESIZE 16
66
67/*
68 * The number of data cache segments.
69 */
70#define CACHE_DSEGMENTS 2
71
72/*
73 * The number of lines in a cache segment.
74 */
75#define CACHE_DENTRIES 256
76
77/*
78 * This is the size at which it becomes more efficient to
79 * clean the whole cache, rather than using the individual
80 * cache line maintainence instructions.
81 */
82#define CACHE_DLIMIT 8192
83
84 .text
85/*
86 * cpu_arm925_proc_init()
87 */
88ENTRY(cpu_arm925_proc_init)
89 mov pc, lr
90
91/*
92 * cpu_arm925_proc_fin()
93 */
94ENTRY(cpu_arm925_proc_fin)
95 stmfd sp!, {lr}
96 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
97 msr cpsr_c, ip
98 bl arm925_flush_kern_cache_all
99 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
100 bic r0, r0, #0x1000 @ ...i............
101 bic r0, r0, #0x000e @ ............wca.
102 mcr p15, 0, r0, c1, c0, 0 @ disable caches
103 ldmfd sp!, {pc}
104
105/*
106 * cpu_arm925_reset(loc)
107 *
108 * Perform a soft reset of the system. Put the CPU into the
109 * same state as it would be if it had been reset, and branch
110 * to what would be the reset vector.
111 *
112 * loc: location to jump to for soft reset
113 */
114 .align 5
115ENTRY(cpu_arm925_reset)
116 /* Send software reset to MPU and DSP */
117 mov ip, #0xff000000
118 orr ip, ip, #0x00fe0000
119 orr ip, ip, #0x0000ce00
120 mov r4, #1
121 strh r4, [ip, #0x10]
122
123 mov ip, #0
124 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
125 mcr p15, 0, ip, c7, c10, 4 @ drain WB
126 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
127 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
128 bic ip, ip, #0x000f @ ............wcam
129 bic ip, ip, #0x1100 @ ...i...s........
130 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
131 mov pc, r0
132
133/*
134 * cpu_arm925_do_idle()
135 *
136 * Called with IRQs disabled
137 */
138 .align 10
139ENTRY(cpu_arm925_do_idle)
140 mov r0, #0
141 mrc p15, 0, r1, c1, c0, 0 @ Read control register
142 mcr p15, 0, r0, c7, c10, 4 @ Drain write buffer
143 bic r2, r1, #1 << 12
144 mcr p15, 0, r2, c1, c0, 0 @ Disable I cache
145 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
146 mcr p15, 0, r1, c1, c0, 0 @ Restore ICache enable
147 mov pc, lr
148
149/*
150 * flush_user_cache_all()
151 *
152 * Clean and invalidate all cache entries in a particular
153 * address space.
154 */
155ENTRY(arm925_flush_user_cache_all)
156 /* FALLTHROUGH */
157
158/*
159 * flush_kern_cache_all()
160 *
161 * Clean and invalidate the entire cache.
162 */
163ENTRY(arm925_flush_kern_cache_all)
164 mov r2, #VM_EXEC
165 mov ip, #0
166__flush_whole_cache:
167#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
168 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
169#else
170 /* Flush entries in both segments at once, see NOTE1 above */
171 mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
1722: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
173 subs r3, r3, #1 << 4
174 bcs 2b @ entries 255 to 0
175#endif
176 tst r2, #VM_EXEC
177 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
178 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
179 mov pc, lr
180
181/*
182 * flush_user_cache_range(start, end, flags)
183 *
184 * Clean and invalidate a range of cache entries in the
185 * specified address range.
186 *
187 * - start - start address (inclusive)
188 * - end - end address (exclusive)
189 * - flags - vm_flags describing address space
190 */
191ENTRY(arm925_flush_user_cache_range)
192 mov ip, #0
193 sub r3, r1, r0 @ calculate total size
194 cmp r3, #CACHE_DLIMIT
195 bgt __flush_whole_cache
1961: tst r2, #VM_EXEC
197#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
198 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
199 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
200 add r0, r0, #CACHE_DLINESIZE
201 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
202 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
203 add r0, r0, #CACHE_DLINESIZE
204#else
205 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
206 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
207 add r0, r0, #CACHE_DLINESIZE
208 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
209 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
210 add r0, r0, #CACHE_DLINESIZE
211#endif
212 cmp r0, r1
213 blo 1b
214 tst r2, #VM_EXEC
215 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
216 mov pc, lr
217
218/*
219 * coherent_kern_range(start, end)
220 *
221 * Ensure coherency between the Icache and the Dcache in the
222 * region described by start, end. If you have non-snooping
223 * Harvard caches, you need to implement this function.
224 *
225 * - start - virtual start address
226 * - end - virtual end address
227 */
228ENTRY(arm925_coherent_kern_range)
229 /* FALLTHROUGH */
230
231/*
232 * coherent_user_range(start, end)
233 *
234 * Ensure coherency between the Icache and the Dcache in the
235 * region described by start, end. If you have non-snooping
236 * Harvard caches, you need to implement this function.
237 *
238 * - start - virtual start address
239 * - end - virtual end address
240 */
241ENTRY(arm925_coherent_user_range)
242 bic r0, r0, #CACHE_DLINESIZE - 1
2431: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
244 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
245 add r0, r0, #CACHE_DLINESIZE
246 cmp r0, r1
247 blo 1b
248 mcr p15, 0, r0, c7, c10, 4 @ drain WB
249 mov pc, lr
250
251/*
252 * flush_kern_dcache_page(void *page)
253 *
254 * Ensure no D cache aliasing occurs, either with itself or
255 * the I cache
256 *
257 * - addr - page aligned address
258 */
259ENTRY(arm925_flush_kern_dcache_page)
260 add r1, r0, #PAGE_SZ
2611: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
262 add r0, r0, #CACHE_DLINESIZE
263 cmp r0, r1
264 blo 1b
265 mov r0, #0
266 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
267 mcr p15, 0, r0, c7, c10, 4 @ drain WB
268 mov pc, lr
269
270/*
271 * dma_inv_range(start, end)
272 *
273 * Invalidate (discard) the specified virtual address range.
274 * May not write back any entries. If 'start' or 'end'
275 * are not cache line aligned, those lines must be written
276 * back.
277 *
278 * - start - virtual start address
279 * - end - virtual end address
280 *
281 * (same as v4wb)
282 */
283ENTRY(arm925_dma_inv_range)
284#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
285 tst r0, #CACHE_DLINESIZE - 1
286 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
287 tst r1, #CACHE_DLINESIZE - 1
288 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
289#endif
290 bic r0, r0, #CACHE_DLINESIZE - 1
2911: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
292 add r0, r0, #CACHE_DLINESIZE
293 cmp r0, r1
294 blo 1b
295 mcr p15, 0, r0, c7, c10, 4 @ drain WB
296 mov pc, lr
297
298/*
299 * dma_clean_range(start, end)
300 *
301 * Clean the specified virtual address range.
302 *
303 * - start - virtual start address
304 * - end - virtual end address
305 *
306 * (same as v4wb)
307 */
308ENTRY(arm925_dma_clean_range)
309#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
310 bic r0, r0, #CACHE_DLINESIZE - 1
3111: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
312 add r0, r0, #CACHE_DLINESIZE
313 cmp r0, r1
314 blo 1b
315#endif
316 mcr p15, 0, r0, c7, c10, 4 @ drain WB
317 mov pc, lr
318
319/*
320 * dma_flush_range(start, end)
321 *
322 * Clean and invalidate the specified virtual address range.
323 *
324 * - start - virtual start address
325 * - end - virtual end address
326 */
327ENTRY(arm925_dma_flush_range)
328 bic r0, r0, #CACHE_DLINESIZE - 1
3291:
330#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
331 mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
332#else
333 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
334#endif
335 add r0, r0, #CACHE_DLINESIZE
336 cmp r0, r1
337 blo 1b
338 mcr p15, 0, r0, c7, c10, 4 @ drain WB
339 mov pc, lr
340
341ENTRY(arm925_cache_fns)
342 .long arm925_flush_kern_cache_all
343 .long arm925_flush_user_cache_all
344 .long arm925_flush_user_cache_range
345 .long arm925_coherent_kern_range
346 .long arm925_coherent_user_range
347 .long arm925_flush_kern_dcache_page
348 .long arm925_dma_inv_range
349 .long arm925_dma_clean_range
350 .long arm925_dma_flush_range
351
352ENTRY(cpu_arm925_dcache_clean_area)
353#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
3541: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
355 add r0, r0, #CACHE_DLINESIZE
356 subs r1, r1, #CACHE_DLINESIZE
357 bhi 1b
358#endif
359 mcr p15, 0, r0, c7, c10, 4 @ drain WB
360 mov pc, lr
361
362/* =============================== PageTable ============================== */
363
364/*
365 * cpu_arm925_switch_mm(pgd)
366 *
367 * Set the translation base pointer to be as described by pgd.
368 *
369 * pgd: new page tables
370 */
371 .align 5
372ENTRY(cpu_arm925_switch_mm)
373 mov ip, #0
374#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
375 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
376#else
377 /* Flush entries in bothe segments at once, see NOTE1 above */
378 mov r3, #(CACHE_DENTRIES - 1) << 4 @ 256 entries in segment
3792: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
380 subs r3, r3, #1 << 4
381 bcs 2b @ entries 255 to 0
382#endif
383 mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
384 mcr p15, 0, ip, c7, c10, 4 @ drain WB
385 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
386 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
387 mov pc, lr
388
389/*
390 * cpu_arm925_set_pte(ptep, pte)
391 *
392 * Set a PTE and flush it out
393 */
394 .align 5
395ENTRY(cpu_arm925_set_pte)
396 str r1, [r0], #-2048 @ linux version
397
398 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
399
400 bic r2, r1, #PTE_SMALL_AP_MASK
401 bic r2, r2, #PTE_TYPE_MASK
402 orr r2, r2, #PTE_TYPE_SMALL
403
404 tst r1, #L_PTE_USER @ User?
405 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
406
407 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
408 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
409
410 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
411 movne r2, #0
412
413#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
414 eor r3, r2, #0x0a @ C & small page?
415 tst r3, #0x0b
416 biceq r2, r2, #4
417#endif
418 str r2, [r0] @ hardware version
419 mov r0, r0
420#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
421 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
422#endif
423 mcr p15, 0, r0, c7, c10, 4 @ drain WB
424 mov pc, lr
425
426 __INIT
427
428 .type __arm925_setup, #function
429__arm925_setup:
430 mov r0, #0
431#if defined(CONFIG_CPU_ICACHE_STREAMING_DISABLE)
432 orr r0,r0,#1 << 7
433#endif
434
435 /* Transparent on, D-cache clean & flush mode. See NOTE2 above */
436 orr r0,r0,#1 << 1 @ transparent mode on
437 mcr p15, 0, r0, c15, c1, 0 @ write TI config register
438
439 mov r0, #0
440 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
441 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
442 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
443
444#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
445 mov r0, #4 @ disable write-back on caches explicitly
446 mcr p15, 7, r0, c15, c0, 0
447#endif
448
449 mrc p15, 0, r0, c1, c0 @ get control register v4
450 ldr r5, arm925_cr1_clear
451 bic r0, r0, r5
452 ldr r5, arm925_cr1_set
453 orr r0, r0, r5
454#ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
455 orr r0, r0, #0x4000 @ .1.. .... .... ....
456#endif
457 mov pc, lr
458 .size __arm925_setup, . - __arm925_setup
459
460 /*
461 * R
462 * .RVI ZFRS BLDP WCAM
463 * .011 0001 ..11 1101
464 *
465 */
466 .type arm925_cr1_clear, #object
467 .type arm925_cr1_set, #object
468arm925_cr1_clear:
469 .word 0x7f3f
470arm925_cr1_set:
471 .word 0x313d
472
473 __INITDATA
474
475/*
476 * Purpose : Function pointers used to access above functions - all calls
477 * come through these
478 */
479 .type arm925_processor_functions, #object
480arm925_processor_functions:
481 .word v4t_early_abort
482 .word cpu_arm925_proc_init
483 .word cpu_arm925_proc_fin
484 .word cpu_arm925_reset
485 .word cpu_arm925_do_idle
486 .word cpu_arm925_dcache_clean_area
487 .word cpu_arm925_switch_mm
488 .word cpu_arm925_set_pte
489 .size arm925_processor_functions, . - arm925_processor_functions
490
491 .section ".rodata"
492
493 .type cpu_arch_name, #object
494cpu_arch_name:
495 .asciz "armv4t"
496 .size cpu_arch_name, . - cpu_arch_name
497
498 .type cpu_elf_name, #object
499cpu_elf_name:
500 .asciz "v4"
501 .size cpu_elf_name, . - cpu_elf_name
502
503 .type cpu_arm925_name, #object
504cpu_arm925_name:
505 .ascii "ARM925T"
506#ifndef CONFIG_CPU_ICACHE_DISABLE
507 .ascii "i"
508#endif
509#ifndef CONFIG_CPU_DCACHE_DISABLE
510 .ascii "d"
511#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
512 .ascii "(wt)"
513#else
514 .ascii "(wb)"
515#endif
516#ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
517 .ascii "RR"
518#endif
519#endif
520 .ascii "\0"
521 .size cpu_arm925_name, . - cpu_arm925_name
522
523 .align
524
Ben Dooks02b7dd12005-09-20 16:35:03 +0100525 .section ".proc.info.init", #alloc, #execinstr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 .type __arm925_proc_info,#object
528__arm925_proc_info:
529 .long 0x54029250
530 .long 0xfffffff0
531 .long PMD_TYPE_SECT | \
532 PMD_BIT4 | \
533 PMD_SECT_AP_WRITE | \
534 PMD_SECT_AP_READ
535 b __arm925_setup
536 .long cpu_arch_name
537 .long cpu_elf_name
538 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
539 .long cpu_arm925_name
540 .long arm925_processor_functions
541 .long v4wbi_tlb_fns
542 .long v4wb_user_fns
543 .long arm925_cache_fns
544 .size __arm925_proc_info, . - __arm925_proc_info
545
546 .type __arm915_proc_info,#object
547__arm915_proc_info:
548 .long 0x54029150
549 .long 0xfffffff0
550 .long PMD_TYPE_SECT | \
551 PMD_BIT4 | \
552 PMD_SECT_AP_WRITE | \
553 PMD_SECT_AP_READ
554 b __arm925_setup
555 .long cpu_arch_name
556 .long cpu_elf_name
557 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
558 .long cpu_arm925_name
559 .long arm925_processor_functions
560 .long v4wbi_tlb_fns
561 .long v4wb_user_fns
562 .long arm925_cache_fns
563 .size __arm925_proc_info, . - __arm925_proc_info