Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
[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 /* 05000443 - IFLUSH cannot be last instruction in hardware loop */
19 #if ANOMALY_05000443
20 # define BROK_FLUSH_INST "IFLUSH"
21 #else
22 # define BROK_FLUSH_INST "no anomaly! yeah!"
23 #endif
24
25 /* Since all L1 caches work the same way, we use the same method for flushing
26  * them.  Only the actual flush instruction differs.  We write this in asm as
27  * GCC can be hard to coax into writing nice hardware loops.
28  *
29  * Also, we assume the following register setup:
30  * R0 = start address
31  * R1 = end address
32  */
33 .macro do_flush flushins:req label
34
35         R2 = -L1_CACHE_BYTES;
36
37         /* start = (start & -L1_CACHE_BYTES) */
38         R0 = R0 & R2;
39
40         /* end = ((end - 1) & -L1_CACHE_BYTES) + L1_CACHE_BYTES; */
41         R1 += -1;
42         R1 = R1 & R2;
43         R1 += L1_CACHE_BYTES;
44
45         /* count = (end - start) >> L1_CACHE_SHIFT */
46         R2 = R1 - R0;
47         R2 >>= L1_CACHE_SHIFT;
48         P1 = R2;
49
50 .ifnb \label
51 \label :
52 .endif
53         P0 = R0;
54
55         LSETUP (1f, 2f) LC1 = P1;
56 1:
57 .ifeqs "\flushins", BROK_FLUSH_INST
58         \flushins [P0++];
59 2:      nop;
60 .else
61 2:      \flushins [P0++];
62 .endif
63
64         RTS;
65 .endm
66
67 /* Invalidate all instruction cache lines assocoiated with this memory area */
68 ENTRY(_blackfin_icache_flush_range)
69 /*
70  * Walkaround to avoid loading wrong instruction after invalidating icache
71  * and following sequence is met.
72  *
73  * 1) One instruction address is cached in the instruction cache.
74  * 2) This instruction in SDRAM is changed.
75  * 3) IFLASH[P0] is executed only once in blackfin_icache_flush_range().
76  * 4) This instruction is executed again, but the old one is loaded.
77  */
78         P0 = R0;
79         IFLUSH[P0];
80         do_flush IFLUSH
81 ENDPROC(_blackfin_icache_flush_range)
82
83 /* Throw away all D-cached data in specified region without any obligation to
84  * write them back.  Since the Blackfin ISA does not have an "invalidate"
85  * instruction, we use flush/invalidate.  Perhaps as a speed optimization we
86  * could bang on the DTEST MMRs ...
87  */
88 ENTRY(_blackfin_dcache_invalidate_range)
89         do_flush FLUSHINV
90 ENDPROC(_blackfin_dcache_invalidate_range)
91
92 /* Flush all data cache lines assocoiated with this memory area */
93 ENTRY(_blackfin_dcache_flush_range)
94         do_flush FLUSH, .Ldfr
95 ENDPROC(_blackfin_dcache_flush_range)
96
97 /* Our headers convert the page structure to an address, so just need to flush
98  * its contents like normal.  We know the start address is page aligned (which
99  * greater than our cache alignment), as is the end address.  So just jump into
100  * the middle of the dcache flush function.
101  */
102 ENTRY(_blackfin_dflush_page)
103         P1 = 1 << (PAGE_SHIFT - L1_CACHE_SHIFT);
104         jump .Ldfr;
105 ENDPROC(_blackfin_dflush_page)