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>
35 #include <asm/ptrace.h>
36 #include "proc-macros.S"
39 * The size of one data cache line.
41 #define CACHE_DLINESIZE 32
44 * The number of data cache segments.
46 #define CACHE_DSEGMENTS 4
49 * The number of lines in a cache segment.
51 #define CACHE_DENTRIES 64
54 * This is the size at which it becomes more efficient to
55 * clean the whole cache, rather than using the individual
56 * cache line maintainence instructions. (I think this should
59 #define CACHE_DLIMIT 8192
64 * cpu_arm922_proc_init()
66 ENTRY(cpu_arm922_proc_init)
70 * cpu_arm922_proc_fin()
72 ENTRY(cpu_arm922_proc_fin)
74 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
76 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
77 bl arm922_flush_kern_cache_all
79 bl v4wt_flush_kern_cache_all
81 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
82 bic r0, r0, #0x1000 @ ...i............
83 bic r0, r0, #0x000e @ ............wca.
84 mcr p15, 0, r0, c1, c0, 0 @ disable caches
88 * cpu_arm922_reset(loc)
90 * Perform a soft reset of the system. Put the CPU into the
91 * same state as it would be if it had been reset, and branch
92 * to what would be the reset vector.
94 * loc: location to jump to for soft reset
97 ENTRY(cpu_arm922_reset)
99 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
100 mcr p15, 0, ip, c7, c10, 4 @ drain WB
101 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
102 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
103 bic ip, ip, #0x000f @ ............wcam
104 bic ip, ip, #0x1100 @ ...i...s........
105 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
109 * cpu_arm922_do_idle()
112 ENTRY(cpu_arm922_do_idle)
113 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
117 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
120 * flush_user_cache_all()
122 * Clean and invalidate all cache entries in a particular
125 ENTRY(arm922_flush_user_cache_all)
129 * flush_kern_cache_all()
131 * Clean and invalidate the entire cache.
133 ENTRY(arm922_flush_kern_cache_all)
137 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
138 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
139 2: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
140 subs r3, r3, #1 << 26
141 bcs 2b @ entries 63 to 0
143 bcs 1b @ segments 7 to 0
145 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
146 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
150 * flush_user_cache_range(start, end, flags)
152 * Clean and invalidate a range of cache entries in the
153 * specified address range.
155 * - start - start address (inclusive)
156 * - end - end address (exclusive)
157 * - flags - vm_flags describing address space
159 ENTRY(arm922_flush_user_cache_range)
161 sub r3, r1, r0 @ calculate total size
162 cmp r3, #CACHE_DLIMIT
163 bhs __flush_whole_cache
165 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
167 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
168 add r0, r0, #CACHE_DLINESIZE
172 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
176 * coherent_kern_range(start, end)
178 * Ensure coherency between the Icache and the Dcache in the
179 * region described by start, end. If you have non-snooping
180 * Harvard caches, you need to implement this function.
182 * - start - virtual start address
183 * - end - virtual end address
185 ENTRY(arm922_coherent_kern_range)
189 * coherent_user_range(start, end)
191 * Ensure coherency between the Icache and the Dcache in the
192 * region described by start, end. If you have non-snooping
193 * Harvard caches, you need to implement this function.
195 * - start - virtual start address
196 * - end - virtual end address
198 ENTRY(arm922_coherent_user_range)
199 bic r0, r0, #CACHE_DLINESIZE - 1
200 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
201 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
202 add r0, r0, #CACHE_DLINESIZE
205 mcr p15, 0, r0, c7, c10, 4 @ drain WB
209 * flush_kern_dcache_page(void *page)
211 * Ensure no D cache aliasing occurs, either with itself or
214 * - addr - page aligned address
216 ENTRY(arm922_flush_kern_dcache_page)
218 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
219 add r0, r0, #CACHE_DLINESIZE
223 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
224 mcr p15, 0, r0, c7, c10, 4 @ drain WB
228 * dma_inv_range(start, end)
230 * Invalidate (discard) the specified virtual address range.
231 * May not write back any entries. If 'start' or 'end'
232 * are not cache line aligned, those lines must be written
235 * - start - virtual start address
236 * - end - virtual end address
240 ENTRY(arm922_dma_inv_range)
241 tst r0, #CACHE_DLINESIZE - 1
242 bic r0, r0, #CACHE_DLINESIZE - 1
243 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
244 tst r1, #CACHE_DLINESIZE - 1
245 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
246 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
247 add r0, r0, #CACHE_DLINESIZE
250 mcr p15, 0, r0, c7, c10, 4 @ drain WB
254 * dma_clean_range(start, end)
256 * Clean the specified virtual address range.
258 * - start - virtual start address
259 * - end - virtual end address
263 ENTRY(arm922_dma_clean_range)
264 bic r0, r0, #CACHE_DLINESIZE - 1
265 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
266 add r0, r0, #CACHE_DLINESIZE
269 mcr p15, 0, r0, c7, c10, 4 @ drain WB
273 * dma_flush_range(start, end)
275 * Clean and invalidate the specified virtual address range.
277 * - start - virtual start address
278 * - end - virtual end address
280 ENTRY(arm922_dma_flush_range)
281 bic r0, r0, #CACHE_DLINESIZE - 1
282 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
283 add r0, r0, #CACHE_DLINESIZE
286 mcr p15, 0, r0, c7, c10, 4 @ drain WB
289 ENTRY(arm922_cache_fns)
290 .long arm922_flush_kern_cache_all
291 .long arm922_flush_user_cache_all
292 .long arm922_flush_user_cache_range
293 .long arm922_coherent_kern_range
294 .long arm922_coherent_user_range
295 .long arm922_flush_kern_dcache_page
296 .long arm922_dma_inv_range
297 .long arm922_dma_clean_range
298 .long arm922_dma_flush_range
303 ENTRY(cpu_arm922_dcache_clean_area)
304 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
305 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
306 add r0, r0, #CACHE_DLINESIZE
307 subs r1, r1, #CACHE_DLINESIZE
312 /* =============================== PageTable ============================== */
315 * cpu_arm922_switch_mm(pgd)
317 * Set the translation base pointer to be as described by pgd.
319 * pgd: new page tables
322 ENTRY(cpu_arm922_switch_mm)
324 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
325 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
327 @ && 'Clean & Invalidate whole DCache'
328 @ && Re-written to use Index Ops.
329 @ && Uses registers r1, r3 and ip
331 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 4 segments
332 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
333 2: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
334 subs r3, r3, #1 << 26
335 bcs 2b @ entries 63 to 0
337 bcs 1b @ segments 7 to 0
339 mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
340 mcr p15, 0, ip, c7, c10, 4 @ drain WB
341 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
342 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
346 * cpu_arm922_set_pte(ptep, pte)
348 * Set a PTE and flush it out
351 ENTRY(cpu_arm922_set_pte)
352 str r1, [r0], #-2048 @ linux version
354 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
356 bic r2, r1, #PTE_SMALL_AP_MASK
357 bic r2, r2, #PTE_TYPE_MASK
358 orr r2, r2, #PTE_TYPE_SMALL
360 tst r1, #L_PTE_USER @ User?
361 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
363 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
364 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
366 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
369 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
370 eor r3, r2, #0x0a @ C & small page?
374 str r2, [r0] @ hardware version
376 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
377 mcr p15, 0, r0, c7, c10, 4 @ drain WB
382 .type __arm922_setup, #function
385 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
386 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
387 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
388 mrc p15, 0, r0, c1, c0 @ get control register v4
389 ldr r5, arm922_cr1_clear
391 ldr r5, arm922_cr1_set
394 .size __arm922_setup, . - __arm922_setup
398 * .RVI ZFRS BLDP WCAM
399 * ..11 0001 ..11 0101
402 .type arm922_cr1_clear, #object
403 .type arm922_cr1_set, #object
412 * Purpose : Function pointers used to access above functions - all calls
415 .type arm922_processor_functions, #object
416 arm922_processor_functions:
417 .word v4t_early_abort
418 .word cpu_arm922_proc_init
419 .word cpu_arm922_proc_fin
420 .word cpu_arm922_reset
421 .word cpu_arm922_do_idle
422 .word cpu_arm922_dcache_clean_area
423 .word cpu_arm922_switch_mm
424 .word cpu_arm922_set_pte
425 .size arm922_processor_functions, . - arm922_processor_functions
429 .type cpu_arch_name, #object
432 .size cpu_arch_name, . - cpu_arch_name
434 .type cpu_elf_name, #object
437 .size cpu_elf_name, . - cpu_elf_name
439 .type cpu_arm922_name, #object
442 #ifndef CONFIG_CPU_ICACHE_DISABLE
445 #ifndef CONFIG_CPU_DCACHE_DISABLE
447 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
454 .size cpu_arm922_name, . - cpu_arm922_name
458 .section ".proc.info.init", #alloc, #execinstr
460 .type __arm922_proc_info,#object
464 .long PMD_TYPE_SECT | \
465 PMD_SECT_BUFFERABLE | \
466 PMD_SECT_CACHEABLE | \
468 PMD_SECT_AP_WRITE | \
473 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
474 .long cpu_arm922_name
475 .long arm922_processor_functions
478 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
479 .long arm922_cache_fns
483 .size __arm922_proc_info, . - __arm922_proc_info