blob: b773c57e75a525c344a892855d8b04a6df14473b [file] [log] [blame]
Chris Zankel9a8fd552005-06-23 22:01:26 -07001/*
2 * include/asm-xtensa/cacheflush.h
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
Chris Zankel66569202007-08-22 10:14:51 -07008 * (C) 2001 - 2007 Tensilica Inc.
Chris Zankel9a8fd552005-06-23 22:01:26 -07009 */
10
11#ifndef _XTENSA_CACHEFLUSH_H
12#define _XTENSA_CACHEFLUSH_H
13
14#ifdef __KERNEL__
15
16#include <linux/mm.h>
17#include <asm/processor.h>
18#include <asm/page.h>
19
20/*
Chris Zankel66569202007-08-22 10:14:51 -070021 * Lo-level routines for cache flushing.
Chris Zankel9a8fd552005-06-23 22:01:26 -070022 *
23 * invalidate data or instruction cache:
24 *
25 * __invalidate_icache_all()
26 * __invalidate_icache_page(adr)
27 * __invalidate_dcache_page(adr)
28 * __invalidate_icache_range(from,size)
29 * __invalidate_dcache_range(from,size)
30 *
31 * flush data cache:
32 *
33 * __flush_dcache_page(adr)
34 *
35 * flush and invalidate data cache:
36 *
37 * __flush_invalidate_dcache_all()
38 * __flush_invalidate_dcache_page(adr)
39 * __flush_invalidate_dcache_range(from,size)
Chris Zankel66569202007-08-22 10:14:51 -070040 *
41 * specials for cache aliasing:
42 *
43 * __flush_invalidate_dcache_page_alias(vaddr,paddr)
44 * __invalidate_icache_page_alias(vaddr,paddr)
Chris Zankel9a8fd552005-06-23 22:01:26 -070045 */
46
Chris Zankel66569202007-08-22 10:14:51 -070047extern void __invalidate_dcache_all(void);
Chris Zankel9a8fd552005-06-23 22:01:26 -070048extern void __invalidate_icache_all(void);
Chris Zankel9a8fd552005-06-23 22:01:26 -070049extern void __invalidate_dcache_page(unsigned long);
50extern void __invalidate_icache_page(unsigned long);
51extern void __invalidate_icache_range(unsigned long, unsigned long);
52extern void __invalidate_dcache_range(unsigned long, unsigned long);
53
Chris Zankel66569202007-08-22 10:14:51 -070054
Chris Zankel9a8fd552005-06-23 22:01:26 -070055#if XCHAL_DCACHE_IS_WRITEBACK
Chris Zankel66569202007-08-22 10:14:51 -070056extern void __flush_invalidate_dcache_all(void);
Chris Zankel9a8fd552005-06-23 22:01:26 -070057extern void __flush_dcache_page(unsigned long);
Chris Zankel66569202007-08-22 10:14:51 -070058extern void __flush_dcache_range(unsigned long, unsigned long);
Chris Zankel9a8fd552005-06-23 22:01:26 -070059extern void __flush_invalidate_dcache_page(unsigned long);
60extern void __flush_invalidate_dcache_range(unsigned long, unsigned long);
61#else
Chris Zankel66569202007-08-22 10:14:51 -070062# define __flush_dcache_range(p,s) do { } while(0)
63# define __flush_dcache_page(p) do { } while(0)
64# define __flush_invalidate_dcache_page(p) __invalidate_dcache_page(p)
65# define __flush_invalidate_dcache_range(p,s) __invalidate_dcache_range(p,s)
66#endif
67
68#if (DCACHE_WAY_SIZE > PAGE_SIZE)
69extern void __flush_invalidate_dcache_page_alias(unsigned long, unsigned long);
70#endif
71#if (ICACHE_WAY_SIZE > PAGE_SIZE)
72extern void __invalidate_icache_page_alias(unsigned long, unsigned long);
Chris Zankel9a8fd552005-06-23 22:01:26 -070073#endif
74
75/*
76 * We have physically tagged caches - nothing to do here -
77 * unless we have cache aliasing.
78 *
79 * Pages can get remapped. Because this might change the 'color' of that page,
80 * we have to flush the cache before the PTE is changed.
81 * (see also Documentation/cachetlb.txt)
82 */
83
Chris Zankel66569202007-08-22 10:14:51 -070084#if (DCACHE_WAY_SIZE > PAGE_SIZE)
Chris Zankel9a8fd552005-06-23 22:01:26 -070085
Chris Zankel66569202007-08-22 10:14:51 -070086#define flush_cache_all() \
87 do { \
88 __flush_invalidate_dcache_all(); \
89 __invalidate_icache_all(); \
90 } while (0)
Chris Zankel9a8fd552005-06-23 22:01:26 -070091
Chris Zankel66569202007-08-22 10:14:51 -070092#define flush_cache_mm(mm) flush_cache_all()
93#define flush_cache_dup_mm(mm) flush_cache_mm(mm)
94
95#define flush_cache_vmap(start,end) flush_cache_all()
96#define flush_cache_vunmap(start,end) flush_cache_all()
Chris Zankel9a8fd552005-06-23 22:01:26 -070097
98extern void flush_dcache_page(struct page*);
Chris Zankel9a8fd552005-06-23 22:01:26 -070099extern void flush_cache_range(struct vm_area_struct*, ulong, ulong);
100extern void flush_cache_page(struct vm_area_struct*, unsigned long, unsigned long);
101
102#else
103
104#define flush_cache_all() do { } while (0)
105#define flush_cache_mm(mm) do { } while (0)
Ralf Baechleec8c0442006-12-12 17:14:57 +0000106#define flush_cache_dup_mm(mm) do { } while (0)
Chris Zankel9a8fd552005-06-23 22:01:26 -0700107
108#define flush_cache_vmap(start,end) do { } while (0)
109#define flush_cache_vunmap(start,end) do { } while (0)
110
111#define flush_dcache_page(page) do { } while (0)
112
113#define flush_cache_page(vma,addr,pfn) do { } while (0)
114#define flush_cache_range(vma,start,end) do { } while (0)
115
116#endif
117
Chris Zankel66569202007-08-22 10:14:51 -0700118/* Ensure consistency between data and instruction cache. */
Chris Zankel9a8fd552005-06-23 22:01:26 -0700119#define flush_icache_range(start,end) \
Chris Zankel66569202007-08-22 10:14:51 -0700120 do { \
121 __flush_dcache_range(start, (end) - (start)); \
122 __invalidate_icache_range(start,(end) - (start)); \
123 } while (0)
Chris Zankel9a8fd552005-06-23 22:01:26 -0700124
125/* This is not required, see Documentation/cachetlb.txt */
Chris Zankel66569202007-08-22 10:14:51 -0700126#define flush_icache_page(vma,page) do { } while (0)
Chris Zankel9a8fd552005-06-23 22:01:26 -0700127
128#define flush_dcache_mmap_lock(mapping) do { } while (0)
129#define flush_dcache_mmap_unlock(mapping) do { } while (0)
130
Chris Zankel66569202007-08-22 10:14:51 -0700131#if (DCACHE_WAY_SIZE > PAGE_SIZE)
Chris Zankel9a8fd552005-06-23 22:01:26 -0700132
Chris Zankel66569202007-08-22 10:14:51 -0700133extern void copy_to_user_page(struct vm_area_struct*, struct page*,
134 unsigned long, void*, const void*, unsigned long);
135extern void copy_from_user_page(struct vm_area_struct*, struct page*,
136 unsigned long, void*, const void*, unsigned long);
137
138#else
139
140#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
141 do { \
142 memcpy(dst, src, len); \
143 __flush_dcache_range((unsigned long) dst, len); \
144 __invalidate_icache_range((unsigned long) dst, len); \
145 } while (0)
Chris Zankel9a8fd552005-06-23 22:01:26 -0700146
147#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
148 memcpy(dst, src, len)
149
Chris Zankel66569202007-08-22 10:14:51 -0700150#endif
151
Chris Zankel9a8fd552005-06-23 22:01:26 -0700152#endif /* __KERNEL__ */
Chris Zankel9a8fd552005-06-23 22:01:26 -0700153#endif /* _XTENSA_CACHEFLUSH_H */