ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.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/config.h>
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/sched.h>
13 #include <linux/mm.h>
14
15 #include <asm/cacheflush.h>
16 #include <asm/processor.h>
17 #include <asm/cpu.h>
18 #include <asm/cpu-features.h>
19
20 /* Cache operations. */
21 void (*flush_cache_all)(void);
22 void (*__flush_cache_all)(void);
23 void (*flush_cache_mm)(struct mm_struct *mm);
24 void (*flush_cache_range)(struct vm_area_struct *vma, unsigned long start,
25         unsigned long end);
26 void (*flush_cache_page)(struct vm_area_struct *vma, unsigned long page);
27 void (*flush_icache_range)(unsigned long start, unsigned long end);
28 void (*flush_icache_page)(struct vm_area_struct *vma, struct page *page);
29
30 /* MIPS specific cache operations */
31 void (*flush_cache_sigtramp)(unsigned long addr);
32 void (*flush_data_cache_page)(unsigned long addr);
33 void (*flush_icache_all)(void);
34
35 #ifdef CONFIG_DMA_NONCOHERENT
36
37 /* DMA cache operations. */
38 void (*_dma_cache_wback_inv)(unsigned long start, unsigned long size);
39 void (*_dma_cache_wback)(unsigned long start, unsigned long size);
40 void (*_dma_cache_inv)(unsigned long start, unsigned long size);
41
42 EXPORT_SYMBOL(_dma_cache_wback_inv);
43 EXPORT_SYMBOL(_dma_cache_wback);
44 EXPORT_SYMBOL(_dma_cache_inv);
45
46 #endif /* CONFIG_DMA_NONCOHERENT */
47
48 asmlinkage int sys_cacheflush(void *addr, int bytes, int cache)
49 {
50         /* This should flush more selectivly ...  */
51         __flush_cache_all();
52
53         return 0;
54 }
55
56 void __flush_dcache_page(struct page *page)
57 {
58         struct address_space *mapping = page_mapping(page);
59         unsigned long addr;
60
61         if (mapping && !mapping_mapped(mapping)) {
62                 SetPageDcacheDirty(page);
63                 return;
64         }
65
66         /*
67          * We could delay the flush for the !page_mapping case too.  But that
68          * case is for exec env/arg pages and those are %99 certainly going to
69          * get faulted into the tlb (and thus flushed) anyways.
70          */
71         addr = (unsigned long) page_address(page);
72         flush_data_cache_page(addr);
73 }
74
75 EXPORT_SYMBOL(__flush_dcache_page);
76
77 void __update_cache(struct vm_area_struct *vma, unsigned long address,
78         pte_t pte)
79 {
80         struct page *page;
81         unsigned long pfn, addr;
82
83         pfn = pte_pfn(pte);
84         if (pfn_valid(pfn) && (page = pfn_to_page(pfn), page_mapping(page)) &&
85             Page_dcache_dirty(page)) {
86                 if (pages_do_alias((unsigned long)page_address(page),
87                                    address & PAGE_MASK)) {
88                         addr = (unsigned long) page_address(page);
89                         flush_data_cache_page(addr);
90                 }
91
92                 ClearPageDcacheDirty(page);
93         }
94 }
95
96 extern void ld_mmu_r23000(void);
97 extern void ld_mmu_r4xx0(void);
98 extern void ld_mmu_tx39(void);
99 extern void ld_mmu_r6000(void);
100 extern void ld_mmu_tfp(void);
101 extern void ld_mmu_andes(void);
102 extern void ld_mmu_sb1(void);
103
104 void __init cpu_cache_init(void)
105 {
106         if (cpu_has_4ktlb) {
107 #if defined(CONFIG_CPU_R4X00)  || defined(CONFIG_CPU_VR41XX) || \
108     defined(CONFIG_CPU_R4300)  || defined(CONFIG_CPU_R5000)  || \
109     defined(CONFIG_CPU_NEVADA) || defined(CONFIG_CPU_R5432)  || \
110     defined(CONFIG_CPU_R5500)  || defined(CONFIG_CPU_MIPS32) || \
111     defined(CONFIG_CPU_MIPS64) || defined(CONFIG_CPU_TX49XX) || \
112     defined(CONFIG_CPU_RM7000) || defined(CONFIG_CPU_RM9000)
113                 ld_mmu_r4xx0();
114 #endif
115         } else switch (current_cpu_data.cputype) {
116 #ifdef CONFIG_CPU_R3000
117         case CPU_R2000:
118         case CPU_R3000:
119         case CPU_R3000A:
120         case CPU_R3081E:
121                 ld_mmu_r23000();
122                 break;
123 #endif
124 #ifdef CONFIG_CPU_TX39XX
125         case CPU_TX3912:
126         case CPU_TX3922:
127         case CPU_TX3927:
128                 ld_mmu_tx39();
129                 break;
130 #endif
131 #ifdef CONFIG_CPU_R10000
132         case CPU_R10000:
133         case CPU_R12000:
134                 ld_mmu_r4xx0();
135                 break;
136 #endif
137 #ifdef CONFIG_CPU_SB1
138         case CPU_SB1:
139                 ld_mmu_sb1();
140                 break;
141 #endif
142
143         case CPU_R8000:
144                 panic("R8000 is unsupported");
145                 break;
146
147         default:
148                 panic("Yeee, unsupported cache architecture.");
149         }
150 }