2 * Copyright (C) 2004-2006 Atmel Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/highmem.h>
10 #include <linux/unistd.h>
12 #include <asm/cacheflush.h>
13 #include <asm/cachectl.h>
14 #include <asm/processor.h>
15 #include <asm/uaccess.h>
18 * If you attempt to flush anything more than this, you need superuser
19 * privileges. The value is completely arbitrary.
21 #define CACHEFLUSH_MAX_LEN 1024
23 void invalidate_dcache_region(void *start, size_t size)
25 unsigned long v, begin, end, linesz, mask;
28 linesz = boot_cpu_data.dcache.linesz;
31 /* when first and/or last cachelines are shared, flush them
32 * instead of invalidating ... never discard valid data!
34 begin = (unsigned long)start;
35 end = begin + size - 1;
38 flush_dcache_line(start);
42 if ((end & mask) != mask) {
43 flush_dcache_line((void *)end);
48 /* remaining cachelines only need invalidation */
49 for (v = begin; v <= end; v += linesz)
50 invalidate_dcache_line((void *)v);
55 void clean_dcache_region(void *start, size_t size)
57 unsigned long v, begin, end, linesz;
59 linesz = boot_cpu_data.dcache.linesz;
60 begin = (unsigned long)start & ~(linesz - 1);
61 end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
63 for (v = begin; v < end; v += linesz)
64 clean_dcache_line((void *)v);
68 void flush_dcache_region(void *start, size_t size)
70 unsigned long v, begin, end, linesz;
72 linesz = boot_cpu_data.dcache.linesz;
73 begin = (unsigned long)start & ~(linesz - 1);
74 end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
76 for (v = begin; v < end; v += linesz)
77 flush_dcache_line((void *)v);
81 void invalidate_icache_region(void *start, size_t size)
83 unsigned long v, begin, end, linesz;
85 linesz = boot_cpu_data.icache.linesz;
86 begin = (unsigned long)start & ~(linesz - 1);
87 end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
89 for (v = begin; v < end; v += linesz)
90 invalidate_icache_line((void *)v);
93 static inline void __flush_icache_range(unsigned long start, unsigned long end)
95 unsigned long v, linesz;
97 linesz = boot_cpu_data.dcache.linesz;
98 for (v = start; v < end; v += linesz) {
99 clean_dcache_line((void *)v);
100 invalidate_icache_line((void *)v);
103 flush_write_buffer();
107 * This one is called after a module has been loaded.
109 void flush_icache_range(unsigned long start, unsigned long end)
111 unsigned long linesz;
113 linesz = boot_cpu_data.dcache.linesz;
114 __flush_icache_range(start & ~(linesz - 1),
115 (end + linesz - 1) & ~(linesz - 1));
119 * This one is called from do_no_page(), do_swap_page() and install_page().
121 void flush_icache_page(struct vm_area_struct *vma, struct page *page)
123 if (vma->vm_flags & VM_EXEC) {
124 void *v = kmap(page);
125 __flush_icache_range((unsigned long)v, (unsigned long)v + PAGE_SIZE);
131 * This one is used by copy_to_user_page()
133 void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
134 unsigned long addr, int len)
136 if (vma->vm_flags & VM_EXEC)
137 flush_icache_range(addr, addr + len);
140 asmlinkage int sys_cacheflush(int operation, void __user *addr, size_t len)
144 if (len > CACHEFLUSH_MAX_LEN) {
146 if (!capable(CAP_SYS_ADMIN))
151 if (!access_ok(VERIFY_WRITE, addr, len))
156 flush_icache_range((unsigned long)addr,
157 (unsigned long)addr + len);