blob: 5f460d7172536bec87ef668bad9e8038916e8555 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mm/proc-arm1020.S: MMU functions for ARM1020
3 *
4 * Copyright (C) 2000 ARM Limited
5 * Copyright (C) 2000 Deep Blue Solutions Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 *
22 * These are the low level assembler for performing cache and TLB
23 * functions on the arm1020.
24 *
25 * CONFIG_CPU_ARM1020_CPU_IDLE -> nohlt
26 */
27#include <linux/linkage.h>
28#include <linux/config.h>
29#include <linux/init.h>
30#include <asm/assembler.h>
Sam Ravnborge6ae7442005-09-09 21:08:59 +020031#include <asm/asm-offsets.h>
Russell King74945c82006-03-16 14:44:36 +000032#include <asm/pgtable-hwdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/pgtable.h>
34#include <asm/procinfo.h>
35#include <asm/ptrace.h>
36#include <asm/hardware.h>
37
38/*
39 * This is the maximum size of an area which will be invalidated
40 * using the single invalidate entry instructions. Anything larger
41 * than this, and we go for the whole cache.
42 *
43 * This value should be chosen such that we choose the cheapest
44 * alternative.
45 */
46#define MAX_AREA_SIZE 32768
47
48/*
49 * The size of one data cache line.
50 */
51#define CACHE_DLINESIZE 32
52
53/*
54 * The number of data cache segments.
55 */
56#define CACHE_DSEGMENTS 16
57
58/*
59 * The number of lines in a cache segment.
60 */
61#define CACHE_DENTRIES 64
62
63/*
64 * This is the size at which it becomes more efficient to
65 * clean the whole cache, rather than using the individual
66 * cache line maintainence instructions.
67 */
68#define CACHE_DLIMIT 32768
69
70 .text
71/*
72 * cpu_arm1020_proc_init()
73 */
74ENTRY(cpu_arm1020_proc_init)
75 mov pc, lr
76
77/*
78 * cpu_arm1020_proc_fin()
79 */
80ENTRY(cpu_arm1020_proc_fin)
81 stmfd sp!, {lr}
82 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
83 msr cpsr_c, ip
84 bl arm1020_flush_kern_cache_all
85 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
86 bic r0, r0, #0x1000 @ ...i............
87 bic r0, r0, #0x000e @ ............wca.
88 mcr p15, 0, r0, c1, c0, 0 @ disable caches
89 ldmfd sp!, {pc}
90
91/*
92 * cpu_arm1020_reset(loc)
93 *
94 * Perform a soft reset of the system. Put the CPU into the
95 * same state as it would be if it had been reset, and branch
96 * to what would be the reset vector.
97 *
98 * loc: location to jump to for soft reset
99 */
100 .align 5
101ENTRY(cpu_arm1020_reset)
102 mov ip, #0
103 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
104 mcr p15, 0, ip, c7, c10, 4 @ drain WB
105 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
106 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
107 bic ip, ip, #0x000f @ ............wcam
108 bic ip, ip, #0x1100 @ ...i...s........
109 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
110 mov pc, r0
111
112/*
113 * cpu_arm1020_do_idle()
114 */
115 .align 5
116ENTRY(cpu_arm1020_do_idle)
117 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
118 mov pc, lr
119
120/* ================================= CACHE ================================ */
121
122 .align 5
123/*
124 * flush_user_cache_all()
125 *
126 * Invalidate all cache entries in a particular address
127 * space.
128 */
129ENTRY(arm1020_flush_user_cache_all)
130 /* FALLTHROUGH */
131/*
132 * flush_kern_cache_all()
133 *
134 * Clean and invalidate the entire cache.
135 */
136ENTRY(arm1020_flush_kern_cache_all)
137 mov r2, #VM_EXEC
138 mov ip, #0
139__flush_whole_cache:
140#ifndef CONFIG_CPU_DCACHE_DISABLE
141 mcr p15, 0, ip, c7, c10, 4 @ drain WB
142 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
1431: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
1442: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
145 mcr p15, 0, ip, c7, c10, 4 @ drain WB
146 subs r3, r3, #1 << 26
147 bcs 2b @ entries 63 to 0
148 subs r1, r1, #1 << 5
149 bcs 1b @ segments 15 to 0
150#endif
151 tst r2, #VM_EXEC
152#ifndef CONFIG_CPU_ICACHE_DISABLE
153 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
154#endif
155 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
156 mov pc, lr
157
158/*
159 * flush_user_cache_range(start, end, flags)
160 *
161 * Invalidate a range of cache entries in the specified
162 * address space.
163 *
164 * - start - start address (inclusive)
165 * - end - end address (exclusive)
166 * - flags - vm_flags for this space
167 */
168ENTRY(arm1020_flush_user_cache_range)
169 mov ip, #0
170 sub r3, r1, r0 @ calculate total size
171 cmp r3, #CACHE_DLIMIT
172 bhs __flush_whole_cache
173
174#ifndef CONFIG_CPU_DCACHE_DISABLE
175 mcr p15, 0, ip, c7, c10, 4
1761: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
177 mcr p15, 0, ip, c7, c10, 4 @ drain WB
178 add r0, r0, #CACHE_DLINESIZE
179 cmp r0, r1
180 blo 1b
181#endif
182 tst r2, #VM_EXEC
183#ifndef CONFIG_CPU_ICACHE_DISABLE
184 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
185#endif
186 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
187 mov pc, lr
188
189/*
190 * coherent_kern_range(start, end)
191 *
192 * Ensure coherency between the Icache and the Dcache in the
193 * region described by start. If you have non-snooping
194 * Harvard caches, you need to implement this function.
195 *
196 * - start - virtual start address
197 * - end - virtual end address
198 */
199ENTRY(arm1020_coherent_kern_range)
200 /* FALLTRHOUGH */
201
202/*
203 * coherent_user_range(start, end)
204 *
205 * Ensure coherency between the Icache and the Dcache in the
206 * region described by start. If you have non-snooping
207 * Harvard caches, you need to implement this function.
208 *
209 * - start - virtual start address
210 * - end - virtual end address
211 */
212ENTRY(arm1020_coherent_user_range)
213 mov ip, #0
214 bic r0, r0, #CACHE_DLINESIZE - 1
215 mcr p15, 0, ip, c7, c10, 4
2161:
217#ifndef CONFIG_CPU_DCACHE_DISABLE
218 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
219 mcr p15, 0, ip, c7, c10, 4 @ drain WB
220#endif
221#ifndef CONFIG_CPU_ICACHE_DISABLE
222 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
223#endif
224 add r0, r0, #CACHE_DLINESIZE
225 cmp r0, r1
226 blo 1b
227 mcr p15, 0, ip, c7, c10, 4 @ drain WB
228 mov pc, lr
229
230/*
231 * flush_kern_dcache_page(void *page)
232 *
233 * Ensure no D cache aliasing occurs, either with itself or
234 * the I cache
235 *
236 * - page - page aligned address
237 */
238ENTRY(arm1020_flush_kern_dcache_page)
239 mov ip, #0
240#ifndef CONFIG_CPU_DCACHE_DISABLE
241 add r1, r0, #PAGE_SZ
2421: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
243 mcr p15, 0, ip, c7, c10, 4 @ drain WB
244 add r0, r0, #CACHE_DLINESIZE
245 cmp r0, r1
246 blo 1b
247#endif
248 mcr p15, 0, ip, c7, c10, 4 @ drain WB
249 mov pc, lr
250
251/*
252 * dma_inv_range(start, end)
253 *
254 * Invalidate (discard) the specified virtual address range.
255 * May not write back any entries. If 'start' or 'end'
256 * are not cache line aligned, those lines must be written
257 * back.
258 *
259 * - start - virtual start address
260 * - end - virtual end address
261 *
262 * (same as v4wb)
263 */
264ENTRY(arm1020_dma_inv_range)
265 mov ip, #0
266#ifndef CONFIG_CPU_DCACHE_DISABLE
267 tst r0, #CACHE_DLINESIZE - 1
268 bic r0, r0, #CACHE_DLINESIZE - 1
269 mcrne p15, 0, ip, c7, c10, 4
270 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
271 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
272 tst r1, #CACHE_DLINESIZE - 1
273 mcrne p15, 0, ip, c7, c10, 4
274 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
275 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
2761: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
277 add r0, r0, #CACHE_DLINESIZE
278 cmp r0, r1
279 blo 1b
280#endif
281 mcr p15, 0, ip, c7, c10, 4 @ drain WB
282 mov pc, lr
283
284/*
285 * dma_clean_range(start, end)
286 *
287 * Clean the specified virtual address range.
288 *
289 * - start - virtual start address
290 * - end - virtual end address
291 *
292 * (same as v4wb)
293 */
294ENTRY(arm1020_dma_clean_range)
295 mov ip, #0
296#ifndef CONFIG_CPU_DCACHE_DISABLE
297 bic r0, r0, #CACHE_DLINESIZE - 1
2981: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
299 mcr p15, 0, ip, c7, c10, 4 @ drain WB
300 add r0, r0, #CACHE_DLINESIZE
301 cmp r0, r1
302 blo 1b
303#endif
304 mcr p15, 0, ip, c7, c10, 4 @ drain WB
305 mov pc, lr
306
307/*
308 * dma_flush_range(start, end)
309 *
310 * Clean and invalidate the specified virtual address range.
311 *
312 * - start - virtual start address
313 * - end - virtual end address
314 */
315ENTRY(arm1020_dma_flush_range)
316 mov ip, #0
317#ifndef CONFIG_CPU_DCACHE_DISABLE
318 bic r0, r0, #CACHE_DLINESIZE - 1
319 mcr p15, 0, ip, c7, c10, 4
3201: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
321 mcr p15, 0, ip, c7, c10, 4 @ drain WB
322 add r0, r0, #CACHE_DLINESIZE
323 cmp r0, r1
324 blo 1b
325#endif
326 mcr p15, 0, ip, c7, c10, 4 @ drain WB
327 mov pc, lr
328
329ENTRY(arm1020_cache_fns)
330 .long arm1020_flush_kern_cache_all
331 .long arm1020_flush_user_cache_all
332 .long arm1020_flush_user_cache_range
333 .long arm1020_coherent_kern_range
334 .long arm1020_coherent_user_range
335 .long arm1020_flush_kern_dcache_page
336 .long arm1020_dma_inv_range
337 .long arm1020_dma_clean_range
338 .long arm1020_dma_flush_range
339
340 .align 5
341ENTRY(cpu_arm1020_dcache_clean_area)
342#ifndef CONFIG_CPU_DCACHE_DISABLE
343 mov ip, #0
3441: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
345 mcr p15, 0, ip, c7, c10, 4 @ drain WB
346 add r0, r0, #CACHE_DLINESIZE
347 subs r1, r1, #CACHE_DLINESIZE
348 bhi 1b
349#endif
350 mov pc, lr
351
352/* =============================== PageTable ============================== */
353
354/*
355 * cpu_arm1020_switch_mm(pgd)
356 *
357 * Set the translation base pointer to be as described by pgd.
358 *
359 * pgd: new page tables
360 */
361 .align 5
362ENTRY(cpu_arm1020_switch_mm)
363#ifndef CONFIG_CPU_DCACHE_DISABLE
364 mcr p15, 0, r3, c7, c10, 4
365 mov r1, #0xF @ 16 segments
3661: mov r3, #0x3F @ 64 entries
3672: mov ip, r3, LSL #26 @ shift up entry
368 orr ip, ip, r1, LSL #5 @ shift in/up index
369 mcr p15, 0, ip, c7, c14, 2 @ Clean & Inval DCache entry
370 mov ip, #0
371 mcr p15, 0, ip, c7, c10, 4
372 subs r3, r3, #1
373 cmp r3, #0
374 bge 2b @ entries 3F to 0
375 subs r1, r1, #1
376 cmp r1, #0
377 bge 1b @ segments 15 to 0
378
379#endif
380 mov r1, #0
381#ifndef CONFIG_CPU_ICACHE_DISABLE
382 mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
383#endif
384 mcr p15, 0, r1, c7, c10, 4 @ drain WB
385 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
386 mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
387 mov pc, lr
388
389/*
390 * cpu_arm1020_set_pte(ptep, pte)
391 *
392 * Set a PTE and flush it out
393 */
394 .align 5
395ENTRY(cpu_arm1020_set_pte)
396 str r1, [r0], #-2048 @ linux version
397
398 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
399
400 bic r2, r1, #PTE_SMALL_AP_MASK
401 bic r2, r2, #PTE_TYPE_MASK
402 orr r2, r2, #PTE_TYPE_SMALL
403
404 tst r1, #L_PTE_USER @ User?
405 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
406
407 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
408 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
409
410 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
411 movne r2, #0
412
413#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
414 eor r3, r1, #0x0a @ C & small page?
415 tst r3, #0x0b
416 biceq r2, r2, #4
417#endif
418 str r2, [r0] @ hardware version
419 mov r0, r0
420#ifndef CONFIG_CPU_DCACHE_DISABLE
421 mcr p15, 0, r0, c7, c10, 4
422 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
423#endif
424 mcr p15, 0, r0, c7, c10, 4 @ drain WB
425 mov pc, lr
426
427 __INIT
428
429 .type __arm1020_setup, #function
430__arm1020_setup:
431 mov r0, #0
432 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
433 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
434 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
435 mrc p15, 0, r0, c1, c0 @ get control register v4
436 ldr r5, arm1020_cr1_clear
437 bic r0, r0, r5
438 ldr r5, arm1020_cr1_set
439 orr r0, r0, r5
440#ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
441 orr r0, r0, #0x4000 @ .R.. .... .... ....
442#endif
443 mov pc, lr
444 .size __arm1020_setup, . - __arm1020_setup
445
446 /*
447 * R
448 * .RVI ZFRS BLDP WCAM
Catalin Marinasabaf48a2005-06-30 17:04:14 +0100449 * .011 1001 ..11 0101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 */
451 .type arm1020_cr1_clear, #object
452 .type arm1020_cr1_set, #object
453arm1020_cr1_clear:
454 .word 0x593f
455arm1020_cr1_set:
Catalin Marinasabaf48a2005-06-30 17:04:14 +0100456 .word 0x3935
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 __INITDATA
459
460/*
461 * Purpose : Function pointers used to access above functions - all calls
462 * come through these
463 */
464 .type arm1020_processor_functions, #object
465arm1020_processor_functions:
466 .word v4t_early_abort
467 .word cpu_arm1020_proc_init
468 .word cpu_arm1020_proc_fin
469 .word cpu_arm1020_reset
470 .word cpu_arm1020_do_idle
471 .word cpu_arm1020_dcache_clean_area
472 .word cpu_arm1020_switch_mm
473 .word cpu_arm1020_set_pte
474 .size arm1020_processor_functions, . - arm1020_processor_functions
475
476 .section ".rodata"
477
478 .type cpu_arch_name, #object
479cpu_arch_name:
480 .asciz "armv5t"
481 .size cpu_arch_name, . - cpu_arch_name
482
483 .type cpu_elf_name, #object
484cpu_elf_name:
485 .asciz "v5"
486 .size cpu_elf_name, . - cpu_elf_name
487
488 .type cpu_arm1020_name, #object
489cpu_arm1020_name:
490 .ascii "ARM1020"
491#ifndef CONFIG_CPU_ICACHE_DISABLE
492 .ascii "i"
493#endif
494#ifndef CONFIG_CPU_DCACHE_DISABLE
495 .ascii "d"
496#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
497 .ascii "(wt)"
498#else
499 .ascii "(wb)"
500#endif
501#endif
502#ifndef CONFIG_CPU_BPREDICT_DISABLE
503 .ascii "B"
504#endif
505#ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
506 .ascii "RR"
507#endif
508 .ascii "\0"
509 .size cpu_arm1020_name, . - cpu_arm1020_name
510
511 .align
512
Ben Dooks02b7dd12005-09-20 16:35:03 +0100513 .section ".proc.info.init", #alloc, #execinstr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 .type __arm1020_proc_info,#object
516__arm1020_proc_info:
517 .long 0x4104a200 @ ARM 1020T (Architecture v5T)
518 .long 0xff0ffff0
519 .long PMD_TYPE_SECT | \
520 PMD_SECT_AP_WRITE | \
521 PMD_SECT_AP_READ
522 b __arm1020_setup
523 .long cpu_arch_name
524 .long cpu_elf_name
525 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
526 .long cpu_arm1020_name
527 .long arm1020_processor_functions
528 .long v4wbi_tlb_fns
529 .long v4wb_user_fns
530 .long arm1020_cache_fns
531 .size __arm1020_proc_info, . - __arm1020_proc_info