2 * linux/arch/arm/mm/proc-arm1020.S: MMU functions for ARM1020
4 * Copyright (C) 2000 ARM Limited
5 * Copyright (C) 2000 Deep Blue Solutions Ltd.
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.
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.
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
22 * These are the low level assembler for performing cache and TLB
23 * functions on the arm1020.
25 * CONFIG_CPU_ARM1020_CPU_IDLE -> nohlt
27 #include <linux/linkage.h>
28 #include <linux/config.h>
29 #include <linux/init.h>
30 #include <asm/assembler.h>
31 #include <asm/asm-offsets.h>
32 #include <asm/pgtable.h>
33 #include <asm/procinfo.h>
34 #include <asm/ptrace.h>
37 * This is the maximum size of an area which will be invalidated
38 * using the single invalidate entry instructions. Anything larger
39 * than this, and we go for the whole cache.
41 * This value should be chosen such that we choose the cheapest
44 #define MAX_AREA_SIZE 32768
47 * The size of one data cache line.
49 #define CACHE_DLINESIZE 32
52 * The number of data cache segments.
54 #define CACHE_DSEGMENTS 16
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.
66 #define CACHE_DLIMIT 32768
70 * cpu_arm1020_proc_init()
72 ENTRY(cpu_arm1020_proc_init)
76 * cpu_arm1020_proc_fin()
78 ENTRY(cpu_arm1020_proc_fin)
80 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
82 bl arm1020_flush_kern_cache_all
83 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
84 bic r0, r0, #0x1000 @ ...i............
85 bic r0, r0, #0x000e @ ............wca.
86 mcr p15, 0, r0, c1, c0, 0 @ disable caches
90 * cpu_arm1020_reset(loc)
92 * Perform a soft reset of the system. Put the CPU into the
93 * same state as it would be if it had been reset, and branch
94 * to what would be the reset vector.
96 * loc: location to jump to for soft reset
99 ENTRY(cpu_arm1020_reset)
101 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
102 mcr p15, 0, ip, c7, c10, 4 @ drain WB
103 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
104 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
105 bic ip, ip, #0x000f @ ............wcam
106 bic ip, ip, #0x1100 @ ...i...s........
107 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
111 * cpu_arm1020_do_idle()
114 ENTRY(cpu_arm1020_do_idle)
115 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
118 /* ================================= CACHE ================================ */
122 * flush_user_cache_all()
124 * Invalidate all cache entries in a particular address
127 ENTRY(arm1020_flush_user_cache_all)
130 * flush_kern_cache_all()
132 * Clean and invalidate the entire cache.
134 ENTRY(arm1020_flush_kern_cache_all)
138 #ifndef CONFIG_CPU_DCACHE_DISABLE
139 mcr p15, 0, ip, c7, c10, 4 @ drain WB
140 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
141 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
142 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
143 mcr p15, 0, ip, c7, c10, 4 @ drain WB
144 subs r3, r3, #1 << 26
145 bcs 2b @ entries 63 to 0
147 bcs 1b @ segments 15 to 0
150 #ifndef CONFIG_CPU_ICACHE_DISABLE
151 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
153 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
157 * flush_user_cache_range(start, end, flags)
159 * Invalidate a range of cache entries in the specified
162 * - start - start address (inclusive)
163 * - end - end address (exclusive)
164 * - flags - vm_flags for this space
166 ENTRY(arm1020_flush_user_cache_range)
168 sub r3, r1, r0 @ calculate total size
169 cmp r3, #CACHE_DLIMIT
170 bhs __flush_whole_cache
172 #ifndef CONFIG_CPU_DCACHE_DISABLE
173 mcr p15, 0, ip, c7, c10, 4
174 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
175 mcr p15, 0, ip, c7, c10, 4 @ drain WB
176 add r0, r0, #CACHE_DLINESIZE
181 #ifndef CONFIG_CPU_ICACHE_DISABLE
182 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
184 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
188 * coherent_kern_range(start, end)
190 * Ensure coherency between the Icache and the Dcache in the
191 * region described by start. If you have non-snooping
192 * Harvard caches, you need to implement this function.
194 * - start - virtual start address
195 * - end - virtual end address
197 ENTRY(arm1020_coherent_kern_range)
201 * coherent_user_range(start, end)
203 * Ensure coherency between the Icache and the Dcache in the
204 * region described by start. If you have non-snooping
205 * Harvard caches, you need to implement this function.
207 * - start - virtual start address
208 * - end - virtual end address
210 ENTRY(arm1020_coherent_user_range)
212 bic r0, r0, #CACHE_DLINESIZE - 1
213 mcr p15, 0, ip, c7, c10, 4
215 #ifndef CONFIG_CPU_DCACHE_DISABLE
216 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
217 mcr p15, 0, ip, c7, c10, 4 @ drain WB
219 #ifndef CONFIG_CPU_ICACHE_DISABLE
220 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
222 add r0, r0, #CACHE_DLINESIZE
225 mcr p15, 0, ip, c7, c10, 4 @ drain WB
229 * flush_kern_dcache_page(void *page)
231 * Ensure no D cache aliasing occurs, either with itself or
234 * - page - page aligned address
236 ENTRY(arm1020_flush_kern_dcache_page)
238 #ifndef CONFIG_CPU_DCACHE_DISABLE
240 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
241 mcr p15, 0, ip, c7, c10, 4 @ drain WB
242 add r0, r0, #CACHE_DLINESIZE
246 mcr p15, 0, ip, c7, c10, 4 @ drain WB
250 * dma_inv_range(start, end)
252 * Invalidate (discard) the specified virtual address range.
253 * May not write back any entries. If 'start' or 'end'
254 * are not cache line aligned, those lines must be written
257 * - start - virtual start address
258 * - end - virtual end address
262 ENTRY(arm1020_dma_inv_range)
264 #ifndef CONFIG_CPU_DCACHE_DISABLE
265 tst r0, #CACHE_DLINESIZE - 1
266 bic r0, r0, #CACHE_DLINESIZE - 1
267 mcrne p15, 0, ip, c7, c10, 4
268 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
269 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
270 tst r1, #CACHE_DLINESIZE - 1
271 mcrne p15, 0, ip, c7, c10, 4
272 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
273 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
274 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
275 add r0, r0, #CACHE_DLINESIZE
279 mcr p15, 0, ip, c7, c10, 4 @ drain WB
283 * dma_clean_range(start, end)
285 * Clean the specified virtual address range.
287 * - start - virtual start address
288 * - end - virtual end address
292 ENTRY(arm1020_dma_clean_range)
294 #ifndef CONFIG_CPU_DCACHE_DISABLE
295 bic r0, r0, #CACHE_DLINESIZE - 1
296 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
297 mcr p15, 0, ip, c7, c10, 4 @ drain WB
298 add r0, r0, #CACHE_DLINESIZE
302 mcr p15, 0, ip, c7, c10, 4 @ drain WB
306 * dma_flush_range(start, end)
308 * Clean and invalidate the specified virtual address range.
310 * - start - virtual start address
311 * - end - virtual end address
313 ENTRY(arm1020_dma_flush_range)
315 #ifndef CONFIG_CPU_DCACHE_DISABLE
316 bic r0, r0, #CACHE_DLINESIZE - 1
317 mcr p15, 0, ip, c7, c10, 4
318 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
319 mcr p15, 0, ip, c7, c10, 4 @ drain WB
320 add r0, r0, #CACHE_DLINESIZE
324 mcr p15, 0, ip, c7, c10, 4 @ drain WB
327 ENTRY(arm1020_cache_fns)
328 .long arm1020_flush_kern_cache_all
329 .long arm1020_flush_user_cache_all
330 .long arm1020_flush_user_cache_range
331 .long arm1020_coherent_kern_range
332 .long arm1020_coherent_user_range
333 .long arm1020_flush_kern_dcache_page
334 .long arm1020_dma_inv_range
335 .long arm1020_dma_clean_range
336 .long arm1020_dma_flush_range
339 ENTRY(cpu_arm1020_dcache_clean_area)
340 #ifndef CONFIG_CPU_DCACHE_DISABLE
342 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
343 mcr p15, 0, ip, c7, c10, 4 @ drain WB
344 add r0, r0, #CACHE_DLINESIZE
345 subs r1, r1, #CACHE_DLINESIZE
350 /* =============================== PageTable ============================== */
353 * cpu_arm1020_switch_mm(pgd)
355 * Set the translation base pointer to be as described by pgd.
357 * pgd: new page tables
360 ENTRY(cpu_arm1020_switch_mm)
361 #ifndef CONFIG_CPU_DCACHE_DISABLE
362 mcr p15, 0, r3, c7, c10, 4
363 mov r1, #0xF @ 16 segments
364 1: mov r3, #0x3F @ 64 entries
365 2: mov ip, r3, LSL #26 @ shift up entry
366 orr ip, ip, r1, LSL #5 @ shift in/up index
367 mcr p15, 0, ip, c7, c14, 2 @ Clean & Inval DCache entry
369 mcr p15, 0, ip, c7, c10, 4
372 bge 2b @ entries 3F to 0
375 bge 1b @ segments 15 to 0
379 #ifndef CONFIG_CPU_ICACHE_DISABLE
380 mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
382 mcr p15, 0, r1, c7, c10, 4 @ drain WB
383 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
384 mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
388 * cpu_arm1020_set_pte(ptep, pte)
390 * Set a PTE and flush it out
393 ENTRY(cpu_arm1020_set_pte)
394 str r1, [r0], #-2048 @ linux version
396 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
398 bic r2, r1, #PTE_SMALL_AP_MASK
399 bic r2, r2, #PTE_TYPE_MASK
400 orr r2, r2, #PTE_TYPE_SMALL
402 tst r1, #L_PTE_USER @ User?
403 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
405 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
406 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
408 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
411 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
412 eor r3, r1, #0x0a @ C & small page?
416 str r2, [r0] @ hardware version
418 #ifndef CONFIG_CPU_DCACHE_DISABLE
419 mcr p15, 0, r0, c7, c10, 4
420 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
422 mcr p15, 0, r0, c7, c10, 4 @ drain WB
427 .type __arm1020_setup, #function
430 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
431 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
432 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
433 mrc p15, 0, r0, c1, c0 @ get control register v4
434 ldr r5, arm1020_cr1_clear
436 ldr r5, arm1020_cr1_set
438 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
439 orr r0, r0, #0x4000 @ .R.. .... .... ....
442 .size __arm1020_setup, . - __arm1020_setup
446 * .RVI ZFRS BLDP WCAM
447 * .011 1001 ..11 0101
449 .type arm1020_cr1_clear, #object
450 .type arm1020_cr1_set, #object
459 * Purpose : Function pointers used to access above functions - all calls
462 .type arm1020_processor_functions, #object
463 arm1020_processor_functions:
464 .word v4t_early_abort
465 .word cpu_arm1020_proc_init
466 .word cpu_arm1020_proc_fin
467 .word cpu_arm1020_reset
468 .word cpu_arm1020_do_idle
469 .word cpu_arm1020_dcache_clean_area
470 .word cpu_arm1020_switch_mm
471 .word cpu_arm1020_set_pte
472 .size arm1020_processor_functions, . - arm1020_processor_functions
476 .type cpu_arch_name, #object
479 .size cpu_arch_name, . - cpu_arch_name
481 .type cpu_elf_name, #object
484 .size cpu_elf_name, . - cpu_elf_name
486 .type cpu_arm1020_name, #object
489 #ifndef CONFIG_CPU_ICACHE_DISABLE
492 #ifndef CONFIG_CPU_DCACHE_DISABLE
494 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
500 #ifndef CONFIG_CPU_BPREDICT_DISABLE
503 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
507 .size cpu_arm1020_name, . - cpu_arm1020_name
511 .section ".proc.info.init", #alloc, #execinstr
513 .type __arm1020_proc_info,#object
515 .long 0x4104a200 @ ARM 1020T (Architecture v5T)
517 .long PMD_TYPE_SECT | \
518 PMD_SECT_AP_WRITE | \
523 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
524 .long cpu_arm1020_name
525 .long arm1020_processor_functions
528 .long arm1020_cache_fns
529 .size __arm1020_proc_info, . - __arm1020_proc_info