import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / mips / mm / cache.c
1 /*
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
4  * for more details.
5  *
6  * Copyright (C) 1994 - 2003 by Ralf Baechle
7  */
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/sched.h>
11 #include <linux/mm.h>
12
13 #include <asm/cacheflush.h>
14
15 asmlinkage int sys_cacheflush(void *addr, int bytes, int cache)
16 {
17         /* This should flush more selectivly ...  */
18         __flush_cache_all();
19
20         return 0;
21 }
22
23 void flush_dcache_page(struct page *page)
24 {
25         unsigned long addr;
26
27         if (!cpu_has_dc_aliases)
28                 return;
29
30         if (page->mapping && page->mapping->i_mmap == NULL &&
31             page->mapping->i_mmap_shared == NULL) {
32                 SetPageDcacheDirty(page);
33
34                 return;
35         }
36
37         /*
38          * We could delay the flush for the !page->mapping case too.  But that
39          * case is for exec env/arg pages and those are 99% certainly going to
40          * get faulted into the tlb (and thus flushed) anyways.
41          */
42         addr = (unsigned long) page_address(page);
43         flush_data_cache_page(addr);
44 }
45
46 void __update_cache(struct vm_area_struct *vma, unsigned long address,
47         pte_t pte)
48 {
49         unsigned long addr;
50         struct page *page;
51
52         if (!cpu_has_dc_aliases)
53                 return;
54
55         page = pte_page(pte);
56         if (VALID_PAGE(page) && page->mapping &&
57             (page->flags & (1UL << PG_dcache_dirty))) {
58                 if (pages_do_alias((unsigned long) page_address(page), address & PAGE_MASK)) {
59                         addr = (unsigned long) page_address(page);
60                         flush_data_cache_page(addr);
61                 }
62
63                 ClearPageDcacheDirty(page);
64         }
65 }
66
67 EXPORT_SYMBOL(flush_dcache_page);