blob: db532181fbdeb9200a6d445b6f7fd940cd088830 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Mike Frysingerded963a2008-10-16 23:01:24 +08002 * Blackfin cache control code
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Mike Frysingerded963a2008-10-16 23:01:24 +08004 * Copyright 2004-2008 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -07005 *
Mike Frysingerded963a2008-10-16 23:01:24 +08006 * Enter bugs at http://blackfin.uclinux.org/
Bryan Wu1394f032007-05-06 14:50:22 -07007 *
Mike Frysingerded963a2008-10-16 23:01:24 +08008 * Licensed under the GPL-2 or later.
Bryan Wu1394f032007-05-06 14:50:22 -07009 */
10
11#include <linux/linkage.h>
Bryan Wu1394f032007-05-06 14:50:22 -070012#include <asm/blackfin.h>
13#include <asm/cache.h>
Mike Frysingerded963a2008-10-16 23:01:24 +080014#include <asm/page.h>
Bryan Wu1394f032007-05-06 14:50:22 -070015
16.text
Bryan Wu1394f032007-05-06 14:50:22 -070017
Mike Frysingerded963a2008-10-16 23:01:24 +080018/* 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.
Bryan Wu1394f032007-05-06 14:50:22 -070021 *
Mike Frysingerded963a2008-10-16 23:01:24 +080022 * Also, we assume the following register setup:
23 * R0 = start address
24 * R1 = end address
Bryan Wu1394f032007-05-06 14:50:22 -070025 */
Mike Frysingerded963a2008-10-16 23:01:24 +080026.macro do_flush flushins:req optflushins optnopins label
27
28 /* end = ((end - 1) & -L1_CACHE_BYTES) + L1_CACHE_BYTES; */
29 R1 += -1;
Bryan Wu1394f032007-05-06 14:50:22 -070030 R2 = -L1_CACHE_BYTES;
Mike Frysingerded963a2008-10-16 23:01:24 +080031 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;
Bryan Wu1394f032007-05-06 14:50:22 -0700441:
Mike Frysingerded963a2008-10-16 23:01:24 +080045.ifnb \optflushins
46 \optflushins [P0];
47.endif
48.ifb \optnopins
492:
50.endif
51 \flushins [P0++];
52.ifnb \optnopins
532: \optnopins;
54.endif
55
Bryan Wu1394f032007-05-06 14:50:22 -070056 RTS;
Mike Frysingerded963a2008-10-16 23:01:24 +080057.endm
58
59/* Invalidate all instruction cache lines assocoiated with this memory area */
60ENTRY(_blackfin_icache_flush_range)
61 do_flush IFLUSH, , nop
Mike Frysinger51be24c2007-06-11 15:31:30 +080062ENDPROC(_blackfin_icache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -070063
Mike Frysingerded963a2008-10-16 23:01:24 +080064/* Flush all cache lines assocoiated with this area of memory. */
Bryan Wu1394f032007-05-06 14:50:22 -070065ENTRY(_blackfin_icache_dcache_flush_range)
Mike Frysingerded963a2008-10-16 23:01:24 +080066 do_flush IFLUSH, FLUSH
Mike Frysinger51be24c2007-06-11 15:31:30 +080067ENDPROC(_blackfin_icache_dcache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -070068
69/* Throw away all D-cached data in specified region without any obligation to
Mike Frysingerded963a2008-10-16 23:01:24 +080070 * 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 ...
Bryan Wu1394f032007-05-06 14:50:22 -070073 */
Bryan Wu1394f032007-05-06 14:50:22 -070074ENTRY(_blackfin_dcache_invalidate_range)
Mike Frysingerded963a2008-10-16 23:01:24 +080075 do_flush FLUSHINV
Mike Frysinger51be24c2007-06-11 15:31:30 +080076ENDPROC(_blackfin_dcache_invalidate_range)
Bryan Wu1394f032007-05-06 14:50:22 -070077
Mike Frysingerded963a2008-10-16 23:01:24 +080078/* Flush all data cache lines assocoiated with this memory area */
Bryan Wu1394f032007-05-06 14:50:22 -070079ENTRY(_blackfin_dcache_flush_range)
Mike Frysingerded963a2008-10-16 23:01:24 +080080 do_flush FLUSH, , , .Ldfr
Mike Frysinger51be24c2007-06-11 15:31:30 +080081ENDPROC(_blackfin_dcache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -070082
Mike Frysingerded963a2008-10-16 23:01:24 +080083/* 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 */
Bryan Wu1394f032007-05-06 14:50:22 -070088ENTRY(_blackfin_dflush_page)
89 P1 = 1 << (PAGE_SHIFT - L1_CACHE_SHIFT);
Mike Frysingerded963a2008-10-16 23:01:24 +080090 jump .Ldfr;
Mike Frysinger51be24c2007-06-11 15:31:30 +080091ENDPROC(_blackfin_dflush_page)