Automatic merge of rsync://rsync.kernel.org/pub/scm/linux/kernel/git/gregkh/driver...
[linux-2.6/verdex.git] / arch / parisc / kernel / cache.c
blobf46a07a792187626370dd139e9496dc0551bb6f0
1 /* $Id: cache.c,v 1.4 2000/01/25 00:11:38 prumpf Exp $
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
5 * for more details.
7 * Copyright (C) 1999 Helge Deller (07-13-1999)
8 * Copyright (C) 1999 SuSE GmbH Nuernberg
9 * Copyright (C) 2000 Philipp Rumpf (prumpf@tux.org)
11 * Cache and TLB management
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/mm.h>
18 #include <linux/module.h>
19 #include <linux/seq_file.h>
20 #include <linux/pagemap.h>
22 #include <asm/pdc.h>
23 #include <asm/cache.h>
24 #include <asm/cacheflush.h>
25 #include <asm/tlbflush.h>
26 #include <asm/system.h>
27 #include <asm/page.h>
28 #include <asm/pgalloc.h>
29 #include <asm/processor.h>
31 int split_tlb;
32 int dcache_stride;
33 int icache_stride;
34 EXPORT_SYMBOL(dcache_stride);
37 #if defined(CONFIG_SMP)
38 /* On some machines (e.g. ones with the Merced bus), there can be
39 * only a single PxTLB broadcast at a time; this must be guaranteed
40 * by software. We put a spinlock around all TLB flushes to
41 * ensure this.
43 DEFINE_SPINLOCK(pa_tlb_lock);
44 EXPORT_SYMBOL(pa_tlb_lock);
45 #endif
47 struct pdc_cache_info cache_info;
48 #ifndef CONFIG_PA20
49 static struct pdc_btlb_info btlb_info;
50 #endif
52 #ifdef CONFIG_SMP
53 void
54 flush_data_cache(void)
56 on_each_cpu((void (*)(void *))flush_data_cache_local, NULL, 1, 1);
58 void
59 flush_instruction_cache(void)
61 on_each_cpu((void (*)(void *))flush_instruction_cache_local, NULL, 1, 1);
63 #endif
65 void
66 flush_cache_all_local(void)
68 flush_instruction_cache_local();
69 flush_data_cache_local();
71 EXPORT_SYMBOL(flush_cache_all_local);
73 /* flushes EVERYTHING (tlb & cache) */
75 void
76 flush_all_caches(void)
78 flush_cache_all();
79 flush_tlb_all();
81 EXPORT_SYMBOL(flush_all_caches);
83 void
84 update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
86 struct page *page = pte_page(pte);
88 if (pfn_valid(page_to_pfn(page)) && page_mapping(page) &&
89 test_bit(PG_dcache_dirty, &page->flags)) {
91 flush_kernel_dcache_page(page_address(page));
92 clear_bit(PG_dcache_dirty, &page->flags);
96 void
97 show_cache_info(struct seq_file *m)
99 seq_printf(m, "I-cache\t\t: %ld KB\n",
100 cache_info.ic_size/1024 );
101 seq_printf(m, "D-cache\t\t: %ld KB (%s%s, %d-way associative)\n",
102 cache_info.dc_size/1024,
103 (cache_info.dc_conf.cc_wt ? "WT":"WB"),
104 (cache_info.dc_conf.cc_sh ? ", shared I/D":""),
105 (cache_info.dc_conf.cc_assoc)
108 seq_printf(m, "ITLB entries\t: %ld\n" "DTLB entries\t: %ld%s\n",
109 cache_info.it_size,
110 cache_info.dt_size,
111 cache_info.dt_conf.tc_sh ? " - shared with ITLB":""
114 #ifndef CONFIG_PA20
115 /* BTLB - Block TLB */
116 if (btlb_info.max_size==0) {
117 seq_printf(m, "BTLB\t\t: not supported\n" );
118 } else {
119 seq_printf(m,
120 "BTLB fixed\t: max. %d pages, pagesize=%d (%dMB)\n"
121 "BTLB fix-entr.\t: %d instruction, %d data (%d combined)\n"
122 "BTLB var-entr.\t: %d instruction, %d data (%d combined)\n",
123 btlb_info.max_size, (int)4096,
124 btlb_info.max_size>>8,
125 btlb_info.fixed_range_info.num_i,
126 btlb_info.fixed_range_info.num_d,
127 btlb_info.fixed_range_info.num_comb,
128 btlb_info.variable_range_info.num_i,
129 btlb_info.variable_range_info.num_d,
130 btlb_info.variable_range_info.num_comb
133 #endif
136 void __init
137 parisc_cache_init(void)
139 if (pdc_cache_info(&cache_info) < 0)
140 panic("parisc_cache_init: pdc_cache_info failed");
142 #if 0
143 printk("ic_size %lx dc_size %lx it_size %lx\n",
144 cache_info.ic_size,
145 cache_info.dc_size,
146 cache_info.it_size);
148 printk("DC base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx\n",
149 cache_info.dc_base,
150 cache_info.dc_stride,
151 cache_info.dc_count,
152 cache_info.dc_loop);
154 printk("dc_conf = 0x%lx alias %d blk %d line %d shift %d\n",
155 *(unsigned long *) (&cache_info.dc_conf),
156 cache_info.dc_conf.cc_alias,
157 cache_info.dc_conf.cc_block,
158 cache_info.dc_conf.cc_line,
159 cache_info.dc_conf.cc_shift);
160 printk(" wt %d sh %d cst %d assoc %d\n",
161 cache_info.dc_conf.cc_wt,
162 cache_info.dc_conf.cc_sh,
163 cache_info.dc_conf.cc_cst,
164 cache_info.dc_conf.cc_assoc);
166 printk("IC base 0x%lx stride 0x%lx count 0x%lx loop 0x%lx\n",
167 cache_info.ic_base,
168 cache_info.ic_stride,
169 cache_info.ic_count,
170 cache_info.ic_loop);
172 printk("ic_conf = 0x%lx alias %d blk %d line %d shift %d\n",
173 *(unsigned long *) (&cache_info.ic_conf),
174 cache_info.ic_conf.cc_alias,
175 cache_info.ic_conf.cc_block,
176 cache_info.ic_conf.cc_line,
177 cache_info.ic_conf.cc_shift);
178 printk(" wt %d sh %d cst %d assoc %d\n",
179 cache_info.ic_conf.cc_wt,
180 cache_info.ic_conf.cc_sh,
181 cache_info.ic_conf.cc_cst,
182 cache_info.ic_conf.cc_assoc);
184 printk("D-TLB conf: sh %d page %d cst %d aid %d pad1 %d \n",
185 cache_info.dt_conf.tc_sh,
186 cache_info.dt_conf.tc_page,
187 cache_info.dt_conf.tc_cst,
188 cache_info.dt_conf.tc_aid,
189 cache_info.dt_conf.tc_pad1);
191 printk("I-TLB conf: sh %d page %d cst %d aid %d pad1 %d \n",
192 cache_info.it_conf.tc_sh,
193 cache_info.it_conf.tc_page,
194 cache_info.it_conf.tc_cst,
195 cache_info.it_conf.tc_aid,
196 cache_info.it_conf.tc_pad1);
197 #endif
199 split_tlb = 0;
200 if (cache_info.dt_conf.tc_sh == 0 || cache_info.dt_conf.tc_sh == 2) {
201 if (cache_info.dt_conf.tc_sh == 2)
202 printk(KERN_WARNING "Unexpected TLB configuration. "
203 "Will flush I/D separately (could be optimized).\n");
205 split_tlb = 1;
208 /* "New and Improved" version from Jim Hull
209 * (1 << (cc_block-1)) * (cc_line << (4 + cnf.cc_shift))
211 #define CAFL_STRIDE(cnf) (cnf.cc_line << (3 + cnf.cc_block + cnf.cc_shift))
212 dcache_stride = CAFL_STRIDE(cache_info.dc_conf);
213 icache_stride = CAFL_STRIDE(cache_info.ic_conf);
214 #undef CAFL_STRIDE
216 #ifndef CONFIG_PA20
217 if (pdc_btlb_info(&btlb_info) < 0) {
218 memset(&btlb_info, 0, sizeof btlb_info);
220 #endif
222 if ((boot_cpu_data.pdc.capabilities & PDC_MODEL_NVA_MASK) ==
223 PDC_MODEL_NVA_UNSUPPORTED) {
224 printk(KERN_WARNING "parisc_cache_init: Only equivalent aliasing supported!\n");
225 #if 0
226 panic("SMP kernel required to avoid non-equivalent aliasing");
227 #endif
231 void disable_sr_hashing(void)
233 int srhash_type;
235 switch (boot_cpu_data.cpu_type) {
236 case pcx: /* We shouldn't get this far. setup.c should prevent it. */
237 BUG();
238 return;
240 case pcxs:
241 case pcxt:
242 case pcxt_:
243 srhash_type = SRHASH_PCXST;
244 break;
246 case pcxl:
247 srhash_type = SRHASH_PCXL;
248 break;
250 case pcxl2: /* pcxl2 doesn't support space register hashing */
251 return;
253 default: /* Currently all PA2.0 machines use the same ins. sequence */
254 srhash_type = SRHASH_PA20;
255 break;
258 disable_sr_hashing_asm(srhash_type);
261 void flush_dcache_page(struct page *page)
263 struct address_space *mapping = page_mapping(page);
264 struct vm_area_struct *mpnt;
265 struct prio_tree_iter iter;
266 unsigned long offset;
267 unsigned long addr;
268 pgoff_t pgoff;
269 pte_t *pte;
270 unsigned long pfn = page_to_pfn(page);
273 if (mapping && !mapping_mapped(mapping)) {
274 set_bit(PG_dcache_dirty, &page->flags);
275 return;
278 flush_kernel_dcache_page(page_address(page));
280 if (!mapping)
281 return;
283 pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
285 /* We have carefully arranged in arch_get_unmapped_area() that
286 * *any* mappings of a file are always congruently mapped (whether
287 * declared as MAP_PRIVATE or MAP_SHARED), so we only need
288 * to flush one address here for them all to become coherent */
290 flush_dcache_mmap_lock(mapping);
291 vma_prio_tree_foreach(mpnt, &iter, &mapping->i_mmap, pgoff, pgoff) {
292 offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT;
293 addr = mpnt->vm_start + offset;
295 /* Flush instructions produce non access tlb misses.
296 * On PA, we nullify these instructions rather than
297 * taking a page fault if the pte doesn't exist.
298 * This is just for speed. If the page translation
299 * isn't there, there's no point exciting the
300 * nadtlb handler into a nullification frenzy */
303 if(!(pte = translation_exists(mpnt, addr)))
304 continue;
306 /* make sure we really have this page: the private
307 * mappings may cover this area but have COW'd this
308 * particular page */
309 if(pte_pfn(*pte) != pfn)
310 continue;
312 __flush_cache_page(mpnt, addr);
314 break;
316 flush_dcache_mmap_unlock(mapping);
318 EXPORT_SYMBOL(flush_dcache_page);
320 /* Defined in arch/parisc/kernel/pacache.S */
321 EXPORT_SYMBOL(flush_kernel_dcache_range_asm);
322 EXPORT_SYMBOL(flush_kernel_dcache_page);
323 EXPORT_SYMBOL(flush_data_cache_local);
324 EXPORT_SYMBOL(flush_kernel_icache_range_asm);
326 void clear_user_page_asm(void *page, unsigned long vaddr)
328 /* This function is implemented in assembly in pacache.S */
329 extern void __clear_user_page_asm(void *page, unsigned long vaddr);
331 purge_tlb_start();
332 __clear_user_page_asm(page, vaddr);
333 purge_tlb_end();
336 #define FLUSH_THRESHOLD 0x80000 /* 0.5MB */
337 int parisc_cache_flush_threshold = FLUSH_THRESHOLD;
339 void parisc_setup_cache_timing(void)
341 unsigned long rangetime, alltime;
342 extern char _text; /* start of kernel code, defined by linker */
343 extern char _end; /* end of BSS, defined by linker */
344 unsigned long size;
346 alltime = mfctl(16);
347 flush_data_cache();
348 alltime = mfctl(16) - alltime;
350 size = (unsigned long)(&_end - _text);
351 rangetime = mfctl(16);
352 flush_kernel_dcache_range((unsigned long)&_text, size);
353 rangetime = mfctl(16) - rangetime;
355 printk(KERN_DEBUG "Whole cache flush %lu cycles, flushing %lu bytes %lu cycles\n",
356 alltime, size, rangetime);
358 /* Racy, but if we see an intermediate value, it's ok too... */
359 parisc_cache_flush_threshold = size * alltime / rangetime;
361 parisc_cache_flush_threshold = (parisc_cache_flush_threshold + L1_CACHE_BYTES - 1) &~ (L1_CACHE_BYTES - 1);
362 if (!parisc_cache_flush_threshold)
363 parisc_cache_flush_threshold = FLUSH_THRESHOLD;
365 printk("Setting cache flush threshold to %x (%d CPUs online)\n", parisc_cache_flush_threshold, num_online_cpus());