blob: 0c33a5ed5a613adf7253badcf8b331f945ca34c1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mm/proc-arm1020e.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 arm1020e.
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_arm1020e_proc_init()
72 */
73ENTRY(cpu_arm1020e_proc_init)
74 mov pc, lr
75
76/*
77 * cpu_arm1020e_proc_fin()
78 */
79ENTRY(cpu_arm1020e_proc_fin)
80 stmfd sp!, {lr}
81 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
82 msr cpsr_c, ip
83 bl arm1020e_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_arm1020e_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_arm1020e_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_arm1020e_do_idle()
115 */
116 .align 5
117ENTRY(cpu_arm1020e_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(arm1020e_flush_user_cache_all)
131 /* FALLTHROUGH */
132/*
133 * flush_kern_cache_all()
134 *
135 * Clean and invalidate the entire cache.
136 */
137ENTRY(arm1020e_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 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(arm1020e_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
1751: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
176 add r0, r0, #CACHE_DLINESIZE
177 cmp r0, r1
178 blo 1b
179#endif
180 tst r2, #VM_EXEC
181#ifndef CONFIG_CPU_ICACHE_DISABLE
182 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
183#endif
184 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
185 mov pc, lr
186
187/*
188 * coherent_kern_range(start, end)
189 *
190 * Ensure coherency between the Icache and the Dcache in the
191 * region described by start. If you have non-snooping
192 * Harvard caches, you need to implement this function.
193 *
194 * - start - virtual start address
195 * - end - virtual end address
196 */
197ENTRY(arm1020e_coherent_kern_range)
198 /* FALLTHROUGH */
199/*
200 * coherent_user_range(start, end)
201 *
202 * Ensure coherency between the Icache and the Dcache in the
203 * region described by start. If you have non-snooping
204 * Harvard caches, you need to implement this function.
205 *
206 * - start - virtual start address
207 * - end - virtual end address
208 */
209ENTRY(arm1020e_coherent_user_range)
210 mov ip, #0
211 bic r0, r0, #CACHE_DLINESIZE - 1
2121:
213#ifndef CONFIG_CPU_DCACHE_DISABLE
214 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
215#endif
216#ifndef CONFIG_CPU_ICACHE_DISABLE
217 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
218#endif
219 add r0, r0, #CACHE_DLINESIZE
220 cmp r0, r1
221 blo 1b
222 mcr p15, 0, ip, c7, c10, 4 @ drain WB
223 mov pc, lr
224
225/*
226 * flush_kern_dcache_page(void *page)
227 *
228 * Ensure no D cache aliasing occurs, either with itself or
229 * the I cache
230 *
231 * - page - page aligned address
232 */
233ENTRY(arm1020e_flush_kern_dcache_page)
234 mov ip, #0
235#ifndef CONFIG_CPU_DCACHE_DISABLE
236 add r1, r0, #PAGE_SZ
2371: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
238 add r0, r0, #CACHE_DLINESIZE
239 cmp r0, r1
240 blo 1b
241#endif
242 mcr p15, 0, ip, c7, c10, 4 @ drain WB
243 mov pc, lr
244
245/*
246 * dma_inv_range(start, end)
247 *
248 * Invalidate (discard) the specified virtual address range.
249 * May not write back any entries. If 'start' or 'end'
250 * are not cache line aligned, those lines must be written
251 * back.
252 *
253 * - start - virtual start address
254 * - end - virtual end address
255 *
256 * (same as v4wb)
257 */
258ENTRY(arm1020e_dma_inv_range)
259 mov ip, #0
260#ifndef CONFIG_CPU_DCACHE_DISABLE
261 tst r0, #CACHE_DLINESIZE - 1
262 bic r0, r0, #CACHE_DLINESIZE - 1
263 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
264 tst r1, #CACHE_DLINESIZE - 1
265 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
2661: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
267 add r0, r0, #CACHE_DLINESIZE
268 cmp r0, r1
269 blo 1b
270#endif
271 mcr p15, 0, ip, c7, c10, 4 @ drain WB
272 mov pc, lr
273
274/*
275 * dma_clean_range(start, end)
276 *
277 * Clean the specified virtual address range.
278 *
279 * - start - virtual start address
280 * - end - virtual end address
281 *
282 * (same as v4wb)
283 */
284ENTRY(arm1020e_dma_clean_range)
285 mov ip, #0
286#ifndef CONFIG_CPU_DCACHE_DISABLE
287 bic r0, r0, #CACHE_DLINESIZE - 1
2881: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
289 add r0, r0, #CACHE_DLINESIZE
290 cmp r0, r1
291 blo 1b
292#endif
293 mcr p15, 0, ip, c7, c10, 4 @ drain WB
294 mov pc, lr
295
296/*
297 * dma_flush_range(start, end)
298 *
299 * Clean and invalidate the specified virtual address range.
300 *
301 * - start - virtual start address
302 * - end - virtual end address
303 */
304ENTRY(arm1020e_dma_flush_range)
305 mov ip, #0
306#ifndef CONFIG_CPU_DCACHE_DISABLE
307 bic r0, r0, #CACHE_DLINESIZE - 1
3081: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
309 add r0, r0, #CACHE_DLINESIZE
310 cmp r0, r1
311 blo 1b
312#endif
313 mcr p15, 0, ip, c7, c10, 4 @ drain WB
314 mov pc, lr
315
316ENTRY(arm1020e_cache_fns)
317 .long arm1020e_flush_kern_cache_all
318 .long arm1020e_flush_user_cache_all
319 .long arm1020e_flush_user_cache_range
320 .long arm1020e_coherent_kern_range
321 .long arm1020e_coherent_user_range
322 .long arm1020e_flush_kern_dcache_page
323 .long arm1020e_dma_inv_range
324 .long arm1020e_dma_clean_range
325 .long arm1020e_dma_flush_range
326
327 .align 5
328ENTRY(cpu_arm1020e_dcache_clean_area)
329#ifndef CONFIG_CPU_DCACHE_DISABLE
330 mov ip, #0
3311: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
332 add r0, r0, #CACHE_DLINESIZE
333 subs r1, r1, #CACHE_DLINESIZE
334 bhi 1b
335#endif
336 mov pc, lr
337
338/* =============================== PageTable ============================== */
339
340/*
341 * cpu_arm1020e_switch_mm(pgd)
342 *
343 * Set the translation base pointer to be as described by pgd.
344 *
345 * pgd: new page tables
346 */
347 .align 5
348ENTRY(cpu_arm1020e_switch_mm)
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100349#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350#ifndef CONFIG_CPU_DCACHE_DISABLE
351 mcr p15, 0, r3, c7, c10, 4
352 mov r1, #0xF @ 16 segments
3531: mov r3, #0x3F @ 64 entries
3542: mov ip, r3, LSL #26 @ shift up entry
355 orr ip, ip, r1, LSL #5 @ shift in/up index
356 mcr p15, 0, ip, c7, c14, 2 @ Clean & Inval DCache entry
357 mov ip, #0
358 subs r3, r3, #1
359 cmp r3, #0
360 bge 2b @ entries 3F to 0
361 subs r1, r1, #1
362 cmp r1, #0
363 bge 1b @ segments 15 to 0
364
365#endif
366 mov r1, #0
367#ifndef CONFIG_CPU_ICACHE_DISABLE
368 mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
369#endif
370 mcr p15, 0, r1, c7, c10, 4 @ drain WB
371 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
372 mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100373#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 mov pc, lr
375
376/*
377 * cpu_arm1020e_set_pte(ptep, pte)
378 *
379 * Set a PTE and flush it out
380 */
381 .align 5
382ENTRY(cpu_arm1020e_set_pte)
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100383#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 str r1, [r0], #-2048 @ linux version
385
386 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
387
388 bic r2, r1, #PTE_SMALL_AP_MASK
389 bic r2, r2, #PTE_TYPE_MASK
390 orr r2, r2, #PTE_TYPE_SMALL
391
392 tst r1, #L_PTE_USER @ User?
393 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
394
395 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
396 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
397
398 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
399 movne r2, #0
400
401#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
402 eor r3, r1, #0x0a @ C & small page?
403 tst r3, #0x0b
404 biceq r2, r2, #4
405#endif
406 str r2, [r0] @ hardware version
407 mov r0, r0
408#ifndef CONFIG_CPU_DCACHE_DISABLE
409 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
410#endif
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100411#endif /* CONFIG_MMU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 mov pc, lr
413
414 __INIT
415
416 .type __arm1020e_setup, #function
417__arm1020e_setup:
418 mov r0, #0
419 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
420 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100421#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100423#endif
Russell King22b19082006-06-29 15:09:57 +0100424 adr r5, arm1020e_crval
425 ldmia r5, {r5, r6}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 mrc p15, 0, r0, c1, c0 @ get control register v4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 bic r0, r0, r5
Russell King22b19082006-06-29 15:09:57 +0100428 orr r0, r0, r6
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
430 orr r0, r0, #0x4000 @ .R.. .... .... ....
431#endif
432 mov pc, lr
433 .size __arm1020e_setup, . - __arm1020e_setup
434
435 /*
436 * R
437 * .RVI ZFRS BLDP WCAM
Catalin Marinasabaf48a2005-06-30 17:04:14 +0100438 * .011 1001 ..11 0101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 */
Russell King22b19082006-06-29 15:09:57 +0100440 .type arm1020e_crval, #object
441arm1020e_crval:
442 crval clear=0x00007f3f, mmuset=0x00003935, ucset=0x00001930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 __INITDATA
445
446/*
447 * Purpose : Function pointers used to access above functions - all calls
448 * come through these
449 */
450 .type arm1020e_processor_functions, #object
451arm1020e_processor_functions:
452 .word v4t_early_abort
453 .word cpu_arm1020e_proc_init
454 .word cpu_arm1020e_proc_fin
455 .word cpu_arm1020e_reset
456 .word cpu_arm1020e_do_idle
457 .word cpu_arm1020e_dcache_clean_area
458 .word cpu_arm1020e_switch_mm
459 .word cpu_arm1020e_set_pte
460 .size arm1020e_processor_functions, . - arm1020e_processor_functions
461
462 .section ".rodata"
463
464 .type cpu_arch_name, #object
465cpu_arch_name:
466 .asciz "armv5te"
467 .size cpu_arch_name, . - cpu_arch_name
468
469 .type cpu_elf_name, #object
470cpu_elf_name:
471 .asciz "v5"
472 .size cpu_elf_name, . - cpu_elf_name
473
474 .type cpu_arm1020e_name, #object
475cpu_arm1020e_name:
Russell King264edb32006-06-29 15:03:09 +0100476 .asciz "ARM1020E"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 .size cpu_arm1020e_name, . - cpu_arm1020e_name
478
479 .align
480
Ben Dooks02b7dd12005-09-20 16:35:03 +0100481 .section ".proc.info.init", #alloc, #execinstr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 .type __arm1020e_proc_info,#object
484__arm1020e_proc_info:
485 .long 0x4105a200 @ ARM 1020TE (Architecture v5TE)
486 .long 0xff0ffff0
487 .long PMD_TYPE_SECT | \
488 PMD_BIT4 | \
489 PMD_SECT_AP_WRITE | \
490 PMD_SECT_AP_READ
Russell King8799ee92006-06-29 18:24:21 +0100491 .long PMD_TYPE_SECT | \
492 PMD_BIT4 | \
493 PMD_SECT_AP_WRITE | \
494 PMD_SECT_AP_READ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 b __arm1020e_setup
496 .long cpu_arch_name
497 .long cpu_elf_name
498 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_EDSP
499 .long cpu_arm1020e_name
500 .long arm1020e_processor_functions
501 .long v4wbi_tlb_fns
502 .long v4wb_user_fns
503 .long arm1020e_cache_fns
504 .size __arm1020e_proc_info, . - __arm1020e_proc_info