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
7 * hacked for non-paged-MM by Hyok S. Choi, 2003.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * These are the low level assembler for performing cache and TLB
25 * functions on the arm922.
27 * CONFIG_CPU_ARM922_CPU_IDLE -> nohlt
29 #include <linux/linkage.h>
30 #include <linux/init.h>
31 #include <asm/assembler.h>
32 #include <asm/pgtable-hwdef.h>
33 #include <asm/pgtable.h>
34 #include <asm/procinfo.h>
36 #include <asm/ptrace.h>
37 #include "proc-macros.S"
40 * The size of one data cache line.
42 #define CACHE_DLINESIZE 16
43 #if 1 /* add by Victor Yu. 02-08-2007 */
44 #define CACHE_DSIZE 16384
45 #define CACHE_ISIZE 16384
46 #define CACHE_ILINESIZE 16
50 * The number of data cache segments.
52 #define CACHE_DSEGMENTS 4
55 * The number of lines in a cache segment.
57 #define CACHE_DENTRIES 64
60 * This is the size at which it becomes more efficient to
61 * clean the whole cache, rather than using the individual
62 * cache line maintainence instructions. (I think this should
65 #define CACHE_DLIMIT 8192
70 * cpu_arm922_proc_init()
72 ENTRY(cpu_arm922_proc_init)
76 * cpu_arm922_proc_fin()
78 ENTRY(cpu_arm922_proc_fin)
80 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
82 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
83 bl arm922_flush_kern_cache_all
85 bl v4wt_flush_kern_cache_all
87 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
88 bic r0, r0, #0x1000 @ ...i............
89 bic r0, r0, #0x000e @ ............wca.
90 mcr p15, 0, r0, c1, c0, 0 @ disable caches
94 * cpu_arm922_reset(loc)
96 * Perform a soft reset of the system. Put the CPU into the
97 * same state as it would be if it had been reset, and branch
98 * to what would be the reset vector.
100 * loc: location to jump to for soft reset
103 ENTRY(cpu_arm922_reset)
105 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
106 mcr p15, 0, ip, c7, c10, 4 @ drain WB
108 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 bic ip, ip, #0x0800 @ off BTB
116 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
120 * cpu_arm922_do_idle()
123 ENTRY(cpu_arm922_do_idle)
124 #if 0 /* mask by Victor Yu. 02-08-2007 */
125 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
130 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
133 * flush_user_cache_all()
135 * Clean and invalidate all cache entries in a particular
138 ENTRY(arm922_flush_user_cache_all)
142 * flush_kern_cache_all()
144 * Clean and invalidate the entire cache.
146 ENTRY(arm922_flush_kern_cache_all)
147 #if 1 /* mask by Victor Yu. 05-30-2005 */
151 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
152 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
153 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
154 subs r3, r3, #1 << 26
155 bcs 2b @ entries 63 to 0
157 bcs 1b @ segments 7 to 0
159 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
160 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
162 #else /* add by Victor Yu. 05-30-2005 */
165 #ifndef CONFIG_CPU_ICACHE_DISABLE
166 mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
171 #ifndef CONFIG_CPU_DCACHE_DISABLE
173 # ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
174 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
176 mcr p15, 0, ip, c7,c14, 0 @ clean/invalidate D cache
178 #endif /*CONFIG_CPU_DCACHE_DISABLE*/
180 #ifndef CONFIG_CPU_FA_WB_DISABLE
181 mcr p15, 0, ip, c7, c10, 4 @ drain write buffer
187 * flush_user_cache_range(start, end, flags)
189 * Clean and invalidate a range of cache entries in the
190 * specified address range.
192 * - start - start address (inclusive)
193 * - end - end address (exclusive)
194 * - flags - vm_flags describing address space
196 ENTRY(arm922_flush_user_cache_range)
197 #if 1 /* mask by Victor Yu. 05-30-2005 */
199 sub r3, r1, r0 @ calculate total size
200 cmp r3, #CACHE_DLIMIT
201 bhs __flush_whole_cache
203 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
205 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
206 add r0, r0, #CACHE_DLINESIZE
210 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
212 #else /* add by Victor Yu. 05-30-2005 */
214 sub r3, r1, r0 @ calculate total size
215 #ifndef CONFIG_CPU_ICACHE_DISABLE
216 tst r2, #VM_EXEC @ executable region?
217 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
220 #ifndef CONFIG_CPU_DCACHE_DISABLE
221 cmp r3, #CACHE_DSIZE @ total size >= limit?
222 bhs __flush_whole_cache @ flush whole D cache
226 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
227 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
229 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
231 add r0, r0, #CACHE_DLINESIZE
234 #endif /* CONFIG_CPU_DCACHE_DISABLE */
236 #ifndef CONFIG_CPU_FA_WB_DISABLE
238 mcreq p15, 0, r4, c7, c10, 4 @ drain write buffer
245 * flush_kern_dcache_page(void *page)
247 * Ensure no D cache aliasing occurs, either with itself or
250 * - addr - page aligned address
252 ENTRY(arm922_flush_kern_dcache_page)
253 #if 1 /* mask by Victor Yu. 05-30-2005 */
255 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
256 add r0, r0, #CACHE_DLINESIZE
260 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
261 mcr p15, 0, r0, c7, c10, 4 @ drain WB
263 #else /* add by Victor Yu. 05-30-2005 */
269 * coherent_kern_range(start, end)
271 * Ensure coherency between the Icache and the Dcache in the
272 * region described by start, end. If you have non-snooping
273 * Harvard caches, you need to implement this function.
275 * - start - virtual start address
276 * - end - virtual end address
278 ENTRY(arm922_coherent_kern_range)
282 * coherent_user_range(start, end)
284 * Ensure coherency between the Icache and the Dcache in the
285 * region described by start, end. If you have non-snooping
286 * Harvard caches, you need to implement this function.
288 * - start - virtual start address
289 * - end - virtual end address
291 ENTRY(arm922_coherent_user_range)
292 #if 1 /* mask by Victor Yu. 06-09-2005 */
293 bic r0, r0, #CACHE_DLINESIZE - 1
294 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
295 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
296 add r0, r0, #CACHE_DLINESIZE
299 mcr p15, 0, r0, c7, c10, 4 @ drain WB
301 #else /* add by Victor Yu. 06-09-2005 */
302 bic r0, r0, #CACHE_DLINESIZE-1
304 #if !(defined(CONFIG_CPU_DCACHE_DISABLE) && defined(CONFIG_CPU_ICACHE_DISABLE))
306 #ifndef CONFIG_CPU_DCACHE_DISABLE
307 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
308 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
310 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
312 #endif /* CONFIG_CPU_DCACHE_DISABLE */
314 #ifndef CONFIG_CPU_ICACHE_DISABLE
315 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
317 add r0, r0, #CACHE_DLINESIZE
319 bls 1b @ Luke Lee 05/19/2005 blo->bls
320 #endif /* !(defined(CONFIG_CPU_DCACHE_DISABLE) && defined(CONFIG_CPU_ICACHE_DISABLE)) */
324 #ifndef CONFIG_CPU_FA_WB_DISABLE
325 mcr p15, 0, ip, c7, c10, 4 @ drain WB
332 * dma_inv_range(start, end)
334 * Invalidate (discard) the specified virtual address range.
335 * May not write back any entries. If 'start' or 'end'
336 * are not cache line aligned, those lines must be written
339 * - start - virtual start address
340 * - end - virtual end address
344 ENTRY(arm922_dma_inv_range)
345 #if 1 /* mask by Victor Yu. 05-30-2005 */
346 tst r0, #CACHE_DLINESIZE - 1
347 bic r0, r0, #CACHE_DLINESIZE - 1
348 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
349 tst r1, #CACHE_DLINESIZE - 1
350 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
351 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
352 add r0, r0, #CACHE_DLINESIZE
355 mcr p15, 0, r0, c7, c10, 4 @ drain WB
357 #else /* add by Victor Yu. 05-30-2005 */
358 #ifndef CONFIG_CPU_DCACHE_DISABLE
360 # ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
361 tst r0, #CACHE_DLINESIZE -1
362 bic r0, r0, #CACHE_DLINESIZE -1
363 mcrne p15, 0, r0, c7, c10, 1 @ clean boundary D entry
364 mcr p15, 0, r1, c7, c10, 1 @ clean boundary D entry
366 bic r0, r0, #CACHE_DLINESIZE -1
367 # endif /* CONFIG_CPU_DCACHE_WRITETHROUGH */
369 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
370 add r0, r0, #CACHE_DLINESIZE
372 bls 1b @ Luke Lee 05/19/2005 blo->bls
373 #endif /* CONFIG_CPU_DCACHE_DISABLE */
375 #ifndef CONFIG_CPU_FA_WB_DISABLE
377 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
383 * dma_clean_range(start, end)
385 * Clean the specified virtual address range.
387 * - start - virtual start address
388 * - end - virtual end address
392 ENTRY(arm922_dma_clean_range)
393 #if 1 /* mask by Victor Yu. 05-30-2005 */
394 bic r0, r0, #CACHE_DLINESIZE - 1
395 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
396 add r0, r0, #CACHE_DLINESIZE
399 mcr p15, 0, r0, c7, c10, 4 @ drain WB
401 #else /* add by Victor Yu. 05-30-2005 */
402 #ifndef CONFIG_CPU_DCACHE_DISABLE
403 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
404 bic r0, r0, #CACHE_DLINESIZE - 1
405 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
406 add r0, r0, #CACHE_DLINESIZE
408 bls 1b @ Luke Lee 05/19/2005 blo->bls
410 #endif /* CONFIG_CPU_DCACHE_WRITETHROUGH */
411 #endif /* CONFIG_CPU_DCACHE_DISABLE */
413 #ifndef CONFIG_CPU_FA_WB_DISABLE
415 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
421 * dma_flush_range(start, end)
423 * Clean and invalidate the specified virtual address range.
425 * - start - virtual start address
426 * - end - virtual end address
428 #if 1 /* mask by Victor Yu. 06-09-2005 */
429 ENTRY(arm922_dma_flush_range)
430 bic r0, r0, #CACHE_DLINESIZE - 1
431 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
432 add r0, r0, #CACHE_DLINESIZE
435 mcr p15, 0, r0, c7, c10, 4 @ drain WB
437 #else /* add by Victor Yu. 06-09-2005 */
438 .globl arm922_dma_flush_range
439 .set arm922_dma_flush_range, arm922_coherent_kern_range
442 ENTRY(arm922_cache_fns)
443 .long arm922_flush_kern_cache_all
444 .long arm922_flush_user_cache_all
445 .long arm922_flush_user_cache_range
446 .long arm922_coherent_kern_range
447 .long arm922_coherent_user_range
448 .long arm922_flush_kern_dcache_page
449 .long arm922_dma_inv_range
450 .long arm922_dma_clean_range
451 .long arm922_dma_flush_range
452 #if 1 /* add by Victor Yu. 06-09-2005 */
453 .size arm922_cache_fns, . - arm922_cache_fns
459 ENTRY(cpu_arm922_dcache_clean_area)
460 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
461 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
462 add r0, r0, #CACHE_DLINESIZE
463 subs r1, r1, #CACHE_DLINESIZE
468 /* =============================== PageTable ============================== */
471 * cpu_arm922_switch_mm(pgd)
473 * Set the translation base pointer to be as described by pgd.
475 * pgd: new page tables
478 ENTRY(cpu_arm922_switch_mm)
481 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
482 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
484 @ && 'Clean & Invalidate whole DCache'
485 @ && Re-written to use Index Ops.
486 @ && Uses registers r1, r3 and ip
488 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 4 segments
489 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
490 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
491 subs r3, r3, #1 << 26
492 bcs 2b @ entries 63 to 0
494 bcs 1b @ segments 7 to 0
496 mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
497 mcr p15, 0, ip, c7, c10, 4 @ drain WB
498 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
499 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
504 * cpu_arm922_set_pte(ptep, pte)
506 * Set a PTE and flush it out
509 ENTRY(cpu_arm922_set_pte)
511 str r1, [r0], #-2048 @ linux version
513 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
515 bic r2, r1, #PTE_SMALL_AP_MASK
516 bic r2, r2, #PTE_TYPE_MASK
517 orr r2, r2, #PTE_TYPE_SMALL
519 tst r1, #L_PTE_USER @ User?
520 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
522 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
523 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
525 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
528 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
529 eor r3, r2, #0x0a @ C & small page?
533 str r2, [r0] @ hardware version
535 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
536 mcr p15, 0, r0, c7, c10, 4 @ drain WB
537 #endif /* CONFIG_MMU */
542 .type __arm922_setup, #function
545 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
546 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
548 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
552 mrc p15, 0, r0, c1, c0 @ get control register v4
556 .size __arm922_setup, . - __arm922_setup
560 * .RVI ZFRS BLDP WCAM
561 * ..11 0001 ..11 0101
564 .type arm922_crval, #object
566 crval clear=0x00003f3f, mmuset=0x00003135, ucset=0x00001130
571 * Purpose : Function pointers used to access above functions - all calls
574 .type arm922_processor_functions, #object
575 arm922_processor_functions:
576 #if 0 /* mask by Victor Yu. 02-08-2007 */
577 .word v4t_early_abort
579 .word nommu_early_abort
581 .word cpu_arm922_proc_init
582 .word cpu_arm922_proc_fin
583 .word cpu_arm922_reset
584 .word cpu_arm922_do_idle
585 .word cpu_arm922_dcache_clean_area
586 .word cpu_arm922_switch_mm
587 .word cpu_arm922_set_pte
588 .size arm922_processor_functions, . - arm922_processor_functions
592 .type cpu_arch_name, #object
595 .size cpu_arch_name, . - cpu_arch_name
597 .type cpu_elf_name, #object
600 .size cpu_elf_name, . - cpu_elf_name
602 .type cpu_arm922_name, #object
605 .size cpu_arm922_name, . - cpu_arm922_name
609 .section ".proc.info.init", #alloc, #execinstr
611 .type __arm922_proc_info,#object
613 #if 0 /* mask by Victor Yu. 02-08-2007 */
620 .long PMD_TYPE_SECT | \
621 PMD_SECT_BUFFERABLE | \
622 PMD_SECT_CACHEABLE | \
624 PMD_SECT_AP_WRITE | \
626 .long PMD_TYPE_SECT | \
628 PMD_SECT_AP_WRITE | \
633 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
634 .long cpu_arm922_name
635 .long arm922_processor_functions
638 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
639 .long arm922_cache_fns
643 .size __arm922_proc_info, . - __arm922_proc_info