Merge branches 'sh/serial-rework' and 'sh/oprofile'
[pandora-kernel.git] / arch / blackfin / mach-common / cache.S
1 /*
2  * Blackfin cache control code
3  *
4  * Copyright 2004-2008 Analog Devices Inc.
5  *
6  * Enter bugs at http://blackfin.uclinux.org/
7  *
8  * Licensed under the GPL-2 or later.
9  */
10
11 #include <linux/linkage.h>
12 #include <asm/blackfin.h>
13 #include <asm/cache.h>
14 #include <asm/page.h>
15
16 .text
17
18 /* Since all L1 caches work the same way, we use the same method for flushing
19  * them.  Only the actual flush instruction differs.  We write this in asm as
20  * GCC can be hard to coax into writing nice hardware loops.
21  *
22  * Also, we assume the following register setup:
23  * R0 = start address
24  * R1 = end address
25  */
26 .macro do_flush flushins:req optflushins optnopins label
27
28         /* end = ((end - 1) & -L1_CACHE_BYTES) + L1_CACHE_BYTES; */
29         R1 += -1;
30         R2 = -L1_CACHE_BYTES;
31         R1 = R1 & R2;
32         R1 += L1_CACHE_BYTES;
33
34         /* count = (end - start) >> L1_CACHE_SHIFT */
35         R2 = R1 - R0;
36         R2 >>= L1_CACHE_SHIFT;
37         P1 = R2;
38
39 .ifnb \label
40 \label :
41 .endif
42         P0 = R0;
43         LSETUP (1f, 2f) LC1 = P1;
44 1:
45 .ifnb \optflushins
46         \optflushins [P0];
47 .endif
48 .ifb \optnopins
49 2:
50 .endif
51         \flushins [P0++];
52 .ifnb \optnopins
53 2: \optnopins;
54 .endif
55
56         RTS;
57 .endm
58
59 /* Invalidate all instruction cache lines assocoiated with this memory area */
60 ENTRY(_blackfin_icache_flush_range)
61         do_flush IFLUSH, , nop
62 ENDPROC(_blackfin_icache_flush_range)
63
64 /* Flush all cache lines assocoiated with this area of memory. */
65 ENTRY(_blackfin_icache_dcache_flush_range)
66         do_flush IFLUSH, FLUSH
67 ENDPROC(_blackfin_icache_dcache_flush_range)
68
69 /* Throw away all D-cached data in specified region without any obligation to
70  * write them back.  Since the Blackfin ISA does not have an "invalidate"
71  * instruction, we use flush/invalidate.  Perhaps as a speed optimization we
72  * could bang on the DTEST MMRs ...
73  */
74 ENTRY(_blackfin_dcache_invalidate_range)
75         do_flush FLUSHINV
76 ENDPROC(_blackfin_dcache_invalidate_range)
77
78 /* Flush all data cache lines assocoiated with this memory area */
79 ENTRY(_blackfin_dcache_flush_range)
80         do_flush FLUSH, , , .Ldfr
81 ENDPROC(_blackfin_dcache_flush_range)
82
83 /* Our headers convert the page structure to an address, so just need to flush
84  * its contents like normal.  We know the start address is page aligned (which
85  * greater than our cache alignment), as is the end address.  So just jump into
86  * the middle of the dcache flush function.
87  */
88 ENTRY(_blackfin_dflush_page)
89         P1 = 1 << (PAGE_SHIFT - L1_CACHE_SHIFT);
90         jump .Ldfr;
91 ENDPROC(_blackfin_dflush_page)