blob: 700297ae4a55c460f871be3389da3ec3ee52f651 [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.
Hyok S. Choid090ddd2006-06-28 14:10:01 +01006 * hacked for non-paged-MM by Hyok S. Choi, 2003.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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 arm1020.
25 *
26 * CONFIG_CPU_ARM1020_CPU_IDLE -> nohlt
27 */
28#include <linux/linkage.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/*
38 * This is the maximum size of an area which will be invalidated
39 * using the single invalidate entry instructions. Anything larger
40 * than this, and we go for the whole cache.
41 *
42 * This value should be chosen such that we choose the cheapest
43 * alternative.
44 */
45#define MAX_AREA_SIZE 32768
46
47/*
48 * The size of one data cache line.
49 */
50#define CACHE_DLINESIZE 32
51
52/*
53 * The number of data cache segments.
54 */
55#define CACHE_DSEGMENTS 16
56
57/*
58 * The number of lines in a cache segment.
59 */
60#define CACHE_DENTRIES 64
61
62/*
63 * This is the size at which it becomes more efficient to
64 * clean the whole cache, rather than using the individual
65 * cache line maintainence instructions.
66 */
67#define CACHE_DLIMIT 32768
68
69 .text
70/*
71 * cpu_arm1020_proc_init()
72 */
73ENTRY(cpu_arm1020_proc_init)
74 mov pc, lr
75
76/*
77 * cpu_arm1020_proc_fin()
78 */
79ENTRY(cpu_arm1020_proc_fin)
80 stmfd sp!, {lr}
81 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
82 msr cpsr_c, ip
83 bl arm1020_flush_kern_cache_all
84 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
85 bic r0, r0, #0x1000 @ ...i............
86 bic r0, r0, #0x000e @ ............wca.
87 mcr p15, 0, r0, c1, c0, 0 @ disable caches
88 ldmfd sp!, {pc}
89
90/*
91 * cpu_arm1020_reset(loc)
92 *
93 * Perform a soft reset of the system. Put the CPU into the
94 * same state as it would be if it had been reset, and branch
95 * to what would be the reset vector.
96 *
97 * loc: location to jump to for soft reset
98 */
99 .align 5
100ENTRY(cpu_arm1020_reset)
101 mov ip, #0
102 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
103 mcr p15, 0, ip, c7, c10, 4 @ drain WB
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100104#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100106#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
108 bic ip, ip, #0x000f @ ............wcam
109 bic ip, ip, #0x1100 @ ...i...s........
110 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
111 mov pc, r0
112
113/*
114 * cpu_arm1020_do_idle()
115 */
116 .align 5
117ENTRY(cpu_arm1020_do_idle)
118 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
119 mov pc, lr
120
121/* ================================= CACHE ================================ */
122
123 .align 5
124/*
125 * flush_user_cache_all()
126 *
127 * Invalidate all cache entries in a particular address
128 * space.
129 */
130ENTRY(arm1020_flush_user_cache_all)
131 /* FALLTHROUGH */
132/*
133 * flush_kern_cache_all()
134 *
135 * Clean and invalidate the entire cache.
136 */
137ENTRY(arm1020_flush_kern_cache_all)
138 mov r2, #VM_EXEC
139 mov ip, #0
140__flush_whole_cache:
141#ifndef CONFIG_CPU_DCACHE_DISABLE
142 mcr p15, 0, ip, c7, c10, 4 @ drain WB
143 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
1441: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
1452: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
146 mcr p15, 0, ip, c7, c10, 4 @ drain WB
147 subs r3, r3, #1 << 26
148 bcs 2b @ entries 63 to 0
149 subs r1, r1, #1 << 5
150 bcs 1b @ segments 15 to 0
151#endif
152 tst r2, #VM_EXEC
153#ifndef CONFIG_CPU_ICACHE_DISABLE
154 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
155#endif
156 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
157 mov pc, lr
158
159/*
160 * flush_user_cache_range(start, end, flags)
161 *
162 * Invalidate a range of cache entries in the specified
163 * address space.
164 *
165 * - start - start address (inclusive)
166 * - end - end address (exclusive)
167 * - flags - vm_flags for this space
168 */
169ENTRY(arm1020_flush_user_cache_range)
170 mov ip, #0
171 sub r3, r1, r0 @ calculate total size
172 cmp r3, #CACHE_DLIMIT
173 bhs __flush_whole_cache
174
175#ifndef CONFIG_CPU_DCACHE_DISABLE
176 mcr p15, 0, ip, c7, c10, 4
1771: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
178 mcr p15, 0, ip, c7, c10, 4 @ drain WB
179 add r0, r0, #CACHE_DLINESIZE
180 cmp r0, r1
181 blo 1b
182#endif
183 tst r2, #VM_EXEC
184#ifndef CONFIG_CPU_ICACHE_DISABLE
185 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
186#endif
187 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
188 mov pc, lr
189
190/*
191 * coherent_kern_range(start, end)
192 *
193 * Ensure coherency between the Icache and the Dcache in the
194 * region described by start. If you have non-snooping
195 * Harvard caches, you need to implement this function.
196 *
197 * - start - virtual start address
198 * - end - virtual end address
199 */
200ENTRY(arm1020_coherent_kern_range)
201 /* FALLTRHOUGH */
202
203/*
204 * coherent_user_range(start, end)
205 *
206 * Ensure coherency between the Icache and the Dcache in the
207 * region described by start. If you have non-snooping
208 * Harvard caches, you need to implement this function.
209 *
210 * - start - virtual start address
211 * - end - virtual end address
212 */
213ENTRY(arm1020_coherent_user_range)
214 mov ip, #0
215 bic r0, r0, #CACHE_DLINESIZE - 1
216 mcr p15, 0, ip, c7, c10, 4
2171:
218#ifndef CONFIG_CPU_DCACHE_DISABLE
219 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
220 mcr p15, 0, ip, c7, c10, 4 @ drain WB
221#endif
222#ifndef CONFIG_CPU_ICACHE_DISABLE
223 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
224#endif
225 add r0, r0, #CACHE_DLINESIZE
226 cmp r0, r1
227 blo 1b
228 mcr p15, 0, ip, c7, c10, 4 @ drain WB
229 mov pc, lr
230
231/*
232 * flush_kern_dcache_page(void *page)
233 *
234 * Ensure no D cache aliasing occurs, either with itself or
235 * the I cache
236 *
237 * - page - page aligned address
238 */
239ENTRY(arm1020_flush_kern_dcache_page)
240 mov ip, #0
241#ifndef CONFIG_CPU_DCACHE_DISABLE
242 add r1, r0, #PAGE_SZ
2431: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
244 mcr p15, 0, ip, c7, c10, 4 @ drain WB
245 add r0, r0, #CACHE_DLINESIZE
246 cmp r0, r1
247 blo 1b
248#endif
249 mcr p15, 0, ip, c7, c10, 4 @ drain WB
250 mov pc, lr
251
252/*
253 * dma_inv_range(start, end)
254 *
255 * Invalidate (discard) the specified virtual address range.
256 * May not write back any entries. If 'start' or 'end'
257 * are not cache line aligned, those lines must be written
258 * back.
259 *
260 * - start - virtual start address
261 * - end - virtual end address
262 *
263 * (same as v4wb)
264 */
265ENTRY(arm1020_dma_inv_range)
266 mov ip, #0
267#ifndef CONFIG_CPU_DCACHE_DISABLE
268 tst r0, #CACHE_DLINESIZE - 1
269 bic r0, r0, #CACHE_DLINESIZE - 1
270 mcrne p15, 0, ip, c7, c10, 4
271 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
272 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
273 tst r1, #CACHE_DLINESIZE - 1
274 mcrne p15, 0, ip, c7, c10, 4
275 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
276 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
2771: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
278 add r0, r0, #CACHE_DLINESIZE
279 cmp r0, r1
280 blo 1b
281#endif
282 mcr p15, 0, ip, c7, c10, 4 @ drain WB
283 mov pc, lr
284
285/*
286 * dma_clean_range(start, end)
287 *
288 * Clean the specified virtual address range.
289 *
290 * - start - virtual start address
291 * - end - virtual end address
292 *
293 * (same as v4wb)
294 */
295ENTRY(arm1020_dma_clean_range)
296 mov ip, #0
297#ifndef CONFIG_CPU_DCACHE_DISABLE
298 bic r0, r0, #CACHE_DLINESIZE - 1
2991: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
300 mcr p15, 0, ip, c7, c10, 4 @ drain WB
301 add r0, r0, #CACHE_DLINESIZE
302 cmp r0, r1
303 blo 1b
304#endif
305 mcr p15, 0, ip, c7, c10, 4 @ drain WB
306 mov pc, lr
307
308/*
309 * dma_flush_range(start, end)
310 *
311 * Clean and invalidate the specified virtual address range.
312 *
313 * - start - virtual start address
314 * - end - virtual end address
315 */
316ENTRY(arm1020_dma_flush_range)
317 mov ip, #0
318#ifndef CONFIG_CPU_DCACHE_DISABLE
319 bic r0, r0, #CACHE_DLINESIZE - 1
320 mcr p15, 0, ip, c7, c10, 4
3211: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
322 mcr p15, 0, ip, c7, c10, 4 @ drain WB
323 add r0, r0, #CACHE_DLINESIZE
324 cmp r0, r1
325 blo 1b
326#endif
327 mcr p15, 0, ip, c7, c10, 4 @ drain WB
328 mov pc, lr
329
330ENTRY(arm1020_cache_fns)
331 .long arm1020_flush_kern_cache_all
332 .long arm1020_flush_user_cache_all
333 .long arm1020_flush_user_cache_range
334 .long arm1020_coherent_kern_range
335 .long arm1020_coherent_user_range
336 .long arm1020_flush_kern_dcache_page
337 .long arm1020_dma_inv_range
338 .long arm1020_dma_clean_range
339 .long arm1020_dma_flush_range
340
341 .align 5
342ENTRY(cpu_arm1020_dcache_clean_area)
343#ifndef CONFIG_CPU_DCACHE_DISABLE
344 mov ip, #0
3451: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
346 mcr p15, 0, ip, c7, c10, 4 @ drain WB
347 add r0, r0, #CACHE_DLINESIZE
348 subs r1, r1, #CACHE_DLINESIZE
349 bhi 1b
350#endif
351 mov pc, lr
352
353/* =============================== PageTable ============================== */
354
355/*
356 * cpu_arm1020_switch_mm(pgd)
357 *
358 * Set the translation base pointer to be as described by pgd.
359 *
360 * pgd: new page tables
361 */
362 .align 5
363ENTRY(cpu_arm1020_switch_mm)
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100364#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#ifndef CONFIG_CPU_DCACHE_DISABLE
366 mcr p15, 0, r3, c7, c10, 4
367 mov r1, #0xF @ 16 segments
3681: mov r3, #0x3F @ 64 entries
3692: mov ip, r3, LSL #26 @ shift up entry
370 orr ip, ip, r1, LSL #5 @ shift in/up index
371 mcr p15, 0, ip, c7, c14, 2 @ Clean & Inval DCache entry
372 mov ip, #0
373 mcr p15, 0, ip, c7, c10, 4
374 subs r3, r3, #1
375 cmp r3, #0
376 bge 2b @ entries 3F to 0
377 subs r1, r1, #1
378 cmp r1, #0
379 bge 1b @ segments 15 to 0
380
381#endif
382 mov r1, #0
383#ifndef CONFIG_CPU_ICACHE_DISABLE
384 mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
385#endif
386 mcr p15, 0, r1, c7, c10, 4 @ drain WB
387 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
388 mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100389#endif /* CONFIG_MMU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 mov pc, lr
391
392/*
393 * cpu_arm1020_set_pte(ptep, pte)
394 *
395 * Set a PTE and flush it out
396 */
397 .align 5
398ENTRY(cpu_arm1020_set_pte)
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100399#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 str r1, [r0], #-2048 @ linux version
401
402 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
403
404 bic r2, r1, #PTE_SMALL_AP_MASK
405 bic r2, r2, #PTE_TYPE_MASK
406 orr r2, r2, #PTE_TYPE_SMALL
407
408 tst r1, #L_PTE_USER @ User?
409 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
410
411 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
412 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
413
414 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
415 movne r2, #0
416
417#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
418 eor r3, r1, #0x0a @ C & small page?
419 tst r3, #0x0b
420 biceq r2, r2, #4
421#endif
422 str r2, [r0] @ hardware version
423 mov r0, r0
424#ifndef CONFIG_CPU_DCACHE_DISABLE
425 mcr p15, 0, r0, c7, c10, 4
426 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
427#endif
428 mcr p15, 0, r0, c7, c10, 4 @ drain WB
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100429#endif /* CONFIG_MMU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 mov pc, lr
431
432 __INIT
433
434 .type __arm1020_setup, #function
435__arm1020_setup:
436 mov r0, #0
437 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
438 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100439#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100441#endif
Russell King22b190862006-06-29 15:09:57 +0100442
443 adr r5, arm1020_crval
444 ldmia r5, {r5, r6}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 mrc p15, 0, r0, c1, c0 @ get control register v4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 bic r0, r0, r5
Russell King22b190862006-06-29 15:09:57 +0100447 orr r0, r0, r6
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448#ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
449 orr r0, r0, #0x4000 @ .R.. .... .... ....
450#endif
451 mov pc, lr
452 .size __arm1020_setup, . - __arm1020_setup
453
454 /*
455 * R
456 * .RVI ZFRS BLDP WCAM
Catalin Marinasabaf48a2005-06-30 17:04:14 +0100457 * .011 1001 ..11 0101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 */
Russell King22b190862006-06-29 15:09:57 +0100459 .type arm1020_crval, #object
460arm1020_crval:
461 crval clear=0x0000593f, mmuset=0x00003935, ucset=0x00001930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 __INITDATA
464
465/*
466 * Purpose : Function pointers used to access above functions - all calls
467 * come through these
468 */
469 .type arm1020_processor_functions, #object
470arm1020_processor_functions:
471 .word v4t_early_abort
472 .word cpu_arm1020_proc_init
473 .word cpu_arm1020_proc_fin
474 .word cpu_arm1020_reset
475 .word cpu_arm1020_do_idle
476 .word cpu_arm1020_dcache_clean_area
477 .word cpu_arm1020_switch_mm
478 .word cpu_arm1020_set_pte
479 .size arm1020_processor_functions, . - arm1020_processor_functions
480
481 .section ".rodata"
482
483 .type cpu_arch_name, #object
484cpu_arch_name:
485 .asciz "armv5t"
486 .size cpu_arch_name, . - cpu_arch_name
487
488 .type cpu_elf_name, #object
489cpu_elf_name:
490 .asciz "v5"
491 .size cpu_elf_name, . - cpu_elf_name
492
493 .type cpu_arm1020_name, #object
494cpu_arm1020_name:
495 .ascii "ARM1020"
496#ifndef CONFIG_CPU_ICACHE_DISABLE
497 .ascii "i"
498#endif
499#ifndef CONFIG_CPU_DCACHE_DISABLE
500 .ascii "d"
501#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
502 .ascii "(wt)"
503#else
504 .ascii "(wb)"
505#endif
506#endif
507#ifndef CONFIG_CPU_BPREDICT_DISABLE
508 .ascii "B"
509#endif
510#ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
511 .ascii "RR"
512#endif
513 .ascii "\0"
514 .size cpu_arm1020_name, . - cpu_arm1020_name
515
516 .align
517
Ben Dooks02b7dd12005-09-20 16:35:03 +0100518 .section ".proc.info.init", #alloc, #execinstr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 .type __arm1020_proc_info,#object
521__arm1020_proc_info:
522 .long 0x4104a200 @ ARM 1020T (Architecture v5T)
523 .long 0xff0ffff0
524 .long PMD_TYPE_SECT | \
525 PMD_SECT_AP_WRITE | \
526 PMD_SECT_AP_READ
Russell King8799ee92006-06-29 18:24:21 +0100527 .long PMD_TYPE_SECT | \
528 PMD_SECT_AP_WRITE | \
529 PMD_SECT_AP_READ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 b __arm1020_setup
531 .long cpu_arch_name
532 .long cpu_elf_name
533 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB
534 .long cpu_arm1020_name
535 .long arm1020_processor_functions
536 .long v4wbi_tlb_fns
537 .long v4wb_user_fns
538 .long arm1020_cache_fns
539 .size __arm1020_proc_info, . - __arm1020_proc_info