blob: 410b032faa3ba276b1fbff64d2664ae8423d959f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mm/proc-arm922.S: MMU functions for ARM922
3 *
4 * Copyright (C) 1999,2000 ARM Limited
5 * Copyright (C) 2000 Deep Blue Solutions Ltd.
6 * Copyright (C) 2001 Altera Corporation
7 *
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.
12 *
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.
17 *
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
21 *
22 *
23 * These are the low level assembler for performing cache and TLB
24 * functions on the arm922.
25 *
26 * CONFIG_CPU_ARM922_CPU_IDLE -> nohlt
27 */
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/page.h>
35#include <asm/ptrace.h>
36#include "proc-macros.S"
37
38/*
39 * The size of one data cache line.
40 */
41#define CACHE_DLINESIZE 32
42
43/*
44 * The number of data cache segments.
45 */
46#define CACHE_DSEGMENTS 4
47
48/*
49 * The number of lines in a cache segment.
50 */
51#define CACHE_DENTRIES 64
52
53/*
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
57 * be 32768).
58 */
59#define CACHE_DLIMIT 8192
60
61
62 .text
63/*
64 * cpu_arm922_proc_init()
65 */
66ENTRY(cpu_arm922_proc_init)
67 mov pc, lr
68
69/*
70 * cpu_arm922_proc_fin()
71 */
72ENTRY(cpu_arm922_proc_fin)
73 stmfd sp!, {lr}
74 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
75 msr cpsr_c, ip
76#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
77 bl arm922_flush_kern_cache_all
78#else
79 bl v4wt_flush_kern_cache_all
80#endif
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
85 ldmfd sp!, {pc}
86
87/*
88 * cpu_arm922_reset(loc)
89 *
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.
93 *
94 * loc: location to jump to for soft reset
95 */
96 .align 5
97ENTRY(cpu_arm922_reset)
98 mov ip, #0
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
106 mov pc, r0
107
108/*
109 * cpu_arm922_do_idle()
110 */
111 .align 5
112ENTRY(cpu_arm922_do_idle)
113 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
114 mov pc, lr
115
116
117#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
118
119/*
120 * flush_user_cache_all()
121 *
122 * Clean and invalidate all cache entries in a particular
123 * address space.
124 */
125ENTRY(arm922_flush_user_cache_all)
126 /* FALLTHROUGH */
127
128/*
129 * flush_kern_cache_all()
130 *
131 * Clean and invalidate the entire cache.
132 */
133ENTRY(arm922_flush_kern_cache_all)
134 mov r2, #VM_EXEC
135 mov ip, #0
136__flush_whole_cache:
137 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 8 segments
1381: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
1392: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
140 subs r3, r3, #1 << 26
141 bcs 2b @ entries 63 to 0
142 subs r1, r1, #1 << 5
143 bcs 1b @ segments 7 to 0
144 tst r2, #VM_EXEC
145 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
146 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
147 mov pc, lr
148
149/*
150 * flush_user_cache_range(start, end, flags)
151 *
152 * Clean and invalidate a range of cache entries in the
153 * specified address range.
154 *
155 * - start - start address (inclusive)
156 * - end - end address (exclusive)
157 * - flags - vm_flags describing address space
158 */
159ENTRY(arm922_flush_user_cache_range)
160 mov ip, #0
161 sub r3, r1, r0 @ calculate total size
162 cmp r3, #CACHE_DLIMIT
163 bhs __flush_whole_cache
164
1651: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
166 tst r2, #VM_EXEC
167 mcrne p15, 0, r0, c7, c5, 1 @ invalidate I entry
168 add r0, r0, #CACHE_DLINESIZE
169 cmp r0, r1
170 blo 1b
171 tst r2, #VM_EXEC
172 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
173 mov pc, lr
174
175/*
176 * coherent_kern_range(start, end)
177 *
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.
181 *
182 * - start - virtual start address
183 * - end - virtual end address
184 */
185ENTRY(arm922_coherent_kern_range)
186 /* FALLTHROUGH */
187
188/*
189 * coherent_user_range(start, end)
190 *
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.
194 *
195 * - start - virtual start address
196 * - end - virtual end address
197 */
198ENTRY(arm922_coherent_user_range)
199 bic r0, r0, #CACHE_DLINESIZE - 1
2001: 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
203 cmp r0, r1
204 blo 1b
205 mcr p15, 0, r0, c7, c10, 4 @ drain WB
206 mov pc, lr
207
208/*
209 * flush_kern_dcache_page(void *page)
210 *
211 * Ensure no D cache aliasing occurs, either with itself or
212 * the I cache
213 *
214 * - addr - page aligned address
215 */
216ENTRY(arm922_flush_kern_dcache_page)
217 add r1, r0, #PAGE_SZ
2181: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
219 add r0, r0, #CACHE_DLINESIZE
220 cmp r0, r1
221 blo 1b
222 mov r0, #0
223 mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
224 mcr p15, 0, r0, c7, c10, 4 @ drain WB
225 mov pc, lr
226
227/*
228 * dma_inv_range(start, end)
229 *
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
233 * back.
234 *
235 * - start - virtual start address
236 * - end - virtual end address
237 *
238 * (same as v4wb)
239 */
240ENTRY(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
2461: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
247 add r0, r0, #CACHE_DLINESIZE
248 cmp r0, r1
249 blo 1b
250 mcr p15, 0, r0, c7, c10, 4 @ drain WB
251 mov pc, lr
252
253/*
254 * dma_clean_range(start, end)
255 *
256 * Clean the specified virtual address range.
257 *
258 * - start - virtual start address
259 * - end - virtual end address
260 *
261 * (same as v4wb)
262 */
263ENTRY(arm922_dma_clean_range)
264 bic r0, r0, #CACHE_DLINESIZE - 1
2651: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
266 add r0, r0, #CACHE_DLINESIZE
267 cmp r0, r1
268 blo 1b
269 mcr p15, 0, r0, c7, c10, 4 @ drain WB
270 mov pc, lr
271
272/*
273 * dma_flush_range(start, end)
274 *
275 * Clean and invalidate the specified virtual address range.
276 *
277 * - start - virtual start address
278 * - end - virtual end address
279 */
280ENTRY(arm922_dma_flush_range)
281 bic r0, r0, #CACHE_DLINESIZE - 1
2821: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
283 add r0, r0, #CACHE_DLINESIZE
284 cmp r0, r1
285 blo 1b
286 mcr p15, 0, r0, c7, c10, 4 @ drain WB
287 mov pc, lr
288
289ENTRY(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
299
300#endif
301
302
303ENTRY(cpu_arm922_dcache_clean_area)
304#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
3051: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
306 add r0, r0, #CACHE_DLINESIZE
307 subs r1, r1, #CACHE_DLINESIZE
308 bhi 1b
309#endif
310 mov pc, lr
311
312/* =============================== PageTable ============================== */
313
314/*
315 * cpu_arm922_switch_mm(pgd)
316 *
317 * Set the translation base pointer to be as described by pgd.
318 *
319 * pgd: new page tables
320 */
321 .align 5
322ENTRY(cpu_arm922_switch_mm)
323 mov ip, #0
324#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
325 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
326#else
327@ && 'Clean & Invalidate whole DCache'
328@ && Re-written to use Index Ops.
329@ && Uses registers r1, r3 and ip
330
331 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 4 segments
3321: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
3332: mcr p15, 0, r3, c7, c14, 2 @ clean & invalidate D index
334 subs r3, r3, #1 << 26
335 bcs 2b @ entries 63 to 0
336 subs r1, r1, #1 << 5
337 bcs 1b @ segments 7 to 0
338#endif
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
343 mov pc, lr
344
345/*
346 * cpu_arm922_set_pte(ptep, pte)
347 *
348 * Set a PTE and flush it out
349 */
350 .align 5
351ENTRY(cpu_arm922_set_pte)
352 str r1, [r0], #-2048 @ linux version
353
354 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
355
356 bic r2, r1, #PTE_SMALL_AP_MASK
357 bic r2, r2, #PTE_TYPE_MASK
358 orr r2, r2, #PTE_TYPE_SMALL
359
360 tst r1, #L_PTE_USER @ User?
361 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
362
363 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
364 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
365
366 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
367 movne r2, #0
368
369#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
370 eor r3, r2, #0x0a @ C & small page?
371 tst r3, #0x0b
372 biceq r2, r2, #4
373#endif
374 str r2, [r0] @ hardware version
375 mov r0, r0
376 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
377 mcr p15, 0, r0, c7, c10, 4 @ drain WB
378 mov pc, lr
379
380 __INIT
381
382 .type __arm922_setup, #function
383__arm922_setup:
384 mov r0, #0
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
390 bic r0, r0, r5
391 ldr r5, arm922_cr1_set
392 orr r0, r0, r5
393 mov pc, lr
394 .size __arm922_setup, . - __arm922_setup
395
396 /*
397 * R
398 * .RVI ZFRS BLDP WCAM
399 * ..11 0001 ..11 0101
400 *
401 */
402 .type arm922_cr1_clear, #object
403 .type arm922_cr1_set, #object
404arm922_cr1_clear:
405 .word 0x3f3f
406arm922_cr1_set:
407 .word 0x3135
408
409 __INITDATA
410
411/*
412 * Purpose : Function pointers used to access above functions - all calls
413 * come through these
414 */
415 .type arm922_processor_functions, #object
416arm922_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
426
427 .section ".rodata"
428
429 .type cpu_arch_name, #object
430cpu_arch_name:
431 .asciz "armv4t"
432 .size cpu_arch_name, . - cpu_arch_name
433
434 .type cpu_elf_name, #object
435cpu_elf_name:
436 .asciz "v4"
437 .size cpu_elf_name, . - cpu_elf_name
438
439 .type cpu_arm922_name, #object
440cpu_arm922_name:
441 .ascii "ARM922T"
442#ifndef CONFIG_CPU_ICACHE_DISABLE
443 .ascii "i"
444#endif
445#ifndef CONFIG_CPU_DCACHE_DISABLE
446 .ascii "d"
447#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
448 .ascii "(wt)"
449#else
450 .ascii "(wb)"
451#endif
452#endif
453 .ascii "\0"
454 .size cpu_arm922_name, . - cpu_arm922_name
455
456 .align
457
Ben Dooks02b7dd12005-09-20 16:35:03 +0100458 .section ".proc.info.init", #alloc, #execinstr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 .type __arm922_proc_info,#object
461__arm922_proc_info:
462 .long 0x41009220
463 .long 0xff00fff0
464 .long PMD_TYPE_SECT | \
465 PMD_SECT_BUFFERABLE | \
466 PMD_SECT_CACHEABLE | \
467 PMD_BIT4 | \
468 PMD_SECT_AP_WRITE | \
469 PMD_SECT_AP_READ
470 b __arm922_setup
471 .long cpu_arch_name
472 .long cpu_elf_name
473 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
474 .long cpu_arm922_name
475 .long arm922_processor_functions
476 .long v4wbi_tlb_fns
477 .long v4wb_user_fns
478#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
479 .long arm922_cache_fns
480#else
481 .long v4wt_cache_fns
482#endif
483 .size __arm922_proc_info, . - __arm922_proc_info