cacheflush.h 3.8 KB
Newer Older
B
Bryan Wu 已提交
1
/*
2
 * Blackfin low-level cache routines
B
Bryan Wu 已提交
3
 *
4
 * Copyright 2004-2009 Analog Devices Inc.
B
Bryan Wu 已提交
5
 *
6
 * Licensed under the GPL-2 or later.
B
Bryan Wu 已提交
7 8 9 10 11
 */

#ifndef _BLACKFIN_CACHEFLUSH_H
#define _BLACKFIN_CACHEFLUSH_H

12
#include <asm/blackfin.h>	/* for SSYNC() */
13
#include <asm/sections.h>	/* for _ramend */
14 15 16
#ifdef CONFIG_SMP
#include <asm/smp.h>
#endif
17

18 19 20 21
extern void blackfin_icache_flush_range(unsigned long start_address, unsigned long end_address);
extern void blackfin_dcache_flush_range(unsigned long start_address, unsigned long end_address);
extern void blackfin_dcache_invalidate_range(unsigned long start_address, unsigned long end_address);
extern void blackfin_dflush_page(void *page);
22
extern void blackfin_invalidate_entire_dcache(void);
23
extern void blackfin_invalidate_entire_icache(void);
B
Bryan Wu 已提交
24 25 26 27 28 29 30 31 32

#define flush_dcache_mmap_lock(mapping)		do { } while (0)
#define flush_dcache_mmap_unlock(mapping)	do { } while (0)
#define flush_cache_mm(mm)			do { } while (0)
#define flush_cache_range(vma, start, end)	do { } while (0)
#define flush_cache_page(vma, vmaddr)		do { } while (0)
#define flush_cache_vmap(start, end)		do { } while (0)
#define flush_cache_vunmap(start, end)		do { } while (0)

33 34 35 36 37 38 39
#ifdef CONFIG_SMP
#define flush_icache_range_others(start, end)	\
	smp_icache_flush_range_others((start), (end))
#else
#define flush_icache_range_others(start, end)	do { } while (0)
#endif

B
Bryan Wu 已提交
40 41
static inline void flush_icache_range(unsigned start, unsigned end)
{
42 43 44 45 46 47 48
#if defined(CONFIG_BFIN_EXTMEM_WRITEBACK)
	if (end <= physical_mem_end)
		blackfin_dcache_flush_range(start, end);
#endif
#if defined(CONFIG_BFIN_L2_WRITEBACK)
	if (start >= L2_START && end <= L2_START + L2_LENGTH)
		blackfin_dcache_flush_range(start, end);
49
#endif
B
Bryan Wu 已提交
50

51 52 53 54 55 56 57 58 59
	/* Make sure all write buffers in the data side of the core
	 * are flushed before trying to invalidate the icache.  This
	 * needs to be after the data flush and before the icache
	 * flush so that the SSYNC does the right thing in preventing
	 * the instruction prefetcher from hitting things in cached
	 * memory at the wrong time -- it runs much further ahead than
	 * the pipeline.
	 */
	SSYNC();
60 61 62 63 64 65 66 67 68 69 70
#if defined(CONFIG_BFIN_EXTMEM_ICACHEABLE)
	if (end <= physical_mem_end) {
		blackfin_icache_flush_range(start, end);
		flush_icache_range_others(start, end);
	}
#endif
#if defined(CONFIG_BFIN_L2_ICACHEABLE)
	if (start >= L2_START && end <= L2_START + L2_LENGTH) {
		blackfin_icache_flush_range(start, end);
		flush_icache_range_others(start, end);
	}
B
Bryan Wu 已提交
71 72 73
#endif
}

74 75 76
#define copy_to_user_page(vma, page, vaddr, dst, src, len)		\
do { memcpy(dst, src, len);						\
     flush_icache_range((unsigned) (dst), (unsigned) (dst) + (len));	\
B
Bryan Wu 已提交
77
} while (0)
78

B
Bryan Wu 已提交
79 80
#define copy_from_user_page(vma, page, vaddr, dst, src, len)	memcpy(dst, src, len)

81
#if defined(CONFIG_BFIN_DCACHE)
B
Bryan Wu 已提交
82 83 84 85
# define invalidate_dcache_range(start,end)	blackfin_dcache_invalidate_range((start), (end))
#else
# define invalidate_dcache_range(start,end)	do { } while (0)
#endif
86
#if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
B
Bryan Wu 已提交
87
# define flush_dcache_range(start,end)		blackfin_dcache_flush_range((start), (end))
88
#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
89
# define flush_dcache_page(page)		blackfin_dflush_page(page_address(page))
B
Bryan Wu 已提交
90 91
#else
# define flush_dcache_range(start,end)		do { } while (0)
92
#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
93
# define flush_dcache_page(page)		do { } while (0)
B
Bryan Wu 已提交
94 95
#endif

96 97 98
extern unsigned long reserved_mem_dcache_on;
extern unsigned long reserved_mem_icache_on;

99
static inline int bfin_addr_dcacheable(unsigned long addr)
100
{
101
#ifdef CONFIG_BFIN_EXTMEM_DCACHEABLE
102 103 104 105 106 107 108 109
	if (addr < (_ramend - DMA_UNCACHED_REGION))
		return 1;
#endif

	if (reserved_mem_dcache_on &&
		addr >= _ramend && addr < physical_mem_end)
		return 1;

110
#ifdef CONFIG_BFIN_L2_DCACHEABLE
111 112 113 114
	if (addr >= L2_START && addr < L2_START + L2_LENGTH)
		return 1;
#endif

115 116 117
	return 0;
}

118
#endif				/* _BLACKFIN_ICACHEFLUSH_H */