2 * linux/arch/arm/mm/proc-xscale.S
4 * Author: Nicolas Pitre
5 * Created: November 2000
6 * Copyright: (C) 2000, 2001 MontaVista Software Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * MMU functions for the Intel XScale CPUs
15 * some contributions by Brett Gaines <brett.w.gaines@intel.com>
16 * Copyright 2001 by Intel Corp.
19 * Completely revisited, many important fixes
20 * Nicolas Pitre <nico@cam.org>
23 #include <linux/linkage.h>
24 #include <linux/init.h>
25 #include <asm/assembler.h>
26 #include <asm/procinfo.h>
27 #include <asm/hardware.h>
28 #include <asm/pgtable-hwdef.h>
29 #include <asm/pgtable.h>
31 #include <asm/ptrace.h>
32 #include "proc-macros.S"
35 * This is the maximum size of an area which will be flushed. If the area
36 * is larger than this, then we flush the whole cache
38 #define MAX_AREA_SIZE 32768
41 * the cache line size of the I and D cache
43 #define CACHELINESIZE 32
46 * the size of the data cache
48 #define CACHESIZE 32768
51 * Virtual address used to allocate the cache when flushed
53 * This must be an address range which is _never_ used. It should
54 * apparently have a mapping in the corresponding page table for
55 * compatibility with future CPUs that _could_ require it. For instance we
58 * This must be aligned on a 2*CACHESIZE boundary. The code selects one of
59 * the 2 areas in alternance each time the clean_d_cache macro is used.
60 * Without this the XScale core exhibits cache eviction problems and no one
63 * Reminder: the vector table is located at 0xffff0000-0xffff0fff.
65 #define CLEAN_ADDR 0xfffe0000
68 * This macro is used to wait for a CP15 write and is needed
69 * when we have to ensure that the last operation to the co-pro
70 * was completed before continuing with operation.
73 mrc p15, 0, \rd, c2, c0, 0 @ arbitrary read of cp15
74 mov \rd, \rd @ wait for completion
75 sub pc, pc, #4 @ flush instruction pipeline
78 .macro cpwait_ret, lr, rd
79 mrc p15, 0, \rd, c2, c0, 0 @ arbitrary read of cp15
80 sub pc, \lr, \rd, LSR #32 @ wait for completion and
81 @ flush instruction pipeline
85 * This macro cleans the entire dcache using line allocate.
86 * The main loop has been unrolled to reduce loop overhead.
87 * rd and rs are two scratch registers.
89 .macro clean_d_cache, rd, rs
92 eor \rd, \rd, #CACHESIZE
94 add \rs, \rd, #CACHESIZE
95 1: mcr p15, 0, \rd, c7, c2, 5 @ allocate D cache line
96 add \rd, \rd, #CACHELINESIZE
97 mcr p15, 0, \rd, c7, c2, 5 @ allocate D cache line
98 add \rd, \rd, #CACHELINESIZE
99 mcr p15, 0, \rd, c7, c2, 5 @ allocate D cache line
100 add \rd, \rd, #CACHELINESIZE
101 mcr p15, 0, \rd, c7, c2, 5 @ allocate D cache line
102 add \rd, \rd, #CACHELINESIZE
108 clean_addr: .word CLEAN_ADDR
113 * cpu_xscale_proc_init()
115 * Nothing too exciting at the moment
117 ENTRY(cpu_xscale_proc_init)
121 * cpu_xscale_proc_fin()
123 ENTRY(cpu_xscale_proc_fin)
125 mov r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
127 bl xscale_flush_kern_cache_all @ clean caches
128 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
129 bic r0, r0, #0x1800 @ ...IZ...........
130 bic r0, r0, #0x0006 @ .............CA.
131 mcr p15, 0, r0, c1, c0, 0 @ disable caches
135 * cpu_xscale_reset(loc)
137 * Perform a soft reset of the system. Put the CPU into the
138 * same state as it would be if it had been reset, and branch
139 * to what would be the reset vector.
141 * loc: location to jump to for soft reset
144 ENTRY(cpu_xscale_reset)
145 mov r1, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
146 msr cpsr_c, r1 @ reset CPSR
147 mrc p15, 0, r1, c1, c0, 0 @ ctrl register
148 bic r1, r1, #0x0086 @ ........B....CA.
149 bic r1, r1, #0x3900 @ ..VIZ..S........
150 mcr p15, 0, r1, c1, c0, 0 @ ctrl register
151 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches & BTB
152 bic r1, r1, #0x0001 @ ...............M
153 mcr p15, 0, r1, c1, c0, 0 @ ctrl register
154 @ CAUTION: MMU turned off from this point. We count on the pipeline
155 @ already containing those two last instructions to survive.
156 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
160 * cpu_xscale_do_idle()
162 * Cause the processor to idle
164 * For now we do nothing but go to idle mode for every case
166 * XScale supports clock switching, but using idle mode support
167 * allows external hardware to react to system state changes.
171 ENTRY(cpu_xscale_do_idle)
173 mcr p14, 0, r0, c7, c0, 0 @ Go to IDLE
176 /* ================================= CACHE ================================ */
179 * flush_user_cache_all()
181 * Invalidate all cache entries in a particular address
184 ENTRY(xscale_flush_user_cache_all)
188 * flush_kern_cache_all()
190 * Clean and invalidate the entire cache.
192 ENTRY(xscale_flush_kern_cache_all)
198 mcrne p15, 0, ip, c7, c5, 0 @ Invalidate I cache & BTB
199 mcrne p15, 0, ip, c7, c10, 4 @ Drain Write (& Fill) Buffer
203 * flush_user_cache_range(start, end, vm_flags)
205 * Invalidate a range of cache entries in the specified
208 * - start - start address (may not be aligned)
209 * - end - end address (exclusive, may not be aligned)
210 * - vma - vma_area_struct describing address space
213 ENTRY(xscale_flush_user_cache_range)
215 sub r3, r1, r0 @ calculate total size
216 cmp r3, #MAX_AREA_SIZE
217 bhs __flush_whole_cache
220 mcrne p15, 0, r0, c7, c5, 1 @ Invalidate I cache line
221 mcr p15, 0, r0, c7, c10, 1 @ Clean D cache line
222 mcr p15, 0, r0, c7, c6, 1 @ Invalidate D cache line
223 add r0, r0, #CACHELINESIZE
227 mcrne p15, 0, ip, c7, c5, 6 @ Invalidate BTB
228 mcrne p15, 0, ip, c7, c10, 4 @ Drain Write (& Fill) Buffer
232 * coherent_kern_range(start, end)
234 * Ensure coherency between the Icache and the Dcache in the
235 * region described by start. If you have non-snooping
236 * Harvard caches, you need to implement this function.
238 * - start - virtual start address
239 * - end - virtual end address
241 * Note: single I-cache line invalidation isn't used here since
242 * it also trashes the mini I-cache used by JTAG debuggers.
244 ENTRY(xscale_coherent_kern_range)
245 bic r0, r0, #CACHELINESIZE - 1
246 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
247 add r0, r0, #CACHELINESIZE
251 mcr p15, 0, r0, c7, c5, 0 @ Invalidate I cache & BTB
252 mcr p15, 0, r0, c7, c10, 4 @ Drain Write (& Fill) Buffer
256 * coherent_user_range(start, end)
258 * Ensure coherency between the Icache and the Dcache in the
259 * region described by start. If you have non-snooping
260 * Harvard caches, you need to implement this function.
262 * - start - virtual start address
263 * - end - virtual end address
265 ENTRY(xscale_coherent_user_range)
266 bic r0, r0, #CACHELINESIZE - 1
267 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
268 mcr p15, 0, r0, c7, c5, 1 @ Invalidate I cache entry
269 add r0, r0, #CACHELINESIZE
273 mcr p15, 0, r0, c7, c5, 6 @ Invalidate BTB
274 mcr p15, 0, r0, c7, c10, 4 @ Drain Write (& Fill) Buffer
278 * flush_kern_dcache_page(void *page)
280 * Ensure no D cache aliasing occurs, either with itself or
283 * - addr - page aligned address
285 ENTRY(xscale_flush_kern_dcache_page)
287 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
288 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
289 add r0, r0, #CACHELINESIZE
293 mcr p15, 0, r0, c7, c5, 0 @ Invalidate I cache & BTB
294 mcr p15, 0, r0, c7, c10, 4 @ Drain Write (& Fill) Buffer
298 * dma_inv_range(start, end)
300 * Invalidate (discard) the specified virtual address range.
301 * May not write back any entries. If 'start' or 'end'
302 * are not cache line aligned, those lines must be written
305 * - start - virtual start address
306 * - end - virtual end address
308 ENTRY(xscale_dma_inv_range)
309 mrc p15, 0, r2, c0, c0, 0 @ read ID
310 eor r2, r2, #0x69000000
311 eor r2, r2, #0x00052000
313 beq xscale_dma_flush_range
315 tst r0, #CACHELINESIZE - 1
316 bic r0, r0, #CACHELINESIZE - 1
317 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
318 tst r1, #CACHELINESIZE - 1
319 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
320 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
321 add r0, r0, #CACHELINESIZE
324 mcr p15, 0, r0, c7, c10, 4 @ Drain Write (& Fill) Buffer
328 * dma_clean_range(start, end)
330 * Clean the specified virtual address range.
332 * - start - virtual start address
333 * - end - virtual end address
335 ENTRY(xscale_dma_clean_range)
336 bic r0, r0, #CACHELINESIZE - 1
337 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
338 add r0, r0, #CACHELINESIZE
341 mcr p15, 0, r0, c7, c10, 4 @ Drain Write (& Fill) Buffer
345 * dma_flush_range(start, end)
347 * Clean and invalidate the specified virtual address range.
349 * - start - virtual start address
350 * - end - virtual end address
352 ENTRY(xscale_dma_flush_range)
353 bic r0, r0, #CACHELINESIZE - 1
354 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
355 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
356 add r0, r0, #CACHELINESIZE
359 mcr p15, 0, r0, c7, c10, 4 @ Drain Write (& Fill) Buffer
362 ENTRY(xscale_cache_fns)
363 .long xscale_flush_kern_cache_all
364 .long xscale_flush_user_cache_all
365 .long xscale_flush_user_cache_range
366 .long xscale_coherent_kern_range
367 .long xscale_coherent_user_range
368 .long xscale_flush_kern_dcache_page
369 .long xscale_dma_inv_range
370 .long xscale_dma_clean_range
371 .long xscale_dma_flush_range
373 ENTRY(cpu_xscale_dcache_clean_area)
374 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
375 add r0, r0, #CACHELINESIZE
376 subs r1, r1, #CACHELINESIZE
380 /* =============================== PageTable ============================== */
382 #define PTE_CACHE_WRITE_ALLOCATE 0
385 * cpu_xscale_switch_mm(pgd)
387 * Set the translation base pointer to be as described by pgd.
389 * pgd: new page tables
392 ENTRY(cpu_xscale_switch_mm)
394 mcr p15, 0, ip, c7, c5, 0 @ Invalidate I cache & BTB
395 mcr p15, 0, ip, c7, c10, 4 @ Drain Write (& Fill) Buffer
396 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
397 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
401 * cpu_xscale_set_pte(ptep, pte)
403 * Set a PTE and flush it out
405 * Errata 40: must set memory to write-through for user read-only pages.
408 ENTRY(cpu_xscale_set_pte)
409 str r1, [r0], #-2048 @ linux version
412 orr r2, r2, #PTE_TYPE_EXT @ extended page
414 eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
416 tst r3, #L_PTE_USER @ User?
417 orrne r2, r2, #PTE_EXT_AP_URO_SRW @ yes -> user r/o, system r/w
419 tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
420 orreq r2, r2, #PTE_EXT_AP_UNO_SRW @ yes -> user n/a, system r/w
421 @ combined with user -> user r/w
424 @ Handle the X bit. We want to set this bit for the minicache
425 @ (U = E = B = W = 0, C = 1) or when write allocate is enabled,
426 @ and we have a writeable, cacheable region. If we ignore the
427 @ U and E bits, we can allow user space to use the minicache as
430 @ X = (C & ~W & ~B) | (C & W & B & write_allocate)
432 eor ip, r1, #L_PTE_CACHEABLE
433 tst ip, #L_PTE_CACHEABLE | L_PTE_WRITE | L_PTE_BUFFERABLE
434 #if PTE_CACHE_WRITE_ALLOCATE
435 eorne ip, r1, #L_PTE_CACHEABLE | L_PTE_WRITE | L_PTE_BUFFERABLE
436 tstne ip, #L_PTE_CACHEABLE | L_PTE_WRITE | L_PTE_BUFFERABLE
438 orreq r2, r2, #PTE_EXT_TEX(1)
441 @ Erratum 40: The B bit must be cleared for a user read-only
444 @ B = B & ~(U & C & ~W)
446 and ip, r1, #L_PTE_USER | L_PTE_WRITE | L_PTE_CACHEABLE
447 teq ip, #L_PTE_USER | L_PTE_CACHEABLE
448 biceq r2, r2, #PTE_BUFFERABLE
450 tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
451 movne r2, #0 @ no -> fault
453 str r2, [r0] @ hardware version
455 mcr p15, 0, r0, c7, c10, 1 @ Clean D cache line
456 mcr p15, 0, ip, c7, c10, 4 @ Drain Write (& Fill) Buffer
466 .type __xscale_setup, #function
468 mcr p15, 0, ip, c7, c7, 0 @ invalidate I, D caches & BTB
469 mcr p15, 0, ip, c7, c10, 4 @ Drain Write (& Fill) Buffer
470 mcr p15, 0, ip, c8, c7, 0 @ invalidate I, D TLBs
472 mov r0, #0 @ initially disallow access to CP0/CP1
474 mov r0, #1 @ Allow access to CP0
476 orr r0, r0, #1 << 6 @ cp6 for IOP3xx and Bulverde
477 orr r0, r0, #1 << 13 @ Its undefined whether this
478 mcr p15, 0, r0, c15, c1, 0 @ affects USR or SVC modes
479 mrc p15, 0, r0, c1, c0, 0 @ get control register
480 ldr r5, xscale_cr1_clear
482 ldr r5, xscale_cr1_set
485 .size __xscale_setup, . - __xscale_setup
489 * .RVI ZFRS BLDP WCAM
490 * ..11 1.01 .... .101
493 .type xscale_cr1_clear, #object
494 .type xscale_cr1_set, #object
503 * Purpose : Function pointers used to access above functions - all calls
507 .type xscale_processor_functions, #object
508 ENTRY(xscale_processor_functions)
509 .word v5t_early_abort
510 .word cpu_xscale_proc_init
511 .word cpu_xscale_proc_fin
512 .word cpu_xscale_reset
513 .word cpu_xscale_do_idle
514 .word cpu_xscale_dcache_clean_area
515 .word cpu_xscale_switch_mm
516 .word cpu_xscale_set_pte
517 .size xscale_processor_functions, . - xscale_processor_functions
521 .type cpu_arch_name, #object
524 .size cpu_arch_name, . - cpu_arch_name
526 .type cpu_elf_name, #object
529 .size cpu_elf_name, . - cpu_elf_name
531 .type cpu_80200_name, #object
533 .asciz "XScale-80200"
534 .size cpu_80200_name, . - cpu_80200_name
536 .type cpu_8032x_name, #object
538 .asciz "XScale-IOP8032x Family"
539 .size cpu_8032x_name, . - cpu_8032x_name
541 .type cpu_8033x_name, #object
543 .asciz "XScale-IOP8033x Family"
544 .size cpu_8033x_name, . - cpu_8033x_name
546 .type cpu_pxa250_name, #object
548 .asciz "XScale-PXA250"
549 .size cpu_pxa250_name, . - cpu_pxa250_name
551 .type cpu_pxa210_name, #object
553 .asciz "XScale-PXA210"
554 .size cpu_pxa210_name, . - cpu_pxa210_name
556 .type cpu_ixp42x_name, #object
558 .asciz "XScale-IXP42x Family"
559 .size cpu_ixp42x_name, . - cpu_ixp42x_name
561 .type cpu_ixp46x_name, #object
563 .asciz "XScale-IXP46x Family"
564 .size cpu_ixp46x_name, . - cpu_ixp46x_name
566 .type cpu_ixp2400_name, #object
568 .asciz "XScale-IXP2400"
569 .size cpu_ixp2400_name, . - cpu_ixp2400_name
571 .type cpu_ixp2800_name, #object
573 .asciz "XScale-IXP2800"
574 .size cpu_ixp2800_name, . - cpu_ixp2800_name
576 .type cpu_pxa255_name, #object
578 .asciz "XScale-PXA255"
579 .size cpu_pxa255_name, . - cpu_pxa255_name
581 .type cpu_pxa270_name, #object
583 .asciz "XScale-PXA270"
584 .size cpu_pxa270_name, . - cpu_pxa270_name
588 .section ".proc.info.init", #alloc, #execinstr
590 .type __80200_proc_info,#object
594 .long PMD_TYPE_SECT | \
595 PMD_SECT_BUFFERABLE | \
596 PMD_SECT_CACHEABLE | \
597 PMD_SECT_AP_WRITE | \
602 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
604 .long xscale_processor_functions
606 .long xscale_mc_user_fns
607 .long xscale_cache_fns
608 .size __80200_proc_info, . - __80200_proc_info
610 .type __8032x_proc_info,#object
613 .long 0xfffff5e0 @ mask should accomodate IOP80219 also
614 .long PMD_TYPE_SECT | \
615 PMD_SECT_BUFFERABLE | \
616 PMD_SECT_CACHEABLE | \
617 PMD_SECT_AP_WRITE | \
622 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
624 .long xscale_processor_functions
626 .long xscale_mc_user_fns
627 .long xscale_cache_fns
628 .size __8032x_proc_info, . - __8032x_proc_info
630 .type __8033x_proc_info,#object
634 .long PMD_TYPE_SECT | \
635 PMD_SECT_BUFFERABLE | \
636 PMD_SECT_CACHEABLE | \
637 PMD_SECT_AP_WRITE | \
642 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
644 .long xscale_processor_functions
646 .long xscale_mc_user_fns
647 .long xscale_cache_fns
648 .size __8033x_proc_info, . - __8033x_proc_info
650 .type __pxa250_proc_info,#object
654 .long PMD_TYPE_SECT | \
655 PMD_SECT_BUFFERABLE | \
656 PMD_SECT_CACHEABLE | \
657 PMD_SECT_AP_WRITE | \
662 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
663 .long cpu_pxa250_name
664 .long xscale_processor_functions
666 .long xscale_mc_user_fns
667 .long xscale_cache_fns
668 .size __pxa250_proc_info, . - __pxa250_proc_info
670 .type __pxa210_proc_info,#object
674 .long PMD_TYPE_SECT | \
675 PMD_SECT_BUFFERABLE | \
676 PMD_SECT_CACHEABLE | \
677 PMD_SECT_AP_WRITE | \
682 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
683 .long cpu_pxa210_name
684 .long xscale_processor_functions
686 .long xscale_mc_user_fns
687 .long xscale_cache_fns
688 .size __pxa210_proc_info, . - __pxa210_proc_info
690 .type __ixp2400_proc_info, #object
694 .long PMD_TYPE_SECT | \
695 PMD_SECT_BUFFERABLE | \
696 PMD_SECT_CACHEABLE | \
697 PMD_SECT_AP_WRITE | \
702 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
703 .long cpu_ixp2400_name
704 .long xscale_processor_functions
706 .long xscale_mc_user_fns
707 .long xscale_cache_fns
708 .size __ixp2400_proc_info, . - __ixp2400_proc_info
710 .type __ixp2800_proc_info, #object
714 .long PMD_TYPE_SECT | \
715 PMD_SECT_BUFFERABLE | \
716 PMD_SECT_CACHEABLE | \
717 PMD_SECT_AP_WRITE | \
722 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
723 .long cpu_ixp2800_name
724 .long xscale_processor_functions
726 .long xscale_mc_user_fns
727 .long xscale_cache_fns
728 .size __ixp2800_proc_info, . - __ixp2800_proc_info
730 .type __ixp42x_proc_info, #object
734 .long PMD_TYPE_SECT | \
735 PMD_SECT_BUFFERABLE | \
736 PMD_SECT_CACHEABLE | \
737 PMD_SECT_AP_WRITE | \
742 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
743 .long cpu_ixp42x_name
744 .long xscale_processor_functions
746 .long xscale_mc_user_fns
747 .long xscale_cache_fns
748 .size __ixp42x_proc_info, . - __ixp42x_proc_info
750 .type __ixp46x_proc_info, #object
758 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
759 .long cpu_ixp46x_name
760 .long xscale_processor_functions
762 .long xscale_mc_user_fns
763 .long xscale_cache_fns
764 .size __ixp46x_proc_info, . - __ixp46x_proc_info
766 .type __pxa255_proc_info,#object
770 .long PMD_TYPE_SECT | \
771 PMD_SECT_BUFFERABLE | \
772 PMD_SECT_CACHEABLE | \
773 PMD_SECT_AP_WRITE | \
778 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
779 .long cpu_pxa255_name
780 .long xscale_processor_functions
782 .long xscale_mc_user_fns
783 .long xscale_cache_fns
784 .size __pxa255_proc_info, . - __pxa255_proc_info
786 .type __pxa270_proc_info,#object
790 .long PMD_TYPE_SECT | \
791 PMD_SECT_BUFFERABLE | \
792 PMD_SECT_CACHEABLE | \
793 PMD_SECT_AP_WRITE | \
798 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
799 .long cpu_pxa270_name
800 .long xscale_processor_functions
802 .long xscale_mc_user_fns
803 .long xscale_cache_fns
804 .size __pxa270_proc_info, . - __pxa270_proc_info