Merge branch 'for-linus' of git://oss.sgi.com:8090/xfs/xfs-2.6
[powerpc.git] / arch / avr32 / mm / cache.c
index 450515b..15a4e5e 100644 (file)
 
 void invalidate_dcache_region(void *start, size_t size)
 {
-       unsigned long v, begin, end, linesz;
+       unsigned long v, begin, end, linesz, mask;
 
        linesz = boot_cpu_data.dcache.linesz;
+       mask = linesz - 1;
 
-       //printk("invalidate dcache: %p + %u\n", start, size);
+       /* when first and/or last cachelines are shared, flush them
+        * instead of invalidating ... never discard valid data!
+        */
+       begin = (unsigned long)start;
+       end = begin + size;
 
-       /* You asked for it, you got it */
-       begin = (unsigned long)start & ~(linesz - 1);
-       end = ((unsigned long)start + size + linesz - 1) & ~(linesz - 1);
+       if (begin & mask) {
+               flush_dcache_line(start);
+               begin += linesz;
+       }
+       if (end & mask) {
+               flush_dcache_line((void *)end);
+               end &= ~mask;
+       }
 
+       /* remaining cachelines only need invalidation */
        for (v = begin; v < end; v += linesz)
                invalidate_dcache_line((void *)v);
+       flush_write_buffer();
 }
 
 void clean_dcache_region(void *start, size_t size)
@@ -105,22 +117,11 @@ void flush_icache_range(unsigned long start, unsigned long end)
 void flush_icache_page(struct vm_area_struct *vma, struct page *page)
 {
        if (vma->vm_flags & VM_EXEC) {
-               void *v = kmap(page);
+               void *v = page_address(page);
                __flush_icache_range((unsigned long)v, (unsigned long)v + PAGE_SIZE);
-               kunmap(v);
        }
 }
 
-/*
- * This one is used by copy_to_user_page()
- */
-void flush_icache_user_range(struct vm_area_struct *vma, struct page *page,
-                            unsigned long addr, int len)
-{
-       if (vma->vm_flags & VM_EXEC)
-               flush_icache_range(addr, addr + len);
-}
-
 asmlinkage int sys_cacheflush(int operation, void __user *addr, size_t len)
 {
        int ret;
@@ -148,3 +149,13 @@ asmlinkage int sys_cacheflush(int operation, void __user *addr, size_t len)
 out:
        return ret;
 }
+
+void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
+               unsigned long vaddr, void *dst, const void *src,
+               unsigned long len)
+{
+       memcpy(dst, src, len);
+       if (vma->vm_flags & VM_EXEC)
+               flush_icache_range((unsigned long)dst,
+                               (unsigned long)dst + len);
+}