blob: 77135b62818e16794db3d441debbec3c0cfb7254 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * Blackfin low-level cache routines
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Robin Getz96f10502009-09-24 14:11:24 +00004 * Copyright 2004-2009 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -07005 *
Robin Getz96f10502009-09-24 14:11:24 +00006 * Licensed under the GPL-2 or later.
Bryan Wu1394f032007-05-06 14:50:22 -07007 */
8
9#ifndef _BLACKFIN_CACHEFLUSH_H
10#define _BLACKFIN_CACHEFLUSH_H
11
Mike Frysinger5d891372009-04-10 20:52:08 +000012#include <asm/blackfin.h> /* for SSYNC() */
Mike Frysingerbbc51e92009-10-09 07:34:00 +000013#include <asm/sections.h> /* for _ramend */
Graf Yang71a66282010-03-12 04:24:21 +000014#ifdef CONFIG_SMP
15#include <asm/smp.h>
16#endif
Mike Frysinger5d891372009-04-10 20:52:08 +000017
Mike Frysinger8fb4f8f2008-10-16 23:39:12 +080018extern void blackfin_icache_flush_range(unsigned long start_address, unsigned long end_address);
19extern void blackfin_dcache_flush_range(unsigned long start_address, unsigned long end_address);
20extern void blackfin_dcache_invalidate_range(unsigned long start_address, unsigned long end_address);
21extern void blackfin_dflush_page(void *page);
Graf Yang6b3087c2009-01-07 23:14:39 +080022extern void blackfin_invalidate_entire_dcache(void);
Sonic Zhang47e9ded2009-06-10 08:57:08 +000023extern void blackfin_invalidate_entire_icache(void);
Bryan Wu1394f032007-05-06 14:50:22 -070024
25#define flush_dcache_mmap_lock(mapping) do { } while (0)
26#define flush_dcache_mmap_unlock(mapping) do { } while (0)
27#define flush_cache_mm(mm) do { } while (0)
28#define flush_cache_range(vma, start, end) do { } while (0)
29#define flush_cache_page(vma, vmaddr) do { } while (0)
30#define flush_cache_vmap(start, end) do { } while (0)
31#define flush_cache_vunmap(start, end) do { } while (0)
32
Graf Yang6b3087c2009-01-07 23:14:39 +080033#ifdef CONFIG_SMP
34#define flush_icache_range_others(start, end) \
35 smp_icache_flush_range_others((start), (end))
36#else
37#define flush_icache_range_others(start, end) do { } while (0)
38#endif
39
Bryan Wu1394f032007-05-06 14:50:22 -070040static inline void flush_icache_range(unsigned start, unsigned end)
41{
Jie Zhang41ba6532009-06-16 09:48:33 +000042#if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
Mike Frysinger5d891372009-04-10 20:52:08 +000043 blackfin_dcache_flush_range(start, end);
44#endif
Bryan Wu1394f032007-05-06 14:50:22 -070045
Mike Frysinger5d891372009-04-10 20:52:08 +000046 /* Make sure all write buffers in the data side of the core
47 * are flushed before trying to invalidate the icache. This
48 * needs to be after the data flush and before the icache
49 * flush so that the SSYNC does the right thing in preventing
50 * the instruction prefetcher from hitting things in cached
51 * memory at the wrong time -- it runs much further ahead than
52 * the pipeline.
53 */
54 SSYNC();
55#if defined(CONFIG_BFIN_ICACHE)
56 blackfin_icache_flush_range(start, end);
Graf Yang6b3087c2009-01-07 23:14:39 +080057 flush_icache_range_others(start, end);
Bryan Wu1394f032007-05-06 14:50:22 -070058#endif
59}
60
Graf Yang6b3087c2009-01-07 23:14:39 +080061#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
62do { memcpy(dst, src, len); \
63 flush_icache_range((unsigned) (dst), (unsigned) (dst) + (len)); \
Bryan Wu1394f032007-05-06 14:50:22 -070064} while (0)
Graf Yang6b3087c2009-01-07 23:14:39 +080065
Bryan Wu1394f032007-05-06 14:50:22 -070066#define copy_from_user_page(vma, page, vaddr, dst, src, len) memcpy(dst, src, len)
67
Robin Getz3bebca22007-10-10 23:55:26 +080068#if defined(CONFIG_BFIN_DCACHE)
Bryan Wu1394f032007-05-06 14:50:22 -070069# define invalidate_dcache_range(start,end) blackfin_dcache_invalidate_range((start), (end))
70#else
71# define invalidate_dcache_range(start,end) do { } while (0)
72#endif
Jie Zhang41ba6532009-06-16 09:48:33 +000073#if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
Bryan Wu1394f032007-05-06 14:50:22 -070074# define flush_dcache_range(start,end) blackfin_dcache_flush_range((start), (end))
Ilya Loginov2d4dc892009-11-26 09:16:19 +010075#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
Jie Zhang41ba6532009-06-16 09:48:33 +000076# define flush_dcache_page(page) blackfin_dflush_page(page_address(page))
Bryan Wu1394f032007-05-06 14:50:22 -070077#else
78# define flush_dcache_range(start,end) do { } while (0)
Ilya Loginov2d4dc892009-11-26 09:16:19 +010079#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
Graf Yang6b3087c2009-01-07 23:14:39 +080080# define flush_dcache_page(page) do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070081#endif
82
Mike Frysinger04be80e2008-10-16 23:33:53 +080083extern unsigned long reserved_mem_dcache_on;
84extern unsigned long reserved_mem_icache_on;
85
Jie Zhang67834fa2009-06-10 06:26:26 +000086static inline int bfin_addr_dcacheable(unsigned long addr)
Mike Frysinger04be80e2008-10-16 23:33:53 +080087{
Jie Zhang41ba6532009-06-16 09:48:33 +000088#ifdef CONFIG_BFIN_EXTMEM_DCACHEABLE
Mike Frysinger04be80e2008-10-16 23:33:53 +080089 if (addr < (_ramend - DMA_UNCACHED_REGION))
90 return 1;
91#endif
92
93 if (reserved_mem_dcache_on &&
94 addr >= _ramend && addr < physical_mem_end)
95 return 1;
96
Jie Zhang41ba6532009-06-16 09:48:33 +000097#ifdef CONFIG_BFIN_L2_DCACHEABLE
Mike Frysingerf339f462009-05-19 12:58:13 +000098 if (addr >= L2_START && addr < L2_START + L2_LENGTH)
99 return 1;
100#endif
101
Mike Frysinger04be80e2008-10-16 23:33:53 +0800102 return 0;
103}
104
Robin Getz3bebca22007-10-10 23:55:26 +0800105#endif /* _BLACKFIN_ICACHEFLUSH_H */