]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/nios2/mm/cacheflush.c
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2009, Wind River Systems Inc
7 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
10 #include <linux/export.h>
11 #include <linux/sched.h>
15 #include <asm/cacheflush.h>
16 #include <asm/cpuinfo.h>
18 static void __flush_dcache(unsigned long start
, unsigned long end
)
22 start
&= ~(cpuinfo
.dcache_line_size
- 1);
23 end
+= (cpuinfo
.dcache_line_size
- 1);
24 end
&= ~(cpuinfo
.dcache_line_size
- 1);
26 if (end
> start
+ cpuinfo
.dcache_size
)
27 end
= start
+ cpuinfo
.dcache_size
;
29 for (addr
= start
; addr
< end
; addr
+= cpuinfo
.dcache_line_size
) {
30 __asm__
__volatile__ (" flushda 0(%0)\n"
32 : /* Inputs */ "r"(addr
)
37 static void __flush_dcache_all(unsigned long start
, unsigned long end
)
41 start
&= ~(cpuinfo
.dcache_line_size
- 1);
42 end
+= (cpuinfo
.dcache_line_size
- 1);
43 end
&= ~(cpuinfo
.dcache_line_size
- 1);
45 if (end
> start
+ cpuinfo
.dcache_size
)
46 end
= start
+ cpuinfo
.dcache_size
;
48 for (addr
= start
; addr
< end
; addr
+= cpuinfo
.dcache_line_size
) {
49 __asm__
__volatile__ (" flushd 0(%0)\n"
51 : /* Inputs */ "r"(addr
)
56 static void __invalidate_dcache(unsigned long start
, unsigned long end
)
60 start
&= ~(cpuinfo
.dcache_line_size
- 1);
61 end
+= (cpuinfo
.dcache_line_size
- 1);
62 end
&= ~(cpuinfo
.dcache_line_size
- 1);
64 if (end
> start
+ cpuinfo
.dcache_size
)
65 end
= start
+ cpuinfo
.dcache_size
;
67 for (addr
= start
; addr
< end
; addr
+= cpuinfo
.dcache_line_size
) {
68 __asm__
__volatile__ (" initda 0(%0)\n"
70 : /* Inputs */ "r"(addr
)
75 static void __flush_icache(unsigned long start
, unsigned long end
)
79 start
&= ~(cpuinfo
.icache_line_size
- 1);
80 end
+= (cpuinfo
.icache_line_size
- 1);
81 end
&= ~(cpuinfo
.icache_line_size
- 1);
83 if (end
> start
+ cpuinfo
.icache_size
)
84 end
= start
+ cpuinfo
.icache_size
;
86 for (addr
= start
; addr
< end
; addr
+= cpuinfo
.icache_line_size
) {
87 __asm__
__volatile__ (" flushi %0\n"
89 : /* Inputs */ "r"(addr
)
92 __asm__
__volatile(" flushp\n");
95 static void flush_aliases(struct address_space
*mapping
, struct page
*page
)
97 struct mm_struct
*mm
= current
->active_mm
;
98 struct vm_area_struct
*mpnt
;
103 flush_dcache_mmap_lock(mapping
);
104 vma_interval_tree_foreach(mpnt
, &mapping
->i_mmap
, pgoff
, pgoff
) {
105 unsigned long offset
;
107 if (mpnt
->vm_mm
!= mm
)
109 if (!(mpnt
->vm_flags
& VM_MAYSHARE
))
112 offset
= (pgoff
- mpnt
->vm_pgoff
) << PAGE_SHIFT
;
113 flush_cache_page(mpnt
, mpnt
->vm_start
+ offset
,
116 flush_dcache_mmap_unlock(mapping
);
119 void flush_cache_all(void)
121 __flush_dcache_all(0, cpuinfo
.dcache_size
);
122 __flush_icache(0, cpuinfo
.icache_size
);
125 void flush_cache_mm(struct mm_struct
*mm
)
130 void flush_cache_dup_mm(struct mm_struct
*mm
)
135 void flush_icache_range(unsigned long start
, unsigned long end
)
137 __flush_icache(start
, end
);
140 void flush_dcache_range(unsigned long start
, unsigned long end
)
142 __flush_dcache(start
, end
);
144 EXPORT_SYMBOL(flush_dcache_range
);
146 void invalidate_dcache_range(unsigned long start
, unsigned long end
)
148 __invalidate_dcache(start
, end
);
150 EXPORT_SYMBOL(invalidate_dcache_range
);
152 void flush_cache_range(struct vm_area_struct
*vma
, unsigned long start
,
155 __flush_dcache(start
, end
);
156 if (vma
== NULL
|| (vma
->vm_flags
& VM_EXEC
))
157 __flush_icache(start
, end
);
160 void flush_icache_page(struct vm_area_struct
*vma
, struct page
*page
)
162 unsigned long start
= (unsigned long) page_address(page
);
163 unsigned long end
= start
+ PAGE_SIZE
;
165 __flush_icache(start
, end
);
168 void flush_cache_page(struct vm_area_struct
*vma
, unsigned long vmaddr
,
171 unsigned long start
= vmaddr
;
172 unsigned long end
= start
+ PAGE_SIZE
;
174 __flush_dcache(start
, end
);
175 if (vma
->vm_flags
& VM_EXEC
)
176 __flush_icache(start
, end
);
179 void flush_dcache_page(struct page
*page
)
181 struct address_space
*mapping
;
184 * The zero page is never written to, so never has any dirty
185 * cache lines, and therefore never needs to be flushed.
187 if (page
== ZERO_PAGE(0))
190 mapping
= page_mapping(page
);
192 /* Flush this page if there are aliases. */
193 if (mapping
&& !mapping_mapped(mapping
)) {
194 clear_bit(PG_dcache_clean
, &page
->flags
);
196 unsigned long start
= (unsigned long)page_address(page
);
198 __flush_dcache_all(start
, start
+ PAGE_SIZE
);
200 flush_aliases(mapping
, page
);
201 set_bit(PG_dcache_clean
, &page
->flags
);
204 EXPORT_SYMBOL(flush_dcache_page
);
206 void update_mmu_cache(struct vm_area_struct
*vma
,
207 unsigned long address
, pte_t
*pte
)
209 unsigned long pfn
= pte_pfn(*pte
);
216 * The zero page is never written to, so never has any dirty
217 * cache lines, and therefore never needs to be flushed.
219 page
= pfn_to_page(pfn
);
220 if (page
== ZERO_PAGE(0))
223 if (!PageReserved(page
) &&
224 !test_and_set_bit(PG_dcache_clean
, &page
->flags
)) {
225 unsigned long start
= page_to_virt(page
);
226 struct address_space
*mapping
;
228 __flush_dcache(start
, start
+ PAGE_SIZE
);
230 mapping
= page_mapping(page
);
232 flush_aliases(mapping
, page
);
236 void copy_user_page(void *vto
, void *vfrom
, unsigned long vaddr
,
239 __flush_dcache(vaddr
, vaddr
+ PAGE_SIZE
);
240 copy_page(vto
, vfrom
);
241 __flush_dcache((unsigned long)vto
, (unsigned long)vto
+ PAGE_SIZE
);
244 void clear_user_page(void *addr
, unsigned long vaddr
, struct page
*page
)
246 __flush_dcache(vaddr
, vaddr
+ PAGE_SIZE
);
248 __flush_dcache((unsigned long)addr
, (unsigned long)addr
+ PAGE_SIZE
);
251 void copy_from_user_page(struct vm_area_struct
*vma
, struct page
*page
,
252 unsigned long user_vaddr
,
253 void *dst
, void *src
, int len
)
255 flush_cache_page(vma
, user_vaddr
, page_to_pfn(page
));
256 memcpy(dst
, src
, len
);
257 __flush_dcache((unsigned long)src
, (unsigned long)src
+ len
);
258 if (vma
->vm_flags
& VM_EXEC
)
259 __flush_icache((unsigned long)src
, (unsigned long)src
+ len
);
262 void copy_to_user_page(struct vm_area_struct
*vma
, struct page
*page
,
263 unsigned long user_vaddr
,
264 void *dst
, void *src
, int len
)
266 flush_cache_page(vma
, user_vaddr
, page_to_pfn(page
));
267 memcpy(dst
, src
, len
);
268 __flush_dcache((unsigned long)dst
, (unsigned long)dst
+ len
);
269 if (vma
->vm_flags
& VM_EXEC
)
270 __flush_icache((unsigned long)dst
, (unsigned long)dst
+ len
);