blob: 566a5565307241313e4b244bc133df0c7755b4da [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/arm/mm/proc-arm1022.S: MMU functions for ARM1022E
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 *
14 * These are the low level assembler for performing cache and TLB
15 * functions on the ARM1022E.
16 */
17#include <linux/linkage.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/init.h>
19#include <asm/assembler.h>
Sam Ravnborge6ae7442005-09-09 21:08:59 +020020#include <asm/asm-offsets.h>
Russell King74945c82006-03-16 14:44:36 +000021#include <asm/pgtable-hwdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/pgtable.h>
23#include <asm/procinfo.h>
24#include <asm/ptrace.h>
25
26/*
27 * This is the maximum size of an area which will be invalidated
28 * using the single invalidate entry instructions. Anything larger
29 * than this, and we go for the whole cache.
30 *
31 * This value should be chosen such that we choose the cheapest
32 * alternative.
33 */
34#define MAX_AREA_SIZE 32768
35
36/*
37 * The size of one data cache line.
38 */
39#define CACHE_DLINESIZE 32
40
41/*
42 * The number of data cache segments.
43 */
44#define CACHE_DSEGMENTS 16
45
46/*
47 * The number of lines in a cache segment.
48 */
49#define CACHE_DENTRIES 64
50
51/*
52 * This is the size at which it becomes more efficient to
53 * clean the whole cache, rather than using the individual
54 * cache line maintainence instructions.
55 */
56#define CACHE_DLIMIT 32768
57
58 .text
59/*
60 * cpu_arm1022_proc_init()
61 */
62ENTRY(cpu_arm1022_proc_init)
63 mov pc, lr
64
65/*
66 * cpu_arm1022_proc_fin()
67 */
68ENTRY(cpu_arm1022_proc_fin)
69 stmfd sp!, {lr}
70 mov ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
71 msr cpsr_c, ip
72 bl arm1022_flush_kern_cache_all
73 mrc p15, 0, r0, c1, c0, 0 @ ctrl register
74 bic r0, r0, #0x1000 @ ...i............
75 bic r0, r0, #0x000e @ ............wca.
76 mcr p15, 0, r0, c1, c0, 0 @ disable caches
77 ldmfd sp!, {pc}
78
79/*
80 * cpu_arm1022_reset(loc)
81 *
82 * Perform a soft reset of the system. Put the CPU into the
83 * same state as it would be if it had been reset, and branch
84 * to what would be the reset vector.
85 *
86 * loc: location to jump to for soft reset
87 */
88 .align 5
89ENTRY(cpu_arm1022_reset)
90 mov ip, #0
91 mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
92 mcr p15, 0, ip, c7, c10, 4 @ drain WB
Hyok S. Choid090ddd2006-06-28 14:10:01 +010093#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 mcr p15, 0, ip, c8, c7, 0 @ invalidate I & D TLBs
Hyok S. Choid090ddd2006-06-28 14:10:01 +010095#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 mrc p15, 0, ip, c1, c0, 0 @ ctrl register
97 bic ip, ip, #0x000f @ ............wcam
98 bic ip, ip, #0x1100 @ ...i...s........
99 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
100 mov pc, r0
101
102/*
103 * cpu_arm1022_do_idle()
104 */
105 .align 5
106ENTRY(cpu_arm1022_do_idle)
107 mcr p15, 0, r0, c7, c0, 4 @ Wait for interrupt
108 mov pc, lr
109
110/* ================================= CACHE ================================ */
111
112 .align 5
113/*
114 * flush_user_cache_all()
115 *
116 * Invalidate all cache entries in a particular address
117 * space.
118 */
119ENTRY(arm1022_flush_user_cache_all)
120 /* FALLTHROUGH */
121/*
122 * flush_kern_cache_all()
123 *
124 * Clean and invalidate the entire cache.
125 */
126ENTRY(arm1022_flush_kern_cache_all)
127 mov r2, #VM_EXEC
128 mov ip, #0
129__flush_whole_cache:
130#ifndef CONFIG_CPU_DCACHE_DISABLE
131 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
1321: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
1332: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
134 subs r3, r3, #1 << 26
135 bcs 2b @ entries 63 to 0
136 subs r1, r1, #1 << 5
137 bcs 1b @ segments 15 to 0
138#endif
139 tst r2, #VM_EXEC
140#ifndef CONFIG_CPU_ICACHE_DISABLE
141 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
142#endif
143 mcrne p15, 0, ip, c7, c10, 4 @ drain WB
144 mov pc, lr
145
146/*
147 * flush_user_cache_range(start, end, flags)
148 *
149 * Invalidate a range of cache entries in the specified
150 * address space.
151 *
152 * - start - start address (inclusive)
153 * - end - end address (exclusive)
154 * - flags - vm_flags for this space
155 */
156ENTRY(arm1022_flush_user_cache_range)
157 mov ip, #0
158 sub r3, r1, r0 @ calculate total size
159 cmp r3, #CACHE_DLIMIT
160 bhs __flush_whole_cache
161
162#ifndef CONFIG_CPU_DCACHE_DISABLE
1631: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
164 add r0, r0, #CACHE_DLINESIZE
165 cmp r0, r1
166 blo 1b
167#endif
168 tst r2, #VM_EXEC
169#ifndef CONFIG_CPU_ICACHE_DISABLE
170 mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
171#endif
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. 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(arm1022_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. 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(arm1022_coherent_user_range)
199 mov ip, #0
200 bic r0, r0, #CACHE_DLINESIZE - 1
2011:
202#ifndef CONFIG_CPU_DCACHE_DISABLE
203 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
204#endif
205#ifndef CONFIG_CPU_ICACHE_DISABLE
206 mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
207#endif
208 add r0, r0, #CACHE_DLINESIZE
209 cmp r0, r1
210 blo 1b
211 mcr p15, 0, ip, c7, c10, 4 @ drain WB
212 mov pc, lr
213
214/*
215 * flush_kern_dcache_page(void *page)
216 *
217 * Ensure no D cache aliasing occurs, either with itself or
218 * the I cache
219 *
220 * - page - page aligned address
221 */
222ENTRY(arm1022_flush_kern_dcache_page)
223 mov ip, #0
224#ifndef CONFIG_CPU_DCACHE_DISABLE
225 add r1, r0, #PAGE_SZ
2261: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
227 add r0, r0, #CACHE_DLINESIZE
228 cmp r0, r1
229 blo 1b
230#endif
231 mcr p15, 0, ip, c7, c10, 4 @ drain WB
232 mov pc, lr
233
234/*
235 * dma_inv_range(start, end)
236 *
237 * Invalidate (discard) the specified virtual address range.
238 * May not write back any entries. If 'start' or 'end'
239 * are not cache line aligned, those lines must be written
240 * back.
241 *
242 * - start - virtual start address
243 * - end - virtual end address
244 *
245 * (same as v4wb)
246 */
247ENTRY(arm1022_dma_inv_range)
248 mov ip, #0
249#ifndef CONFIG_CPU_DCACHE_DISABLE
250 tst r0, #CACHE_DLINESIZE - 1
251 bic r0, r0, #CACHE_DLINESIZE - 1
252 mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
253 tst r1, #CACHE_DLINESIZE - 1
254 mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
2551: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
256 add r0, r0, #CACHE_DLINESIZE
257 cmp r0, r1
258 blo 1b
259#endif
260 mcr p15, 0, ip, c7, c10, 4 @ drain WB
261 mov pc, lr
262
263/*
264 * dma_clean_range(start, end)
265 *
266 * Clean the specified virtual address range.
267 *
268 * - start - virtual start address
269 * - end - virtual end address
270 *
271 * (same as v4wb)
272 */
273ENTRY(arm1022_dma_clean_range)
274 mov ip, #0
275#ifndef CONFIG_CPU_DCACHE_DISABLE
276 bic r0, r0, #CACHE_DLINESIZE - 1
2771: mcr p15, 0, r0, c7, c10, 1 @ clean 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_flush_range(start, end)
287 *
288 * Clean and invalidate the specified virtual address range.
289 *
290 * - start - virtual start address
291 * - end - virtual end address
292 */
293ENTRY(arm1022_dma_flush_range)
294 mov ip, #0
295#ifndef CONFIG_CPU_DCACHE_DISABLE
296 bic r0, r0, #CACHE_DLINESIZE - 1
2971: mcr p15, 0, r0, c7, c14, 1 @ clean+invalidate D entry
298 add r0, r0, #CACHE_DLINESIZE
299 cmp r0, r1
300 blo 1b
301#endif
302 mcr p15, 0, ip, c7, c10, 4 @ drain WB
303 mov pc, lr
304
305ENTRY(arm1022_cache_fns)
306 .long arm1022_flush_kern_cache_all
307 .long arm1022_flush_user_cache_all
308 .long arm1022_flush_user_cache_range
309 .long arm1022_coherent_kern_range
310 .long arm1022_coherent_user_range
311 .long arm1022_flush_kern_dcache_page
312 .long arm1022_dma_inv_range
313 .long arm1022_dma_clean_range
314 .long arm1022_dma_flush_range
315
316 .align 5
317ENTRY(cpu_arm1022_dcache_clean_area)
318#ifndef CONFIG_CPU_DCACHE_DISABLE
319 mov ip, #0
3201: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
321 add r0, r0, #CACHE_DLINESIZE
322 subs r1, r1, #CACHE_DLINESIZE
323 bhi 1b
324#endif
325 mov pc, lr
326
327/* =============================== PageTable ============================== */
328
329/*
330 * cpu_arm1022_switch_mm(pgd)
331 *
332 * Set the translation base pointer to be as described by pgd.
333 *
334 * pgd: new page tables
335 */
336 .align 5
337ENTRY(cpu_arm1022_switch_mm)
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100338#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339#ifndef CONFIG_CPU_DCACHE_DISABLE
340 mov r1, #(CACHE_DSEGMENTS - 1) << 5 @ 16 segments
3411: orr r3, r1, #(CACHE_DENTRIES - 1) << 26 @ 64 entries
3422: mcr p15, 0, r3, c7, c14, 2 @ clean+invalidate D index
343 subs r3, r3, #1 << 26
344 bcs 2b @ entries 63 to 0
345 subs r1, r1, #1 << 5
346 bcs 1b @ segments 15 to 0
347#endif
348 mov r1, #0
349#ifndef CONFIG_CPU_ICACHE_DISABLE
350 mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
351#endif
352 mcr p15, 0, r1, c7, c10, 4 @ drain WB
353 mcr p15, 0, r0, c2, c0, 0 @ load page table pointer
354 mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100355#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 mov pc, lr
357
358/*
359 * cpu_arm1022_set_pte(ptep, pte)
360 *
361 * Set a PTE and flush it out
362 */
363 .align 5
364ENTRY(cpu_arm1022_set_pte)
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100365#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 str r1, [r0], #-2048 @ linux version
367
368 eor r1, r1, #L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_WRITE | L_PTE_DIRTY
369
370 bic r2, r1, #PTE_SMALL_AP_MASK
371 bic r2, r2, #PTE_TYPE_MASK
372 orr r2, r2, #PTE_TYPE_SMALL
373
374 tst r1, #L_PTE_USER @ User?
375 orrne r2, r2, #PTE_SMALL_AP_URO_SRW
376
377 tst r1, #L_PTE_WRITE | L_PTE_DIRTY @ Write and Dirty?
378 orreq r2, r2, #PTE_SMALL_AP_UNO_SRW
379
380 tst r1, #L_PTE_PRESENT | L_PTE_YOUNG @ Present and Young?
381 movne r2, #0
382
383#ifdef CONFIG_CPU_DCACHE_WRITETHROUGH
384 eor r3, r1, #0x0a @ C & small page?
385 tst r3, #0x0b
386 biceq r2, r2, #4
387#endif
388 str r2, [r0] @ hardware version
389 mov r0, r0
390#ifndef CONFIG_CPU_DCACHE_DISABLE
391 mcr p15, 0, r0, c7, c10, 1 @ clean D entry
392#endif
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100393#endif /* CONFIG_MMU */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 mov pc, lr
395
396 __INIT
397
398 .type __arm1022_setup, #function
399__arm1022_setup:
400 mov r0, #0
401 mcr p15, 0, r0, c7, c7 @ invalidate I,D caches on v4
402 mcr p15, 0, r0, c7, c10, 4 @ drain write buffer on v4
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100403#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 mcr p15, 0, r0, c8, c7 @ invalidate I,D TLBs on v4
Hyok S. Choid090ddd2006-06-28 14:10:01 +0100405#endif
Russell King22b190862006-06-29 15:09:57 +0100406 adr r5, arm1022_crval
407 ldmia r5, {r5, r6}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 mrc p15, 0, r0, c1, c0 @ get control register v4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 bic r0, r0, r5
Russell King22b190862006-06-29 15:09:57 +0100410 orr r0, r0, r6
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#ifdef CONFIG_CPU_CACHE_ROUND_ROBIN
412 orr r0, r0, #0x4000 @ .R..............
413#endif
414 mov pc, lr
415 .size __arm1022_setup, . - __arm1022_setup
416
417 /*
418 * R
419 * .RVI ZFRS BLDP WCAM
420 * .011 1001 ..11 0101
421 *
422 */
Russell King22b190862006-06-29 15:09:57 +0100423 .type arm1022_crval, #object
424arm1022_crval:
425 crval clear=0x00007f3f, mmuset=0x00003935, ucset=0x00001930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 __INITDATA
428
429/*
430 * Purpose : Function pointers used to access above functions - all calls
431 * come through these
432 */
433 .type arm1022_processor_functions, #object
434arm1022_processor_functions:
435 .word v4t_early_abort
436 .word cpu_arm1022_proc_init
437 .word cpu_arm1022_proc_fin
438 .word cpu_arm1022_reset
439 .word cpu_arm1022_do_idle
440 .word cpu_arm1022_dcache_clean_area
441 .word cpu_arm1022_switch_mm
442 .word cpu_arm1022_set_pte
443 .size arm1022_processor_functions, . - arm1022_processor_functions
444
445 .section ".rodata"
446
447 .type cpu_arch_name, #object
448cpu_arch_name:
449 .asciz "armv5te"
450 .size cpu_arch_name, . - cpu_arch_name
451
452 .type cpu_elf_name, #object
453cpu_elf_name:
454 .asciz "v5"
455 .size cpu_elf_name, . - cpu_elf_name
456
457 .type cpu_arm1022_name, #object
458cpu_arm1022_name:
Russell King264edb32006-06-29 15:03:09 +0100459 .asciz "ARM1022"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 .size cpu_arm1022_name, . - cpu_arm1022_name
461
462 .align
463
Ben Dooks02b7dd12005-09-20 16:35:03 +0100464 .section ".proc.info.init", #alloc, #execinstr
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 .type __arm1022_proc_info,#object
467__arm1022_proc_info:
468 .long 0x4105a220 @ ARM 1022E (v5TE)
469 .long 0xff0ffff0
470 .long PMD_TYPE_SECT | \
471 PMD_BIT4 | \
472 PMD_SECT_AP_WRITE | \
473 PMD_SECT_AP_READ
Russell King8799ee92006-06-29 18:24:21 +0100474 .long PMD_TYPE_SECT | \
475 PMD_BIT4 | \
476 PMD_SECT_AP_WRITE | \
477 PMD_SECT_AP_READ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 b __arm1022_setup
479 .long cpu_arch_name
480 .long cpu_elf_name
481 .long HWCAP_SWP | HWCAP_HALF | HWCAP_THUMB | HWCAP_EDSP
482 .long cpu_arm1022_name
483 .long arm1022_processor_functions
484 .long v4wbi_tlb_fns
485 .long v4wb_user_fns
486 .long arm1022_cache_fns
487 .size __arm1022_proc_info, . - __arm1022_proc_info