1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * linux/arch/arm/mm/arm946.S: utility functions for ARM946E-S
5 * Copyright (C) 2004-2006 Hyok S. Choi (hyok.choi@samsung.com)
7 * (Many of cache codes are from proc-arm926.S)
9 #include <linux/linkage.h>
10 #include <linux/init.h>
11 #include <asm/assembler.h>
12 #include <asm/hwcap.h>
13 #include <asm/pgtable-hwdef.h>
14 #include <asm/pgtable.h>
15 #include <asm/ptrace.h>
16 #include "proc-macros.S"
19 * ARM946E-S is synthesizable to have 0KB to 1MB sized D-Cache,
20 * comprising 256 lines of 32 bytes (8 words).
22 #define CACHE_DSIZE (CONFIG_CPU_DCACHE_SIZE) /* typically 8KB. */
23 #define CACHE_DLINESIZE 32 /* fixed */
24 #define CACHE_DSEGMENTS 4 /* fixed */
25 #define CACHE_DENTRIES (CACHE_DSIZE / CACHE_DSEGMENTS / CACHE_DLINESIZE)
26 #define CACHE_DLIMIT (CACHE_DSIZE * 4) /* benchmark needed */
30 * cpu_arm946_proc_init()
31 * cpu_arm946_switch_mm()
33 * These are not required.
35 ENTRY(cpu_arm946_proc_init)
36 ENTRY(cpu_arm946_switch_mm)
40 * cpu_arm946_proc_fin()
42 ENTRY(cpu_arm946_proc_fin)
43 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
44 bic r0, r0, #0x00001000 @ i-cache
45 bic r0, r0, #0x00000004 @ d-cache
46 mcr p15, 0, r0, c1, c0, 0 @ disable caches
50 * cpu_arm946_reset(loc)
51 * Params : r0 = address to jump to
52 * Notes : This sets up everything for a reset
54 .pushsection .idmap.text, "ax"
55 ENTRY(cpu_arm946_reset)
57 mcr p15, 0, ip, c7, c5, 0 @ flush I cache
58 mcr p15, 0, ip, c7, c6, 0 @ flush D cache
59 mcr p15, 0, ip, c7, c10, 4 @ drain WB
60 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
61 bic ip, ip, #0x00000005 @ .............c.p
62 bic ip, ip, #0x00001000 @ i-cache
63 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
65 ENDPROC(cpu_arm946_reset)
69 * cpu_arm946_do_idle()
72 ENTRY(cpu_arm946_do_idle)
73 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
79 * Unconditionally clean and invalidate the entire icache.
81 ENTRY(arm946_flush_icache_all)
83 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
85 ENDPROC(arm946_flush_icache_all)
88 * flush_user_cache_all()
90 ENTRY(arm946_flush_user_cache_all)
94 * flush_kern_cache_all()
96 * Clean and invalidate the entire cache.
98 ENTRY(arm946_flush_kern_cache_all)
102 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
103 mcr p15, 0, ip, c7, c6, 0 @ flush D cache
105 mov r1, #(CACHE_DSEGMENTS - 1) << 29 @ 4 segments
106 1: orr r3, r1, #(CACHE_DENTRIES - 1) << 4 @ n entries
107 2: mcr p15, 0, r3, c7, c14, 2 @ clean/flush D index
109 bcs 2b @ entries n to 0
110 subs r1, r1, #1 << 29
111 bcs 1b @ segments 3 to 0
114 mcrne p15, 0, ip, c7, c5, 0 @ flush I cache
115 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
119 * flush_user_cache_range(start, end, flags)
121 * Clean and invalidate a range of cache entries in the
122 * specified address range.
124 * - start - start address (inclusive)
125 * - end - end address (exclusive)
126 * - flags - vm_flags describing address space
129 ENTRY(arm946_flush_user_cache_range)
131 sub r3, r1, r0 @ calculate total size
132 cmp r3, #CACHE_DLIMIT
133 bhs __flush_whole_cache
136 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
137 mcr p15, 0, r0, c7, c6, 1 @ 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, c6, 1 @ invalidate D entry
141 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
142 add r0, r0, #CACHE_DLINESIZE
144 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
145 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
146 add r0, r0, #CACHE_DLINESIZE
147 mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
148 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
149 add r0, r0, #CACHE_DLINESIZE
154 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
158 * coherent_kern_range(start, end)
160 * Ensure coherency between the Icache and the Dcache in the
161 * region described by start, end. If you have non-snooping
162 * Harvard caches, you need to implement this function.
164 * - start - virtual start address
165 * - end - virtual end address
167 ENTRY(arm946_coherent_kern_range)
171 * coherent_user_range(start, end)
173 * Ensure coherency between the Icache and the Dcache in the
174 * region described by start, end. If you have non-snooping
175 * Harvard caches, you need to implement this function.
177 * - start - virtual start address
178 * - end - virtual end address
181 ENTRY(arm946_coherent_user_range)
182 bic r0, r0, #CACHE_DLINESIZE - 1
183 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
184 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
185 add r0, r0, #CACHE_DLINESIZE
188 mcr p15, 0, r0, c7, c10, 4 @ drain WB
193 * flush_kern_dcache_area(void *addr, size_t size)
195 * Ensure no D cache aliasing occurs, either with itself or
198 * - addr - kernel address
199 * - size - region size
202 ENTRY(arm946_flush_kern_dcache_area)
204 1: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
205 add r0, r0, #CACHE_DLINESIZE
209 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
210 mcr p15, 0, r0, c7, c10, 4 @ drain WB
214 * dma_inv_range(start, end)
216 * Invalidate (discard) the specified virtual address range.
217 * May not write back any entries. If 'start' or 'end'
218 * are not cache line aligned, those lines must be written
221 * - start - virtual start address
222 * - end - virtual end address
225 arm946_dma_inv_range:
226 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
227 tst r0, #CACHE_DLINESIZE - 1
228 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
229 tst r1, #CACHE_DLINESIZE - 1
230 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
232 bic r0, r0, #CACHE_DLINESIZE - 1
233 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
234 add r0, r0, #CACHE_DLINESIZE
237 mcr p15, 0, r0, c7, c10, 4 @ drain WB
241 * dma_clean_range(start, end)
243 * Clean the specified virtual address range.
245 * - start - virtual start address
246 * - end - virtual end address
250 arm946_dma_clean_range:
251 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
252 bic r0, r0, #CACHE_DLINESIZE - 1
253 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
254 add r0, r0, #CACHE_DLINESIZE
258 mcr p15, 0, r0, c7, c10, 4 @ drain WB
262 * dma_flush_range(start, end)
264 * Clean and invalidate the specified virtual address range.
266 * - start - virtual start address
267 * - end - virtual end address
271 ENTRY(arm946_dma_flush_range)
272 bic r0, r0, #CACHE_DLINESIZE - 1
274 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
275 mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
277 mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
279 add r0, r0, #CACHE_DLINESIZE
282 mcr p15, 0, r0, c7, c10, 4 @ drain WB
286 * dma_map_area(start, size, dir)
287 * - start - kernel virtual start address
288 * - size - size of region
289 * - dir - DMA direction
291 ENTRY(arm946_dma_map_area)
293 cmp r2, #DMA_TO_DEVICE
294 beq arm946_dma_clean_range
295 bcs arm946_dma_inv_range
296 b arm946_dma_flush_range
297 ENDPROC(arm946_dma_map_area)
300 * dma_unmap_area(start, size, dir)
301 * - start - kernel virtual start address
302 * - size - size of region
303 * - dir - DMA direction
305 ENTRY(arm946_dma_unmap_area)
307 ENDPROC(arm946_dma_unmap_area)
309 .globl arm946_flush_kern_cache_louis
310 .equ arm946_flush_kern_cache_louis, arm946_flush_kern_cache_all
312 @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
313 define_cache_functions arm946
315 ENTRY(cpu_arm946_dcache_clean_area)
316 #ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
317 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
318 add r0, r0, #CACHE_DLINESIZE
319 subs r1, r1, #CACHE_DLINESIZE
322 mcr p15, 0, r0, c7, c10, 4 @ drain WB
325 .type __arm946_setup, #function
328 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
329 mcr p15, 0, r0, c7, c6, 0 @ invalidate D cache
330 mcr p15, 0, r0, c7, c10, 4 @ drain WB
332 mcr p15, 0, r0, c6, c3, 0 @ disable memory region 3~7
333 mcr p15, 0, r0, c6, c4, 0
334 mcr p15, 0, r0, c6, c5, 0
335 mcr p15, 0, r0, c6, c6, 0
336 mcr p15, 0, r0, c6, c7, 0
338 mov r0, #0x0000003F @ base = 0, size = 4GB
339 mcr p15, 0, r0, c6, c0, 0 @ set region 0, default
341 ldr r0, =(CONFIG_DRAM_BASE & 0xFFFFF000) @ base[31:12] of RAM
342 ldr r7, =CONFIG_DRAM_SIZE @ size of RAM (must be >= 4KB)
343 pr_val r3, r0, r7, #1
344 mcr p15, 0, r3, c6, c1, 0
346 ldr r0, =(CONFIG_FLASH_MEM_BASE & 0xFFFFF000) @ base[31:12] of FLASH
347 ldr r7, =CONFIG_FLASH_SIZE @ size of FLASH (must be >= 4KB)
348 pr_val r3, r0, r7, #1
349 mcr p15, 0, r3, c6, c2, 0
352 mcr p15, 0, r0, c2, c0, 0 @ region 1,2 d-cacheable
353 mcr p15, 0, r0, c2, c0, 1 @ region 1,2 i-cacheable
354 #ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
355 mov r0, #0x00 @ disable whole write buffer
357 mov r0, #0x02 @ region 1 write bufferred
359 mcr p15, 0, r0, c3, c0, 0
362 * Access Permission Settings for future permission control by PU.
365 * region 0 (whole) rw -- : b0001
366 * region 1 (RAM) rw rw : b0011
367 * region 2 (FLASH) rw r- : b0010
368 * region 3~7 (none) -- -- : b0000
371 orr r0, r0, #0x00000200
372 mcr p15, 0, r0, c5, c0, 2 @ set data access permission
373 mcr p15, 0, r0, c5, c0, 3 @ set inst. access permission
375 mrc p15, 0, r0, c1, c0 @ get control register
376 orr r0, r0, #0x00001000 @ I-cache
377 orr r0, r0, #0x00000005 @ MPU/D-cache
378 #ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
379 orr r0, r0, #0x00004000 @ .1.. .... .... ....
383 .size __arm946_setup, . - __arm946_setup
387 @ define struct processor (see <asm/proc-fns.h> and proc-macros.S)
388 define_processor_functions arm946, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
392 string cpu_arch_name, "armv5te"
393 string cpu_elf_name, "v5t"
394 string cpu_arm946_name, "ARM946E-S"
398 .section ".proc.info.init", "a"
399 .type __arm946_proc_info,#object
405 initfn __arm946_setup, __arm946_proc_info
408 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
409 .long cpu_arm946_name
410 .long arm946_processor_functions
413 .long arm946_cache_fns
414 .size __arm946_proc_info, . - __arm946_proc_info