2 * linux/arch/arm/mm/proc-xsc3.S
4 * Original Author: Matthew Gilbert
5 * Current Maintainer: Deepak Saxena <dsaxena@plexity.net>
7 * Copyright 2004 (C) Intel Corp.
8 * Copyright 2005 (c) MontaVista Software, Inc.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * MMU functions for the Intel XScale3 Core (XSC3). The XSC3 core is an
15 * extension to Intel's original XScale core that adds the following
18 * - ARMv6 Supersections
19 * - Low Locality Reference pages (replaces mini-cache)
22 * - Cache-coherency if chipset supports it
24 * Based on orignal XScale code by Nicolas Pitre
27 #include <linux/linkage.h>
28 #include <linux/init.h>
29 #include <asm/assembler.h>
30 #include <asm/procinfo.h>
31 #include <asm/hardware.h>
32 #include <asm/pgtable.h>
34 #include <asm/ptrace.h>
35 #include "proc-macros.S"
38 * This is the maximum size of an area which will be flushed. If the
39 * area is larger than this, then we flush the whole cache.
41 #define MAX_AREA_SIZE 32768
44 * The cache line size of the I and D cache.
46 #define CACHELINESIZE 32
49 * The size of the data cache.
51 #define CACHESIZE 32768
54 * Run with L2 enabled.
56 #define L2_CACHE_ENABLE 1
59 * Enable the Branch Target Buffer (can cause crashes, see erratum #42.)
64 * This macro is used to wait for a CP15 write and is needed
65 * when we have to ensure that the last operation to the co-pro
66 * was completed before continuing with operation.
68 .macro cpwait_ret, lr, rd
69 mrc p15, 0, \rd, c2, c0, 0 @ arbitrary read of cp15
70 sub pc, \lr, \rd, LSR #32 @ wait for completion and
71 @ flush instruction pipeline
75 * This macro cleans & invalidates the entire xsc3 dcache by set & way.
78 .macro clean_d_cache rd, rs
81 1: mcr p15, 0, \rd, c7, c14, 2 @ clean/inv set/way
82 adds \rd, \rd, #0x40000000
91 * cpu_xsc3_proc_init()
93 * Nothing too exciting at the moment
95 ENTRY(cpu_xsc3_proc_init)
101 ENTRY(cpu_xsc3_proc_fin)
103 mov r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
105 bl xsc3_flush_kern_cache_all @ clean caches
106 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
107 bic r0, r0, #0x1800 @ ...IZ...........
108 bic r0, r0, #0x0006 @ .............CA.
109 mcr p15, 0, r0, c1, c0, 0 @ disable caches
113 * cpu_xsc3_reset(loc)
115 * Perform a soft reset of the system. Put the CPU into the
116 * same state as it would be if it had been reset, and branch
117 * to what would be the reset vector.
119 * loc: location to jump to for soft reset
122 ENTRY(cpu_xsc3_reset)
123 mov r1, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
124 msr cpsr_c, r1 @ reset CPSR
125 mrc p15, 0, r1, c1, c0, 0 @ ctrl register
126 bic r1, r1, #0x0086 @ ........B....CA.
127 bic r1, r1, #0x3900 @ ..VIZ..S........
128 mcr p15, 0, r1, c1, c0, 0 @ ctrl register
129 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches & BTB
130 bic r1, r1, #0x0001 @ ...............M
131 mcr p15, 0, r1, c1, c0, 0 @ ctrl register
132 @ CAUTION: MMU turned off from this point. We count on the pipeline
133 @ already containing those two last instructions to survive.
134 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
140 * Cause the processor to idle
142 * For now we do nothing but go to idle mode for every case
144 * XScale supports clock switching, but using idle mode support
145 * allows external hardware to react to system state changes.
147 MMG: Come back to this one.
151 ENTRY(cpu_xsc3_do_idle)
153 mcr p14, 0, r0, c7, c0, 0 @ Go to IDLE
156 /* ================================= CACHE ================================ */
159 * flush_user_cache_all()
161 * Invalidate all cache entries in a particular address
164 ENTRY(xsc3_flush_user_cache_all)
168 * flush_kern_cache_all()
170 * Clean and invalidate the entire cache.
172 ENTRY(xsc3_flush_kern_cache_all)
178 mcrne p15, 0, ip, c7, c5, 0 @ Invalidate I cache & BTB
179 mcrne p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
180 mcrne p15, 0, ip, c7, c5, 4 @ Prefetch Flush
184 * flush_user_cache_range(start, end, vm_flags)
186 * Invalidate a range of cache entries in the specified
189 * - start - start address (may not be aligned)
190 * - end - end address (exclusive, may not be aligned)
191 * - vma - vma_area_struct describing address space
194 ENTRY(xsc3_flush_user_cache_range)
196 sub r3, r1, r0 @ calculate total size
197 cmp r3, #MAX_AREA_SIZE
198 bhs __flush_whole_cache
201 mcrne p15, 0, r0, c7, c5, 1 @ Invalidate I cache line
202 mcr p15, 0, r0, c7, c14, 1 @ Clean/invalidate D cache line
203 add r0, r0, #CACHELINESIZE
207 mcrne p15, 0, ip, c7, c5, 6 @ Invalidate BTB
208 mcrne p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
209 mcrne p15, 0, ip, c7, c5, 4 @ Prefetch Flush
213 * coherent_kern_range(start, end)
215 * Ensure coherency between the Icache and the Dcache in the
216 * region described by start. If you have non-snooping
217 * Harvard caches, you need to implement this function.
219 * - start - virtual start address
220 * - end - virtual end address
222 * Note: single I-cache line invalidation isn't used here since
223 * it also trashes the mini I-cache used by JTAG debuggers.
225 ENTRY(xsc3_coherent_kern_range)
227 ENTRY(xsc3_coherent_user_range)
228 bic r0, r0, #CACHELINESIZE - 1
229 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
230 add r0, r0, #CACHELINESIZE
234 mcr p15, 0, r0, c7, c5, 0 @ Invalidate I cache & BTB
235 mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
236 mcr p15, 0, r0, c7, c5, 4 @ Prefetch Flush
240 * flush_kern_dcache_page(void *page)
242 * Ensure no D cache aliasing occurs, either with itself or
245 * - addr - page aligned address
247 ENTRY(xsc3_flush_kern_dcache_page)
249 1: mcr p15, 0, r0, c7, c14, 1 @ Clean/Invalidate D Cache line
250 add r0, r0, #CACHELINESIZE
254 mcr p15, 0, r0, c7, c5, 0 @ Invalidate I cache & BTB
255 mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
256 mcr p15, 0, r0, c7, c5, 4 @ Prefetch Flush
260 * dma_inv_range(start, end)
262 * Invalidate (discard) the specified virtual address range.
263 * May not write back any entries. If 'start' or 'end'
264 * are not cache line aligned, those lines must be written
267 * - start - virtual start address
268 * - end - virtual end address
270 ENTRY(xsc3_dma_inv_range)
271 tst r0, #CACHELINESIZE - 1
272 bic r0, r0, #CACHELINESIZE - 1
273 mcrne p15, 0, r0, c7, c10, 1 @ clean L1 D entry
274 mcrne p15, 1, r0, c7, c11, 1 @ clean L2 D entry
275 tst r1, #CACHELINESIZE - 1
276 mcrne p15, 0, r1, c7, c10, 1 @ clean L1 D entry
277 mcrne p15, 1, r1, c7, c11, 1 @ clean L2 D entry
278 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate L1 D entry
279 mcr p15, 1, r0, c7, c7, 1 @ Invalidate L2 D cache line
280 add r0, r0, #CACHELINESIZE
283 mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
287 * dma_clean_range(start, end)
289 * Clean the specified virtual address range.
291 * - start - virtual start address
292 * - end - virtual end address
294 ENTRY(xsc3_dma_clean_range)
295 bic r0, r0, #CACHELINESIZE - 1
296 1: mcr p15, 0, r0, c7, c10, 1 @ clean L1 D entry
297 mcr p15, 1, r0, c7, c11, 1 @ clean L2 D entry
298 add r0, r0, #CACHELINESIZE
301 mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
305 * dma_flush_range(start, end)
307 * Clean and invalidate the specified virtual address range.
309 * - start - virtual start address
310 * - end - virtual end address
312 ENTRY(xsc3_dma_flush_range)
313 bic r0, r0, #CACHELINESIZE - 1
314 1: mcr p15, 0, r0, c7, c14, 1 @ Clean/invalidate L1 D cache line
315 mcr p15, 1, r0, c7, c11, 1 @ Clean L2 D cache line
316 mcr p15, 1, r0, c7, c7, 1 @ Invalidate L2 D cache line
317 add r0, r0, #CACHELINESIZE
320 mcr p15, 0, r0, c7, c10, 4 @ Drain Write Buffer
323 ENTRY(xsc3_cache_fns)
324 .long xsc3_flush_kern_cache_all
325 .long xsc3_flush_user_cache_all
326 .long xsc3_flush_user_cache_range
327 .long xsc3_coherent_kern_range
328 .long xsc3_coherent_user_range
329 .long xsc3_flush_kern_dcache_page
330 .long xsc3_dma_inv_range
331 .long xsc3_dma_clean_range
332 .long xsc3_dma_flush_range
334 ENTRY(cpu_xsc3_dcache_clean_area)
335 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
336 add r0, r0, #CACHELINESIZE
337 subs r1, r1, #CACHELINESIZE
341 /* =============================== PageTable ============================== */
344 * cpu_xsc3_switch_mm(pgd)
346 * Set the translation base pointer to be as described by pgd.
348 * pgd: new page tables
351 ENTRY(cpu_xsc3_switch_mm)
353 mcr p15, 0, ip, c7, c5, 0 @ Invalidate I cache & BTB
354 mcr p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
355 mcr p15, 0, ip, c7, c5, 4 @ Prefetch Flush
356 #ifdef L2_CACHE_ENABLE
357 orr r0, r0, #0x18 @ cache the page table in L2
359 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
360 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
364 * cpu_xsc3_set_pte(ptep, pte)
366 * Set a PTE and flush it out
370 ENTRY(cpu_xsc3_set_pte)
371 str r1, [r0], #-2048 @ linux version
374 orr r2, r2, #PTE_TYPE_EXT @ extended page
376 eor r3, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
378 tst r3, #L_PTE_USER @ User?
379 orrne r2, r2, #PTE_EXT_AP_URO_SRW @ yes -> user r/o, system r/w
381 tst r3, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
382 orreq r2, r2, #PTE_EXT_AP_UNO_SRW @ yes -> user n/a, system r/w
383 @ combined with user -> user r/w
386 @ If its cacheable it needs to be in L2 also.
387 eor ip, r1, #L_PTE_CACHEABLE
388 tst ip, #L_PTE_CACHEABLE
389 orreq r2, r2, #PTE_EXT_TEX(0x5)
392 tst r3, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
393 movne r2, #0 @ no -> fault
395 str r2, [r0] @ hardware version
397 mcr p15, 0, r0, c7, c10, 1 @ Clean D cache line mcr
398 mcr p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
407 .type __xsc3_setup, #function
409 mov r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
411 mcr p15, 0, ip, c7, c7, 0 @ invalidate I, D caches & BTB
412 mcr p15, 0, ip, c7, c10, 4 @ Drain Write Buffer
413 mcr p15, 0, ip, c7, c5, 4 @ Prefetch Flush
414 mcr p15, 0, ip, c8, c7, 0 @ invalidate I, D TLBs
416 orr r4, r4, #0x18 @ cache the page table in L2
418 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
419 mov r0, #1 @ Allow access to CP0 and CP13
420 orr r0, r0, #1 << 13 @ Its undefined whether this
421 mcr p15, 0, r0, c15, c1, 0 @ affects USR or SVC modes
422 mrc p15, 0, r0, c1, c0, 1 @ get auxiliary control reg
423 and r0, r0, #2 @ preserve bit P bit setting
425 orr r0, r0, #(1 << 10) @ enable L2 for LLR cache
427 mcr p15, 0, r0, c1, c0, 1 @ set auxiliary control reg
428 mrc p15, 0, r0, c1, c0, 0 @ get control register
429 bic r0, r0, #0x0200 @ .... ..R. .... ....
430 bic r0, r0, #0x0002 @ .... .... .... ..A.
431 orr r0, r0, #0x0005 @ .... .... .... .C.M
433 orr r0, r0, #0x3900 @ ..VI Z..S .... ....
435 orr r0, r0, #0x3100 @ ..VI ...S .... ....
438 orr r0, r0, #0x4000000 @ L2 enable
442 .size __xsc3_setup, . - __xsc3_setup
447 * Purpose : Function pointers used to access above functions - all calls
451 .type xsc3_processor_functions, #object
452 ENTRY(xsc3_processor_functions)
453 .word v5t_early_abort
454 .word cpu_xsc3_proc_init
455 .word cpu_xsc3_proc_fin
457 .word cpu_xsc3_do_idle
458 .word cpu_xsc3_dcache_clean_area
459 .word cpu_xsc3_switch_mm
460 .word cpu_xsc3_set_pte
461 .size xsc3_processor_functions, . - xsc3_processor_functions
465 .type cpu_arch_name, #object
468 .size cpu_arch_name, . - cpu_arch_name
470 .type cpu_elf_name, #object
473 .size cpu_elf_name, . - cpu_elf_name
475 .type cpu_xsc3_name, #object
477 .asciz "XScale-Core3"
478 .size cpu_xsc3_name, . - cpu_xsc3_name
482 .section ".proc.info.init", #alloc, #execinstr
484 .type __xsc3_proc_info,#object
492 .long HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
494 .long xsc3_processor_functions
496 .long xsc3_mc_user_fns
498 .size __xsc3_proc_info, . - __xsc3_proc_info