x86/paravirt: make set_pud operation common
[linux-2.6/openmoko-kernel/knife-kernel.git] / arch / avr32 / mm / cache.c
blob15a4e5e142c161aeae51f61187f5f370c0e130e1
1 /*
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.
7 */
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;
27 linesz = boot_cpu_data.dcache.linesz;
28 mask = linesz - 1;
30 /* when first and/or last cachelines are shared, flush them
31 * instead of invalidating ... never discard valid data!
33 begin = (unsigned long)start;
34 end = begin + size;
36 if (begin & mask) {
37 flush_dcache_line(start);
38 begin += linesz;
40 if (end & mask) {
41 flush_dcache_line((void *)end);
42 end &= ~mask;
45 /* remaining cachelines only need invalidation */
46 for (v = begin; v < end; v += linesz)
47 invalidate_dcache_line((void *)v);
48 flush_write_buffer();
51 void clean_dcache_region(void *start, size_t size)
53 unsigned long v, begin, end, linesz;
55 linesz = boot_cpu_data.dcache.linesz;
56 begin = (unsigned long)start & ~(linesz - 1);
57 end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
59 for (v = begin; v < end; v += linesz)
60 clean_dcache_line((void *)v);
61 flush_write_buffer();
64 void flush_dcache_region(void *start, size_t size)
66 unsigned long v, begin, end, linesz;
68 linesz = boot_cpu_data.dcache.linesz;
69 begin = (unsigned long)start & ~(linesz - 1);
70 end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
72 for (v = begin; v < end; v += linesz)
73 flush_dcache_line((void *)v);
74 flush_write_buffer();
77 void invalidate_icache_region(void *start, size_t size)
79 unsigned long v, begin, end, linesz;
81 linesz = boot_cpu_data.icache.linesz;
82 begin = (unsigned long)start & ~(linesz - 1);
83 end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
85 for (v = begin; v < end; v += linesz)
86 invalidate_icache_line((void *)v);
89 static inline void __flush_icache_range(unsigned long start, unsigned long end)
91 unsigned long v, linesz;
93 linesz = boot_cpu_data.dcache.linesz;
94 for (v = start; v < end; v += linesz) {
95 clean_dcache_line((void *)v);
96 invalidate_icache_line((void *)v);
99 flush_write_buffer();
103 * This one is called after a module has been loaded.
105 void flush_icache_range(unsigned long start, unsigned long end)
107 unsigned long linesz;
109 linesz = boot_cpu_data.dcache.linesz;
110 __flush_icache_range(start & ~(linesz - 1),
111 (end + linesz - 1) & ~(linesz - 1));
115 * This one is called from do_no_page(), do_swap_page() and install_page().
117 void flush_icache_page(struct vm_area_struct *vma, struct page *page)
119 if (vma->vm_flags & VM_EXEC) {
120 void *v = page_address(page);
121 __flush_icache_range((unsigned long)v, (unsigned long)v + PAGE_SIZE);
125 asmlinkage int sys_cacheflush(int operation, void __user *addr, size_t len)
127 int ret;
129 if (len > CACHEFLUSH_MAX_LEN) {
130 ret = -EPERM;
131 if (!capable(CAP_SYS_ADMIN))
132 goto out;
135 ret = -EFAULT;
136 if (!access_ok(VERIFY_WRITE, addr, len))
137 goto out;
139 switch (operation) {
140 case CACHE_IFLUSH:
141 flush_icache_range((unsigned long)addr,
142 (unsigned long)addr + len);
143 ret = 0;
144 break;
145 default:
146 ret = -EINVAL;
149 out:
150 return ret;
153 void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
154 unsigned long vaddr, void *dst, const void *src,
155 unsigned long len)
157 memcpy(dst, src, len);
158 if (vma->vm_flags & VM_EXEC)
159 flush_icache_range((unsigned long)dst,
160 (unsigned long)dst + len);