blob: 9f4dd35bfd743fbc91cf680c6f4cc90867fc0a05 [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 Frysinger78f28a02009-04-10 21:20:19 +000014/* 05000443 - IFLUSH cannot be last instruction in hardware loop */
15#if ANOMALY_05000443
16# define BROK_FLUSH_INST "IFLUSH"
17#else
18# define BROK_FLUSH_INST "no anomaly! yeah!"
19#endif
20
Mike Frysingerded963a2008-10-16 23:01:24 +080021/* Since all L1 caches work the same way, we use the same method for flushing
22 * them. Only the actual flush instruction differs. We write this in asm as
23 * GCC can be hard to coax into writing nice hardware loops.
Bryan Wu1394f032007-05-06 14:50:22 -070024 *
Mike Frysingerded963a2008-10-16 23:01:24 +080025 * Also, we assume the following register setup:
26 * R0 = start address
27 * R1 = end address
Bryan Wu1394f032007-05-06 14:50:22 -070028 */
Mike Frysinger78f28a02009-04-10 21:20:19 +000029.macro do_flush flushins:req label
Mike Frysingerded963a2008-10-16 23:01:24 +080030
Mike Frysinger39e96c82008-11-18 17:48:22 +080031 R2 = -L1_CACHE_BYTES;
32
33 /* start = (start & -L1_CACHE_BYTES) */
34 R0 = R0 & R2;
35
Mike Frysingerded963a2008-10-16 23:01:24 +080036 /* end = ((end - 1) & -L1_CACHE_BYTES) + L1_CACHE_BYTES; */
37 R1 += -1;
Mike Frysingerded963a2008-10-16 23:01:24 +080038 R1 = R1 & R2;
39 R1 += L1_CACHE_BYTES;
40
41 /* count = (end - start) >> L1_CACHE_SHIFT */
42 R2 = R1 - R0;
43 R2 >>= L1_CACHE_SHIFT;
44 P1 = R2;
45
46.ifnb \label
47\label :
48.endif
49 P0 = R0;
Mike Frysinger78f28a02009-04-10 21:20:19 +000050
Mike Frysingerded963a2008-10-16 23:01:24 +080051 LSETUP (1f, 2f) LC1 = P1;
Bryan Wu1394f032007-05-06 14:50:22 -0700521:
Mike Frysinger78f28a02009-04-10 21:20:19 +000053.ifeqs "\flushins", BROK_FLUSH_INST
Mike Frysingerded963a2008-10-16 23:01:24 +080054 \flushins [P0++];
Mike Frysingerbe1229b2011-02-02 01:55:22 +000055 nop;
56 nop;
Mike Frysinger78f28a02009-04-10 21:20:19 +0000572: nop;
58.else
Mike Frysinger2cf85112008-10-28 16:34:42 +0800592: \flushins [P0++];
Mike Frysinger78f28a02009-04-10 21:20:19 +000060.endif
Mike Frysingerded963a2008-10-16 23:01:24 +080061
Bryan Wu1394f032007-05-06 14:50:22 -070062 RTS;
Mike Frysingerded963a2008-10-16 23:01:24 +080063.endm
64
Mike Frysinger820b1272011-02-02 22:31:42 -050065#ifdef CONFIG_ICACHE_FLUSH_L1
66.section .l1.text
67#else
68.text
69#endif
70
Mike Frysingerded963a2008-10-16 23:01:24 +080071/* Invalidate all instruction cache lines assocoiated with this memory area */
Sonic Zhangc6345ab2010-08-05 07:49:26 +000072#ifdef CONFIG_SMP
73# define _blackfin_icache_flush_range _blackfin_icache_flush_range_l1
74#endif
Mike Frysingerded963a2008-10-16 23:01:24 +080075ENTRY(_blackfin_icache_flush_range)
Mike Frysinger78f28a02009-04-10 21:20:19 +000076 do_flush IFLUSH
Mike Frysinger51be24c2007-06-11 15:31:30 +080077ENDPROC(_blackfin_icache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -070078
Sonic Zhangc6345ab2010-08-05 07:49:26 +000079#ifdef CONFIG_SMP
80.text
81# undef _blackfin_icache_flush_range
82ENTRY(_blackfin_icache_flush_range)
83 p0.L = LO(DSPID);
84 p0.H = HI(DSPID);
85 r3 = [p0];
86 r3 = r3.b (z);
87 p2 = r3;
88 p0.L = _blackfin_iflush_l1_entry;
89 p0.H = _blackfin_iflush_l1_entry;
90 p0 = p0 + (p2 << 2);
91 p1 = [p0];
92 jump (p1);
93ENDPROC(_blackfin_icache_flush_range)
94#endif
95
Mike Frysinger820b1272011-02-02 22:31:42 -050096#ifdef CONFIG_DCACHE_FLUSH_L1
97.section .l1.text
98#else
99.text
100#endif
101
Bryan Wu1394f032007-05-06 14:50:22 -0700102/* Throw away all D-cached data in specified region without any obligation to
Mike Frysingerded963a2008-10-16 23:01:24 +0800103 * write them back. Since the Blackfin ISA does not have an "invalidate"
104 * instruction, we use flush/invalidate. Perhaps as a speed optimization we
105 * could bang on the DTEST MMRs ...
Bryan Wu1394f032007-05-06 14:50:22 -0700106 */
Bryan Wu1394f032007-05-06 14:50:22 -0700107ENTRY(_blackfin_dcache_invalidate_range)
Mike Frysingerded963a2008-10-16 23:01:24 +0800108 do_flush FLUSHINV
Mike Frysinger51be24c2007-06-11 15:31:30 +0800109ENDPROC(_blackfin_dcache_invalidate_range)
Bryan Wu1394f032007-05-06 14:50:22 -0700110
Mike Frysingerded963a2008-10-16 23:01:24 +0800111/* Flush all data cache lines assocoiated with this memory area */
Bryan Wu1394f032007-05-06 14:50:22 -0700112ENTRY(_blackfin_dcache_flush_range)
Mike Frysinger78f28a02009-04-10 21:20:19 +0000113 do_flush FLUSH, .Ldfr
Mike Frysinger51be24c2007-06-11 15:31:30 +0800114ENDPROC(_blackfin_dcache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -0700115
Mike Frysingerded963a2008-10-16 23:01:24 +0800116/* Our headers convert the page structure to an address, so just need to flush
117 * its contents like normal. We know the start address is page aligned (which
118 * greater than our cache alignment), as is the end address. So just jump into
119 * the middle of the dcache flush function.
120 */
Bryan Wu1394f032007-05-06 14:50:22 -0700121ENTRY(_blackfin_dflush_page)
122 P1 = 1 << (PAGE_SHIFT - L1_CACHE_SHIFT);
Mike Frysingerded963a2008-10-16 23:01:24 +0800123 jump .Ldfr;
Mike Frysinger51be24c2007-06-11 15:31:30 +0800124ENDPROC(_blackfin_dflush_page)