blob: d9666fe6c3d6e4847db784ae6d3f2ab1bb14af01 [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 Frysinger78f28a02009-04-10 21:20:19 +000018/* 05000443 - IFLUSH cannot be last instruction in hardware loop */
19#if ANOMALY_05000443
20# define BROK_FLUSH_INST "IFLUSH"
21#else
22# define BROK_FLUSH_INST "no anomaly! yeah!"
23#endif
24
Mike Frysingerded963a2008-10-16 23:01:24 +080025/* Since all L1 caches work the same way, we use the same method for flushing
26 * them. Only the actual flush instruction differs. We write this in asm as
27 * GCC can be hard to coax into writing nice hardware loops.
Bryan Wu1394f032007-05-06 14:50:22 -070028 *
Mike Frysingerded963a2008-10-16 23:01:24 +080029 * Also, we assume the following register setup:
30 * R0 = start address
31 * R1 = end address
Bryan Wu1394f032007-05-06 14:50:22 -070032 */
Mike Frysinger78f28a02009-04-10 21:20:19 +000033.macro do_flush flushins:req label
Mike Frysingerded963a2008-10-16 23:01:24 +080034
Mike Frysinger39e96c82008-11-18 17:48:22 +080035 R2 = -L1_CACHE_BYTES;
36
37 /* start = (start & -L1_CACHE_BYTES) */
38 R0 = R0 & R2;
39
Mike Frysingerded963a2008-10-16 23:01:24 +080040 /* end = ((end - 1) & -L1_CACHE_BYTES) + L1_CACHE_BYTES; */
41 R1 += -1;
Mike Frysingerded963a2008-10-16 23:01:24 +080042 R1 = R1 & R2;
43 R1 += L1_CACHE_BYTES;
44
45 /* count = (end - start) >> L1_CACHE_SHIFT */
46 R2 = R1 - R0;
47 R2 >>= L1_CACHE_SHIFT;
48 P1 = R2;
49
50.ifnb \label
51\label :
52.endif
53 P0 = R0;
Mike Frysinger78f28a02009-04-10 21:20:19 +000054
Mike Frysingerded963a2008-10-16 23:01:24 +080055 LSETUP (1f, 2f) LC1 = P1;
Bryan Wu1394f032007-05-06 14:50:22 -0700561:
Mike Frysinger78f28a02009-04-10 21:20:19 +000057.ifeqs "\flushins", BROK_FLUSH_INST
Mike Frysingerded963a2008-10-16 23:01:24 +080058 \flushins [P0++];
Mike Frysinger78f28a02009-04-10 21:20:19 +0000592: nop;
60.else
Mike Frysinger2cf85112008-10-28 16:34:42 +0800612: \flushins [P0++];
Mike Frysinger78f28a02009-04-10 21:20:19 +000062.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)
Sonic Zhangd7ff1a92009-03-05 18:26:59 +080069/*
70 * Walkaround to avoid loading wrong instruction after invalidating icache
71 * and following sequence is met.
72 *
73 * 1) One instruction address is cached in the instruction cache.
74 * 2) This instruction in SDRAM is changed.
75 * 3) IFLASH[P0] is executed only once in blackfin_icache_flush_range().
76 * 4) This instruction is executed again, but the old one is loaded.
77 */
78 P0 = R0;
79 IFLUSH[P0];
Mike Frysinger78f28a02009-04-10 21:20:19 +000080 do_flush IFLUSH
Mike Frysinger51be24c2007-06-11 15:31:30 +080081ENDPROC(_blackfin_icache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -070082
Bryan Wu1394f032007-05-06 14:50:22 -070083/* Throw away all D-cached data in specified region without any obligation to
Mike Frysingerded963a2008-10-16 23:01:24 +080084 * write them back. Since the Blackfin ISA does not have an "invalidate"
85 * instruction, we use flush/invalidate. Perhaps as a speed optimization we
86 * could bang on the DTEST MMRs ...
Bryan Wu1394f032007-05-06 14:50:22 -070087 */
Bryan Wu1394f032007-05-06 14:50:22 -070088ENTRY(_blackfin_dcache_invalidate_range)
Mike Frysingerded963a2008-10-16 23:01:24 +080089 do_flush FLUSHINV
Mike Frysinger51be24c2007-06-11 15:31:30 +080090ENDPROC(_blackfin_dcache_invalidate_range)
Bryan Wu1394f032007-05-06 14:50:22 -070091
Mike Frysingerded963a2008-10-16 23:01:24 +080092/* Flush all data cache lines assocoiated with this memory area */
Bryan Wu1394f032007-05-06 14:50:22 -070093ENTRY(_blackfin_dcache_flush_range)
Mike Frysinger78f28a02009-04-10 21:20:19 +000094 do_flush FLUSH, .Ldfr
Mike Frysinger51be24c2007-06-11 15:31:30 +080095ENDPROC(_blackfin_dcache_flush_range)
Bryan Wu1394f032007-05-06 14:50:22 -070096
Mike Frysingerded963a2008-10-16 23:01:24 +080097/* Our headers convert the page structure to an address, so just need to flush
98 * its contents like normal. We know the start address is page aligned (which
99 * greater than our cache alignment), as is the end address. So just jump into
100 * the middle of the dcache flush function.
101 */
Bryan Wu1394f032007-05-06 14:50:22 -0700102ENTRY(_blackfin_dflush_page)
103 P1 = 1 << (PAGE_SHIFT - L1_CACHE_SHIFT);
Mike Frysingerded963a2008-10-16 23:01:24 +0800104 jump .Ldfr;
Mike Frysinger51be24c2007-06-11 15:31:30 +0800105ENDPROC(_blackfin_dflush_page)