2 * linux/arch/arm/mm/proc-arm922.S: MMU functions for ARM922
4 * Copyright (C) 1999,2000 ARM Limited
5 * Copyright (C) 2000 Deep Blue Solutions Ltd.
6 * Copyright (C) 2001 Altera Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * These are the low level assembler for performing cache and TLB
24 * functions on the arm922.
26 * CONFIG_CPU_ARM922_CPU_IDLE -> nohlt
28 #include <linux/linkage.h>
29 #include <linux/config.h>
30 #include <linux/init.h>
31 #include <asm/assembler.h>
32 #include <asm/pgtable.h>
33 #include <asm/procinfo.h>
34 #include <asm/hardware.h>
36 #include <asm/ptrace.h>
37 #include "proc-macros.S"
40 * The size of one data cache line.
42 #if 0 /* mask by Victor Yu. 05-30-2005 */
43 #define CACHE_DLINESIZE 32
44 #else /* add by Victor Yu. 05-30-2005 */
45 #define CACHE_DLINESIZE 16
46 #define CACHE_DSIZE 16384
47 #define CACHE_ISIZE 16384
48 #define CACHE_ILINESIZE 16
52 * The number of data cache segments.
54 #define CACHE_DSEGMENTS 4
57 * The number of lines in a cache segment.
59 #define CACHE_DENTRIES 64
62 * This is the size at which it becomes more efficient to
63 * clean the whole cache, rather than using the individual
64 * cache line maintainence instructions. (I think this should
67 #define CACHE_DLIMIT 8192
72 * cpu_arm922_proc_init()
74 ENTRY(cpu_arm922_proc_init)
78 * cpu_arm922_proc_fin()
80 ENTRY(cpu_arm922_proc_fin)
82 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
84 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
85 bl arm922_flush_kern_cache_all
87 bl v4wt_flush_kern_cache_all
89 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
90 bic r0, r0, #0x1000 @ ...i............
91 bic r0, r0, #0x000e @ ............wca.
92 mcr p15, 0, r0, c1, c0, 0 @ disable caches
96 * cpu_arm922_reset(loc)
98 * Perform a soft reset of the system. Put the CPU into the
99 * same state as it would be if it had been reset, and branch
100 * to what would be the reset vector.
102 * loc: location to jump to for soft reset
105 ENTRY(cpu_arm922_reset)
107 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
108 mcr p15, 0, ip, c7, c10, 4 @ drain WB
109 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
110 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
111 bic ip, ip, #0x000f @ ............wcam
112 bic ip, ip, #0x1100 @ ...i...s........
113 #if 1 /* add by Victor Yu. 06-09-2005 */
114 #ifdef CONFIG_ARCH_MOXACPU
115 bic ip, ip, #0x0800 @ off BTB
118 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
119 #if 1 /* add by Victor Yu. 06-09-2005 */
120 #ifdef CONFIG_ARCH_MOXACPU
128 * cpu_arm922_do_idle()
131 ENTRY(cpu_arm922_do_idle)
132 #if 1 /* add by Victor Yu. 06-09-2005 */
133 #ifdef CONFIG_ARCH_MOXACPU
134 #ifdef CONFIG_CPU_FA_IDLE
137 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
138 #endif /* CONFIG_CPU_FA_IDLE */
139 #endif /* CONFIG_ARCH_MOXACPU */
144 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
147 * flush_user_cache_all()
149 * Clean and invalidate all cache entries in a particular
152 ENTRY(arm922_flush_user_cache_all)
156 * flush_kern_cache_all()
158 * Clean and invalidate the entire cache.
160 ENTRY(arm922_flush_kern_cache_all)
161 #if 0 /* mask by Victor Yu. 05-30-2005 */
165 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
166 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
167 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
168 subs r3, r3, #1 << 26
169 bcs 2b @ entries 63 to 0
171 bcs 1b @ segments 7 to 0
173 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
174 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
176 #else /* add by Victor Yu. 05-30-2005 */
179 #ifndef CONFIG_CPU_ICACHE_DISABLE
180 mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
185 #ifndef CONFIG_CPU_DCACHE_DISABLE
187 # ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
188 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
190 mcr p15, 0, ip, c7,c14, 0 @ clean/invalidate D cache
192 #endif /*CONFIG_CPU_DCACHE_DISABLE*/
194 #ifndef CONFIG_CPU_FA_WB_DISABLE
195 mcr p15, 0, ip, c7, c10, 4 @ drain write buffer
198 #ifdef CONFIG_CPU_FA_BTB
199 mcr p15, 0, ip, c7, c5, 6 @ invalidate BTB
207 * flush_user_cache_range(start, end, flags)
209 * Clean and invalidate a range of cache entries in the
210 * specified address range.
212 * - start - start address (inclusive)
213 * - end - end address (exclusive)
214 * - flags - vm_flags describing address space
216 ENTRY(arm922_flush_user_cache_range)
217 #if 0 /* mask by Victor Yu. 05-30-2005 */
219 sub r3, r1, r0 @ calculate total size
220 cmp r3, #CACHE_DLIMIT
221 bhs __flush_whole_cache
223 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
225 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
226 add r0, r0, #CACHE_DLINESIZE
230 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
232 #else /* add by Victor Yu. 05-30-2005 */
234 sub r3, r1, r0 @ calculate total size
235 #ifndef CONFIG_CPU_ICACHE_DISABLE
236 tst r2, #VM_EXEC @ executable region?
237 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
240 #ifndef CONFIG_CPU_DCACHE_DISABLE
241 cmp r3, #CACHE_DSIZE @ total size >= limit?
242 bhs __flush_whole_cache @ flush whole D cache
246 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
247 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
249 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
251 add r0, r0, #CACHE_DLINESIZE
254 #endif /* CONFIG_CPU_DCACHE_DISABLE */
256 #ifndef CONFIG_CPU_FA_WB_DISABLE
258 mcreq p15, 0, r4, c7, c10, 4 @ drain write buffer
261 #ifdef CONFIG_CPU_FA_BTB
264 mcrne p15, 0, ip, c7, c5, 6 @ invalidate BTB
272 * flush_kern_dcache_page(void *page)
274 * Ensure no D cache aliasing occurs, either with itself or
277 * - addr - page aligned address
279 ENTRY(arm922_flush_kern_dcache_page)
280 #if 0 /* mask by Victor Yu. 05-30-2005 */
282 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
283 add r0, r0, #CACHE_DLINESIZE
287 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
288 mcr p15, 0, r0, c7, c10, 4 @ drain WB
290 #else /* add by Victor Yu. 05-30-2005 */
296 * coherent_kern_range(start, end)
298 * Ensure coherency between the Icache and the Dcache in the
299 * region described by start, end. If you have non-snooping
300 * Harvard caches, you need to implement this function.
302 * - start - virtual start address
303 * - end - virtual end address
305 ENTRY(arm922_coherent_kern_range)
309 * coherent_user_range(start, end)
311 * Ensure coherency between the Icache and the Dcache in the
312 * region described by start, end. If you have non-snooping
313 * Harvard caches, you need to implement this function.
315 * - start - virtual start address
316 * - end - virtual end address
318 ENTRY(arm922_coherent_user_range)
319 #if 0 /* mask by Victor Yu. 06-09-2005 */
320 bic r0, r0, #CACHE_DLINESIZE - 1
321 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
322 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
323 add r0, r0, #CACHE_DLINESIZE
326 mcr p15, 0, r0, c7, c10, 4 @ drain WB
328 #else /* add by Victor Yu. 06-09-2005 */
329 bic r0, r0, #CACHE_DLINESIZE-1
331 #if !(defined(CONFIG_CPU_DCACHE_DISABLE) && defined(CONFIG_CPU_ICACHE_DISABLE))
333 #ifndef CONFIG_CPU_DCACHE_DISABLE
334 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
335 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
337 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
339 #endif /* CONFIG_CPU_DCACHE_DISABLE */
341 #ifndef CONFIG_CPU_ICACHE_DISABLE
342 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
344 add r0, r0, #CACHE_DLINESIZE
346 bls 1b @ Luke Lee 05/19/2005 blo->bls
347 #endif /* !(defined(CONFIG_CPU_DCACHE_DISABLE) && defined(CONFIG_CPU_ICACHE_DISABLE)) */
350 #ifdef CONFIG_CPU_FA_BTB
351 mcr p15, 0, ip, c7, c5, 6 @ invalidate BTB
356 #ifndef CONFIG_CPU_FA_WB_DISABLE
357 mcr p15, 0, ip, c7, c10, 4 @ drain WB
364 * dma_inv_range(start, end)
366 * Invalidate (discard) the specified virtual address range.
367 * May not write back any entries. If 'start' or 'end'
368 * are not cache line aligned, those lines must be written
371 * - start - virtual start address
372 * - end - virtual end address
376 ENTRY(arm922_dma_inv_range)
377 #if 1 /* mask by Victor Yu. 05-30-2005 */
378 tst r0, #CACHE_DLINESIZE - 1
379 bic r0, r0, #CACHE_DLINESIZE - 1
380 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
381 tst r1, #CACHE_DLINESIZE - 1
382 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
383 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
384 add r0, r0, #CACHE_DLINESIZE
387 mcr p15, 0, r0, c7, c10, 4 @ drain WB
389 #else /* add by Victor Yu. 05-30-2005 */
390 #ifndef CONFIG_CPU_DCACHE_DISABLE
392 # ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
393 tst r0, #CACHE_DLINESIZE -1
394 bic r0, r0, #CACHE_DLINESIZE -1
395 mcrne p15, 0, r0, c7, c10, 1 @ clean boundary D entry
396 mcr p15, 0, r1, c7, c10, 1 @ clean boundary D entry
398 bic r0, r0, #CACHE_DLINESIZE -1
399 # endif /* CONFIG_CPU_DCACHE_WRITETHROUGH */
401 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
402 add r0, r0, #CACHE_DLINESIZE
404 bls 1b @ Luke Lee 05/19/2005 blo->bls
405 #endif /* CONFIG_CPU_DCACHE_DISABLE */
407 #ifndef CONFIG_CPU_FA_WB_DISABLE
409 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
415 * dma_clean_range(start, end)
417 * Clean the specified virtual address range.
419 * - start - virtual start address
420 * - end - virtual end address
424 ENTRY(arm922_dma_clean_range)
425 #if 0 /* mask by Victor Yu. 05-30-2005 */
426 bic r0, r0, #CACHE_DLINESIZE - 1
427 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
428 add r0, r0, #CACHE_DLINESIZE
431 mcr p15, 0, r0, c7, c10, 4 @ drain WB
433 #else /* add by Victor Yu. 05-30-2005 */
434 #ifndef CONFIG_CPU_DCACHE_DISABLE
435 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
436 bic r0, r0, #CACHE_DLINESIZE - 1
437 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
438 add r0, r0, #CACHE_DLINESIZE
440 bls 1b @ Luke Lee 05/19/2005 blo->bls
442 #endif /* CONFIG_CPU_DCACHE_WRITETHROUGH */
443 #endif /* CONFIG_CPU_DCACHE_DISABLE */
445 #ifndef CONFIG_CPU_FA_WB_DISABLE
447 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
453 * dma_flush_range(start, end)
455 * Clean and invalidate the specified virtual address range.
457 * - start - virtual start address
458 * - end - virtual end address
460 ENTRY(arm922_dma_flush_range)
461 #if 0 /* mask by Victor Yu. 06-09-2005 */
462 bic r0, r0, #CACHE_DLINESIZE - 1
463 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
464 add r0, r0, #CACHE_DLINESIZE
467 mcr p15, 0, r0, c7, c10, 4 @ drain WB
469 #else /* add by Victor Yu. 06-09-2005 */
470 .globl arm922_dma_flush_range
471 .set arm922_dma_flush_range, arm922_coherent_kern_range
474 ENTRY(arm922_cache_fns)
475 .long arm922_flush_kern_cache_all
476 .long arm922_flush_user_cache_all
477 .long arm922_flush_user_cache_range
478 .long arm922_coherent_kern_range
479 .long arm922_coherent_user_range
480 .long arm922_flush_kern_dcache_page
481 .long arm922_dma_inv_range
482 .long arm922_dma_clean_range
483 .long arm922_dma_flush_range
484 #if 1 /* add by Victor Yu. 06-09-2005 */
485 .size arm922_cache_fns, . - arm922_cache_fns
490 ENTRY(cpu_arm922_dcache_clean_area)
491 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
492 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
493 add r0, r0, #CACHE_DLINESIZE
494 subs r1, r1, #CACHE_DLINESIZE
499 /* =============================== PageTable ============================== */
502 * cpu_arm922_switch_mm(pgd)
504 * Set the translation base pointer to be as described by pgd.
506 * pgd: new page tables
509 ENTRY(cpu_arm922_switch_mm)
511 #if 0 /* mask by Victor Yu. 06-09-2005 */
512 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
513 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
515 @ && 'Clean & Invalidate whole DCache'
516 @ && Re-written to use Index Ops.
517 @ && Uses registers r1, r3 and ip
519 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 4 segments
520 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
521 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
522 subs r3, r3, #1 << 26
523 bcs 2b @ entries 63 to 0
525 bcs 1b @ segments 7 to 0
526 #endif /* CONFIG_CPU_DCACHE_WRITETHROUGH */
527 #else /* add by Victor Yu. 06-09-2005 */
528 #ifndef CONFIG_CPU_DCACHE_DISABLE
529 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
530 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
532 mcr p15, 0, ip, c7, c14, 0 @ Clean and invalidate whole DCache
533 #endif /* CONFIG_CPU_DCACHE_WRITETHROUGH */
534 #endif /*CONFIG_CPU_DCACHE_DISABLE*/
536 mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
537 mcr p15, 0, ip, c7, c10, 4 @ drain WB
538 #if 1 /* add by Victor Yu. 06-09-2005 */
539 #ifdef CONFIG_ARCH_MOXACPU
540 bic r0, r0, #0xff @ clear bits [7:0]
541 bic r0, r0, #0x3f00 @ clear bits [13:8]
544 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
545 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
546 #if 1 /* add by Victor Yu. 06-09-2005 */
547 #ifdef CONFIG_ARCH_MOXACPU
555 * cpu_arm922_set_pte(ptep, pte)
557 * Set a PTE and flush it out
560 ENTRY(cpu_arm922_set_pte)
561 str r1, [r0], #-2048 @ linux version
563 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
565 bic r2, r1, #PTE_SMALL_AP_MASK
566 bic r2, r2, #PTE_TYPE_MASK
567 orr r2, r2, #PTE_TYPE_SMALL
569 tst r1, #L_PTE_USER @ User?
570 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
572 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
573 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
575 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
578 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
579 eor r3, r2, #0x0a @ C & small page?
583 str r2, [r0] @ hardware version
584 #if 0 /* mask by Victor Yu. 06-09-2005 */
586 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
587 mcr p15, 0, r0, c7, c10, 4 @ drain WB
588 #else // add by Victor Yu. 06-09-2005 */
590 mcr p15, 0, r2, c7, c10, 0 @ clean D cache all
596 .type __arm922_setup, #function
599 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
600 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
601 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
602 #if 1 /* add by Victor Yu. 06-09-2005 */
603 #ifdef CONFIG_ARCH_MOXACPU
604 mcr p15, 0, r0, c7, c5, 5 @ invalidate IScratchpad RAM
605 mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB all
608 mcr p15, 0, r0, c1, c1, 0 @ turn-on ECR
610 mrc p15, 0, r0, c9, c1, 0 @ DScratchpad
612 mcr p15, 0, r0, c9, c1, 0 @ disable it
613 mrc p15, 0, r0, c9, c1, 1 @ IScratchpad
615 mcr p15, 0, r0, c9, c1, 1 @ disable it
617 mrc p15, 0, r0, c1, c0, 0 @ get control register v4
619 mcr p15, 0, r0, c1, c0, 0 @ disable it
622 mcr p15, 0, r0, c1, c1, 0 @ turn-off ECR
623 #endif /* CONFIG_ARCH_MOXACPU */
625 mcr p15, 0, r4, c2, c0 @ load page table pointer
626 mov r0, #0x1f @ Domains 0, 1 = client
627 mcr p15, 0, r0, c3, c0 @ load domain access register
628 mrc p15, 0, r0, c1, c0 @ get control register v4
630 * Clear out 'unwanted' bits (then put them in if we need them)
636 bic r0, r0, #0x1000 @ ...0 000. .... 000.
638 * Turn on what we want
641 orr r0, r0, #0x2100 @ ..1. ...1 ..11 ...1
643 #ifndef CONFIG_CPU_DCACHE_DISABLE
644 orr r0, r0, #0x0004 @ .... .... .... .1..
646 #ifndef CONFIG_CPU_ICACHE_DISABLE
647 orr r0, r0, #0x1000 @ ...1 .... .... ....
650 .size __arm922_setup, . - __arm922_setup
655 * Purpose : Function pointers used to access above functions - all calls
658 .type arm922_processor_functions, #object
659 arm922_processor_functions:
660 #if 0 /* mask by Victor Yu. 06-08-2005 */
661 .word v4t_early_abort
662 #else /* add by Victor YU. 06-08-2005 */
665 .word cpu_arm922_proc_init
666 .word cpu_arm922_proc_fin
667 .word cpu_arm922_reset
668 .word cpu_arm922_do_idle
669 .word cpu_arm922_dcache_clean_area
670 .word cpu_arm922_switch_mm
671 .word cpu_arm922_set_pte
672 .size arm922_processor_functions, . - arm922_processor_functions
676 .type cpu_arch_name, #object
679 .size cpu_arch_name, . - cpu_arch_name
681 .type cpu_elf_name, #object
684 .size cpu_elf_name, . - cpu_elf_name
686 .type cpu_arm922_name, #object
689 #ifndef CONFIG_CPU_ICACHE_DISABLE
692 #ifndef CONFIG_CPU_DCACHE_DISABLE
694 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
701 .size cpu_arm922_name, . - cpu_arm922_name
705 .section ".proc.info", #alloc, #execinstr
707 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
708 #define __PMD_SECT_BUFFERABLE 0
710 #define __PMD_SECT_BUFFERABLE PMD_SECT_BUFFERABLE
712 .type __arm922_proc_info,#object
714 #ifdef CONFIG_ARCH_MOXACPU /* add by Victor Yu. 05-23-2005 */
718 .long PMD_TYPE_SECT | \
719 __PMD_SECT_BUFFERABLE | \
720 PMD_SECT_CACHEABLE | \
722 PMD_SECT_AP_WRITE | \
727 #else /* mask by Victor Yu. 05-23-2005 */
730 .long 0x00000c1e @ mmuflags
731 #endif /* CONFIG_ARCH_MOXACPU */
735 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
736 .long cpu_arm922_name
737 .long arm922_processor_functions
740 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
741 .long arm922_cache_fns
745 .size __arm922_proc_info, . - __arm922_proc_info