Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
[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  * Licensed under the GPL-2 or later.
7  */
8
9 #include <linux/linkage.h>
10 #include <asm/blackfin.h>
11 #include <asm/cache.h>
12 #include <asm/page.h>
13
14 #ifdef CONFIG_CACHE_FLUSH_L1
15 .section .l1.text
16 #else
17 .text
18 #endif
19
20 /* 05000443 - IFLUSH cannot be last instruction in hardware loop */
21 #if ANOMALY_05000443
22 # define BROK_FLUSH_INST "IFLUSH"
23 #else
24 # define BROK_FLUSH_INST "no anomaly! yeah!"
25 #endif
26
27 /* Since all L1 caches work the same way, we use the same method for flushing
28  * them.  Only the actual flush instruction differs.  We write this in asm as
29  * GCC can be hard to coax into writing nice hardware loops.
30  *
31  * Also, we assume the following register setup:
32  * R0 = start address
33  * R1 = end address
34  */
35 .macro do_flush flushins:req label
36
37         R2 = -L1_CACHE_BYTES;
38
39         /* start = (start & -L1_CACHE_BYTES) */
40         R0 = R0 & R2;
41
42         /* end = ((end - 1) & -L1_CACHE_BYTES) + L1_CACHE_BYTES; */
43         R1 += -1;
44         R1 = R1 & R2;
45         R1 += L1_CACHE_BYTES;
46
47         /* count = (end - start) >> L1_CACHE_SHIFT */
48         R2 = R1 - R0;
49         R2 >>= L1_CACHE_SHIFT;
50         P1 = R2;
51
52 .ifnb \label
53 \label :
54 .endif
55         P0 = R0;
56
57         LSETUP (1f, 2f) LC1 = P1;
58 1:
59 .ifeqs "\flushins", BROK_FLUSH_INST
60         \flushins [P0++];
61         nop;
62         nop;
63 2:      nop;
64 .else
65 2:      \flushins [P0++];
66 .endif
67
68         RTS;
69 .endm
70
71 /* Invalidate all instruction cache lines assocoiated with this memory area */
72 ENTRY(_blackfin_icache_flush_range)
73         do_flush IFLUSH
74 ENDPROC(_blackfin_icache_flush_range)
75
76 /* Throw away all D-cached data in specified region without any obligation to
77  * write them back.  Since the Blackfin ISA does not have an "invalidate"
78  * instruction, we use flush/invalidate.  Perhaps as a speed optimization we
79  * could bang on the DTEST MMRs ...
80  */
81 ENTRY(_blackfin_dcache_invalidate_range)
82         do_flush FLUSHINV
83 ENDPROC(_blackfin_dcache_invalidate_range)
84
85 /* Flush all data cache lines assocoiated with this memory area */
86 ENTRY(_blackfin_dcache_flush_range)
87         do_flush FLUSH, .Ldfr
88 ENDPROC(_blackfin_dcache_flush_range)
89
90 /* Our headers convert the page structure to an address, so just need to flush
91  * its contents like normal.  We know the start address is page aligned (which
92  * greater than our cache alignment), as is the end address.  So just jump into
93  * the middle of the dcache flush function.
94  */
95 ENTRY(_blackfin_dflush_page)
96         P1 = 1 << (PAGE_SHIFT - L1_CACHE_SHIFT);
97         jump .Ldfr;
98 ENDPROC(_blackfin_dflush_page)