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>
16 #include <asm/syscalls.h>
19 * If you attempt to flush anything more than this, you need superuser
20 * privileges. The value is completely arbitrary.
22 #define CACHEFLUSH_MAX_LEN 1024
24 void invalidate_dcache_region(void *start
, size_t size
)
26 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
;
38 flush_dcache_line(start
);
42 flush_dcache_line((void *)end
);
46 /* remaining cachelines only need invalidation */
47 for (v
= begin
; v
< end
; v
+= linesz
)
48 invalidate_dcache_line((void *)v
);
52 void clean_dcache_region(void *start
, size_t size
)
54 unsigned long v
, begin
, end
, linesz
;
56 linesz
= boot_cpu_data
.dcache
.linesz
;
57 begin
= (unsigned long)start
& ~(linesz
- 1);
58 end
= ((unsigned long)start
+ size
+ linesz
- 1) & ~(linesz
- 1);
60 for (v
= begin
; v
< end
; v
+= linesz
)
61 clean_dcache_line((void *)v
);
65 void flush_dcache_region(void *start
, size_t size
)
67 unsigned long v
, begin
, end
, linesz
;
69 linesz
= boot_cpu_data
.dcache
.linesz
;
70 begin
= (unsigned long)start
& ~(linesz
- 1);
71 end
= ((unsigned long)start
+ size
+ linesz
- 1) & ~(linesz
- 1);
73 for (v
= begin
; v
< end
; v
+= linesz
)
74 flush_dcache_line((void *)v
);
78 void invalidate_icache_region(void *start
, size_t size
)
80 unsigned long v
, begin
, end
, linesz
;
82 linesz
= boot_cpu_data
.icache
.linesz
;
83 begin
= (unsigned long)start
& ~(linesz
- 1);
84 end
= ((unsigned long)start
+ size
+ linesz
- 1) & ~(linesz
- 1);
86 for (v
= begin
; v
< end
; v
+= linesz
)
87 invalidate_icache_line((void *)v
);
90 static inline void __flush_icache_range(unsigned long start
, unsigned long end
)
92 unsigned long v
, linesz
;
94 linesz
= boot_cpu_data
.dcache
.linesz
;
95 for (v
= start
; v
< end
; v
+= linesz
) {
96 clean_dcache_line((void *)v
);
97 invalidate_icache_line((void *)v
);
100 flush_write_buffer();
104 * This one is called after a module has been loaded.
106 void flush_icache_range(unsigned long start
, unsigned long end
)
108 unsigned long linesz
;
110 linesz
= boot_cpu_data
.dcache
.linesz
;
111 __flush_icache_range(start
& ~(linesz
- 1),
112 (end
+ linesz
- 1) & ~(linesz
- 1));
114 EXPORT_SYMBOL(flush_icache_range
);
117 * This one is called from __do_fault() and do_swap_page().
119 void flush_icache_page(struct vm_area_struct
*vma
, struct page
*page
)
121 if (vma
->vm_flags
& VM_EXEC
) {
122 void *v
= page_address(page
);
123 __flush_icache_range((unsigned long)v
, (unsigned long)v
+ PAGE_SIZE
);
127 asmlinkage
int sys_cacheflush(int operation
, void __user
*addr
, size_t len
)
131 if (len
> CACHEFLUSH_MAX_LEN
) {
133 if (!capable(CAP_SYS_ADMIN
))
138 if (!access_ok(VERIFY_WRITE
, addr
, len
))
143 flush_icache_range((unsigned long)addr
,
144 (unsigned long)addr
+ len
);
155 void copy_to_user_page(struct vm_area_struct
*vma
, struct page
*page
,
156 unsigned long vaddr
, void *dst
, const void *src
,
159 memcpy(dst
, src
, len
);
160 if (vma
->vm_flags
& VM_EXEC
)
161 flush_icache_range((unsigned long)dst
,
162 (unsigned long)dst
+ len
);