2 * linux/arch/arm/mm/arm946.S: utility functions for ARM946E-S
4 * Copyright (C) 2004-2006 Hyok S. Choi (hyok.choi@samsung.com)
6 * (Many of cache codes are from proc-arm926.S)
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.
13 #include <linux/linkage.h>
14 #include <linux/init.h>
15 #include <asm/assembler.h>
17 #include <asm/pgtable-hwdef.h>
18 #include <asm/pgtable.h>
19 #include <asm/ptrace.h>
22 * ARM946E-S is synthesizable to have 0KB to 1MB sized D-Cache,
23 * comprising 256 lines of 32 bytes (8 words).
25 #define CACHE_DSIZE (CONFIG_CPU_DCACHE_SIZE) /* typically 8KB. */
26 #define CACHE_DLINESIZE 32 /* fixed */
27 #define CACHE_DSEGMENTS 4 /* fixed */
28 #define CACHE_DENTRIES (CACHE_DSIZE / CACHE_DSEGMENTS / CACHE_DLINESIZE)
29 #define CACHE_DLIMIT (CACHE_DSIZE * 4) /* benchmark needed */
33 * cpu_arm946_proc_init()
34 * cpu_arm946_switch_mm()
36 * These are not required.
38 ENTRY(cpu_arm946_proc_init)
39 ENTRY(cpu_arm946_switch_mm)
43 * cpu_arm946_proc_fin()
45 ENTRY(cpu_arm946_proc_fin)
47 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
49 bl arm946_flush_kern_cache_all
50 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
51 bic r0, r0, #0x00001000 @ i-cache
52 bic r0, r0, #0x00000004 @ d-cache
53 mcr p15, 0, r0, c1, c0, 0 @ disable caches
57 * cpu_arm946_reset(loc)
58 * Params : r0 = address to jump to
59 * Notes : This sets up everything for a reset
61 ENTRY(cpu_arm946_reset)
63 mcr p15, 0, ip, c7, c5, 0 @ flush I cache
64 mcr p15, 0, ip, c7, c6, 0 @ flush D cache
65 mcr p15, 0, ip, c7, c10, 4 @ drain WB
66 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
67 bic ip, ip, #0x00000005 @ .............c.p
68 bic ip, ip, #0x00001000 @ i-cache
69 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
73 * cpu_arm946_do_idle()
76 ENTRY(cpu_arm946_do_idle)
77 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
81 * flush_user_cache_all()
83 ENTRY(arm946_flush_user_cache_all)
87 * flush_kern_cache_all()
89 * Clean and invalidate the entire cache.
91 ENTRY(arm946_flush_kern_cache_all)
95 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
96 mcr p15, 0, ip, c7, c6, 0 @ flush D cache
98 mov r1, #(CACHE_DSEGMENTS - 1) << 29 @ 4 segments
99 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 4 @ n entries
100 2: mcr p15, 0, r3, c7, c14, 2 @ clean/flush D index
102 bcs 2b @ entries n to 0
103 subs r1, r1, #1 << 29
104 bcs 1b @ segments 3 to 0
107 mcrne p15, 0, ip, c7, c5, 0 @ flush I cache
108 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
112 * flush_user_cache_range(start, end, flags)
114 * Clean and invalidate a range of cache entries in the
115 * specified address range.
117 * - start - start address (inclusive)
118 * - end - end address (exclusive)
119 * - flags - vm_flags describing address space
122 ENTRY(arm946_flush_user_cache_range)
124 sub r3, r1, r0 @ calculate total size
125 cmp r3, #CACHE_DLIMIT
126 bhs __flush_whole_cache
129 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
130 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
131 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
132 add r0, r0, #CACHE_DLINESIZE
133 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
134 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
135 add r0, r0, #CACHE_DLINESIZE
137 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
138 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
139 add r0, r0, #CACHE_DLINESIZE
140 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
141 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
142 add r0, r0, #CACHE_DLINESIZE
147 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
151 * coherent_kern_range(start, end)
153 * Ensure coherency between the Icache and the Dcache in the
154 * region described by start, end. If you have non-snooping
155 * Harvard caches, you need to implement this function.
157 * - start - virtual start address
158 * - end - virtual end address
160 ENTRY(arm946_coherent_kern_range)
164 * coherent_user_range(start, end)
166 * Ensure coherency between the Icache and the Dcache in the
167 * region described by start, end. If you have non-snooping
168 * Harvard caches, you need to implement this function.
170 * - start - virtual start address
171 * - end - virtual end address
174 ENTRY(arm946_coherent_user_range)
175 bic r0, r0, #CACHE_DLINESIZE - 1
176 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
177 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
178 add r0, r0, #CACHE_DLINESIZE
181 mcr p15, 0, r0, c7, c10, 4 @ drain WB
185 * flush_kern_dcache_page(void *page)
187 * Ensure no D cache aliasing occurs, either with itself or
190 * - addr - page aligned address
193 ENTRY(arm946_flush_kern_dcache_page)
195 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
196 add r0, r0, #CACHE_DLINESIZE
200 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
201 mcr p15, 0, r0, c7, c10, 4 @ drain WB
205 * dma_inv_range(start, end)
207 * Invalidate (discard) the specified virtual address range.
208 * May not write back any entries. If 'start' or 'end'
209 * are not cache line aligned, those lines must be written
212 * - start - virtual start address
213 * - end - virtual end address
216 ENTRY(arm946_dma_inv_range)
217 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
218 tst r0, #CACHE_DLINESIZE - 1
219 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
220 tst r1, #CACHE_DLINESIZE - 1
221 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
223 bic r0, r0, #CACHE_DLINESIZE - 1
224 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
225 add r0, r0, #CACHE_DLINESIZE
228 mcr p15, 0, r0, c7, c10, 4 @ drain WB
232 * dma_clean_range(start, end)
234 * Clean the specified virtual address range.
236 * - start - virtual start address
237 * - end - virtual end address
241 ENTRY(arm946_dma_clean_range)
242 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
243 bic r0, r0, #CACHE_DLINESIZE - 1
244 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
245 add r0, r0, #CACHE_DLINESIZE
249 mcr p15, 0, r0, c7, c10, 4 @ drain WB
253 * dma_flush_range(start, end)
255 * Clean and invalidate the specified virtual address range.
257 * - start - virtual start address
258 * - end - virtual end address
262 ENTRY(arm946_dma_flush_range)
263 bic r0, r0, #CACHE_DLINESIZE - 1
265 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
266 mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
268 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
270 add r0, r0, #CACHE_DLINESIZE
273 mcr p15, 0, r0, c7, c10, 4 @ drain WB
276 ENTRY(arm946_cache_fns)
277 .long arm946_flush_kern_cache_all
278 .long arm946_flush_user_cache_all
279 .long arm946_flush_user_cache_range
280 .long arm946_coherent_kern_range
281 .long arm946_coherent_user_range
282 .long arm946_flush_kern_dcache_page
283 .long arm946_dma_inv_range
284 .long arm946_dma_clean_range
285 .long arm946_dma_flush_range
288 ENTRY(cpu_arm946_dcache_clean_area)
289 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
290 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
291 add r0, r0, #CACHE_DLINESIZE
292 subs r1, r1, #CACHE_DLINESIZE
295 mcr p15, 0, r0, c7, c10, 4 @ drain WB
300 .type __arm946_setup, #function
303 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
304 mcr p15, 0, r0, c7, c6, 0 @ invalidate D cache
305 mcr p15, 0, r0, c7, c10, 4 @ drain WB
307 mcr p15, 0, r0, c6, c3, 0 @ disable memory region 3~7
308 mcr p15, 0, r0, c6, c4, 0
309 mcr p15, 0, r0, c6, c5, 0
310 mcr p15, 0, r0, c6, c6, 0
311 mcr p15, 0, r0, c6, c7, 0
313 mov r0, #0x0000003F @ base = 0, size = 4GB
314 mcr p15, 0, r0, c6, c0, 0 @ set region 0, default
316 ldr r0, =(CONFIG_DRAM_BASE & 0xFFFFF000) @ base[31:12] of RAM
317 ldr r1, =(CONFIG_DRAM_SIZE >> 12) @ size of RAM (must be >= 4KB)
318 mov r2, #10 @ 11 is the minimum (4KB)
319 1: add r2, r2, #1 @ area size *= 2
321 bne 1b @ count not zero r-shift
322 orr r0, r0, r2, lsl #1 @ the region register value
323 orr r0, r0, #1 @ set enable bit
324 mcr p15, 0, r0, c6, c1, 0 @ set region 1, RAM
326 ldr r0, =(CONFIG_FLASH_MEM_BASE & 0xFFFFF000) @ base[31:12] of FLASH
327 ldr r1, =(CONFIG_FLASH_SIZE >> 12) @ size of FLASH (must be >= 4KB)
328 mov r2, #10 @ 11 is the minimum (4KB)
329 1: add r2, r2, #1 @ area size *= 2
331 bne 1b @ count not zero r-shift
332 orr r0, r0, r2, lsl #1 @ the region register value
333 orr r0, r0, #1 @ set enable bit
334 mcr p15, 0, r0, c6, c2, 0 @ set region 2, ROM/FLASH
337 mcr p15, 0, r0, c2, c0, 0 @ region 1,2 d-cacheable
338 mcr p15, 0, r0, c2, c0, 1 @ region 1,2 i-cacheable
339 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
340 mov r0, #0x00 @ disable whole write buffer
342 mov r0, #0x02 @ region 1 write bufferred
344 mcr p15, 0, r0, c3, c0, 0
347 * Access Permission Settings for future permission control by PU.
350 * region 0 (whole) rw -- : b0001
351 * region 1 (RAM) rw rw : b0011
352 * region 2 (FLASH) rw r- : b0010
353 * region 3~7 (none) -- -- : b0000
356 orr r0, r0, #0x00000200
357 mcr p15, 0, r0, c5, c0, 2 @ set data access permission
358 mcr p15, 0, r0, c5, c0, 3 @ set inst. access permission
360 mrc p15, 0, r0, c1, c0 @ get control register
361 orr r0, r0, #0x00001000 @ I-cache
362 orr r0, r0, #0x00000005 @ MPU/D-cache
363 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
364 orr r0, r0, #0x00004000 @ .1.. .... .... ....
368 .size __arm946_setup, . - __arm946_setup
373 * Purpose : Function pointers used to access above functions - all calls
376 .type arm946_processor_functions, #object
377 ENTRY(arm946_processor_functions)
378 .word nommu_early_abort
380 .word cpu_arm946_proc_init
381 .word cpu_arm946_proc_fin
382 .word cpu_arm946_reset
383 .word cpu_arm946_do_idle
385 .word cpu_arm946_dcache_clean_area
386 .word cpu_arm946_switch_mm
387 .word 0 @ cpu_*_set_pte
388 .size arm946_processor_functions, . - arm946_processor_functions
392 .type cpu_arch_name, #object
395 .size cpu_arch_name, . - cpu_arch_name
397 .type cpu_elf_name, #object
400 .size cpu_elf_name, . - cpu_elf_name
402 .type cpu_arm946_name, #object
405 .size cpu_arm946_name, . - cpu_arm946_name
409 .section ".proc.info.init", #alloc, #execinstr
410 .type __arm946_proc_info,#object
418 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
419 .long cpu_arm946_name
420 .long arm946_processor_functions
423 .long arm940_cache_fns
424 .size __arm946_proc_info, . - __arm946_proc_info