parisc: flush pages through tmpalias space
[linux-flexiantxendom0-3.2.10.git] / arch / parisc / kernel / cache.c
index 7e8d697..3f11331 100644 (file)
@@ -1,5 +1,4 @@
-/* $Id: cache.c,v 1.4 2000/01/25 00:11:38 prumpf Exp $
- *
+/*
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
@@ -18,7 +17,7 @@
 #include <linux/module.h>
 #include <linux/seq_file.h>
 #include <linux/pagemap.h>
-
+#include <linux/sched.h>
 #include <asm/pdc.h>
 #include <asm/cache.h>
 #include <asm/cacheflush.h>
 #include <asm/pgalloc.h>
 #include <asm/processor.h>
 #include <asm/sections.h>
+#include <asm/shmparam.h>
 
 int split_tlb __read_mostly;
 int dcache_stride __read_mostly;
 int icache_stride __read_mostly;
 EXPORT_SYMBOL(dcache_stride);
 
+void flush_dcache_page_asm(unsigned long phys_addr, unsigned long vaddr);
+EXPORT_SYMBOL(flush_dcache_page_asm);
+void flush_icache_page_asm(unsigned long phys_addr, unsigned long vaddr);
+
 
-#if defined(CONFIG_SMP)
 /* On some machines (e.g. ones with the Merced bus), there can be
  * only a single PxTLB broadcast at a time; this must be guaranteed
  * by software.  We put a spinlock around all TLB flushes  to
  * ensure this.
  */
 DEFINE_SPINLOCK(pa_tlb_lock);
-EXPORT_SYMBOL(pa_tlb_lock);
-#endif
 
 struct pdc_cache_info cache_info __read_mostly;
 #ifndef CONFIG_PA20
@@ -54,12 +55,12 @@ static struct pdc_btlb_info btlb_info __read_mostly;
 void
 flush_data_cache(void)
 {
-       on_each_cpu(flush_data_cache_local, NULL, 1, 1);
+       on_each_cpu(flush_data_cache_local, NULL, 1);
 }
 void 
 flush_instruction_cache(void)
 {
-       on_each_cpu(flush_instruction_cache_local, NULL, 1, 1);
+       on_each_cpu(flush_instruction_cache_local, NULL, 1);
 }
 #endif
 
@@ -71,20 +72,10 @@ flush_cache_all_local(void)
 }
 EXPORT_SYMBOL(flush_cache_all_local);
 
-/* flushes EVERYTHING (tlb & cache) */
-
 void
-flush_all_caches(void)
+update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep)
 {
-       flush_cache_all();
-       flush_tlb_all();
-}
-EXPORT_SYMBOL(flush_all_caches);
-
-void
-update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
-{
-       struct page *page = pte_page(pte);
+       struct page *page = pte_page(*ptep);
 
        if (pfn_valid(page_to_pfn(page)) && page_mapping(page) &&
            test_bit(PG_dcache_dirty, &page->flags)) {
@@ -102,7 +93,7 @@ show_cache_info(struct seq_file *m)
 
        seq_printf(m, "I-cache\t\t: %ld KB\n", 
                cache_info.ic_size/1024 );
-       if (cache_info.dc_loop == 1)
+       if (cache_info.dc_loop != 1)
                snprintf(buf, 32, "%lu-way associative", cache_info.dc_loop);
        seq_printf(m, "D-cache\t\t: %ld KB (%s%s, %s)\n",
                cache_info.dc_size/1024,
@@ -185,14 +176,14 @@ parisc_cache_init(void)
                cache_info.ic_conf.cc_cst,
                cache_info.ic_conf.cc_hv);
 
-       printk("D-TLB conf: sh %d page %d cst %d aid %d pad1 %d \n",
+       printk("D-TLB conf: sh %d page %d cst %d aid %d pad1 %d\n",
                cache_info.dt_conf.tc_sh,
                cache_info.dt_conf.tc_page,
                cache_info.dt_conf.tc_cst,
                cache_info.dt_conf.tc_aid,
                cache_info.dt_conf.tc_pad1);
 
-       printk("I-TLB conf: sh %d page %d cst %d aid %d pad1 %d \n",
+       printk("I-TLB conf: sh %d page %d cst %d aid %d pad1 %d\n",
                cache_info.it_conf.tc_sh,
                cache_info.it_conf.tc_page,
                cache_info.it_conf.tc_cst,
@@ -273,16 +264,23 @@ void disable_sr_hashing(void)
                panic("SpaceID hashing is still on!\n");
 }
 
+static inline void
+__flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr,
+                  unsigned long physaddr)
+{
+       flush_dcache_page_asm(physaddr, vmaddr);
+       if (vma->vm_flags & VM_EXEC)
+               flush_icache_page_asm(physaddr, vmaddr);
+}
+
 void flush_dcache_page(struct page *page)
 {
        struct address_space *mapping = page_mapping(page);
        struct vm_area_struct *mpnt;
        struct prio_tree_iter iter;
        unsigned long offset;
-       unsigned long addr;
+       unsigned long addr, old_addr = 0;
        pgoff_t pgoff;
-       unsigned long pfn = page_to_pfn(page);
-
 
        if (mapping && !mapping_mapped(mapping)) {
                set_bit(PG_dcache_dirty, &page->flags);
@@ -306,20 +304,11 @@ void flush_dcache_page(struct page *page)
                offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT;
                addr = mpnt->vm_start + offset;
 
-               /* Flush instructions produce non access tlb misses.
-                * On PA, we nullify these instructions rather than
-                * taking a page fault if the pte doesn't exist.
-                * This is just for speed.  If the page translation
-                * isn't there, there's no point exciting the
-                * nadtlb handler into a nullification frenzy.
-                *
-                * Make sure we really have this page: the private
-                * mappings may cover this area but have COW'd this
-                * particular page.
-                */
-               if (translation_exists(mpnt, addr, pfn)) {
-                       __flush_cache_page(mpnt, addr);
-                       break;
+               if (old_addr == 0 || (old_addr & (SHMLBA - 1)) != (addr & (SHMLBA - 1))) {
+                       __flush_cache_page(mpnt, addr, page_to_phys(page));
+                       if (old_addr)
+                               printk(KERN_ERR "INEQUIVALENT ALIASES 0x%lx and 0x%lx in file %s\n", old_addr, addr, mpnt->vm_file ? mpnt->vm_file->f_path.dentry->d_name.name : "(null)");
+                       old_addr = addr;
                }
        }
        flush_dcache_mmap_unlock(mapping);
@@ -334,18 +323,19 @@ EXPORT_SYMBOL(flush_kernel_icache_range_asm);
 
 void clear_user_page_asm(void *page, unsigned long vaddr)
 {
+       unsigned long flags;
        /* This function is implemented in assembly in pacache.S */
        extern void __clear_user_page_asm(void *page, unsigned long vaddr);
 
-       purge_tlb_start();
+       purge_tlb_start(flags);
        __clear_user_page_asm(page, vaddr);
-       purge_tlb_end();
+       purge_tlb_end(flags);
 }
 
 #define FLUSH_THRESHOLD 0x80000 /* 0.5MB */
 int parisc_cache_flush_threshold __read_mostly = FLUSH_THRESHOLD;
 
-void parisc_setup_cache_timing(void)
+void __init parisc_setup_cache_timing(void)
 {
        unsigned long rangetime, alltime;
        unsigned long size;
@@ -369,28 +359,35 @@ void parisc_setup_cache_timing(void)
        if (!parisc_cache_flush_threshold)
                parisc_cache_flush_threshold = FLUSH_THRESHOLD;
 
+       if (parisc_cache_flush_threshold > cache_info.dc_size)
+               parisc_cache_flush_threshold = cache_info.dc_size;
+
        printk(KERN_INFO "Setting cache flush threshold to %x (%d CPUs online)\n", parisc_cache_flush_threshold, num_online_cpus());
 }
 
 extern void purge_kernel_dcache_page(unsigned long);
 extern void clear_user_page_asm(void *page, unsigned long vaddr);
 
-void
-clear_user_page(void *page, unsigned long vaddr, struct page *pg)
+void clear_user_page(void *page, unsigned long vaddr, struct page *pg)
 {
+       unsigned long flags;
+
        purge_kernel_dcache_page((unsigned long)page);
-       purge_tlb_start();
+       purge_tlb_start(flags);
        pdtlb_kernel(page);
-       purge_tlb_end();
+       purge_tlb_end(flags);
        clear_user_page_asm(page, vaddr);
 }
+EXPORT_SYMBOL(clear_user_page);
 
 void flush_kernel_dcache_page_addr(void *addr)
 {
+       unsigned long flags;
+
        flush_kernel_dcache_page_asm(addr);
-       purge_tlb_start();
+       purge_tlb_start(flags);
        pdtlb_kernel(addr);
-       purge_tlb_end();
+       purge_tlb_end(flags);
 }
 EXPORT_SYMBOL(flush_kernel_dcache_page_addr);
 
@@ -413,3 +410,95 @@ void kunmap_parisc(void *addr)
 }
 EXPORT_SYMBOL(kunmap_parisc);
 #endif
+
+void __flush_tlb_range(unsigned long sid, unsigned long start,
+                      unsigned long end)
+{
+       unsigned long npages;
+
+       npages = ((end - (start & PAGE_MASK)) + (PAGE_SIZE - 1)) >> PAGE_SHIFT;
+       if (npages >= 512)  /* 2MB of space: arbitrary, should be tuned */
+               flush_tlb_all();
+       else {
+               unsigned long flags;
+
+               mtsp(sid, 1);
+               purge_tlb_start(flags);
+               if (split_tlb) {
+                       while (npages--) {
+                               pdtlb(start);
+                               pitlb(start);
+                               start += PAGE_SIZE;
+                       }
+               } else {
+                       while (npages--) {
+                               pdtlb(start);
+                               start += PAGE_SIZE;
+                       }
+               }
+               purge_tlb_end(flags);
+       }
+}
+
+static void cacheflush_h_tmp_function(void *dummy)
+{
+       flush_cache_all_local();
+}
+
+void flush_cache_all(void)
+{
+       on_each_cpu(cacheflush_h_tmp_function, NULL, 1);
+}
+
+void flush_cache_mm(struct mm_struct *mm)
+{
+#ifdef CONFIG_SMP
+       flush_cache_all();
+#else
+       flush_cache_all_local();
+#endif
+}
+
+void
+flush_user_dcache_range(unsigned long start, unsigned long end)
+{
+       if ((end - start) < parisc_cache_flush_threshold)
+               flush_user_dcache_range_asm(start,end);
+       else
+               flush_data_cache();
+}
+
+void
+flush_user_icache_range(unsigned long start, unsigned long end)
+{
+       if ((end - start) < parisc_cache_flush_threshold)
+               flush_user_icache_range_asm(start,end);
+       else
+               flush_instruction_cache();
+}
+
+
+void flush_cache_range(struct vm_area_struct *vma,
+               unsigned long start, unsigned long end)
+{
+       int sr3;
+
+       BUG_ON(!vma->vm_mm->context);
+
+       sr3 = mfsp(3);
+       if (vma->vm_mm->context == sr3) {
+               flush_user_dcache_range(start,end);
+               flush_user_icache_range(start,end);
+       } else {
+               flush_cache_all();
+       }
+}
+
+void
+flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
+{
+       BUG_ON(!vma->vm_mm->context);
+
+       __flush_cache_page(vma, vmaddr, page_to_phys(pfn_to_page(pfn)));
+
+}