blob: ab4a925a443e4e82001df0beb146b7b7b8e3b40a [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 * Licensed under the GPL-2 or later.
Bryan Wu1394f032007-05-06 14:50:22 -07007 */
8
9#include <linux/linkage.h>
Bryan Wu1394f032007-05-06 14:50:22 -070010#include <asm/blackfin.h>
11#include <asm/cache.h>
Mike Frysingerded963a2008-10-16 23:01:24 +080012#include <asm/page.h>
Bryan Wu1394f032007-05-06 14:50:22 -070013
Mike Frysinger74181292010-05-27 22:46:46 +000014#ifdef CONFIG_CACHE_FLUSH_L1
15.section .l1.text
16#else
Bryan Wu1394f032007-05-06 14:50:22 -070017.text
Mike Frysinger74181292010-05-27 22:46:46 +000018#endif
Bryan Wu1394f032007-05-06 14:50:22 -070019
Mike Frysinger78f28a02009-04-10 21:20:19 +000020/* 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
Mike Frysingerded963a2008-10-16 23:01:24 +080027/* 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.
Bryan Wu1394f032007-05-06 14:50:22 -070030 *
Mike Frysingerded963a2008-10-16 23:01:24 +080031 * Also, we assume the following register setup:
32 * R0 = start address
33 * R1 = end address
Bryan Wu1394f032007-05-06 14:50:22 -070034 */
Mike Frysinger78f28a02009-04-10 21:20:19 +000035.macro do_flush flushins:req label
Mike Frysingerded963a2008-10-16 23:01:24 +080036
Mike Frysinger39e96c82008-11-18 17:48:22 +080037 R2 = -L1_CACHE_BYTES;
38
39 /* start = (start & -L1_CACHE_BYTES) */
40 R0 = R0 & R2;
41
Mike Frysingerded963a2008-10-16 23:01:24 +080042 /* end = ((end - 1) & -L1_CACHE_BYTES) + L1_CACHE_BYTES; */
43 R1 += -1;
Mike Frysingerded963a2008-10-16 23:01:24 +080044 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;
Mike Frysinger78f28a02009-04-10 21:20:19 +000056
Mike Frysingerded963a2008-10-16 23:01:24 +080057 LSETUP (1f, 2f) LC1 = P1;
Bryan Wu1394f032007-05-06 14:50:22 -0700581:
Mike Frysinger78f28a02009-04-10 21:20:19 +000059.ifeqs "\flushins", BROK_FLUSH_INST
Mike Frysingerded963a2008-10-16 23:01:24 +080060 \flushins [P0++];
Mike Frysingerbe1229b2011-02-02 01:55:22 +000061 nop;
62 nop;
Mike Frysinger78f28a02009-04-10 21:20:19 +0000632: nop;
64.else
Mike Frysinger2cf85112008-10-28 16:34:42 +0800652: \flushins [P0++];
Mike Frysinger78f28a02009-04-10 21:20:19 +000066.endif
Mike Frysingerded963a2008-10-16 23:01:24 +080067
Bryan Wu1394f032007-05-06 14:50:22 -070068 RTS;
Mike Frysingerded963a2008-10-16 23:01:24 +080069.endm
70
71/* Invalidate all instruction cache lines assocoiated with this memory area */
72ENTRY(_blackfin_icache_flush_range)
Mike Frysinger78f28a02009-04-10 21:20:19 +000073 do_flush IFLUSH
Mike Frysinger51be24c2007-06-11 15:31:30 +080074ENDPROC(_blackfin_icache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -070075
Bryan Wu1394f032007-05-06 14:50:22 -070076/* Throw away all D-cached data in specified region without any obligation to
Mike Frysingerded963a2008-10-16 23:01:24 +080077 * 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 ...
Bryan Wu1394f032007-05-06 14:50:22 -070080 */
Bryan Wu1394f032007-05-06 14:50:22 -070081ENTRY(_blackfin_dcache_invalidate_range)
Mike Frysingerded963a2008-10-16 23:01:24 +080082 do_flush FLUSHINV
Mike Frysinger51be24c2007-06-11 15:31:30 +080083ENDPROC(_blackfin_dcache_invalidate_range)
Bryan Wu1394f032007-05-06 14:50:22 -070084
Mike Frysingerded963a2008-10-16 23:01:24 +080085/* Flush all data cache lines assocoiated with this memory area */
Bryan Wu1394f032007-05-06 14:50:22 -070086ENTRY(_blackfin_dcache_flush_range)
Mike Frysinger78f28a02009-04-10 21:20:19 +000087 do_flush FLUSH, .Ldfr
Mike Frysinger51be24c2007-06-11 15:31:30 +080088ENDPROC(_blackfin_dcache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -070089
Mike Frysingerded963a2008-10-16 23:01:24 +080090/* 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 */
Bryan Wu1394f032007-05-06 14:50:22 -070095ENTRY(_blackfin_dflush_page)
96 P1 = 1 << (PAGE_SHIFT - L1_CACHE_SHIFT);
Mike Frysingerded963a2008-10-16 23:01:24 +080097 jump .Ldfr;
Mike Frysinger51be24c2007-06-11 15:31:30 +080098ENDPROC(_blackfin_dflush_page)