blob: 3c98dacbf2892960ec4053f3c3bfde85bbc01fd9 [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
Mike Frysinger39e96c82008-11-18 17:48:22 +080028 R2 = -L1_CACHE_BYTES;
29
30 /* start = (start & -L1_CACHE_BYTES) */
31 R0 = R0 & R2;
32
Mike Frysingerded963a2008-10-16 23:01:24 +080033 /* end = ((end - 1) & -L1_CACHE_BYTES) + L1_CACHE_BYTES; */
34 R1 += -1;
Mike Frysingerded963a2008-10-16 23:01:24 +080035 R1 = R1 & R2;
36 R1 += L1_CACHE_BYTES;
37
38 /* count = (end - start) >> L1_CACHE_SHIFT */
39 R2 = R1 - R0;
40 R2 >>= L1_CACHE_SHIFT;
41 P1 = R2;
42
43.ifnb \label
44\label :
45.endif
46 P0 = R0;
47 LSETUP (1f, 2f) LC1 = P1;
Bryan Wu1394f032007-05-06 14:50:22 -0700481:
Mike Frysingerded963a2008-10-16 23:01:24 +080049.ifnb \optflushins
50 \optflushins [P0];
51.endif
Mike Frysinger2cf85112008-10-28 16:34:42 +080052#if ANOMALY_05000443
Mike Frysingerded963a2008-10-16 23:01:24 +080053.ifb \optnopins
542:
55.endif
56 \flushins [P0++];
57.ifnb \optnopins
Mike Frysinger2cf85112008-10-28 16:34:42 +0800582: \optnopins;
Mike Frysingerded963a2008-10-16 23:01:24 +080059.endif
Mike Frysinger2cf85112008-10-28 16:34:42 +080060#else
612: \flushins [P0++];
62#endif
Mike Frysingerded963a2008-10-16 23:01:24 +080063
Bryan Wu1394f032007-05-06 14:50:22 -070064 RTS;
Mike Frysingerded963a2008-10-16 23:01:24 +080065.endm
66
67/* Invalidate all instruction cache lines assocoiated with this memory area */
68ENTRY(_blackfin_icache_flush_range)
69 do_flush IFLUSH, , nop
Mike Frysinger51be24c2007-06-11 15:31:30 +080070ENDPROC(_blackfin_icache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -070071
Mike Frysingerded963a2008-10-16 23:01:24 +080072/* Flush all cache lines assocoiated with this area of memory. */
Bryan Wu1394f032007-05-06 14:50:22 -070073ENTRY(_blackfin_icache_dcache_flush_range)
Mike Frysinger7f6b2e72008-10-28 12:29:26 +080074 do_flush FLUSH, IFLUSH
Mike Frysinger51be24c2007-06-11 15:31:30 +080075ENDPROC(_blackfin_icache_dcache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -070076
77/* Throw away all D-cached data in specified region without any obligation to
Mike Frysingerded963a2008-10-16 23:01:24 +080078 * write them back. Since the Blackfin ISA does not have an "invalidate"
79 * instruction, we use flush/invalidate. Perhaps as a speed optimization we
80 * could bang on the DTEST MMRs ...
Bryan Wu1394f032007-05-06 14:50:22 -070081 */
Bryan Wu1394f032007-05-06 14:50:22 -070082ENTRY(_blackfin_dcache_invalidate_range)
Mike Frysingerded963a2008-10-16 23:01:24 +080083 do_flush FLUSHINV
Mike Frysinger51be24c2007-06-11 15:31:30 +080084ENDPROC(_blackfin_dcache_invalidate_range)
Bryan Wu1394f032007-05-06 14:50:22 -070085
Mike Frysingerded963a2008-10-16 23:01:24 +080086/* Flush all data cache lines assocoiated with this memory area */
Bryan Wu1394f032007-05-06 14:50:22 -070087ENTRY(_blackfin_dcache_flush_range)
Mike Frysingerded963a2008-10-16 23:01:24 +080088 do_flush FLUSH, , , .Ldfr
Mike Frysinger51be24c2007-06-11 15:31:30 +080089ENDPROC(_blackfin_dcache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -070090
Mike Frysingerded963a2008-10-16 23:01:24 +080091/* Our headers convert the page structure to an address, so just need to flush
92 * its contents like normal. We know the start address is page aligned (which
93 * greater than our cache alignment), as is the end address. So just jump into
94 * the middle of the dcache flush function.
95 */
Bryan Wu1394f032007-05-06 14:50:22 -070096ENTRY(_blackfin_dflush_page)
97 P1 = 1 << (PAGE_SHIFT - L1_CACHE_SHIFT);
Mike Frysingerded963a2008-10-16 23:01:24 +080098 jump .Ldfr;
Mike Frysinger51be24c2007-06-11 15:31:30 +080099ENDPROC(_blackfin_dflush_page)