blob: 417eaac7fe99948a077d38707fb1cb9c22f03f10 [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() */
13
Mike Frysinger8fb4f8f2008-10-16 23:39:12 +080014extern void blackfin_icache_flush_range(unsigned long start_address, unsigned long end_address);
15extern void blackfin_dcache_flush_range(unsigned long start_address, unsigned long end_address);
16extern void blackfin_dcache_invalidate_range(unsigned long start_address, unsigned long end_address);
17extern void blackfin_dflush_page(void *page);
Graf Yang6b3087c2009-01-07 23:14:39 +080018extern void blackfin_invalidate_entire_dcache(void);
Sonic Zhang47e9ded2009-06-10 08:57:08 +000019extern void blackfin_invalidate_entire_icache(void);
Bryan Wu1394f032007-05-06 14:50:22 -070020
21#define flush_dcache_mmap_lock(mapping) do { } while (0)
22#define flush_dcache_mmap_unlock(mapping) do { } while (0)
23#define flush_cache_mm(mm) do { } while (0)
24#define flush_cache_range(vma, start, end) do { } while (0)
25#define flush_cache_page(vma, vmaddr) do { } while (0)
26#define flush_cache_vmap(start, end) do { } while (0)
27#define flush_cache_vunmap(start, end) do { } while (0)
28
Graf Yang6b3087c2009-01-07 23:14:39 +080029#ifdef CONFIG_SMP
30#define flush_icache_range_others(start, end) \
31 smp_icache_flush_range_others((start), (end))
32#else
33#define flush_icache_range_others(start, end) do { } while (0)
34#endif
35
Bryan Wu1394f032007-05-06 14:50:22 -070036static inline void flush_icache_range(unsigned start, unsigned end)
37{
Jie Zhang41ba6532009-06-16 09:48:33 +000038#if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
Mike Frysinger5d891372009-04-10 20:52:08 +000039 blackfin_dcache_flush_range(start, end);
40#endif
Bryan Wu1394f032007-05-06 14:50:22 -070041
Mike Frysinger5d891372009-04-10 20:52:08 +000042 /* Make sure all write buffers in the data side of the core
43 * are flushed before trying to invalidate the icache. This
44 * needs to be after the data flush and before the icache
45 * flush so that the SSYNC does the right thing in preventing
46 * the instruction prefetcher from hitting things in cached
47 * memory at the wrong time -- it runs much further ahead than
48 * the pipeline.
49 */
50 SSYNC();
51#if defined(CONFIG_BFIN_ICACHE)
52 blackfin_icache_flush_range(start, end);
Graf Yang6b3087c2009-01-07 23:14:39 +080053 flush_icache_range_others(start, end);
Bryan Wu1394f032007-05-06 14:50:22 -070054#endif
55}
56
Graf Yang6b3087c2009-01-07 23:14:39 +080057#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
58do { memcpy(dst, src, len); \
59 flush_icache_range((unsigned) (dst), (unsigned) (dst) + (len)); \
Bryan Wu1394f032007-05-06 14:50:22 -070060} while (0)
Graf Yang6b3087c2009-01-07 23:14:39 +080061
Bryan Wu1394f032007-05-06 14:50:22 -070062#define copy_from_user_page(vma, page, vaddr, dst, src, len) memcpy(dst, src, len)
63
Robin Getz3bebca22007-10-10 23:55:26 +080064#if defined(CONFIG_BFIN_DCACHE)
Bryan Wu1394f032007-05-06 14:50:22 -070065# define invalidate_dcache_range(start,end) blackfin_dcache_invalidate_range((start), (end))
66#else
67# define invalidate_dcache_range(start,end) do { } while (0)
68#endif
Jie Zhang41ba6532009-06-16 09:48:33 +000069#if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
Bryan Wu1394f032007-05-06 14:50:22 -070070# define flush_dcache_range(start,end) blackfin_dcache_flush_range((start), (end))
Ilya Loginov2d4dc892009-11-26 09:16:19 +010071#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
Jie Zhang41ba6532009-06-16 09:48:33 +000072# define flush_dcache_page(page) blackfin_dflush_page(page_address(page))
Bryan Wu1394f032007-05-06 14:50:22 -070073#else
74# define flush_dcache_range(start,end) do { } while (0)
Ilya Loginov2d4dc892009-11-26 09:16:19 +010075#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
Graf Yang6b3087c2009-01-07 23:14:39 +080076# define flush_dcache_page(page) do { } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070077#endif
78
Mike Frysinger04be80e2008-10-16 23:33:53 +080079extern unsigned long reserved_mem_dcache_on;
80extern unsigned long reserved_mem_icache_on;
81
Jie Zhang67834fa2009-06-10 06:26:26 +000082static inline int bfin_addr_dcacheable(unsigned long addr)
Mike Frysinger04be80e2008-10-16 23:33:53 +080083{
Jie Zhang41ba6532009-06-16 09:48:33 +000084#ifdef CONFIG_BFIN_EXTMEM_DCACHEABLE
Mike Frysinger04be80e2008-10-16 23:33:53 +080085 if (addr < (_ramend - DMA_UNCACHED_REGION))
86 return 1;
87#endif
88
89 if (reserved_mem_dcache_on &&
90 addr >= _ramend && addr < physical_mem_end)
91 return 1;
92
Jie Zhang41ba6532009-06-16 09:48:33 +000093#ifdef CONFIG_BFIN_L2_DCACHEABLE
Mike Frysingerf339f462009-05-19 12:58:13 +000094 if (addr >= L2_START && addr < L2_START + L2_LENGTH)
95 return 1;
96#endif
97
Mike Frysinger04be80e2008-10-16 23:33:53 +080098 return 0;
99}
100
Robin Getz3bebca22007-10-10 23:55:26 +0800101#endif /* _BLACKFIN_ICACHEFLUSH_H */